pi-subagents 0.80.0 → 0.82.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/CHANGELOG.md +66 -0
- package/bundle/agents.js +18 -0
- package/bundle/background-work.js +16 -0
- package/bundle/capability-ceiling.js +22 -0
- package/bundle/child-tool-plan.js +11 -0
- package/bundle/chunk-43SCHIMD.js +57 -0
- package/bundle/chunk-4QFZZV3O.js +57 -0
- package/bundle/chunk-4SDU2BZX.js +1190 -0
- package/bundle/chunk-52UBALJL.js +753 -0
- package/bundle/chunk-5LFLVSTM.js +260 -0
- package/bundle/chunk-5TYMSZX3.js +235 -0
- package/bundle/chunk-62OCY2S4.js +14 -0
- package/bundle/chunk-7F6RKT6W.js +132 -0
- package/bundle/chunk-7IVSUMQQ.js +1337 -0
- package/bundle/chunk-7J4ZXMY7.js +18 -0
- package/bundle/chunk-7PCKZHR5.js +1234 -0
- package/bundle/chunk-7YMXOYEU.js +1373 -0
- package/bundle/chunk-B5EKXDHE.js +16870 -0
- package/bundle/chunk-CIZQXJ5Q.js +8619 -0
- package/bundle/chunk-CTPAE36Y.js +94 -0
- package/bundle/chunk-D4EHT5SJ.js +14 -0
- package/bundle/chunk-GC4DSPMH.js +946 -0
- package/bundle/chunk-GJECHSAR.js +179 -0
- package/bundle/chunk-M2CTFYT3.js +4164 -0
- package/bundle/chunk-MHZ4G23A.js +1296 -0
- package/bundle/chunk-N2BN7BF5.js +159 -0
- package/bundle/chunk-NF7IEKBH.js +490 -0
- package/bundle/chunk-NGGAFDL6.js +742 -0
- package/bundle/chunk-NIXWDZZV.js +9 -0
- package/bundle/chunk-NRQ75MGH.js +8327 -0
- package/bundle/chunk-OYF6AFDY.js +458 -0
- package/bundle/chunk-PLCCBLPY.js +526 -0
- package/bundle/chunk-RMQFMMAT.js +416 -0
- package/bundle/chunk-SIJ4S3EN.js +276 -0
- package/bundle/chunk-UKG4V45O.js +228 -0
- package/bundle/chunk-VH5OAWVG.js +4096 -0
- package/bundle/chunk-W2SZ22EM.js +5462 -0
- package/bundle/chunk-WVD4UEL4.js +9367 -0
- package/bundle/chunk-XSWOTIA3.js +175 -0
- package/bundle/chunk-YFCK7H2S.js +129 -0
- package/bundle/chunk-YKEWIB4M.js +380 -0
- package/bundle/chunk-YYREO77V.js +137 -0
- package/bundle/chunk-Z7KVHQHL.js +173 -0
- package/bundle/chunk-ZLINIYTP.js +8613 -0
- package/bundle/chunk-ZQGSDHL6.js +128 -0
- package/bundle/control-channel.js +11 -0
- package/bundle/delegation.js +14 -0
- package/bundle/external-job-provider.js +20 -0
- package/bundle/external-runs.js +21 -0
- package/bundle/index.js +30 -0
- package/bundle/inspectors.js +8 -0
- package/bundle/intercom-bridge.js +11 -0
- package/bundle/preflight.js +425 -0
- package/bundle/project-panes.js +28 -0
- package/bundle/required-child-extensions.js +6 -0
- package/bundle/shared-types.js +8 -0
- package/bundle/workflow-resources.js +7 -0
- package/docs/agents.md +31 -0
- package/docs/configuration.md +9 -1
- package/docs/extension-api.md +27 -0
- package/docs/observability.md +6 -2
- package/docs/tool-reference.md +3 -1
- package/docs/workflows.md +16 -0
- package/package.json +19 -19
- package/skills/pi-subagents/references/execution-controls.md +5 -4
- package/src/agents/agent-management.js +3 -3
- package/src/agents/agent-memory.js +3 -1
- package/src/agents/agents.js +6 -6
- package/src/agents/frontmatter.d.ts +4 -0
- package/src/agents/frontmatter.js +24 -3
- package/src/agents/skills.js +2 -1
- package/src/api/delegation.d.ts +20 -0
- package/src/extension/config.js +3 -0
- package/src/extension/herdr-pi-bridge.js +17 -10
- package/src/extension/index.js +109 -9
- package/src/extension/schemas.js +3 -3
- package/src/intercom/native-supervisor-channel.js +20 -0
- package/src/missions/lifecycle.js +7 -1
- package/src/runs/background/active-async-capacity.d.ts +1 -0
- package/src/runs/background/active-async-capacity.js +9 -3
- package/src/runs/background/async-execution.js +20 -10
- package/src/runs/background/async-job-tracker.d.ts +6 -1
- package/src/runs/background/async-job-tracker.js +9 -4
- package/src/runs/background/async-status.d.ts +2 -0
- package/src/runs/background/async-status.js +21 -2
- package/src/runs/background/await-async-run.js +3 -7
- package/src/runs/background/boot-id.d.ts +12 -0
- package/src/runs/background/boot-id.js +47 -0
- package/src/runs/background/interrupted-elsewhere.d.ts +22 -0
- package/src/runs/background/interrupted-elsewhere.js +68 -0
- package/src/runs/background/notify.d.ts +2 -0
- package/src/runs/background/notify.js +13 -0
- package/src/runs/background/result-delivery-ownership.d.ts +6 -0
- package/src/runs/background/result-delivery-ownership.js +19 -1
- package/src/runs/background/result-watcher.d.ts +3 -1
- package/src/runs/background/result-watcher.js +24 -8
- package/src/runs/background/run-child-session.d.ts +1 -6
- package/src/runs/background/run-child-session.js +19 -1
- package/src/runs/background/run-status.js +2 -1
- package/src/runs/background/stale-run-reconciler.d.ts +25 -0
- package/src/runs/background/stale-run-reconciler.js +54 -13
- package/src/runs/background/subagent-runner-bootstrap.js +3 -0
- package/src/runs/background/subagent-runner.d.ts +4 -0
- package/src/runs/background/subagent-runner.js +13 -5
- package/src/runs/background/subagent-wait.d.ts +1 -1
- package/src/runs/background/subagent-wait.js +6 -1
- package/src/runs/background/terminal-run-index.d.ts +1 -0
- package/src/runs/background/terminal-run-index.js +4 -2
- package/src/runs/foreground/async-stop-action.js +3 -1
- package/src/runs/foreground/execution.js +45 -5
- package/src/runs/foreground/foreground-history.d.ts +16 -2
- package/src/runs/foreground/foreground-history.js +133 -31
- package/src/runs/foreground/subagent-executor.d.ts +11 -0
- package/src/runs/foreground/subagent-executor.js +277 -74
- package/src/runs/shared/child-launch.d.ts +2 -2
- package/src/runs/shared/child-session.d.ts +3 -2
- package/src/runs/shared/child-session.js +51 -8
- package/src/runs/shared/child-tool-plan.d.ts +7 -0
- package/src/runs/shared/child-tool-plan.js +21 -6
- package/src/runs/shared/herdr-connection.d.ts +17 -8
- package/src/runs/shared/herdr-connection.js +19 -7
- package/src/runs/shared/herdr-external-adapters.d.ts +3 -2
- package/src/runs/shared/herdr-external-adapters.js +1 -1
- package/src/runs/shared/herdr-machine.d.ts +12 -2
- package/src/runs/shared/herdr-machine.js +55 -9
- package/src/runs/shared/herdr-pane-host.d.ts +88 -0
- package/src/runs/shared/herdr-pane-host.js +155 -0
- package/src/runs/shared/herdr-placed-run.d.ts +27 -150
- package/src/runs/shared/herdr-placed-run.js +48 -395
- package/src/runs/shared/local-machine-access.d.ts +5 -0
- package/src/runs/shared/local-machine-access.js +28 -0
- package/src/runs/shared/orca-progress-tabs.d.ts +0 -1
- package/src/runs/shared/orca-progress-tabs.js +1 -24
- package/src/runs/shared/parallel-utils.d.ts +1 -1
- package/src/runs/shared/placed-run-owner.d.ts +49 -0
- package/src/runs/shared/placed-run-owner.js +93 -0
- package/src/runs/shared/placement-host.d.ts +99 -0
- package/src/runs/shared/placement-host.js +157 -0
- package/src/runs/shared/rex-machine.d.ts +25 -0
- package/src/runs/shared/rex-machine.js +83 -0
- package/src/runs/shared/rex-pane-host.d.ts +62 -0
- package/src/runs/shared/rex-pane-host.js +327 -0
- package/src/runs/shared/structured-output.d.ts +1 -0
- package/src/runs/shared/structured-output.js +1 -0
- package/src/shared/accessible-dir.js +4 -1
- package/src/shared/completion-owner.d.ts +5 -0
- package/src/shared/completion-owner.js +5 -0
- package/src/shared/provider-diagnostics.d.ts +9 -0
- package/src/shared/provider-diagnostics.js +75 -0
- package/src/shared/session-identity.d.ts +2 -0
- package/src/shared/session-identity.js +26 -0
- package/src/shared/types.d.ts +48 -6
- package/src/slash/delegation-adapters.d.ts +3 -1
- package/src/slash/delegation-adapters.js +7 -0
- package/src/slash/prompt-template-bridge.js +3 -1
- package/src/slash/subagents-admin.d.ts +1 -0
- package/src/slash/subagents-admin.js +1 -1
- package/src/tui/fleet-layout.d.ts +20 -0
- package/src/tui/fleet-layout.js +17 -0
- package/src/tui/fleet-viewport.d.ts +12 -0
- package/src/tui/fleet-viewport.js +35 -0
- package/src/tui/fleet.d.ts +6 -6
- package/src/tui/fleet.js +93 -66
- package/src/tui/render.d.ts +6 -0
- package/src/tui/render.js +3 -3
- package/src/tui/subagent-messages.js +1 -0
- package/src/workflows/scripted-workflow.d.ts +1 -1
- package/src/workflows/structured-workflow-scripts.d.ts +1 -0
- package/src/workflows/structured-workflow-scripts.js +5 -4
- package/src/workflows/workflow-auto-resume.d.ts +32 -0
- package/src/workflows/workflow-auto-resume.js +102 -0
- package/src/workflows/workflow-launch-record.d.ts +27 -0
- package/src/workflows/workflow-launch-record.js +48 -0
- package/src/workflows/workflow-resources.js +2 -2
- package/src/workflows/workflow-resume-claim.d.ts +82 -0
- package/src/workflows/workflow-resume-claim.js +210 -0
- package/src/workflows/workflow-resume.d.ts +56 -0
- package/src/workflows/workflow-resume.js +106 -0
- package/src/workflows/workflow-reuse.d.ts +15 -9
- package/src/workflows/workflow-reuse.js +77 -14
- package/src/workflows/workflow-revival.d.ts +2 -0
- package/src/workflows/workflow-revival.js +2 -1
- package/src/workflows/workflow-stop-cause.d.ts +6 -0
- package/src/workflows/workflow-stop-cause.js +8 -0
|
@@ -0,0 +1,380 @@
|
|
|
1
|
+
import {
|
|
2
|
+
BUILTIN_AGENT_NAMES,
|
|
3
|
+
CODE_OWNED_EXTERNAL_CLI_ADAPTER_LABEL,
|
|
4
|
+
applyRuntimeAgentSettings,
|
|
5
|
+
isCodeOwnedExternalCliAdapterId,
|
|
6
|
+
parseExternalCliCapabilityNarrowing,
|
|
7
|
+
validateAcceptanceInput,
|
|
8
|
+
validateCodeOwnedProfileRunner,
|
|
9
|
+
validatePermissionRules,
|
|
10
|
+
validateToolBudgetConfig
|
|
11
|
+
} from "./chunk-CIZQXJ5Q.js";
|
|
12
|
+
|
|
13
|
+
// src/agents/runtime-agent-registry.ts
|
|
14
|
+
var RUNTIME_AGENT_REGISTRY_KEY = "pi-subagents.runtime-agents.v1";
|
|
15
|
+
var MAX_RUNTIME_AGENTS_PER_PI = 200;
|
|
16
|
+
var MAX_AGENT_NAME_LENGTH = 128;
|
|
17
|
+
var MAX_DESCRIPTION_LENGTH = 4096;
|
|
18
|
+
var MAX_SYSTEM_PROMPT_LENGTH = 1024 * 1024;
|
|
19
|
+
var MAX_FIELD_STRING_LENGTH = 8192;
|
|
20
|
+
function defaultSystemPromptMode(name) {
|
|
21
|
+
return name === "delegate" ? "append" : "replace";
|
|
22
|
+
}
|
|
23
|
+
function defaultInheritProjectContext(name) {
|
|
24
|
+
return name === "delegate";
|
|
25
|
+
}
|
|
26
|
+
function defaultInheritSkills() {
|
|
27
|
+
return false;
|
|
28
|
+
}
|
|
29
|
+
function registry() {
|
|
30
|
+
const key = Symbol.for(RUNTIME_AGENT_REGISTRY_KEY);
|
|
31
|
+
const globalObject = globalThis;
|
|
32
|
+
const existing = globalObject[key];
|
|
33
|
+
if (existing === void 0) {
|
|
34
|
+
const created = { version: 1, byPi: /* @__PURE__ */ new WeakMap() };
|
|
35
|
+
globalObject[key] = created;
|
|
36
|
+
return created;
|
|
37
|
+
}
|
|
38
|
+
if (!existing || typeof existing !== "object" || Array.isArray(existing)) {
|
|
39
|
+
throw new Error(`Malformed runtime agent registry at Symbol.for("${RUNTIME_AGENT_REGISTRY_KEY}").`);
|
|
40
|
+
}
|
|
41
|
+
const candidate = existing;
|
|
42
|
+
if (candidate.version !== 1 || !(candidate.byPi instanceof WeakMap)) {
|
|
43
|
+
throw new Error(`Unsupported runtime agent registry at Symbol.for("${RUNTIME_AGENT_REGISTRY_KEY}").`);
|
|
44
|
+
}
|
|
45
|
+
return candidate;
|
|
46
|
+
}
|
|
47
|
+
function validatePi(value) {
|
|
48
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) throw new Error("Runtime agent pi must be an ExtensionAPI object.");
|
|
49
|
+
const pi = value;
|
|
50
|
+
if (typeof pi.on !== "function" || typeof pi.registerTool !== "function") throw new Error("Runtime agent pi must be an ExtensionAPI object.");
|
|
51
|
+
return value;
|
|
52
|
+
}
|
|
53
|
+
function validateString(value, field, maxLength) {
|
|
54
|
+
if (typeof value !== "string" || value.length === 0 || value.trim() !== value) {
|
|
55
|
+
throw new Error(`${field} must be a non-empty string without leading or trailing whitespace.`);
|
|
56
|
+
}
|
|
57
|
+
if (value.length > maxLength) throw new Error(`${field} must be at most ${maxLength} characters.`);
|
|
58
|
+
if (value.includes("\0")) throw new Error(`${field} must not contain NUL characters.`);
|
|
59
|
+
return value;
|
|
60
|
+
}
|
|
61
|
+
function validateOptionalString(value, field, maxLength = MAX_FIELD_STRING_LENGTH) {
|
|
62
|
+
if (value === void 0) return void 0;
|
|
63
|
+
return validateString(value, field, maxLength);
|
|
64
|
+
}
|
|
65
|
+
function validateStringList(value, field) {
|
|
66
|
+
if (value === void 0) return void 0;
|
|
67
|
+
if (!Array.isArray(value)) throw new Error(`${field} must be an array of strings when provided.`);
|
|
68
|
+
return [...new Set(value.map((entry, index) => validateString(entry, `${field}[${index}]`, MAX_FIELD_STRING_LENGTH)))];
|
|
69
|
+
}
|
|
70
|
+
function validatePositiveInteger(value, field) {
|
|
71
|
+
if (value === void 0) return void 0;
|
|
72
|
+
if (typeof value !== "number" || !Number.isInteger(value) || value <= 0) throw new Error(`${field} must be a positive integer when provided.`);
|
|
73
|
+
return value;
|
|
74
|
+
}
|
|
75
|
+
function validateBoolean(value, field) {
|
|
76
|
+
if (value === void 0) return void 0;
|
|
77
|
+
if (typeof value !== "boolean") throw new Error(`${field} must be a boolean when provided.`);
|
|
78
|
+
return value;
|
|
79
|
+
}
|
|
80
|
+
function isJsonSerializable(value) {
|
|
81
|
+
if (value === null || typeof value === "string" || typeof value === "boolean") return true;
|
|
82
|
+
if (typeof value === "number") return Number.isFinite(value);
|
|
83
|
+
if (Array.isArray(value)) return value.every(isJsonSerializable);
|
|
84
|
+
if (value && typeof value === "object") return Object.values(value).every(isJsonSerializable);
|
|
85
|
+
return false;
|
|
86
|
+
}
|
|
87
|
+
function validateRunner(value) {
|
|
88
|
+
if (value === void 0) return void 0;
|
|
89
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) throw new Error("Runtime agent definition runner must be an object when provided.");
|
|
90
|
+
const runner = value;
|
|
91
|
+
if (runner.type === "pi") {
|
|
92
|
+
if (Object.keys(runner).some((key) => key !== "type")) throw new Error("Runtime agent definition Pi runner supports only 'type'.");
|
|
93
|
+
return { type: "pi" };
|
|
94
|
+
}
|
|
95
|
+
if (runner.type === "external-job") {
|
|
96
|
+
if (typeof runner.provider !== "string" || !runner.provider.trim() || runner.provider.trim() !== runner.provider) throw new Error("Runtime agent definition external-job runner requires a non-empty trimmed provider string.");
|
|
97
|
+
if (runner.options !== void 0 && (!runner.options || typeof runner.options !== "object" || Array.isArray(runner.options) || !isJsonSerializable(runner.options))) throw new Error("Runtime agent definition external-job runner options must be a JSON-serializable object.");
|
|
98
|
+
const supported2 = /* @__PURE__ */ new Set(["type", "provider", "options"]);
|
|
99
|
+
const unknown2 = Object.keys(runner).filter((key) => !supported2.has(key));
|
|
100
|
+
if (unknown2.length > 0) throw new Error(`Runtime agent definition external-job runner has unsupported fields: ${unknown2.join(", ")}.`);
|
|
101
|
+
return { type: "external-job", provider: runner.provider, ...runner.options ? { options: runner.options } : {} };
|
|
102
|
+
}
|
|
103
|
+
if (runner.type !== "external-cli") throw new Error("Runtime agent definition runner.type must be 'pi', 'external-cli', or 'external-job'.");
|
|
104
|
+
if (typeof runner.command !== "string" || !runner.command.trim()) throw new Error("Runtime agent definition external-cli runner requires a non-empty command string.");
|
|
105
|
+
if (runner.args !== void 0 && (!Array.isArray(runner.args) || runner.args.some((arg) => typeof arg !== "string"))) throw new Error("Runtime agent definition external-cli runner args must be an array of strings.");
|
|
106
|
+
if (runner.adapter !== void 0 && !isCodeOwnedExternalCliAdapterId(runner.adapter)) throw new Error(`Runtime agent definition external-cli runner adapter must be ${CODE_OWNED_EXTERNAL_CLI_ADAPTER_LABEL}.`);
|
|
107
|
+
if (runner.adapter !== void 0 && Array.isArray(runner.args) && runner.args.length > 0) throw new Error(`Runtime agent definition ${runner.adapter} adapter owns its argv; runner args are not supported.`);
|
|
108
|
+
if (runner.promptDelivery !== void 0 && runner.promptDelivery !== "stdin") throw new Error("Runtime agent definition external-cli runner promptDelivery must be 'stdin'.");
|
|
109
|
+
const capabilities = parseExternalCliCapabilityNarrowing(runner.capabilities, "Runtime agent definition external-cli runner capabilities");
|
|
110
|
+
const supported = /* @__PURE__ */ new Set(["type", "adapter", "command", "args", "promptDelivery", "capabilities"]);
|
|
111
|
+
const unknown = Object.keys(runner).filter((key) => !supported.has(key));
|
|
112
|
+
if (unknown.length > 0) throw new Error(`Runtime agent definition external-cli runner has unsupported fields: ${unknown.join(", ")}.`);
|
|
113
|
+
const args = runner.args;
|
|
114
|
+
return { type: "external-cli", ...isCodeOwnedExternalCliAdapterId(runner.adapter) ? { adapter: runner.adapter } : {}, command: runner.command.trim(), ...args?.length ? { args } : {}, ...runner.promptDelivery ? { promptDelivery: "stdin" } : {}, ...capabilities ? { capabilities } : {} };
|
|
115
|
+
}
|
|
116
|
+
function validateAcceptance(value) {
|
|
117
|
+
const errors = validateAcceptanceInput(value, "Runtime agent definition defaultAcceptance");
|
|
118
|
+
if (errors.length > 0) throw new Error(errors.join(" "));
|
|
119
|
+
return value;
|
|
120
|
+
}
|
|
121
|
+
function validateToolBudget(value) {
|
|
122
|
+
const result = validateToolBudgetConfig(value, "Runtime agent definition toolBudget");
|
|
123
|
+
if (result.error) throw new Error(result.error);
|
|
124
|
+
return result.budget;
|
|
125
|
+
}
|
|
126
|
+
function validateDefinition(value) {
|
|
127
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) throw new Error("Runtime agent definition must be an object.");
|
|
128
|
+
const definition = value;
|
|
129
|
+
const supported = /* @__PURE__ */ new Set([
|
|
130
|
+
"description",
|
|
131
|
+
"systemPrompt",
|
|
132
|
+
"aliases",
|
|
133
|
+
"tools",
|
|
134
|
+
"excludeTools",
|
|
135
|
+
"allowNestedSubagents",
|
|
136
|
+
"mcpDirectTools",
|
|
137
|
+
"model",
|
|
138
|
+
"thinking",
|
|
139
|
+
"systemPromptMode",
|
|
140
|
+
"inheritProjectContext",
|
|
141
|
+
"inheritGlobalContext",
|
|
142
|
+
"inheritSkills",
|
|
143
|
+
"defaultContext",
|
|
144
|
+
"defaultAsync",
|
|
145
|
+
"defaultTimeoutMs",
|
|
146
|
+
"defaultToolTimeoutMs",
|
|
147
|
+
"defaultAcceptance",
|
|
148
|
+
"acceptanceRole",
|
|
149
|
+
"runner",
|
|
150
|
+
"machine",
|
|
151
|
+
"skills",
|
|
152
|
+
"skillPath",
|
|
153
|
+
"extensions",
|
|
154
|
+
"subagentOnlyExtensions",
|
|
155
|
+
"mutationTools",
|
|
156
|
+
"output",
|
|
157
|
+
"outputMode",
|
|
158
|
+
"defaultReads",
|
|
159
|
+
"defaultProgress",
|
|
160
|
+
"interactive",
|
|
161
|
+
"maxSubagentDepth",
|
|
162
|
+
"toolBudget",
|
|
163
|
+
"permissions"
|
|
164
|
+
]);
|
|
165
|
+
const unknown = Object.keys(definition).filter((key) => !supported.has(key));
|
|
166
|
+
if (unknown.length > 0) throw new Error(`Runtime agent definition has unknown fields: ${unknown.join(", ")}.`);
|
|
167
|
+
const systemPromptMode = definition.systemPromptMode;
|
|
168
|
+
if (systemPromptMode !== void 0 && systemPromptMode !== "append" && systemPromptMode !== "replace") throw new Error("Runtime agent definition systemPromptMode must be 'append' or 'replace'.");
|
|
169
|
+
const defaultContext = definition.defaultContext;
|
|
170
|
+
if (defaultContext !== void 0 && defaultContext !== "fresh" && defaultContext !== "fork") throw new Error("Runtime agent definition defaultContext must be 'fresh' or 'fork'.");
|
|
171
|
+
const thinking = definition.thinking;
|
|
172
|
+
if (thinking !== void 0 && thinking !== false && typeof thinking !== "string") throw new Error("Runtime agent definition thinking must be a string or false when provided.");
|
|
173
|
+
const acceptanceRole = definition.acceptanceRole;
|
|
174
|
+
if (acceptanceRole !== void 0 && acceptanceRole !== "read-only" && acceptanceRole !== "writer") throw new Error("Runtime agent definition acceptanceRole must be 'read-only' or 'writer'.");
|
|
175
|
+
const outputMode = definition.outputMode;
|
|
176
|
+
if (outputMode !== void 0 && outputMode !== "inline" && outputMode !== "file-only") throw new Error("Runtime agent definition outputMode must be 'inline' or 'file-only'.");
|
|
177
|
+
const aliases = validateStringList(definition.aliases, "Runtime agent definition aliases");
|
|
178
|
+
const tools = validateStringList(definition.tools, "Runtime agent definition tools");
|
|
179
|
+
const excludeTools = validateStringList(definition.excludeTools, "Runtime agent definition excludeTools");
|
|
180
|
+
const allowNestedSubagents = validateBoolean(definition.allowNestedSubagents, "Runtime agent definition allowNestedSubagents");
|
|
181
|
+
const mcpDirectTools = validateStringList(definition.mcpDirectTools, "Runtime agent definition mcpDirectTools");
|
|
182
|
+
const model = validateOptionalString(definition.model, "Runtime agent definition model");
|
|
183
|
+
if (definition.fallbackModels !== void 0) throw new Error("Runtime agent definition fallbackModels was removed; configure one model instead.");
|
|
184
|
+
const inheritProjectContext = validateBoolean(definition.inheritProjectContext, "Runtime agent definition inheritProjectContext");
|
|
185
|
+
const inheritGlobalContext = validateBoolean(definition.inheritGlobalContext, "Runtime agent definition inheritGlobalContext");
|
|
186
|
+
const inheritSkills = validateBoolean(definition.inheritSkills, "Runtime agent definition inheritSkills");
|
|
187
|
+
const defaultAsync = validateBoolean(definition.defaultAsync, "Runtime agent definition defaultAsync");
|
|
188
|
+
const defaultTimeoutMs = validatePositiveInteger(definition.defaultTimeoutMs, "Runtime agent definition defaultTimeoutMs");
|
|
189
|
+
const defaultToolTimeoutMs = validatePositiveInteger(definition.defaultToolTimeoutMs, "Runtime agent definition defaultToolTimeoutMs");
|
|
190
|
+
const defaultAcceptance = validateAcceptance(definition.defaultAcceptance);
|
|
191
|
+
const runner = validateRunner(definition.runner);
|
|
192
|
+
const skills = validateStringList(definition.skills, "Runtime agent definition skills");
|
|
193
|
+
const skillPath = validateStringList(definition.skillPath, "Runtime agent definition skillPath");
|
|
194
|
+
const extensions = validateStringList(definition.extensions, "Runtime agent definition extensions");
|
|
195
|
+
const subagentOnlyExtensions = validateStringList(definition.subagentOnlyExtensions, "Runtime agent definition subagentOnlyExtensions");
|
|
196
|
+
const mutationTools = validateStringList(definition.mutationTools, "Runtime agent definition mutationTools");
|
|
197
|
+
const machine = validateOptionalString(definition.machine, "Runtime agent definition machine");
|
|
198
|
+
const output = validateOptionalString(definition.output, "Runtime agent definition output");
|
|
199
|
+
const defaultReads = validateStringList(definition.defaultReads, "Runtime agent definition defaultReads");
|
|
200
|
+
const defaultProgress = validateBoolean(definition.defaultProgress, "Runtime agent definition defaultProgress");
|
|
201
|
+
const interactive = validateBoolean(definition.interactive, "Runtime agent definition interactive");
|
|
202
|
+
const maxSubagentDepth = validatePositiveInteger(definition.maxSubagentDepth, "Runtime agent definition maxSubagentDepth");
|
|
203
|
+
const toolBudget = validateToolBudget(definition.toolBudget);
|
|
204
|
+
const permissions = validatePermissionRules(definition.permissions, "Runtime agent definition permissions");
|
|
205
|
+
return {
|
|
206
|
+
description: validateString(definition.description, "Runtime agent definition description", MAX_DESCRIPTION_LENGTH),
|
|
207
|
+
systemPrompt: validateString(definition.systemPrompt, "Runtime agent definition systemPrompt", MAX_SYSTEM_PROMPT_LENGTH),
|
|
208
|
+
...aliases ? { aliases } : {},
|
|
209
|
+
...tools ? { tools } : {},
|
|
210
|
+
...excludeTools ? { excludeTools } : {},
|
|
211
|
+
...allowNestedSubagents !== void 0 ? { allowNestedSubagents } : {},
|
|
212
|
+
...mcpDirectTools ? { mcpDirectTools } : {},
|
|
213
|
+
...model ? { model } : {},
|
|
214
|
+
...thinking !== void 0 ? { thinking } : {},
|
|
215
|
+
...systemPromptMode !== void 0 ? { systemPromptMode } : {},
|
|
216
|
+
...inheritProjectContext !== void 0 ? { inheritProjectContext } : {},
|
|
217
|
+
...inheritGlobalContext !== void 0 ? { inheritGlobalContext } : {},
|
|
218
|
+
...inheritSkills !== void 0 ? { inheritSkills } : {},
|
|
219
|
+
...defaultContext !== void 0 ? { defaultContext } : {},
|
|
220
|
+
...defaultAsync !== void 0 ? { defaultAsync } : {},
|
|
221
|
+
...defaultTimeoutMs !== void 0 ? { defaultTimeoutMs } : {},
|
|
222
|
+
...defaultToolTimeoutMs !== void 0 ? { defaultToolTimeoutMs } : {},
|
|
223
|
+
...defaultAcceptance !== void 0 ? { defaultAcceptance } : {},
|
|
224
|
+
...acceptanceRole !== void 0 ? { acceptanceRole } : {},
|
|
225
|
+
...runner !== void 0 ? { runner } : {},
|
|
226
|
+
...skills ? { skills } : {},
|
|
227
|
+
...skillPath ? { skillPath } : {},
|
|
228
|
+
...extensions ? { extensions } : {},
|
|
229
|
+
...subagentOnlyExtensions ? { subagentOnlyExtensions } : {},
|
|
230
|
+
...mutationTools ? { mutationTools } : {},
|
|
231
|
+
...machine ? { machine } : {},
|
|
232
|
+
...output ? { output } : {},
|
|
233
|
+
...outputMode !== void 0 ? { outputMode } : {},
|
|
234
|
+
...defaultReads ? { defaultReads } : {},
|
|
235
|
+
...defaultProgress !== void 0 ? { defaultProgress } : {},
|
|
236
|
+
...interactive !== void 0 ? { interactive } : {},
|
|
237
|
+
...maxSubagentDepth !== void 0 ? { maxSubagentDepth } : {},
|
|
238
|
+
...toolBudget !== void 0 ? { toolBudget } : {},
|
|
239
|
+
...permissions !== void 0 ? { permissions } : {}
|
|
240
|
+
};
|
|
241
|
+
}
|
|
242
|
+
function normalizeAliases(rawAliases, agentName) {
|
|
243
|
+
const aliases = [...new Set((rawAliases ?? []).map((alias) => alias.trim()).filter(Boolean))].filter((alias) => alias !== agentName);
|
|
244
|
+
return aliases.length > 0 ? aliases : void 0;
|
|
245
|
+
}
|
|
246
|
+
function identityKeys(agent) {
|
|
247
|
+
return [agent.name, ...agent.localName ? [agent.localName] : [], ...agent.aliases ?? []];
|
|
248
|
+
}
|
|
249
|
+
function assertNoIdentityCollisions(agents, context) {
|
|
250
|
+
const seen = /* @__PURE__ */ new Map();
|
|
251
|
+
for (const agent of agents) {
|
|
252
|
+
for (const key of identityKeys(agent)) {
|
|
253
|
+
const previous = seen.get(key);
|
|
254
|
+
if (previous !== void 0) throw new Error(`${context} collision for '${key}' between '${previous}' and '${agent.name}'.`);
|
|
255
|
+
seen.set(key, agent.name);
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
function assertNoRuntimeCollision(agent, existing) {
|
|
260
|
+
const existingKeys = /* @__PURE__ */ new Map();
|
|
261
|
+
for (const registered of existing) {
|
|
262
|
+
for (const key of identityKeys(registered)) existingKeys.set(key, registered.name);
|
|
263
|
+
}
|
|
264
|
+
for (const key of identityKeys(agent)) {
|
|
265
|
+
const previous = existingKeys.get(key);
|
|
266
|
+
if (previous !== void 0) throw new Error(`Runtime agent '${agent.name}' collides with runtime agent '${previous}' on name or alias '${key}'.`);
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
function assertNoBuiltinCollision(agent) {
|
|
270
|
+
for (const key of identityKeys(agent)) {
|
|
271
|
+
if (BUILTIN_AGENT_NAMES.includes(key)) throw new Error(`Runtime agent '${agent.name}' collides with builtin agent '${key}'.`);
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
function toAgentConfig(name, definition) {
|
|
275
|
+
const aliases = normalizeAliases(definition.aliases, name);
|
|
276
|
+
const agent = {
|
|
277
|
+
name,
|
|
278
|
+
description: definition.description,
|
|
279
|
+
...aliases ? { aliases } : {},
|
|
280
|
+
...definition.runner !== void 0 ? { runner: definition.runner } : {},
|
|
281
|
+
...definition.tools !== void 0 ? { tools: [...definition.tools] } : {},
|
|
282
|
+
...definition.excludeTools !== void 0 ? { excludeTools: [...definition.excludeTools] } : {},
|
|
283
|
+
...definition.allowNestedSubagents !== void 0 ? { allowNestedSubagents: definition.allowNestedSubagents } : {},
|
|
284
|
+
...definition.mcpDirectTools !== void 0 ? { mcpDirectTools: [...definition.mcpDirectTools] } : {},
|
|
285
|
+
...definition.model !== void 0 ? { model: definition.model } : {},
|
|
286
|
+
...definition.thinking !== void 0 ? { thinking: definition.thinking } : {},
|
|
287
|
+
systemPromptMode: definition.systemPromptMode ?? defaultSystemPromptMode(name),
|
|
288
|
+
inheritProjectContext: definition.inheritProjectContext ?? defaultInheritProjectContext(name),
|
|
289
|
+
inheritGlobalContext: definition.inheritGlobalContext ?? false,
|
|
290
|
+
inheritSkills: definition.inheritSkills ?? defaultInheritSkills(),
|
|
291
|
+
...definition.defaultContext !== void 0 ? { defaultContext: definition.defaultContext } : {},
|
|
292
|
+
...definition.defaultAsync !== void 0 ? { defaultAsync: definition.defaultAsync } : {},
|
|
293
|
+
...definition.defaultTimeoutMs !== void 0 ? { defaultTimeoutMs: definition.defaultTimeoutMs } : {},
|
|
294
|
+
...definition.defaultToolTimeoutMs !== void 0 ? { defaultToolTimeoutMs: definition.defaultToolTimeoutMs } : {},
|
|
295
|
+
...definition.defaultAcceptance !== void 0 ? { defaultAcceptance: definition.defaultAcceptance } : {},
|
|
296
|
+
...definition.acceptanceRole !== void 0 ? { acceptanceRole: definition.acceptanceRole } : {},
|
|
297
|
+
systemPrompt: definition.systemPrompt,
|
|
298
|
+
source: "runtime",
|
|
299
|
+
filePath: `runtime:${name}`,
|
|
300
|
+
...definition.skills !== void 0 ? { skills: [...definition.skills] } : {},
|
|
301
|
+
...definition.skillPath !== void 0 ? { skillPath: [...definition.skillPath] } : {},
|
|
302
|
+
...definition.extensions !== void 0 ? { extensions: [...definition.extensions] } : {},
|
|
303
|
+
...definition.subagentOnlyExtensions !== void 0 ? { subagentOnlyExtensions: [...definition.subagentOnlyExtensions] } : {},
|
|
304
|
+
...definition.mutationTools !== void 0 ? { mutationTools: [...definition.mutationTools] } : {},
|
|
305
|
+
...definition.machine !== void 0 ? { machine: definition.machine } : {},
|
|
306
|
+
...definition.output !== void 0 ? { output: definition.output } : {},
|
|
307
|
+
...definition.outputMode !== void 0 ? { outputMode: definition.outputMode } : {},
|
|
308
|
+
...definition.defaultReads !== void 0 ? { defaultReads: [...definition.defaultReads] } : {},
|
|
309
|
+
...definition.defaultProgress !== void 0 ? { defaultProgress: definition.defaultProgress } : {},
|
|
310
|
+
...definition.interactive !== void 0 ? { interactive: definition.interactive } : {},
|
|
311
|
+
...definition.maxSubagentDepth !== void 0 ? { maxSubagentDepth: definition.maxSubagentDepth } : {},
|
|
312
|
+
...definition.toolBudget !== void 0 ? { toolBudget: definition.toolBudget } : {},
|
|
313
|
+
...definition.permissions !== void 0 ? { permissions: definition.permissions } : {}
|
|
314
|
+
};
|
|
315
|
+
assertNoIdentityCollisions([agent], `Runtime agent '${name}'`);
|
|
316
|
+
return agent;
|
|
317
|
+
}
|
|
318
|
+
function registerRuntimeAgent(input) {
|
|
319
|
+
const pi = validatePi(input.pi);
|
|
320
|
+
const name = validateString(input.name, "Runtime agent name", MAX_AGENT_NAME_LENGTH);
|
|
321
|
+
const definition = validateDefinition(input.definition);
|
|
322
|
+
const agent = toAgentConfig(name, definition);
|
|
323
|
+
const profileError = validateCodeOwnedProfileRunner(agent);
|
|
324
|
+
if (profileError) throw new Error(profileError);
|
|
325
|
+
assertNoBuiltinCollision(agent);
|
|
326
|
+
const current = registry();
|
|
327
|
+
const records = current.byPi.get(pi) ?? [];
|
|
328
|
+
if (records.length >= MAX_RUNTIME_AGENTS_PER_PI) throw new Error(`Runtime agent registry supports at most ${MAX_RUNTIME_AGENTS_PER_PI} agents per Pi runtime.`);
|
|
329
|
+
assertNoRuntimeCollision(agent, records.map((record2) => record2.agent));
|
|
330
|
+
const record = { pi, agent };
|
|
331
|
+
records.push(record);
|
|
332
|
+
current.byPi.set(pi, records);
|
|
333
|
+
let disposed = false;
|
|
334
|
+
return {
|
|
335
|
+
dispose() {
|
|
336
|
+
if (disposed) return;
|
|
337
|
+
disposed = true;
|
|
338
|
+
const latest = current.byPi.get(pi);
|
|
339
|
+
if (!latest) return;
|
|
340
|
+
const next = latest.filter((entry) => entry !== record);
|
|
341
|
+
if (next.length > 0) current.byPi.set(pi, next);
|
|
342
|
+
else current.byPi.delete(pi);
|
|
343
|
+
}
|
|
344
|
+
};
|
|
345
|
+
}
|
|
346
|
+
function clearRuntimeAgentsForPi(pi) {
|
|
347
|
+
registry().byPi.delete(pi);
|
|
348
|
+
}
|
|
349
|
+
function listRuntimeAgentConfigs(pi) {
|
|
350
|
+
return (registry().byPi.get(pi) ?? []).map((record) => ({ ...record.agent, aliases: record.agent.aliases ? [...record.agent.aliases] : void 0 }));
|
|
351
|
+
}
|
|
352
|
+
function assertNoConfiguredCollision(configuredAgents, runtimeAgents) {
|
|
353
|
+
const configured = /* @__PURE__ */ new Map();
|
|
354
|
+
for (const agent of configuredAgents) {
|
|
355
|
+
for (const key of identityKeys(agent)) configured.set(key, agent.name);
|
|
356
|
+
}
|
|
357
|
+
for (const agent of runtimeAgents) {
|
|
358
|
+
for (const key of identityKeys(agent)) {
|
|
359
|
+
const previous = configured.get(key);
|
|
360
|
+
if (previous !== void 0) {
|
|
361
|
+
throw new Error(`Runtime agent '${agent.name}' collides with configured agent '${previous}' on name or alias '${key}'.`);
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
function mergeRuntimeAgents(pi, discovered, configuredAgents = discovered.agents, settings) {
|
|
367
|
+
const registered = listRuntimeAgentConfigs(pi).filter((agent) => agent.disabled !== true);
|
|
368
|
+
if (registered.length === 0) return discovered;
|
|
369
|
+
assertNoIdentityCollisions(registered, "Runtime agent registration");
|
|
370
|
+
assertNoConfiguredCollision(configuredAgents, registered);
|
|
371
|
+
const runtimeAgents = settings ? applyRuntimeAgentSettings(registered, settings) : registered;
|
|
372
|
+
return { ...discovered, agents: [...discovered.agents, ...runtimeAgents] };
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
export {
|
|
376
|
+
registerRuntimeAgent,
|
|
377
|
+
clearRuntimeAgentsForPi,
|
|
378
|
+
listRuntimeAgentConfigs,
|
|
379
|
+
mergeRuntimeAgents
|
|
380
|
+
};
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
// src/api/external-job-provider.ts
|
|
2
|
+
var EXTERNAL_JOB_PROVIDER_PROTOCOL_VERSION = 1;
|
|
3
|
+
var EXTERNAL_JOB_PROVIDER_REGISTRY_KEY = "pi-subagents.external-job-providers.v1";
|
|
4
|
+
var MAX_PROVIDER_NAME_LENGTH = 128;
|
|
5
|
+
var MAX_PROVIDERS = 100;
|
|
6
|
+
var MAX_JOB_ID_LENGTH = 256;
|
|
7
|
+
var MAX_FAILURE_CODE_LENGTH = 128;
|
|
8
|
+
var MAX_FAILURE_MESSAGE_LENGTH = 4096;
|
|
9
|
+
var MAX_URL_LENGTH = 4096;
|
|
10
|
+
var ExternalJobProviderError = class extends Error {
|
|
11
|
+
code;
|
|
12
|
+
blockingJobId;
|
|
13
|
+
constructor(message, options) {
|
|
14
|
+
super(message, options.cause === void 0 ? void 0 : { cause: options.cause });
|
|
15
|
+
this.name = "ExternalJobProviderError";
|
|
16
|
+
this.code = options.code;
|
|
17
|
+
this.blockingJobId = options.blockingJobId;
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
function registry() {
|
|
21
|
+
const key = Symbol.for(EXTERNAL_JOB_PROVIDER_REGISTRY_KEY);
|
|
22
|
+
const globalObject = globalThis;
|
|
23
|
+
const existing = globalObject[key];
|
|
24
|
+
if (existing === void 0) {
|
|
25
|
+
const created = {
|
|
26
|
+
version: EXTERNAL_JOB_PROVIDER_PROTOCOL_VERSION,
|
|
27
|
+
providers: /* @__PURE__ */ new Map()
|
|
28
|
+
};
|
|
29
|
+
globalObject[key] = created;
|
|
30
|
+
return created;
|
|
31
|
+
}
|
|
32
|
+
if (!existing || typeof existing !== "object" || Array.isArray(existing)) {
|
|
33
|
+
throw new Error(`Malformed external-job provider registry at Symbol.for("${EXTERNAL_JOB_PROVIDER_REGISTRY_KEY}").`);
|
|
34
|
+
}
|
|
35
|
+
const candidate = existing;
|
|
36
|
+
if (candidate.version !== EXTERNAL_JOB_PROVIDER_PROTOCOL_VERSION || !(candidate.providers instanceof Map)) {
|
|
37
|
+
throw new Error(`Unsupported external-job provider registry at Symbol.for("${EXTERNAL_JOB_PROVIDER_REGISTRY_KEY}").`);
|
|
38
|
+
}
|
|
39
|
+
return candidate;
|
|
40
|
+
}
|
|
41
|
+
function validateString(value, field, maxLength) {
|
|
42
|
+
if (typeof value !== "string" || value.length === 0 || value.trim() !== value) {
|
|
43
|
+
throw new Error(`${field} must be a non-empty string without leading or trailing whitespace.`);
|
|
44
|
+
}
|
|
45
|
+
if (value.length > maxLength) throw new Error(`${field} must be at most ${maxLength} characters.`);
|
|
46
|
+
if (value.includes("\0")) throw new Error(`${field} must not contain NUL characters.`);
|
|
47
|
+
return value;
|
|
48
|
+
}
|
|
49
|
+
function validateOptionalString(value, field, maxLength) {
|
|
50
|
+
if (value === void 0) return void 0;
|
|
51
|
+
return validateString(value, field, maxLength);
|
|
52
|
+
}
|
|
53
|
+
function validateState(value, field) {
|
|
54
|
+
if (value === "queued" || value === "running" || value === "completed" || value === "failed" || value === "stopped" || value === "blocked") return value;
|
|
55
|
+
throw new Error(`${field} must be queued, running, completed, failed, stopped, or blocked.`);
|
|
56
|
+
}
|
|
57
|
+
function validateHandle(provider, value, field, extraFields = []) {
|
|
58
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) throw new Error(`${field} from external-job provider '${provider}' must be an object.`);
|
|
59
|
+
const handle = value;
|
|
60
|
+
const supported = /* @__PURE__ */ new Set(["providerJobId", "state", "handleUrl", "conversationUrl", "failureCode", "failureMessage", "blockingJobId", ...extraFields]);
|
|
61
|
+
const unknown = Object.keys(handle).filter((key) => !supported.has(key));
|
|
62
|
+
if (unknown.length > 0) throw new Error(`${field} from external-job provider '${provider}' has unknown fields: ${unknown.join(", ")}.`);
|
|
63
|
+
const handleUrl = validateOptionalString(handle.handleUrl, `${field}.handleUrl`, MAX_URL_LENGTH);
|
|
64
|
+
const conversationUrl = validateOptionalString(handle.conversationUrl, `${field}.conversationUrl`, MAX_URL_LENGTH);
|
|
65
|
+
const failureCode = validateOptionalString(handle.failureCode, `${field}.failureCode`, MAX_FAILURE_CODE_LENGTH);
|
|
66
|
+
const failureMessage = validateOptionalString(handle.failureMessage, `${field}.failureMessage`, MAX_FAILURE_MESSAGE_LENGTH);
|
|
67
|
+
const blockingJobId = validateOptionalString(handle.blockingJobId, `${field}.blockingJobId`, MAX_JOB_ID_LENGTH);
|
|
68
|
+
return {
|
|
69
|
+
providerJobId: validateString(handle.providerJobId, `${field}.providerJobId`, MAX_JOB_ID_LENGTH),
|
|
70
|
+
state: validateState(handle.state, `${field}.state`),
|
|
71
|
+
...handleUrl ? { handleUrl } : {},
|
|
72
|
+
...conversationUrl ? { conversationUrl } : {},
|
|
73
|
+
...failureCode ? { failureCode } : {},
|
|
74
|
+
...failureMessage ? { failureMessage } : {},
|
|
75
|
+
...blockingJobId ? { blockingJobId } : {}
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
function validateExternalJobHandle(provider, value, field = "External-job handle") {
|
|
79
|
+
return validateHandle(provider, value, field);
|
|
80
|
+
}
|
|
81
|
+
function validateExternalJobResult(provider, value, field = "External-job result") {
|
|
82
|
+
const result = validateHandle(provider, value, field, ["output", "artifactPath"]);
|
|
83
|
+
const record = value;
|
|
84
|
+
const output = validateOptionalString(record.output, `${field}.output`, 1024 * 1024);
|
|
85
|
+
const artifactPath = validateOptionalString(record.artifactPath, `${field}.artifactPath`, MAX_URL_LENGTH);
|
|
86
|
+
return {
|
|
87
|
+
...result,
|
|
88
|
+
...output !== void 0 ? { output } : {},
|
|
89
|
+
...artifactPath !== void 0 ? { artifactPath } : {}
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
function validateProvider(value) {
|
|
93
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) throw new Error("External-job provider must be an object.");
|
|
94
|
+
const provider = value;
|
|
95
|
+
const name = validateString(provider.name, "External-job provider name", MAX_PROVIDER_NAME_LENGTH);
|
|
96
|
+
for (const op of ["start", "status", "result", "reattach"]) {
|
|
97
|
+
if (typeof provider[op] !== "function") throw new Error(`External-job provider '${name}' must expose ${op}().`);
|
|
98
|
+
}
|
|
99
|
+
return value;
|
|
100
|
+
}
|
|
101
|
+
function registerExternalJobProvider(provider) {
|
|
102
|
+
const validated = validateProvider(provider);
|
|
103
|
+
const current = registry();
|
|
104
|
+
if (!current.providers.has(validated.name) && current.providers.size >= MAX_PROVIDERS) {
|
|
105
|
+
throw new Error(`External-job provider registry supports at most ${MAX_PROVIDERS} providers.`);
|
|
106
|
+
}
|
|
107
|
+
current.providers.set(validated.name, validated);
|
|
108
|
+
return () => {
|
|
109
|
+
if (current.providers.get(validated.name) === validated) current.providers.delete(validated.name);
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
function listExternalJobProviders() {
|
|
113
|
+
const current = registry();
|
|
114
|
+
if (current.providers.size > MAX_PROVIDERS) throw new Error(`External-job provider registry contains more than ${MAX_PROVIDERS} providers.`);
|
|
115
|
+
const providers = [];
|
|
116
|
+
for (const [key, value] of current.providers) {
|
|
117
|
+
const provider = validateProvider(value);
|
|
118
|
+
if (key !== provider.name) throw new Error(`External-job provider registry key '${key}' does not match provider name '${provider.name}'.`);
|
|
119
|
+
providers.push(provider);
|
|
120
|
+
}
|
|
121
|
+
return providers;
|
|
122
|
+
}
|
|
123
|
+
function getExternalJobProvider(name) {
|
|
124
|
+
const safeName = validateString(name, "External-job provider name", MAX_PROVIDER_NAME_LENGTH);
|
|
125
|
+
return listExternalJobProviders().find((provider) => provider.name === safeName);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
export {
|
|
129
|
+
EXTERNAL_JOB_PROVIDER_PROTOCOL_VERSION,
|
|
130
|
+
EXTERNAL_JOB_PROVIDER_REGISTRY_KEY,
|
|
131
|
+
ExternalJobProviderError,
|
|
132
|
+
validateExternalJobHandle,
|
|
133
|
+
validateExternalJobResult,
|
|
134
|
+
registerExternalJobProvider,
|
|
135
|
+
listExternalJobProviders,
|
|
136
|
+
getExternalJobProvider
|
|
137
|
+
};
|