@opencode/ai 0.0.0-dev-451 → 0.0.0-dev-457

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/README.md CHANGED
@@ -58,7 +58,9 @@ after each step that has tool calls, with every step's `LLMResponse`; returning
58
58
  them. Tools are an array, sent in the order given so the provider can reuse its cached prompt prefix. Each tool has a
59
59
  `name`, and two tools with the same name fail the request. `tool` takes a plain `async` execute; a throw or rejection
60
60
  goes back to the model as an error result, and `signal` aborts when the loop is interrupted.
61
- `tool` from `@opencode/ai/effect` takes the same options (including an optional `success` schema) with an Effect execute:
61
+ `input` is an Effect Schema that decodes and types the arguments, or a raw JSON Schema object, such as an MCP tool's,
62
+ whose arguments arrive as `unknown` (pair it with an optional JSON Schema `outputSchema`). `tool` from
63
+ `@opencode/ai/effect` takes the same options (including an optional `success` schema) with an Effect execute:
62
64
 
63
65
  ```ts
64
66
  import { readFile } from "node:fs/promises"
@@ -68,7 +70,7 @@ import { ai, tool } from "@opencode/ai"
68
70
  const read_file = tool({
69
71
  name: "read_file",
70
72
  description: "Read a UTF-8 file.",
71
- parameters: Schema.Struct({ path: Schema.String }),
73
+ input: Schema.Struct({ path: Schema.String }),
72
74
  execute: ({ path }, { signal }) => readFile(path, { encoding: "utf8", signal }),
73
75
  })
74
76
 
@@ -92,7 +94,7 @@ instead of JSON arguments: unconstrained `text`, or text matching a `regex` or `
92
94
  const run_code = tool({
93
95
  name: "run_code",
94
96
  description: "Run JavaScript",
95
- parameters: Schema.Struct({ code: Schema.String }),
97
+ input: Schema.Struct({ code: Schema.String }),
96
98
  freeform: { type: "lark", grammar: JS_GRAMMAR },
97
99
  execute: ({ code }) => runCode(code),
98
100
  })
@@ -131,11 +133,15 @@ import { ai, LLMEvent } from "@opencode/ai/effect"
131
133
  const flagged = (data: unknown) =>
132
134
  typeof data === "object" && data !== null && "type" in data && data.type === "moderation.flagged"
133
135
 
134
- const events = ai.stream({ model, prompt: "Say hello.", includeRaw: true }).pipe(
135
- Stream.map((event) =>
136
- event.type === "raw" && flagged(event.data) ? LLMEvent.providerError({ message: "Flagged by moderation" }) : event,
137
- ),
138
- )
136
+ const events = ai
137
+ .stream({ model, prompt: "Say hello.", includeRaw: true })
138
+ .pipe(
139
+ Stream.map((event) =>
140
+ event.type === "raw" && flagged(event.data)
141
+ ? LLMEvent.providerError({ message: "Flagged by moderation" })
142
+ : event,
143
+ ),
144
+ )
139
145
  ```
140
146
 
141
147
  ### Google Interactions
@@ -150,11 +156,13 @@ live under `providerMetadata.vertex`. The default is still full-history replay w
150
156
 
151
157
  ```ts
152
158
  const model = Google.configure({ apiKey }).interactions("gemini-3.8-flash")
153
- const response = yield* ai.generate({
154
- model,
155
- prompt: "Say hello.",
156
- providerOptions: { thinkingLevel: "low", thinkingSummaries: "auto", store: true },
157
- })
159
+ const response =
160
+ yield *
161
+ ai.generate({
162
+ model,
163
+ prompt: "Say hello.",
164
+ providerOptions: { thinkingLevel: "low", thinkingSummaries: "auto", store: true },
165
+ })
158
166
  ```
159
167
 
160
168
  Interactions supports text output, streamed function calls, native tool results, thought signatures, and multimodal
@@ -669,18 +677,18 @@ Common fields are portable in shape, not in support. Some routes approximate `as
669
677
  size they offer; others fail with a typed `AIError` before any network call rather than dropping them, so check this
670
678
  table before swapping only the `model`:
671
679
 
672
- | Provider | `n` | `aspect` | `resolution` | `images` | Moved to `providerOptions` |
673
- | --------------------- | --- | -------------------- | --------------------- | -------------------------------- | -------------------------------------------------- |
674
- | OpenAI | ✓¹ | nearest size | nearest size | ✓ | `size`, `outputFormat`, `mask` |
675
- | Google (Gemini) | 1 | ✓ | ✓ (`0.5K` as `512`) | ✓ (no public URLs) | `seed` |
676
- | xAI | ✓ | ✓ | `1k`/`2k` | ✓ | none |
677
- | Meta | ✓ | ✓ (hint) | ignored | ✓ | `size`, `outputFormat` |
678
- | Z.ai | ✗ | width × height | width × height | ✗ | `size` |
679
- | Alibaba | ✓ | width × height | width × height | ✓ | `size`, `seed` |
680
- | MiniMax | ✓ | preset or w × h⁴ | preset or w × h⁴ | 1 (portrait subject) | `aspect_ratio`, `width`, `height`, `seed` |
681
- | Vercel AI Gateway | ✓ | as OpenAI³ | as OpenAI³ | per model | as OpenAI |
682
- | OpenRouter | ✓ | ✓ (`aspect_ratio`) | tier⁵ | per model⁵ | `size`, `outputFormat` (no `mask`) |
683
- | Cloudflare Workers AI | 1 | width × height² | width × height² | ✗ | `width`, `height`, `seed` |
680
+ | Provider | `n` | `aspect` | `resolution` | `images` | Moved to `providerOptions` |
681
+ | --------------------- | --- | ------------------ | ------------------- | -------------------- | ----------------------------------------- |
682
+ | OpenAI | ✓¹ | nearest size | nearest size | ✓ | `size`, `outputFormat`, `mask` |
683
+ | Google (Gemini) | 1 | ✓ | ✓ (`0.5K` as `512`) | ✓ (no public URLs) | `seed` |
684
+ | xAI | ✓ | ✓ | `1k`/`2k` | ✓ | none |
685
+ | Meta | ✓ | ✓ (hint) | ignored | ✓ | `size`, `outputFormat` |
686
+ | Z.ai | ✗ | width × height | width × height | ✗ | `size` |
687
+ | Alibaba | ✓ | width × height | width × height | ✓ | `size`, `seed` |
688
+ | MiniMax | ✓ | preset or w × h⁴ | preset or w × h⁴ | 1 (portrait subject) | `aspect_ratio`, `width`, `height`, `seed` |
689
+ | Vercel AI Gateway | ✓ | as OpenAI³ | as OpenAI³ | per model | as OpenAI |
690
+ | OpenRouter | ✓ | ✓ (`aspect_ratio`) | tier⁵ | per model⁵ | `size`, `outputFormat` (no `mask`) |
691
+ | Cloudflare Workers AI | 1 | width × height² | width × height² | ✗ | `width`, `height`, `seed` |
684
692
 
685
693
  ✓ lowers natively; ✗ fails whenever the field is set (including `n: 1`); `1` means `n > 1` fails. "width × height"
686
694
  computes a size the provider accepts and fails when the request falls outside its limits. ¹ `ai.image.stream` on OpenAI
@@ -851,11 +859,13 @@ and emits `image-partial` events before each final `image`; `ai.image.generate`
851
859
  import { Stream } from "effect"
852
860
  import { ImageEvent } from "@opencode/ai/effect"
853
861
 
854
- const previews = ai.image.stream({
855
- model: openai.image("gpt-image-2"),
856
- prompt: "A lighthouse at dusk",
857
- providerOptions: { partialImages: 2 },
858
- }).pipe(Stream.runForEach((event) => (ImageEvent.is.imagePartial(event) ? showPreview(event.image) : Effect.void)))
862
+ const previews = ai.image
863
+ .stream({
864
+ model: openai.image("gpt-image-2"),
865
+ prompt: "A lighthouse at dusk",
866
+ providerOptions: { partialImages: 2 },
867
+ })
868
+ .pipe(Stream.runForEach((event) => (ImageEvent.is.imagePartial(event) ? showPreview(event.image) : Effect.void)))
859
869
  ```
860
870
 
861
871
  The provider may send fewer previews than requested when the final image is ready first.
package/dist/effect.d.ts CHANGED
@@ -62,5 +62,5 @@ export type { AwaitOptions as GenerationAwaitOptions, Event as GenerationEvent,
62
62
  export { ToolFailure, emptyInputJsonSchema, toDefinitions, tool } from "./tool.js";
63
63
  export { ToolRuntime } from "./tool-runtime.js";
64
64
  export type { ToolSettlement } from "./tool-runtime.js";
65
- export type { ExecutableTool, Tool, ToolExecute, ToolExecuteContext, ToolModelOutputInput, ToolOptions, ToolSchema, ToolToModelOutput, } from "./tool.js";
65
+ export type { ExecutableTool, Tool, ToolExecute, ToolExecuteContext, ToolInput, ToolInputType, ToolModelOutputInput, ToolOptions, ToolSchema, ToolToModelOutput, } from "./tool.js";
66
66
  export type { LLM } from "./llm.js";
package/dist/index.d.ts CHANGED
@@ -11,7 +11,7 @@ import { LanguageModel, type CompactionCheckpointResponse, type CompactionRespon
11
11
  import type { LoopInput, LoopObjectEvent, ObjectEvent, ObjectInput, ObjectResponse, OutputSchema, OutputType, RequestInput } from "./llm.js";
12
12
  import { type SpeechModel, type SpeechRequest, type SpeechRequestInput } from "./speech.js";
13
13
  import { type TranscriptionModel, type TranscriptionRequest, type TranscriptionRequestInput } from "./transcription.js";
14
- import type { NoExecute, ToolExecuteContext, ToolOptions, ToolSchema } from "./tool.js";
14
+ import type { NoExecute, ToolExecuteContext, ToolInput, ToolInputType, ToolOptions, ToolSchema } from "./tool.js";
15
15
  import { type VideoModel, type VideoRequest, type VideoRequestInput } from "./video.js";
16
16
  /**
17
17
  * Promise-first entrypoint for scripts and non-Effect callers. One `ManagedRuntime` hosts the LLM, image, video, speech,
@@ -307,9 +307,9 @@ export declare const make: (options?: Options) => {
307
307
  };
308
308
  export type Client = ReturnType<typeof make>;
309
309
  /** `tool` from `@opencode/ai/effect`, with an `execute` that returns a value or a Promise and throws to fail. */
310
- export declare const tool: <Parameters extends ToolSchema<any> = typeof Schema.Unknown, Success extends ToolSchema<any> = typeof Schema.Unknown, Result extends Schema.Schema.Type<Success> | PromiseLike<Schema.Schema.Type<Success>> | NoExecute = NoExecute>(config: ToolOptions<Parameters, Success, (params: Schema.Schema.Type<Parameters>, context: Partial<ToolExecuteContext> & {
310
+ export declare const tool: <Input extends ToolInput = typeof Schema.Unknown, Success extends ToolSchema<any> = typeof Schema.Unknown, Result extends Schema.Schema.Type<Success> | PromiseLike<Schema.Schema.Type<Success>> | NoExecute = NoExecute>(config: ToolOptions<Input, Success, (input: ToolInputType<Input>, context: Partial<ToolExecuteContext> & {
311
311
  signal: AbortSignal;
312
- }) => Result>) => 0 extends 1 & Result ? import("./tool.js").ExecutableTool<Parameters, Success> : [Result, NoExecute] extends [NoExecute, Result] ? import("./tool.js").Tool<Parameters, Success> : import("./tool.js").ExecutableTool<Parameters, Success>;
312
+ }) => Result>) => 0 extends 1 & Result ? import("./tool.js").ExecutableTool<Input, Success> : [Result, NoExecute] extends [NoExecute, Result] ? import("./tool.js").Tool<Input, Success> : import("./tool.js").ExecutableTool<Input, Success>;
313
313
  /** Default client over `RequestExecutor.fetchLayer`; the runtime builds its layer on first use and holds nothing to dispose. */
314
314
  export declare const ai: Omit<Client, "dispose">;
315
315
  export * as AI from "./index.js";
@@ -322,5 +322,5 @@ export { ChoiceAnswer, ChoiceQuestion, ChoiceValue, DecisionAnswer, DecisionJson
322
322
  export type { AnswerFor, AnswersFor, DecisionInput, DecisionModelOptions, DecisionOptions, DecisionQuestions, DecisionRequestFor, DecisionRequestInput, DecisionResponseFor, DecisionModelRoute, } from "./decision.js";
323
323
  export { Media } from "./media.js";
324
324
  export type { AwaitOptions as GenerationAwaitOptions, Event as GenerationEvent, Poll, Route as GenerationRoute, Snapshot as GenerationSnapshot, Status as GenerationStatus, } from "./generation.js";
325
- export type { ExecutableTool, Tool, ToolExecute, ToolExecuteContext, ToolModelOutputInput, ToolOptions, ToolSchema, ToolToModelOutput, } from "./tool.js";
325
+ export type { ExecutableTool, Tool, ToolExecute, ToolExecuteContext, ToolInput, ToolInputType, ToolModelOutputInput, ToolOptions, ToolSchema, ToolToModelOutput, } from "./tool.js";
326
326
  export type { LLM } from "./llm.js";
package/dist/index.js CHANGED
@@ -130,8 +130,8 @@ const fileError = (message, cause) => new AIError({ reason: new InvalidRequestEr
130
130
  export const tool = (config) => {
131
131
  const execute = config.execute;
132
132
  return build(config, execute &&
133
- ((params, context) => Effect.tryPromise({
134
- try: async (signal) => execute(params, { ...context, signal }),
133
+ ((input, context) => Effect.tryPromise({
134
+ try: async (signal) => execute(input, { ...context, signal }),
135
135
  catch: (error) => new ToolFailure({ message: error instanceof Error ? error.message : String(error), error }),
136
136
  })));
137
137
  };
package/dist/llm.js CHANGED
@@ -73,11 +73,7 @@ const prepare = (input) => {
73
73
  const { schema, ...rest } = input;
74
74
  return tryRequest(() => {
75
75
  const description = "Return the structured result by calling this tool.";
76
- const output = schema === undefined
77
- ? undefined
78
- : Schema.isSchema(schema)
79
- ? tool({ name: OBJECT_TOOL, description, parameters: schema })
80
- : tool({ name: OBJECT_TOOL, description, jsonSchema: schema });
76
+ const output = schema === undefined ? undefined : tool({ name: OBJECT_TOOL, description, input: schema });
81
77
  const tools = rest.tools ?? [];
82
78
  const built = request(output === undefined
83
79
  ? rest
package/dist/tool.d.ts CHANGED
@@ -3,30 +3,34 @@ import type { Content } from "@opencode/schema/tool";
3
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
- * Schema constraint for tool parameters / success values: no decoding or
6
+ * Schema constraint for tool input / success values: no decoding or
7
7
  * encoding services are allowed. Tools should be self-contained — anything
8
8
  * beyond pure data conversion belongs in the handler closure.
9
9
  */
10
10
  export type ToolSchema<T> = Schema.Codec<T, any, never, never>;
11
+ /** A tool's `input`: an Effect Schema decodes and types it; a raw JSON Schema leaves it `unknown`. */
12
+ export type ToolInput = ToolSchema<any> | JsonSchema.JsonSchema;
13
+ /** The value `execute` receives for a tool `input`. */
14
+ export type ToolInputType<Input extends ToolInput> = Input extends ToolSchema<infer T> ? T : unknown;
11
15
  export interface ToolExecuteContext {
12
16
  readonly id: ToolCallPart["id"];
13
17
  readonly name: ToolCallPart["name"];
14
18
  readonly namespace?: ToolCallPart["namespace"];
15
19
  }
16
- export type ToolExecute<Parameters extends ToolSchema<any>, Success extends ToolSchema<any>> = (params: Schema.Schema.Type<Parameters>, context?: ToolExecuteContext) => Effect.Effect<Schema.Schema.Type<Success>, ToolFailure>;
17
- export interface ToolModelOutputInput<Parameters, Output> {
20
+ export type ToolExecute<Input extends ToolInput, Success extends ToolSchema<any>> = (input: ToolInputType<Input>, context?: ToolExecuteContext) => Effect.Effect<Schema.Schema.Type<Success>, ToolFailure>;
21
+ export interface ToolModelOutputInput<Input, Output> {
18
22
  readonly id: ToolCallPart["id"];
19
- readonly parameters: Parameters;
23
+ readonly input: Input;
20
24
  readonly output: Output;
21
25
  }
22
- export type ToolToModelOutput<Parameters extends ToolSchema<any>, Success extends ToolSchema<any>> = (input: ToolModelOutputInput<Schema.Schema.Type<Parameters>, Success["Encoded"]>) => ReadonlyArray<Content>;
26
+ export type ToolToModelOutput<Input extends ToolInput, Success extends ToolSchema<any>> = (result: ToolModelOutputInput<ToolInputType<Input>, Success["Encoded"]>) => ReadonlyArray<Content>;
23
27
  type FreeformField<T> = {
24
28
  [K in keyof T]-?: [Exclude<keyof T, K>] extends [never] ? {} extends Pick<T, K> ? never : T[K] extends string ? K : never : never;
25
29
  }[keyof T];
26
- /** `Freeform` for exactly one required string parameter or unknown ones (`jsonSchema`), otherwise `undefined`. */
27
- export type FreeformOption<Parameters extends ToolSchema<any>> = unknown extends Schema.Schema.Type<Parameters> ? Freeform : [FreeformField<Schema.Schema.Type<Parameters>>] extends [never] ? undefined : Freeform;
30
+ /** `Freeform` for exactly one required string field or unknown ones (a JSON Schema `input`), otherwise `undefined`. */
31
+ export type FreeformOption<Input extends ToolInput> = unknown extends ToolInputType<Input> ? Freeform : [FreeformField<ToolInputType<Input>>] extends [never] ? undefined : Freeform;
28
32
  /**
29
- * A type-safe LLM tool. Each tool bundles its own description, parameter
33
+ * A type-safe LLM tool. Each tool bundles its own description, input
30
34
  * Schema and success Schema. The execute handler is optional: omit it when you
31
35
  * only want to expose a tool schema to the model and handle tool calls outside
32
36
  * this package.
@@ -37,48 +41,47 @@ export type FreeformOption<Parameters extends ToolSchema<any>> = unknown extends
37
41
  * Internally each tool also carries memoized codecs and a precomputed
38
42
  * `ToolDefinition` so callers do not rebuild them per invocation.
39
43
  */
40
- export interface Tool<Parameters extends ToolSchema<any> = any, Success extends ToolSchema<any> = any> {
44
+ export interface Tool<Input extends ToolInput = any, Success extends ToolSchema<any> = any> {
41
45
  /** The tool name the model sees and calls. */
42
46
  readonly name: string;
43
47
  readonly description: string;
44
- readonly parameters: Parameters;
48
+ readonly input: Input;
45
49
  readonly success: Success;
46
- readonly execute?: ToolExecute<Parameters, Success>;
47
- readonly toModelOutput?: ToolToModelOutput<Parameters, Success>;
50
+ readonly execute?: ToolExecute<Input, Success>;
51
+ readonly toModelOutput?: ToolToModelOutput<Input, Success>;
48
52
  readonly toStructuredOutput?: (output: Success["Encoded"]) => unknown;
49
53
  /** @internal */
50
- readonly _decode: (input: unknown) => Effect.Effect<Schema.Schema.Type<Parameters>, Schema.SchemaError>;
54
+ readonly _decode: (input: unknown) => Effect.Effect<ToolInputType<Input>, Schema.SchemaError>;
51
55
  /** @internal */
52
56
  _encode(value: Schema.Schema.Type<Success>): Effect.Effect<unknown, Schema.SchemaError>;
53
57
  /** @internal */
54
- _project(parameters: Schema.Schema.Type<Parameters>, id: ToolCallPart["id"], output: unknown): ToolOutputType;
58
+ _project(input: ToolInputType<Input>, id: ToolCallPart["id"], output: unknown): ToolOutputType;
55
59
  /** @internal */
56
60
  readonly _legacyResult: boolean;
57
61
  /** @internal */
58
62
  readonly _definition: ToolDefinitionClass;
59
63
  }
60
64
  /** A tool with an `execute` handler, which `LLM.loop` and `ToolRuntime.dispatch` can run. */
61
- export type ExecutableTool<Parameters extends ToolSchema<any> = any, Success extends ToolSchema<any> = any> = Tool<Parameters, Success> & {
62
- readonly execute: ToolExecute<Parameters, Success>;
65
+ export type ExecutableTool<Input extends ToolInput = any, Success extends ToolSchema<any> = any> = Tool<Input, Success> & {
66
+ readonly execute: ToolExecute<Input, Success>;
63
67
  };
64
68
  /**
65
- * Options for `tool`, where `Execute` is the only part that differs between the Effect and Promise clients. Pass
66
- * Effect `parameters` (and optionally a `success` schema that validates the result, otherwise it is sent as is with
67
- * `undefined` as `null`), or raw `jsonSchema` known only at runtime, such as an MCP tool's. Omit `execute` to declare
68
- * a tool the model can call without running it here.
69
+ * Options for `tool`, where `Execute` is the only part that differs between the Effect and Promise clients. Pass an
70
+ * Effect Schema `input` (and optionally a `success` schema that validates the result, otherwise it is sent as is with
71
+ * `undefined` as `null`), or a raw JSON Schema `input` known only at runtime, such as an MCP tool's, with an optional
72
+ * JSON Schema `outputSchema`. Omit `execute` to declare a tool the model can call without running it here.
69
73
  */
70
- export type ToolOptions<Parameters extends ToolSchema<any>, Success extends ToolSchema<any>, Execute = ToolExecute<Parameters, Success>> = {
74
+ export type ToolOptions<Input extends ToolInput, Success extends ToolSchema<any>, Execute = ToolExecute<Input, Success>> = {
71
75
  readonly name: string;
72
76
  readonly description: string;
73
- readonly freeform?: FreeformOption<Parameters>;
77
+ readonly input: Input;
78
+ readonly freeform?: FreeformOption<Input>;
74
79
  readonly execute?: Execute;
75
- readonly toModelOutput?: ToolToModelOutput<Parameters, Success>;
80
+ readonly toModelOutput?: ToolToModelOutput<Input, Success>;
76
81
  readonly toStructuredOutput?: (output: Success["Encoded"]) => unknown;
77
- } & ({
78
- readonly parameters: Parameters;
82
+ } & (Input extends ToolSchema<any> ? {
79
83
  readonly success?: Success;
80
- } | {
81
- readonly jsonSchema: JsonSchema.JsonSchema;
84
+ } : {
82
85
  readonly outputSchema?: JsonSchema.JsonSchema;
83
86
  });
84
87
  /**
@@ -88,20 +91,20 @@ export type ToolOptions<Parameters extends ToolSchema<any>, Success extends Tool
88
91
  * tool({
89
92
  * name: "weather",
90
93
  * description: "Get current weather",
91
- * parameters: Schema.Struct({ city: Schema.String }),
94
+ * input: Schema.Struct({ city: Schema.String }),
92
95
  * success: Schema.Struct({ temperature: Schema.Number }),
93
96
  * execute: ({ city }) => Effect.succeed({ temperature: 22 }),
94
97
  * })
95
98
  * ```
96
99
  */
97
- export declare const tool: <Parameters extends ToolSchema<any> = typeof Schema.Unknown, Success extends ToolSchema<any> = typeof Schema.Unknown, Result extends Effect.Effect<Schema.Schema.Type<Success>, ToolFailure> | NoExecute = NoExecute>(config: ToolOptions<Parameters, Success, (params: Schema.Schema.Type<Parameters>, context?: ToolExecuteContext) => Result>) => 0 extends 1 & Result ? ExecutableTool<Parameters, Success> : [Result, NoExecute] extends [NoExecute, Result] ? Tool<Parameters, Success> : ExecutableTool<Parameters, Success>;
100
+ export declare const tool: <Input extends ToolInput = typeof Schema.Unknown, Success extends ToolSchema<any> = typeof Schema.Unknown, Result extends Effect.Effect<Schema.Schema.Type<Success>, ToolFailure> | NoExecute = NoExecute>(config: ToolOptions<Input, Success, (input: ToolInputType<Input>, context?: ToolExecuteContext) => Result>) => 0 extends 1 & Result ? ExecutableTool<Input, Success> : [Result, NoExecute] extends [NoExecute, Result] ? Tool<Input, Success> : ExecutableTool<Input, Success>;
98
101
  declare const noExecute: unique symbol;
99
102
  /** @internal The inferred `execute` result when `execute` is omitted; no function can return it. */
100
103
  export type NoExecute = {
101
104
  readonly [noExecute]: never;
102
105
  };
103
106
  /** @internal Builds a tool for both clients from its options and an Effect `execute`. */
104
- export declare function build<Parameters extends ToolSchema<any>, Success extends ToolSchema<any>, Result>(config: ToolOptions<Parameters, Success, (...args: never) => Result>, execute: ((params: Schema.Schema.Type<Parameters>, context?: ToolExecuteContext) => unknown) | undefined): 0 extends 1 & Result ? ExecutableTool<Parameters, Success> : [Result, NoExecute] extends [NoExecute, Result] ? Tool<Parameters, Success> : ExecutableTool<Parameters, Success>;
107
+ export declare function build<Input extends ToolInput, Success extends ToolSchema<any>, Result>(config: ToolOptions<Input, Success, (...args: never) => Result>, execute: ((input: ToolInputType<Input>, context?: ToolExecuteContext) => unknown) | undefined): 0 extends 1 & Result ? ExecutableTool<Input, Success> : [Result, NoExecute] extends [NoExecute, Result] ? Tool<Input, Success> : ExecutableTool<Input, Success>;
105
108
  /** The `ToolDefinition[]` that `LLMRequest.tools` expects, in array order. */
106
109
  export declare const toDefinitions: (tools: ReadonlyArray<Tool>) => ReadonlyArray<ToolDefinitionClass>;
107
110
  /**
package/dist/tool.js CHANGED
@@ -8,7 +8,7 @@ import { isRecord } from "./utils/record.js";
8
8
  * tool({
9
9
  * name: "weather",
10
10
  * description: "Get current weather",
11
- * parameters: Schema.Struct({ city: Schema.String }),
11
+ * input: Schema.Struct({ city: Schema.String }),
12
12
  * success: Schema.Struct({ temperature: Schema.Number }),
13
13
  * execute: ({ city }) => Effect.succeed({ temperature: 22 }),
14
14
  * })
@@ -22,12 +22,13 @@ export function build(config, execute) {
22
22
  execute,
23
23
  toModelOutput: config.toModelOutput,
24
24
  toStructuredOutput: config.toStructuredOutput,
25
- _project: (parameters, id, output) => project(config.toModelOutput, config.toStructuredOutput, parameters, id, output),
25
+ _project: (input, id, output) => project(config.toModelOutput, config.toStructuredOutput, input, id, output),
26
26
  };
27
- if ("jsonSchema" in config)
27
+ const input = config.input;
28
+ if (!Schema.isSchema(input))
28
29
  return {
29
30
  ...shared,
30
- parameters: Schema.Unknown,
31
+ input,
31
32
  success: Schema.Unknown,
32
33
  _decode: Effect.succeed,
33
34
  _encode: Effect.succeed,
@@ -35,22 +36,22 @@ export function build(config, execute) {
35
36
  _definition: definition({
36
37
  name: config.name,
37
38
  description: config.description,
38
- inputSchema: config.jsonSchema,
39
+ inputSchema: input,
39
40
  outputSchema: config.outputSchema,
40
41
  freeform: config.freeform,
41
42
  }),
42
43
  };
43
44
  return {
44
45
  ...shared,
45
- parameters: config.parameters,
46
+ input,
46
47
  success: config.success ?? Schema.Unknown,
47
- _decode: Schema.decodeUnknownEffect(config.parameters),
48
+ _decode: Schema.decodeUnknownEffect(input),
48
49
  _encode: config.success ? Schema.encodeEffect(config.success) : (value) => Effect.succeed(value ?? null),
49
50
  _legacyResult: false,
50
51
  _definition: definition({
51
52
  name: config.name,
52
53
  description: config.description,
53
- inputSchema: emptyInputJsonSchema(config.parameters) ?? toJsonSchema(config.parameters),
54
+ inputSchema: emptyInputJsonSchema(input) ?? toJsonSchema(input),
54
55
  outputSchema: config.success && toJsonSchema(config.success),
55
56
  freeform: config.freeform,
56
57
  }),
@@ -87,5 +88,5 @@ const toJsonSchema = (schema) => {
87
88
  return document.schema;
88
89
  return { ...document.schema, $defs: document.definitions };
89
90
  };
90
- const project = (toModelOutput, toStructuredOutput, parameters, id, output) => ToolOutput.make(toStructuredOutput?.(output) ?? output, toModelOutput?.({ id, parameters, output }) ?? (typeof output === "string" ? [{ type: "text", text: output }] : []));
91
+ const project = (toModelOutput, toStructuredOutput, input, id, output) => ToolOutput.make(toStructuredOutput?.(output) ?? output, toModelOutput?.({ id, input, output }) ?? (typeof output === "string" ? [{ type: "text", text: output }] : []));
91
92
  export { ToolFailure };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "$schema": "https://json.schemastore.org/package.json",
3
- "version": "0.0.0-dev-451",
3
+ "version": "0.0.0-dev-457",
4
4
  "name": "@opencode/ai",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -520,7 +520,7 @@
520
520
  "devDependencies": {
521
521
  "@clack/prompts": "1.0.0-alpha.1",
522
522
  "@effect/platform-node": "4.1.0",
523
- "@opencode/http-recorder": "0.0.0-dev-451",
523
+ "@opencode/http-recorder": "0.0.0-dev-457",
524
524
  "@tsconfig/bun": "1.0.9",
525
525
  "@types/bun": "1.4.3",
526
526
  "@typescript/native": "npm:typescript@7.1.0-beta",
@@ -530,7 +530,7 @@
530
530
  "@aws-sdk/credential-providers": "3.1057.0",
531
531
  "@smithy/eventstream-codec": "4.2.14",
532
532
  "@smithy/util-utf8": "4.2.2",
533
- "@opencode/schema": "0.0.0-dev-451",
533
+ "@opencode/schema": "0.0.0-dev-457",
534
534
  "aws4fetch": "1.0.20",
535
535
  "effect": "4.1.0",
536
536
  "google-auth-library": "10.5.0"