@opencode/ai 2.0.21 → 2.0.23
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 +61 -1
- package/dist/cache-policy.js +10 -2
- package/dist/llm.d.ts +4 -0
- package/dist/promise.d.ts +8 -0
- package/dist/protocols/alibaba-chat.d.ts +7 -3
- package/dist/protocols/alibaba-chat.js +2 -1
- package/dist/protocols/alibaba-responses.d.ts +16 -12
- package/dist/protocols/alibaba-responses.js +3 -5
- package/dist/protocols/anthropic-messages.js +58 -51
- package/dist/protocols/bedrock-converse.js +33 -4
- package/dist/protocols/cartesia-speech.js +3 -3
- package/dist/protocols/cohere-chat.d.ts +178 -0
- package/dist/protocols/cohere-chat.js +299 -0
- package/dist/protocols/elevenlabs-speech.js +3 -3
- package/dist/protocols/gemini.d.ts +2 -2
- package/dist/protocols/gemini.js +3 -3
- package/dist/protocols/google-interactions.d.ts +236 -0
- package/dist/protocols/google-interactions.js +478 -0
- package/dist/protocols/google-speech.js +1 -1
- package/dist/protocols/google-transcription.js +1 -1
- package/dist/protocols/index.d.ts +2 -0
- package/dist/protocols/index.js +2 -0
- package/dist/protocols/meta-responses.d.ts +31 -58
- package/dist/protocols/meta-responses.js +8 -27
- package/dist/protocols/mistral-chat.d.ts +24 -9
- package/dist/protocols/mistral-chat.js +22 -10
- package/dist/protocols/open-responses.d.ts +410 -91
- package/dist/protocols/open-responses.js +25 -15
- package/dist/protocols/openai-chat.d.ts +409 -5
- package/dist/protocols/openai-chat.js +27 -26
- package/dist/protocols/openai-compatible-chat.d.ts +1 -1
- package/dist/protocols/openai-compatible-responses.d.ts +16 -4
- package/dist/protocols/openai-images.js +2 -2
- package/dist/protocols/openai-responses.d.ts +87 -223
- package/dist/protocols/openai-responses.js +10 -16
- package/dist/protocols/openai-speech.js +1 -1
- package/dist/protocols/openai-transcription.js +1 -1
- package/dist/protocols/shared.js +2 -2
- package/dist/protocols/stability-images.js +1 -1
- package/dist/protocols/utils/bedrock-media.js +2 -2
- package/dist/protocols/utils/cache.d.ts +5 -0
- package/dist/protocols/utils/cache.js +9 -1
- package/dist/protocols/utils/responses-checkpoint.js +2 -2
- package/dist/protocols/utils/responses-hosted-tools.js +1 -1
- package/dist/protocols/utils/tool-stream.d.ts +12 -0
- package/dist/protocols/utils/tool-stream.js +15 -7
- package/dist/protocols/venice-chat.d.ts +280 -0
- package/dist/protocols/venice-chat.js +283 -0
- package/dist/protocols/xai-responses.d.ts +18 -21
- package/dist/protocols/xai-responses.js +2 -8
- package/dist/protocols/zai-chat.d.ts +7 -3
- package/dist/protocols/zai-chat.js +6 -3
- package/dist/provider-error.js +27 -7
- package/dist/providers/alibaba.d.ts +17 -13
- package/dist/providers/amazon-bedrock/mantle/messages.d.ts +2 -0
- package/dist/providers/amazon-bedrock/mantle/messages.js +1 -0
- package/dist/providers/amazon-bedrock-mantle.d.ts +301 -9
- package/dist/providers/amazon-bedrock-mantle.js +28 -3
- package/dist/providers/azure.d.ts +13 -61
- package/dist/providers/baseten.d.ts +2 -2
- package/dist/providers/cerebras.d.ts +2 -2
- package/dist/providers/cloudflare-ai-gateway.d.ts +14 -62
- package/dist/providers/cloudflare-workers-ai.d.ts +2 -2
- package/dist/providers/cohere/chat.d.ts +4 -0
- package/dist/providers/cohere/chat.js +8 -0
- package/dist/providers/cohere.d.ts +395 -0
- package/dist/providers/cohere.js +48 -0
- package/dist/providers/deepinfra.d.ts +2 -2
- package/dist/providers/deepseek.d.ts +2 -2
- package/dist/providers/digitalocean.d.ts +469 -0
- package/dist/providers/digitalocean.js +53 -0
- package/dist/providers/fireworks.d.ts +2 -2
- package/dist/providers/google/interactions.d.ts +7 -0
- package/dist/providers/google/interactions.js +8 -0
- package/dist/providers/google-vertex-chat.d.ts +1 -1
- package/dist/providers/google-vertex-messages.js +1 -1
- package/dist/providers/google-vertex-responses.d.ts +16 -4
- package/dist/providers/google-vertex.d.ts +1 -1
- package/dist/providers/google.d.ts +95 -4
- package/dist/providers/google.js +8 -1
- package/dist/providers/groq.d.ts +8 -4
- package/dist/providers/groq.js +1 -1
- package/dist/providers/index.d.ts +3 -0
- package/dist/providers/index.js +3 -0
- package/dist/providers/meta.d.ts +15 -28
- package/dist/providers/minimax.d.ts +17 -5
- package/dist/providers/mistral.d.ts +10 -4
- package/dist/providers/moonshot.d.ts +17 -5
- package/dist/providers/openai-compatible-responses.d.ts +16 -4
- package/dist/providers/openai-compatible.d.ts +1 -1
- package/dist/providers/openai-options.d.ts +1 -1
- package/dist/providers/openai.d.ts +7 -31
- package/dist/providers/openrouter.d.ts +9 -5
- package/dist/providers/openrouter.js +1 -13
- package/dist/providers/togetherai.d.ts +2 -2
- package/dist/providers/venice.d.ts +183 -0
- package/dist/providers/venice.js +38 -0
- package/dist/providers/xai.d.ts +1 -1
- package/dist/providers/zai-coding-plan.d.ts +17 -5
- package/dist/providers/zai.d.ts +1 -1
- package/dist/route/client.d.ts +4 -0
- package/dist/route/client.js +2 -5
- package/dist/route/executor.js +13 -6
- package/dist/route/framing.js +23 -23
- package/dist/route/transport/http.d.ts +2 -1
- package/dist/route/transport/http.js +28 -6
- package/dist/schema/events.d.ts +176 -0
- package/dist/schema/events.js +4 -0
- package/dist/schema/options.d.ts +11 -0
- package/dist/schema/options.js +15 -2
- package/dist/testing.d.ts +32 -0
- package/dist/tool-history.js +17 -3
- package/package.json +3 -3
package/dist/route/framing.js
CHANGED
|
@@ -14,32 +14,32 @@ export const sseFraming = (bytes, events, includeDone = false) => bytes.pipe(Str
|
|
|
14
14
|
return {
|
|
15
15
|
output,
|
|
16
16
|
parser: makeParser((event) => {
|
|
17
|
-
if (event._tag === "Event"
|
|
18
|
-
|
|
17
|
+
if (event._tag === "Event" &&
|
|
18
|
+
(events === undefined || events.has(event.event)) &&
|
|
19
|
+
event.data.length > 0 &&
|
|
20
|
+
// Some OpenAI-compatible proxies serialize an empty flush as a bare
|
|
21
|
+
// `data: null`, between events or after `[DONE]`. No protocol has a
|
|
22
|
+
// null event, so it carries nothing and must not abort the stream.
|
|
23
|
+
event.data !== "null" &&
|
|
24
|
+
// Vertex AI partner models (e.g. `xai/grok-4.6`) send their SSE
|
|
25
|
+
// keepalive comment as `data: : keepalive` while reasoning.
|
|
26
|
+
event.data !== ": keepalive" &&
|
|
27
|
+
(event.data !== "[DONE]" || includeDone || (events !== undefined && event.event !== "message")))
|
|
28
|
+
output.push(event.data);
|
|
19
29
|
}),
|
|
20
30
|
};
|
|
21
|
-
}, (state, chunk) =>
|
|
31
|
+
}, (state, chunk) => {
|
|
22
32
|
const error = state.parser.feed(chunk);
|
|
23
|
-
if (error)
|
|
24
|
-
return
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
})), Stream.filter((event) => (events === undefined || events.has(event.event)) &&
|
|
34
|
-
event.data.length > 0 &&
|
|
35
|
-
// Some OpenAI-compatible proxies serialize an empty flush as a bare
|
|
36
|
-
// `data: null`, between events or after `[DONE]`. No protocol has a
|
|
37
|
-
// null event, so it carries nothing and must not abort the stream.
|
|
38
|
-
event.data !== "null" &&
|
|
39
|
-
// Vertex AI partner models (e.g. `xai/grok-4.6`) send their SSE
|
|
40
|
-
// keepalive comment as `data: : keepalive` while reasoning.
|
|
41
|
-
event.data !== ": keepalive" &&
|
|
42
|
-
(event.data !== "[DONE]" || includeDone || (events !== undefined && event.event !== "message"))), Stream.map((event) => event.data));
|
|
33
|
+
if (!error)
|
|
34
|
+
return Effect.succeed([state, state.output.splice(0)]);
|
|
35
|
+
const reason = new InvalidProviderOutputError({
|
|
36
|
+
route: "sse",
|
|
37
|
+
message: error.message,
|
|
38
|
+
body: chunk,
|
|
39
|
+
cause: error,
|
|
40
|
+
});
|
|
41
|
+
return Effect.fail(new AIError({ reason }));
|
|
42
|
+
}));
|
|
43
43
|
/** Server-Sent Events framing. Used by every JSON-streaming HTTP provider. */
|
|
44
44
|
export const sse = { id: "sse", frame: sseFraming };
|
|
45
45
|
/** Server-Sent Events framing that retains the conventional `[DONE]` sentinel. */
|
|
@@ -2,6 +2,7 @@ import { Effect } from "effect";
|
|
|
2
2
|
import { Headers, HttpClientRequest } from "effect/unstable/http";
|
|
3
3
|
import { Framing } from "../framing.js";
|
|
4
4
|
import type { HttpMiddleware, Transport, TransportPrepareInput } from "./index.js";
|
|
5
|
+
import { AIError } from "../../schema/index.js";
|
|
5
6
|
export type JsonRequestInput<Body> = TransportPrepareInput<Body>;
|
|
6
7
|
export interface JsonRequestParts<Body = unknown> {
|
|
7
8
|
readonly url: string;
|
|
@@ -19,7 +20,7 @@ export declare const jsonRequestParts: <Body>(input: JsonRequestInput<Body>) =>
|
|
|
19
20
|
jsonBody: Record<string, unknown> | Body;
|
|
20
21
|
bodyText: string;
|
|
21
22
|
headers: Headers.Headers;
|
|
22
|
-
},
|
|
23
|
+
}, AIError, never>;
|
|
23
24
|
export interface HttpJsonInput<_Body, Frame> {
|
|
24
25
|
readonly framing: Framing.Definition<Frame>;
|
|
25
26
|
}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { Effect } from "effect";
|
|
1
|
+
import { Clock, Duration, Effect, Stream } from "effect";
|
|
2
2
|
import { Headers, HttpClientRequest } from "effect/unstable/http";
|
|
3
3
|
import { Auth } from "../auth.js";
|
|
4
4
|
import { render as renderEndpoint } from "../endpoint.js";
|
|
5
5
|
import { Framing } from "../framing.js";
|
|
6
6
|
import * as ProviderShared from "../../protocols/shared.js";
|
|
7
|
-
import { mergeJsonRecords } from "../../schema/index.js";
|
|
7
|
+
import { AIError, DEFAULT_HTTP_TIMEOUT_MS, mergeJsonRecords, TransportError, } from "../../schema/index.js";
|
|
8
8
|
import { RequestExecutor } from "../executor.js";
|
|
9
9
|
const applyQuery = (url, query) => {
|
|
10
10
|
if (!query)
|
|
@@ -53,15 +53,37 @@ export const httpJson = (input) => ({
|
|
|
53
53
|
middleware: prepareInput.middleware,
|
|
54
54
|
};
|
|
55
55
|
}),
|
|
56
|
-
execute: (prepared,
|
|
57
|
-
const
|
|
56
|
+
execute: (prepared, request, runtime) => Effect.gen(function* () {
|
|
57
|
+
const timeout = (operation, message, http) => new AIError({
|
|
58
|
+
reason: new TransportError({
|
|
59
|
+
message,
|
|
60
|
+
transport: "http",
|
|
61
|
+
operation,
|
|
62
|
+
code: "Timeout",
|
|
63
|
+
url: prepared.request.url,
|
|
64
|
+
http,
|
|
65
|
+
}),
|
|
66
|
+
});
|
|
67
|
+
const started = yield* Clock.currentTimeMillis;
|
|
68
|
+
// Unlike the header and chunk limits, the whole-request budget has no default.
|
|
69
|
+
const total = request.http?.timeout ? Duration.millis(request.http.timeout) : Duration.infinity;
|
|
70
|
+
const response = yield* runtime.http.execute(prepared.request, prepared.middleware).pipe(Effect.timeoutOrElse({
|
|
71
|
+
duration: Duration.min(timeoutDuration(request.http?.headerTimeout), total),
|
|
72
|
+
orElse: () => timeout("request", "Timed out waiting for response headers"),
|
|
73
|
+
}));
|
|
74
|
+
const http = RequestExecutor.responseHttp(response);
|
|
75
|
+
const remaining = Duration.subtract(total, Duration.millis((yield* Clock.currentTimeMillis) - started));
|
|
58
76
|
return {
|
|
59
|
-
frames: prepared.framing.frame(RequestExecutor.responseStream(response)
|
|
60
|
-
|
|
77
|
+
frames: prepared.framing.frame(RequestExecutor.responseStream(response).pipe(Stream.timeoutOrElse({
|
|
78
|
+
duration: timeoutDuration(request.http?.chunkTimeout),
|
|
79
|
+
orElse: () => Stream.fail(timeout("read", "Timed out waiting for response data", http)),
|
|
80
|
+
}), Stream.interruptWhen(Effect.sleep(remaining).pipe(Effect.andThen(Effect.fail(timeout("read", "Timed out waiting for the response to complete", http))))))),
|
|
81
|
+
http,
|
|
61
82
|
body: prepared.framing.body,
|
|
62
83
|
};
|
|
63
84
|
}),
|
|
64
85
|
});
|
|
86
|
+
const timeoutDuration = (value) => value === false ? Duration.infinity : Duration.millis(value ?? DEFAULT_HTTP_TIMEOUT_MS);
|
|
65
87
|
export const sseJson = {
|
|
66
88
|
id: "http-json/sse",
|
|
67
89
|
with: () => httpJson({ framing: Framing.sse }),
|