@caupulican/pi-adaptative 0.90.2 → 0.90.5
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 +41 -0
- package/dist/core/agent-session-contracts.d.ts +2 -0
- package/dist/core/agent-session-contracts.d.ts.map +1 -1
- package/dist/core/agent-session-contracts.js.map +1 -1
- package/dist/core/autonomy/bounded-completion.d.ts +10 -1
- package/dist/core/autonomy/bounded-completion.d.ts.map +1 -1
- package/dist/core/autonomy/bounded-completion.js +24 -2
- package/dist/core/autonomy/bounded-completion.js.map +1 -1
- package/dist/core/autonomy/lane-tracker.d.ts +6 -1
- package/dist/core/autonomy/lane-tracker.d.ts.map +1 -1
- package/dist/core/autonomy/lane-tracker.js +17 -1
- package/dist/core/autonomy/lane-tracker.js.map +1 -1
- package/dist/core/background-lane-controller.d.ts +1 -3
- package/dist/core/background-lane-controller.d.ts.map +1 -1
- package/dist/core/background-lane-controller.js.map +1 -1
- package/dist/core/compaction-controller.d.ts.map +1 -1
- package/dist/core/compaction-controller.js +0 -1
- package/dist/core/compaction-controller.js.map +1 -1
- package/dist/core/delegation/managed-lane-controller.d.ts.map +1 -1
- package/dist/core/delegation/managed-lane-controller.js +5 -1
- package/dist/core/delegation/managed-lane-controller.js.map +1 -1
- package/dist/core/delegation/worker-agent-control-coordinator.d.ts +8 -1
- package/dist/core/delegation/worker-agent-control-coordinator.d.ts.map +1 -1
- package/dist/core/delegation/worker-agent-control-coordinator.js +94 -36
- package/dist/core/delegation/worker-agent-control-coordinator.js.map +1 -1
- package/dist/core/delegation/worker-agent-control.d.ts +1 -0
- package/dist/core/delegation/worker-agent-control.d.ts.map +1 -1
- package/dist/core/delegation/worker-agent-control.js.map +1 -1
- package/dist/core/delegation/worker-attempt-executor.d.ts.map +1 -1
- package/dist/core/delegation/worker-attempt-executor.js +7 -2
- package/dist/core/delegation/worker-attempt-executor.js.map +1 -1
- package/dist/core/delegation/worker-authority-resolver.d.ts +2 -0
- package/dist/core/delegation/worker-authority-resolver.d.ts.map +1 -1
- package/dist/core/delegation/worker-authority-resolver.js +49 -6
- package/dist/core/delegation/worker-authority-resolver.js.map +1 -1
- package/dist/core/delegation/worker-delegation-controller.d.ts +8 -5
- package/dist/core/delegation/worker-delegation-controller.d.ts.map +1 -1
- package/dist/core/delegation/worker-delegation-controller.js +158 -40
- package/dist/core/delegation/worker-delegation-controller.js.map +1 -1
- package/dist/core/delegation/worker-fleet-limits.d.ts +9 -2
- package/dist/core/delegation/worker-fleet-limits.d.ts.map +1 -1
- package/dist/core/delegation/worker-fleet-limits.js +39 -3
- package/dist/core/delegation/worker-fleet-limits.js.map +1 -1
- package/dist/core/delegation/worker-lane-projection.d.ts.map +1 -1
- package/dist/core/delegation/worker-lane-projection.js +10 -0
- package/dist/core/delegation/worker-lane-projection.js.map +1 -1
- package/dist/core/delegation/worker-lease-heartbeat.d.ts +16 -0
- package/dist/core/delegation/worker-lease-heartbeat.d.ts.map +1 -0
- package/dist/core/delegation/worker-lease-heartbeat.js +37 -0
- package/dist/core/delegation/worker-lease-heartbeat.js.map +1 -0
- package/dist/core/delegation/worker-lifecycle.d.ts +1 -0
- package/dist/core/delegation/worker-lifecycle.d.ts.map +1 -1
- package/dist/core/delegation/worker-lifecycle.js +6 -0
- package/dist/core/delegation/worker-lifecycle.js.map +1 -1
- package/dist/core/delegation/worker-notification-coordinator.d.ts.map +1 -1
- package/dist/core/delegation/worker-notification-coordinator.js +2 -1
- package/dist/core/delegation/worker-notification-coordinator.js.map +1 -1
- package/dist/core/delegation/worker-profile-resolver.d.ts +28 -1
- package/dist/core/delegation/worker-profile-resolver.d.ts.map +1 -1
- package/dist/core/delegation/worker-profile-resolver.js +38 -9
- package/dist/core/delegation/worker-profile-resolver.js.map +1 -1
- package/dist/core/delegation/worker-runner.js +2 -2
- package/dist/core/delegation/worker-runner.js.map +1 -1
- package/dist/core/delegation/worker-terminal-handoff-coordinator.d.ts +1 -0
- package/dist/core/delegation/worker-terminal-handoff-coordinator.d.ts.map +1 -1
- package/dist/core/delegation/worker-terminal-handoff-coordinator.js +1 -0
- package/dist/core/delegation/worker-terminal-handoff-coordinator.js.map +1 -1
- package/dist/core/delegation/worker-tree-budget-coordinator.d.ts +4 -2
- package/dist/core/delegation/worker-tree-budget-coordinator.d.ts.map +1 -1
- package/dist/core/delegation/worker-tree-budget-coordinator.js +10 -2
- package/dist/core/delegation/worker-tree-budget-coordinator.js.map +1 -1
- package/dist/core/delegation/worker-write-reservation-coordinator.d.ts +14 -0
- package/dist/core/delegation/worker-write-reservation-coordinator.d.ts.map +1 -1
- package/dist/core/delegation/worker-write-reservation-coordinator.js +121 -33
- package/dist/core/delegation/worker-write-reservation-coordinator.js.map +1 -1
- package/dist/core/foreground-terminal-handoff-controller.d.ts +5 -0
- package/dist/core/foreground-terminal-handoff-controller.d.ts.map +1 -1
- package/dist/core/foreground-terminal-handoff-controller.js +28 -12
- package/dist/core/foreground-terminal-handoff-controller.js.map +1 -1
- package/dist/core/orchestration/capability-gateway.d.ts +2 -1
- package/dist/core/orchestration/capability-gateway.d.ts.map +1 -1
- package/dist/core/orchestration/capability-gateway.js +9 -2
- package/dist/core/orchestration/capability-gateway.js.map +1 -1
- package/dist/core/orchestration/contracts.d.ts +16 -1
- package/dist/core/orchestration/contracts.d.ts.map +1 -1
- package/dist/core/orchestration/contracts.js +5 -0
- package/dist/core/orchestration/contracts.js.map +1 -1
- package/dist/core/orchestration/profile-registry.d.ts.map +1 -1
- package/dist/core/orchestration/profile-registry.js +38 -1
- package/dist/core/orchestration/profile-registry.js.map +1 -1
- package/dist/core/orchestration/risk-budget.d.ts +10 -0
- package/dist/core/orchestration/risk-budget.d.ts.map +1 -1
- package/dist/core/orchestration/risk-budget.js +14 -0
- package/dist/core/orchestration/risk-budget.js.map +1 -1
- package/dist/core/orchestration/task-runtime-reducer.d.ts +1 -0
- package/dist/core/orchestration/task-runtime-reducer.d.ts.map +1 -1
- package/dist/core/orchestration/task-runtime-reducer.js +34 -0
- package/dist/core/orchestration/task-runtime-reducer.js.map +1 -1
- package/dist/core/orchestration/task-runtime.d.ts +1 -0
- package/dist/core/orchestration/task-runtime.d.ts.map +1 -1
- package/dist/core/orchestration/task-runtime.js +24 -1
- package/dist/core/orchestration/task-runtime.js.map +1 -1
- package/dist/core/orchestration/worker-model-pins.d.ts +28 -0
- package/dist/core/orchestration/worker-model-pins.d.ts.map +1 -0
- package/dist/core/orchestration/worker-model-pins.js +141 -0
- package/dist/core/orchestration/worker-model-pins.js.map +1 -0
- package/dist/core/provider-prompt-contracts.d.ts.map +1 -1
- package/dist/core/provider-prompt-contracts.js +2 -1
- package/dist/core/provider-prompt-contracts.js.map +1 -1
- package/dist/core/reflection-controller.d.ts.map +1 -1
- package/dist/core/reflection-controller.js +8 -1
- package/dist/core/reflection-controller.js.map +1 -1
- package/dist/core/runtime-builder.d.ts.map +1 -1
- package/dist/core/runtime-builder.js +1 -0
- package/dist/core/runtime-builder.js.map +1 -1
- package/dist/core/settings-manager.d.ts +6 -3
- package/dist/core/settings-manager.d.ts.map +1 -1
- package/dist/core/settings-manager.js +26 -2
- package/dist/core/settings-manager.js.map +1 -1
- package/dist/core/tools/bash.d.ts +3 -0
- package/dist/core/tools/bash.d.ts.map +1 -1
- package/dist/core/tools/bash.js +13 -2
- package/dist/core/tools/bash.js.map +1 -1
- package/dist/core/tools/delegate-status.d.ts +3 -0
- package/dist/core/tools/delegate-status.d.ts.map +1 -1
- package/dist/core/tools/delegate-status.js +26 -1
- package/dist/core/tools/delegate-status.js.map +1 -1
- package/dist/core/tools/delegate.d.ts +15 -1
- package/dist/core/tools/delegate.d.ts.map +1 -1
- package/dist/core/tools/delegate.js +234 -68
- package/dist/core/tools/delegate.js.map +1 -1
- package/dist/core/tools/edit.d.ts.map +1 -1
- package/dist/core/tools/edit.js +14 -1
- package/dist/core/tools/edit.js.map +1 -1
- package/dist/core/tools/file-failure-recovery.d.ts +3 -0
- package/dist/core/tools/file-failure-recovery.d.ts.map +1 -1
- package/dist/core/tools/file-failure-recovery.js +11 -0
- package/dist/core/tools/file-failure-recovery.js.map +1 -1
- package/dist/core/tools/orchestration-panel.d.ts +1 -1
- package/dist/core/tools/orchestration-panel.d.ts.map +1 -1
- package/dist/core/tools/orchestration-panel.js +1 -0
- package/dist/core/tools/orchestration-panel.js.map +1 -1
- package/dist/core/tools/profile-writer.d.ts.map +1 -1
- package/dist/core/tools/profile-writer.js +2 -8
- package/dist/core/tools/profile-writer.js.map +1 -1
- package/dist/core/tools/search-command-guard.d.ts.map +1 -1
- package/dist/core/tools/search-command-guard.js +10 -3
- package/dist/core/tools/search-command-guard.js.map +1 -1
- package/dist/core/tools/write.d.ts.map +1 -1
- package/dist/core/tools/write.js +10 -1
- package/dist/core/tools/write.js.map +1 -1
- package/dist/modes/interactive/components/activity-lane.d.ts +1 -1
- package/dist/modes/interactive/components/activity-lane.d.ts.map +1 -1
- package/dist/modes/interactive/components/activity-lane.js +11 -2
- package/dist/modes/interactive/components/activity-lane.js.map +1 -1
- package/dist/modes/interactive/components/settings-selector.js +1 -1
- package/dist/modes/interactive/components/settings-selector.js.map +1 -1
- package/dist/utils/shell.d.ts +2 -0
- package/dist/utils/shell.d.ts.map +1 -1
- package/dist/utils/shell.js +3 -1
- package/dist/utils/shell.js.map +1 -1
- package/docs/harness-architecture.md +6 -3
- package/docs/settings.md +39 -6
- package/docs/tool-repair.md +1 -1
- package/docs/worker-profiles.md +2 -2
- package/examples/extensions/custom-provider-anthropic/package-lock.json +2 -2
- package/examples/extensions/custom-provider-anthropic/package.json +1 -1
- package/examples/extensions/custom-provider-gitlab-duo/package.json +1 -1
- package/examples/extensions/sandbox/package-lock.json +2 -2
- package/examples/extensions/sandbox/package.json +1 -1
- package/examples/extensions/with-deps/package-lock.json +2 -2
- package/examples/extensions/with-deps/package.json +1 -1
- package/npm-shrinkwrap.json +12 -12
- package/package.json +4 -4
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { describeToolCapabilityAuthority, resolveProfileToolCapability } from "../tool-capability-policy.js";
|
|
2
2
|
import { hasOnlyKeys, isPlainRecord } from "../util/value-guards.js";
|
|
3
|
-
import { HARNESS_CAPABILITIES, MAX_ORCHESTRATION_COLLECTION_LENGTH, MAX_ORCHESTRATION_DESCRIPTION_LENGTH, MAX_ORCHESTRATION_DISPATCH_INSTRUCTIONS_LENGTH, MAX_ORCHESTRATION_IDENTIFIER_LENGTH, MAX_ORCHESTRATION_MODEL_ID_LENGTH, MAX_ORCHESTRATION_MODEL_PROVIDER_LENGTH, MAX_ORCHESTRATION_PROCESS_OUTPUT_BYTES, MAX_WORKER_AUTHORITY_PATH_LENGTH, ORCHESTRATION_SCHEMA_VERSION, ORCHESTRATION_THINKING_LEVELS, toJsonObject, WORKER_ROLES, } from "./contracts.js";
|
|
3
|
+
import { HARNESS_CAPABILITIES, MAX_ORCHESTRATION_AGENT_BINDINGS, MAX_ORCHESTRATION_AGENT_DEPTH, MAX_ORCHESTRATION_COLLECTION_LENGTH, MAX_ORCHESTRATION_DESCRIPTION_LENGTH, MAX_ORCHESTRATION_DIRECT_CHILDREN, MAX_ORCHESTRATION_DISPATCH_INSTRUCTIONS_LENGTH, MAX_ORCHESTRATION_IDENTIFIER_LENGTH, MAX_ORCHESTRATION_MODEL_ID_LENGTH, MAX_ORCHESTRATION_MODEL_PROVIDER_LENGTH, MAX_ORCHESTRATION_PROCESS_OUTPUT_BYTES, MAX_WORKER_AUTHORITY_PATH_LENGTH, ORCHESTRATION_SCHEMA_VERSION, ORCHESTRATION_THINKING_LEVELS, toJsonObject, WORKER_ROLES, } from "./contracts.js";
|
|
4
4
|
import { ORCHESTRATION_PROFILE_TOOL_NAMES } from "./lane-tool-manifests.js";
|
|
5
5
|
import { DEFAULT_ROLE_CAPABILITY_CEILINGS, } from "./policy-compiler.js";
|
|
6
6
|
import { parseRiskBudget, validateRiskBudget } from "./risk-budget.js";
|
|
@@ -129,6 +129,19 @@ export function validateOrchestrationProfile(profile) {
|
|
|
129
129
|
if (!Number.isSafeInteger(profile.leaseTtlMs) || profile.leaseTtlMs <= 0) {
|
|
130
130
|
throw new OrchestrationProfileError(`Profile '${profile.profileId}' leaseTtlMs must be positive.`);
|
|
131
131
|
}
|
|
132
|
+
if (profile.delegationLimits &&
|
|
133
|
+
(!Number.isSafeInteger(profile.delegationLimits.maxDepth) ||
|
|
134
|
+
profile.delegationLimits.maxDepth < 0 ||
|
|
135
|
+
profile.delegationLimits.maxDepth > MAX_ORCHESTRATION_AGENT_DEPTH ||
|
|
136
|
+
!Number.isSafeInteger(profile.delegationLimits.maxChildrenPerAgent) ||
|
|
137
|
+
profile.delegationLimits.maxChildrenPerAgent < 0 ||
|
|
138
|
+
profile.delegationLimits.maxChildrenPerAgent > MAX_ORCHESTRATION_DIRECT_CHILDREN ||
|
|
139
|
+
(profile.delegationLimits.maxNestedAgentsPerSession !== undefined &&
|
|
140
|
+
(!Number.isSafeInteger(profile.delegationLimits.maxNestedAgentsPerSession) ||
|
|
141
|
+
profile.delegationLimits.maxNestedAgentsPerSession < 0 ||
|
|
142
|
+
profile.delegationLimits.maxNestedAgentsPerSession > MAX_ORCHESTRATION_AGENT_BINDINGS)))) {
|
|
143
|
+
throw new OrchestrationProfileError(`Profile '${profile.profileId}' delegationLimits are invalid.`);
|
|
144
|
+
}
|
|
132
145
|
try {
|
|
133
146
|
validateRiskBudget(profile.budget, `Profile '${profile.profileId}' budget`);
|
|
134
147
|
}
|
|
@@ -192,6 +205,7 @@ export function parseOrchestrationProfile(value, sourcePath) {
|
|
|
192
205
|
"resourceProfileNames",
|
|
193
206
|
"dispatchProfileIds",
|
|
194
207
|
"executionPolicy",
|
|
208
|
+
"delegationLimits",
|
|
195
209
|
"budget",
|
|
196
210
|
"maxConcurrent",
|
|
197
211
|
"leaseTtlMs",
|
|
@@ -206,6 +220,7 @@ export function parseOrchestrationProfile(value, sourcePath) {
|
|
|
206
220
|
const rawBudget = value.budget;
|
|
207
221
|
let budget;
|
|
208
222
|
const executionPolicy = value.executionPolicy;
|
|
223
|
+
const delegationLimits = value.delegationLimits;
|
|
209
224
|
if (!isPlainRecord(modelPolicy) ||
|
|
210
225
|
!hasOnlyKeys(modelPolicy, ["mode", "candidates"]) ||
|
|
211
226
|
!Array.isArray(modelPolicy.candidates) ||
|
|
@@ -226,6 +241,15 @@ export function parseOrchestrationProfile(value, sourcePath) {
|
|
|
226
241
|
!Number.isSafeInteger(executionPolicy.maxOutputBytes))) {
|
|
227
242
|
throw new OrchestrationProfileError("Orchestration profile executionPolicy is invalid.");
|
|
228
243
|
}
|
|
244
|
+
if (delegationLimits !== undefined &&
|
|
245
|
+
(!isPlainRecord(delegationLimits) ||
|
|
246
|
+
!hasOnlyKeys(delegationLimits, ["maxDepth", "maxChildrenPerAgent", "maxNestedAgentsPerSession"]) ||
|
|
247
|
+
!Number.isSafeInteger(delegationLimits.maxDepth) ||
|
|
248
|
+
!Number.isSafeInteger(delegationLimits.maxChildrenPerAgent) ||
|
|
249
|
+
(delegationLimits.maxNestedAgentsPerSession !== undefined &&
|
|
250
|
+
!Number.isSafeInteger(delegationLimits.maxNestedAgentsPerSession)))) {
|
|
251
|
+
throw new OrchestrationProfileError("Orchestration profile delegationLimits are invalid.");
|
|
252
|
+
}
|
|
229
253
|
const candidates = modelPolicy.candidates.map((candidate) => {
|
|
230
254
|
if (!isPlainRecord(candidate) || !hasOnlyKeys(candidate, ["provider", "modelId", "thinkingLevel"])) {
|
|
231
255
|
throw new OrchestrationProfileError("Orchestration profile model candidate is invalid.");
|
|
@@ -297,6 +321,17 @@ export function parseOrchestrationProfile(value, sourcePath) {
|
|
|
297
321
|
},
|
|
298
322
|
}
|
|
299
323
|
: {}),
|
|
324
|
+
...(isPlainRecord(delegationLimits)
|
|
325
|
+
? {
|
|
326
|
+
delegationLimits: {
|
|
327
|
+
maxDepth: Number(delegationLimits.maxDepth),
|
|
328
|
+
maxChildrenPerAgent: Number(delegationLimits.maxChildrenPerAgent),
|
|
329
|
+
...(delegationLimits.maxNestedAgentsPerSession !== undefined
|
|
330
|
+
? { maxNestedAgentsPerSession: Number(delegationLimits.maxNestedAgentsPerSession) }
|
|
331
|
+
: {}),
|
|
332
|
+
},
|
|
333
|
+
}
|
|
334
|
+
: {}),
|
|
300
335
|
budget,
|
|
301
336
|
maxConcurrent: Number(value.maxConcurrent),
|
|
302
337
|
leaseTtlMs: Number(value.leaseTtlMs),
|
|
@@ -326,6 +361,8 @@ function freezeProfile(profile) {
|
|
|
326
361
|
Object.freeze(clone.executionPolicy.allowedEnvironmentVariables);
|
|
327
362
|
Object.freeze(clone.executionPolicy);
|
|
328
363
|
}
|
|
364
|
+
if (clone.delegationLimits)
|
|
365
|
+
Object.freeze(clone.delegationLimits);
|
|
329
366
|
Object.freeze(clone.budget);
|
|
330
367
|
return Object.freeze(clone);
|
|
331
368
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"profile-registry.js","sourceRoot":"","sources":["../../../src/core/orchestration/profile-registry.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,+BAA+B,EAAE,4BAA4B,EAAE,MAAM,8BAA8B,CAAC;AAC7G,OAAO,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AAWrE,OAAO,EACN,oBAAoB,EACpB,mCAAmC,EACnC,oCAAoC,EACpC,8CAA8C,EAC9C,mCAAmC,EACnC,iCAAiC,EACjC,uCAAuC,EACvC,sCAAsC,EACtC,gCAAgC,EAChC,4BAA4B,EAC5B,6BAA6B,EAC7B,YAAY,EACZ,YAAY,GACZ,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,gCAAgC,EAAE,MAAM,0BAA0B,CAAC;AAC5E,OAAO,EAEN,gCAAgC,GAGhC,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,eAAe,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AAkBvE,MAAM,OAAO,yBAA0B,SAAQ,KAAK;IACnD,YAAY,OAAe;QAC1B,KAAK,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AI,CAAC,aAAa;QACjC,SAAS,EAAE,iBAAiB;QAC5B,SAAS,EAAE,IAAI,CAAC,SAAS;QACzB,UAAU,EAAE,IAAI,CAAC,UAAU;QAC3B,WAAW,EAAE,IAAI,CAAC,WAAW;QAC7B,eAAe,EAAE,OAAO,CAAC,MAAM;QAC/B,eAAe,EAAE,OAAO,CAAC,MAAM;QAC/B,aAAa,EAAE,IAAI,CAAC,aAAa;KACjC,CAAC;IACF,MAAM,QAAQ,GAAG,IAAI,CAAC,cAAc,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC;IAC1D,IAAI,QAAQ,CAAC,OAAO,KAAK,OAAO;QAAE,OAAO,QAAQ,CAAC;IAClD,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,EAAE,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,QAAQ,CAAC,KAAK,EAAE,aAAa,EAAE,QAAQ,CAAC,aAAa,EAAE,EAAE,CAAC;AACrH,CAAC","sourcesContent":["import { describeToolCapabilityAuthority, resolveProfileToolCapability } from \"../tool-capability-policy.ts\";\nimport { hasOnlyKeys, isPlainRecord } from \"../util/value-guards.ts\";\nimport type {\n\tExecutionGrant,\n\tOrchestrationDispatchRequest,\n\tOrchestrationModelBinding,\n\tOrchestrationProfile,\n\tResourcePointer,\n\tRiskBudget,\n\tTaskContract,\n\tToolCapabilityManifest,\n} from \"./contracts.ts\";\nimport {\n\tHARNESS_CAPABILITIES,\n\tMAX_ORCHESTRATION_COLLECTION_LENGTH,\n\tMAX_ORCHESTRATION_DESCRIPTION_LENGTH,\n\tMAX_ORCHESTRATION_DISPATCH_INSTRUCTIONS_LENGTH,\n\tMAX_ORCHESTRATION_IDENTIFIER_LENGTH,\n\tMAX_ORCHESTRATION_MODEL_ID_LENGTH,\n\tMAX_ORCHESTRATION_MODEL_PROVIDER_LENGTH,\n\tMAX_ORCHESTRATION_PROCESS_OUTPUT_BYTES,\n\tMAX_WORKER_AUTHORITY_PATH_LENGTH,\n\tORCHESTRATION_SCHEMA_VERSION,\n\tORCHESTRATION_THINKING_LEVELS,\n\ttoJsonObject,\n\tWORKER_ROLES,\n} from \"./contracts.ts\";\nimport { ORCHESTRATION_PROFILE_TOOL_NAMES } from \"./lane-tool-manifests.ts\";\nimport {\n\ttype CompileExecutionGrantInput,\n\tDEFAULT_ROLE_CAPABILITY_CEILINGS,\n\ttype ExecutionPolicyCompiler,\n\ttype PolicyCompilationResult,\n} from \"./policy-compiler.ts\";\nimport { parseRiskBudget, validateRiskBudget } from \"./risk-budget.ts\";\n\nexport interface ModelHealthView {\n\tisHealthy(binding: OrchestrationModelBinding): boolean;\n}\n\nexport interface ProfileDispatchPlan {\n\tprofile: OrchestrationProfile;\n\tmodel: OrchestrationModelBinding;\n\tgrant: ExecutionGrant;\n\ttoolManifests: readonly ToolCapabilityManifest[];\n}\n\nexport type ProfileDispatchPlanResult =\n\t| { outcome: \"allow\"; plan: ProfileDispatchPlan }\n\t| Exclude<PolicyCompilationResult, { outcome: \"allow\" }>\n\t| { outcome: \"deny\"; decisions: readonly []; reasonCodes: readonly [\"profile_model_unavailable\"] };\n\nexport class OrchestrationProfileError extends Error {\n\tconstructor(message: string) {\n\t\tsuper(message);\n\t\tthis.name = \"OrchestrationProfileError\";\n\t}\n}\n\nfunction duplicateStrings(values: readonly string[]): string[] {\n\tconst seen = new Set<string>();\n\tconst duplicates = new Set<string>();\n\tfor (const value of values) {\n\t\tif (seen.has(value)) duplicates.add(value);\n\t\tseen.add(value);\n\t}\n\treturn [...duplicates];\n}\n\nexport function parseOrchestrationDispatchRequest(value: unknown): OrchestrationDispatchRequest {\n\tif (!isPlainRecord(value)) throw new OrchestrationProfileError(\"Dispatch request must be an object.\");\n\tif (!hasOnlyKeys(value, [\"taskId\", \"profileId\", \"instructions\", \"resourcePointerIds\"])) {\n\t\tthrow new OrchestrationProfileError(\"Dispatch request contains an unsupported durable metadata field.\");\n\t}\n\tif (\n\t\ttypeof value.taskId !== \"string\" ||\n\t\t!value.taskId ||\n\t\tvalue.taskId.length > MAX_ORCHESTRATION_IDENTIFIER_LENGTH ||\n\t\ttypeof value.profileId !== \"string\" ||\n\t\t!value.profileId ||\n\t\tvalue.profileId.length > MAX_ORCHESTRATION_IDENTIFIER_LENGTH ||\n\t\ttypeof value.instructions !== \"string\" ||\n\t\tvalue.instructions.length > MAX_ORCHESTRATION_DISPATCH_INSTRUCTIONS_LENGTH ||\n\t\t!value.instructions.trim() ||\n\t\t!Array.isArray(value.resourcePointerIds) ||\n\t\tvalue.resourcePointerIds.length > MAX_ORCHESTRATION_COLLECTION_LENGTH ||\n\t\t!value.resourcePointerIds.every(\n\t\t\t(entry) =>\n\t\t\t\ttypeof entry === \"string\" && entry.length > 0 && entry.length <= MAX_ORCHESTRATION_IDENTIFIER_LENGTH,\n\t\t) ||\n\t\tnew Set(value.resourcePointerIds).size !== value.resourcePointerIds.length\n\t) {\n\t\tthrow new OrchestrationProfileError(\"Dispatch request is invalid.\");\n\t}\n\treturn {\n\t\ttaskId: value.taskId,\n\t\tprofileId: value.profileId,\n\t\tinstructions: value.instructions.trim(),\n\t\tresourcePointerIds: [...value.resourcePointerIds],\n\t};\n}\n\nexport function validateOrchestrationProfile(profile: OrchestrationProfile): void {\n\tif (profile.schemaVersion !== ORCHESTRATION_SCHEMA_VERSION) {\n\t\tthrow new OrchestrationProfileError(`Profile '${profile.profileId}' has an unsupported schema version.`);\n\t}\n\tif (\n\t\tprofile.profileId.length > MAX_ORCHESTRATION_IDENTIFIER_LENGTH ||\n\t\t!profile.profileId.trim() ||\n\t\tprofile.description.length > MAX_ORCHESTRATION_DESCRIPTION_LENGTH ||\n\t\t!profile.description.trim()\n\t)\n\t\tthrow new OrchestrationProfileError(\"Profile id and description are required.\");\n\tif (profile.role !== \"orchestrator\" && profile.dispatchProfileIds.length > 0) {\n\t\tthrow new OrchestrationProfileError(\n\t\t\t`Only orchestrator profiles may declare dispatchProfileIds ('${profile.profileId}').`,\n\t\t);\n\t}\n\tif (profile.dispatchProfileIds.includes(profile.profileId)) {\n\t\tthrow new OrchestrationProfileError(`Profile '${profile.profileId}' cannot dispatch itself.`);\n\t}\n\tif (profile.requireIndependentVerification) {\n\t\tif (profile.role === \"verifier\") {\n\t\t\tthrow new OrchestrationProfileError(\n\t\t\t\t`Verifier profile '${profile.profileId}' cannot require another verifier.`,\n\t\t\t);\n\t\t}\n\t\tif (\n\t\t\t!profile.verificationProfileId?.trim() ||\n\t\t\tprofile.verificationProfileId.length > MAX_ORCHESTRATION_IDENTIFIER_LENGTH\n\t\t) {\n\t\t\tthrow new OrchestrationProfileError(\n\t\t\t\t`Profile '${profile.profileId}' requires independent verification but has no verificationProfileId.`,\n\t\t\t);\n\t\t}\n\t} else if (profile.verificationProfileId !== undefined) {\n\t\tthrow new OrchestrationProfileError(\n\t\t\t`Profile '${profile.profileId}' cannot declare verificationProfileId without requiring verification.`,\n\t\t);\n\t}\n\tif (profile.verificationProfileId === profile.profileId) {\n\t\tthrow new OrchestrationProfileError(`Profile '${profile.profileId}' cannot verify itself.`);\n\t}\n\tif (\n\t\t!profile.createdAt.trim() ||\n\t\tprofile.createdAt.length > MAX_ORCHESTRATION_IDENTIFIER_LENGTH ||\n\t\t!profile.updatedAt.trim() ||\n\t\tprofile.updatedAt.length > MAX_ORCHESTRATION_IDENTIFIER_LENGTH\n\t) {\n\t\tthrow new OrchestrationProfileError(`Profile '${profile.profileId}' timestamps are invalid.`);\n\t}\n\tfor (const [label, values] of [\n\t\t[\"capabilityCeiling\", profile.capabilityCeiling],\n\t\t[\"toolNames\", profile.toolNames],\n\t\t[\"resourceProfileNames\", profile.resourceProfileNames],\n\t\t[\"dispatchProfileIds\", profile.dispatchProfileIds],\n\t] as const) {\n\t\tif (\n\t\t\tvalues.length > MAX_ORCHESTRATION_COLLECTION_LENGTH ||\n\t\t\tvalues.some((value) => !value.trim() || value.length > MAX_ORCHESTRATION_IDENTIFIER_LENGTH)\n\t\t) {\n\t\t\tthrow new OrchestrationProfileError(`Profile '${profile.profileId}' contains an invalid ${label}.`);\n\t\t}\n\t\tconst duplicates = duplicateStrings(values);\n\t\tif (duplicates.length > 0) {\n\t\t\tthrow new OrchestrationProfileError(\n\t\t\t\t`Profile '${profile.profileId}' contains duplicate ${label}: ${duplicates.join(\", \")}.`,\n\t\t\t);\n\t\t}\n\t}\n\tconst roleCeiling = new Set(DEFAULT_ROLE_CAPABILITY_CEILINGS[profile.role]);\n\tconst outOfRoleCapabilities = profile.capabilityCeiling.filter((capability) => !roleCeiling.has(capability));\n\tif (outOfRoleCapabilities.length > 0) {\n\t\tthrow new OrchestrationProfileError(\n\t\t\t`Profile '${profile.profileId}' exceeds the ${profile.role} role ceiling: ${outOfRoleCapabilities.join(\", \")}.`,\n\t\t);\n\t}\n\tif (\n\t\tprofile.modelPolicy.candidates.length === 0 ||\n\t\tprofile.modelPolicy.candidates.length > MAX_ORCHESTRATION_COLLECTION_LENGTH\n\t) {\n\t\tthrow new OrchestrationProfileError(`Profile '${profile.profileId}' must declare a model candidate.`);\n\t}\n\tif (profile.modelPolicy.mode === \"fixed\" && profile.modelPolicy.candidates.length !== 1) {\n\t\tthrow new OrchestrationProfileError(\n\t\t\t`Fixed profile '${profile.profileId}' must declare exactly one model candidate.`,\n\t\t);\n\t}\n\tfor (const candidate of profile.modelPolicy.candidates) {\n\t\tif (\n\t\t\tcandidate.provider.length > MAX_ORCHESTRATION_MODEL_PROVIDER_LENGTH ||\n\t\t\t!candidate.provider.trim() ||\n\t\t\tcandidate.modelId.length > MAX_ORCHESTRATION_MODEL_ID_LENGTH ||\n\t\t\t!candidate.modelId.trim()\n\t\t) {\n\t\t\tthrow new OrchestrationProfileError(`Profile '${profile.profileId}' contains an invalid model binding.`);\n\t\t}\n\t}\n\tconst duplicateModels = duplicateStrings(\n\t\tprofile.modelPolicy.candidates.map((candidate) => `${candidate.provider}/${candidate.modelId}`),\n\t);\n\tif (duplicateModels.length > 0) {\n\t\tthrow new OrchestrationProfileError(\n\t\t\t`Profile '${profile.profileId}' contains duplicate model candidates: ${duplicateModels.join(\", \")}.`,\n\t\t);\n\t}\n\tif (!Number.isSafeInteger(profile.maxConcurrent) || profile.maxConcurrent <= 0) {\n\t\tthrow new OrchestrationProfileError(`Profile '${profile.profileId}' maxConcurrent must be positive.`);\n\t}\n\tif (!Number.isSafeInteger(profile.leaseTtlMs) || profile.leaseTtlMs <= 0) {\n\t\tthrow new OrchestrationProfileError(`Profile '${profile.profileId}' leaseTtlMs must be positive.`);\n\t}\n\ttry {\n\t\tvalidateRiskBudget(profile.budget, `Profile '${profile.profileId}' budget`);\n\t} catch (error) {\n\t\tthrow new OrchestrationProfileError(error instanceof Error ? error.message : String(error));\n\t}\n\tif (profile.budget.maxWallClockMs !== undefined && profile.budget.maxWallClockMs <= 0) {\n\t\tthrow new OrchestrationProfileError(\n\t\t\t`Profile '${profile.profileId}' maxWallClockMs budget must be positive when specified.`,\n\t\t);\n\t}\n\tif (profile.budget.maxWallClockMs !== undefined && profile.leaseTtlMs < profile.budget.maxWallClockMs) {\n\t\tthrow new OrchestrationProfileError(\n\t\t\t`Profile '${profile.profileId}' leaseTtlMs must cover its maxWallClockMs budget.`,\n\t\t);\n\t}\n\tconst processCapable =\n\t\tprofile.capabilityCeiling.includes(\"process.exec\") || profile.capabilityCeiling.includes(\"tests.execute\");\n\tconst directProcessLauncher = profile.toolNames.includes(\"run_process\");\n\tif (directProcessLauncher && (!profile.executionPolicy || profile.executionPolicy.allowedExecutables.length === 0)) {\n\t\tthrow new OrchestrationProfileError(\n\t\t\t`Profile '${profile.profileId}' must declare executionPolicy.allowedExecutables for run_process.`,\n\t\t);\n\t}\n\tif (!processCapable && profile.executionPolicy) {\n\t\tthrow new OrchestrationProfileError(\n\t\t\t`Profile '${profile.profileId}' cannot declare executionPolicy without process capabilities.`,\n\t\t);\n\t}\n\tif (profile.executionPolicy) {\n\t\tif (\n\t\t\tprofile.executionPolicy.allowedExecutables.length > MAX_ORCHESTRATION_COLLECTION_LENGTH ||\n\t\t\tprofile.executionPolicy.allowedEnvironmentVariables.length > MAX_ORCHESTRATION_COLLECTION_LENGTH ||\n\t\t\tprofile.executionPolicy.allowedExecutables.some(\n\t\t\t\t(executable) =>\n\t\t\t\t\t!executable.trim() ||\n\t\t\t\t\texecutable.length > MAX_WORKER_AUTHORITY_PATH_LENGTH ||\n\t\t\t\t\t/[\\0\\r\\n]/.test(executable),\n\t\t\t) ||\n\t\t\tprofile.executionPolicy.allowedEnvironmentVariables.some(\n\t\t\t\t(name) => name.length > MAX_ORCHESTRATION_IDENTIFIER_LENGTH || !/^[A-Za-z_][A-Za-z0-9_]*$/.test(name),\n\t\t\t) ||\n\t\t\t!Number.isSafeInteger(profile.executionPolicy.maxOutputBytes) ||\n\t\t\tprofile.executionPolicy.maxOutputBytes <= 0 ||\n\t\t\tprofile.executionPolicy.maxOutputBytes > MAX_ORCHESTRATION_PROCESS_OUTPUT_BYTES\n\t\t) {\n\t\t\tthrow new OrchestrationProfileError(`Profile '${profile.profileId}' executionPolicy is invalid.`);\n\t\t}\n\t}\n\tconst unknownTools = profile.toolNames.filter(\n\t\t(toolName) => !(ORCHESTRATION_PROFILE_TOOL_NAMES as readonly string[]).includes(toolName),\n\t);\n\tif (unknownTools.length > 0) {\n\t\tthrow new OrchestrationProfileError(\n\t\t\t`Profile '${profile.profileId}' contains unclassified orchestration tools: ${unknownTools.join(\", \")}.`,\n\t\t);\n\t}\n\tfor (const toolName of profile.toolNames) {\n\t\tif (!resolveProfileToolCapability(profile, toolName)) {\n\t\t\tthrow new OrchestrationProfileError(\n\t\t\t\t`Profile '${profile.profileId}' tool '${toolName}' lacks ${describeToolCapabilityAuthority(toolName)} authority.`,\n\t\t\t);\n\t\t}\n\t}\n\ttoJsonObject({ profile });\n}\n\nfunction isStringArray(value: unknown, maxLength = MAX_ORCHESTRATION_IDENTIFIER_LENGTH): value is string[] {\n\treturn (\n\t\tArray.isArray(value) &&\n\t\tvalue.length <= MAX_ORCHESTRATION_COLLECTION_LENGTH &&\n\t\tvalue.every((entry) => typeof entry === \"string\" && entry.length > 0 && entry.length <= maxLength)\n\t);\n}\n\nexport function parseOrchestrationProfile(value: unknown, sourcePath?: string): OrchestrationProfile {\n\tif (!isPlainRecord(value)) throw new OrchestrationProfileError(\"Orchestration profile must be an object.\");\n\tif (\n\t\t!hasOnlyKeys(value, [\n\t\t\t\"schemaVersion\",\n\t\t\t\"profileId\",\n\t\t\t\"description\",\n\t\t\t\"role\",\n\t\t\t\"modelPolicy\",\n\t\t\t\"capabilityCeiling\",\n\t\t\t\"toolNames\",\n\t\t\t\"resourceProfileNames\",\n\t\t\t\"dispatchProfileIds\",\n\t\t\t\"executionPolicy\",\n\t\t\t\"budget\",\n\t\t\t\"maxConcurrent\",\n\t\t\t\"leaseTtlMs\",\n\t\t\t\"requireIndependentVerification\",\n\t\t\t\"verificationProfileId\",\n\t\t\t\"createdAt\",\n\t\t\t\"updatedAt\",\n\t\t])\n\t) {\n\t\tthrow new OrchestrationProfileError(\"Orchestration profile contains an unsupported field.\");\n\t}\n\tconst modelPolicy = value.modelPolicy;\n\tconst rawBudget = value.budget;\n\tlet budget: RiskBudget;\n\tconst executionPolicy = value.executionPolicy;\n\tif (\n\t\t!isPlainRecord(modelPolicy) ||\n\t\t!hasOnlyKeys(modelPolicy, [\"mode\", \"candidates\"]) ||\n\t\t!Array.isArray(modelPolicy.candidates) ||\n\t\tmodelPolicy.candidates.length > MAX_ORCHESTRATION_COLLECTION_LENGTH\n\t) {\n\t\tthrow new OrchestrationProfileError(\"Orchestration profile modelPolicy is invalid.\");\n\t}\n\ttry {\n\t\tbudget = parseRiskBudget(rawBudget, \"Orchestration profile budget\");\n\t} catch (error) {\n\t\tthrow new OrchestrationProfileError(\n\t\t\terror instanceof Error ? error.message : \"Orchestration profile budget is invalid.\",\n\t\t);\n\t}\n\tif (\n\t\texecutionPolicy !== undefined &&\n\t\t(!isPlainRecord(executionPolicy) ||\n\t\t\t!hasOnlyKeys(executionPolicy, [\"allowedExecutables\", \"allowedEnvironmentVariables\", \"maxOutputBytes\"]) ||\n\t\t\t!isStringArray(executionPolicy.allowedExecutables, MAX_WORKER_AUTHORITY_PATH_LENGTH) ||\n\t\t\t!isStringArray(executionPolicy.allowedEnvironmentVariables) ||\n\t\t\t!Number.isSafeInteger(executionPolicy.maxOutputBytes))\n\t) {\n\t\tthrow new OrchestrationProfileError(\"Orchestration profile executionPolicy is invalid.\");\n\t}\n\tconst candidates = modelPolicy.candidates.map((candidate) => {\n\t\tif (!isPlainRecord(candidate) || !hasOnlyKeys(candidate, [\"provider\", \"modelId\", \"thinkingLevel\"])) {\n\t\t\tthrow new OrchestrationProfileError(\"Orchestration profile model candidate is invalid.\");\n\t\t}\n\t\tif (\n\t\t\ttypeof candidate.provider !== \"string\" ||\n\t\t\tcandidate.provider.length === 0 ||\n\t\t\tcandidate.provider.length > MAX_ORCHESTRATION_MODEL_PROVIDER_LENGTH ||\n\t\t\ttypeof candidate.modelId !== \"string\" ||\n\t\t\tcandidate.modelId.length === 0 ||\n\t\t\tcandidate.modelId.length > MAX_ORCHESTRATION_MODEL_ID_LENGTH ||\n\t\t\ttypeof candidate.thinkingLevel !== \"string\" ||\n\t\t\t!ORCHESTRATION_THINKING_LEVELS.includes(\n\t\t\t\tcandidate.thinkingLevel as (typeof ORCHESTRATION_THINKING_LEVELS)[number],\n\t\t\t)\n\t\t) {\n\t\t\tthrow new OrchestrationProfileError(\"Orchestration profile model candidate is invalid.\");\n\t\t}\n\t\treturn {\n\t\t\tprovider: candidate.provider,\n\t\t\tmodelId: candidate.modelId,\n\t\t\tthinkingLevel: candidate.thinkingLevel as (typeof ORCHESTRATION_THINKING_LEVELS)[number],\n\t\t};\n\t});\n\tif (\n\t\tvalue.schemaVersion !== ORCHESTRATION_SCHEMA_VERSION ||\n\t\ttypeof value.profileId !== \"string\" ||\n\t\tvalue.profileId.length === 0 ||\n\t\tvalue.profileId.length > MAX_ORCHESTRATION_IDENTIFIER_LENGTH ||\n\t\ttypeof value.description !== \"string\" ||\n\t\tvalue.description.length === 0 ||\n\t\tvalue.description.length > MAX_ORCHESTRATION_DESCRIPTION_LENGTH ||\n\t\ttypeof value.role !== \"string\" ||\n\t\t!WORKER_ROLES.includes(value.role as (typeof WORKER_ROLES)[number]) ||\n\t\t(modelPolicy.mode !== \"fixed\" && modelPolicy.mode !== \"ordered-fallback\") ||\n\t\t!Array.isArray(value.capabilityCeiling) ||\n\t\tvalue.capabilityCeiling.length > MAX_ORCHESTRATION_COLLECTION_LENGTH ||\n\t\t!value.capabilityCeiling.every(\n\t\t\t(capability) =>\n\t\t\t\ttypeof capability === \"string\" &&\n\t\t\t\tHARNESS_CAPABILITIES.includes(capability as (typeof HARNESS_CAPABILITIES)[number]),\n\t\t) ||\n\t\t!isStringArray(value.toolNames) ||\n\t\t!isStringArray(value.resourceProfileNames) ||\n\t\t!isStringArray(value.dispatchProfileIds) ||\n\t\t!Number.isSafeInteger(value.maxConcurrent) ||\n\t\t!Number.isSafeInteger(value.leaseTtlMs) ||\n\t\ttypeof value.requireIndependentVerification !== \"boolean\" ||\n\t\t(value.verificationProfileId !== undefined &&\n\t\t\t(typeof value.verificationProfileId !== \"string\" ||\n\t\t\t\tvalue.verificationProfileId.length === 0 ||\n\t\t\t\tvalue.verificationProfileId.length > MAX_ORCHESTRATION_IDENTIFIER_LENGTH)) ||\n\t\ttypeof value.createdAt !== \"string\" ||\n\t\tvalue.createdAt.length === 0 ||\n\t\tvalue.createdAt.length > MAX_ORCHESTRATION_IDENTIFIER_LENGTH ||\n\t\ttypeof value.updatedAt !== \"string\" ||\n\t\tvalue.updatedAt.length === 0 ||\n\t\tvalue.updatedAt.length > MAX_ORCHESTRATION_IDENTIFIER_LENGTH\n\t) {\n\t\tthrow new OrchestrationProfileError(\"Orchestration profile is invalid.\");\n\t}\n\tconst profile = structuredClone({\n\t\tschemaVersion: ORCHESTRATION_SCHEMA_VERSION,\n\t\tprofileId: value.profileId,\n\t\tdescription: value.description,\n\t\trole: value.role as OrchestrationProfile[\"role\"],\n\t\tmodelPolicy: { mode: modelPolicy.mode as OrchestrationProfile[\"modelPolicy\"][\"mode\"], candidates },\n\t\tcapabilityCeiling: value.capabilityCeiling as OrchestrationProfile[\"capabilityCeiling\"],\n\t\ttoolNames: value.toolNames,\n\t\tresourceProfileNames: value.resourceProfileNames,\n\t\tdispatchProfileIds: value.dispatchProfileIds,\n\t\t...(executionPolicy\n\t\t\t? {\n\t\t\t\t\texecutionPolicy: {\n\t\t\t\t\t\tallowedExecutables: executionPolicy.allowedExecutables as string[],\n\t\t\t\t\t\tallowedEnvironmentVariables: executionPolicy.allowedEnvironmentVariables as string[],\n\t\t\t\t\t\tmaxOutputBytes: Number(executionPolicy.maxOutputBytes),\n\t\t\t\t\t},\n\t\t\t\t}\n\t\t\t: {}),\n\t\tbudget,\n\t\tmaxConcurrent: Number(value.maxConcurrent),\n\t\tleaseTtlMs: Number(value.leaseTtlMs),\n\t\trequireIndependentVerification: value.requireIndependentVerification,\n\t\t...(typeof value.verificationProfileId === \"string\"\n\t\t\t? { verificationProfileId: value.verificationProfileId }\n\t\t\t: {}),\n\t\t...(sourcePath ? { sourcePath } : {}),\n\t\tcreatedAt: value.createdAt,\n\t\tupdatedAt: value.updatedAt,\n\t}) as OrchestrationProfile;\n\tvalidateOrchestrationProfile(profile);\n\treturn profile;\n}\n\nfunction freezeProfile(profile: OrchestrationProfile): OrchestrationProfile {\n\tconst clone = structuredClone(profile);\n\tfor (const candidate of clone.modelPolicy.candidates) Object.freeze(candidate);\n\tObject.freeze(clone.modelPolicy.candidates);\n\tObject.freeze(clone.modelPolicy);\n\tObject.freeze(clone.capabilityCeiling);\n\tObject.freeze(clone.toolNames);\n\tObject.freeze(clone.resourceProfileNames);\n\tObject.freeze(clone.dispatchProfileIds);\n\tif (clone.executionPolicy) {\n\t\tObject.freeze(clone.executionPolicy.allowedExecutables);\n\t\tObject.freeze(clone.executionPolicy.allowedEnvironmentVariables);\n\t\tObject.freeze(clone.executionPolicy);\n\t}\n\tObject.freeze(clone.budget);\n\treturn Object.freeze(clone);\n}\n\nexport class OrchestrationProfileRegistry {\n\tprivate readonly profiles = new Map<string, OrchestrationProfile>();\n\n\tconstructor(profiles: readonly OrchestrationProfile[] = []) {\n\t\tfor (const profile of profiles) this.register(profile);\n\t\tfor (const profile of this.profiles.values()) {\n\t\t\tfor (const dispatchedProfileId of profile.dispatchProfileIds) {\n\t\t\t\tconst target = this.profiles.get(dispatchedProfileId);\n\t\t\t\tif (!target) {\n\t\t\t\t\tthrow new OrchestrationProfileError(\n\t\t\t\t\t\t`Profile '${profile.profileId}' dispatches missing profile '${dispatchedProfileId}'.`,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (profile.verificationProfileId) {\n\t\t\t\tconst verifier = this.profiles.get(profile.verificationProfileId);\n\t\t\t\tif (!verifier) {\n\t\t\t\t\tthrow new OrchestrationProfileError(\n\t\t\t\t\t\t`Profile '${profile.profileId}' requires missing verifier profile '${profile.verificationProfileId}'.`,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\tif (verifier.role !== \"verifier\") {\n\t\t\t\t\tthrow new OrchestrationProfileError(\n\t\t\t\t\t\t`Profile '${profile.profileId}' verificationProfileId '${profile.verificationProfileId}' is not a verifier.`,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (profile.role === \"orchestrator\") {\n\t\t\t\tfor (const dispatchedProfileId of profile.dispatchProfileIds) {\n\t\t\t\t\tconst worker = this.profiles.get(dispatchedProfileId);\n\t\t\t\t\tif (\n\t\t\t\t\t\tworker?.verificationProfileId &&\n\t\t\t\t\t\t!profile.dispatchProfileIds.includes(worker.verificationProfileId)\n\t\t\t\t\t) {\n\t\t\t\t\t\tthrow new OrchestrationProfileError(\n\t\t\t\t\t\t\t`Orchestrator '${profile.profileId}' dispatches '${worker.profileId}' but not its verifier '${worker.verificationProfileId}'.`,\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\tregister(profile: OrchestrationProfile): void {\n\t\tvalidateOrchestrationProfile(profile);\n\t\tif (this.profiles.has(profile.profileId)) {\n\t\t\tthrow new OrchestrationProfileError(`Duplicate orchestration profile '${profile.profileId}'.`);\n\t\t}\n\t\tthis.profiles.set(profile.profileId, freezeProfile(profile));\n\t}\n\n\tget(profileId: string): OrchestrationProfile | undefined {\n\t\tconst profile = this.profiles.get(profileId);\n\t\treturn profile ? structuredClone(profile) : undefined;\n\t}\n\n\tlist(): OrchestrationProfile[] {\n\t\treturn [...this.profiles.values()].map((profile) => structuredClone(profile));\n\t}\n}\n\nexport function resolveProfileModel(\n\tprofile: OrchestrationProfile,\n\thealth: ModelHealthView,\n): OrchestrationModelBinding | undefined {\n\tif (profile.modelPolicy.mode === \"fixed\") {\n\t\tconst fixed = profile.modelPolicy.candidates[0];\n\t\treturn fixed && health.isHealthy(fixed) ? structuredClone(fixed) : undefined;\n\t}\n\tconst selected = profile.modelPolicy.candidates.find((candidate) => health.isHealthy(candidate));\n\treturn selected ? structuredClone(selected) : undefined;\n}\n\nexport function planProfileDispatch(args: {\n\trequest: OrchestrationDispatchRequest;\n\ttask: TaskContract;\n\tattemptId: string;\n\tsubjectId: string;\n\tregistry: OrchestrationProfileRegistry;\n\thealth: ModelHealthView;\n\tpolicyCompiler: ExecutionPolicyCompiler;\n\ttoolManifests: readonly ToolCapabilityManifest[];\n\tresources: readonly ResourcePointer[];\n\treadPaths: readonly string[];\n\twritePaths?: readonly string[];\n\tdeniedPaths?: readonly string[];\n\tpolicyVersion: string;\n}): ProfileDispatchPlanResult {\n\tconst profile = args.registry.get(args.request.profileId);\n\tif (!profile) return { outcome: \"deny\", decisions: [], reasonCodes: [\"profile_model_unavailable\"] };\n\tif (profile.role !== args.task.role) {\n\t\treturn { outcome: \"deny\", decisions: [], reasonCodes: [\"required_capability_exceeds_role_ceiling\"] };\n\t}\n\tconst model = resolveProfileModel(profile, args.health);\n\tif (!model) return { outcome: \"deny\", decisions: [], reasonCodes: [\"profile_model_unavailable\"] };\n\tconst selectedResources = args.resources.filter((resource) => args.request.resourcePointerIds.includes(resource.id));\n\tconst manifestsByName = new Map(args.toolManifests.map((manifest) => [manifest.toolName, manifest]));\n\tconst requestedTools = profile.toolNames.filter((toolName) => {\n\t\tconst manifest = manifestsByName.get(toolName);\n\t\treturn manifest?.capabilities.every((capability) => args.task.requiredCapabilities.includes(capability)) === true;\n\t});\n\tconst policyInput: CompileExecutionGrantInput = {\n\t\tobjectiveId: args.task.objectiveId,\n\t\ttaskId: args.task.taskId,\n\t\tattemptId: args.attemptId,\n\t\tsubjectId: args.subjectId,\n\t\trole: profile.role,\n\t\trequiredCapabilities: args.task.requiredCapabilities,\n\t\trequestedCapabilities: args.task.requiredCapabilities,\n\t\tauthorityCapabilities: profile.capabilityCeiling,\n\t\trequestedTools,\n\t\ttoolManifests: args.toolManifests,\n\t\tresources: selectedResources,\n\t\treadPaths: args.readPaths,\n\t\twritePaths: args.writePaths,\n\t\tdeniedPaths: args.deniedPaths,\n\t\trequestedBudget: profile.budget,\n\t\tauthorityBudget: profile.budget,\n\t\tpolicyVersion: args.policyVersion,\n\t};\n\tconst compiled = args.policyCompiler.compile(policyInput);\n\tif (compiled.outcome !== \"allow\") return compiled;\n\treturn { outcome: \"allow\", plan: { profile, model, grant: compiled.grant, toolManifests: compiled.toolManifests } };\n}\n"]}
|
|
1
|
+
{"version":3,"file":"profile-registry.js","sourceRoot":"","sources":["../../../src/core/orchestration/profile-registry.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,+BAA+B,EAAE,4BAA4B,EAAE,MAAM,8BAA8B,CAAC;AAC7G,OAAO,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AAWrE,OAAO,EACN,oBAAoB,EACpB,gCAAgC,EAChC,6BAA6B,EAC7B,mCAAmC,EACnC,oCAAoC,EACpC,iCAAiC,EACjC,8CAA8C,EAC9C,mCAAmC,EACnC,iCAA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/B,aAAa,EAAE,IAAI,CAAC,aAAa;KACjC,CAAC;IACF,MAAM,QAAQ,GAAG,IAAI,CAAC,cAAc,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC;IAC1D,IAAI,QAAQ,CAAC,OAAO,KAAK,OAAO;QAAE,OAAO,QAAQ,CAAC;IAClD,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,EAAE,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,QAAQ,CAAC,KAAK,EAAE,aAAa,EAAE,QAAQ,CAAC,aAAa,EAAE,EAAE,CAAC;AACrH,CAAC","sourcesContent":["import { describeToolCapabilityAuthority, resolveProfileToolCapability } from \"../tool-capability-policy.ts\";\nimport { hasOnlyKeys, isPlainRecord } from \"../util/value-guards.ts\";\nimport type {\n\tExecutionGrant,\n\tOrchestrationDispatchRequest,\n\tOrchestrationModelBinding,\n\tOrchestrationProfile,\n\tResourcePointer,\n\tRiskBudget,\n\tTaskContract,\n\tToolCapabilityManifest,\n} from \"./contracts.ts\";\nimport {\n\tHARNESS_CAPABILITIES,\n\tMAX_ORCHESTRATION_AGENT_BINDINGS,\n\tMAX_ORCHESTRATION_AGENT_DEPTH,\n\tMAX_ORCHESTRATION_COLLECTION_LENGTH,\n\tMAX_ORCHESTRATION_DESCRIPTION_LENGTH,\n\tMAX_ORCHESTRATION_DIRECT_CHILDREN,\n\tMAX_ORCHESTRATION_DISPATCH_INSTRUCTIONS_LENGTH,\n\tMAX_ORCHESTRATION_IDENTIFIER_LENGTH,\n\tMAX_ORCHESTRATION_MODEL_ID_LENGTH,\n\tMAX_ORCHESTRATION_MODEL_PROVIDER_LENGTH,\n\tMAX_ORCHESTRATION_PROCESS_OUTPUT_BYTES,\n\tMAX_WORKER_AUTHORITY_PATH_LENGTH,\n\tORCHESTRATION_SCHEMA_VERSION,\n\tORCHESTRATION_THINKING_LEVELS,\n\ttoJsonObject,\n\tWORKER_ROLES,\n} from \"./contracts.ts\";\nimport { ORCHESTRATION_PROFILE_TOOL_NAMES } from \"./lane-tool-manifests.ts\";\nimport {\n\ttype CompileExecutionGrantInput,\n\tDEFAULT_ROLE_CAPABILITY_CEILINGS,\n\ttype ExecutionPolicyCompiler,\n\ttype PolicyCompilationResult,\n} from \"./policy-compiler.ts\";\nimport { parseRiskBudget, validateRiskBudget } from \"./risk-budget.ts\";\n\nexport interface ModelHealthView {\n\tisHealthy(binding: OrchestrationModelBinding): boolean;\n}\n\nexport interface ProfileDispatchPlan {\n\tprofile: OrchestrationProfile;\n\tmodel: OrchestrationModelBinding;\n\tgrant: ExecutionGrant;\n\ttoolManifests: readonly ToolCapabilityManifest[];\n}\n\nexport type ProfileDispatchPlanResult =\n\t| { outcome: \"allow\"; plan: ProfileDispatchPlan }\n\t| Exclude<PolicyCompilationResult, { outcome: \"allow\" }>\n\t| { outcome: \"deny\"; decisions: readonly []; reasonCodes: readonly [\"profile_model_unavailable\"] };\n\nexport class OrchestrationProfileError extends Error {\n\tconstructor(message: string) {\n\t\tsuper(message);\n\t\tthis.name = \"OrchestrationProfileError\";\n\t}\n}\n\nfunction duplicateStrings(values: readonly string[]): string[] {\n\tconst seen = new Set<string>();\n\tconst duplicates = new Set<string>();\n\tfor (const value of values) {\n\t\tif (seen.has(value)) duplicates.add(value);\n\t\tseen.add(value);\n\t}\n\treturn [...duplicates];\n}\n\nexport function parseOrchestrationDispatchRequest(value: unknown): OrchestrationDispatchRequest {\n\tif (!isPlainRecord(value)) throw new OrchestrationProfileError(\"Dispatch request must be an object.\");\n\tif (!hasOnlyKeys(value, [\"taskId\", \"profileId\", \"instructions\", \"resourcePointerIds\"])) {\n\t\tthrow new OrchestrationProfileError(\"Dispatch request contains an unsupported durable metadata field.\");\n\t}\n\tif (\n\t\ttypeof value.taskId !== \"string\" ||\n\t\t!value.taskId ||\n\t\tvalue.taskId.length > MAX_ORCHESTRATION_IDENTIFIER_LENGTH ||\n\t\ttypeof value.profileId !== \"string\" ||\n\t\t!value.profileId ||\n\t\tvalue.profileId.length > MAX_ORCHESTRATION_IDENTIFIER_LENGTH ||\n\t\ttypeof value.instructions !== \"string\" ||\n\t\tvalue.instructions.length > MAX_ORCHESTRATION_DISPATCH_INSTRUCTIONS_LENGTH ||\n\t\t!value.instructions.trim() ||\n\t\t!Array.isArray(value.resourcePointerIds) ||\n\t\tvalue.resourcePointerIds.length > MAX_ORCHESTRATION_COLLECTION_LENGTH ||\n\t\t!value.resourcePointerIds.every(\n\t\t\t(entry) =>\n\t\t\t\ttypeof entry === \"string\" && entry.length > 0 && entry.length <= MAX_ORCHESTRATION_IDENTIFIER_LENGTH,\n\t\t) ||\n\t\tnew Set(value.resourcePointerIds).size !== value.resourcePointerIds.length\n\t) {\n\t\tthrow new OrchestrationProfileError(\"Dispatch request is invalid.\");\n\t}\n\treturn {\n\t\ttaskId: value.taskId,\n\t\tprofileId: value.profileId,\n\t\tinstructions: value.instructions.trim(),\n\t\tresourcePointerIds: [...value.resourcePointerIds],\n\t};\n}\n\nexport function validateOrchestrationProfile(profile: OrchestrationProfile): void {\n\tif (profile.schemaVersion !== ORCHESTRATION_SCHEMA_VERSION) {\n\t\tthrow new OrchestrationProfileError(`Profile '${profile.profileId}' has an unsupported schema version.`);\n\t}\n\tif (\n\t\tprofile.profileId.length > MAX_ORCHESTRATION_IDENTIFIER_LENGTH ||\n\t\t!profile.profileId.trim() ||\n\t\tprofile.description.length > MAX_ORCHESTRATION_DESCRIPTION_LENGTH ||\n\t\t!profile.description.trim()\n\t)\n\t\tthrow new OrchestrationProfileError(\"Profile id and description are required.\");\n\tif (profile.role !== \"orchestrator\" && profile.dispatchProfileIds.length > 0) {\n\t\tthrow new OrchestrationProfileError(\n\t\t\t`Only orchestrator profiles may declare dispatchProfileIds ('${profile.profileId}').`,\n\t\t);\n\t}\n\tif (profile.dispatchProfileIds.includes(profile.profileId)) {\n\t\tthrow new OrchestrationProfileError(`Profile '${profile.profileId}' cannot dispatch itself.`);\n\t}\n\tif (profile.requireIndependentVerification) {\n\t\tif (profile.role === \"verifier\") {\n\t\t\tthrow new OrchestrationProfileError(\n\t\t\t\t`Verifier profile '${profile.profileId}' cannot require another verifier.`,\n\t\t\t);\n\t\t}\n\t\tif (\n\t\t\t!profile.verificationProfileId?.trim() ||\n\t\t\tprofile.verificationProfileId.length > MAX_ORCHESTRATION_IDENTIFIER_LENGTH\n\t\t) {\n\t\t\tthrow new OrchestrationProfileError(\n\t\t\t\t`Profile '${profile.profileId}' requires independent verification but has no verificationProfileId.`,\n\t\t\t);\n\t\t}\n\t} else if (profile.verificationProfileId !== undefined) {\n\t\tthrow new OrchestrationProfileError(\n\t\t\t`Profile '${profile.profileId}' cannot declare verificationProfileId without requiring verification.`,\n\t\t);\n\t}\n\tif (profile.verificationProfileId === profile.profileId) {\n\t\tthrow new OrchestrationProfileError(`Profile '${profile.profileId}' cannot verify itself.`);\n\t}\n\tif (\n\t\t!profile.createdAt.trim() ||\n\t\tprofile.createdAt.length > MAX_ORCHESTRATION_IDENTIFIER_LENGTH ||\n\t\t!profile.updatedAt.trim() ||\n\t\tprofile.updatedAt.length > MAX_ORCHESTRATION_IDENTIFIER_LENGTH\n\t) {\n\t\tthrow new OrchestrationProfileError(`Profile '${profile.profileId}' timestamps are invalid.`);\n\t}\n\tfor (const [label, values] of [\n\t\t[\"capabilityCeiling\", profile.capabilityCeiling],\n\t\t[\"toolNames\", profile.toolNames],\n\t\t[\"resourceProfileNames\", profile.resourceProfileNames],\n\t\t[\"dispatchProfileIds\", profile.dispatchProfileIds],\n\t] as const) {\n\t\tif (\n\t\t\tvalues.length > MAX_ORCHESTRATION_COLLECTION_LENGTH ||\n\t\t\tvalues.some((value) => !value.trim() || value.length > MAX_ORCHESTRATION_IDENTIFIER_LENGTH)\n\t\t) {\n\t\t\tthrow new OrchestrationProfileError(`Profile '${profile.profileId}' contains an invalid ${label}.`);\n\t\t}\n\t\tconst duplicates = duplicateStrings(values);\n\t\tif (duplicates.length > 0) {\n\t\t\tthrow new OrchestrationProfileError(\n\t\t\t\t`Profile '${profile.profileId}' contains duplicate ${label}: ${duplicates.join(\", \")}.`,\n\t\t\t);\n\t\t}\n\t}\n\tconst roleCeiling = new Set(DEFAULT_ROLE_CAPABILITY_CEILINGS[profile.role]);\n\tconst outOfRoleCapabilities = profile.capabilityCeiling.filter((capability) => !roleCeiling.has(capability));\n\tif (outOfRoleCapabilities.length > 0) {\n\t\tthrow new OrchestrationProfileError(\n\t\t\t`Profile '${profile.profileId}' exceeds the ${profile.role} role ceiling: ${outOfRoleCapabilities.join(\", \")}.`,\n\t\t);\n\t}\n\tif (\n\t\tprofile.modelPolicy.candidates.length === 0 ||\n\t\tprofile.modelPolicy.candidates.length > MAX_ORCHESTRATION_COLLECTION_LENGTH\n\t) {\n\t\tthrow new OrchestrationProfileError(`Profile '${profile.profileId}' must declare a model candidate.`);\n\t}\n\tif (profile.modelPolicy.mode === \"fixed\" && profile.modelPolicy.candidates.length !== 1) {\n\t\tthrow new OrchestrationProfileError(\n\t\t\t`Fixed profile '${profile.profileId}' must declare exactly one model candidate.`,\n\t\t);\n\t}\n\tfor (const candidate of profile.modelPolicy.candidates) {\n\t\tif (\n\t\t\tcandidate.provider.length > MAX_ORCHESTRATION_MODEL_PROVIDER_LENGTH ||\n\t\t\t!candidate.provider.trim() ||\n\t\t\tcandidate.modelId.length > MAX_ORCHESTRATION_MODEL_ID_LENGTH ||\n\t\t\t!candidate.modelId.trim()\n\t\t) {\n\t\t\tthrow new OrchestrationProfileError(`Profile '${profile.profileId}' contains an invalid model binding.`);\n\t\t}\n\t}\n\tconst duplicateModels = duplicateStrings(\n\t\tprofile.modelPolicy.candidates.map((candidate) => `${candidate.provider}/${candidate.modelId}`),\n\t);\n\tif (duplicateModels.length > 0) {\n\t\tthrow new OrchestrationProfileError(\n\t\t\t`Profile '${profile.profileId}' contains duplicate model candidates: ${duplicateModels.join(\", \")}.`,\n\t\t);\n\t}\n\tif (!Number.isSafeInteger(profile.maxConcurrent) || profile.maxConcurrent <= 0) {\n\t\tthrow new OrchestrationProfileError(`Profile '${profile.profileId}' maxConcurrent must be positive.`);\n\t}\n\tif (!Number.isSafeInteger(profile.leaseTtlMs) || profile.leaseTtlMs <= 0) {\n\t\tthrow new OrchestrationProfileError(`Profile '${profile.profileId}' leaseTtlMs must be positive.`);\n\t}\n\tif (\n\t\tprofile.delegationLimits &&\n\t\t(!Number.isSafeInteger(profile.delegationLimits.maxDepth) ||\n\t\t\tprofile.delegationLimits.maxDepth < 0 ||\n\t\t\tprofile.delegationLimits.maxDepth > MAX_ORCHESTRATION_AGENT_DEPTH ||\n\t\t\t!Number.isSafeInteger(profile.delegationLimits.maxChildrenPerAgent) ||\n\t\t\tprofile.delegationLimits.maxChildrenPerAgent < 0 ||\n\t\t\tprofile.delegationLimits.maxChildrenPerAgent > MAX_ORCHESTRATION_DIRECT_CHILDREN ||\n\t\t\t(profile.delegationLimits.maxNestedAgentsPerSession !== undefined &&\n\t\t\t\t(!Number.isSafeInteger(profile.delegationLimits.maxNestedAgentsPerSession) ||\n\t\t\t\t\tprofile.delegationLimits.maxNestedAgentsPerSession < 0 ||\n\t\t\t\t\tprofile.delegationLimits.maxNestedAgentsPerSession > MAX_ORCHESTRATION_AGENT_BINDINGS)))\n\t) {\n\t\tthrow new OrchestrationProfileError(`Profile '${profile.profileId}' delegationLimits are invalid.`);\n\t}\n\ttry {\n\t\tvalidateRiskBudget(profile.budget, `Profile '${profile.profileId}' budget`);\n\t} catch (error) {\n\t\tthrow new OrchestrationProfileError(error instanceof Error ? error.message : String(error));\n\t}\n\tif (profile.budget.maxWallClockMs !== undefined && profile.budget.maxWallClockMs <= 0) {\n\t\tthrow new OrchestrationProfileError(\n\t\t\t`Profile '${profile.profileId}' maxWallClockMs budget must be positive when specified.`,\n\t\t);\n\t}\n\tif (profile.budget.maxWallClockMs !== undefined && profile.leaseTtlMs < profile.budget.maxWallClockMs) {\n\t\tthrow new OrchestrationProfileError(\n\t\t\t`Profile '${profile.profileId}' leaseTtlMs must cover its maxWallClockMs budget.`,\n\t\t);\n\t}\n\tconst processCapable =\n\t\tprofile.capabilityCeiling.includes(\"process.exec\") || profile.capabilityCeiling.includes(\"tests.execute\");\n\tconst directProcessLauncher = profile.toolNames.includes(\"run_process\");\n\tif (directProcessLauncher && (!profile.executionPolicy || profile.executionPolicy.allowedExecutables.length === 0)) {\n\t\tthrow new OrchestrationProfileError(\n\t\t\t`Profile '${profile.profileId}' must declare executionPolicy.allowedExecutables for run_process.`,\n\t\t);\n\t}\n\tif (!processCapable && profile.executionPolicy) {\n\t\tthrow new OrchestrationProfileError(\n\t\t\t`Profile '${profile.profileId}' cannot declare executionPolicy without process capabilities.`,\n\t\t);\n\t}\n\tif (profile.executionPolicy) {\n\t\tif (\n\t\t\tprofile.executionPolicy.allowedExecutables.length > MAX_ORCHESTRATION_COLLECTION_LENGTH ||\n\t\t\tprofile.executionPolicy.allowedEnvironmentVariables.length > MAX_ORCHESTRATION_COLLECTION_LENGTH ||\n\t\t\tprofile.executionPolicy.allowedExecutables.some(\n\t\t\t\t(executable) =>\n\t\t\t\t\t!executable.trim() ||\n\t\t\t\t\texecutable.length > MAX_WORKER_AUTHORITY_PATH_LENGTH ||\n\t\t\t\t\t/[\\0\\r\\n]/.test(executable),\n\t\t\t) ||\n\t\t\tprofile.executionPolicy.allowedEnvironmentVariables.some(\n\t\t\t\t(name) => name.length > MAX_ORCHESTRATION_IDENTIFIER_LENGTH || !/^[A-Za-z_][A-Za-z0-9_]*$/.test(name),\n\t\t\t) ||\n\t\t\t!Number.isSafeInteger(profile.executionPolicy.maxOutputBytes) ||\n\t\t\tprofile.executionPolicy.maxOutputBytes <= 0 ||\n\t\t\tprofile.executionPolicy.maxOutputBytes > MAX_ORCHESTRATION_PROCESS_OUTPUT_BYTES\n\t\t) {\n\t\t\tthrow new OrchestrationProfileError(`Profile '${profile.profileId}' executionPolicy is invalid.`);\n\t\t}\n\t}\n\tconst unknownTools = profile.toolNames.filter(\n\t\t(toolName) => !(ORCHESTRATION_PROFILE_TOOL_NAMES as readonly string[]).includes(toolName),\n\t);\n\tif (unknownTools.length > 0) {\n\t\tthrow new OrchestrationProfileError(\n\t\t\t`Profile '${profile.profileId}' contains unclassified orchestration tools: ${unknownTools.join(\", \")}.`,\n\t\t);\n\t}\n\tfor (const toolName of profile.toolNames) {\n\t\tif (!resolveProfileToolCapability(profile, toolName)) {\n\t\t\tthrow new OrchestrationProfileError(\n\t\t\t\t`Profile '${profile.profileId}' tool '${toolName}' lacks ${describeToolCapabilityAuthority(toolName)} authority.`,\n\t\t\t);\n\t\t}\n\t}\n\ttoJsonObject({ profile });\n}\n\nfunction isStringArray(value: unknown, maxLength = MAX_ORCHESTRATION_IDENTIFIER_LENGTH): value is string[] {\n\treturn (\n\t\tArray.isArray(value) &&\n\t\tvalue.length <= MAX_ORCHESTRATION_COLLECTION_LENGTH &&\n\t\tvalue.every((entry) => typeof entry === \"string\" && entry.length > 0 && entry.length <= maxLength)\n\t);\n}\n\nexport function parseOrchestrationProfile(value: unknown, sourcePath?: string): OrchestrationProfile {\n\tif (!isPlainRecord(value)) throw new OrchestrationProfileError(\"Orchestration profile must be an object.\");\n\tif (\n\t\t!hasOnlyKeys(value, [\n\t\t\t\"schemaVersion\",\n\t\t\t\"profileId\",\n\t\t\t\"description\",\n\t\t\t\"role\",\n\t\t\t\"modelPolicy\",\n\t\t\t\"capabilityCeiling\",\n\t\t\t\"toolNames\",\n\t\t\t\"resourceProfileNames\",\n\t\t\t\"dispatchProfileIds\",\n\t\t\t\"executionPolicy\",\n\t\t\t\"delegationLimits\",\n\t\t\t\"budget\",\n\t\t\t\"maxConcurrent\",\n\t\t\t\"leaseTtlMs\",\n\t\t\t\"requireIndependentVerification\",\n\t\t\t\"verificationProfileId\",\n\t\t\t\"createdAt\",\n\t\t\t\"updatedAt\",\n\t\t])\n\t) {\n\t\tthrow new OrchestrationProfileError(\"Orchestration profile contains an unsupported field.\");\n\t}\n\tconst modelPolicy = value.modelPolicy;\n\tconst rawBudget = value.budget;\n\tlet budget: RiskBudget;\n\tconst executionPolicy = value.executionPolicy;\n\tconst delegationLimits = value.delegationLimits;\n\tif (\n\t\t!isPlainRecord(modelPolicy) ||\n\t\t!hasOnlyKeys(modelPolicy, [\"mode\", \"candidates\"]) ||\n\t\t!Array.isArray(modelPolicy.candidates) ||\n\t\tmodelPolicy.candidates.length > MAX_ORCHESTRATION_COLLECTION_LENGTH\n\t) {\n\t\tthrow new OrchestrationProfileError(\"Orchestration profile modelPolicy is invalid.\");\n\t}\n\ttry {\n\t\tbudget = parseRiskBudget(rawBudget, \"Orchestration profile budget\");\n\t} catch (error) {\n\t\tthrow new OrchestrationProfileError(\n\t\t\terror instanceof Error ? error.message : \"Orchestration profile budget is invalid.\",\n\t\t);\n\t}\n\tif (\n\t\texecutionPolicy !== undefined &&\n\t\t(!isPlainRecord(executionPolicy) ||\n\t\t\t!hasOnlyKeys(executionPolicy, [\"allowedExecutables\", \"allowedEnvironmentVariables\", \"maxOutputBytes\"]) ||\n\t\t\t!isStringArray(executionPolicy.allowedExecutables, MAX_WORKER_AUTHORITY_PATH_LENGTH) ||\n\t\t\t!isStringArray(executionPolicy.allowedEnvironmentVariables) ||\n\t\t\t!Number.isSafeInteger(executionPolicy.maxOutputBytes))\n\t) {\n\t\tthrow new OrchestrationProfileError(\"Orchestration profile executionPolicy is invalid.\");\n\t}\n\tif (\n\t\tdelegationLimits !== undefined &&\n\t\t(!isPlainRecord(delegationLimits) ||\n\t\t\t!hasOnlyKeys(delegationLimits, [\"maxDepth\", \"maxChildrenPerAgent\", \"maxNestedAgentsPerSession\"]) ||\n\t\t\t!Number.isSafeInteger(delegationLimits.maxDepth) ||\n\t\t\t!Number.isSafeInteger(delegationLimits.maxChildrenPerAgent) ||\n\t\t\t(delegationLimits.maxNestedAgentsPerSession !== undefined &&\n\t\t\t\t!Number.isSafeInteger(delegationLimits.maxNestedAgentsPerSession)))\n\t) {\n\t\tthrow new OrchestrationProfileError(\"Orchestration profile delegationLimits are invalid.\");\n\t}\n\tconst candidates = modelPolicy.candidates.map((candidate) => {\n\t\tif (!isPlainRecord(candidate) || !hasOnlyKeys(candidate, [\"provider\", \"modelId\", \"thinkingLevel\"])) {\n\t\t\tthrow new OrchestrationProfileError(\"Orchestration profile model candidate is invalid.\");\n\t\t}\n\t\tif (\n\t\t\ttypeof candidate.provider !== \"string\" ||\n\t\t\tcandidate.provider.length === 0 ||\n\t\t\tcandidate.provider.length > MAX_ORCHESTRATION_MODEL_PROVIDER_LENGTH ||\n\t\t\ttypeof candidate.modelId !== \"string\" ||\n\t\t\tcandidate.modelId.length === 0 ||\n\t\t\tcandidate.modelId.length > MAX_ORCHESTRATION_MODEL_ID_LENGTH ||\n\t\t\ttypeof candidate.thinkingLevel !== \"string\" ||\n\t\t\t!ORCHESTRATION_THINKING_LEVELS.includes(\n\t\t\t\tcandidate.thinkingLevel as (typeof ORCHESTRATION_THINKING_LEVELS)[number],\n\t\t\t)\n\t\t) {\n\t\t\tthrow new OrchestrationProfileError(\"Orchestration profile model candidate is invalid.\");\n\t\t}\n\t\treturn {\n\t\t\tprovider: candidate.provider,\n\t\t\tmodelId: candidate.modelId,\n\t\t\tthinkingLevel: candidate.thinkingLevel as (typeof ORCHESTRATION_THINKING_LEVELS)[number],\n\t\t};\n\t});\n\tif (\n\t\tvalue.schemaVersion !== ORCHESTRATION_SCHEMA_VERSION ||\n\t\ttypeof value.profileId !== \"string\" ||\n\t\tvalue.profileId.length === 0 ||\n\t\tvalue.profileId.length > MAX_ORCHESTRATION_IDENTIFIER_LENGTH ||\n\t\ttypeof value.description !== \"string\" ||\n\t\tvalue.description.length === 0 ||\n\t\tvalue.description.length > MAX_ORCHESTRATION_DESCRIPTION_LENGTH ||\n\t\ttypeof value.role !== \"string\" ||\n\t\t!WORKER_ROLES.includes(value.role as (typeof WORKER_ROLES)[number]) ||\n\t\t(modelPolicy.mode !== \"fixed\" && modelPolicy.mode !== \"ordered-fallback\") ||\n\t\t!Array.isArray(value.capabilityCeiling) ||\n\t\tvalue.capabilityCeiling.length > MAX_ORCHESTRATION_COLLECTION_LENGTH ||\n\t\t!value.capabilityCeiling.every(\n\t\t\t(capability) =>\n\t\t\t\ttypeof capability === \"string\" &&\n\t\t\t\tHARNESS_CAPABILITIES.includes(capability as (typeof HARNESS_CAPABILITIES)[number]),\n\t\t) ||\n\t\t!isStringArray(value.toolNames) ||\n\t\t!isStringArray(value.resourceProfileNames) ||\n\t\t!isStringArray(value.dispatchProfileIds) ||\n\t\t!Number.isSafeInteger(value.maxConcurrent) ||\n\t\t!Number.isSafeInteger(value.leaseTtlMs) ||\n\t\ttypeof value.requireIndependentVerification !== \"boolean\" ||\n\t\t(value.verificationProfileId !== undefined &&\n\t\t\t(typeof value.verificationProfileId !== \"string\" ||\n\t\t\t\tvalue.verificationProfileId.length === 0 ||\n\t\t\t\tvalue.verificationProfileId.length > MAX_ORCHESTRATION_IDENTIFIER_LENGTH)) ||\n\t\ttypeof value.createdAt !== \"string\" ||\n\t\tvalue.createdAt.length === 0 ||\n\t\tvalue.createdAt.length > MAX_ORCHESTRATION_IDENTIFIER_LENGTH ||\n\t\ttypeof value.updatedAt !== \"string\" ||\n\t\tvalue.updatedAt.length === 0 ||\n\t\tvalue.updatedAt.length > MAX_ORCHESTRATION_IDENTIFIER_LENGTH\n\t) {\n\t\tthrow new OrchestrationProfileError(\"Orchestration profile is invalid.\");\n\t}\n\tconst profile = structuredClone({\n\t\tschemaVersion: ORCHESTRATION_SCHEMA_VERSION,\n\t\tprofileId: value.profileId,\n\t\tdescription: value.description,\n\t\trole: value.role as OrchestrationProfile[\"role\"],\n\t\tmodelPolicy: { mode: modelPolicy.mode as OrchestrationProfile[\"modelPolicy\"][\"mode\"], candidates },\n\t\tcapabilityCeiling: value.capabilityCeiling as OrchestrationProfile[\"capabilityCeiling\"],\n\t\ttoolNames: value.toolNames,\n\t\tresourceProfileNames: value.resourceProfileNames,\n\t\tdispatchProfileIds: value.dispatchProfileIds,\n\t\t...(executionPolicy\n\t\t\t? {\n\t\t\t\t\texecutionPolicy: {\n\t\t\t\t\t\tallowedExecutables: executionPolicy.allowedExecutables as string[],\n\t\t\t\t\t\tallowedEnvironmentVariables: executionPolicy.allowedEnvironmentVariables as string[],\n\t\t\t\t\t\tmaxOutputBytes: Number(executionPolicy.maxOutputBytes),\n\t\t\t\t\t},\n\t\t\t\t}\n\t\t\t: {}),\n\t\t...(isPlainRecord(delegationLimits)\n\t\t\t? {\n\t\t\t\t\tdelegationLimits: {\n\t\t\t\t\t\tmaxDepth: Number(delegationLimits.maxDepth),\n\t\t\t\t\t\tmaxChildrenPerAgent: Number(delegationLimits.maxChildrenPerAgent),\n\t\t\t\t\t\t...(delegationLimits.maxNestedAgentsPerSession !== undefined\n\t\t\t\t\t\t\t? { maxNestedAgentsPerSession: Number(delegationLimits.maxNestedAgentsPerSession) }\n\t\t\t\t\t\t\t: {}),\n\t\t\t\t\t},\n\t\t\t\t}\n\t\t\t: {}),\n\t\tbudget,\n\t\tmaxConcurrent: Number(value.maxConcurrent),\n\t\tleaseTtlMs: Number(value.leaseTtlMs),\n\t\trequireIndependentVerification: value.requireIndependentVerification,\n\t\t...(typeof value.verificationProfileId === \"string\"\n\t\t\t? { verificationProfileId: value.verificationProfileId }\n\t\t\t: {}),\n\t\t...(sourcePath ? { sourcePath } : {}),\n\t\tcreatedAt: value.createdAt,\n\t\tupdatedAt: value.updatedAt,\n\t}) as OrchestrationProfile;\n\tvalidateOrchestrationProfile(profile);\n\treturn profile;\n}\n\nfunction freezeProfile(profile: OrchestrationProfile): OrchestrationProfile {\n\tconst clone = structuredClone(profile);\n\tfor (const candidate of clone.modelPolicy.candidates) Object.freeze(candidate);\n\tObject.freeze(clone.modelPolicy.candidates);\n\tObject.freeze(clone.modelPolicy);\n\tObject.freeze(clone.capabilityCeiling);\n\tObject.freeze(clone.toolNames);\n\tObject.freeze(clone.resourceProfileNames);\n\tObject.freeze(clone.dispatchProfileIds);\n\tif (clone.executionPolicy) {\n\t\tObject.freeze(clone.executionPolicy.allowedExecutables);\n\t\tObject.freeze(clone.executionPolicy.allowedEnvironmentVariables);\n\t\tObject.freeze(clone.executionPolicy);\n\t}\n\tif (clone.delegationLimits) Object.freeze(clone.delegationLimits);\n\tObject.freeze(clone.budget);\n\treturn Object.freeze(clone);\n}\n\nexport class OrchestrationProfileRegistry {\n\tprivate readonly profiles = new Map<string, OrchestrationProfile>();\n\n\tconstructor(profiles: readonly OrchestrationProfile[] = []) {\n\t\tfor (const profile of profiles) this.register(profile);\n\t\tfor (const profile of this.profiles.values()) {\n\t\t\tfor (const dispatchedProfileId of profile.dispatchProfileIds) {\n\t\t\t\tconst target = this.profiles.get(dispatchedProfileId);\n\t\t\t\tif (!target) {\n\t\t\t\t\tthrow new OrchestrationProfileError(\n\t\t\t\t\t\t`Profile '${profile.profileId}' dispatches missing profile '${dispatchedProfileId}'.`,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (profile.verificationProfileId) {\n\t\t\t\tconst verifier = this.profiles.get(profile.verificationProfileId);\n\t\t\t\tif (!verifier) {\n\t\t\t\t\tthrow new OrchestrationProfileError(\n\t\t\t\t\t\t`Profile '${profile.profileId}' requires missing verifier profile '${profile.verificationProfileId}'.`,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\tif (verifier.role !== \"verifier\") {\n\t\t\t\t\tthrow new OrchestrationProfileError(\n\t\t\t\t\t\t`Profile '${profile.profileId}' verificationProfileId '${profile.verificationProfileId}' is not a verifier.`,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (profile.role === \"orchestrator\") {\n\t\t\t\tfor (const dispatchedProfileId of profile.dispatchProfileIds) {\n\t\t\t\t\tconst worker = this.profiles.get(dispatchedProfileId);\n\t\t\t\t\tif (\n\t\t\t\t\t\tworker?.verificationProfileId &&\n\t\t\t\t\t\t!profile.dispatchProfileIds.includes(worker.verificationProfileId)\n\t\t\t\t\t) {\n\t\t\t\t\t\tthrow new OrchestrationProfileError(\n\t\t\t\t\t\t\t`Orchestrator '${profile.profileId}' dispatches '${worker.profileId}' but not its verifier '${worker.verificationProfileId}'.`,\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\tregister(profile: OrchestrationProfile): void {\n\t\tvalidateOrchestrationProfile(profile);\n\t\tif (this.profiles.has(profile.profileId)) {\n\t\t\tthrow new OrchestrationProfileError(`Duplicate orchestration profile '${profile.profileId}'.`);\n\t\t}\n\t\tthis.profiles.set(profile.profileId, freezeProfile(profile));\n\t}\n\n\tget(profileId: string): OrchestrationProfile | undefined {\n\t\tconst profile = this.profiles.get(profileId);\n\t\treturn profile ? structuredClone(profile) : undefined;\n\t}\n\n\tlist(): OrchestrationProfile[] {\n\t\treturn [...this.profiles.values()].map((profile) => structuredClone(profile));\n\t}\n}\n\nexport function resolveProfileModel(\n\tprofile: OrchestrationProfile,\n\thealth: ModelHealthView,\n): OrchestrationModelBinding | undefined {\n\tif (profile.modelPolicy.mode === \"fixed\") {\n\t\tconst fixed = profile.modelPolicy.candidates[0];\n\t\treturn fixed && health.isHealthy(fixed) ? structuredClone(fixed) : undefined;\n\t}\n\tconst selected = profile.modelPolicy.candidates.find((candidate) => health.isHealthy(candidate));\n\treturn selected ? structuredClone(selected) : undefined;\n}\n\nexport function planProfileDispatch(args: {\n\trequest: OrchestrationDispatchRequest;\n\ttask: TaskContract;\n\tattemptId: string;\n\tsubjectId: string;\n\tregistry: OrchestrationProfileRegistry;\n\thealth: ModelHealthView;\n\tpolicyCompiler: ExecutionPolicyCompiler;\n\ttoolManifests: readonly ToolCapabilityManifest[];\n\tresources: readonly ResourcePointer[];\n\treadPaths: readonly string[];\n\twritePaths?: readonly string[];\n\tdeniedPaths?: readonly string[];\n\tpolicyVersion: string;\n}): ProfileDispatchPlanResult {\n\tconst profile = args.registry.get(args.request.profileId);\n\tif (!profile) return { outcome: \"deny\", decisions: [], reasonCodes: [\"profile_model_unavailable\"] };\n\tif (profile.role !== args.task.role) {\n\t\treturn { outcome: \"deny\", decisions: [], reasonCodes: [\"required_capability_exceeds_role_ceiling\"] };\n\t}\n\tconst model = resolveProfileModel(profile, args.health);\n\tif (!model) return { outcome: \"deny\", decisions: [], reasonCodes: [\"profile_model_unavailable\"] };\n\tconst selectedResources = args.resources.filter((resource) => args.request.resourcePointerIds.includes(resource.id));\n\tconst manifestsByName = new Map(args.toolManifests.map((manifest) => [manifest.toolName, manifest]));\n\tconst requestedTools = profile.toolNames.filter((toolName) => {\n\t\tconst manifest = manifestsByName.get(toolName);\n\t\treturn manifest?.capabilities.every((capability) => args.task.requiredCapabilities.includes(capability)) === true;\n\t});\n\tconst policyInput: CompileExecutionGrantInput = {\n\t\tobjectiveId: args.task.objectiveId,\n\t\ttaskId: args.task.taskId,\n\t\tattemptId: args.attemptId,\n\t\tsubjectId: args.subjectId,\n\t\trole: profile.role,\n\t\trequiredCapabilities: args.task.requiredCapabilities,\n\t\trequestedCapabilities: args.task.requiredCapabilities,\n\t\tauthorityCapabilities: profile.capabilityCeiling,\n\t\trequestedTools,\n\t\ttoolManifests: args.toolManifests,\n\t\tresources: selectedResources,\n\t\treadPaths: args.readPaths,\n\t\twritePaths: args.writePaths,\n\t\tdeniedPaths: args.deniedPaths,\n\t\trequestedBudget: profile.budget,\n\t\tauthorityBudget: profile.budget,\n\t\tpolicyVersion: args.policyVersion,\n\t};\n\tconst compiled = args.policyCompiler.compile(policyInput);\n\tif (compiled.outcome !== \"allow\") return compiled;\n\treturn { outcome: \"allow\", plan: { profile, model, grant: compiled.grant, toolManifests: compiled.toolManifests } };\n}\n"]}
|
|
@@ -1,7 +1,17 @@
|
|
|
1
|
+
import { Type } from "typebox";
|
|
1
2
|
import type { RiskBudget } from "./contracts.ts";
|
|
2
3
|
export declare const RISK_BUDGET_LIMIT_FIELDS: readonly ["maxTokens", "maxWallClockMs", "maxCostUsd", "maxAttempts", "maxToolCalls"];
|
|
3
4
|
export type RiskBudgetLimitField = (typeof RISK_BUDGET_LIMIT_FIELDS)[number];
|
|
4
5
|
export declare const RISK_BUDGET_FIELDS: readonly ["maxTokens", "maxWallClockMs", "maxCostUsd", "maxAttempts", "maxToolCalls", "requireApprovalAboveCostUsd"];
|
|
6
|
+
/** One model-facing schema for every explicit worker/profile budget boundary. */
|
|
7
|
+
export declare function createRiskBudgetSchema(): Type.TObject<{
|
|
8
|
+
maxTokens: Type.TOptional<Type.TNumber>;
|
|
9
|
+
maxWallClockMs: Type.TOptional<Type.TNumber>;
|
|
10
|
+
maxCostUsd: Type.TOptional<Type.TNumber>;
|
|
11
|
+
maxAttempts: Type.TOptional<Type.TNumber>;
|
|
12
|
+
maxToolCalls: Type.TOptional<Type.TNumber>;
|
|
13
|
+
requireApprovalAboveCostUsd: Type.TOptional<Type.TNumber>;
|
|
14
|
+
}>;
|
|
5
15
|
/** Parse raw durable budget input without cloning untrusted values. */
|
|
6
16
|
export declare function parseRiskBudget(value: unknown, label: string): RiskBudget;
|
|
7
17
|
export declare function validateRiskBudget(budget: RiskBudget, label: string): void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"risk-budget.d.ts","sourceRoot":"","sources":["../../../src/core/orchestration/risk-budget.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"risk-budget.d.ts","sourceRoot":"","sources":["../../../src/core/orchestration/risk-budget.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,SAAS,CAAC;AAE/B,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAEjD,eAAO,MAAM,wBAAwB,YACpC,WAAW,EACX,gBAAgB,EAChB,YAAY,EACZ,aAAa,EACb,cAAc,CACL,CAAC;AAEX,MAAM,MAAM,oBAAoB,GAAG,CAAC,OAAO,wBAAwB,CAAC,CAAC,MAAM,CAAC,CAAC;AAE7E,eAAO,MAAM,kBAAkB,sHAAwE,CAAC;AASxG,iFAAiF;AACjF,wBAAgB,sBAAsB;;;;;;;GAcrC;AASD,uEAAuE;AACvE,wBAAgB,eAAe,CAAC,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,GAAG,UAAU,CAYzE;AAED,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,UAAU,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI,CAW1E;AAED,wBAAgB,wBAAwB,CAAC,SAAS,EAAE,UAAU,EAAE,SAAS,EAAE,UAAU,GAAG,oBAAoB,EAAE,CAM7G;AAED,qFAAqF;AACrF,wBAAgB,oBAAoB,CAAC,GAAG,OAAO,EAAE,SAAS,UAAU,EAAE,GAAG,UAAU,CAWlF"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { Type } from "typebox";
|
|
1
2
|
import { isPlainRecord } from "../util/value-guards.js";
|
|
2
3
|
export const RISK_BUDGET_LIMIT_FIELDS = [
|
|
3
4
|
"maxTokens",
|
|
@@ -13,6 +14,19 @@ const DISCRETE_BUDGET_FIELDS = new Set([
|
|
|
13
14
|
"maxAttempts",
|
|
14
15
|
"maxToolCalls",
|
|
15
16
|
]);
|
|
17
|
+
/** One model-facing schema for every explicit worker/profile budget boundary. */
|
|
18
|
+
export function createRiskBudgetSchema() {
|
|
19
|
+
// Shape belongs to the tool schema. Numeric range and integer invariants belong to
|
|
20
|
+
// parseRiskBudget so every caller follows the same authoritative validation path.
|
|
21
|
+
return Type.Object({
|
|
22
|
+
maxTokens: Type.Optional(Type.Number()),
|
|
23
|
+
maxWallClockMs: Type.Optional(Type.Number()),
|
|
24
|
+
maxCostUsd: Type.Optional(Type.Number()),
|
|
25
|
+
maxAttempts: Type.Optional(Type.Number()),
|
|
26
|
+
maxToolCalls: Type.Optional(Type.Number()),
|
|
27
|
+
requireApprovalAboveCostUsd: Type.Optional(Type.Number()),
|
|
28
|
+
}, { additionalProperties: false });
|
|
29
|
+
}
|
|
16
30
|
function assertKnownRiskBudgetFields(budget, label) {
|
|
17
31
|
const unknownField = Object.keys(budget).find((field) => !RISK_BUDGET_FIELDS.includes(field));
|
|
18
32
|
if (unknownField)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"risk-budget.js","sourceRoot":"","sources":["../../../src/core/orchestration/risk-budget.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AAGxD,MAAM,CAAC,MAAM,wBAAwB,GAAG;IACvC,WAAW;IACX,gBAAgB;IAChB,YAAY;IACZ,aAAa;IACb,cAAc;CACL,CAAC;AAIX,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAAC,GAAG,wBAAwB,EAAE,6BAA6B,CAAU,CAAC;AAExG,MAAM,sBAAsB,GAAqD,IAAI,GAAG,CAAC;IACxF,WAAW;IACX,gBAAgB;IAChB,aAAa;IACb,cAAc;CACd,CAAC,CAAC;AAEH,SAAS,2BAA2B,CAAC,MAA+B,EAAE,KAAa;IAClF,MAAM,YAAY,GAAG,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,IAAI,CAC5C,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,kBAAkB,CAAC,QAAQ,CAAC,KAA4C,CAAC,CACrF,CAAC;IACF,IAAI,YAAY;QAAE,MAAM,IAAI,SAAS,CAAC,GAAG,KAAK,iCAAiC,CAAC,CAAC;AAClF,CAAC;AAED,uEAAuE;AACvE,MAAM,UAAU,eAAe,CAAC,KAAc,EAAE,KAAa;IAC5D,IAAI,CAAC,aAAa,CAAC,KAAK,CAAC;QAAE,MAAM,IAAI,SAAS,CAAC,GAAG,KAAK,qBAAqB,CAAC,CAAC;IAC9E,2BAA2B,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;IAC1C,MAAM,MAAM,GAAe,EAAE,CAAC;IAC9B,KAAK,MAAM,KAAK,IAAI,kBAAkB,EAAE,CAAC;QACxC,MAAM,SAAS,GAAG,KAAK,CAAC,KAAK,CAAC,CAAC;QAC/B,IAAI,SAAS,KAAK,SAAS;YAAE,SAAS;QACtC,IAAI,OA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I,OAAO,KAAK,SAAS,IAAI,OAAO,GAAG,OAAO,CAAC;IAC5E,CAAC,CAAC,CAAC;AACJ,CAAC;AAED,qFAAqF;AACrF,MAAM,UAAU,oBAAoB,CAAC,GAAG,OAA8B;IACrE,MAAM,MAAM,GAAe,EAAE,CAAC;IAC9B,KAAK,MAAM,KAAK,IAAI,kBAAkB,EAAE,CAAC;QACxC,MAAM,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,KAAK,EAAmB,EAAE,CAAC,KAAK,KAAK,SAAS,CAAC,CAAC;QAC9G,IAAI,MAAM,CAAC,MAAM,GAAG,CAAC;YAAE,MAAM,CAAC,KAAK,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,GAAG,MAAM,CAAC,CAAC;IAC5D,CAAC;IACD,MAAM,iBAAiB,GAAG,MAAM,CAAC,2BAA2B,CAAC;IAC7D,IAAI,iBAAiB,KAAK,SAAS,EAAE,CAAC;QACrC,MAAM,CAAC,UAAU,GAAG,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,UAAU,IAAI,iBAAiB,EAAE,iBAAiB,CAAC,CAAC;IACzF,CAAC;IACD,OAAO,MAAM,CAAC;AACf,CAAC","sourcesContent":["import { isPlainRecord } from \"../util/value-guards.ts\";\nimport type { RiskBudget } from \"./contracts.ts\";\n\nexport const RISK_BUDGET_LIMIT_FIELDS = [\n\t\"maxTokens\",\n\t\"maxWallClockMs\",\n\t\"maxCostUsd\",\n\t\"maxAttempts\",\n\t\"maxToolCalls\",\n] as const;\n\nexport type RiskBudgetLimitField = (typeof RISK_BUDGET_LIMIT_FIELDS)[number];\n\nexport const RISK_BUDGET_FIELDS = [...RISK_BUDGET_LIMIT_FIELDS, \"requireApprovalAboveCostUsd\"] as const;\n\nconst DISCRETE_BUDGET_FIELDS: ReadonlySet<(typeof RISK_BUDGET_FIELDS)[number]> = new Set([\n\t\"maxTokens\",\n\t\"maxWallClockMs\",\n\t\"maxAttempts\",\n\t\"maxToolCalls\",\n]);\n\nfunction assertKnownRiskBudgetFields(budget: Record<string, unknown>, label: string): void {\n\tconst unknownField = Object.keys(budget).find(\n\t\t(field) => !RISK_BUDGET_FIELDS.includes(field as (typeof RISK_BUDGET_FIELDS)[number]),\n\t);\n\tif (unknownField) throw new TypeError(`${label} contains an unsupported field.`);\n}\n\n/** Parse raw durable budget input without cloning untrusted values. */\nexport function parseRiskBudget(value: unknown, label: string): RiskBudget {\n\tif (!isPlainRecord(value)) throw new TypeError(`${label} must be an object.`);\n\tassertKnownRiskBudgetFields(value, label);\n\tconst budget: RiskBudget = {};\n\tfor (const field of RISK_BUDGET_FIELDS) {\n\t\tconst candidate = value[field];\n\t\tif (candidate === undefined) continue;\n\t\tif (typeof candidate !== \"number\") throw new TypeError(`${label}.${field} must be a number.`);\n\t\tbudget[field] = candidate;\n\t}\n\tvalidateRiskBudget(budget, label);\n\treturn budget;\n}\n\nexport function validateRiskBudget(budget: RiskBudget, label: string): void {\n\tif (!isPlainRecord(budget)) throw new TypeError(`${label} must be an object.`);\n\tassertKnownRiskBudgetFields(budget, label);\n\tfor (const field of RISK_BUDGET_FIELDS) {\n\t\tconst value = (budget as RiskBudget)[field];\n\t\tif (value === undefined) continue;\n\t\tif (!Number.isFinite(value) || value < 0) throw new TypeError(`${label}.${field} must be non-negative.`);\n\t\tif (DISCRETE_BUDGET_FIELDS.has(field) && !Number.isSafeInteger(value)) {\n\t\t\tthrow new TypeError(`${label}.${field} must be a non-negative safe integer.`);\n\t\t}\n\t}\n}\n\nexport function exceededRiskBudgetFields(requested: RiskBudget, authority: RiskBudget): RiskBudgetLimitField[] {\n\treturn RISK_BUDGET_LIMIT_FIELDS.filter((field) => {\n\t\tconst request = requested[field];\n\t\tconst ceiling = authority[field];\n\t\treturn request !== undefined && ceiling !== undefined && request > ceiling;\n\t});\n}\n\n/** Intersects independent ceilings. Undefined fields do not constrain the result. */\nexport function intersectRiskBudgets(...budgets: readonly RiskBudget[]): RiskBudget {\n\tconst result: RiskBudget = {};\n\tfor (const field of RISK_BUDGET_FIELDS) {\n\t\tconst values = budgets.map((budget) => budget[field]).filter((value): value is number => value !== undefined);\n\t\tif (values.length > 0) result[field] = Math.min(...values);\n\t}\n\tconst approvalThreshold = result.requireApprovalAboveCostUsd;\n\tif (approvalThreshold !== undefined) {\n\t\tresult.maxCostUsd = Math.min(result.maxCostUsd ?? approvalThreshold, approvalThreshold);\n\t}\n\treturn result;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"risk-budget.js","sourceRoot":"","sources":["../../../src/core/orchestration/risk-budget.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,SAAS,CAAC;AAC/B,OAAO,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AAGxD,MAAM,CAAC,MAAM,wBAAwB,GAAG;IACvC,WAAW;IACX,gBAAgB;IAChB,YAAY;IACZ,aAAa;IACb,cAAc;CACL,CAAC;AAIX,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAAC,GAAG,wBAAwB,EAAE,6BAA6B,CAAU,CAAC;AAExG,MAAM,sBAAsB,GAAqD,IAAI,GAAG,CAAC;IACxF,WAAW;IACX,gBAAgB;IAChB,aAAa;IACb,cAAc;CACd,CAAC,CAAC;AAEH,iFAAiF;AACjF,MAAM,UAAU,sBAAsB;IACrC,mFAAmF;IACnF,kFAAkF;IAClF,OAAO,IAAI,CAAC,MAAM,CACjB;QACC,SAAS,EAAE,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC;QACvC,cAAc,EAAE,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC;QAC5C,UAAU,EAAE,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC;QACxC,WAAW,EAAE,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,MAAM,EA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C,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,KAAK,EAAmB,EAAE,CAAC,KAAK,KAAK,SAAS,CAAC,CAAC;QAC9G,IAAI,MAAM,CAAC,MAAM,GAAG,CAAC;YAAE,MAAM,CAAC,KAAK,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,GAAG,MAAM,CAAC,CAAC;IAC5D,CAAC;IACD,MAAM,iBAAiB,GAAG,MAAM,CAAC,2BAA2B,CAAC;IAC7D,IAAI,iBAAiB,KAAK,SAAS,EAAE,CAAC;QACrC,MAAM,CAAC,UAAU,GAAG,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,UAAU,IAAI,iBAAiB,EAAE,iBAAiB,CAAC,CAAC;IACzF,CAAC;IACD,OAAO,MAAM,CAAC;AACf,CAAC","sourcesContent":["import { Type } from \"typebox\";\nimport { isPlainRecord } from \"../util/value-guards.ts\";\nimport type { RiskBudget } from \"./contracts.ts\";\n\nexport const RISK_BUDGET_LIMIT_FIELDS = [\n\t\"maxTokens\",\n\t\"maxWallClockMs\",\n\t\"maxCostUsd\",\n\t\"maxAttempts\",\n\t\"maxToolCalls\",\n] as const;\n\nexport type RiskBudgetLimitField = (typeof RISK_BUDGET_LIMIT_FIELDS)[number];\n\nexport const RISK_BUDGET_FIELDS = [...RISK_BUDGET_LIMIT_FIELDS, \"requireApprovalAboveCostUsd\"] as const;\n\nconst DISCRETE_BUDGET_FIELDS: ReadonlySet<(typeof RISK_BUDGET_FIELDS)[number]> = new Set([\n\t\"maxTokens\",\n\t\"maxWallClockMs\",\n\t\"maxAttempts\",\n\t\"maxToolCalls\",\n]);\n\n/** One model-facing schema for every explicit worker/profile budget boundary. */\nexport function createRiskBudgetSchema() {\n\t// Shape belongs to the tool schema. Numeric range and integer invariants belong to\n\t// parseRiskBudget so every caller follows the same authoritative validation path.\n\treturn Type.Object(\n\t\t{\n\t\t\tmaxTokens: Type.Optional(Type.Number()),\n\t\t\tmaxWallClockMs: Type.Optional(Type.Number()),\n\t\t\tmaxCostUsd: Type.Optional(Type.Number()),\n\t\t\tmaxAttempts: Type.Optional(Type.Number()),\n\t\t\tmaxToolCalls: Type.Optional(Type.Number()),\n\t\t\trequireApprovalAboveCostUsd: Type.Optional(Type.Number()),\n\t\t},\n\t\t{ additionalProperties: false },\n\t);\n}\n\nfunction assertKnownRiskBudgetFields(budget: Record<string, unknown>, label: string): void {\n\tconst unknownField = Object.keys(budget).find(\n\t\t(field) => !RISK_BUDGET_FIELDS.includes(field as (typeof RISK_BUDGET_FIELDS)[number]),\n\t);\n\tif (unknownField) throw new TypeError(`${label} contains an unsupported field.`);\n}\n\n/** Parse raw durable budget input without cloning untrusted values. */\nexport function parseRiskBudget(value: unknown, label: string): RiskBudget {\n\tif (!isPlainRecord(value)) throw new TypeError(`${label} must be an object.`);\n\tassertKnownRiskBudgetFields(value, label);\n\tconst budget: RiskBudget = {};\n\tfor (const field of RISK_BUDGET_FIELDS) {\n\t\tconst candidate = value[field];\n\t\tif (candidate === undefined) continue;\n\t\tif (typeof candidate !== \"number\") throw new TypeError(`${label}.${field} must be a number.`);\n\t\tbudget[field] = candidate;\n\t}\n\tvalidateRiskBudget(budget, label);\n\treturn budget;\n}\n\nexport function validateRiskBudget(budget: RiskBudget, label: string): void {\n\tif (!isPlainRecord(budget)) throw new TypeError(`${label} must be an object.`);\n\tassertKnownRiskBudgetFields(budget, label);\n\tfor (const field of RISK_BUDGET_FIELDS) {\n\t\tconst value = (budget as RiskBudget)[field];\n\t\tif (value === undefined) continue;\n\t\tif (!Number.isFinite(value) || value < 0) throw new TypeError(`${label}.${field} must be non-negative.`);\n\t\tif (DISCRETE_BUDGET_FIELDS.has(field) && !Number.isSafeInteger(value)) {\n\t\t\tthrow new TypeError(`${label}.${field} must be a non-negative safe integer.`);\n\t\t}\n\t}\n}\n\nexport function exceededRiskBudgetFields(requested: RiskBudget, authority: RiskBudget): RiskBudgetLimitField[] {\n\treturn RISK_BUDGET_LIMIT_FIELDS.filter((field) => {\n\t\tconst request = requested[field];\n\t\tconst ceiling = authority[field];\n\t\treturn request !== undefined && ceiling !== undefined && request > ceiling;\n\t});\n}\n\n/** Intersects independent ceilings. Undefined fields do not constrain the result. */\nexport function intersectRiskBudgets(...budgets: readonly RiskBudget[]): RiskBudget {\n\tconst result: RiskBudget = {};\n\tfor (const field of RISK_BUDGET_FIELDS) {\n\t\tconst values = budgets.map((budget) => budget[field]).filter((value): value is number => value !== undefined);\n\t\tif (values.length > 0) result[field] = Math.min(...values);\n\t}\n\tconst approvalThreshold = result.requireApprovalAboveCostUsd;\n\tif (approvalThreshold !== undefined) {\n\t\tresult.maxCostUsd = Math.min(result.maxCostUsd ?? approvalThreshold, approvalThreshold);\n\t}\n\treturn result;\n}\n"]}
|
|
@@ -17,6 +17,7 @@ export declare function assertAttemptFinishTransition(state: TaskRuntimeProjecti
|
|
|
17
17
|
export declare function assertAttemptGrantTransition(state: TaskRuntimeProjection, aggregateId: string, attemptId: string, grant: ExecutionGrant): AttemptRuntimeState;
|
|
18
18
|
export declare function assertAttemptLeaseTransition(state: TaskRuntimeProjection, aggregateId: string, lease: AttemptLease, agentId: string | undefined, occurredAt: string): AttemptRuntimeState;
|
|
19
19
|
export declare function assertAttemptStartTransition(state: TaskRuntimeProjection, aggregateId: string, attemptId: string, leaseId: string, fencingToken: number, occurredAt: string): AttemptRuntimeState;
|
|
20
|
+
export declare function assertAttemptLeaseRenewalTransition(state: TaskRuntimeProjection, aggregateId: string, attemptId: string, leaseId: string, fencingToken: number, expiresAt: string, occurredAt: string): AttemptRuntimeState;
|
|
20
21
|
export declare function assertAttemptCheckpointTransition(state: TaskRuntimeProjection, aggregateId: string, checkpoint: AttemptCheckpoint, leaseId: string, occurredAt: string): AttemptRuntimeState;
|
|
21
22
|
export declare function assertApprovalRequestTransition(state: TaskRuntimeProjection, aggregateId: string, approval: ApprovalRequestContract): void;
|
|
22
23
|
export declare function assertApprovalResolutionTransition(state: TaskRuntimeProjection, aggregateId: string, resolution: ApprovalResolutionContract): ApprovalRuntimeState;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"task-runtime-reducer.d.ts","sourceRoot":"","sources":["../../../src/core/orchestration/task-runtime-reducer.ts"],"names":[],"mappings":"AAEA,OAAO,EACN,KAAK,oBAAoB,EACzB,KAAK,uBAAuB,EAC5B,KAAK,0BAA0B,EAC/B,KAAK,iBAAiB,EACtB,KAAK,YAAY,EAGjB,KAAK,cAAc,EAQnB,KAAK,iBAAiB,EACtB,KAAK,eAAe,EAEpB,KAAK,kBAAkB,EAIvB,KAAK,oBAAoB,EACzB,MAAM,gBAAgB,CAAC;AA8BxB,OAAO,EACN,KAAK,oBAAoB,EACzB,KAAK,wBAAwB,EAC7B,KAAK,mBAAmB,EAKxB,KAAK,qBAAqB,EAC1B,KAAK,gBAAgB,EAErB,MAAM,yBAAyB,CAAC;AAuDjC,MAAM,MAAM,yBAAyB,GAAG,eAAe,GAAG,gBAAgB,GAAG,gBAAgB,CAAC;AA0C9F,wBAAgB,+BAA+B,CAC9C,KAAK,EAAE,qBAAqB,EAC5B,WAAW,EAAE,MAAM,EACnB,MAAM,EAAE,eAAe,EACvB,gBAAgB,CAAC,EAAE,yBAAyB,GAC1C,IAAI,CAiBN;AAsBD,oFAAoF;AACpF,wBAAgB,6BAA6B,CAAC,KAAK,EAAE,qBAAqB,EAAE,OAAO,EAAE,MAAM,GAAG,oBAAoB,CA8BjH;AAED,wBAAgB,qBAAqB,CAAC,KAAK,EAAE,oBAAoB,EAAE,UAAU,EAAE,MAAM,GAAG,IAAI,CAI3F;AAoGD,wBAAgB,wBAAwB,CACvC,KAAK,EAAE,qBAAqB,EAC5B,OAAO,EAAE,mBAAmB,GAC1B,wBAAwB,CAgD1B;AA0BD,wBAAgB,iBAAiB,CAChC,KAAK,EAAE,qBAAqB,EAC5B,IAAI,EAAE,gBAAgB,GACpB,mBAAmB,GAAG,SAAS,CAMjC;AAED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B,EAC5B,WAAW,EAAE,MAAM,EACnB,QAAQ,EAAE,uBAAuB,GAC/B,IAAI,CAsCN;AAED,wBAAgB,kCAAkC,CACjD,KAAK,EAAE,qBAAqB,EAC5B,WAAW,EAAE,MAAM,EACnB,UAAU,EAAE,0BAA0B,GACpC,oBAAoB,CAWtB;AAED,wBAAgB,wBAAwB,CACvC,KAAK,EAAE,qBAAqB,EAC5B,WAAW,EAAE,MAAM,EACnB,SAAS,EAAE,MAAM,GAAG,SAAS,GAC3B,IAAI,CAQN;AAED,MAAM,WAAW,2BAA2B;IAC3C,MAAM,EAAE,MAAM,CAAC;IACf,cAAc,EAAE,MAAM,CAAC;IACvB,iBAAiB,EAAE,MAAM,CAAC;IAC1B,OAAO,EAAE,UAAU,GAAG,UAAU,GAAG,cAAc,CAAC;IAClD,UAAU,EAAE,MAAM,CAAC;CACnB;AAED,wBAAgB,2BAA2B,CAC1C,KAAK,EAAE,qBAAqB,EAC5B,WAAW,EAAE,MAAM,EACnB,MAAM,EAAE,MAAM,EACd,UAAU,EAAE,MAAM,GAChB,gBAAgB,CAclB;AAED,wBAAgB,4BAA4B,CAC3C,KAAK,EAAE,qBAAqB,EAC5B,WAAW,EAAE,MAAM,EACnB,IAAI,EAAE,2BAA2B,GAC/B;IAAE,OAAO,EAAE,gBAAgB,CAAC;IAAC,eAAe,EAAE,mBAAmB,CAAA;CAAE,CA4CrE;AAwDD,wBAAgB,wBAAwB,CACvC,UAAU,EAAE,qBAAqB,EACjC,KAAK,EAAE,kBAAkB,GACvB,qBAAqB,
|
|
1
|
+
{"version":3,"file":"task-runtime-reducer.d.ts","sourceRoot":"","sources":["../../../src/core/orchestration/task-runtime-reducer.ts"],"names":[],"mappings":"AAEA,OAAO,EACN,KAAK,oBAAoB,EACzB,KAAK,uBAAuB,EAC5B,KAAK,0BAA0B,EAC/B,KAAK,iBAAiB,EACtB,KAAK,YAAY,EAGjB,KAAK,cAAc,EAQnB,KAAK,iBAAiB,EACtB,KAAK,eAAe,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M,EACnB,UAAU,EAAE,0BAA0B,GACpC,oBAAoB,CAWtB;AAED,wBAAgB,wBAAwB,CACvC,KAAK,EAAE,qBAAqB,EAC5B,WAAW,EAAE,MAAM,EACnB,SAAS,EAAE,MAAM,GAAG,SAAS,GAC3B,IAAI,CAQN;AAED,MAAM,WAAW,2BAA2B;IAC3C,MAAM,EAAE,MAAM,CAAC;IACf,cAAc,EAAE,MAAM,CAAC;IACvB,iBAAiB,EAAE,MAAM,CAAC;IAC1B,OAAO,EAAE,UAAU,GAAG,UAAU,GAAG,cAAc,CAAC;IAClD,UAAU,EAAE,MAAM,CAAC;CACnB;AAED,wBAAgB,2BAA2B,CAC1C,KAAK,EAAE,qBAAqB,EAC5B,WAAW,EAAE,MAAM,EACnB,MAAM,EAAE,MAAM,EACd,UAAU,EAAE,MAAM,GAChB,gBAAgB,CAclB;AAED,wBAAgB,4BAA4B,CAC3C,KAAK,EAAE,qBAAqB,EAC5B,WAAW,EAAE,MAAM,EACnB,IAAI,EAAE,2BAA2B,GAC/B;IAAE,OAAO,EAAE,gBAAgB,CAAC;IAAC,eAAe,EAAE,mBAAmB,CAAA;CAAE,CA4CrE;AAwDD,wBAAgB,wBAAwB,CACvC,UAAU,EAAE,qBAAqB,EACjC,KAAK,EAAE,kBAAkB,GACvB,qBAAqB,CAokBvB;AAED,wBAAgB,0BAA0B,CAAC,MAAM,EAAE,SAAS,kBAAkB,EAAE,GAAG,qBAAqB,CAEvG"}
|
|
@@ -543,6 +543,27 @@ export function assertAttemptStartTransition(state, aggregateId, attemptId, leas
|
|
|
543
543
|
requireActiveObjectiveForAttemptInProjection(state, attempt);
|
|
544
544
|
return attempt;
|
|
545
545
|
}
|
|
546
|
+
export function assertAttemptLeaseRenewalTransition(state, aggregateId, attemptId, leaseId, fencingToken, expiresAt, occurredAt) {
|
|
547
|
+
if (aggregateId !== attemptId) {
|
|
548
|
+
throw new DurableTaskRuntimeError(`Renewed attempt '${attemptId}' does not match its aggregate.`);
|
|
549
|
+
}
|
|
550
|
+
const attempt = state.attempts[attemptId];
|
|
551
|
+
if (!attempt)
|
|
552
|
+
throw new DurableTaskRuntimeError(`Unknown attempt '${attemptId}'.`);
|
|
553
|
+
if (attempt.status !== "leased" && attempt.status !== "running") {
|
|
554
|
+
throw new DurableTaskRuntimeError(`Attempt '${attemptId}' cannot renew from '${attempt.status}'.`);
|
|
555
|
+
}
|
|
556
|
+
if (!attempt.lease || attempt.lease.leaseId !== leaseId || attempt.lease.fencingToken !== fencingToken) {
|
|
557
|
+
throw new DurableTaskRuntimeError(`Attempt '${attemptId}' lease or fencing token is stale.`);
|
|
558
|
+
}
|
|
559
|
+
assertLeaseLiveAt(attempt.lease, occurredAt, `Attempt '${attemptId}'`);
|
|
560
|
+
const expiresAtMs = Date.parse(expiresAt);
|
|
561
|
+
if (!Number.isFinite(expiresAtMs) || expiresAtMs <= Date.parse(attempt.lease.expiresAt)) {
|
|
562
|
+
throw new DurableTaskRuntimeError(`Attempt '${attemptId}' renewed lease must extend its expiration.`);
|
|
563
|
+
}
|
|
564
|
+
requireActiveObjectiveForAttemptInProjection(state, attempt);
|
|
565
|
+
return attempt;
|
|
566
|
+
}
|
|
546
567
|
export function assertAttemptCheckpointTransition(state, aggregateId, checkpoint, leaseId, occurredAt) {
|
|
547
568
|
if (aggregateId !== checkpoint.attemptId) {
|
|
548
569
|
throw new DurableTaskRuntimeError(`Checkpointed attempt '${checkpoint.attemptId}' does not match its aggregate.`);
|
|
@@ -1022,6 +1043,19 @@ export function reduceOrchestrationEvent(projection, event) {
|
|
|
1022
1043
|
attempts[attemptId] = { ...attempt, status: "running", updatedAt: event.occurredAt };
|
|
1023
1044
|
break;
|
|
1024
1045
|
}
|
|
1046
|
+
case "attempt.lease_renewed": {
|
|
1047
|
+
const attemptId = string(event.payload.attemptId, "attempt.lease_renewed.attemptId");
|
|
1048
|
+
const leaseId = string(event.payload.leaseId, "attempt.lease_renewed.leaseId");
|
|
1049
|
+
const fencingToken = number(event.payload.fencingToken, "attempt.lease_renewed.fencingToken");
|
|
1050
|
+
const expiresAt = string(event.payload.expiresAt, "attempt.lease_renewed.expiresAt");
|
|
1051
|
+
const attempt = assertAttemptLeaseRenewalTransition(state, event.aggregateId, attemptId, leaseId, fencingToken, expiresAt, event.occurredAt);
|
|
1052
|
+
attempts[attemptId] = {
|
|
1053
|
+
...attempt,
|
|
1054
|
+
lease: { ...attempt.lease, expiresAt },
|
|
1055
|
+
updatedAt: event.occurredAt,
|
|
1056
|
+
};
|
|
1057
|
+
break;
|
|
1058
|
+
}
|
|
1025
1059
|
case "attempt.checkpointed": {
|
|
1026
1060
|
const checkpoint = checkpointFromPayload(event.payload);
|
|
1027
1061
|
const leaseId = string(event.payload.leaseId, "attempt.checkpointed.leaseId");
|