@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
package/src/link/assets.ts
CHANGED
|
@@ -10,6 +10,7 @@ export const DARI_MARK = `<svg class="mark" viewBox="0 0 1024 1024" aria-label="
|
|
|
10
10
|
const MARKS: Record<string, string> = {
|
|
11
11
|
anthropic: `<svg class="logo" viewBox="0 0 24 24" fill="currentColor" fill-rule="evenodd" aria-hidden="true"><path d="M13.827 3.52h3.603L24 20h-3.603l-6.57-16.48zm-7.258 0h3.767L16.906 20h-3.674l-1.343-3.461H5.017l-1.344 3.46H0L6.57 3.522zm4.132 9.959L8.453 7.687 6.205 13.48H10.7z"></path></svg>`,
|
|
12
12
|
claude: `<svg class="logo" viewBox="0 0 24 24" fill="currentColor" fill-rule="evenodd" aria-hidden="true"><path d="M4.709 15.955l4.72-2.647.08-.23-.08-.128H9.2l-.79-.048-2.698-.073-2.339-.097-2.266-.122-.571-.121L0 11.784l.055-.352.48-.321.686.06 1.52.103 2.278.158 1.652.097 2.449.255h.389l.055-.157-.134-.098-.103-.097-2.358-1.596-2.552-1.688-1.336-.972-.724-.491-.364-.462-.158-1.008.656-.722.881.06.225.061.893.686 1.908 1.476 2.491 1.833.365.304.145-.103.019-.073-.164-.274-1.355-2.446-1.446-2.49-.644-1.032-.17-.619a2.97 2.97 0 01-.104-.729L6.283.134 6.696 0l.996.134.42.364.62 1.414 1.002 2.229 1.555 3.03.456.898.243.832.091.255h.158V9.01l.128-1.706.237-2.095.23-2.695.08-.76.376-.91.747-.492.584.28.48.685-.067.444-.286 1.851-.559 2.903-.364 1.942h.212l.243-.242.985-1.306 1.652-2.064.73-.82.85-.904.547-.431h1.033l.76 1.129-.34 1.166-1.064 1.347-.881 1.142-1.264 1.7-.79 1.36.073.11.188-.02 2.856-.606 1.543-.28 1.841-.315.833.388.091.395-.328.807-1.969.486-2.309.462-3.439.813-.042.03.049.061 1.549.146.662.036h1.622l3.02.225.79.522.474.638-.079.485-1.215.62-1.64-.389-3.829-.91-1.312-.329h-.182v.11l1.093 1.068 2.006 1.81 2.509 2.33.127.578-.322.455-.34-.049-2.205-1.657-.851-.747-1.926-1.62h-.128v.17l.444.649 2.345 3.521.122 1.08-.17.353-.608.213-.668-.122-1.374-1.925-1.415-2.167-1.143-1.943-.14.08-.674 7.254-.316.37-.729.28-.607-.461-.322-.747.322-1.476.389-1.924.315-1.53.286-1.9.17-.632-.012-.042-.14.018-1.434 1.967-2.18 2.945-1.726 1.845-.414.164-.717-.37.067-.662.401-.589 2.388-3.036 1.44-1.882.93-1.086-.006-.158h-.055L4.132 18.56l-1.13.146-.487-.456.061-.746.231-.243 1.908-1.312-.006.006z"></path></svg>`,
|
|
13
|
+
gemini: `<svg class="logo" viewBox="0 0 24 24" fill="currentColor" fill-rule="evenodd" aria-hidden="true"><path d="M12 24A14.304 14.304 0 000 12 14.304 14.304 0 0012 0a14.305 14.305 0 0012 12 14.305 14.305 0 00-12 12"></path></svg>`,
|
|
13
14
|
meta: `<svg class="logo" viewBox="0 0 24 24" fill="currentColor" fill-rule="evenodd" aria-hidden="true"><path d="M6.897 4c1.915 0 3.516.932 5.43 3.376l.282-.373c.19-.246.383-.484.58-.71l.313-.35C14.588 4.788 15.792 4 17.225 4c1.273 0 2.469.557 3.491 1.516l.218.213c1.73 1.765 2.917 4.71 3.053 8.026l.011.392.002.25c0 1.501-.28 2.759-.818 3.7l-.14.23-.108.153c-.301.42-.664.758-1.086 1.009l-.265.142-.087.04a3.493 3.493 0 01-.302.118 4.117 4.117 0 01-1.33.208c-.524 0-.996-.067-1.438-.215-.614-.204-1.163-.56-1.726-1.116l-.227-.235c-.753-.812-1.534-1.976-2.493-3.586l-1.43-2.41-.544-.895-1.766 3.13-.343.592C7.597 19.156 6.227 20 4.356 20c-1.21 0-2.205-.42-2.936-1.182l-.168-.184c-.484-.573-.837-1.311-1.043-2.189l-.067-.32a8.69 8.69 0 01-.136-1.288L0 14.468c.002-.745.06-1.49.174-2.23l.1-.573c.298-1.53.828-2.958 1.536-4.157l.209-.34c1.177-1.83 2.789-3.053 4.615-3.16L6.897 4zm-.033 2.615l-.201.01c-.83.083-1.606.673-2.252 1.577l-.138.199-.01.018c-.67 1.017-1.185 2.378-1.456 3.845l-.004.022a12.591 12.591 0 00-.207 2.254l.002.188c.004.18.017.36.04.54l.043.291c.092.503.257.908.486 1.208l.117.137c.303.323.698.492 1.17.492 1.1 0 1.796-.676 3.696-3.641l2.175-3.4.454-.701-.139-.198C9.11 7.3 8.084 6.616 6.864 6.616zm10.196-.552l-.176.007c-.635.048-1.223.359-1.82.933l-.196.198c-.439.462-.887 1.064-1.367 1.807l.266.398c.18.274.362.56.55.858l.293.475 1.396 2.335.695 1.114c.583.926 1.03 1.6 1.408 2.082l.213.262c.282.326.529.54.777.673l.102.05c.227.1.457.138.718.138.176.002.35-.023.518-.073.338-.104.61-.32.813-.637l.095-.163.077-.162c.194-.459.29-1.06.29-1.785l-.006-.449c-.08-2.871-.938-5.372-2.2-6.798l-.176-.189c-.67-.683-1.444-1.074-2.27-1.074z"></path></svg>`,
|
|
14
15
|
moonshot: `<svg class="logo" viewBox="0 0 24 24" fill="currentColor" fill-rule="evenodd" aria-hidden="true"><path d="M1.052 16.916l9.539 2.552a21.007 21.007 0 00.06 2.033l5.956 1.593a11.997 11.997 0 01-5.586.865l-.18-.016-.044-.004-.084-.009-.094-.01a11.605 11.605 0 01-.157-.02l-.107-.014-.11-.016a11.962 11.962 0 01-.32-.051l-.042-.008-.075-.013-.107-.02-.07-.015-.093-.019-.075-.016-.095-.02-.097-.023-.094-.022-.068-.017-.088-.022-.09-.024-.095-.025-.082-.023-.109-.03-.062-.02-.084-.025-.093-.028-.105-.034-.058-.019-.08-.026-.09-.031-.066-.024a6.293 6.293 0 01-.044-.015l-.068-.025-.101-.037-.057-.022-.08-.03-.087-.035-.088-.035-.079-.032-.095-.04-.063-.028-.063-.027a5.655 5.655 0 01-.041-.018l-.066-.03-.103-.047-.052-.024-.096-.046-.062-.03-.084-.04-.086-.044-.093-.047-.052-.027-.103-.055-.057-.03-.058-.032a6.49 6.49 0 01-.046-.026l-.094-.053-.06-.034-.051-.03-.072-.041-.082-.05-.093-.056-.052-.032-.084-.053-.061-.039-.079-.05-.07-.047-.053-.035a7.785 7.785 0 01-.054-.036l-.044-.03-.044-.03a6.066 6.066 0 01-.04-.028l-.057-.04-.076-.054-.069-.05-.074-.054-.056-.042-.076-.057-.076-.059-.086-.067-.045-.035-.064-.052-.074-.06-.089-.073-.046-.039-.046-.039a7.516 7.516 0 01-.043-.037l-.045-.04-.061-.053-.07-.062-.068-.06-.062-.058-.067-.062-.053-.05-.088-.084a13.28 13.28 0 01-.099-.097l-.029-.028-.041-.042-.069-.07-.05-.051-.05-.053a6.457 6.457 0 01-.168-.179l-.08-.088-.062-.07-.071-.08-.042-.049-.053-.062-.058-.068-.046-.056a7.175 7.175 0 01-.027-.033l-.045-.055-.066-.082-.041-.052-.05-.064-.02-.025a11.99 11.99 0 01-1.44-2.402zm-1.02-5.794l11.353 3.037a20.468 20.468 0 00-.469 2.011l10.817 2.894a12.076 12.076 0 01-1.845 2.005L.657 15.923l-.016-.046-.035-.104a11.965 11.965 0 01-.05-.153l-.007-.023a11.896 11.896 0 01-.207-.741l-.03-.126-.018-.08-.021-.097-.018-.081-.018-.09-.017-.084-.018-.094c-.026-.141-.05-.283-.071-.426l-.017-.118-.011-.083-.013-.102a12.01 12.01 0 01-.019-.161l-.005-.047a12.12 12.12 0 01-.034-2.145zm1.593-5.15l11.948 3.196c-.368.605-.705 1.231-1.01 1.875l11.295 3.022c-.142.82-.368 1.612-.668 2.365l-11.55-3.09L.124 10.26l.015-.1.008-.049.01-.067.015-.087.018-.098c.026-.148.056-.295.088-.442l.028-.124.02-.085.024-.097c.022-.09.045-.18.07-.268l.028-.102.023-.083.03-.1.025-.082.03-.096.026-.082.031-.095a11.896 11.896 0 011.01-2.232zm4.442-4.4L17.352 4.59a20.77 20.77 0 00-1.688 1.721l7.823 2.093c.267.852.442 1.744.513 2.665L2.106 5.213l.045-.065.027-.04.04-.055.046-.065.055-.076.054-.072.064-.086.05-.065.057-.073.055-.07.06-.074.055-.069.065-.077.054-.066.066-.077.053-.06.072-.082.053-.06.067-.074.054-.058.073-.078.058-.06.063-.067.168-.17.1-.098.059-.056.076-.071a12.084 12.084 0 012.272-1.677zM12.017 0h.097l.082.001.069.001.054.002.068.002.046.001.076.003.047.002.06.003.054.002.087.005.105.007.144.011.088.007.044.004.077.008.082.008.047.005.102.012.05.006.108.014.081.01.042.006.065.01.207.032.07.012.065.011.14.026.092.018.11.022.046.01.075.016.041.01L14.7.3l.042.01.065.015.049.012.071.017.096.024.112.03.113.03.113.032.05.015.07.02.078.024.073.023.05.016.05.016.076.025.099.033.102.036.048.017.064.023.093.034.11.041.116.045.1.04.047.02.06.024.041.018.063.026.04.018.057.025.11.048.1.046.074.035.075.036.06.028.092.046.091.045.102.052.053.028.049.026.046.024.06.033.041.022.052.029.088.05.106.06.087.051.057.034.053.032.096.059.088.055.098.062.036.024.064.041.084.056.04.027.062.042.062.043.023.017c.054.037.108.075.161.114l.083.06.065.048.056.043.086.065.082.064.04.03.05.041.086.069.079.065.085.071c.712.6 1.353 1.283 1.909 2.031L7.222.994l.062-.027.065-.028.081-.034.086-.035c.113-.045.227-.09.341-.131l.096-.035.093-.033.084-.03.096-.031c.087-.03.176-.058.264-.085l.091-.027.086-.025.102-.03.085-.023.1-.026L9.04.37l.09-.023.091-.022.095-.022.09-.02.098-.021.091-.02.095-.018.092-.018.1-.018.091-.016.098-.017.092-.014.097-.015.092-.013.102-.013.091-.012.105-.012.09-.01.105-.01c.093-.01.186-.018.28-.024l.106-.008.09-.005.11-.006.093-.004.1-.004.097-.002.099-.002.197-.002z"></path></svg>`,
|
|
15
16
|
openai: `<svg class="logo" viewBox="0 0 24 24" fill="currentColor" fill-rule="evenodd" aria-hidden="true"><path d="M9.205 8.658v-2.26c0-.19.072-.333.238-.428l4.543-2.616c.619-.357 1.356-.523 2.117-.523 2.854 0 4.662 2.212 4.662 4.566 0 .167 0 .357-.024.547l-4.71-2.759a.797.797 0 00-.856 0l-5.97 3.473zm10.609 8.8V12.06c0-.333-.143-.57-.429-.737l-5.97-3.473 1.95-1.118a.433.433 0 01.476 0l4.543 2.617c1.309.76 2.189 2.378 2.189 3.948 0 1.808-1.07 3.473-2.76 4.163zM7.802 12.703l-1.95-1.142c-.167-.095-.239-.238-.239-.428V5.899c0-2.545 1.95-4.472 4.591-4.472 1 0 1.927.333 2.712.928L8.23 5.067c-.285.166-.428.404-.428.737v6.898zM12 15.128l-2.795-1.57v-3.33L12 8.658l2.795 1.57v3.33L12 15.128zm1.796 7.23c-1 0-1.927-.332-2.712-.927l4.686-2.712c.285-.166.428-.404.428-.737v-6.898l1.974 1.142c.167.095.238.238.238.428v5.233c0 2.545-1.974 4.472-4.614 4.472zm-5.637-5.303l-4.544-2.617c-1.308-.761-2.188-2.378-2.188-3.948A4.482 4.482 0 014.21 6.327v5.423c0 .333.143.571.428.738l5.947 3.449-1.95 1.118a.432.432 0 01-.476 0zm-.262 3.9c-2.688 0-4.662-2.021-4.662-4.519 0-.19.024-.38.047-.57l4.686 2.71c.286.167.571.167.856 0l5.97-3.448v2.26c0 .19-.07.333-.237.428l-4.543 2.616c-.619.357-1.356.523-2.117.523zm5.899 2.83a5.947 5.947 0 005.827-4.756C22.287 18.339 24 15.84 24 13.296c0-1.665-.713-3.282-1.998-4.448.119-.5.19-.999.19-1.498 0-3.401-2.759-5.947-5.946-5.947-.642 0-1.26.095-1.88.31A5.962 5.962 0 0010.205 0a5.947 5.947 0 00-5.827 4.757C1.713 5.447 0 7.945 0 10.49c0 1.666.713 3.283 1.998 4.448-.119.5-.19 1-.19 1.499 0 3.401 2.759 5.946 5.946 5.946.642 0 1.26-.095 1.88-.309a5.96 5.96 0 004.162 1.713z"></path></svg>`,
|
|
@@ -30,6 +31,7 @@ const MARK_FOR: Record<string, string> = {
|
|
|
30
31
|
meta: "meta",
|
|
31
32
|
moonshotai: "moonshot",
|
|
32
33
|
xai: "xai",
|
|
34
|
+
google: "gemini",
|
|
33
35
|
openrouter: "openrouter",
|
|
34
36
|
"vercel-ai-gateway": "vercel",
|
|
35
37
|
};
|
package/src/models/canonical.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import canonicalModels from "./canonical_models.json" with { type: "json" };
|
|
2
|
+
import providerModels from "./provider_models.json" with { type: "json" };
|
|
2
3
|
|
|
3
4
|
export type CanonicalModel = {
|
|
4
5
|
id: string;
|
|
@@ -14,3 +15,24 @@ export const CANONICAL_MODELS: readonly CanonicalModel[] = canonicalModels;
|
|
|
14
15
|
export function canonicalModelName(id: string): string {
|
|
15
16
|
return CANONICAL_MODELS.find((model) => model.id === id)?.name ?? id;
|
|
16
17
|
}
|
|
18
|
+
|
|
19
|
+
/** A canonical model as a provider other than the one its id names serves it. */
|
|
20
|
+
export type ProviderModel = {
|
|
21
|
+
model_id: string;
|
|
22
|
+
provider: string;
|
|
23
|
+
native_model_id: string;
|
|
24
|
+
api: string;
|
|
25
|
+
base_url: string | null;
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
const PROVIDER_MODELS: readonly ProviderModel[] = providerModels;
|
|
29
|
+
|
|
30
|
+
/** How `provider` serves a model whose id names another provider, if it does. */
|
|
31
|
+
export function providerModel(modelId: string, provider: string): ProviderModel | undefined {
|
|
32
|
+
return PROVIDER_MODELS.find((row) => row.model_id === modelId && row.provider === provider);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/** The providers besides the one its id names that serve a model. */
|
|
36
|
+
export function otherModelProviders(modelId: string): string[] {
|
|
37
|
+
return PROVIDER_MODELS.filter((row) => row.model_id === modelId).map((row) => row.provider);
|
|
38
|
+
}
|
|
@@ -1,4 +1,15 @@
|
|
|
1
1
|
[
|
|
2
|
+
{
|
|
3
|
+
"id": "openai/gpt-6.2-astra",
|
|
4
|
+
"name": "GPT-6.2 Astra",
|
|
5
|
+
"thinking_levels": [
|
|
6
|
+
"low",
|
|
7
|
+
"medium",
|
|
8
|
+
"high",
|
|
9
|
+
"xhigh",
|
|
10
|
+
"max"
|
|
11
|
+
]
|
|
12
|
+
},
|
|
2
13
|
{
|
|
3
14
|
"id": "openai/gpt-6-astra",
|
|
4
15
|
"name": "GPT-6 Astra",
|
|
@@ -22,6 +33,17 @@
|
|
|
22
33
|
"max"
|
|
23
34
|
]
|
|
24
35
|
},
|
|
36
|
+
{
|
|
37
|
+
"id": "openai/gpt-6.2-sol",
|
|
38
|
+
"name": "GPT-6.2 Sol",
|
|
39
|
+
"thinking_levels": [
|
|
40
|
+
"low",
|
|
41
|
+
"medium",
|
|
42
|
+
"high",
|
|
43
|
+
"xhigh",
|
|
44
|
+
"max"
|
|
45
|
+
]
|
|
46
|
+
},
|
|
25
47
|
{
|
|
26
48
|
"id": "openai/gpt-6.1-sol",
|
|
27
49
|
"name": "GPT-6.1 Sol",
|
|
@@ -352,5 +374,52 @@
|
|
|
352
374
|
"high",
|
|
353
375
|
"xhigh"
|
|
354
376
|
]
|
|
377
|
+
},
|
|
378
|
+
{
|
|
379
|
+
"id": "google/gemini-4-argon",
|
|
380
|
+
"name": "Gemini 4 Argon",
|
|
381
|
+
"thinking_levels": [
|
|
382
|
+
"low",
|
|
383
|
+
"medium",
|
|
384
|
+
"high"
|
|
385
|
+
]
|
|
386
|
+
},
|
|
387
|
+
{
|
|
388
|
+
"id": "google/gemini-4-carbon",
|
|
389
|
+
"name": "Gemini 4 Carbon",
|
|
390
|
+
"thinking_levels": [
|
|
391
|
+
"low",
|
|
392
|
+
"medium",
|
|
393
|
+
"high"
|
|
394
|
+
]
|
|
395
|
+
},
|
|
396
|
+
{
|
|
397
|
+
"id": "google/gemini-4-neon",
|
|
398
|
+
"name": "Gemini 4 Neon",
|
|
399
|
+
"thinking_levels": [
|
|
400
|
+
"low",
|
|
401
|
+
"medium",
|
|
402
|
+
"high",
|
|
403
|
+
"xhigh"
|
|
404
|
+
]
|
|
405
|
+
},
|
|
406
|
+
{
|
|
407
|
+
"id": "google/gemini-4-hydrogen",
|
|
408
|
+
"name": "Gemini 4 Hydrogen",
|
|
409
|
+
"thinking_levels": [
|
|
410
|
+
"low",
|
|
411
|
+
"medium",
|
|
412
|
+
"high",
|
|
413
|
+
"xhigh"
|
|
414
|
+
]
|
|
415
|
+
},
|
|
416
|
+
{
|
|
417
|
+
"id": "google/gemini-3.8-flash",
|
|
418
|
+
"name": "Gemini 3.8 Flash",
|
|
419
|
+
"thinking_levels": [
|
|
420
|
+
"low",
|
|
421
|
+
"medium",
|
|
422
|
+
"high"
|
|
423
|
+
]
|
|
355
424
|
}
|
|
356
425
|
]
|
package/src/models/catalog.ts
CHANGED
|
@@ -10,6 +10,7 @@ const PROVIDER_LABELS: Record<string, string> = {
|
|
|
10
10
|
fireworks: "Fireworks",
|
|
11
11
|
meta: "Meta",
|
|
12
12
|
xai: "xAI",
|
|
13
|
+
google: "Google",
|
|
13
14
|
"opencode-go": "OpenCode Go",
|
|
14
15
|
dari: "Dari",
|
|
15
16
|
"amazon-bedrock": "Amazon Bedrock",
|
|
@@ -34,6 +35,7 @@ const PROVIDER_BASE_URLS: Record<string, string> = {
|
|
|
34
35
|
anthropic: "https://api.anthropic.com",
|
|
35
36
|
fireworks: "https://api.fireworks.ai/inference/v1",
|
|
36
37
|
xai: "https://api.x.ai/v1",
|
|
38
|
+
google: "https://generativelanguage.googleapis.com/v1beta",
|
|
37
39
|
// A flat-rate plan for open models; each model keeps its own API path
|
|
38
40
|
// under https://opencode.ai/inference/go/, and this is chat completions.
|
|
39
41
|
"opencode-go": "https://opencode.ai/inference/go/openai/v1",
|
|
@@ -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
|
+
]
|
|
@@ -61,9 +61,20 @@ const MODEL_COMPAT_OVERRIDES: Record<string, Record<string, unknown>> = {
|
|
|
61
61
|
"openai/gpt-6-astra": {
|
|
62
62
|
supportsTemperature: false,
|
|
63
63
|
},
|
|
64
|
+
"openai/gpt-6.2-astra": {
|
|
65
|
+
supportsTemperature: false,
|
|
66
|
+
},
|
|
64
67
|
// GPT-6 Sol and Luna are newer than the installed Pi registry. They retain
|
|
65
68
|
// the GPT-5.6 Responses feature set, including explicit prompt caching and
|
|
66
69
|
// deferred tool loading. Keep this local until Pi ships their metadata.
|
|
70
|
+
"openai/gpt-6.2-sol": {
|
|
71
|
+
supportsStrictMode: true,
|
|
72
|
+
supportsOpenAIGrammarTools: true,
|
|
73
|
+
supportsAdditionalTools: true,
|
|
74
|
+
supportsToolSearch: true,
|
|
75
|
+
supportsExplicitPromptCacheMode: true,
|
|
76
|
+
supportsReasoningConfigurationUpdate: true,
|
|
77
|
+
},
|
|
67
78
|
"openai/gpt-6.1-sol": {
|
|
68
79
|
supportsStrictMode: true,
|
|
69
80
|
supportsOpenAIGrammarTools: true,
|
|
@@ -157,6 +168,7 @@ const MODEL_INPUT_OVERRIDES: Record<string, string[]> = {
|
|
|
157
168
|
"anthropic/claude-haiku-5-5": ["text", "image"],
|
|
158
169
|
"anthropic/claude-sonnet-5-5": ["text", "image"],
|
|
159
170
|
"meta/muse-ember": ["text", "image"],
|
|
171
|
+
"openai/gpt-6.2-sol": ["text", "image"],
|
|
160
172
|
"openai/gpt-6.1-sol": ["text", "image"],
|
|
161
173
|
"openai/gpt-6.1-terra": ["text", "image"],
|
|
162
174
|
"openai/gpt-6-sol": ["text", "image"],
|
|
@@ -164,6 +176,7 @@ const MODEL_INPUT_OVERRIDES: Record<string, string[]> = {
|
|
|
164
176
|
"openai/gpt-5.6-luna": ["text", "image"],
|
|
165
177
|
"openai/gpt-5.6-sol": ["text", "image"],
|
|
166
178
|
"openai/gpt-5.6-terra": ["text", "image"],
|
|
179
|
+
"openai/gpt-6.2-astra": ["text", "image"],
|
|
167
180
|
"openai/gpt-6-astra": ["text", "image"],
|
|
168
181
|
"moonshotai/Kimi-K3": ["text", "image"],
|
|
169
182
|
"deepseek-ai/DeepSeek-V4.1-Flash-1017": ["text", "image"],
|
|
@@ -86,7 +86,11 @@ export function anthropicReasoningBlock(
|
|
|
86
86
|
const encoded = item.continuation
|
|
87
87
|
? encodeProviderContinuationState(item.continuation)
|
|
88
88
|
: encodePortableReasoningState({ source: item.source, itemId: item.id });
|
|
89
|
-
|
|
89
|
+
// Gemini's signature-only state has nothing readable to show.
|
|
90
|
+
if (
|
|
91
|
+
item.continuation?.kind === "anthropic_redacted_thinking"
|
|
92
|
+
|| item.continuation?.kind === "google_thought_signatures"
|
|
93
|
+
) {
|
|
90
94
|
return { type: "redacted_thinking", data: encoded };
|
|
91
95
|
}
|
|
92
96
|
return {
|
|
@@ -228,6 +228,22 @@ export function anthropicMessagesSseStream(args: {
|
|
|
228
228
|
sendProviderError(event.message);
|
|
229
229
|
} else {
|
|
230
230
|
const output = piMessageToInteractionOutput(event.message, args.source, args.request);
|
|
231
|
+
// Content blocks stream at the provider's content indexes;
|
|
232
|
+
// Gemini's signatures follow them in one more block.
|
|
233
|
+
const signatures = output.items.at(-1);
|
|
234
|
+
if (
|
|
235
|
+
signatures?.type === "reasoning"
|
|
236
|
+
&& signatures.continuation?.kind === "google_thought_signatures"
|
|
237
|
+
&& Array.isArray(event.message.content)
|
|
238
|
+
) {
|
|
239
|
+
const index = event.message.content.length;
|
|
240
|
+
send("content_block_start", {
|
|
241
|
+
type: "content_block_start",
|
|
242
|
+
index,
|
|
243
|
+
content_block: anthropicReasoningBlock(signatures),
|
|
244
|
+
});
|
|
245
|
+
send("content_block_stop", { type: "content_block_stop", index });
|
|
246
|
+
}
|
|
231
247
|
settle({ status: "completed", message: event.message, output });
|
|
232
248
|
send("message_delta", {
|
|
233
249
|
type: "message_delta",
|
|
@@ -37,10 +37,15 @@ export function providerApiCanSerializeResponseFormat(metadata: ModelCapabilityM
|
|
|
37
37
|
metadata.model.api === "openai-responses" ||
|
|
38
38
|
metadata.model.api === "azure-openai-responses" ||
|
|
39
39
|
metadata.model.api === "openai-completions" ||
|
|
40
|
-
metadata.model.api === "anthropic-messages"
|
|
40
|
+
metadata.model.api === "anthropic-messages" ||
|
|
41
|
+
isGoogleApi(metadata.model.api)
|
|
41
42
|
);
|
|
42
43
|
}
|
|
43
44
|
|
|
45
|
+
export function isGoogleApi(api: unknown): boolean {
|
|
46
|
+
return api === "google-generative-ai" || api === "google-vertex";
|
|
47
|
+
}
|
|
48
|
+
|
|
44
49
|
export function isOpenAIResponsesApi(api: unknown): boolean {
|
|
45
50
|
return (
|
|
46
51
|
api === "openai-responses"
|
package/src/providers/pi.ts
CHANGED
|
@@ -569,6 +569,7 @@ function defaultApi(provider: string): string {
|
|
|
569
569
|
// Meta recommends Responses: its Chat Completions drops reasoning between turns.
|
|
570
570
|
if (provider === "openai" || provider === "xai" || provider === "meta") return "openai-responses";
|
|
571
571
|
if (provider === "anthropic") return "anthropic-messages";
|
|
572
|
+
if (provider === "google") return "google-generative-ai";
|
|
572
573
|
if (provider === "amazon-bedrock") return BEDROCK_API;
|
|
573
574
|
if (provider === "azure") return "azure-openai-responses";
|
|
574
575
|
return "openai-completions";
|
|
@@ -54,6 +54,7 @@ export function buildContext(
|
|
|
54
54
|
const timestamp = Date.now();
|
|
55
55
|
let pending: PiAssistant | null = null;
|
|
56
56
|
let sawConversationItem = false;
|
|
57
|
+
const thoughtSignatures = googleThoughtSignatures(request.items, target);
|
|
57
58
|
|
|
58
59
|
const flushAssistant = () => {
|
|
59
60
|
if (!pending) return;
|
|
@@ -150,7 +151,9 @@ export function buildContext(
|
|
|
150
151
|
continue;
|
|
151
152
|
}
|
|
152
153
|
if (item.type === "reasoning") {
|
|
153
|
-
const
|
|
154
|
+
const compatible = compatibleProviderContinuation(item.continuation, target);
|
|
155
|
+
// Gemini signatures are replayed on their tool calls below.
|
|
156
|
+
const continuation = compatible?.kind === "google_thought_signatures" ? null : compatible;
|
|
154
157
|
if (continuation) {
|
|
155
158
|
const assistant = assistantForReasoning(continuation.source);
|
|
156
159
|
const firstNonReasoning = assistant.content.findIndex((content) => content.type !== "thinking");
|
|
@@ -180,7 +183,12 @@ export function buildContext(
|
|
|
180
183
|
continue;
|
|
181
184
|
}
|
|
182
185
|
if (item.type === "tool_call") {
|
|
183
|
-
const
|
|
186
|
+
const thoughtSignature = thoughtSignatures.get(itemIndex);
|
|
187
|
+
// A signed call came from the target model; Pi replays its signature
|
|
188
|
+
// only on an assistant turn that model produced.
|
|
189
|
+
const assistant = thoughtSignature
|
|
190
|
+
? assistantForReasoning(target)
|
|
191
|
+
: assistantFor(pending ? identityOf(pending) : UNKNOWN_SOURCE);
|
|
184
192
|
const id = providerToolCallId(item.callId, item.id, target.api);
|
|
185
193
|
const name = toolWireName(item.namespace, item.name);
|
|
186
194
|
assistant.content.push({
|
|
@@ -188,6 +196,7 @@ export function buildContext(
|
|
|
188
196
|
id,
|
|
189
197
|
name,
|
|
190
198
|
arguments: toolArguments(item.kind, item.input),
|
|
199
|
+
...(thoughtSignature ? { thoughtSignature } : {}),
|
|
191
200
|
});
|
|
192
201
|
toolCalls.set(item.callId, { id, name });
|
|
193
202
|
continue;
|
|
@@ -282,13 +291,35 @@ export function buildContext(
|
|
|
282
291
|
return context;
|
|
283
292
|
}
|
|
284
293
|
|
|
294
|
+
// Signatures are keyed by item index, not call id: Gemini may reuse a call id
|
|
295
|
+
// in a later step, so each envelope signs only the calls of its own assistant
|
|
296
|
+
// turn (the items between the surrounding tool results and user messages).
|
|
297
|
+
function googleThoughtSignatures(items: InteractionItem[], target: ProviderIdentity): Map<number, string> {
|
|
298
|
+
const signatures = new Map<number, string>();
|
|
299
|
+
const bounds = (item: InteractionItem) =>
|
|
300
|
+
item.type === "tool_result" || (item.type === "message" && item.role !== "assistant");
|
|
301
|
+
for (const [index, item] of items.entries()) {
|
|
302
|
+
if (item.type !== "reasoning") continue;
|
|
303
|
+
const continuation = compatibleProviderContinuation(item.continuation, target);
|
|
304
|
+
if (continuation?.kind !== "google_thought_signatures") continue;
|
|
305
|
+
let start = index;
|
|
306
|
+
while (start > 0 && !bounds(items[start - 1]!)) start -= 1;
|
|
307
|
+
for (let callIndex = start; callIndex < items.length && !bounds(items[callIndex]!); callIndex += 1) {
|
|
308
|
+
const call = items[callIndex]!;
|
|
309
|
+
const signature = call.type === "tool_call" && Object.hasOwn(continuation.toolCallSignatures, call.callId) ? continuation.toolCallSignatures[call.callId] : undefined;
|
|
310
|
+
if (signature) signatures.set(callIndex, signature);
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
return signatures;
|
|
314
|
+
}
|
|
315
|
+
|
|
285
316
|
function isSentTool(tool: InteractionTool, target: ProviderIdentity): tool is Exclude<InteractionTool, { kind: "hosted" }> {
|
|
286
317
|
return tool.kind !== "hosted" && (tool.kind !== "server_tool" || target.api === "anthropic-messages");
|
|
287
318
|
}
|
|
288
319
|
|
|
289
320
|
function thinkingContent(
|
|
290
321
|
item: Extract<InteractionItem, { type: "reasoning" }>,
|
|
291
|
-
continuation: ProviderContinuationState
|
|
322
|
+
continuation: Exclude<ProviderContinuationState, { kind: "google_thought_signatures" }>
|
|
292
323
|
): Record<string, unknown> {
|
|
293
324
|
if (continuation.kind === "openai_reasoning") {
|
|
294
325
|
const providerItemId = continuation.providerItemId ?? item.id;
|
|
@@ -154,7 +154,14 @@ export function buildOptions(
|
|
|
154
154
|
// Bedrock builds its Converse toolConfig from options.toolChoice before
|
|
155
155
|
// onPayload runs, so the choice must ride on options, not a payload patch.
|
|
156
156
|
if (isBedrockApi(api)) options.toolChoice = bedrockToolChoice(toolChoice);
|
|
157
|
-
else
|
|
157
|
+
else if (isGoogle(api)) {
|
|
158
|
+
// Pi's Google transport builds functionCallingConfig from the option.
|
|
159
|
+
options.toolChoice = googleToolChoice(toolChoice);
|
|
160
|
+
if (typeof toolChoice !== "string" && toolChoice.kind !== "hosted") {
|
|
161
|
+
const name = toolWireName(toolChoice.namespace, toolChoice.name);
|
|
162
|
+
patches.push((payload) => payloadWithGoogleAllowedFunction(payload, name));
|
|
163
|
+
}
|
|
164
|
+
} else patches.push((payload) => ({ ...payload, tool_choice: providerToolChoice(toolChoice, api) }));
|
|
158
165
|
}
|
|
159
166
|
if (request.tools.some((tool) => tool.kind === "function" && (tool.strict !== undefined || isAnthropic(api)))) {
|
|
160
167
|
patches.push((payload) => payloadWithStrictTools(payload, request, api));
|
|
@@ -191,6 +198,7 @@ export function buildOptions(
|
|
|
191
198
|
patches.push(payloadWithoutReasoningEffort);
|
|
192
199
|
}
|
|
193
200
|
if (isOpenAIResponsesApi(api)) patches.push(payloadWithDetailedReasoningSummary);
|
|
201
|
+
if (isGoogle(api)) patches.push(payloadWithGoogleThoughtSignatures);
|
|
194
202
|
|
|
195
203
|
// Some clients send the default tool_choice even after omitting tools for
|
|
196
204
|
// a turn. OpenAI rejects every tool_choice value when the lowered payload
|
|
@@ -401,6 +409,10 @@ function payloadWithResponseFormat(payload: Payload, format: InteractionResponse
|
|
|
401
409
|
const schema = format.type === "json_schema" ? format.schema : { type: "object" };
|
|
402
410
|
return { ...payload, output_config: { ...asRecord(payload.output_config), format: { type: "json_schema", schema } } };
|
|
403
411
|
}
|
|
412
|
+
if (isGoogle(api)) {
|
|
413
|
+
const config = { ...asRecord(payload.config), responseMimeType: "application/json" };
|
|
414
|
+
return { ...payload, config: format.type === "json_schema" ? { ...config, responseJsonSchema: format.schema } : config };
|
|
415
|
+
}
|
|
404
416
|
if (format.type === "json_object") {
|
|
405
417
|
if (isResponses(api)) return { ...payload, text: { ...asRecord(payload.text), format } };
|
|
406
418
|
if (isCompletions(api)) return { ...payload, response_format: format };
|
|
@@ -418,6 +430,44 @@ function bedrockToolChoice(choice: InteractionToolChoice): unknown {
|
|
|
418
430
|
return { type: "function", function: { name: toolWireName(choice.namespace, choice.name) } };
|
|
419
431
|
}
|
|
420
432
|
|
|
433
|
+
function googleToolChoice(choice: InteractionToolChoice): "auto" | "none" | "any" | undefined {
|
|
434
|
+
if (typeof choice === "string") return choice === "auto" || choice === "none" ? choice : "any";
|
|
435
|
+
return choice.kind === "hosted" ? undefined : "any";
|
|
436
|
+
}
|
|
437
|
+
|
|
438
|
+
function payloadWithGoogleAllowedFunction(payload: Payload, name: string): Payload {
|
|
439
|
+
const config = asRecord(payload.config);
|
|
440
|
+
const toolConfig = asRecord(config.toolConfig);
|
|
441
|
+
const functionCallingConfig = { ...asRecord(toolConfig.functionCallingConfig), allowedFunctionNames: [name] };
|
|
442
|
+
return { ...payload, config: { ...config, toolConfig: { ...toolConfig, functionCallingConfig } } };
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
// Gemini rejects a step whose first function call has no thought signature.
|
|
446
|
+
// Calls another model made, or whose signature the client dropped, carry
|
|
447
|
+
// Google's documented placeholder that skips the check.
|
|
448
|
+
const GOOGLE_SKIP_THOUGHT_SIGNATURE = "skip_thought_signature_validator";
|
|
449
|
+
|
|
450
|
+
function payloadWithGoogleThoughtSignatures(payload: Payload): Payload | undefined {
|
|
451
|
+
if (!Array.isArray(payload.contents)) return undefined;
|
|
452
|
+
let changed = false;
|
|
453
|
+
const contents = payload.contents.map((content) => {
|
|
454
|
+
if (!isRecord(content) || content.role !== "model" || !Array.isArray(content.parts)) return content;
|
|
455
|
+
const parts = content.parts;
|
|
456
|
+
// Gemini validates the first call of each step, so that call needs a
|
|
457
|
+
// signature even when a later call in the same turn carries one.
|
|
458
|
+
const first = parts.findIndex((part) => isRecord(part) && isRecord(part.functionCall));
|
|
459
|
+
if (first === -1 || asRecord(parts[first]).thoughtSignature) return content;
|
|
460
|
+
changed = true;
|
|
461
|
+
return {
|
|
462
|
+
...content,
|
|
463
|
+
parts: parts.map((part, index) =>
|
|
464
|
+
index === first ? { ...asRecord(part), thoughtSignature: GOOGLE_SKIP_THOUGHT_SIGNATURE } : part
|
|
465
|
+
),
|
|
466
|
+
};
|
|
467
|
+
});
|
|
468
|
+
return changed ? { ...payload, contents } : undefined;
|
|
469
|
+
}
|
|
470
|
+
|
|
421
471
|
function providerToolChoice(choice: InteractionToolChoice, api: unknown): unknown {
|
|
422
472
|
if (typeof choice === "string") {
|
|
423
473
|
if (isAnthropic(api)) return { type: choice === "required" ? "any" : choice };
|
|
@@ -3,7 +3,7 @@ import { isRecord } from "@mupt-ai/dari-router/policy-engine";
|
|
|
3
3
|
import { HttpError } from "../http/errors.js";
|
|
4
4
|
import { providerToolCallIdentity, toolsByWireName } from "../interaction/tool_identity.js";
|
|
5
5
|
import { isAnthropicEffort } from "../interaction/provider_continuation_state.js";
|
|
6
|
-
import { isBedrockApi, isOpenAIResponsesApi } from "./model_capabilities.js";
|
|
6
|
+
import { isBedrockApi, isGoogleApi, isOpenAIResponsesApi } from "./model_capabilities.js";
|
|
7
7
|
import type {
|
|
8
8
|
InteractionItem,
|
|
9
9
|
InteractionOutput,
|
|
@@ -29,11 +29,13 @@ export function piMessageToInteractionOutput(
|
|
|
29
29
|
if (content !== undefined && !Array.isArray(content)) throw invalidProviderOutput("content must be an array.");
|
|
30
30
|
|
|
31
31
|
let pendingServerToolCall: { id: string; name: string; input: Record<string, unknown> } | null = null;
|
|
32
|
+
const toolCallSignatures: Record<string, string> = {};
|
|
32
33
|
for (const block of content ?? []) {
|
|
33
34
|
if (!isRecord(block)) throw invalidProviderOutput("content blocks must be objects.");
|
|
34
35
|
if (block.type === "text") {
|
|
35
36
|
if (typeof block.text !== "string") throw invalidProviderOutput("text content is missing text.");
|
|
36
|
-
|
|
37
|
+
// Gemini's text signatures are thought signatures, not item identity.
|
|
38
|
+
const signature = isGoogleApi(source.api) ? null : textSignature(block.textSignature);
|
|
37
39
|
items.push({
|
|
38
40
|
type: "message",
|
|
39
41
|
...(signature?.id ? { id: signature.id } : {}),
|
|
@@ -50,7 +52,10 @@ export function piMessageToInteractionOutput(
|
|
|
50
52
|
continue;
|
|
51
53
|
}
|
|
52
54
|
if (block.type === "toolCall") {
|
|
53
|
-
|
|
55
|
+
const item = toolCallItem(block, source, tools);
|
|
56
|
+
items.push(item);
|
|
57
|
+
const thoughtSignature = optionalString(block.thoughtSignature);
|
|
58
|
+
if (thoughtSignature && isGoogleApi(source.api)) toolCallSignatures[item.callId] = thoughtSignature;
|
|
54
59
|
continue;
|
|
55
60
|
}
|
|
56
61
|
if (block.type === "serverToolCall") {
|
|
@@ -114,6 +119,19 @@ export function piMessageToInteractionOutput(
|
|
|
114
119
|
throw invalidProviderOutput(`content block type '${String(block.type ?? "unknown")}' is not supported.`);
|
|
115
120
|
}
|
|
116
121
|
|
|
122
|
+
// Gemini rejects a replayed step whose function call lost its signature.
|
|
123
|
+
// Clients only round-trip reasoning state, so the signatures ride in one
|
|
124
|
+
// reasoning item after the calls, keeping every other item's index.
|
|
125
|
+
if (Object.keys(toolCallSignatures).length > 0) {
|
|
126
|
+
items.push({
|
|
127
|
+
type: "reasoning",
|
|
128
|
+
summary: [],
|
|
129
|
+
content: [],
|
|
130
|
+
source,
|
|
131
|
+
continuation: { kind: "google_thought_signatures", source, toolCallSignatures },
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
|
|
117
135
|
if (items.length === 0) {
|
|
118
136
|
items.push({
|
|
119
137
|
type: "message",
|