@desplega.ai/agent-swarm 2.8.0 → 2.8.2
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-t949vbbp.js → acp-adapter-fqzkxyra.js} +3 -3
- package/dist/{actions-7e9czc7s.js → actions-kxek041g.js} +18 -18
- package/dist/{amp-adapter-gv6cbb7d.js → amp-adapter-ce7jjke4.js} +1 -1
- package/dist/{app-b9fbkp9v.js → app-v6zz8yh0.js} +3 -3
- package/dist/{assistant-wjb7v4c7.js → assistant-m0sw9xx2.js} +19 -19
- package/dist/{boot-args-schema-2t37e0fe.js → boot-args-schema-66bk37wv.js} +1 -1
- package/dist/{boot-reembed-gka3zas7.js → boot-reembed-edjpwsc1.js} +1 -1
- package/dist/{boot-reembed-a35nkyr1.js → boot-reembed-y27n09tz.js} +1 -1
- package/dist/{boot-scrub-sweep-65sdnp6c.js → boot-scrub-sweep-1xc35965.js} +3 -3
- package/dist/{boot-seeds-x42tzytw.js → boot-seeds-7hjj91qj.js} +4 -4
- package/dist/{boxd-qbkxy6ap.js → boxd-ent8ch04.js} +1 -1
- package/dist/{claude-adapter-v221b2fd.js → claude-adapter-stw7jdcf.js} +3 -3
- package/dist/{claude-managed-adapter-29eq09wd.js → claude-managed-adapter-jh6c523j.js} +2 -2
- package/dist/{claude-managed-setup-9m6450zk.js → claude-managed-setup-y6z2perp.js} +5 -5
- package/dist/{claude-sdk-session-0q0ptaba.js → claude-sdk-session-vvya8wqk.js} +3 -3
- package/dist/{cli-wk18cm92.js → cli-0cq8y6m7.js} +1 -1
- package/dist/{cli-p1w18yhx.js → cli-1pz0330a.js} +1 -1
- package/dist/{cli-y97qxcfx.js → cli-1qkz151v.js} +3 -3
- package/dist/{cli-qwca7s44.js → cli-26ctbcdp.js} +18 -6
- package/dist/{cli-8fknbnhw.js → cli-2kvhc7x8.js} +7 -7
- package/dist/{cli-rfywm85n.js → cli-3e875j5p.js} +136 -49
- package/dist/{cli-6wxjceza.js → cli-3sy2xags.js} +10 -10
- package/dist/{cli-a7wvp2km.js → cli-3vmb0n58.js} +1 -1
- package/dist/{cli-p1bq50aa.js → cli-4vzgeta4.js} +13 -13
- package/dist/{cli-m28atx8q.js → cli-5y340nzn.js} +4 -4
- package/dist/{cli-7p1kvkck.js → cli-6rc5frdm.js} +1 -1
- package/dist/{cli-tph5wt3y.js → cli-6wj7p986.js} +1 -1
- package/dist/{cli-t73cas91.js → cli-7349va39.js} +8100 -7620
- package/dist/{cli-ee0b971j.js → cli-837vfs2x.js} +2 -2
- package/dist/{cli-abejgen1.js → cli-959kp5h2.js} +12 -11
- package/dist/{cli-8kzasymh.js → cli-97ae65rz.js} +4 -4
- package/dist/{cli-m4dqmnbp.js → cli-9mb2q6pb.js} +1 -1
- package/dist/{cli-p2gfst4m.js → cli-a0z912j7.js} +123 -35
- package/dist/{cli-4txa0ter.js → cli-b98a65ed.js} +3 -3
- package/dist/{cli-k0wwfqbg.js → cli-dns0y538.js} +4 -0
- package/dist/{cli-tk7cjj8h.js → cli-dzpc6en0.js} +1 -1
- package/dist/{cli-qa4wdgsy.js → cli-e1p3n5gq.js} +4 -4
- package/dist/{cli-gxkx0zzp.js → cli-f4e8r23x.js} +1 -1
- package/dist/{cli-qmqk2yc2.js → cli-f4r3g076.js} +1 -1
- package/dist/{cli-wcg8x116.js → cli-f6bahpn5.js} +1 -1
- package/dist/{cli-qsnnd04k.js → cli-fpjmegdb.js} +1 -1
- package/dist/{cli-j790gp2w.js → cli-fwy8kfd6.js} +271 -37
- package/dist/{cli-rmmpt0wm.js → cli-g5mtmf6t.js} +6 -6
- package/dist/{cli-rzsy6nc6.js → cli-gyt3zydq.js} +3 -3
- package/dist/{cli-pasjcnmj.js → cli-j24zbska.js} +3 -3
- package/dist/{cli-qfedvmcr.js → cli-jdknh18m.js} +10 -10
- package/dist/{cli-7b8sbmag.js → cli-kjtwrhea.js} +1 -1
- package/dist/{cli-gpwhbgx0.js → cli-m9s2qff2.js} +57 -25
- package/dist/{cli-2wnq8jkz.js → cli-mxn1qvbn.js} +3 -2
- package/dist/{cli-s7t6p9my.js → cli-n6vtrcht.js} +1 -1
- package/dist/{cli-2zp0et3v.js → cli-pchypa1s.js} +55 -19
- package/dist/{cli-yq3zak69.js → cli-pfs8adn4.js} +1 -1
- package/dist/{cli-c55z5chy.js → cli-q24n86d2.js} +2 -2
- package/dist/{cli-h38x262p.js → cli-rcecc3yq.js} +167 -43
- package/dist/{cli-xae4g51r.js → cli-rh15cakt.js} +1 -1
- package/dist/{cli-sdtt3men.js → cli-rmzsadkf.js} +1 -1
- package/dist/{cli-f3vq58d2.js → cli-t2tma8gb.js} +1 -1
- package/dist/{cli-m23zjcy2.js → cli-tekytdq9.js} +2 -2
- package/dist/{cli-tqegb8eq.js → cli-vdektqgf.js} +1 -1
- package/dist/{cli-ffhtssbp.js → cli-vj75tyaw.js} +1 -1
- package/dist/{cli-deefvewm.js → cli-w401b9tq.js} +1 -1
- package/dist/{cli-n9ftpys4.js → cli-x6t50dmw.js} +7 -7
- package/dist/{cli-6t09sdhy.js → cli-xf3qw745.js} +3 -3
- package/dist/{cli-hxpyc9sn.js → cli-z1w943va.js} +2 -2
- package/dist/{cli-334z18y3.js → cli-zh9rsbqf.js} +3 -3
- package/dist/cli.js +17 -17
- package/dist/{codex-adapter-30j9bpzd.js → codex-adapter-zerf5qsp.js} +1 -1
- package/dist/{codex-hook-h3vk6xzr.js → codex-hook-30gyhzxe.js} +1 -1
- package/dist/{codex-session-runner-8vp57v8w.js → codex-session-runner-89s304py.js} +1 -1
- package/dist/{commands-bngnz9g7.js → commands-jeh1b51j.js} +3 -3
- package/dist/{controller-hxx8wwy1.js → controller-mctfbrse.js} +3 -3
- package/dist/{controllers-connect-e2b4gyxc.js → controllers-connect-nxa1ddwn.js} +19 -19
- package/dist/{cursor-adapter-n5nc3mfe.js → cursor-adapter-qj8vehv6.js} +1 -1
- package/dist/{db-bgm7vkc0.js → db-2dvay0es.js} +3 -3
- package/dist/{db-c6np41ca.js → db-b36qn6k3.js} +2 -2
- package/dist/{dispatcher-jnybck15.js → dispatcher-gndbta01.js} +17 -17
- package/dist/{dsh-adapter-nrhbrjz8.js → dsh-adapter-f75sz821.js} +1 -1
- package/dist/{e2b-jkwfhbcv.js → e2b-3gpc2n3w.js} +1 -1
- package/dist/{e2b-s16txnpx.js → e2b-jbm7mj93.js} +1 -1
- package/dist/{embedding-space-crsm2zp0.js → embedding-space-4p05vb2x.js} +6 -6
- package/dist/{embeddings-e7z3f27f.js → embeddings-m6768mgh.js} +1 -1
- package/dist/{external-channel-m77wf5z3.js → external-channel-gjv3jne3.js} +2 -2
- package/dist/{fx-adapter-b6w0kf56.js → fx-adapter-rpsgb1tw.js} +4 -4
- package/dist/{grok-adapter-4sqtebdk.js → grok-adapter-n2m3zjg1.js} +4 -4
- package/dist/handlers-nv8edn19.js +32 -0
- package/dist/{heartbeat-xgb036sx.js → heartbeat-a1tv60gt.js} +20 -20
- package/dist/{hook-xsk1jbha.js → hook-8h5dzcgq.js} +2 -2
- package/dist/{hook-5h02c9ga.js → hook-cyaps9ba.js} +4 -4
- package/dist/{http-txe7qhvn.js → http-t15mhbd9.js} +1733 -79
- package/dist/{index-0eny15vj.js → index-2skqtd76.js} +2 -2
- package/dist/{index-w7em4ktq.js → index-d6wkh8ar.js} +2 -2
- package/dist/{index-rvccek1w.js → index-gjwaqaq8.js} +5 -5
- package/dist/{index-e5pfbsys.js → index-hjhfk3ra.js} +3 -3
- package/dist/{index-1qw6f2dc.js → index-khe3gp0k.js} +4 -4
- package/dist/index-ksmyd6kc.js +37 -0
- package/dist/{index-vk63emp7.js → index-qav6455f.js} +14 -12
- package/dist/index-rjnrje98.js +32 -0
- package/dist/index-tv3413wy.js +33 -0
- package/dist/{index-ysvbhg5m.js → index-w1zqf680.js} +1 -1
- package/dist/{keepalive-4zsrce78.js → keepalive-91s7hzrb.js} +3 -3
- package/dist/lead-3hmddvrm.js +70 -0
- package/dist/{maintenance-86jvartk.js → maintenance-7pjmy5xy.js} +1 -1
- package/dist/{node-je82wjet.js → node-4c5jqxr3.js} +1 -1
- package/dist/{oauth-refresh-sweep-j52kg9pr.js → oauth-refresh-sweep-rzqfm94j.js} +2 -2
- package/dist/{onboard-c2aj5p8q.js → onboard-74st7pag.js} +3 -3
- package/dist/{opencode-adapter-dsagkhtw.js → opencode-adapter-arn7gm8q.js} +2 -2
- package/dist/{otel-impl-yyy203z8.js → otel-impl-rnzey8cb.js} +1 -1
- package/dist/{pi-mono-adapter-546cd1cc.js → pi-mono-adapter-6mkwq64n.js} +3 -2
- package/dist/{pricing-refresh-1rgzqyzz.js → pricing-refresh-ha21jhk7.js} +2 -2
- package/dist/{rbac-roles-e70xfeyj.js → rbac-roles-59dxachk.js} +2 -2
- package/dist/{rbac-roles-q89qe8er.js → rbac-roles-wqhma4dr.js} +3 -3
- package/dist/{render-v2-k6tt107q.js → render-v2-14kpzx12.js} +3 -3
- package/dist/{resume-cnnrjfxa.js → resume-gsa5fb5f.js} +6 -6
- package/dist/{session-access-xkxkjw3n.js → session-access-skm7bnp6.js} +4 -4
- package/dist/{session-source-backfill-1d5pdwww.js → session-source-backfill-pbqzbncv.js} +2 -2
- package/dist/{setup-se8q7gkc.js → setup-5yermsem.js} +1 -1
- package/dist/{work-objects-1kxnbzy5.js → work-objects-xj0ck0w4.js} +20 -20
- package/dist/{worker-follow-up-zqm8apt4.js → worker-follow-up-911xc0b8.js} +19 -17
- package/dist/worker-qgg0m2gw.js +70 -0
- package/openapi.json +1741 -290
- package/package.json +3 -3
- package/src/apps/catalog.generated.json +120 -1
- package/src/apps/definition.ts +38 -11
- package/src/apps/page-validator.ts +88 -0
- package/src/be/db/model-profiles.ts +110 -11
- package/src/be/db/tasks/read.ts +20 -0
- package/src/be/db/workflow-run-definitions.ts +19 -8
- package/src/be/db-client.ts +43 -5
- package/src/be/db.ts +9 -3
- package/src/be/migrations/284_model_profile_fallbacks.sql +9 -0
- package/src/be/model-profile-check.ts +43 -18
- package/src/be/runtime-pools/routing.ts +1 -0
- package/src/be/savings/calibrate.ts +468 -0
- package/src/be/savings/compute.ts +182 -0
- package/src/be/savings/model.ts +406 -0
- package/src/be/scripts/typecheck.ts +5 -0
- package/src/be/seed/agent-fs-provision.ts +48 -11
- package/src/be/seed/workflows-seeder.ts +67 -23
- package/src/be/skill-parser.ts +19 -7
- package/src/commands/onboard/agent-fs-version.ts +1 -1
- package/src/commands/provider-error-class.ts +97 -0
- package/src/commands/runner.ts +99 -17
- package/src/extensions/contract-types.generated.ts +1 -1
- package/src/http/all-routes.ts +2 -0
- package/src/http/fs.ts +8 -2
- package/src/http/index.ts +4 -0
- package/src/http/model-profiles.ts +43 -10
- package/src/http/poll.ts +1 -0
- package/src/http/savings-calibration.ts +277 -0
- package/src/http/savings.ts +363 -0
- package/src/http/tasks.ts +46 -4
- package/src/http/trackers/authorize-gate.ts +41 -0
- package/src/http/trackers/jira.ts +26 -4
- package/src/http/trackers/linear.ts +26 -4
- package/src/integrations/chat-sdk/limits.ts +6 -1
- package/src/jira/oauth.ts +7 -1
- package/src/linear/README.md +2 -1
- package/src/linear/oauth.ts +7 -1
- package/src/providers/amp-adapter.ts +1 -1
- package/src/providers/codex-adapter.ts +3 -0
- package/src/providers/pi-mono-adapter.ts +6 -5
- package/src/providers/types.ts +7 -0
- package/src/scripts-runtime/eval-harness.ts +14 -1
- package/src/scripts-runtime/executors/types.ts +3 -0
- package/src/scripts-runtime/sdk-allowlist.ts +11 -1
- package/src/scripts-runtime/swarm-sdk.ts +6 -0
- package/src/scripts-runtime/types/stdlib.d.ts +9 -0
- package/src/scripts-runtime/types/swarm-extension.d.ts +34 -0
- package/src/scripts-runtime/types/swarm-sdk.d.ts +9 -0
- package/src/tasks/worker-follow-up.ts +142 -3
- package/src/tests/agent-fs-provision-seeder.test.ts +81 -0
- package/src/tests/apps-chart-shell.test.ts +170 -0
- package/src/tests/apps-icon.test.ts +156 -2
- package/src/tests/chat-sdk-relay.test.ts +12 -0
- package/src/tests/codex-adapter.test.ts +11 -0
- package/src/tests/comb-default.test.ts +6 -0
- package/src/tests/core-auth.test.ts +7 -6
- package/src/tests/db-client-busy-retry.test.ts +58 -6
- package/src/tests/deploy-guard.test.ts +154 -0
- package/src/tests/docs-index-footprint.test.js +3 -3
- package/src/tests/fixtures/app-shell-charts-definition.json.txt +180 -0
- package/src/tests/mcp-tools.test.ts +1 -1
- package/src/tests/model-profile-fallbacks.test.ts +482 -0
- package/src/tests/model-profiles-api.test.ts +1 -0
- package/src/tests/pi-mono-session-cost-on-abort.test.ts +115 -0
- package/src/tests/provider-error-class.test.ts +174 -0
- package/src/tests/runner-provider-fallback.test.ts +197 -0
- package/src/tests/savings-calibration-api.test.ts +264 -0
- package/src/tests/savings-calibration.test.ts +201 -0
- package/src/tests/savings-compute.test.ts +406 -0
- package/src/tests/savings-model.test.ts +287 -0
- package/src/tests/script-connections.test.ts +2 -0
- package/src/tests/script-native-unawaited-drain.test.ts +167 -0
- package/src/tests/sdk-allowlist.test.ts +40 -0
- package/src/tests/seed-workflows.test.ts +167 -11
- package/src/tests/skill-parser.test.ts +45 -0
- package/src/tests/tracker-oauth-authorize-auth.test.ts +262 -0
- package/src/tests/workflow-definition-pinning.test.ts +128 -3
- package/src/tests/workflow-script-principal.test.ts +94 -4
- package/src/tools/app-upsert.ts +1 -1
- package/src/tools/model-profiles/list-model-profiles.ts +4 -2
- package/src/tools/script-run.ts +1 -1
- package/src/tools/update-profile.ts +1 -1
- package/src/types.ts +115 -33
- package/src/utils/constants.ts +2 -0
- package/templates/skills/apps/SKILL.md +62 -3
- package/templates/skills/apps/content.md +62 -3
- package/templates/skills/swarm-docs/content.md +2 -0
- package/templates/skills/swarm-scripts/SKILL.md +1 -1
- package/templates/skills/swarm-scripts/content.md +1 -1
- package/dist/handlers-kdjcyzdj.js +0 -32
- package/dist/index-835xdgnm.js +0 -33
- package/dist/index-d469300x.js +0 -37
- package/dist/index-rzqwp11g.js +0 -32
- package/dist/lead-yqt47dkr.js +0 -70
- package/dist/worker-j6xxtq7p.js +0 -70
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { afterAll, afterEach, beforeAll, describe, expect, test } from "bun:test";
|
|
1
|
+
import { afterAll, afterEach, beforeAll, describe, expect, spyOn, test } from "bun:test";
|
|
2
2
|
import { unlink } from "node:fs/promises";
|
|
3
3
|
import { z } from "zod";
|
|
4
4
|
import * as db from "../be/db";
|
|
@@ -20,7 +20,12 @@ import {
|
|
|
20
20
|
resolveWaitState,
|
|
21
21
|
toPinnedDefinition,
|
|
22
22
|
} from "../be/db";
|
|
23
|
-
import {
|
|
23
|
+
import {
|
|
24
|
+
getPinnedRunDefinition,
|
|
25
|
+
hashPinnedDefinition,
|
|
26
|
+
mergePinnedDefinition,
|
|
27
|
+
} from "../be/db/workflow-run-definitions";
|
|
28
|
+
import type { DbParam } from "../be/db-client";
|
|
24
29
|
import {
|
|
25
30
|
type ExecutorMeta,
|
|
26
31
|
type Workflow,
|
|
@@ -577,7 +582,14 @@ describe("pinned definition storage", () => {
|
|
|
577
582
|
expect(rowsAfter?.n).toBe(rowsBefore?.n);
|
|
578
583
|
});
|
|
579
584
|
|
|
580
|
-
test(
|
|
585
|
+
test.each([
|
|
586
|
+
"running",
|
|
587
|
+
"waiting",
|
|
588
|
+
"completed",
|
|
589
|
+
"failed",
|
|
590
|
+
"skipped",
|
|
591
|
+
"cancelled",
|
|
592
|
+
] as const)("deleteWorkflow preserves unrelated snapshots and snapshots shared with a %s run", async (status) => {
|
|
581
593
|
const wf1 = await makeWorkflow(twoNode("A", agentTaskFirst));
|
|
582
594
|
const wf2 = await makeWorkflow(twoNode("A", agentTaskFirst));
|
|
583
595
|
const run1 = await startOnA(wf1);
|
|
@@ -585,9 +597,11 @@ describe("pinned definition storage", () => {
|
|
|
585
597
|
const run3 = await startOnA(wf2);
|
|
586
598
|
const h1 = (await pinHash(run1))!;
|
|
587
599
|
const h2 = (await pinHash(run2))!;
|
|
600
|
+
const unrelated = await pinWorkflowDefinition({ ...wf1, name: "unrelated orphan" });
|
|
588
601
|
expect(h1).not.toBe(h2);
|
|
589
602
|
// A wf2 run shares wf1's snapshot row, as identical content does.
|
|
590
603
|
await getDbClient().run("UPDATE workflow_runs SET definitionHash = ? WHERE id = ?", [h1, run3]);
|
|
604
|
+
await db.updateWorkflowRun(run3, { status });
|
|
591
605
|
const exists = async (hash: string) =>
|
|
592
606
|
(await getDbClient().get("SELECT 1 FROM workflow_run_definitions WHERE hash = ?", [hash])) !=
|
|
593
607
|
null;
|
|
@@ -595,10 +609,121 @@ describe("pinned definition storage", () => {
|
|
|
595
609
|
await deleteWorkflow(wf1.id);
|
|
596
610
|
expect(await exists(h1)).toBe(true);
|
|
597
611
|
expect(await exists(h2)).toBe(true);
|
|
612
|
+
expect(await exists(unrelated)).toBe(true);
|
|
598
613
|
|
|
599
614
|
await deleteWorkflow(wf2.id);
|
|
600
615
|
expect(await exists(h1)).toBe(false);
|
|
601
616
|
expect(await exists(h2)).toBe(false);
|
|
617
|
+
expect(await exists(unrelated)).toBe(true);
|
|
618
|
+
});
|
|
619
|
+
|
|
620
|
+
test.each([
|
|
621
|
+
"no runs",
|
|
622
|
+
"unpinned run",
|
|
623
|
+
"missing workflow",
|
|
624
|
+
])("deleteWorkflow leaves unrelated snapshots alone with %s", async (scenario) => {
|
|
625
|
+
const workflow = await makeWorkflow(twoNode("A", agentTaskFirst));
|
|
626
|
+
const unrelated = await pinWorkflowDefinition(workflow);
|
|
627
|
+
if (scenario === "unpinned run") {
|
|
628
|
+
await db.createWorkflowRun({ id: crypto.randomUUID(), workflowId: workflow.id });
|
|
629
|
+
}
|
|
630
|
+
|
|
631
|
+
expect(
|
|
632
|
+
await deleteWorkflow(scenario === "missing workflow" ? crypto.randomUUID() : workflow.id),
|
|
633
|
+
).toBe(scenario !== "missing workflow");
|
|
634
|
+
expect(
|
|
635
|
+
await getDbClient().get("SELECT 1 FROM workflow_run_definitions WHERE hash = ?", [unrelated]),
|
|
636
|
+
).not.toBeNull();
|
|
637
|
+
});
|
|
638
|
+
|
|
639
|
+
test("deleteWorkflow uses indexed snapshot cleanup across many definitions, including FK checks", async () => {
|
|
640
|
+
const workflow = await makeWorkflow(twoNode("A", agentTaskFirst));
|
|
641
|
+
const client = getDbClient();
|
|
642
|
+
const hashes: string[] = [];
|
|
643
|
+
await client.transaction(async () => {
|
|
644
|
+
for (let version = 0; version < 121; version++) {
|
|
645
|
+
const definitionHash = await pinWorkflowDefinition({
|
|
646
|
+
...workflow,
|
|
647
|
+
description: `v${version}`,
|
|
648
|
+
});
|
|
649
|
+
hashes.push(definitionHash);
|
|
650
|
+
await db.createWorkflowRun({
|
|
651
|
+
id: crypto.randomUUID(),
|
|
652
|
+
workflowId: workflow.id,
|
|
653
|
+
definitionHash,
|
|
654
|
+
});
|
|
655
|
+
}
|
|
656
|
+
});
|
|
657
|
+
|
|
658
|
+
// Explain the statements actually used by the public delete path. The
|
|
659
|
+
// spies pass through to the real database, including its FK enforcement.
|
|
660
|
+
const querySpy = spyOn(client, "query");
|
|
661
|
+
const runSpy = spyOn(client, "run");
|
|
662
|
+
let queries: typeof querySpy.mock.calls = [];
|
|
663
|
+
let deletes: typeof runSpy.mock.calls = [];
|
|
664
|
+
try {
|
|
665
|
+
expect(await deleteWorkflow(workflow.id)).toBe(true);
|
|
666
|
+
queries = querySpy.mock.calls.filter(([sql]) => sql.includes("definitionHash"));
|
|
667
|
+
deletes = runSpy.mock.calls.filter(([sql]) =>
|
|
668
|
+
sql.includes("DELETE FROM workflow_run_definitions"),
|
|
669
|
+
);
|
|
670
|
+
} finally {
|
|
671
|
+
querySpy.mockRestore();
|
|
672
|
+
runSpy.mockRestore();
|
|
673
|
+
}
|
|
674
|
+
|
|
675
|
+
const explain = (sql: string, params: DbParam[] = []) => {
|
|
676
|
+
// Finalize EXPLAIN explicitly: Bun 1.4.4 can leave a cached DELETE plan
|
|
677
|
+
// active after .all(), which blocks later transaction commits.
|
|
678
|
+
const statement = db
|
|
679
|
+
.getDb()
|
|
680
|
+
.prepare<{ detail: string }, DbParam[]>(`EXPLAIN QUERY PLAN ${sql}`);
|
|
681
|
+
try {
|
|
682
|
+
return statement
|
|
683
|
+
.all(...params)
|
|
684
|
+
.map((row) => row.detail)
|
|
685
|
+
.join("\n");
|
|
686
|
+
} finally {
|
|
687
|
+
statement.finalize();
|
|
688
|
+
}
|
|
689
|
+
};
|
|
690
|
+
expect(deletes.length).toBeGreaterThan(0);
|
|
691
|
+
for (const [sql, params] of deletes) {
|
|
692
|
+
const plan = explain(sql, params);
|
|
693
|
+
expect(plan).toMatch(/SEARCH workflow_run_definitions USING (COVERING )?INDEX .*\(hash=\?\)/);
|
|
694
|
+
expect(plan).toContain("SEARCH r USING COVERING INDEX idx_workflow_runs_definitionHash");
|
|
695
|
+
expect(plan).toContain(
|
|
696
|
+
"SEARCH workflow_runs USING COVERING INDEX idx_workflow_runs_definitionHash",
|
|
697
|
+
);
|
|
698
|
+
expect(plan).not.toMatch(/SCAN (workflow_run_definitions|workflow_runs|r)\b/);
|
|
699
|
+
}
|
|
700
|
+
expect(queries.length).toBeGreaterThan(0);
|
|
701
|
+
for (const [sql, params] of queries) {
|
|
702
|
+
const plan = explain(sql, params);
|
|
703
|
+
expect(plan).toMatch(/SEARCH workflow_runs USING INDEX .*\(workflowId=\?\)/);
|
|
704
|
+
expect(plan).not.toContain("SCAN workflow_runs");
|
|
705
|
+
}
|
|
706
|
+
for (const hash of hashes) {
|
|
707
|
+
expect(
|
|
708
|
+
await client.get("SELECT 1 FROM workflow_run_definitions WHERE hash = ?", [hash]),
|
|
709
|
+
).toBeNull();
|
|
710
|
+
}
|
|
711
|
+
});
|
|
712
|
+
|
|
713
|
+
test("deleteWorkflow rolls snapshot cleanup back with the runs", async () => {
|
|
714
|
+
const workflow = await makeWorkflow(twoNode("A", agentTaskFirst));
|
|
715
|
+
const runId = await startOnA(workflow);
|
|
716
|
+
const hash = await pinHash(runId);
|
|
717
|
+
await expect(
|
|
718
|
+
getDbClient().transaction(async () => {
|
|
719
|
+
await deleteWorkflow(workflow.id);
|
|
720
|
+
throw new Error("abort delete");
|
|
721
|
+
}),
|
|
722
|
+
).rejects.toThrow("abort delete");
|
|
723
|
+
|
|
724
|
+
expect(await getWorkflow(workflow.id)).not.toBeNull();
|
|
725
|
+
expect(await pinHash(runId)).toBe(hash);
|
|
726
|
+
expect(await getPinnedRunDefinition(runId)).not.toBeNull();
|
|
602
727
|
});
|
|
603
728
|
});
|
|
604
729
|
|
|
@@ -7,9 +7,12 @@ import {
|
|
|
7
7
|
type ServerResponse,
|
|
8
8
|
} from "node:http";
|
|
9
9
|
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
10
|
+
import dreamingConfig from "../../templates/workflows/dreaming/config.json" with { type: "text" };
|
|
11
|
+
import dreamingContent from "../../templates/workflows/dreaming/content.md" with { type: "text" };
|
|
10
12
|
import {
|
|
11
13
|
closeDb,
|
|
12
14
|
completeTask,
|
|
15
|
+
computeContentHash,
|
|
13
16
|
createAgent,
|
|
14
17
|
createScheduledTask,
|
|
15
18
|
createWorkflow,
|
|
@@ -24,9 +27,15 @@ import {
|
|
|
24
27
|
import { upsertScriptByName } from "../be/scripts/db";
|
|
25
28
|
import { setScriptEmbeddingProviderForTests } from "../be/scripts/embeddings";
|
|
26
29
|
import * as runCredential from "../be/scripts/run-credential";
|
|
27
|
-
import { runSeeder } from "../be/seed";
|
|
30
|
+
import { getSeedState, runSeeder } from "../be/seed";
|
|
28
31
|
import { createSchedulesSeeder } from "../be/seed/schedules-seeder";
|
|
29
|
-
import {
|
|
32
|
+
import { recordSeedState } from "../be/seed/state-db";
|
|
33
|
+
import {
|
|
34
|
+
canonicalJson,
|
|
35
|
+
createWorkflowsSeeder,
|
|
36
|
+
loadSeedWorkflows,
|
|
37
|
+
seededWorkflowState,
|
|
38
|
+
} from "../be/seed/workflows-seeder";
|
|
30
39
|
import { getPathSegments, parseQueryParams } from "../http/utils";
|
|
31
40
|
import { handleWorkflows } from "../http/workflows";
|
|
32
41
|
import { dispatchScheduleTarget } from "../scheduler/scheduler";
|
|
@@ -168,6 +177,22 @@ afterAll(async () => {
|
|
|
168
177
|
});
|
|
169
178
|
|
|
170
179
|
/** Put the seeded dreaming row back after a test edits it. */
|
|
180
|
+
/** The built-in dreaming template, with `marker` appended to the synthesize prompt. */
|
|
181
|
+
function dreamingSource(marker?: string): { config: string; content: string } {
|
|
182
|
+
const content = dreamingContent as unknown as string;
|
|
183
|
+
if (!marker) return { config: dreamingConfig as unknown as string, content };
|
|
184
|
+
const match = content.match(/```json\s*\n([\s\S]*?)\n```/)!;
|
|
185
|
+
const payload = JSON.parse(match[1]!) as {
|
|
186
|
+
nodes: { id: string; config: Record<string, unknown> }[];
|
|
187
|
+
};
|
|
188
|
+
const synthesize = payload.nodes.find((node) => node.id === "synthesize")!;
|
|
189
|
+
synthesize.config.template = `${synthesize.config.template as string}\n${marker}`;
|
|
190
|
+
return {
|
|
191
|
+
config: dreamingConfig as unknown as string,
|
|
192
|
+
content: content.replace(match[1]!, () => JSON.stringify(payload)),
|
|
193
|
+
};
|
|
194
|
+
}
|
|
195
|
+
|
|
171
196
|
async function restoreDreaming(): Promise<void> {
|
|
172
197
|
await updateWorkflow(dreaming.id, {
|
|
173
198
|
description: dreaming.description,
|
|
@@ -364,24 +389,89 @@ describe("swarm-script principal for a creator-less workflow", () => {
|
|
|
364
389
|
expect(calls).toEqual([]);
|
|
365
390
|
});
|
|
366
391
|
|
|
367
|
-
test("a creator-less schedule refuses the lead for
|
|
392
|
+
test("a creator-less schedule refuses the lead for a legacy-state edit with no seeded snapshot", async () => {
|
|
368
393
|
const schedule = await createScheduledTask({
|
|
369
394
|
name: `principal-unsnapshotted-${crypto.randomUUID().slice(0, 8)}`,
|
|
370
395
|
cronExpression: "0 0 1 1 *",
|
|
371
396
|
targetType: "workflow",
|
|
372
397
|
workflowId: dreaming.id,
|
|
373
398
|
});
|
|
374
|
-
|
|
399
|
+
const state = await getSeedState("workflow", "dreaming");
|
|
400
|
+
// Older releases recorded a whole-workflow hash, which a description edit
|
|
401
|
+
// changes. Delete the history so no snapshot proves the seeded state.
|
|
402
|
+
const [seed] = loadSeedWorkflows([dreamingSource()]);
|
|
403
|
+
await recordSeedState("workflow", "dreaming", computeContentHash(canonicalJson(seed)));
|
|
375
404
|
await getDbClient().run("DELETE FROM workflow_versions WHERE workflowId = ?", [dreaming.id]);
|
|
376
405
|
await updateWorkflow(dreaming.id, { description: "edited without a snapshot" });
|
|
377
406
|
try {
|
|
378
407
|
await expect(dispatchScheduleTarget(schedule)).rejects.toThrow("were edited");
|
|
379
408
|
} finally {
|
|
380
409
|
await restoreDreaming();
|
|
410
|
+
await recordSeedState("workflow", "dreaming", state!.seededHash);
|
|
381
411
|
}
|
|
382
412
|
expect(calls).toEqual([]);
|
|
383
413
|
});
|
|
384
414
|
|
|
415
|
+
test("a creator-less schedule refuses the lead for a node edit with no seeded snapshot", async () => {
|
|
416
|
+
const schedule = await createScheduledTask({
|
|
417
|
+
name: `principal-unsnapshotted-node-${crypto.randomUUID().slice(0, 8)}`,
|
|
418
|
+
cronExpression: "0 0 1 1 *",
|
|
419
|
+
targetType: "workflow",
|
|
420
|
+
workflowId: dreaming.id,
|
|
421
|
+
});
|
|
422
|
+
await getDbClient().run("DELETE FROM workflow_versions WHERE workflowId = ?", [dreaming.id]);
|
|
423
|
+
const [gather, ...rest] = dreaming.definition.nodes;
|
|
424
|
+
await updateWorkflow(dreaming.id, {
|
|
425
|
+
definition: {
|
|
426
|
+
...dreaming.definition,
|
|
427
|
+
nodes: [{ ...gather!, config: { ...gather!.config, scriptName: "evil" } }, ...rest],
|
|
428
|
+
},
|
|
429
|
+
});
|
|
430
|
+
try {
|
|
431
|
+
await expect(dispatchScheduleTarget(schedule)).rejects.toThrow("were edited");
|
|
432
|
+
} finally {
|
|
433
|
+
await restoreDreaming();
|
|
434
|
+
}
|
|
435
|
+
expect(calls).toEqual([]);
|
|
436
|
+
});
|
|
437
|
+
|
|
438
|
+
test("a template update on input-tuned dreaming with legacy seed state keeps the lead", async () => {
|
|
439
|
+
// The live shape: seeded under a whole-workflow hash, then the lead set
|
|
440
|
+
// `input` through update-workflow, then a release changed the template.
|
|
441
|
+
const state = await getSeedState("workflow", "dreaming");
|
|
442
|
+
const [seed] = loadSeedWorkflows([dreamingSource()]);
|
|
443
|
+
await recordSeedState("workflow", "dreaming", computeContentHash(canonicalJson(seed)));
|
|
444
|
+
const tunedInput = { ...dreaming.input, leadAgentId: leadId, slackChannel: "C123" };
|
|
445
|
+
await snapshotAndUpdateWorkflow(
|
|
446
|
+
dreaming.id,
|
|
447
|
+
{ input: tunedInput },
|
|
448
|
+
{ changedByAgentId: leadId },
|
|
449
|
+
);
|
|
450
|
+
const schedule = await createScheduledTask({
|
|
451
|
+
name: `principal-template-update-${crypto.randomUUID().slice(0, 8)}`,
|
|
452
|
+
cronExpression: "0 0 1 1 *",
|
|
453
|
+
targetType: "workflow",
|
|
454
|
+
workflowId: dreaming.id,
|
|
455
|
+
});
|
|
456
|
+
try {
|
|
457
|
+
const result = await runSeeder(createWorkflowsSeeder([dreamingSource("TEMPLATE UPDATE")]), {
|
|
458
|
+
quiet: true,
|
|
459
|
+
});
|
|
460
|
+
expect(result).toMatchObject({ updated: 1, skippedUserModified: 0, failed: [] });
|
|
461
|
+
const live = (await listWorkflows()).find((w) => w.name === "dreaming")!;
|
|
462
|
+
expect(live.input).toEqual(tunedInput);
|
|
463
|
+
expect(JSON.stringify(live.definition)).toContain("TEMPLATE UPDATE");
|
|
464
|
+
expect(await seededWorkflowState(live)).toBe("pristine");
|
|
465
|
+
|
|
466
|
+
await dispatchScheduleTarget(schedule);
|
|
467
|
+
expect(gatherPrincipals()).toEqual([leadId]);
|
|
468
|
+
expect(calls[0]?.args.leadAgentId).toBe(leadId);
|
|
469
|
+
} finally {
|
|
470
|
+
await restoreDreaming();
|
|
471
|
+
await recordSeedState("workflow", "dreaming", state!.seededHash);
|
|
472
|
+
}
|
|
473
|
+
});
|
|
474
|
+
|
|
385
475
|
test("a long successful night does not make the next nightly fire skip", async () => {
|
|
386
476
|
const schedule = await createScheduledTask({
|
|
387
477
|
name: `principal-long-${crypto.randomUUID().slice(0, 8)}`,
|
package/src/tools/app-upsert.ts
CHANGED
|
@@ -24,7 +24,7 @@ export const registerAppUpsertTool = (server: McpServer) => {
|
|
|
24
24
|
{
|
|
25
25
|
title: "Create or update an app",
|
|
26
26
|
description:
|
|
27
|
-
|
|
27
|
+
'Stores a schema-backed app definition with models, queries/actions, pages, reusable elements, optional userConfig fields, an optional top-level theme (a dashboard preset slug for the app\'s canvas: hive (stock; omit to inherit the viewer\'s theme), meadow, iris, rose, cobalt, ember, carbon, paper (the warm editorial paper look), plus the classic presets github, vscode, material, solarized, tokyo, monokai, gruvbox, catppuccin; viewers can override it per-user; unknown slugs degrade to the viewer\'s dashboard theme), and an optional top-level icon shown on the dashboard Apps page, one of { type: "lucide", icon: "<kebab-case lucide icon name>", color?: "#RRGGBB" } (an unrecognized name shows a generic default), { type: "url", url: "https://..." } (https only, no credentials), or { type: "agent-fs", path: "/apps/<appId>/icon.png" } (swarm drive; add orgId and driveId for another drive); the dashboard shows a glyph when an image cannot load, and a patch replaces icon whole, then returns its dashboard URL. userConfig is versioned schema only; each user\'s values are stored separately, survive rollback, and schema changes are always compatible. Pages may bind a declared field read-only at exactly /user/<field>; pure and bound reusable elements must receive that value through a prop. Elements are private by default: pure elements read declared props, allow $item/$index inside repeats, may expose one leaf ElementSlot, and cannot invoke actions; bound elements may use the defining app\'s queries/actions, while exported bound elements cannot navigate. Prop kinds include enum with a required non-empty enum values array. Pages or elements reuse them with literal ElementRef targets, and cross-app refs require export: true. Zero-model pure-UI apps are valid. Pass appId to update; breaking a referenced export is blocked by the compatibility gate unless forceElementBreak explicitly names it.',
|
|
28
28
|
annotations: { destructiveHint: false },
|
|
29
29
|
inputSchema: z.object({
|
|
30
30
|
name: z.string().min(1).describe("Human-readable app name."),
|
|
@@ -10,7 +10,7 @@ export const registerListModelProfilesTool = (server: McpServer) => {
|
|
|
10
10
|
{
|
|
11
11
|
title: "List Model Profiles",
|
|
12
12
|
description:
|
|
13
|
-
"List model profiles: named harness + model + effort combinations. Pass a profile's name as `profile` on send-task to run that task on it, or set it as an agent's default through PATCH /api/agents/{id}/runtime. A profile runs only on its own harness. Filter by `harness` to see what an agent on that harness can run.",
|
|
13
|
+
"List model profiles: named harness + model + effort combinations. Pass a profile's name as `profile` on send-task to run that task on it, or set it as an agent's default through PATCH /api/agents/{id}/runtime. A profile runs only on its own harness. `fallbacks` are the same-harness profiles a task hops to, in order, when a provider error (rate limit, seat, overload, auth, empty key pool) ends it. Filter by `harness` to see what an agent on that harness can run.",
|
|
14
14
|
annotations: { readOnlyHint: true },
|
|
15
15
|
inputSchema: z.object({
|
|
16
16
|
harness: ProviderNameSchema.optional().describe(
|
|
@@ -26,6 +26,7 @@ export const registerListModelProfilesTool = (server: McpServer) => {
|
|
|
26
26
|
model: z.string().optional(),
|
|
27
27
|
effort: z.string().nullable().optional(),
|
|
28
28
|
description: z.string().nullable().optional(),
|
|
29
|
+
fallbacks: z.array(z.string()).optional(),
|
|
29
30
|
}),
|
|
30
31
|
)
|
|
31
32
|
.optional(),
|
|
@@ -35,7 +36,7 @@ export const registerListModelProfilesTool = (server: McpServer) => {
|
|
|
35
36
|
const profiles = await listModelProfiles({ harness });
|
|
36
37
|
const lines = profiles.map(
|
|
37
38
|
(p) =>
|
|
38
|
-
`${p.name}: ${p.harness} / ${p.model}${p.effort ? ` / effort ${p.effort}` : ""}${p.description ? ` (${p.description})` : ""}`,
|
|
39
|
+
`${p.name}: ${p.harness} / ${p.model}${p.effort ? ` / effort ${p.effort}` : ""}${p.fallbacks.length > 0 ? ` → fallbacks ${p.fallbacks.join(", ")}` : ""}${p.description ? ` (${p.description})` : ""}`,
|
|
39
40
|
);
|
|
40
41
|
return toolOk(`${profiles.length} model profile(s)${harness ? ` for ${harness}` : ""}.`, {
|
|
41
42
|
details: lines.join("\n"),
|
|
@@ -46,6 +47,7 @@ export const registerListModelProfilesTool = (server: McpServer) => {
|
|
|
46
47
|
model: p.model,
|
|
47
48
|
effort: p.effort,
|
|
48
49
|
description: p.description,
|
|
50
|
+
fallbacks: p.fallbacks,
|
|
49
51
|
})),
|
|
50
52
|
},
|
|
51
53
|
});
|
package/src/tools/script-run.ts
CHANGED
|
@@ -11,7 +11,7 @@ import {
|
|
|
11
11
|
} from "./script-common";
|
|
12
12
|
|
|
13
13
|
export const SCRIPT_RUN_DESCRIPTION =
|
|
14
|
-
"Run a named swarm-shared script (callable across agents and from workflow `swarm-script` nodes), OR inline source (auto-saved as scratch to the catalog). Inline source executes without the `script-upsert` compile-time typecheck. Use for swarm-visible, durable scripts. For local-only throwaway TS, use code-mode `run`.";
|
|
14
|
+
"Run a named swarm-shared script (callable across agents and from workflow `swarm-script` nodes), OR inline source (auto-saved as scratch to the catalog). Inline source executes without the `script-upsert` compile-time typecheck. Use for swarm-visible, durable scripts. For local-only throwaway TS, use code-mode `run`. The run ends when the script's default export resolves: a call it did not await gets 2 s more, then is stopped (native) or aborted at once (quickjs), so await every write that must land. A `Promise.race` deadline therefore bounds the run; a nested `script_run` that lost the race keeps running on the server under its own wall.";
|
|
15
15
|
|
|
16
16
|
function renderRunOutput(data: unknown): string | undefined {
|
|
17
17
|
if (typeof data !== "object" || data === null) return undefined;
|
|
@@ -159,7 +159,7 @@ export const registerUpdateProfileTool = (server: McpServer) => {
|
|
|
159
159
|
avatar: AgentAvatarSchema.nullable()
|
|
160
160
|
.optional()
|
|
161
161
|
.describe(
|
|
162
|
-
"Custom avatar: { type: 'lucide', icon: '<kebab-case-lucide-name>', color?: '#RRGGBB' }. Pass null to reset to the default deterministic icon/color.",
|
|
162
|
+
"Custom avatar, one of: { type: 'lucide', icon: '<kebab-case-lucide-name>', color?: '#RRGGBB' }; { type: 'url', url: 'https://…' } (https image, no credentials); { type: 'agent-fs', path: '/agents/<id>/avatar.png', orgId?, driveId? } (an image in agent-fs; pass both IDs or neither for the swarm drive). An image that cannot load falls back to the default glyph. Pass null to reset to the default deterministic icon/color.",
|
|
163
163
|
),
|
|
164
164
|
slackIcon: AgentSlackIconSchema.nullable()
|
|
165
165
|
.optional()
|
package/src/types.ts
CHANGED
|
@@ -488,11 +488,48 @@ export const ModelProfileSchema = z.object({
|
|
|
488
488
|
seededFrom: z.string().nullable(),
|
|
489
489
|
/** Pooled-key allowlist (column `credentialAllowlist`); null uses the whole pool. */
|
|
490
490
|
credentials: ModelProfileCredentialsSchema.nullable(),
|
|
491
|
+
/**
|
|
492
|
+
* Profiles on the same harness to hop to, in order, when a provider error
|
|
493
|
+
* (rate limit, seat, overload, auth, empty pool) ends a task running on
|
|
494
|
+
* this one. Empty: the task fails as before.
|
|
495
|
+
*/
|
|
496
|
+
fallbacks: z.array(z.string()),
|
|
491
497
|
createdAt: z.string(),
|
|
492
498
|
lastUpdatedAt: z.string(),
|
|
493
499
|
});
|
|
494
500
|
export type ModelProfile = z.infer<typeof ModelProfileSchema>;
|
|
495
501
|
|
|
502
|
+
/**
|
|
503
|
+
* Why a provider session ended in a way another profile may survive. Set by
|
|
504
|
+
* the worker's classifier (`src/commands/provider-error-class.ts`); never a
|
|
505
|
+
* task failure, tool error, context overflow, cancellation or budget refusal.
|
|
506
|
+
*/
|
|
507
|
+
export const ProviderErrorClassSchema = z.enum([
|
|
508
|
+
"rate_limit",
|
|
509
|
+
"model_window",
|
|
510
|
+
"seat",
|
|
511
|
+
"credits",
|
|
512
|
+
"overloaded",
|
|
513
|
+
"server_error",
|
|
514
|
+
"auth",
|
|
515
|
+
"pool_empty",
|
|
516
|
+
]);
|
|
517
|
+
export type ProviderErrorClass = z.infer<typeof ProviderErrorClassSchema>;
|
|
518
|
+
|
|
519
|
+
/**
|
|
520
|
+
* One same-agent fallback hop: the task left `from` on `errorClass` and its
|
|
521
|
+
* resume runs `profile`. `skipped` lists the fallbacks passed over because
|
|
522
|
+
* they failed the profile check on the agent.
|
|
523
|
+
*/
|
|
524
|
+
export const FallbackHopSchema = z.object({
|
|
525
|
+
from: z.string(),
|
|
526
|
+
profile: z.string(),
|
|
527
|
+
errorClass: ProviderErrorClassSchema,
|
|
528
|
+
at: z.string(),
|
|
529
|
+
skipped: z.array(z.object({ profile: z.string(), reason: z.string() })).optional(),
|
|
530
|
+
});
|
|
531
|
+
export type FallbackHop = z.infer<typeof FallbackHopSchema>;
|
|
532
|
+
|
|
496
533
|
/** One check's verdict: only `fail` blocks; `unverified` means nothing to judge yet. */
|
|
497
534
|
export const ProfileCheckStateSchema = z.enum(["pass", "warn", "fail", "unverified"]);
|
|
498
535
|
export type ProfileCheckState = z.infer<typeof ProfileCheckStateSchema>;
|
|
@@ -830,6 +867,9 @@ export const AgentTaskSchema = z
|
|
|
830
867
|
// the agent's default). Unset when no profile applied.
|
|
831
868
|
profile: z.string().optional(),
|
|
832
869
|
resolvedProfile: z.string().optional(),
|
|
870
|
+
// Provider-error fallback hops so far, oldest first; carried by every
|
|
871
|
+
// resume of the same work. Unset when the work never hopped.
|
|
872
|
+
fallbackHops: z.array(FallbackHopSchema).optional(),
|
|
833
873
|
|
|
834
874
|
// Schedule linking (optional — set when task was created by a schedule).
|
|
835
875
|
// z.string(): also reachable verbatim from the create-task query param.
|
|
@@ -962,6 +1002,8 @@ export const CreateTaskOptionsSchema = z.object({
|
|
|
962
1002
|
modelTier: ModelTierSchema.optional(),
|
|
963
1003
|
effort: ReasoningEffortSchema.optional(),
|
|
964
1004
|
profile: z.string().optional(),
|
|
1005
|
+
/** Internal: the fallback hops a resume carries over (`createResumeFollowUp`). */
|
|
1006
|
+
fallbackHops: z.array(FallbackHopSchema).optional(),
|
|
965
1007
|
scheduleId: z.string().optional(),
|
|
966
1008
|
workflowRunId: z.string().optional(),
|
|
967
1009
|
workflowRunStepId: z.string().optional(),
|
|
@@ -1309,32 +1351,80 @@ export type TaskTemplate = z.infer<typeof TaskTemplateSchema>;
|
|
|
1309
1351
|
|
|
1310
1352
|
export const AgentStatusSchema = z.enum(["idle", "busy", "offline", "waiting_for_credentials"]);
|
|
1311
1353
|
|
|
1312
|
-
//
|
|
1313
|
-
//
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
|
|
1320
|
-
.
|
|
1321
|
-
|
|
1322
|
-
|
|
1323
|
-
|
|
1354
|
+
// An https image link, shared by Slack icons and media icons so the rules
|
|
1355
|
+
// can't drift: https only, at most 2048 characters, no embedded credentials.
|
|
1356
|
+
export const HttpsImageUrlSchema = z
|
|
1357
|
+
.url({ protocol: /^https$/, error: "Must be an https:// URL" })
|
|
1358
|
+
.max(2048)
|
|
1359
|
+
.refine((value) => {
|
|
1360
|
+
try {
|
|
1361
|
+
const parsed = new URL(value);
|
|
1362
|
+
return !parsed.username && !parsed.password;
|
|
1363
|
+
} catch {
|
|
1364
|
+
return false;
|
|
1365
|
+
}
|
|
1366
|
+
}, "URL must be valid and contain no credentials");
|
|
1367
|
+
|
|
1368
|
+
// Server validates shape only; the UI owns the curated icon catalog and
|
|
1369
|
+
// deterministic fallback, so an unrecognized/hand-set icon name can never
|
|
1370
|
+
// break rendering.
|
|
1371
|
+
export const LucideIconSchema = z.object({
|
|
1372
|
+
type: z.literal("lucide"),
|
|
1373
|
+
icon: z
|
|
1374
|
+
.string()
|
|
1375
|
+
.regex(/^[a-z0-9-]+$/)
|
|
1376
|
+
.max(64),
|
|
1377
|
+
color: z
|
|
1378
|
+
.string()
|
|
1379
|
+
.regex(/^#[0-9a-fA-F]{6}$/)
|
|
1380
|
+
.optional(),
|
|
1381
|
+
});
|
|
1382
|
+
|
|
1383
|
+
export const UrlIconSchema = z.object({
|
|
1384
|
+
type: z.literal("url"),
|
|
1385
|
+
url: HttpsImageUrlSchema,
|
|
1386
|
+
});
|
|
1387
|
+
|
|
1388
|
+
// Same addressing as the agent-fs task attachment ref: an absolute path, plus
|
|
1389
|
+
// both `orgId` and `driveId` for a specific drive, or neither for the swarm
|
|
1390
|
+
// drive. A single ID is never mixed with the swarm defaults.
|
|
1391
|
+
export const AgentFsIconSchema = z
|
|
1392
|
+
.object({
|
|
1393
|
+
type: z.literal("agent-fs"),
|
|
1394
|
+
path: z
|
|
1324
1395
|
.string()
|
|
1325
|
-
.
|
|
1326
|
-
.
|
|
1327
|
-
|
|
1396
|
+
.min(2)
|
|
1397
|
+
.max(1024)
|
|
1398
|
+
.refine((value) => value.startsWith("/"), "Path must be absolute (start with /)")
|
|
1399
|
+
.refine((value) => !value.split("/").includes(".."), 'Path must not contain ".." segments'),
|
|
1400
|
+
orgId: z.string().min(1).optional(),
|
|
1401
|
+
driveId: z.string().min(1).optional(),
|
|
1402
|
+
})
|
|
1403
|
+
.refine(
|
|
1404
|
+
(value) => (value.orgId === undefined) === (value.driveId === undefined),
|
|
1405
|
+
"Pass both orgId and driveId, or neither for the swarm drive",
|
|
1406
|
+
);
|
|
1407
|
+
|
|
1408
|
+
// Discriminated union so future icon types can be added with zero migrations:
|
|
1409
|
+
// a new zod branch plus a UI renderer branch. Images that can't load fall back
|
|
1410
|
+
// to a lucide glyph in the dashboard.
|
|
1411
|
+
export const MediaIconSchema = z.discriminatedUnion("type", [
|
|
1412
|
+
LucideIconSchema,
|
|
1413
|
+
UrlIconSchema,
|
|
1414
|
+
AgentFsIconSchema,
|
|
1328
1415
|
]);
|
|
1329
|
-
export type
|
|
1416
|
+
export type MediaIcon = z.infer<typeof MediaIconSchema>;
|
|
1417
|
+
|
|
1418
|
+
// Agent avatars accept the same shapes as app icons.
|
|
1419
|
+
export const AgentAvatarSchema = MediaIconSchema;
|
|
1420
|
+
export type AgentAvatar = MediaIcon;
|
|
1330
1421
|
|
|
1331
1422
|
/**
|
|
1332
|
-
*
|
|
1333
|
-
*
|
|
1334
|
-
* sites self-documenting.
|
|
1423
|
+
* Icon shown for an app on the dashboard Apps page: a lucide glyph, an https
|
|
1424
|
+
* image link, or an image in agent-fs.
|
|
1335
1425
|
*/
|
|
1336
|
-
export const AppIconSchema =
|
|
1337
|
-
export type AppIcon =
|
|
1426
|
+
export const AppIconSchema = MediaIconSchema;
|
|
1427
|
+
export type AppIcon = MediaIcon;
|
|
1338
1428
|
|
|
1339
1429
|
// Separate from `avatar` so an agent can keep its lucide disc and still post
|
|
1340
1430
|
// to Slack with its own emoji or image.
|
|
@@ -1349,17 +1439,7 @@ export const AgentSlackIconSchema = z
|
|
|
1349
1439
|
}),
|
|
1350
1440
|
z.object({
|
|
1351
1441
|
type: z.literal("url"),
|
|
1352
|
-
url:
|
|
1353
|
-
.url({ protocol: /^https$/ })
|
|
1354
|
-
.max(2048)
|
|
1355
|
-
.refine((value) => {
|
|
1356
|
-
try {
|
|
1357
|
-
const parsed = new URL(value);
|
|
1358
|
-
return !parsed.username && !parsed.password;
|
|
1359
|
-
} catch {
|
|
1360
|
-
return false;
|
|
1361
|
-
}
|
|
1362
|
-
}, "URL must be valid and contain no credentials"),
|
|
1442
|
+
url: HttpsImageUrlSchema,
|
|
1363
1443
|
}),
|
|
1364
1444
|
// No icon override: Slack shows the app's own avatar.
|
|
1365
1445
|
z.object({ type: z.literal("app") }),
|
|
@@ -1432,7 +1512,8 @@ export const AgentSchema = z
|
|
|
1432
1512
|
.nullable()
|
|
1433
1513
|
.optional(),
|
|
1434
1514
|
|
|
1435
|
-
// Custom avatar
|
|
1515
|
+
// Custom avatar: a lucide glyph, an https image link, or an agent-fs image.
|
|
1516
|
+
// Null/missing = fall back to the
|
|
1436
1517
|
// deterministic hash-derived icon and color (see apps/ui/src/lib/agent-icon.ts
|
|
1437
1518
|
// and agent-color.ts). Migration 119 adds the column.
|
|
1438
1519
|
avatar: z
|
|
@@ -1787,6 +1868,7 @@ export const ResumeReasonSchema = z.enum([
|
|
|
1787
1868
|
"context_limits", // Provider session approaching context-window limits (Phase 6)
|
|
1788
1869
|
"manual_supersede", // Operator-triggered (e.g. dashboard button)
|
|
1789
1870
|
"crash_recovery", // Heartbeat sweep detected dead/stalled worker (DES-523)
|
|
1871
|
+
"provider_fallback", // Provider error; the resume runs the next fallback profile
|
|
1790
1872
|
]);
|
|
1791
1873
|
export type ResumeReason = z.infer<typeof ResumeReasonSchema>;
|
|
1792
1874
|
|
package/src/utils/constants.ts
CHANGED
|
@@ -273,6 +273,7 @@ export function isBrowserReachableUrl(value: string): boolean {
|
|
|
273
273
|
// IPv4-mapped `::ffff:a.b.c.d`: judge the embedded IPv4 address.
|
|
274
274
|
if (parsed.slice(0, 5).every((x) => x === 0) && g(5) === 0xffff) {
|
|
275
275
|
const a = g(6) >> 8;
|
|
276
|
+
if (a === 0) return false;
|
|
276
277
|
return a === 127 || !isPrivateIpv4(a, g(6) & 0xff);
|
|
277
278
|
}
|
|
278
279
|
return true;
|
|
@@ -280,6 +281,7 @@ export function isBrowserReachableUrl(value: string): boolean {
|
|
|
280
281
|
const octets = host.match(/^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/);
|
|
281
282
|
if (octets) {
|
|
282
283
|
const [a, b] = [Number(octets[1]), Number(octets[2])];
|
|
284
|
+
if (a === 0) return false;
|
|
283
285
|
return a === 127 || !isPrivateIpv4(a, b);
|
|
284
286
|
}
|
|
285
287
|
if (!host.includes(".")) return false;
|