@desplega.ai/agent-swarm 1.105.0 → 1.107.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/{actions-45g8tvc8.js → actions-q3hcb6ea.js} +7 -7
- package/dist/{anthropic-messages-8q7p5vyq.js → anthropic-messages-8nc6r2dw.js} +10 -4
- package/dist/{app-18x5k1cj.js → app-4r3mstc2.js} +3 -3
- package/dist/{assistant-ka281qe8.js → assistant-a6vp3nv8.js} +10 -10
- package/dist/{azure-openai-responses-0dmr2hzc.js → azure-openai-responses-6yfzw3qw.js} +10 -18
- package/dist/{boot-reembed-f38vbxw8.js → boot-reembed-cnsk021h.js} +3 -3
- package/dist/{boot-reembed-rp2gba79.js → boot-reembed-gaxjq6ds.js} +4 -4
- package/dist/{boot-scrub-logs-nsnc9f1a.js → boot-scrub-logs-sm0m581p.js} +2 -2
- package/dist/{claude-adapter-e3dhkq85.js → claude-adapter-hw0wsvpj.js} +3 -2
- package/dist/{claude-managed-adapter-z29hjgzz.js → claude-managed-adapter-vj9kzegz.js} +4 -4
- package/dist/{claude-managed-setup-ftbmvmvx.js → claude-managed-setup-yhbcx0bz.js} +2 -2
- package/dist/{cli-92fqyjcv.js → cli-07er7wrs.js} +1 -1
- package/dist/{cli-vpwffend.js → cli-2yn35y8c.js} +5 -4
- package/dist/{cli-0s37sw3k.js → cli-3jcx2wmm.js} +1 -1
- package/dist/{cli-p04j6hjv.js → cli-4r9m8f3t.js} +11 -2
- package/dist/{cli-87fj1jk4.js → cli-4rx7v585.js} +1 -1
- package/dist/{cli-4df7btj0.js → cli-5nt81kzd.js} +1 -1
- package/dist/{cli-c4h8m0m3.js → cli-5s8hgqmd.js} +1 -1
- package/dist/{cli-gzmv1371.js → cli-61hj3yzp.js} +5 -5
- package/dist/{cli-7b9ctyfq.js → cli-8da61htc.js} +1 -1
- package/dist/{cli-0e24r2b6.js → cli-8p36pjyp.js} +346 -201
- package/dist/{cli-sm9yseh1.js → cli-938phztx.js} +1 -1
- package/dist/{cli-yfyqsqzj.js → cli-9xjc8dt2.js} +1 -1
- package/dist/{cli-4wmnp8q3.js → cli-amncg1dq.js} +108 -21
- package/dist/{cli-yzr0qxx1.js → cli-awqz8v9k.js} +101 -43
- package/dist/{cli-ncg70f07.js → cli-bk526b46.js} +30 -4
- package/dist/{cli-2q1ct4en.js → cli-bsyka9ta.js} +104 -3
- package/dist/{cli-ehcjr5vs.js → cli-ccre5q9r.js} +9 -7
- package/dist/{cli-ba47wf2q.js → cli-f8cdgmdk.js} +3 -3
- package/dist/{cli-zmta7t3y.js → cli-heavyg0w.js} +4 -4
- package/dist/{cli-dd6tegmp.js → cli-hn38x1bp.js} +2 -2
- package/dist/{cli-p03mawph.js → cli-hr69yv51.js} +929 -336
- package/dist/{cli-yp2krx5r.js → cli-jk4tj5m6.js} +9 -3
- package/dist/{cli-v2fb1fxf.js → cli-kgr1cazt.js} +1105 -18
- package/dist/{cli-0n4xxmy0.js → cli-n4qvvhy0.js} +1 -1
- package/dist/cli-pscrc6tw.js +73 -0
- package/dist/{cli-2hg6bj31.js → cli-r0nfastp.js} +64 -30
- package/dist/{cli-634jy7sa.js → cli-rpjrpkzy.js} +1 -1
- package/dist/{cli-0fxvpa2q.js → cli-sdpnhajn.js} +150 -163
- package/dist/{cli-yd29d4n4.js → cli-t6r1ex00.js} +2 -2
- package/dist/{cli-8y7y1vmp.js → cli-t7cyte2g.js} +2 -2
- package/dist/{cli-7esh9fda.js → cli-tda8d5q0.js} +2 -2
- package/dist/{cli-0k9dc6ks.js → cli-tghre7g6.js} +1 -0
- package/dist/cli-tkmm5nf9.js +4178 -0
- package/dist/{cli-wztagmpk.js → cli-wb4j4tfe.js} +98 -15
- package/dist/{cli-khe4x17a.js → cli-wnkwyhmw.js} +35 -16
- package/dist/{cli-sdf2qwkt.js → cli-xaht317v.js} +548 -152
- package/dist/{cli-jntqphs0.js → cli-ygcrdkqt.js} +15 -9
- package/dist/{cli-2957pqpj.js → cli-yv9dttkh.js} +32 -9
- package/dist/cli.js +22 -19
- package/dist/{codex-adapter-w0xharsg.js → codex-adapter-wer4en6f.js} +9 -6
- package/dist/{codex-login-27ea9qfw.js → codex-login-4sywkz6v.js} +1 -1
- package/dist/{codex-session-runner-kzbjcm2k.js → codex-session-runner-b199pwwr.js} +7 -6
- package/dist/{commands-tn8zj0an.js → commands-ys948zs2.js} +2 -2
- package/dist/{db-gtqymk7r.js → db-sy3tqg9d.js} +4 -2
- package/dist/{google-generative-ai-mdn340ga.js → google-generative-ai-rf42vj2h.js} +9 -4
- package/dist/{google-vertex-mkdewpwe.js → google-vertex-m92pj5fb.js} +9 -4
- package/dist/{handlers-5xdqk40d.js → handlers-h9vh0t22.js} +10 -10
- package/dist/{hook-gj6j6zwj.js → hook-06rfe1bc.js} +4 -4
- package/dist/{http-4pceba9h.js → http-fk80h22g.js} +710 -140
- package/dist/{index-as4evz9g.js → index-0krvvan6.js} +9 -10
- package/dist/{index-paaw4xt5.js → index-40wjvdfg.js} +12 -14
- package/dist/index-bb95344w.js +30 -0
- package/dist/{index-wf0q4k03.js → index-pq2d08xe.js} +10 -6
- package/dist/{keepalive-akbzjt41.js → keepalive-np0ham11.js} +4 -4
- package/dist/{lead-g8v85nf4.js → lead-gf7sa5vn.js} +28 -28
- package/dist/{maintenance-9yrzmrh8.js → maintenance-38n2z7p9.js} +4 -4
- package/dist/{mistral-conversations-j380wd2q.js → mistral-conversations-26yrnbf1.js} +2 -2
- package/dist/{onboard-v5bx0kpy.js → onboard-63r24gwq.js} +2 -2
- package/dist/{openai-codex-responses-v80z7kgx.js → openai-codex-responses-8h6kvfv8.js} +16 -25
- package/dist/{openai-completions-39vefwrq.js → openai-completions-x6kjnqjd.js} +11 -5
- package/dist/{openai-responses-dp5bkm3q.js → openai-responses-7jwyz3ds.js} +8 -16
- package/dist/{opencode-adapter-s8vsmzpy.js → opencode-adapter-5jxw9cv8.js} +3 -2
- package/dist/{openrouter-images-54cva05t.js → openrouter-images-537nmn1r.js} +5 -1
- package/dist/{otel-impl-530442da.js → otel-impl-18fxmezz.js} +1 -1
- package/dist/{pi-mono-adapter-zf7dt1wg.js → pi-mono-adapter-5bbyymfw.js} +615 -304
- package/dist/{pricing-refresh-dt289v11.js → pricing-refresh-x7b6rjxy.js} +4 -4
- package/dist/{seed-pricing-183er9b3.js → seed-pricing-8hdb1xyg.js} +3 -3
- package/dist/{setup-tjgsvznx.js → setup-prqde3h7.js} +2 -2
- package/dist/{worker-nxcxk5pb.js → worker-34hev47c.js} +28 -28
- package/openapi.json +575 -7
- package/package.json +9 -7
- package/src/be/db.ts +115 -10
- package/src/be/memory/access.ts +5 -0
- package/src/be/migrations/102_script_apis.sql +31 -0
- package/src/be/migrations/103_schedule_target_type.sql +79 -0
- package/src/be/migrations/104_task_reasoning_effort.sql +1 -0
- package/src/be/modelsdev-cache.json +22170 -7247
- package/src/be/scripts/db.ts +214 -1
- package/src/be/seed-pricing.ts +1 -1
- package/src/commands/claude-managed-setup.ts +1 -1
- package/src/commands/provider-credentials.ts +10 -1
- package/src/commands/runner.ts +57 -2
- package/src/heartbeat/heartbeat.ts +8 -1
- package/src/hooks/tool-loop-detection.test.ts +81 -1
- package/src/hooks/tool-loop-detection.ts +53 -10
- package/src/http/agents.ts +76 -16
- package/src/http/index.ts +13 -1
- package/src/http/mcp.ts +49 -0
- package/src/http/memory.ts +21 -11
- package/src/http/oauth-locks.ts +90 -0
- package/src/http/schedules.ts +102 -61
- package/src/http/scripts.ts +213 -0
- package/src/http/stats.ts +6 -0
- package/src/http/tasks.ts +3 -0
- package/src/http/x.ts +244 -0
- package/src/prompts/session-templates.ts +5 -1
- package/src/providers/claude-adapter.ts +13 -0
- package/src/providers/claude-managed-models.ts +9 -0
- package/src/providers/codex-adapter.ts +75 -11
- package/src/providers/codex-oauth/auth-json-fs.ts +9 -1
- package/src/providers/codex-oauth/auth-json.ts +24 -2
- package/src/providers/codex-oauth/storage.ts +184 -23
- package/src/providers/modelsdev-reasoning.json +4034 -0
- package/src/providers/opencode-adapter.ts +38 -1
- package/src/providers/pi-mono-adapter.ts +21 -3
- package/src/providers/reasoning-effort.ts +299 -0
- package/src/providers/types.ts +18 -0
- package/src/scheduler/index.ts +8 -1
- package/src/scheduler/scheduler.test.ts +1 -0
- package/src/scheduler/scheduler.ts +144 -53
- package/src/server.ts +2 -0
- package/src/tests/agents-harness-provider.test.ts +294 -0
- package/src/tests/agents-list-model-display.test.ts +12 -0
- package/src/tests/bedrock-model-groups.test.ts +3 -0
- package/src/tests/claude-adapter.test.ts +65 -1
- package/src/tests/claude-managed-adapter.test.ts +14 -0
- package/src/tests/claude-managed-setup.test.ts +3 -3
- package/src/tests/codex-adapter-pool-auth-revalidate.test.ts +406 -0
- package/src/tests/codex-adapter.test.ts +40 -0
- package/src/tests/codex-oauth-refresh-lock.test.ts +321 -0
- package/src/tests/codex-oauth-storage.test.ts +20 -1
- package/src/tests/context-window.test.ts +1 -0
- package/src/tests/credential-status-routing.test.ts +57 -0
- package/src/tests/harness-provider-resolution.test.ts +39 -0
- package/src/tests/heartbeat.test.ts +17 -0
- package/src/tests/http-api-integration.test.ts +1 -1
- package/src/tests/mcp-user-route.test.ts +70 -5
- package/src/tests/memory-get-tool.test.ts +132 -0
- package/src/tests/memory-http-recall-gating.test.ts +17 -1
- package/src/tests/migration-046-budgets.test.ts +32 -0
- package/src/tests/model-control.test.ts +136 -0
- package/src/tests/opencode-adapter.test.ts +55 -0
- package/src/tests/pi-mono-adapter.test.ts +68 -2
- package/src/tests/preload.ts +26 -0
- package/src/tests/reasoning-effort.test.ts +203 -0
- package/src/tests/register-service-security.test.ts +194 -0
- package/src/tests/schedule-target-type.test.ts +472 -0
- package/src/tests/script-apis-mcp.test.ts +308 -0
- package/src/tests/scripts-external-api.test.ts +449 -0
- package/src/tests/session-costs-model-key-normalize.test.ts +1 -0
- package/src/tests/update-profile-auth.test.ts +35 -1
- package/src/tests/workflow-agent-task.test.ts +2 -0
- package/src/tools/memory-get.ts +17 -2
- package/src/tools/register-service.ts +68 -4
- package/src/tools/schedules/create-schedule.ts +85 -4
- package/src/tools/schedules/update-schedule.ts +81 -2
- package/src/tools/script-apis.ts +158 -0
- package/src/tools/script-common.ts +1 -1
- package/src/tools/send-task.ts +8 -0
- package/src/tools/task-action.ts +5 -0
- package/src/tools/tool-config.ts +2 -1
- package/src/tools/update-profile.ts +84 -1
- package/src/types.ts +67 -2
- package/src/utils/context-window.ts +1 -0
- package/src/utils/harness-provider.ts +35 -6
- package/src/utils/short-id.ts +44 -0
- package/src/workflows/executors/agent-task.ts +8 -1
- package/templates/community/code-health-reports/run.sh +12 -6
- package/templates/community/dora-metrics/run.sh +10 -2
- package/templates/official/coder/start-up.sh +2 -2
- package/templates/official/content-reviewer/start-up.sh +2 -2
- package/templates/official/content-strategist/start-up.sh +2 -2
- package/templates/official/content-writer/start-up.sh +2 -2
- package/templates/official/discoverability-optimizer/start-up.sh +2 -2
- package/templates/official/ux-principles/start-up.sh +5 -5
- package/templates/skills/swarm-scripts/SKILL.md +4 -0
- package/templates/skills/swarm-scripts/content.md +4 -0
- package/dist/cli-gq7gvvrn.js +0 -1112
- package/dist/index-0rfp6wh2.js +0 -21
|
@@ -1,12 +1,16 @@
|
|
|
1
1
|
import {
|
|
2
2
|
embedScript
|
|
3
|
-
} from "./cli-
|
|
3
|
+
} from "./cli-hn38x1bp.js";
|
|
4
4
|
import {
|
|
5
5
|
computeContentHash,
|
|
6
|
+
decryptSecret,
|
|
7
|
+
encryptSecret,
|
|
6
8
|
getDb,
|
|
9
|
+
getEncryptionKey,
|
|
7
10
|
getSwarmConfigs,
|
|
11
|
+
init_crypto,
|
|
8
12
|
init_db
|
|
9
|
-
} from "./cli-
|
|
13
|
+
} from "./cli-wb4j4tfe.js";
|
|
10
14
|
import {
|
|
11
15
|
init_zod
|
|
12
16
|
} from "./cli-q21d49ac.js";
|
|
@@ -18,6 +22,10 @@ import {
|
|
|
18
22
|
string,
|
|
19
23
|
union
|
|
20
24
|
} from "./cli-anrj584m.js";
|
|
25
|
+
import {
|
|
26
|
+
init_secret_scrubber,
|
|
27
|
+
registerVolatileSecret
|
|
28
|
+
} from "./cli-3pp1362w.js";
|
|
21
29
|
import {
|
|
22
30
|
__commonJS,
|
|
23
31
|
__require,
|
|
@@ -168745,6 +168753,339 @@ Additional information: BADCLIENT: Bad error code, ${badCode} not found in range
|
|
|
168745
168753
|
} });
|
|
168746
168754
|
});
|
|
168747
168755
|
|
|
168756
|
+
// src/be/scripts/db.ts
|
|
168757
|
+
init_secret_scrubber();
|
|
168758
|
+
|
|
168759
|
+
// src/utils/short-id.ts
|
|
168760
|
+
import { randomBytes } from "node:crypto";
|
|
168761
|
+
var LETTERS = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
|
168762
|
+
var BASE62 = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
|
168763
|
+
function generateShortId(len = 12) {
|
|
168764
|
+
let out = "";
|
|
168765
|
+
while (out.length < len) {
|
|
168766
|
+
for (const byte of randomBytes((len - out.length) * 2)) {
|
|
168767
|
+
if (byte < 208) {
|
|
168768
|
+
out += LETTERS[byte % 52];
|
|
168769
|
+
if (out.length === len)
|
|
168770
|
+
break;
|
|
168771
|
+
}
|
|
168772
|
+
}
|
|
168773
|
+
}
|
|
168774
|
+
return out;
|
|
168775
|
+
}
|
|
168776
|
+
function base62(bytes) {
|
|
168777
|
+
let out = "";
|
|
168778
|
+
for (const byte of bytes)
|
|
168779
|
+
out += BASE62[byte % 62];
|
|
168780
|
+
return out;
|
|
168781
|
+
}
|
|
168782
|
+
function generateBearerToken() {
|
|
168783
|
+
return `xsk_${base62(randomBytes(24))}`;
|
|
168784
|
+
}
|
|
168785
|
+
|
|
168786
|
+
// src/be/scripts/db.ts
|
|
168787
|
+
init_crypto();
|
|
168788
|
+
init_db();
|
|
168789
|
+
function normalizeScopeId(scope, scopeId) {
|
|
168790
|
+
if (scope === "global")
|
|
168791
|
+
return null;
|
|
168792
|
+
if (!scopeId) {
|
|
168793
|
+
throw new Error("scopeId is required for agent-scoped scripts");
|
|
168794
|
+
}
|
|
168795
|
+
return scopeId;
|
|
168796
|
+
}
|
|
168797
|
+
function rowToScript(row) {
|
|
168798
|
+
return {
|
|
168799
|
+
...row,
|
|
168800
|
+
scopeId: row.scopeId ?? null,
|
|
168801
|
+
isScratch: row.isScratch === 1,
|
|
168802
|
+
typeChecked: row.typeChecked === 1,
|
|
168803
|
+
createdByAgentId: row.createdByAgentId ?? null
|
|
168804
|
+
};
|
|
168805
|
+
}
|
|
168806
|
+
function rowToScriptVersion(row) {
|
|
168807
|
+
return {
|
|
168808
|
+
...row,
|
|
168809
|
+
changedByAgentId: row.changedByAgentId ?? null,
|
|
168810
|
+
changeReason: row.changeReason ?? null
|
|
168811
|
+
};
|
|
168812
|
+
}
|
|
168813
|
+
function insertScriptVersion(args) {
|
|
168814
|
+
getDb().prepare(`INSERT INTO script_versions (
|
|
168815
|
+
id, scriptId, version, source, description, intent, signatureJson,
|
|
168816
|
+
contentHash, changedByAgentId, changedAt, changeReason
|
|
168817
|
+
)
|
|
168818
|
+
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`).run(crypto.randomUUID(), args.scriptId, args.version, args.source, args.description, args.intent, args.signatureJson, args.contentHash, args.changedByAgentId ?? null, new Date().toISOString(), args.changeReason ?? null);
|
|
168819
|
+
}
|
|
168820
|
+
function insertScript(args) {
|
|
168821
|
+
const now = new Date().toISOString();
|
|
168822
|
+
const id = crypto.randomUUID();
|
|
168823
|
+
const scopeId = normalizeScopeId(args.scope, args.scopeId);
|
|
168824
|
+
const contentHash = computeContentHash(args.source);
|
|
168825
|
+
const fsMode = args.fsMode ?? "none";
|
|
168826
|
+
const isScratch = args.isScratch ? 1 : 0;
|
|
168827
|
+
const typeChecked = args.typeChecked ? 1 : 0;
|
|
168828
|
+
const txn = getDb().transaction(() => {
|
|
168829
|
+
const row = getDb().prepare(`INSERT INTO scripts (
|
|
168830
|
+
id, name, scope, scopeId, source, description, intent, signatureJson,
|
|
168831
|
+
argsJsonSchema, contentHash, isScratch, typeChecked, fsMode, createdByAgentId, createdAt, updatedAt,
|
|
168832
|
+
created_by, updated_by
|
|
168833
|
+
)
|
|
168834
|
+
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
|
168835
|
+
RETURNING *`).get(id, args.name, args.scope, scopeId, args.source, args.description, args.intent, args.signatureJson, args.argsJsonSchema ?? null, contentHash, isScratch, typeChecked, fsMode, args.agentId ?? null, now, now, args.createdBy ?? null, args.createdBy ?? null);
|
|
168836
|
+
if (!row)
|
|
168837
|
+
throw new Error("Failed to insert script");
|
|
168838
|
+
insertScriptVersion({
|
|
168839
|
+
scriptId: row.id,
|
|
168840
|
+
version: row.version,
|
|
168841
|
+
source: row.source,
|
|
168842
|
+
description: row.description,
|
|
168843
|
+
intent: row.intent,
|
|
168844
|
+
signatureJson: row.signatureJson,
|
|
168845
|
+
contentHash: row.contentHash,
|
|
168846
|
+
changedByAgentId: args.agentId ?? null,
|
|
168847
|
+
changeReason: args.changeReason ?? "Initial creation"
|
|
168848
|
+
});
|
|
168849
|
+
return rowToScript(row);
|
|
168850
|
+
});
|
|
168851
|
+
return txn();
|
|
168852
|
+
}
|
|
168853
|
+
async function upsertScriptByName(args) {
|
|
168854
|
+
const shouldEmbed = args.embeddingMode !== "skip";
|
|
168855
|
+
const existing = getScript(args);
|
|
168856
|
+
if (!existing) {
|
|
168857
|
+
const script2 = insertScript(args);
|
|
168858
|
+
if (!script2.isScratch && shouldEmbed) {
|
|
168859
|
+
await embedScript(script2);
|
|
168860
|
+
}
|
|
168861
|
+
return {
|
|
168862
|
+
script: script2,
|
|
168863
|
+
isNew: true,
|
|
168864
|
+
contentDeduped: false
|
|
168865
|
+
};
|
|
168866
|
+
}
|
|
168867
|
+
const contentHash = computeContentHash(args.source);
|
|
168868
|
+
if (existing.contentHash === contentHash) {
|
|
168869
|
+
const fsMode2 = args.fsMode ?? existing.fsMode;
|
|
168870
|
+
const isScratch2 = args.isScratch ?? existing.isScratch;
|
|
168871
|
+
const typeChecked2 = args.typeChecked ?? existing.typeChecked;
|
|
168872
|
+
const argsJsonSchema2 = args.argsJsonSchema !== undefined ? args.argsJsonSchema : existing.argsJsonSchema;
|
|
168873
|
+
const trackedMetadataChanged = args.description !== existing.description || args.intent !== existing.intent || args.signatureJson !== existing.signatureJson || argsJsonSchema2 !== existing.argsJsonSchema;
|
|
168874
|
+
const promotedFromScratch = existing.isScratch && !isScratch2;
|
|
168875
|
+
if (fsMode2 !== existing.fsMode || isScratch2 !== existing.isScratch || typeChecked2 !== existing.typeChecked || trackedMetadataChanged) {
|
|
168876
|
+
const row = getDb().prepare(`UPDATE scripts
|
|
168877
|
+
SET description = ?, intent = ?, signatureJson = ?, argsJsonSchema = ?,
|
|
168878
|
+
isScratch = ?, typeChecked = ?, fsMode = ?, updatedAt = ?, updated_by = ?
|
|
168879
|
+
WHERE id = ?
|
|
168880
|
+
RETURNING *`).get(args.description, args.intent, args.signatureJson, argsJsonSchema2 ?? null, isScratch2 ? 1 : 0, typeChecked2 ? 1 : 0, fsMode2, new Date().toISOString(), args.createdBy ?? null, existing.id);
|
|
168881
|
+
if (!row)
|
|
168882
|
+
throw new Error("Failed to update script metadata");
|
|
168883
|
+
const script2 = rowToScript(row);
|
|
168884
|
+
if (!script2.isScratch && shouldEmbed && (trackedMetadataChanged || promotedFromScratch)) {
|
|
168885
|
+
await embedScript(script2);
|
|
168886
|
+
}
|
|
168887
|
+
return {
|
|
168888
|
+
script: script2,
|
|
168889
|
+
isNew: false,
|
|
168890
|
+
contentDeduped: true
|
|
168891
|
+
};
|
|
168892
|
+
}
|
|
168893
|
+
return {
|
|
168894
|
+
script: existing,
|
|
168895
|
+
isNew: false,
|
|
168896
|
+
contentDeduped: true
|
|
168897
|
+
};
|
|
168898
|
+
}
|
|
168899
|
+
const now = new Date().toISOString();
|
|
168900
|
+
const newVersion = existing.version + 1;
|
|
168901
|
+
const fsMode = args.fsMode ?? existing.fsMode;
|
|
168902
|
+
const isScratch = args.isScratch ?? existing.isScratch;
|
|
168903
|
+
const typeChecked = args.typeChecked ?? existing.typeChecked;
|
|
168904
|
+
const argsJsonSchema = args.argsJsonSchema !== undefined ? args.argsJsonSchema : existing.argsJsonSchema;
|
|
168905
|
+
const txn = getDb().transaction(() => {
|
|
168906
|
+
const row = getDb().prepare(`UPDATE scripts
|
|
168907
|
+
SET source = ?, description = ?, intent = ?, signatureJson = ?, argsJsonSchema = ?,
|
|
168908
|
+
contentHash = ?, version = ?, isScratch = ?, typeChecked = ?, fsMode = ?, updatedAt = ?, updated_by = ?
|
|
168909
|
+
WHERE id = ?
|
|
168910
|
+
RETURNING *`).get(args.source, args.description, args.intent, args.signatureJson, argsJsonSchema ?? null, contentHash, newVersion, isScratch ? 1 : 0, typeChecked ? 1 : 0, fsMode, now, args.createdBy ?? null, existing.id);
|
|
168911
|
+
if (!row)
|
|
168912
|
+
throw new Error("Failed to update script");
|
|
168913
|
+
insertScriptVersion({
|
|
168914
|
+
scriptId: row.id,
|
|
168915
|
+
version: row.version,
|
|
168916
|
+
source: row.source,
|
|
168917
|
+
description: row.description,
|
|
168918
|
+
intent: row.intent,
|
|
168919
|
+
signatureJson: row.signatureJson,
|
|
168920
|
+
contentHash: row.contentHash,
|
|
168921
|
+
changedByAgentId: args.agentId ?? null,
|
|
168922
|
+
changeReason: args.changeReason ?? null
|
|
168923
|
+
});
|
|
168924
|
+
return rowToScript(row);
|
|
168925
|
+
});
|
|
168926
|
+
const script = txn();
|
|
168927
|
+
if (!script.isScratch && shouldEmbed) {
|
|
168928
|
+
await embedScript(script);
|
|
168929
|
+
}
|
|
168930
|
+
return {
|
|
168931
|
+
script,
|
|
168932
|
+
isNew: false,
|
|
168933
|
+
contentDeduped: false
|
|
168934
|
+
};
|
|
168935
|
+
}
|
|
168936
|
+
function getScript(args) {
|
|
168937
|
+
const scopeId = normalizeScopeId(args.scope, args.scopeId);
|
|
168938
|
+
const row = scopeId === null ? getDb().prepare("SELECT * FROM scripts WHERE name = ? AND scope = ? AND scopeId IS NULL").get(args.name, args.scope) : getDb().prepare("SELECT * FROM scripts WHERE name = ? AND scope = ? AND scopeId = ?").get(args.name, args.scope, scopeId);
|
|
168939
|
+
return row ? rowToScript(row) : null;
|
|
168940
|
+
}
|
|
168941
|
+
function getScriptById(id) {
|
|
168942
|
+
const row = getDb().prepare("SELECT * FROM scripts WHERE id = ?").get(id);
|
|
168943
|
+
return row ? rowToScript(row) : null;
|
|
168944
|
+
}
|
|
168945
|
+
function getScriptVersion(args) {
|
|
168946
|
+
if (args.version === undefined && args.contentHash === undefined) {
|
|
168947
|
+
throw new Error("version or contentHash is required");
|
|
168948
|
+
}
|
|
168949
|
+
const row = args.version !== undefined ? getDb().prepare("SELECT * FROM script_versions WHERE scriptId = ? AND version = ?").get(args.scriptId, args.version) : getDb().prepare("SELECT * FROM script_versions WHERE scriptId = ? AND contentHash = ? ORDER BY version DESC LIMIT 1").get(args.scriptId, args.contentHash);
|
|
168950
|
+
return row ? rowToScriptVersion(row) : null;
|
|
168951
|
+
}
|
|
168952
|
+
function listScripts(args) {
|
|
168953
|
+
const conditions = [];
|
|
168954
|
+
const params = [];
|
|
168955
|
+
if (args?.scope) {
|
|
168956
|
+
conditions.push("scope = ?");
|
|
168957
|
+
params.push(args.scope);
|
|
168958
|
+
if (args.scope === "global") {
|
|
168959
|
+
conditions.push("scopeId IS NULL");
|
|
168960
|
+
} else if (args.scopeId !== undefined) {
|
|
168961
|
+
conditions.push("scopeId = ?");
|
|
168962
|
+
params.push(normalizeScopeId(args.scope, args.scopeId));
|
|
168963
|
+
}
|
|
168964
|
+
} else if (args?.scopeId !== undefined) {
|
|
168965
|
+
conditions.push("scopeId = ?");
|
|
168966
|
+
params.push(args.scopeId ?? "");
|
|
168967
|
+
}
|
|
168968
|
+
if (!args?.includeScratch) {
|
|
168969
|
+
conditions.push("isScratch = 0");
|
|
168970
|
+
}
|
|
168971
|
+
const whereClause = conditions.length > 0 ? `WHERE ${conditions.join(" AND ")}` : "";
|
|
168972
|
+
return getDb().prepare(`SELECT * FROM scripts ${whereClause} ORDER BY scope ASC, scopeId ASC, name ASC`).all(...params).map(rowToScript);
|
|
168973
|
+
}
|
|
168974
|
+
function listScriptVersions(scriptId) {
|
|
168975
|
+
return getDb().prepare("SELECT * FROM script_versions WHERE scriptId = ? ORDER BY version DESC").all(scriptId).map(rowToScriptVersion);
|
|
168976
|
+
}
|
|
168977
|
+
function deleteScript(args) {
|
|
168978
|
+
const existing = getScript(args);
|
|
168979
|
+
if (!existing)
|
|
168980
|
+
return false;
|
|
168981
|
+
const result = getDb().run("DELETE FROM scripts WHERE id = ?", [existing.id]);
|
|
168982
|
+
return result.changes > 0;
|
|
168983
|
+
}
|
|
168984
|
+
var SCRIPT_API_ID_LEN = 12;
|
|
168985
|
+
function rowToScriptApi(row) {
|
|
168986
|
+
return {
|
|
168987
|
+
id: row.id,
|
|
168988
|
+
scriptId: row.scriptId,
|
|
168989
|
+
agentId: row.agentId,
|
|
168990
|
+
authMode: row.authMode,
|
|
168991
|
+
enabled: row.enabled === 1,
|
|
168992
|
+
label: row.label ?? null,
|
|
168993
|
+
callCount: row.callCount,
|
|
168994
|
+
lastUsedAt: row.lastUsedAt ?? null,
|
|
168995
|
+
createdAt: row.createdAt
|
|
168996
|
+
};
|
|
168997
|
+
}
|
|
168998
|
+
function isUniqueConstraintError(err) {
|
|
168999
|
+
return err instanceof Error && /UNIQUE constraint failed/i.test(err.message);
|
|
169000
|
+
}
|
|
169001
|
+
function createScriptApi(args) {
|
|
169002
|
+
const now = new Date().toISOString();
|
|
169003
|
+
const token = args.authMode === "bearer" ? generateBearerToken() : null;
|
|
169004
|
+
const encrypted = token ? encryptSecret(token, getEncryptionKey()) : null;
|
|
169005
|
+
const createdBy = args.createdBy ?? null;
|
|
169006
|
+
for (let attempt = 0;attempt < 5; attempt++) {
|
|
169007
|
+
const id = generateShortId(SCRIPT_API_ID_LEN);
|
|
169008
|
+
try {
|
|
169009
|
+
const row = getDb().prepare(`INSERT INTO script_apis
|
|
169010
|
+
(id, scriptId, agentId, authMode, bearerTokenEncrypted, enabled, label,
|
|
169011
|
+
callCount, lastUsedAt, createdAt, created_by, updated_by)
|
|
169012
|
+
VALUES (?, ?, ?, ?, ?, 1, ?, 0, NULL, ?, ?, ?)
|
|
169013
|
+
RETURNING *`).get(id, args.scriptId, args.agentId, args.authMode, encrypted, args.label ?? null, now, createdBy, createdBy);
|
|
169014
|
+
if (!row)
|
|
169015
|
+
throw new Error("Failed to create script API endpoint");
|
|
169016
|
+
if (token)
|
|
169017
|
+
registerVolatileSecret(token, `script-api:${id}`);
|
|
169018
|
+
return { ...rowToScriptApi(row), token };
|
|
169019
|
+
} catch (err) {
|
|
169020
|
+
if (isUniqueConstraintError(err) && attempt < 4)
|
|
169021
|
+
continue;
|
|
169022
|
+
throw err;
|
|
169023
|
+
}
|
|
169024
|
+
}
|
|
169025
|
+
throw new Error("Failed to allocate a unique script API endpoint id");
|
|
169026
|
+
}
|
|
169027
|
+
function listScriptApisForScript(scriptId) {
|
|
169028
|
+
return getDb().prepare("SELECT * FROM script_apis WHERE scriptId = ? ORDER BY createdAt DESC").all(scriptId).map(rowToScriptApi);
|
|
169029
|
+
}
|
|
169030
|
+
function getScriptApiById(id) {
|
|
169031
|
+
const row = getDb().prepare("SELECT * FROM script_apis WHERE id = ?").get(id);
|
|
169032
|
+
if (!row)
|
|
169033
|
+
return null;
|
|
169034
|
+
return { ...rowToScriptApi(row), bearerTokenEncrypted: row.bearerTokenEncrypted ?? null };
|
|
169035
|
+
}
|
|
169036
|
+
function getScriptApiSecret(id) {
|
|
169037
|
+
const row = getDb().prepare("SELECT bearerTokenEncrypted FROM script_apis WHERE id = ?").get(id);
|
|
169038
|
+
if (!row?.bearerTokenEncrypted)
|
|
169039
|
+
return null;
|
|
169040
|
+
const token = decryptSecret(row.bearerTokenEncrypted, getEncryptionKey());
|
|
169041
|
+
registerVolatileSecret(token, `script-api:${id}`);
|
|
169042
|
+
return token;
|
|
169043
|
+
}
|
|
169044
|
+
function updateScriptApi(id, args) {
|
|
169045
|
+
const sets = [];
|
|
169046
|
+
const vals = [];
|
|
169047
|
+
if (args.enabled !== undefined) {
|
|
169048
|
+
sets.push("enabled = ?");
|
|
169049
|
+
vals.push(args.enabled ? 1 : 0);
|
|
169050
|
+
}
|
|
169051
|
+
if (args.label !== undefined) {
|
|
169052
|
+
sets.push("label = ?");
|
|
169053
|
+
vals.push(args.label);
|
|
169054
|
+
}
|
|
169055
|
+
if (args.updatedBy !== undefined) {
|
|
169056
|
+
sets.push("updated_by = ?");
|
|
169057
|
+
vals.push(args.updatedBy);
|
|
169058
|
+
}
|
|
169059
|
+
if (sets.length === 0) {
|
|
169060
|
+
const row2 = getDb().prepare("SELECT * FROM script_apis WHERE id = ?").get(id);
|
|
169061
|
+
return row2 ? rowToScriptApi(row2) : null;
|
|
169062
|
+
}
|
|
169063
|
+
vals.push(id);
|
|
169064
|
+
const row = getDb().prepare(`UPDATE script_apis SET ${sets.join(", ")} WHERE id = ? RETURNING *`).get(...vals);
|
|
169065
|
+
return row ? rowToScriptApi(row) : null;
|
|
169066
|
+
}
|
|
169067
|
+
function rotateScriptApiSecret(id, updatedBy) {
|
|
169068
|
+
const existing = getScriptApiById(id);
|
|
169069
|
+
if (!existing || existing.authMode !== "bearer")
|
|
169070
|
+
return null;
|
|
169071
|
+
const token = generateBearerToken();
|
|
169072
|
+
const encrypted = encryptSecret(token, getEncryptionKey());
|
|
169073
|
+
const row = getDb().prepare("UPDATE script_apis SET bearerTokenEncrypted = ?, updated_by = ? WHERE id = ? RETURNING *").get(encrypted, updatedBy ?? null, id);
|
|
169074
|
+
if (!row)
|
|
169075
|
+
return null;
|
|
169076
|
+
registerVolatileSecret(token, `script-api:${id}`);
|
|
169077
|
+
return { ...rowToScriptApi(row), token };
|
|
169078
|
+
}
|
|
169079
|
+
function deleteScriptApi(id) {
|
|
169080
|
+
return getDb().run("DELETE FROM script_apis WHERE id = ?", [id]).changes > 0;
|
|
169081
|
+
}
|
|
169082
|
+
function recordScriptApiUsage(id) {
|
|
169083
|
+
getDb().run("UPDATE script_apis SET callCount = callCount + 1, lastUsedAt = ? WHERE id = ?", [
|
|
169084
|
+
new Date().toISOString(),
|
|
169085
|
+
id
|
|
169086
|
+
]);
|
|
169087
|
+
}
|
|
169088
|
+
|
|
168748
169089
|
// src/scripts-runtime/credential-broker/types.ts
|
|
168749
169090
|
init_zod();
|
|
168750
169091
|
var CREDENTIAL_BINDINGS_CONFIG_KEY = "SCRIPT_CREDENTIAL_BINDINGS";
|
|
@@ -168820,6 +169161,7 @@ class CredentialBroker {
|
|
|
168820
169161
|
return resolved;
|
|
168821
169162
|
}
|
|
168822
169163
|
}
|
|
169164
|
+
|
|
168823
169165
|
// src/scripts-runtime/credential-broker/default-bindings.ts
|
|
168824
169166
|
var DEFAULT_CREDENTIAL_BINDINGS = [
|
|
168825
169167
|
{
|
|
@@ -168831,6 +169173,7 @@ var DEFAULT_CREDENTIAL_BINDINGS = [
|
|
|
168831
169173
|
active: true
|
|
168832
169174
|
}
|
|
168833
169175
|
];
|
|
169176
|
+
|
|
168834
169177
|
// src/scripts-runtime/credential-broker/store.ts
|
|
168835
169178
|
function appliesToContext(binding, context) {
|
|
168836
169179
|
if (binding.scope === "global")
|
|
@@ -169281,204 +169624,6 @@ ${members.join(`
|
|
|
169281
169624
|
`;
|
|
169282
169625
|
}
|
|
169283
169626
|
|
|
169284
|
-
// src/be/scripts/db.ts
|
|
169285
|
-
init_db();
|
|
169286
|
-
function normalizeScopeId(scope, scopeId) {
|
|
169287
|
-
if (scope === "global")
|
|
169288
|
-
return null;
|
|
169289
|
-
if (!scopeId) {
|
|
169290
|
-
throw new Error("scopeId is required for agent-scoped scripts");
|
|
169291
|
-
}
|
|
169292
|
-
return scopeId;
|
|
169293
|
-
}
|
|
169294
|
-
function rowToScript(row) {
|
|
169295
|
-
return {
|
|
169296
|
-
...row,
|
|
169297
|
-
scopeId: row.scopeId ?? null,
|
|
169298
|
-
isScratch: row.isScratch === 1,
|
|
169299
|
-
typeChecked: row.typeChecked === 1,
|
|
169300
|
-
createdByAgentId: row.createdByAgentId ?? null
|
|
169301
|
-
};
|
|
169302
|
-
}
|
|
169303
|
-
function rowToScriptVersion(row) {
|
|
169304
|
-
return {
|
|
169305
|
-
...row,
|
|
169306
|
-
changedByAgentId: row.changedByAgentId ?? null,
|
|
169307
|
-
changeReason: row.changeReason ?? null
|
|
169308
|
-
};
|
|
169309
|
-
}
|
|
169310
|
-
function insertScriptVersion(args) {
|
|
169311
|
-
getDb().prepare(`INSERT INTO script_versions (
|
|
169312
|
-
id, scriptId, version, source, description, intent, signatureJson,
|
|
169313
|
-
contentHash, changedByAgentId, changedAt, changeReason
|
|
169314
|
-
)
|
|
169315
|
-
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`).run(crypto.randomUUID(), args.scriptId, args.version, args.source, args.description, args.intent, args.signatureJson, args.contentHash, args.changedByAgentId ?? null, new Date().toISOString(), args.changeReason ?? null);
|
|
169316
|
-
}
|
|
169317
|
-
function insertScript(args) {
|
|
169318
|
-
const now = new Date().toISOString();
|
|
169319
|
-
const id = crypto.randomUUID();
|
|
169320
|
-
const scopeId = normalizeScopeId(args.scope, args.scopeId);
|
|
169321
|
-
const contentHash = computeContentHash(args.source);
|
|
169322
|
-
const fsMode = args.fsMode ?? "none";
|
|
169323
|
-
const isScratch = args.isScratch ? 1 : 0;
|
|
169324
|
-
const typeChecked = args.typeChecked ? 1 : 0;
|
|
169325
|
-
const txn = getDb().transaction(() => {
|
|
169326
|
-
const row = getDb().prepare(`INSERT INTO scripts (
|
|
169327
|
-
id, name, scope, scopeId, source, description, intent, signatureJson,
|
|
169328
|
-
argsJsonSchema, contentHash, isScratch, typeChecked, fsMode, createdByAgentId, createdAt, updatedAt,
|
|
169329
|
-
created_by, updated_by
|
|
169330
|
-
)
|
|
169331
|
-
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
|
169332
|
-
RETURNING *`).get(id, args.name, args.scope, scopeId, args.source, args.description, args.intent, args.signatureJson, args.argsJsonSchema ?? null, contentHash, isScratch, typeChecked, fsMode, args.agentId ?? null, now, now, args.createdBy ?? null, args.createdBy ?? null);
|
|
169333
|
-
if (!row)
|
|
169334
|
-
throw new Error("Failed to insert script");
|
|
169335
|
-
insertScriptVersion({
|
|
169336
|
-
scriptId: row.id,
|
|
169337
|
-
version: row.version,
|
|
169338
|
-
source: row.source,
|
|
169339
|
-
description: row.description,
|
|
169340
|
-
intent: row.intent,
|
|
169341
|
-
signatureJson: row.signatureJson,
|
|
169342
|
-
contentHash: row.contentHash,
|
|
169343
|
-
changedByAgentId: args.agentId ?? null,
|
|
169344
|
-
changeReason: args.changeReason ?? "Initial creation"
|
|
169345
|
-
});
|
|
169346
|
-
return rowToScript(row);
|
|
169347
|
-
});
|
|
169348
|
-
return txn();
|
|
169349
|
-
}
|
|
169350
|
-
async function upsertScriptByName(args) {
|
|
169351
|
-
const shouldEmbed = args.embeddingMode !== "skip";
|
|
169352
|
-
const existing = getScript(args);
|
|
169353
|
-
if (!existing) {
|
|
169354
|
-
const script2 = insertScript(args);
|
|
169355
|
-
if (!script2.isScratch && shouldEmbed) {
|
|
169356
|
-
await embedScript(script2);
|
|
169357
|
-
}
|
|
169358
|
-
return {
|
|
169359
|
-
script: script2,
|
|
169360
|
-
isNew: true,
|
|
169361
|
-
contentDeduped: false
|
|
169362
|
-
};
|
|
169363
|
-
}
|
|
169364
|
-
const contentHash = computeContentHash(args.source);
|
|
169365
|
-
if (existing.contentHash === contentHash) {
|
|
169366
|
-
const fsMode2 = args.fsMode ?? existing.fsMode;
|
|
169367
|
-
const isScratch2 = args.isScratch ?? existing.isScratch;
|
|
169368
|
-
const typeChecked2 = args.typeChecked ?? existing.typeChecked;
|
|
169369
|
-
const argsJsonSchema2 = args.argsJsonSchema !== undefined ? args.argsJsonSchema : existing.argsJsonSchema;
|
|
169370
|
-
const trackedMetadataChanged = args.description !== existing.description || args.intent !== existing.intent || args.signatureJson !== existing.signatureJson || argsJsonSchema2 !== existing.argsJsonSchema;
|
|
169371
|
-
const promotedFromScratch = existing.isScratch && !isScratch2;
|
|
169372
|
-
if (fsMode2 !== existing.fsMode || isScratch2 !== existing.isScratch || typeChecked2 !== existing.typeChecked || trackedMetadataChanged) {
|
|
169373
|
-
const row = getDb().prepare(`UPDATE scripts
|
|
169374
|
-
SET description = ?, intent = ?, signatureJson = ?, argsJsonSchema = ?,
|
|
169375
|
-
isScratch = ?, typeChecked = ?, fsMode = ?, updatedAt = ?, updated_by = ?
|
|
169376
|
-
WHERE id = ?
|
|
169377
|
-
RETURNING *`).get(args.description, args.intent, args.signatureJson, argsJsonSchema2 ?? null, isScratch2 ? 1 : 0, typeChecked2 ? 1 : 0, fsMode2, new Date().toISOString(), args.createdBy ?? null, existing.id);
|
|
169378
|
-
if (!row)
|
|
169379
|
-
throw new Error("Failed to update script metadata");
|
|
169380
|
-
const script2 = rowToScript(row);
|
|
169381
|
-
if (!script2.isScratch && shouldEmbed && (trackedMetadataChanged || promotedFromScratch)) {
|
|
169382
|
-
await embedScript(script2);
|
|
169383
|
-
}
|
|
169384
|
-
return {
|
|
169385
|
-
script: script2,
|
|
169386
|
-
isNew: false,
|
|
169387
|
-
contentDeduped: true
|
|
169388
|
-
};
|
|
169389
|
-
}
|
|
169390
|
-
return {
|
|
169391
|
-
script: existing,
|
|
169392
|
-
isNew: false,
|
|
169393
|
-
contentDeduped: true
|
|
169394
|
-
};
|
|
169395
|
-
}
|
|
169396
|
-
const now = new Date().toISOString();
|
|
169397
|
-
const newVersion = existing.version + 1;
|
|
169398
|
-
const fsMode = args.fsMode ?? existing.fsMode;
|
|
169399
|
-
const isScratch = args.isScratch ?? existing.isScratch;
|
|
169400
|
-
const typeChecked = args.typeChecked ?? existing.typeChecked;
|
|
169401
|
-
const argsJsonSchema = args.argsJsonSchema !== undefined ? args.argsJsonSchema : existing.argsJsonSchema;
|
|
169402
|
-
const txn = getDb().transaction(() => {
|
|
169403
|
-
const row = getDb().prepare(`UPDATE scripts
|
|
169404
|
-
SET source = ?, description = ?, intent = ?, signatureJson = ?, argsJsonSchema = ?,
|
|
169405
|
-
contentHash = ?, version = ?, isScratch = ?, typeChecked = ?, fsMode = ?, updatedAt = ?, updated_by = ?
|
|
169406
|
-
WHERE id = ?
|
|
169407
|
-
RETURNING *`).get(args.source, args.description, args.intent, args.signatureJson, argsJsonSchema ?? null, contentHash, newVersion, isScratch ? 1 : 0, typeChecked ? 1 : 0, fsMode, now, args.createdBy ?? null, existing.id);
|
|
169408
|
-
if (!row)
|
|
169409
|
-
throw new Error("Failed to update script");
|
|
169410
|
-
insertScriptVersion({
|
|
169411
|
-
scriptId: row.id,
|
|
169412
|
-
version: row.version,
|
|
169413
|
-
source: row.source,
|
|
169414
|
-
description: row.description,
|
|
169415
|
-
intent: row.intent,
|
|
169416
|
-
signatureJson: row.signatureJson,
|
|
169417
|
-
contentHash: row.contentHash,
|
|
169418
|
-
changedByAgentId: args.agentId ?? null,
|
|
169419
|
-
changeReason: args.changeReason ?? null
|
|
169420
|
-
});
|
|
169421
|
-
return rowToScript(row);
|
|
169422
|
-
});
|
|
169423
|
-
const script = txn();
|
|
169424
|
-
if (!script.isScratch && shouldEmbed) {
|
|
169425
|
-
await embedScript(script);
|
|
169426
|
-
}
|
|
169427
|
-
return {
|
|
169428
|
-
script,
|
|
169429
|
-
isNew: false,
|
|
169430
|
-
contentDeduped: false
|
|
169431
|
-
};
|
|
169432
|
-
}
|
|
169433
|
-
function getScript(args) {
|
|
169434
|
-
const scopeId = normalizeScopeId(args.scope, args.scopeId);
|
|
169435
|
-
const row = scopeId === null ? getDb().prepare("SELECT * FROM scripts WHERE name = ? AND scope = ? AND scopeId IS NULL").get(args.name, args.scope) : getDb().prepare("SELECT * FROM scripts WHERE name = ? AND scope = ? AND scopeId = ?").get(args.name, args.scope, scopeId);
|
|
169436
|
-
return row ? rowToScript(row) : null;
|
|
169437
|
-
}
|
|
169438
|
-
function getScriptById(id) {
|
|
169439
|
-
const row = getDb().prepare("SELECT * FROM scripts WHERE id = ?").get(id);
|
|
169440
|
-
return row ? rowToScript(row) : null;
|
|
169441
|
-
}
|
|
169442
|
-
function getScriptVersion(args) {
|
|
169443
|
-
if (args.version === undefined && args.contentHash === undefined) {
|
|
169444
|
-
throw new Error("version or contentHash is required");
|
|
169445
|
-
}
|
|
169446
|
-
const row = args.version !== undefined ? getDb().prepare("SELECT * FROM script_versions WHERE scriptId = ? AND version = ?").get(args.scriptId, args.version) : getDb().prepare("SELECT * FROM script_versions WHERE scriptId = ? AND contentHash = ? ORDER BY version DESC LIMIT 1").get(args.scriptId, args.contentHash);
|
|
169447
|
-
return row ? rowToScriptVersion(row) : null;
|
|
169448
|
-
}
|
|
169449
|
-
function listScripts(args) {
|
|
169450
|
-
const conditions = [];
|
|
169451
|
-
const params = [];
|
|
169452
|
-
if (args?.scope) {
|
|
169453
|
-
conditions.push("scope = ?");
|
|
169454
|
-
params.push(args.scope);
|
|
169455
|
-
if (args.scope === "global") {
|
|
169456
|
-
conditions.push("scopeId IS NULL");
|
|
169457
|
-
} else if (args.scopeId !== undefined) {
|
|
169458
|
-
conditions.push("scopeId = ?");
|
|
169459
|
-
params.push(normalizeScopeId(args.scope, args.scopeId));
|
|
169460
|
-
}
|
|
169461
|
-
} else if (args?.scopeId !== undefined) {
|
|
169462
|
-
conditions.push("scopeId = ?");
|
|
169463
|
-
params.push(args.scopeId ?? "");
|
|
169464
|
-
}
|
|
169465
|
-
if (!args?.includeScratch) {
|
|
169466
|
-
conditions.push("isScratch = 0");
|
|
169467
|
-
}
|
|
169468
|
-
const whereClause = conditions.length > 0 ? `WHERE ${conditions.join(" AND ")}` : "";
|
|
169469
|
-
return getDb().prepare(`SELECT * FROM scripts ${whereClause} ORDER BY scope ASC, scopeId ASC, name ASC`).all(...params).map(rowToScript);
|
|
169470
|
-
}
|
|
169471
|
-
function listScriptVersions(scriptId) {
|
|
169472
|
-
return getDb().prepare("SELECT * FROM script_versions WHERE scriptId = ? ORDER BY version DESC").all(scriptId).map(rowToScriptVersion);
|
|
169473
|
-
}
|
|
169474
|
-
function deleteScript(args) {
|
|
169475
|
-
const existing = getScript(args);
|
|
169476
|
-
if (!existing)
|
|
169477
|
-
return false;
|
|
169478
|
-
const result = getDb().run("DELETE FROM scripts WHERE id = ?", [existing.id]);
|
|
169479
|
-
return result.changes > 0;
|
|
169480
|
-
}
|
|
169481
|
-
|
|
169482
169627
|
// src/scripts-runtime/import-allowlist.ts
|
|
169483
169628
|
var import_typescript = __toESM(require_typescript(), 1);
|
|
169484
169629
|
var ALLOWED_BARE_IMPORTS = new Set(["swarm-sdk", "stdlib", "zod"]);
|
|
@@ -169544,4 +169689,4 @@ function validateScriptImports(source) {
|
|
|
169544
169689
|
return { ok: false, diagnostic: reason, imports: rejected };
|
|
169545
169690
|
}
|
|
169546
169691
|
|
|
169547
|
-
export { CREDENTIAL_BINDINGS_CONFIG_KEY, CredentialBindingSchema, placeholderForConfigKey, CredentialBroker, DEFAULT_CREDENTIAL_BINDINGS, SwarmConfigCredentialBindingStore, listRelationalCredentialBindings, upsertCredentialBinding, disableCredentialBinding, importLegacyCredentialBindings, listScriptConnections, upsertScriptConnection, setScriptConnectionEnabled, getScriptApiConnectionDescriptors, getScriptApiTypes, upsertScriptByName, getScript, getScriptById, getScriptVersion, listScripts, listScriptVersions, deleteScript, require_typescript, validateScriptImports };
|
|
169692
|
+
export { CREDENTIAL_BINDINGS_CONFIG_KEY, CredentialBindingSchema, placeholderForConfigKey, CredentialBroker, DEFAULT_CREDENTIAL_BINDINGS, SwarmConfigCredentialBindingStore, listRelationalCredentialBindings, upsertCredentialBinding, disableCredentialBinding, importLegacyCredentialBindings, listScriptConnections, upsertScriptConnection, setScriptConnectionEnabled, getScriptApiConnectionDescriptors, getScriptApiTypes, upsertScriptByName, getScript, getScriptById, getScriptVersion, listScripts, listScriptVersions, deleteScript, createScriptApi, listScriptApisForScript, getScriptApiById, getScriptApiSecret, updateScriptApi, rotateScriptApiSecret, deleteScriptApi, recordScriptApiUsage, require_typescript, validateScriptImports };
|