@caupulican/pi-adaptative 0.90.4 → 0.90.6
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 +12 -0
- package/dist/core/autonomy/lane-tracker.d.ts +5 -0
- package/dist/core/autonomy/lane-tracker.d.ts.map +1 -1
- package/dist/core/autonomy/lane-tracker.js +8 -0
- package/dist/core/autonomy/lane-tracker.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 +23 -3
- package/dist/core/delegation/worker-authority-resolver.js.map +1 -1
- package/dist/core/delegation/worker-delegation-controller.d.ts +1 -1
- package/dist/core/delegation/worker-delegation-controller.d.ts.map +1 -1
- package/dist/core/delegation/worker-delegation-controller.js +48 -13
- package/dist/core/delegation/worker-delegation-controller.js.map +1 -1
- package/dist/core/delegation/worker-lane-projection.d.ts.map +1 -1
- package/dist/core/delegation/worker-lane-projection.js +6 -0
- package/dist/core/delegation/worker-lane-projection.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/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-tool-text.d.ts.map +1 -1
- package/dist/core/provider-tool-text.js +29 -13
- package/dist/core/provider-tool-text.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 +4 -1
- package/dist/core/settings-manager.d.ts.map +1 -1
- package/dist/core/settings-manager.js +24 -0
- package/dist/core/settings-manager.js.map +1 -1
- package/dist/core/tools/delegate-status.d.ts +2 -0
- package/dist/core/tools/delegate-status.d.ts.map +1 -1
- package/dist/core/tools/delegate-status.js +7 -0
- package/dist/core/tools/delegate-status.js.map +1 -1
- package/dist/core/tools/delegate.d.ts +6 -0
- package/dist/core/tools/delegate.d.ts.map +1 -1
- package/dist/core/tools/delegate.js +38 -6
- package/dist/core/tools/delegate.js.map +1 -1
- package/docs/settings.md +31 -0
- 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 +1 @@
|
|
|
1
|
-
{"version":3,"file":"worker-lane-projection.d.ts","sourceRoot":"","sources":["../../../src/core/delegation/worker-lane-projection.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAsB,MAAM,6BAA6B,CAAC;AAClF,OAAO,KAAK,EAAE,mBAAmB,EAAE,qBAAqB,EAAE,MAAM,kCAAkC,CAAC;AAGnG,eAAO,MAAM,8BAA8B,EAAE,WAAW,CAAC,MAAM,CAA4C,CAAC;AAC5G,eAAO,MAAM,mCAAmC,EAAE,WAAW,CAAC,MAAM,CAGlE,CAAC;AAEH,wBAAgB,sBAAsB,CAAC,OAAO,EAAE,mBAAmB,GAAG,OAAO,CAE5E;AAaD,wBAAgB,qBAAqB,CACpC,QAAQ,EAAE,qBAAqB,EAC/B,MAAM,EAAE,MAAM,GACZ,mBAAmB,GAAG,SAAS,CAQjC;AAED;;;GAGG;AACH,wBAAgB,uBAAuB,CAAC,QAAQ,EAAE,qBAAqB,EAAE,MAAM,EAAE,MAAM,GAAG,UAAU,GAAG,SAAS,
|
|
1
|
+
{"version":3,"file":"worker-lane-projection.d.ts","sourceRoot":"","sources":["../../../src/core/delegation/worker-lane-projection.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAsB,MAAM,6BAA6B,CAAC;AAClF,OAAO,KAAK,EAAE,mBAAmB,EAAE,qBAAqB,EAAE,MAAM,kCAAkC,CAAC;AAGnG,eAAO,MAAM,8BAA8B,EAAE,WAAW,CAAC,MAAM,CAA4C,CAAC;AAC5G,eAAO,MAAM,mCAAmC,EAAE,WAAW,CAAC,MAAM,CAGlE,CAAC;AAEH,wBAAgB,sBAAsB,CAAC,OAAO,EAAE,mBAAmB,GAAG,OAAO,CAE5E;AAaD,wBAAgB,qBAAqB,CACpC,QAAQ,EAAE,qBAAqB,EAC/B,MAAM,EAAE,MAAM,GACZ,mBAAmB,GAAG,SAAS,CAQjC;AAED;;;GAGG;AACH,wBAAgB,uBAAuB,CAAC,QAAQ,EAAE,qBAAqB,EAAE,MAAM,EAAE,MAAM,GAAG,UAAU,GAAG,SAAS,CAiD/G;AAED,oEAAoE;AACpE,wBAAgB,+BAA+B,CAAC,QAAQ,EAAE,qBAAqB,GAAG,UAAU,EAAE,CAkB7F;AAED,wBAAgB,4BAA4B,CAC3C,QAAQ,EAAE,qBAAqB,EAC/B,aAAa,EAAE,MAAM,GACnB,mBAAmB,GAAG,SAAS,CAQjC"}
|
|
@@ -66,6 +66,12 @@ export function projectWorkerLaneRecord(snapshot, taskId) {
|
|
|
66
66
|
status,
|
|
67
67
|
label,
|
|
68
68
|
profileId: attempt.dispatch.profileId,
|
|
69
|
+
...(attempt.dispatch.executionContract
|
|
70
|
+
? {
|
|
71
|
+
modelRef: `${attempt.dispatch.executionContract.worker.modelBinding.provider}/${attempt.dispatch.executionContract.worker.modelBinding.modelId}`,
|
|
72
|
+
thinkingLevel: attempt.dispatch.executionContract.worker.modelBinding.thinkingLevel,
|
|
73
|
+
}
|
|
74
|
+
: {}),
|
|
69
75
|
...(reasonCode ? { reasonCode } : {}),
|
|
70
76
|
...(attempt.status !== "queued" ? { startedAt: attempt.createdAt } : {}),
|
|
71
77
|
...(status === "queued" || status === "running"
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"worker-lane-projection.js","sourceRoot":"","sources":["../../../src/core/delegation/worker-lane-projection.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,qBAAqB,EAAE,MAAM,wBAAwB,CAAC;AAE/D,MAAM,CAAC,MAAM,8BAA8B,GAAwB,IAAI,GAAG,CAAC,CAAC,QAAQ,EAAE,QAAQ,EAAE,SAAS,CAAC,CAAC,CAAC;AAC5G,MAAM,CAAC,MAAM,mCAAmC,GAAwB,IAAI,GAAG,CAAC;IAC/E,GAAG,8BAA8B;IACjC,WAAW;CACX,CAAC,CAAC;AAEH,MAAM,UAAU,sBAAsB,CAAC,OAA4B;IAClE,OAAO,OAAO,CAAC,QAAQ,CAAC,aAAa,KAAK,iBAAiB,CAAC;AAC7D,CAAC;AAED,SAAS,cAAc,CAAC,OAA4B;IACnD,IAAI,OAAO,CAAC,MAAM,KAAK,WAAW;QAAE,OAAO,WAAW,CAAC;IACvD,IAAI,OAAO,CAAC,MAAM,KAAK,WAAW;QAAE,OAAO,UAAU,CAAC;IACtD,IAAI,OAAO,CAAC,MAAM,EAAE,MAAM,KAAK,SAAS;QAAE,OAAO,SAAS,CAAC;IAC3D,IAAI,OAAO,CAAC,MAAM,EAAE,MAAM,KAAK,SAAS;QAAE,OAAO,SAAS,CAAC;IAC3D,MAAM,UAAU,GAAG,OAAO,CAAC,MAAM,EAAE,UAAU,IAAI,OAAO,CAAC,UAAU,IAAI,EAAE,CAAC;IAC1E,IAAI,UAAU,CAAC,QAAQ,CAAC,QAAQ,CAAC;QAAE,OAAO,kBAAkB,CAAC;IAC7D,IAAI,UAAU,CAAC,QAAQ,CAAC,SAAS,CAAC;QAAE,OAAO,SAAS,CAAC;IACrD,OAAO,QAAQ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AO,QAAQ,KAAK,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,aAAa,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC;IAClF,CAAC,CAAC;SACD,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC;AACV,CAAC","sourcesContent":["import type { LaneRecord, LaneTerminalStatus } from \"../autonomy/lane-tracker.ts\";\nimport type { AttemptRuntimeState, TaskRuntimeProjection } from \"../orchestration/task-runtime.ts\";\nimport { deriveWorkerTaskLabel } from \"./worker-task-label.ts\";\n\nexport const ACTIVE_WORKER_ATTEMPT_STATUSES: ReadonlySet<string> = new Set([\"queued\", \"leased\", \"running\"]);\nexport const NONTERMINAL_WORKER_ATTEMPT_STATUSES: ReadonlySet<string> = new Set([\n\t...ACTIVE_WORKER_ATTEMPT_STATUSES,\n\t\"suspended\",\n]);\n\nexport function isManagedWorkerAttempt(attempt: AttemptRuntimeState): boolean {\n\treturn attempt.dispatch.executionKind === \"managed-process\";\n}\n\nfunction terminalStatus(attempt: AttemptRuntimeState): LaneTerminalStatus {\n\tif (attempt.status === \"completed\") return \"succeeded\";\n\tif (attempt.status === \"cancelled\") return \"canceled\";\n\tif (attempt.result?.status === \"partial\") return \"partial\";\n\tif (attempt.result?.status === \"blocked\") return \"blocked\";\n\tconst reasonCode = attempt.result?.reasonCode ?? attempt.reasonCode ?? \"\";\n\tif (reasonCode.includes(\"budget\")) return \"budget_exhausted\";\n\tif (reasonCode.includes(\"timeout\")) return \"timeout\";\n\treturn \"failed\";\n}\n\nexport function selectedWorkerAttempt(\n\tsnapshot: TaskRuntimeProjection,\n\ttaskId: string,\n): AttemptRuntimeState | undefined {\n\tconst task = snapshot.tasks[taskId];\n\tif (!task) return undefined;\n\tconst attempts = task.attemptIds.map((attemptId) => snapshot.attempts[attemptId]).filter(Boolean);\n\treturn (\n\t\t[...attempts].reverse().find((attempt) => attempt && NONTERMINAL_WORKER_ATTEMPT_STATUSES.has(attempt.status)) ??\n\t\tattempts.at(-1)\n\t);\n}\n\n/**\n * One-way compatibility projection from durable orchestration state. A LaneRecord is never read\n * back to decide lifecycle, retry, verification, or notification transitions.\n */\nexport function projectWorkerLaneRecord(snapshot: TaskRuntimeProjection, taskId: string): LaneRecord | undefined {\n\tconst task = snapshot.tasks[taskId];\n\tconst attempt = selectedWorkerAttempt(snapshot, taskId);\n\tif (!task || !attempt) return undefined;\n\tconst managed = isManagedWorkerAttempt(attempt);\n\tconst objective = snapshot.objectives[task.task.objectiveId];\n\tconst awaitingVerification =\n\t\tattempt.result?.nextAction === \"independent_verification_required\" && task.verification === undefined;\n\tconst status = awaitingVerification\n\t\t? \"running\"\n\t\t: task.verification\n\t\t\t? task.verification.verdict === \"accepted\"\n\t\t\t\t? \"succeeded\"\n\t\t\t\t: \"failed\"\n\t\t\t: attempt.status === \"queued\"\n\t\t\t\t? \"queued\"\n\t\t\t\t: attempt.status === \"leased\" || attempt.status === \"running\" || attempt.status === \"suspended\"\n\t\t\t\t\t? \"running\"\n\t\t\t\t\t: terminalStatus(attempt);\n\tconst reasonCode = task.verification?.reasonCode ?? attempt.result?.reasonCode ?? attempt.reasonCode;\n\tconst genericTitle = `Delegated ${task.task.role} work`;\n\tconst label = deriveWorkerTaskLabel(\n\t\ttask.task.title === genericTitle ? task.task.description : task.task.title,\n\t\tgenericTitle,\n\t);\n\tconst goalId = objective?.objective.objectiveId.startsWith(\"goal:\")\n\t\t? objective.objective.objectiveId.slice(\"goal:\".length)\n\t\t: undefined;\n\treturn {\n\t\tlaneId: managed ? (attempt.dispatch.logicalLaneId ?? taskId) : taskId,\n\t\ttype: managed ? \"tmux-worker\" : \"worker\",\n\t\tstatus,\n\t\tlabel,\n\t\tprofileId: attempt.dispatch.profileId,\n\t\t...(reasonCode ? { reasonCode } : {}),\n\t\t...(attempt.status !== \"queued\" ? { startedAt: attempt.createdAt } : {}),\n\t\t...(status === \"queued\" || status === \"running\"\n\t\t\t? {}\n\t\t\t: { completedAt: task.verification?.completedAt ?? attempt.updatedAt }),\n\t\t...(attempt.result?.usage.costUsd !== undefined ? { costUsd: attempt.result.usage.costUsd } : {}),\n\t\t...(goalId ? { goalId } : {}),\n\t\t...(attempt.dispatch.worktreeLaneKey ? { worktreeLaneKey: attempt.dispatch.worktreeLaneKey } : {}),\n\t};\n}\n\n/** Latest durable turn for each externally managed logical lane. */\nexport function projectManagedWorkerLaneRecords(snapshot: TaskRuntimeProjection): LaneRecord[] {\n\tconst latest = new Map<string, { sequence: number; createdAt: string; record: LaneRecord }>();\n\tfor (const taskId of Object.keys(snapshot.tasks)) {\n\t\tconst attempt = selectedWorkerAttempt(snapshot, taskId);\n\t\tif (!attempt || !isManagedWorkerAttempt(attempt)) continue;\n\t\tconst record = projectWorkerLaneRecord(snapshot, taskId);\n\t\tif (!record) continue;\n\t\tconst sequence = attempt.dispatch.dispatchSequence ?? 1;\n\t\tconst current = latest.get(record.laneId);\n\t\tif (\n\t\t\t!current ||\n\t\t\tsequence > current.sequence ||\n\t\t\t(sequence === current.sequence && attempt.createdAt.localeCompare(current.createdAt) > 0)\n\t\t) {\n\t\t\tlatest.set(record.laneId, { sequence, createdAt: attempt.createdAt, record });\n\t\t}\n\t}\n\treturn [...latest.values()].map((entry) => entry.record);\n}\n\nexport function selectedManagedWorkerAttempt(\n\tsnapshot: TaskRuntimeProjection,\n\tlogicalLaneId: string,\n): AttemptRuntimeState | undefined {\n\treturn Object.values(snapshot.attempts)\n\t\t.filter((attempt) => isManagedWorkerAttempt(attempt) && attempt.dispatch.logicalLaneId === logicalLaneId)\n\t\t.sort((left, right) => {\n\t\t\tconst sequence = (left.dispatch.dispatchSequence ?? 1) - (right.dispatch.dispatchSequence ?? 1);\n\t\t\treturn sequence !== 0 ? sequence : left.createdAt.localeCompare(right.createdAt);\n\t\t})\n\t\t.at(-1);\n}\n"]}
|
|
1
|
+
{"version":3,"file":"worker-lane-projection.js","sourceRoot":"","sources":["../../../src/core/delegation/worker-lane-projection.ts"],"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AAC,IAAI,CAAC,QAAQ,CAAC,gBAAgB,IAAI,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,QAAQ,CAAC,gBAAgB,IAAI,CAAC,CAAC,CAAC;QAChG,OAAO,QAAQ,KAAK,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,aAAa,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC;IAClF,CAAC,CAAC;SACD,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC;AACV,CAAC","sourcesContent":["import type { LaneRecord, LaneTerminalStatus } from \"../autonomy/lane-tracker.ts\";\nimport type { AttemptRuntimeState, TaskRuntimeProjection } from \"../orchestration/task-runtime.ts\";\nimport { deriveWorkerTaskLabel } from \"./worker-task-label.ts\";\n\nexport const ACTIVE_WORKER_ATTEMPT_STATUSES: ReadonlySet<string> = new Set([\"queued\", \"leased\", \"running\"]);\nexport const NONTERMINAL_WORKER_ATTEMPT_STATUSES: ReadonlySet<string> = new Set([\n\t...ACTIVE_WORKER_ATTEMPT_STATUSES,\n\t\"suspended\",\n]);\n\nexport function isManagedWorkerAttempt(attempt: AttemptRuntimeState): boolean {\n\treturn attempt.dispatch.executionKind === \"managed-process\";\n}\n\nfunction terminalStatus(attempt: AttemptRuntimeState): LaneTerminalStatus {\n\tif (attempt.status === \"completed\") return \"succeeded\";\n\tif (attempt.status === \"cancelled\") return \"canceled\";\n\tif (attempt.result?.status === \"partial\") return \"partial\";\n\tif (attempt.result?.status === \"blocked\") return \"blocked\";\n\tconst reasonCode = attempt.result?.reasonCode ?? attempt.reasonCode ?? \"\";\n\tif (reasonCode.includes(\"budget\")) return \"budget_exhausted\";\n\tif (reasonCode.includes(\"timeout\")) return \"timeout\";\n\treturn \"failed\";\n}\n\nexport function selectedWorkerAttempt(\n\tsnapshot: TaskRuntimeProjection,\n\ttaskId: string,\n): AttemptRuntimeState | undefined {\n\tconst task = snapshot.tasks[taskId];\n\tif (!task) return undefined;\n\tconst attempts = task.attemptIds.map((attemptId) => snapshot.attempts[attemptId]).filter(Boolean);\n\treturn (\n\t\t[...attempts].reverse().find((attempt) => attempt && NONTERMINAL_WORKER_ATTEMPT_STATUSES.has(attempt.status)) ??\n\t\tattempts.at(-1)\n\t);\n}\n\n/**\n * One-way compatibility projection from durable orchestration state. A LaneRecord is never read\n * back to decide lifecycle, retry, verification, or notification transitions.\n */\nexport function projectWorkerLaneRecord(snapshot: TaskRuntimeProjection, taskId: string): LaneRecord | undefined {\n\tconst task = snapshot.tasks[taskId];\n\tconst attempt = selectedWorkerAttempt(snapshot, taskId);\n\tif (!task || !attempt) return undefined;\n\tconst managed = isManagedWorkerAttempt(attempt);\n\tconst objective = snapshot.objectives[task.task.objectiveId];\n\tconst awaitingVerification =\n\t\tattempt.result?.nextAction === \"independent_verification_required\" && task.verification === undefined;\n\tconst status = awaitingVerification\n\t\t? \"running\"\n\t\t: task.verification\n\t\t\t? task.verification.verdict === \"accepted\"\n\t\t\t\t? \"succeeded\"\n\t\t\t\t: \"failed\"\n\t\t\t: attempt.status === \"queued\"\n\t\t\t\t? \"queued\"\n\t\t\t\t: attempt.status === \"leased\" || attempt.status === \"running\" || attempt.status === \"suspended\"\n\t\t\t\t\t? \"running\"\n\t\t\t\t\t: terminalStatus(attempt);\n\tconst reasonCode = task.verification?.reasonCode ?? attempt.result?.reasonCode ?? attempt.reasonCode;\n\tconst genericTitle = `Delegated ${task.task.role} work`;\n\tconst label = deriveWorkerTaskLabel(\n\t\ttask.task.title === genericTitle ? task.task.description : task.task.title,\n\t\tgenericTitle,\n\t);\n\tconst goalId = objective?.objective.objectiveId.startsWith(\"goal:\")\n\t\t? objective.objective.objectiveId.slice(\"goal:\".length)\n\t\t: undefined;\n\treturn {\n\t\tlaneId: managed ? (attempt.dispatch.logicalLaneId ?? taskId) : taskId,\n\t\ttype: managed ? \"tmux-worker\" : \"worker\",\n\t\tstatus,\n\t\tlabel,\n\t\tprofileId: attempt.dispatch.profileId,\n\t\t...(attempt.dispatch.executionContract\n\t\t\t? {\n\t\t\t\t\tmodelRef: `${attempt.dispatch.executionContract.worker.modelBinding.provider}/${attempt.dispatch.executionContract.worker.modelBinding.modelId}`,\n\t\t\t\t\tthinkingLevel: attempt.dispatch.executionContract.worker.modelBinding.thinkingLevel,\n\t\t\t\t}\n\t\t\t: {}),\n\t\t...(reasonCode ? { reasonCode } : {}),\n\t\t...(attempt.status !== \"queued\" ? { startedAt: attempt.createdAt } : {}),\n\t\t...(status === \"queued\" || status === \"running\"\n\t\t\t? {}\n\t\t\t: { completedAt: task.verification?.completedAt ?? attempt.updatedAt }),\n\t\t...(attempt.result?.usage.costUsd !== undefined ? { costUsd: attempt.result.usage.costUsd } : {}),\n\t\t...(goalId ? { goalId } : {}),\n\t\t...(attempt.dispatch.worktreeLaneKey ? { worktreeLaneKey: attempt.dispatch.worktreeLaneKey } : {}),\n\t};\n}\n\n/** Latest durable turn for each externally managed logical lane. */\nexport function projectManagedWorkerLaneRecords(snapshot: TaskRuntimeProjection): LaneRecord[] {\n\tconst latest = new Map<string, { sequence: number; createdAt: string; record: LaneRecord }>();\n\tfor (const taskId of Object.keys(snapshot.tasks)) {\n\t\tconst attempt = selectedWorkerAttempt(snapshot, taskId);\n\t\tif (!attempt || !isManagedWorkerAttempt(attempt)) continue;\n\t\tconst record = projectWorkerLaneRecord(snapshot, taskId);\n\t\tif (!record) continue;\n\t\tconst sequence = attempt.dispatch.dispatchSequence ?? 1;\n\t\tconst current = latest.get(record.laneId);\n\t\tif (\n\t\t\t!current ||\n\t\t\tsequence > current.sequence ||\n\t\t\t(sequence === current.sequence && attempt.createdAt.localeCompare(current.createdAt) > 0)\n\t\t) {\n\t\t\tlatest.set(record.laneId, { sequence, createdAt: attempt.createdAt, record });\n\t\t}\n\t}\n\treturn [...latest.values()].map((entry) => entry.record);\n}\n\nexport function selectedManagedWorkerAttempt(\n\tsnapshot: TaskRuntimeProjection,\n\tlogicalLaneId: string,\n): AttemptRuntimeState | undefined {\n\treturn Object.values(snapshot.attempts)\n\t\t.filter((attempt) => isManagedWorkerAttempt(attempt) && attempt.dispatch.logicalLaneId === logicalLaneId)\n\t\t.sort((left, right) => {\n\t\t\tconst sequence = (left.dispatch.dispatchSequence ?? 1) - (right.dispatch.dispatchSequence ?? 1);\n\t\t\treturn sequence !== 0 ? sequence : left.createdAt.localeCompare(right.createdAt);\n\t\t})\n\t\t.at(-1);\n}\n"]}
|
|
@@ -13,6 +13,12 @@ export interface ResolvedWorkerProfile {
|
|
|
13
13
|
resourcePointers: readonly ResourcePointer[];
|
|
14
14
|
soul?: string;
|
|
15
15
|
}
|
|
16
|
+
export interface ResolvedWorkerProfilePreset {
|
|
17
|
+
profile: OrchestrationProfile;
|
|
18
|
+
/** Metadata-only pointers admitted from the profile-linked resource configuration. */
|
|
19
|
+
resourcePointers: readonly ResourcePointer[];
|
|
20
|
+
soul?: string;
|
|
21
|
+
}
|
|
16
22
|
export interface WorkerProfileResolverOptions {
|
|
17
23
|
agentDir: string;
|
|
18
24
|
cwd: string;
|
|
@@ -39,6 +45,13 @@ export declare class WorkerProfileResolver {
|
|
|
39
45
|
ok: false;
|
|
40
46
|
reason: string;
|
|
41
47
|
};
|
|
48
|
+
resolvePreset(request: WorkerDelegationRequest, defaultProfileId: string | undefined): {
|
|
49
|
+
ok: true;
|
|
50
|
+
resolved: ResolvedWorkerProfilePreset;
|
|
51
|
+
} | {
|
|
52
|
+
ok: false;
|
|
53
|
+
reason: string;
|
|
54
|
+
};
|
|
42
55
|
resolveVerifier(workerProfile: OrchestrationProfile): {
|
|
43
56
|
ok: true;
|
|
44
57
|
resolved: ResolvedWorkerProfile;
|
|
@@ -46,6 +59,20 @@ export declare class WorkerProfileResolver {
|
|
|
46
59
|
ok: false;
|
|
47
60
|
reason: string;
|
|
48
61
|
};
|
|
62
|
+
resolveVerifierPreset(workerProfile: OrchestrationProfile): {
|
|
63
|
+
ok: true;
|
|
64
|
+
resolved: ResolvedWorkerProfilePreset;
|
|
65
|
+
} | {
|
|
66
|
+
ok: false;
|
|
67
|
+
reason: string;
|
|
68
|
+
};
|
|
69
|
+
bindPreset(preset: ResolvedWorkerProfilePreset, modelPin?: OrchestrationModelBinding): {
|
|
70
|
+
ok: true;
|
|
71
|
+
resolved: ResolvedWorkerProfile;
|
|
72
|
+
} | {
|
|
73
|
+
ok: false;
|
|
74
|
+
reason: string;
|
|
75
|
+
};
|
|
49
76
|
resolveContract(contract: WorkerProfileExecutionContract): {
|
|
50
77
|
ok: true;
|
|
51
78
|
resolved: ResolvedWorkerProfile;
|
|
@@ -53,7 +80,7 @@ export declare class WorkerProfileResolver {
|
|
|
53
80
|
ok: false;
|
|
54
81
|
reason: string;
|
|
55
82
|
};
|
|
56
|
-
private
|
|
83
|
+
private resolveProfilePresetId;
|
|
57
84
|
private loadProfiles;
|
|
58
85
|
}
|
|
59
86
|
//# sourceMappingURL=worker-profile-resolver.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"worker-profile-resolver.d.ts","sourceRoot":"","sources":["../../../src/core/delegation/worker-profile-resolver.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAC1D,OAAO,KAAK,EACX,yBAAyB,EACzB,oBAAoB,EACpB,eAAe,EACf,8BAA8B,EAC9B,MAAM,+BAA+B,CAAC;AAMvC,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,gDAAgD,CAAC;AAC9F,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAC9D,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,gCAAgC,CAAC;AAC9E,OAAO,EAAiC,KAAK,mCAAmC,EAAE,MAAM,8BAA8B,CAAC;AAEvH,MAAM,WAAW,qBAAqB;IACrC,KAAK,EAAE,KAAK,CAAC,GAAG,CAAC,CA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C;QAAC,MAAM,EAAE,MAAM,CAAA;KAAE,CA6B/E;IAED,eAAe,CACd,QAAQ,EAAE,8BAA8B,GACtC;QAAE,EAAE,EAAE,IAAI,CAAC;QAAC,QAAQ,EAAE,qBAAqB,CAAA;KAAE,GAAG;QAAE,EAAE,EAAE,KAAK,CAAC;QAAC,MAAM,EAAE,MAAM,CAAA;KAAE,CAmB/E;IAED,OAAO,CAAC,sBAAsB;IAiC9B,OAAO,CAAC,YAAY;CA4BpB"}
|
|
@@ -15,13 +15,17 @@ export class WorkerProfileResolver {
|
|
|
15
15
|
}));
|
|
16
16
|
}
|
|
17
17
|
resolve(request, defaultProfileId) {
|
|
18
|
+
const preset = this.resolvePreset(request, defaultProfileId);
|
|
19
|
+
return preset.ok ? this.bindPreset(preset.resolved) : preset;
|
|
20
|
+
}
|
|
21
|
+
resolvePreset(request, defaultProfileId) {
|
|
18
22
|
const requestedProfileId = request.profileId?.trim();
|
|
19
23
|
// Profiles are routing presets, not authority cages. Any loaded preset may be selected; the
|
|
20
24
|
// execution controller independently intersects its materialized plan with inherited authority.
|
|
21
25
|
const profileId = requestedProfileId || defaultProfileId;
|
|
22
26
|
if (!profileId)
|
|
23
27
|
return { ok: false, reason: "orchestration_profile_required" };
|
|
24
|
-
const selected = this.
|
|
28
|
+
const selected = this.resolveProfilePresetId(profileId);
|
|
25
29
|
if (!selected.ok)
|
|
26
30
|
return selected;
|
|
27
31
|
const profile = selected.resolved.profile;
|
|
@@ -34,10 +38,14 @@ export class WorkerProfileResolver {
|
|
|
34
38
|
return selected;
|
|
35
39
|
}
|
|
36
40
|
resolveVerifier(workerProfile) {
|
|
41
|
+
const preset = this.resolveVerifierPreset(workerProfile);
|
|
42
|
+
return preset.ok ? this.bindPreset(preset.resolved) : preset;
|
|
43
|
+
}
|
|
44
|
+
resolveVerifierPreset(workerProfile) {
|
|
37
45
|
if (!workerProfile.requireIndependentVerification || !workerProfile.verificationProfileId) {
|
|
38
46
|
return { ok: false, reason: "independent_verifier_not_configured" };
|
|
39
47
|
}
|
|
40
|
-
const selected = this.
|
|
48
|
+
const selected = this.resolveProfilePresetId(workerProfile.verificationProfileId);
|
|
41
49
|
if (!selected.ok)
|
|
42
50
|
return selected;
|
|
43
51
|
if (selected.resolved.profile.role !== "verifier") {
|
|
@@ -45,6 +53,32 @@ export class WorkerProfileResolver {
|
|
|
45
53
|
}
|
|
46
54
|
return selected;
|
|
47
55
|
}
|
|
56
|
+
bindPreset(preset, modelPin) {
|
|
57
|
+
const resolvedModel = modelPin
|
|
58
|
+
? resolvePinnedOrchestrationModel(modelPin, this.options.getModelRegistry(), (model) => this.options.isModelExhausted(model))
|
|
59
|
+
: resolveConfiguredOrchestrationModel(preset.profile, this.options.getModelRegistry(), (model) => this.options.isModelExhausted(model));
|
|
60
|
+
if (!resolvedModel) {
|
|
61
|
+
return {
|
|
62
|
+
ok: false,
|
|
63
|
+
reason: modelPin ? "orchestration_model_unavailable" : "orchestration_profile_model_unavailable",
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
return {
|
|
67
|
+
ok: true,
|
|
68
|
+
resolved: {
|
|
69
|
+
model: resolvedModel.model,
|
|
70
|
+
modelBinding: resolvedModel.binding,
|
|
71
|
+
profile: modelPin
|
|
72
|
+
? {
|
|
73
|
+
...structuredClone(preset.profile),
|
|
74
|
+
modelPolicy: { mode: "fixed", candidates: [resolvedModel.binding] },
|
|
75
|
+
}
|
|
76
|
+
: structuredClone(preset.profile),
|
|
77
|
+
resourcePointers: structuredClone(preset.resourcePointers),
|
|
78
|
+
...(preset.soul ? { soul: preset.soul } : {}),
|
|
79
|
+
},
|
|
80
|
+
};
|
|
81
|
+
}
|
|
48
82
|
resolveContract(contract) {
|
|
49
83
|
// Admission already fixed this contract. Live host controls may revoke execution, but mutable
|
|
50
84
|
// profile files cannot retroactively redefine the model, resources, or authority snapshot.
|
|
@@ -62,13 +96,10 @@ export class WorkerProfileResolver {
|
|
|
62
96
|
},
|
|
63
97
|
};
|
|
64
98
|
}
|
|
65
|
-
|
|
99
|
+
resolveProfilePresetId(profileId, loaded = this.loadProfiles()) {
|
|
66
100
|
const profile = loaded.registry.get(profileId);
|
|
67
101
|
if (!profile)
|
|
68
102
|
return { ok: false, reason: "orchestration_profile_not_found" };
|
|
69
|
-
const resolvedModel = resolveConfiguredOrchestrationModel(profile, this.options.getModelRegistry(), (model) => this.options.isModelExhausted(model));
|
|
70
|
-
if (!resolvedModel)
|
|
71
|
-
return { ok: false, reason: "orchestration_profile_model_unavailable" };
|
|
72
103
|
const linkedProfiles = profile.resourceProfileNames.map((name) => this.options.getSettingsManager().getProfileRegistry().getProfile(name));
|
|
73
104
|
if (linkedProfiles.some((linked) => linked === undefined)) {
|
|
74
105
|
return { ok: false, reason: "orchestration_resource_profile_not_found" };
|
|
@@ -85,9 +116,7 @@ export class WorkerProfileResolver {
|
|
|
85
116
|
return {
|
|
86
117
|
ok: true,
|
|
87
118
|
resolved: {
|
|
88
|
-
|
|
89
|
-
modelBinding: resolvedModel.binding,
|
|
90
|
-
profile,
|
|
119
|
+
profile: structuredClone(profile),
|
|
91
120
|
resourcePointers,
|
|
92
121
|
...(soul ? { soul } : {}),
|
|
93
122
|
},
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"worker-profile-resolver.js","sourceRoot":"","sources":["../../../src/core/delegation/worker-profile-resolver.ts"],"names":[],"mappings":"AAQA,OAAO,EACN,mCAAmC,EACnC,+BAA+B,GAC/B,MAAM,mCAAmC,CAAC;AAC3C,OAAO,EAAE,yBAAyB,EAAE,MAAM,mCAAmC,CAAC;AAI9E,OAAO,EAAE,6BAA6B,EAA4C,MAAM,8BAA8B,CAAC;AA2BvH,MAAM,OAAO,qBAAqB;IAIjC,YAAY,OAAqC;QAFhC,sBAAiB,GAAG,IAAI,GAAG,EAAU,CAAC;QAGtD,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;IACxB,CAAC;IAED,OAAO;QACN,MAAM,MAAM,GAAG,IAAI,CAAC,YA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,CAAC;YACnD,MAAM,GAAG,GAAG,YAAY,UAAU,EAAE,CAAC;YACrC,IAAI,IAAI,CAAC,iBAAiB,CAAC,GAAG,CAAC,GAAG,CAAC;gBAAE,SAAS;YAC9C,IAAI,CAAC,iBAAiB,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;YAChC,IAAI,CAAC,OAAO,CAAC,YAAY,CAAC,iCAAiC,UAAU,EAAE,CAAC,CAAC;QAC1E,CAAC;QACD,MAAM,QAAQ,GAAG,CAAC,GAAG,MAAM,CAAC,QAAQ,CAAC,CAAC;QACtC,MAAM,QAAQ,GAAG,IAAI,GAAG,CAAC,MAAM,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC,OAAO,CAAC,SAAS,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC;QACzF,KAAK,MAAM,MAAM,IAAI,YAAY,CAAC,OAAO,EAAE,CAAC;YAC3C,IAAI,QAAQ,CAAC,GAAG,CAAC,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC;gBAAE,SAAS;YACrD,QAAQ,CAAC,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;YAC9B,QAAQ,CAAC,GAAG,CAAC,MAAM,CAAC,OAAO,CAAC,SAAS,EAAE,MAAM,CAAC,OAAO,CAAC,CAAC;QACxD,CAAC;QACD,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,CAAC;IAC/B,CAAC;CACD","sourcesContent":["import type { Api, Model } from \"@caupulican/pi-ai\";\nimport type { ModelRegistry } from \"../model-registry.ts\";\nimport type {\n\tOrchestrationModelBinding,\n\tOrchestrationProfile,\n\tResourcePointer,\n\tWorkerProfileExecutionContract,\n} from \"../orchestration/contracts.ts\";\nimport {\n\tresolveConfiguredOrchestrationModel,\n\tresolvePinnedOrchestrationModel,\n} from \"../orchestration/model-binding.ts\";\nimport { OrchestrationProfileStore } from \"../orchestration/profile-store.ts\";\nimport type { SessionTaskProfileStore } from \"../orchestration/session-task-profile-store.ts\";\nimport type { SettingsManager } from \"../settings-manager.ts\";\nimport type { WorkerDelegationRequest } from \"./worker-delegation-request.ts\";\nimport { catalogWorkerResourcePointers, type WorkerResourceCatalogResourceLoader } from \"./worker-resource-catalog.ts\";\n\nexport interface ResolvedWorkerProfile {\n\tmodel: Model<Api>;\n\tmodelBinding: OrchestrationModelBinding;\n\tprofile: OrchestrationProfile;\n\t/** Metadata-only pointers admitted from the profile-linked resource configuration. */\n\tresourcePointers: readonly ResourcePointer[];\n\tsoul?: string;\n}\n\nexport interface WorkerProfileResolverOptions {\n\tagentDir: string;\n\tcwd: string;\n\tgetSettingsManager(): SettingsManager;\n\tgetResourceLoader(): WorkerResourceCatalogResourceLoader;\n\tgetModelRegistry(): ModelRegistry;\n\tisModelExhausted(model: Model<Api>): boolean;\n\tgetTaskProfileStore(): SessionTaskProfileStore;\n\tonDiagnostic(message: string): void;\n}\n\ninterface LoadedWorkerProfiles {\n\tprofiles: OrchestrationProfile[];\n\tregistry: ReadonlyMap<string, OrchestrationProfile>;\n}\n\nexport class WorkerProfileResolver {\n\tprivate readonly options: WorkerProfileResolverOptions;\n\tprivate readonly warnedDiagnostics = new Set<string>();\n\n\tconstructor(options: WorkerProfileResolverOptions) {\n\t\tthis.options = options;\n\t}\n\n\tcatalog(): Array<{ profileId: string; role: string; description: string }> {\n\t\tconst loaded = this.loadProfiles();\n\t\treturn loaded.profiles.map((profile) => ({\n\t\t\tprofileId: profile.profileId,\n\t\t\trole: profile.role,\n\t\t\tdescription: profile.description,\n\t\t}));\n\t}\n\n\tresolve(\n\t\trequest: WorkerDelegationRequest,\n\t\tdefaultProfileId: string | undefined,\n\t): { ok: true; resolved: ResolvedWorkerProfile } | { ok: false; reason: string } {\n\t\tconst requestedProfileId = request.profileId?.trim();\n\t\t// Profiles are routing presets, not authority cages. Any loaded preset may be selected; the\n\t\t// execution controller independently intersects its materialized plan with inherited authority.\n\t\tconst profileId = requestedProfileId || defaultProfileId;\n\t\tif (!profileId) return { ok: false, reason: \"orchestration_profile_required\" };\n\t\tconst selected = this.resolveProfileId(profileId);\n\t\tif (!selected.ok) return selected;\n\t\tconst profile = selected.resolved.profile;\n\t\tif (request.verificationOfTaskId && profile.role !== \"verifier\") {\n\t\t\treturn { ok: false, reason: \"verification_profile_role_mismatch\" };\n\t\t}\n\t\tif (!request.verificationOfTaskId && profile.role === \"verifier\") {\n\t\t\treturn { ok: false, reason: \"verifier_profile_requires_runtime_dispatch\" };\n\t\t}\n\t\treturn selected;\n\t}\n\n\tresolveVerifier(\n\t\tworkerProfile: OrchestrationProfile,\n\t): { ok: true; resolved: ResolvedWorkerProfile } | { ok: false; reason: string } {\n\t\tif (!workerProfile.requireIndependentVerification || !workerProfile.verificationProfileId) {\n\t\t\treturn { ok: false, reason: \"independent_verifier_not_configured\" };\n\t\t}\n\t\tconst selected = this.resolveProfileId(workerProfile.verificationProfileId);\n\t\tif (!selected.ok) return selected;\n\t\tif (selected.resolved.profile.role !== \"verifier\") {\n\t\t\treturn { ok: false, reason: \"verification_profile_role_mismatch\" };\n\t\t}\n\t\treturn selected;\n\t}\n\n\tresolveContract(\n\t\tcontract: WorkerProfileExecutionContract,\n\t): { ok: true; resolved: ResolvedWorkerProfile } | { ok: false; reason: string } {\n\t\t// Admission already fixed this contract. Live host controls may revoke execution, but mutable\n\t\t// profile files cannot retroactively redefine the model, resources, or authority snapshot.\n\t\tconst resolvedModel = resolvePinnedOrchestrationModel(\n\t\t\tcontract.modelBinding,\n\t\t\tthis.options.getModelRegistry(),\n\t\t\t(model) => this.options.isModelExhausted(model),\n\t\t);\n\t\tif (!resolvedModel) return { ok: false, reason: \"orchestration_profile_model_unavailable\" };\n\t\treturn {\n\t\t\tok: true,\n\t\t\tresolved: {\n\t\t\t\tmodel: resolvedModel.model,\n\t\t\t\tmodelBinding: resolvedModel.binding,\n\t\t\t\tprofile: structuredClone(contract.profile),\n\t\t\t\tresourcePointers: structuredClone(contract.resourcePointers),\n\t\t\t\t...(contract.soul ? { soul: contract.soul } : {}),\n\t\t\t},\n\t\t};\n\t}\n\n\tprivate resolveProfileId(\n\t\tprofileId: string,\n\t\tloaded: LoadedWorkerProfiles = this.loadProfiles(),\n\t): { ok: true; resolved: ResolvedWorkerProfile } | { ok: false; reason: string } {\n\t\tconst profile = loaded.registry.get(profileId);\n\t\tif (!profile) return { ok: false, reason: \"orchestration_profile_not_found\" };\n\t\tconst resolvedModel = resolveConfiguredOrchestrationModel(profile, this.options.getModelRegistry(), (model) =>\n\t\t\tthis.options.isModelExhausted(model),\n\t\t);\n\t\tif (!resolvedModel) return { ok: false, reason: \"orchestration_profile_model_unavailable\" };\n\t\tconst linkedProfiles = profile.resourceProfileNames.map((name) =>\n\t\t\tthis.options.getSettingsManager().getProfileRegistry().getProfile(name),\n\t\t);\n\t\tif (linkedProfiles.some((linked) => linked === undefined)) {\n\t\t\treturn { ok: false, reason: \"orchestration_resource_profile_not_found\" };\n\t\t}\n\t\tconst soul = linkedProfiles\n\t\t\t.flatMap((linked) => (linked?.soul ? [linked.soul] : []))\n\t\t\t.join(\"\\n\\n\")\n\t\t\t.trim();\n\t\tconst resourcePointers = catalogWorkerResourcePointers({\n\t\t\tcwd: this.options.cwd,\n\t\t\tresourceLoader: this.options.getResourceLoader(),\n\t\t\tresourceProfiles: linkedProfiles.filter(\n\t\t\t\t(linked): linked is NonNullable<typeof linked> => linked !== undefined,\n\t\t\t),\n\t\t});\n\t\treturn {\n\t\t\tok: true,\n\t\t\tresolved: {\n\t\t\t\tmodel: resolvedModel.model,\n\t\t\t\tmodelBinding: resolvedModel.binding,\n\t\t\t\tprofile,\n\t\t\t\tresourcePointers,\n\t\t\t\t...(soul ? { soul } : {}),\n\t\t\t},\n\t\t};\n\t}\n\n\tprivate loadProfiles(): LoadedWorkerProfiles {\n\t\tconst loaded = new OrchestrationProfileStore({\n\t\t\tagentDir: this.options.agentDir,\n\t\t\tcwd: this.options.cwd,\n\t\t\tprojectTrusted: this.options.getSettingsManager().isProjectTrusted(),\n\t\t}).load();\n\t\tfor (const diagnostic of loaded.diagnostics) {\n\t\t\tconst key = `${diagnostic.path}\\0${diagnostic.message}`;\n\t\t\tif (this.warnedDiagnostics.has(key)) continue;\n\t\t\tthis.warnedDiagnostics.add(key);\n\t\t\tthis.options.onDiagnostic(`Orchestration profile ignored (${diagnostic.path}): ${diagnostic.message}`);\n\t\t}\n\t\tconst taskProfiles = this.options.getTaskProfileStore().load();\n\t\tfor (const diagnostic of taskProfiles.diagnostics) {\n\t\t\tconst key = `session\\0${diagnostic}`;\n\t\t\tif (this.warnedDiagnostics.has(key)) continue;\n\t\t\tthis.warnedDiagnostics.add(key);\n\t\t\tthis.options.onDiagnostic(`Session task profile ignored: ${diagnostic}`);\n\t\t}\n\t\tconst profiles = [...loaded.profiles];\n\t\tconst registry = new Map(loaded.profiles.map((profile) => [profile.profileId, profile]));\n\t\tfor (const record of taskProfiles.records) {\n\t\t\tif (registry.has(record.profile.profileId)) continue;\n\t\t\tprofiles.push(record.profile);\n\t\t\tregistry.set(record.profile.profileId, record.profile);\n\t\t}\n\t\treturn { profiles, registry };\n\t}\n}\n"]}
|
|
1
|
+
{"version":3,"file":"worker-profile-resolver.js","sourceRoot":"","sources":["../../../src/core/delegation/worker-profile-resolver.ts"],"names":[],"mappings":"AAQA,OAAO,EACN,mCAAmC,EACnC,+BAA+B,GAC/B,MAAM,mCAAmC,CAAC;AAC3C,OAAO,EAAE,yBAAyB,EAAE,MAAM,mCAAmC,CAAC;AAI9E,OAAO,EAAE,6BAA6B,EAA4C,MAAM,8BAA8B,CAAC;AAkCvH,MAAM,OAAO,qBAAqB;IAIjC,YAAY,OAAqC;QAFhC,sBAAiB,GAAG,IAAI,GAAG,EAAU,CAAC;QAGtD,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;IACxB,CAAC;IAED,OAAO;QACN,MAAM,MAAM,GAAG,IAAI,CAAC,YAAY,EAAE,CAAC;QACnC,OAAO,MAAM,CAAC,QAAQ,CAAC,G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BAAmB,EAAE,CAAC,IAAI,EAAE,CAAC;QAC/D,KAAK,MAAM,UAAU,IAAI,YAAY,CAAC,WAAW,EAAE,CAAC;YACnD,MAAM,GAAG,GAAG,YAAY,UAAU,EAAE,CAAC;YACrC,IAAI,IAAI,CAAC,iBAAiB,CAAC,GAAG,CAAC,GAAG,CAAC;gBAAE,SAAS;YAC9C,IAAI,CAAC,iBAAiB,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;YAChC,IAAI,CAAC,OAAO,CAAC,YAAY,CAAC,iCAAiC,UAAU,EAAE,CAAC,CAAC;QAC1E,CAAC;QACD,MAAM,QAAQ,GAAG,CAAC,GAAG,MAAM,CAAC,QAAQ,CAAC,CAAC;QACtC,MAAM,QAAQ,GAAG,IAAI,GAAG,CAAC,MAAM,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC,OAAO,CAAC,SAAS,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC;QACzF,KAAK,MAAM,MAAM,IAAI,YAAY,CAAC,OAAO,EAAE,CAAC;YAC3C,IAAI,QAAQ,CAAC,GAAG,CAAC,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC;gBAAE,SAAS;YACrD,QAAQ,CAAC,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;YAC9B,QAAQ,CAAC,GAAG,CAAC,MAAM,CAAC,OAAO,CAAC,SAAS,EAAE,MAAM,CAAC,OAAO,CAAC,CAAC;QACxD,CAAC;QACD,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,CAAC;IAC/B,CAAC;CACD","sourcesContent":["import type { Api, Model } from \"@caupulican/pi-ai\";\nimport type { ModelRegistry } from \"../model-registry.ts\";\nimport type {\n\tOrchestrationModelBinding,\n\tOrchestrationProfile,\n\tResourcePointer,\n\tWorkerProfileExecutionContract,\n} from \"../orchestration/contracts.ts\";\nimport {\n\tresolveConfiguredOrchestrationModel,\n\tresolvePinnedOrchestrationModel,\n} from \"../orchestration/model-binding.ts\";\nimport { OrchestrationProfileStore } from \"../orchestration/profile-store.ts\";\nimport type { SessionTaskProfileStore } from \"../orchestration/session-task-profile-store.ts\";\nimport type { SettingsManager } from \"../settings-manager.ts\";\nimport type { WorkerDelegationRequest } from \"./worker-delegation-request.ts\";\nimport { catalogWorkerResourcePointers, type WorkerResourceCatalogResourceLoader } from \"./worker-resource-catalog.ts\";\n\nexport interface ResolvedWorkerProfile {\n\tmodel: Model<Api>;\n\tmodelBinding: OrchestrationModelBinding;\n\tprofile: OrchestrationProfile;\n\t/** Metadata-only pointers admitted from the profile-linked resource configuration. */\n\tresourcePointers: readonly ResourcePointer[];\n\tsoul?: string;\n}\n\nexport interface ResolvedWorkerProfilePreset {\n\tprofile: OrchestrationProfile;\n\t/** Metadata-only pointers admitted from the profile-linked resource configuration. */\n\tresourcePointers: readonly ResourcePointer[];\n\tsoul?: string;\n}\n\nexport interface WorkerProfileResolverOptions {\n\tagentDir: string;\n\tcwd: string;\n\tgetSettingsManager(): SettingsManager;\n\tgetResourceLoader(): WorkerResourceCatalogResourceLoader;\n\tgetModelRegistry(): ModelRegistry;\n\tisModelExhausted(model: Model<Api>): boolean;\n\tgetTaskProfileStore(): SessionTaskProfileStore;\n\tonDiagnostic(message: string): void;\n}\n\ninterface LoadedWorkerProfiles {\n\tprofiles: OrchestrationProfile[];\n\tregistry: ReadonlyMap<string, OrchestrationProfile>;\n}\n\nexport class WorkerProfileResolver {\n\tprivate readonly options: WorkerProfileResolverOptions;\n\tprivate readonly warnedDiagnostics = new Set<string>();\n\n\tconstructor(options: WorkerProfileResolverOptions) {\n\t\tthis.options = options;\n\t}\n\n\tcatalog(): Array<{ profileId: string; role: string; description: string }> {\n\t\tconst loaded = this.loadProfiles();\n\t\treturn loaded.profiles.map((profile) => ({\n\t\t\tprofileId: profile.profileId,\n\t\t\trole: profile.role,\n\t\t\tdescription: profile.description,\n\t\t}));\n\t}\n\n\tresolve(\n\t\trequest: WorkerDelegationRequest,\n\t\tdefaultProfileId: string | undefined,\n\t): { ok: true; resolved: ResolvedWorkerProfile } | { ok: false; reason: string } {\n\t\tconst preset = this.resolvePreset(request, defaultProfileId);\n\t\treturn preset.ok ? this.bindPreset(preset.resolved) : preset;\n\t}\n\n\tresolvePreset(\n\t\trequest: WorkerDelegationRequest,\n\t\tdefaultProfileId: string | undefined,\n\t): { ok: true; resolved: ResolvedWorkerProfilePreset } | { ok: false; reason: string } {\n\t\tconst requestedProfileId = request.profileId?.trim();\n\t\t// Profiles are routing presets, not authority cages. Any loaded preset may be selected; the\n\t\t// execution controller independently intersects its materialized plan with inherited authority.\n\t\tconst profileId = requestedProfileId || defaultProfileId;\n\t\tif (!profileId) return { ok: false, reason: \"orchestration_profile_required\" };\n\t\tconst selected = this.resolveProfilePresetId(profileId);\n\t\tif (!selected.ok) return selected;\n\t\tconst profile = selected.resolved.profile;\n\t\tif (request.verificationOfTaskId && profile.role !== \"verifier\") {\n\t\t\treturn { ok: false, reason: \"verification_profile_role_mismatch\" };\n\t\t}\n\t\tif (!request.verificationOfTaskId && profile.role === \"verifier\") {\n\t\t\treturn { ok: false, reason: \"verifier_profile_requires_runtime_dispatch\" };\n\t\t}\n\t\treturn selected;\n\t}\n\n\tresolveVerifier(\n\t\tworkerProfile: OrchestrationProfile,\n\t): { ok: true; resolved: ResolvedWorkerProfile } | { ok: false; reason: string } {\n\t\tconst preset = this.resolveVerifierPreset(workerProfile);\n\t\treturn preset.ok ? this.bindPreset(preset.resolved) : preset;\n\t}\n\n\tresolveVerifierPreset(\n\t\tworkerProfile: OrchestrationProfile,\n\t): { ok: true; resolved: ResolvedWorkerProfilePreset } | { ok: false; reason: string } {\n\t\tif (!workerProfile.requireIndependentVerification || !workerProfile.verificationProfileId) {\n\t\t\treturn { ok: false, reason: \"independent_verifier_not_configured\" };\n\t\t}\n\t\tconst selected = this.resolveProfilePresetId(workerProfile.verificationProfileId);\n\t\tif (!selected.ok) return selected;\n\t\tif (selected.resolved.profile.role !== \"verifier\") {\n\t\t\treturn { ok: false, reason: \"verification_profile_role_mismatch\" };\n\t\t}\n\t\treturn selected;\n\t}\n\n\tbindPreset(\n\t\tpreset: ResolvedWorkerProfilePreset,\n\t\tmodelPin?: OrchestrationModelBinding,\n\t): { ok: true; resolved: ResolvedWorkerProfile } | { ok: false; reason: string } {\n\t\tconst resolvedModel = modelPin\n\t\t\t? resolvePinnedOrchestrationModel(modelPin, this.options.getModelRegistry(), (model) =>\n\t\t\t\t\tthis.options.isModelExhausted(model),\n\t\t\t\t)\n\t\t\t: resolveConfiguredOrchestrationModel(preset.profile, this.options.getModelRegistry(), (model) =>\n\t\t\t\t\tthis.options.isModelExhausted(model),\n\t\t\t\t);\n\t\tif (!resolvedModel) {\n\t\t\treturn {\n\t\t\t\tok: false,\n\t\t\t\treason: modelPin ? \"orchestration_model_unavailable\" : \"orchestration_profile_model_unavailable\",\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\tok: true,\n\t\t\tresolved: {\n\t\t\t\tmodel: resolvedModel.model,\n\t\t\t\tmodelBinding: resolvedModel.binding,\n\t\t\t\tprofile: modelPin\n\t\t\t\t\t? {\n\t\t\t\t\t\t\t...structuredClone(preset.profile),\n\t\t\t\t\t\t\tmodelPolicy: { mode: \"fixed\", candidates: [resolvedModel.binding] },\n\t\t\t\t\t\t}\n\t\t\t\t\t: structuredClone(preset.profile),\n\t\t\t\tresourcePointers: structuredClone(preset.resourcePointers),\n\t\t\t\t...(preset.soul ? { soul: preset.soul } : {}),\n\t\t\t},\n\t\t};\n\t}\n\n\tresolveContract(\n\t\tcontract: WorkerProfileExecutionContract,\n\t): { ok: true; resolved: ResolvedWorkerProfile } | { ok: false; reason: string } {\n\t\t// Admission already fixed this contract. Live host controls may revoke execution, but mutable\n\t\t// profile files cannot retroactively redefine the model, resources, or authority snapshot.\n\t\tconst resolvedModel = resolvePinnedOrchestrationModel(\n\t\t\tcontract.modelBinding,\n\t\t\tthis.options.getModelRegistry(),\n\t\t\t(model) => this.options.isModelExhausted(model),\n\t\t);\n\t\tif (!resolvedModel) return { ok: false, reason: \"orchestration_profile_model_unavailable\" };\n\t\treturn {\n\t\t\tok: true,\n\t\t\tresolved: {\n\t\t\t\tmodel: resolvedModel.model,\n\t\t\t\tmodelBinding: resolvedModel.binding,\n\t\t\t\tprofile: structuredClone(contract.profile),\n\t\t\t\tresourcePointers: structuredClone(contract.resourcePointers),\n\t\t\t\t...(contract.soul ? { soul: contract.soul } : {}),\n\t\t\t},\n\t\t};\n\t}\n\n\tprivate resolveProfilePresetId(\n\t\tprofileId: string,\n\t\tloaded: LoadedWorkerProfiles = this.loadProfiles(),\n\t): { ok: true; resolved: ResolvedWorkerProfilePreset } | { ok: false; reason: string } {\n\t\tconst profile = loaded.registry.get(profileId);\n\t\tif (!profile) return { ok: false, reason: \"orchestration_profile_not_found\" };\n\t\tconst linkedProfiles = profile.resourceProfileNames.map((name) =>\n\t\t\tthis.options.getSettingsManager().getProfileRegistry().getProfile(name),\n\t\t);\n\t\tif (linkedProfiles.some((linked) => linked === undefined)) {\n\t\t\treturn { ok: false, reason: \"orchestration_resource_profile_not_found\" };\n\t\t}\n\t\tconst soul = linkedProfiles\n\t\t\t.flatMap((linked) => (linked?.soul ? [linked.soul] : []))\n\t\t\t.join(\"\\n\\n\")\n\t\t\t.trim();\n\t\tconst resourcePointers = catalogWorkerResourcePointers({\n\t\t\tcwd: this.options.cwd,\n\t\t\tresourceLoader: this.options.getResourceLoader(),\n\t\t\tresourceProfiles: linkedProfiles.filter(\n\t\t\t\t(linked): linked is NonNullable<typeof linked> => linked !== undefined,\n\t\t\t),\n\t\t});\n\t\treturn {\n\t\t\tok: true,\n\t\t\tresolved: {\n\t\t\t\tprofile: structuredClone(profile),\n\t\t\t\tresourcePointers,\n\t\t\t\t...(soul ? { soul } : {}),\n\t\t\t},\n\t\t};\n\t}\n\n\tprivate loadProfiles(): LoadedWorkerProfiles {\n\t\tconst loaded = new OrchestrationProfileStore({\n\t\t\tagentDir: this.options.agentDir,\n\t\t\tcwd: this.options.cwd,\n\t\t\tprojectTrusted: this.options.getSettingsManager().isProjectTrusted(),\n\t\t}).load();\n\t\tfor (const diagnostic of loaded.diagnostics) {\n\t\t\tconst key = `${diagnostic.path}\\0${diagnostic.message}`;\n\t\t\tif (this.warnedDiagnostics.has(key)) continue;\n\t\t\tthis.warnedDiagnostics.add(key);\n\t\t\tthis.options.onDiagnostic(`Orchestration profile ignored (${diagnostic.path}): ${diagnostic.message}`);\n\t\t}\n\t\tconst taskProfiles = this.options.getTaskProfileStore().load();\n\t\tfor (const diagnostic of taskProfiles.diagnostics) {\n\t\t\tconst key = `session\\0${diagnostic}`;\n\t\t\tif (this.warnedDiagnostics.has(key)) continue;\n\t\t\tthis.warnedDiagnostics.add(key);\n\t\t\tthis.options.onDiagnostic(`Session task profile ignored: ${diagnostic}`);\n\t\t}\n\t\tconst profiles = [...loaded.profiles];\n\t\tconst registry = new Map(loaded.profiles.map((profile) => [profile.profileId, profile]));\n\t\tfor (const record of taskProfiles.records) {\n\t\t\tif (registry.has(record.profile.profileId)) continue;\n\t\t\tprofiles.push(record.profile);\n\t\t\tregistry.set(record.profile.profileId, record.profile);\n\t\t}\n\t\treturn { profiles, registry };\n\t}\n}\n"]}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { type OrchestrationModelBinding, type WorkerRole } from "./contracts.ts";
|
|
2
|
+
export type WorkerModelPinSource = "global" | "project" | "directoryProfile";
|
|
3
|
+
export interface WorkerModelPinsSettings {
|
|
4
|
+
default?: OrchestrationModelBinding;
|
|
5
|
+
roles?: Partial<Record<WorkerRole, OrchestrationModelBinding>>;
|
|
6
|
+
}
|
|
7
|
+
export interface ResolvedWorkerModelPin {
|
|
8
|
+
binding: OrchestrationModelBinding;
|
|
9
|
+
source: WorkerModelPinSource;
|
|
10
|
+
}
|
|
11
|
+
export type WorkerModelPinPolicy = {
|
|
12
|
+
status: "absent";
|
|
13
|
+
} | {
|
|
14
|
+
status: "invalid";
|
|
15
|
+
diagnostics: readonly string[];
|
|
16
|
+
} | {
|
|
17
|
+
status: "active";
|
|
18
|
+
byRole: Readonly<Partial<Record<WorkerRole, ResolvedWorkerModelPin>>>;
|
|
19
|
+
};
|
|
20
|
+
export interface WorkerModelPinPolicyLayers {
|
|
21
|
+
global?: unknown;
|
|
22
|
+
project?: unknown;
|
|
23
|
+
directoryProfile?: unknown;
|
|
24
|
+
}
|
|
25
|
+
/** Compile independently validated settings scopes into one immutable admission policy. */
|
|
26
|
+
export declare function compileWorkerModelPinPolicy(layers: WorkerModelPinPolicyLayers): WorkerModelPinPolicy;
|
|
27
|
+
export declare function resolveWorkerModelPin(policy: WorkerModelPinPolicy, role: WorkerRole): ResolvedWorkerModelPin | undefined;
|
|
28
|
+
//# sourceMappingURL=worker-model-pins.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"worker-model-pins.d.ts","sourceRoot":"","sources":["../../../src/core/orchestration/worker-model-pins.ts"],"names":[],"mappings":"AACA,OAAO,EAIN,KAAK,yBAAyB,EAE9B,KAAK,UAAU,EACf,MAAM,gBAAgB,CAAC;AAExB,MAAM,MAAM,oBAAoB,GAAG,QAAQ,GAAG,SAAS,GAAG,kBAAkB,CAAC;AAE7E,MAAM,WAAW,uBAAuB;IACvC,OAAO,CAAC,EAAE,yBAAyB,CAAC;IACpC,KAAK,CAAC,EAAE,OAAO,CAAC,MAAM,CAAC,UAAU,EAAE,yBAAyB,CAAC,CAAC,CAAC;CAC/D;AAED,MAAM,WAAW,sBAAsB;IACtC,OAAO,EAAE,yBAAyB,CAAC;IACnC,MAAM,EAAE,oBAAoB,CAAC;CAC7B;AAED,MAAM,MAAM,oBAAoB,GAC7B;IAAE,MAAM,EAAE,QAAQ,CAAA;CAAE,GACpB;IAAE,MAAM,EAAE,SAAS,CAAC;IAAC,WAAW,EAAE,SAAS,MAAM,EAAE,CAAA;CAAE,GACrD;IACA,MAAM,EAAE,QAAQ,CAAC;IACjB,MAAM,EAAE,QAAQ,CAAC,OAAO,CAAC,MAAM,CAAC,UAAU,EAAE,sBAAsB,CAAC,CAAC,CAAC,CAAC;CACrE,CAAC;AAEL,MAAM,WAAW,0BAA0B;IAC1C,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,gBAAgB,CAAC,EAAE,OAAO,CAAC;CAC3B;AAqJD,2FAA2F;AAC3F,wBAAgB,2BAA2B,CAAC,MAAM,EAAE,0BAA0B,GAAG,oBAAoB,CAmBpG;AAED,wBAAgB,qBAAqB,CACpC,MAAM,EAAE,oBAAoB,EAC5B,IAAI,EAAE,UAAU,GACd,sBAAsB,GAAG,SAAS,CAIpC"}
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
import { isPlainRecord } from "../util/value-guards.js";
|
|
2
|
+
import { MAX_ORCHESTRATION_MODEL_ID_LENGTH, MAX_ORCHESTRATION_MODEL_PROVIDER_LENGTH, ORCHESTRATION_THINKING_LEVELS, WORKER_ROLES, } from "./contracts.js";
|
|
3
|
+
const POLICY_KEYS = new Set(["default", "roles"]);
|
|
4
|
+
const BINDING_KEYS = new Set(["provider", "modelId", "thinkingLevel"]);
|
|
5
|
+
const WORKER_ROLE_SET = new Set(WORKER_ROLES);
|
|
6
|
+
const THINKING_LEVEL_SET = new Set(ORCHESTRATION_THINKING_LEVELS);
|
|
7
|
+
function cloneBinding(binding) {
|
|
8
|
+
return { ...binding };
|
|
9
|
+
}
|
|
10
|
+
function bindingDiagnostic(scope, path, expectation) {
|
|
11
|
+
return `workerDelegation.modelPins.${path} in ${scope} settings must ${expectation}`;
|
|
12
|
+
}
|
|
13
|
+
function parseBinding(value, scope, path, diagnostics) {
|
|
14
|
+
if (!isPlainRecord(value)) {
|
|
15
|
+
diagnostics.push(bindingDiagnostic(scope, path, "be an object"));
|
|
16
|
+
return undefined;
|
|
17
|
+
}
|
|
18
|
+
const unknownKeys = Object.keys(value).filter((key) => !BINDING_KEYS.has(key));
|
|
19
|
+
if (unknownKeys.length > 0) {
|
|
20
|
+
diagnostics.push(bindingDiagnostic(scope, path, `contain only provider, modelId, and thinkingLevel`));
|
|
21
|
+
return undefined;
|
|
22
|
+
}
|
|
23
|
+
const provider = typeof value.provider === "string" ? value.provider.trim() : "";
|
|
24
|
+
if (!provider || provider.length > MAX_ORCHESTRATION_MODEL_PROVIDER_LENGTH) {
|
|
25
|
+
diagnostics.push(bindingDiagnostic(scope, `${path}.provider`, `be a nonempty string of at most ${MAX_ORCHESTRATION_MODEL_PROVIDER_LENGTH} characters`));
|
|
26
|
+
}
|
|
27
|
+
const modelId = typeof value.modelId === "string" ? value.modelId.trim() : "";
|
|
28
|
+
if (!modelId || modelId.length > MAX_ORCHESTRATION_MODEL_ID_LENGTH) {
|
|
29
|
+
diagnostics.push(bindingDiagnostic(scope, `${path}.modelId`, `be a nonempty string of at most ${MAX_ORCHESTRATION_MODEL_ID_LENGTH} characters`));
|
|
30
|
+
}
|
|
31
|
+
const thinkingLevel = value.thinkingLevel;
|
|
32
|
+
if (typeof thinkingLevel !== "string" || !THINKING_LEVEL_SET.has(thinkingLevel)) {
|
|
33
|
+
diagnostics.push(bindingDiagnostic(scope, `${path}.thinkingLevel`, `be one of ${ORCHESTRATION_THINKING_LEVELS.join(", ")}`));
|
|
34
|
+
}
|
|
35
|
+
if (!provider || !modelId || typeof thinkingLevel !== "string" || !THINKING_LEVEL_SET.has(thinkingLevel)) {
|
|
36
|
+
return undefined;
|
|
37
|
+
}
|
|
38
|
+
return {
|
|
39
|
+
provider,
|
|
40
|
+
modelId,
|
|
41
|
+
thinkingLevel: thinkingLevel,
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
function parseLayer(value, scope) {
|
|
45
|
+
if (value === undefined)
|
|
46
|
+
return { present: false, diagnostics: [] };
|
|
47
|
+
const diagnostics = [];
|
|
48
|
+
if (!isPlainRecord(value)) {
|
|
49
|
+
return {
|
|
50
|
+
present: true,
|
|
51
|
+
diagnostics: [`workerDelegation.modelPins in ${scope} settings must be an object`],
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
const unknownKeys = Object.keys(value).filter((key) => !POLICY_KEYS.has(key));
|
|
55
|
+
if (unknownKeys.length > 0) {
|
|
56
|
+
diagnostics.push(`workerDelegation.modelPins in ${scope} settings contains unknown fields: ${unknownKeys.join(", ")}`);
|
|
57
|
+
}
|
|
58
|
+
const settings = {};
|
|
59
|
+
if (Object.hasOwn(value, "default")) {
|
|
60
|
+
const binding = parseBinding(value.default, scope, "default", diagnostics);
|
|
61
|
+
if (binding)
|
|
62
|
+
settings.default = binding;
|
|
63
|
+
}
|
|
64
|
+
if (Object.hasOwn(value, "roles")) {
|
|
65
|
+
if (!isPlainRecord(value.roles)) {
|
|
66
|
+
diagnostics.push(`workerDelegation.modelPins.roles in ${scope} settings must be an object`);
|
|
67
|
+
}
|
|
68
|
+
else {
|
|
69
|
+
const roles = {};
|
|
70
|
+
for (const [role, candidate] of Object.entries(value.roles)) {
|
|
71
|
+
if (!WORKER_ROLE_SET.has(role)) {
|
|
72
|
+
diagnostics.push(`workerDelegation.modelPins.roles in ${scope} settings contains unknown role: ${role}`);
|
|
73
|
+
continue;
|
|
74
|
+
}
|
|
75
|
+
const binding = parseBinding(candidate, scope, `roles.${role}`, diagnostics);
|
|
76
|
+
if (binding)
|
|
77
|
+
roles[role] = binding;
|
|
78
|
+
}
|
|
79
|
+
settings.roles = roles;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
return { present: true, settings, diagnostics };
|
|
83
|
+
}
|
|
84
|
+
function pinFromLayer(layer, role) {
|
|
85
|
+
if (!layer)
|
|
86
|
+
return undefined;
|
|
87
|
+
const binding = layer.settings.roles?.[role] ?? layer.settings.default;
|
|
88
|
+
return binding ? { binding: cloneBinding(binding), source: layer.source } : undefined;
|
|
89
|
+
}
|
|
90
|
+
function pinFromLocalLayers(directoryLayer, projectLayer, role) {
|
|
91
|
+
const roleLayer = directoryLayer?.settings.roles?.[role]
|
|
92
|
+
? directoryLayer
|
|
93
|
+
: projectLayer?.settings.roles?.[role]
|
|
94
|
+
? projectLayer
|
|
95
|
+
: undefined;
|
|
96
|
+
const roleBinding = roleLayer?.settings.roles?.[role];
|
|
97
|
+
if (roleLayer && roleBinding) {
|
|
98
|
+
return {
|
|
99
|
+
binding: cloneBinding(roleBinding),
|
|
100
|
+
source: roleLayer.source,
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
const defaultLayer = directoryLayer?.settings.default
|
|
104
|
+
? directoryLayer
|
|
105
|
+
: projectLayer?.settings.default
|
|
106
|
+
? projectLayer
|
|
107
|
+
: undefined;
|
|
108
|
+
return defaultLayer?.settings.default
|
|
109
|
+
? { binding: cloneBinding(defaultLayer.settings.default), source: defaultLayer.source }
|
|
110
|
+
: undefined;
|
|
111
|
+
}
|
|
112
|
+
/** Compile independently validated settings scopes into one immutable admission policy. */
|
|
113
|
+
export function compileWorkerModelPinPolicy(layers) {
|
|
114
|
+
const global = parseLayer(layers.global, "global");
|
|
115
|
+
const project = parseLayer(layers.project, "project");
|
|
116
|
+
const directoryProfile = parseLayer(layers.directoryProfile, "directoryProfile");
|
|
117
|
+
const diagnostics = [...global.diagnostics, ...project.diagnostics, ...directoryProfile.diagnostics];
|
|
118
|
+
if (diagnostics.length > 0)
|
|
119
|
+
return { status: "invalid", diagnostics };
|
|
120
|
+
if (!global.present && !project.present && !directoryProfile.present)
|
|
121
|
+
return { status: "absent" };
|
|
122
|
+
const globalLayer = global.settings ? { settings: global.settings, source: "global" } : undefined;
|
|
123
|
+
const projectLayer = project.settings ? { settings: project.settings, source: "project" } : undefined;
|
|
124
|
+
const directoryLayer = directoryProfile.settings
|
|
125
|
+
? { settings: directoryProfile.settings, source: "directoryProfile" }
|
|
126
|
+
: undefined;
|
|
127
|
+
const byRole = {};
|
|
128
|
+
for (const role of WORKER_ROLES) {
|
|
129
|
+
const pin = pinFromLayer(globalLayer, role) ?? pinFromLocalLayers(directoryLayer, projectLayer, role);
|
|
130
|
+
if (pin)
|
|
131
|
+
byRole[role] = pin;
|
|
132
|
+
}
|
|
133
|
+
return Object.keys(byRole).length > 0 ? { status: "active", byRole } : { status: "absent" };
|
|
134
|
+
}
|
|
135
|
+
export function resolveWorkerModelPin(policy, role) {
|
|
136
|
+
if (policy.status !== "active")
|
|
137
|
+
return undefined;
|
|
138
|
+
const pin = policy.byRole[role];
|
|
139
|
+
return pin ? { binding: cloneBinding(pin.binding), source: pin.source } : undefined;
|
|
140
|
+
}
|
|
141
|
+
//# sourceMappingURL=worker-model-pins.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"worker-model-pins.js","sourceRoot":"","sources":["../../../src/core/orchestration/worker-model-pins.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AACxD,OAAO,EACN,iCAAiC,EACjC,uCAAuC,EACvC,6BAA6B,EAE7B,YAAY,GAEZ,MAAM,gBAAgB,CAAC;AAuCxB,MAAM,WAAW,GAAG,IAAI,GAAG,CAAC,CAAC,SAAS,EAAE,OAAO,CAAC,CAAC,CAAC;AAClD,MAAM,YAAY,GAAG,IAAI,GAAG,CAAC,CAAC,UAAU,EAAE,SAAS,EAAE,eAAe,CAAC,CAAC,CAAC;AACvE,MAAM,eAAe,GAAwB,IAAI,GAAG,CAAC,YAAY,CAAC,CAAC;AACnE,MAAM,kBAAkB,GAAwB,IAAI,GAAG,CAAC,6BAA6B,CAAC,CAAC;AAEvF,SAAS,YAAY,CAAC,OAAkC;IACvD,OAAO,EAAE,GAAG,OAAO,EAAE,CAAC;AACvB,CAAC;AAED,SAAS,iBAAiB,CAAC,KAA2B,EAAE,IAAY,EAAE,WAAmB;IACxF,OAAO,8BAA8B,IAAI,OAAO,KAAK,kBAAkB,WAAW,EAAE,CAAC;AACtF,CAAC;AAED,SAAS,YAAY,CACpB,KAAc,EACd,KAA2B,EAC3B,IAAY,EACZ,WAAqB;IAErB,I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IACvE,KAAK,MAAM,IAAI,IAAI,YAAY,EAAE,CAAC;QACjC,MAAM,GAAG,GAAG,YAAY,CAAC,WAAW,EAAE,IAAI,CAAC,IAAI,kBAAkB,CAAC,cAAc,EAAE,YAAY,EAAE,IAAI,CAAC,CAAC;QACtG,IAAI,GAAG;YAAE,MAAM,CAAC,IAAI,CAAC,GAAG,GAAG,CAAC;IAC7B,CAAC;IACD,OAAO,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAC;AAC7F,CAAC;AAED,MAAM,UAAU,qBAAqB,CACpC,MAA4B,EAC5B,IAAgB;IAEhB,IAAI,MAAM,CAAC,MAAM,KAAK,QAAQ;QAAE,OAAO,SAAS,CAAC;IACjD,MAAM,GAAG,GAAG,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;IAChC,OAAO,GAAG,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,YAAY,CAAC,GAAG,CAAC,OAAO,CAAC,EAAE,MAAM,EAAE,GAAG,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC;AACrF,CAAC","sourcesContent":["import { isPlainRecord } from \"../util/value-guards.ts\";\nimport {\n\tMAX_ORCHESTRATION_MODEL_ID_LENGTH,\n\tMAX_ORCHESTRATION_MODEL_PROVIDER_LENGTH,\n\tORCHESTRATION_THINKING_LEVELS,\n\ttype OrchestrationModelBinding,\n\tWORKER_ROLES,\n\ttype WorkerRole,\n} from \"./contracts.ts\";\n\nexport type WorkerModelPinSource = \"global\" | \"project\" | \"directoryProfile\";\n\nexport interface WorkerModelPinsSettings {\n\tdefault?: OrchestrationModelBinding;\n\troles?: Partial<Record<WorkerRole, OrchestrationModelBinding>>;\n}\n\nexport interface ResolvedWorkerModelPin {\n\tbinding: OrchestrationModelBinding;\n\tsource: WorkerModelPinSource;\n}\n\nexport type WorkerModelPinPolicy =\n\t| { status: \"absent\" }\n\t| { status: \"invalid\"; diagnostics: readonly string[] }\n\t| {\n\t\t\tstatus: \"active\";\n\t\t\tbyRole: Readonly<Partial<Record<WorkerRole, ResolvedWorkerModelPin>>>;\n\t };\n\nexport interface WorkerModelPinPolicyLayers {\n\tglobal?: unknown;\n\tproject?: unknown;\n\tdirectoryProfile?: unknown;\n}\n\ninterface NormalizedPinLayer {\n\tsettings: WorkerModelPinsSettings;\n\tsource: WorkerModelPinSource;\n}\n\ninterface ParsedPinLayer {\n\tpresent: boolean;\n\tsettings?: WorkerModelPinsSettings;\n\tdiagnostics: string[];\n}\n\nconst POLICY_KEYS = new Set([\"default\", \"roles\"]);\nconst BINDING_KEYS = new Set([\"provider\", \"modelId\", \"thinkingLevel\"]);\nconst WORKER_ROLE_SET: ReadonlySet<string> = new Set(WORKER_ROLES);\nconst THINKING_LEVEL_SET: ReadonlySet<string> = new Set(ORCHESTRATION_THINKING_LEVELS);\n\nfunction cloneBinding(binding: OrchestrationModelBinding): OrchestrationModelBinding {\n\treturn { ...binding };\n}\n\nfunction bindingDiagnostic(scope: WorkerModelPinSource, path: string, expectation: string): string {\n\treturn `workerDelegation.modelPins.${path} in ${scope} settings must ${expectation}`;\n}\n\nfunction parseBinding(\n\tvalue: unknown,\n\tscope: WorkerModelPinSource,\n\tpath: string,\n\tdiagnostics: string[],\n): OrchestrationModelBinding | undefined {\n\tif (!isPlainRecord(value)) {\n\t\tdiagnostics.push(bindingDiagnostic(scope, path, \"be an object\"));\n\t\treturn undefined;\n\t}\n\tconst unknownKeys = Object.keys(value).filter((key) => !BINDING_KEYS.has(key));\n\tif (unknownKeys.length > 0) {\n\t\tdiagnostics.push(bindingDiagnostic(scope, path, `contain only provider, modelId, and thinkingLevel`));\n\t\treturn undefined;\n\t}\n\tconst provider = typeof value.provider === \"string\" ? value.provider.trim() : \"\";\n\tif (!provider || provider.length > MAX_ORCHESTRATION_MODEL_PROVIDER_LENGTH) {\n\t\tdiagnostics.push(\n\t\t\tbindingDiagnostic(\n\t\t\t\tscope,\n\t\t\t\t`${path}.provider`,\n\t\t\t\t`be a nonempty string of at most ${MAX_ORCHESTRATION_MODEL_PROVIDER_LENGTH} characters`,\n\t\t\t),\n\t\t);\n\t}\n\tconst modelId = typeof value.modelId === \"string\" ? value.modelId.trim() : \"\";\n\tif (!modelId || modelId.length > MAX_ORCHESTRATION_MODEL_ID_LENGTH) {\n\t\tdiagnostics.push(\n\t\t\tbindingDiagnostic(\n\t\t\t\tscope,\n\t\t\t\t`${path}.modelId`,\n\t\t\t\t`be a nonempty string of at most ${MAX_ORCHESTRATION_MODEL_ID_LENGTH} characters`,\n\t\t\t),\n\t\t);\n\t}\n\tconst thinkingLevel = value.thinkingLevel;\n\tif (typeof thinkingLevel !== \"string\" || !THINKING_LEVEL_SET.has(thinkingLevel)) {\n\t\tdiagnostics.push(\n\t\t\tbindingDiagnostic(scope, `${path}.thinkingLevel`, `be one of ${ORCHESTRATION_THINKING_LEVELS.join(\", \")}`),\n\t\t);\n\t}\n\tif (!provider || !modelId || typeof thinkingLevel !== \"string\" || !THINKING_LEVEL_SET.has(thinkingLevel)) {\n\t\treturn undefined;\n\t}\n\treturn {\n\t\tprovider,\n\t\tmodelId,\n\t\tthinkingLevel: thinkingLevel as OrchestrationModelBinding[\"thinkingLevel\"],\n\t};\n}\n\nfunction parseLayer(value: unknown, scope: WorkerModelPinSource): ParsedPinLayer {\n\tif (value === undefined) return { present: false, diagnostics: [] };\n\tconst diagnostics: string[] = [];\n\tif (!isPlainRecord(value)) {\n\t\treturn {\n\t\t\tpresent: true,\n\t\t\tdiagnostics: [`workerDelegation.modelPins in ${scope} settings must be an object`],\n\t\t};\n\t}\n\tconst unknownKeys = Object.keys(value).filter((key) => !POLICY_KEYS.has(key));\n\tif (unknownKeys.length > 0) {\n\t\tdiagnostics.push(\n\t\t\t`workerDelegation.modelPins in ${scope} settings contains unknown fields: ${unknownKeys.join(\", \")}`,\n\t\t);\n\t}\n\tconst settings: WorkerModelPinsSettings = {};\n\tif (Object.hasOwn(value, \"default\")) {\n\t\tconst binding = parseBinding(value.default, scope, \"default\", diagnostics);\n\t\tif (binding) settings.default = binding;\n\t}\n\tif (Object.hasOwn(value, \"roles\")) {\n\t\tif (!isPlainRecord(value.roles)) {\n\t\t\tdiagnostics.push(`workerDelegation.modelPins.roles in ${scope} settings must be an object`);\n\t\t} else {\n\t\t\tconst roles: Partial<Record<WorkerRole, OrchestrationModelBinding>> = {};\n\t\t\tfor (const [role, candidate] of Object.entries(value.roles)) {\n\t\t\t\tif (!WORKER_ROLE_SET.has(role)) {\n\t\t\t\t\tdiagnostics.push(`workerDelegation.modelPins.roles in ${scope} settings contains unknown role: ${role}`);\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tconst binding = parseBinding(candidate, scope, `roles.${role}`, diagnostics);\n\t\t\t\tif (binding) roles[role as WorkerRole] = binding;\n\t\t\t}\n\t\t\tsettings.roles = roles;\n\t\t}\n\t}\n\treturn { present: true, settings, diagnostics };\n}\n\nfunction pinFromLayer(layer: NormalizedPinLayer | undefined, role: WorkerRole): ResolvedWorkerModelPin | undefined {\n\tif (!layer) return undefined;\n\tconst binding = layer.settings.roles?.[role] ?? layer.settings.default;\n\treturn binding ? { binding: cloneBinding(binding), source: layer.source } : undefined;\n}\n\nfunction pinFromLocalLayers(\n\tdirectoryLayer: NormalizedPinLayer | undefined,\n\tprojectLayer: NormalizedPinLayer | undefined,\n\trole: WorkerRole,\n): ResolvedWorkerModelPin | undefined {\n\tconst roleLayer = directoryLayer?.settings.roles?.[role]\n\t\t? directoryLayer\n\t\t: projectLayer?.settings.roles?.[role]\n\t\t\t? projectLayer\n\t\t\t: undefined;\n\tconst roleBinding = roleLayer?.settings.roles?.[role];\n\tif (roleLayer && roleBinding) {\n\t\treturn {\n\t\t\tbinding: cloneBinding(roleBinding),\n\t\t\tsource: roleLayer.source,\n\t\t};\n\t}\n\tconst defaultLayer = directoryLayer?.settings.default\n\t\t? directoryLayer\n\t\t: projectLayer?.settings.default\n\t\t\t? projectLayer\n\t\t\t: undefined;\n\treturn defaultLayer?.settings.default\n\t\t? { binding: cloneBinding(defaultLayer.settings.default), source: defaultLayer.source }\n\t\t: undefined;\n}\n\n/** Compile independently validated settings scopes into one immutable admission policy. */\nexport function compileWorkerModelPinPolicy(layers: WorkerModelPinPolicyLayers): WorkerModelPinPolicy {\n\tconst global = parseLayer(layers.global, \"global\");\n\tconst project = parseLayer(layers.project, \"project\");\n\tconst directoryProfile = parseLayer(layers.directoryProfile, \"directoryProfile\");\n\tconst diagnostics = [...global.diagnostics, ...project.diagnostics, ...directoryProfile.diagnostics];\n\tif (diagnostics.length > 0) return { status: \"invalid\", diagnostics };\n\tif (!global.present && !project.present && !directoryProfile.present) return { status: \"absent\" };\n\n\tconst globalLayer = global.settings ? { settings: global.settings, source: \"global\" as const } : undefined;\n\tconst projectLayer = project.settings ? { settings: project.settings, source: \"project\" as const } : undefined;\n\tconst directoryLayer = directoryProfile.settings\n\t\t? { settings: directoryProfile.settings, source: \"directoryProfile\" as const }\n\t\t: undefined;\n\tconst byRole: Partial<Record<WorkerRole, ResolvedWorkerModelPin>> = {};\n\tfor (const role of WORKER_ROLES) {\n\t\tconst pin = pinFromLayer(globalLayer, role) ?? pinFromLocalLayers(directoryLayer, projectLayer, role);\n\t\tif (pin) byRole[role] = pin;\n\t}\n\treturn Object.keys(byRole).length > 0 ? { status: \"active\", byRole } : { status: \"absent\" };\n}\n\nexport function resolveWorkerModelPin(\n\tpolicy: WorkerModelPinPolicy,\n\trole: WorkerRole,\n): ResolvedWorkerModelPin | undefined {\n\tif (policy.status !== \"active\") return undefined;\n\tconst pin = policy.byRole[role];\n\treturn pin ? { binding: cloneBinding(pin.binding), source: pin.source } : undefined;\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"provider-tool-text.d.ts","sourceRoot":"","sources":["../../src/core/provider-tool-text.ts"],"names":[],"mappings":"AAAA,uFAAuF;AACvF,eAAO,MAAM,+BAA+B,MAAM,CAAC;AACnD,eAAO,MAAM,iCAAiC,MAAM,CAAC;AACrD,eAAO,MAAM,kCAAkC,OAAQ,CAAC;
|
|
1
|
+
{"version":3,"file":"provider-tool-text.d.ts","sourceRoot":"","sources":["../../src/core/provider-tool-text.ts"],"names":[],"mappings":"AAAA,uFAAuF;AACvF,eAAO,MAAM,+BAA+B,MAAM,CAAC;AACnD,eAAO,MAAM,iCAAiC,MAAM,CAAC;AACrD,eAAO,MAAM,kCAAkC,OAAQ,CAAC;AAsBxD,wBAAgB,8BAA8B,CAAC,IAAI,EAAE,MAAM,GAAG,SAAS,GAAG,MAAM,GAAG,SAAS,CAK3F;AAED,wBAAgB,iCAAiC,CAAC,UAAU,EAAE,MAAM,EAAE,GAAG,SAAS,GAAG,MAAM,EAAE,CAmB5F"}
|
|
@@ -8,16 +8,27 @@ function oneLine(text) {
|
|
|
8
8
|
.replace(/\s+/g, " ")
|
|
9
9
|
.trim();
|
|
10
10
|
}
|
|
11
|
+
function truncateWithEllipsis(text, maxChars) {
|
|
12
|
+
if (text.length <= maxChars)
|
|
13
|
+
return text;
|
|
14
|
+
if (maxChars <= 0)
|
|
15
|
+
return "";
|
|
16
|
+
if (maxChars === 1)
|
|
17
|
+
return "…";
|
|
18
|
+
let end = maxChars - 1;
|
|
19
|
+
const finalCodeUnit = text.charCodeAt(end - 1);
|
|
20
|
+
if (finalCodeUnit >= 0xd800 && finalCodeUnit <= 0xdbff) {
|
|
21
|
+
end -= 1;
|
|
22
|
+
}
|
|
23
|
+
return `${text.slice(0, end).trimEnd()}…`;
|
|
24
|
+
}
|
|
11
25
|
export function normalizeProviderPromptSnippet(text) {
|
|
12
26
|
if (!text)
|
|
13
27
|
return undefined;
|
|
14
28
|
const normalized = oneLine(text);
|
|
15
29
|
if (normalized.length === 0)
|
|
16
30
|
return undefined;
|
|
17
|
-
|
|
18
|
-
throw new Error(`Provider tool snippet exceeds ${MAX_PROVIDER_TOOL_SNIPPET_CHARS} characters (${normalized.length}): ${normalized.slice(0, 48)}`);
|
|
19
|
-
}
|
|
20
|
-
return normalized;
|
|
31
|
+
return truncateWithEllipsis(normalized, MAX_PROVIDER_TOOL_SNIPPET_CHARS);
|
|
21
32
|
}
|
|
22
33
|
export function normalizeProviderPromptGuidelines(guidelines) {
|
|
23
34
|
if (!guidelines || guidelines.length === 0)
|
|
@@ -26,16 +37,21 @@ export function normalizeProviderPromptGuidelines(guidelines) {
|
|
|
26
37
|
let total = 0;
|
|
27
38
|
for (const guideline of guidelines) {
|
|
28
39
|
const normalized = oneLine(guideline);
|
|
29
|
-
if (normalized.length === 0
|
|
40
|
+
if (normalized.length === 0)
|
|
41
|
+
continue;
|
|
42
|
+
const bounded = truncateWithEllipsis(normalized, MAX_PROVIDER_TOOL_GUIDELINE_CHARS);
|
|
43
|
+
if (unique.has(bounded))
|
|
30
44
|
continue;
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
if (
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
45
|
+
const remaining = MAX_PROVIDER_TOOL_GUIDELINES_CHARS - total;
|
|
46
|
+
if (remaining <= 0)
|
|
47
|
+
break;
|
|
48
|
+
const admitted = truncateWithEllipsis(bounded, remaining);
|
|
49
|
+
if (admitted.length === 0)
|
|
50
|
+
break;
|
|
51
|
+
unique.add(admitted);
|
|
52
|
+
total += admitted.length;
|
|
53
|
+
if (admitted.length < bounded.length)
|
|
54
|
+
break;
|
|
39
55
|
}
|
|
40
56
|
return Array.from(unique);
|
|
41
57
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"provider-tool-text.js","sourceRoot":"","sources":["../../src/core/provider-tool-text.ts"],"names":[],"mappings":"AAAA,uFAAuF;AACvF,MAAM,CAAC,MAAM,+BAA+B,GAAG,GAAG,CAAC;AACnD,MAAM,CAAC,MAA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;AAC3B,CAAC","sourcesContent":["/** Provider-bound tool prose budgets. Structural schemas remain separate and exact. */\nexport const MAX_PROVIDER_TOOL_SNIPPET_CHARS = 120;\nexport const MAX_PROVIDER_TOOL_GUIDELINE_CHARS = 140;\nexport const MAX_PROVIDER_TOOL_GUIDELINES_CHARS = 1_200;\n\nfunction oneLine(text: string): string {\n\treturn text\n\t\t.replace(/[\\r\\n]+/g, \" \")\n\t\t.replace(/\\s+/g, \" \")\n\t\t.trim();\n}\n\nfunction truncateWithEllipsis(text: string, maxChars: number): string {\n\tif (text.length <= maxChars) return text;\n\tif (maxChars <= 0) return \"\";\n\tif (maxChars === 1) return \"…\";\n\n\tlet end = maxChars - 1;\n\tconst finalCodeUnit = text.charCodeAt(end - 1);\n\tif (finalCodeUnit >= 0xd800 && finalCodeUnit <= 0xdbff) {\n\t\tend -= 1;\n\t}\n\treturn `${text.slice(0, end).trimEnd()}…`;\n}\n\nexport function normalizeProviderPromptSnippet(text: string | undefined): string | undefined {\n\tif (!text) return undefined;\n\tconst normalized = oneLine(text);\n\tif (normalized.length === 0) return undefined;\n\treturn truncateWithEllipsis(normalized, MAX_PROVIDER_TOOL_SNIPPET_CHARS);\n}\n\nexport function normalizeProviderPromptGuidelines(guidelines: string[] | undefined): string[] {\n\tif (!guidelines || guidelines.length === 0) return [];\n\tconst unique = new Set<string>();\n\tlet total = 0;\n\tfor (const guideline of guidelines) {\n\t\tconst normalized = oneLine(guideline);\n\t\tif (normalized.length === 0) continue;\n\t\tconst bounded = truncateWithEllipsis(normalized, MAX_PROVIDER_TOOL_GUIDELINE_CHARS);\n\t\tif (unique.has(bounded)) continue;\n\n\t\tconst remaining = MAX_PROVIDER_TOOL_GUIDELINES_CHARS - total;\n\t\tif (remaining <= 0) break;\n\t\tconst admitted = truncateWithEllipsis(bounded, remaining);\n\t\tif (admitted.length === 0) break;\n\t\tunique.add(admitted);\n\t\ttotal += admitted.length;\n\t\tif (admitted.length < bounded.length) break;\n\t}\n\treturn Array.from(unique);\n}\n"]}
|