endpoint = $endpoint ?? config('services.agent_provider.endpoint', ''); } /** * @param array $context * @param array $options */ public function generate(array $context, array $options = []): string { if (empty($this->endpoint)) { // placeholder to avoid accidental outbound calls when未配置 return (new DummyAgentProvider())->generate($context, $options); } $payload = [ 'context' => $context, 'options' => $options, ]; $response = Http::post($this->endpoint, $payload); if (! $response->successful()) { throw new \RuntimeException('Agent provider failed: '.$response->body()); } $data = $response->json(); return is_string($data) ? $data : ($data['content'] ?? ''); } }