@opencode/ai 0.0.0-dev-1302 → 0.0.0-dev-1304

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.
Files changed (52) hide show
  1. package/dist/cache-policy.js +4 -2
  2. package/dist/llm.d.ts +4 -1
  3. package/dist/llm.js +10 -1
  4. package/dist/protocols/alibaba-messages.d.ts +24 -2
  5. package/dist/protocols/alibaba-responses.d.ts +26 -0
  6. package/dist/protocols/anthropic-messages.d.ts +70 -6
  7. package/dist/protocols/anthropic-messages.js +74 -9
  8. package/dist/protocols/meta-messages.d.ts +24 -2
  9. package/dist/protocols/meta-responses.d.ts +52 -0
  10. package/dist/protocols/open-responses.d.ts +250 -24
  11. package/dist/protocols/open-responses.js +40 -24
  12. package/dist/protocols/openai-compatible-responses.d.ts +26 -0
  13. package/dist/protocols/openai-freeform.d.ts +1 -1
  14. package/dist/protocols/openai-freeform.js +9 -5
  15. package/dist/protocols/openai-responses.d.ts +153 -0
  16. package/dist/protocols/openai-responses.js +68 -7
  17. package/dist/protocols/utils/gateway-protocol.js +1 -0
  18. package/dist/protocols/utils/responses-compaction.js +7 -3
  19. package/dist/protocols/xai-responses.d.ts +26 -0
  20. package/dist/protocols/zai-messages.d.ts +24 -2
  21. package/dist/providers/alibaba.d.ts +50 -2
  22. package/dist/providers/amazon-bedrock-mantle.d.ts +50 -2
  23. package/dist/providers/anthropic-compatible.d.ts +24 -2
  24. package/dist/providers/anthropic.d.ts +24 -2
  25. package/dist/providers/azure.d.ts +76 -2
  26. package/dist/providers/cloudflare-ai-gateway.d.ts +100 -4
  27. package/dist/providers/digitalocean.d.ts +26 -0
  28. package/dist/providers/google-vertex-messages.d.ts +24 -2
  29. package/dist/providers/google-vertex-messages.js +1 -0
  30. package/dist/providers/google-vertex-responses.d.ts +26 -0
  31. package/dist/providers/meta.d.ts +50 -2
  32. package/dist/providers/minimax.d.ts +50 -2
  33. package/dist/providers/moonshot.d.ts +50 -2
  34. package/dist/providers/openai-compatible-responses.d.ts +26 -0
  35. package/dist/providers/openai.d.ts +26 -0
  36. package/dist/providers/openrouter.d.ts +26 -0
  37. package/dist/providers/venice.d.ts +26 -0
  38. package/dist/providers/zai-coding-plan.d.ts +50 -2
  39. package/dist/public.d.ts +2 -2
  40. package/dist/public.js +1 -1
  41. package/dist/route/client.d.ts +2 -0
  42. package/dist/route/client.js +5 -1
  43. package/dist/route/protocol.d.ts +3 -0
  44. package/dist/schema/events.d.ts +5 -0
  45. package/dist/schema/messages.d.ts +24 -1
  46. package/dist/schema/messages.js +26 -2
  47. package/dist/schema/options.d.ts +10 -2
  48. package/dist/tool-updates.d.ts +34 -0
  49. package/dist/tool-updates.js +93 -0
  50. package/dist/tool.d.ts +6 -1
  51. package/dist/tool.js +1 -1
  52. package/package.json +3 -3
@@ -1,7 +1,7 @@
1
1
  import { Effect, Schema } from "effect";
2
2
  import { HttpTransport } from "../route/transport/index.js";
3
3
  import { Protocol } from "../route/protocol.js";
4
- import { AIError, LLMEvent, Usage, type LLMRequest, type MediaPart, type ProviderMetadata, type ToolDefinition } from "../schema/index.js";
4
+ import { AIError, LLMEvent, Usage, type LLMRequest, type MediaPart, type ProviderMetadata, type ToolChanges, type ToolDefinition } from "../schema/index.js";
5
5
  import type { Media } from "../media.js";
6
6
  import { OpenResponsesOptions } from "./utils/open-responses-options.js";
7
7
  import { Lifecycle } from "./utils/lifecycle.js";
@@ -105,6 +105,53 @@ export declare const HostedToolReplay: Schema.StructWithRest<Schema.Struct<{
105
105
  readonly id: Schema.String;
106
106
  }>, readonly [Schema.$Record<Schema.String, Schema.Unknown>]>;
107
107
  export type HostedToolReplayItem = Schema.Schema.Type<typeof HostedToolReplay>;
108
+ export declare const Tool: Schema.Struct<{
109
+ readonly type: Schema.tag<"function">;
110
+ readonly name: Schema.String;
111
+ readonly description: Schema.String;
112
+ readonly parameters: Schema.$Record<Schema.String, Schema.Unknown>;
113
+ readonly strict: Schema.optional<Schema.Boolean>;
114
+ }>;
115
+ export declare const CustomTool: Schema.Struct<{
116
+ readonly type: Schema.tag<"custom">;
117
+ readonly name: Schema.String;
118
+ readonly description: Schema.String;
119
+ readonly format: Schema.Union<readonly [Schema.Struct<{
120
+ readonly type: Schema.tag<"text">;
121
+ }>, Schema.Struct<{
122
+ readonly type: Schema.tag<"grammar">;
123
+ readonly syntax: Schema.Literals<readonly ["lark", "regex"]>;
124
+ readonly definition: Schema.String;
125
+ }>]>;
126
+ }>;
127
+ export declare const HostedTool: Schema.StructWithRest<Schema.Struct<{
128
+ readonly type: Schema.String;
129
+ }>, readonly [Schema.$Record<Schema.String, Schema.Unknown>]>;
130
+ export type HostedTool = Schema.Schema.Type<typeof HostedTool>;
131
+ export declare const AdditionalTools: Schema.Struct<{
132
+ readonly type: Schema.Literal<"additional_tools">;
133
+ readonly role: Schema.Literal<"developer">;
134
+ readonly tools: Schema.$Array<Schema.Union<readonly [Schema.Struct<{
135
+ readonly type: Schema.tag<"function">;
136
+ readonly name: Schema.String;
137
+ readonly description: Schema.String;
138
+ readonly parameters: Schema.$Record<Schema.String, Schema.Unknown>;
139
+ readonly strict: Schema.optional<Schema.Boolean>;
140
+ }>, Schema.Struct<{
141
+ readonly type: Schema.tag<"custom">;
142
+ readonly name: Schema.String;
143
+ readonly description: Schema.String;
144
+ readonly format: Schema.Union<readonly [Schema.Struct<{
145
+ readonly type: Schema.tag<"text">;
146
+ }>, Schema.Struct<{
147
+ readonly type: Schema.tag<"grammar">;
148
+ readonly syntax: Schema.Literals<readonly ["lark", "regex"]>;
149
+ readonly definition: Schema.String;
150
+ }>]>;
151
+ }>, Schema.StructWithRest<Schema.Struct<{
152
+ readonly type: Schema.String;
153
+ }>, readonly [Schema.$Record<Schema.String, Schema.Unknown>]>]>>;
154
+ }>;
108
155
  export declare const InputItem: Schema.Union<readonly [Schema.Struct<{
109
156
  readonly type: Schema.Literal<"compaction">;
110
157
  readonly id: Schema.optional<Schema.NullOr<Schema.String>>;
@@ -114,6 +161,29 @@ export declare const InputItem: Schema.Union<readonly [Schema.Struct<{
114
161
  readonly reasoning: Schema.Struct<{
115
162
  readonly effort: Schema.declare<OpenResponsesOptions.ReasoningEffort, OpenResponsesOptions.ReasoningEffort>;
116
163
  }>;
164
+ }>, Schema.Struct<{
165
+ readonly type: Schema.Literal<"additional_tools">;
166
+ readonly role: Schema.Literal<"developer">;
167
+ readonly tools: Schema.$Array<Schema.Union<readonly [Schema.Struct<{
168
+ readonly type: Schema.tag<"function">;
169
+ readonly name: Schema.String;
170
+ readonly description: Schema.String;
171
+ readonly parameters: Schema.$Record<Schema.String, Schema.Unknown>;
172
+ readonly strict: Schema.optional<Schema.Boolean>;
173
+ }>, Schema.Struct<{
174
+ readonly type: Schema.tag<"custom">;
175
+ readonly name: Schema.String;
176
+ readonly description: Schema.String;
177
+ readonly format: Schema.Union<readonly [Schema.Struct<{
178
+ readonly type: Schema.tag<"text">;
179
+ }>, Schema.Struct<{
180
+ readonly type: Schema.tag<"grammar">;
181
+ readonly syntax: Schema.Literals<readonly ["lark", "regex"]>;
182
+ readonly definition: Schema.String;
183
+ }>]>;
184
+ }>, Schema.StructWithRest<Schema.Struct<{
185
+ readonly type: Schema.String;
186
+ }>, readonly [Schema.$Record<Schema.String, Schema.Unknown>]>]>>;
117
187
  }>, Schema.Struct<{
118
188
  readonly type: Schema.tag<"message">;
119
189
  readonly role: Schema.tag<"system">;
@@ -226,29 +296,7 @@ export declare const InputItem: Schema.Union<readonly [Schema.Struct<{
226
296
  readonly type: Schema.String;
227
297
  readonly id: Schema.String;
228
298
  }>, readonly [Schema.$Record<Schema.String, Schema.Unknown>]>]>;
229
- export declare const Tool: Schema.Struct<{
230
- readonly type: Schema.tag<"function">;
231
- readonly name: Schema.String;
232
- readonly description: Schema.String;
233
- readonly parameters: Schema.$Record<Schema.String, Schema.Unknown>;
234
- readonly strict: Schema.optional<Schema.Boolean>;
235
- }>;
236
- export declare const CustomTool: Schema.Struct<{
237
- readonly type: Schema.tag<"custom">;
238
- readonly name: Schema.String;
239
- readonly description: Schema.String;
240
- readonly format: Schema.Union<readonly [Schema.Struct<{
241
- readonly type: Schema.tag<"text">;
242
- }>, Schema.Struct<{
243
- readonly type: Schema.tag<"grammar">;
244
- readonly syntax: Schema.Literals<readonly ["lark", "regex"]>;
245
- readonly definition: Schema.String;
246
- }>]>;
247
- }>;
248
- export declare const HostedTool: Schema.StructWithRest<Schema.Struct<{
249
- readonly type: Schema.String;
250
- }>, readonly [Schema.$Record<Schema.String, Schema.Unknown>]>;
251
- export type HostedTool = Schema.Schema.Type<typeof HostedTool>;
299
+ type OpenResponsesInputItem = Schema.Schema.Type<typeof InputItem>;
252
300
  export declare const ToolChoice: Schema.Union<readonly [Schema.Literals<readonly ["auto", "none", "required"]>, Schema.Struct<{
253
301
  readonly type: Schema.Literals<readonly ["function", "custom"]>;
254
302
  readonly name: Schema.String;
@@ -271,6 +319,29 @@ export declare const coreFields: {
271
319
  readonly reasoning: Schema.Struct<{
272
320
  readonly effort: Schema.declare<OpenResponsesOptions.ReasoningEffort, OpenResponsesOptions.ReasoningEffort>;
273
321
  }>;
322
+ }>, Schema.Struct<{
323
+ readonly type: Schema.Literal<"additional_tools">;
324
+ readonly role: Schema.Literal<"developer">;
325
+ readonly tools: Schema.$Array<Schema.Union<readonly [Schema.Struct<{
326
+ readonly type: Schema.tag<"function">;
327
+ readonly name: Schema.String;
328
+ readonly description: Schema.String;
329
+ readonly parameters: Schema.$Record<Schema.String, Schema.Unknown>;
330
+ readonly strict: Schema.optional<Schema.Boolean>;
331
+ }>, Schema.Struct<{
332
+ readonly type: Schema.tag<"custom">;
333
+ readonly name: Schema.String;
334
+ readonly description: Schema.String;
335
+ readonly format: Schema.Union<readonly [Schema.Struct<{
336
+ readonly type: Schema.tag<"text">;
337
+ }>, Schema.Struct<{
338
+ readonly type: Schema.tag<"grammar">;
339
+ readonly syntax: Schema.Literals<readonly ["lark", "regex"]>;
340
+ readonly definition: Schema.String;
341
+ }>]>;
342
+ }>, Schema.StructWithRest<Schema.Struct<{
343
+ readonly type: Schema.String;
344
+ }>, readonly [Schema.$Record<Schema.String, Schema.Unknown>]>]>>;
274
345
  }>, Schema.Struct<{
275
346
  readonly type: Schema.tag<"message">;
276
347
  readonly role: Schema.tag<"system">;
@@ -452,6 +523,29 @@ export declare const OpenResponsesBody: Schema.Struct<{
452
523
  readonly reasoning: Schema.Struct<{
453
524
  readonly effort: Schema.declare<OpenResponsesOptions.ReasoningEffort, OpenResponsesOptions.ReasoningEffort>;
454
525
  }>;
526
+ }>, Schema.Struct<{
527
+ readonly type: Schema.Literal<"additional_tools">;
528
+ readonly role: Schema.Literal<"developer">;
529
+ readonly tools: Schema.$Array<Schema.Union<readonly [Schema.Struct<{
530
+ readonly type: Schema.tag<"function">;
531
+ readonly name: Schema.String;
532
+ readonly description: Schema.String;
533
+ readonly parameters: Schema.$Record<Schema.String, Schema.Unknown>;
534
+ readonly strict: Schema.optional<Schema.Boolean>;
535
+ }>, Schema.Struct<{
536
+ readonly type: Schema.tag<"custom">;
537
+ readonly name: Schema.String;
538
+ readonly description: Schema.String;
539
+ readonly format: Schema.Union<readonly [Schema.Struct<{
540
+ readonly type: Schema.tag<"text">;
541
+ }>, Schema.Struct<{
542
+ readonly type: Schema.tag<"grammar">;
543
+ readonly syntax: Schema.Literals<readonly ["lark", "regex"]>;
544
+ readonly definition: Schema.String;
545
+ }>]>;
546
+ }>, Schema.StructWithRest<Schema.Struct<{
547
+ readonly type: Schema.String;
548
+ }>, readonly [Schema.$Record<Schema.String, Schema.Unknown>]>]>>;
455
549
  }>, Schema.Struct<{
456
550
  readonly type: Schema.tag<"message">;
457
551
  readonly role: Schema.tag<"system">;
@@ -915,6 +1009,8 @@ export interface ProviderAdapter {
915
1009
  readonly request: LLMRequest;
916
1010
  }) => MediaInput | undefined;
917
1011
  readonly restoreHostedToolItem?: (item: unknown) => HostedToolReplayItem | undefined;
1012
+ /** Lowers a `Message.tools(...)` marker sent in place; routes without it must fold tool updates. */
1013
+ readonly lowerToolChanges?: (changes: ToolChanges) => Effect.Effect<ReadonlyArray<OpenResponsesInputItem>, AIError>;
918
1014
  }
919
1015
  export interface ParserState {
920
1016
  readonly provider: LLMRequest["model"]["provider"];
@@ -1000,6 +1096,32 @@ export declare const lowerConversation: (request: LLMRequest<import("../schema/o
1000
1096
  readonly reasoning: {
1001
1097
  readonly effort: OpenResponsesOptions.ReasoningEffort;
1002
1098
  };
1099
+ } | {
1100
+ readonly type: "additional_tools";
1101
+ readonly role: "developer";
1102
+ readonly tools: readonly ({
1103
+ readonly type: "custom";
1104
+ readonly name: string;
1105
+ readonly description: string;
1106
+ readonly format: {
1107
+ readonly type: "text";
1108
+ } | {
1109
+ readonly type: "grammar";
1110
+ readonly syntax: "lark" | "regex";
1111
+ readonly definition: string;
1112
+ };
1113
+ } | {
1114
+ readonly type: "function";
1115
+ readonly name: string;
1116
+ readonly description: string;
1117
+ readonly parameters: {
1118
+ readonly [x: string]: unknown;
1119
+ };
1120
+ readonly strict?: boolean | undefined;
1121
+ } | {
1122
+ readonly [x: string]: unknown;
1123
+ readonly type: string;
1124
+ })[];
1003
1125
  } | {
1004
1126
  readonly type: "message";
1005
1127
  readonly role: "system";
@@ -1177,6 +1299,32 @@ export declare const fromRequestWithAdapter: (request: LLMRequest<import("../sch
1177
1299
  readonly reasoning: {
1178
1300
  readonly effort: OpenResponsesOptions.ReasoningEffort;
1179
1301
  };
1302
+ } | {
1303
+ readonly type: "additional_tools";
1304
+ readonly role: "developer";
1305
+ readonly tools: readonly ({
1306
+ readonly type: "custom";
1307
+ readonly name: string;
1308
+ readonly description: string;
1309
+ readonly format: {
1310
+ readonly type: "text";
1311
+ } | {
1312
+ readonly type: "grammar";
1313
+ readonly syntax: "lark" | "regex";
1314
+ readonly definition: string;
1315
+ };
1316
+ } | {
1317
+ readonly type: "function";
1318
+ readonly name: string;
1319
+ readonly description: string;
1320
+ readonly parameters: {
1321
+ readonly [x: string]: unknown;
1322
+ };
1323
+ readonly strict?: boolean | undefined;
1324
+ } | {
1325
+ readonly [x: string]: unknown;
1326
+ readonly type: string;
1327
+ })[];
1180
1328
  } | {
1181
1329
  readonly type: "message";
1182
1330
  readonly role: "system";
@@ -1375,6 +1523,32 @@ export declare const fromRequest: (request: LLMRequest) => Effect.Effect<{
1375
1523
  readonly reasoning: {
1376
1524
  readonly effort: OpenResponsesOptions.ReasoningEffort;
1377
1525
  };
1526
+ } | {
1527
+ readonly type: "additional_tools";
1528
+ readonly role: "developer";
1529
+ readonly tools: readonly ({
1530
+ readonly type: "custom";
1531
+ readonly name: string;
1532
+ readonly description: string;
1533
+ readonly format: {
1534
+ readonly type: "text";
1535
+ } | {
1536
+ readonly type: "grammar";
1537
+ readonly syntax: "lark" | "regex";
1538
+ readonly definition: string;
1539
+ };
1540
+ } | {
1541
+ readonly type: "function";
1542
+ readonly name: string;
1543
+ readonly description: string;
1544
+ readonly parameters: {
1545
+ readonly [x: string]: unknown;
1546
+ };
1547
+ readonly strict?: boolean | undefined;
1548
+ } | {
1549
+ readonly [x: string]: unknown;
1550
+ readonly type: string;
1551
+ })[];
1378
1552
  } | {
1379
1553
  readonly type: "message";
1380
1554
  readonly role: "system";
@@ -1791,6 +1965,32 @@ export declare const protocol: Protocol<{
1791
1965
  readonly reasoning: {
1792
1966
  readonly effort: OpenResponsesOptions.ReasoningEffort;
1793
1967
  };
1968
+ } | {
1969
+ readonly type: "additional_tools";
1970
+ readonly role: "developer";
1971
+ readonly tools: readonly ({
1972
+ readonly type: "custom";
1973
+ readonly name: string;
1974
+ readonly description: string;
1975
+ readonly format: {
1976
+ readonly type: "text";
1977
+ } | {
1978
+ readonly type: "grammar";
1979
+ readonly syntax: "lark" | "regex";
1980
+ readonly definition: string;
1981
+ };
1982
+ } | {
1983
+ readonly type: "function";
1984
+ readonly name: string;
1985
+ readonly description: string;
1986
+ readonly parameters: {
1987
+ readonly [x: string]: unknown;
1988
+ };
1989
+ readonly strict?: boolean | undefined;
1990
+ } | {
1991
+ readonly [x: string]: unknown;
1992
+ readonly type: string;
1993
+ })[];
1794
1994
  } | {
1795
1995
  readonly type: "message";
1796
1996
  readonly role: "system";
@@ -2047,6 +2247,32 @@ export declare const httpTransport: HttpTransport.HttpJsonTransport<{
2047
2247
  readonly reasoning: {
2048
2248
  readonly effort: OpenResponsesOptions.ReasoningEffort;
2049
2249
  };
2250
+ } | {
2251
+ readonly type: "additional_tools";
2252
+ readonly role: "developer";
2253
+ readonly tools: readonly ({
2254
+ readonly type: "custom";
2255
+ readonly name: string;
2256
+ readonly description: string;
2257
+ readonly format: {
2258
+ readonly type: "text";
2259
+ } | {
2260
+ readonly type: "grammar";
2261
+ readonly syntax: "lark" | "regex";
2262
+ readonly definition: string;
2263
+ };
2264
+ } | {
2265
+ readonly type: "function";
2266
+ readonly name: string;
2267
+ readonly description: string;
2268
+ readonly parameters: {
2269
+ readonly [x: string]: unknown;
2270
+ };
2271
+ readonly strict?: boolean | undefined;
2272
+ } | {
2273
+ readonly [x: string]: unknown;
2274
+ readonly type: string;
2275
+ })[];
2050
2276
  } | {
2051
2277
  readonly type: "message";
2052
2278
  readonly role: "system";
@@ -5,6 +5,7 @@ import { AIError, LLMEvent, ProviderInternalError, Usage, } from "../schema/inde
5
5
  import { JsonObject, lenient, optionalArray, optionalNull, optionalNullish, ProviderShared, withUntypedFrames, } from "./shared.js";
6
6
  import { classifyProviderFailure } from "../provider-error.js";
7
7
  import { effortUpdate } from "../effort-updates.js";
8
+ import { toolsUpdate } from "../tool-updates.js";
8
9
  import { OpenResponsesOptions } from "./utils/open-responses-options.js";
9
10
  import { Lifecycle } from "./utils/lifecycle.js";
10
11
  import { ToolStream } from "./utils/tool-stream.js";
@@ -126,9 +127,40 @@ export const HostedToolReplay = Schema.StructWithRest(Schema.Struct({
126
127
  type: Schema.String,
127
128
  id: Schema.String,
128
129
  }), [JsonObject]);
130
+ export const Tool = Schema.Struct({
131
+ type: Schema.tag("function"),
132
+ name: Schema.String,
133
+ description: Schema.String,
134
+ parameters: JsonObject,
135
+ strict: Schema.optional(Schema.Boolean),
136
+ });
137
+ export const CustomTool = Schema.Struct({
138
+ type: Schema.tag("custom"),
139
+ name: Schema.String,
140
+ description: Schema.String,
141
+ format: Schema.Union([
142
+ Schema.Struct({ type: Schema.tag("text") }),
143
+ Schema.Struct({
144
+ type: Schema.tag("grammar"),
145
+ syntax: Schema.Literals(["lark", "regex"]),
146
+ definition: Schema.String,
147
+ }),
148
+ ]),
149
+ });
150
+ export const HostedTool = Schema.StructWithRest(Schema.Struct({
151
+ type: Schema.String,
152
+ }), [JsonObject]);
153
+ const NamedTool = Schema.Struct({ type: Schema.Literals(["function", "custom"]), name: Schema.String });
154
+ // Tools added mid-conversation. Only the OpenAI extension lowers it; other hosts fold tool updates.
155
+ export const AdditionalTools = Schema.Struct({
156
+ type: Schema.Literal("additional_tools"),
157
+ role: Schema.Literal("developer"),
158
+ tools: Schema.Array(Schema.Union([Tool, CustomTool, HostedTool])),
159
+ });
129
160
  export const InputItem = Schema.Union([
130
161
  CompactionItem,
131
162
  ConfigurationUpdate,
163
+ AdditionalTools,
132
164
  Schema.Struct({ type: Schema.tag("message"), role: Schema.tag("system"), content: Schema.String }),
133
165
  Schema.Struct({ type: Schema.tag("message"), role: Schema.tag("developer"), content: Schema.String }),
134
166
  Schema.Struct({
@@ -170,30 +202,6 @@ export const InputItem = Schema.Union([
170
202
  HostedToolItem,
171
203
  HostedToolReplay,
172
204
  ]);
173
- export const Tool = Schema.Struct({
174
- type: Schema.tag("function"),
175
- name: Schema.String,
176
- description: Schema.String,
177
- parameters: JsonObject,
178
- strict: Schema.optional(Schema.Boolean),
179
- });
180
- export const CustomTool = Schema.Struct({
181
- type: Schema.tag("custom"),
182
- name: Schema.String,
183
- description: Schema.String,
184
- format: Schema.Union([
185
- Schema.Struct({ type: Schema.tag("text") }),
186
- Schema.Struct({
187
- type: Schema.tag("grammar"),
188
- syntax: Schema.Literals(["lark", "regex"]),
189
- definition: Schema.String,
190
- }),
191
- ]),
192
- });
193
- export const HostedTool = Schema.StructWithRest(Schema.Struct({
194
- type: Schema.String,
195
- }), [JsonObject]);
196
- const NamedTool = Schema.Struct({ type: Schema.Literals(["function", "custom"]), name: Schema.String });
197
205
  export const ToolChoice = Schema.Union([
198
206
  Schema.Literals(["auto", "none", "required"]),
199
207
  NamedTool,
@@ -462,6 +470,14 @@ const lowerMessages = Effect.fnUntraced(function* (request, adapter) {
462
470
  input.push({ type: "configuration_update", reasoning: { effort: update.effort ?? DEFAULT_EFFORT } });
463
471
  continue;
464
472
  }
473
+ // Planning folds every marker on routes whose protocol has no `toolUpdates`, so only adapters with
474
+ // `lowerToolChanges` see one.
475
+ const tools = toolsUpdate(message);
476
+ if (tools && adapter.lowerToolChanges) {
477
+ input.push(...(yield* adapter.lowerToolChanges(tools)));
478
+ if (message.content.length === 0)
479
+ continue;
480
+ }
465
481
  input.push({
466
482
  type: "message",
467
483
  role: "developer",
@@ -11,6 +11,32 @@ export declare const route: Route<{
11
11
  readonly reasoning: {
12
12
  readonly effort: import("../public.js").ReasoningEffort;
13
13
  };
14
+ } | {
15
+ readonly type: "additional_tools";
16
+ readonly role: "developer";
17
+ readonly tools: readonly ({
18
+ readonly type: "custom";
19
+ readonly name: string;
20
+ readonly description: string;
21
+ readonly format: {
22
+ readonly type: "text";
23
+ } | {
24
+ readonly type: "grammar";
25
+ readonly syntax: "lark" | "regex";
26
+ readonly definition: string;
27
+ };
28
+ } | {
29
+ readonly type: "function";
30
+ readonly name: string;
31
+ readonly description: string;
32
+ readonly parameters: {
33
+ readonly [x: string]: unknown;
34
+ };
35
+ readonly strict?: boolean | undefined;
36
+ } | {
37
+ readonly [x: string]: unknown;
38
+ readonly type: string;
39
+ })[];
14
40
  } | {
15
41
  readonly type: "message";
16
42
  readonly role: "system";
@@ -7,7 +7,7 @@ export interface Custom {
7
7
  }
8
8
  /** How a tool goes out: a custom tool when it declares `freeform` with one required string parameter. */
9
9
  export declare const resolve: (tool: ToolDefinition) => Custom | undefined;
10
- /** Custom tools in this request, by flattened tool name. */
10
+ /** Custom tools in this request, including ones added mid-conversation, by flattened tool name. */
11
11
  export declare const tools: (request: LLMRequest) => ReadonlyMap<string, Custom>;
12
12
  /** The format's grammar, or `undefined` for unconstrained text. */
13
13
  export declare const grammar: (format: Freeform) => {
@@ -2,6 +2,7 @@ import { Option, Schema } from "effect";
2
2
  import { ToolDefinition, } from "../schema/index.js";
3
3
  import { encodeJson, flattenTools, isRecord } from "./shared.js";
4
4
  import { ToolStream } from "./utils/tool-stream.js";
5
+ import { toolsUpdate } from "../tool-updates.js";
5
6
  /** How a tool goes out: a custom tool when it declares `freeform` with one required string parameter. */
6
7
  export const resolve = (tool) => {
7
8
  const field = ToolDefinition.freeformField(tool.inputSchema);
@@ -9,11 +10,14 @@ export const resolve = (tool) => {
9
10
  return undefined;
10
11
  return { field, format: tool.freeform };
11
12
  };
12
- /** Custom tools in this request, by flattened tool name. */
13
- export const tools = (request) => new Map(flattenTools(request.tools).flatMap((tool) => {
14
- const custom = resolve(tool);
15
- return custom ? [[tool.name, custom]] : [];
16
- }));
13
+ /** Custom tools in this request, including ones added mid-conversation, by flattened tool name. */
14
+ export const tools = (request) => {
15
+ const added = request.messages.flatMap((message) => toolsUpdate(message)?.add ?? []);
16
+ return new Map(flattenTools([...request.tools, ...added]).flatMap((tool) => {
17
+ const custom = resolve(tool);
18
+ return custom ? [[tool.name, custom]] : [];
19
+ }));
20
+ };
17
21
  /** The format's grammar, or `undefined` for unconstrained text. */
18
22
  export const grammar = (format) => format.type === "text"
19
23
  ? undefined