@desplega.ai/agent-swarm 2.13.1 → 2.13.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/README.md +1 -1
- package/dist/{acp-adapter-xtj40wd8.js → acp-adapter-x1qqgzwx.js} +5 -5
- package/dist/{acp-targets-n7vm5atw.js → acp-targets-mz8c5dnt.js} +4 -4
- package/dist/{actions-hq6wp9xv.js → actions-5ft3qp5a.js} +25 -25
- package/dist/{agent-fs-provision-y0qc1rdd.js → agent-fs-provision-6fgz7wvz.js} +4 -4
- package/dist/{amp-adapter-1qqs6h91.js → amp-adapter-nthn8ezm.js} +1 -1
- package/dist/{app-7m4z44rv.js → app-535m78qw.js} +8 -8
- package/dist/{approval-notifications-8sr41gjx.js → approval-notifications-dewbk403.js} +9 -9
- package/dist/{assistant-hkczwfv6.js → assistant-39zyabv2.js} +25 -25
- package/dist/{boot-args-schema-8025snev.js → boot-args-schema-bqv5bf77.js} +1 -1
- package/dist/{boot-reembed-4bbpxjh1.js → boot-reembed-157c0gcz.js} +1 -1
- package/dist/{boot-reembed-15m87nr1.js → boot-reembed-fas7z3zn.js} +1 -1
- package/dist/{boot-scrub-sweep-eajr97e9.js → boot-scrub-sweep-tmec0be2.js} +2 -2
- package/dist/{boot-seeds-9cwy39jx.js → boot-seeds-32zm50x2.js} +4 -4
- package/dist/{claude-adapter-g61wa4rt.js → claude-adapter-gwq7x2nj.js} +2 -2
- package/dist/{claude-managed-adapter-znkk0prm.js → claude-managed-adapter-rkvw6fvq.js} +2 -2
- package/dist/{claude-managed-setup-f1wndkr2.js → claude-managed-setup-0vgz4d1j.js} +4 -4
- package/dist/{claude-sdk-session-687xzf21.js → claude-sdk-session-5wbwxy8c.js} +11964 -11769
- package/dist/{cli-snypfjgj.js → cli-0f7n3td3.js} +1 -1
- package/dist/{cli-0m77n7ej.js → cli-1f48qdnb.js} +54 -12
- package/dist/{cli-04103ryh.js → cli-1gevjrc1.js} +1 -1
- package/dist/{cli-a8ts6x1n.js → cli-2wde56gv.js} +5 -5
- package/dist/{cli-aebswqmz.js → cli-31vt7baf.js} +14 -14
- package/dist/{cli-cn6fpa1p.js → cli-4djg31jh.js} +1 -1
- package/dist/{cli-bjmq14k9.js → cli-5k1hvycs.js} +3 -3
- package/dist/{cli-mmw2sjaf.js → cli-62fjschk.js} +1 -1
- package/dist/{cli-t90k0phh.js → cli-69eq6gdk.js} +15 -15
- package/dist/{cli-dd57p1gd.js → cli-6rmryz03.js} +2 -2
- package/dist/{cli-byxsctca.js → cli-7m6bbtab.js} +6 -6
- package/dist/{cli-c8kqmzzf.js → cli-8a4qg44m.js} +1 -1
- package/dist/{cli-8rbkw18r.js → cli-8qvte9hn.js} +2 -2
- package/dist/{cli-h03j6je3.js → cli-a6rzw649.js} +2 -2
- package/dist/{cli-w41bvvms.js → cli-b0kqw55g.js} +1 -1
- package/dist/{cli-84xtgbn6.js → cli-b0m3bg0f.js} +100 -2
- package/dist/{cli-zaate0rd.js → cli-c9bwawf9.js} +2 -2
- package/dist/{cli-4mj5g29m.js → cli-cs26ed89.js} +6 -6
- package/dist/{cli-yeh3g1q6.js → cli-d0jb2qnt.js} +23 -23
- package/dist/{cli-cp0m07wb.js → cli-d528acsw.js} +1 -1
- package/dist/{cli-fn8aj7gb.js → cli-dnvmwsvc.js} +95 -68
- package/dist/{cli-w6c6dj91.js → cli-e87fg3en.js} +1 -1
- package/dist/{cli-h9bejmkf.js → cli-erh1rgh4.js} +49 -26
- package/dist/{cli-9xx36trj.js → cli-ewb028rs.js} +2 -2
- package/dist/{cli-hs3mqswp.js → cli-f1sdh8ca.js} +4 -4
- package/dist/{cli-zvpkrgsc.js → cli-fcwrd7bh.js} +3 -3
- package/dist/{cli-sfajkbd7.js → cli-fgm2mad9.js} +2 -2
- package/dist/{cli-32xndx6b.js → cli-g0b3ma7r.js} +1 -1
- package/dist/{cli-nk8swfpx.js → cli-gc7jkf4a.js} +3 -3
- package/dist/{cli-z6m6xzxt.js → cli-getrvmtx.js} +26 -5
- package/dist/{cli-y6qqbpwc.js → cli-j2ybkdk2.js} +1 -1
- package/dist/{cli-1dr5at77.js → cli-jkkcm72j.js} +10 -10
- package/dist/{cli-cqxwjb93.js → cli-ka13xx6b.js} +1 -1
- package/dist/{cli-4h90xaet.js → cli-m1wddksc.js} +1 -1
- package/dist/{cli-qx1dwrr5.js → cli-n14r8h4n.js} +2 -2
- package/dist/{cli-jhtvt7gn.js → cli-n46d87mj.js} +3 -3
- package/dist/{cli-13t0smbk.js → cli-nkfv398a.js} +185 -58
- package/dist/{cli-p7g7wd9n.js → cli-nvqq3232.js} +7 -7
- package/dist/{cli-0a336ze7.js → cli-r4fphq38.js} +3 -3
- package/dist/{cli-4tbvndmm.js → cli-r8ddn0hf.js} +1 -1
- package/dist/{cli-3m8vqehw.js → cli-rvhaahfv.js} +2 -2
- package/dist/{cli-cd9acnvd.js → cli-s08zsqva.js} +2 -2
- package/dist/{cli-w24f3j49.js → cli-sjk85d7v.js} +6 -5
- package/dist/{cli-grcc2h2g.js → cli-t9nxq30h.js} +6 -6
- package/dist/{cli-6r1dwegd.js → cli-tbdw3f92.js} +2 -2
- package/dist/{cli-0fx95c06.js → cli-tceqvv6h.js} +2 -2
- package/dist/{cli-tzzas8rb.js → cli-tgmate57.js} +2 -2
- package/dist/{cli-3zyme1wt.js → cli-wdtqkqnq.js} +3 -3
- package/dist/{cli-8cmjkbvj.js → cli-x7aqhxj5.js} +1 -1
- package/dist/{cli-7ewre3dm.js → cli-xerdrnqs.js} +2 -2
- package/dist/{cli-c0tyzt73.js → cli-xysy1g8x.js} +1 -1
- package/dist/{cli-1b5axkt1.js → cli-zm6bkx3e.js} +2 -2
- package/dist/{cli-1carhg8g.js → cli-zqy28rwx.js} +2 -2
- package/dist/cli.js +17 -16
- package/dist/{codex-adapter-ysfg6ty3.js → codex-adapter-x25xfbnh.js} +2 -2
- package/dist/{codex-session-runner-823scr6g.js → codex-session-runner-kn5xnrvp.js} +2 -2
- package/dist/{commands-5rbm07fz.js → commands-8n59gxmy.js} +3 -3
- package/dist/{controllers-connect-34jzhfft.js → controllers-connect-09gvkrhc.js} +24 -24
- package/dist/core-2b8bv6ny.js +42 -0
- package/dist/{db-6bkgbfwk.js → db-e71keqxk.js} +3 -3
- package/dist/{db-hcj16x7z.js → db-spg81qtr.js} +1 -1
- package/dist/{dispatcher-jgjqrfzv.js → dispatcher-fr4vawwb.js} +23 -23
- package/dist/{easter-egg-3d-w17nsny6.js → easter-egg-3d-ac9tv9a6.js} +1 -1
- package/dist/{embedding-space-v06fwy7b.js → embedding-space-an77f45k.js} +6 -6
- package/dist/{embeddings-g50dxea4.js → embeddings-jkrehejr.js} +1 -1
- package/dist/{execute-1n36haw1.js → execute-3mys4nta.js} +1 -1
- package/dist/{external-channel-43tv8pg6.js → external-channel-s6zxpts9.js} +2 -2
- package/dist/{fx-adapter-bvh05t4a.js → fx-adapter-4yet1c4f.js} +6 -6
- package/dist/{grok-adapter-my5j8mdf.js → grok-adapter-8ge6tw7m.js} +6 -6
- package/dist/handlers-0r9evrdj.js +41 -0
- package/dist/{heartbeat-sf3nk937.js → heartbeat-jjpb44e5.js} +25 -25
- package/dist/{hook-m1m9dm6w.js → hook-68gbs87k.js} +1 -1
- package/dist/{hook-dqph1e05.js → hook-y6n23zzj.js} +1 -1
- package/dist/{http-w0th1cz9.js → http-8c6y008s.js} +297 -97
- package/dist/{index-ffba0z8q.js → index-0vthtbc2.js} +20 -18
- package/dist/index-1v23363p.js +39 -0
- package/dist/index-30qw6vyw.js +44 -0
- package/dist/index-6bm3w6cn.js +40 -0
- package/dist/{index-gkpfgpg7.js → index-6h3r0vpe.js} +1 -1
- package/dist/{index-e8pz8qdg.js → index-7dgxveck.js} +2 -2
- package/dist/{index-k8ajc0g0.js → index-maddg9ys.js} +1 -1
- package/dist/{index-y4vd4mhn.js → index-mbpxhc4w.js} +1 -1
- package/dist/index-rz8ve510.js +569 -0
- package/dist/{index-c0e8en64.js → index-we3nd2t0.js} +1 -1
- package/dist/{index-pb03vans.js → index-xcw7hjt5.js} +25 -25
- package/dist/{index-ez823q84.js → index-ym9fgxad.js} +1 -1
- package/dist/{keepalive-2v06q2e8.js → keepalive-7e9r5dvp.js} +4 -4
- package/dist/lead-3jpc7kcr.js +79 -0
- package/dist/{maintenance-vx7vjhhy.js → maintenance-d3erjvcg.js} +1 -1
- package/dist/{oauth-refresh-sweep-g06k4bza.js → oauth-refresh-sweep-0qh70988.js} +3 -3
- package/dist/{object-webhooks-3dzdq4fm.js → object-webhooks-ac7v2q5p.js} +7 -7
- package/dist/{onboard-232pazny.js → onboard-5yphtken.js} +3 -3
- package/dist/{opencode-adapter-t0paqbh8.js → opencode-adapter-0xvyba4m.js} +3 -3
- package/dist/{otel-impl-kmpkyp4y.js → otel-impl-svqp691q.js} +1 -1
- package/dist/{pending-x0z3vx1x.js → pending-bn4xe5br.js} +24 -24
- package/dist/{pi-mono-adapter-7pmypn6d.js → pi-mono-adapter-763s8a3w.js} +6 -6
- package/dist/{pricing-refresh-ytjmtyd7.js → pricing-refresh-kfc215mf.js} +2 -2
- package/dist/{rbac-roles-fgm5mxr2.js → rbac-roles-3bznvkpt.js} +3 -3
- package/dist/{rbac-roles-xyaxekh3.js → rbac-roles-6r4h2ghj.js} +2 -2
- package/dist/{render-v2-ws972g4r.js → render-v2-f3qedbpy.js} +8 -8
- package/dist/{resume-m6mjzhkp.js → resume-vcag4ann.js} +11 -11
- package/dist/{runtime-zzpc0c8a.js → runtime-x0s55z2t.js} +1 -1
- package/dist/{session-access-vp35xs91.js → session-access-nwzve8q2.js} +5 -5
- package/dist/{session-source-backfill-p73e8zbe.js → session-source-backfill-jpqfzmgz.js} +1 -1
- package/dist/{setup-r4kd7rxg.js → setup-d2smwaem.js} +1 -1
- package/dist/thread-buffer-8fc703jc.js +42 -0
- package/dist/{tree-visibility-07h2tbs2.js → tree-visibility-dwzc8en0.js} +2 -2
- package/dist/{user-merge-jobs-96vg9rpe.js → user-merge-jobs-4ce7kma2.js} +3 -3
- package/dist/{virtual-modules-vgn3f2x4.js → virtual-modules-78a6yw71.js} +1 -1
- package/dist/{work-objects-74hbcx3e.js → work-objects-m0w1e7q8.js} +26 -26
- package/dist/worker-3p2vq107.js +79 -0
- package/dist/{worker-follow-up-ezavwn5d.js → worker-follow-up-e3t6f895.js} +23 -23
- package/openapi.json +3 -2
- package/package.json +6 -5
- package/src/be/migrations/341_user_token_expiry.sql +4 -0
- package/src/be/scripts/run-credential.ts +55 -1
- package/src/be/scripts/typecheck.ts +4 -4
- package/src/be/scripts/user-code-mode.ts +160 -0
- package/src/be/users.ts +48 -7
- package/src/commands/onboard/agent-fs-version.ts +1 -1
- package/src/http/script-connection-proxy.ts +18 -6
- package/src/http/scripts.ts +2 -11
- package/src/http/users.ts +1 -0
- package/src/integrations/chat-sdk/adapters.ts +29 -0
- package/src/integrations/chat-sdk/limits.ts +3 -0
- package/src/integrations/chat-sdk/rocketchat/README.md +8 -0
- package/src/integrations/chat-sdk/rocketchat/index.ts +790 -0
- package/src/integrations/chat-sdk/rocketchat/markdown.ts +210 -0
- package/src/integrations/chat-sdk/rocketchat/types.ts +249 -0
- package/src/integrations/chat-sdk/runtime.ts +11 -5
- package/src/integrations/chat-sdk/schema.ts +37 -3
- package/src/integrations/chat-sdk/status.ts +9 -0
- package/src/providers/amp-adapter.ts +1 -1
- package/src/rbac/legacy-policy.ts +1 -0
- package/src/rbac/permissions.ts +4 -0
- package/src/scripts-runtime/executors/native.ts +225 -67
- package/src/scripts-runtime/mcp-client.ts +2 -1
- package/src/scripts-runtime/swarm-sdk.ts +2 -1
- package/src/scripts-runtime/types/stdlib.d.ts +4 -4
- package/src/scripts-runtime/types/swarm-sdk.d.ts +4 -4
- package/src/server-user.ts +98 -0
- package/src/tests/chat-sdk-rocketchat-vendored.test.ts +67 -0
- package/src/tests/chat-sdk-status-route.test.ts +13 -1
- package/src/tests/codex-app-server.test.ts +4 -6
- package/src/tests/mcp-user-route.test.ts +10 -1
- package/src/tests/script-connections-mcp.test.ts +14 -10
- package/src/tests/script-connections-sql.test.ts +6 -2
- package/src/tests/script-connections.test.ts +2 -0
- package/src/tools/script-common.ts +37 -22
- package/src/tools/script-query-types.ts +1 -1
- package/src/tools/script-run.ts +1 -1
- package/src/tools/script-search.ts +12 -10
- package/src/tools/utils.ts +7 -1
- package/templates/skills/chat-sdk/content.md +2 -2
- package/templates/skills/swarm-docs/content.md +2 -0
- package/dist/core-kdehq26g.js +0 -42
- package/dist/handlers-wyymeeqh.js +0 -41
- package/dist/index-22khdtby.js +0 -44
- package/dist/index-np0582ac.js +0 -40
- package/dist/index-vgkrj1jt.js +0 -39
- package/dist/lead-55z813ng.js +0 -79
- package/dist/thread-buffer-cm2nzq6t.js +0 -42
- package/dist/worker-5pn2vzx6.js +0 -79
- package/dist/{cli-5v6b2am8.js → cli-bp2rt28p.js} +4 -4
- /package/dist/{cli-m4ejz4nj.js → cli-cah298e5.js} +0 -0
|
@@ -247,27 +247,203 @@ async function linkOrWriteBareImportShims(baseTmpDir: string, tmpdir: string): P
|
|
|
247
247
|
}
|
|
248
248
|
}
|
|
249
249
|
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
}
|
|
266
|
-
|
|
267
|
-
|
|
250
|
+
type HarnessProcess = Bun.Subprocess<"pipe", "pipe", "pipe">;
|
|
251
|
+
|
|
252
|
+
/** Everything a harness spawn depends on, apart from its run dir. */
|
|
253
|
+
interface HarnessSpec {
|
|
254
|
+
harnessPath: string;
|
|
255
|
+
baseTmpDir: string;
|
|
256
|
+
runAs: SandboxIdentity | undefined;
|
|
257
|
+
hostValidatedArgs: boolean;
|
|
258
|
+
resources: ExecutorInput["resources"];
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
function harnessRunPaths(tmpdir: string) {
|
|
262
|
+
return {
|
|
263
|
+
argsFile: `${tmpdir}/args.json`,
|
|
264
|
+
sourceFile: `${tmpdir}/user-module/user-script.ts`,
|
|
265
|
+
resultFile: `${tmpdir}/result.json`,
|
|
266
|
+
errorFile: `${tmpdir}/error.json`,
|
|
267
|
+
startedFile: `${tmpdir}/started.marker`,
|
|
268
|
+
};
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
function harnessEnvFor(spec: HarnessSpec, tmpdir: string): Record<string, string> {
|
|
272
|
+
const paths = harnessRunPaths(tmpdir);
|
|
273
|
+
return {
|
|
274
|
+
PATH: process.env.PATH ?? "/usr/bin:/bin",
|
|
275
|
+
// The dropped identity cannot use the API's HOME.
|
|
276
|
+
HOME: spec.runAs ? tmpdir : (process.env.HOME ?? "/tmp"),
|
|
277
|
+
LANG: process.env.LANG ?? "C.UTF-8",
|
|
278
|
+
LC_ALL: process.env.LC_ALL ?? "C.UTF-8",
|
|
279
|
+
TMPDIR: tmpdir,
|
|
280
|
+
SWARM_SCRIPT_TMPDIR: tmpdir,
|
|
281
|
+
SWARM_SCRIPT_ARGS_FILE: paths.argsFile,
|
|
282
|
+
SWARM_SCRIPT_SOURCE_FILE: paths.sourceFile,
|
|
283
|
+
SWARM_SCRIPT_RESULT_FILE: paths.resultFile,
|
|
284
|
+
SWARM_SCRIPT_ERROR_FILE: paths.errorFile,
|
|
285
|
+
SWARM_SCRIPT_STARTED_FILE: paths.startedFile,
|
|
286
|
+
...(spec.hostValidatedArgs ? { SWARM_SCRIPT_HOST_VALIDATED_ARGS: "1" } : {}),
|
|
287
|
+
};
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
function spawnHarness(spec: HarnessSpec, tmpdir: string): HarnessProcess {
|
|
291
|
+
const harnessEnv = harnessEnvFor(spec, tmpdir);
|
|
292
|
+
const limits = {
|
|
293
|
+
virtualMemoryMb: spec.resources.memoryMb,
|
|
294
|
+
cpuTimeSec: spec.resources.cpuTimeSec,
|
|
295
|
+
maxProcs: spec.resources.maxProcs,
|
|
296
|
+
maxFileKb: Math.floor(spec.resources.maxFileBytes / 1024),
|
|
297
|
+
maxFdCount: spec.resources.maxFdCount,
|
|
298
|
+
};
|
|
299
|
+
return registerProcessGroup(
|
|
300
|
+
Bun.spawn(
|
|
301
|
+
buildSandboxedCommand(
|
|
302
|
+
["bun", "run", spec.harnessPath],
|
|
303
|
+
harnessEnv,
|
|
304
|
+
limits,
|
|
305
|
+
"inline",
|
|
306
|
+
spec.runAs,
|
|
307
|
+
),
|
|
308
|
+
{
|
|
309
|
+
// On POSIX, Bun.spawn only needs PATH itself to locate the `sh`
|
|
310
|
+
// binary for argv[0] — the sandboxed command's `env -i` prelude is
|
|
311
|
+
// what actually scrubs the child's environment down to `harnessEnv`
|
|
312
|
+
// above. On win32 there is no such prelude, so `sandboxSpawnEnv`
|
|
313
|
+
// passes `harnessEnv` through directly instead — see
|
|
314
|
+
// `buildSandboxedCommand`'s win32 doc comment.
|
|
315
|
+
env: sandboxSpawnEnv(harnessEnv),
|
|
316
|
+
cwd: tmpdir,
|
|
317
|
+
detached: detachedProcessGroup,
|
|
318
|
+
stdin: "pipe",
|
|
319
|
+
stdout: "pipe",
|
|
320
|
+
stderr: "pipe",
|
|
321
|
+
},
|
|
322
|
+
),
|
|
268
323
|
);
|
|
269
324
|
}
|
|
270
325
|
|
|
326
|
+
/**
|
|
327
|
+
* Warm harness pool. A harness spends most of a short run loading its own
|
|
328
|
+
* modules (ctx, SDK, zod) before it reads the config payload from stdin, and
|
|
329
|
+
* none of that depends on the run. So after each spawn the executor starts
|
|
330
|
+
* one spare harness with the same spec in a fresh run dir; it loads and then
|
|
331
|
+
* blocks on stdin. The next run with that spec writes its args and source
|
|
332
|
+
* into the spare's run dir and sends the payload, skipping spawn and module
|
|
333
|
+
* load. The script itself still runs once per call, in its own process, with
|
|
334
|
+
* the same env, limits and identity, so outputs and side effects are those of
|
|
335
|
+
* a cold run. A spare holds no credentials (they arrive on stdin), is
|
|
336
|
+
* single-use, and is stopped after WARM_IDLE_MS unused.
|
|
337
|
+
*
|
|
338
|
+
* The user module dir is created only after the spare has started: Bun
|
|
339
|
+
* snapshots the cwd listing at startup, and a subdir created later is
|
|
340
|
+
* resolved from disk (see the note above `userModulePath` in eval-harness.ts).
|
|
341
|
+
*
|
|
342
|
+
* Under a dropped identity the spare's run dir stays owned by the API until a
|
|
343
|
+
* run takes it. Every script shares that identity, so a dir it owned while
|
|
344
|
+
* idle could hold links planted by another script, and the API's writes and
|
|
345
|
+
* chowns below would follow them. The harness writes nothing before it reads
|
|
346
|
+
* stdin, so the spare needs no write access while it waits. A taken spare's
|
|
347
|
+
* dir gets the cold path's order: write as the API, then chown.
|
|
348
|
+
*/
|
|
349
|
+
interface WarmHarness {
|
|
350
|
+
key: string;
|
|
351
|
+
tmpdir: string;
|
|
352
|
+
proc: HarnessProcess;
|
|
353
|
+
idleTimer: ReturnType<typeof setTimeout>;
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
const WARM_IDLE_MS = 30_000;
|
|
357
|
+
const MAX_WARM_SPECS = 4;
|
|
358
|
+
const warmHarnesses = new Map<string, WarmHarness>();
|
|
359
|
+
const warmingSpecs = new Set<string>();
|
|
360
|
+
|
|
361
|
+
function harnessSpecKey(spec: HarnessSpec): string {
|
|
362
|
+
return JSON.stringify([
|
|
363
|
+
spec.harnessPath,
|
|
364
|
+
spec.baseTmpDir,
|
|
365
|
+
spec.runAs ?? null,
|
|
366
|
+
spec.hostValidatedArgs,
|
|
367
|
+
spec.resources.memoryMb,
|
|
368
|
+
spec.resources.cpuTimeSec,
|
|
369
|
+
spec.resources.maxProcs,
|
|
370
|
+
spec.resources.maxFileBytes,
|
|
371
|
+
spec.resources.maxFdCount,
|
|
372
|
+
process.env.PATH ?? null,
|
|
373
|
+
process.env.HOME ?? null,
|
|
374
|
+
process.env.LANG ?? null,
|
|
375
|
+
process.env.LC_ALL ?? null,
|
|
376
|
+
]);
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
function harnessAlive(proc: HarnessProcess): boolean {
|
|
380
|
+
return proc.exitCode === null && proc.signalCode === null && !proc.killed;
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
function discardWarmHarness(entry: WarmHarness): void {
|
|
384
|
+
clearTimeout(entry.idleTimer);
|
|
385
|
+
if (warmHarnesses.get(entry.key) === entry) warmHarnesses.delete(entry.key);
|
|
386
|
+
void terminateProcessGroup(entry.proc.pid)
|
|
387
|
+
.catch(() => {})
|
|
388
|
+
.finally(() => rm(entry.tmpdir, { recursive: true, force: true }).catch(() => {}));
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
/** Removes and returns the spare for `key` when it is still waiting on stdin. */
|
|
392
|
+
function takeWarmHarness(key: string): WarmHarness | undefined {
|
|
393
|
+
const entry = warmHarnesses.get(key);
|
|
394
|
+
if (!entry) return undefined;
|
|
395
|
+
warmHarnesses.delete(key);
|
|
396
|
+
clearTimeout(entry.idleTimer);
|
|
397
|
+
if (!harnessAlive(entry.proc)) {
|
|
398
|
+
discardWarmHarness(entry);
|
|
399
|
+
return undefined;
|
|
400
|
+
}
|
|
401
|
+
entry.proc.ref();
|
|
402
|
+
return entry;
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
async function startWarmHarness(key: string, spec: HarnessSpec): Promise<void> {
|
|
406
|
+
if (process.platform === "win32") return;
|
|
407
|
+
if (warmHarnesses.has(key) || warmingSpecs.has(key)) return;
|
|
408
|
+
warmingSpecs.add(key);
|
|
409
|
+
const tmpdir = `${spec.baseTmpDir}/swarm-script-${crypto.randomUUID()}`;
|
|
410
|
+
let started = false;
|
|
411
|
+
try {
|
|
412
|
+
// The run dir stays owned by the API until a run takes the spare (see
|
|
413
|
+
// above): no chown here.
|
|
414
|
+
await mkdir(tmpdir, { recursive: true, mode: 0o755 });
|
|
415
|
+
await linkOrWriteBareImportShims(spec.baseTmpDir, tmpdir);
|
|
416
|
+
if (warmHarnesses.has(key)) return;
|
|
417
|
+
const proc = spawnHarness(spec, tmpdir);
|
|
418
|
+
// A spare must not keep the API (or a CLI / test process) alive.
|
|
419
|
+
proc.unref();
|
|
420
|
+
started = true;
|
|
421
|
+
const entry: WarmHarness = {
|
|
422
|
+
key,
|
|
423
|
+
tmpdir,
|
|
424
|
+
proc,
|
|
425
|
+
idleTimer: setTimeout(() => discardWarmHarness(entry), WARM_IDLE_MS),
|
|
426
|
+
};
|
|
427
|
+
entry.idleTimer.unref?.();
|
|
428
|
+
if (warmHarnesses.size >= MAX_WARM_SPECS) {
|
|
429
|
+
const oldest = warmHarnesses.values().next().value;
|
|
430
|
+
if (oldest) discardWarmHarness(oldest);
|
|
431
|
+
}
|
|
432
|
+
warmHarnesses.set(key, entry);
|
|
433
|
+
void proc.exited.then(
|
|
434
|
+
() => {
|
|
435
|
+
if (warmHarnesses.get(key) === entry) discardWarmHarness(entry);
|
|
436
|
+
},
|
|
437
|
+
() => {},
|
|
438
|
+
);
|
|
439
|
+
} catch {
|
|
440
|
+
// Best-effort: the next run spawns cold.
|
|
441
|
+
} finally {
|
|
442
|
+
warmingSpecs.delete(key);
|
|
443
|
+
if (!started) await rm(tmpdir, { recursive: true, force: true }).catch(() => {});
|
|
444
|
+
}
|
|
445
|
+
}
|
|
446
|
+
|
|
271
447
|
export class NativeScriptExecutor implements ScriptExecutor {
|
|
272
448
|
readonly name = "native";
|
|
273
449
|
|
|
@@ -278,24 +454,24 @@ export class NativeScriptExecutor implements ScriptExecutor {
|
|
|
278
454
|
|
|
279
455
|
const start = Date.now();
|
|
280
456
|
const baseTmpDir = process.env.TMPDIR ?? (process.platform === "win32" ? osTmpdir() : "/tmp");
|
|
281
|
-
const tmpdir = `${baseTmpDir}/swarm-script-${crypto.randomUUID()}`;
|
|
282
|
-
await mkdir(`${tmpdir}/user-module`, { recursive: true });
|
|
283
|
-
|
|
284
|
-
const argsFile = `${tmpdir}/args.json`;
|
|
285
|
-
const sourceFile = `${tmpdir}/user-module/user-script.ts`;
|
|
286
|
-
const resultFile = `${tmpdir}/result.json`;
|
|
287
|
-
const errorFile = `${tmpdir}/error.json`;
|
|
288
|
-
const startedFile = `${tmpdir}/started.marker`;
|
|
289
457
|
const runAs = resolveSandboxIdentity();
|
|
290
458
|
// In compiled binary mode, import.meta.url points into /$bunfs/ which spawned
|
|
291
459
|
// subprocesses cannot access. Use the pre-built bundle from real filesystem instead.
|
|
292
460
|
const harnessPath = process.env.SCRIPT_RUNTIME_DIR
|
|
293
461
|
? `${process.env.SCRIPT_RUNTIME_DIR}/eval-harness.bundle.js`
|
|
294
462
|
: fileURLToPath(new URL("../eval-harness.ts", import.meta.url));
|
|
463
|
+
const spec: HarnessSpec = {
|
|
464
|
+
harnessPath,
|
|
465
|
+
baseTmpDir,
|
|
466
|
+
runAs,
|
|
467
|
+
hostValidatedArgs: Boolean(input.hostValidatedArgs),
|
|
468
|
+
resources: input.resources,
|
|
469
|
+
};
|
|
470
|
+
const specKey = harnessSpecKey(spec);
|
|
295
471
|
let timedOut = false;
|
|
296
472
|
let killed = input.signal?.aborted ?? false;
|
|
297
473
|
let removeAbortListener: (() => void) | undefined;
|
|
298
|
-
let proc:
|
|
474
|
+
let proc: HarnessProcess | undefined;
|
|
299
475
|
|
|
300
476
|
const killedOutput = (): ExecutorOutput => ({
|
|
301
477
|
result: undefined,
|
|
@@ -307,9 +483,16 @@ export class NativeScriptExecutor implements ScriptExecutor {
|
|
|
307
483
|
error: "killed",
|
|
308
484
|
});
|
|
309
485
|
|
|
310
|
-
|
|
311
|
-
|
|
486
|
+
if (killed) return killedOutput();
|
|
487
|
+
|
|
488
|
+
const warm = takeWarmHarness(specKey);
|
|
489
|
+
const tmpdir = warm?.tmpdir ?? `${baseTmpDir}/swarm-script-${crypto.randomUUID()}`;
|
|
490
|
+
const { argsFile, sourceFile, resultFile, errorFile, startedFile } = harnessRunPaths(tmpdir);
|
|
491
|
+
// A taken spare is this run's process from here on: an abort or error
|
|
492
|
+
// below terminates it and removes its run dir like a cold child's.
|
|
493
|
+
if (warm) proc = warm.proc;
|
|
312
494
|
|
|
495
|
+
try {
|
|
313
496
|
// Listen before the first await: an abort during the file writes below
|
|
314
497
|
// must stop the spawn, not land between the writes and the listener.
|
|
315
498
|
const onExternalAbort = () => {
|
|
@@ -319,11 +502,14 @@ export class NativeScriptExecutor implements ScriptExecutor {
|
|
|
319
502
|
input.signal?.addEventListener("abort", onExternalAbort, { once: true });
|
|
320
503
|
removeAbortListener = () => input.signal?.removeEventListener("abort", onExternalAbort);
|
|
321
504
|
|
|
505
|
+
// A spare's run dir already has its node_modules link, and is still
|
|
506
|
+
// owned by the API: write as the API first, then chown, on both paths.
|
|
507
|
+
await mkdir(`${tmpdir}/user-module`, { recursive: true });
|
|
322
508
|
await Promise.all([
|
|
323
509
|
Bun.write(argsFile, JSON.stringify(input.args ?? null)),
|
|
324
510
|
Bun.write(sourceFile, input.source),
|
|
325
|
-
linkOrWriteBareImportShims(baseTmpDir, tmpdir),
|
|
326
511
|
]);
|
|
512
|
+
if (!warm) await linkOrWriteBareImportShims(baseTmpDir, tmpdir);
|
|
327
513
|
if (runAs) {
|
|
328
514
|
// The child writes its result and marker files into the run dir.
|
|
329
515
|
await Promise.all(
|
|
@@ -341,46 +527,18 @@ export class NativeScriptExecutor implements ScriptExecutor {
|
|
|
341
527
|
if (proc) void terminateProcessGroup(proc.pid);
|
|
342
528
|
}, input.resources.wallClockMs);
|
|
343
529
|
|
|
344
|
-
const
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
LANG: process.env.LANG ?? "C.UTF-8",
|
|
349
|
-
LC_ALL: process.env.LC_ALL ?? "C.UTF-8",
|
|
350
|
-
TMPDIR: tmpdir,
|
|
351
|
-
SWARM_SCRIPT_TMPDIR: tmpdir,
|
|
352
|
-
SWARM_SCRIPT_ARGS_FILE: argsFile,
|
|
353
|
-
SWARM_SCRIPT_SOURCE_FILE: sourceFile,
|
|
354
|
-
SWARM_SCRIPT_RESULT_FILE: resultFile,
|
|
355
|
-
SWARM_SCRIPT_ERROR_FILE: errorFile,
|
|
356
|
-
SWARM_SCRIPT_STARTED_FILE: startedFile,
|
|
357
|
-
...(input.hostValidatedArgs ? { SWARM_SCRIPT_HOST_VALIDATED_ARGS: "1" } : {}),
|
|
358
|
-
};
|
|
530
|
+
const child = proc ?? spawnHarness(spec, tmpdir);
|
|
531
|
+
proc = child;
|
|
532
|
+
// Load the next run's harness while this one runs.
|
|
533
|
+
void startWarmHarness(specKey, spec);
|
|
359
534
|
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
// On POSIX, Bun.spawn only needs PATH itself to locate the `sh`
|
|
363
|
-
// binary for argv[0] — the sandboxed command's `env -i` prelude is
|
|
364
|
-
// what actually scrubs the child's environment down to `harnessEnv`
|
|
365
|
-
// above. On win32 there is no such prelude, so `sandboxSpawnEnv`
|
|
366
|
-
// passes `harnessEnv` through directly instead — see
|
|
367
|
-
// `buildSandboxedCommand`'s win32 doc comment.
|
|
368
|
-
env: sandboxSpawnEnv(harnessEnv),
|
|
369
|
-
cwd: tmpdir,
|
|
370
|
-
detached: detachedProcessGroup,
|
|
371
|
-
stdin: "pipe",
|
|
372
|
-
stdout: "pipe",
|
|
373
|
-
stderr: "pipe",
|
|
374
|
-
}),
|
|
375
|
-
);
|
|
376
|
-
|
|
377
|
-
proc.stdin.write(JSON.stringify(input.configPayload));
|
|
378
|
-
proc.stdin.end();
|
|
535
|
+
child.stdin.write(JSON.stringify(input.configPayload));
|
|
536
|
+
child.stdin.end();
|
|
379
537
|
|
|
380
538
|
const [stdout, stderr, exitCode] = await Promise.all([
|
|
381
|
-
readStreamCapped(
|
|
382
|
-
readStreamCapped(
|
|
383
|
-
|
|
539
|
+
readStreamCapped(child.stdout, input.resources.maxStdoutBytes),
|
|
540
|
+
readStreamCapped(child.stderr, input.resources.maxStdoutBytes),
|
|
541
|
+
child.exited.catch(() => (timedOut ? 124 : 1)),
|
|
384
542
|
]).finally(() => clearTimeout(timeout));
|
|
385
543
|
// The child owns the run dir: read its files only through the checked reader.
|
|
386
544
|
const runDirCheck: RunDirFileCheck = {
|
|
@@ -35,7 +35,8 @@ function methodNames(
|
|
|
35
35
|
function headers(config: SwarmConfig): Record<string, string> {
|
|
36
36
|
return {
|
|
37
37
|
Authorization: `Bearer ${Redacted.value(config.apiKey)}`,
|
|
38
|
-
|
|
38
|
+
// A user-scoped run has no agent; its user token must not name one.
|
|
39
|
+
...(Redacted.value(config.agentId) ? { "X-Agent-ID": Redacted.value(config.agentId) } : {}),
|
|
39
40
|
// Audit-only header: X-Source-Task-Id would also rescope kv, parent send-task, etc.
|
|
40
41
|
...(config.auditSourceTaskId
|
|
41
42
|
? { "X-Audit-Source-Task-Id": Redacted.value(config.auditSourceTaskId) }
|
|
@@ -23,7 +23,8 @@ type BridgeRequest = {
|
|
|
23
23
|
function headers(config: SwarmConfig): Record<string, string> {
|
|
24
24
|
return {
|
|
25
25
|
Authorization: `Bearer ${Redacted.value(config.apiKey)}`,
|
|
26
|
-
|
|
26
|
+
// A user-scoped run has no agent; its user token must not name one.
|
|
27
|
+
...(Redacted.value(config.agentId) ? { "X-Agent-ID": Redacted.value(config.agentId) } : {}),
|
|
27
28
|
// Per-boot identity of the invoking worker process (system context, not
|
|
28
29
|
// script input) — work-acquisition endpoints gate on it in multi-runtime
|
|
29
30
|
// mode.
|
|
@@ -847,25 +847,25 @@ declare module "swarm-sdk" {
|
|
|
847
847
|
// --- write: chat sdk ---
|
|
848
848
|
chat_reply(args: { text?: string; card?: unknown }): Promise<unknown>;
|
|
849
849
|
chat_post(args: {
|
|
850
|
-
adapter: "telegram" | "slack" | "discord" | "teams";
|
|
850
|
+
adapter: "telegram" | "slack" | "discord" | "teams" | "rocketchat";
|
|
851
851
|
threadId?: string;
|
|
852
852
|
channelId?: string;
|
|
853
853
|
text?: string;
|
|
854
854
|
card?: unknown;
|
|
855
855
|
}): Promise<unknown>;
|
|
856
856
|
chat_openDm(args: {
|
|
857
|
-
adapter: "telegram" | "slack" | "discord" | "teams";
|
|
857
|
+
adapter: "telegram" | "slack" | "discord" | "teams" | "rocketchat";
|
|
858
858
|
userId: string;
|
|
859
859
|
}): Promise<unknown>;
|
|
860
860
|
chat_registerChannel(args: {
|
|
861
|
-
adapter: "telegram" | "slack" | "discord" | "teams";
|
|
861
|
+
adapter: "telegram" | "slack" | "discord" | "teams" | "rocketchat";
|
|
862
862
|
channelId: string;
|
|
863
863
|
agentId?: string;
|
|
864
864
|
workflowId?: string;
|
|
865
865
|
name?: string;
|
|
866
866
|
}): Promise<unknown>;
|
|
867
867
|
chat_unregisterChannel(args: {
|
|
868
|
-
adapter: "telegram" | "slack" | "discord" | "teams";
|
|
868
|
+
adapter: "telegram" | "slack" | "discord" | "teams" | "rocketchat";
|
|
869
869
|
channelId: string;
|
|
870
870
|
}): Promise<unknown>;
|
|
871
871
|
|
|
@@ -805,25 +805,25 @@ declare module "swarm-sdk" {
|
|
|
805
805
|
// --- write: chat sdk ---
|
|
806
806
|
chat_reply(args: { text?: string; card?: unknown }): Promise<unknown>;
|
|
807
807
|
chat_post(args: {
|
|
808
|
-
adapter: "telegram" | "slack" | "discord" | "teams";
|
|
808
|
+
adapter: "telegram" | "slack" | "discord" | "teams" | "rocketchat";
|
|
809
809
|
threadId?: string;
|
|
810
810
|
channelId?: string;
|
|
811
811
|
text?: string;
|
|
812
812
|
card?: unknown;
|
|
813
813
|
}): Promise<unknown>;
|
|
814
814
|
chat_openDm(args: {
|
|
815
|
-
adapter: "telegram" | "slack" | "discord" | "teams";
|
|
815
|
+
adapter: "telegram" | "slack" | "discord" | "teams" | "rocketchat";
|
|
816
816
|
userId: string;
|
|
817
817
|
}): Promise<unknown>;
|
|
818
818
|
chat_registerChannel(args: {
|
|
819
|
-
adapter: "telegram" | "slack" | "discord" | "teams";
|
|
819
|
+
adapter: "telegram" | "slack" | "discord" | "teams" | "rocketchat";
|
|
820
820
|
channelId: string;
|
|
821
821
|
agentId?: string;
|
|
822
822
|
workflowId?: string;
|
|
823
823
|
name?: string;
|
|
824
824
|
}): Promise<unknown>;
|
|
825
825
|
chat_unregisterChannel(args: {
|
|
826
|
-
adapter: "telegram" | "slack" | "discord" | "teams";
|
|
826
|
+
adapter: "telegram" | "slack" | "discord" | "teams" | "rocketchat";
|
|
827
827
|
channelId: string;
|
|
828
828
|
}): Promise<unknown>;
|
|
829
829
|
|
package/src/server-user.ts
CHANGED
|
@@ -6,6 +6,12 @@ import { isMcpUserEventsEnabled } from "./be/mcp-events/catalog";
|
|
|
6
6
|
import { registerUserEvents } from "./be/mcp-events/protocol";
|
|
7
7
|
import { enqueueAdmissionRow } from "./be/rbac-audit";
|
|
8
8
|
import { getUserGrant } from "./be/rbac-roles";
|
|
9
|
+
import {
|
|
10
|
+
runScriptForUser,
|
|
11
|
+
scriptTypesForUser,
|
|
12
|
+
searchScriptsForUser,
|
|
13
|
+
type UserCodeModeResponse,
|
|
14
|
+
} from "./be/scripts/user-code-mode";
|
|
9
15
|
import { MCP_MAX_TOOL_INPUT_ELEMENTS } from "./mcp-limits";
|
|
10
16
|
import {
|
|
11
17
|
type AdmissionRbac,
|
|
@@ -24,6 +30,14 @@ import {
|
|
|
24
30
|
getTaskDetailsOutputSchema,
|
|
25
31
|
} from "./tools/get-task-details";
|
|
26
32
|
import { getTasksHandler, getTasksInputSchema, getTasksOutputSchema } from "./tools/get-tasks";
|
|
33
|
+
import {
|
|
34
|
+
scriptNameSchema,
|
|
35
|
+
scriptsApiToolResult,
|
|
36
|
+
scriptToolOutputSchema,
|
|
37
|
+
} from "./tools/script-common";
|
|
38
|
+
import { renderTypeBlobs } from "./tools/script-query-types";
|
|
39
|
+
import { renderRunOutput } from "./tools/script-run";
|
|
40
|
+
import { renderSearchResults, searchSuccessMessage } from "./tools/script-search";
|
|
27
41
|
import { checkOutputSchemaShape, sendTaskHandler, sendTaskOutputSchema } from "./tools/send-task";
|
|
28
42
|
import {
|
|
29
43
|
steerTaskHandler,
|
|
@@ -68,6 +82,17 @@ export const userSendTaskInputSchema = z
|
|
|
68
82
|
})
|
|
69
83
|
.superRefine((data, ctx) => checkOutputSchemaShape(data.outputSchema, ctx));
|
|
70
84
|
|
|
85
|
+
const USER_CODE_MODE_SCOPE =
|
|
86
|
+
"Runs as you: the script's swarm calls carry your permissions, no agent's credentials or connections, and no task is created. Only global scripts are visible.";
|
|
87
|
+
|
|
88
|
+
function codeModeResult(
|
|
89
|
+
response: UserCodeModeResponse,
|
|
90
|
+
rendering: Parameters<typeof scriptsApiToolResult>[2],
|
|
91
|
+
): SwarmToolResult {
|
|
92
|
+
const ok = response.status >= 200 && response.status < 300;
|
|
93
|
+
return scriptsApiToolResult(response.body, { ok, status: response.status }, rendering);
|
|
94
|
+
}
|
|
95
|
+
|
|
71
96
|
function permission(verb: PermissionVerb): AdmissionRbac {
|
|
72
97
|
return { permission: verb };
|
|
73
98
|
}
|
|
@@ -190,6 +215,79 @@ export function createUserServer(user: User, tokenId?: string): McpServer {
|
|
|
190
215
|
return cancelTaskHandler(userCtx(user, info.sessionId), args);
|
|
191
216
|
});
|
|
192
217
|
|
|
218
|
+
// Code mode: the agent-side script-search / script-query-types / script-run,
|
|
219
|
+
// scoped to the user (see src/be/scripts/user-code-mode.ts).
|
|
220
|
+
const scriptSearchConfig = {
|
|
221
|
+
title: "Script Search",
|
|
222
|
+
description: `Search the swarm's reusable TypeScript scripts by intent. ${USER_CODE_MODE_SCOPE}`,
|
|
223
|
+
annotations: { readOnlyHint: true, openWorldHint: false },
|
|
224
|
+
rbac: permission("script.search"),
|
|
225
|
+
inputSchema: z.object({
|
|
226
|
+
query: z.string().default("").describe("What the script should do."),
|
|
227
|
+
limit: z.number().int().min(1).max(100).default(10).describe("Maximum results."),
|
|
228
|
+
}),
|
|
229
|
+
outputSchema: scriptToolOutputSchema,
|
|
230
|
+
};
|
|
231
|
+
registerTool("script-search", scriptSearchConfig, async (args) => {
|
|
232
|
+
const denied = await maybeDenyUserToolAdmission(user, "script-search", scriptSearchConfig);
|
|
233
|
+
if (denied) return denied;
|
|
234
|
+
return codeModeResult(await searchScriptsForUser(args), {
|
|
235
|
+
successMessage: searchSuccessMessage,
|
|
236
|
+
successDetails: renderSearchResults,
|
|
237
|
+
});
|
|
238
|
+
});
|
|
239
|
+
|
|
240
|
+
// Not `script-query-types`: this name is exempt from the result-size spill
|
|
241
|
+
// (CTX_CONTROL_EXEMPT_TOOLS), since a user has no kv to read a spill back from.
|
|
242
|
+
const scriptGetTypesConfig = {
|
|
243
|
+
title: "Script Get Types",
|
|
244
|
+
description: `Get the TypeScript declarations a script is written against: the \`swarm-sdk\` module (\`ScriptContext\`, \`ctx.swarm\`) and the \`stdlib\` module, about 12k tokens. Pass \`name\` to also get that script's signature and args schema. ${USER_CODE_MODE_SCOPE}`,
|
|
245
|
+
annotations: { readOnlyHint: true, openWorldHint: false },
|
|
246
|
+
inputSchema: z.object({
|
|
247
|
+
name: scriptNameSchema.optional().describe("Optional global script name."),
|
|
248
|
+
}),
|
|
249
|
+
outputSchema: scriptToolOutputSchema,
|
|
250
|
+
};
|
|
251
|
+
registerTool("script-get-types", scriptGetTypesConfig, async ({ name }) => {
|
|
252
|
+
const denied = await maybeDenyUserToolAdmission(user, "script-get-types", scriptGetTypesConfig);
|
|
253
|
+
if (denied) return denied;
|
|
254
|
+
const response = await scriptTypesForUser(name);
|
|
255
|
+
const { stdlibTypes: _types, ...small } = response.body as Record<string, unknown>;
|
|
256
|
+
return codeModeResult(
|
|
257
|
+
// The declarations go out once, in details; data keeps only the small fields.
|
|
258
|
+
{ status: response.status, body: small },
|
|
259
|
+
{
|
|
260
|
+
successMessage: () =>
|
|
261
|
+
name
|
|
262
|
+
? `Type definitions for script \`${name}\` fetched.`
|
|
263
|
+
: "Script type definitions fetched.",
|
|
264
|
+
successDetails: () => renderTypeBlobs(response.body),
|
|
265
|
+
uncappedDetails: true,
|
|
266
|
+
},
|
|
267
|
+
);
|
|
268
|
+
});
|
|
269
|
+
|
|
270
|
+
const scriptRunConfig = {
|
|
271
|
+
title: "Script Run",
|
|
272
|
+
description: `Run a global script by \`name\`, or inline TypeScript \`source\` that does \`export default async function (args, ctx)\`. Inline source is not typechecked or saved. ${USER_CODE_MODE_SCOPE}`,
|
|
273
|
+
annotations: { openWorldHint: true },
|
|
274
|
+
rbac: permission("script.run"),
|
|
275
|
+
inputSchema: z.object({
|
|
276
|
+
name: scriptNameSchema.optional().describe("Global script to run."),
|
|
277
|
+
source: z.string().min(1).optional().describe("Inline TypeScript source to run."),
|
|
278
|
+
args: z.unknown().optional().describe("JSON-serializable script arguments."),
|
|
279
|
+
}),
|
|
280
|
+
outputSchema: scriptToolOutputSchema,
|
|
281
|
+
};
|
|
282
|
+
registerTool("script-run", scriptRunConfig, async (args) => {
|
|
283
|
+
const denied = await maybeDenyUserToolAdmission(user, "script-run", scriptRunConfig);
|
|
284
|
+
if (denied) return denied;
|
|
285
|
+
return codeModeResult(await runScriptForUser({ userId: user.id, ...args }), {
|
|
286
|
+
successMessage: () => "Script run completed.",
|
|
287
|
+
successDetails: renderRunOutput,
|
|
288
|
+
});
|
|
289
|
+
});
|
|
290
|
+
|
|
193
291
|
if (isSteeringEnabled()) {
|
|
194
292
|
const steerTaskConfig = {
|
|
195
293
|
title: "Steer Task",
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { describe, expect, test } from "bun:test";
|
|
2
|
+
import { NetworkError } from "@chat-adapter/shared";
|
|
3
|
+
import { createRocketChatAdapter } from "../integrations/chat-sdk/rocketchat/index";
|
|
4
|
+
|
|
5
|
+
const WEBHOOK_TOKEN = "rc-outgoing-webhook-token";
|
|
6
|
+
|
|
7
|
+
function adapterFor(baseUrl: string) {
|
|
8
|
+
return createRocketChatAdapter({
|
|
9
|
+
baseUrl,
|
|
10
|
+
token: "rc-personal-access-token",
|
|
11
|
+
botUserId: "rc-bot-user-id",
|
|
12
|
+
webhookToken: WEBHOOK_TOKEN,
|
|
13
|
+
userName: "swarm",
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
function webhook(token: string | undefined): Request {
|
|
18
|
+
return new Request("http://localhost/webhook", {
|
|
19
|
+
method: "POST",
|
|
20
|
+
body: JSON.stringify({ token, message_id: "m1", channel_id: "room", user_id: "u1", text: "" }),
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
describe("in-repo Rocket.Chat adapter", () => {
|
|
25
|
+
test("loads from the repo with no chat-adapter-rocketchat npm package", async () => {
|
|
26
|
+
expect(() => Bun.resolveSync("chat-adapter-rocketchat", import.meta.dir)).toThrow();
|
|
27
|
+
const pkg = await Bun.file(new URL("../../package.json", import.meta.url)).json();
|
|
28
|
+
expect(pkg.dependencies?.["chat-adapter-rocketchat"]).toBeUndefined();
|
|
29
|
+
expect(adapterFor("https://chat.example.com/").name).toBe("rocketchat");
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
test("the webhook token check rejects a wrong, shorter, longer or missing token", async () => {
|
|
33
|
+
const adapter = adapterFor("https://chat.example.com");
|
|
34
|
+
// No Chat instance is attached, so a valid token answers 200 without processing.
|
|
35
|
+
expect((await adapter.handleWebhook(webhook(WEBHOOK_TOKEN))).status).toBe(200);
|
|
36
|
+
for (const token of ["x".repeat(WEBHOOK_TOKEN.length), "short", `${WEBHOOK_TOKEN}-x`, ""]) {
|
|
37
|
+
expect((await adapter.handleWebhook(webhook(token))).status).toBe(401);
|
|
38
|
+
}
|
|
39
|
+
expect((await adapter.handleWebhook(webhook(undefined))).status).toBe(401);
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
test("the auth token never follows a redirect to another origin", async () => {
|
|
43
|
+
const seen: Array<string | null> = [];
|
|
44
|
+
const foreign = Bun.serve({
|
|
45
|
+
port: 0,
|
|
46
|
+
fetch(request) {
|
|
47
|
+
seen.push(request.headers.get("x-auth-token"));
|
|
48
|
+
return Response.json({ success: true, message: { _id: "m1" } });
|
|
49
|
+
},
|
|
50
|
+
});
|
|
51
|
+
const instance = Bun.serve({
|
|
52
|
+
port: 0,
|
|
53
|
+
fetch: () =>
|
|
54
|
+
Response.redirect(`http://127.0.0.1:${foreign.port}/api/v1/chat.postMessage`, 307),
|
|
55
|
+
});
|
|
56
|
+
try {
|
|
57
|
+
const adapter = adapterFor(`http://localhost:${instance.port}`);
|
|
58
|
+
await expect(
|
|
59
|
+
adapter.postMessage("rocketchat:room", { markdown: "hi" }),
|
|
60
|
+
).rejects.toBeInstanceOf(NetworkError);
|
|
61
|
+
expect(seen).toEqual([]);
|
|
62
|
+
} finally {
|
|
63
|
+
instance.stop(true);
|
|
64
|
+
foreign.stop(true);
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
});
|
|
@@ -175,7 +175,13 @@ describe("GET /api/integrations/chat/status", () => {
|
|
|
175
175
|
expect(body.enabled).toBe(true);
|
|
176
176
|
expect(body.slackClash).toBe(false);
|
|
177
177
|
const byName = Object.fromEntries(body.adapters.map((a) => [a.name, a]));
|
|
178
|
-
expect(Object.keys(byName).sort()).toEqual([
|
|
178
|
+
expect(Object.keys(byName).sort()).toEqual([
|
|
179
|
+
"discord",
|
|
180
|
+
"rocketchat",
|
|
181
|
+
"slack",
|
|
182
|
+
"teams",
|
|
183
|
+
"telegram",
|
|
184
|
+
]);
|
|
179
185
|
|
|
180
186
|
expect(byName.telegram).toMatchObject({
|
|
181
187
|
configured: true,
|
|
@@ -201,6 +207,12 @@ describe("GET /api/integrations/chat/status", () => {
|
|
|
201
207
|
webhookUrl: `${PUBLIC_URL}/api/integrations/chat/discord/webhook`,
|
|
202
208
|
});
|
|
203
209
|
expect(byName.teams).toMatchObject({ configured: false, health: "disabled", connected: false });
|
|
210
|
+
expect(byName.rocketchat).toMatchObject({
|
|
211
|
+
configured: false,
|
|
212
|
+
health: "disabled",
|
|
213
|
+
connected: false,
|
|
214
|
+
webhookUrl: `${PUBLIC_URL}/api/integrations/chat/rocketchat/webhook`,
|
|
215
|
+
});
|
|
204
216
|
});
|
|
205
217
|
|
|
206
218
|
test("flags the Slack clash when SLACK_DISABLE is not true", async () => {
|
|
@@ -226,7 +226,9 @@ describe("CodexAppServer", () => {
|
|
|
226
226
|
|
|
227
227
|
for (const { name, launchOnGateway } of [
|
|
228
228
|
{
|
|
229
|
-
|
|
229
|
+
// Codex <= 0.167 rejected this turn ("your current provider is openai").
|
|
230
|
+
// 0.168+ honors the thread-level provider, so both launches start the turn.
|
|
231
|
+
name: "pinned Codex accepts a gateway turn on an app-server launched without it",
|
|
230
232
|
launchOnGateway: false,
|
|
231
233
|
},
|
|
232
234
|
{
|
|
@@ -267,11 +269,7 @@ describe("CodexAppServer", () => {
|
|
|
267
269
|
threadId: started.thread.id,
|
|
268
270
|
input: [{ type: "text", text: "hi" }],
|
|
269
271
|
});
|
|
270
|
-
|
|
271
|
-
else
|
|
272
|
-
await expect(turn).rejects.toThrow(
|
|
273
|
-
"This chat uses swarm-gateway, but your current provider is openai",
|
|
274
|
-
);
|
|
272
|
+
await turn;
|
|
275
273
|
} finally {
|
|
276
274
|
await server.close();
|
|
277
275
|
await rm(home, { recursive: true, force: true });
|