Skip to content

Commit 2d4da8e

Browse files
ochafikclaude
andcommitted
refactor: derive CreateMessageResultSchema from generated spec schema
Use .omit({ content: true }).extend() to inherit all fields from the generated spec schema while only overriding content to use the backwards-compatible SamplingContentSchema. This ensures we automatically inherit any new fields added to the spec. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent a8171e4 commit 2d4da8e

File tree

1 file changed

+6
-15
lines changed

1 file changed

+6
-15
lines changed

src/types.ts

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -601,21 +601,12 @@ export const SamplingContentSchema = z.discriminatedUnion('type', [TextContentSc
601601
* Uses single content block without tool types for v1.x API compatibility.
602602
* For tool use support, use CreateMessageResultWithToolsSchema instead.
603603
*/
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-
});
604+
export const CreateMessageResultSchema = CreateMessageResultSpecSchema
605+
.omit({ content: true })
606+
.extend({
607+
/** Response content. Single block, basic types only (text/image/audio). */
608+
content: SamplingContentSchema
609+
});
619610

620611
/**
621612
* The client's response to a sampling/create_message request when tools were provided.

0 commit comments

Comments
 (0)