@to11ai/sdk 0.7.0 → 0.8.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/gateway.cjs CHANGED
@@ -40,8 +40,10 @@ var __export = (target, all) => {
40
40
  var exports_gateway = {};
41
41
  __export(exports_gateway, {
42
42
  toOpenAITools: () => toOpenAITools,
43
+ toOpenAIToolChoice: () => toOpenAIToolChoice,
43
44
  toOpenAIMessages: () => toOpenAIMessages,
44
45
  toAnthropicTools: () => toAnthropicTools,
46
+ toAnthropicToolChoice: () => toAnthropicToolChoice,
45
47
  toAnthropicMessages: () => toAnthropicMessages,
46
48
  gatewayPromptHeaders: () => gatewayPromptHeaders,
47
49
  gatewayAuthHeaders: () => gatewayAuthHeaders
@@ -102,6 +104,13 @@ function toOpenAITools(tools) {
102
104
  return { type: "function", function: fn };
103
105
  });
104
106
  }
107
+ function toOpenAIToolChoice(toolChoice) {
108
+ if (toolChoice == null)
109
+ return;
110
+ if (typeof toolChoice === "string")
111
+ return toolChoice;
112
+ return { type: "function", function: { name: toolChoice.name } };
113
+ }
105
114
  function toAnthropicTools(tools) {
106
115
  if (tools == null)
107
116
  return [];
@@ -116,6 +125,17 @@ function toAnthropicTools(tools) {
116
125
  return out;
117
126
  });
118
127
  }
128
+ function toAnthropicToolChoice(toolChoice) {
129
+ if (toolChoice == null)
130
+ return;
131
+ if (toolChoice === "auto")
132
+ return { type: "auto" };
133
+ if (toolChoice === "none")
134
+ return { type: "none" };
135
+ if (toolChoice === "required")
136
+ return { type: "any" };
137
+ return { type: "tool", name: toolChoice.name };
138
+ }
119
139
  function requireToolCallId(id) {
120
140
  if (typeof id !== "string" || id.length === 0) {
121
141
  throw new Error("to11 SDK: malformed tool history — a tool call/result is missing its id (toolCallId). Author a non-empty id before converting messages.");
package/dist/gateway.d.ts CHANGED
@@ -62,6 +62,13 @@ export interface OpenAITool {
62
62
  parameters: Record<string, unknown>;
63
63
  };
64
64
  }
65
+ /** OpenAI `tool_choice` value for a Chat Completions request. */
66
+ export type OpenAIToolChoice = "auto" | "none" | "required" | {
67
+ type: "function";
68
+ function: {
69
+ name: string;
70
+ };
71
+ };
65
72
  /** OpenAI Chat Completions assistant `tool_calls[]` entry. */
66
73
  export interface OpenAIToolCall {
67
74
  id: string;
@@ -103,6 +110,17 @@ export interface AnthropicMessage {
103
110
  role: "user" | "assistant";
104
111
  content: string | AnthropicContentBlock[];
105
112
  }
113
+ /** Anthropic Messages `tool_choice` value. */
114
+ export type AnthropicToolChoice = {
115
+ type: "auto";
116
+ } | {
117
+ type: "any";
118
+ } | {
119
+ type: "none";
120
+ } | {
121
+ type: "tool";
122
+ name: string;
123
+ };
106
124
  /**
107
125
  * Shape resolved tool definitions for the OpenAI Chat Completions `tools`
108
126
  * field: `{ type: "function", function: { name, description?, parameters } }`.
@@ -112,9 +130,24 @@ export interface AnthropicMessage {
112
130
  *
113
131
  * @example
114
132
  * const tools = toOpenAITools(prompt.tools);
115
- * await openai.chat.completions.create({ model, messages, tools });
133
+ * const tool_choice = toOpenAIToolChoice(prompt.toolChoice);
134
+ * await openai.chat.completions.create({ model, messages, tools, tool_choice });
116
135
  */
117
136
  export declare function toOpenAITools(tools: ReadonlyArray<ResolvedToolDefinition> | null | undefined): OpenAITool[];
137
+ /**
138
+ * Map a resolved prompt's provider-neutral `toolChoice` to the OpenAI
139
+ * Chat Completions `tool_choice` field.
140
+ *
141
+ * - `null` / `undefined` → `undefined` (omit the field)
142
+ * - `"auto"` → `"auto"`, `"none"` → `"none"`, `"required"` → `"required"`
143
+ * - `{ name }` → `{ type: "function", function: { name } }`
144
+ *
145
+ * @example
146
+ * const tools = toOpenAITools(prompt.tools);
147
+ * const tool_choice = toOpenAIToolChoice(prompt.toolChoice);
148
+ * await openai.chat.completions.create({ model, messages, tools, tool_choice });
149
+ */
150
+ export declare function toOpenAIToolChoice(toolChoice: ResolvedPrompt["toolChoice"]): OpenAIToolChoice | undefined;
118
151
  /**
119
152
  * Shape resolved tool definitions for the Anthropic Messages `tools` field:
120
153
  * `{ name, description?, input_schema }` (Anthropic names the JSON Schema field
@@ -122,9 +155,26 @@ export declare function toOpenAITools(tools: ReadonlyArray<ResolvedToolDefinitio
122
155
  *
123
156
  * @example
124
157
  * const tools = toAnthropicTools(prompt.tools);
125
- * await anthropic.messages.create({ model, system, messages, tools });
158
+ * const tool_choice = toAnthropicToolChoice(prompt.toolChoice);
159
+ * await anthropic.messages.create({ model, system, messages, tools, tool_choice });
126
160
  */
127
161
  export declare function toAnthropicTools(tools: ReadonlyArray<ResolvedToolDefinition> | null | undefined): AnthropicTool[];
162
+ /**
163
+ * Map a resolved prompt's provider-neutral `toolChoice` to the Anthropic
164
+ * Messages `tool_choice` field.
165
+ *
166
+ * - `null` / `undefined` → `undefined` (omit the field)
167
+ * - `"auto"` → `{ type: "auto" }`
168
+ * - `"none"` → `{ type: "none" }` (the Anthropic API supports this natively)
169
+ * - `"required"` → `{ type: "any" }` (Anthropic's name for "must invoke a tool")
170
+ * - `{ name }` → `{ type: "tool", name }`
171
+ *
172
+ * @example
173
+ * const tools = toAnthropicTools(prompt.tools);
174
+ * const tool_choice = toAnthropicToolChoice(prompt.toolChoice);
175
+ * await anthropic.messages.create({ model, system, messages, tools, tool_choice });
176
+ */
177
+ export declare function toAnthropicToolChoice(toolChoice: ResolvedPrompt["toolChoice"]): AnthropicToolChoice | undefined;
128
178
  /**
129
179
  * Shape rendered turns for the OpenAI Chat Completions `messages` field.
130
180
  *
package/dist/gateway.js CHANGED
@@ -56,6 +56,13 @@ function toOpenAITools(tools) {
56
56
  return { type: "function", function: fn };
57
57
  });
58
58
  }
59
+ function toOpenAIToolChoice(toolChoice) {
60
+ if (toolChoice == null)
61
+ return;
62
+ if (typeof toolChoice === "string")
63
+ return toolChoice;
64
+ return { type: "function", function: { name: toolChoice.name } };
65
+ }
59
66
  function toAnthropicTools(tools) {
60
67
  if (tools == null)
61
68
  return [];
@@ -70,6 +77,17 @@ function toAnthropicTools(tools) {
70
77
  return out;
71
78
  });
72
79
  }
80
+ function toAnthropicToolChoice(toolChoice) {
81
+ if (toolChoice == null)
82
+ return;
83
+ if (toolChoice === "auto")
84
+ return { type: "auto" };
85
+ if (toolChoice === "none")
86
+ return { type: "none" };
87
+ if (toolChoice === "required")
88
+ return { type: "any" };
89
+ return { type: "tool", name: toolChoice.name };
90
+ }
73
91
  function requireToolCallId(id) {
74
92
  if (typeof id !== "string" || id.length === 0) {
75
93
  throw new Error("to11 SDK: malformed tool history — a tool call/result is missing its id (toolCallId). Author a non-empty id before converting messages.");
@@ -150,8 +168,10 @@ function toAnthropicMessages(messages) {
150
168
  }
151
169
  export {
152
170
  toOpenAITools,
171
+ toOpenAIToolChoice,
153
172
  toOpenAIMessages,
154
173
  toAnthropicTools,
174
+ toAnthropicToolChoice,
155
175
  toAnthropicMessages,
156
176
  gatewayPromptHeaders,
157
177
  gatewayAuthHeaders
@@ -233,6 +233,7 @@ export type PromptRelease = {
233
233
  };
234
234
  export type PromptVersion = {
235
235
  changelog: string | null;
236
+ contextSchema: unknown;
236
237
  createdAt: string;
237
238
  createdByDisplayName: string | null;
238
239
  createdByImage: string | null;
@@ -279,6 +280,9 @@ export type ResolvedPrompt = {
279
280
  releaseId: string;
280
281
  rendered: RenderedPrompt;
281
282
  subjectHash?: string | null;
283
+ toolChoice?: 'auto' | 'none' | 'required' | {
284
+ name: string;
285
+ } | null;
282
286
  tools?: Array<ResolvedToolDefinition> | null;
283
287
  variantName?: string | null;
284
288
  version: number;
@@ -14574,6 +14578,15 @@ export type PromptsCreatePromptVersionData = {
14574
14578
  allowBlockRemovals?: Array<string> | null;
14575
14579
  baseVersionId?: string | null;
14576
14580
  changelog?: string | null;
14581
+ contextSchema?: {
14582
+ properties?: {
14583
+ [key: string]: {
14584
+ enum?: Array<string> | null;
14585
+ type?: 'string' | 'number' | 'boolean' | 'enum' | null;
14586
+ };
14587
+ } | null;
14588
+ required?: Array<string> | null;
14589
+ } | null;
14577
14590
  format: 'text' | 'chat';
14578
14591
  modelConfig?: unknown | null;
14579
14592
  templateJson: unknown;
@@ -14740,6 +14753,7 @@ export type PromptsGetPromptVersionDiffResponses = {
14740
14753
  name: string;
14741
14754
  op: 'add';
14742
14755
  role: 'system' | 'user' | 'assistant' | 'developer' | 'tool';
14756
+ toolCallId?: string | null;
14743
14757
  toolCalls?: Array<{
14744
14758
  arguments: {
14745
14759
  [key: string]: unknown;
@@ -14747,15 +14761,6 @@ export type PromptsGetPromptVersionDiffResponses = {
14747
14761
  id: string;
14748
14762
  name: string;
14749
14763
  }> | null;
14750
- toolSchema?: {
14751
- content?: string | null;
14752
- description?: string | null;
14753
- parameters?: {
14754
- [key: string]: unknown;
14755
- } | null;
14756
- toolCallId?: string | null;
14757
- toolKind?: 'definition' | 'result' | null;
14758
- } | null;
14759
14764
  } | {
14760
14765
  condition: {
14761
14766
  kind: string;
@@ -14764,6 +14769,7 @@ export type PromptsGetPromptVersionDiffResponses = {
14764
14769
  name: string;
14765
14770
  op: 'remove';
14766
14771
  role: 'system' | 'user' | 'assistant' | 'developer' | 'tool';
14772
+ toolCallId?: string | null;
14767
14773
  toolCalls?: Array<{
14768
14774
  arguments: {
14769
14775
  [key: string]: unknown;
@@ -14771,15 +14777,6 @@ export type PromptsGetPromptVersionDiffResponses = {
14771
14777
  id: string;
14772
14778
  name: string;
14773
14779
  }> | null;
14774
- toolSchema?: {
14775
- content?: string | null;
14776
- description?: string | null;
14777
- parameters?: {
14778
- [key: string]: unknown;
14779
- } | null;
14780
- toolCallId?: string | null;
14781
- toolKind?: 'definition' | 'result' | null;
14782
- } | null;
14783
14780
  } | {
14784
14781
  after: string;
14785
14782
  before: string;
@@ -14805,26 +14802,10 @@ export type PromptsGetPromptVersionDiffResponses = {
14805
14802
  name: string;
14806
14803
  op: 'edit_required';
14807
14804
  } | {
14808
- after: {
14809
- content?: string | null;
14810
- description?: string | null;
14811
- parameters?: {
14812
- [key: string]: unknown;
14813
- } | null;
14814
- toolCallId?: string | null;
14815
- toolKind?: 'definition' | 'result' | null;
14816
- };
14817
- before: {
14818
- content?: string | null;
14819
- description?: string | null;
14820
- parameters?: {
14821
- [key: string]: unknown;
14822
- } | null;
14823
- toolCallId?: string | null;
14824
- toolKind?: 'definition' | 'result' | null;
14825
- };
14805
+ after: string;
14806
+ before: string;
14826
14807
  name: string;
14827
- op: 'edit_tool_schema';
14808
+ op: 'edit_tool_call_id';
14828
14809
  } | {
14829
14810
  after: Array<{
14830
14811
  arguments: {
@@ -301,6 +301,7 @@ export declare const zPromptRelease: z.ZodObject<{
301
301
  }, z.core.$strip>;
302
302
  export declare const zPromptVersion: z.ZodObject<{
303
303
  changelog: z.ZodNullable<z.ZodString>;
304
+ contextSchema: z.ZodUnknown;
304
305
  createdAt: z.ZodISODateTime;
305
306
  createdByDisplayName: z.ZodNullable<z.ZodString>;
306
307
  createdByImage: z.ZodNullable<z.ZodString>;
@@ -489,6 +490,13 @@ export declare const zResolvedPrompt: z.ZodObject<{
489
490
  }, z.core.$strip>]>>;
490
491
  }, z.core.$strip>]>;
491
492
  subjectHash: z.ZodOptional<z.ZodNullable<z.ZodString>>;
493
+ toolChoice: z.ZodOptional<z.ZodNullable<z.ZodUnion<readonly [z.ZodEnum<{
494
+ auto: "auto";
495
+ none: "none";
496
+ required: "required";
497
+ }>, z.ZodObject<{
498
+ name: z.ZodString;
499
+ }, z.core.$strip>]>>>;
492
500
  tools: z.ZodOptional<z.ZodNullable<z.ZodArray<z.ZodObject<{
493
501
  description: z.ZodOptional<z.ZodNullable<z.ZodString>>;
494
502
  name: z.ZodString;
@@ -8378,6 +8386,7 @@ export declare const zPromptsListPromptVersionsResponse: z.ZodObject<{
8378
8386
  code: z.ZodNumber;
8379
8387
  data: z.ZodNullable<z.ZodArray<z.ZodObject<{
8380
8388
  changelog: z.ZodNullable<z.ZodString>;
8389
+ contextSchema: z.ZodUnknown;
8381
8390
  createdAt: z.ZodISODateTime;
8382
8391
  createdByDisplayName: z.ZodNullable<z.ZodString>;
8383
8392
  createdByImage: z.ZodNullable<z.ZodString>;
@@ -8419,6 +8428,18 @@ export declare const zPromptsCreatePromptVersionBody: z.ZodObject<{
8419
8428
  allowBlockRemovals: z.ZodOptional<z.ZodNullable<z.ZodArray<z.ZodString>>>;
8420
8429
  baseVersionId: z.ZodOptional<z.ZodNullable<z.ZodString>>;
8421
8430
  changelog: z.ZodOptional<z.ZodNullable<z.ZodString>>;
8431
+ contextSchema: z.ZodOptional<z.ZodNullable<z.ZodObject<{
8432
+ properties: z.ZodOptional<z.ZodNullable<z.ZodRecord<z.ZodString, z.ZodObject<{
8433
+ enum: z.ZodOptional<z.ZodNullable<z.ZodArray<z.ZodString>>>;
8434
+ type: z.ZodOptional<z.ZodNullable<z.ZodEnum<{
8435
+ string: "string";
8436
+ number: "number";
8437
+ boolean: "boolean";
8438
+ enum: "enum";
8439
+ }>>>;
8440
+ }, z.core.$strip>>>>;
8441
+ required: z.ZodOptional<z.ZodNullable<z.ZodArray<z.ZodString>>>;
8442
+ }, z.core.$strip>>>;
8422
8443
  format: z.ZodEnum<{
8423
8444
  text: "text";
8424
8445
  chat: "chat";
@@ -8438,6 +8459,7 @@ export declare const zPromptsCreatePromptVersionResponse: z.ZodObject<{
8438
8459
  code: z.ZodNumber;
8439
8460
  data: z.ZodNullable<z.ZodObject<{
8440
8461
  changelog: z.ZodNullable<z.ZodString>;
8462
+ contextSchema: z.ZodUnknown;
8441
8463
  createdAt: z.ZodISODateTime;
8442
8464
  createdByDisplayName: z.ZodNullable<z.ZodString>;
8443
8465
  createdByImage: z.ZodNullable<z.ZodString>;
@@ -8505,21 +8527,12 @@ export declare const zPromptsGetPromptVersionDiffResponse: z.ZodObject<{
8505
8527
  tool: "tool";
8506
8528
  assistant: "assistant";
8507
8529
  }>;
8530
+ toolCallId: z.ZodOptional<z.ZodNullable<z.ZodString>>;
8508
8531
  toolCalls: z.ZodOptional<z.ZodNullable<z.ZodArray<z.ZodObject<{
8509
8532
  arguments: z.ZodRecord<z.ZodString, z.ZodUnknown>;
8510
8533
  id: z.ZodString;
8511
8534
  name: z.ZodString;
8512
8535
  }, z.core.$strip>>>>;
8513
- toolSchema: z.ZodOptional<z.ZodNullable<z.ZodObject<{
8514
- content: z.ZodOptional<z.ZodNullable<z.ZodString>>;
8515
- description: z.ZodOptional<z.ZodNullable<z.ZodString>>;
8516
- parameters: z.ZodOptional<z.ZodNullable<z.ZodRecord<z.ZodString, z.ZodUnknown>>>;
8517
- toolCallId: z.ZodOptional<z.ZodNullable<z.ZodString>>;
8518
- toolKind: z.ZodOptional<z.ZodNullable<z.ZodEnum<{
8519
- definition: "definition";
8520
- result: "result";
8521
- }>>>;
8522
- }, z.core.$strip>>>;
8523
8536
  }, z.core.$strip>, z.ZodObject<{
8524
8537
  condition: z.ZodObject<{
8525
8538
  kind: z.ZodString;
@@ -8536,21 +8549,12 @@ export declare const zPromptsGetPromptVersionDiffResponse: z.ZodObject<{
8536
8549
  tool: "tool";
8537
8550
  assistant: "assistant";
8538
8551
  }>;
8552
+ toolCallId: z.ZodOptional<z.ZodNullable<z.ZodString>>;
8539
8553
  toolCalls: z.ZodOptional<z.ZodNullable<z.ZodArray<z.ZodObject<{
8540
8554
  arguments: z.ZodRecord<z.ZodString, z.ZodUnknown>;
8541
8555
  id: z.ZodString;
8542
8556
  name: z.ZodString;
8543
8557
  }, z.core.$strip>>>>;
8544
- toolSchema: z.ZodOptional<z.ZodNullable<z.ZodObject<{
8545
- content: z.ZodOptional<z.ZodNullable<z.ZodString>>;
8546
- description: z.ZodOptional<z.ZodNullable<z.ZodString>>;
8547
- parameters: z.ZodOptional<z.ZodNullable<z.ZodRecord<z.ZodString, z.ZodUnknown>>>;
8548
- toolCallId: z.ZodOptional<z.ZodNullable<z.ZodString>>;
8549
- toolKind: z.ZodOptional<z.ZodNullable<z.ZodEnum<{
8550
- definition: "definition";
8551
- result: "result";
8552
- }>>>;
8553
- }, z.core.$strip>>>;
8554
8558
  }, z.core.$strip>, z.ZodObject<{
8555
8559
  after: z.ZodString;
8556
8560
  before: z.ZodString;
@@ -8596,29 +8600,11 @@ export declare const zPromptsGetPromptVersionDiffResponse: z.ZodObject<{
8596
8600
  edit_required: "edit_required";
8597
8601
  }>;
8598
8602
  }, z.core.$strip>, z.ZodObject<{
8599
- after: z.ZodObject<{
8600
- content: z.ZodOptional<z.ZodNullable<z.ZodString>>;
8601
- description: z.ZodOptional<z.ZodNullable<z.ZodString>>;
8602
- parameters: z.ZodOptional<z.ZodNullable<z.ZodRecord<z.ZodString, z.ZodUnknown>>>;
8603
- toolCallId: z.ZodOptional<z.ZodNullable<z.ZodString>>;
8604
- toolKind: z.ZodOptional<z.ZodNullable<z.ZodEnum<{
8605
- definition: "definition";
8606
- result: "result";
8607
- }>>>;
8608
- }, z.core.$strip>;
8609
- before: z.ZodObject<{
8610
- content: z.ZodOptional<z.ZodNullable<z.ZodString>>;
8611
- description: z.ZodOptional<z.ZodNullable<z.ZodString>>;
8612
- parameters: z.ZodOptional<z.ZodNullable<z.ZodRecord<z.ZodString, z.ZodUnknown>>>;
8613
- toolCallId: z.ZodOptional<z.ZodNullable<z.ZodString>>;
8614
- toolKind: z.ZodOptional<z.ZodNullable<z.ZodEnum<{
8615
- definition: "definition";
8616
- result: "result";
8617
- }>>>;
8618
- }, z.core.$strip>;
8603
+ after: z.ZodString;
8604
+ before: z.ZodString;
8619
8605
  name: z.ZodString;
8620
8606
  op: z.ZodEnum<{
8621
- edit_tool_schema: "edit_tool_schema";
8607
+ edit_tool_call_id: "edit_tool_call_id";
8622
8608
  }>;
8623
8609
  }, z.core.$strip>, z.ZodObject<{
8624
8610
  after: z.ZodArray<z.ZodObject<{
@@ -8678,6 +8664,7 @@ export declare const zPromptsGetPromptVersionResponse: z.ZodObject<{
8678
8664
  code: z.ZodNumber;
8679
8665
  data: z.ZodNullable<z.ZodObject<{
8680
8666
  changelog: z.ZodNullable<z.ZodString>;
8667
+ contextSchema: z.ZodUnknown;
8681
8668
  createdAt: z.ZodISODateTime;
8682
8669
  createdByDisplayName: z.ZodNullable<z.ZodString>;
8683
8670
  createdByImage: z.ZodNullable<z.ZodString>;
@@ -8952,6 +8939,13 @@ export declare const zPromptsResolvePromptResponse: z.ZodObject<{
8952
8939
  }, z.core.$strip>]>>;
8953
8940
  }, z.core.$strip>]>;
8954
8941
  subjectHash: z.ZodOptional<z.ZodNullable<z.ZodString>>;
8942
+ toolChoice: z.ZodOptional<z.ZodNullable<z.ZodUnion<readonly [z.ZodEnum<{
8943
+ auto: "auto";
8944
+ none: "none";
8945
+ required: "required";
8946
+ }>, z.ZodObject<{
8947
+ name: z.ZodString;
8948
+ }, z.core.$strip>]>>>;
8955
8949
  tools: z.ZodOptional<z.ZodNullable<z.ZodArray<z.ZodObject<{
8956
8950
  description: z.ZodOptional<z.ZodNullable<z.ZodString>>;
8957
8951
  name: z.ZodString;
@@ -54,7 +54,8 @@ var zResolvedPromptLegacy = import_zod2.zResolvedPrompt.pick({
54
54
  labels: true,
55
55
  contentHash: true,
56
56
  rendered: true,
57
- tools: true
57
+ tools: true,
58
+ toolChoice: true
58
59
  });
59
60
  var zResolvedPromptEnvelope = import_zod2.zResolvedPrompt.partial({ releaseId: true }).extend({ strategy: import_zod.z.enum(["single", "weighted"]).optional() });
60
61
  function unwrap(envelope) {
@@ -88,6 +89,9 @@ function normalizeResolvedEnvelope(raw) {
88
89
  if (raw.tools != null && raw.tools.length > 0) {
89
90
  result.tools = raw.tools;
90
91
  }
92
+ if (raw.toolChoice != null) {
93
+ result.toolChoice = raw.toolChoice;
94
+ }
91
95
  if (typeof provenance.variantName === "string" && provenance.variantName.length > 0) {
92
96
  result.variantName = provenance.variantName;
93
97
  }
@@ -2,7 +2,7 @@ import type { Transport } from "../transport";
2
2
  import type { CacheConfig } from "./cache";
3
3
  import type { ArchivePromptInput, ArchivePromptResult, CreateProjectPromptLabelInput, CreateProjectPromptLabelResult, CreatePromptInput, CreatePromptResult, CreatePromptVersionInput, CreatePromptVersionResult, DeleteProjectPromptLabelInput, DeleteProjectPromptLabelResult, FetchedPrompt, FetchPromptOptions, GetProjectPromptLabelInput, GetProjectPromptLabelResult, GetPromptInput, GetPromptResult, GetPromptVersionInput, GetPromptVersionResult, ListLabelEventsInput, ListLabelEventsResult, ListProjectPromptLabelsInput, ListProjectPromptLabelsResult, ListProjectPromptLabelUsagesInput, ListProjectPromptLabelUsagesResult, ListPromptLabelsInput, ListPromptLabelsResult, ListPromptsInput, ListPromptsResult, ListPromptVersionsInput, ListPromptVersionsResult, MovePromptLabelInput, MovePromptLabelResult, PaginatedResult, ResolvePromptInput, ResolvePromptResult, UpdateProjectPromptLabelInput, UpdateProjectPromptLabelResult, UpdatePromptInput, UpdatePromptResult } from "./types";
4
4
  export type { CacheConfig } from "./cache";
5
- export type { ArchivePromptInput, ArchivePromptResult, BlockRenderRecord, ChatMessage, CreateProjectPromptLabelInput, CreateProjectPromptLabelResult, CreatePromptInput, CreatePromptResult, CreatePromptVersionInput, CreatePromptVersionResult, DeleteProjectPromptLabelInput, DeleteProjectPromptLabelResult, FetchedPrompt, FetchPromptOptions, GetProjectPromptLabelInput, GetProjectPromptLabelResult, GetPromptInput, GetPromptResult, GetPromptVersionInput, GetPromptVersionResult, ListLabelEventsInput, ListLabelEventsResult, ListProjectPromptLabelsInput, ListProjectPromptLabelsResult, ListProjectPromptLabelUsagesInput, ListProjectPromptLabelUsagesResult, ListPromptLabelsInput, ListPromptLabelsResult, ListPromptsInput, ListPromptsResult, ListPromptVersionsInput, ListPromptVersionsResult, MovePromptLabelInput, MovePromptLabelResult, PaginatedResult, PaginationInfo, PaletteToken, ProjectPromptLabel, ProjectPromptLabelUsage, Prompt, PromptContext, PromptFormat, PromptLabelEvent, PromptLabelPointer, PromptStatus, PromptVersion, RenderedChatMessage, RenderedPrompt, ResolvedPrompt, ResolvedPromptEnvelope, ResolvedToolCall, ResolvedToolDefinition, ResolvePromptInput, ResolvePromptResult, RowError, TextChatMessage, TextChatRole, ToolChatMessage, UpdateProjectPromptLabelInput, UpdateProjectPromptLabelResult, UpdatePromptInput, UpdatePromptResult, } from "./types";
5
+ export type { ArchivePromptInput, ArchivePromptResult, BlockRenderRecord, ChatMessage, CreateProjectPromptLabelInput, CreateProjectPromptLabelResult, CreatePromptInput, CreatePromptResult, CreatePromptVersionInput, CreatePromptVersionResult, DeleteProjectPromptLabelInput, DeleteProjectPromptLabelResult, FetchedPrompt, FetchPromptOptions, GetProjectPromptLabelInput, GetProjectPromptLabelResult, GetPromptInput, GetPromptResult, GetPromptVersionInput, GetPromptVersionResult, ListLabelEventsInput, ListLabelEventsResult, ListProjectPromptLabelsInput, ListProjectPromptLabelsResult, ListProjectPromptLabelUsagesInput, ListProjectPromptLabelUsagesResult, ListPromptLabelsInput, ListPromptLabelsResult, ListPromptsInput, ListPromptsResult, ListPromptVersionsInput, ListPromptVersionsResult, MovePromptLabelInput, MovePromptLabelResult, PaginatedResult, PaginationInfo, PaletteToken, ProjectPromptLabel, ProjectPromptLabelUsage, Prompt, PromptContext, PromptFormat, PromptLabelEvent, PromptLabelPointer, PromptStatus, PromptVersion, RenderedChatMessage, RenderedPrompt, ResolvedPrompt, ResolvedPromptEnvelope, ResolvedToolCall, ResolvedToolDefinition, ResolvePromptInput, ResolvePromptResult, RowError, TextChatMessage, TextChatRole, UpdateProjectPromptLabelInput, UpdateProjectPromptLabelResult, UpdatePromptInput, UpdatePromptResult, } from "./types";
6
6
  /**
7
7
  * Init-time config for the env-aware `fetch()` surface (TO11-980 / S9).
8
8
  *
@@ -11,7 +11,8 @@ var zResolvedPromptLegacy = zResolvedPrompt.pick({
11
11
  labels: true,
12
12
  contentHash: true,
13
13
  rendered: true,
14
- tools: true
14
+ tools: true,
15
+ toolChoice: true
15
16
  });
16
17
  var zResolvedPromptEnvelope = zResolvedPrompt.partial({ releaseId: true }).extend({ strategy: z.enum(["single", "weighted"]).optional() });
17
18
  function unwrap(envelope) {
@@ -45,6 +46,9 @@ function normalizeResolvedEnvelope(raw) {
45
46
  if (raw.tools != null && raw.tools.length > 0) {
46
47
  result.tools = raw.tools;
47
48
  }
49
+ if (raw.toolChoice != null) {
50
+ result.toolChoice = raw.toolChoice;
51
+ }
48
52
  if (typeof provenance.variantName === "string" && provenance.variantName.length > 0) {
49
53
  result.variantName = provenance.variantName;
50
54
  }
@@ -15,14 +15,7 @@ export interface TextChatMessage {
15
15
  content: string;
16
16
  disabled?: boolean;
17
17
  }
18
- export interface ToolChatMessage {
19
- role: "tool";
20
- name: string;
21
- description?: string;
22
- parameters: unknown;
23
- disabled?: boolean;
24
- }
25
- export type ChatMessage = TextChatMessage | ToolChatMessage;
18
+ export type ChatMessage = TextChatMessage;
26
19
  export type RenderedChatMessage = GenRenderedChatPrompt["messages"][number];
27
20
  export type RenderedPrompt = GenRenderedPrompt;
28
21
  /**
@@ -36,7 +29,7 @@ export type ResolvedToolDefinition = GenResolvedToolDefinition;
36
29
  * on a rendered `assistant` turn (few-shot multi-tool history).
37
30
  */
38
31
  export type ResolvedToolCall = GenResolvedToolCall;
39
- export type ResolvedPrompt = Pick<GenResolvedPrompt, "promptId" | "versionId" | "version" | "labels" | "contentHash" | "rendered" | "tools">;
32
+ export type ResolvedPrompt = Pick<GenResolvedPrompt, "promptId" | "versionId" | "version" | "labels" | "contentHash" | "rendered" | "tools" | "toolChoice">;
40
33
  export interface PaginationInfo {
41
34
  page: number;
42
35
  limit: number;
@@ -88,6 +81,7 @@ export interface CreatePromptVersionInput {
88
81
  format: PromptFormat;
89
82
  templateJson: unknown;
90
83
  variablesSchema: unknown;
84
+ contextSchema?: unknown;
91
85
  modelConfig?: unknown;
92
86
  changelog?: string;
93
87
  }
@@ -147,6 +141,16 @@ export interface FetchedPrompt {
147
141
  * tools. Shape for a provider with `toOpenAITools` / `toAnthropicTools`.
148
142
  */
149
143
  tools?: ResolvedToolDefinition[];
144
+ /**
145
+ * Provider-neutral tool-choice directive lifted from the resolved version.
146
+ * Absent (rather than `null`) when the version declares none. Feed straight
147
+ * into `toOpenAIToolChoice` / `toAnthropicToolChoice`.
148
+ *
149
+ * `NonNullable` because `normalizeResolvedEnvelope` maps wire-`null` to absent,
150
+ * so a present `FetchedPrompt.toolChoice` is never `null` — callers get the
151
+ * key or nothing, and never have to branch on `null`.
152
+ */
153
+ toolChoice?: NonNullable<ResolvedPrompt["toolChoice"]>;
150
154
  }
151
155
  export type ResolvedPromptEnvelope = GenResolvedPrompt & {
152
156
  /** Active release strategy. Used to decide weighted-no-subject cache bypass (D8). */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@to11ai/sdk",
3
- "version": "0.7.0",
3
+ "version": "0.8.1",
4
4
  "license": "MPL-2.0",
5
5
  "repository": {
6
6
  "type": "git",
package/src/gateway.ts CHANGED
@@ -138,6 +138,13 @@ export interface OpenAITool {
138
138
  };
139
139
  }
140
140
 
141
+ /** OpenAI `tool_choice` value for a Chat Completions request. */
142
+ export type OpenAIToolChoice =
143
+ | "auto"
144
+ | "none"
145
+ | "required"
146
+ | { type: "function"; function: { name: string } };
147
+
141
148
  /** OpenAI Chat Completions assistant `tool_calls[]` entry. */
142
149
  export interface OpenAIToolCall {
143
150
  id: string;
@@ -177,6 +184,13 @@ export interface AnthropicMessage {
177
184
  content: string | AnthropicContentBlock[];
178
185
  }
179
186
 
187
+ /** Anthropic Messages `tool_choice` value. */
188
+ export type AnthropicToolChoice =
189
+ | { type: "auto" }
190
+ | { type: "any" }
191
+ | { type: "none" }
192
+ | { type: "tool"; name: string };
193
+
180
194
  /**
181
195
  * Shape resolved tool definitions for the OpenAI Chat Completions `tools`
182
196
  * field: `{ type: "function", function: { name, description?, parameters } }`.
@@ -186,7 +200,8 @@ export interface AnthropicMessage {
186
200
  *
187
201
  * @example
188
202
  * const tools = toOpenAITools(prompt.tools);
189
- * await openai.chat.completions.create({ model, messages, tools });
203
+ * const tool_choice = toOpenAIToolChoice(prompt.toolChoice);
204
+ * await openai.chat.completions.create({ model, messages, tools, tool_choice });
190
205
  */
191
206
  export function toOpenAITools(
192
207
  tools: ReadonlyArray<ResolvedToolDefinition> | null | undefined,
@@ -204,6 +219,27 @@ export function toOpenAITools(
204
219
  });
205
220
  }
206
221
 
222
+ /**
223
+ * Map a resolved prompt's provider-neutral `toolChoice` to the OpenAI
224
+ * Chat Completions `tool_choice` field.
225
+ *
226
+ * - `null` / `undefined` → `undefined` (omit the field)
227
+ * - `"auto"` → `"auto"`, `"none"` → `"none"`, `"required"` → `"required"`
228
+ * - `{ name }` → `{ type: "function", function: { name } }`
229
+ *
230
+ * @example
231
+ * const tools = toOpenAITools(prompt.tools);
232
+ * const tool_choice = toOpenAIToolChoice(prompt.toolChoice);
233
+ * await openai.chat.completions.create({ model, messages, tools, tool_choice });
234
+ */
235
+ export function toOpenAIToolChoice(
236
+ toolChoice: ResolvedPrompt["toolChoice"],
237
+ ): OpenAIToolChoice | undefined {
238
+ if (toolChoice == null) return undefined;
239
+ if (typeof toolChoice === "string") return toolChoice;
240
+ return { type: "function", function: { name: toolChoice.name } };
241
+ }
242
+
207
243
  /**
208
244
  * Shape resolved tool definitions for the Anthropic Messages `tools` field:
209
245
  * `{ name, description?, input_schema }` (Anthropic names the JSON Schema field
@@ -211,7 +247,8 @@ export function toOpenAITools(
211
247
  *
212
248
  * @example
213
249
  * const tools = toAnthropicTools(prompt.tools);
214
- * await anthropic.messages.create({ model, system, messages, tools });
250
+ * const tool_choice = toAnthropicToolChoice(prompt.toolChoice);
251
+ * await anthropic.messages.create({ model, system, messages, tools, tool_choice });
215
252
  */
216
253
  export function toAnthropicTools(
217
254
  tools: ReadonlyArray<ResolvedToolDefinition> | null | undefined,
@@ -229,6 +266,31 @@ export function toAnthropicTools(
229
266
  });
230
267
  }
231
268
 
269
+ /**
270
+ * Map a resolved prompt's provider-neutral `toolChoice` to the Anthropic
271
+ * Messages `tool_choice` field.
272
+ *
273
+ * - `null` / `undefined` → `undefined` (omit the field)
274
+ * - `"auto"` → `{ type: "auto" }`
275
+ * - `"none"` → `{ type: "none" }` (the Anthropic API supports this natively)
276
+ * - `"required"` → `{ type: "any" }` (Anthropic's name for "must invoke a tool")
277
+ * - `{ name }` → `{ type: "tool", name }`
278
+ *
279
+ * @example
280
+ * const tools = toAnthropicTools(prompt.tools);
281
+ * const tool_choice = toAnthropicToolChoice(prompt.toolChoice);
282
+ * await anthropic.messages.create({ model, system, messages, tools, tool_choice });
283
+ */
284
+ export function toAnthropicToolChoice(
285
+ toolChoice: ResolvedPrompt["toolChoice"],
286
+ ): AnthropicToolChoice | undefined {
287
+ if (toolChoice == null) return undefined;
288
+ if (toolChoice === "auto") return { type: "auto" };
289
+ if (toolChoice === "none") return { type: "none" };
290
+ if (toolChoice === "required") return { type: "any" };
291
+ return { type: "tool", name: toolChoice.name };
292
+ }
293
+
232
294
  /**
233
295
  * Guard a tool-call linkage id before it is serialized into a provider payload.
234
296
  * A missing/empty id means malformed tool history (an assistant tool call or a
@@ -254,6 +254,7 @@ export type PromptRelease = {
254
254
 
255
255
  export type PromptVersion = {
256
256
  changelog: string | null;
257
+ contextSchema: unknown;
257
258
  createdAt: string;
258
259
  createdByDisplayName: string | null;
259
260
  createdByImage: string | null;
@@ -308,6 +309,9 @@ export type ResolvedPrompt = {
308
309
  releaseId: string;
309
310
  rendered: RenderedPrompt;
310
311
  subjectHash?: string | null;
312
+ toolChoice?: 'auto' | 'none' | 'required' | {
313
+ name: string;
314
+ } | null;
311
315
  tools?: Array<ResolvedToolDefinition> | null;
312
316
  variantName?: string | null;
313
317
  version: number;
@@ -15310,6 +15314,15 @@ export type PromptsCreatePromptVersionData = {
15310
15314
  allowBlockRemovals?: Array<string> | null;
15311
15315
  baseVersionId?: string | null;
15312
15316
  changelog?: string | null;
15317
+ contextSchema?: {
15318
+ properties?: {
15319
+ [key: string]: {
15320
+ enum?: Array<string> | null;
15321
+ type?: 'string' | 'number' | 'boolean' | 'enum' | null;
15322
+ };
15323
+ } | null;
15324
+ required?: Array<string> | null;
15325
+ } | null;
15313
15326
  format: 'text' | 'chat';
15314
15327
  modelConfig?: unknown | null;
15315
15328
  templateJson: unknown;
@@ -15484,6 +15497,7 @@ export type PromptsGetPromptVersionDiffResponses = {
15484
15497
  name: string;
15485
15498
  op: 'add';
15486
15499
  role: 'system' | 'user' | 'assistant' | 'developer' | 'tool';
15500
+ toolCallId?: string | null;
15487
15501
  toolCalls?: Array<{
15488
15502
  arguments: {
15489
15503
  [key: string]: unknown;
@@ -15491,15 +15505,6 @@ export type PromptsGetPromptVersionDiffResponses = {
15491
15505
  id: string;
15492
15506
  name: string;
15493
15507
  }> | null;
15494
- toolSchema?: {
15495
- content?: string | null;
15496
- description?: string | null;
15497
- parameters?: {
15498
- [key: string]: unknown;
15499
- } | null;
15500
- toolCallId?: string | null;
15501
- toolKind?: 'definition' | 'result' | null;
15502
- } | null;
15503
15508
  } | {
15504
15509
  condition: {
15505
15510
  kind: string;
@@ -15508,6 +15513,7 @@ export type PromptsGetPromptVersionDiffResponses = {
15508
15513
  name: string;
15509
15514
  op: 'remove';
15510
15515
  role: 'system' | 'user' | 'assistant' | 'developer' | 'tool';
15516
+ toolCallId?: string | null;
15511
15517
  toolCalls?: Array<{
15512
15518
  arguments: {
15513
15519
  [key: string]: unknown;
@@ -15515,15 +15521,6 @@ export type PromptsGetPromptVersionDiffResponses = {
15515
15521
  id: string;
15516
15522
  name: string;
15517
15523
  }> | null;
15518
- toolSchema?: {
15519
- content?: string | null;
15520
- description?: string | null;
15521
- parameters?: {
15522
- [key: string]: unknown;
15523
- } | null;
15524
- toolCallId?: string | null;
15525
- toolKind?: 'definition' | 'result' | null;
15526
- } | null;
15527
15524
  } | {
15528
15525
  after: string;
15529
15526
  before: string;
@@ -15549,26 +15546,10 @@ export type PromptsGetPromptVersionDiffResponses = {
15549
15546
  name: string;
15550
15547
  op: 'edit_required';
15551
15548
  } | {
15552
- after: {
15553
- content?: string | null;
15554
- description?: string | null;
15555
- parameters?: {
15556
- [key: string]: unknown;
15557
- } | null;
15558
- toolCallId?: string | null;
15559
- toolKind?: 'definition' | 'result' | null;
15560
- };
15561
- before: {
15562
- content?: string | null;
15563
- description?: string | null;
15564
- parameters?: {
15565
- [key: string]: unknown;
15566
- } | null;
15567
- toolCallId?: string | null;
15568
- toolKind?: 'definition' | 'result' | null;
15569
- };
15549
+ after: string;
15550
+ before: string;
15570
15551
  name: string;
15571
- op: 'edit_tool_schema';
15552
+ op: 'edit_tool_call_id';
15572
15553
  } | {
15573
15554
  after: Array<{
15574
15555
  arguments: {
@@ -280,6 +280,7 @@ export const zPromptRelease = z.object({
280
280
 
281
281
  export const zPromptVersion = z.object({
282
282
  changelog: z.string().nullable(),
283
+ contextSchema: z.unknown(),
283
284
  createdAt: z.iso.datetime(),
284
285
  createdByDisplayName: z.string().nullable(),
285
286
  createdByImage: z.string().nullable(),
@@ -355,6 +356,16 @@ export const zResolvedPrompt = z.object({
355
356
  releaseId: z.string(),
356
357
  rendered: zRenderedPrompt,
357
358
  subjectHash: z.string().nullish(),
359
+ toolChoice: z.union([
360
+ z.enum([
361
+ 'auto',
362
+ 'none',
363
+ 'required'
364
+ ]),
365
+ z.object({
366
+ name: z.string().min(1)
367
+ })
368
+ ]).nullish(),
358
369
  tools: z.array(zResolvedToolDefinition).nullish(),
359
370
  variantName: z.string().nullish(),
360
371
  version: z.number(),
@@ -7883,6 +7894,18 @@ export const zPromptsCreatePromptVersionBody = z.object({
7883
7894
  allowBlockRemovals: z.array(z.string()).nullish(),
7884
7895
  baseVersionId: z.string().nullish(),
7885
7896
  changelog: z.string().nullish(),
7897
+ contextSchema: z.object({
7898
+ properties: z.record(z.string(), z.object({
7899
+ enum: z.array(z.string()).nullish(),
7900
+ type: z.enum([
7901
+ 'string',
7902
+ 'number',
7903
+ 'boolean',
7904
+ 'enum'
7905
+ ]).nullish()
7906
+ })).nullish(),
7907
+ required: z.array(z.string()).nullish()
7908
+ }).nullish(),
7886
7909
  format: z.enum(['text', 'chat']),
7887
7910
  modelConfig: z.unknown().nullish(),
7888
7911
  templateJson: z.unknown(),
@@ -7954,18 +7977,12 @@ export const zPromptsGetPromptVersionDiffResponse = z.object({
7954
7977
  'developer',
7955
7978
  'tool'
7956
7979
  ]),
7980
+ toolCallId: z.string().nullish(),
7957
7981
  toolCalls: z.array(z.object({
7958
7982
  arguments: z.record(z.string(), z.unknown()),
7959
7983
  id: z.string(),
7960
7984
  name: z.string()
7961
- })).nullish(),
7962
- toolSchema: z.object({
7963
- content: z.string().nullish(),
7964
- description: z.string().nullish(),
7965
- parameters: z.record(z.string(), z.unknown()).nullish(),
7966
- toolCallId: z.string().nullish(),
7967
- toolKind: z.enum(['definition', 'result']).nullish()
7968
- }).nullish()
7985
+ })).nullish()
7969
7986
  }),
7970
7987
  z.object({
7971
7988
  condition: z.object({
@@ -7981,18 +7998,12 @@ export const zPromptsGetPromptVersionDiffResponse = z.object({
7981
7998
  'developer',
7982
7999
  'tool'
7983
8000
  ]),
8001
+ toolCallId: z.string().nullish(),
7984
8002
  toolCalls: z.array(z.object({
7985
8003
  arguments: z.record(z.string(), z.unknown()),
7986
8004
  id: z.string(),
7987
8005
  name: z.string()
7988
- })).nullish(),
7989
- toolSchema: z.object({
7990
- content: z.string().nullish(),
7991
- description: z.string().nullish(),
7992
- parameters: z.record(z.string(), z.unknown()).nullish(),
7993
- toolCallId: z.string().nullish(),
7994
- toolKind: z.enum(['definition', 'result']).nullish()
7995
- }).nullish()
8006
+ })).nullish()
7996
8007
  }),
7997
8008
  z.object({
7998
8009
  after: z.string(),
@@ -8035,22 +8046,10 @@ export const zPromptsGetPromptVersionDiffResponse = z.object({
8035
8046
  op: z.enum(['edit_required'])
8036
8047
  }),
8037
8048
  z.object({
8038
- after: z.object({
8039
- content: z.string().nullish(),
8040
- description: z.string().nullish(),
8041
- parameters: z.record(z.string(), z.unknown()).nullish(),
8042
- toolCallId: z.string().nullish(),
8043
- toolKind: z.enum(['definition', 'result']).nullish()
8044
- }),
8045
- before: z.object({
8046
- content: z.string().nullish(),
8047
- description: z.string().nullish(),
8048
- parameters: z.record(z.string(), z.unknown()).nullish(),
8049
- toolCallId: z.string().nullish(),
8050
- toolKind: z.enum(['definition', 'result']).nullish()
8051
- }),
8049
+ after: z.string(),
8050
+ before: z.string(),
8052
8051
  name: z.string(),
8053
- op: z.enum(['edit_tool_schema'])
8052
+ op: z.enum(['edit_tool_call_id'])
8054
8053
  }),
8055
8054
  z.object({
8056
8055
  after: z.array(z.object({
@@ -111,7 +111,6 @@ export type {
111
111
  RowError,
112
112
  TextChatMessage,
113
113
  TextChatRole,
114
- ToolChatMessage,
115
114
  UpdateProjectPromptLabelInput,
116
115
  UpdateProjectPromptLabelResult,
117
116
  UpdatePromptInput,
@@ -126,6 +125,7 @@ const zResolvedPromptLegacy = zResolvedPrompt.pick({
126
125
  contentHash: true,
127
126
  rendered: true,
128
127
  tools: true,
128
+ toolChoice: true,
129
129
  });
130
130
 
131
131
  const zResolvedPromptEnvelope = zResolvedPrompt
@@ -187,6 +187,13 @@ function normalizeResolvedEnvelope(
187
187
  if (raw.tools != null && raw.tools.length > 0) {
188
188
  result.tools = raw.tools;
189
189
  }
190
+ // `toolChoice` mirrors `tools`: present IFF the resolved version declares a
191
+ // directive. The wire may send `null` (or omit it); normalize both to absent
192
+ // so callers feed `toOpenAIToolChoice` / `toAnthropicToolChoice` (which map
193
+ // `null`/`undefined` → omit) without a separate guard.
194
+ if (raw.toolChoice != null) {
195
+ result.toolChoice = raw.toolChoice;
196
+ }
190
197
  // Set `variantName` only when it is a non-empty string, so the key is
191
198
  // genuinely absent for `single`-strategy releases (R5: present IFF weighted —
192
199
  // never `null`, never `""`). A `null`/`""` from the wire is normalized to
@@ -32,15 +32,7 @@ export interface TextChatMessage {
32
32
  disabled?: boolean;
33
33
  }
34
34
 
35
- export interface ToolChatMessage {
36
- role: "tool";
37
- name: string;
38
- description?: string;
39
- parameters: unknown;
40
- disabled?: boolean;
41
- }
42
-
43
- export type ChatMessage = TextChatMessage | ToolChatMessage;
35
+ export type ChatMessage = TextChatMessage;
44
36
 
45
37
  export type RenderedChatMessage = GenRenderedChatPrompt["messages"][number];
46
38
 
@@ -68,6 +60,7 @@ export type ResolvedPrompt = Pick<
68
60
  | "contentHash"
69
61
  | "rendered"
70
62
  | "tools"
63
+ | "toolChoice"
71
64
  >;
72
65
 
73
66
  export interface PaginationInfo {
@@ -133,6 +126,9 @@ export interface CreatePromptVersionInput {
133
126
  format: PromptFormat;
134
127
  templateJson: unknown;
135
128
  variablesSchema: unknown;
129
+ // TO11-2609: server-trusted, gating-only context schema (scalar/enum keys).
130
+ // Optional on write; omitted → no context keys.
131
+ contextSchema?: unknown;
136
132
  modelConfig?: unknown;
137
133
  changelog?: string;
138
134
  }
@@ -207,6 +203,16 @@ export interface FetchedPrompt {
207
203
  * tools. Shape for a provider with `toOpenAITools` / `toAnthropicTools`.
208
204
  */
209
205
  tools?: ResolvedToolDefinition[];
206
+ /**
207
+ * Provider-neutral tool-choice directive lifted from the resolved version.
208
+ * Absent (rather than `null`) when the version declares none. Feed straight
209
+ * into `toOpenAIToolChoice` / `toAnthropicToolChoice`.
210
+ *
211
+ * `NonNullable` because `normalizeResolvedEnvelope` maps wire-`null` to absent,
212
+ * so a present `FetchedPrompt.toolChoice` is never `null` — callers get the
213
+ * key or nothing, and never have to branch on `null`.
214
+ */
215
+ toolChoice?: NonNullable<ResolvedPrompt["toolChoice"]>;
210
216
  }
211
217
 
212
218
  export type ResolvedPromptEnvelope = GenResolvedPrompt & {