@mupt-ai/dari-gateway 1.0.329 → 1.0.331
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 +38 -8
- package/dari-gateway.example.yaml +4 -0
- package/dist/activity/conversations.js +4 -2
- package/dist/activity/core.js +52 -28
- package/dist/activity/people.js +20 -17
- package/dist/link/assets.js +2 -0
- package/dist/link/key_providers.js +1 -0
- package/dist/models/canonical.d.ts +12 -0
- package/dist/models/canonical.js +10 -0
- package/dist/models/canonical_models.json +69 -0
- package/dist/models/catalog.js +1 -0
- package/dist/models/provider_defaults.js +2 -0
- package/dist/models/provider_models.json +114 -0
- package/dist/models/runtime_overrides.js +13 -0
- package/dist/protocol/output/anthropic_messages_output.js +3 -1
- package/dist/protocol/output/anthropic_messages_stream.js +14 -0
- package/dist/providers/model_capabilities.d.ts +1 -0
- package/dist/providers/model_capabilities.js +5 -1
- package/dist/providers/pi.js +2 -0
- package/dist/providers/pi_context.js +35 -2
- package/dist/providers/pi_options.js +50 -0
- package/dist/providers/pi_output.js +21 -3
- package/dist/self_host/config.d.ts +46 -4
- package/dist/self_host/config.js +165 -54
- package/dist/self_host/main.d.ts +7 -3
- package/dist/self_host/main.js +40 -17
- package/dist/self_host/platform.d.ts +4 -3
- package/dist/self_host/platform.js +6 -4
- package/dist/self_host/resolve.d.ts +2 -0
- package/dist/self_host/resolve.js +23 -10
- package/dist/self_host/router_models.d.ts +5 -2
- package/dist/self_host/router_models.js +10 -5
- package/dist/self_host/router_specs.d.ts +64 -0
- package/dist/self_host/router_specs.js +194 -0
- package/dist/telemetry/requests/interaction_observability.js +1 -0
- package/package.json +3 -3
- package/src/activity/conversations.ts +4 -2
- package/src/activity/core.ts +52 -28
- package/src/activity/people.ts +20 -18
- package/src/link/assets.ts +2 -0
- package/src/link/key_providers.ts +1 -0
- package/src/models/canonical.ts +22 -0
- package/src/models/canonical_models.json +69 -0
- package/src/models/catalog.ts +1 -0
- package/src/models/provider_defaults.ts +2 -0
- package/src/models/provider_models.json +114 -0
- package/src/models/runtime_overrides.ts +13 -0
- package/src/protocol/output/anthropic_messages_output.ts +5 -1
- package/src/protocol/output/anthropic_messages_stream.ts +16 -0
- package/src/providers/model_capabilities.ts +6 -1
- package/src/providers/pi.ts +1 -0
- package/src/providers/pi_context.ts +34 -3
- package/src/providers/pi_options.ts +51 -1
- package/src/providers/pi_output.ts +21 -3
- package/src/self_host/config.ts +217 -60
- package/src/self_host/main.ts +47 -18
- package/src/self_host/platform.ts +6 -4
- package/src/self_host/resolve.ts +24 -9
- package/src/self_host/router_models.ts +16 -6
- package/src/self_host/router_specs.ts +236 -0
- package/src/telemetry/requests/interaction_observability.ts +1 -0
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
[
|
|
2
|
+
{
|
|
3
|
+
"model_id": "meta/muse-spark-open",
|
|
4
|
+
"provider": "fireworks",
|
|
5
|
+
"native_model_id": "accounts/fireworks/models/muse-spark-open",
|
|
6
|
+
"api": "anthropic-messages",
|
|
7
|
+
"base_url": "https://api.fireworks.ai/inference"
|
|
8
|
+
},
|
|
9
|
+
{
|
|
10
|
+
"model_id": "moonshotai/Kimi-K3",
|
|
11
|
+
"provider": "fireworks",
|
|
12
|
+
"native_model_id": "accounts/fireworks/models/kimi-k3",
|
|
13
|
+
"api": "openai-completions",
|
|
14
|
+
"base_url": "https://api.fireworks.ai/inference/v1"
|
|
15
|
+
},
|
|
16
|
+
{
|
|
17
|
+
"model_id": "zai-org/GLM-5.3",
|
|
18
|
+
"provider": "fireworks",
|
|
19
|
+
"native_model_id": "accounts/fireworks/models/glm-5p3",
|
|
20
|
+
"api": "openai-completions",
|
|
21
|
+
"base_url": "https://api.fireworks.ai/inference/v1"
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
"model_id": "zai-org/GLM-5.3-Flash",
|
|
25
|
+
"provider": "fireworks",
|
|
26
|
+
"native_model_id": "accounts/fireworks/models/glm-5p3-flash",
|
|
27
|
+
"api": "openai-completions",
|
|
28
|
+
"base_url": "https://api.fireworks.ai/inference/v1"
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
"model_id": "deepseek-ai/DeepSeek-V4-Pro-0813",
|
|
32
|
+
"provider": "fireworks",
|
|
33
|
+
"native_model_id": "accounts/fireworks/models/deepseek-v4-pro-0813",
|
|
34
|
+
"api": "openai-completions",
|
|
35
|
+
"base_url": "https://api.fireworks.ai/inference/v1"
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
"model_id": "zai-org/GLM-5.2",
|
|
39
|
+
"provider": "fireworks",
|
|
40
|
+
"native_model_id": "accounts/fireworks/models/glm-5p2",
|
|
41
|
+
"api": "openai-completions",
|
|
42
|
+
"base_url": "https://api.fireworks.ai/inference/v1"
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
"model_id": "deepseek-ai/DeepSeek-V4-Flash-0731",
|
|
46
|
+
"provider": "fireworks",
|
|
47
|
+
"native_model_id": "accounts/fireworks/models/deepseek-v4-flash-0731",
|
|
48
|
+
"api": "openai-completions",
|
|
49
|
+
"base_url": "https://api.fireworks.ai/inference/v1"
|
|
50
|
+
},
|
|
51
|
+
{
|
|
52
|
+
"model_id": "deepseek-ai/DeepSeek-V4.1-Flash",
|
|
53
|
+
"provider": "fireworks",
|
|
54
|
+
"native_model_id": "accounts/fireworks/models/deepseek-v4p1-flash",
|
|
55
|
+
"api": "openai-completions",
|
|
56
|
+
"base_url": "https://api.fireworks.ai/inference/v1"
|
|
57
|
+
},
|
|
58
|
+
{
|
|
59
|
+
"model_id": "deepseek-ai/DeepSeek-V4.1-Flash-1017",
|
|
60
|
+
"provider": "fireworks",
|
|
61
|
+
"native_model_id": "accounts/fireworks/models/deepseek-v4p1-flash-1017",
|
|
62
|
+
"api": "openai-completions",
|
|
63
|
+
"base_url": "https://api.fireworks.ai/inference/v1"
|
|
64
|
+
},
|
|
65
|
+
{
|
|
66
|
+
"model_id": "moonshotai/Kimi-K3",
|
|
67
|
+
"provider": "opencode-go",
|
|
68
|
+
"native_model_id": "kimi-k3",
|
|
69
|
+
"api": "openai-completions",
|
|
70
|
+
"base_url": "https://opencode.ai/inference/go/openai/v1"
|
|
71
|
+
},
|
|
72
|
+
{
|
|
73
|
+
"model_id": "moonshotai/Kimi-K3.1-Pro",
|
|
74
|
+
"provider": "fireworks",
|
|
75
|
+
"native_model_id": "accounts/fireworks/models/kimi-k3p1-pro",
|
|
76
|
+
"api": "openai-completions",
|
|
77
|
+
"base_url": "https://api.fireworks.ai/inference/v1"
|
|
78
|
+
},
|
|
79
|
+
{
|
|
80
|
+
"model_id": "moonshotai/Kimi-K3.1-Pro",
|
|
81
|
+
"provider": "opencode-go",
|
|
82
|
+
"native_model_id": "kimi-k3.1-pro",
|
|
83
|
+
"api": "openai-completions",
|
|
84
|
+
"base_url": "https://opencode.ai/inference/go/openai/v1"
|
|
85
|
+
},
|
|
86
|
+
{
|
|
87
|
+
"model_id": "zai-org/GLM-5.3",
|
|
88
|
+
"provider": "opencode-go",
|
|
89
|
+
"native_model_id": "glm-5.3",
|
|
90
|
+
"api": "openai-completions",
|
|
91
|
+
"base_url": "https://opencode.ai/inference/go/openai/v1"
|
|
92
|
+
},
|
|
93
|
+
{
|
|
94
|
+
"model_id": "zai-org/GLM-5.3-Flash",
|
|
95
|
+
"provider": "opencode-go",
|
|
96
|
+
"native_model_id": "glm-5.3-flash",
|
|
97
|
+
"api": "openai-completions",
|
|
98
|
+
"base_url": "https://opencode.ai/inference/go/openai/v1"
|
|
99
|
+
},
|
|
100
|
+
{
|
|
101
|
+
"model_id": "zai-org/GLM-5.2",
|
|
102
|
+
"provider": "opencode-go",
|
|
103
|
+
"native_model_id": "glm-5.2",
|
|
104
|
+
"api": "openai-completions",
|
|
105
|
+
"base_url": "https://opencode.ai/inference/go/openai/v1"
|
|
106
|
+
},
|
|
107
|
+
{
|
|
108
|
+
"model_id": "deepseek-ai/DeepSeek-V4.1-Flash-1017",
|
|
109
|
+
"provider": "opencode-go",
|
|
110
|
+
"native_model_id": "deepseek-v4.1-flash",
|
|
111
|
+
"api": "openai-completions",
|
|
112
|
+
"base_url": "https://opencode.ai/inference/go/openai/v1"
|
|
113
|
+
}
|
|
114
|
+
]
|
|
@@ -58,9 +58,20 @@ const MODEL_COMPAT_OVERRIDES = {
|
|
|
58
58
|
"openai/gpt-6-astra": {
|
|
59
59
|
supportsTemperature: false,
|
|
60
60
|
},
|
|
61
|
+
"openai/gpt-6.2-astra": {
|
|
62
|
+
supportsTemperature: false,
|
|
63
|
+
},
|
|
61
64
|
// GPT-6 Sol and Luna are newer than the installed Pi registry. They retain
|
|
62
65
|
// the GPT-5.6 Responses feature set, including explicit prompt caching and
|
|
63
66
|
// deferred tool loading. Keep this local until Pi ships their metadata.
|
|
67
|
+
"openai/gpt-6.2-sol": {
|
|
68
|
+
supportsStrictMode: true,
|
|
69
|
+
supportsOpenAIGrammarTools: true,
|
|
70
|
+
supportsAdditionalTools: true,
|
|
71
|
+
supportsToolSearch: true,
|
|
72
|
+
supportsExplicitPromptCacheMode: true,
|
|
73
|
+
supportsReasoningConfigurationUpdate: true,
|
|
74
|
+
},
|
|
64
75
|
"openai/gpt-6.1-sol": {
|
|
65
76
|
supportsStrictMode: true,
|
|
66
77
|
supportsOpenAIGrammarTools: true,
|
|
@@ -151,6 +162,7 @@ const MODEL_INPUT_OVERRIDES = {
|
|
|
151
162
|
"anthropic/claude-haiku-5-5": ["text", "image"],
|
|
152
163
|
"anthropic/claude-sonnet-5-5": ["text", "image"],
|
|
153
164
|
"meta/muse-ember": ["text", "image"],
|
|
165
|
+
"openai/gpt-6.2-sol": ["text", "image"],
|
|
154
166
|
"openai/gpt-6.1-sol": ["text", "image"],
|
|
155
167
|
"openai/gpt-6.1-terra": ["text", "image"],
|
|
156
168
|
"openai/gpt-6-sol": ["text", "image"],
|
|
@@ -158,6 +170,7 @@ const MODEL_INPUT_OVERRIDES = {
|
|
|
158
170
|
"openai/gpt-5.6-luna": ["text", "image"],
|
|
159
171
|
"openai/gpt-5.6-sol": ["text", "image"],
|
|
160
172
|
"openai/gpt-5.6-terra": ["text", "image"],
|
|
173
|
+
"openai/gpt-6.2-astra": ["text", "image"],
|
|
161
174
|
"openai/gpt-6-astra": ["text", "image"],
|
|
162
175
|
"moonshotai/Kimi-K3": ["text", "image"],
|
|
163
176
|
"deepseek-ai/DeepSeek-V4.1-Flash-1017": ["text", "image"],
|
|
@@ -83,7 +83,9 @@ export function anthropicReasoningBlock(item) {
|
|
|
83
83
|
const encoded = item.continuation
|
|
84
84
|
? encodeProviderContinuationState(item.continuation)
|
|
85
85
|
: encodePortableReasoningState({ source: item.source, itemId: item.id });
|
|
86
|
-
|
|
86
|
+
// Gemini's signature-only state has nothing readable to show.
|
|
87
|
+
if (item.continuation?.kind === "anthropic_redacted_thinking"
|
|
88
|
+
|| item.continuation?.kind === "google_thought_signatures") {
|
|
87
89
|
return { type: "redacted_thinking", data: encoded };
|
|
88
90
|
}
|
|
89
91
|
return {
|
|
@@ -220,6 +220,20 @@ export function anthropicMessagesSseStream(args) {
|
|
|
220
220
|
}
|
|
221
221
|
else {
|
|
222
222
|
const output = piMessageToInteractionOutput(event.message, args.source, args.request);
|
|
223
|
+
// Content blocks stream at the provider's content indexes;
|
|
224
|
+
// Gemini's signatures follow them in one more block.
|
|
225
|
+
const signatures = output.items.at(-1);
|
|
226
|
+
if (signatures?.type === "reasoning"
|
|
227
|
+
&& signatures.continuation?.kind === "google_thought_signatures"
|
|
228
|
+
&& Array.isArray(event.message.content)) {
|
|
229
|
+
const index = event.message.content.length;
|
|
230
|
+
send("content_block_start", {
|
|
231
|
+
type: "content_block_start",
|
|
232
|
+
index,
|
|
233
|
+
content_block: anthropicReasoningBlock(signatures),
|
|
234
|
+
});
|
|
235
|
+
send("content_block_stop", { type: "content_block_stop", index });
|
|
236
|
+
}
|
|
223
237
|
settle({ status: "completed", message: event.message, output });
|
|
224
238
|
send("message_delta", {
|
|
225
239
|
type: "message_delta",
|
|
@@ -7,6 +7,7 @@ export declare function modelSupportsImageInput(metadata: ModelCapabilityMetadat
|
|
|
7
7
|
export declare function apiSupportsDocumentInput(api: string): boolean;
|
|
8
8
|
export declare function modelSupportsDocumentInput(modelId: string, metadata: ModelCapabilityMetadata): boolean;
|
|
9
9
|
export declare function providerApiCanSerializeResponseFormat(metadata: ModelCapabilityMetadata): boolean;
|
|
10
|
+
export declare function isGoogleApi(api: unknown): boolean;
|
|
10
11
|
export declare function isOpenAIResponsesApi(api: unknown): boolean;
|
|
11
12
|
export declare function modelSupportsReasoningConfigurationUpdate(metadata: ModelCapabilityMetadata): boolean;
|
|
12
13
|
export declare function modelSupportsNativeCompaction(metadata: ModelCapabilityMetadata): boolean;
|
|
@@ -25,7 +25,11 @@ export function providerApiCanSerializeResponseFormat(metadata) {
|
|
|
25
25
|
return (metadata.model.api === "openai-responses" ||
|
|
26
26
|
metadata.model.api === "azure-openai-responses" ||
|
|
27
27
|
metadata.model.api === "openai-completions" ||
|
|
28
|
-
metadata.model.api === "anthropic-messages"
|
|
28
|
+
metadata.model.api === "anthropic-messages" ||
|
|
29
|
+
isGoogleApi(metadata.model.api));
|
|
30
|
+
}
|
|
31
|
+
export function isGoogleApi(api) {
|
|
32
|
+
return api === "google-generative-ai" || api === "google-vertex";
|
|
29
33
|
}
|
|
30
34
|
export function isOpenAIResponsesApi(api) {
|
|
31
35
|
return (api === "openai-responses"
|
package/dist/providers/pi.js
CHANGED
|
@@ -367,6 +367,8 @@ function defaultApi(provider) {
|
|
|
367
367
|
return "openai-responses";
|
|
368
368
|
if (provider === "anthropic")
|
|
369
369
|
return "anthropic-messages";
|
|
370
|
+
if (provider === "google")
|
|
371
|
+
return "google-generative-ai";
|
|
370
372
|
if (provider === "amazon-bedrock")
|
|
371
373
|
return BEDROCK_API;
|
|
372
374
|
if (provider === "azure")
|
|
@@ -19,6 +19,7 @@ export function buildContext(request, target) {
|
|
|
19
19
|
const timestamp = Date.now();
|
|
20
20
|
let pending = null;
|
|
21
21
|
let sawConversationItem = false;
|
|
22
|
+
const thoughtSignatures = googleThoughtSignatures(request.items, target);
|
|
22
23
|
const flushAssistant = () => {
|
|
23
24
|
if (!pending)
|
|
24
25
|
return;
|
|
@@ -114,7 +115,9 @@ export function buildContext(request, target) {
|
|
|
114
115
|
continue;
|
|
115
116
|
}
|
|
116
117
|
if (item.type === "reasoning") {
|
|
117
|
-
const
|
|
118
|
+
const compatible = compatibleProviderContinuation(item.continuation, target);
|
|
119
|
+
// Gemini signatures are replayed on their tool calls below.
|
|
120
|
+
const continuation = compatible?.kind === "google_thought_signatures" ? null : compatible;
|
|
118
121
|
if (continuation) {
|
|
119
122
|
const assistant = assistantForReasoning(continuation.source);
|
|
120
123
|
const firstNonReasoning = assistant.content.findIndex((content) => content.type !== "thinking");
|
|
@@ -141,7 +144,12 @@ export function buildContext(request, target) {
|
|
|
141
144
|
continue;
|
|
142
145
|
}
|
|
143
146
|
if (item.type === "tool_call") {
|
|
144
|
-
const
|
|
147
|
+
const thoughtSignature = thoughtSignatures.get(itemIndex);
|
|
148
|
+
// A signed call came from the target model; Pi replays its signature
|
|
149
|
+
// only on an assistant turn that model produced.
|
|
150
|
+
const assistant = thoughtSignature
|
|
151
|
+
? assistantForReasoning(target)
|
|
152
|
+
: assistantFor(pending ? identityOf(pending) : UNKNOWN_SOURCE);
|
|
145
153
|
const id = providerToolCallId(item.callId, item.id, target.api);
|
|
146
154
|
const name = toolWireName(item.namespace, item.name);
|
|
147
155
|
assistant.content.push({
|
|
@@ -149,6 +157,7 @@ export function buildContext(request, target) {
|
|
|
149
157
|
id,
|
|
150
158
|
name,
|
|
151
159
|
arguments: toolArguments(item.kind, item.input),
|
|
160
|
+
...(thoughtSignature ? { thoughtSignature } : {}),
|
|
152
161
|
});
|
|
153
162
|
toolCalls.set(item.callId, { id, name });
|
|
154
163
|
continue;
|
|
@@ -248,6 +257,30 @@ export function buildContext(request, target) {
|
|
|
248
257
|
context.tools = clientTools.map((tool) => toolToPi(tool, target.api));
|
|
249
258
|
return context;
|
|
250
259
|
}
|
|
260
|
+
// Signatures are keyed by item index, not call id: Gemini may reuse a call id
|
|
261
|
+
// in a later step, so each envelope signs only the calls of its own assistant
|
|
262
|
+
// turn (the items between the surrounding tool results and user messages).
|
|
263
|
+
function googleThoughtSignatures(items, target) {
|
|
264
|
+
const signatures = new Map();
|
|
265
|
+
const bounds = (item) => item.type === "tool_result" || (item.type === "message" && item.role !== "assistant");
|
|
266
|
+
for (const [index, item] of items.entries()) {
|
|
267
|
+
if (item.type !== "reasoning")
|
|
268
|
+
continue;
|
|
269
|
+
const continuation = compatibleProviderContinuation(item.continuation, target);
|
|
270
|
+
if (continuation?.kind !== "google_thought_signatures")
|
|
271
|
+
continue;
|
|
272
|
+
let start = index;
|
|
273
|
+
while (start > 0 && !bounds(items[start - 1]))
|
|
274
|
+
start -= 1;
|
|
275
|
+
for (let callIndex = start; callIndex < items.length && !bounds(items[callIndex]); callIndex += 1) {
|
|
276
|
+
const call = items[callIndex];
|
|
277
|
+
const signature = call.type === "tool_call" && Object.hasOwn(continuation.toolCallSignatures, call.callId) ? continuation.toolCallSignatures[call.callId] : undefined;
|
|
278
|
+
if (signature)
|
|
279
|
+
signatures.set(callIndex, signature);
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
return signatures;
|
|
283
|
+
}
|
|
251
284
|
function isSentTool(tool, target) {
|
|
252
285
|
return tool.kind !== "hosted" && (tool.kind !== "server_tool" || target.api === "anthropic-messages");
|
|
253
286
|
}
|
|
@@ -123,6 +123,14 @@ export function buildOptions(request, auth, selectedModel, model, pi, sessionId,
|
|
|
123
123
|
// onPayload runs, so the choice must ride on options, not a payload patch.
|
|
124
124
|
if (isBedrockApi(api))
|
|
125
125
|
options.toolChoice = bedrockToolChoice(toolChoice);
|
|
126
|
+
else if (isGoogle(api)) {
|
|
127
|
+
// Pi's Google transport builds functionCallingConfig from the option.
|
|
128
|
+
options.toolChoice = googleToolChoice(toolChoice);
|
|
129
|
+
if (typeof toolChoice !== "string" && toolChoice.kind !== "hosted") {
|
|
130
|
+
const name = toolWireName(toolChoice.namespace, toolChoice.name);
|
|
131
|
+
patches.push((payload) => payloadWithGoogleAllowedFunction(payload, name));
|
|
132
|
+
}
|
|
133
|
+
}
|
|
126
134
|
else
|
|
127
135
|
patches.push((payload) => ({ ...payload, tool_choice: providerToolChoice(toolChoice, api) }));
|
|
128
136
|
}
|
|
@@ -163,6 +171,8 @@ export function buildOptions(request, auth, selectedModel, model, pi, sessionId,
|
|
|
163
171
|
}
|
|
164
172
|
if (isOpenAIResponsesApi(api))
|
|
165
173
|
patches.push(payloadWithDetailedReasoningSummary);
|
|
174
|
+
if (isGoogle(api))
|
|
175
|
+
patches.push(payloadWithGoogleThoughtSignatures);
|
|
166
176
|
// Some clients send the default tool_choice even after omitting tools for
|
|
167
177
|
// a turn. OpenAI rejects every tool_choice value when the lowered payload
|
|
168
178
|
// has no tools, so enforce that provider invariant after all tool patches.
|
|
@@ -360,6 +370,10 @@ function payloadWithResponseFormat(payload, format, api) {
|
|
|
360
370
|
const schema = format.type === "json_schema" ? format.schema : { type: "object" };
|
|
361
371
|
return { ...payload, output_config: { ...asRecord(payload.output_config), format: { type: "json_schema", schema } } };
|
|
362
372
|
}
|
|
373
|
+
if (isGoogle(api)) {
|
|
374
|
+
const config = { ...asRecord(payload.config), responseMimeType: "application/json" };
|
|
375
|
+
return { ...payload, config: format.type === "json_schema" ? { ...config, responseJsonSchema: format.schema } : config };
|
|
376
|
+
}
|
|
363
377
|
if (format.type === "json_object") {
|
|
364
378
|
if (isResponses(api))
|
|
365
379
|
return { ...payload, text: { ...asRecord(payload.text), format } };
|
|
@@ -381,6 +395,42 @@ function bedrockToolChoice(choice) {
|
|
|
381
395
|
return undefined;
|
|
382
396
|
return { type: "function", function: { name: toolWireName(choice.namespace, choice.name) } };
|
|
383
397
|
}
|
|
398
|
+
function googleToolChoice(choice) {
|
|
399
|
+
if (typeof choice === "string")
|
|
400
|
+
return choice === "auto" || choice === "none" ? choice : "any";
|
|
401
|
+
return choice.kind === "hosted" ? undefined : "any";
|
|
402
|
+
}
|
|
403
|
+
function payloadWithGoogleAllowedFunction(payload, name) {
|
|
404
|
+
const config = asRecord(payload.config);
|
|
405
|
+
const toolConfig = asRecord(config.toolConfig);
|
|
406
|
+
const functionCallingConfig = { ...asRecord(toolConfig.functionCallingConfig), allowedFunctionNames: [name] };
|
|
407
|
+
return { ...payload, config: { ...config, toolConfig: { ...toolConfig, functionCallingConfig } } };
|
|
408
|
+
}
|
|
409
|
+
// Gemini rejects a step whose first function call has no thought signature.
|
|
410
|
+
// Calls another model made, or whose signature the client dropped, carry
|
|
411
|
+
// Google's documented placeholder that skips the check.
|
|
412
|
+
const GOOGLE_SKIP_THOUGHT_SIGNATURE = "skip_thought_signature_validator";
|
|
413
|
+
function payloadWithGoogleThoughtSignatures(payload) {
|
|
414
|
+
if (!Array.isArray(payload.contents))
|
|
415
|
+
return undefined;
|
|
416
|
+
let changed = false;
|
|
417
|
+
const contents = payload.contents.map((content) => {
|
|
418
|
+
if (!isRecord(content) || content.role !== "model" || !Array.isArray(content.parts))
|
|
419
|
+
return content;
|
|
420
|
+
const parts = content.parts;
|
|
421
|
+
// Gemini validates the first call of each step, so that call needs a
|
|
422
|
+
// signature even when a later call in the same turn carries one.
|
|
423
|
+
const first = parts.findIndex((part) => isRecord(part) && isRecord(part.functionCall));
|
|
424
|
+
if (first === -1 || asRecord(parts[first]).thoughtSignature)
|
|
425
|
+
return content;
|
|
426
|
+
changed = true;
|
|
427
|
+
return {
|
|
428
|
+
...content,
|
|
429
|
+
parts: parts.map((part, index) => index === first ? { ...asRecord(part), thoughtSignature: GOOGLE_SKIP_THOUGHT_SIGNATURE } : part),
|
|
430
|
+
};
|
|
431
|
+
});
|
|
432
|
+
return changed ? { ...payload, contents } : undefined;
|
|
433
|
+
}
|
|
384
434
|
function providerToolChoice(choice, api) {
|
|
385
435
|
if (typeof choice === "string") {
|
|
386
436
|
if (isAnthropic(api))
|
|
@@ -2,7 +2,7 @@ import { isRecord } from "@mupt-ai/dari-router/policy-engine";
|
|
|
2
2
|
import { HttpError } from "../http/errors.js";
|
|
3
3
|
import { providerToolCallIdentity, toolsByWireName } from "../interaction/tool_identity.js";
|
|
4
4
|
import { isAnthropicEffort } from "../interaction/provider_continuation_state.js";
|
|
5
|
-
import { isBedrockApi, isOpenAIResponsesApi } from "./model_capabilities.js";
|
|
5
|
+
import { isBedrockApi, isGoogleApi, isOpenAIResponsesApi } from "./model_capabilities.js";
|
|
6
6
|
export function piMessageToInteractionOutput(message, source, request) {
|
|
7
7
|
if (isRecord(message.providerResponse) && isOpenAIResponsesApi(source.api)) {
|
|
8
8
|
return openAIProviderResponseToInteractionOutput(message.providerResponse, message, source, request);
|
|
@@ -13,13 +13,15 @@ export function piMessageToInteractionOutput(message, source, request) {
|
|
|
13
13
|
if (content !== undefined && !Array.isArray(content))
|
|
14
14
|
throw invalidProviderOutput("content must be an array.");
|
|
15
15
|
let pendingServerToolCall = null;
|
|
16
|
+
const toolCallSignatures = {};
|
|
16
17
|
for (const block of content ?? []) {
|
|
17
18
|
if (!isRecord(block))
|
|
18
19
|
throw invalidProviderOutput("content blocks must be objects.");
|
|
19
20
|
if (block.type === "text") {
|
|
20
21
|
if (typeof block.text !== "string")
|
|
21
22
|
throw invalidProviderOutput("text content is missing text.");
|
|
22
|
-
|
|
23
|
+
// Gemini's text signatures are thought signatures, not item identity.
|
|
24
|
+
const signature = isGoogleApi(source.api) ? null : textSignature(block.textSignature);
|
|
23
25
|
items.push({
|
|
24
26
|
type: "message",
|
|
25
27
|
...(signature?.id ? { id: signature.id } : {}),
|
|
@@ -36,7 +38,11 @@ export function piMessageToInteractionOutput(message, source, request) {
|
|
|
36
38
|
continue;
|
|
37
39
|
}
|
|
38
40
|
if (block.type === "toolCall") {
|
|
39
|
-
|
|
41
|
+
const item = toolCallItem(block, source, tools);
|
|
42
|
+
items.push(item);
|
|
43
|
+
const thoughtSignature = optionalString(block.thoughtSignature);
|
|
44
|
+
if (thoughtSignature && isGoogleApi(source.api))
|
|
45
|
+
toolCallSignatures[item.callId] = thoughtSignature;
|
|
40
46
|
continue;
|
|
41
47
|
}
|
|
42
48
|
if (block.type === "serverToolCall") {
|
|
@@ -98,6 +104,18 @@ export function piMessageToInteractionOutput(message, source, request) {
|
|
|
98
104
|
}
|
|
99
105
|
throw invalidProviderOutput(`content block type '${String(block.type ?? "unknown")}' is not supported.`);
|
|
100
106
|
}
|
|
107
|
+
// Gemini rejects a replayed step whose function call lost its signature.
|
|
108
|
+
// Clients only round-trip reasoning state, so the signatures ride in one
|
|
109
|
+
// reasoning item after the calls, keeping every other item's index.
|
|
110
|
+
if (Object.keys(toolCallSignatures).length > 0) {
|
|
111
|
+
items.push({
|
|
112
|
+
type: "reasoning",
|
|
113
|
+
summary: [],
|
|
114
|
+
content: [],
|
|
115
|
+
source,
|
|
116
|
+
continuation: { kind: "google_thought_signatures", source, toolCallSignatures },
|
|
117
|
+
});
|
|
118
|
+
}
|
|
101
119
|
if (items.length === 0) {
|
|
102
120
|
items.push({
|
|
103
121
|
type: "message",
|
|
@@ -8,16 +8,16 @@ import type { ClientHarness, RouterRoleModels, RouterRolePrompts } from "../type
|
|
|
8
8
|
* default:
|
|
9
9
|
* models:
|
|
10
10
|
* - anthropic/claude-sonnet-5-5
|
|
11
|
-
* - id: openai/gpt-6.
|
|
11
|
+
* - id: openai/gpt-6.2-sol
|
|
12
12
|
* thinking: [medium, high]
|
|
13
13
|
* agentModels: # optional: a coding agent's own list
|
|
14
14
|
* codex:
|
|
15
|
-
* - openai/gpt-6.
|
|
15
|
+
* - openai/gpt-6.2-sol
|
|
16
16
|
* subscriptions: true # serve with connected Claude Code / ChatGPT plans
|
|
17
17
|
* sessionPinning: false # route each session and subagent once, then keep its model
|
|
18
18
|
* roleModels: # optional: serve an agent role one model, without routing
|
|
19
19
|
* main: anthropic/claude-fable-5-2
|
|
20
|
-
* subagent: openai/gpt-6.
|
|
20
|
+
* subagent: openai/gpt-6.2-sol
|
|
21
21
|
* rolePrompts: # optional: append to an agent role's system prompt
|
|
22
22
|
* main: Delegate codebase exploration to subagents.
|
|
23
23
|
* nativeCompaction: false # let Codex compact server-side with the provider's native compaction
|
|
@@ -36,7 +36,8 @@ import type { ClientHarness, RouterRoleModels, RouterRolePrompts } from "../type
|
|
|
36
36
|
* provider API keys from each provider's standard environment variable, and
|
|
37
37
|
* personal subscriptions from the gateway database. Model lists saved through
|
|
38
38
|
* the gateway's API (`dari gateway models`) live in the database too, and are
|
|
39
|
-
* served in place of this file's.
|
|
39
|
+
* served in place of this file's. So do router specs (parseRouterSpec), each a
|
|
40
|
+
* whole router, which are served in place of this file's router of their id.
|
|
40
41
|
*/
|
|
41
42
|
export type GatewayConfig = {
|
|
42
43
|
routers: Record<string, RouterConfig>;
|
|
@@ -65,7 +66,11 @@ export type RouterConfig = {
|
|
|
65
66
|
export type RouterModelConfig = {
|
|
66
67
|
id: string;
|
|
67
68
|
thinking?: ReasoningEffort[];
|
|
69
|
+
provider?: string;
|
|
68
70
|
};
|
|
71
|
+
/** The provider that serves a router's model, whose credential it needs. */
|
|
72
|
+
export declare function modelProvider(model: RouterModelConfig): string;
|
|
73
|
+
export declare const ROUTER_ID_PATTERN: RegExp;
|
|
69
74
|
export declare const DEFAULT_GATEWAY_CONFIG: GatewayConfig;
|
|
70
75
|
/**
|
|
71
76
|
* Load the config at `path`, which must exist. Without a path, load
|
|
@@ -81,3 +86,40 @@ export declare function allRouterModels(router: RouterConfig): RouterModelConfig
|
|
|
81
86
|
export declare const ROLE_PROMPT_MAX_LENGTH = 4000;
|
|
82
87
|
/** Read one model list of a router, naming `field` in what it rejects. */
|
|
83
88
|
export declare function parseRouterModels(routerId: string, field: string, raw: unknown): RouterModelConfig[];
|
|
89
|
+
/**
|
|
90
|
+
* A router spec: a whole router as one document, the same one hosted Dari
|
|
91
|
+
* applies (`dari router apply`), with no credentials:
|
|
92
|
+
*
|
|
93
|
+
* ```yaml
|
|
94
|
+
* name: Opus 5.5 + DeepSeek Subagents
|
|
95
|
+
* models:
|
|
96
|
+
* - anthropic/claude-opus-5-5
|
|
97
|
+
* - id: deepseek-ai/DeepSeek-V4.1-Flash-1017
|
|
98
|
+
* thinking: [high]
|
|
99
|
+
* provider: opencode-go # served by this provider, not the one its id names
|
|
100
|
+
* roles:
|
|
101
|
+
* main: { model: anthropic/claude-opus-5-5 }
|
|
102
|
+
* subagent: { model: deepseek-ai/DeepSeek-V4.1-Flash-1017, prompt: Be brief. }
|
|
103
|
+
* routing: { session_pinning: false, retries: 1 }
|
|
104
|
+
* payment: { allow: [subscription, key, credits] }
|
|
105
|
+
* native_compaction: false
|
|
106
|
+
* agents: { codex: [openai/gpt-6.1-sol] }
|
|
107
|
+
* ```
|
|
108
|
+
*
|
|
109
|
+
* The gateway pays with connected subscriptions when `payment.allow` lists
|
|
110
|
+
* `subscription`, and otherwise with provider API keys; it has no credits.
|
|
111
|
+
* `hosted` settings and a model's `fast` apply only on hosted Dari, and are
|
|
112
|
+
* accepted and left unused; `routing.rules` runs only there and is refused.
|
|
113
|
+
*/
|
|
114
|
+
export type RouterSpec = {
|
|
115
|
+
name: string;
|
|
116
|
+
router: RouterConfig;
|
|
117
|
+
};
|
|
118
|
+
/** Read a router spec's YAML (or JSON) text; YAML 1.2, so `off` stays a thinking level. */
|
|
119
|
+
export declare function parseRouterSpecText(text: string): unknown;
|
|
120
|
+
/** Check a router spec and read it as the router `id` serves it. */
|
|
121
|
+
export declare function parseRouterSpec(id: string, raw: unknown): RouterSpec;
|
|
122
|
+
/** The spec of a router, such as one from the config file. */
|
|
123
|
+
export declare function routerSpecFor(name: string, router: RouterConfig): Record<string, unknown>;
|
|
124
|
+
/** A spec as YAML text. */
|
|
125
|
+
export declare function routerSpecYaml(spec: unknown): string;
|