@opencode/ai 0.0.0-dev-465 → 0.0.0-dev-468
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 +27 -16
- package/dist/cache-policy.d.ts +1 -1
- package/dist/cache-policy.js +2 -2
- package/dist/decision-client.d.ts +3 -3
- package/dist/decision.d.ts +13 -120
- package/dist/decision.js +17 -13
- package/dist/effect.d.ts +8 -6
- package/dist/effect.js +4 -3
- package/dist/effort-updates.d.ts +1 -1
- 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 +12 -38
- package/dist/experimental/extraction.js +13 -11
- package/dist/experimental.d.ts +8 -8
- package/dist/experimental.js +4 -4
- package/dist/image-client.d.ts +11 -5
- package/dist/image-client.js +1 -1
- package/dist/image.d.ts +21 -62
- package/dist/image.js +16 -13
- package/dist/index.d.ts +20 -14
- package/dist/index.js +6 -3
- package/dist/llm.d.ts +60 -25
- package/dist/llm.js +126 -38
- package/dist/protocols/alibaba-images.d.ts +2 -2
- package/dist/protocols/alibaba-messages.js +3 -3
- package/dist/protocols/anthropic-messages.d.ts +1 -1
- package/dist/protocols/anthropic-messages.js +4 -3
- package/dist/protocols/assemblyai-transcription.d.ts +2 -2
- package/dist/protocols/cartesia-speech.d.ts +2 -2
- package/dist/protocols/cloudflare-workers-ai-images.d.ts +2 -2
- 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.js +2 -8
- package/dist/protocols/google-images.d.ts +2 -2
- 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 +4 -3
- package/dist/protocols/minimax-images.d.ts +2 -2
- package/dist/protocols/open-responses.d.ts +1 -21
- package/dist/protocols/openai-chat.d.ts +1 -21
- package/dist/protocols/openai-chat.js +7 -9
- package/dist/protocols/openai-decisions.js +1 -1
- package/dist/protocols/openai-images.d.ts +2 -2
- package/dist/protocols/openai-responses.js +0 -1
- 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 -1
- package/dist/protocols/shared.js +2 -2
- package/dist/protocols/system-one.d.ts +4 -4
- 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 +4 -3
- package/dist/protocols/utils/tool-stream.d.ts +3 -63
- package/dist/protocols/xai-images.d.ts +2 -2
- package/dist/protocols/xai-video.d.ts +2 -2
- package/dist/protocols/zai-images.d.ts +2 -2
- package/dist/protocols/zai-messages.js +3 -3
- package/dist/provider-error.js +4 -4
- package/dist/providers/vercel-ai-gateway.js +4 -3
- package/dist/route/client.d.ts +43 -19
- package/dist/route/client.js +30 -18
- package/dist/route/decision.d.ts +6 -6
- package/dist/schema/errors.d.ts +1 -2
- package/dist/schema/errors.js +1 -2
- package/dist/schema/events.d.ts +61 -769
- package/dist/schema/events.js +3 -30
- package/dist/schema/messages.d.ts +20 -92
- package/dist/schema/messages.js +1 -52
- package/dist/speech-client.d.ts +5 -5
- package/dist/speech.d.ts +17 -19
- package/dist/speech.js +16 -12
- package/dist/testing.d.ts +8 -168
- package/dist/tool-runtime.js +12 -30
- package/dist/transcription-client.d.ts +5 -5
- package/dist/transcription.d.ts +17 -19
- package/dist/transcription.js +16 -12
- package/dist/video-client.d.ts +5 -5
- package/dist/video-client.js +1 -1
- package/dist/video.d.ts +18 -20
- package/dist/video.js +16 -12
- package/package.json +3 -3
package/dist/llm.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Effect, JsonSchema, Schema, Stream } from "effect";
|
|
2
2
|
import { tryRequest } from "./media-model.js";
|
|
3
|
-
import { LLMClient, Service } from "./route/client.js";
|
|
4
|
-
import { GenerationOptions, HttpOptions, InvalidProviderOutputError, InvalidRequestError, AIError, LLMEvent,
|
|
3
|
+
import { LLMClient, Service, canCompact, compactRequest, } from "./route/client.js";
|
|
4
|
+
import { GenerationOptions, HttpOptions, InvalidProviderOutputError, InvalidRequestError, AIError, LLMEvent, LLMResponse, Message, LanguageModel, SystemPart, ToolChoice, ToolEntry, Usage, withPartial, } from "./schema/index.js";
|
|
5
5
|
import { tool } from "./tool.js";
|
|
6
6
|
import { ToolRuntime } from "./tool-runtime.js";
|
|
7
7
|
export function generate(input, options) {
|
|
@@ -14,9 +14,11 @@ export function stream(input, options) {
|
|
|
14
14
|
let state = LLMResponse.empty();
|
|
15
15
|
return LLMClient.stream(request, options).pipe(Stream.mapEffect((event) => {
|
|
16
16
|
state = LLMResponse.reduce(state, event);
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
17
|
+
const response = event.type === "finish" ? LLMResponse.complete(state) : undefined;
|
|
18
|
+
if (!response || event.type !== "finish")
|
|
19
|
+
return Effect.succeed(event);
|
|
20
|
+
const finish = { ...event, usage: response.usage, message: response.message };
|
|
21
|
+
return output === undefined ? Effect.succeed(finish) : withObject(output, finish, state);
|
|
20
22
|
}));
|
|
21
23
|
}))));
|
|
22
24
|
}
|
|
@@ -26,28 +28,27 @@ export function loop(input, options) {
|
|
|
26
28
|
const clientCalls = (response, output) => output && response.toolCalls.some((call) => call.name === OBJECT_TOOL)
|
|
27
29
|
? []
|
|
28
30
|
: response.toolCalls.filter((call) => call.providerExecuted !== true);
|
|
29
|
-
const step = (request, steps, output) => Stream.suspend(() => {
|
|
31
|
+
const step = (request, steps, usage, output) => Stream.suspend(() => {
|
|
30
32
|
let state = LLMResponse.empty();
|
|
31
|
-
return LLMClient.stream(request, options).pipe(Stream.map((event) => event.type === "step-start" || event.type === "step-finish" ? { ...event, index: steps.length } : event), Stream.
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
return Effect.succeed(event);
|
|
35
|
-
const response = LLMResponse.complete(state);
|
|
36
|
-
return response && clientCalls(response, output).length > 0
|
|
37
|
-
? Effect.succeed(event)
|
|
38
|
-
: withObject(output, event, state);
|
|
39
|
-
}), Stream.mapError((error) => withPartial(error, LLMResponse.partial(state))), Stream.concat(Stream.unwrap(Effect.gen(function* () {
|
|
33
|
+
return LLMClient.stream(request, options).pipe(Stream.map((event) => event.type === "step-start" || event.type === "step-finish" ? { ...event, index: steps.length } : event), Stream.tap((event) => Effect.sync(() => (state = LLMResponse.reduce(state, event)))),
|
|
34
|
+
// Each call's `finish` ends only this step; the loop emits its own once it stops.
|
|
35
|
+
Stream.filter((event) => event.type !== "finish"), Stream.mapError((error) => withPartial(error, LLMResponse.partial(state))), Stream.concat(Stream.unwrap(Effect.gen(function* () {
|
|
40
36
|
const response = LLMResponse.complete(state);
|
|
41
|
-
const
|
|
42
|
-
if (!response ||
|
|
37
|
+
const finish = state.events.findLast(LLMEvent.is.finish);
|
|
38
|
+
if (!response || !finish)
|
|
43
39
|
return Stream.empty;
|
|
40
|
+
const total = addUsage(usage, response.usage);
|
|
41
|
+
const calls = clientCalls(response, output);
|
|
44
42
|
const done = [...steps, response];
|
|
45
|
-
if (until?.({ steps: done }))
|
|
46
|
-
|
|
43
|
+
if (calls.length === 0 || until?.({ steps: done })) {
|
|
44
|
+
const event = { ...finish, usage: total, message: response.message };
|
|
45
|
+
return Stream.fromEffect(output === undefined || calls.length > 0 ? Effect.succeed(event) : withObject(output, event, state));
|
|
46
|
+
}
|
|
47
47
|
const results = yield* Effect.forEach(calls, (call) => ToolRuntime.dispatch(tools, call), {
|
|
48
48
|
concurrency: "unbounded",
|
|
49
49
|
});
|
|
50
|
-
const next =
|
|
50
|
+
const next = {
|
|
51
|
+
...request,
|
|
51
52
|
messages: [
|
|
52
53
|
...request.messages,
|
|
53
54
|
response.message,
|
|
@@ -59,17 +60,96 @@ export function loop(input, options) {
|
|
|
59
60
|
providerMetadata: call.providerMetadata,
|
|
60
61
|
})),
|
|
61
62
|
],
|
|
62
|
-
}
|
|
63
|
-
return Stream.fromIterable(results.flatMap((result) => result.events)).pipe(Stream.concat(step(next, done, output)));
|
|
63
|
+
};
|
|
64
|
+
return Stream.fromIterable(results.flatMap((result) => result.events)).pipe(Stream.concat(step(next, done, total, output)));
|
|
64
65
|
}))));
|
|
65
66
|
});
|
|
66
|
-
return Stream.unwrap(prepare({ ...rest, tools }).pipe(Effect.map(({ request, output }) => step(request, [], output))));
|
|
67
|
+
return Stream.unwrap(prepare({ ...rest, tools }).pipe(Effect.map(({ request, output }) => step(request, [], undefined, output))));
|
|
68
|
+
}
|
|
69
|
+
export function collect(events) {
|
|
70
|
+
return Effect.suspend(() => {
|
|
71
|
+
const steps = [];
|
|
72
|
+
const messages = [];
|
|
73
|
+
let step = LLMResponse.empty();
|
|
74
|
+
// Between a `step-finish` and the next `step-start`, tool results come from the loop running tools.
|
|
75
|
+
let betweenSteps = false;
|
|
76
|
+
let finish;
|
|
77
|
+
const close = (reason, usage) => {
|
|
78
|
+
if (step.events.length === 0)
|
|
79
|
+
return;
|
|
80
|
+
const response = new LLMResponse({
|
|
81
|
+
message: step.message,
|
|
82
|
+
events: step.events,
|
|
83
|
+
usage: usage ?? step.usage,
|
|
84
|
+
finishReason: reason,
|
|
85
|
+
});
|
|
86
|
+
steps.push(response);
|
|
87
|
+
messages.push(response.message);
|
|
88
|
+
step = LLMResponse.empty();
|
|
89
|
+
};
|
|
90
|
+
return Stream.runForEach(events, (event) => Effect.sync(() => {
|
|
91
|
+
if (event.type === "finish") {
|
|
92
|
+
close(event.reason, event.usage);
|
|
93
|
+
finish = event;
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
if (event.type === "tool-result" && betweenSteps) {
|
|
97
|
+
messages.push(Message.tool({
|
|
98
|
+
id: event.id,
|
|
99
|
+
name: event.name,
|
|
100
|
+
namespace: event.namespace,
|
|
101
|
+
result: event.result,
|
|
102
|
+
providerMetadata: event.providerMetadata,
|
|
103
|
+
}));
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
if (event.type === "step-start")
|
|
107
|
+
betweenSteps = false;
|
|
108
|
+
step = LLMResponse.reduce(step, event);
|
|
109
|
+
if (event.type !== "step-finish")
|
|
110
|
+
return;
|
|
111
|
+
close(event.reason, event.usage);
|
|
112
|
+
betweenSteps = true;
|
|
113
|
+
})).pipe(Effect.flatMap(() => {
|
|
114
|
+
if (finish === undefined)
|
|
115
|
+
return Effect.fail(new AIError({
|
|
116
|
+
reason: new InvalidProviderOutputError({
|
|
117
|
+
message: "The stream ended without a finish event.",
|
|
118
|
+
classification: "incomplete-stream",
|
|
119
|
+
}),
|
|
120
|
+
}));
|
|
121
|
+
const result = {
|
|
122
|
+
text: steps.at(-1)?.text ?? "",
|
|
123
|
+
steps,
|
|
124
|
+
messages,
|
|
125
|
+
usage: finish.usage,
|
|
126
|
+
finishReason: finish.reason,
|
|
127
|
+
...("object" in finish ? { object: finish.object } : {}),
|
|
128
|
+
};
|
|
129
|
+
return Effect.succeed(result);
|
|
130
|
+
}));
|
|
131
|
+
});
|
|
67
132
|
}
|
|
133
|
+
const addUsage = (total, step) => {
|
|
134
|
+
if (total === undefined || step === undefined)
|
|
135
|
+
return total ?? step;
|
|
136
|
+
const sum = (key) => (total[key] === undefined && step[key] === undefined ? undefined : (total[key] ?? 0) + (step[key] ?? 0));
|
|
137
|
+
return new Usage({
|
|
138
|
+
// Context size describes the latest call, not a running total.
|
|
139
|
+
contextTokens: step.contextTokens ?? total.contextTokens,
|
|
140
|
+
inputTokens: sum("inputTokens"),
|
|
141
|
+
outputTokens: sum("outputTokens"),
|
|
142
|
+
nonCachedInputTokens: sum("nonCachedInputTokens"),
|
|
143
|
+
cacheReadInputTokens: sum("cacheReadInputTokens"),
|
|
144
|
+
cacheWriteInputTokens: sum("cacheWriteInputTokens"),
|
|
145
|
+
reasoningTokens: sum("reasoningTokens"),
|
|
146
|
+
totalTokens: sum("totalTokens"),
|
|
147
|
+
cost: sum("cost"),
|
|
148
|
+
});
|
|
149
|
+
};
|
|
68
150
|
const OBJECT_TOOL = "generate_object";
|
|
69
151
|
// `schema` adds a hidden tool whose input is the answer. With other tools the model only has to call some tool.
|
|
70
152
|
const prepare = (input) => {
|
|
71
|
-
if (input instanceof LLMRequest)
|
|
72
|
-
return Effect.succeed({ request: input, output: undefined });
|
|
73
153
|
const { schema, ...rest } = input;
|
|
74
154
|
return tryRequest(() => {
|
|
75
155
|
const description = "Return the structured result by calling this tool.";
|
|
@@ -106,22 +186,30 @@ const withObject = (output, event, state) => {
|
|
|
106
186
|
? Effect.succeed(event)
|
|
107
187
|
: decodeObject(output, response).pipe(Effect.map((object) => ({ ...event, object })));
|
|
108
188
|
};
|
|
189
|
+
/** Normalize text request input into a plain `LLMRequest`, with `prompt` turned into the one user message. */
|
|
109
190
|
export const request = (input) => {
|
|
110
|
-
|
|
111
|
-
if ((prompt === undefined) === (messages === undefined))
|
|
191
|
+
if ((input.prompt === undefined) === (input.messages === undefined))
|
|
112
192
|
throw new AIError({
|
|
113
193
|
reason: new InvalidRequestError({ message: "Pass exactly one of `prompt` or `messages`, not both or neither" }),
|
|
114
194
|
});
|
|
115
|
-
return
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
195
|
+
return {
|
|
196
|
+
id: input.id,
|
|
197
|
+
model: input.model,
|
|
198
|
+
system: SystemPart.content(input.system),
|
|
199
|
+
messages: input.prompt === undefined ? (input.messages ?? []).map(Message.make) : [Message.user(input.prompt)],
|
|
200
|
+
tools: input.tools?.map((item) => ("_definition" in item ? item._definition : ToolEntry.make(item))) ?? [],
|
|
201
|
+
toolChoice: input.toolChoice ? ToolChoice.make(input.toolChoice) : undefined,
|
|
202
|
+
generation: input.generation === undefined ? undefined : GenerationOptions.make(input.generation),
|
|
203
|
+
providerOptions: input.providerOptions,
|
|
204
|
+
http: HttpOptions.make(input.http),
|
|
205
|
+
cache: input.cache,
|
|
206
|
+
promptCacheKey: input.promptCacheKey,
|
|
207
|
+
metadata: input.metadata,
|
|
208
|
+
includeRaw: input.includeRaw,
|
|
209
|
+
};
|
|
125
210
|
};
|
|
126
|
-
export
|
|
211
|
+
export function compact(input, options) {
|
|
212
|
+
return tryRequest(() => request(input)).pipe(Effect.flatMap((normalized) => compactRequest(normalized, options)));
|
|
213
|
+
}
|
|
214
|
+
export { canCompact };
|
|
127
215
|
export * as LLM from "./llm.js";
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ImageModel, ImageResponse, type
|
|
1
|
+
import { ImageModel, ImageResponse, type ImageRequest } from "../image.js";
|
|
2
2
|
import { MediaProtocol } from "../route/media-protocol.js";
|
|
3
3
|
import { MediaRoute } from "../route/media.js";
|
|
4
4
|
export declare const PATH = "/services/aigc/multimodal-generation/generation";
|
|
@@ -13,7 +13,7 @@ export type AlibabaImageOptions = {
|
|
|
13
13
|
readonly thinkingMode?: boolean;
|
|
14
14
|
readonly enableSequential?: boolean;
|
|
15
15
|
} & Record<string, unknown>;
|
|
16
|
-
export type Request =
|
|
16
|
+
export type Request = ImageRequest<ImageModel<AlibabaImageOptions>>;
|
|
17
17
|
export declare const protocol: MediaProtocol.Inline<Request, ImageResponse>;
|
|
18
18
|
export declare const model: (input: MediaRoute.ModelInput) => ImageModel<AlibabaImageOptions>;
|
|
19
19
|
export declare const AlibabaImages: {
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { Effect, Schema } from "effect";
|
|
2
2
|
import { Protocol } from "../route/protocol.js";
|
|
3
|
-
import { LLMRequest } from "../schema/index.js";
|
|
4
3
|
import { AnthropicMessages } from "./anthropic-messages.js";
|
|
5
4
|
import { ProviderShared } from "./shared.js";
|
|
6
5
|
import { OpenResponsesOptions } from "./utils/open-responses-options.js";
|
|
@@ -22,9 +21,10 @@ export const protocol = Protocol.make({
|
|
|
22
21
|
from: Effect.fn("AlibabaMessages.fromRequest")(function* (req) {
|
|
23
22
|
const opts = yield* ProviderShared.validateWith(Schema.decodeUnknownEffect(Options))(req.providerOptions ?? {});
|
|
24
23
|
// Model Studio accepts enabled thinking without Anthropic's mandatory token budget.
|
|
25
|
-
const body = yield* AnthropicMessages.protocol.body.from(
|
|
24
|
+
const body = yield* AnthropicMessages.protocol.body.from({
|
|
25
|
+
...req,
|
|
26
26
|
providerOptions: { ...req.providerOptions, thinking: undefined },
|
|
27
|
-
})
|
|
27
|
+
});
|
|
28
28
|
const budget = opts.thinking?.budgetTokens ?? opts.thinking?.budget_tokens;
|
|
29
29
|
return {
|
|
30
30
|
...body,
|
|
@@ -3,7 +3,7 @@ import { Route } from "../route/client.js";
|
|
|
3
3
|
import { Framing } from "../route/framing.js";
|
|
4
4
|
import { Protocol } from "../route/protocol.js";
|
|
5
5
|
import { HttpTransport } from "../route/transport/index.js";
|
|
6
|
-
import { AIError, LLMRequest, type ProviderOptions } from "../schema/index.js";
|
|
6
|
+
import { AIError, type LLMRequest, type ProviderOptions } from "../schema/index.js";
|
|
7
7
|
import { Lifecycle } from "./utils/lifecycle.js";
|
|
8
8
|
import { ToolStream } from "./utils/tool-stream.js";
|
|
9
9
|
export declare const DEFAULT_BASE_URL = "https://api.anthropic.com/v1";
|
|
@@ -8,7 +8,7 @@ import { Framing } from "../route/framing.js";
|
|
|
8
8
|
import { Protocol } from "../route/protocol.js";
|
|
9
9
|
import { Headers } from "effect/http";
|
|
10
10
|
import { HttpTransport } from "../route/transport/index.js";
|
|
11
|
-
import { AIError, CacheTTL, HttpOptions,
|
|
11
|
+
import { AIError, CacheTTL, HttpOptions, LLMEvent, mergeJsonRecords, Usage, } from "../schema/index.js";
|
|
12
12
|
import { JsonObject, knownString, optionalArray, optionalNull, ProviderShared, withUntypedFrames } from "./shared.js";
|
|
13
13
|
import { classifyProviderFailure } from "../provider-error.js";
|
|
14
14
|
import { effortUpdate, resolveEffortUpdates } from "../effort-updates.js";
|
|
@@ -1429,12 +1429,13 @@ export const transport = () => {
|
|
|
1429
1429
|
const betas = new Set([...existingBetas, ...requiredBetas]);
|
|
1430
1430
|
return http.prepare({
|
|
1431
1431
|
...input,
|
|
1432
|
-
request:
|
|
1432
|
+
request: {
|
|
1433
|
+
...input.request,
|
|
1433
1434
|
http: new HttpOptions({
|
|
1434
1435
|
...input.request.http,
|
|
1435
1436
|
headers: { ...headers, "anthropic-beta": [...betas].join(",") },
|
|
1436
1437
|
}),
|
|
1437
|
-
}
|
|
1438
|
+
},
|
|
1438
1439
|
});
|
|
1439
1440
|
},
|
|
1440
1441
|
};
|
|
@@ -2,7 +2,7 @@ import { Schema } from "effect";
|
|
|
2
2
|
import { MediaProtocol } from "../route/media-protocol.js";
|
|
3
3
|
import { MediaRoute } from "../route/media.js";
|
|
4
4
|
import { type OpenString } from "../schema/index.js";
|
|
5
|
-
import { TranscriptionModel, TranscriptionResponse, type
|
|
5
|
+
import { TranscriptionModel, TranscriptionResponse, type TranscriptionRequest } from "../transcription.js";
|
|
6
6
|
export declare const DEFAULT_BASE_URL = "https://api.assemblyai.com";
|
|
7
7
|
export declare const PATH = "/v2/transcript";
|
|
8
8
|
export declare const UPLOAD_PATH = "/v2/upload";
|
|
@@ -24,7 +24,7 @@ export type AssemblyAITranscriptionOptions = {
|
|
|
24
24
|
};
|
|
25
25
|
readonly speech_models?: ReadonlyArray<OpenString<"universal-3-5-pro" | "universal-2">>;
|
|
26
26
|
} & Record<string, unknown>;
|
|
27
|
-
export type Request =
|
|
27
|
+
export type Request = TranscriptionRequest<TranscriptionModel<AssemblyAITranscriptionOptions>>;
|
|
28
28
|
export declare const Token: Schema.Struct<{
|
|
29
29
|
readonly transcriptID: Schema.String;
|
|
30
30
|
}>;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { MediaProtocol } from "../route/media-protocol.js";
|
|
2
2
|
import { MediaRoute } from "../route/media.js";
|
|
3
3
|
import { type OpenString } from "../schema/index.js";
|
|
4
|
-
import { SpeechModel, type
|
|
4
|
+
import { SpeechModel, type SpeechRequest } from "../speech.js";
|
|
5
5
|
import { SpeechStream } from "./utils/speech-stream.js";
|
|
6
6
|
export declare const DEFAULT_BASE_URL = "https://api.cartesia.ai";
|
|
7
7
|
export declare const API_VERSION = "2026-08-14";
|
|
@@ -18,7 +18,7 @@ export type CartesiaSpeechOptions = {
|
|
|
18
18
|
};
|
|
19
19
|
readonly pronunciation_dict_id?: string;
|
|
20
20
|
} & Record<string, unknown>;
|
|
21
|
-
export type Request =
|
|
21
|
+
export type Request = SpeechRequest<SpeechModel<CartesiaSpeechOptions>>;
|
|
22
22
|
interface State extends SpeechStream.Audio {
|
|
23
23
|
readonly done: boolean;
|
|
24
24
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ImageModel, ImageResponse, type
|
|
1
|
+
import { ImageModel, ImageResponse, type ImageRequest } from "../image.js";
|
|
2
2
|
import { MediaProtocol } from "../route/media-protocol.js";
|
|
3
3
|
import type { MediaRoute } from "../route/media.js";
|
|
4
4
|
/**
|
|
@@ -14,7 +14,7 @@ export type CloudflareWorkersAIImageOptions = {
|
|
|
14
14
|
readonly guidance?: number;
|
|
15
15
|
readonly negative_prompt?: string;
|
|
16
16
|
} & Record<string, unknown>;
|
|
17
|
-
export type Request =
|
|
17
|
+
export type Request = ImageRequest<ImageModel<CloudflareWorkersAIImageOptions>>;
|
|
18
18
|
export declare const protocol: MediaProtocol.Inline<Request, ImageResponse>;
|
|
19
19
|
export declare const model: (input: MediaRoute.ModelInput) => ImageModel<CloudflareWorkersAIImageOptions>;
|
|
20
20
|
export declare const CloudflareWorkersAIImages: {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { MediaProtocol } from "../route/media-protocol.js";
|
|
2
2
|
import { MediaRoute } from "../route/media.js";
|
|
3
3
|
import { type OpenString } from "../schema/index.js";
|
|
4
|
-
import { SpeechModel, type
|
|
4
|
+
import { SpeechModel, type SpeechRequest } from "../speech.js";
|
|
5
5
|
import { SpeechStream } from "./utils/speech-stream.js";
|
|
6
6
|
export declare const DEFAULT_BASE_URL = "https://api.deepgram.com";
|
|
7
7
|
export declare const PATH = "/v1/speak";
|
|
@@ -14,7 +14,7 @@ export type DeepgramSpeechOptions = {
|
|
|
14
14
|
readonly mip_opt_out?: boolean;
|
|
15
15
|
readonly tag?: string;
|
|
16
16
|
} & Record<string, unknown>;
|
|
17
|
-
export type Request =
|
|
17
|
+
export type Request = SpeechRequest<SpeechModel<DeepgramSpeechOptions>>;
|
|
18
18
|
export declare const protocol: MediaProtocol.Streamed<Request, {
|
|
19
19
|
readonly type: "audio-delta";
|
|
20
20
|
readonly chunk: Uint8Array<ArrayBufferLike>;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { MediaProtocol } from "../route/media-protocol.js";
|
|
2
2
|
import { MediaRoute } from "../route/media.js";
|
|
3
3
|
import { type OpenString } from "../schema/index.js";
|
|
4
|
-
import { TranscriptionModel, TranscriptionResponse, type
|
|
4
|
+
import { TranscriptionModel, TranscriptionResponse, type TranscriptionRequest } from "../transcription.js";
|
|
5
5
|
export declare const DEFAULT_BASE_URL = "https://api.deepgram.com";
|
|
6
6
|
export declare const PATH = "/v1/listen";
|
|
7
7
|
export type DeepgramTranscriptionOptions = {
|
|
@@ -17,7 +17,7 @@ export type DeepgramTranscriptionOptions = {
|
|
|
17
17
|
readonly mip_opt_out?: boolean;
|
|
18
18
|
readonly tag?: string | ReadonlyArray<string>;
|
|
19
19
|
} & Record<string, unknown>;
|
|
20
|
-
export type Request =
|
|
20
|
+
export type Request = TranscriptionRequest<TranscriptionModel<DeepgramTranscriptionOptions>>;
|
|
21
21
|
export declare const protocol: MediaProtocol.Inline<Request, TranscriptionResponse>;
|
|
22
22
|
export declare const model: (input: MediaRoute.ModelInput) => TranscriptionModel<DeepgramTranscriptionOptions>;
|
|
23
23
|
export declare const DeepgramTranscription: {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { MediaProtocol } from "../route/media-protocol.js";
|
|
2
2
|
import { MediaRoute } from "../route/media.js";
|
|
3
3
|
import { type OpenString } from "../schema/index.js";
|
|
4
|
-
import { SpeechModel, type
|
|
4
|
+
import { SpeechModel, type SpeechRequest } from "../speech.js";
|
|
5
5
|
import { SpeechStream } from "./utils/speech-stream.js";
|
|
6
6
|
export declare const DEFAULT_BASE_URL = "https://api.elevenlabs.io";
|
|
7
7
|
export declare const PATH = "/v1/text-to-speech";
|
|
@@ -17,7 +17,7 @@ export type ElevenLabsSpeechOptions = {
|
|
|
17
17
|
readonly seed?: number;
|
|
18
18
|
readonly apply_text_normalization?: OpenString<"auto" | "on" | "off">;
|
|
19
19
|
} & Record<string, unknown>;
|
|
20
|
-
export type Request =
|
|
20
|
+
export type Request = SpeechRequest<SpeechModel<ElevenLabsSpeechOptions>>;
|
|
21
21
|
export declare const protocol: MediaProtocol.Streamed<Request, {
|
|
22
22
|
readonly type: "audio-delta";
|
|
23
23
|
readonly chunk: Uint8Array<ArrayBufferLike>;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { MediaProtocol } from "../route/media-protocol.js";
|
|
2
2
|
import { MediaRoute } from "../route/media.js";
|
|
3
3
|
import { type OpenString } from "../schema/index.js";
|
|
4
|
-
import { TranscriptionModel, TranscriptionResponse, type
|
|
4
|
+
import { TranscriptionModel, TranscriptionResponse, type TranscriptionRequest } from "../transcription.js";
|
|
5
5
|
export declare const DEFAULT_BASE_URL = "https://api.elevenlabs.io";
|
|
6
6
|
export declare const PATH = "/v1/speech-to-text";
|
|
7
7
|
export type ElevenLabsTranscriptionOptions = {
|
|
@@ -19,7 +19,7 @@ export type ElevenLabsTranscriptionOptions = {
|
|
|
19
19
|
readonly entity_redaction?: string | ReadonlyArray<string>;
|
|
20
20
|
readonly entity_redaction_mode?: OpenString<"redacted" | "entity_type" | "enumerated_entity_type">;
|
|
21
21
|
} & Record<string, unknown>;
|
|
22
|
-
export type Request =
|
|
22
|
+
export type Request = TranscriptionRequest<TranscriptionModel<ElevenLabsTranscriptionOptions>>;
|
|
23
23
|
export declare const protocol: MediaProtocol.Inline<Request, TranscriptionResponse>;
|
|
24
24
|
export declare const model: (input: MediaRoute.ModelInput) => TranscriptionModel<ElevenLabsTranscriptionOptions>;
|
|
25
25
|
export declare const ElevenLabsTranscription: {
|
package/dist/protocols/gemini.js
CHANGED
|
@@ -443,11 +443,7 @@ const mapContinuedUsage = (requests, metadataKey) => {
|
|
|
443
443
|
});
|
|
444
444
|
};
|
|
445
445
|
const terminalFinishReason = (finishReason) => finishReason && finishReason !== "FINISH_REASON_UNSPECIFIED" ? finishReason : undefined;
|
|
446
|
-
const RECOVERABLE_FINISH_REASONS = new Set([
|
|
447
|
-
"MALFORMED_RESPONSE",
|
|
448
|
-
"MALFORMED_FUNCTION_CALL",
|
|
449
|
-
"UNEXPECTED_TOOL_CALL",
|
|
450
|
-
]);
|
|
446
|
+
const RECOVERABLE_FINISH_REASONS = new Set(["MALFORMED_RESPONSE", "MALFORMED_FUNCTION_CALL", "UNEXPECTED_TOOL_CALL"]);
|
|
451
447
|
const mapFinishReason = (finishReason, hasToolCalls) => {
|
|
452
448
|
if (finishReason === undefined)
|
|
453
449
|
return hasToolCalls ? "tool-calls" : "unknown";
|
|
@@ -715,9 +711,7 @@ export const transport = {
|
|
|
715
711
|
return Stream.empty;
|
|
716
712
|
})));
|
|
717
713
|
});
|
|
718
|
-
const next = (continuationToken) => Stream.unwrap(sse
|
|
719
|
-
.prepare({ ...prepared.input, body: { ...prepared.input.body, continuationToken } })
|
|
720
|
-
.pipe(Effect.flatMap((continued) => sse.execute(continued, request, runtime)), Effect.map(respond)));
|
|
714
|
+
const next = (continuationToken) => Stream.unwrap(sse.prepare({ ...prepared.input, body: { ...prepared.input.body, continuationToken } }).pipe(Effect.flatMap((continued) => sse.execute(continued, request, runtime)), Effect.map(respond)));
|
|
721
715
|
const first = yield* sse.execute(prepared.http, request, runtime);
|
|
722
716
|
return {
|
|
723
717
|
frames: respond(first),
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ImageModel, ImageResponse, type
|
|
1
|
+
import { ImageModel, ImageResponse, type ImageRequest } from "../image.js";
|
|
2
2
|
import { MediaProtocol } from "../route/media-protocol.js";
|
|
3
3
|
import { MediaRoute } from "../route/media.js";
|
|
4
4
|
import { type OpenString } from "../schema/index.js";
|
|
@@ -9,7 +9,7 @@ export type GoogleImageOptions = {
|
|
|
9
9
|
readonly thinkingLevel?: OpenString<"MINIMAL" | "LOW" | "MEDIUM" | "HIGH">;
|
|
10
10
|
readonly includeThoughts?: boolean;
|
|
11
11
|
} & Record<string, unknown>;
|
|
12
|
-
export type Request =
|
|
12
|
+
export type Request = ImageRequest<ImageModel<GoogleImageOptions>>;
|
|
13
13
|
export declare const protocol: MediaProtocol.Inline<Request, ImageResponse>;
|
|
14
14
|
export declare const model: (input: MediaRoute.ModelInput) => ImageModel<GoogleImageOptions>;
|
|
15
15
|
export declare const GoogleImages: {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { MediaProtocol } from "../route/media-protocol.js";
|
|
2
2
|
import { MediaRoute } from "../route/media.js";
|
|
3
|
-
import { SpeechModel, type
|
|
3
|
+
import { SpeechModel, type SpeechRequest } from "../speech.js";
|
|
4
4
|
import { GeminiGenerateContent } from "./utils/gemini-generate-content.js";
|
|
5
5
|
import { SpeechStream } from "./utils/speech-stream.js";
|
|
6
6
|
export declare const DEFAULT_BASE_URL = "https://generativelanguage.googleapis.com/v1beta";
|
|
@@ -21,7 +21,7 @@ export type GoogleSpeechOptions = {
|
|
|
21
21
|
};
|
|
22
22
|
};
|
|
23
23
|
} & Record<string, unknown>;
|
|
24
|
-
export type Request =
|
|
24
|
+
export type Request = SpeechRequest<SpeechModel<GoogleSpeechOptions>>;
|
|
25
25
|
interface State extends SpeechStream.Audio, GeminiGenerateContent.Metadata {
|
|
26
26
|
readonly mimeType?: string;
|
|
27
27
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { MediaProtocol } from "../route/media-protocol.js";
|
|
2
2
|
import { MediaRoute } from "../route/media.js";
|
|
3
3
|
import { type OpenString } from "../schema/index.js";
|
|
4
|
-
import { TranscriptionModel, type
|
|
4
|
+
import { TranscriptionModel, type TranscriptionRequest, type TranscriptionSegment, type TranscriptionWord } from "../transcription.js";
|
|
5
5
|
import { GeminiGenerateContent } from "./utils/gemini-generate-content.js";
|
|
6
6
|
export declare const DEFAULT_BASE_URL = "https://generativelanguage.googleapis.com/v1beta";
|
|
7
7
|
/**
|
|
@@ -15,7 +15,7 @@ export type GoogleTranscriptionOptions = {
|
|
|
15
15
|
readonly languageCodes?: ReadonlyArray<string>;
|
|
16
16
|
};
|
|
17
17
|
} & Record<string, unknown>;
|
|
18
|
-
export type Request =
|
|
18
|
+
export type Request = TranscriptionRequest<TranscriptionModel<GoogleTranscriptionOptions>>;
|
|
19
19
|
interface State extends GeminiGenerateContent.Metadata {
|
|
20
20
|
readonly text: string;
|
|
21
21
|
readonly segments: Array<TranscriptionSegment>;
|
|
@@ -2,13 +2,13 @@ import { Schema } from "effect";
|
|
|
2
2
|
import { MediaProtocol } from "../route/media-protocol.js";
|
|
3
3
|
import { MediaRoute } from "../route/media.js";
|
|
4
4
|
import { type OpenString } from "../schema/index.js";
|
|
5
|
-
import { VideoModel, VideoResponse, type
|
|
5
|
+
import { VideoModel, VideoResponse, type VideoRequest } from "../video.js";
|
|
6
6
|
export declare const DEFAULT_BASE_URL = "https://generativelanguage.googleapis.com/v1beta";
|
|
7
7
|
/** Provider-native `parameters`. Common fields (`aspect`, `resolution`, `durationSeconds`, `seed`) live on the request. */
|
|
8
8
|
export type GoogleVideoOptions = {
|
|
9
9
|
readonly personGeneration?: OpenString<"allow_all" | "allow_adult" | "dont_allow">;
|
|
10
10
|
} & Record<string, unknown>;
|
|
11
|
-
export type Request =
|
|
11
|
+
export type Request = VideoRequest<VideoModel<GoogleVideoOptions>>;
|
|
12
12
|
/** The long-running operation name, e.g. `models/veo-3.1-generate-preview/operations/abc123`. */
|
|
13
13
|
export declare const Token: Schema.Struct<{
|
|
14
14
|
readonly operation: Schema.String;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ImageModel, ImageResponse, type
|
|
1
|
+
import { ImageModel, ImageResponse, type ImageRequest } from "../image.js";
|
|
2
2
|
import { MediaProtocol } from "../route/media-protocol.js";
|
|
3
3
|
import { MediaRoute } from "../route/media.js";
|
|
4
4
|
import { type OpenString } from "../schema/index.js";
|
|
@@ -20,7 +20,7 @@ export type ImageOptions = {
|
|
|
20
20
|
};
|
|
21
21
|
readonly [key: string]: unknown;
|
|
22
22
|
};
|
|
23
|
-
export type Request =
|
|
23
|
+
export type Request = ImageRequest<ImageModel<ImageOptions>>;
|
|
24
24
|
export declare const protocol: MediaProtocol.Inline<Request, ImageResponse>;
|
|
25
25
|
export declare const model: (input: MediaRoute.ModelInput) => ImageModel<ImageOptions>;
|
|
26
26
|
export * as MetaImages from "./meta-images.js";
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Effect, Schema } from "effect";
|
|
2
2
|
import { Base64 } from "effect/encoding";
|
|
3
3
|
import { Protocol } from "../route/protocol.js";
|
|
4
|
-
import { LLMEvent,
|
|
4
|
+
import { LLMEvent, Message, ToolResultPart } from "../schema/index.js";
|
|
5
5
|
import { OpenResponses } from "./open-responses.js";
|
|
6
6
|
import { JsonObject, optionalArray, optionalNull, ProviderShared } from "./shared.js";
|
|
7
7
|
import { ResponsesHostedTools } from "./utils/responses-hosted-tools.js";
|
|
@@ -48,7 +48,8 @@ const adapter = {
|
|
|
48
48
|
};
|
|
49
49
|
const fromRequest = Effect.fn("MetaResponses.fromRequest")(function* (request) {
|
|
50
50
|
const key = request.model.route.providerMetadataKey ?? String(request.model.provider);
|
|
51
|
-
const body = yield* OpenResponses.fromRequestWithAdapter(
|
|
51
|
+
const body = yield* OpenResponses.fromRequestWithAdapter({
|
|
52
|
+
...request,
|
|
52
53
|
messages: request.messages.map((message) => Message.make({
|
|
53
54
|
...message,
|
|
54
55
|
content: message.content.map((part) => {
|
|
@@ -68,7 +69,7 @@ const fromRequest = Effect.fn("MetaResponses.fromRequest")(function* (request) {
|
|
|
68
69
|
});
|
|
69
70
|
}),
|
|
70
71
|
})),
|
|
71
|
-
}
|
|
72
|
+
}, adapter);
|
|
72
73
|
// Meta cannot see video nested in tool results; attach it after the complete result batch.
|
|
73
74
|
const input = [];
|
|
74
75
|
const videos = [];
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ImageModel, ImageResponse, type
|
|
1
|
+
import { ImageModel, ImageResponse, type ImageRequest } from "../image.js";
|
|
2
2
|
import { MediaProtocol } from "../route/media-protocol.js";
|
|
3
3
|
import { MediaRoute } from "../route/media.js";
|
|
4
4
|
import { type OpenString } from "../schema/index.js";
|
|
@@ -16,7 +16,7 @@ export type MiniMaxImageOptions = {
|
|
|
16
16
|
readonly width?: number;
|
|
17
17
|
readonly height?: number;
|
|
18
18
|
} & Record<string, unknown>;
|
|
19
|
-
export type Request =
|
|
19
|
+
export type Request = ImageRequest<ImageModel<MiniMaxImageOptions>>;
|
|
20
20
|
export declare const protocol: MediaProtocol.Inline<Request, ImageResponse>;
|
|
21
21
|
export declare const model: (input: MediaRoute.ModelInput) => ImageModel<MiniMaxImageOptions>;
|
|
22
22
|
export declare const MiniMaxImages: {
|
|
@@ -1728,18 +1728,6 @@ export declare const step: (state: ParserState, event: NormalizedEvent) => AIErr
|
|
|
1728
1728
|
readonly [x: string]: unknown;
|
|
1729
1729
|
};
|
|
1730
1730
|
} | undefined;
|
|
1731
|
-
} | {
|
|
1732
|
-
readonly type: "tool-error";
|
|
1733
|
-
readonly id: string;
|
|
1734
|
-
readonly name: string;
|
|
1735
|
-
readonly namespace?: string | undefined;
|
|
1736
|
-
readonly message: string;
|
|
1737
|
-
readonly error?: unknown;
|
|
1738
|
-
readonly providerMetadata?: {
|
|
1739
|
-
readonly [x: string]: {
|
|
1740
|
-
readonly [x: string]: unknown;
|
|
1741
|
-
};
|
|
1742
|
-
} | undefined;
|
|
1743
1731
|
} | {
|
|
1744
1732
|
readonly type: "step-finish";
|
|
1745
1733
|
readonly index: number;
|
|
@@ -1764,6 +1752,7 @@ export declare const step: (state: ParserState, event: NormalizedEvent) => AIErr
|
|
|
1764
1752
|
readonly explanation?: string | undefined;
|
|
1765
1753
|
};
|
|
1766
1754
|
readonly usage?: Usage | undefined;
|
|
1755
|
+
readonly message?: import("../schema/messages.js").Message | undefined;
|
|
1767
1756
|
readonly providerMetadata?: {
|
|
1768
1757
|
readonly [x: string]: {
|
|
1769
1758
|
readonly [x: string]: unknown;
|
|
@@ -1777,15 +1766,6 @@ export declare const step: (state: ParserState, event: NormalizedEvent) => AIErr
|
|
|
1777
1766
|
readonly [x: string]: unknown;
|
|
1778
1767
|
};
|
|
1779
1768
|
} | undefined;
|
|
1780
|
-
} | {
|
|
1781
|
-
readonly type: "provider-error";
|
|
1782
|
-
readonly message: string;
|
|
1783
|
-
readonly classification?: "context-overflow" | "payload-too-large" | undefined;
|
|
1784
|
-
readonly providerMetadata?: {
|
|
1785
|
-
readonly [x: string]: {
|
|
1786
|
-
readonly [x: string]: unknown;
|
|
1787
|
-
};
|
|
1788
|
-
} | undefined;
|
|
1789
1769
|
} | ({
|
|
1790
1770
|
readonly type: "compaction";
|
|
1791
1771
|
readonly provider: string & import("effect/Brand").Brand<"AI.ProviderID">;
|