@desplega.ai/agent-swarm 1.161.0 → 1.162.0
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 +3 -2
- package/dist/{acp-adapter-xx489vvb.js → acp-adapter-74m73ae9.js} +1 -1
- package/dist/{actions-ykjkn0m9.js → actions-4sr14gnt.js} +34 -31
- package/dist/{anthropic-messages-5qx80j9k.js → anthropic-messages-8xxrzky9.js} +22 -26
- package/dist/{app-0hdqa4k1.js → app-pt68fbwp.js} +13 -11
- package/dist/{artifact-3v5t9jtg.js → artifact-fey7dvj9.js} +3 -2
- package/dist/{assistant-am2g5g8a.js → assistant-cv3jytks.js} +37 -34
- package/dist/{azure-openai-responses-fszbkp0e.js → azure-openai-responses-f5cqsyj8.js} +15 -10
- package/dist/{boot-reembed-xy9t7avg.js → boot-reembed-4ht4gqth.js} +13 -11
- package/dist/{boot-reembed-gt5gjkt4.js → boot-reembed-nxpcvpj9.js} +12 -10
- package/dist/{boot-scrub-logs-9x0985y5.js → boot-scrub-logs-k93kyw8k.js} +9 -7
- package/dist/{boot-seeds-trv0d4vg.js → boot-seeds-1skcrs0e.js} +13 -10
- package/dist/{claude-adapter-jb6e1e54.js → claude-adapter-r5g0tzge.js} +23 -20
- package/dist/{claude-managed-setup-d1q9hv2b.js → claude-managed-setup-pkyrgshb.js} +3 -2
- package/dist/{claude-sdk-session-zga700s2.js → claude-sdk-session-jxyxnrwd.js} +5565 -5512
- package/dist/{cli-we0q7t0e.js → cli-2zy95vhm.js} +137 -64
- package/dist/{cli-35pj2yva.js → cli-4cwxn7gp.js} +38 -11
- package/dist/{cli-ad4qxm6j.js → cli-4dcpaefp.js} +2 -2
- package/dist/{cli-82c1pacn.js → cli-4x0csdjq.js} +71 -37
- package/dist/{cli-sqm3r5ps.js → cli-5bcd7sfy.js} +14 -18
- package/dist/{cli-d56tgd45.js → cli-5k6k8ta3.js} +2 -2
- package/dist/{cli-1er0rhz8.js → cli-5xhpb3kv.js} +15 -15
- package/dist/{cli-yrg7c73k.js → cli-7af8yhav.js} +10 -183
- package/dist/{cli-r6fsxc76.js → cli-7tre70zp.js} +513 -961
- package/dist/{cli-bh7jed3k.js → cli-8ev9xqnx.js} +34 -18
- package/dist/cli-bsky8g7w.js +449 -0
- package/dist/{cli-hn04t9db.js → cli-cebmgwsc.js} +14 -10
- package/dist/{cli-cfkrztza.js → cli-cvatsam7.js} +2 -2
- package/dist/{cli-2658f6at.js → cli-cvk6yzw5.js} +6 -8
- package/dist/{cli-ptr8h7kp.js → cli-eg0b3p0k.js} +5 -218
- package/dist/{cli-zb6xbk61.js → cli-g739zqzt.js} +4 -4
- package/dist/{cli-dv6cdjs2.js → cli-gd4favx9.js} +28 -7
- package/dist/{cli-5p3x4zna.js → cli-gpqpmns7.js} +2 -2
- package/dist/{cli-5nbmpy8w.js → cli-hb5c2x5y.js} +1 -1
- package/dist/{cli-jpf7e1zq.js → cli-hmsw1gpy.js} +3 -3
- package/dist/{cli-1cz0c18q.js → cli-jf7wmv1r.js} +2521 -733
- package/dist/{cli-qwsnmjdd.js → cli-jxs2ygaw.js} +168 -61
- package/dist/cli-kdkwd3yr.js +615 -0
- package/dist/{cli-hgmnf38m.js → cli-kh04eqwe.js} +1 -1
- package/dist/{cli-0383bp7f.js → cli-kp42yek0.js} +425 -90
- package/dist/{cli-ybgv4kw2.js → cli-mbssg1xv.js} +9 -2
- package/dist/{cli-jsp14b6c.js → cli-mzfth0bp.js} +38 -1
- package/dist/{cli-8g6mc14k.js → cli-nq7yqw7b.js} +16 -5
- package/dist/{cli-ee8bc46j.js → cli-nt8hecg9.js} +33 -32
- package/dist/{cli-9s68w752.js → cli-p0r8sxj5.js} +1 -1
- package/dist/{cli-58e8yr0d.js → cli-pkd6s2wy.js} +4 -2
- package/dist/{cli-17xpf7cm.js → cli-q24re23n.js} +6 -4
- package/dist/cli-qjjvzwzd.js +222 -0
- package/dist/cli-qrgt5bqf.js +189 -0
- package/dist/{cli-et8m9xsv.js → cli-rfjw9jw2.js} +22 -10
- package/dist/{cli-798vkbks.js → cli-rj0gqwwp.js} +2 -2
- package/dist/{cli-121ph74b.js → cli-rnyzn44p.js} +1 -1
- package/dist/{cli-vnnz5ncg.js → cli-s3hwpt9v.js} +95 -16
- package/dist/{cli-7119ja3w.js → cli-sptrj5f5.js} +2 -2
- package/dist/{cli-a8c82p2t.js → cli-sqvfa090.js} +13 -6
- package/dist/{cli-phfg8vy8.js → cli-swfmp1fx.js} +26 -26
- package/dist/{cli-nsdxtcbg.js → cli-tcen9p5w.js} +8 -5
- package/dist/{cli-9m03pzga.js → cli-vc9bp061.js} +5 -5
- package/dist/{cli-rtx9dygp.js → cli-vxe6qa4h.js} +1 -1
- package/dist/{cli-ecfxwnyb.js → cli-vy3ed88x.js} +1 -1
- package/dist/{cli-0c7ata9h.js → cli-vyqs9ya8.js} +6 -6
- package/dist/cli-wbvnn6tk.js +861 -0
- package/dist/{cli-kgd3p0bm.js → cli-wjgs5wxe.js} +6 -6
- package/dist/cli-wxkkd0e0.js +33 -0
- package/dist/{cli-akfj32vj.js → cli-xqpk3rp7.js} +5 -4
- package/dist/cli-zp38xvtm.js +9487 -0
- package/dist/{cli-3zc55ctx.js → cli-zvhd3f64.js} +2 -2
- package/dist/{cli-ze1d3wzv.js → cli-zxqx25nz.js} +5 -5
- package/dist/cli.js +32 -25
- package/dist/{cloudflare-workers-ai-system-one-k6fbxw9d.js → cloudflare-workers-ai-system-one-k8ddqjkq.js} +8 -6
- package/dist/{codex-adapter-04v97vep.js → codex-adapter-esvmnhn7.js} +13 -13
- package/dist/{codex-hook-20me6byw.js → codex-hook-m73jmqgx.js} +19 -3
- package/dist/{codex-session-runner-ax69mqq3.js → codex-session-runner-ban9excr.js} +13 -13
- package/dist/{commands-18gy08n1.js → commands-75413p2n.js} +9 -7
- package/dist/{db-d2pvjpyt.js → db-7f5pecwg.js} +11 -7
- package/dist/{dispatcher-8wbwyzjg.js → dispatcher-fh9at8nz.js} +33 -30
- package/dist/{dsh-adapter-ysqk9snv.js → dsh-adapter-wpze65d4.js} +3 -3
- package/dist/{e2b-esmt1r16.js → e2b-gjgdjp91.js} +10 -9
- package/dist/{pi-logo-animation-e9a0t68z.js → easter-egg-3d-3w5c2n4c.js} +122 -68
- package/dist/{execute-cmagrbrz.js → execute-f50wg9nh.js} +29 -6
- package/dist/{google-generative-ai-k6n5nbpp.js → google-generative-ai-jxxpnegy.js} +2 -2
- package/dist/{google-vertex-44xxtcvp.js → google-vertex-x7q1angm.js} +5 -5
- package/dist/{handlers-6b69m5kp.js → handlers-w13787bb.js} +36 -33
- package/dist/{hook-srnkt0hb.js → hook-46g1jrvx.js} +28 -15
- package/dist/{hook-k3mydf2n.js → hook-4tpts2ry.js} +20 -17
- package/dist/{http-hrf80ca1.js → http-19pzbfrt.js} +964 -176
- package/dist/{index-9rxdvj6w.js → index-8fd4dm4h.js} +34 -31
- package/dist/{index-1asbaj62.js → index-dqmp15bq.js} +35 -32
- package/dist/{index-45evq4ee.js → index-qb4q1y3e.js} +33 -30
- package/dist/{index-k4nj18qs.js → index-s75wc4wd.js} +12 -10
- package/dist/{index-xmevk2b9.js → index-scptvdxg.js} +27 -25
- package/dist/{keepalive-sfdz6ksp.js → keepalive-xa5ts9cd.js} +11 -9
- package/dist/{lead-ej91e9hw.js → lead-qp4xkvjq.js} +45 -41
- package/dist/{maintenance-80dnd7ke.js → maintenance-rm5885hm.js} +13 -11
- package/dist/{mistral-conversations-pc3ntnxt.js → mistral-conversations-rw7fbt22.js} +4 -4
- package/dist/{node-a5e00qhp.js → node-8zkdq42h.js} +834 -833
- package/dist/{oauth-refresh-sweep-m1etk2mx.js → oauth-refresh-sweep-1csdfebf.js} +10 -8
- package/dist/{onboard-0q8sdfqc.js → onboard-r6b78cs4.js} +10 -10
- package/dist/{openai-codex-responses-n7n683p2.js → openai-codex-responses-efvrgrq3.js} +4 -4
- package/dist/{openai-completions-jpaj5g2b.js → openai-completions-bbbrrz4z.js} +12 -8
- package/dist/{openai-responses-9a3nme9j.js → openai-responses-9jjyrcm1.js} +15 -10
- package/dist/{opencode-adapter-4wcgmvgf.js → opencode-adapter-kb3g6pkf.js} +2 -2
- package/dist/{otel-impl-hnqm9mxq.js → otel-impl-0y9knpky.js} +5 -5
- package/dist/{pi-mono-adapter-d6sqm9wr.js → pi-mono-adapter-z6s1bme2.js} +100 -19
- package/dist/{pricing-refresh-y60z64pm.js → pricing-refresh-mth26tgp.js} +11 -9
- package/dist/{rbac-roles-8pa0754b.js → rbac-roles-kwntb23q.js} +13 -9
- package/dist/rbac-roles-vpk4ebm8.js +45 -0
- package/dist/{registry-v5wytg0s.js → registry-km6t1jd2.js} +1 -1
- package/dist/{render-v2-418s1vj7.js → render-v2-hcm7h00y.js} +13 -11
- package/dist/{runtime-3pknc168.js → runtime-vfjsfsc5.js} +4 -4
- package/dist/{setup-yghdkj4x.js → setup-hbyzd65h.js} +2 -2
- package/dist/{virtual-modules-jcceevt5.js → virtual-modules-9bv7ry91.js} +9 -8
- package/dist/{work-objects-j1sz20v9.js → work-objects-m09sxnhe.js} +36 -33
- package/dist/{worker-d4gcvkjt.js → worker-0h35rvk4.js} +45 -41
- package/openapi.json +491 -12
- package/package.json +13 -6
- package/src/be/api-drain.ts +184 -0
- package/src/be/db/tasks/read.ts +31 -6
- package/src/be/db/tasks/write.ts +5 -4
- package/src/be/db.ts +42 -18
- package/src/be/memory/link-resolver.ts +29 -3
- package/src/be/migrations/192_favorites_agent_fs_path.sql +36 -0
- package/src/be/onboarding.ts +7 -1
- package/src/be/seed-prompt-templates.ts +1 -0
- package/src/be/swarm-config-guard.ts +35 -16
- package/src/be/task-citations.ts +11 -5
- package/src/be/users.ts +3 -0
- package/src/cli.tsx +3 -2
- package/src/comb/agent-fs.ts +39 -0
- package/src/comb/config.ts +37 -0
- package/src/comb/markers.ts +37 -0
- package/src/comb/review-batch.ts +486 -0
- package/src/comb/templates.ts +88 -0
- package/src/commands/context-preamble.ts +4 -1
- package/src/commands/hook.ts +2 -1
- package/src/commands/runner.ts +262 -68
- package/src/commands/templates.ts +10 -0
- package/src/extensions/contract-types.generated.ts +1 -1
- package/src/fs/agent-fs-provider.ts +106 -2
- package/src/heartbeat/heartbeat.ts +4 -0
- package/src/hooks/codex-hook.ts +25 -1
- package/src/hooks/hook.ts +13 -0
- package/src/hooks/pr-body-guard.ts +983 -0
- package/src/http/all-routes.ts +1 -0
- package/src/http/assets.ts +5 -17
- package/src/http/comb.ts +131 -0
- package/src/http/core.ts +2 -1
- package/src/http/fs.ts +9 -17
- package/src/http/index.ts +23 -9
- package/src/http/onboarding.ts +21 -2
- package/src/http/poll.ts +30 -3
- package/src/http/realtime.ts +62 -0
- package/src/http/request-principal.ts +22 -0
- package/src/http/status.ts +34 -2
- package/src/kv-reserved-namespaces.ts +10 -5
- package/src/providers/dsh-adapter.ts +1 -1
- package/src/providers/pi-mono-adapter.ts +123 -0
- package/src/rbac/legacy-policy.ts +1 -0
- package/src/rbac/permissions.ts +4 -0
- package/src/realtime/auth.ts +63 -1
- package/src/realtime/tickets.ts +52 -0
- package/src/realtime/transport.ts +51 -22
- package/src/scripts-runtime/types/swarm-extension.d.ts +3 -1
- package/src/telemetry-context.ts +175 -0
- package/src/telemetry-contract/EVENTS.md +81 -0
- package/src/telemetry-contract/SOURCE.json +9 -0
- package/src/telemetry-contract/catalog.json +1335 -0
- package/src/telemetry-contract/index.ts +60 -0
- package/src/telemetry-contract/types.gen.ts +1971 -0
- package/src/telemetry-identity.ts +129 -0
- package/src/telemetry-snapshot.ts +211 -0
- package/src/telemetry-trigger.ts +125 -0
- package/src/telemetry-types.typetest.ts +40 -0
- package/src/telemetry.ts +271 -67
- package/src/tests/api-drain-e2e.test.ts +249 -0
- package/src/tests/api-drain-worker-e2e.test.ts +216 -0
- package/src/tests/api-drain.test.ts +351 -0
- package/src/tests/comb-config-guard.test.ts +38 -0
- package/src/tests/comb-links.test.ts +162 -0
- package/src/tests/comb-markers.test.ts +68 -0
- package/src/tests/comb-review-batch.test.ts +770 -0
- package/src/tests/comb-status.test.ts +152 -0
- package/src/tests/db-task-read-contract.test.ts +2 -0
- package/src/tests/db-task-write-contract.test.ts +1 -0
- package/src/tests/docs-index-footprint.test.js +3 -3
- package/src/tests/dsh-adapter.test.ts +1 -1
- package/src/tests/favorites-agent-fs-path.test.ts +226 -0
- package/src/tests/memory-link-resolver.test.ts +34 -0
- package/src/tests/onboarding.test.ts +108 -0
- package/src/tests/pi-mono-adapter.test.ts +265 -2
- package/src/tests/pr-body-leaks.test.ts +789 -0
- package/src/tests/preload.ts +8 -0
- package/src/tests/rbac-engine.test.ts +19 -0
- package/src/tests/realtime-room-auth.test.ts +104 -1
- package/src/tests/realtime-tickets.test.ts +74 -0
- package/src/tests/realtime-transport.test.ts +131 -4
- package/src/tests/runner-api-drain.test.ts +301 -0
- package/src/tests/runner-fallback-output.test.ts +61 -0
- package/src/tests/runner-fenced-json-output.test.ts +178 -0
- package/src/tests/script-connections.test.ts +2 -0
- package/src/tests/send-task-requested-by.test.ts +133 -15
- package/src/tests/task-lifecycle-telemetry.test.ts +8 -3
- package/src/tests/telemetry-context.test.ts +314 -0
- package/src/tests/telemetry-init.test.ts +51 -19
- package/src/tests/telemetry-snapshot.test.ts +229 -0
- package/src/tests/telemetry-trigger.test.ts +200 -0
- package/src/tests/template-registry-helpers.ts +1 -0
- package/src/tests/workflow-agent-task-retry.test.ts +363 -0
- package/src/tests/workflow-definition-telemetry.test.ts +4 -4
- package/src/tools/poll-task.ts +20 -1
- package/src/tools/send-task.ts +9 -1
- package/src/tools/task-action.ts +11 -0
- package/src/types.ts +2 -1
- package/src/utils/api-drain.ts +24 -0
- package/src/utils/constants.ts +57 -16
- package/src/utils/pr-body-leaks.ts +172 -0
- package/src/utils/task-attachment-links.ts +14 -8
- package/src/workflows/recovery.ts +26 -1
- package/src/workflows/resume.ts +31 -4
- package/src/workflows/task-step-routing.ts +75 -2
- package/tsconfig.json +3 -0
- package/dist/cli-tjf4cn8z.js +0 -9119
- package/dist/cli-tsk3nz8a.js +0 -582
- package/dist/{cli-t6v2ah3r.js → cli-twrh04ap.js} +3 -3
package/src/tests/preload.ts
CHANGED
|
@@ -22,6 +22,14 @@ import { startHangWatchdog } from "./hang-watchdog";
|
|
|
22
22
|
|
|
23
23
|
startHangWatchdog();
|
|
24
24
|
|
|
25
|
+
// The API drain (src/be/api-drain.ts) is off unless API_DRAIN_MAX_MS is set,
|
|
26
|
+
// but a shell can inherit it (a swarm worker container gets the deploy's value).
|
|
27
|
+
// Test servers are stopped with SIGTERM and their fixtures leave in_progress rows
|
|
28
|
+
// on fresh agents, so an inherited cap would make every teardown wait it out.
|
|
29
|
+
// Force it off here; spawned servers inherit this, and suites that exercise the
|
|
30
|
+
// drain set API_DRAIN_MAX_MS for their own server.
|
|
31
|
+
process.env.API_DRAIN_MAX_MS = "0";
|
|
32
|
+
|
|
25
33
|
// @hono/node-server (pulled in transitively by @modelcontextprotocol/sdk's
|
|
26
34
|
// streamableHttp transport) replaces globalThis.Response/Request with its own
|
|
27
35
|
// lightweight Node-adapter classes the first time getRequestListener() runs.
|
|
@@ -88,6 +88,7 @@ const LEAD_OR_OPERATOR_OR_USER_VERBS: PermissionVerb[] = [
|
|
|
88
88
|
"extension.activate",
|
|
89
89
|
"extension.install.inline",
|
|
90
90
|
];
|
|
91
|
+
const OPERATOR_OR_USER_VERBS: PermissionVerb[] = ["comb.presence"];
|
|
91
92
|
|
|
92
93
|
const LEAD_OR_OPERATOR_VERBS: PermissionVerb[] = ["models.catalog.write"];
|
|
93
94
|
|
|
@@ -192,6 +193,7 @@ describe("verb-group partition", () => {
|
|
|
192
193
|
...COMPOSITE_VERBS,
|
|
193
194
|
...OPERATOR_ONLY_VERBS,
|
|
194
195
|
...LEAD_OR_OPERATOR_OR_USER_VERBS,
|
|
196
|
+
...OPERATOR_OR_USER_VERBS,
|
|
195
197
|
...LEAD_OR_OPERATOR_VERBS,
|
|
196
198
|
...AGENT_OR_OPERATOR_VERBS,
|
|
197
199
|
];
|
|
@@ -273,6 +275,23 @@ describe("lead-or-operator-or-user verbs", () => {
|
|
|
273
275
|
}
|
|
274
276
|
});
|
|
275
277
|
|
|
278
|
+
describe("operator-or-user verbs", () => {
|
|
279
|
+
const expected: Expected = {
|
|
280
|
+
lead: false,
|
|
281
|
+
worker: false,
|
|
282
|
+
ownerWorker: false,
|
|
283
|
+
creatorWorker: false,
|
|
284
|
+
userRequester: true,
|
|
285
|
+
foreignUser: true,
|
|
286
|
+
operator: true,
|
|
287
|
+
};
|
|
288
|
+
for (const verb of OPERATOR_OR_USER_VERBS) {
|
|
289
|
+
test(`${verb}: the operator or a dashboard user allowed, agents denied`, () => {
|
|
290
|
+
expectDecisions(verb, { kind: "none" }, expected);
|
|
291
|
+
});
|
|
292
|
+
}
|
|
293
|
+
});
|
|
294
|
+
|
|
276
295
|
describe("agent-or-operator verbs", () => {
|
|
277
296
|
const expected: Expected = {
|
|
278
297
|
lead: true,
|
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
import { describe, expect, test } from "bun:test";
|
|
2
2
|
import type { IncomingMessage } from "node:http";
|
|
3
|
-
import {
|
|
3
|
+
import {
|
|
4
|
+
isReservedNamespace,
|
|
5
|
+
reservedNamespaceError,
|
|
6
|
+
reservedRoomKeyError,
|
|
7
|
+
} from "../kv-reserved-namespaces";
|
|
8
|
+
import { can } from "../rbac";
|
|
4
9
|
import { authorizeRoomNamespace, resolveRoomNamespace, roomRequestInfo } from "../realtime/auth";
|
|
5
10
|
|
|
6
11
|
describe("realtime room namespace guards", () => {
|
|
@@ -29,6 +34,104 @@ describe("realtime room namespace guards", () => {
|
|
|
29
34
|
expect(isReservedNamespace("apps:demo")).toBe(true);
|
|
30
35
|
});
|
|
31
36
|
|
|
37
|
+
test("reserves the comb namespace family for Comb's send claims", () => {
|
|
38
|
+
expect(isReservedNamespace("comb")).toBe(true);
|
|
39
|
+
expect(isReservedNamespace("comb:sent")).toBe(true);
|
|
40
|
+
expect(reservedNamespaceError("comb:sent")).toContain("Comb");
|
|
41
|
+
expect(reservedNamespaceError("apps")).toContain("swarm apps");
|
|
42
|
+
expect(isReservedNamespace("combo")).toBe(false);
|
|
43
|
+
expect(isReservedNamespace("user:comb")).toBe(false);
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
test("limits Comb presence namespaces to dashboard presence operations", async () => {
|
|
47
|
+
const keys = [
|
|
48
|
+
"RBAC_ENABLED",
|
|
49
|
+
"COMB_ENABLED",
|
|
50
|
+
"AGENT_FS_API_URL",
|
|
51
|
+
"AGENT_FS_DEFAULT_ORG_ID",
|
|
52
|
+
"AGENT_FS_DEFAULT_DRIVE_ID",
|
|
53
|
+
] as const;
|
|
54
|
+
const previous = Object.fromEntries(keys.map((key) => [key, process.env[key]]));
|
|
55
|
+
process.env.RBAC_ENABLED = "false";
|
|
56
|
+
process.env.COMB_ENABLED = "true";
|
|
57
|
+
process.env.AGENT_FS_API_URL = "http://agent-fs.test";
|
|
58
|
+
process.env.AGENT_FS_DEFAULT_ORG_ID = "org_123";
|
|
59
|
+
process.env.AGENT_FS_DEFAULT_DRIVE_ID = "drive-456";
|
|
60
|
+
const namespace = "presence:comb:org_123:drive-456";
|
|
61
|
+
try {
|
|
62
|
+
// Only the configured drive, and only while Comb is on.
|
|
63
|
+
await expect(
|
|
64
|
+
authorizeRoomNamespace(
|
|
65
|
+
"presence:comb:org_123:other-drive",
|
|
66
|
+
{ isOperator: true, callOrigin: "ws" },
|
|
67
|
+
"join",
|
|
68
|
+
),
|
|
69
|
+
).resolves.toContain("configured Comb drive");
|
|
70
|
+
process.env.COMB_ENABLED = "false";
|
|
71
|
+
await expect(
|
|
72
|
+
authorizeRoomNamespace(namespace, { isOperator: true, callOrigin: "ws" }, "join"),
|
|
73
|
+
).resolves.toBe("Comb is off");
|
|
74
|
+
process.env.COMB_ENABLED = "true";
|
|
75
|
+
await expect(
|
|
76
|
+
authorizeRoomNamespace(namespace, { isOperator: true, callOrigin: "ws" }, "join"),
|
|
77
|
+
).resolves.toBeNull();
|
|
78
|
+
await expect(
|
|
79
|
+
authorizeRoomNamespace(namespace, { userId: "user-1", callOrigin: "ws" }, "presence"),
|
|
80
|
+
).resolves.toBeNull();
|
|
81
|
+
await expect(
|
|
82
|
+
authorizeRoomNamespace(namespace, { isOperator: true, callOrigin: "ws" }, "update"),
|
|
83
|
+
).resolves.toContain("only allow");
|
|
84
|
+
await expect(
|
|
85
|
+
authorizeRoomNamespace(namespace, { isOperator: true, callOrigin: "ws" }, "publish"),
|
|
86
|
+
).resolves.toContain("only allow");
|
|
87
|
+
await expect(
|
|
88
|
+
authorizeRoomNamespace(namespace, { agentId: "agent-1", callOrigin: "ws" }, "join"),
|
|
89
|
+
).resolves.toContain("dashboard authentication");
|
|
90
|
+
await expect(
|
|
91
|
+
authorizeRoomNamespace(
|
|
92
|
+
namespace,
|
|
93
|
+
{ pageId: "page-1", userId: "user-1", callOrigin: "ws" },
|
|
94
|
+
"join",
|
|
95
|
+
),
|
|
96
|
+
).resolves.toContain("dashboard authentication");
|
|
97
|
+
await expect(
|
|
98
|
+
authorizeRoomNamespace(
|
|
99
|
+
"presence:comb:org:drive:extra",
|
|
100
|
+
{ isOperator: true, callOrigin: "ws" },
|
|
101
|
+
"join",
|
|
102
|
+
),
|
|
103
|
+
).resolves.toContain("invalid");
|
|
104
|
+
} finally {
|
|
105
|
+
for (const key of keys) {
|
|
106
|
+
if (previous[key] === undefined) delete process.env[key];
|
|
107
|
+
else process.env[key] = previous[key];
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
test("allows Comb presence for humans and denies agents in the legacy policy", () => {
|
|
113
|
+
const resource = { kind: "kv-namespace", namespace: "presence:comb:org:drive" } as const;
|
|
114
|
+
expect(
|
|
115
|
+
can({ principal: { kind: "operator" }, verb: "comb.presence", resource, source: "http" }),
|
|
116
|
+
).toEqual({ allow: true });
|
|
117
|
+
expect(
|
|
118
|
+
can({
|
|
119
|
+
principal: { kind: "user", userId: "user-1" },
|
|
120
|
+
verb: "comb.presence",
|
|
121
|
+
resource,
|
|
122
|
+
source: "http",
|
|
123
|
+
}),
|
|
124
|
+
).toEqual({ allow: true });
|
|
125
|
+
expect(
|
|
126
|
+
can({
|
|
127
|
+
principal: { kind: "agent", agentId: "agent-1", isLead: true },
|
|
128
|
+
verb: "comb.presence",
|
|
129
|
+
resource,
|
|
130
|
+
source: "http",
|
|
131
|
+
}),
|
|
132
|
+
).toMatchObject({ allow: false, missing: "comb.presence" });
|
|
133
|
+
});
|
|
134
|
+
|
|
32
135
|
test("does not trust an agent header from a user bearer request", () => {
|
|
33
136
|
const req = {
|
|
34
137
|
headers: { "x-agent-id": "spoofed-agent" },
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { afterEach, describe, expect, test } from "bun:test";
|
|
2
|
+
import type { IncomingMessage, ServerResponse } from "node:http";
|
|
3
|
+
import { handleRealtimeTicket } from "../http/realtime";
|
|
4
|
+
import {
|
|
5
|
+
issueRealtimeTicket,
|
|
6
|
+
REALTIME_TICKET_CAPACITY,
|
|
7
|
+
REALTIME_TICKET_TTL_MS,
|
|
8
|
+
redeemRealtimeTicket,
|
|
9
|
+
sweepRealtimeTickets,
|
|
10
|
+
} from "../realtime/tickets";
|
|
11
|
+
|
|
12
|
+
const auth = { kind: "operator", fingerprint: "test-operator" } as const;
|
|
13
|
+
|
|
14
|
+
afterEach(() => {
|
|
15
|
+
sweepRealtimeTickets(Number.MAX_SAFE_INTEGER);
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
describe("realtime tickets", () => {
|
|
19
|
+
test("issues URL-safe tickets with at least 128 bits and redeems once", () => {
|
|
20
|
+
const issued = issueRealtimeTicket(auth, 1_000);
|
|
21
|
+
|
|
22
|
+
expect(issued.ticket).toMatch(/^[A-Za-z0-9_-]+$/);
|
|
23
|
+
expect(Buffer.from(issued.ticket, "base64url")).toHaveLength(24);
|
|
24
|
+
expect(issued.expiresAt).toBe(1_000 + REALTIME_TICKET_TTL_MS);
|
|
25
|
+
expect(redeemRealtimeTicket(issued.ticket, 1_001)).toEqual(auth);
|
|
26
|
+
expect(redeemRealtimeTicket(issued.ticket, 1_002)).toBeNull();
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
test("rejects expired tickets and sweeps expired entries", () => {
|
|
30
|
+
const expired = issueRealtimeTicket(auth, 2_000);
|
|
31
|
+
const swept = issueRealtimeTicket(auth, 3_000);
|
|
32
|
+
|
|
33
|
+
expect(redeemRealtimeTicket(expired.ticket, expired.expiresAt)).toBeNull();
|
|
34
|
+
expect(sweepRealtimeTickets(swept.expiresAt)).toBe(1);
|
|
35
|
+
expect(redeemRealtimeTicket(swept.ticket, swept.expiresAt)).toBeNull();
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
test("evicts the oldest ticket when the size cap is reached", () => {
|
|
39
|
+
const oldest = issueRealtimeTicket(auth, 4_000);
|
|
40
|
+
let newest = oldest;
|
|
41
|
+
for (let index = 0; index < REALTIME_TICKET_CAPACITY; index++) {
|
|
42
|
+
newest = issueRealtimeTicket(auth, 4_000);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
expect(redeemRealtimeTicket(oldest.ticket, 4_001)).toBeNull();
|
|
46
|
+
expect(redeemRealtimeTicket(newest.ticket, 4_001)).toEqual(auth);
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
test("the ticket route answers 404 while Comb is off", async () => {
|
|
50
|
+
const previous = process.env.COMB_ENABLED;
|
|
51
|
+
process.env.COMB_ENABLED = "false";
|
|
52
|
+
try {
|
|
53
|
+
let status = 0;
|
|
54
|
+
const res = {
|
|
55
|
+
writeHead: (code: number) => {
|
|
56
|
+
status = code;
|
|
57
|
+
},
|
|
58
|
+
end: () => {},
|
|
59
|
+
} as unknown as ServerResponse;
|
|
60
|
+
const req = { method: "POST", headers: {} } as IncomingMessage;
|
|
61
|
+
const handled = await handleRealtimeTicket(
|
|
62
|
+
req,
|
|
63
|
+
res,
|
|
64
|
+
["api", "realtime", "ticket"],
|
|
65
|
+
new URLSearchParams(),
|
|
66
|
+
);
|
|
67
|
+
expect(handled).toBe(true);
|
|
68
|
+
expect(status).toBe(404);
|
|
69
|
+
} finally {
|
|
70
|
+
if (previous === undefined) delete process.env.COMB_ENABLED;
|
|
71
|
+
else process.env.COMB_ENABLED = previous;
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
});
|
|
@@ -13,6 +13,10 @@ type SocketHeaders = Record<string, string>;
|
|
|
13
13
|
const dbPath = `/tmp/test-realtime-transport-${Date.now()}-${randomUUID()}.sqlite`;
|
|
14
14
|
const apiKey = `realtime-test-${randomUUID()}`;
|
|
15
15
|
const pageSecret = `realtime-page-secret-${randomUUID()}`;
|
|
16
|
+
// Comb presence only opens for the configured drive while Comb is on.
|
|
17
|
+
const combOrgId = randomUUID();
|
|
18
|
+
const combDriveId = randomUUID();
|
|
19
|
+
const combNamespace = `presence:comb:${combOrgId}:${combDriveId}`;
|
|
16
20
|
let baseUrl = "";
|
|
17
21
|
let socketUrl = "";
|
|
18
22
|
let server: Subprocess;
|
|
@@ -90,6 +94,14 @@ async function createUserToken(name: string): Promise<{ id: string; token: strin
|
|
|
90
94
|
return { id: userId!, token: token! };
|
|
91
95
|
}
|
|
92
96
|
|
|
97
|
+
async function issueTicket(token = apiKey): Promise<{ ticket: string; expiresAt: number }> {
|
|
98
|
+
const response = await api("POST", "/api/realtime/ticket", {
|
|
99
|
+
headers: { Authorization: `Bearer ${token}` },
|
|
100
|
+
});
|
|
101
|
+
expect(response.status).toBe(200);
|
|
102
|
+
return (await response.json()) as { ticket: string; expiresAt: number };
|
|
103
|
+
}
|
|
104
|
+
|
|
93
105
|
async function launchPageAsUser(pageId: string, token: string): Promise<string> {
|
|
94
106
|
const response = await api("POST", `/api/pages/${pageId}/launch`, {
|
|
95
107
|
headers: { Authorization: `Bearer ${token}` },
|
|
@@ -193,10 +205,7 @@ function openSocket(
|
|
|
193
205
|
waiter.reject(error);
|
|
194
206
|
}
|
|
195
207
|
});
|
|
196
|
-
handshakeTimer = setTimeout(
|
|
197
|
-
() => fail(new Error(`WebSocket handshake failed: ${target}`)),
|
|
198
|
-
5_000,
|
|
199
|
-
);
|
|
208
|
+
handshakeTimer = setTimeout(() => fail(new Error("WebSocket handshake failed")), 5_000);
|
|
200
209
|
});
|
|
201
210
|
}
|
|
202
211
|
|
|
@@ -274,6 +283,10 @@ beforeAll(async () => {
|
|
|
274
283
|
JIRA_DISABLE: "true",
|
|
275
284
|
AGENTMAIL_DISABLE: "true",
|
|
276
285
|
OAUTH_KEEPALIVE_DISABLE: "true",
|
|
286
|
+
COMB_ENABLED: "true",
|
|
287
|
+
AGENT_FS_API_URL: "http://127.0.0.1:9",
|
|
288
|
+
AGENT_FS_DEFAULT_ORG_ID: combOrgId,
|
|
289
|
+
AGENT_FS_DEFAULT_DRIVE_ID: combDriveId,
|
|
277
290
|
},
|
|
278
291
|
stdout: "ignore",
|
|
279
292
|
stderr: "ignore",
|
|
@@ -470,6 +483,10 @@ describe("realtime transport", () => {
|
|
|
470
483
|
JIRA_DISABLE: "true",
|
|
471
484
|
AGENTMAIL_DISABLE: "true",
|
|
472
485
|
OAUTH_KEEPALIVE_DISABLE: "true",
|
|
486
|
+
COMB_ENABLED: "true",
|
|
487
|
+
AGENT_FS_API_URL: "http://127.0.0.1:9",
|
|
488
|
+
AGENT_FS_DEFAULT_ORG_ID: combOrgId,
|
|
489
|
+
AGENT_FS_DEFAULT_DRIVE_ID: combDriveId,
|
|
473
490
|
},
|
|
474
491
|
stdout: "ignore",
|
|
475
492
|
stderr: "ignore",
|
|
@@ -544,6 +561,116 @@ describe("realtime transport", () => {
|
|
|
544
561
|
const result = await join(client, 1, "agent-room", `task:agent:${agentId}`);
|
|
545
562
|
expect(result.me.userId).toBe(agentId);
|
|
546
563
|
expect(result.me.kind).toBe("agent");
|
|
564
|
+
// Creating a room in another agent's namespace is a write, so a worker is refused.
|
|
565
|
+
client.send({
|
|
566
|
+
id: 2,
|
|
567
|
+
op: "join",
|
|
568
|
+
name: "agent-room",
|
|
569
|
+
namespace: `task:agent:${randomUUID()}`,
|
|
570
|
+
schemaVersion: 1,
|
|
571
|
+
});
|
|
572
|
+
const denied = await client.next((frame) => frame.type === "error" && frame.id === 2);
|
|
573
|
+
expect(denied.error).toContain("require lead");
|
|
574
|
+
} finally {
|
|
575
|
+
await closeSocket(client);
|
|
576
|
+
}
|
|
577
|
+
});
|
|
578
|
+
|
|
579
|
+
test("uses one-shot dashboard tickets for Comb presence on the API alias", async () => {
|
|
580
|
+
const viewer = await createUserToken("Comb Realtime Viewer");
|
|
581
|
+
const operatorTicket = await issueTicket();
|
|
582
|
+
const userTicket = await issueTicket(viewer.token);
|
|
583
|
+
const aliasUrl = socketUrl.replace("/@swarm/realtime", "/api/realtime");
|
|
584
|
+
const operator = await openSocket({}, `${aliasUrl}?ticket=${operatorTicket.ticket}`);
|
|
585
|
+
const user = await openSocket({}, `${socketUrl}?ticket=${userTicket.ticket}`);
|
|
586
|
+
const namespace = combNamespace;
|
|
587
|
+
try {
|
|
588
|
+
const operatorHello = await operator.next((frame) => frame.type === "hello");
|
|
589
|
+
expect(operatorHello.me).toMatchObject({ kind: "guest" });
|
|
590
|
+
const userHello = await user.next((frame) => frame.type === "hello");
|
|
591
|
+
expect(userHello.me).toMatchObject({
|
|
592
|
+
userId: viewer.id,
|
|
593
|
+
name: "Comb Realtime Viewer",
|
|
594
|
+
kind: "user",
|
|
595
|
+
});
|
|
596
|
+
|
|
597
|
+
const operatorJoined = await join(operator, 1, "default", namespace);
|
|
598
|
+
await join(user, 2, "default", namespace);
|
|
599
|
+
user.send({
|
|
600
|
+
id: 3,
|
|
601
|
+
op: "presence",
|
|
602
|
+
name: "default",
|
|
603
|
+
namespace,
|
|
604
|
+
data: { file: { path: "notes.md" }, pointer: { line: 4 } },
|
|
605
|
+
});
|
|
606
|
+
await user.next((frame) => frame.type === "result" && frame.id === 3);
|
|
607
|
+
const shared = await operator.next(
|
|
608
|
+
(frame) =>
|
|
609
|
+
frame.type === "presence" &&
|
|
610
|
+
frame.namespace === namespace &&
|
|
611
|
+
Array.isArray(frame.peers) &&
|
|
612
|
+
frame.peers.some(
|
|
613
|
+
(peer: Frame) => peer.userId === viewer.id && peer.data?.file?.path === "notes.md",
|
|
614
|
+
),
|
|
615
|
+
);
|
|
616
|
+
expect(shared.peers).toHaveLength(2);
|
|
617
|
+
|
|
618
|
+
operator.send({ id: 4, op: "update", name: "default", namespace });
|
|
619
|
+
const updateDenied = await operator.next((frame) => frame.type === "error" && frame.id === 4);
|
|
620
|
+
expect(updateDenied.error).toContain("only allow");
|
|
621
|
+
operator.send({ id: 5, op: "publish", name: "default", namespace, data: {} });
|
|
622
|
+
const publishDenied = await operator.next(
|
|
623
|
+
(frame) => frame.type === "error" && frame.id === 5,
|
|
624
|
+
);
|
|
625
|
+
expect(publishDenied.error).toContain("only allow");
|
|
626
|
+
operator.send({ id: 6, op: "join", name: "default", namespace: "comb:sent" });
|
|
627
|
+
const reservedDenied = await operator.next(
|
|
628
|
+
(frame) => frame.type === "error" && frame.id === 6,
|
|
629
|
+
);
|
|
630
|
+
expect(reservedDenied.error).toContain("reserved for Comb");
|
|
631
|
+
operator.send({ id: 7, op: "join", name: "another", namespace });
|
|
632
|
+
const roomDenied = await operator.next((frame) => frame.type === "error" && frame.id === 7);
|
|
633
|
+
expect(roomDenied.error).toContain("default room");
|
|
634
|
+
operator.send({
|
|
635
|
+
id: 8,
|
|
636
|
+
op: "join",
|
|
637
|
+
name: "default",
|
|
638
|
+
namespace: `presence:comb:${combOrgId}:${randomUUID()}`,
|
|
639
|
+
});
|
|
640
|
+
const driveDenied = await operator.next((frame) => frame.type === "error" && frame.id === 8);
|
|
641
|
+
expect(driveDenied.error).toContain("configured Comb drive");
|
|
642
|
+
|
|
643
|
+
await closeSocket(operator);
|
|
644
|
+
const left = await user.next(
|
|
645
|
+
(frame) =>
|
|
646
|
+
frame.type === "presence" &&
|
|
647
|
+
frame.namespace === namespace &&
|
|
648
|
+
Array.isArray(frame.peers) &&
|
|
649
|
+
!frame.peers.some((peer: Frame) => peer.userId === operatorJoined.me.userId),
|
|
650
|
+
);
|
|
651
|
+
expect(left.peers).toHaveLength(1);
|
|
652
|
+
} finally {
|
|
653
|
+
await closeSocket(operator);
|
|
654
|
+
await closeSocket(user);
|
|
655
|
+
}
|
|
656
|
+
});
|
|
657
|
+
|
|
658
|
+
test("refuses agent access to Comb presence namespaces", async () => {
|
|
659
|
+
const agentId = await registerAgent();
|
|
660
|
+
const client = await openSocket({
|
|
661
|
+
Authorization: `Bearer ${apiKey}`,
|
|
662
|
+
"X-Agent-ID": agentId,
|
|
663
|
+
Origin: baseUrl,
|
|
664
|
+
});
|
|
665
|
+
try {
|
|
666
|
+
client.send({
|
|
667
|
+
id: 1,
|
|
668
|
+
op: "join",
|
|
669
|
+
name: "default",
|
|
670
|
+
namespace: combNamespace,
|
|
671
|
+
});
|
|
672
|
+
const denied = await client.next((frame) => frame.type === "error" && frame.id === 1);
|
|
673
|
+
expect(denied.error).toContain("dashboard authentication");
|
|
547
674
|
} finally {
|
|
548
675
|
await closeSocket(client);
|
|
549
676
|
}
|