@opencode/ai 0.0.0-dev-170 → 0.0.0-dev-176

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 (67) hide show
  1. package/README.md +48 -3
  2. package/dist/effect.d.ts +1 -1
  3. package/dist/effect.js +1 -1
  4. package/dist/index.d.ts +2 -1
  5. package/dist/index.js +1 -0
  6. package/dist/protocols/alibaba-chat.d.ts +39 -4
  7. package/dist/protocols/alibaba-responses.d.ts +20 -3
  8. package/dist/protocols/fal-images.d.ts +2 -0
  9. package/dist/protocols/fal-images.js +1 -0
  10. package/dist/protocols/meta-responses.d.ts +40 -6
  11. package/dist/protocols/meta-responses.js +1 -1
  12. package/dist/protocols/minimax-images.d.ts +25 -0
  13. package/dist/protocols/minimax-images.js +150 -0
  14. package/dist/protocols/open-responses.d.ts +182 -27
  15. package/dist/protocols/open-responses.js +108 -36
  16. package/dist/protocols/openai-chat.d.ts +438 -46
  17. package/dist/protocols/openai-chat.js +121 -39
  18. package/dist/protocols/openai-compatible-chat.d.ts +35 -4
  19. package/dist/protocols/openai-compatible-responses.d.ts +20 -3
  20. package/dist/protocols/openai-freeform.d.ts +47 -0
  21. package/dist/protocols/openai-freeform.js +54 -0
  22. package/dist/protocols/openai-images.js +8 -2
  23. package/dist/protocols/openai-responses.d.ts +120 -18
  24. package/dist/protocols/openai-responses.js +17 -8
  25. package/dist/protocols/venice-chat.d.ts +39 -4
  26. package/dist/protocols/venice-chat.js +1 -1
  27. package/dist/protocols/xai-images.d.ts +1 -0
  28. package/dist/protocols/xai-images.js +2 -4
  29. package/dist/protocols/xai-responses.d.ts +20 -3
  30. package/dist/protocols/xai-responses.js +2 -1
  31. package/dist/protocols/zai-chat.d.ts +39 -4
  32. package/dist/providers/alibaba.d.ts +55 -7
  33. package/dist/providers/amazon-bedrock-mantle.d.ts +55 -7
  34. package/dist/providers/azure.d.ts +75 -10
  35. package/dist/providers/baseten.d.ts +70 -8
  36. package/dist/providers/cerebras.d.ts +70 -8
  37. package/dist/providers/cloudflare-ai-gateway.d.ts +110 -14
  38. package/dist/providers/cloudflare-workers-ai.d.ts +70 -8
  39. package/dist/providers/cohere.d.ts +70 -8
  40. package/dist/providers/deepinfra.d.ts +70 -8
  41. package/dist/providers/deepseek.d.ts +70 -8
  42. package/dist/providers/digitalocean.d.ts +109 -12
  43. package/dist/providers/fireworks.d.ts +70 -8
  44. package/dist/providers/google-vertex-chat.d.ts +35 -4
  45. package/dist/providers/google-vertex-responses.d.ts +20 -3
  46. package/dist/providers/groq.d.ts +74 -8
  47. package/dist/providers/meta.d.ts +55 -7
  48. package/dist/providers/minimax/images.d.ts +3 -0
  49. package/dist/providers/minimax/images.js +1 -0
  50. package/dist/providers/minimax.d.ts +62 -8
  51. package/dist/providers/minimax.js +22 -9
  52. package/dist/providers/moonshot.d.ts +55 -7
  53. package/dist/providers/openai-compatible-responses.d.ts +20 -3
  54. package/dist/providers/openai-compatible.d.ts +35 -4
  55. package/dist/providers/openai-compatible.js +9 -2
  56. package/dist/providers/openai.d.ts +55 -7
  57. package/dist/providers/openrouter.d.ts +144 -16
  58. package/dist/providers/togetherai.d.ts +70 -8
  59. package/dist/providers/venice.d.ts +35 -4
  60. package/dist/providers/xai.d.ts +35 -4
  61. package/dist/providers/zai-coding-plan.d.ts +55 -7
  62. package/dist/providers/zai.d.ts +35 -4
  63. package/dist/schema/messages.d.ts +35 -1
  64. package/dist/schema/messages.js +20 -0
  65. package/dist/tool.d.ts +12 -1
  66. package/dist/tool.js +10 -2
  67. package/package.json +7 -3
@@ -88,7 +88,14 @@ export declare const route: Route<{
88
88
  readonly ttl?: string | undefined;
89
89
  } | undefined;
90
90
  }[] | null;
91
- readonly tool_calls?: readonly {
91
+ readonly tool_calls?: readonly ({
92
+ readonly id: string;
93
+ readonly type: "custom";
94
+ readonly custom: {
95
+ readonly name: string;
96
+ readonly input: string;
97
+ };
98
+ } | {
92
99
  readonly id: string;
93
100
  readonly type: "function";
94
101
  readonly function: {
@@ -100,13 +107,13 @@ export declare const route: Route<{
100
107
  readonly thought_signature: string;
101
108
  };
102
109
  } | undefined;
103
- }[] | undefined;
110
+ })[] | undefined;
104
111
  readonly reasoning_content?: string | undefined;
105
112
  readonly reasoning?: string | undefined;
106
113
  readonly reasoning_text?: string | undefined;
107
114
  readonly reasoning_details?: unknown;
108
115
  })[];
109
- readonly tools?: readonly {
116
+ readonly tools?: readonly ({
110
117
  readonly type: "function";
111
118
  readonly function: {
112
119
  readonly name: string;
@@ -120,12 +127,36 @@ export declare const route: Route<{
120
127
  readonly type: "ephemeral";
121
128
  readonly ttl?: string | undefined;
122
129
  } | undefined;
123
- }[] | undefined;
130
+ } | {
131
+ readonly type: "custom";
132
+ readonly custom: {
133
+ readonly name: string;
134
+ readonly description: string;
135
+ readonly format: {
136
+ readonly type: "text";
137
+ } | {
138
+ readonly type: "grammar";
139
+ readonly grammar: {
140
+ readonly syntax: "lark" | "regex";
141
+ readonly definition: string;
142
+ };
143
+ };
144
+ };
145
+ readonly cache_control?: {
146
+ readonly type: "ephemeral";
147
+ readonly ttl?: string | undefined;
148
+ } | undefined;
149
+ })[] | undefined;
124
150
  readonly tool_choice?: "auto" | "none" | "required" | {
125
151
  readonly type: "function";
126
152
  readonly function: {
127
153
  readonly name: string;
128
154
  };
155
+ } | {
156
+ readonly type: "custom";
157
+ readonly custom: {
158
+ readonly name: string;
159
+ };
129
160
  } | undefined;
130
161
  readonly stream: true;
131
162
  readonly stream_options?: {
@@ -231,7 +262,14 @@ export declare const routes: Route<{
231
262
  readonly ttl?: string | undefined;
232
263
  } | undefined;
233
264
  }[] | null;
234
- readonly tool_calls?: readonly {
265
+ readonly tool_calls?: readonly ({
266
+ readonly id: string;
267
+ readonly type: "custom";
268
+ readonly custom: {
269
+ readonly name: string;
270
+ readonly input: string;
271
+ };
272
+ } | {
235
273
  readonly id: string;
236
274
  readonly type: "function";
237
275
  readonly function: {
@@ -243,13 +281,13 @@ export declare const routes: Route<{
243
281
  readonly thought_signature: string;
244
282
  };
245
283
  } | undefined;
246
- }[] | undefined;
284
+ })[] | undefined;
247
285
  readonly reasoning_content?: string | undefined;
248
286
  readonly reasoning?: string | undefined;
249
287
  readonly reasoning_text?: string | undefined;
250
288
  readonly reasoning_details?: unknown;
251
289
  })[];
252
- readonly tools?: readonly {
290
+ readonly tools?: readonly ({
253
291
  readonly type: "function";
254
292
  readonly function: {
255
293
  readonly name: string;
@@ -263,12 +301,36 @@ export declare const routes: Route<{
263
301
  readonly type: "ephemeral";
264
302
  readonly ttl?: string | undefined;
265
303
  } | undefined;
266
- }[] | undefined;
304
+ } | {
305
+ readonly type: "custom";
306
+ readonly custom: {
307
+ readonly name: string;
308
+ readonly description: string;
309
+ readonly format: {
310
+ readonly type: "text";
311
+ } | {
312
+ readonly type: "grammar";
313
+ readonly grammar: {
314
+ readonly syntax: "lark" | "regex";
315
+ readonly definition: string;
316
+ };
317
+ };
318
+ };
319
+ readonly cache_control?: {
320
+ readonly type: "ephemeral";
321
+ readonly ttl?: string | undefined;
322
+ } | undefined;
323
+ })[] | undefined;
267
324
  readonly tool_choice?: "auto" | "none" | "required" | {
268
325
  readonly type: "function";
269
326
  readonly function: {
270
327
  readonly name: string;
271
328
  };
329
+ } | {
330
+ readonly type: "custom";
331
+ readonly custom: {
332
+ readonly name: string;
333
+ };
272
334
  } | undefined;
273
335
  readonly stream: true;
274
336
  readonly stream_options?: {
@@ -17,7 +17,7 @@ export type Settings = ProviderPackage.Settings & ChatOptionsInput & {
17
17
  };
18
18
  export declare const routes: Route<{
19
19
  readonly model: string;
20
- readonly tools?: readonly {
20
+ readonly tools?: readonly ({
21
21
  readonly type: "function";
22
22
  readonly function: {
23
23
  readonly name: string;
@@ -31,12 +31,36 @@ export declare const routes: Route<{
31
31
  readonly type: "ephemeral";
32
32
  readonly ttl?: string | undefined;
33
33
  } | undefined;
34
- }[] | undefined;
34
+ } | {
35
+ readonly type: "custom";
36
+ readonly custom: {
37
+ readonly name: string;
38
+ readonly description: string;
39
+ readonly format: {
40
+ readonly type: "text";
41
+ } | {
42
+ readonly type: "grammar";
43
+ readonly grammar: {
44
+ readonly syntax: "lark" | "regex";
45
+ readonly definition: string;
46
+ };
47
+ };
48
+ };
49
+ readonly cache_control?: {
50
+ readonly type: "ephemeral";
51
+ readonly ttl?: string | undefined;
52
+ } | undefined;
53
+ })[] | undefined;
35
54
  readonly tool_choice?: "auto" | "none" | "required" | {
36
55
  readonly type: "function";
37
56
  readonly function: {
38
57
  readonly name: string;
39
58
  };
59
+ } | {
60
+ readonly type: "custom";
61
+ readonly custom: {
62
+ readonly name: string;
63
+ };
40
64
  } | undefined;
41
65
  readonly stream: true;
42
66
  readonly stream_options?: {
@@ -141,7 +165,14 @@ export declare const routes: Route<{
141
165
  readonly reasoning?: string | undefined;
142
166
  readonly reasoning_text?: string | undefined;
143
167
  readonly reasoning_details?: unknown;
144
- readonly tool_calls?: readonly {
168
+ readonly tool_calls?: readonly ({
169
+ readonly id: string;
170
+ readonly type: "custom";
171
+ readonly custom: {
172
+ readonly name: string;
173
+ readonly input: string;
174
+ };
175
+ } | {
145
176
  readonly id: string;
146
177
  readonly type: "function";
147
178
  readonly function: {
@@ -154,7 +185,7 @@ export declare const routes: Route<{
154
185
  };
155
186
  } | undefined;
156
187
  readonly thought_signature?: string | undefined;
157
- }[] | undefined;
188
+ })[] | undefined;
158
189
  readonly thought_signature?: string | undefined;
159
190
  })[];
160
191
  readonly reasoning?: {
@@ -99,7 +99,14 @@ export declare const routes: (Route<unknown, import("../protocols/open-responses
99
99
  readonly ttl?: string | undefined;
100
100
  } | undefined;
101
101
  }[] | null;
102
- readonly tool_calls?: readonly {
102
+ readonly tool_calls?: readonly ({
103
+ readonly id: string;
104
+ readonly type: "custom";
105
+ readonly custom: {
106
+ readonly name: string;
107
+ readonly input: string;
108
+ };
109
+ } | {
103
110
  readonly id: string;
104
111
  readonly type: "function";
105
112
  readonly function: {
@@ -111,13 +118,13 @@ export declare const routes: (Route<unknown, import("../protocols/open-responses
111
118
  readonly thought_signature: string;
112
119
  };
113
120
  } | undefined;
114
- }[] | undefined;
121
+ })[] | undefined;
115
122
  readonly reasoning_content?: string | undefined;
116
123
  readonly reasoning?: string | undefined;
117
124
  readonly reasoning_text?: string | undefined;
118
125
  readonly reasoning_details?: unknown;
119
126
  })[];
120
- readonly tools?: readonly {
127
+ readonly tools?: readonly ({
121
128
  readonly type: "function";
122
129
  readonly function: {
123
130
  readonly name: string;
@@ -131,12 +138,36 @@ export declare const routes: (Route<unknown, import("../protocols/open-responses
131
138
  readonly type: "ephemeral";
132
139
  readonly ttl?: string | undefined;
133
140
  } | undefined;
134
- }[] | undefined;
141
+ } | {
142
+ readonly type: "custom";
143
+ readonly custom: {
144
+ readonly name: string;
145
+ readonly description: string;
146
+ readonly format: {
147
+ readonly type: "text";
148
+ } | {
149
+ readonly type: "grammar";
150
+ readonly grammar: {
151
+ readonly syntax: "lark" | "regex";
152
+ readonly definition: string;
153
+ };
154
+ };
155
+ };
156
+ readonly cache_control?: {
157
+ readonly type: "ephemeral";
158
+ readonly ttl?: string | undefined;
159
+ } | undefined;
160
+ })[] | undefined;
135
161
  readonly tool_choice?: "auto" | "none" | "required" | {
136
162
  readonly type: "function";
137
163
  readonly function: {
138
164
  readonly name: string;
139
165
  };
166
+ } | {
167
+ readonly type: "custom";
168
+ readonly custom: {
169
+ readonly name: string;
170
+ };
140
171
  } | undefined;
141
172
  readonly stream: true;
142
173
  readonly stream_options?: {
@@ -35,7 +35,7 @@ export declare const routes: (Route<{
35
35
  readonly role: "developer";
36
36
  readonly content: string;
37
37
  } | {
38
- readonly type: "function_call_output";
38
+ readonly type: "custom_tool_call_output" | "function_call_output";
39
39
  readonly call_id: string;
40
40
  readonly output: string | readonly ({
41
41
  readonly type: "input_text";
@@ -105,6 +105,12 @@ export declare const routes: (Route<{
105
105
  readonly name: string;
106
106
  readonly namespace?: string | undefined;
107
107
  readonly arguments: string;
108
+ } | {
109
+ readonly type: "custom_tool_call";
110
+ readonly id?: string | undefined;
111
+ readonly call_id: string;
112
+ readonly name: string;
113
+ readonly input: string;
108
114
  } | {
109
115
  readonly [x: string]: unknown;
110
116
  readonly type: "web_search_call";
@@ -149,6 +155,17 @@ export declare const routes: (Route<{
149
155
  })[];
150
156
  readonly instructions?: string | undefined;
151
157
  readonly tools?: readonly ({
158
+ readonly type: "custom";
159
+ readonly name: string;
160
+ readonly description: string;
161
+ readonly format: {
162
+ readonly type: "text";
163
+ } | {
164
+ readonly type: "grammar";
165
+ readonly syntax: "lark" | "regex";
166
+ readonly definition: string;
167
+ };
168
+ } | {
152
169
  readonly type: "function";
153
170
  readonly name: string;
154
171
  readonly description: string;
@@ -161,13 +178,13 @@ export declare const routes: (Route<{
161
178
  readonly type: string;
162
179
  })[] | undefined;
163
180
  readonly tool_choice?: "auto" | "none" | "required" | {
164
- readonly type: "function";
181
+ readonly type: "custom" | "function";
165
182
  readonly name: string;
166
183
  } | {
167
184
  readonly type: "allowed_tools";
168
185
  readonly mode: "auto" | "none" | "required";
169
186
  readonly tools: readonly {
170
- readonly type: "function";
187
+ readonly type: "custom" | "function";
171
188
  readonly name: string;
172
189
  }[];
173
190
  } | undefined;
@@ -275,7 +292,14 @@ export declare const routes: (Route<{
275
292
  readonly ttl?: string | undefined;
276
293
  } | undefined;
277
294
  }[] | null;
278
- readonly tool_calls?: readonly {
295
+ readonly tool_calls?: readonly ({
296
+ readonly id: string;
297
+ readonly type: "custom";
298
+ readonly custom: {
299
+ readonly name: string;
300
+ readonly input: string;
301
+ };
302
+ } | {
279
303
  readonly id: string;
280
304
  readonly type: "function";
281
305
  readonly function: {
@@ -287,13 +311,13 @@ export declare const routes: (Route<{
287
311
  readonly thought_signature: string;
288
312
  };
289
313
  } | undefined;
290
- }[] | undefined;
314
+ })[] | undefined;
291
315
  readonly reasoning_content?: string | undefined;
292
316
  readonly reasoning?: string | undefined;
293
317
  readonly reasoning_text?: string | undefined;
294
318
  readonly reasoning_details?: unknown;
295
319
  })[];
296
- readonly tools?: readonly {
320
+ readonly tools?: readonly ({
297
321
  readonly type: "function";
298
322
  readonly function: {
299
323
  readonly name: string;
@@ -307,12 +331,36 @@ export declare const routes: (Route<{
307
331
  readonly type: "ephemeral";
308
332
  readonly ttl?: string | undefined;
309
333
  } | undefined;
310
- }[] | undefined;
334
+ } | {
335
+ readonly type: "custom";
336
+ readonly custom: {
337
+ readonly name: string;
338
+ readonly description: string;
339
+ readonly format: {
340
+ readonly type: "text";
341
+ } | {
342
+ readonly type: "grammar";
343
+ readonly grammar: {
344
+ readonly syntax: "lark" | "regex";
345
+ readonly definition: string;
346
+ };
347
+ };
348
+ };
349
+ readonly cache_control?: {
350
+ readonly type: "ephemeral";
351
+ readonly ttl?: string | undefined;
352
+ } | undefined;
353
+ })[] | undefined;
311
354
  readonly tool_choice?: "auto" | "none" | "required" | {
312
355
  readonly type: "function";
313
356
  readonly function: {
314
357
  readonly name: string;
315
358
  };
359
+ } | {
360
+ readonly type: "custom";
361
+ readonly custom: {
362
+ readonly name: string;
363
+ };
316
364
  } | undefined;
317
365
  readonly stream: true;
318
366
  readonly stream_options?: {
@@ -90,7 +90,14 @@ export declare const routes: Route<{
90
90
  readonly ttl?: string | undefined;
91
91
  } | undefined;
92
92
  }[] | null;
93
- readonly tool_calls?: readonly {
93
+ readonly tool_calls?: readonly ({
94
+ readonly id: string;
95
+ readonly type: "custom";
96
+ readonly custom: {
97
+ readonly name: string;
98
+ readonly input: string;
99
+ };
100
+ } | {
94
101
  readonly id: string;
95
102
  readonly type: "function";
96
103
  readonly function: {
@@ -102,13 +109,13 @@ export declare const routes: Route<{
102
109
  readonly thought_signature: string;
103
110
  };
104
111
  } | undefined;
105
- }[] | undefined;
112
+ })[] | undefined;
106
113
  readonly reasoning_content?: string | undefined;
107
114
  readonly reasoning?: string | undefined;
108
115
  readonly reasoning_text?: string | undefined;
109
116
  readonly reasoning_details?: unknown;
110
117
  })[];
111
- readonly tools?: readonly {
118
+ readonly tools?: readonly ({
112
119
  readonly type: "function";
113
120
  readonly function: {
114
121
  readonly name: string;
@@ -122,12 +129,36 @@ export declare const routes: Route<{
122
129
  readonly type: "ephemeral";
123
130
  readonly ttl?: string | undefined;
124
131
  } | undefined;
125
- }[] | undefined;
132
+ } | {
133
+ readonly type: "custom";
134
+ readonly custom: {
135
+ readonly name: string;
136
+ readonly description: string;
137
+ readonly format: {
138
+ readonly type: "text";
139
+ } | {
140
+ readonly type: "grammar";
141
+ readonly grammar: {
142
+ readonly syntax: "lark" | "regex";
143
+ readonly definition: string;
144
+ };
145
+ };
146
+ };
147
+ readonly cache_control?: {
148
+ readonly type: "ephemeral";
149
+ readonly ttl?: string | undefined;
150
+ } | undefined;
151
+ })[] | undefined;
126
152
  readonly tool_choice?: "auto" | "none" | "required" | {
127
153
  readonly type: "function";
128
154
  readonly function: {
129
155
  readonly name: string;
130
156
  };
157
+ } | {
158
+ readonly type: "custom";
159
+ readonly custom: {
160
+ readonly name: string;
161
+ };
131
162
  } | undefined;
132
163
  readonly stream: true;
133
164
  readonly stream_options?: {
@@ -1,6 +1,6 @@
1
1
  import { Schema } from "effect";
2
2
  import { Tool } from "@opencode/schema/tool";
3
- import { CacheHint, GenerationOptions, HttpOptions, type LanguageModel, ReasoningEffort } from "./options.js";
3
+ import { CacheHint, GenerationOptions, HttpOptions, JsonSchema, type LanguageModel, ReasoningEffort } from "./options.js";
4
4
  import { Media } from "../media.js";
5
5
  export declare const MessageRole: Schema.Literals<readonly ["system", "user", "assistant", "tool"]>;
6
6
  export type MessageRole = Schema.Schema.Type<typeof MessageRole>;
@@ -598,11 +598,34 @@ export declare namespace Message {
598
598
  }) => Message;
599
599
  const tool: (result: ToolResultPart | Parameters<typeof ToolResultPart.make>[0]) => Message;
600
600
  }
601
+ /**
602
+ * Raw-text wire encoding for a tool with exactly one required string parameter. Models that accept the format
603
+ * write that parameter's value directly instead of JSON arguments; calls still decode to the normal object input.
604
+ */
605
+ export declare const Freeform: Schema.Union<readonly [Schema.Struct<{
606
+ readonly type: Schema.Literal<"text">;
607
+ }>, Schema.Struct<{
608
+ readonly type: Schema.Literal<"regex">;
609
+ readonly pattern: Schema.String;
610
+ }>, Schema.Struct<{
611
+ readonly type: Schema.Literal<"lark">;
612
+ readonly grammar: Schema.String;
613
+ }>]>;
614
+ export type Freeform = Schema.Schema.Type<typeof Freeform>;
601
615
  declare const toolDefinitionFields: {
602
616
  name: Schema.String;
603
617
  description: Schema.String;
604
618
  inputSchema: Schema.$Record<Schema.String, Schema.Unknown>;
605
619
  outputSchema: Schema.optional<Schema.$Record<Schema.String, Schema.Unknown>>;
620
+ freeform: Schema.optional<Schema.Union<readonly [Schema.Struct<{
621
+ readonly type: Schema.Literal<"text">;
622
+ }>, Schema.Struct<{
623
+ readonly type: Schema.Literal<"regex">;
624
+ readonly pattern: Schema.String;
625
+ }>, Schema.Struct<{
626
+ readonly type: Schema.Literal<"lark">;
627
+ readonly grammar: Schema.String;
628
+ }>]>>;
606
629
  cache: Schema.optional<typeof CacheHint>;
607
630
  metadata: Schema.optional<Schema.$Record<Schema.String, Schema.Unknown>>;
608
631
  native: Schema.optional<Schema.$Record<Schema.String, Schema.Unknown>>;
@@ -613,6 +636,15 @@ declare const ToolDefinition_base: Schema.Class<ToolDefinition, Schema.Struct<{
613
636
  readonly description: Schema.String;
614
637
  readonly inputSchema: Schema.$Record<Schema.String, Schema.Unknown>;
615
638
  readonly outputSchema: Schema.optional<Schema.$Record<Schema.String, Schema.Unknown>>;
639
+ readonly freeform: Schema.optional<Schema.Union<readonly [Schema.Struct<{
640
+ readonly type: Schema.Literal<"text">;
641
+ }>, Schema.Struct<{
642
+ readonly type: Schema.Literal<"regex">;
643
+ readonly pattern: Schema.String;
644
+ }>, Schema.Struct<{
645
+ readonly type: Schema.Literal<"lark">;
646
+ readonly grammar: Schema.String;
647
+ }>]>>;
616
648
  readonly cache: Schema.optional<typeof CacheHint>;
617
649
  readonly metadata: Schema.optional<Schema.$Record<Schema.String, Schema.Unknown>>;
618
650
  readonly native: Schema.optional<Schema.$Record<Schema.String, Schema.Unknown>>;
@@ -625,6 +657,8 @@ export declare namespace ToolDefinition {
625
657
  type Input = ToolDefinition | ToolDefinitionInput;
626
658
  /** Normalize tool definition input into the canonical `ToolDefinition` class. */
627
659
  const make: (input: Input) => ToolDefinition;
660
+ /** The parameter a freeform call fills: the input schema's only property, when it is a required string. */
661
+ const freeformField: (schema: JsonSchema) => string | undefined;
628
662
  }
629
663
  export type ToolNamespace = {
630
664
  readonly type: "namespace";
@@ -202,11 +202,21 @@ export class Message extends Schema.Class("LLM.Message")({
202
202
  Message.effort = (input) => Message.make({ role: "system", content: [{ type: "effort", effort: input.effort, previous: input.previous }] });
203
203
  Message.tool = (result) => Message.make({ role: "tool", content: ["type" in result ? result : ToolResultPart.make(result)] });
204
204
  })(Message || (Message = {}));
205
+ /**
206
+ * Raw-text wire encoding for a tool with exactly one required string parameter. Models that accept the format
207
+ * write that parameter's value directly instead of JSON arguments; calls still decode to the normal object input.
208
+ */
209
+ export const Freeform = Schema.Union([
210
+ Schema.Struct({ type: Schema.Literal("text") }),
211
+ Schema.Struct({ type: Schema.Literal("regex"), pattern: Schema.String }),
212
+ Schema.Struct({ type: Schema.Literal("lark"), grammar: Schema.String }),
213
+ ]).annotate({ identifier: "LLM.Freeform" });
205
214
  const toolDefinitionFields = {
206
215
  name: Schema.String,
207
216
  description: Schema.String,
208
217
  inputSchema: JsonSchema,
209
218
  outputSchema: Schema.optional(JsonSchema),
219
+ freeform: Schema.optional(Freeform),
210
220
  cache: Schema.optional(CacheHint),
211
221
  metadata: Schema.optional(Schema.Record(Schema.String, Schema.Unknown)),
212
222
  native: Schema.optional(Schema.Record(Schema.String, Schema.Unknown)),
@@ -222,6 +232,16 @@ export class ToolDefinition extends Schema.Class("LLM.ToolDefinition")({
222
232
  (function (ToolDefinition) {
223
233
  /** Normalize tool definition input into the canonical `ToolDefinition` class. */
224
234
  ToolDefinition.make = (input) => (input instanceof ToolDefinition ? input : new ToolDefinition(input));
235
+ /** The parameter a freeform call fills: the input schema's only property, when it is a required string. */
236
+ ToolDefinition.freeformField = (schema) => {
237
+ const properties = Object.entries(Schema.is(JsonSchema)(schema.properties) ? schema.properties : {});
238
+ if (properties.length !== 1)
239
+ return undefined;
240
+ const [name, property] = properties[0];
241
+ if (!Schema.is(JsonSchema)(property) || property.type !== "string")
242
+ return undefined;
243
+ return Array.isArray(schema.required) && schema.required.includes(name) ? name : undefined;
244
+ };
225
245
  })(ToolDefinition || (ToolDefinition = {}));
226
246
  export const ToolNamespace = withStatics(Schema.Struct({
227
247
  type: Schema.Literal("namespace"),
package/dist/tool.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { Effect, JsonSchema, Schema } from "effect";
2
2
  import { Tool } from "@opencode/schema/tool";
3
- import type { ToolCallPart, ToolDefinition as ToolDefinitionClass, ToolOutput as ToolOutputType } from "./schema/index.js";
3
+ import type { Freeform, ToolCallPart, ToolDefinition as ToolDefinitionClass, ToolOutput as ToolOutputType } from "./schema/index.js";
4
4
  import { ToolFailure } from "./schema/index.js";
5
5
  /**
6
6
  * Schema constraint for tool parameters / success values: no decoding or
@@ -20,6 +20,13 @@ export interface ToolModelOutputInput<Parameters, Output> {
20
20
  readonly output: Output;
21
21
  }
22
22
  export type ToolToModelOutput<Parameters extends ToolSchema<any>, Success extends ToolSchema<any>> = (input: ToolModelOutputInput<Schema.Schema.Type<Parameters>, Success["Encoded"]>) => ReadonlyArray<Tool.Content>;
23
+ type FreeformField<T> = {
24
+ [K in keyof T]-?: [Exclude<keyof T, K>] extends [never] ? {} extends Pick<T, K> ? never : T[K] extends string ? K : never : never;
25
+ }[keyof T];
26
+ /** `Freeform` when the parameters are exactly one required string field, otherwise `undefined`. */
27
+ export type FreeformOption<Parameters extends ToolSchema<any>> = [
28
+ FreeformField<Schema.Schema.Type<Parameters>>
29
+ ] extends [never] ? undefined : Freeform;
23
30
  /**
24
31
  * A type-safe LLM tool. Each tool bundles its own description, parameter
25
32
  * Schema and success Schema. The execute handler is optional: omit it when you
@@ -91,6 +98,7 @@ export declare function make<Parameters extends ToolSchema<any>, Success extends
91
98
  readonly description: string;
92
99
  readonly parameters: Parameters;
93
100
  readonly success: Success;
101
+ readonly freeform?: FreeformOption<Parameters>;
94
102
  readonly execute: ToolExecute<Parameters, Success>;
95
103
  readonly toModelOutput?: ToolToModelOutput<Parameters, Success>;
96
104
  readonly toStructuredOutput?: (output: Success["Encoded"]) => unknown;
@@ -99,6 +107,7 @@ export declare function make<Parameters extends ToolSchema<any>, Success extends
99
107
  readonly description: string;
100
108
  readonly parameters: Parameters;
101
109
  readonly success: Success;
110
+ readonly freeform?: FreeformOption<Parameters>;
102
111
  readonly execute?: undefined;
103
112
  readonly toModelOutput?: ToolToModelOutput<Parameters, Success>;
104
113
  readonly toStructuredOutput?: (output: Success["Encoded"]) => unknown;
@@ -107,6 +116,7 @@ export declare function make(config: {
107
116
  readonly description: string;
108
117
  readonly jsonSchema: JsonSchema.JsonSchema;
109
118
  readonly outputSchema?: JsonSchema.JsonSchema;
119
+ readonly freeform?: Freeform;
110
120
  readonly execute: (params: unknown, context?: ToolExecuteContext) => Effect.Effect<unknown, ToolFailure>;
111
121
  readonly toModelOutput?: (input: ToolModelOutputInput<unknown, unknown>) => ReadonlyArray<Tool.Content>;
112
122
  readonly toStructuredOutput?: (output: unknown) => unknown;
@@ -115,6 +125,7 @@ export declare function make(config: {
115
125
  readonly description: string;
116
126
  readonly jsonSchema: JsonSchema.JsonSchema;
117
127
  readonly outputSchema?: JsonSchema.JsonSchema;
128
+ readonly freeform?: Freeform;
118
129
  readonly execute?: undefined;
119
130
  readonly toModelOutput?: (input: ToolModelOutputInput<unknown, unknown>) => ReadonlyArray<Tool.Content>;
120
131
  readonly toStructuredOutput?: (output: unknown) => unknown;
package/dist/tool.js CHANGED
@@ -15,11 +15,12 @@ export function make(config) {
15
15
  _encode: Effect.succeed,
16
16
  _project: (parameters, id, output) => project(config.toModelOutput, config.toStructuredOutput, parameters, id, output),
17
17
  _legacyResult: config.toModelOutput === undefined && config.toStructuredOutput === undefined,
18
- _definition: new ToolDefinition({
18
+ _definition: definition({
19
19
  name: "",
20
20
  description: config.description,
21
21
  inputSchema: config.jsonSchema,
22
22
  outputSchema: config.outputSchema,
23
+ freeform: config.freeform,
23
24
  }),
24
25
  };
25
26
  }
@@ -34,11 +35,12 @@ export function make(config) {
34
35
  _encode: Schema.encodeEffect(config.success),
35
36
  _project: (parameters, id, output) => project(config.toModelOutput, config.toStructuredOutput, parameters, id, output),
36
37
  _legacyResult: false,
37
- _definition: new ToolDefinition({
38
+ _definition: definition({
38
39
  name: "",
39
40
  description: config.description,
40
41
  inputSchema: emptyInputJsonSchema(config.parameters) ?? toJsonSchema(config.parameters),
41
42
  outputSchema: toJsonSchema(config.success),
43
+ freeform: config.freeform,
42
44
  }),
43
45
  };
44
46
  }
@@ -55,6 +57,7 @@ export const toDefinitions = (tools) => Object.entries(tools).map(([name, item])
55
57
  description: item._definition.description,
56
58
  inputSchema: item._definition.inputSchema,
57
59
  outputSchema: item._definition.outputSchema,
60
+ freeform: item._definition.freeform,
58
61
  }));
59
62
  /**
60
63
  * Describes a no-argument Effect tool input as an empty object, or returns
@@ -73,6 +76,11 @@ export const emptyInputJsonSchema = (schema) => {
73
76
  return undefined;
74
77
  return { ...rest, type: "object", properties: {}, additionalProperties: false };
75
78
  };
79
+ const definition = (input) => {
80
+ if (input.freeform !== undefined && ToolDefinition.freeformField(input.inputSchema) === undefined)
81
+ throw new Error("A freeform tool needs exactly one parameter, a required string");
82
+ return new ToolDefinition(input);
83
+ };
76
84
  const annotationKeywords = new Set(["title", "description", "default", "examples", "readOnly", "writeOnly"]);
77
85
  const toJsonSchema = (schema) => {
78
86
  const document = Schema.toJsonSchemaDocument(schema, { onExcessProperty: "error" });