Skip to content

Commit a8171e4

Browse files
ochafikclaude
andcommitted
fix: define CreateMessageResultSchema locally for backwards compat
The spec's CreateMessageResult includes array content and tool types (ToolUseContent, ToolResultContent), but the SDK's v1.x API expects single content without tools for backwards compatibility. - Import generated CreateMessageResultSchema as CreateMessageResultSpecSchema - Define local CreateMessageResultSchema with single SamplingContentSchema (text/image/audio only, no arrays, no tool types) - Keep CreateMessageResultWithToolsSchema for full spec-compliant responses This fixes type errors in toolWithSampleServer.ts and spec.types.test.ts where code expected single content blocks. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 6eef9e6 commit a8171e4

File tree

1 file changed

+24
-2
lines changed

1 file changed

+24
-2
lines changed

src/types.ts

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ import {
103103
// Sampling schemas
104104
CreateMessageRequestParamsSchema,
105105
CreateMessageRequestSchema,
106-
CreateMessageResultSchema,
106+
CreateMessageResultSchema as CreateMessageResultSpecSchema,
107107
// Elicitation schemas
108108
ElicitRequestFormParamsSchema,
109109
ElicitRequestURLParamsSchema,
@@ -273,7 +273,8 @@ export {
273273
CompleteResultSchema,
274274
CreateMessageRequestParamsSchema,
275275
CreateMessageRequestSchema,
276-
CreateMessageResultSchema,
276+
// Note: CreateMessageResultSchema is defined locally for backwards compat (single content, no tools)
277+
// CreateMessageResultSpecSchema (generated) is used for CreateMessageResultWithToolsSchema
277278
ElicitRequestFormParamsSchema,
278279
ElicitRequestURLParamsSchema,
279280
ElicitRequestParamsSchema,
@@ -595,6 +596,27 @@ export const SamplingContentSchema = z.discriminatedUnion('type', [TextContentSc
595596

596597
// SamplingMessageSchema, CreateMessageRequestParamsSchema, CreateMessageRequestSchema,
597598

599+
/**
600+
* The client's response to a sampling/create_message request (backwards-compatible version).
601+
* Uses single content block without tool types for v1.x API compatibility.
602+
* For tool use support, use CreateMessageResultWithToolsSchema instead.
603+
*/
604+
export const CreateMessageResultSchema = ResultSchema.extend({
605+
/**
606+
* The name of the model that generated the message.
607+
*/
608+
model: z.string(),
609+
/**
610+
* The reason why sampling stopped, if known.
611+
*/
612+
stopReason: z.optional(z.enum(['endTurn', 'stopSequence', 'maxTokens']).or(z.string())),
613+
role: RoleSchema,
614+
/**
615+
* Response content. Single block, basic types only (text/image/audio).
616+
*/
617+
content: SamplingContentSchema
618+
});
619+
598620
/**
599621
* The client's response to a sampling/create_message request when tools were provided.
600622
* This version supports array content for tool use flows.

0 commit comments

Comments
 (0)