Skip to content

Commit 8031790

Browse files
committed
add Role type
1 parent 4b5c25d commit 8031790

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

@@ -1567,7 +1572,7 @@ export const SamplingMessageContentBlockSchema = z.discriminatedUnion('type', [
15671572
*/
15681573
export const SamplingMessageSchema = z
15691574
.object({
1570-
role: z.enum(['user', 'assistant']),
1575+
role: RoleSchema,
15711576
content: z.union([SamplingMessageContentBlockSchema, z.array(SamplingMessageContentBlockSchema)]),
15721577
/**
15731578
* See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)
@@ -1651,7 +1656,7 @@ export const CreateMessageResultSchema = ResultSchema.extend({
16511656
* This field is an open string to allow for provider-specific stop reasons.
16521657
*/
16531658
stopReason: z.optional(z.enum(['endTurn', 'stopSequence', 'maxTokens']).or(z.string())),
1654-
role: z.enum(['user', 'assistant']),
1659+
role: RoleSchema,
16551660
/**
16561661
* Response content. Single content block (text, image, or audio).
16571662
*/
@@ -1679,7 +1684,7 @@ export const CreateMessageResultWithToolsSchema = ResultSchema.extend({
16791684
* This field is an open string to allow for provider-specific stop reasons.
16801685
*/
16811686
stopReason: z.optional(z.enum(['endTurn', 'stopSequence', 'maxTokens', 'toolUse']).or(z.string())),
1682-
role: z.enum(['user', 'assistant']),
1687+
role: RoleSchema,
16831688
/**
16841689
* Response content. May be a single block or array. May include ToolUseContent if stopReason is "toolUse".
16851690
*/
@@ -2269,6 +2274,7 @@ export type Icon = Infer<typeof IconSchema>;
22692274
export type Icons = Infer<typeof IconsSchema>;
22702275
export type BaseMetadata = Infer<typeof BaseMetadataSchema>;
22712276
export type Annotations = Infer<typeof AnnotationsSchema>;
2277+
export type Role = Infer<typeof RoleSchema>;
22722278

22732279
/* Initialization */
22742280
export type Implementation = Infer<typeof ImplementationSchema>;

0 commit comments

Comments
 (0)