Uh oh!
There was an error while loading. Please reload this page.
Align AI chat protocol with Vercel AI SDK — remove custom types and schemas - #1028
Conversation
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Agent-Logs-Url: https://github.com/objectstack-ai/spec/sessions/2515d700-01d1-4303-8678-41f0ce9674da Co-authored-by: hotlong <50353452+hotlong@users.noreply.github.com>
…and schemas - Re-export ModelMessage, ToolCallPart, ToolResultPart, TextStreamPart from 'ai' - Remove AiChatRequestSchema/AiChatResponseSchema (use Vercel wire protocol) - Update IAIService/LLMAdapter to use Vercel types - Deprecate AIMessage, AIToolCall, AIToolResult, AIStreamEvent as aliases - Remove aiChat from IObjectStackAPI, client SDK, and DEFAULT_AI_ROUTES - Keep NLQ/Suggest/Insights protocols (ObjectStack-specific) - Update all tests (6772 pass) - Update CHANGELOG.md and ROADMAP.md Agent-Logs-Url: https://github.com/objectstack-ai/spec/sessions/2515d700-01d1-4303-8678-41f0ce9674da Co-authored-by: hotlong <50353452+hotlong@users.noreply.github.com>
hotlong
commented
Apr 1, 2026
@copilot 评估是否已经完成了任务中要求的所有开发,继续 |
hotlong
commented
Apr 1, 2026
@copilot 继续 |
…AI SDK types
- toolCalls: {id, name, arguments} → {type, toolCallId, toolName, input}
- AIMessage → ModelMessage
- AIStreamEvent → TextStreamPart<ToolSet>
- AIToolCall → ToolCallPart
- textDelta → text
- toolCall?.name → toolName
- streamChat yields updated to Vercel AI SDK format
- onToolError assertions: name → toolName
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: hotlong <50353452+hotlong@users.noreply.github.com>… types
- AIMessage → ModelMessage
- AIToolCall → ToolCallPart
- Tool call objects: { id, name, arguments } → { type: 'tool-call', toolCallId, toolName, input }
- Tool result access: result.content → (result.output as any).value
- Assistant message assertions: .toolCalls → content-based ToolCallPart filtering
- Tool message assertions: .toolCallId/.content → content[0].toolCallId/.output.value
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: hotlong <50353452+hotlong@users.noreply.github.com>- Update objectql-conversation-service.test.ts to use ModelMessage - Export ToolExecutionResult from tools/index.ts and service index - Fix comment referencing AIMessage in ai-routes.ts Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Co-authored-by: hotlong <50353452+hotlong@users.noreply.github.com>
- Extract extractOutputText() helper to deduplicate error text extraction - Replace any casts with proper type guards in objectql-conversation-service Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Co-authored-by: hotlong <50353452+hotlong@users.noreply.github.com>
Agent-Logs-Url: https://github.com/objectstack-ai/spec/sessions/7b5017d9-7b75-41e6-a0ad-6eb250b8d770 Co-authored-by: hotlong <50353452+hotlong@users.noreply.github.com>
…narrowing Agent-Logs-Url: https://github.com/objectstack-ai/spec/sessions/7b5017d9-7b75-41e6-a0ad-6eb250b8d770 Co-authored-by: hotlong <50353452+hotlong@users.noreply.github.com>
All remaining work is now complete in commit
|
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Pull request overview
This PR aligns ObjectStack’s AI chat contracts and related runtime/service code with the canonical Vercel AI SDK (ai) message/tool/streaming types, removing the duplicated “AiChat” wire protocol and migrating downstream usage to Vercel’s discriminated unions.
Changes:
- Re-export Vercel AI SDK types in
@objectstack/spec/contractsand updateIAIService/LLMAdaptersignatures to useModelMessage[]andTextStreamPart<ToolSet>. - Remove
AiChatRequestSchema/AiChatResponseSchemaand theaiChatmethod/route/client surface area from the ObjectStack protocol layer. - Migrate
@objectstack/service-aitool calling, conversation persistence, and streaming helpers to Vercel AI SDK message/part shapes.
Reviewed changes
Copilot reviewed 27 out of 28 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| ROADMAP.md | Bumps “Last Updated” date to reflect protocol changes. |
| pnpm-lock.yaml | Locks new ai dependency and its transitive packages. |
| packages/spec/src/contracts/llm-adapter.ts | Switches adapter contract to Vercel ModelMessage + TextStreamPart<ToolSet>. |
| packages/spec/src/contracts/llm-adapter.test.ts | Updates contract tests to compile against Vercel stream/message types. |
| packages/spec/src/contracts/ai-service.ts | Re-exports canonical Vercel types; preserves deprecated aliases; updates service contracts. |
| packages/spec/src/contracts/ai-service.test.ts | Updates contract tests for Vercel message/stream/tool-part shapes. |
| packages/spec/src/api/protocol.zod.ts | Removes AiChat request/response schemas and aiChat from protocol interface. |
| packages/spec/src/api/protocol.test.ts | Removes AiChat schema validation assertions. |
| packages/spec/src/api/plugin-rest-api.zod.ts | Removes aiChat from default AI REST route registration. |
| packages/spec/src/api/plugin-rest-api.test.ts | Updates expectations for removed aiChat endpoint. |
| packages/spec/package.json | Adds ai dependency to spec for type re-exports. |
| packages/services/service-ai/src/tools/tool-registry.ts | Migrates tool execution to ToolCallPart input + ToolResultPart output (ToolExecutionResult). |
| packages/services/service-ai/src/tools/index.ts | Exports ToolExecutionResult type. |
| packages/services/service-ai/src/routes/ai-routes.ts | Updates route typing/casts to ModelMessage. |
| packages/services/service-ai/src/routes/agent-routes.ts | Updates agent chat route message typing to ModelMessage. |
| packages/services/service-ai/src/index.ts | Re-exports new tool execution result type. |
| packages/services/service-ai/src/conversation/objectql-conversation-service.ts | Serializes/deserializes Vercel ModelMessage union into flat DB columns. |
| packages/services/service-ai/src/conversation/in-memory-conversation-service.ts | Updates conversation message type to ModelMessage. |
| packages/services/service-ai/src/ai-service.ts | Migrates chat/tool-call loop + streaming helpers to Vercel message/stream part formats. |
| packages/services/service-ai/src/agent-runtime.ts | Updates system message construction to ModelMessage. |
| packages/services/service-ai/src/adapters/memory-adapter.ts | Streams Vercel TextStreamPart<ToolSet> and handles non-string message content safely. |
| packages/services/service-ai/src/tests/objectql-conversation-service.test.ts | Updates persistence tests for Vercel message union shapes. |
| packages/services/service-ai/src/tests/chatbot-features.test.ts | Updates tool-calling tests to Vercel tool-call/tool-result parts. |
| packages/services/service-ai/src/tests/auth-and-toolcalling.test.ts | Updates streaming/tool-loop tests to Vercel stream parts + tool call parts. |
| packages/services/service-ai/src/tests/ai-service.test.ts | Updates AIService + ToolRegistry tests to new types and stream part fields. |
| packages/client/src/index.ts | Removes client ai.chat() method and associated exported types. |
| content/docs/references/api/protocol.mdx | Removes AiChat protocol docs and references in TypeScript usage snippet. |
| CHANGELOG.md | Documents the migration/removal and new ai dependency. |
Files not reviewed (1)
- pnpm-lock.yaml: Language not supported
| /** | ||
| * Validate that `raw` is a well-formed AIMessage. | ||
| * Validate that `raw` is a well-formed message. | ||
| * Returns null on success, or an error string on failure. | ||
| */ | ||
| function validateMessage(raw: unknown): string | null { |
There was a problem hiding this comment.
validateMessage() is still written for the old flat message shape (it assumes content is always a string). With the switch to Vercel ModelMessage, assistant.content can be an array of parts (including tool-call parts) and tool.content is an array of tool-result parts, so this validator will reject valid tool-calling conversations and/or force unsafe casts downstream. Please update validation to be role-aware (system/user: string; assistant: string | parts[]; tool: tool-result parts[]) or validate against Vercel AI SDK message structures before invoking aiService/conversationService.
| "ai": "^6.0.142", | ||
| "zod": "^4.3.6" | ||
| }, |
There was a problem hiding this comment.
Adding ai as a direct dependency pulls in transitive packages with stricter Node engine requirements (e.g. @vercel/oidc declares node >= 20 in the lockfile). This is inconsistent with the repo/package engines (node >=18) and can break installs in engine-strict environments or cause runtime incompatibilities. Consider (a) verifying the project’s supported Node version and bumping engines.node accordingly, or (b) switching to an ai version whose transitive deps support Node 18, or (c) moving ai to a peer dependency (with clear install guidance) since it’s only needed for type re-exports.
| "ai": "^6.0.142", | |
| "zod": "^4.3.6" | |
| }, | |
| "zod": "^4.3.6" | |
| }, | |
| "peerDependencies": { | |
| "ai": "^6.0.142" | |
| }, |
| '@vercel/oidc@3.1.0': | ||
| resolution: {integrity: sha512-Fw28YZpRnA3cAHHDlkt7xQHiJ0fcL+NRcIqsocZQUSmbzeIKRpwttJjik5ZGanXP+vlA4SbTg+AbA3bP363l+w==} | ||
| engines: {node: '>= 20'} | ||
There was a problem hiding this comment.
This lockfile now includes @vercel/oidc@3.1.0 with engines: { node: '>= 20' } as a transitive dependency of ai. That conflicts with the repo’s declared Node support (>=18) and may fail CI or consumer installs when engines are enforced. Please either align the repo/package engines.node to >=20 or adjust the ai dependency strategy/version to avoid pulling Node>=20-only transitive deps.
The spec layer defined custom AI chat types (
AIMessage,AIToolCall,AIStreamEvent) and Zod schemas (AiChatRequestSchema,AiChatResponseSchema) that duplicate what the Vercel AI SDK already provides. Since the frontend uses@ai-sdk/react/useChatdirectly, these custom definitions create maintenance burden and potential drift.Re-export Vercel AI SDK types as canonical
ModelMessagereplacesAIMessageToolCallPartreplacesAIToolCallToolResultPartreplacesAIToolResultTextStreamPart<ToolSet>replacesAIStreamEventUpdate service contracts
IAIService.chat(),streamChat(),chatWithTools()now acceptModelMessage[]LLMAdaptermethods updated similarlyAIConversation.messagesis nowModelMessage[]ChatWithToolsOptions.onToolErrorcallback receivesToolCallPartRemove redundant chat wire protocol
AiChatRequestSchema/AiChatResponseSchemafromprotocol.zod.tsaiChatfromIObjectStackAPI,DEFAULT_AI_ROUTES, and client SDKMigrate
packages/services/service-aito canonical Vercel typesAll 8 source files and 4 test files in
service-aihave been migrated from deprecated aliases to canonical Vercel AI SDK types with proper structural alignment:ToolRegistry:execute()now acceptsToolCallPart(usingtoolCallId,toolName,input) and returnsToolExecutionResult(extendsToolResultPartwithisError?: booleanfor error tracking in the tool-call loop)AIService.chatWithTools(): Constructs properAssistantModelMessage(content asArray<TextPart | ToolCallPart>) andToolModelMessage(content asArray<ToolResultPart>)MemoryLLMAdapter.streamChat(): Emits VercelTextStreamPart<ToolSet>events with{ type: 'text-delta', id, text }formatModelMessagediscriminated union to/from flat DB columns with backward compatibility for old-format messagestextDeltaPart()andfinishPart()utility functions eliminate repeated type castsFix documentation
AiChatRequest/AiChatResponsereferences fromcontent/docs/references/api/protocol.mdx