@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/speech.js
CHANGED
|
@@ -3,7 +3,7 @@ import { ProgressEvent, QueuedEvent } from "./generation.js";
|
|
|
3
3
|
import { Media } from "./media.js";
|
|
4
4
|
import { MediaModel, composeRoute, tryRequest } from "./media-model.js";
|
|
5
5
|
import { MediaRoute } from "./route/media.js";
|
|
6
|
-
import { AIError,
|
|
6
|
+
import { AIError, MediaUsage, ProviderMetadata, ProviderOptions, } from "./schema/index.js";
|
|
7
7
|
import { SpeechClient, Service } from "./speech-client.js";
|
|
8
8
|
export class SpeechModel extends MediaModel {
|
|
9
9
|
static fromRoute(route, input) {
|
|
@@ -32,7 +32,7 @@ export const SpeechTimestamp = Schema.Struct({
|
|
|
32
32
|
startSeconds: Schema.Number,
|
|
33
33
|
endSeconds: Schema.Number,
|
|
34
34
|
}).annotate({ identifier: "Speech.Timestamp" });
|
|
35
|
-
|
|
35
|
+
const SpeechRequestSchema = Schema.Struct({
|
|
36
36
|
model: SpeechModelSchema,
|
|
37
37
|
text: Schema.String,
|
|
38
38
|
voice: Schema.optional(SpeechVoice),
|
|
@@ -42,9 +42,7 @@ export class SpeechRequest extends Schema.Class("Speech.Request")({
|
|
|
42
42
|
instructions: Schema.optional(Schema.String),
|
|
43
43
|
timestamps: Schema.optional(Schema.Boolean),
|
|
44
44
|
providerOptions: Schema.optional(ProviderOptions),
|
|
45
|
-
|
|
46
|
-
}) {
|
|
47
|
-
}
|
|
45
|
+
});
|
|
48
46
|
// ---------------------------------------------------------------------------
|
|
49
47
|
// Response and events
|
|
50
48
|
// ---------------------------------------------------------------------------
|
|
@@ -100,15 +98,19 @@ const collectResponse = (events) => {
|
|
|
100
98
|
providerMetadata: finish.providerMetadata,
|
|
101
99
|
}));
|
|
102
100
|
};
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
const requestEffect = (input) => tryRequest(() =>
|
|
101
|
+
// ---------------------------------------------------------------------------
|
|
102
|
+
// Request-shaped call API
|
|
103
|
+
// ---------------------------------------------------------------------------
|
|
104
|
+
/** Normalize speech request input into a plain `SpeechRequest`. */
|
|
105
|
+
export const request = (input) => ({
|
|
106
|
+
...input,
|
|
107
|
+
});
|
|
108
|
+
const validate = Schema.decodeUnknownSync(SpeechRequestSchema);
|
|
109
|
+
const requestEffect = (input) => tryRequest(() => {
|
|
110
|
+
const normalized = request(input);
|
|
111
|
+
validate(normalized);
|
|
112
|
+
return normalized;
|
|
113
|
+
});
|
|
112
114
|
export function generate(input) {
|
|
113
115
|
return requestEffect(input).pipe(Effect.flatMap((request) => SpeechClient.generate(request)));
|
|
114
116
|
}
|
package/dist/testing.d.ts
CHANGED
|
@@ -1,21 +1,37 @@
|
|
|
1
1
|
export * as TestLLM from "./testing.js";
|
|
2
2
|
export { compileRequest } from "./route/client.js";
|
|
3
|
-
export { TestDecision } from "./testing/decision.js";
|
|
4
|
-
export { TestImage } from "./testing/image.js";
|
|
5
3
|
import { LLMClient } from "./route/client.js";
|
|
6
4
|
import { LLMEvent, CompactionResponse, CompactionCheckpointResponse, type FinishReasonDetails, type AIError, type LLMRequest, type ProviderMetadata, type UsageInput } from "./schema/index.js";
|
|
7
|
-
import { Context, Layer, Stream } from "effect";
|
|
8
|
-
import { TestScript } from "./testing/script.js";
|
|
5
|
+
import { Context, Effect, Layer, Scope, Stream } from "effect";
|
|
9
6
|
export type Response = readonly LLMEvent[] | Stream.Stream<LLMEvent, AIError> | CompactionResponse | CompactionCheckpointResponse;
|
|
10
|
-
export type Gate =
|
|
7
|
+
export type Gate = Readonly<{
|
|
8
|
+
started: Effect.Effect<void>;
|
|
9
|
+
release: Effect.Effect<void>;
|
|
10
|
+
}>;
|
|
11
11
|
type ClientInterface = Context.Service.Shape<typeof LLMClient.Service>;
|
|
12
12
|
export type Responder = (request: LLMRequest) => Response;
|
|
13
|
-
|
|
13
|
+
interface Controls {
|
|
14
|
+
/** Returns a snapshot of requests observed at execution time. */
|
|
15
|
+
readonly requests: () => Effect.Effect<readonly LLMRequest[]>;
|
|
16
|
+
readonly push: (...responses: readonly Response[]) => Effect.Effect<void>;
|
|
17
|
+
/** Replaces the fallback without changing queued responses. */
|
|
18
|
+
readonly always: (response: Response) => Effect.Effect<void>;
|
|
19
|
+
/** Answers requests after the one-shot queue is exhausted; receives the original request. */
|
|
20
|
+
readonly serve: (responder: Responder) => Effect.Effect<void>;
|
|
21
|
+
/** Waits for request arrivals, not output or completion. */
|
|
22
|
+
readonly wait: (count: number) => Effect.Effect<void>;
|
|
23
|
+
readonly gate: () => Effect.Effect<Gate, never, Scope.Scope>;
|
|
24
|
+
}
|
|
25
|
+
export interface TestInterface extends ClientInterface, Controls {
|
|
14
26
|
}
|
|
15
27
|
declare const Test_base: Context.ServiceClass<Test, "@opencode/ai/TestLLM/Test", TestInterface>;
|
|
16
28
|
export declare class Test extends Test_base {
|
|
17
29
|
}
|
|
18
|
-
export
|
|
30
|
+
export interface LayerOptions {
|
|
31
|
+
readonly transformRequest?: (request: LLMRequest) => LLMRequest;
|
|
32
|
+
/** Used after the one-shot response queue is exhausted. Omit to defect on unexpected requests. */
|
|
33
|
+
readonly fallback?: Response;
|
|
34
|
+
}
|
|
19
35
|
export declare const complete: (options: {
|
|
20
36
|
readonly reason: FinishReasonDetails;
|
|
21
37
|
readonly usage?: UsageInput;
|
|
@@ -168,18 +184,6 @@ export declare const complete: (options: {
|
|
|
168
184
|
readonly [x: string]: unknown;
|
|
169
185
|
};
|
|
170
186
|
} | undefined;
|
|
171
|
-
} | {
|
|
172
|
-
readonly type: "tool-error";
|
|
173
|
-
readonly id: string;
|
|
174
|
-
readonly name: string;
|
|
175
|
-
readonly namespace?: string | undefined;
|
|
176
|
-
readonly message: string;
|
|
177
|
-
readonly error?: unknown;
|
|
178
|
-
readonly providerMetadata?: {
|
|
179
|
-
readonly [x: string]: {
|
|
180
|
-
readonly [x: string]: unknown;
|
|
181
|
-
};
|
|
182
|
-
} | undefined;
|
|
183
187
|
} | {
|
|
184
188
|
readonly type: "step-finish";
|
|
185
189
|
readonly index: number;
|
|
@@ -204,6 +208,7 @@ export declare const complete: (options: {
|
|
|
204
208
|
readonly explanation?: string | undefined;
|
|
205
209
|
};
|
|
206
210
|
readonly usage?: import("./schema/events.js").Usage | undefined;
|
|
211
|
+
readonly message?: import("./schema/messages.js").AssistantMessage | undefined;
|
|
207
212
|
readonly providerMetadata?: {
|
|
208
213
|
readonly [x: string]: {
|
|
209
214
|
readonly [x: string]: unknown;
|
|
@@ -217,15 +222,6 @@ export declare const complete: (options: {
|
|
|
217
222
|
readonly [x: string]: unknown;
|
|
218
223
|
};
|
|
219
224
|
} | undefined;
|
|
220
|
-
} | {
|
|
221
|
-
readonly type: "provider-error";
|
|
222
|
-
readonly message: string;
|
|
223
|
-
readonly classification?: "context-overflow" | "payload-too-large" | undefined;
|
|
224
|
-
readonly providerMetadata?: {
|
|
225
|
-
readonly [x: string]: {
|
|
226
|
-
readonly [x: string]: unknown;
|
|
227
|
-
};
|
|
228
|
-
} | undefined;
|
|
229
225
|
} | ({
|
|
230
226
|
readonly type: "compaction";
|
|
231
227
|
readonly provider: string & import("effect/Brand").Brand<"AI.ProviderID">;
|
|
@@ -387,18 +383,6 @@ export declare const stop: (...events: readonly LLMEvent[]) => ({
|
|
|
387
383
|
readonly [x: string]: unknown;
|
|
388
384
|
};
|
|
389
385
|
} | undefined;
|
|
390
|
-
} | {
|
|
391
|
-
readonly type: "tool-error";
|
|
392
|
-
readonly id: string;
|
|
393
|
-
readonly name: string;
|
|
394
|
-
readonly namespace?: string | undefined;
|
|
395
|
-
readonly message: string;
|
|
396
|
-
readonly error?: unknown;
|
|
397
|
-
readonly providerMetadata?: {
|
|
398
|
-
readonly [x: string]: {
|
|
399
|
-
readonly [x: string]: unknown;
|
|
400
|
-
};
|
|
401
|
-
} | undefined;
|
|
402
386
|
} | {
|
|
403
387
|
readonly type: "step-finish";
|
|
404
388
|
readonly index: number;
|
|
@@ -423,6 +407,7 @@ export declare const stop: (...events: readonly LLMEvent[]) => ({
|
|
|
423
407
|
readonly explanation?: string | undefined;
|
|
424
408
|
};
|
|
425
409
|
readonly usage?: import("./schema/events.js").Usage | undefined;
|
|
410
|
+
readonly message?: import("./schema/messages.js").AssistantMessage | undefined;
|
|
426
411
|
readonly providerMetadata?: {
|
|
427
412
|
readonly [x: string]: {
|
|
428
413
|
readonly [x: string]: unknown;
|
|
@@ -436,15 +421,6 @@ export declare const stop: (...events: readonly LLMEvent[]) => ({
|
|
|
436
421
|
readonly [x: string]: unknown;
|
|
437
422
|
};
|
|
438
423
|
} | undefined;
|
|
439
|
-
} | {
|
|
440
|
-
readonly type: "provider-error";
|
|
441
|
-
readonly message: string;
|
|
442
|
-
readonly classification?: "context-overflow" | "payload-too-large" | undefined;
|
|
443
|
-
readonly providerMetadata?: {
|
|
444
|
-
readonly [x: string]: {
|
|
445
|
-
readonly [x: string]: unknown;
|
|
446
|
-
};
|
|
447
|
-
} | undefined;
|
|
448
424
|
} | ({
|
|
449
425
|
readonly type: "compaction";
|
|
450
426
|
readonly provider: string & import("effect/Brand").Brand<"AI.ProviderID">;
|
|
@@ -606,18 +582,6 @@ export declare const toolCalls: (...events: readonly LLMEvent[]) => ({
|
|
|
606
582
|
readonly [x: string]: unknown;
|
|
607
583
|
};
|
|
608
584
|
} | undefined;
|
|
609
|
-
} | {
|
|
610
|
-
readonly type: "tool-error";
|
|
611
|
-
readonly id: string;
|
|
612
|
-
readonly name: string;
|
|
613
|
-
readonly namespace?: string | undefined;
|
|
614
|
-
readonly message: string;
|
|
615
|
-
readonly error?: unknown;
|
|
616
|
-
readonly providerMetadata?: {
|
|
617
|
-
readonly [x: string]: {
|
|
618
|
-
readonly [x: string]: unknown;
|
|
619
|
-
};
|
|
620
|
-
} | undefined;
|
|
621
585
|
} | {
|
|
622
586
|
readonly type: "step-finish";
|
|
623
587
|
readonly index: number;
|
|
@@ -642,6 +606,7 @@ export declare const toolCalls: (...events: readonly LLMEvent[]) => ({
|
|
|
642
606
|
readonly explanation?: string | undefined;
|
|
643
607
|
};
|
|
644
608
|
readonly usage?: import("./schema/events.js").Usage | undefined;
|
|
609
|
+
readonly message?: import("./schema/messages.js").AssistantMessage | undefined;
|
|
645
610
|
readonly providerMetadata?: {
|
|
646
611
|
readonly [x: string]: {
|
|
647
612
|
readonly [x: string]: unknown;
|
|
@@ -655,15 +620,6 @@ export declare const toolCalls: (...events: readonly LLMEvent[]) => ({
|
|
|
655
620
|
readonly [x: string]: unknown;
|
|
656
621
|
};
|
|
657
622
|
} | undefined;
|
|
658
|
-
} | {
|
|
659
|
-
readonly type: "provider-error";
|
|
660
|
-
readonly message: string;
|
|
661
|
-
readonly classification?: "context-overflow" | "payload-too-large" | undefined;
|
|
662
|
-
readonly providerMetadata?: {
|
|
663
|
-
readonly [x: string]: {
|
|
664
|
-
readonly [x: string]: unknown;
|
|
665
|
-
};
|
|
666
|
-
} | undefined;
|
|
667
623
|
} | ({
|
|
668
624
|
readonly type: "compaction";
|
|
669
625
|
readonly provider: string & import("effect/Brand").Brand<"AI.ProviderID">;
|
|
@@ -825,18 +781,6 @@ export declare const text: (value: string, id: string) => ({
|
|
|
825
781
|
readonly [x: string]: unknown;
|
|
826
782
|
};
|
|
827
783
|
} | undefined;
|
|
828
|
-
} | {
|
|
829
|
-
readonly type: "tool-error";
|
|
830
|
-
readonly id: string;
|
|
831
|
-
readonly name: string;
|
|
832
|
-
readonly namespace?: string | undefined;
|
|
833
|
-
readonly message: string;
|
|
834
|
-
readonly error?: unknown;
|
|
835
|
-
readonly providerMetadata?: {
|
|
836
|
-
readonly [x: string]: {
|
|
837
|
-
readonly [x: string]: unknown;
|
|
838
|
-
};
|
|
839
|
-
} | undefined;
|
|
840
784
|
} | {
|
|
841
785
|
readonly type: "step-finish";
|
|
842
786
|
readonly index: number;
|
|
@@ -861,6 +805,7 @@ export declare const text: (value: string, id: string) => ({
|
|
|
861
805
|
readonly explanation?: string | undefined;
|
|
862
806
|
};
|
|
863
807
|
readonly usage?: import("./schema/events.js").Usage | undefined;
|
|
808
|
+
readonly message?: import("./schema/messages.js").AssistantMessage | undefined;
|
|
864
809
|
readonly providerMetadata?: {
|
|
865
810
|
readonly [x: string]: {
|
|
866
811
|
readonly [x: string]: unknown;
|
|
@@ -874,15 +819,6 @@ export declare const text: (value: string, id: string) => ({
|
|
|
874
819
|
readonly [x: string]: unknown;
|
|
875
820
|
};
|
|
876
821
|
} | undefined;
|
|
877
|
-
} | {
|
|
878
|
-
readonly type: "provider-error";
|
|
879
|
-
readonly message: string;
|
|
880
|
-
readonly classification?: "context-overflow" | "payload-too-large" | undefined;
|
|
881
|
-
readonly providerMetadata?: {
|
|
882
|
-
readonly [x: string]: {
|
|
883
|
-
readonly [x: string]: unknown;
|
|
884
|
-
};
|
|
885
|
-
} | undefined;
|
|
886
822
|
} | ({
|
|
887
823
|
readonly type: "compaction";
|
|
888
824
|
readonly provider: string & import("effect/Brand").Brand<"AI.ProviderID">;
|
|
@@ -1044,18 +980,6 @@ export declare const textWithUsage: (value: string, id: string, inputTokens: num
|
|
|
1044
980
|
readonly [x: string]: unknown;
|
|
1045
981
|
};
|
|
1046
982
|
} | undefined;
|
|
1047
|
-
} | {
|
|
1048
|
-
readonly type: "tool-error";
|
|
1049
|
-
readonly id: string;
|
|
1050
|
-
readonly name: string;
|
|
1051
|
-
readonly namespace?: string | undefined;
|
|
1052
|
-
readonly message: string;
|
|
1053
|
-
readonly error?: unknown;
|
|
1054
|
-
readonly providerMetadata?: {
|
|
1055
|
-
readonly [x: string]: {
|
|
1056
|
-
readonly [x: string]: unknown;
|
|
1057
|
-
};
|
|
1058
|
-
} | undefined;
|
|
1059
983
|
} | {
|
|
1060
984
|
readonly type: "step-finish";
|
|
1061
985
|
readonly index: number;
|
|
@@ -1080,6 +1004,7 @@ export declare const textWithUsage: (value: string, id: string, inputTokens: num
|
|
|
1080
1004
|
readonly explanation?: string | undefined;
|
|
1081
1005
|
};
|
|
1082
1006
|
readonly usage?: import("./schema/events.js").Usage | undefined;
|
|
1007
|
+
readonly message?: import("./schema/messages.js").AssistantMessage | undefined;
|
|
1083
1008
|
readonly providerMetadata?: {
|
|
1084
1009
|
readonly [x: string]: {
|
|
1085
1010
|
readonly [x: string]: unknown;
|
|
@@ -1093,15 +1018,6 @@ export declare const textWithUsage: (value: string, id: string, inputTokens: num
|
|
|
1093
1018
|
readonly [x: string]: unknown;
|
|
1094
1019
|
};
|
|
1095
1020
|
} | undefined;
|
|
1096
|
-
} | {
|
|
1097
|
-
readonly type: "provider-error";
|
|
1098
|
-
readonly message: string;
|
|
1099
|
-
readonly classification?: "context-overflow" | "payload-too-large" | undefined;
|
|
1100
|
-
readonly providerMetadata?: {
|
|
1101
|
-
readonly [x: string]: {
|
|
1102
|
-
readonly [x: string]: unknown;
|
|
1103
|
-
};
|
|
1104
|
-
} | undefined;
|
|
1105
1021
|
} | ({
|
|
1106
1022
|
readonly type: "compaction";
|
|
1107
1023
|
readonly provider: string & import("effect/Brand").Brand<"AI.ProviderID">;
|
|
@@ -1263,18 +1179,6 @@ export declare const toolCall: (id: string, name: string, input: unknown) => ({
|
|
|
1263
1179
|
readonly [x: string]: unknown;
|
|
1264
1180
|
};
|
|
1265
1181
|
} | undefined;
|
|
1266
|
-
} | {
|
|
1267
|
-
readonly type: "tool-error";
|
|
1268
|
-
readonly id: string;
|
|
1269
|
-
readonly name: string;
|
|
1270
|
-
readonly namespace?: string | undefined;
|
|
1271
|
-
readonly message: string;
|
|
1272
|
-
readonly error?: unknown;
|
|
1273
|
-
readonly providerMetadata?: {
|
|
1274
|
-
readonly [x: string]: {
|
|
1275
|
-
readonly [x: string]: unknown;
|
|
1276
|
-
};
|
|
1277
|
-
} | undefined;
|
|
1278
1182
|
} | {
|
|
1279
1183
|
readonly type: "step-finish";
|
|
1280
1184
|
readonly index: number;
|
|
@@ -1299,6 +1203,7 @@ export declare const toolCall: (id: string, name: string, input: unknown) => ({
|
|
|
1299
1203
|
readonly explanation?: string | undefined;
|
|
1300
1204
|
};
|
|
1301
1205
|
readonly usage?: import("./schema/events.js").Usage | undefined;
|
|
1206
|
+
readonly message?: import("./schema/messages.js").AssistantMessage | undefined;
|
|
1302
1207
|
readonly providerMetadata?: {
|
|
1303
1208
|
readonly [x: string]: {
|
|
1304
1209
|
readonly [x: string]: unknown;
|
|
@@ -1312,15 +1217,6 @@ export declare const toolCall: (id: string, name: string, input: unknown) => ({
|
|
|
1312
1217
|
readonly [x: string]: unknown;
|
|
1313
1218
|
};
|
|
1314
1219
|
} | undefined;
|
|
1315
|
-
} | {
|
|
1316
|
-
readonly type: "provider-error";
|
|
1317
|
-
readonly message: string;
|
|
1318
|
-
readonly classification?: "context-overflow" | "payload-too-large" | undefined;
|
|
1319
|
-
readonly providerMetadata?: {
|
|
1320
|
-
readonly [x: string]: {
|
|
1321
|
-
readonly [x: string]: unknown;
|
|
1322
|
-
};
|
|
1323
|
-
} | undefined;
|
|
1324
1220
|
} | ({
|
|
1325
1221
|
readonly type: "compaction";
|
|
1326
1222
|
readonly provider: string & import("effect/Brand").Brand<"AI.ProviderID">;
|
|
@@ -1482,18 +1378,6 @@ export declare const failAfter: (error: AIError, ...events: readonly LLMEvent[])
|
|
|
1482
1378
|
readonly [x: string]: unknown;
|
|
1483
1379
|
};
|
|
1484
1380
|
} | undefined;
|
|
1485
|
-
} | {
|
|
1486
|
-
readonly type: "tool-error";
|
|
1487
|
-
readonly id: string;
|
|
1488
|
-
readonly name: string;
|
|
1489
|
-
readonly namespace?: string | undefined;
|
|
1490
|
-
readonly message: string;
|
|
1491
|
-
readonly error?: unknown;
|
|
1492
|
-
readonly providerMetadata?: {
|
|
1493
|
-
readonly [x: string]: {
|
|
1494
|
-
readonly [x: string]: unknown;
|
|
1495
|
-
};
|
|
1496
|
-
} | undefined;
|
|
1497
1381
|
} | {
|
|
1498
1382
|
readonly type: "step-finish";
|
|
1499
1383
|
readonly index: number;
|
|
@@ -1518,6 +1402,7 @@ export declare const failAfter: (error: AIError, ...events: readonly LLMEvent[])
|
|
|
1518
1402
|
readonly explanation?: string | undefined;
|
|
1519
1403
|
};
|
|
1520
1404
|
readonly usage?: import("./schema/events.js").Usage | undefined;
|
|
1405
|
+
readonly message?: import("./schema/messages.js").AssistantMessage | undefined;
|
|
1521
1406
|
readonly providerMetadata?: {
|
|
1522
1407
|
readonly [x: string]: {
|
|
1523
1408
|
readonly [x: string]: unknown;
|
|
@@ -1531,15 +1416,6 @@ export declare const failAfter: (error: AIError, ...events: readonly LLMEvent[])
|
|
|
1531
1416
|
readonly [x: string]: unknown;
|
|
1532
1417
|
};
|
|
1533
1418
|
} | undefined;
|
|
1534
|
-
} | {
|
|
1535
|
-
readonly type: "provider-error";
|
|
1536
|
-
readonly message: string;
|
|
1537
|
-
readonly classification?: "context-overflow" | "payload-too-large" | undefined;
|
|
1538
|
-
readonly providerMetadata?: {
|
|
1539
|
-
readonly [x: string]: {
|
|
1540
|
-
readonly [x: string]: unknown;
|
|
1541
|
-
};
|
|
1542
|
-
} | undefined;
|
|
1543
1419
|
} | ({
|
|
1544
1420
|
readonly type: "compaction";
|
|
1545
1421
|
readonly provider: string & import("effect/Brand").Brand<"AI.ProviderID">;
|
|
@@ -1701,18 +1577,6 @@ export declare const hangAfter: (...events: readonly LLMEvent[]) => Stream.Strea
|
|
|
1701
1577
|
readonly [x: string]: unknown;
|
|
1702
1578
|
};
|
|
1703
1579
|
} | undefined;
|
|
1704
|
-
} | {
|
|
1705
|
-
readonly type: "tool-error";
|
|
1706
|
-
readonly id: string;
|
|
1707
|
-
readonly name: string;
|
|
1708
|
-
readonly namespace?: string | undefined;
|
|
1709
|
-
readonly message: string;
|
|
1710
|
-
readonly error?: unknown;
|
|
1711
|
-
readonly providerMetadata?: {
|
|
1712
|
-
readonly [x: string]: {
|
|
1713
|
-
readonly [x: string]: unknown;
|
|
1714
|
-
};
|
|
1715
|
-
} | undefined;
|
|
1716
1580
|
} | {
|
|
1717
1581
|
readonly type: "step-finish";
|
|
1718
1582
|
readonly index: number;
|
|
@@ -1737,6 +1601,7 @@ export declare const hangAfter: (...events: readonly LLMEvent[]) => Stream.Strea
|
|
|
1737
1601
|
readonly explanation?: string | undefined;
|
|
1738
1602
|
};
|
|
1739
1603
|
readonly usage?: import("./schema/events.js").Usage | undefined;
|
|
1604
|
+
readonly message?: import("./schema/messages.js").AssistantMessage | undefined;
|
|
1740
1605
|
readonly providerMetadata?: {
|
|
1741
1606
|
readonly [x: string]: {
|
|
1742
1607
|
readonly [x: string]: unknown;
|
|
@@ -1750,15 +1615,6 @@ export declare const hangAfter: (...events: readonly LLMEvent[]) => Stream.Strea
|
|
|
1750
1615
|
readonly [x: string]: unknown;
|
|
1751
1616
|
};
|
|
1752
1617
|
} | undefined;
|
|
1753
|
-
} | {
|
|
1754
|
-
readonly type: "provider-error";
|
|
1755
|
-
readonly message: string;
|
|
1756
|
-
readonly classification?: "context-overflow" | "payload-too-large" | undefined;
|
|
1757
|
-
readonly providerMetadata?: {
|
|
1758
|
-
readonly [x: string]: {
|
|
1759
|
-
readonly [x: string]: unknown;
|
|
1760
|
-
};
|
|
1761
|
-
} | undefined;
|
|
1762
1618
|
} | ({
|
|
1763
1619
|
readonly type: "compaction";
|
|
1764
1620
|
readonly provider: string & import("effect/Brand").Brand<"AI.ProviderID">;
|
package/dist/testing.js
CHANGED
|
@@ -1,11 +1,8 @@
|
|
|
1
1
|
export * as TestLLM from "./testing.js";
|
|
2
2
|
export { compileRequest } from "./route/client.js";
|
|
3
|
-
export { TestDecision } from "./testing/decision.js";
|
|
4
|
-
export { TestImage } from "./testing/image.js";
|
|
5
3
|
import { LLMClient, generateWith, } from "./route/client.js";
|
|
6
4
|
import { LLMEvent, CompactionResponse, CompactionCheckpointResponse, } from "./schema/index.js";
|
|
7
|
-
import { Context, Effect, Layer, Stream } from "effect";
|
|
8
|
-
import { TestScript } from "./testing/script.js";
|
|
5
|
+
import { Context, Deferred, Effect, Latch, Layer, Queue, Scope, Stream } from "effect";
|
|
9
6
|
export class Test extends Context.Service()("@opencode/ai/TestLLM/Test") {
|
|
10
7
|
}
|
|
11
8
|
export const complete = (options, ...events) => [
|
|
@@ -32,7 +29,7 @@ export const toolCall = (id, name, input) => toolCalls(LLMEvent.toolCall({ id, n
|
|
|
32
29
|
export const failAfter = (error, ...events) => Stream.fromIterable(events).pipe(Stream.concat(Stream.fail(error)));
|
|
33
30
|
export const hangAfter = (...events) => Stream.concat(Stream.fromIterable(events), Stream.never);
|
|
34
31
|
const make = (options) => Effect.sync(() => {
|
|
35
|
-
const script =
|
|
32
|
+
const script = makeScript(options);
|
|
36
33
|
const stream = (request) => Stream.unwrap(script.take(request).pipe(Effect.map((response) => {
|
|
37
34
|
if (response instanceof CompactionResponse || response instanceof CompactionCheckpointResponse)
|
|
38
35
|
return Stream.die("TestLLM generation requires an event response");
|
|
@@ -58,3 +55,61 @@ const make = (options) => Effect.sync(() => {
|
|
|
58
55
|
});
|
|
59
56
|
/** Provides one shared implementation under the normal client and test-control tags. */
|
|
60
57
|
export const testLayer = (options = {}) => Layer.effectContext(Effect.map(make(options), (test) => Context.make(LLMClient.Service, test).pipe(Context.add(Test, test))));
|
|
58
|
+
/** The response queue, fallback, request log, and gates behind the test controls. */
|
|
59
|
+
const makeScript = (options) => {
|
|
60
|
+
const requests = [];
|
|
61
|
+
const responses = [];
|
|
62
|
+
let started = Deferred.makeUnsafe();
|
|
63
|
+
const initial = options.fallback;
|
|
64
|
+
let fallback = initial === undefined ? undefined : () => initial;
|
|
65
|
+
let activeGate;
|
|
66
|
+
const wait = (count) => Effect.suspend(() => requests.length >= count ? Effect.void : Deferred.await(started).pipe(Effect.andThen(wait(count))));
|
|
67
|
+
const take = (request) => Effect.suspend(() => {
|
|
68
|
+
const count = requests.push(options.transformRequest?.(request) ?? request);
|
|
69
|
+
const waiting = started;
|
|
70
|
+
started = Deferred.makeUnsafe();
|
|
71
|
+
const gate = activeGate;
|
|
72
|
+
try {
|
|
73
|
+
const response = responses.shift() ?? fallback?.(request);
|
|
74
|
+
if (!response)
|
|
75
|
+
return Effect.die(new Error(`TestLLM has no response for request ${count}`));
|
|
76
|
+
if (!gate)
|
|
77
|
+
return Effect.succeed(response);
|
|
78
|
+
return Queue.offer(gate.started, undefined).pipe(Effect.andThen(gate.release.await), Effect.as(response));
|
|
79
|
+
}
|
|
80
|
+
finally {
|
|
81
|
+
// Waiters can resume synchronously; assign the reply and gate before notifying them.
|
|
82
|
+
Deferred.doneUnsafe(waiting, Effect.void);
|
|
83
|
+
}
|
|
84
|
+
});
|
|
85
|
+
const controls = {
|
|
86
|
+
requests: () => Effect.sync(() => [...requests]),
|
|
87
|
+
push: (...input) => Effect.sync(() => {
|
|
88
|
+
responses.push(...input);
|
|
89
|
+
}),
|
|
90
|
+
always: (response) => Effect.sync(() => {
|
|
91
|
+
fallback = () => response;
|
|
92
|
+
}),
|
|
93
|
+
serve: (responder) => Effect.sync(() => {
|
|
94
|
+
fallback = responder;
|
|
95
|
+
}),
|
|
96
|
+
wait,
|
|
97
|
+
gate: () => Effect.gen(function* () {
|
|
98
|
+
const gate = {
|
|
99
|
+
started: yield* Effect.acquireRelease(Queue.unbounded(), Queue.shutdown),
|
|
100
|
+
release: yield* Latch.make(),
|
|
101
|
+
};
|
|
102
|
+
activeGate = gate;
|
|
103
|
+
const release = Effect.sync(() => {
|
|
104
|
+
if (activeGate === gate)
|
|
105
|
+
activeGate = undefined;
|
|
106
|
+
}).pipe(Effect.andThen(gate.release.open), Effect.asVoid);
|
|
107
|
+
yield* Effect.addFinalizer(() => release);
|
|
108
|
+
return {
|
|
109
|
+
started: Queue.take(gate.started),
|
|
110
|
+
release,
|
|
111
|
+
};
|
|
112
|
+
}),
|
|
113
|
+
};
|
|
114
|
+
return { take, controls };
|
|
115
|
+
};
|
package/dist/tool-history.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { Message } from "./schema/messages.js";
|
|
1
|
+
import { type Message } from "./schema/messages.js";
|
|
2
2
|
export declare function normalizeToolHistory(messages: ReadonlyArray<Message>): readonly Message[];
|
package/dist/tool-history.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ToolMessage, ToolResultPart } from "./schema/messages.js";
|
|
2
2
|
const EMPTY_TOOL_OUTPUT = "(no tool output)";
|
|
3
3
|
const MISSING_TOOL_RESULT = "Tool result missing";
|
|
4
4
|
export function normalizeToolHistory(messages) {
|
|
@@ -46,7 +46,7 @@ export function normalizeToolHistory(messages) {
|
|
|
46
46
|
: normalized;
|
|
47
47
|
}
|
|
48
48
|
function missingToolResults(calls) {
|
|
49
|
-
return new
|
|
49
|
+
return new ToolMessage({
|
|
50
50
|
role: "tool",
|
|
51
51
|
content: [...calls].map((call) => ToolResultPart.make({
|
|
52
52
|
id: call.id,
|
|
@@ -70,14 +70,7 @@ function normalizeToolMessage(message, pending) {
|
|
|
70
70
|
return undefined;
|
|
71
71
|
if (content.every((part, index) => part === message.content[index]))
|
|
72
72
|
return message;
|
|
73
|
-
return new
|
|
74
|
-
id: message.id,
|
|
75
|
-
role: message.role,
|
|
76
|
-
content,
|
|
77
|
-
metadata: message.metadata,
|
|
78
|
-
providerMetadata: message.providerMetadata,
|
|
79
|
-
native: message.native,
|
|
80
|
-
});
|
|
73
|
+
return new ToolMessage({ ...message, content });
|
|
81
74
|
}
|
|
82
75
|
function normalizeToolResult(part, call) {
|
|
83
76
|
const named = call === undefined || (part.name === call.name && part.namespace === call.namespace)
|
package/dist/tool-runtime.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Effect } from "effect";
|
|
2
2
|
import { LLMEvent, type ToolCallPart, type ToolOutput as ToolOutputType, type ToolResultValue as ToolResultValueType } from "./schema/index.js";
|
|
3
|
-
import { type
|
|
3
|
+
import { type Tool } from "./tool.js";
|
|
4
4
|
export interface ToolSettlement {
|
|
5
5
|
readonly result: ToolResultValueType;
|
|
6
6
|
readonly output?: ToolOutputType;
|
|
@@ -9,7 +9,14 @@ export interface DispatchResult extends ToolSettlement {
|
|
|
9
9
|
readonly events: ReadonlyArray<LLMEvent>;
|
|
10
10
|
}
|
|
11
11
|
/** Execute one canonical tool call without owning provider IO or continuation. */
|
|
12
|
-
export declare const dispatch: (tools:
|
|
12
|
+
export declare const dispatch: (tools: ReadonlyArray<Tool>, call: ToolCallPart) => Effect.Effect<DispatchResult>;
|
|
13
|
+
/** A call the loop answers before the next step. With `error`, it is not run and the model gets the error back. */
|
|
14
|
+
export interface PendingCall {
|
|
15
|
+
readonly call: ToolCallPart;
|
|
16
|
+
readonly error?: string;
|
|
17
|
+
}
|
|
18
|
+
/** Run a step's tool calls concurrently, with results in call order. */
|
|
19
|
+
export declare const runTools: (tools: ReadonlyArray<Tool>, calls: ReadonlyArray<PendingCall>) => Effect.Effect<DispatchResult[], never, never>;
|
|
13
20
|
export declare const ToolRuntime: {
|
|
14
21
|
readonly dispatch: typeof dispatch;
|
|
15
22
|
};
|
package/dist/tool-runtime.js
CHANGED
|
@@ -4,7 +4,7 @@ import {} from "./tool.js";
|
|
|
4
4
|
/** Execute one canonical tool call without owning provider IO or continuation. */
|
|
5
5
|
export const dispatch = (tools, call) => {
|
|
6
6
|
const name = call.namespace === undefined ? call.name : `${call.namespace}.${call.name}`;
|
|
7
|
-
const tool = tools
|
|
7
|
+
const tool = tools.find((item) => item.name === name);
|
|
8
8
|
if (!tool)
|
|
9
9
|
return Effect.succeed(result(call, {
|
|
10
10
|
type: "error",
|
|
@@ -12,8 +12,12 @@ export const dispatch = (tools, call) => {
|
|
|
12
12
|
}));
|
|
13
13
|
if (!tool.execute)
|
|
14
14
|
return Effect.succeed(result(call, { type: "error", value: `Tool has no execute handler: ${name}` }));
|
|
15
|
-
return decodeAndExecute(tool, call).pipe(Effect.map((value) => result(call, value)), Effect.catchTag("Tool.Error", (failure) => Effect.succeed(result(call, { type: "error", value: failure.message }
|
|
15
|
+
return decodeAndExecute(tool, call).pipe(Effect.map((value) => result(call, value)), Effect.catchTag("Tool.Error", (failure) => Effect.succeed(result(call, { type: "error", value: failure.message }))));
|
|
16
16
|
};
|
|
17
|
+
/** Run a step's tool calls concurrently, with results in call order. */
|
|
18
|
+
export const runTools = (tools, calls) => Effect.forEach(calls, (item) => item.error === undefined
|
|
19
|
+
? dispatch(tools, item.call)
|
|
20
|
+
: Effect.succeed(result(item.call, { type: "error", value: item.error })), { concurrency: "unbounded" });
|
|
17
21
|
const decodeAndExecute = (tool, call) => tool._decode(call.input).pipe(Effect.mapError((error) => new ToolFailure({ message: `Invalid tool input: ${error.message}` })), Effect.flatMap((decoded) => tool.execute(decoded, {
|
|
18
22
|
id: call.id,
|
|
19
23
|
name: call.name,
|
|
@@ -27,39 +31,21 @@ const decodeAndExecute = (tool, call) => tool._decode(call.input).pipe(Effect.ma
|
|
|
27
31
|
const result = ToolOutput.toResultValue(output);
|
|
28
32
|
return result.type === "error" ? { result } : { result, output };
|
|
29
33
|
}))));
|
|
30
|
-
const result = (call, value
|
|
34
|
+
const result = (call, value) => {
|
|
31
35
|
const settlement = ToolResultValue.is(value) ? { result: value } : value;
|
|
32
36
|
return {
|
|
33
37
|
result: settlement.result,
|
|
34
38
|
output: settlement.output,
|
|
35
|
-
events:
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
LLMEvent.toolResult({
|
|
46
|
-
id: call.id,
|
|
47
|
-
name: call.name,
|
|
48
|
-
namespace: call.namespace,
|
|
49
|
-
result: settlement.result,
|
|
50
|
-
providerMetadata: call.providerMetadata,
|
|
51
|
-
}),
|
|
52
|
-
]
|
|
53
|
-
: [
|
|
54
|
-
LLMEvent.toolResult({
|
|
55
|
-
id: call.id,
|
|
56
|
-
name: call.name,
|
|
57
|
-
namespace: call.namespace,
|
|
58
|
-
result: settlement.result,
|
|
59
|
-
output: settlement.output,
|
|
60
|
-
providerMetadata: call.providerMetadata,
|
|
61
|
-
}),
|
|
62
|
-
],
|
|
39
|
+
events: [
|
|
40
|
+
LLMEvent.toolResult({
|
|
41
|
+
id: call.id,
|
|
42
|
+
name: call.name,
|
|
43
|
+
namespace: call.namespace,
|
|
44
|
+
result: settlement.result,
|
|
45
|
+
output: settlement.output,
|
|
46
|
+
providerMetadata: call.providerMetadata,
|
|
47
|
+
}),
|
|
48
|
+
],
|
|
63
49
|
};
|
|
64
50
|
};
|
|
65
51
|
export const ToolRuntime = { dispatch };
|