main ← claude/sdk-changes-pr-2744-d6ltvk
ouvert 03:46PM - 03 Aug 26 UTC
SDK counterpart of GladysAssistant/Gladys#2744 (generic AI provider external int…egration, contract B.19): integrations can now declare manifest `type: "ai"` and serve as the AI backend of Gladys in place of Gladys Plus.
## What's in
- **New WebSocket message type** `external-integration.ai.chat` in `WEBSOCKET_MESSAGE_TYPES.EXTERNAL_INTEGRATION.AI_CHAT`.
- **New `onAiChat(cb)` handler**: receives the OpenAI-compatible chat completion request relayed by the core (`{ messages, tools?, tool_choice?, purpose?, categories? }` — the `model` field is stripped core-side, picking one is the provider's job) and resolves an OpenAI-compatible completion, acked back as the `command-result` data. The core awaits the ack under **120 s** (`AI_CHAT_TIMEOUT_MS`), not the standard 5 s.
- **Client-side completion validation**, mirroring the core's contract check: the resolved value must be an object carrying an object `choices[0].message` — anything else (including `undefined`) acks the command as failed with an explicit error, instead of letting a malformed completion travel to Gladys and die at the contract boundary (`ExternalIntegrationUnavailableError`).
- **TypeScript typings**: `AiChatRequest`, `AiChatRequestMessage`, `AiChatCompletion`, `AiChatCompletionChoice`, `AiChatCompletionMessage`, the `onAiChat` method and the `AI_CHAT` message type.
- **README**: new "AI providers" section (fetch-based OpenAI-compatible example, 120 s ack window, no-silent-fallback doctrine) + a row in the Handlers table.
- **Tests**: `test/ai.test.js` against the fake Gladys server (success with `data`, tool_calls-only completion, handler throw, malformed completions, "not implemented"), plus compile-time coverage in `test/types/api.test-d.ts`.
## Checks
- `npm test`: 185/185 pass
- `npm run coverage`: thresholds green (100% stmts/funcs/lines)
- `npm run lint`, `npm run prettier-check`, `npm run check-types`: clean
🤖 Generated with [Claude Code](https://claude.com/claude-code)
https://claude.ai/code/session_018mwqzunU7Hj5yXKoAwR1hi
---
_Generated by [Claude Code](https://claude.ai/code/session_018mwqzunU7Hj5yXKoAwR1hi)_