@opencode/ai 2.2.4 → 2.2.6
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 +133 -69
- package/dist/cache-policy.d.ts +1 -1
- package/dist/cache-policy.js +16 -4
- package/dist/decision-client.d.ts +3 -3
- package/dist/decision.d.ts +20 -125
- package/dist/decision.js +25 -15
- package/dist/effect.d.ts +4 -15
- package/dist/effect.js +2 -6
- package/dist/effort-updates.d.ts +3 -3
- package/dist/effort-updates.js +2 -2
- package/dist/experimental/cloudflare-run-extraction.d.ts +7 -3
- package/dist/experimental/cloudflare-run-extraction.js +4 -1
- package/dist/experimental/extraction.d.ts +10 -40
- package/dist/experimental/extraction.js +14 -13
- package/dist/experimental.d.ts +8 -8
- package/dist/experimental.js +4 -4
- package/dist/generation.d.ts +0 -2
- package/dist/generation.js +2 -2
- package/dist/image-client.d.ts +13 -7
- package/dist/image-client.js +1 -1
- package/dist/image.d.ts +357 -464
- package/dist/image.js +17 -15
- package/dist/index.d.ts +28 -465
- package/dist/index.js +18 -17
- package/dist/llm.d.ts +65 -266
- package/dist/llm.js +101 -92
- package/dist/loop.d.ts +38 -0
- package/dist/loop.js +136 -0
- package/dist/media-model.d.ts +1 -1
- package/dist/media-model.js +8 -6
- package/dist/media.d.ts +9 -0
- package/dist/media.js +37 -2
- package/dist/protocols/alibaba-chat.d.ts +5 -1
- package/dist/protocols/alibaba-chat.js +3 -3
- package/dist/protocols/alibaba-images.d.ts +2 -2
- package/dist/protocols/alibaba-messages.js +3 -3
- package/dist/protocols/alibaba-responses.js +8 -20
- package/dist/protocols/anthropic-messages.d.ts +1 -1
- package/dist/protocols/anthropic-messages.js +57 -185
- package/dist/protocols/assemblyai-transcription.d.ts +2 -2
- package/dist/protocols/bedrock-converse.js +11 -22
- package/dist/protocols/cartesia-speech.d.ts +2 -2
- package/dist/protocols/cloudflare-workers-ai-images.d.ts +2 -2
- package/dist/protocols/cohere-chat.js +9 -12
- package/dist/protocols/deepgram-speech.d.ts +2 -2
- package/dist/protocols/deepgram-transcription.d.ts +2 -2
- package/dist/protocols/elevenlabs-speech.d.ts +2 -2
- package/dist/protocols/elevenlabs-transcription.d.ts +2 -2
- package/dist/protocols/gemini.d.ts +3 -0
- package/dist/protocols/gemini.js +56 -89
- package/dist/protocols/google-images.d.ts +2 -2
- package/dist/protocols/google-interactions.d.ts +3 -4
- package/dist/protocols/google-interactions.js +54 -32
- package/dist/protocols/google-speech.d.ts +2 -2
- package/dist/protocols/google-transcription.d.ts +2 -2
- package/dist/protocols/google-video.d.ts +2 -2
- package/dist/protocols/meta-images.d.ts +2 -2
- package/dist/protocols/meta-responses.js +26 -23
- package/dist/protocols/minimax-images.d.ts +2 -2
- package/dist/protocols/mistral-chat.js +14 -20
- package/dist/protocols/open-responses-channel.js +6 -19
- package/dist/protocols/open-responses-continuation.d.ts +1 -5
- package/dist/protocols/open-responses-continuation.js +1 -3
- package/dist/protocols/open-responses.d.ts +1 -21
- package/dist/protocols/open-responses.js +10 -15
- package/dist/protocols/openai-chat.d.ts +3 -23
- package/dist/protocols/openai-chat.js +26 -47
- package/dist/protocols/openai-compatible-chat.d.ts +1 -1
- package/dist/protocols/openai-compatible-responses.d.ts +2 -2
- package/dist/protocols/openai-compatible-responses.js +1 -1
- package/dist/protocols/openai-decisions.js +1 -1
- package/dist/protocols/openai-images.d.ts +2 -2
- package/dist/protocols/openai-responses.js +10 -29
- package/dist/protocols/openai-speech.d.ts +2 -2
- package/dist/protocols/openai-transcription.d.ts +2 -2
- package/dist/protocols/runway-video.d.ts +2 -2
- package/dist/protocols/shared.d.ts +1 -4
- package/dist/protocols/shared.js +13 -11
- package/dist/protocols/system-one.d.ts +4 -4
- package/dist/protocols/utils/bedrock-cache.js +2 -5
- package/dist/protocols/utils/bedrock-media.d.ts +0 -3
- package/dist/protocols/utils/cache.d.ts +3 -0
- package/dist/protocols/utils/cache.js +15 -2
- package/dist/protocols/utils/image-sizing.d.ts +1 -1
- package/dist/protocols/utils/responses-checkpoint.js +1 -1
- package/dist/protocols/utils/responses-compaction.d.ts +1 -1
- package/dist/protocols/utils/responses-compaction.js +6 -5
- package/dist/protocols/utils/responses-hosted-tools.d.ts +97 -1
- package/dist/protocols/utils/responses-hosted-tools.js +31 -0
- package/dist/protocols/utils/tool-stream.d.ts +5 -271
- package/dist/protocols/utils/tool-stream.js +3 -13
- package/dist/protocols/venice-chat.d.ts +3 -1
- package/dist/protocols/venice-chat.js +4 -4
- package/dist/protocols/xai-images.d.ts +2 -2
- package/dist/protocols/xai-responses.js +5 -25
- package/dist/protocols/xai-video.d.ts +2 -2
- package/dist/protocols/zai-chat.d.ts +5 -1
- package/dist/protocols/zai-chat.js +1 -1
- package/dist/protocols/zai-images.d.ts +2 -2
- package/dist/protocols/zai-messages.js +3 -3
- package/dist/provider-error.d.ts +0 -1
- package/dist/provider-error.js +9 -80
- package/dist/providers/alibaba.d.ts +67 -4
- package/dist/providers/alibaba.js +6 -1
- package/dist/providers/amazon-bedrock-mantle.d.ts +6 -3
- package/dist/providers/amazon-bedrock-mantle.js +6 -3
- package/dist/providers/amazon-bedrock.d.ts +6 -7
- package/dist/providers/amazon-bedrock.js +1 -1
- package/dist/providers/anthropic-compatible.d.ts +7 -8
- package/dist/providers/anthropic-compatible.js +2 -5
- package/dist/providers/anthropic.d.ts +8 -9
- package/dist/providers/anthropic.js +2 -7
- package/dist/providers/assemblyai.d.ts +2 -2
- package/dist/providers/assemblyai.js +2 -7
- package/dist/providers/azure/messages.d.ts +2 -0
- package/dist/providers/azure/messages.js +1 -0
- package/dist/providers/azure.d.ts +322 -7
- package/dist/providers/azure.js +25 -9
- package/dist/providers/baseten.d.ts +5 -5
- package/dist/providers/baseten.js +7 -21
- package/dist/providers/cartesia.d.ts +1 -1
- package/dist/providers/cerebras.d.ts +5 -5
- package/dist/providers/cerebras.js +4 -15
- package/dist/providers/cloudflare-ai-gateway.d.ts +21 -13
- package/dist/providers/cloudflare-ai-gateway.js +28 -40
- package/dist/providers/cloudflare-shared.d.ts +9 -0
- package/dist/providers/cloudflare-shared.js +25 -0
- package/dist/providers/cloudflare-workers-ai.d.ts +4 -4
- package/dist/providers/cloudflare-workers-ai.js +4 -20
- package/dist/providers/cohere/chat.js +2 -7
- package/dist/providers/cohere.d.ts +6 -5
- package/dist/providers/cohere.js +7 -13
- package/dist/providers/deepgram.d.ts +2 -2
- package/dist/providers/deepgram.js +2 -7
- package/dist/providers/deepinfra.d.ts +5 -5
- package/dist/providers/deepinfra.js +5 -13
- package/dist/providers/deepseek.d.ts +5 -5
- package/dist/providers/deepseek.js +3 -14
- package/dist/providers/digitalocean.d.ts +8 -5
- package/dist/providers/digitalocean.js +13 -14
- package/dist/providers/elevenlabs.d.ts +2 -2
- package/dist/providers/elevenlabs.js +2 -7
- package/dist/providers/fireworks.d.ts +5 -5
- package/dist/providers/fireworks.js +4 -15
- package/dist/providers/google/interactions.d.ts +1 -1
- package/dist/providers/google/interactions.js +2 -7
- package/dist/providers/google-vertex-chat.d.ts +3 -3
- package/dist/providers/google-vertex-chat.js +3 -29
- package/dist/providers/google-vertex-interactions.d.ts +3 -3
- package/dist/providers/google-vertex-messages.d.ts +3 -3
- package/dist/providers/google-vertex-messages.js +3 -29
- package/dist/providers/google-vertex-mistral.d.ts +3 -3
- package/dist/providers/google-vertex-mistral.js +3 -29
- package/dist/providers/google-vertex-responses.d.ts +3 -3
- package/dist/providers/google-vertex-responses.js +4 -30
- package/dist/providers/google-vertex-shared.d.ts +31 -0
- package/dist/providers/google-vertex-shared.js +25 -0
- package/dist/providers/google-vertex.d.ts +3 -3
- package/dist/providers/google.d.ts +15 -13
- package/dist/providers/google.js +9 -19
- package/dist/providers/groq.d.ts +5 -5
- package/dist/providers/groq.js +4 -15
- package/dist/providers/meta.d.ts +5 -5
- package/dist/providers/meta.js +10 -24
- package/dist/providers/minimax/chat.js +2 -7
- package/dist/providers/minimax/responses.js +2 -7
- package/dist/providers/minimax.d.ts +5 -5
- package/dist/providers/minimax.js +11 -23
- package/dist/providers/mistral.d.ts +10 -11
- package/dist/providers/mistral.js +3 -14
- package/dist/providers/moonshot/messages.js +2 -7
- package/dist/providers/moonshot/responses.js +2 -7
- package/dist/providers/moonshot.d.ts +5 -5
- package/dist/providers/moonshot.js +4 -16
- package/dist/providers/openai-compatible-responses.d.ts +6 -7
- package/dist/providers/openai-compatible-responses.js +2 -8
- package/dist/providers/openai-compatible.d.ts +6 -7
- package/dist/providers/openai-compatible.js +4 -10
- package/dist/providers/openai.d.ts +4 -4
- package/dist/providers/openai.js +3 -3
- package/dist/providers/opencode.d.ts +4 -4
- package/dist/providers/opencode.js +6 -2
- package/dist/providers/openrouter.d.ts +8 -5
- package/dist/providers/openrouter.js +16 -24
- package/dist/providers/runway.d.ts +1 -1
- package/dist/providers/settings.d.ts +40 -0
- package/dist/providers/settings.js +19 -0
- package/dist/providers/togetherai.d.ts +5 -5
- package/dist/providers/togetherai.js +5 -15
- package/dist/providers/typesafe-ai.d.ts +4 -4
- package/dist/providers/typesafe-ai.js +6 -2
- package/dist/providers/venice.d.ts +4 -4
- package/dist/providers/venice.js +6 -2
- package/dist/providers/vercel-ai-gateway.d.ts +5 -5
- package/dist/providers/vercel-ai-gateway.js +15 -28
- package/dist/providers/xai.d.ts +4 -4
- package/dist/providers/xai.js +4 -12
- package/dist/providers/zai-coding-plan/messages.js +2 -7
- package/dist/providers/zai-coding-plan/responses.js +2 -7
- package/dist/providers/zai-coding-plan.d.ts +5 -5
- package/dist/providers/zai-coding-plan.js +8 -15
- package/dist/providers/zai.d.ts +5 -5
- package/dist/providers/zai.js +10 -22
- package/dist/public.d.ts +12 -0
- package/dist/public.js +5 -0
- package/dist/route/auth-options.d.ts +9 -5
- package/dist/route/auth-options.js +10 -7
- package/dist/route/client.d.ts +50 -37
- package/dist/route/client.js +42 -53
- package/dist/route/decision.d.ts +8 -8
- package/dist/route/decision.js +3 -3
- package/dist/route/executor.d.ts +5 -0
- package/dist/route/executor.js +10 -0
- package/dist/route/index.d.ts +5 -7
- package/dist/route/index.js +1 -1
- package/dist/route/media.d.ts +7 -11
- package/dist/route/media.js +22 -26
- package/dist/route/transport/http.js +6 -5
- package/dist/route/transport/websocket.js +7 -1
- package/dist/schema/errors.d.ts +16 -17
- package/dist/schema/errors.js +63 -12
- package/dist/schema/events.d.ts +2563 -2954
- package/dist/schema/events.js +54 -109
- package/dist/schema/messages.d.ts +194 -137
- package/dist/schema/messages.js +66 -83
- package/dist/schema/options.d.ts +112 -65
- package/dist/schema/options.js +52 -101
- package/dist/speech-client.d.ts +7 -7
- package/dist/speech.d.ts +306 -316
- package/dist/speech.js +16 -14
- package/dist/testing.d.ts +31 -175
- package/dist/testing.js +60 -5
- package/dist/tool-history.d.ts +1 -1
- package/dist/tool-history.js +3 -10
- package/dist/tool-runtime.d.ts +9 -2
- package/dist/tool-runtime.js +17 -31
- package/dist/tool.d.ts +39 -43
- package/dist/tool.js +16 -26
- package/dist/transcription-client.d.ts +7 -7
- package/dist/transcription.d.ts +314 -265
- package/dist/transcription.js +16 -14
- package/dist/utils/provider-codes.d.ts +3 -0
- package/dist/utils/provider-codes.js +41 -0
- package/dist/video-client.d.ts +7 -7
- package/dist/video-client.js +1 -1
- package/dist/video.d.ts +269 -287
- package/dist/video.js +16 -14
- package/package.json +9 -9
- package/dist/experimental/testing.d.ts +0 -3
- package/dist/experimental/testing.js +0 -3
- package/dist/testing/decision.d.ts +0 -16
- package/dist/testing/decision.js +0 -20
- package/dist/testing/image.d.ts +0 -14
- package/dist/testing/image.js +0 -12
- package/dist/testing/media.d.ts +0 -18
- package/dist/testing/media.js +0 -36
- package/dist/testing/script.d.ts +0 -28
- package/dist/testing/script.js +0 -60
- package/dist/testing/speech.d.ts +0 -14
- package/dist/testing/speech.js +0 -12
- package/dist/testing/transcription.d.ts +0 -14
- package/dist/testing/transcription.js +0 -12
- package/dist/testing/video.d.ts +0 -14
- package/dist/testing/video.js +0 -12
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
|
|
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<
|
|
17
|
-
export interface ToolModelOutputInput<
|
|
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
|
|
23
|
+
readonly input: Input;
|
|
20
24
|
readonly output: Output;
|
|
21
25
|
}
|
|
22
|
-
export type ToolToModelOutput<
|
|
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
|
|
27
|
-
export type FreeformOption<
|
|
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,
|
|
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,45 +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<
|
|
44
|
+
export interface Tool<Input extends ToolInput = any, Success extends ToolSchema<any> = any> {
|
|
45
|
+
/** The tool name the model sees and calls. */
|
|
46
|
+
readonly name: string;
|
|
41
47
|
readonly description: string;
|
|
42
|
-
readonly
|
|
48
|
+
readonly input: Input;
|
|
43
49
|
readonly success: Success;
|
|
44
|
-
readonly execute?: ToolExecute<
|
|
45
|
-
readonly toModelOutput?: ToolToModelOutput<
|
|
50
|
+
readonly execute?: ToolExecute<Input, Success>;
|
|
51
|
+
readonly toModelOutput?: ToolToModelOutput<Input, Success>;
|
|
46
52
|
readonly toStructuredOutput?: (output: Success["Encoded"]) => unknown;
|
|
47
53
|
/** @internal */
|
|
48
|
-
readonly _decode: (input: unknown) => Effect.Effect<
|
|
54
|
+
readonly _decode: (input: unknown) => Effect.Effect<ToolInputType<Input>, Schema.SchemaError>;
|
|
49
55
|
/** @internal */
|
|
50
56
|
_encode(value: Schema.Schema.Type<Success>): Effect.Effect<unknown, Schema.SchemaError>;
|
|
51
57
|
/** @internal */
|
|
52
|
-
_project(
|
|
58
|
+
_project(input: ToolInputType<Input>, id: ToolCallPart["id"], output: unknown): ToolOutputType;
|
|
53
59
|
/** @internal */
|
|
54
60
|
readonly _legacyResult: boolean;
|
|
55
61
|
/** @internal */
|
|
56
62
|
readonly _definition: ToolDefinitionClass;
|
|
57
63
|
}
|
|
58
64
|
/** A tool with an `execute` handler, which `LLM.loop` and `ToolRuntime.dispatch` can run. */
|
|
59
|
-
export type ExecutableTool<
|
|
60
|
-
readonly execute: ToolExecute<
|
|
65
|
+
export type ExecutableTool<Input extends ToolInput = any, Success extends ToolSchema<any> = any> = Tool<Input, Success> & {
|
|
66
|
+
readonly execute: ToolExecute<Input, Success>;
|
|
61
67
|
};
|
|
62
68
|
/**
|
|
63
|
-
* Options for `tool`, where `Execute` is the only part that differs between the Effect and Promise clients. Pass
|
|
64
|
-
* Effect `
|
|
65
|
-
* `undefined` as `null`), or raw `
|
|
66
|
-
* 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.
|
|
67
73
|
*/
|
|
68
|
-
export type ToolOptions<
|
|
74
|
+
export type ToolOptions<Input extends ToolInput, Success extends ToolSchema<any>, Execute = ToolExecute<Input, Success>> = {
|
|
75
|
+
readonly name: string;
|
|
69
76
|
readonly description: string;
|
|
70
|
-
readonly
|
|
77
|
+
readonly input: Input;
|
|
78
|
+
readonly freeform?: FreeformOption<Input>;
|
|
71
79
|
readonly execute?: Execute;
|
|
72
|
-
readonly toModelOutput?: ToolToModelOutput<
|
|
80
|
+
readonly toModelOutput?: ToolToModelOutput<Input, Success>;
|
|
73
81
|
readonly toStructuredOutput?: (output: Success["Encoded"]) => unknown;
|
|
74
|
-
} & ({
|
|
75
|
-
readonly parameters: Parameters;
|
|
82
|
+
} & (Input extends ToolSchema<any> ? {
|
|
76
83
|
readonly success?: Success;
|
|
77
|
-
}
|
|
78
|
-
readonly jsonSchema: JsonSchema.JsonSchema;
|
|
84
|
+
} : {
|
|
79
85
|
readonly outputSchema?: JsonSchema.JsonSchema;
|
|
80
86
|
});
|
|
81
87
|
/**
|
|
@@ -83,34 +89,24 @@ export type ToolOptions<Parameters extends ToolSchema<any>, Success extends Tool
|
|
|
83
89
|
*
|
|
84
90
|
* ```ts
|
|
85
91
|
* tool({
|
|
92
|
+
* name: "weather",
|
|
86
93
|
* description: "Get current weather",
|
|
87
|
-
*
|
|
94
|
+
* input: Schema.Struct({ city: Schema.String }),
|
|
88
95
|
* success: Schema.Struct({ temperature: Schema.Number }),
|
|
89
96
|
* execute: ({ city }) => Effect.succeed({ temperature: 22 }),
|
|
90
97
|
* })
|
|
91
98
|
* ```
|
|
92
99
|
*/
|
|
93
|
-
export declare const tool: <
|
|
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>;
|
|
94
101
|
declare const noExecute: unique symbol;
|
|
95
102
|
/** @internal The inferred `execute` result when `execute` is omitted; no function can return it. */
|
|
96
103
|
export type NoExecute = {
|
|
97
104
|
readonly [noExecute]: never;
|
|
98
105
|
};
|
|
99
106
|
/** @internal Builds a tool for both clients from its options and an Effect `execute`. */
|
|
100
|
-
export declare function build<
|
|
101
|
-
/**
|
|
102
|
-
|
|
103
|
-
*/
|
|
104
|
-
export type Tools = Record<string, Tool>;
|
|
105
|
-
/**
|
|
106
|
-
* Convert a tools record into the `ToolDefinition[]` shape that
|
|
107
|
-
* `LLMRequest.tools` expects.
|
|
108
|
-
*
|
|
109
|
-
* Tool names come from the record keys, so the per-tool cached
|
|
110
|
-
* `_definition` is rebuilt with the correct name here. The JSON Schema body
|
|
111
|
-
* is reused.
|
|
112
|
-
*/
|
|
113
|
-
export declare const toDefinitions: (tools: Tools) => ReadonlyArray<ToolDefinitionClass>;
|
|
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>;
|
|
108
|
+
/** The `ToolDefinition[]` that `LLMRequest.tools` expects, in array order. */
|
|
109
|
+
export declare const toDefinitions: (tools: ReadonlyArray<Tool>) => ReadonlyArray<ToolDefinitionClass>;
|
|
114
110
|
/**
|
|
115
111
|
* Describes a no-argument Effect tool input as an empty object, or returns
|
|
116
112
|
* `undefined` when the input takes arguments.
|
package/dist/tool.js
CHANGED
|
@@ -6,8 +6,9 @@ import { isRecord } from "./utils/record.js";
|
|
|
6
6
|
*
|
|
7
7
|
* ```ts
|
|
8
8
|
* tool({
|
|
9
|
+
* name: "weather",
|
|
9
10
|
* description: "Get current weather",
|
|
10
|
-
*
|
|
11
|
+
* input: Schema.Struct({ city: Schema.String }),
|
|
11
12
|
* success: Schema.Struct({ temperature: Schema.Number }),
|
|
12
13
|
* execute: ({ city }) => Effect.succeed({ temperature: 22 }),
|
|
13
14
|
* })
|
|
@@ -16,59 +17,48 @@ import { isRecord } from "./utils/record.js";
|
|
|
16
17
|
export const tool = (config) => build(config, config.execute);
|
|
17
18
|
export function build(config, execute) {
|
|
18
19
|
const shared = {
|
|
20
|
+
name: config.name,
|
|
19
21
|
description: config.description,
|
|
20
22
|
execute,
|
|
21
23
|
toModelOutput: config.toModelOutput,
|
|
22
24
|
toStructuredOutput: config.toStructuredOutput,
|
|
23
|
-
_project: (
|
|
25
|
+
_project: (input, id, output) => project(config.toModelOutput, config.toStructuredOutput, input, id, output),
|
|
24
26
|
};
|
|
25
|
-
|
|
27
|
+
const input = config.input;
|
|
28
|
+
if (!Schema.isSchema(input))
|
|
26
29
|
return {
|
|
27
30
|
...shared,
|
|
28
|
-
|
|
31
|
+
input,
|
|
29
32
|
success: Schema.Unknown,
|
|
30
33
|
_decode: Effect.succeed,
|
|
31
34
|
_encode: Effect.succeed,
|
|
32
35
|
_legacyResult: config.toModelOutput === undefined && config.toStructuredOutput === undefined,
|
|
33
36
|
_definition: definition({
|
|
34
|
-
name:
|
|
37
|
+
name: config.name,
|
|
35
38
|
description: config.description,
|
|
36
|
-
inputSchema:
|
|
39
|
+
inputSchema: input,
|
|
37
40
|
outputSchema: config.outputSchema,
|
|
38
41
|
freeform: config.freeform,
|
|
39
42
|
}),
|
|
40
43
|
};
|
|
41
44
|
return {
|
|
42
45
|
...shared,
|
|
43
|
-
|
|
46
|
+
input,
|
|
44
47
|
success: config.success ?? Schema.Unknown,
|
|
45
|
-
_decode: Schema.decodeUnknownEffect(
|
|
48
|
+
_decode: Schema.decodeUnknownEffect(input),
|
|
46
49
|
_encode: config.success ? Schema.encodeEffect(config.success) : (value) => Effect.succeed(value ?? null),
|
|
47
50
|
_legacyResult: false,
|
|
48
51
|
_definition: definition({
|
|
49
|
-
name:
|
|
52
|
+
name: config.name,
|
|
50
53
|
description: config.description,
|
|
51
|
-
inputSchema: emptyInputJsonSchema(
|
|
54
|
+
inputSchema: emptyInputJsonSchema(input) ?? toJsonSchema(input),
|
|
52
55
|
outputSchema: config.success && toJsonSchema(config.success),
|
|
53
56
|
freeform: config.freeform,
|
|
54
57
|
}),
|
|
55
58
|
};
|
|
56
59
|
}
|
|
57
|
-
/**
|
|
58
|
-
|
|
59
|
-
* `LLMRequest.tools` expects.
|
|
60
|
-
*
|
|
61
|
-
* Tool names come from the record keys, so the per-tool cached
|
|
62
|
-
* `_definition` is rebuilt with the correct name here. The JSON Schema body
|
|
63
|
-
* is reused.
|
|
64
|
-
*/
|
|
65
|
-
export const toDefinitions = (tools) => Object.entries(tools).map(([name, item]) => new ToolDefinition({
|
|
66
|
-
name,
|
|
67
|
-
description: item._definition.description,
|
|
68
|
-
inputSchema: item._definition.inputSchema,
|
|
69
|
-
outputSchema: item._definition.outputSchema,
|
|
70
|
-
freeform: item._definition.freeform,
|
|
71
|
-
}));
|
|
60
|
+
/** The `ToolDefinition[]` that `LLMRequest.tools` expects, in array order. */
|
|
61
|
+
export const toDefinitions = (tools) => tools.map((item) => item._definition);
|
|
72
62
|
/**
|
|
73
63
|
* Describes a no-argument Effect tool input as an empty object, or returns
|
|
74
64
|
* `undefined` when the input takes arguments.
|
|
@@ -98,5 +88,5 @@ const toJsonSchema = (schema) => {
|
|
|
98
88
|
return document.schema;
|
|
99
89
|
return { ...document.schema, $defs: document.definitions };
|
|
100
90
|
};
|
|
101
|
-
const project = (toModelOutput, toStructuredOutput,
|
|
91
|
+
const project = (toModelOutput, toStructuredOutput, input, id, output) => ToolOutput.make(toStructuredOutput?.(output) ?? output, toModelOutput?.({ id, input, output }) ?? (typeof output === "string" ? [{ type: "text", text: output }] : []));
|
|
102
92
|
export { ToolFailure };
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Context } from "effect";
|
|
2
2
|
import { MediaClient } from "./media-client.js";
|
|
3
|
-
import { type TranscriptionEvent, type
|
|
4
|
-
export type Interface = MediaClient.Interface<
|
|
3
|
+
import { type TranscriptionEvent, type TranscriptionRequest, type TranscriptionResponse } from "./transcription.js";
|
|
4
|
+
export type Interface = MediaClient.Interface<TranscriptionRequest, TranscriptionEvent, TranscriptionResponse>;
|
|
5
5
|
declare const TranscriptionClientService_base: Context.ServiceClass<TranscriptionClientService, "@opencode/TranscriptionClient", Interface>;
|
|
6
6
|
export declare class TranscriptionClientService extends TranscriptionClientService_base {
|
|
7
7
|
}
|
|
@@ -73,8 +73,8 @@ export declare const TranscriptionClient: {
|
|
|
73
73
|
readonly type: "finish";
|
|
74
74
|
})[];
|
|
75
75
|
readonly layer: import("effect/Layer").Layer<TranscriptionClientService, never, import("./route.js").RequestExecutorService>;
|
|
76
|
-
readonly generate: (request:
|
|
77
|
-
readonly stream: (request:
|
|
76
|
+
readonly generate: (request: TranscriptionRequest, options?: import("./generation.js").AwaitOptions) => import("effect/Effect").Effect<TranscriptionResponse, import("./public.js").AIError, TranscriptionClientService>;
|
|
77
|
+
readonly stream: (request: TranscriptionRequest, options?: import("./generation.js").AwaitOptions) => import("effect/Stream").Stream<{
|
|
78
78
|
readonly type: "text-delta";
|
|
79
79
|
readonly delta: string;
|
|
80
80
|
} | {
|
|
@@ -129,11 +129,11 @@ export declare const TranscriptionClient: {
|
|
|
129
129
|
};
|
|
130
130
|
} | undefined;
|
|
131
131
|
readonly type: "finish";
|
|
132
|
-
} | import("./generation.js").Observation, import("./
|
|
133
|
-
readonly start: (request:
|
|
132
|
+
} | import("./generation.js").Observation, import("./public.js").AIError, TranscriptionClientService>;
|
|
133
|
+
readonly start: (request: TranscriptionRequest) => import("effect/Effect").Effect<import("./generation.js").Generation<TranscriptionResponse>, import("./public.js").AIError, TranscriptionClientService>;
|
|
134
134
|
readonly resume: (model: import("./transcription.js").TranscriptionModel<{
|
|
135
135
|
readonly [x: string]: unknown;
|
|
136
|
-
}>, token: unknown) => import("effect/Effect").Effect<import("./generation.js").Generation<TranscriptionResponse>, import("./
|
|
136
|
+
}>, token: unknown) => import("effect/Effect").Effect<import("./generation.js").Generation<TranscriptionResponse>, import("./public.js").AIError, TranscriptionClientService>;
|
|
137
137
|
readonly Service: typeof TranscriptionClientService;
|
|
138
138
|
};
|
|
139
139
|
export {};
|