Skip to content

Commit e7ab32f

Browse files
Role - moved from inline to reusable type (#1221)
1 parent b0aac58 commit e7ab32f

File tree

2 files changed

+15
-6
lines changed

2 files changed

+15
-6
lines changed

src/spec.types.test.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -660,6 +660,10 @@ const sdkTypeChecks = {
660660
Annotations: (sdk: SDKTypes.Annotations, spec: SpecTypes.Annotations) => {
661661
sdk = spec;
662662
spec = sdk;
663+
},
664+
Role: (sdk: SDKTypes.Role, spec: SpecTypes.Role) => {
665+
sdk = spec;
666+
spec = sdk;
663667
}
664668
};
665669

@@ -669,7 +673,6 @@ const SDK_TYPES_FILE = 'src/types.ts';
669673

670674
const MISSING_SDK_TYPES = [
671675
// These are inlined in the SDK:
672-
'Role',
673676
'Error', // The inner error object of a JSONRPCError
674677
'URLElicitationRequiredError' // In the SDK, but with a custom definition
675678
];

src/types.ts

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -790,14 +790,19 @@ export const BlobResourceContentsSchema = ResourceContentsSchema.extend({
790790
blob: Base64Schema
791791
});
792792

793+
/**
794+
* The sender or recipient of messages and data in a conversation.
795+
*/
796+
export const RoleSchema = z.enum(['user', 'assistant']);
797+
793798
/**
794799
* Optional annotations providing clients additional context about a resource.
795800
*/
796801
export const AnnotationsSchema = z.object({
797802
/**
798803
* Intended audience(s) for the resource.
799804
*/
800-
audience: z.array(z.enum(['user', 'assistant'])).optional(),
805+
audience: z.array(RoleSchema).optional(),
801806

802807
/**
803808
* Importance hint for the resource, from 0 (least) to 1 (most).
@@ -1200,7 +1205,7 @@ export const ContentBlockSchema = z.union([
12001205
* Describes a message returned as part of a prompt.
12011206
*/
12021207
export const PromptMessageSchema = z.object({
1203-
role: z.enum(['user', 'assistant']),
1208+
role: RoleSchema,
12041209
content: ContentBlockSchema
12051210
});
12061211

@@ -1647,7 +1652,7 @@ export const SamplingMessageContentBlockSchema = z.discriminatedUnion('type', [
16471652
*/
16481653
export const SamplingMessageSchema = z
16491654
.object({
1650-
role: z.enum(['user', 'assistant']),
1655+
role: RoleSchema,
16511656
content: z.union([SamplingMessageContentBlockSchema, z.array(SamplingMessageContentBlockSchema)]),
16521657
/**
16531658
* See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)
@@ -1731,7 +1736,7 @@ export const CreateMessageResultSchema = ResultSchema.extend({
17311736
* This field is an open string to allow for provider-specific stop reasons.
17321737
*/
17331738
stopReason: z.optional(z.enum(['endTurn', 'stopSequence', 'maxTokens']).or(z.string())),
1734-
role: z.enum(['user', 'assistant']),
1739+
role: RoleSchema,
17351740
/**
17361741
* Response content. Single content block (text, image, or audio).
17371742
*/
@@ -1759,7 +1764,7 @@ export const CreateMessageResultWithToolsSchema = ResultSchema.extend({
17591764
* This field is an open string to allow for provider-specific stop reasons.
17601765
*/
17611766
stopReason: z.optional(z.enum(['endTurn', 'stopSequence', 'maxTokens', 'toolUse']).or(z.string())),
1762-
role: z.enum(['user', 'assistant']),
1767+
role: RoleSchema,
17631768
/**
17641769
* Response content. May be a single block or array. May include ToolUseContent if stopReason is "toolUse".
17651770
*/
@@ -2349,6 +2354,7 @@ export type Icon = Infer<typeof IconSchema>;
23492354
export type Icons = Infer<typeof IconsSchema>;
23502355
export type BaseMetadata = Infer<typeof BaseMetadataSchema>;
23512356
export type Annotations = Infer<typeof AnnotationsSchema>;
2357+
export type Role = Infer<typeof RoleSchema>;
23522358

23532359
/* Initialization */
23542360
export type Implementation = Infer<typeof ImplementationSchema>;

0 commit comments

Comments
 (0)