@opencode/ai 0.0.0-reserved → 2.0.1
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 +879 -2
- package/dist/cache-policy.d.ts +2 -0
- package/dist/cache-policy.js +129 -0
- package/dist/image-client.d.ts +19 -0
- package/dist/image-client.js +28 -0
- package/dist/image.d.ts +110 -0
- package/dist/image.js +103 -0
- package/dist/index.d.ts +18 -0
- package/dist/index.js +12 -0
- package/dist/llm.d.ts +252 -0
- package/dist/llm.js +74 -0
- package/dist/protocols/alibaba-chat.d.ts +225 -0
- package/dist/protocols/alibaba-chat.js +75 -0
- package/dist/protocols/alibaba-messages.d.ts +350 -0
- package/dist/protocols/alibaba-messages.js +40 -0
- package/dist/protocols/alibaba-responses.d.ts +255 -0
- package/dist/protocols/alibaba-responses.js +80 -0
- package/dist/protocols/anthropic-messages.d.ts +980 -0
- package/dist/protocols/anthropic-messages.js +1460 -0
- package/dist/protocols/bedrock-converse.d.ts +499 -0
- package/dist/protocols/bedrock-converse.js +643 -0
- package/dist/protocols/bedrock-event-stream.d.ts +9 -0
- package/dist/protocols/bedrock-event-stream.js +97 -0
- package/dist/protocols/gemini.d.ts +285 -0
- package/dist/protocols/gemini.js +671 -0
- package/dist/protocols/google-images.d.ts +30 -0
- package/dist/protocols/google-images.js +181 -0
- package/dist/protocols/index.d.ts +12 -0
- package/dist/protocols/index.js +12 -0
- package/dist/protocols/meta-images.d.ts +26 -0
- package/dist/protocols/meta-images.js +89 -0
- package/dist/protocols/meta-messages.d.ts +356 -0
- package/dist/protocols/meta-messages.js +41 -0
- package/dist/protocols/meta-responses.d.ts +473 -0
- package/dist/protocols/meta-responses.js +173 -0
- package/dist/protocols/mistral-chat.d.ts +540 -0
- package/dist/protocols/mistral-chat.js +624 -0
- package/dist/protocols/open-responses-channel.d.ts +25 -0
- package/dist/protocols/open-responses-channel.js +141 -0
- package/dist/protocols/open-responses-continuation.d.ts +16 -0
- package/dist/protocols/open-responses-continuation.js +170 -0
- package/dist/protocols/open-responses.d.ts +1715 -0
- package/dist/protocols/open-responses.js +1228 -0
- package/dist/protocols/openai-chat.d.ts +860 -0
- package/dist/protocols/openai-chat.js +966 -0
- package/dist/protocols/openai-compatible-chat.d.ts +109 -0
- package/dist/protocols/openai-compatible-chat.js +19 -0
- package/dist/protocols/openai-compatible-responses.d.ts +172 -0
- package/dist/protocols/openai-compatible-responses.js +18 -0
- package/dist/protocols/openai-images.d.ts +32 -0
- package/dist/protocols/openai-images.js +183 -0
- package/dist/protocols/openai-responses.d.ts +1389 -0
- package/dist/protocols/openai-responses.js +260 -0
- package/dist/protocols/shared.d.ts +193 -0
- package/dist/protocols/shared.js +290 -0
- package/dist/protocols/utils/bedrock-auth.d.ts +60 -0
- package/dist/protocols/utils/bedrock-auth.js +85 -0
- package/dist/protocols/utils/bedrock-cache.d.ts +19 -0
- package/dist/protocols/utils/bedrock-cache.js +49 -0
- package/dist/protocols/utils/bedrock-media.d.ts +55 -0
- package/dist/protocols/utils/bedrock-media.js +73 -0
- package/dist/protocols/utils/cache.d.ts +6 -0
- package/dist/protocols/utils/cache.js +5 -0
- package/dist/protocols/utils/gemini-tool-schema.d.ts +2 -0
- package/dist/protocols/utils/gemini-tool-schema.js +103 -0
- package/dist/protocols/utils/image-input.d.ts +21 -0
- package/dist/protocols/utils/image-input.js +20 -0
- package/dist/protocols/utils/lifecycle.d.ts +24 -0
- package/dist/protocols/utils/lifecycle.js +72 -0
- package/dist/protocols/utils/meta-image.d.ts +2 -0
- package/dist/protocols/utils/meta-image.js +13 -0
- package/dist/protocols/utils/open-responses-options.d.ts +56 -0
- package/dist/protocols/utils/open-responses-options.js +61 -0
- package/dist/protocols/utils/openai-image.d.ts +5 -0
- package/dist/protocols/utils/openai-image.js +18 -0
- package/dist/protocols/utils/openai-options.d.ts +16 -0
- package/dist/protocols/utils/openai-options.js +14 -0
- package/dist/protocols/utils/partial-json-options.d.ts +62 -0
- package/dist/protocols/utils/partial-json-options.js +52 -0
- package/dist/protocols/utils/partial-json.d.ts +8 -0
- package/dist/protocols/utils/partial-json.js +279 -0
- package/dist/protocols/utils/responses-checkpoint.d.ts +4 -0
- package/dist/protocols/utils/responses-checkpoint.js +107 -0
- package/dist/protocols/utils/responses-compaction.d.ts +4 -0
- package/dist/protocols/utils/responses-compaction.js +129 -0
- package/dist/protocols/utils/responses-hosted-tools.d.ts +26 -0
- package/dist/protocols/utils/responses-hosted-tools.js +32 -0
- package/dist/protocols/utils/tool-schema.d.ts +8 -0
- package/dist/protocols/utils/tool-schema.js +54 -0
- package/dist/protocols/utils/tool-stream.d.ts +710 -0
- package/dist/protocols/utils/tool-stream.js +155 -0
- package/dist/protocols/xai-images.d.ts +26 -0
- package/dist/protocols/xai-images.js +106 -0
- package/dist/protocols/xai-responses.d.ts +250 -0
- package/dist/protocols/xai-responses.js +81 -0
- package/dist/protocols/zai-chat.d.ts +202 -0
- package/dist/protocols/zai-chat.js +49 -0
- package/dist/protocols/zai-images.d.ts +22 -0
- package/dist/protocols/zai-images.js +79 -0
- package/dist/protocols/zai-messages.d.ts +344 -0
- package/dist/protocols/zai-messages.js +27 -0
- package/dist/protocols.d.ts +1 -0
- package/dist/protocols.js +1 -0
- package/dist/provider-error.d.ts +15 -0
- package/dist/provider-error.js +125 -0
- package/dist/provider-package.d.ts +15 -0
- package/dist/provider-package.js +1 -0
- package/dist/provider.d.ts +23 -0
- package/dist/provider.js +2 -0
- package/dist/providers/alibaba/chat.d.ts +1 -0
- package/dist/providers/alibaba/chat.js +1 -0
- package/dist/providers/alibaba/messages.d.ts +3 -0
- package/dist/providers/alibaba/messages.js +1 -0
- package/dist/providers/alibaba/responses.d.ts +3 -0
- package/dist/providers/alibaba/responses.js +1 -0
- package/dist/providers/alibaba.d.ts +711 -0
- package/dist/providers/alibaba.js +94 -0
- package/dist/providers/amazon-bedrock/mantle/chat.d.ts +2 -0
- package/dist/providers/amazon-bedrock/mantle/chat.js +1 -0
- package/dist/providers/amazon-bedrock/mantle/responses.d.ts +2 -0
- package/dist/providers/amazon-bedrock/mantle/responses.js +1 -0
- package/dist/providers/amazon-bedrock/mantle.d.ts +2 -0
- package/dist/providers/amazon-bedrock/mantle.js +1 -0
- package/dist/providers/amazon-bedrock-mantle.d.ts +313 -0
- package/dist/providers/amazon-bedrock-mantle.js +79 -0
- package/dist/providers/amazon-bedrock.d.ts +173 -0
- package/dist/providers/amazon-bedrock.js +41 -0
- package/dist/providers/anthropic-compatible.d.ts +309 -0
- package/dist/providers/anthropic-compatible.js +50 -0
- package/dist/providers/anthropic.d.ts +307 -0
- package/dist/providers/anthropic.js +42 -0
- package/dist/providers/azure/chat.d.ts +2 -0
- package/dist/providers/azure/chat.js +1 -0
- package/dist/providers/azure/responses.d.ts +2 -0
- package/dist/providers/azure/responses.js +1 -0
- package/dist/providers/azure.d.ts +598 -0
- package/dist/providers/azure.js +115 -0
- package/dist/providers/baseten.d.ts +228 -0
- package/dist/providers/baseten.js +38 -0
- package/dist/providers/cerebras.d.ts +227 -0
- package/dist/providers/cerebras.js +40 -0
- package/dist/providers/cloudflare-ai-gateway.d.ts +237 -0
- package/dist/providers/cloudflare-ai-gateway.js +65 -0
- package/dist/providers/cloudflare-workers-ai.d.ts +231 -0
- package/dist/providers/cloudflare-workers-ai.js +51 -0
- package/dist/providers/deepinfra.d.ts +227 -0
- package/dist/providers/deepinfra.js +43 -0
- package/dist/providers/deepseek.d.ts +228 -0
- package/dist/providers/deepseek.js +41 -0
- package/dist/providers/fireworks.d.ts +228 -0
- package/dist/providers/fireworks.js +38 -0
- package/dist/providers/google-vertex/chat.d.ts +2 -0
- package/dist/providers/google-vertex/chat.js +1 -0
- package/dist/providers/google-vertex/gemini.d.ts +2 -0
- package/dist/providers/google-vertex/gemini.js +1 -0
- package/dist/providers/google-vertex/messages.d.ts +2 -0
- package/dist/providers/google-vertex/messages.js +1 -0
- package/dist/providers/google-vertex/responses.d.ts +2 -0
- package/dist/providers/google-vertex/responses.js +1 -0
- package/dist/providers/google-vertex-chat.d.ts +132 -0
- package/dist/providers/google-vertex-chat.js +55 -0
- package/dist/providers/google-vertex-messages.d.ts +306 -0
- package/dist/providers/google-vertex-messages.js +75 -0
- package/dist/providers/google-vertex-responses.d.ts +197 -0
- package/dist/providers/google-vertex-responses.js +56 -0
- package/dist/providers/google-vertex-shared.d.ts +22 -0
- package/dist/providers/google-vertex-shared.js +72 -0
- package/dist/providers/google-vertex.d.ts +119 -0
- package/dist/providers/google-vertex.js +98 -0
- package/dist/providers/google.d.ts +114 -0
- package/dist/providers/google.js +42 -0
- package/dist/providers/groq.d.ts +314 -0
- package/dist/providers/groq.js +81 -0
- package/dist/providers/index.d.ts +31 -0
- package/dist/providers/index.js +31 -0
- package/dist/providers/meta/chat.d.ts +2 -0
- package/dist/providers/meta/chat.js +1 -0
- package/dist/providers/meta/messages.d.ts +2 -0
- package/dist/providers/meta/messages.js +1 -0
- package/dist/providers/meta/responses.d.ts +2 -0
- package/dist/providers/meta/responses.js +1 -0
- package/dist/providers/meta.d.ts +636 -0
- package/dist/providers/meta.js +113 -0
- package/dist/providers/minimax/chat.d.ts +4 -0
- package/dist/providers/minimax/chat.js +8 -0
- package/dist/providers/minimax/messages.d.ts +1 -0
- package/dist/providers/minimax/messages.js +1 -0
- package/dist/providers/minimax/responses.d.ts +4 -0
- package/dist/providers/minimax/responses.js +8 -0
- package/dist/providers/minimax.d.ts +598 -0
- package/dist/providers/minimax.js +89 -0
- package/dist/providers/mistral.d.ts +207 -0
- package/dist/providers/mistral.js +28 -0
- package/dist/providers/moonshot/chat.d.ts +1 -0
- package/dist/providers/moonshot/chat.js +1 -0
- package/dist/providers/moonshot/messages.d.ts +4 -0
- package/dist/providers/moonshot/messages.js +8 -0
- package/dist/providers/moonshot/responses.d.ts +4 -0
- package/dist/providers/moonshot/responses.js +8 -0
- package/dist/providers/moonshot.d.ts +596 -0
- package/dist/providers/moonshot.js +90 -0
- package/dist/providers/open-responses-options.d.ts +6 -0
- package/dist/providers/open-responses-options.js +1 -0
- package/dist/providers/openai/chat.d.ts +2 -0
- package/dist/providers/openai/chat.js +1 -0
- package/dist/providers/openai/responses.d.ts +2 -0
- package/dist/providers/openai/responses.js +1 -0
- package/dist/providers/openai-compatible/responses.d.ts +1 -0
- package/dist/providers/openai-compatible/responses.js +1 -0
- package/dist/providers/openai-compatible-responses.d.ts +195 -0
- package/dist/providers/openai-compatible-responses.js +32 -0
- package/dist/providers/openai-compatible.d.ts +130 -0
- package/dist/providers/openai-compatible.js +33 -0
- package/dist/providers/openai-options.d.ts +26 -0
- package/dist/providers/openai-options.js +41 -0
- package/dist/providers/openai.d.ts +404 -0
- package/dist/providers/openai.js +82 -0
- package/dist/providers/openrouter.d.ts +563 -0
- package/dist/providers/openrouter.js +114 -0
- package/dist/providers/togetherai.d.ts +227 -0
- package/dist/providers/togetherai.js +40 -0
- package/dist/providers/xai.d.ts +163 -0
- package/dist/providers/xai.js +88 -0
- package/dist/providers/zai/chat.d.ts +1 -0
- package/dist/providers/zai/chat.js +1 -0
- package/dist/providers/zai-coding-plan/chat.d.ts +1 -0
- package/dist/providers/zai-coding-plan/chat.js +1 -0
- package/dist/providers/zai-coding-plan/messages.d.ts +4 -0
- package/dist/providers/zai-coding-plan/messages.js +8 -0
- package/dist/providers/zai-coding-plan/responses.d.ts +4 -0
- package/dist/providers/zai-coding-plan/responses.js +8 -0
- package/dist/providers/zai-coding-plan.d.ts +577 -0
- package/dist/providers/zai-coding-plan.js +63 -0
- package/dist/providers/zai.d.ts +149 -0
- package/dist/providers/zai.js +53 -0
- package/dist/providers.d.ts +1 -0
- package/dist/providers.js +1 -0
- package/dist/route/auth-options.d.ts +34 -0
- package/dist/route/auth-options.js +14 -0
- package/dist/route/auth.d.ts +51 -0
- package/dist/route/auth.js +87 -0
- package/dist/route/client.d.ts +430 -0
- package/dist/route/client.js +307 -0
- package/dist/route/endpoint.d.ts +28 -0
- package/dist/route/endpoint.js +21 -0
- package/dist/route/executor.d.ts +27 -0
- package/dist/route/executor.js +183 -0
- package/dist/route/framing.d.ts +29 -0
- package/dist/route/framing.js +14 -0
- package/dist/route/index.d.ts +16 -0
- package/dist/route/index.js +9 -0
- package/dist/route/protocol.d.ts +76 -0
- package/dist/route/protocol.js +16 -0
- package/dist/route/transport/http.d.ts +34 -0
- package/dist/route/transport/http.js +68 -0
- package/dist/route/transport/index.d.ts +41 -0
- package/dist/route/transport/index.js +4 -0
- package/dist/route/transport/websocket-channel.d.ts +57 -0
- package/dist/route/transport/websocket-channel.js +1 -0
- package/dist/route/transport/websocket.d.ts +56 -0
- package/dist/route/transport/websocket.js +370 -0
- package/dist/route.d.ts +1 -0
- package/dist/route.js +1 -0
- package/dist/schema/errors.d.ts +170 -0
- package/dist/schema/errors.js +131 -0
- package/dist/schema/events.d.ts +8123 -0
- package/dist/schema/events.js +550 -0
- package/dist/schema/ids.d.ts +17 -0
- package/dist/schema/ids.js +10 -0
- package/dist/schema/index.d.ts +5 -0
- package/dist/schema/index.js +5 -0
- package/dist/schema/messages.d.ts +646 -0
- package/dist/schema/messages.js +301 -0
- package/dist/schema/options.d.ts +159 -0
- package/dist/schema/options.js +189 -0
- package/dist/testing.d.ts +1693 -0
- package/dist/testing.js +129 -0
- package/dist/tool-history.d.ts +2 -0
- package/dist/tool-history.js +84 -0
- package/dist/tool-runtime.d.ts +15 -0
- package/dist/tool-runtime.js +62 -0
- package/dist/tool.d.ts +136 -0
- package/dist/tool.js +66 -0
- package/dist/utils/record.d.ts +2 -0
- package/dist/utils/record.js +2 -0
- package/dist/utils/sanitize.d.ts +1 -0
- package/dist/utils/sanitize.js +12 -0
- package/package.json +43 -10
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { EventStreamCodec } from "@smithy/eventstream-codec";
|
|
2
|
+
import { fromUtf8, toUtf8 } from "@smithy/util-utf8";
|
|
3
|
+
import { Effect, Encoding, Stream } from "effect";
|
|
4
|
+
import { AIError, AIErrorReason, InvalidProviderOutputError } from "../schema/index.js";
|
|
5
|
+
import { Framing } from "../route/framing.js";
|
|
6
|
+
import { ProviderShared } from "./shared.js";
|
|
7
|
+
// Bedrock streams responses using the AWS event stream binary protocol — each
|
|
8
|
+
// frame is `[length:4][headers-length:4][prelude-crc:4][headers][payload][crc:4]`.
|
|
9
|
+
// We use `@smithy/eventstream-codec` to validate framing and CRCs, then
|
|
10
|
+
// reconstruct the JSON wrapping by `:event-type` so the chunk schema can match.
|
|
11
|
+
const eventCodec = new EventStreamCodec(toUtf8, fromUtf8);
|
|
12
|
+
const utf8 = new TextDecoder();
|
|
13
|
+
const initialFrameBuffer = { buffer: new Uint8Array(0), offset: 0 };
|
|
14
|
+
const endOfStream = { _tag: "End" };
|
|
15
|
+
const appendChunk = (state, chunk) => {
|
|
16
|
+
const remaining = state.buffer.length - state.offset;
|
|
17
|
+
// Compact: drop the consumed prefix and append the new chunk in one alloc.
|
|
18
|
+
// This bounds buffer growth to at most one network chunk past the live
|
|
19
|
+
// window, regardless of stream length.
|
|
20
|
+
const next = new Uint8Array(remaining + chunk.length);
|
|
21
|
+
next.set(state.buffer.subarray(state.offset), 0);
|
|
22
|
+
next.set(chunk, remaining);
|
|
23
|
+
return { buffer: next, offset: 0 };
|
|
24
|
+
};
|
|
25
|
+
const consumeFrames = (route) => (state, input) => Effect.gen(function* () {
|
|
26
|
+
if (input._tag === "End") {
|
|
27
|
+
const remaining = state.buffer.subarray(state.offset);
|
|
28
|
+
if (remaining.length > 0)
|
|
29
|
+
return yield* new AIError({
|
|
30
|
+
reason: new InvalidProviderOutputError({
|
|
31
|
+
route,
|
|
32
|
+
classification: "incomplete-stream",
|
|
33
|
+
message: `Incomplete Bedrock Converse event-stream frame: ${remaining.length} buffered bytes remain at end of stream`,
|
|
34
|
+
body: Encoding.encodeBase64(remaining),
|
|
35
|
+
}),
|
|
36
|
+
});
|
|
37
|
+
return [state, []];
|
|
38
|
+
}
|
|
39
|
+
let cursor = appendChunk(state, input.bytes);
|
|
40
|
+
const out = [];
|
|
41
|
+
while (cursor.buffer.length - cursor.offset >= 4) {
|
|
42
|
+
const view = cursor.buffer.subarray(cursor.offset);
|
|
43
|
+
const totalLength = new DataView(view.buffer, view.byteOffset, view.byteLength).getUint32(0, false);
|
|
44
|
+
if (view.length < totalLength)
|
|
45
|
+
break;
|
|
46
|
+
const decoded = yield* Effect.try({
|
|
47
|
+
try: () => eventCodec.decode(view.subarray(0, totalLength)),
|
|
48
|
+
catch: (error) => ProviderShared.eventError(route, `Failed to decode Bedrock Converse event-stream frame: ${error instanceof Error ? error.message : String(error)}`, Encoding.encodeBase64(view.subarray(0, totalLength)), error),
|
|
49
|
+
});
|
|
50
|
+
cursor = { buffer: cursor.buffer, offset: cursor.offset + totalLength };
|
|
51
|
+
const payload = utf8.decode(decoded.body);
|
|
52
|
+
const body = ProviderShared.encodeJson({ headers: decoded.headers, body: payload });
|
|
53
|
+
const messageType = decoded.headers[":message-type"]?.value;
|
|
54
|
+
if (messageType === "error") {
|
|
55
|
+
const code = decoded.headers[":error-code"]?.value;
|
|
56
|
+
const message = decoded.headers[":error-message"]?.value;
|
|
57
|
+
return yield* ProviderShared.eventError(route, [code, message].filter((value) => typeof value === "string").join(": ") ||
|
|
58
|
+
"Bedrock Converse event-stream error", body);
|
|
59
|
+
}
|
|
60
|
+
const eventType = messageType === "event"
|
|
61
|
+
? decoded.headers[":event-type"]?.value
|
|
62
|
+
: messageType === "exception"
|
|
63
|
+
? decoded.headers[":exception-type"]?.value
|
|
64
|
+
: undefined;
|
|
65
|
+
if (typeof eventType !== "string")
|
|
66
|
+
continue;
|
|
67
|
+
if (!payload)
|
|
68
|
+
continue;
|
|
69
|
+
// The AWS event stream pads short payloads with a `p` field. Drop it
|
|
70
|
+
// before handing the object to the chunk schema. JSON decode goes
|
|
71
|
+
// through the shared Schema-driven codec to satisfy the package rule
|
|
72
|
+
// against ad-hoc `JSON.parse` calls.
|
|
73
|
+
const parsed = (yield* ProviderShared.parseJson(route, payload, "Failed to parse Bedrock Converse event-stream payload").pipe(Effect.mapError((error) => new AIError({
|
|
74
|
+
reason: AIErrorReason.make({ ...error.reason, message: error.message, cause: error.reason.cause, body }),
|
|
75
|
+
}))));
|
|
76
|
+
delete parsed.p;
|
|
77
|
+
out.push({
|
|
78
|
+
...(messageType === "exception"
|
|
79
|
+
? { exception: { type: eventType, details: parsed } }
|
|
80
|
+
: { [eventType]: parsed }),
|
|
81
|
+
rawBody: body,
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
return [cursor, out];
|
|
85
|
+
});
|
|
86
|
+
/**
|
|
87
|
+
* AWS event-stream framing for Bedrock Converse. Each frame is decoded by
|
|
88
|
+
* `@smithy/eventstream-codec` (length + header + payload + CRC) and rewrapped
|
|
89
|
+
* under its `:event-type` header so the chunk schema can match the JSON
|
|
90
|
+
* payload directly.
|
|
91
|
+
*/
|
|
92
|
+
export const framing = (route) => ({
|
|
93
|
+
id: "aws-event-stream",
|
|
94
|
+
body: (frame) => ("rawBody" in frame && typeof frame.rawBody === "string" ? frame.rawBody : undefined),
|
|
95
|
+
frame: (bytes) => bytes.pipe(Stream.map((bytes) => ({ _tag: "Chunk", bytes })), Stream.concat(Stream.succeed(endOfStream)), Stream.mapAccumEffect(() => initialFrameBuffer, consumeFrames(route))),
|
|
96
|
+
});
|
|
97
|
+
export * as BedrockEventStream from "./bedrock-event-stream.js";
|
|
@@ -0,0 +1,285 @@
|
|
|
1
|
+
import { Schema } from "effect";
|
|
2
|
+
import { Route } from "../route/client.js";
|
|
3
|
+
import { Protocol } from "../route/protocol.js";
|
|
4
|
+
import { Lifecycle } from "./utils/lifecycle.js";
|
|
5
|
+
export declare const DEFAULT_BASE_URL = "https://generativelanguage.googleapis.com/v1beta";
|
|
6
|
+
export interface OptionsInput {
|
|
7
|
+
readonly [key: string]: unknown;
|
|
8
|
+
readonly cachedContent?: string;
|
|
9
|
+
readonly safetySettings?: ReadonlyArray<{
|
|
10
|
+
readonly category: "HARM_CATEGORY_UNSPECIFIED" | "HARM_CATEGORY_HATE_SPEECH" | "HARM_CATEGORY_DANGEROUS_CONTENT" | "HARM_CATEGORY_HARASSMENT" | "HARM_CATEGORY_SEXUALLY_EXPLICIT" | "HARM_CATEGORY_CIVIC_INTEGRITY" | (string & {});
|
|
11
|
+
readonly threshold: "HARM_BLOCK_THRESHOLD_UNSPECIFIED" | "BLOCK_LOW_AND_ABOVE" | "BLOCK_MEDIUM_AND_ABOVE" | "BLOCK_ONLY_HIGH" | "BLOCK_NONE" | "OFF" | (string & {});
|
|
12
|
+
}>;
|
|
13
|
+
readonly serviceTier?: "standard" | "flex" | "priority" | (string & {});
|
|
14
|
+
readonly thinkingConfig?: {
|
|
15
|
+
readonly thinkingBudget?: number;
|
|
16
|
+
readonly includeThoughts?: boolean;
|
|
17
|
+
readonly thinkingLevel?: "minimal" | "low" | "medium" | "high" | (string & {});
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
export type ProviderOptionsInput = OptionsInput;
|
|
21
|
+
declare const GeminiBody: Schema.Struct<{
|
|
22
|
+
cachedContent: Schema.optional<Schema.String>;
|
|
23
|
+
contents: Schema.$Array<Schema.Struct<{
|
|
24
|
+
readonly role: Schema.optional<Schema.NullOr<Schema.Literals<readonly ["user", "model"]>>>;
|
|
25
|
+
readonly parts: Schema.optional<Schema.NullOr<Schema.$Array<Schema.Union<readonly [Schema.Struct<{
|
|
26
|
+
readonly text: Schema.String;
|
|
27
|
+
readonly thought: Schema.optional<Schema.NullOr<Schema.Boolean>>;
|
|
28
|
+
readonly thoughtSignature: Schema.optional<Schema.NullOr<Schema.String>>;
|
|
29
|
+
}>, Schema.Struct<{
|
|
30
|
+
readonly inlineData: Schema.Struct<{
|
|
31
|
+
readonly mimeType: Schema.String;
|
|
32
|
+
readonly data: Schema.String;
|
|
33
|
+
}>;
|
|
34
|
+
}>, Schema.Struct<{
|
|
35
|
+
readonly functionCall: Schema.Struct<{
|
|
36
|
+
readonly id: Schema.optional<Schema.NullOr<Schema.String>>;
|
|
37
|
+
readonly name: Schema.String;
|
|
38
|
+
readonly args: Schema.optional<Schema.Unknown>;
|
|
39
|
+
}>;
|
|
40
|
+
readonly thoughtSignature: Schema.optional<Schema.NullOr<Schema.String>>;
|
|
41
|
+
}>, Schema.Struct<{
|
|
42
|
+
readonly functionResponse: Schema.Struct<{
|
|
43
|
+
readonly id: Schema.optional<Schema.String>;
|
|
44
|
+
readonly name: Schema.String;
|
|
45
|
+
readonly response: Schema.Unknown;
|
|
46
|
+
readonly parts: Schema.optional<Schema.$Array<Schema.Struct<{
|
|
47
|
+
readonly inlineData: Schema.Struct<{
|
|
48
|
+
readonly mimeType: Schema.String;
|
|
49
|
+
readonly data: Schema.String;
|
|
50
|
+
}>;
|
|
51
|
+
}>>>;
|
|
52
|
+
}>;
|
|
53
|
+
}>]>>>>;
|
|
54
|
+
}>>;
|
|
55
|
+
labels: Schema.optional<Schema.$Record<Schema.String, Schema.String>>;
|
|
56
|
+
safetySettings: Schema.optional<Schema.$Array<Schema.Struct<{
|
|
57
|
+
readonly category: Schema.String;
|
|
58
|
+
readonly threshold: Schema.String;
|
|
59
|
+
}>>>;
|
|
60
|
+
serviceTier: Schema.optional<Schema.String>;
|
|
61
|
+
systemInstruction: Schema.optional<Schema.Struct<{
|
|
62
|
+
readonly parts: Schema.$Array<Schema.Struct<{
|
|
63
|
+
readonly text: Schema.String;
|
|
64
|
+
}>>;
|
|
65
|
+
}>>;
|
|
66
|
+
tools: Schema.optional<Schema.$Array<Schema.Struct<{
|
|
67
|
+
readonly functionDeclarations: Schema.$Array<Schema.Struct<{
|
|
68
|
+
readonly name: Schema.String;
|
|
69
|
+
readonly description: Schema.String;
|
|
70
|
+
readonly parameters: Schema.optional<Schema.$Record<Schema.String, Schema.Unknown>>;
|
|
71
|
+
}>>;
|
|
72
|
+
}>>>;
|
|
73
|
+
toolConfig: Schema.optional<Schema.Struct<{
|
|
74
|
+
readonly functionCallingConfig: Schema.Struct<{
|
|
75
|
+
readonly mode: Schema.Literals<readonly ["AUTO", "NONE", "ANY"]>;
|
|
76
|
+
readonly allowedFunctionNames: Schema.optional<Schema.$Array<Schema.String>>;
|
|
77
|
+
}>;
|
|
78
|
+
}>>;
|
|
79
|
+
generationConfig: Schema.optional<Schema.Struct<{
|
|
80
|
+
readonly maxOutputTokens: Schema.optional<Schema.Number>;
|
|
81
|
+
readonly temperature: Schema.optional<Schema.Number>;
|
|
82
|
+
readonly topP: Schema.optional<Schema.Number>;
|
|
83
|
+
readonly topK: Schema.optional<Schema.Number>;
|
|
84
|
+
readonly frequencyPenalty: Schema.optional<Schema.Number>;
|
|
85
|
+
readonly presencePenalty: Schema.optional<Schema.Number>;
|
|
86
|
+
readonly seed: Schema.optional<Schema.Number>;
|
|
87
|
+
readonly stopSequences: Schema.optional<Schema.$Array<Schema.String>>;
|
|
88
|
+
readonly thinkingConfig: Schema.optional<Schema.Struct<{
|
|
89
|
+
readonly thinkingBudget: Schema.optional<Schema.Number>;
|
|
90
|
+
readonly includeThoughts: Schema.optional<Schema.Boolean>;
|
|
91
|
+
readonly thinkingLevel: Schema.optional<Schema.String>;
|
|
92
|
+
}>>;
|
|
93
|
+
}>>;
|
|
94
|
+
}>;
|
|
95
|
+
export type GeminiBody = Schema.Schema.Type<typeof GeminiBody>;
|
|
96
|
+
/**
|
|
97
|
+
* The Gemini protocol — request body construction, body schema, and the
|
|
98
|
+
* streaming-event state machine shared by Google AI Studio and Vertex Gemini.
|
|
99
|
+
*/
|
|
100
|
+
export declare const protocol: Protocol<{
|
|
101
|
+
readonly contents: readonly {
|
|
102
|
+
readonly parts?: readonly ({
|
|
103
|
+
readonly inlineData: {
|
|
104
|
+
readonly mimeType: string;
|
|
105
|
+
readonly data: string;
|
|
106
|
+
};
|
|
107
|
+
} | {
|
|
108
|
+
readonly text: string;
|
|
109
|
+
readonly thought?: boolean | null | undefined;
|
|
110
|
+
readonly thoughtSignature?: string | null | undefined;
|
|
111
|
+
} | {
|
|
112
|
+
readonly functionCall: {
|
|
113
|
+
readonly name: string;
|
|
114
|
+
readonly id?: string | null | undefined;
|
|
115
|
+
readonly args?: unknown;
|
|
116
|
+
};
|
|
117
|
+
readonly thoughtSignature?: string | null | undefined;
|
|
118
|
+
} | {
|
|
119
|
+
readonly functionResponse: {
|
|
120
|
+
readonly name: string;
|
|
121
|
+
readonly response: unknown;
|
|
122
|
+
readonly id?: string | undefined;
|
|
123
|
+
readonly parts?: readonly {
|
|
124
|
+
readonly inlineData: {
|
|
125
|
+
readonly mimeType: string;
|
|
126
|
+
readonly data: string;
|
|
127
|
+
};
|
|
128
|
+
}[] | undefined;
|
|
129
|
+
};
|
|
130
|
+
})[] | null | undefined;
|
|
131
|
+
readonly role?: "model" | "user" | null | undefined;
|
|
132
|
+
}[];
|
|
133
|
+
readonly tools?: readonly {
|
|
134
|
+
readonly functionDeclarations: readonly {
|
|
135
|
+
readonly description: string;
|
|
136
|
+
readonly name: string;
|
|
137
|
+
readonly parameters?: {
|
|
138
|
+
readonly [x: string]: unknown;
|
|
139
|
+
} | undefined;
|
|
140
|
+
}[];
|
|
141
|
+
}[] | undefined;
|
|
142
|
+
readonly serviceTier?: string | undefined;
|
|
143
|
+
readonly toolConfig?: {
|
|
144
|
+
readonly functionCallingConfig: {
|
|
145
|
+
readonly mode: "AUTO" | "NONE" | "ANY";
|
|
146
|
+
readonly allowedFunctionNames?: readonly string[] | undefined;
|
|
147
|
+
};
|
|
148
|
+
} | undefined;
|
|
149
|
+
readonly cachedContent?: string | undefined;
|
|
150
|
+
readonly safetySettings?: readonly {
|
|
151
|
+
readonly category: string;
|
|
152
|
+
readonly threshold: string;
|
|
153
|
+
}[] | undefined;
|
|
154
|
+
readonly labels?: {
|
|
155
|
+
readonly [x: string]: string;
|
|
156
|
+
} | undefined;
|
|
157
|
+
readonly systemInstruction?: {
|
|
158
|
+
readonly parts: readonly {
|
|
159
|
+
readonly text: string;
|
|
160
|
+
}[];
|
|
161
|
+
} | undefined;
|
|
162
|
+
readonly generationConfig?: {
|
|
163
|
+
readonly temperature?: number | undefined;
|
|
164
|
+
readonly topP?: number | undefined;
|
|
165
|
+
readonly topK?: number | undefined;
|
|
166
|
+
readonly frequencyPenalty?: number | undefined;
|
|
167
|
+
readonly presencePenalty?: number | undefined;
|
|
168
|
+
readonly seed?: number | undefined;
|
|
169
|
+
readonly stopSequences?: readonly string[] | undefined;
|
|
170
|
+
readonly thinkingConfig?: {
|
|
171
|
+
readonly thinkingBudget?: number | undefined;
|
|
172
|
+
readonly includeThoughts?: boolean | undefined;
|
|
173
|
+
readonly thinkingLevel?: string | undefined;
|
|
174
|
+
} | undefined;
|
|
175
|
+
readonly maxOutputTokens?: number | undefined;
|
|
176
|
+
} | undefined;
|
|
177
|
+
}, string, {
|
|
178
|
+
readonly error?: unknown;
|
|
179
|
+
readonly candidates?: readonly {
|
|
180
|
+
readonly content?: {
|
|
181
|
+
readonly parts?: readonly unknown[] | null | undefined;
|
|
182
|
+
readonly role?: "model" | "user" | null | undefined;
|
|
183
|
+
} | null | undefined;
|
|
184
|
+
readonly finishReason?: string | null | undefined;
|
|
185
|
+
}[] | null | undefined;
|
|
186
|
+
readonly promptFeedback?: {
|
|
187
|
+
readonly [x: string]: unknown;
|
|
188
|
+
readonly blockReason?: string | null | undefined;
|
|
189
|
+
readonly blockReasonMessage?: string | null | undefined;
|
|
190
|
+
readonly safetyRatings?: unknown;
|
|
191
|
+
} | null | undefined;
|
|
192
|
+
readonly usageMetadata?: {
|
|
193
|
+
readonly cachedContentTokenCount?: number | null | undefined;
|
|
194
|
+
readonly thoughtsTokenCount?: number | null | undefined;
|
|
195
|
+
readonly promptTokenCount?: number | null | undefined;
|
|
196
|
+
readonly candidatesTokenCount?: number | null | undefined;
|
|
197
|
+
readonly totalTokenCount?: number | null | undefined;
|
|
198
|
+
} | null | undefined;
|
|
199
|
+
}, {
|
|
200
|
+
route: string;
|
|
201
|
+
providerMetadataKey: string;
|
|
202
|
+
hasToolCalls: boolean;
|
|
203
|
+
lifecycle: Lifecycle.State;
|
|
204
|
+
nextReasoningId: number;
|
|
205
|
+
nextTextId: number;
|
|
206
|
+
}>;
|
|
207
|
+
export declare const route: Route<{
|
|
208
|
+
readonly contents: readonly {
|
|
209
|
+
readonly parts?: readonly ({
|
|
210
|
+
readonly inlineData: {
|
|
211
|
+
readonly mimeType: string;
|
|
212
|
+
readonly data: string;
|
|
213
|
+
};
|
|
214
|
+
} | {
|
|
215
|
+
readonly text: string;
|
|
216
|
+
readonly thought?: boolean | null | undefined;
|
|
217
|
+
readonly thoughtSignature?: string | null | undefined;
|
|
218
|
+
} | {
|
|
219
|
+
readonly functionCall: {
|
|
220
|
+
readonly name: string;
|
|
221
|
+
readonly id?: string | null | undefined;
|
|
222
|
+
readonly args?: unknown;
|
|
223
|
+
};
|
|
224
|
+
readonly thoughtSignature?: string | null | undefined;
|
|
225
|
+
} | {
|
|
226
|
+
readonly functionResponse: {
|
|
227
|
+
readonly name: string;
|
|
228
|
+
readonly response: unknown;
|
|
229
|
+
readonly id?: string | undefined;
|
|
230
|
+
readonly parts?: readonly {
|
|
231
|
+
readonly inlineData: {
|
|
232
|
+
readonly mimeType: string;
|
|
233
|
+
readonly data: string;
|
|
234
|
+
};
|
|
235
|
+
}[] | undefined;
|
|
236
|
+
};
|
|
237
|
+
})[] | null | undefined;
|
|
238
|
+
readonly role?: "model" | "user" | null | undefined;
|
|
239
|
+
}[];
|
|
240
|
+
readonly tools?: readonly {
|
|
241
|
+
readonly functionDeclarations: readonly {
|
|
242
|
+
readonly description: string;
|
|
243
|
+
readonly name: string;
|
|
244
|
+
readonly parameters?: {
|
|
245
|
+
readonly [x: string]: unknown;
|
|
246
|
+
} | undefined;
|
|
247
|
+
}[];
|
|
248
|
+
}[] | undefined;
|
|
249
|
+
readonly serviceTier?: string | undefined;
|
|
250
|
+
readonly toolConfig?: {
|
|
251
|
+
readonly functionCallingConfig: {
|
|
252
|
+
readonly mode: "AUTO" | "NONE" | "ANY";
|
|
253
|
+
readonly allowedFunctionNames?: readonly string[] | undefined;
|
|
254
|
+
};
|
|
255
|
+
} | undefined;
|
|
256
|
+
readonly cachedContent?: string | undefined;
|
|
257
|
+
readonly safetySettings?: readonly {
|
|
258
|
+
readonly category: string;
|
|
259
|
+
readonly threshold: string;
|
|
260
|
+
}[] | undefined;
|
|
261
|
+
readonly labels?: {
|
|
262
|
+
readonly [x: string]: string;
|
|
263
|
+
} | undefined;
|
|
264
|
+
readonly systemInstruction?: {
|
|
265
|
+
readonly parts: readonly {
|
|
266
|
+
readonly text: string;
|
|
267
|
+
}[];
|
|
268
|
+
} | undefined;
|
|
269
|
+
readonly generationConfig?: {
|
|
270
|
+
readonly temperature?: number | undefined;
|
|
271
|
+
readonly topP?: number | undefined;
|
|
272
|
+
readonly topK?: number | undefined;
|
|
273
|
+
readonly frequencyPenalty?: number | undefined;
|
|
274
|
+
readonly presencePenalty?: number | undefined;
|
|
275
|
+
readonly seed?: number | undefined;
|
|
276
|
+
readonly stopSequences?: readonly string[] | undefined;
|
|
277
|
+
readonly thinkingConfig?: {
|
|
278
|
+
readonly thinkingBudget?: number | undefined;
|
|
279
|
+
readonly includeThoughts?: boolean | undefined;
|
|
280
|
+
readonly thinkingLevel?: string | undefined;
|
|
281
|
+
} | undefined;
|
|
282
|
+
readonly maxOutputTokens?: number | undefined;
|
|
283
|
+
} | undefined;
|
|
284
|
+
}, import("../route/transport/http.js").HttpPrepared<string>, import("../route/client.js").CompactionOperations | undefined>;
|
|
285
|
+
export * as Gemini from "./gemini.js";
|