@desplega.ai/agent-swarm 2.13.2 → 2.13.3
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/acp-adapter-t2q6nsqv.js +17 -0
- package/dist/{acp-targets-mz8c5dnt.js → acp-targets-k8xs4tj8.js} +7 -7
- package/dist/{actions-5ft3qp5a.js → actions-pg5fxjer.js} +23 -23
- package/dist/{agent-fs-provision-6fgz7wvz.js → agent-fs-provision-vbk3fppw.js} +4 -4
- package/dist/{amp-adapter-nthn8ezm.js → amp-adapter-adbhxsz9.js} +2 -2
- package/dist/{app-535m78qw.js → app-b267ggx1.js} +6 -6
- package/dist/{approval-notifications-dewbk403.js → approval-notifications-evc1a9z5.js} +7 -7
- package/dist/{assistant-39zyabv2.js → assistant-wgz2ab84.js} +24 -24
- package/dist/{boot-args-schema-bqv5bf77.js → boot-args-schema-6tpk28j4.js} +1 -1
- package/dist/{boot-reembed-fas7z3zn.js → boot-reembed-ankp369c.js} +1 -1
- package/dist/{boot-reembed-157c0gcz.js → boot-reembed-r1zyvefv.js} +1 -1
- package/dist/{boot-scrub-sweep-tmec0be2.js → boot-scrub-sweep-cgb6r5bd.js} +2 -2
- package/dist/{boot-seeds-32zm50x2.js → boot-seeds-bjceqg7b.js} +4 -4
- package/dist/{claude-adapter-gwq7x2nj.js → claude-adapter-knztdnff.js} +9 -6
- package/dist/{claude-managed-adapter-rkvw6fvq.js → claude-managed-adapter-qwejzqkk.js} +2 -2
- package/dist/{claude-sdk-session-5wbwxy8c.js → claude-sdk-session-c3g6dv0g.js} +22 -8
- package/dist/{cli-cs26ed89.js → cli-0j4qmc80.js} +7 -7
- package/dist/{cli-dnvmwsvc.js → cli-1606qw3n.js} +32 -32
- package/dist/{cli-b0kqw55g.js → cli-1gnf5c7x.js} +1 -1
- package/dist/{cli-31vt7baf.js → cli-1wew39p0.js} +10 -10
- package/dist/{cli-tceqvv6h.js → cli-268b3dgn.js} +2 -2
- package/dist/cli-2ap1the6.js +11 -0
- package/dist/{cli-e87fg3en.js → cli-4dyhzhpx.js} +1 -1
- package/dist/{cli-t9nxq30h.js → cli-55fqpd9q.js} +8 -8
- package/dist/{cli-nvqq3232.js → cli-61fzwtjk.js} +7 -7
- package/dist/{cli-c9bwawf9.js → cli-61p7ty8d.js} +2 -2
- package/dist/{cli-d528acsw.js → cli-7fa6yv98.js} +2 -2
- package/dist/{cli-bp2rt28p.js → cli-7kv5d674.js} +3 -3
- package/dist/{cli-tbdw3f92.js → cli-80d5g0fa.js} +2 -2
- package/dist/{cli-0xwb7zpt.js → cli-88np9va3.js} +1 -1
- package/dist/{cli-zm6bkx3e.js → cli-8m6gqnf1.js} +2 -2
- package/dist/{cli-r4fphq38.js → cli-8pnawt98.js} +3 -3
- package/dist/{cli-xerdrnqs.js → cli-8sayvj48.js} +2 -2
- package/dist/{cli-d0jb2qnt.js → cli-9gmkw6xn.js} +53 -32
- package/dist/{cli-a6rzw649.js → cli-a21cwm89.js} +2 -2
- package/dist/{cli-s6fhqbz1.js → cli-aytna2fm.js} +1 -1
- package/dist/{cli-mwxez0pz.js → cli-b768ek79.js} +1 -1
- package/dist/{cli-ewb028rs.js → cli-bh53ppqm.js} +2 -2
- package/dist/{cli-zqy28rwx.js → cli-czeh7x13.js} +3 -3
- package/dist/{cli-s08zsqva.js → cli-djwt4mtn.js} +71 -5
- package/dist/{cli-fgm2mad9.js → cli-dq30fq3q.js} +2 -2
- package/dist/{cli-2wde56gv.js → cli-dw43pnzp.js} +5 -5
- package/dist/{cli-erh1rgh4.js → cli-e4gx499y.js} +12 -12
- package/dist/{cli-69eq6gdk.js → cli-ea367bdn.js} +31 -22
- package/dist/{cli-cmgdptmx.js → cli-ef590376.js} +29 -5
- package/dist/{cli-8qvte9hn.js → cli-fbmgpt72.js} +2 -2
- package/dist/{cli-tgmate57.js → cli-g4dhd3pr.js} +2 -2
- package/dist/{cli-0f7n3td3.js → cli-gc715jrc.js} +1 -1
- package/dist/{cli-xysy1g8x.js → cli-gkjw33x5.js} +1 -1
- package/dist/{cli-getrvmtx.js → cli-grk77aen.js} +1 -1
- package/dist/{cli-f1sdh8ca.js → cli-gxqwm3k3.js} +5 -5
- package/dist/{cli-m1wddksc.js → cli-h3drhntp.js} +1 -1
- package/dist/{cli-qn79645p.js → cli-h9d3sdnc.js} +1 -1
- package/dist/{cli-7m6bbtab.js → cli-hd2a204w.js} +6 -6
- package/dist/{cli-jkkcm72j.js → cli-hhb8kbwd.js} +9 -9
- package/dist/{cli-fcwrd7bh.js → cli-hpxcfvdm.js} +3 -3
- package/dist/{cli-ka13xx6b.js → cli-hxj888w3.js} +1 -1
- package/dist/{cli-82j36f2m.js → cli-jjzxsk47.js} +9 -3
- package/dist/{cli-nkfv398a.js → cli-ka4tqjzd.js} +6 -6
- package/dist/{cli-n46d87mj.js → cli-kh973792.js} +3 -3
- package/dist/{cli-x5yb8zc8.js → cli-kwm1bek7.js} +1 -1
- package/dist/{cli-5k1hvycs.js → cli-mgr3gatr.js} +4 -4
- package/dist/{cli-8a4qg44m.js → cli-nbawx3s0.js} +2 -2
- package/dist/{cli-1gevjrc1.js → cli-ppf9ap9n.js} +1 -1
- package/dist/{cli-6rmryz03.js → cli-pzsedyb0.js} +4 -4
- package/dist/{cli-g0b3ma7r.js → cli-r6xnchva.js} +1 -1
- package/dist/{cli-j2ybkdk2.js → cli-snwz16eg.js} +1 -1
- package/dist/{cli-sjk85d7v.js → cli-sy2ge2ye.js} +3 -3
- package/dist/{cli-rvhaahfv.js → cli-syqcny89.js} +3 -3
- package/dist/{cli-n14r8h4n.js → cli-tjf1bh1v.js} +2 -2
- package/dist/{cli-xhkek467.js → cli-v1v49t36.js} +28 -2
- package/dist/{cli-4djg31jh.js → cli-v8rpjrnx.js} +1 -1
- package/dist/{cli-62fjschk.js → cli-vgh5adn9.js} +5 -5
- package/dist/{cli-wdtqkqnq.js → cli-w24741sm.js} +3 -3
- package/dist/{cli-gq6qhmrr.js → cli-wsnradtk.js} +3 -3
- package/dist/{cli-gc7jkf4a.js → cli-wtffytm8.js} +3 -3
- package/dist/{cli-1f48qdnb.js → cli-xc8m5cjn.js} +2 -2
- package/dist/{cli-x7aqhxj5.js → cli-y0q92v4r.js} +2 -2
- package/dist/{cli-gedf48yw.js → cli-y754psdt.js} +4 -4
- package/dist/cli.js +14 -14
- package/dist/{codex-adapter-x25xfbnh.js → codex-adapter-493vb8cv.js} +5 -5
- package/dist/{codex-hook-c0nvm30r.js → codex-hook-ej8hn6z5.js} +9 -2
- package/dist/{codex-session-runner-kn5xnrvp.js → codex-session-runner-ps5m4z1g.js} +5 -5
- package/dist/{commands-8n59gxmy.js → commands-shktk0b8.js} +3 -3
- package/dist/{controllers-connect-09gvkrhc.js → controllers-connect-yft057ws.js} +22 -22
- package/dist/{core-2b8bv6ny.js → core-nheayfgm.js} +21 -21
- package/dist/{cursor-adapter-w1681kp1.js → cursor-adapter-8fpm4dng.js} +1 -1
- package/dist/{db-e71keqxk.js → db-0ezhdhz5.js} +3 -3
- package/dist/{db-spg81qtr.js → db-84pz2w5c.js} +2 -2
- package/dist/{dispatcher-fr4vawwb.js → dispatcher-h2rz69f6.js} +21 -21
- package/dist/{easter-egg-3d-ac9tv9a6.js → easter-egg-3d-m41ad78v.js} +1 -1
- package/dist/{embedding-space-an77f45k.js → embedding-space-yam9zwzj.js} +6 -6
- package/dist/{embeddings-jkrehejr.js → embeddings-g2be0y8q.js} +1 -1
- package/dist/{execute-3mys4nta.js → execute-hhdejgzf.js} +1 -1
- package/dist/{external-channel-s6zxpts9.js → external-channel-kjt2yzfj.js} +2 -2
- package/dist/fx-adapter-8g7xsp8q.js +20 -0
- package/dist/{grok-adapter-8ge6tw7m.js → grok-adapter-ztk2zkz1.js} +9 -9
- package/dist/handlers-9ywssz71.js +41 -0
- package/dist/{heartbeat-jjpb44e5.js → heartbeat-2e5jdexj.js} +23 -23
- package/dist/{hook-y6n23zzj.js → hook-34s8cmgn.js} +9 -6
- package/dist/{hook-68gbs87k.js → hook-acg9saz7.js} +8 -5
- package/dist/{http-8c6y008s.js → http-ra2zr2f8.js} +58 -65
- package/dist/{index-xcw7hjt5.js → index-2z1z7qx6.js} +24 -24
- package/dist/{index-p2f5xg64.js → index-3j803vnb.js} +36259 -34299
- package/dist/index-6mgbdtv1.js +44 -0
- package/dist/{index-6h3r0vpe.js → index-93bw5wds.js} +1 -1
- package/dist/{index-we3nd2t0.js → index-9q42cr54.js} +1 -1
- package/dist/{index-0vthtbc2.js → index-9r4j0a60.js} +23 -15
- package/dist/index-hqdsn2t2.js +39 -0
- package/dist/index-st231bqv.js +40 -0
- package/dist/{keepalive-7e9r5dvp.js → keepalive-vjnnqbkm.js} +4 -4
- package/dist/lead-mk0xkth2.js +82 -0
- package/dist/{maintenance-d3erjvcg.js → maintenance-px2g599e.js} +1 -1
- package/dist/{oauth-refresh-sweep-0qh70988.js → oauth-refresh-sweep-nkykf09m.js} +3 -3
- package/dist/{object-webhooks-ac7v2q5p.js → object-webhooks-gt9xnq21.js} +7 -7
- package/dist/{onboard-5yphtken.js → onboard-1f134p65.js} +3 -3
- package/dist/{opencode-adapter-0xvyba4m.js → opencode-adapter-94976yab.js} +6 -6
- package/dist/{otel-impl-svqp691q.js → otel-impl-5d4p2fqs.js} +1 -1
- package/dist/{pending-bn4xe5br.js → pending-vkk0vx6n.js} +22 -22
- package/dist/{pi-mono-adapter-763s8a3w.js → pi-mono-adapter-cyzdv5er.js} +8 -8
- package/dist/{pricing-refresh-kfc215mf.js → pricing-refresh-jtmjwss9.js} +2 -2
- package/dist/{rbac-roles-6r4h2ghj.js → rbac-roles-1fvmdyeb.js} +2 -2
- package/dist/{rbac-roles-3bznvkpt.js → rbac-roles-yd1fgpsn.js} +3 -3
- package/dist/{render-v2-f3qedbpy.js → render-v2-kb5s3vx4.js} +6 -6
- package/dist/{resume-vcag4ann.js → resume-z1vs44n5.js} +9 -9
- package/dist/{runtime-x0s55z2t.js → runtime-gk6ct7r7.js} +1 -1
- package/dist/{session-access-nwzve8q2.js → session-access-nz6nre4d.js} +5 -5
- package/dist/{session-source-backfill-jpqfzmgz.js → session-source-backfill-wb60zjkd.js} +1 -1
- package/dist/{setup-d2smwaem.js → setup-2x8g8j4s.js} +1 -1
- package/dist/thread-buffer-d50rqpev.js +42 -0
- package/dist/{tree-visibility-dwzc8en0.js → tree-visibility-ts3z30kw.js} +2 -2
- package/dist/{user-merge-jobs-4ce7kma2.js → user-merge-jobs-zetg26e0.js} +3 -3
- package/dist/{virtual-modules-78a6yw71.js → virtual-modules-674fka8x.js} +3 -3
- package/dist/{work-objects-m0w1e7q8.js → work-objects-w52yyjxm.js} +24 -24
- package/dist/worker-662x1vse.js +82 -0
- package/dist/{worker-follow-up-e3t6f895.js → worker-follow-up-dyfxyjbj.js} +21 -21
- package/openapi.json +4 -1
- package/package.json +3 -3
- package/src/commands/onboard/agent-fs-version.ts +1 -1
- package/src/commands/runner.ts +62 -6
- package/src/hooks/codex-hook.ts +15 -4
- package/src/hooks/hook.ts +7 -0
- package/src/http/session-cost-recompute.ts +3 -1
- package/src/http/session-data.ts +3 -0
- package/src/prompts/base-prompt.ts +1 -1
- package/src/prompts/session-templates.ts +1 -1
- package/src/providers/acp-targets.ts +2 -2
- package/src/providers/amp-adapter.ts +1 -1
- package/src/providers/claude-adapter.ts +21 -1
- package/src/providers/claude-sdk-session.ts +22 -3
- package/src/providers/claude-session-events.ts +76 -1
- package/src/providers/cursor-adapter.ts +1 -1
- package/src/providers/fx-adapter.ts +2 -2
- package/src/providers/pricing-sources.md +3 -0
- package/src/providers/types.ts +13 -0
- package/src/slack/render-v2.ts +27 -7
- package/src/tests/base-prompt.test.ts +6 -2
- package/src/tests/claude-adapter.test.ts +115 -0
- package/src/tests/fixtures/fx/acp-updates-recorded.jsonl +1 -1
- package/src/tests/internal-ai/complete-structured.test.ts +105 -0
- package/src/tests/internal-ai/credentials.test.ts +149 -0
- package/src/tests/internal-ai/task-title.test.ts +78 -0
- package/src/tests/mcp-input-caps.test.ts +16 -11
- package/src/tests/runner-slot-reconcile.test.ts +102 -0
- package/src/tests/slack-render-v2.test.ts +85 -0
- package/src/types.ts +2 -1
- package/src/utils/internal-ai/complete-structured.ts +36 -5
- package/src/utils/internal-ai/credentials.ts +78 -2
- package/src/utils/internal-ai/models.ts +37 -1
- package/src/utils/internal-ai/task-title.ts +31 -1
- package/templates/skills/swarm-docs/content.md +8 -0
- package/dist/acp-adapter-x1qqgzwx.js +0 -17
- package/dist/fx-adapter-4yet1c4f.js +0 -20
- package/dist/handlers-0r9evrdj.js +0 -41
- package/dist/index-1v23363p.js +0 -39
- package/dist/index-30qw6vyw.js +0 -44
- package/dist/index-6bm3w6cn.js +0 -40
- package/dist/lead-3jpc7kcr.js +0 -79
- package/dist/thread-buffer-8fc703jc.js +0 -42
- package/dist/worker-3p2vq107.js +0 -79
|
@@ -393,3 +393,152 @@ describe("resolveCredentials", () => {
|
|
|
393
393
|
expect(probed).toBe(2);
|
|
394
394
|
});
|
|
395
395
|
});
|
|
396
|
+
|
|
397
|
+
describe("fireworks", () => {
|
|
398
|
+
test("FIREWORKS_API_KEY resolves through env and through pi-ai's key lookup", async () => {
|
|
399
|
+
for (const source of ["env", "fallback"] as const) {
|
|
400
|
+
const cred = await resolveCredential(
|
|
401
|
+
makeOpts({
|
|
402
|
+
env: source === "env" ? { FIREWORKS_API_KEY: "fw-key" } : {},
|
|
403
|
+
_getEnvApiKey: (provider) =>
|
|
404
|
+
source === "fallback" && provider === "fireworks" ? "fw-key" : undefined,
|
|
405
|
+
}),
|
|
406
|
+
);
|
|
407
|
+
expect(cred?.kind).toBe("fireworks");
|
|
408
|
+
if (cred?.kind === "fireworks") {
|
|
409
|
+
expect(cred.apiKey).toBe("fw-key");
|
|
410
|
+
expect(cred.modelDefault).toBe("fireworks/accounts/fireworks/models/deepseek-v4p1-flash");
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
});
|
|
414
|
+
|
|
415
|
+
test("a comma-separated pool picks one member, never the joined string", async () => {
|
|
416
|
+
const cred = await resolveCredential(
|
|
417
|
+
makeOpts({ env: { FIREWORKS_API_KEY: "fw-first, fw-second" } }),
|
|
418
|
+
);
|
|
419
|
+
expect(cred?.kind).toBe("fireworks");
|
|
420
|
+
if (cred?.kind === "fireworks") {
|
|
421
|
+
expect(["fw-first", "fw-second"]).toContain(cred.apiKey);
|
|
422
|
+
}
|
|
423
|
+
});
|
|
424
|
+
|
|
425
|
+
test("FIREWORKS_API_KEY does not outrank a key an operator set for this layer", async () => {
|
|
426
|
+
// Precedence decision: existing callers keep their provider.
|
|
427
|
+
for (const earlier of ["OPENROUTER_API_KEY", "ANTHROPIC_API_KEY", "OPENAI_API_KEY"]) {
|
|
428
|
+
const cred = await resolveCredential(
|
|
429
|
+
makeOpts({ env: { FIREWORKS_API_KEY: "fw", [earlier]: "earlier-key" } }),
|
|
430
|
+
);
|
|
431
|
+
expect(cred?.kind).not.toBe("fireworks");
|
|
432
|
+
}
|
|
433
|
+
const only = await resolveCredential(makeOpts({ env: { FIREWORKS_API_KEY: "fw" } }));
|
|
434
|
+
expect(only?.kind).toBe("fireworks");
|
|
435
|
+
});
|
|
436
|
+
});
|
|
437
|
+
|
|
438
|
+
describe("amazon-bedrock", () => {
|
|
439
|
+
/** pi-ai's `getEnvApiKey` answers the sentinel when the AWS chain is configured. */
|
|
440
|
+
const awsChain = (provider: string) =>
|
|
441
|
+
provider === "amazon-bedrock" ? "<authenticated>" : undefined;
|
|
442
|
+
|
|
443
|
+
test("resolves from the credential chain plus a region, with no apiKey field", async () => {
|
|
444
|
+
const cred = await resolveCredential(
|
|
445
|
+
makeOpts({
|
|
446
|
+
env: { AWS_PROFILE: "example-profile", AWS_REGION: "eu-west-1" },
|
|
447
|
+
_getEnvApiKey: awsChain,
|
|
448
|
+
}),
|
|
449
|
+
);
|
|
450
|
+
expect(cred).toEqual({
|
|
451
|
+
kind: "amazon-bedrock",
|
|
452
|
+
modelDefault: "amazon-bedrock/global.anthropic.claude-haiku-5-5",
|
|
453
|
+
region: "eu-west-1",
|
|
454
|
+
});
|
|
455
|
+
// The shape is the design decision: there is no apiKey to fabricate.
|
|
456
|
+
expect(cred && "apiKey" in cred).toBe(false);
|
|
457
|
+
});
|
|
458
|
+
|
|
459
|
+
test("AWS_DEFAULT_REGION is accepted when AWS_REGION is unset", async () => {
|
|
460
|
+
const cred = await resolveCredential(
|
|
461
|
+
makeOpts({
|
|
462
|
+
env: { AWS_PROFILE: "p", AWS_DEFAULT_REGION: "us-west-2" },
|
|
463
|
+
_getEnvApiKey: awsChain,
|
|
464
|
+
}),
|
|
465
|
+
);
|
|
466
|
+
expect(cred?.kind).toBe("amazon-bedrock");
|
|
467
|
+
if (cred?.kind === "amazon-bedrock") expect(cred.region).toBe("us-west-2");
|
|
468
|
+
});
|
|
469
|
+
|
|
470
|
+
test("an empty or blank AWS_REGION falls back to AWS_DEFAULT_REGION", async () => {
|
|
471
|
+
// A compose file writes `AWS_REGION=${AWS_REGION:-}`, which sets the var to
|
|
472
|
+
// an empty string. `??` would keep that and discard the real region, and
|
|
473
|
+
// Bedrock would be skipped despite a valid AWS_DEFAULT_REGION.
|
|
474
|
+
for (const blank of ["", " "]) {
|
|
475
|
+
const cred = await resolveCredential(
|
|
476
|
+
makeOpts({
|
|
477
|
+
env: { AWS_PROFILE: "p", AWS_REGION: blank, AWS_DEFAULT_REGION: "eu-west-1" },
|
|
478
|
+
_getEnvApiKey: awsChain,
|
|
479
|
+
}),
|
|
480
|
+
);
|
|
481
|
+
expect(cred?.kind).toBe("amazon-bedrock");
|
|
482
|
+
if (cred?.kind === "amazon-bedrock") expect(cred.region).toBe("eu-west-1");
|
|
483
|
+
}
|
|
484
|
+
});
|
|
485
|
+
|
|
486
|
+
test("no region → clean no-op rather than a guessed us-east-1", async () => {
|
|
487
|
+
const cred = await resolveCredential(
|
|
488
|
+
makeOpts({ env: { AWS_PROFILE: "p" }, _getEnvApiKey: awsChain }),
|
|
489
|
+
);
|
|
490
|
+
expect(cred).toBeNull();
|
|
491
|
+
});
|
|
492
|
+
|
|
493
|
+
test("no credential chain → clean no-op even with a region", async () => {
|
|
494
|
+
expect(await resolveCredential(makeOpts({ env: { AWS_REGION: "us-east-1" } }))).toBeNull();
|
|
495
|
+
});
|
|
496
|
+
|
|
497
|
+
test("region whitespace alone is not a region", async () => {
|
|
498
|
+
const cred = await resolveCredential(
|
|
499
|
+
makeOpts({ env: { AWS_PROFILE: "p", AWS_REGION: " " }, _getEnvApiKey: awsChain }),
|
|
500
|
+
);
|
|
501
|
+
expect(cred).toBeNull();
|
|
502
|
+
});
|
|
503
|
+
|
|
504
|
+
test("sits after fireworks and after every key-based kind", async () => {
|
|
505
|
+
const withKeys = await resolveCredentials(
|
|
506
|
+
makeOpts({
|
|
507
|
+
env: {
|
|
508
|
+
OPENROUTER_API_KEY: "or",
|
|
509
|
+
FIREWORKS_API_KEY: "fw",
|
|
510
|
+
AWS_PROFILE: "p",
|
|
511
|
+
AWS_REGION: "us-east-1",
|
|
512
|
+
},
|
|
513
|
+
_getEnvApiKey: awsChain,
|
|
514
|
+
}),
|
|
515
|
+
);
|
|
516
|
+
expect(withKeys.map((cred) => cred.kind)).toEqual([
|
|
517
|
+
"openrouter",
|
|
518
|
+
"fireworks",
|
|
519
|
+
"amazon-bedrock",
|
|
520
|
+
]);
|
|
521
|
+
|
|
522
|
+
const ambientOnly = await resolveCredentials(
|
|
523
|
+
makeOpts({
|
|
524
|
+
env: { AWS_PROFILE: "p", AWS_REGION: "us-east-1" },
|
|
525
|
+
_getEnvApiKey: awsChain,
|
|
526
|
+
}),
|
|
527
|
+
);
|
|
528
|
+
expect(ambientOnly.map((cred) => cred.kind)).toEqual(["amazon-bedrock"]);
|
|
529
|
+
});
|
|
530
|
+
|
|
531
|
+
test("a pinned rater model applies to the bedrock credential too", async () => {
|
|
532
|
+
const saved = process.env.MEMORY_RATER_MODEL;
|
|
533
|
+
process.env.MEMORY_RATER_MODEL = "amazon-bedrock/us.anthropic.claude-haiku-5-5";
|
|
534
|
+
try {
|
|
535
|
+
const cred = await resolveCredential(
|
|
536
|
+
makeOpts({ env: { AWS_PROFILE: "p", AWS_REGION: "us-east-1" }, _getEnvApiKey: awsChain }),
|
|
537
|
+
);
|
|
538
|
+
expect(cred?.modelDefault).toBe("amazon-bedrock/us.anthropic.claude-haiku-5-5");
|
|
539
|
+
} finally {
|
|
540
|
+
if (saved === undefined) delete process.env.MEMORY_RATER_MODEL;
|
|
541
|
+
else process.env.MEMORY_RATER_MODEL = saved;
|
|
542
|
+
}
|
|
543
|
+
});
|
|
544
|
+
});
|
|
@@ -1,10 +1,16 @@
|
|
|
1
1
|
import { describe, expect, test } from "bun:test";
|
|
2
|
+
import { getBuiltinModel } from "@earendil-works/pi-ai/providers/all";
|
|
2
3
|
import type { completeStructuredWithModel } from "../../utils/internal-ai/complete-structured.js";
|
|
3
4
|
import type {
|
|
4
5
|
CredentialKind,
|
|
5
6
|
ResolvedCredential,
|
|
6
7
|
resolveCredentials,
|
|
7
8
|
} from "../../utils/internal-ai/credentials.js";
|
|
9
|
+
import {
|
|
10
|
+
DEFAULT_MODEL,
|
|
11
|
+
MEMORY_RATER_DEFAULT_MODEL,
|
|
12
|
+
parseModelStr,
|
|
13
|
+
} from "../../utils/internal-ai/models.js";
|
|
8
14
|
import {
|
|
9
15
|
buildTaskTitlePlan,
|
|
10
16
|
generateTaskTitle,
|
|
@@ -108,6 +114,8 @@ describe("buildTaskTitlePlan", () => {
|
|
|
108
114
|
"anthropic",
|
|
109
115
|
"openai-codex",
|
|
110
116
|
"claude-cli",
|
|
117
|
+
"fireworks",
|
|
118
|
+
"amazon-bedrock",
|
|
111
119
|
]);
|
|
112
120
|
});
|
|
113
121
|
|
|
@@ -132,6 +140,49 @@ describe("buildTaskTitlePlan", () => {
|
|
|
132
140
|
expect(kindForModelString("haiku")).toBe("claude-cli");
|
|
133
141
|
expect(kindForModelString("mistral/ministral-3b")).toBeNull();
|
|
134
142
|
});
|
|
143
|
+
|
|
144
|
+
test("kindForModelString recognises the two new providers", () => {
|
|
145
|
+
expect(kindForModelString("fireworks/accounts/fireworks/models/deepseek-v4p1-flash")).toBe(
|
|
146
|
+
"fireworks",
|
|
147
|
+
);
|
|
148
|
+
expect(kindForModelString("amazon-bedrock/global.anthropic.claude-haiku-5-5")).toBe(
|
|
149
|
+
"amazon-bedrock",
|
|
150
|
+
);
|
|
151
|
+
// No regression on the compound-id and bare-alias shapes.
|
|
152
|
+
expect(kindForModelString("openrouter/anthropic/claude-haiku-5.5")).toBe("openrouter");
|
|
153
|
+
expect(kindForModelString("sonnet")).toBe("claude-cli");
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
test("pinning either new provider moves it first with its own fallbacks", () => {
|
|
157
|
+
const fireworks = buildTaskTitlePlan({
|
|
158
|
+
[TASK_TITLE_MODEL_ENV]: "fireworks/accounts/fireworks/routers/kimi-k3-fast",
|
|
159
|
+
});
|
|
160
|
+
expect(fireworks[0]).toEqual({
|
|
161
|
+
kind: "fireworks",
|
|
162
|
+
models: [
|
|
163
|
+
"fireworks/accounts/fireworks/routers/kimi-k3-fast",
|
|
164
|
+
"fireworks/accounts/fireworks/models/deepseek-v4p1-flash",
|
|
165
|
+
"fireworks/accounts/fireworks/models/glm-5p3-flash",
|
|
166
|
+
],
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
const bedrock = buildTaskTitlePlan({
|
|
170
|
+
[TASK_TITLE_MODEL_ENV]: "amazon-bedrock/eu.anthropic.claude-haiku-5-5",
|
|
171
|
+
});
|
|
172
|
+
expect(bedrock[0].kind).toBe("amazon-bedrock");
|
|
173
|
+
expect(bedrock[0].models[0]).toBe("amazon-bedrock/eu.anthropic.claude-haiku-5-5");
|
|
174
|
+
// A region-scoped pin does not displace the shipped defaults behind it.
|
|
175
|
+
expect(bedrock[0].models).toContain("amazon-bedrock/global.anthropic.claude-haiku-5-5");
|
|
176
|
+
expect(bedrock.map((group) => group.kind)).toEqual([
|
|
177
|
+
"amazon-bedrock",
|
|
178
|
+
"openrouter",
|
|
179
|
+
"anthropic",
|
|
180
|
+
"openai",
|
|
181
|
+
"openai-codex",
|
|
182
|
+
"claude-cli",
|
|
183
|
+
"fireworks",
|
|
184
|
+
]);
|
|
185
|
+
});
|
|
135
186
|
});
|
|
136
187
|
|
|
137
188
|
describe("generateTaskTitle", () => {
|
|
@@ -281,3 +332,30 @@ describe("generateTaskTitle", () => {
|
|
|
281
332
|
expect(models).toEqual([]);
|
|
282
333
|
});
|
|
283
334
|
});
|
|
335
|
+
|
|
336
|
+
describe("catalog verification for the new kinds", () => {
|
|
337
|
+
// Every default the registries name must resolve in pi-ai's own catalog: a
|
|
338
|
+
// miss is a silent null from `completeStructured`, which would leave titling
|
|
339
|
+
// and summarization dead in exactly the deployments this change is for.
|
|
340
|
+
test("DEFAULT_MODEL and MEMORY_RATER_DEFAULT_MODEL all exist in pi-ai's catalog", () => {
|
|
341
|
+
for (const registry of [DEFAULT_MODEL, MEMORY_RATER_DEFAULT_MODEL]) {
|
|
342
|
+
for (const [kind, modelStr] of Object.entries(registry)) {
|
|
343
|
+
if (kind === "claude-cli") continue; // a `claude -p` alias, not a pi-ai model
|
|
344
|
+
const [provider, modelId] = parseModelStr(modelStr);
|
|
345
|
+
expect(provider).toBe(kind);
|
|
346
|
+
expect(getBuiltinModel(provider as never, modelId as never)).toBeTruthy();
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
});
|
|
350
|
+
|
|
351
|
+
test("every titling candidate resolves in pi-ai's catalog", () => {
|
|
352
|
+
for (const group of TASK_TITLE_MODEL_CANDIDATES) {
|
|
353
|
+
if (group.kind === "claude-cli") continue;
|
|
354
|
+
for (const modelStr of group.models) {
|
|
355
|
+
const [provider, modelId] = parseModelStr(modelStr);
|
|
356
|
+
expect(provider).toBe(group.kind);
|
|
357
|
+
expect(getBuiltinModel(provider as never, modelId as never)).toBeTruthy();
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
});
|
|
361
|
+
});
|
|
@@ -166,7 +166,12 @@ async function openSession(path: string, headers: Record<string, string>): Promi
|
|
|
166
166
|
return init.sessionId;
|
|
167
167
|
}
|
|
168
168
|
|
|
169
|
-
/**
|
|
169
|
+
/**
|
|
170
|
+
* POST `totalBytes` with no Content-Length (chunked), so only the streaming cap can stop it.
|
|
171
|
+
* The body is never ended: the server answers 413 and closes the socket as soon as the cap is
|
|
172
|
+
* crossed. Bytes still in flight at that point make the close a TCP reset that can drop the
|
|
173
|
+
* response, so callers send exactly one byte over the cap.
|
|
174
|
+
*/
|
|
170
175
|
function postChunked(
|
|
171
176
|
path: string,
|
|
172
177
|
headers: Record<string, string>,
|
|
@@ -188,25 +193,25 @@ function postChunked(
|
|
|
188
193
|
body += chunk;
|
|
189
194
|
});
|
|
190
195
|
res.on("error", reject);
|
|
191
|
-
res.on("end", () =>
|
|
196
|
+
res.on("end", () => {
|
|
197
|
+
resolve({ status: res.statusCode ?? 0, body });
|
|
198
|
+
req.destroy();
|
|
199
|
+
});
|
|
192
200
|
},
|
|
193
201
|
);
|
|
194
|
-
//
|
|
195
|
-
req.on("error",
|
|
196
|
-
if (error.code === "EPIPE") return;
|
|
197
|
-
reject(error);
|
|
198
|
-
});
|
|
202
|
+
// An error after the response is complete is just our own teardown.
|
|
203
|
+
req.on("error", reject);
|
|
199
204
|
const chunk = Buffer.alloc(64 * 1024, 0x20);
|
|
200
205
|
let sent = 0;
|
|
201
206
|
const pump = () => {
|
|
202
207
|
while (sent < totalBytes) {
|
|
203
|
-
|
|
204
|
-
|
|
208
|
+
const part = chunk.subarray(0, Math.min(chunk.byteLength, totalBytes - sent));
|
|
209
|
+
sent += part.byteLength;
|
|
210
|
+
if (!req.write(part)) {
|
|
205
211
|
req.once("drain", pump);
|
|
206
212
|
return;
|
|
207
213
|
}
|
|
208
214
|
}
|
|
209
|
-
req.end();
|
|
210
215
|
};
|
|
211
216
|
pump();
|
|
212
217
|
});
|
|
@@ -282,7 +287,7 @@ for (const surface of surfaces) {
|
|
|
282
287
|
const { status, body } = await postChunked(
|
|
283
288
|
surface.path,
|
|
284
289
|
headers,
|
|
285
|
-
MCP_MAX_REQUEST_BODY_BYTES +
|
|
290
|
+
MCP_MAX_REQUEST_BODY_BYTES + 1,
|
|
286
291
|
);
|
|
287
292
|
expect(status).toBe(413);
|
|
288
293
|
expect(JSON.parse(body)).toEqual({
|
|
@@ -12,10 +12,12 @@ import {
|
|
|
12
12
|
type ApiConfig,
|
|
13
13
|
checkCompletedProcesses,
|
|
14
14
|
DEFAULT_TASK_RECONCILE_INTERVAL_MS,
|
|
15
|
+
DEFAULT_TERMINAL_TASK_GRACE_MS,
|
|
15
16
|
type RunnerState,
|
|
16
17
|
type RunningTask,
|
|
17
18
|
reconcileActiveTasks,
|
|
18
19
|
resolveTaskReconcileIntervalMs,
|
|
20
|
+
resolveTerminalTaskGraceMs,
|
|
19
21
|
} from "../commands/runner";
|
|
20
22
|
import type { ProviderResult, ProviderSession } from "../providers/types";
|
|
21
23
|
import { registerVolatileSecret } from "../utils/secret-scrubber";
|
|
@@ -197,6 +199,106 @@ describe("reconcileActiveTasks: a session that never settles", () => {
|
|
|
197
199
|
});
|
|
198
200
|
});
|
|
199
201
|
|
|
202
|
+
describe("reconcileActiveTasks: a server-terminal task whose session can finish its input", () => {
|
|
203
|
+
/** Like Claude: `finishInput` closes stdin; `endsTurn` says whether the turn then ends. */
|
|
204
|
+
function finishableSetup(startedAt: number, endsTurn: boolean) {
|
|
205
|
+
const ctx = setup(startedAt);
|
|
206
|
+
const finishCalls: number[] = [];
|
|
207
|
+
ctx.session.finishInput = () => {
|
|
208
|
+
finishCalls.push(finishCalls.length);
|
|
209
|
+
if (!endsTurn) return;
|
|
210
|
+
ctx.task.result = {
|
|
211
|
+
exitCode: 0,
|
|
212
|
+
isError: false,
|
|
213
|
+
sessionId: "sess-hung",
|
|
214
|
+
cost: {
|
|
215
|
+
sessionId: "runner-session",
|
|
216
|
+
taskId: ctx.taskId,
|
|
217
|
+
agentId: crypto.randomUUID(),
|
|
218
|
+
totalCostUsd: 0.42,
|
|
219
|
+
durationMs: 1_000,
|
|
220
|
+
numTurns: 3,
|
|
221
|
+
model: "claude-sonnet-5-5",
|
|
222
|
+
isError: false,
|
|
223
|
+
provider: "claude",
|
|
224
|
+
},
|
|
225
|
+
};
|
|
226
|
+
};
|
|
227
|
+
return { ...ctx, finishCalls };
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
test("closes input instead of aborting, so the session's result and cost still land", async () => {
|
|
231
|
+
const startedAt = 6_000_000;
|
|
232
|
+
const { session, task, state, finishCalls } = finishableSetup(startedAt, true);
|
|
233
|
+
const apiConfig: ApiConfig = { apiUrl, apiKey: "test-key", agentId: crypto.randomUUID() };
|
|
234
|
+
|
|
235
|
+
await runUntilFree(state, startedAt, {
|
|
236
|
+
serverStatus: () => "completed",
|
|
237
|
+
apiConfig,
|
|
238
|
+
maxMs: 5 * 60_000,
|
|
239
|
+
});
|
|
240
|
+
|
|
241
|
+
expect(state.activeTasks.size).toBe(0);
|
|
242
|
+
expect(finishCalls).toHaveLength(1);
|
|
243
|
+
expect(session.abortReasons).toEqual([]);
|
|
244
|
+
expect(task.serverTerminalStatus).toBe("completed");
|
|
245
|
+
expect(requests).toContain("POST /api/session-costs");
|
|
246
|
+
expect(requests.some((r) => r.endsWith("/finish"))).toBe(false);
|
|
247
|
+
});
|
|
248
|
+
|
|
249
|
+
test("a session still running when the grace ends is aborted, then force-settled", async () => {
|
|
250
|
+
const startedAt = 7_000_000;
|
|
251
|
+
const { session, task, state, finishCalls } = finishableSetup(startedAt, false);
|
|
252
|
+
|
|
253
|
+
const { elapsedMs, statusReads } = await runUntilFree(state, startedAt, {
|
|
254
|
+
serverStatus: () => "completed",
|
|
255
|
+
maxMs: 5 * 60_000,
|
|
256
|
+
});
|
|
257
|
+
|
|
258
|
+
expect(state.activeTasks.size).toBe(0);
|
|
259
|
+
expect(finishCalls).toHaveLength(1);
|
|
260
|
+
expect(statusReads).toBe(1);
|
|
261
|
+
expect(session.abortReasons).toEqual(["server task completed"]);
|
|
262
|
+
expect(elapsedMs).toBeGreaterThanOrEqual(INTERVAL_MS + DEFAULT_TERMINAL_TASK_GRACE_MS);
|
|
263
|
+
expect(elapsedMs).toBeLessThanOrEqual(
|
|
264
|
+
INTERVAL_MS + DEFAULT_TERMINAL_TASK_GRACE_MS + ABORT_SETTLE_GRACE_MS + 2 * TICK_MS,
|
|
265
|
+
);
|
|
266
|
+
expect(task.result?.failureReason).toContain("runner exited without result");
|
|
267
|
+
});
|
|
268
|
+
|
|
269
|
+
test("a cancelled task is aborted at once, without the grace", async () => {
|
|
270
|
+
const startedAt = 8_000_000;
|
|
271
|
+
const { session, state, finishCalls } = finishableSetup(startedAt, true);
|
|
272
|
+
|
|
273
|
+
const { elapsedMs } = await runUntilFree(state, startedAt, {
|
|
274
|
+
serverStatus: () => "cancelled",
|
|
275
|
+
maxMs: 5 * 60_000,
|
|
276
|
+
});
|
|
277
|
+
|
|
278
|
+
expect(state.activeTasks.size).toBe(0);
|
|
279
|
+
expect(finishCalls).toHaveLength(0);
|
|
280
|
+
expect(session.abortReasons).toEqual(["server task cancelled"]);
|
|
281
|
+
expect(elapsedMs).toBeLessThanOrEqual(INTERVAL_MS + ABORT_SETTLE_GRACE_MS + 2 * TICK_MS);
|
|
282
|
+
});
|
|
283
|
+
});
|
|
284
|
+
|
|
285
|
+
describe("resolveTerminalTaskGraceMs", () => {
|
|
286
|
+
test("reads RUNNER_TERMINAL_TASK_GRACE_MS, accepts 0, and falls back on unset or invalid values", () => {
|
|
287
|
+
expect(resolveTerminalTaskGraceMs({ RUNNER_TERMINAL_TASK_GRACE_MS: "60000" })).toBe(60_000);
|
|
288
|
+
expect(resolveTerminalTaskGraceMs({ RUNNER_TERMINAL_TASK_GRACE_MS: "0" })).toBe(0);
|
|
289
|
+
expect(resolveTerminalTaskGraceMs({})).toBe(DEFAULT_TERMINAL_TASK_GRACE_MS);
|
|
290
|
+
expect(resolveTerminalTaskGraceMs({ RUNNER_TERMINAL_TASK_GRACE_MS: "" })).toBe(
|
|
291
|
+
DEFAULT_TERMINAL_TASK_GRACE_MS,
|
|
292
|
+
);
|
|
293
|
+
expect(resolveTerminalTaskGraceMs({ RUNNER_TERMINAL_TASK_GRACE_MS: "-1" })).toBe(
|
|
294
|
+
DEFAULT_TERMINAL_TASK_GRACE_MS,
|
|
295
|
+
);
|
|
296
|
+
expect(resolveTerminalTaskGraceMs({ RUNNER_TERMINAL_TASK_GRACE_MS: "soon" })).toBe(
|
|
297
|
+
DEFAULT_TERMINAL_TASK_GRACE_MS,
|
|
298
|
+
);
|
|
299
|
+
});
|
|
300
|
+
});
|
|
301
|
+
|
|
200
302
|
describe("resolveTaskReconcileIntervalMs", () => {
|
|
201
303
|
test("reads RUNNER_TASK_RECONCILE_INTERVAL_MS and falls back on unset or invalid values", () => {
|
|
202
304
|
expect(resolveTaskReconcileIntervalMs({ RUNNER_TASK_RECONCILE_INTERVAL_MS: "5000" })).toBe(
|
|
@@ -4416,6 +4416,91 @@ describe("Slack renderer v2 delegation (SLACK_RENDER_V2_DELEGATION)", () => {
|
|
|
4416
4416
|
expect(String(conclusionStream?.payload.markdown_text)).toContain(getTaskLink(child.id));
|
|
4417
4417
|
});
|
|
4418
4418
|
|
|
4419
|
+
test("a negative settle window falls back to the default, so a just-terminal closure still waits it out", async () => {
|
|
4420
|
+
process.env.SLACK_CONCLUSION_SETTLE_SEC = "-1";
|
|
4421
|
+
const lead = await createAgent({ name: "Negative Settle Lead", isLead: true, status: "idle" });
|
|
4422
|
+
const worker = await createAgent({
|
|
4423
|
+
name: "Negative Settle Worker",
|
|
4424
|
+
isLead: false,
|
|
4425
|
+
status: "idle",
|
|
4426
|
+
});
|
|
4427
|
+
const { channelId, threadTs } = uniqueSlackAddress("C_NEGATIVE_SETTLE");
|
|
4428
|
+
const ask = await createTaskExtended("negative settle ask", {
|
|
4429
|
+
agentId: lead.id,
|
|
4430
|
+
source: "slack",
|
|
4431
|
+
slackChannelId: channelId,
|
|
4432
|
+
slackThreadTs: threadTs,
|
|
4433
|
+
contextKey: slackContextKey({ channelId, threadTs }),
|
|
4434
|
+
});
|
|
4435
|
+
await startTask(ask.id);
|
|
4436
|
+
const child = await createTaskExtended("settle child work", {
|
|
4437
|
+
agentId: worker.id,
|
|
4438
|
+
source: "mcp",
|
|
4439
|
+
parentTaskId: ask.id,
|
|
4440
|
+
followUpConfig: { disabled: true },
|
|
4441
|
+
});
|
|
4442
|
+
await startTask(child.id);
|
|
4443
|
+
await completeTask(child.id, "Child result body.");
|
|
4444
|
+
calls.length = 0;
|
|
4445
|
+
|
|
4446
|
+
// Tick 1: the child gets its own card; the ask is still open, so no conclusion.
|
|
4447
|
+
await processSlackRenderV2();
|
|
4448
|
+
expect((await getSlackOutcomeMessage(child.id))?.finalizedAt).toBeDefined();
|
|
4449
|
+
expect(await getSlackOutcomeMessage(ask.id)).toBeNull();
|
|
4450
|
+
|
|
4451
|
+
// Every member is terminal but the closure has been quiet for 2s only. A
|
|
4452
|
+
// negative settle window must not read as "already quiet long enough".
|
|
4453
|
+
await completeTask(ask.id, "Ask completed.");
|
|
4454
|
+
await backdateLastUpdated([ask.id, child.id], 2);
|
|
4455
|
+
calls.length = 0;
|
|
4456
|
+
|
|
4457
|
+
await processSlackRenderV2();
|
|
4458
|
+
expect(await getSlackOutcomeMessage(ask.id)).toBeNull();
|
|
4459
|
+
|
|
4460
|
+
// The fallback is the documented 10s, so 30s of quiet does conclude.
|
|
4461
|
+
await backdateLastUpdated([ask.id, child.id], 30);
|
|
4462
|
+
await processSlackRenderV2();
|
|
4463
|
+
expect((await getSlackOutcomeMessage(ask.id))?.conclusionKind).toBe("complete");
|
|
4464
|
+
});
|
|
4465
|
+
|
|
4466
|
+
test("a negative timeout falls back to the default, so a fresh unfinished closure is not timed out at once", async () => {
|
|
4467
|
+
process.env.SLACK_CONCLUSION_TIMEOUT_MIN = "-1";
|
|
4468
|
+
const lead = await createAgent({ name: "Negative Timeout Lead", isLead: true, status: "idle" });
|
|
4469
|
+
const worker = await createAgent({
|
|
4470
|
+
name: "Negative Timeout Worker",
|
|
4471
|
+
isLead: false,
|
|
4472
|
+
status: "idle",
|
|
4473
|
+
});
|
|
4474
|
+
const { channelId, threadTs } = uniqueSlackAddress("C_NEGATIVE_TIMEOUT");
|
|
4475
|
+
const ask = await createTaskExtended("negative timeout ask", {
|
|
4476
|
+
agentId: lead.id,
|
|
4477
|
+
source: "slack",
|
|
4478
|
+
slackChannelId: channelId,
|
|
4479
|
+
slackThreadTs: threadTs,
|
|
4480
|
+
contextKey: slackContextKey({ channelId, threadTs }),
|
|
4481
|
+
});
|
|
4482
|
+
await startTask(ask.id);
|
|
4483
|
+
const child = await createTaskExtended("still running work", {
|
|
4484
|
+
agentId: worker.id,
|
|
4485
|
+
source: "mcp",
|
|
4486
|
+
parentTaskId: ask.id,
|
|
4487
|
+
followUpConfig: { disabled: true },
|
|
4488
|
+
});
|
|
4489
|
+
await startTask(child.id);
|
|
4490
|
+
await completeTask(ask.id, "Ask done; the child never finished.");
|
|
4491
|
+
await backdateLastUpdated([ask.id, child.id], 2);
|
|
4492
|
+
calls.length = 0;
|
|
4493
|
+
|
|
4494
|
+
// 2s of idle is nowhere near the 240min fallback, so no timeout card.
|
|
4495
|
+
await processSlackRenderV2();
|
|
4496
|
+
expect(await getSlackOutcomeMessage(ask.id)).toBeNull();
|
|
4497
|
+
|
|
4498
|
+
// Past the documented 240min default the closure does conclude as timed out.
|
|
4499
|
+
await backdateLastUpdated([ask.id, child.id], 260 * 60);
|
|
4500
|
+
await processSlackRenderV2();
|
|
4501
|
+
expect((await getSlackOutcomeMessage(ask.id))?.conclusionKind).toBe("timeout");
|
|
4502
|
+
});
|
|
4503
|
+
|
|
4419
4504
|
test("a stale in-progress ask times out without a completed outcome", async () => {
|
|
4420
4505
|
process.env.SLACK_CONCLUSION_TIMEOUT_MIN = "1";
|
|
4421
4506
|
const lead = await createAgent({ name: "Stale Ask Lead", isLead: true, status: "idle" });
|
package/src/types.ts
CHANGED
|
@@ -2114,7 +2114,8 @@ export const SessionCostSchema = z
|
|
|
2114
2114
|
// had no matching pricing rows; totalCostUsd is whatever
|
|
2115
2115
|
// the worker submitted (often 0).
|
|
2116
2116
|
// 'estimated' — the API priced fallback token counts at an assumed
|
|
2117
|
-
// model (amp with a failed thread export)
|
|
2117
|
+
// model (amp with a failed thread export), or summed
|
|
2118
|
+
// per-message usage (claude killed before its result).
|
|
2118
2119
|
costSource: SessionCostSourceSchema.default("harness"),
|
|
2119
2120
|
kind: SessionCostKindSchema.default("harness"),
|
|
2120
2121
|
// Migration 128: adapter-reported amount retained for reconciliation only.
|
|
@@ -212,6 +212,24 @@ export interface CompleteStructuredResult<TData> {
|
|
|
212
212
|
model: string;
|
|
213
213
|
}
|
|
214
214
|
|
|
215
|
+
/**
|
|
216
|
+
* Extra pi-ai request options a credential kind needs, or `undefined` for the
|
|
217
|
+
* providers that need none.
|
|
218
|
+
*
|
|
219
|
+
* Only Bedrock: it has no key to pass, so the one thing the adapter cannot
|
|
220
|
+
* derive is the region, and the resolver established that (from `AWS_REGION` or
|
|
221
|
+
* `AWS_DEFAULT_REGION`). It goes in as the documented `region` option rather
|
|
222
|
+
* than an `env` override, because the catalog's model entries carry a
|
|
223
|
+
* `us-east-1` base URL and an explicit region is what stops that default from
|
|
224
|
+
* winning over the deployment's actual region. Credentials are deliberately
|
|
225
|
+
* absent: the AWS SDK reads its own chain from `process.env`, and no AWS
|
|
226
|
+
* variable is in the swarm-config allowlist, so there is nothing extra to
|
|
227
|
+
* forward.
|
|
228
|
+
*/
|
|
229
|
+
function providerRequestOptions(cred: ResolvedCredential): Record<string, unknown> | undefined {
|
|
230
|
+
return cred.kind === "amazon-bedrock" ? { region: cred.region } : undefined;
|
|
231
|
+
}
|
|
232
|
+
|
|
215
233
|
/**
|
|
216
234
|
* Run a structured-output completion. Returns the parsed object on success,
|
|
217
235
|
* `null` on auth-missing or exhausted retries (errors logged, never thrown).
|
|
@@ -304,7 +322,8 @@ export async function completeStructuredWithModel<TZod extends z.ZodTypeAny>(
|
|
|
304
322
|
return null;
|
|
305
323
|
}
|
|
306
324
|
|
|
307
|
-
// 3. pi-ai path (openrouter / anthropic / openai / openai-codex
|
|
325
|
+
// 3. pi-ai path (openrouter / anthropic / openai / openai-codex / fireworks /
|
|
326
|
+
// amazon-bedrock).
|
|
308
327
|
const [provider, modelId] = parseModelStr(cred.modelDefault);
|
|
309
328
|
let model: ReturnType<typeof getModel>;
|
|
310
329
|
try {
|
|
@@ -341,10 +360,18 @@ export async function completeStructuredWithModel<TZod extends z.ZodTypeAny>(
|
|
|
341
360
|
provider === "openrouter" ? getOpenRouterAttributionHeaders(model.baseUrl, env) : {};
|
|
342
361
|
|
|
343
362
|
const completeFn = opts._complete ?? complete;
|
|
363
|
+
// Bedrock's adapter maps a `{type:"tool"}` choice to `toolChoice: {tool:{name}}`,
|
|
364
|
+
// which is the same forcing the Anthropic adapter does. Without it the
|
|
365
|
+
// Converse request carries no toolChoice and the model is free to answer in
|
|
366
|
+
// prose, which costs a retry per call.
|
|
344
367
|
const toolChoice =
|
|
345
|
-
model.api === "anthropic-messages"
|
|
368
|
+
model.api === "anthropic-messages" || model.api === "bedrock-converse-stream"
|
|
346
369
|
? ({ type: "tool", name: opts.toolName } as const)
|
|
347
370
|
: ("required" as const);
|
|
371
|
+
// Bedrock is the one provider whose request config is not a key: the SDK
|
|
372
|
+
// reads its credential chain from the environment, and the region the
|
|
373
|
+
// resolver established has to travel with the request.
|
|
374
|
+
const providerOptions = providerRequestOptions(cred);
|
|
348
375
|
let userPrompt = opts.userPrompt;
|
|
349
376
|
let lastErr: unknown = null;
|
|
350
377
|
for (let attempt = 0; attempt < retries; attempt++) {
|
|
@@ -364,9 +391,13 @@ export async function completeStructuredWithModel<TZod extends z.ZodTypeAny>(
|
|
|
364
391
|
},
|
|
365
392
|
// pi-ai's ProviderStreamOptions type only allows known providers;
|
|
366
393
|
// we pass the validated apiKey through verbatim.
|
|
367
|
-
{
|
|
368
|
-
|
|
369
|
-
|
|
394
|
+
{
|
|
395
|
+
apiKey: "apiKey" in cred ? cred.apiKey : undefined,
|
|
396
|
+
signal: opts.signal,
|
|
397
|
+
toolChoice,
|
|
398
|
+
headers,
|
|
399
|
+
...(providerOptions ?? {}),
|
|
400
|
+
} as Parameters<typeof completeFn>[2],
|
|
370
401
|
);
|
|
371
402
|
|
|
372
403
|
const toolCall = msg.content.find(
|