@opencode/ai 2.0.20 → 2.0.22
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/dist/cache-policy.js +22 -3
- package/dist/llm.d.ts +4 -0
- package/dist/promise.d.ts +8 -0
- package/dist/protocols/alibaba-chat.d.ts +20 -10
- package/dist/protocols/alibaba-chat.js +2 -1
- package/dist/protocols/anthropic-messages.js +14 -12
- package/dist/protocols/bedrock-converse.js +30 -1
- package/dist/protocols/open-responses.d.ts +4 -0
- package/dist/protocols/openai-chat.d.ts +122 -71
- package/dist/protocols/openai-chat.js +40 -37
- package/dist/protocols/openai-compatible-chat.d.ts +16 -10
- package/dist/protocols/openai-responses.js +4 -3
- package/dist/protocols/utils/cache.d.ts +5 -0
- package/dist/protocols/utils/cache.js +9 -1
- package/dist/protocols/utils/tool-stream.d.ts +12 -0
- package/dist/protocols/zai-chat.d.ts +20 -10
- package/dist/protocols/zai-chat.js +6 -3
- package/dist/provider-error.js +24 -6
- package/dist/providers/alibaba.d.ts +16 -10
- package/dist/providers/amazon-bedrock-mantle.d.ts +16 -10
- package/dist/providers/azure.d.ts +16 -10
- package/dist/providers/baseten.d.ts +32 -20
- package/dist/providers/cerebras.d.ts +32 -20
- package/dist/providers/cloudflare-ai-gateway.d.ts +32 -20
- package/dist/providers/cloudflare-ai-gateway.js +43 -35
- package/dist/providers/cloudflare-workers-ai.d.ts +32 -20
- package/dist/providers/deepinfra.d.ts +32 -20
- package/dist/providers/deepseek.d.ts +32 -20
- package/dist/providers/digitalocean.d.ts +469 -0
- package/dist/providers/digitalocean.js +53 -0
- package/dist/providers/fireworks.d.ts +32 -20
- package/dist/providers/google-vertex-chat.d.ts +16 -10
- package/dist/providers/google-vertex-messages.js +1 -1
- package/dist/providers/groq.d.ts +36 -20
- package/dist/providers/groq.js +1 -1
- package/dist/providers/index.d.ts +1 -0
- package/dist/providers/index.js +1 -0
- package/dist/providers/meta.d.ts +16 -10
- package/dist/providers/minimax.d.ts +16 -10
- package/dist/providers/moonshot.d.ts +16 -10
- package/dist/providers/openai-compatible.d.ts +16 -10
- package/dist/providers/openai.d.ts +16 -10
- package/dist/providers/openrouter.d.ts +68 -40
- package/dist/providers/openrouter.js +1 -13
- package/dist/providers/togetherai.d.ts +32 -20
- package/dist/providers/xai.d.ts +16 -10
- package/dist/providers/zai-coding-plan.d.ts +16 -10
- package/dist/providers/zai.d.ts +16 -10
- package/dist/route/client.d.ts +4 -0
- package/dist/route/executor.js +13 -6
- 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/providers/groq.d.ts
CHANGED
|
@@ -67,15 +67,18 @@ export declare const protocol: Protocol<{
|
|
|
67
67
|
})[];
|
|
68
68
|
} | {
|
|
69
69
|
readonly [x: string]: unknown;
|
|
70
|
-
readonly content: string |
|
|
70
|
+
readonly content: string | readonly {
|
|
71
|
+
readonly type: "text";
|
|
72
|
+
readonly text: string;
|
|
73
|
+
readonly cache_control?: {
|
|
74
|
+
readonly type: "ephemeral";
|
|
75
|
+
readonly ttl?: string | undefined;
|
|
76
|
+
} | undefined;
|
|
77
|
+
}[] | null;
|
|
71
78
|
readonly role: "assistant";
|
|
72
79
|
readonly reasoning?: string | undefined;
|
|
73
80
|
readonly reasoning_content?: string | undefined;
|
|
74
81
|
readonly reasoning_text?: string | undefined;
|
|
75
|
-
readonly cache_control?: {
|
|
76
|
-
readonly type: "ephemeral";
|
|
77
|
-
readonly ttl?: string | undefined;
|
|
78
|
-
} | undefined;
|
|
79
82
|
readonly tool_calls?: readonly {
|
|
80
83
|
readonly function: {
|
|
81
84
|
readonly name: string;
|
|
@@ -91,13 +94,16 @@ export declare const protocol: Protocol<{
|
|
|
91
94
|
}[] | undefined;
|
|
92
95
|
readonly reasoning_details?: unknown;
|
|
93
96
|
} | {
|
|
94
|
-
readonly content: string;
|
|
95
97
|
readonly role: "tool";
|
|
96
98
|
readonly tool_call_id: string;
|
|
97
|
-
readonly
|
|
98
|
-
readonly type: "
|
|
99
|
-
readonly
|
|
100
|
-
|
|
99
|
+
readonly content: string | readonly {
|
|
100
|
+
readonly type: "text";
|
|
101
|
+
readonly text: string;
|
|
102
|
+
readonly cache_control?: {
|
|
103
|
+
readonly type: "ephemeral";
|
|
104
|
+
readonly ttl?: string | undefined;
|
|
105
|
+
} | undefined;
|
|
106
|
+
}[];
|
|
101
107
|
})[];
|
|
102
108
|
readonly stream: true;
|
|
103
109
|
readonly max_completion_tokens?: number | undefined;
|
|
@@ -150,6 +156,7 @@ export declare const protocol: Protocol<{
|
|
|
150
156
|
} | null | undefined;
|
|
151
157
|
readonly usage?: {
|
|
152
158
|
readonly [x: string]: unknown;
|
|
159
|
+
readonly cache_read_input_tokens?: number | null | undefined;
|
|
153
160
|
readonly cached_tokens?: number | null | undefined;
|
|
154
161
|
readonly prompt_tokens?: number | null | undefined;
|
|
155
162
|
readonly completion_tokens?: number | null | undefined;
|
|
@@ -160,6 +167,7 @@ export declare const protocol: Protocol<{
|
|
|
160
167
|
readonly cache_write_tokens?: number | null | undefined;
|
|
161
168
|
} | null | undefined;
|
|
162
169
|
readonly prompt_cache_hit_tokens?: number | null | undefined;
|
|
170
|
+
readonly cache_created_input_tokens?: number | null | undefined;
|
|
163
171
|
readonly completion_tokens_details?: {
|
|
164
172
|
readonly [x: string]: unknown;
|
|
165
173
|
readonly reasoning_tokens?: number | null | undefined;
|
|
@@ -189,6 +197,7 @@ export declare const protocol: Protocol<{
|
|
|
189
197
|
} | null | undefined;
|
|
190
198
|
readonly usage?: {
|
|
191
199
|
readonly [x: string]: unknown;
|
|
200
|
+
readonly cache_read_input_tokens?: number | null | undefined;
|
|
192
201
|
readonly cached_tokens?: number | null | undefined;
|
|
193
202
|
readonly prompt_tokens?: number | null | undefined;
|
|
194
203
|
readonly completion_tokens?: number | null | undefined;
|
|
@@ -199,6 +208,7 @@ export declare const protocol: Protocol<{
|
|
|
199
208
|
readonly cache_write_tokens?: number | null | undefined;
|
|
200
209
|
} | null | undefined;
|
|
201
210
|
readonly prompt_cache_hit_tokens?: number | null | undefined;
|
|
211
|
+
readonly cache_created_input_tokens?: number | null | undefined;
|
|
202
212
|
readonly completion_tokens_details?: {
|
|
203
213
|
readonly [x: string]: unknown;
|
|
204
214
|
readonly reasoning_tokens?: number | null | undefined;
|
|
@@ -256,15 +266,18 @@ export declare const route: Route<{
|
|
|
256
266
|
})[];
|
|
257
267
|
} | {
|
|
258
268
|
readonly [x: string]: unknown;
|
|
259
|
-
readonly content: string |
|
|
269
|
+
readonly content: string | readonly {
|
|
270
|
+
readonly type: "text";
|
|
271
|
+
readonly text: string;
|
|
272
|
+
readonly cache_control?: {
|
|
273
|
+
readonly type: "ephemeral";
|
|
274
|
+
readonly ttl?: string | undefined;
|
|
275
|
+
} | undefined;
|
|
276
|
+
}[] | null;
|
|
260
277
|
readonly role: "assistant";
|
|
261
278
|
readonly reasoning?: string | undefined;
|
|
262
279
|
readonly reasoning_content?: string | undefined;
|
|
263
280
|
readonly reasoning_text?: string | undefined;
|
|
264
|
-
readonly cache_control?: {
|
|
265
|
-
readonly type: "ephemeral";
|
|
266
|
-
readonly ttl?: string | undefined;
|
|
267
|
-
} | undefined;
|
|
268
281
|
readonly tool_calls?: readonly {
|
|
269
282
|
readonly function: {
|
|
270
283
|
readonly name: string;
|
|
@@ -280,13 +293,16 @@ export declare const route: Route<{
|
|
|
280
293
|
}[] | undefined;
|
|
281
294
|
readonly reasoning_details?: unknown;
|
|
282
295
|
} | {
|
|
283
|
-
readonly content: string;
|
|
284
296
|
readonly role: "tool";
|
|
285
297
|
readonly tool_call_id: string;
|
|
286
|
-
readonly
|
|
287
|
-
readonly type: "
|
|
288
|
-
readonly
|
|
289
|
-
|
|
298
|
+
readonly content: string | readonly {
|
|
299
|
+
readonly type: "text";
|
|
300
|
+
readonly text: string;
|
|
301
|
+
readonly cache_control?: {
|
|
302
|
+
readonly type: "ephemeral";
|
|
303
|
+
readonly ttl?: string | undefined;
|
|
304
|
+
} | undefined;
|
|
305
|
+
}[];
|
|
290
306
|
})[];
|
|
291
307
|
readonly stream: true;
|
|
292
308
|
readonly max_completion_tokens?: number | undefined;
|
package/dist/providers/groq.js
CHANGED
|
@@ -43,7 +43,7 @@ export const protocol = Protocol.make({
|
|
|
43
43
|
export const route = Route.make({
|
|
44
44
|
id: "groq-chat",
|
|
45
45
|
provider: id,
|
|
46
|
-
providerMetadataKey: "
|
|
46
|
+
providerMetadataKey: "groq",
|
|
47
47
|
protocol,
|
|
48
48
|
endpoint: Endpoint.path("/chat/completions", { baseURL }),
|
|
49
49
|
framing: OpenAIChat.framing,
|
|
@@ -14,6 +14,7 @@ export * as CloudflareWorkersAI from "./cloudflare-workers-ai.js";
|
|
|
14
14
|
export * as DeepInfra from "./deepinfra.js";
|
|
15
15
|
export * as Deepgram from "./deepgram.js";
|
|
16
16
|
export * as DeepSeek from "./deepseek.js";
|
|
17
|
+
export * as DigitalOcean from "./digitalocean.js";
|
|
17
18
|
export * as ElevenLabs from "./elevenlabs.js";
|
|
18
19
|
export * as Fal from "./fal.js";
|
|
19
20
|
export * as Fireworks from "./fireworks.js";
|
package/dist/providers/index.js
CHANGED
|
@@ -14,6 +14,7 @@ export * as CloudflareWorkersAI from "./cloudflare-workers-ai.js";
|
|
|
14
14
|
export * as DeepInfra from "./deepinfra.js";
|
|
15
15
|
export * as Deepgram from "./deepgram.js";
|
|
16
16
|
export * as DeepSeek from "./deepseek.js";
|
|
17
|
+
export * as DigitalOcean from "./digitalocean.js";
|
|
17
18
|
export * as ElevenLabs from "./elevenlabs.js";
|
|
18
19
|
export * as Fal from "./fal.js";
|
|
19
20
|
export * as Fireworks from "./fireworks.js";
|
package/dist/providers/meta.d.ts
CHANGED
|
@@ -84,15 +84,18 @@ export declare const routes: (Route<{
|
|
|
84
84
|
})[];
|
|
85
85
|
} | {
|
|
86
86
|
readonly [x: string]: unknown;
|
|
87
|
-
readonly content: string |
|
|
87
|
+
readonly content: string | readonly {
|
|
88
|
+
readonly type: "text";
|
|
89
|
+
readonly text: string;
|
|
90
|
+
readonly cache_control?: {
|
|
91
|
+
readonly type: "ephemeral";
|
|
92
|
+
readonly ttl?: string | undefined;
|
|
93
|
+
} | undefined;
|
|
94
|
+
}[] | null;
|
|
88
95
|
readonly role: "assistant";
|
|
89
96
|
readonly reasoning?: string | undefined;
|
|
90
97
|
readonly reasoning_content?: string | undefined;
|
|
91
98
|
readonly reasoning_text?: string | undefined;
|
|
92
|
-
readonly cache_control?: {
|
|
93
|
-
readonly type: "ephemeral";
|
|
94
|
-
readonly ttl?: string | undefined;
|
|
95
|
-
} | undefined;
|
|
96
99
|
readonly tool_calls?: readonly {
|
|
97
100
|
readonly function: {
|
|
98
101
|
readonly name: string;
|
|
@@ -108,13 +111,16 @@ export declare const routes: (Route<{
|
|
|
108
111
|
}[] | undefined;
|
|
109
112
|
readonly reasoning_details?: unknown;
|
|
110
113
|
} | {
|
|
111
|
-
readonly content: string;
|
|
112
114
|
readonly role: "tool";
|
|
113
115
|
readonly tool_call_id: string;
|
|
114
|
-
readonly
|
|
115
|
-
readonly type: "
|
|
116
|
-
readonly
|
|
117
|
-
|
|
116
|
+
readonly content: string | readonly {
|
|
117
|
+
readonly type: "text";
|
|
118
|
+
readonly text: string;
|
|
119
|
+
readonly cache_control?: {
|
|
120
|
+
readonly type: "ephemeral";
|
|
121
|
+
readonly ttl?: string | undefined;
|
|
122
|
+
} | undefined;
|
|
123
|
+
}[];
|
|
118
124
|
})[];
|
|
119
125
|
readonly stream: true;
|
|
120
126
|
readonly max_completion_tokens?: number | undefined;
|
|
@@ -516,15 +516,18 @@ export declare const routes: (Route<{
|
|
|
516
516
|
})[];
|
|
517
517
|
} | {
|
|
518
518
|
readonly [x: string]: unknown;
|
|
519
|
-
readonly content: string |
|
|
519
|
+
readonly content: string | readonly {
|
|
520
|
+
readonly type: "text";
|
|
521
|
+
readonly text: string;
|
|
522
|
+
readonly cache_control?: {
|
|
523
|
+
readonly type: "ephemeral";
|
|
524
|
+
readonly ttl?: string | undefined;
|
|
525
|
+
} | undefined;
|
|
526
|
+
}[] | null;
|
|
520
527
|
readonly role: "assistant";
|
|
521
528
|
readonly reasoning?: string | undefined;
|
|
522
529
|
readonly reasoning_content?: string | undefined;
|
|
523
530
|
readonly reasoning_text?: string | undefined;
|
|
524
|
-
readonly cache_control?: {
|
|
525
|
-
readonly type: "ephemeral";
|
|
526
|
-
readonly ttl?: string | undefined;
|
|
527
|
-
} | undefined;
|
|
528
531
|
readonly tool_calls?: readonly {
|
|
529
532
|
readonly function: {
|
|
530
533
|
readonly name: string;
|
|
@@ -540,13 +543,16 @@ export declare const routes: (Route<{
|
|
|
540
543
|
}[] | undefined;
|
|
541
544
|
readonly reasoning_details?: unknown;
|
|
542
545
|
} | {
|
|
543
|
-
readonly content: string;
|
|
544
546
|
readonly role: "tool";
|
|
545
547
|
readonly tool_call_id: string;
|
|
546
|
-
readonly
|
|
547
|
-
readonly type: "
|
|
548
|
-
readonly
|
|
549
|
-
|
|
548
|
+
readonly content: string | readonly {
|
|
549
|
+
readonly type: "text";
|
|
550
|
+
readonly text: string;
|
|
551
|
+
readonly cache_control?: {
|
|
552
|
+
readonly type: "ephemeral";
|
|
553
|
+
readonly ttl?: string | undefined;
|
|
554
|
+
} | undefined;
|
|
555
|
+
}[];
|
|
550
556
|
})[];
|
|
551
557
|
readonly stream: true;
|
|
552
558
|
readonly reasoning_split: boolean;
|
|
@@ -514,15 +514,18 @@ export declare const routes: (Route<{
|
|
|
514
514
|
})[];
|
|
515
515
|
} | {
|
|
516
516
|
readonly [x: string]: unknown;
|
|
517
|
-
readonly content: string |
|
|
517
|
+
readonly content: string | readonly {
|
|
518
|
+
readonly type: "text";
|
|
519
|
+
readonly text: string;
|
|
520
|
+
readonly cache_control?: {
|
|
521
|
+
readonly type: "ephemeral";
|
|
522
|
+
readonly ttl?: string | undefined;
|
|
523
|
+
} | undefined;
|
|
524
|
+
}[] | null;
|
|
518
525
|
readonly role: "assistant";
|
|
519
526
|
readonly reasoning?: string | undefined;
|
|
520
527
|
readonly reasoning_content?: string | undefined;
|
|
521
528
|
readonly reasoning_text?: string | undefined;
|
|
522
|
-
readonly cache_control?: {
|
|
523
|
-
readonly type: "ephemeral";
|
|
524
|
-
readonly ttl?: string | undefined;
|
|
525
|
-
} | undefined;
|
|
526
529
|
readonly tool_calls?: readonly {
|
|
527
530
|
readonly function: {
|
|
528
531
|
readonly name: string;
|
|
@@ -538,13 +541,16 @@ export declare const routes: (Route<{
|
|
|
538
541
|
}[] | undefined;
|
|
539
542
|
readonly reasoning_details?: unknown;
|
|
540
543
|
} | {
|
|
541
|
-
readonly content: string;
|
|
542
544
|
readonly role: "tool";
|
|
543
545
|
readonly tool_call_id: string;
|
|
544
|
-
readonly
|
|
545
|
-
readonly type: "
|
|
546
|
-
readonly
|
|
547
|
-
|
|
546
|
+
readonly content: string | readonly {
|
|
547
|
+
readonly type: "text";
|
|
548
|
+
readonly text: string;
|
|
549
|
+
readonly cache_control?: {
|
|
550
|
+
readonly type: "ephemeral";
|
|
551
|
+
readonly ttl?: string | undefined;
|
|
552
|
+
} | undefined;
|
|
553
|
+
}[];
|
|
548
554
|
})[];
|
|
549
555
|
readonly stream: true;
|
|
550
556
|
readonly max_completion_tokens?: number | undefined;
|
|
@@ -60,15 +60,18 @@ export declare const routes: import("../route/client.js").Route<{
|
|
|
60
60
|
})[];
|
|
61
61
|
} | {
|
|
62
62
|
readonly [x: string]: unknown;
|
|
63
|
-
readonly content: string |
|
|
63
|
+
readonly content: string | readonly {
|
|
64
|
+
readonly type: "text";
|
|
65
|
+
readonly text: string;
|
|
66
|
+
readonly cache_control?: {
|
|
67
|
+
readonly type: "ephemeral";
|
|
68
|
+
readonly ttl?: string | undefined;
|
|
69
|
+
} | undefined;
|
|
70
|
+
}[] | null;
|
|
64
71
|
readonly role: "assistant";
|
|
65
72
|
readonly reasoning?: string | undefined;
|
|
66
73
|
readonly reasoning_content?: string | undefined;
|
|
67
74
|
readonly reasoning_text?: string | undefined;
|
|
68
|
-
readonly cache_control?: {
|
|
69
|
-
readonly type: "ephemeral";
|
|
70
|
-
readonly ttl?: string | undefined;
|
|
71
|
-
} | undefined;
|
|
72
75
|
readonly tool_calls?: readonly {
|
|
73
76
|
readonly function: {
|
|
74
77
|
readonly name: string;
|
|
@@ -84,13 +87,16 @@ export declare const routes: import("../route/client.js").Route<{
|
|
|
84
87
|
}[] | undefined;
|
|
85
88
|
readonly reasoning_details?: unknown;
|
|
86
89
|
} | {
|
|
87
|
-
readonly content: string;
|
|
88
90
|
readonly role: "tool";
|
|
89
91
|
readonly tool_call_id: string;
|
|
90
|
-
readonly
|
|
91
|
-
readonly type: "
|
|
92
|
-
readonly
|
|
93
|
-
|
|
92
|
+
readonly content: string | readonly {
|
|
93
|
+
readonly type: "text";
|
|
94
|
+
readonly text: string;
|
|
95
|
+
readonly cache_control?: {
|
|
96
|
+
readonly type: "ephemeral";
|
|
97
|
+
readonly ttl?: string | undefined;
|
|
98
|
+
} | undefined;
|
|
99
|
+
}[];
|
|
94
100
|
})[];
|
|
95
101
|
readonly stream: true;
|
|
96
102
|
readonly max_completion_tokens?: number | undefined;
|
|
@@ -55,15 +55,18 @@ export declare const routes: (Route<{
|
|
|
55
55
|
})[];
|
|
56
56
|
} | {
|
|
57
57
|
readonly [x: string]: unknown;
|
|
58
|
-
readonly content: string |
|
|
58
|
+
readonly content: string | readonly {
|
|
59
|
+
readonly type: "text";
|
|
60
|
+
readonly text: string;
|
|
61
|
+
readonly cache_control?: {
|
|
62
|
+
readonly type: "ephemeral";
|
|
63
|
+
readonly ttl?: string | undefined;
|
|
64
|
+
} | undefined;
|
|
65
|
+
}[] | null;
|
|
59
66
|
readonly role: "assistant";
|
|
60
67
|
readonly reasoning?: string | undefined;
|
|
61
68
|
readonly reasoning_content?: string | undefined;
|
|
62
69
|
readonly reasoning_text?: string | undefined;
|
|
63
|
-
readonly cache_control?: {
|
|
64
|
-
readonly type: "ephemeral";
|
|
65
|
-
readonly ttl?: string | undefined;
|
|
66
|
-
} | undefined;
|
|
67
70
|
readonly tool_calls?: readonly {
|
|
68
71
|
readonly function: {
|
|
69
72
|
readonly name: string;
|
|
@@ -79,13 +82,16 @@ export declare const routes: (Route<{
|
|
|
79
82
|
}[] | undefined;
|
|
80
83
|
readonly reasoning_details?: unknown;
|
|
81
84
|
} | {
|
|
82
|
-
readonly content: string;
|
|
83
85
|
readonly role: "tool";
|
|
84
86
|
readonly tool_call_id: string;
|
|
85
|
-
readonly
|
|
86
|
-
readonly type: "
|
|
87
|
-
readonly
|
|
88
|
-
|
|
87
|
+
readonly content: string | readonly {
|
|
88
|
+
readonly type: "text";
|
|
89
|
+
readonly text: string;
|
|
90
|
+
readonly cache_control?: {
|
|
91
|
+
readonly type: "ephemeral";
|
|
92
|
+
readonly ttl?: string | undefined;
|
|
93
|
+
} | undefined;
|
|
94
|
+
}[];
|
|
89
95
|
})[];
|
|
90
96
|
readonly stream: true;
|
|
91
97
|
readonly max_completion_tokens?: number | undefined;
|
|
@@ -133,7 +133,14 @@ declare const OpenRouterBody: Schema.StructWithRest<Schema.Struct<{
|
|
|
133
133
|
}>]>>]>;
|
|
134
134
|
}>, Schema.StructWithRest<Schema.Struct<{
|
|
135
135
|
readonly role: Schema.Literal<"assistant">;
|
|
136
|
-
readonly content: Schema.NullOr<Schema.String
|
|
136
|
+
readonly content: Schema.NullOr<Schema.Union<readonly [Schema.String, Schema.$Array<Schema.Struct<{
|
|
137
|
+
readonly type: Schema.Literal<"text">;
|
|
138
|
+
readonly text: Schema.String;
|
|
139
|
+
readonly cache_control: Schema.optional<Schema.Struct<{
|
|
140
|
+
readonly type: Schema.Literal<"ephemeral">;
|
|
141
|
+
readonly ttl: Schema.optional<Schema.String>;
|
|
142
|
+
}>>;
|
|
143
|
+
}>>]>>;
|
|
137
144
|
readonly tool_calls: Schema.optional<Schema.$Array<Schema.Struct<{
|
|
138
145
|
readonly id: Schema.String;
|
|
139
146
|
readonly type: Schema.tag<"function">;
|
|
@@ -151,18 +158,17 @@ declare const OpenRouterBody: Schema.StructWithRest<Schema.Struct<{
|
|
|
151
158
|
readonly reasoning: Schema.optional<Schema.String>;
|
|
152
159
|
readonly reasoning_text: Schema.optional<Schema.String>;
|
|
153
160
|
readonly reasoning_details: Schema.optional<Schema.Unknown>;
|
|
154
|
-
readonly cache_control: Schema.optional<Schema.Struct<{
|
|
155
|
-
readonly type: Schema.Literal<"ephemeral">;
|
|
156
|
-
readonly ttl: Schema.optional<Schema.String>;
|
|
157
|
-
}>>;
|
|
158
161
|
}>, readonly [Schema.$Record<Schema.String, Schema.Unknown>]>, Schema.Struct<{
|
|
159
162
|
readonly role: Schema.Literal<"tool">;
|
|
160
163
|
readonly tool_call_id: Schema.String;
|
|
161
|
-
readonly content: Schema.String
|
|
162
|
-
|
|
163
|
-
readonly
|
|
164
|
-
readonly
|
|
165
|
-
|
|
164
|
+
readonly content: Schema.Union<readonly [Schema.String, Schema.$Array<Schema.Struct<{
|
|
165
|
+
readonly type: Schema.Literal<"text">;
|
|
166
|
+
readonly text: Schema.String;
|
|
167
|
+
readonly cache_control: Schema.optional<Schema.Struct<{
|
|
168
|
+
readonly type: Schema.Literal<"ephemeral">;
|
|
169
|
+
readonly ttl: Schema.optional<Schema.String>;
|
|
170
|
+
}>>;
|
|
171
|
+
}>>]>;
|
|
166
172
|
}>]>>;
|
|
167
173
|
tools: Schema.optional<Schema.$Array<Schema.Struct<{
|
|
168
174
|
readonly type: Schema.tag<"function">;
|
|
@@ -248,15 +254,18 @@ export declare const protocol: Protocol<{
|
|
|
248
254
|
})[];
|
|
249
255
|
} | {
|
|
250
256
|
readonly [x: string]: unknown;
|
|
251
|
-
readonly content: string |
|
|
257
|
+
readonly content: string | readonly {
|
|
258
|
+
readonly type: "text";
|
|
259
|
+
readonly text: string;
|
|
260
|
+
readonly cache_control?: {
|
|
261
|
+
readonly type: "ephemeral";
|
|
262
|
+
readonly ttl?: string | undefined;
|
|
263
|
+
} | undefined;
|
|
264
|
+
}[] | null;
|
|
252
265
|
readonly role: "assistant";
|
|
253
266
|
readonly reasoning?: string | undefined;
|
|
254
267
|
readonly reasoning_content?: string | undefined;
|
|
255
268
|
readonly reasoning_text?: string | undefined;
|
|
256
|
-
readonly cache_control?: {
|
|
257
|
-
readonly type: "ephemeral";
|
|
258
|
-
readonly ttl?: string | undefined;
|
|
259
|
-
} | undefined;
|
|
260
269
|
readonly tool_calls?: readonly {
|
|
261
270
|
readonly function: {
|
|
262
271
|
readonly name: string;
|
|
@@ -272,13 +281,16 @@ export declare const protocol: Protocol<{
|
|
|
272
281
|
}[] | undefined;
|
|
273
282
|
readonly reasoning_details?: unknown;
|
|
274
283
|
} | {
|
|
275
|
-
readonly content: string;
|
|
276
284
|
readonly role: "tool";
|
|
277
285
|
readonly tool_call_id: string;
|
|
278
|
-
readonly
|
|
279
|
-
readonly type: "
|
|
280
|
-
readonly
|
|
281
|
-
|
|
286
|
+
readonly content: string | readonly {
|
|
287
|
+
readonly type: "text";
|
|
288
|
+
readonly text: string;
|
|
289
|
+
readonly cache_control?: {
|
|
290
|
+
readonly type: "ephemeral";
|
|
291
|
+
readonly ttl?: string | undefined;
|
|
292
|
+
} | undefined;
|
|
293
|
+
}[];
|
|
282
294
|
})[];
|
|
283
295
|
readonly stream: true;
|
|
284
296
|
readonly max_completion_tokens?: number | undefined;
|
|
@@ -326,6 +338,7 @@ export declare const protocol: Protocol<{
|
|
|
326
338
|
} | null | undefined;
|
|
327
339
|
readonly usage?: {
|
|
328
340
|
readonly [x: string]: unknown;
|
|
341
|
+
readonly cache_read_input_tokens?: number | null | undefined;
|
|
329
342
|
readonly cached_tokens?: number | null | undefined;
|
|
330
343
|
readonly prompt_tokens?: number | null | undefined;
|
|
331
344
|
readonly completion_tokens?: number | null | undefined;
|
|
@@ -336,6 +349,7 @@ export declare const protocol: Protocol<{
|
|
|
336
349
|
readonly cache_write_tokens?: number | null | undefined;
|
|
337
350
|
} | null | undefined;
|
|
338
351
|
readonly prompt_cache_hit_tokens?: number | null | undefined;
|
|
352
|
+
readonly cache_created_input_tokens?: number | null | undefined;
|
|
339
353
|
readonly completion_tokens_details?: {
|
|
340
354
|
readonly [x: string]: unknown;
|
|
341
355
|
readonly reasoning_tokens?: number | null | undefined;
|
|
@@ -365,6 +379,7 @@ export declare const protocol: Protocol<{
|
|
|
365
379
|
} | null | undefined;
|
|
366
380
|
readonly usage?: {
|
|
367
381
|
readonly [x: string]: unknown;
|
|
382
|
+
readonly cache_read_input_tokens?: number | null | undefined;
|
|
368
383
|
readonly cached_tokens?: number | null | undefined;
|
|
369
384
|
readonly prompt_tokens?: number | null | undefined;
|
|
370
385
|
readonly completion_tokens?: number | null | undefined;
|
|
@@ -375,6 +390,7 @@ export declare const protocol: Protocol<{
|
|
|
375
390
|
readonly cache_write_tokens?: number | null | undefined;
|
|
376
391
|
} | null | undefined;
|
|
377
392
|
readonly prompt_cache_hit_tokens?: number | null | undefined;
|
|
393
|
+
readonly cache_created_input_tokens?: number | null | undefined;
|
|
378
394
|
readonly completion_tokens_details?: {
|
|
379
395
|
readonly [x: string]: unknown;
|
|
380
396
|
readonly reasoning_tokens?: number | null | undefined;
|
|
@@ -433,15 +449,18 @@ export declare const route: Route<{
|
|
|
433
449
|
})[];
|
|
434
450
|
} | {
|
|
435
451
|
readonly [x: string]: unknown;
|
|
436
|
-
readonly content: string |
|
|
452
|
+
readonly content: string | readonly {
|
|
453
|
+
readonly type: "text";
|
|
454
|
+
readonly text: string;
|
|
455
|
+
readonly cache_control?: {
|
|
456
|
+
readonly type: "ephemeral";
|
|
457
|
+
readonly ttl?: string | undefined;
|
|
458
|
+
} | undefined;
|
|
459
|
+
}[] | null;
|
|
437
460
|
readonly role: "assistant";
|
|
438
461
|
readonly reasoning?: string | undefined;
|
|
439
462
|
readonly reasoning_content?: string | undefined;
|
|
440
463
|
readonly reasoning_text?: string | undefined;
|
|
441
|
-
readonly cache_control?: {
|
|
442
|
-
readonly type: "ephemeral";
|
|
443
|
-
readonly ttl?: string | undefined;
|
|
444
|
-
} | undefined;
|
|
445
464
|
readonly tool_calls?: readonly {
|
|
446
465
|
readonly function: {
|
|
447
466
|
readonly name: string;
|
|
@@ -457,13 +476,16 @@ export declare const route: Route<{
|
|
|
457
476
|
}[] | undefined;
|
|
458
477
|
readonly reasoning_details?: unknown;
|
|
459
478
|
} | {
|
|
460
|
-
readonly content: string;
|
|
461
479
|
readonly role: "tool";
|
|
462
480
|
readonly tool_call_id: string;
|
|
463
|
-
readonly
|
|
464
|
-
readonly type: "
|
|
465
|
-
readonly
|
|
466
|
-
|
|
481
|
+
readonly content: string | readonly {
|
|
482
|
+
readonly type: "text";
|
|
483
|
+
readonly text: string;
|
|
484
|
+
readonly cache_control?: {
|
|
485
|
+
readonly type: "ephemeral";
|
|
486
|
+
readonly ttl?: string | undefined;
|
|
487
|
+
} | undefined;
|
|
488
|
+
}[];
|
|
467
489
|
})[];
|
|
468
490
|
readonly stream: true;
|
|
469
491
|
readonly max_completion_tokens?: number | undefined;
|
|
@@ -550,15 +572,18 @@ export declare const routes: Route<{
|
|
|
550
572
|
})[];
|
|
551
573
|
} | {
|
|
552
574
|
readonly [x: string]: unknown;
|
|
553
|
-
readonly content: string |
|
|
575
|
+
readonly content: string | readonly {
|
|
576
|
+
readonly type: "text";
|
|
577
|
+
readonly text: string;
|
|
578
|
+
readonly cache_control?: {
|
|
579
|
+
readonly type: "ephemeral";
|
|
580
|
+
readonly ttl?: string | undefined;
|
|
581
|
+
} | undefined;
|
|
582
|
+
}[] | null;
|
|
554
583
|
readonly role: "assistant";
|
|
555
584
|
readonly reasoning?: string | undefined;
|
|
556
585
|
readonly reasoning_content?: string | undefined;
|
|
557
586
|
readonly reasoning_text?: string | undefined;
|
|
558
|
-
readonly cache_control?: {
|
|
559
|
-
readonly type: "ephemeral";
|
|
560
|
-
readonly ttl?: string | undefined;
|
|
561
|
-
} | undefined;
|
|
562
587
|
readonly tool_calls?: readonly {
|
|
563
588
|
readonly function: {
|
|
564
589
|
readonly name: string;
|
|
@@ -574,13 +599,16 @@ export declare const routes: Route<{
|
|
|
574
599
|
}[] | undefined;
|
|
575
600
|
readonly reasoning_details?: unknown;
|
|
576
601
|
} | {
|
|
577
|
-
readonly content: string;
|
|
578
602
|
readonly role: "tool";
|
|
579
603
|
readonly tool_call_id: string;
|
|
580
|
-
readonly
|
|
581
|
-
readonly type: "
|
|
582
|
-
readonly
|
|
583
|
-
|
|
604
|
+
readonly content: string | readonly {
|
|
605
|
+
readonly type: "text";
|
|
606
|
+
readonly text: string;
|
|
607
|
+
readonly cache_control?: {
|
|
608
|
+
readonly type: "ephemeral";
|
|
609
|
+
readonly ttl?: string | undefined;
|
|
610
|
+
} | undefined;
|
|
611
|
+
}[];
|
|
584
612
|
})[];
|
|
585
613
|
readonly stream: true;
|
|
586
614
|
readonly max_completion_tokens?: number | undefined;
|
|
@@ -6,7 +6,7 @@ import { AuthOptions } from "../route/auth-options.js";
|
|
|
6
6
|
import { HttpOptions, ProviderID } from "../schema/index.js";
|
|
7
7
|
import { SystemOne } from "../experimental/system-one.js";
|
|
8
8
|
import { OpenAIChat } from "../protocols/openai-chat.js";
|
|
9
|
-
import {
|
|
9
|
+
import { cacheControl } from "../protocols/utils/cache.js";
|
|
10
10
|
import { isRecord, ProviderShared } from "../protocols/shared.js";
|
|
11
11
|
export const id = ProviderID.make("openrouter");
|
|
12
12
|
const baseURL = "https://openrouter.ai/api/v1";
|
|
@@ -47,18 +47,6 @@ export const protocol = Protocol.make({
|
|
|
47
47
|
},
|
|
48
48
|
stream: OpenAIChat.protocol.stream,
|
|
49
49
|
});
|
|
50
|
-
const cacheControl = () => {
|
|
51
|
-
const breakpoints = newBreakpoints(4);
|
|
52
|
-
return (cache) => {
|
|
53
|
-
if (cache === undefined || breakpoints.remaining === 0)
|
|
54
|
-
return undefined;
|
|
55
|
-
breakpoints.remaining -= 1;
|
|
56
|
-
return {
|
|
57
|
-
type: "ephemeral",
|
|
58
|
-
...(ttlBucket(cache.ttlSeconds) === "1h" ? { ttl: "1h" } : {}),
|
|
59
|
-
};
|
|
60
|
-
};
|
|
61
|
-
};
|
|
62
50
|
// OpenRouter forwards `reasoning.max_tokens` as the upstream thinking budget. Upstreams such as Anthropic and Alibaba
|
|
63
51
|
// reject one that is not below the output limit; 1,024 is Anthropic's minimum budget.
|
|
64
52
|
const fitReasoning = (reasoning, maxTokens) => typeof reasoning.max_tokens === "number"
|