@opencode/ai 0.0.0-dev-21920 → 0.0.0-dev-44
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 -19
- package/dist/ai-client.d.ts +2 -2
- package/dist/cache-policy.d.ts +4 -0
- package/dist/cache-policy.js +20 -6
- package/dist/decision-client.d.ts +3 -3
- package/dist/decision.d.ts +4 -1
- package/dist/decision.js +3 -0
- package/dist/effect.d.ts +4 -5
- package/dist/effect.js +2 -3
- package/dist/experimental/realtime.d.ts +3 -2
- package/dist/image-client.d.ts +1 -1
- package/dist/image.js +1 -0
- package/dist/index.d.ts +6 -0
- package/dist/llm.d.ts +3 -0
- package/dist/media-client.d.ts +2 -1
- package/dist/media-model.d.ts +3 -0
- package/dist/media-model.js +4 -1
- package/dist/protocols/alibaba-chat.d.ts +4 -0
- package/dist/protocols/alibaba-messages.d.ts +19 -19
- package/dist/protocols/alibaba-responses.d.ts +3 -3
- package/dist/protocols/anthropic-messages.d.ts +59 -59
- package/dist/protocols/anthropic-messages.js +3 -5
- package/dist/protocols/bedrock-converse.d.ts +110 -15
- package/dist/protocols/bedrock-converse.js +112 -15
- package/dist/protocols/bedrock-event-stream.js +1 -0
- package/dist/protocols/meta-messages.d.ts +19 -19
- package/dist/protocols/meta-messages.js +2 -1
- package/dist/protocols/open-responses.d.ts +3 -0
- package/dist/protocols/openai-chat.d.ts +588 -1
- package/dist/protocols/openai-chat.js +7 -2
- package/dist/protocols/openai-compatible-chat.d.ts +6 -2
- package/dist/protocols/openai-compatible-responses.d.ts +3 -3
- package/dist/protocols/openai-responses.d.ts +24 -0
- package/dist/protocols/openai-responses.js +5 -0
- package/dist/protocols/utils/bedrock-cache.d.ts +2 -2
- package/dist/protocols/utils/bedrock-cache.js +7 -6
- package/dist/protocols/utils/cache.d.ts +14 -3
- package/dist/protocols/utils/cache.js +11 -4
- package/dist/protocols/utils/gemini-json-schema.d.ts +5 -0
- package/dist/protocols/utils/gemini-json-schema.js +3 -3
- package/dist/protocols/utils/tool-schema.js +15 -5
- package/dist/protocols/utils/tool-stream.d.ts +9 -0
- package/dist/protocols/venice-chat.d.ts +3 -0
- package/dist/protocols/venice-chat.js +1 -1
- package/dist/protocols/zai-chat.d.ts +4 -0
- package/dist/protocols/zai-messages.d.ts +19 -19
- package/dist/providers/alibaba/images.d.ts +2 -0
- package/dist/providers/alibaba/images.js +1 -0
- package/dist/providers/alibaba.d.ts +26 -21
- package/dist/providers/alibaba.js +12 -8
- package/dist/providers/amazon-bedrock-mantle.d.ts +23 -19
- package/dist/providers/amazon-bedrock.d.ts +34 -14
- package/dist/providers/amazon-bedrock.js +11 -11
- package/dist/providers/anthropic-compatible.d.ts +19 -19
- package/dist/providers/anthropic.d.ts +19 -19
- package/dist/providers/azure/images.d.ts +2 -0
- package/dist/providers/azure/images.js +1 -0
- package/dist/providers/azure.d.ts +15 -1
- package/dist/providers/azure.js +19 -1
- package/dist/providers/baseten/decisions.d.ts +2 -0
- package/dist/providers/baseten/decisions.js +1 -0
- package/dist/providers/baseten.d.ts +13 -4
- package/dist/providers/baseten.js +15 -8
- package/dist/providers/cerebras.d.ts +8 -0
- package/dist/providers/cloudflare-ai-gateway/decisions.d.ts +2 -0
- package/dist/providers/cloudflare-ai-gateway/decisions.js +1 -0
- package/dist/providers/cloudflare-ai-gateway.d.ts +57 -40
- package/dist/providers/cloudflare-ai-gateway.js +11 -6
- package/dist/providers/cloudflare-workers-ai/decisions.d.ts +2 -0
- package/dist/providers/cloudflare-workers-ai/decisions.js +1 -0
- package/dist/providers/cloudflare-workers-ai/images.d.ts +2 -0
- package/dist/providers/cloudflare-workers-ai/images.js +1 -0
- package/dist/providers/cloudflare-workers-ai.d.ts +13 -3
- package/dist/providers/cloudflare-workers-ai.js +16 -7
- package/dist/providers/cohere.d.ts +8 -0
- package/dist/providers/deepinfra.d.ts +8 -0
- package/dist/providers/deepseek.d.ts +8 -0
- package/dist/providers/digitalocean/decisions.d.ts +2 -0
- package/dist/providers/digitalocean/decisions.js +1 -0
- package/dist/providers/digitalocean/images.d.ts +2 -0
- package/dist/providers/digitalocean/images.js +1 -0
- package/dist/providers/digitalocean.d.ts +21 -4
- package/dist/providers/digitalocean.js +25 -8
- package/dist/providers/fireworks.d.ts +8 -0
- package/dist/providers/google/images.d.ts +2 -0
- package/dist/providers/google/images.js +1 -0
- package/dist/providers/google-vertex/images.d.ts +2 -0
- package/dist/providers/google-vertex/images.js +1 -0
- package/dist/providers/google-vertex-chat.d.ts +4 -0
- package/dist/providers/google-vertex-messages.d.ts +19 -19
- package/dist/providers/google-vertex.d.ts +3 -1
- package/dist/providers/google-vertex.js +30 -13
- package/dist/providers/google.d.ts +5 -4
- package/dist/providers/google.js +15 -8
- package/dist/providers/groq.d.ts +8 -0
- package/dist/providers/meta.d.ts +23 -19
- package/dist/providers/minimax.d.ts +23 -19
- package/dist/providers/moonshot.d.ts +23 -19
- package/dist/providers/openai/images.d.ts +2 -0
- package/dist/providers/openai/images.js +1 -0
- package/dist/providers/openai-compatible/images.d.ts +2 -0
- package/dist/providers/openai-compatible/images.js +1 -0
- package/dist/providers/openai-compatible.d.ts +7 -1
- package/dist/providers/openai-compatible.js +21 -9
- package/dist/providers/openai.d.ts +18 -8
- package/dist/providers/openai.js +10 -2
- package/dist/providers/opencode/decisions.d.ts +2 -0
- package/dist/providers/opencode/decisions.js +1 -0
- package/dist/providers/opencode.d.ts +9 -4
- package/dist/providers/opencode.js +2 -1
- package/dist/providers/openrouter/decisions.d.ts +2 -0
- package/dist/providers/openrouter/decisions.js +1 -0
- package/dist/providers/openrouter/images.d.ts +2 -0
- package/dist/providers/openrouter/images.js +1 -0
- package/dist/providers/openrouter.d.ts +25 -4
- package/dist/providers/openrouter.js +31 -9
- package/dist/providers/togetherai.d.ts +8 -0
- package/dist/providers/typesafe-ai/decisions.d.ts +2 -0
- package/dist/providers/typesafe-ai/decisions.js +1 -0
- package/dist/providers/typesafe-ai.d.ts +9 -4
- package/dist/providers/typesafe-ai.js +2 -1
- package/dist/providers/venice.d.ts +3 -0
- package/dist/providers/vercel-ai-gateway/decisions.d.ts +2 -0
- package/dist/providers/vercel-ai-gateway/decisions.js +1 -0
- package/dist/providers/vercel-ai-gateway/images.d.ts +2 -0
- package/dist/providers/vercel-ai-gateway/images.js +1 -0
- package/dist/providers/vercel-ai-gateway.d.ts +9 -7
- package/dist/providers/vercel-ai-gateway.js +18 -10
- package/dist/providers/xai/images.d.ts +2 -0
- package/dist/providers/xai/images.js +1 -0
- package/dist/providers/xai.d.ts +9 -4
- package/dist/providers/xai.js +15 -8
- package/dist/providers/zai/images.d.ts +2 -0
- package/dist/providers/zai/images.js +1 -0
- package/dist/providers/zai-coding-plan.d.ts +23 -19
- package/dist/providers/zai.d.ts +9 -4
- package/dist/providers/zai.js +15 -8
- package/dist/route/client.d.ts +2 -2
- package/dist/route/client.js +15 -4
- package/dist/route/decision.d.ts +2 -1
- package/dist/route/decision.js +1 -0
- package/dist/route/executor.d.ts +1 -1
- package/dist/route/framing.d.ts +2 -0
- package/dist/route/index.d.ts +3 -0
- package/dist/route/index.js +3 -0
- package/dist/route/media.d.ts +5 -1
- package/dist/route/media.js +6 -2
- package/dist/route/transport/http.js +1 -0
- package/dist/route/transport/index.d.ts +1 -0
- package/dist/schema/events.d.ts +135 -6
- package/dist/schema/events.js +10 -0
- package/dist/schema/messages.d.ts +6 -2
- package/dist/schema/messages.js +3 -0
- package/dist/schema/options.d.ts +5 -3
- package/dist/schema/options.js +8 -3
- package/dist/speech-client.d.ts +1 -1
- package/dist/speech.js +2 -1
- package/dist/testing.d.ts +25 -24
- package/dist/testing.js +3 -21
- package/dist/transcription-client.d.ts +1 -1
- package/dist/transcription.js +1 -0
- package/dist/video-client.d.ts +1 -1
- package/dist/video.js +1 -0
- package/package.json +510 -8
- package/dist/provider.d.ts +0 -23
- package/dist/provider.js +0 -2
|
@@ -127,9 +127,13 @@ export declare const route: Route<{
|
|
|
127
127
|
} | undefined;
|
|
128
128
|
readonly store?: boolean | undefined;
|
|
129
129
|
readonly prompt_cache_key?: string | undefined;
|
|
130
|
+
readonly prompt_cache_retention?: string | undefined;
|
|
131
|
+
readonly prompt_cache_options?: {
|
|
132
|
+
readonly ttl?: string | undefined;
|
|
133
|
+
} | undefined;
|
|
130
134
|
readonly reasoning_effort?: import("../effect.js").ReasoningEffort | undefined;
|
|
131
|
-
readonly verbosity?: import("../
|
|
132
|
-
readonly service_tier?: import("../
|
|
135
|
+
readonly verbosity?: import("../schema/options.js").OpenString<"high" | "low" | "medium"> | undefined;
|
|
136
|
+
readonly service_tier?: import("../schema/options.js").OpenString<"auto" | "default" | "flex" | "priority"> | undefined;
|
|
133
137
|
readonly parallel_tool_calls?: boolean | undefined;
|
|
134
138
|
readonly metadata?: {
|
|
135
139
|
readonly [x: string]: string;
|
|
@@ -166,15 +166,15 @@ export declare const route: Route<{
|
|
|
166
166
|
} | undefined;
|
|
167
167
|
readonly top_logprobs?: number | undefined;
|
|
168
168
|
readonly truncation?: "auto" | "disabled" | undefined;
|
|
169
|
-
readonly service_tier?: import("../
|
|
169
|
+
readonly service_tier?: import("../schema/options.js").OpenString<"auto" | "default" | "flex" | "priority"> | undefined;
|
|
170
170
|
readonly prompt_cache_key?: string | undefined;
|
|
171
|
-
readonly include?: readonly import("../
|
|
171
|
+
readonly include?: readonly import("../schema/options.js").OpenString<"code_interpreter_call.outputs" | "computer_call_output.output.image_url" | "file_search_call.results" | "message.input_image.image_url" | "message.output_text.logprobs" | "reasoning.encrypted_content" | "web_search_call.action.sources" | "web_search_call.results">[] | undefined;
|
|
172
172
|
readonly reasoning?: {
|
|
173
173
|
readonly effort?: import("../effect.js").ReasoningEffort | undefined;
|
|
174
174
|
readonly summary?: "auto" | "concise" | "detailed" | undefined;
|
|
175
175
|
} | undefined;
|
|
176
176
|
readonly text?: {
|
|
177
|
-
readonly verbosity?: import("../
|
|
177
|
+
readonly verbosity?: import("../schema/options.js").OpenString<"high" | "low" | "medium"> | undefined;
|
|
178
178
|
} | undefined;
|
|
179
179
|
readonly max_output_tokens?: number | undefined;
|
|
180
180
|
readonly max_tool_calls?: number | undefined;
|
|
@@ -154,6 +154,10 @@ declare const OpenAIResponsesBody: Schema.Struct<{
|
|
|
154
154
|
readonly top_p: Schema.optional<Schema.Number>;
|
|
155
155
|
readonly presence_penalty: Schema.optional<Schema.Number>;
|
|
156
156
|
readonly frequency_penalty: Schema.optional<Schema.Number>;
|
|
157
|
+
readonly prompt_cache_retention: Schema.optional<Schema.String>;
|
|
158
|
+
readonly prompt_cache_options: Schema.optional<Schema.Struct<{
|
|
159
|
+
readonly ttl: Schema.optional<Schema.String>;
|
|
160
|
+
}>>;
|
|
157
161
|
readonly tools: Schema.optional<Schema.$Array<Schema.Union<readonly [Schema.Struct<{
|
|
158
162
|
readonly type: Schema.tag<"function">;
|
|
159
163
|
readonly name: Schema.String;
|
|
@@ -364,6 +368,10 @@ export declare const protocol: Protocol<{
|
|
|
364
368
|
readonly top_p?: number | undefined;
|
|
365
369
|
readonly presence_penalty?: number | undefined;
|
|
366
370
|
readonly frequency_penalty?: number | undefined;
|
|
371
|
+
readonly prompt_cache_retention?: string | undefined;
|
|
372
|
+
readonly prompt_cache_options?: {
|
|
373
|
+
readonly ttl?: string | undefined;
|
|
374
|
+
} | undefined;
|
|
367
375
|
readonly tools?: readonly ({
|
|
368
376
|
readonly type: "namespace";
|
|
369
377
|
readonly name: string;
|
|
@@ -631,6 +639,10 @@ export declare const httpTransport: HttpTransport.HttpJsonTransport<{
|
|
|
631
639
|
readonly top_p?: number | undefined;
|
|
632
640
|
readonly presence_penalty?: number | undefined;
|
|
633
641
|
readonly frequency_penalty?: number | undefined;
|
|
642
|
+
readonly prompt_cache_retention?: string | undefined;
|
|
643
|
+
readonly prompt_cache_options?: {
|
|
644
|
+
readonly ttl?: string | undefined;
|
|
645
|
+
} | undefined;
|
|
634
646
|
readonly tools?: readonly ({
|
|
635
647
|
readonly type: "namespace";
|
|
636
648
|
readonly name: string;
|
|
@@ -840,6 +852,10 @@ export declare const channelTransport: (options: import("./open-responses-channe
|
|
|
840
852
|
readonly top_p?: number | undefined;
|
|
841
853
|
readonly presence_penalty?: number | undefined;
|
|
842
854
|
readonly frequency_penalty?: number | undefined;
|
|
855
|
+
readonly prompt_cache_retention?: string | undefined;
|
|
856
|
+
readonly prompt_cache_options?: {
|
|
857
|
+
readonly ttl?: string | undefined;
|
|
858
|
+
} | undefined;
|
|
843
859
|
readonly tools?: readonly ({
|
|
844
860
|
readonly type: "namespace";
|
|
845
861
|
readonly name: string;
|
|
@@ -1049,6 +1065,10 @@ export declare const transport: import("../route/transport/index.js").Transport<
|
|
|
1049
1065
|
readonly top_p?: number | undefined;
|
|
1050
1066
|
readonly presence_penalty?: number | undefined;
|
|
1051
1067
|
readonly frequency_penalty?: number | undefined;
|
|
1068
|
+
readonly prompt_cache_retention?: string | undefined;
|
|
1069
|
+
readonly prompt_cache_options?: {
|
|
1070
|
+
readonly ttl?: string | undefined;
|
|
1071
|
+
} | undefined;
|
|
1052
1072
|
readonly tools?: readonly ({
|
|
1053
1073
|
readonly type: "namespace";
|
|
1054
1074
|
readonly name: string;
|
|
@@ -1258,6 +1278,10 @@ export declare const route: Route<{
|
|
|
1258
1278
|
readonly top_p?: number | undefined;
|
|
1259
1279
|
readonly presence_penalty?: number | undefined;
|
|
1260
1280
|
readonly frequency_penalty?: number | undefined;
|
|
1281
|
+
readonly prompt_cache_retention?: string | undefined;
|
|
1282
|
+
readonly prompt_cache_options?: {
|
|
1283
|
+
readonly ttl?: string | undefined;
|
|
1284
|
+
} | undefined;
|
|
1261
1285
|
readonly tools?: readonly ({
|
|
1262
1286
|
readonly type: "namespace";
|
|
1263
1287
|
readonly name: string;
|
|
@@ -7,6 +7,7 @@ import { Endpoint } from "../route/endpoint.js";
|
|
|
7
7
|
import { Protocol } from "../route/protocol.js";
|
|
8
8
|
import { HttpTransport } from "../route/transport/index.js";
|
|
9
9
|
import { LLMRequest } from "../schema/index.js";
|
|
10
|
+
import { requestTTL } from "../cache-policy.js";
|
|
10
11
|
import { resolveEffortUpdates } from "../effort-updates.js";
|
|
11
12
|
import { OpenResponses } from "./open-responses.js";
|
|
12
13
|
import { OpenResponsesOptions } from "./utils/open-responses-options.js";
|
|
@@ -15,6 +16,7 @@ import { ResponsesHostedTools } from "./utils/responses-hosted-tools.js";
|
|
|
15
16
|
import { OpenResponsesChannel } from "./open-responses-channel.js";
|
|
16
17
|
import { ResponsesCompaction } from "./utils/responses-compaction.js";
|
|
17
18
|
import { ResponsesCheckpoint } from "./utils/responses-checkpoint.js";
|
|
19
|
+
import * as Cache from "./utils/cache.js";
|
|
18
20
|
const ADAPTER = "openai-responses";
|
|
19
21
|
const NAME = "OpenAI Responses";
|
|
20
22
|
const WEBSOCKET_PROTOCOL_HEADER = "responses_websockets=2026-02-06";
|
|
@@ -90,6 +92,8 @@ const OpenAIResponsesToolChoice = Schema.Union([
|
|
|
90
92
|
]);
|
|
91
93
|
const OpenAIResponsesCoreFields = {
|
|
92
94
|
...OpenResponses.coreFields,
|
|
95
|
+
prompt_cache_retention: Schema.optional(Schema.String),
|
|
96
|
+
prompt_cache_options: Schema.optional(Schema.Struct({ ttl: Schema.optional(Schema.String) })),
|
|
93
97
|
tools: optionalArray(OpenAIResponsesTools),
|
|
94
98
|
tool_choice: Schema.optional(OpenAIResponsesToolChoice),
|
|
95
99
|
reasoning: Schema.optional(Schema.Struct({
|
|
@@ -182,6 +186,7 @@ const fromRequest = Effect.fn("OpenAIResponses.fromRequest")(function* (request)
|
|
|
182
186
|
return {
|
|
183
187
|
...(yield* OpenResponses.lowerConversation(updates.request, adapter)),
|
|
184
188
|
...generation,
|
|
189
|
+
...Cache.openAIRequestTTL(requestTTL(request)),
|
|
185
190
|
...(generation.reasoning || reasoning.reasoningMode || reasoning.reasoningContext
|
|
186
191
|
? {
|
|
187
192
|
reasoning: {
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { Schema } from "effect";
|
|
2
|
-
import type
|
|
2
|
+
import { type CacheHint, type LLMRequest } from "../../schema/index.js";
|
|
3
3
|
export declare const CachePointBlock: Schema.Struct<{
|
|
4
4
|
readonly cachePoint: Schema.Struct<{
|
|
5
5
|
readonly type: Schema.tag<"default">;
|
|
6
|
-
readonly ttl: Schema.optional<Schema.Literals<readonly ["
|
|
6
|
+
readonly ttl: Schema.optional<Schema.TemplateLiteral<readonly [Schema.Number, Schema.Literals<readonly ["ms", "s", "m", "h", "d"]>]>>;
|
|
7
7
|
}>;
|
|
8
8
|
}>;
|
|
9
9
|
export type CachePointBlock = Schema.Schema.Type<typeof CachePointBlock>;
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import { Schema } from "effect";
|
|
2
|
-
import {
|
|
2
|
+
import { CacheTTL } from "../../schema/index.js";
|
|
3
|
+
import { newBreakpoints } from "./cache.js";
|
|
3
4
|
// Bedrock cache markers are positional: emit a `cachePoint` block immediately
|
|
4
5
|
// after the content the caller wants treated as a cacheable prefix. Bedrock
|
|
5
|
-
// accepts optional `ttl
|
|
6
|
+
// accepts an optional `ttl` such as "5m" or "1h" on cachePoint.
|
|
6
7
|
export const CachePointBlock = Schema.Struct({
|
|
7
8
|
cachePoint: Schema.Struct({
|
|
8
9
|
type: Schema.tag("default"),
|
|
9
|
-
ttl: Schema.optional(
|
|
10
|
+
ttl: Schema.optional(CacheTTL),
|
|
10
11
|
}),
|
|
11
12
|
});
|
|
12
13
|
const LEGACY_CLAUDE = ["anthropic.claude-instant", "anthropic.claude-v1", "anthropic.claude-v2", "anthropic.claude-3-"];
|
|
@@ -34,8 +35,6 @@ export const breakpoints = (model) => {
|
|
|
34
35
|
ttl1h: !short,
|
|
35
36
|
};
|
|
36
37
|
};
|
|
37
|
-
const DEFAULT_5M = { cachePoint: { type: "default" } };
|
|
38
|
-
const DEFAULT_1H = { cachePoint: { type: "default", ttl: "1h" } };
|
|
39
38
|
export const block = (breakpoints, cache) => {
|
|
40
39
|
if (!breakpoints.supported)
|
|
41
40
|
return undefined;
|
|
@@ -46,6 +45,8 @@ export const block = (breakpoints, cache) => {
|
|
|
46
45
|
return undefined;
|
|
47
46
|
}
|
|
48
47
|
breakpoints.remaining -= 1;
|
|
49
|
-
|
|
48
|
+
// Older Claude releases cache for five minutes only, so a one-hour request falls back to the default.
|
|
49
|
+
const ttl = cache.ttl === "1h" && !breakpoints.ttl1h ? undefined : cache.ttl;
|
|
50
|
+
return { cachePoint: { type: "default", ...(ttl === undefined ? {} : { ttl }) } };
|
|
50
51
|
};
|
|
51
52
|
export * as BedrockCache from "./bedrock-cache.js";
|
|
@@ -1,11 +1,22 @@
|
|
|
1
|
-
import type { CacheHint } from "../../schema/index.js";
|
|
1
|
+
import type { CacheHint, CacheTTL } from "../../schema/index.js";
|
|
2
2
|
export interface Breakpoints {
|
|
3
3
|
remaining: number;
|
|
4
4
|
dropped: number;
|
|
5
5
|
}
|
|
6
6
|
export declare const newBreakpoints: (cap: number) => Breakpoints;
|
|
7
|
-
export declare const ttlBucket: (ttlSeconds: number | undefined) => "1h" | undefined;
|
|
8
7
|
export declare const cacheControl: () => (cache: CacheHint | undefined) => {
|
|
9
8
|
type: "ephemeral";
|
|
10
|
-
ttl:
|
|
9
|
+
ttl: `${number}d` | `${number}h` | `${number}m` | `${number}ms` | `${number}s` | undefined;
|
|
11
10
|
} | undefined;
|
|
11
|
+
export declare const openAIRequestTTL: (ttl: CacheTTL | undefined) => {
|
|
12
|
+
prompt_cache_retention?: undefined;
|
|
13
|
+
prompt_cache_options?: undefined;
|
|
14
|
+
} | {
|
|
15
|
+
prompt_cache_retention: string;
|
|
16
|
+
prompt_cache_options?: undefined;
|
|
17
|
+
} | {
|
|
18
|
+
prompt_cache_retention?: undefined;
|
|
19
|
+
prompt_cache_options: {
|
|
20
|
+
ttl: `${number}d` | `${number}h` | `${number}m` | `${number}ms` | `${number}s`;
|
|
21
|
+
};
|
|
22
|
+
};
|
|
@@ -1,13 +1,20 @@
|
|
|
1
1
|
export const newBreakpoints = (cap) => ({ remaining: cap, dropped: 0 });
|
|
2
|
-
// Requests of at least one hour use the explicit `"1h"` bucket; shorter
|
|
3
|
-
// requests omit the wire TTL and use the provider default.
|
|
4
|
-
export const ttlBucket = (ttlSeconds) => ttlSeconds !== undefined && ttlSeconds >= 3600 ? "1h" : undefined;
|
|
5
2
|
export const cacheControl = () => {
|
|
6
3
|
const breakpoints = newBreakpoints(4);
|
|
7
4
|
return (cache) => {
|
|
8
5
|
if (cache === undefined || breakpoints.remaining === 0)
|
|
9
6
|
return undefined;
|
|
10
7
|
breakpoints.remaining -= 1;
|
|
11
|
-
return { type: "ephemeral", ttl:
|
|
8
|
+
return { type: "ephemeral", ttl: cache.ttl };
|
|
12
9
|
};
|
|
13
10
|
};
|
|
11
|
+
// OpenAI's request-level lifetime. `prompt_cache_retention` takes only "24h" (or "in_memory") and is the only
|
|
12
|
+
// control before GPT-5.6; every other lifetime goes to `prompt_cache_options.ttl`, which GPT-5.6+, Kimi and
|
|
13
|
+
// DeepInfra read.
|
|
14
|
+
export const openAIRequestTTL = (ttl) => {
|
|
15
|
+
if (ttl === undefined)
|
|
16
|
+
return {};
|
|
17
|
+
if (ttl === "24h")
|
|
18
|
+
return { prompt_cache_retention: ttl };
|
|
19
|
+
return { prompt_cache_options: { ttl } };
|
|
20
|
+
};
|
|
@@ -1,3 +1,8 @@
|
|
|
1
1
|
import type { JsonSchema } from "../../schema/index.js";
|
|
2
|
+
export declare const SCHEMA_MAPS: Set<string>;
|
|
3
|
+
export declare const VALUES: Set<string>;
|
|
4
|
+
export declare const mapValues: (record: Record<string, unknown>, map: (value: unknown, key: string) => unknown) => {
|
|
5
|
+
[k: string]: unknown;
|
|
6
|
+
};
|
|
2
7
|
export declare const normalize: (schema: JsonSchema) => JsonSchema;
|
|
3
8
|
export * as GeminiJsonSchema from "./gemini-json-schema.js";
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { isRecord } from "../../utils/record.js";
|
|
2
2
|
// Gemini's `parametersJsonSchema` accepts standard JSON Schema, but rejects a few shapes that
|
|
3
3
|
// published tool schemas commonly contain. Rewrite only those and send everything else unchanged.
|
|
4
|
-
const SCHEMA_MAPS = new Set([
|
|
4
|
+
export const SCHEMA_MAPS = new Set([
|
|
5
5
|
"properties",
|
|
6
6
|
"patternProperties",
|
|
7
7
|
"$defs",
|
|
@@ -9,8 +9,8 @@ const SCHEMA_MAPS = new Set([
|
|
|
9
9
|
"dependentSchemas",
|
|
10
10
|
"dependencies",
|
|
11
11
|
]);
|
|
12
|
-
const VALUES = new Set(["const", "default", "enum", "examples", "dependentRequired"]);
|
|
13
|
-
const mapValues = (record, map) => Object.fromEntries(Object.entries(record).map(([key, value]) => [key, map(value, key)]));
|
|
12
|
+
export const VALUES = new Set(["const", "default", "enum", "examples", "dependentRequired"]);
|
|
13
|
+
export const mapValues = (record, map) => Object.fromEntries(Object.entries(record).map(([key, value]) => [key, map(value, key)]));
|
|
14
14
|
const normalizeNode = (schema) => {
|
|
15
15
|
if (Array.isArray(schema))
|
|
16
16
|
return schema.map(normalizeNode);
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { ToolDefinition } from "../../schema/index.js";
|
|
2
2
|
import { isRecord } from "../../utils/record.js";
|
|
3
3
|
import { GeminiJsonSchema } from "./gemini-json-schema.js";
|
|
4
|
+
const { SCHEMA_MAPS, VALUES, mapValues } = GeminiJsonSchema;
|
|
4
5
|
const tupleItemsSchema = (items) => {
|
|
5
6
|
const projected = items.map(moonshotNode);
|
|
6
7
|
if (projected.length === 0)
|
|
@@ -31,12 +32,21 @@ const moonshotNode = (schema) => {
|
|
|
31
32
|
return Object.fromEntries([
|
|
32
33
|
...(type === undefined ? [] : [["type", type]]),
|
|
33
34
|
...Object.entries(schema).flatMap(([key, value]) => {
|
|
34
|
-
if (
|
|
35
|
-
return [[key,
|
|
36
|
-
if (key
|
|
37
|
-
|
|
35
|
+
if (VALUES.has(key))
|
|
36
|
+
return [[key, value]];
|
|
37
|
+
if (SCHEMA_MAPS.has(key) && isRecord(value))
|
|
38
|
+
return [[key, mapValues(value, moonshotNode)]];
|
|
39
|
+
if (key === "items") {
|
|
40
|
+
if (Array.isArray(schema.prefixItems))
|
|
38
41
|
return [];
|
|
39
|
-
|
|
42
|
+
if (Array.isArray(value))
|
|
43
|
+
return [[key, tupleItemsSchema(value)]];
|
|
44
|
+
}
|
|
45
|
+
if (key === "prefixItems") {
|
|
46
|
+
if (!Array.isArray(value))
|
|
47
|
+
return "items" in schema ? [] : [["items", {}]];
|
|
48
|
+
const rest = isRecord(schema.items) ? [schema.items] : Array.isArray(schema.items) ? schema.items : [];
|
|
49
|
+
return [["items", tupleItemsSchema([...value, ...rest])]];
|
|
40
50
|
}
|
|
41
51
|
if (key === "unevaluatedItems")
|
|
42
52
|
return [];
|
|
@@ -79,6 +79,9 @@ export declare const finish: <K extends StreamKey>(route: string, tools: State<K
|
|
|
79
79
|
events: readonly ({
|
|
80
80
|
readonly type: "step-start";
|
|
81
81
|
readonly index: number;
|
|
82
|
+
} | {
|
|
83
|
+
readonly type: "raw";
|
|
84
|
+
readonly data: unknown;
|
|
82
85
|
} | {
|
|
83
86
|
readonly type: "text-start";
|
|
84
87
|
readonly id: string;
|
|
@@ -306,6 +309,9 @@ export declare const finishWithInput: <K extends StreamKey>(route: string, tools
|
|
|
306
309
|
events: readonly ({
|
|
307
310
|
readonly type: "step-start";
|
|
308
311
|
readonly index: number;
|
|
312
|
+
} | {
|
|
313
|
+
readonly type: "raw";
|
|
314
|
+
readonly data: unknown;
|
|
309
315
|
} | {
|
|
310
316
|
readonly type: "text-start";
|
|
311
317
|
readonly id: string;
|
|
@@ -530,6 +536,9 @@ export declare const finishAll: <K extends StreamKey>(route: string, tools: Stat
|
|
|
530
536
|
events: ({
|
|
531
537
|
readonly type: "step-start";
|
|
532
538
|
readonly index: number;
|
|
539
|
+
} | {
|
|
540
|
+
readonly type: "raw";
|
|
541
|
+
readonly data: unknown;
|
|
533
542
|
} | {
|
|
534
543
|
readonly type: "text-start";
|
|
535
544
|
readonly id: string;
|
|
@@ -79,6 +79,9 @@ export declare const protocol: Protocol<{
|
|
|
79
79
|
} | undefined;
|
|
80
80
|
readonly store?: boolean | undefined;
|
|
81
81
|
readonly prompt_cache_key?: string | undefined;
|
|
82
|
+
readonly prompt_cache_options?: {
|
|
83
|
+
readonly ttl?: string | undefined;
|
|
84
|
+
} | undefined;
|
|
82
85
|
readonly reasoning_effort?: OpenResponsesOptions.ReasoningEffort | undefined;
|
|
83
86
|
readonly verbosity?: import("../schema/options.js").OpenString<"high" | "low" | "medium"> | undefined;
|
|
84
87
|
readonly service_tier?: import("../schema/options.js").OpenString<"auto" | "default" | "flex" | "priority"> | undefined;
|
|
@@ -150,7 +150,7 @@ const fromRequest = Effect.fn("VeniceChat.fromRequest")(function* (request) {
|
|
|
150
150
|
})
|
|
151
151
|
.filter(([, value]) => value !== undefined)
|
|
152
152
|
.map(([key, value]) => [key.replace(/[A-Z]/g, (letter) => `_${letter.toLowerCase()}`), value])),
|
|
153
|
-
prompt_cache_retention: options.promptCacheRetention,
|
|
153
|
+
prompt_cache_retention: options.promptCacheRetention ?? body.prompt_cache_retention,
|
|
154
154
|
parallel_tool_calls: options.parallelToolCalls,
|
|
155
155
|
min_p: options.minP,
|
|
156
156
|
top_k: request.generation?.topK,
|
|
@@ -146,6 +146,10 @@ export declare const protocol: Protocol<{
|
|
|
146
146
|
} | undefined;
|
|
147
147
|
readonly store?: boolean | undefined;
|
|
148
148
|
readonly prompt_cache_key?: string | undefined;
|
|
149
|
+
readonly prompt_cache_retention?: string | undefined;
|
|
150
|
+
readonly prompt_cache_options?: {
|
|
151
|
+
readonly ttl?: string | undefined;
|
|
152
|
+
} | undefined;
|
|
149
153
|
readonly reasoning_effort?: OpenResponsesOptions.ReasoningEffort | undefined;
|
|
150
154
|
readonly verbosity?: import("../schema/options.js").OpenString<"high" | "low" | "medium"> | undefined;
|
|
151
155
|
readonly service_tier?: import("../schema/options.js").OpenString<"auto" | "default" | "flex" | "priority"> | undefined;
|
|
@@ -26,7 +26,7 @@ export declare const protocol: Protocol<{
|
|
|
26
26
|
readonly text: string;
|
|
27
27
|
readonly cache_control?: {
|
|
28
28
|
readonly type: "ephemeral";
|
|
29
|
-
readonly ttl?:
|
|
29
|
+
readonly ttl?: `${number}d` | `${number}h` | `${number}m` | `${number}ms` | `${number}s` | undefined;
|
|
30
30
|
} | undefined;
|
|
31
31
|
}[] | undefined;
|
|
32
32
|
readonly messages: readonly ({
|
|
@@ -36,7 +36,7 @@ export declare const protocol: Protocol<{
|
|
|
36
36
|
readonly text: string;
|
|
37
37
|
readonly cache_control?: {
|
|
38
38
|
readonly type: "ephemeral";
|
|
39
|
-
readonly ttl?:
|
|
39
|
+
readonly ttl?: `${number}d` | `${number}h` | `${number}m` | `${number}ms` | `${number}s` | undefined;
|
|
40
40
|
} | undefined;
|
|
41
41
|
} | {
|
|
42
42
|
readonly type: "image";
|
|
@@ -53,7 +53,7 @@ export declare const protocol: Protocol<{
|
|
|
53
53
|
};
|
|
54
54
|
readonly cache_control?: {
|
|
55
55
|
readonly type: "ephemeral";
|
|
56
|
-
readonly ttl?:
|
|
56
|
+
readonly ttl?: `${number}d` | `${number}h` | `${number}m` | `${number}ms` | `${number}s` | undefined;
|
|
57
57
|
} | undefined;
|
|
58
58
|
readonly transformations?: {
|
|
59
59
|
readonly oversized_image?: "downsize" | "error" | undefined;
|
|
@@ -73,7 +73,7 @@ export declare const protocol: Protocol<{
|
|
|
73
73
|
};
|
|
74
74
|
readonly cache_control?: {
|
|
75
75
|
readonly type: "ephemeral";
|
|
76
|
-
readonly ttl?:
|
|
76
|
+
readonly ttl?: `${number}d` | `${number}h` | `${number}m` | `${number}ms` | `${number}s` | undefined;
|
|
77
77
|
} | undefined;
|
|
78
78
|
} | {
|
|
79
79
|
readonly type: "document";
|
|
@@ -94,7 +94,7 @@ export declare const protocol: Protocol<{
|
|
|
94
94
|
};
|
|
95
95
|
readonly cache_control?: {
|
|
96
96
|
readonly type: "ephemeral";
|
|
97
|
-
readonly ttl?:
|
|
97
|
+
readonly ttl?: `${number}d` | `${number}h` | `${number}m` | `${number}ms` | `${number}s` | undefined;
|
|
98
98
|
} | undefined;
|
|
99
99
|
readonly title?: string | undefined;
|
|
100
100
|
readonly context?: string | undefined;
|
|
@@ -109,7 +109,7 @@ export declare const protocol: Protocol<{
|
|
|
109
109
|
readonly text: string;
|
|
110
110
|
readonly cache_control?: {
|
|
111
111
|
readonly type: "ephemeral";
|
|
112
|
-
readonly ttl?:
|
|
112
|
+
readonly ttl?: `${number}d` | `${number}h` | `${number}m` | `${number}ms` | `${number}s` | undefined;
|
|
113
113
|
} | undefined;
|
|
114
114
|
} | {
|
|
115
115
|
readonly type: "image";
|
|
@@ -126,7 +126,7 @@ export declare const protocol: Protocol<{
|
|
|
126
126
|
};
|
|
127
127
|
readonly cache_control?: {
|
|
128
128
|
readonly type: "ephemeral";
|
|
129
|
-
readonly ttl?:
|
|
129
|
+
readonly ttl?: `${number}d` | `${number}h` | `${number}m` | `${number}ms` | `${number}s` | undefined;
|
|
130
130
|
} | undefined;
|
|
131
131
|
readonly transformations?: {
|
|
132
132
|
readonly oversized_image?: "downsize" | "error" | undefined;
|
|
@@ -146,7 +146,7 @@ export declare const protocol: Protocol<{
|
|
|
146
146
|
};
|
|
147
147
|
readonly cache_control?: {
|
|
148
148
|
readonly type: "ephemeral";
|
|
149
|
-
readonly ttl?:
|
|
149
|
+
readonly ttl?: `${number}d` | `${number}h` | `${number}m` | `${number}ms` | `${number}s` | undefined;
|
|
150
150
|
} | undefined;
|
|
151
151
|
} | {
|
|
152
152
|
readonly type: "document";
|
|
@@ -167,7 +167,7 @@ export declare const protocol: Protocol<{
|
|
|
167
167
|
};
|
|
168
168
|
readonly cache_control?: {
|
|
169
169
|
readonly type: "ephemeral";
|
|
170
|
-
readonly ttl?:
|
|
170
|
+
readonly ttl?: `${number}d` | `${number}h` | `${number}m` | `${number}ms` | `${number}s` | undefined;
|
|
171
171
|
} | undefined;
|
|
172
172
|
readonly title?: string | undefined;
|
|
173
173
|
readonly context?: string | undefined;
|
|
@@ -178,7 +178,7 @@ export declare const protocol: Protocol<{
|
|
|
178
178
|
readonly is_error?: boolean | undefined;
|
|
179
179
|
readonly cache_control?: {
|
|
180
180
|
readonly type: "ephemeral";
|
|
181
|
-
readonly ttl?:
|
|
181
|
+
readonly ttl?: `${number}d` | `${number}h` | `${number}m` | `${number}ms` | `${number}s` | undefined;
|
|
182
182
|
} | undefined;
|
|
183
183
|
})[];
|
|
184
184
|
} | {
|
|
@@ -191,7 +191,7 @@ export declare const protocol: Protocol<{
|
|
|
191
191
|
readonly text: string;
|
|
192
192
|
readonly cache_control?: {
|
|
193
193
|
readonly type: "ephemeral";
|
|
194
|
-
readonly ttl?:
|
|
194
|
+
readonly ttl?: `${number}d` | `${number}h` | `${number}m` | `${number}ms` | `${number}s` | undefined;
|
|
195
195
|
} | undefined;
|
|
196
196
|
} | {
|
|
197
197
|
readonly type: "thinking";
|
|
@@ -199,14 +199,14 @@ export declare const protocol: Protocol<{
|
|
|
199
199
|
readonly signature: string;
|
|
200
200
|
readonly cache_control?: {
|
|
201
201
|
readonly type: "ephemeral";
|
|
202
|
-
readonly ttl?:
|
|
202
|
+
readonly ttl?: `${number}d` | `${number}h` | `${number}m` | `${number}ms` | `${number}s` | undefined;
|
|
203
203
|
} | undefined;
|
|
204
204
|
} | {
|
|
205
205
|
readonly type: "redacted_thinking";
|
|
206
206
|
readonly data: string;
|
|
207
207
|
readonly cache_control?: {
|
|
208
208
|
readonly type: "ephemeral";
|
|
209
|
-
readonly ttl?:
|
|
209
|
+
readonly ttl?: `${number}d` | `${number}h` | `${number}m` | `${number}ms` | `${number}s` | undefined;
|
|
210
210
|
} | undefined;
|
|
211
211
|
} | {
|
|
212
212
|
readonly type: "tool_use";
|
|
@@ -215,7 +215,7 @@ export declare const protocol: Protocol<{
|
|
|
215
215
|
readonly input: unknown;
|
|
216
216
|
readonly cache_control?: {
|
|
217
217
|
readonly type: "ephemeral";
|
|
218
|
-
readonly ttl?:
|
|
218
|
+
readonly ttl?: `${number}d` | `${number}h` | `${number}m` | `${number}ms` | `${number}s` | undefined;
|
|
219
219
|
} | undefined;
|
|
220
220
|
} | {
|
|
221
221
|
readonly type: "server_tool_use";
|
|
@@ -224,7 +224,7 @@ export declare const protocol: Protocol<{
|
|
|
224
224
|
readonly input: unknown;
|
|
225
225
|
readonly cache_control?: {
|
|
226
226
|
readonly type: "ephemeral";
|
|
227
|
-
readonly ttl?:
|
|
227
|
+
readonly ttl?: `${number}d` | `${number}h` | `${number}m` | `${number}ms` | `${number}s` | undefined;
|
|
228
228
|
} | undefined;
|
|
229
229
|
} | {
|
|
230
230
|
readonly type: "code_execution_tool_result" | "web_fetch_tool_result" | "web_search_tool_result";
|
|
@@ -232,7 +232,7 @@ export declare const protocol: Protocol<{
|
|
|
232
232
|
readonly content: unknown;
|
|
233
233
|
readonly cache_control?: {
|
|
234
234
|
readonly type: "ephemeral";
|
|
235
|
-
readonly ttl?:
|
|
235
|
+
readonly ttl?: `${number}d` | `${number}h` | `${number}m` | `${number}ms` | `${number}s` | undefined;
|
|
236
236
|
} | undefined;
|
|
237
237
|
})[];
|
|
238
238
|
} | {
|
|
@@ -242,7 +242,7 @@ export declare const protocol: Protocol<{
|
|
|
242
242
|
readonly text: string;
|
|
243
243
|
readonly cache_control?: {
|
|
244
244
|
readonly type: "ephemeral";
|
|
245
|
-
readonly ttl?:
|
|
245
|
+
readonly ttl?: `${number}d` | `${number}h` | `${number}m` | `${number}ms` | `${number}s` | undefined;
|
|
246
246
|
} | undefined;
|
|
247
247
|
}[];
|
|
248
248
|
readonly output_config?: {
|
|
@@ -257,7 +257,7 @@ export declare const protocol: Protocol<{
|
|
|
257
257
|
};
|
|
258
258
|
readonly cache_control?: {
|
|
259
259
|
readonly type: "ephemeral";
|
|
260
|
-
readonly ttl?:
|
|
260
|
+
readonly ttl?: `${number}d` | `${number}h` | `${number}m` | `${number}ms` | `${number}s` | undefined;
|
|
261
261
|
} | undefined;
|
|
262
262
|
}[] | undefined;
|
|
263
263
|
readonly tool_choice?: {
|
|
@@ -285,7 +285,7 @@ export declare const protocol: Protocol<{
|
|
|
285
285
|
} | undefined;
|
|
286
286
|
readonly cache_control?: {
|
|
287
287
|
readonly type: "ephemeral";
|
|
288
|
-
readonly ttl?:
|
|
288
|
+
readonly ttl?: `${number}d` | `${number}h` | `${number}m` | `${number}ms` | `${number}s` | undefined;
|
|
289
289
|
} | undefined;
|
|
290
290
|
readonly container?: string | {
|
|
291
291
|
readonly id?: string | null | undefined;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { imageModel as model } from "../alibaba.js";
|