|
1 | 1 | <?php |
2 | 2 |
|
| 3 | +declare(strict_types=1); |
| 4 | + |
3 | 5 | namespace LangGraphPlatform; |
4 | 6 |
|
5 | | -class LangGraphPlatform {} |
| 7 | +use LangGraphPlatform\Http\Client as HttpClient; |
| 8 | +use LangGraphPlatform\Resources\AssistantsClient; |
| 9 | +use LangGraphPlatform\Resources\ThreadsClient; |
| 10 | +use LangGraphPlatform\Resources\RunsClient; |
| 11 | +use LangGraphPlatform\Resources\CronsClient; |
| 12 | +use LangGraphPlatform\Resources\StoreClient; |
| 13 | + |
| 14 | +/** |
| 15 | + * Main LangGraph Platform SDK client. |
| 16 | + */ |
| 17 | +class LangGraphPlatform |
| 18 | +{ |
| 19 | + private HttpClient $httpClient; |
| 20 | + private AssistantsClient $assistants; |
| 21 | + private ThreadsClient $threads; |
| 22 | + private RunsClient $runs; |
| 23 | + private CronsClient $crons; |
| 24 | + private StoreClient $store; |
| 25 | + |
| 26 | + public function __construct(?array $config = null) |
| 27 | + { |
| 28 | + // Get configuration from Laravel config if not provided |
| 29 | + if ($config === null) { |
| 30 | + $config = config('langgraph-platform-php', []); |
| 31 | + } |
| 32 | + |
| 33 | + $this->httpClient = new HttpClient($config); |
| 34 | + $this->initializeResourceClients(); |
| 35 | + } |
| 36 | + |
| 37 | + /** |
| 38 | + * Initialize all resource client instances. |
| 39 | + */ |
| 40 | + private function initializeResourceClients(): void |
| 41 | + { |
| 42 | + $this->assistants = new AssistantsClient($this->httpClient); |
| 43 | + $this->threads = new ThreadsClient($this->httpClient); |
| 44 | + $this->runs = new RunsClient($this->httpClient); |
| 45 | + $this->crons = new CronsClient($this->httpClient); |
| 46 | + $this->store = new StoreClient($this->httpClient); |
| 47 | + } |
| 48 | + |
| 49 | + /** |
| 50 | + * Get assistants resource client. |
| 51 | + */ |
| 52 | + public function assistants(): AssistantsClient |
| 53 | + { |
| 54 | + return $this->assistants; |
| 55 | + } |
| 56 | + |
| 57 | + /** |
| 58 | + * Get threads resource client. |
| 59 | + */ |
| 60 | + public function threads(): ThreadsClient |
| 61 | + { |
| 62 | + return $this->threads; |
| 63 | + } |
| 64 | + |
| 65 | + /** |
| 66 | + * Get runs resource client. |
| 67 | + */ |
| 68 | + public function runs(): RunsClient |
| 69 | + { |
| 70 | + return $this->runs; |
| 71 | + } |
| 72 | + |
| 73 | + /** |
| 74 | + * Get crons resource client. |
| 75 | + */ |
| 76 | + public function crons(): CronsClient |
| 77 | + { |
| 78 | + return $this->crons; |
| 79 | + } |
| 80 | + |
| 81 | + /** |
| 82 | + * Get store resource client. |
| 83 | + */ |
| 84 | + public function store(): StoreClient |
| 85 | + { |
| 86 | + return $this->store; |
| 87 | + } |
| 88 | + |
| 89 | + /** |
| 90 | + * Get the underlying HTTP client. |
| 91 | + */ |
| 92 | + public function getHttpClient(): HttpClient |
| 93 | + { |
| 94 | + return $this->httpClient; |
| 95 | + } |
| 96 | + |
| 97 | + /** |
| 98 | + * Configure the client with new settings. |
| 99 | + */ |
| 100 | + public function configure(array $config): self |
| 101 | + { |
| 102 | + $this->httpClient->configure($config); |
| 103 | + return $this; |
| 104 | + } |
| 105 | + |
| 106 | + /** |
| 107 | + * Create a new client instance with custom configuration. |
| 108 | + */ |
| 109 | + public static function create(array $config = []): self |
| 110 | + { |
| 111 | + return new self($config); |
| 112 | + } |
| 113 | + |
| 114 | + /** |
| 115 | + * Create a client instance using environment variables. |
| 116 | + */ |
| 117 | + public static function fromEnvironment(): self |
| 118 | + { |
| 119 | + return new self([ |
| 120 | + 'api_key' => env('LANGGRAPH_API_KEY', 'fake-api-key'), |
| 121 | + 'base_url' => env('LANGGRAPH_BASE_URL', 'https://api.langchain.com'), |
| 122 | + 'timeout' => (int) env('LANGGRAPH_TIMEOUT', 30), |
| 123 | + 'retries' => (int) env('LANGGRAPH_RETRIES', 3), |
| 124 | + ]); |
| 125 | + } |
| 126 | +} |
0 commit comments