@bastani/atomic 0.9.28-alpha.1 → 0.9.28-alpha.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +33 -0
- package/dist/builtin/intercom/package.json +1 -1
- package/dist/builtin/mcp/package.json +1 -1
- package/dist/builtin/subagents/package.json +1 -1
- package/dist/builtin/web-access/package.json +1 -1
- package/dist/builtin/workflows/CHANGELOG.md +23 -0
- package/dist/builtin/workflows/builtin/{chunk-wz8v67bn.js → chunk-aqv8ny38.js} +257 -259
- package/dist/builtin/workflows/builtin/{chunk-f61w0hpm.js → chunk-br4ac9a3.js} +1 -1
- package/dist/builtin/workflows/builtin/{chunk-tecnpe8j.js → chunk-p3xmajmj.js} +438 -39
- package/dist/builtin/workflows/builtin/chunk-p6jagvyf.js +8 -0
- package/dist/builtin/workflows/builtin/goal.js +2 -2
- package/dist/builtin/workflows/builtin/index.js +4 -4
- package/dist/builtin/workflows/builtin/ralph.js +2 -2
- package/dist/builtin/workflows/package.json +1 -1
- package/dist/builtin/workflows/src/authoring.d.ts +14 -0
- package/dist/builtin/workflows/src/extension/index.bundle.mjs +107577 -106722
- package/dist/builtin/workflows/src/index.js +42284 -41141
- package/dist/builtin/workflows/src/shared/authoring-contract-stage.d.ts +16 -11
- package/dist/builtin/workflows/src/shared/authoring-contract-ui.d.ts +16 -1
- package/dist/cli/credential-print.d.ts +1 -1
- package/dist/cli/credential-print.d.ts.map +1 -1
- package/dist/cli/credential-print.js +2 -56
- package/dist/cli/credential-print.js.map +1 -1
- package/dist/core/agent-session-accessors.d.ts.map +1 -1
- package/dist/core/agent-session-accessors.js +6 -1
- package/dist/core/agent-session-accessors.js.map +1 -1
- package/dist/core/agent-session-compaction.d.ts.map +1 -1
- package/dist/core/agent-session-compaction.js +20 -3
- package/dist/core/agent-session-compaction.js.map +1 -1
- package/dist/core/agent-session-events.d.ts.map +1 -1
- package/dist/core/agent-session-events.js +2 -1
- package/dist/core/agent-session-events.js.map +1 -1
- package/dist/core/agent-session-extension-bindings.d.ts +6 -0
- package/dist/core/agent-session-extension-bindings.d.ts.map +1 -1
- package/dist/core/agent-session-extension-bindings.js +87 -7
- package/dist/core/agent-session-extension-bindings.js.map +1 -1
- package/dist/core/agent-session-methods.d.ts +2 -1
- package/dist/core/agent-session-methods.d.ts.map +1 -1
- package/dist/core/agent-session-methods.js.map +1 -1
- package/dist/core/agent-session-prompt.d.ts.map +1 -1
- package/dist/core/agent-session-prompt.js +14 -1
- package/dist/core/agent-session-prompt.js.map +1 -1
- package/dist/core/agent-session-tool-registry.d.ts.map +1 -1
- package/dist/core/agent-session-tool-registry.js +1 -0
- package/dist/core/agent-session-tool-registry.js.map +1 -1
- package/dist/core/agent-session-types.d.ts +1 -0
- package/dist/core/agent-session-types.d.ts.map +1 -1
- package/dist/core/agent-session-types.js.map +1 -1
- package/dist/core/compaction/classifier-compaction.d.ts +13 -0
- package/dist/core/compaction/classifier-compaction.d.ts.map +1 -0
- package/dist/core/compaction/classifier-compaction.js +110 -0
- package/dist/core/compaction/classifier-compaction.js.map +1 -0
- package/dist/core/compaction/compaction-boundary.d.ts.map +1 -1
- package/dist/core/compaction/compaction-boundary.js +2 -6
- package/dist/core/compaction/compaction-boundary.js.map +1 -1
- package/dist/core/compaction/compaction-runner.d.ts +16 -1
- package/dist/core/compaction/compaction-runner.d.ts.map +1 -1
- package/dist/core/compaction/compaction-runner.js +97 -12
- package/dist/core/compaction/compaction-runner.js.map +1 -1
- package/dist/core/compaction/compaction-types.d.ts +18 -1
- package/dist/core/compaction/compaction-types.d.ts.map +1 -1
- package/dist/core/compaction/compaction-types.js +1 -1
- package/dist/core/compaction/compaction-types.js.map +1 -1
- package/dist/core/compaction/fallback-planner.d.ts +1 -0
- package/dist/core/compaction/fallback-planner.d.ts.map +1 -1
- package/dist/core/compaction/fallback-planner.js +2 -0
- package/dist/core/compaction/fallback-planner.js.map +1 -1
- package/dist/core/compaction/index.d.ts +3 -0
- package/dist/core/compaction/index.d.ts.map +1 -1
- package/dist/core/compaction/index.js +3 -0
- package/dist/core/compaction/index.js.map +1 -1
- package/dist/core/compaction/model-resolver.d.ts +16 -0
- package/dist/core/compaction/model-resolver.d.ts.map +1 -0
- package/dist/core/compaction/model-resolver.js +18 -0
- package/dist/core/compaction/model-resolver.js.map +1 -0
- package/dist/core/compaction/morph-compaction.d.ts +14 -0
- package/dist/core/compaction/morph-compaction.d.ts.map +1 -0
- package/dist/core/compaction/morph-compaction.js +99 -0
- package/dist/core/compaction/morph-compaction.js.map +1 -0
- package/dist/core/compaction/pi-summary-fallback.d.ts +34 -0
- package/dist/core/compaction/pi-summary-fallback.d.ts.map +1 -0
- package/dist/core/compaction/pi-summary-fallback.js +357 -0
- package/dist/core/compaction/pi-summary-fallback.js.map +1 -0
- package/dist/core/compaction/planner-outcome.d.ts +10 -6
- package/dist/core/compaction/planner-outcome.d.ts.map +1 -1
- package/dist/core/compaction/planner-outcome.js +11 -4
- package/dist/core/compaction/planner-outcome.js.map +1 -1
- package/dist/core/compaction/range-planner-diagnostics.d.ts +3 -1
- package/dist/core/compaction/range-planner-diagnostics.d.ts.map +1 -1
- package/dist/core/compaction/range-planner-diagnostics.js +11 -0
- package/dist/core/compaction/range-planner-diagnostics.js.map +1 -1
- package/dist/core/compaction/range-planner.d.ts +3 -3
- package/dist/core/compaction/range-planner.d.ts.map +1 -1
- package/dist/core/compaction/range-planner.js +59 -28
- package/dist/core/compaction/range-planner.js.map +1 -1
- package/dist/core/compaction/region-trimming.d.ts.map +1 -1
- package/dist/core/compaction/region-trimming.js +7 -0
- package/dist/core/compaction/region-trimming.js.map +1 -1
- package/dist/core/compaction/structured-compaction-input.d.ts +19 -0
- package/dist/core/compaction/structured-compaction-input.d.ts.map +1 -0
- package/dist/core/compaction/structured-compaction-input.js +70 -0
- package/dist/core/compaction/structured-compaction-input.js.map +1 -0
- package/dist/core/compaction/transcript-serialization.d.ts +1 -0
- package/dist/core/compaction/transcript-serialization.d.ts.map +1 -1
- package/dist/core/compaction/transcript-serialization.js +26 -0
- package/dist/core/compaction/transcript-serialization.js.map +1 -1
- package/dist/core/extensions/api-types.d.ts +2 -2
- package/dist/core/extensions/api-types.d.ts.map +1 -1
- package/dist/core/extensions/api-types.js.map +1 -1
- package/dist/core/extensions/context-types.d.ts +1 -0
- package/dist/core/extensions/context-types.d.ts.map +1 -1
- package/dist/core/extensions/context-types.js.map +1 -1
- package/dist/core/extensions/loader-api.js.map +1 -1
- package/dist/core/extensions/runner-context.d.ts +10 -4
- package/dist/core/extensions/runner-context.d.ts.map +1 -1
- package/dist/core/extensions/runner-context.js +47 -3
- package/dist/core/extensions/runner-context.js.map +1 -1
- package/dist/core/extensions/runner.d.ts +10 -3
- package/dist/core/extensions/runner.d.ts.map +1 -1
- package/dist/core/extensions/runner.js +31 -7
- package/dist/core/extensions/runner.js.map +1 -1
- package/dist/core/extensions/workflow-events.d.ts +49 -0
- package/dist/core/extensions/workflow-events.d.ts.map +1 -1
- package/dist/core/extensions/workflow-events.js.map +1 -1
- package/dist/core/extensions/workflow-run-control-hub.d.ts +16 -4
- package/dist/core/extensions/workflow-run-control-hub.d.ts.map +1 -1
- package/dist/core/extensions/workflow-run-control-hub.js +72 -1
- package/dist/core/extensions/workflow-run-control-hub.js.map +1 -1
- package/dist/core/extensions/workflow-run-control.d.ts +11 -3
- package/dist/core/extensions/workflow-run-control.d.ts.map +1 -1
- package/dist/core/extensions/workflow-run-control.js.map +1 -1
- package/dist/core/messages.d.ts +1 -0
- package/dist/core/messages.d.ts.map +1 -1
- package/dist/core/messages.js +5 -1
- package/dist/core/messages.js.map +1 -1
- package/dist/core/remote-catalog-provider.d.ts.map +1 -1
- package/dist/core/remote-catalog-provider.js +3 -0
- package/dist/core/remote-catalog-provider.js.map +1 -1
- package/dist/core/session-manager-history.d.ts.map +1 -1
- package/dist/core/session-manager-history.js +4 -2
- package/dist/core/session-manager-history.js.map +1 -1
- package/dist/core/settings-manager-basic-accessors.d.ts +2 -0
- package/dist/core/settings-manager-basic-accessors.d.ts.map +1 -1
- package/dist/core/settings-manager-basic-accessors.js +29 -0
- package/dist/core/settings-manager-basic-accessors.js.map +1 -1
- package/dist/core/settings-types.d.ts +1 -0
- package/dist/core/settings-types.d.ts.map +1 -1
- package/dist/core/settings-types.js.map +1 -1
- package/dist/core/transcript.d.ts +58 -0
- package/dist/core/transcript.d.ts.map +1 -0
- package/dist/core/transcript.js +185 -0
- package/dist/core/transcript.js.map +1 -0
- package/dist/extensions/herdr/index.d.ts.map +1 -1
- package/dist/extensions/herdr/index.js +15 -10
- package/dist/extensions/herdr/index.js.map +1 -1
- package/dist/extensions/herdr/pane-owner.d.ts +6 -2
- package/dist/extensions/herdr/pane-owner.d.ts.map +1 -1
- package/dist/extensions/herdr/pane-owner.js +19 -4
- package/dist/extensions/herdr/pane-owner.js.map +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/modes/interactive/components/compaction-boundary-message.d.ts +2 -0
- package/dist/modes/interactive/components/compaction-boundary-message.d.ts.map +1 -1
- package/dist/modes/interactive/components/compaction-boundary-message.js +15 -3
- package/dist/modes/interactive/components/compaction-boundary-message.js.map +1 -1
- package/dist/modes/interactive/components/settings-selector-items.d.ts.map +1 -1
- package/dist/modes/interactive/components/settings-selector-items.js +43 -0
- package/dist/modes/interactive/components/settings-selector-items.js.map +1 -1
- package/dist/modes/interactive/components/settings-selector-types.d.ts +6 -0
- package/dist/modes/interactive/components/settings-selector-types.d.ts.map +1 -1
- package/dist/modes/interactive/components/settings-selector-types.js.map +1 -1
- package/dist/modes/interactive/interactive-prompt-turn.js +6 -4
- package/dist/modes/interactive/interactive-prompt-turn.js.map +1 -1
- package/dist/modes/interactive/interactive-render-chat.js +13 -1
- package/dist/modes/interactive/interactive-render-chat.js.map +1 -1
- package/dist/modes/interactive/interactive-selectors.js +8 -0
- package/dist/modes/interactive/interactive-selectors.js.map +1 -1
- package/dist/modes/interactive/interactive-session-runtime.js +2 -0
- package/dist/modes/interactive/interactive-session-runtime.js.map +1 -1
- package/dist/modes/interactive/interactive-startup.js +1 -1
- package/dist/modes/interactive/interactive-startup.js.map +1 -1
- package/dist/utils/credential-redaction.d.ts +2 -0
- package/dist/utils/credential-redaction.d.ts.map +1 -0
- package/dist/utils/credential-redaction.js +20 -0
- package/dist/utils/credential-redaction.js.map +1 -0
- package/docs/compaction/reference.md +10 -4
- package/docs/compaction.md +40 -8
- package/docs/docs.json +1 -0
- package/docs/extensions/api-reference.md +4 -0
- package/docs/extensions/events.md +2 -2
- package/docs/providers.md +12 -1
- package/docs/sdk/reference.md +16 -1
- package/docs/sdk/web-server.md +325 -0
- package/docs/sdk.md +83 -1
- package/docs/security.md +1 -1
- package/docs/workflows/api-reference.md +71 -3
- package/docs/workflows/builtins.md +4 -0
- package/docs/workflows/operations.md +12 -4
- package/npm-shrinkwrap.json +32 -32
- package/package.json +3 -3
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { WorkflowRunControlUnavailableError, } from "./workflow-run-control.js";
|
|
2
|
+
/** Session disposal waits at most this long for observers to receive the final `unavailable` snapshot. */
|
|
3
|
+
const OBSERVER_FINAL_DELIVERY_TIMEOUT_MS = 5_000;
|
|
2
4
|
/** Holds the run-control implementation that the workflows extension registers for one extension generation. */
|
|
3
5
|
export class WorkflowRunControlHub {
|
|
4
6
|
control;
|
|
@@ -25,8 +27,11 @@ export class WorkflowRunControlHub {
|
|
|
25
27
|
/** Stable per-session handle that follows the current extension generation across reloads. */
|
|
26
28
|
export class SessionWorkflowsHandle {
|
|
27
29
|
resolve;
|
|
28
|
-
|
|
30
|
+
resolveObserve;
|
|
31
|
+
observers = new Set();
|
|
32
|
+
constructor(resolve, resolveObserve) {
|
|
29
33
|
this.resolve = resolve;
|
|
34
|
+
this.resolveObserve = resolveObserve;
|
|
30
35
|
}
|
|
31
36
|
control() {
|
|
32
37
|
const control = this.resolve();
|
|
@@ -34,6 +39,72 @@ export class SessionWorkflowsHandle {
|
|
|
34
39
|
throw new WorkflowRunControlUnavailableError();
|
|
35
40
|
return control;
|
|
36
41
|
}
|
|
42
|
+
observe(observer) {
|
|
43
|
+
const observe = this.resolveObserve();
|
|
44
|
+
if (observe === undefined)
|
|
45
|
+
throw new WorkflowRunControlUnavailableError();
|
|
46
|
+
let active = true;
|
|
47
|
+
let previous = Promise.resolve();
|
|
48
|
+
// Each generation delivers independently; chain them so a reload never overlaps two callbacks.
|
|
49
|
+
const deliver = (frame) => {
|
|
50
|
+
const delivery = previous.then(() => (active ? observer(frame) : undefined));
|
|
51
|
+
previous = delivery.catch(() => { });
|
|
52
|
+
return delivery;
|
|
53
|
+
};
|
|
54
|
+
const lease = {
|
|
55
|
+
deliver,
|
|
56
|
+
close: () => {
|
|
57
|
+
if (!active)
|
|
58
|
+
return;
|
|
59
|
+
active = false;
|
|
60
|
+
lease.subscription.dispose();
|
|
61
|
+
},
|
|
62
|
+
subscription: observe(deliver),
|
|
63
|
+
};
|
|
64
|
+
this.observers.add(lease);
|
|
65
|
+
return {
|
|
66
|
+
// Close even after session disposal took the lease out of the set, so a queued final callback is skipped.
|
|
67
|
+
dispose: () => {
|
|
68
|
+
this.observers.delete(lease);
|
|
69
|
+
lease.close();
|
|
70
|
+
},
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
/** Move every observer to the current extension generation; each receives that generation's snapshot first. */
|
|
74
|
+
rebindObservers() {
|
|
75
|
+
const observe = this.resolveObserve();
|
|
76
|
+
for (const lease of this.observers) {
|
|
77
|
+
lease.subscription.dispose();
|
|
78
|
+
lease.subscription = observe?.(lease.deliver) ?? { dispose: () => { } };
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Release every observer when the session closes. Each first receives `last` as an `unavailable`
|
|
83
|
+
* snapshot, after any callback already in flight, so hosts never keep showing a closed session's runs.
|
|
84
|
+
*/
|
|
85
|
+
async disposeObservers(last) {
|
|
86
|
+
const terminal = last.availability === "unavailable"
|
|
87
|
+
? last
|
|
88
|
+
: {
|
|
89
|
+
kind: "snapshot",
|
|
90
|
+
cursor: { ...last.cursor, revision: last.cursor.revision + 1 },
|
|
91
|
+
availability: "unavailable",
|
|
92
|
+
};
|
|
93
|
+
const leases = [...this.observers];
|
|
94
|
+
this.observers.clear();
|
|
95
|
+
for (const lease of leases)
|
|
96
|
+
lease.subscription.dispose();
|
|
97
|
+
let timer;
|
|
98
|
+
await Promise.race([
|
|
99
|
+
Promise.all(leases.map((lease) => Promise.resolve(lease.deliver(structuredClone(terminal))).catch(() => { }))),
|
|
100
|
+
new Promise((resolve) => {
|
|
101
|
+
timer = setTimeout(resolve, OBSERVER_FINAL_DELIVERY_TIMEOUT_MS);
|
|
102
|
+
}),
|
|
103
|
+
]);
|
|
104
|
+
clearTimeout(timer);
|
|
105
|
+
for (const lease of leases)
|
|
106
|
+
lease.close();
|
|
107
|
+
}
|
|
37
108
|
async listRuns(filter) {
|
|
38
109
|
return this.control().listRuns(filter);
|
|
39
110
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"workflow-run-control-hub.js","sourceRoot":"","sources":["../../../src/core/extensions/workflow-run-control-hub.ts"],"names":[],"mappings":"AAAA,OAAO,EAKN,kCAAkC,GAQlC,MAAM,2BAA2B,CAAC;AAEnC,gHAAgH;AAChH,MAAM,OAAO,qBAAqB;IACzB,OAAO,CAA+B;IACtC,QAAQ,GAAG,KAAK,CAAC;IAEzB,QAAQ,CAAC,OAAyB;QACjC,IAAI,IAAI,CAAC,QAAQ;YAAE,OAAO,EAAE,OAAO,EAAE,GAAG,EAAE,GAAE,CAAC,EAAE,CAAC;QAChD,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,OAAO;YACN,OAAO,EAAE,GAAG,EAAE;gBACb,IAAI,IAAI,CAAC,OAAO,KAAK,OAAO;oBAAE,IAAI,CAAC,OAAO,GAAG,SAAS,CAAC;YACxD,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AAC,OAAO,EAAE,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IACpC,CAAC;IAED,KAAK,CAAC,MAAM,CAAC,KAAa,EAAE,OAAkC;QAC7D,OAAO,IAAI,CAAC,OAAO,EAAE,CAAC,MAAM,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;IAC9C,CAAC;CACD","sourcesContent":["import {\n\ttype SessionWorkflows,\n\ttype WorkflowRunAllTarget,\n\ttype WorkflowRunControlOutcome,\n\ttype WorkflowRunControlRegistration,\n\tWorkflowRunControlUnavailableError,\n\ttype WorkflowRunDetail,\n\ttype WorkflowRunListFilter,\n\ttype WorkflowRunPauseOptions,\n\ttype WorkflowRunResumeOptions,\n\ttype WorkflowRunStageSummary,\n\ttype WorkflowRunSummary,\n\ttype WorkflowStageListFilter,\n} from \"./workflow-run-control.js\";\n\n/** Holds the run-control implementation that the workflows extension registers for one extension generation. */\nexport class WorkflowRunControlHub {\n\tprivate control: SessionWorkflows | undefined;\n\tprivate disposed = false;\n\n\tregister(control: SessionWorkflows): WorkflowRunControlRegistration {\n\t\tif (this.disposed) return { dispose: () => {} };\n\t\tthis.control = control;\n\t\treturn {\n\t\t\tdispose: () => {\n\t\t\t\tif (this.control === control) this.control = undefined;\n\t\t\t},\n\t\t};\n\t}\n\n\tcurrent(): SessionWorkflows | undefined {\n\t\treturn this.control;\n\t}\n\n\tdispose(): void {\n\t\tthis.disposed = true;\n\t\tthis.control = undefined;\n\t}\n}\n\n/** Stable per-session handle that follows the current extension generation across reloads. */\nexport class SessionWorkflowsHandle implements SessionWorkflows {\n\tprivate readonly resolve: () => SessionWorkflows | undefined;\n\n\tconstructor(resolve: () => SessionWorkflows | undefined) {\n\t\tthis.resolve = resolve;\n\t}\n\n\tprivate control(): SessionWorkflows {\n\t\tconst control = this.resolve();\n\t\tif (control === undefined) throw new WorkflowRunControlUnavailableError();\n\t\treturn control;\n\t}\n\n\tasync listRuns(filter?: WorkflowRunListFilter): Promise<readonly WorkflowRunSummary[]> {\n\t\treturn this.control().listRuns(filter);\n\t}\n\n\tasync getRun(runId: string): Promise<WorkflowRunDetail> {\n\t\treturn this.control().getRun(runId);\n\t}\n\n\tasync getStages(runId: string, filter?: WorkflowStageListFilter): Promise<readonly WorkflowRunStageSummary[]> {\n\t\treturn this.control().getStages(runId, filter);\n\t}\n\n\tpause(runId: string, options?: WorkflowRunPauseOptions): Promise<WorkflowRunControlOutcome>;\n\tpause(target: WorkflowRunAllTarget): Promise<WorkflowRunControlOutcome>;\n\tasync pause(\n\t\ttarget: string | WorkflowRunAllTarget,\n\t\toptions?: WorkflowRunPauseOptions,\n\t): Promise<WorkflowRunControlOutcome> {\n\t\tconst control = this.control();\n\t\treturn typeof target === \"string\" ? control.pause(target, options) : control.pause(target);\n\t}\n\n\tasync quit(target: string | WorkflowRunAllTarget): Promise<WorkflowRunControlOutcome> {\n\t\treturn this.control().quit(target);\n\t}\n\n\tasync resume(runId: string, options?: WorkflowRunResumeOptions): Promise<WorkflowRunControlOutcome> {\n\t\treturn this.control().resume(runId, options);\n\t}\n}\n"]}
|
|
1
|
+
{"version":3,"file":"workflow-run-control-hub.js","sourceRoot":"","sources":["../../../src/core/extensions/workflow-run-control-hub.ts"],"names":[],"mappings":"AAKA,OAAO,EAMN,kCAAkC,GAQlC,MAAM,2BAA2B,CAAC;AAEnC,0GAA0G;AAC1G,MAAM,kCAAkC,GAAG,KAAK,CAAC;AAEjD,gHAAgH;AAChH,MAAM,OAAO,qBAAqB;IACzB,OAAO,CAAiC;IACxC,QAAQ,GAAG,KAAK,CAAC;IAEzB,QAAQ,CAAC,OAA2B;QACnC,IAAI,IAAI,CAAC,QAAQ;YAAE,OAAO,EAAE,OAAO,EAAE,GAAG,EAAE,GAAE,CAAC,EAAE,CAAC;QAChD,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,OAAO;YACN,OAAO,EAAE,GAAG,EAAE;gBACb,IAAI,IAAI,CAAC,OAAO,KAAK,OAAO;oBAAE,IAAI,CAA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MAAM,KAAK,QAAQ,CAAC,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;IAC5F,CAAC;IAED,KAAK,CAAC,IAAI,CAAC,MAAqC;QAC/C,OAAO,IAAI,CAAC,OAAO,EAAE,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IACpC,CAAC;IAED,KAAK,CAAC,MAAM,CAAC,KAAa,EAAE,OAAkC;QAC7D,OAAO,IAAI,CAAC,OAAO,EAAE,CAAC,MAAM,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;IAC9C,CAAC;CACD","sourcesContent":["import type {\n\tWorkflowActivityObserver,\n\tWorkflowActivitySnapshotFrame,\n\tWorkflowActivitySubscription,\n} from \"./workflow-events.js\";\nimport {\n\ttype SessionWorkflows,\n\ttype WorkflowRunAllTarget,\n\ttype WorkflowRunControl,\n\ttype WorkflowRunControlOutcome,\n\ttype WorkflowRunControlRegistration,\n\tWorkflowRunControlUnavailableError,\n\ttype WorkflowRunDetail,\n\ttype WorkflowRunListFilter,\n\ttype WorkflowRunPauseOptions,\n\ttype WorkflowRunResumeOptions,\n\ttype WorkflowRunStageSummary,\n\ttype WorkflowRunSummary,\n\ttype WorkflowStageListFilter,\n} from \"./workflow-run-control.js\";\n\n/** Session disposal waits at most this long for observers to receive the final `unavailable` snapshot. */\nconst OBSERVER_FINAL_DELIVERY_TIMEOUT_MS = 5_000;\n\n/** Holds the run-control implementation that the workflows extension registers for one extension generation. */\nexport class WorkflowRunControlHub {\n\tprivate control: WorkflowRunControl | undefined;\n\tprivate disposed = false;\n\n\tregister(control: WorkflowRunControl): WorkflowRunControlRegistration {\n\t\tif (this.disposed) return { dispose: () => {} };\n\t\tthis.control = control;\n\t\treturn {\n\t\t\tdispose: () => {\n\t\t\t\tif (this.control === control) this.control = undefined;\n\t\t\t},\n\t\t};\n\t}\n\n\tcurrent(): WorkflowRunControl | undefined {\n\t\treturn this.control;\n\t}\n\n\tdispose(): void {\n\t\tthis.disposed = true;\n\t\tthis.control = undefined;\n\t}\n}\n\nexport type ObserveWorkflowActivity = (observer: WorkflowActivityObserver) => WorkflowActivitySubscription;\n\ninterface SessionObserverLease {\n\t/** Serialized delivery shared by every generation this observer is bound to. */\n\treadonly deliver: WorkflowActivityObserver;\n\treadonly close: () => void;\n\tsubscription: WorkflowActivitySubscription;\n}\n\n/** Stable per-session handle that follows the current extension generation across reloads. */\nexport class SessionWorkflowsHandle implements SessionWorkflows {\n\tprivate readonly resolve: () => WorkflowRunControl | undefined;\n\tprivate readonly resolveObserve: () => ObserveWorkflowActivity | undefined;\n\tprivate readonly observers = new Set<SessionObserverLease>();\n\n\tconstructor(\n\t\tresolve: () => WorkflowRunControl | undefined,\n\t\tresolveObserve: () => ObserveWorkflowActivity | undefined,\n\t) {\n\t\tthis.resolve = resolve;\n\t\tthis.resolveObserve = resolveObserve;\n\t}\n\n\tprivate control(): WorkflowRunControl {\n\t\tconst control = this.resolve();\n\t\tif (control === undefined) throw new WorkflowRunControlUnavailableError();\n\t\treturn control;\n\t}\n\n\tobserve(observer: WorkflowActivityObserver): WorkflowActivitySubscription {\n\t\tconst observe = this.resolveObserve();\n\t\tif (observe === undefined) throw new WorkflowRunControlUnavailableError();\n\t\tlet active = true;\n\t\tlet previous: Promise<void> = Promise.resolve();\n\t\t// Each generation delivers independently; chain them so a reload never overlaps two callbacks.\n\t\tconst deliver: WorkflowActivityObserver = (frame) => {\n\t\t\tconst delivery = previous.then(() => (active ? observer(frame) : undefined));\n\t\t\tprevious = delivery.catch(() => {});\n\t\t\treturn delivery;\n\t\t};\n\t\tconst lease: SessionObserverLease = {\n\t\t\tdeliver,\n\t\t\tclose: () => {\n\t\t\t\tif (!active) return;\n\t\t\t\tactive = false;\n\t\t\t\tlease.subscription.dispose();\n\t\t\t},\n\t\t\tsubscription: observe(deliver),\n\t\t};\n\t\tthis.observers.add(lease);\n\t\treturn {\n\t\t\t// Close even after session disposal took the lease out of the set, so a queued final callback is skipped.\n\t\t\tdispose: () => {\n\t\t\t\tthis.observers.delete(lease);\n\t\t\t\tlease.close();\n\t\t\t},\n\t\t};\n\t}\n\n\t/** Move every observer to the current extension generation; each receives that generation's snapshot first. */\n\trebindObservers(): void {\n\t\tconst observe = this.resolveObserve();\n\t\tfor (const lease of this.observers) {\n\t\t\tlease.subscription.dispose();\n\t\t\tlease.subscription = observe?.(lease.deliver) ?? { dispose: () => {} };\n\t\t}\n\t}\n\n\t/**\n\t * Release every observer when the session closes. Each first receives `last` as an `unavailable`\n\t * snapshot, after any callback already in flight, so hosts never keep showing a closed session's runs.\n\t */\n\tasync disposeObservers(last: WorkflowActivitySnapshotFrame): Promise<void> {\n\t\tconst terminal: WorkflowActivitySnapshotFrame =\n\t\t\tlast.availability === \"unavailable\"\n\t\t\t\t? last\n\t\t\t\t: {\n\t\t\t\t\t\tkind: \"snapshot\",\n\t\t\t\t\t\tcursor: { ...last.cursor, revision: last.cursor.revision + 1 },\n\t\t\t\t\t\tavailability: \"unavailable\",\n\t\t\t\t\t};\n\t\tconst leases = [...this.observers];\n\t\tthis.observers.clear();\n\t\tfor (const lease of leases) lease.subscription.dispose();\n\t\tlet timer: ReturnType<typeof setTimeout> | undefined;\n\t\tawait Promise.race([\n\t\t\tPromise.all(leases.map((lease) => Promise.resolve(lease.deliver(structuredClone(terminal))).catch(() => {}))),\n\t\t\tnew Promise<void>((resolve) => {\n\t\t\t\ttimer = setTimeout(resolve, OBSERVER_FINAL_DELIVERY_TIMEOUT_MS);\n\t\t\t}),\n\t\t]);\n\t\tclearTimeout(timer);\n\t\tfor (const lease of leases) lease.close();\n\t}\n\n\tasync listRuns(filter?: WorkflowRunListFilter): Promise<readonly WorkflowRunSummary[]> {\n\t\treturn this.control().listRuns(filter);\n\t}\n\n\tasync getRun(runId: string): Promise<WorkflowRunDetail> {\n\t\treturn this.control().getRun(runId);\n\t}\n\n\tasync getStages(runId: string, filter?: WorkflowStageListFilter): Promise<readonly WorkflowRunStageSummary[]> {\n\t\treturn this.control().getStages(runId, filter);\n\t}\n\n\tpause(runId: string, options?: WorkflowRunPauseOptions): Promise<WorkflowRunControlOutcome>;\n\tpause(target: WorkflowRunAllTarget): Promise<WorkflowRunControlOutcome>;\n\tasync pause(\n\t\ttarget: string | WorkflowRunAllTarget,\n\t\toptions?: WorkflowRunPauseOptions,\n\t): Promise<WorkflowRunControlOutcome> {\n\t\tconst control = this.control();\n\t\treturn typeof target === \"string\" ? control.pause(target, options) : control.pause(target);\n\t}\n\n\tasync quit(target: string | WorkflowRunAllTarget): Promise<WorkflowRunControlOutcome> {\n\t\treturn this.control().quit(target);\n\t}\n\n\tasync resume(runId: string, options?: WorkflowRunResumeOptions): Promise<WorkflowRunControlOutcome> {\n\t\treturn this.control().resume(runId, options);\n\t}\n}\n"]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { WorkflowRunStatus, WorkflowStageStatus } from "./workflow-events.js";
|
|
1
|
+
import type { WorkflowActivityObserver, WorkflowActivitySubscription, WorkflowRunStatus, WorkflowStageStatus } from "./workflow-events.js";
|
|
2
2
|
export type WorkflowRunJsonValue = string | number | boolean | null | readonly WorkflowRunJsonValue[] | WorkflowRunJsonObject;
|
|
3
3
|
export interface WorkflowRunJsonObject {
|
|
4
4
|
readonly [key: string]: WorkflowRunJsonValue | undefined;
|
|
@@ -105,8 +105,8 @@ export interface WorkflowRunControlOutcome {
|
|
|
105
105
|
readonly abandoned?: boolean;
|
|
106
106
|
readonly failedRuns?: readonly WorkflowRunControlFailedRun[];
|
|
107
107
|
}
|
|
108
|
-
/** Typed run management for the workflow runs owned by one session. */
|
|
109
|
-
export interface
|
|
108
|
+
/** Typed run management for the workflow runs owned by one session, as registered by the workflows extension. */
|
|
109
|
+
export interface WorkflowRunControl {
|
|
110
110
|
listRuns(filter?: WorkflowRunListFilter): Promise<readonly WorkflowRunSummary[]>;
|
|
111
111
|
getRun(runId: string): Promise<WorkflowRunDetail>;
|
|
112
112
|
getStages(runId: string, filter?: WorkflowStageListFilter): Promise<readonly WorkflowRunStageSummary[]>;
|
|
@@ -115,6 +115,14 @@ export interface SessionWorkflows {
|
|
|
115
115
|
quit(target: string | WorkflowRunAllTarget): Promise<WorkflowRunControlOutcome>;
|
|
116
116
|
resume(runId: string, options?: WorkflowRunResumeOptions): Promise<WorkflowRunControlOutcome>;
|
|
117
117
|
}
|
|
118
|
+
/** `session.workflows`: run management plus observation of the workflow runs owned by one session. */
|
|
119
|
+
export interface SessionWorkflows extends WorkflowRunControl {
|
|
120
|
+
/**
|
|
121
|
+
* Follow root activity and graph changes. Delivers a snapshot frame first, then FIFO
|
|
122
|
+
* `changed` and `removed` frames; the subscription follows extension reloads.
|
|
123
|
+
*/
|
|
124
|
+
observe(observer: WorkflowActivityObserver): WorkflowActivitySubscription;
|
|
125
|
+
}
|
|
118
126
|
export interface WorkflowRunControlRegistration {
|
|
119
127
|
dispose(): void;
|
|
120
128
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"workflow-run-control.d.ts","sourceRoot":"","sources":["../../../src/core/extensions/workflow-run-control.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"workflow-run-control.d.ts","sourceRoot":"","sources":["../../../src/core/extensions/workflow-run-control.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACX,wBAAwB,EACxB,4BAA4B,EAC5B,iBAAiB,EACjB,mBAAmB,EACnB,MAAM,sBAAsB,CAAC;AAE9B,MAAM,MAAM,oBAAoB,GAC7B,MAAM,GACN,MAAM,GACN,OAAO,GACP,IAAI,GACJ,SAAS,oBAAoB,EAAE,GAC/B,qBAAqB,CAAC;AAEzB,MAAM,WAAW,qBAAqB;IACrC,QAAQ,EAAE,GAAG,EAAE,MAAM,GAAG,oBAAoB,GAAG,SAAS,CAAC;CACzD;AAED,MAAM,MAAM,uBAAuB,GAAG,iBAAiB,GAAG,mBA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AIxC;CACD"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"workflow-run-control.js","sourceRoot":"","sources":["../../../src/core/extensions/workflow-run-control.ts"],"names":[],"mappings":"AA+JA,2FAA2F;AAC3F,MAAM,OAAO,uBAAwB,SAAQ,KAAK;IACxC,IAAI,CAA8B;IAClC,KAAK,CAAU;IACxB,mFAAmF;IAC1E,UAAU,CAA0C;IAE7D,YAAY,IAAiC,EAAE,OAAe,EAAE,OAAO,GAAmC,EAAE;QAC3G,KAAK,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;QACxB,IAAI,CAAC,IAAI,GAAG,yBAAyB,CAAC;QACtC,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,OAAO,CAAC,KAAK,KAAK,SAAS;YAAE,IAAI,CAAC,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC;QAC5D,IAAI,OAAO,CAAC,UAAU,KAAK,SAAS;YAAE,IAAI,CAAC,UAAU,GAAG,OAAO,CAAC,UAAU,CAAC;IAC5E,CAAC;CACD;AAED,gEAAgE;AAChE,MAAM,OAAO,wBAAyB,SAAQ,uBAAuB;IACpE,YAAY,OAAe,EAAE,OAAwC;QACpE,KAAK,CAAC,wBAAwB,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC;QAClD,IAAI,CAAC,IAAI,GAAG,0BAA0B,CAAC;IACxC,CAAC;CACD;AAED,yFAAyF;AACzF,MAAM,OAAO,yBAA0B,SAAQ,uBAAuB;IACrE,YAAY,OAAe,EAAE,OAAwC;QACpE,KAAK,CAAC,8BAA8B,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC;QACxD,IAAI,CAAC,IAAI,GAAG,2BAA2B,CAAC;IACzC,CAAC;CACD;AAED,mGAAmG;AACnG,MAAM,OAAO,4BAA6B,SAAQ,uBAAuB;IACxE,YAAY,OAAe,EAAE,OAAwC;QACpE,KAAK,CAAC,4BAA4B,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC;QACtD,IAAI,CAAC,IAAI,GAAG,8BAA8B,CAAC;IAC5C,CAAC;CACD;AAED,qEAAqE;AACrE,MAAM,OAAO,0BAA2B,SAAQ,uBAAuB;IACtE,YAAY,OAAe,EAAE,OAAwC;QACpE,KAAK,CAAC,0BAA0B,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC;QACpD,IAAI,CAAC,IAAI,GAAG,4BAA4B,CAAC;IAC1C,CAAC;CACD;AAED,sGAAsG;AACtG,MAAM,OAAO,2BAA4B,SAAQ,uBAAuB;IACvE,YAAY,OAAe,EAAE,OAAwC;QACpE,KAAK,CAAC,0BAA0B,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC;QACpD,IAAI,CAAC,IAAI,GAAG,6BAA6B,CAAC;IAC3C,CAAC;CACD;AAED,qFAAqF;AACrF,MAAM,OAAO,mCAAoC,SAAQ,uBAAuB;IAC/E,YAAY,OAAe,EAAE,OAAwC;QACpE,KAAK,CAAC,mCAAmC,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC;QAC7D,IAAI,CAAC,IAAI,GAAG,qCAAqC,CAAC;IACnD,CAAC;CACD;AAED,mFAAmF;AACnF,MAAM,OAAO,wBAAyB,SAAQ,uBAAuB;IACpE,YAAY,OAAe,EAAE,OAAwC;QACpE,KAAK,CAAC,uBAAuB,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC;QACjD,IAAI,CAAC,IAAI,GAAG,0BAA0B,CAAC;IACxC,CAAC;CACD;AAED,2FAA2F;AAC3F,MAAM,OAAO,kCAAmC,SAAQ,uBAAuB;IAC9E,YACC,OAAO,GAAG,uDAAuD,EACjE,OAAwC;QAExC,KAAK,CAAC,kCAAkC,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC;QAC5D,IAAI,CAAC,IAAI,GAAG,oCAAoC,CAAC;IAClD,CAAC;CACD","sourcesContent":["import type { WorkflowRunStatus, WorkflowStageStatus } from \"./workflow-events.js\";\n\nexport type WorkflowRunJsonValue =\n\t| string\n\t| number\n\t| boolean\n\t| null\n\t| readonly WorkflowRunJsonValue[]\n\t| WorkflowRunJsonObject;\n\nexport interface WorkflowRunJsonObject {\n\treadonly [key: string]: WorkflowRunJsonValue | undefined;\n}\n\nexport type WorkflowRunFilterStatus = WorkflowRunStatus | WorkflowStageStatus | \"awaiting_input\";\n\nexport interface WorkflowRunListFilter {\n\t/** Run statuses match directly; `awaiting_input` selects runs with an unanswered prompt. */\n\treadonly status?: WorkflowRunFilterStatus;\n}\n\nexport interface WorkflowStageListFilter {\n\treadonly status?: WorkflowStageStatus;\n}\n\nexport interface WorkflowRunActiveStage {\n\treadonly stageId: string;\n\treadonly name: string;\n\treadonly status: WorkflowStageStatus;\n}\n\nexport interface WorkflowRunAwaitingInput {\n\treadonly stageId?: string;\n\treadonly stageName?: string;\n\treadonly promptId?: string;\n\treadonly promptKind?: string;\n\treadonly message?: string;\n}\n\n/** The concise per-run data that the `workflow` tool's `status` action lists. */\nexport interface WorkflowRunSummary {\n\treadonly runId: string;\n\treadonly name: string;\n\treadonly status: WorkflowRunStatus;\n\treadonly startedAt: number;\n\treadonly endedAt?: number;\n\treadonly elapsedMs: number;\n\treadonly activeStages: readonly WorkflowRunActiveStage[];\n\treadonly awaitingInputCount: number;\n\treadonly awaitingInput: readonly WorkflowRunAwaitingInput[];\n\treadonly exitReason?: string;\n\treadonly error?: string;\n}\n\nexport interface WorkflowRunStageSummary {\n\treadonly id: string;\n\treadonly name: string;\n\treadonly status: WorkflowStageStatus;\n\treadonly sessionId?: string;\n\treadonly error?: string;\n\treadonly skippedReason?: string;\n\treadonly awaitingInputSince?: number;\n}\n\n/** The per-run detail that the `workflow` tool's `status` action returns for one run id. */\nexport interface WorkflowRunDetail {\n\treadonly runId: string;\n\treadonly rootRunId?: string;\n\treadonly name: string;\n\treadonly status: WorkflowRunStatus | \"crashed\";\n\treadonly startedAt: number;\n\treadonly endedAt?: number;\n\treadonly durationMs?: number;\n\treadonly inputs: WorkflowRunJsonObject;\n\treadonly stages: readonly WorkflowRunStageSummary[];\n\treadonly result?: WorkflowRunJsonObject;\n\treadonly error?: string;\n\treadonly exitReason?: string;\n\treadonly resumable?: boolean;\n\treadonly resumeGuidance?: string;\n\treadonly ownerActiveElsewhere?: boolean;\n}\n\nexport interface WorkflowRunAllTarget {\n\treadonly all: true;\n}\n\nexport interface WorkflowRunPauseOptions {\n\t/** Pause one stage instead of the whole run. */\n\treadonly stageId?: string;\n}\n\nexport interface WorkflowRunResumeOptions {\n\t/** Resume one paused stage instead of the whole run. */\n\treadonly stageId?: string;\n\t/** Message delivered to each resumed stage. */\n\treadonly message?: string;\n\treadonly legacyRecovery?: { readonly olderWorkersStopped: true };\n}\n\nexport type WorkflowRunControlStatus = \"ok\" | \"running\" | \"paused\" | \"partial\" | \"noop\" | \"cancelled\";\n\n/** A run that a batch pause or quit could not stop; it may still be active. */\nexport interface WorkflowRunControlFailedRun {\n\treadonly runId: string;\n\t/** Machine-readable refusal, such as `not_found`, `no_active_stages` or `pause_failed`. */\n\treadonly reason: string;\n\treadonly message?: string;\n}\n\n/**\n * The acknowledged result of a pause, quit or resume request, as the `workflow`\n * tool reports it. `runId` is `--all` for a batch request. `noop` means the request was\n * understood and found nothing to change; `partial` means only part of the\n * request took effect. For a batch pause or quit, `failedRuns` names every run that\n * could not be stopped, so a `partial` outcome is never a complete stop.\n */\nexport interface WorkflowRunControlOutcome {\n\treadonly action: \"pause\" | \"quit\" | \"resume\";\n\treadonly runId: string;\n\treadonly status: WorkflowRunControlStatus;\n\treadonly message: string;\n\treadonly stageId?: string;\n\treadonly workflowStatus?: WorkflowRunStatus;\n\treadonly abandoned?: boolean;\n\treadonly failedRuns?: readonly WorkflowRunControlFailedRun[];\n}\n\n/** Typed run management for the workflow runs owned by one session. */\nexport interface SessionWorkflows {\n\tlistRuns(filter?: WorkflowRunListFilter): Promise<readonly WorkflowRunSummary[]>;\n\tgetRun(runId: string): Promise<WorkflowRunDetail>;\n\tgetStages(runId: string, filter?: WorkflowStageListFilter): Promise<readonly WorkflowRunStageSummary[]>;\n\tpause(runId: string, options?: WorkflowRunPauseOptions): Promise<WorkflowRunControlOutcome>;\n\tpause(target: WorkflowRunAllTarget): Promise<WorkflowRunControlOutcome>;\n\tquit(target: string | WorkflowRunAllTarget): Promise<WorkflowRunControlOutcome>;\n\tresume(runId: string, options?: WorkflowRunResumeOptions): Promise<WorkflowRunControlOutcome>;\n}\n\nexport interface WorkflowRunControlRegistration {\n\tdispose(): void;\n}\n\nexport type WorkflowRunControlErrorCode =\n\t| \"WORKFLOW_RUN_NOT_FOUND\"\n\t| \"WORKFLOW_RUN_OWNED_ELSEWHERE\"\n\t| \"WORKFLOW_RUN_NOT_RESUMABLE\"\n\t| \"WORKFLOW_STAGE_NOT_FOUND\"\n\t| \"WORKFLOW_STAGE_AMBIGUOUS\"\n\t| \"WORKFLOW_STAGE_RESUME_UNSUPPORTED\"\n\t| \"WORKFLOW_RUN_DATABASE\"\n\t| \"WORKFLOW_RUN_CONTROL_FAILED\"\n\t| \"WORKFLOW_RUN_CONTROL_UNAVAILABLE\";\n\nexport interface WorkflowRunControlErrorOptions extends ErrorOptions {\n\treadonly runId?: string;\n\treadonly failedRuns?: readonly WorkflowRunControlFailedRun[];\n}\n\n/** Base class for every failure reported by {@link SessionWorkflows}; branch on `code`. */\nexport class WorkflowRunControlError extends Error {\n\treadonly code: WorkflowRunControlErrorCode;\n\treadonly runId?: string;\n\t/** Runs a batch pause or quit could not stop, when the whole batch was refused. */\n\treadonly failedRuns?: readonly WorkflowRunControlFailedRun[];\n\n\tconstructor(code: WorkflowRunControlErrorCode, message: string, options: WorkflowRunControlErrorOptions = {}) {\n\t\tsuper(message, options);\n\t\tthis.name = \"WorkflowRunControlError\";\n\t\tthis.code = code;\n\t\tif (options.runId !== undefined) this.runId = options.runId;\n\t\tif (options.failedRuns !== undefined) this.failedRuns = options.failedRuns;\n\t}\n}\n\n/** The run id is unknown, malformed, or an ambiguous prefix. */\nexport class WorkflowRunNotFoundError extends WorkflowRunControlError {\n\tconstructor(message: string, options?: WorkflowRunControlErrorOptions) {\n\t\tsuper(\"WORKFLOW_RUN_NOT_FOUND\", message, options);\n\t\tthis.name = \"WorkflowRunNotFoundError\";\n\t}\n}\n\n/** The run belongs to another session or is executing in another live Atomic process. */\nexport class WorkflowRunOwnershipError extends WorkflowRunControlError {\n\tconstructor(message: string, options?: WorkflowRunControlErrorOptions) {\n\t\tsuper(\"WORKFLOW_RUN_OWNED_ELSEWHERE\", message, options);\n\t\tthis.name = \"WorkflowRunOwnershipError\";\n\t}\n}\n\n/** The run has no continuation to resume: it completed, was killed, or has no durable progress. */\nexport class WorkflowRunNotResumableError extends WorkflowRunControlError {\n\tconstructor(message: string, options?: WorkflowRunControlErrorOptions) {\n\t\tsuper(\"WORKFLOW_RUN_NOT_RESUMABLE\", message, options);\n\t\tthis.name = \"WorkflowRunNotResumableError\";\n\t}\n}\n\n/** The stage identifier matches no stage or tool node of the run. */\nexport class WorkflowStageNotFoundError extends WorkflowRunControlError {\n\tconstructor(message: string, options?: WorkflowRunControlErrorOptions) {\n\t\tsuper(\"WORKFLOW_STAGE_NOT_FOUND\", message, options);\n\t\tthis.name = \"WorkflowStageNotFoundError\";\n\t}\n}\n\n/** The stage identifier matches more than one stage or tool node; pass a more specific identifier. */\nexport class WorkflowStageAmbiguousError extends WorkflowRunControlError {\n\tconstructor(message: string, options?: WorkflowRunControlErrorOptions) {\n\t\tsuper(\"WORKFLOW_STAGE_AMBIGUOUS\", message, options);\n\t\tthis.name = \"WorkflowStageAmbiguousError\";\n\t}\n}\n\n/** A durable run can only be resumed whole; resume it without a stage identifier. */\nexport class WorkflowStageResumeUnsupportedError extends WorkflowRunControlError {\n\tconstructor(message: string, options?: WorkflowRunControlErrorOptions) {\n\t\tsuper(\"WORKFLOW_STAGE_RESUME_UNSUPPORTED\", message, options);\n\t\tthis.name = \"WorkflowStageResumeUnsupportedError\";\n\t}\n}\n\n/** Workflow durability (the run database) is unavailable, shut down, or failed. */\nexport class WorkflowRunDatabaseError extends WorkflowRunControlError {\n\tconstructor(message: string, options?: WorkflowRunControlErrorOptions) {\n\t\tsuper(\"WORKFLOW_RUN_DATABASE\", message, options);\n\t\tthis.name = \"WorkflowRunDatabaseError\";\n\t}\n}\n\n/** The workflows extension is not loaded for this session, or the session was disposed. */\nexport class WorkflowRunControlUnavailableError extends WorkflowRunControlError {\n\tconstructor(\n\t\tmessage = \"Workflow run control is unavailable for this session.\",\n\t\toptions?: WorkflowRunControlErrorOptions,\n\t) {\n\t\tsuper(\"WORKFLOW_RUN_CONTROL_UNAVAILABLE\", message, options);\n\t\tthis.name = \"WorkflowRunControlUnavailableError\";\n\t}\n}\n"]}
|
|
1
|
+
{"version":3,"file":"workflow-run-control.js","sourceRoot":"","sources":["../../../src/core/extensions/workflow-run-control.ts"],"names":[],"mappings":"AA6KA,2FAA2F;AAC3F,MAAM,OAAO,uBAAwB,SAAQ,KAAK;IACxC,IAAI,CAA8B;IAClC,KAAK,CAAU;IACxB,mFAAmF;IAC1E,UAAU,CAA0C;IAE7D,YAAY,IAAiC,EAAE,OAAe,EAAE,OAAO,GAAmC,EAAE;QAC3G,KAAK,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;QACxB,IAAI,CAAC,IAAI,GAAG,yBAAyB,CAAC;QACtC,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,OAAO,CAAC,KAAK,KAAK,SAAS;YAAE,IAAI,CAAC,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC;QAC5D,IAAI,OAAO,CAAC,UAAU,KAAK,SAAS;YAAE,IAAI,CAAC,UAAU,GAAG,OAAO,CAAC,UAAU,CAAC;IAC5E,CAAC;CACD;AAED,gEAAgE;AAChE,MAAM,OAAO,wBAAyB,SAAQ,uBAAuB;IACpE,YAAY,OAAe,EAAE,OAAwC;QACpE,KAAK,CAAC,wBAAwB,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC;QAClD,IAAI,CAAC,IAAI,GAAG,0BAA0B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QACjD,IAAI,CAAC,IAAI,GAAG,0BAA0B,CAAC;IACxC,CAAC;CACD;AAED,2FAA2F;AAC3F,MAAM,OAAO,kCAAmC,SAAQ,uBAAuB;IAC9E,YACC,OAAO,GAAG,uDAAuD,EACjE,OAAwC;QAExC,KAAK,CAAC,kCAAkC,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC;QAC5D,IAAI,CAAC,IAAI,GAAG,oCAAoC,CAAC;IAClD,CAAC;CACD","sourcesContent":["import type {\n\tWorkflowActivityObserver,\n\tWorkflowActivitySubscription,\n\tWorkflowRunStatus,\n\tWorkflowStageStatus,\n} from \"./workflow-events.js\";\n\nexport type WorkflowRunJsonValue =\n\t| string\n\t| number\n\t| boolean\n\t| null\n\t| readonly WorkflowRunJsonValue[]\n\t| WorkflowRunJsonObject;\n\nexport interface WorkflowRunJsonObject {\n\treadonly [key: string]: WorkflowRunJsonValue | undefined;\n}\n\nexport type WorkflowRunFilterStatus = WorkflowRunStatus | WorkflowStageStatus | \"awaiting_input\";\n\nexport interface WorkflowRunListFilter {\n\t/** Run statuses match directly; `awaiting_input` selects runs with an unanswered prompt. */\n\treadonly status?: WorkflowRunFilterStatus;\n}\n\nexport interface WorkflowStageListFilter {\n\treadonly status?: WorkflowStageStatus;\n}\n\nexport interface WorkflowRunActiveStage {\n\treadonly stageId: string;\n\treadonly name: string;\n\treadonly status: WorkflowStageStatus;\n}\n\nexport interface WorkflowRunAwaitingInput {\n\treadonly stageId?: string;\n\treadonly stageName?: string;\n\treadonly promptId?: string;\n\treadonly promptKind?: string;\n\treadonly message?: string;\n}\n\n/** The concise per-run data that the `workflow` tool's `status` action lists. */\nexport interface WorkflowRunSummary {\n\treadonly runId: string;\n\treadonly name: string;\n\treadonly status: WorkflowRunStatus;\n\treadonly startedAt: number;\n\treadonly endedAt?: number;\n\treadonly elapsedMs: number;\n\treadonly activeStages: readonly WorkflowRunActiveStage[];\n\treadonly awaitingInputCount: number;\n\treadonly awaitingInput: readonly WorkflowRunAwaitingInput[];\n\treadonly exitReason?: string;\n\treadonly error?: string;\n}\n\nexport interface WorkflowRunStageSummary {\n\treadonly id: string;\n\treadonly name: string;\n\treadonly status: WorkflowStageStatus;\n\treadonly sessionId?: string;\n\treadonly error?: string;\n\treadonly skippedReason?: string;\n\treadonly awaitingInputSince?: number;\n}\n\n/** The per-run detail that the `workflow` tool's `status` action returns for one run id. */\nexport interface WorkflowRunDetail {\n\treadonly runId: string;\n\treadonly rootRunId?: string;\n\treadonly name: string;\n\treadonly status: WorkflowRunStatus | \"crashed\";\n\treadonly startedAt: number;\n\treadonly endedAt?: number;\n\treadonly durationMs?: number;\n\treadonly inputs: WorkflowRunJsonObject;\n\treadonly stages: readonly WorkflowRunStageSummary[];\n\treadonly result?: WorkflowRunJsonObject;\n\treadonly error?: string;\n\treadonly exitReason?: string;\n\treadonly resumable?: boolean;\n\treadonly resumeGuidance?: string;\n\treadonly ownerActiveElsewhere?: boolean;\n}\n\nexport interface WorkflowRunAllTarget {\n\treadonly all: true;\n}\n\nexport interface WorkflowRunPauseOptions {\n\t/** Pause one stage instead of the whole run. */\n\treadonly stageId?: string;\n}\n\nexport interface WorkflowRunResumeOptions {\n\t/** Resume one paused stage instead of the whole run. */\n\treadonly stageId?: string;\n\t/** Message delivered to each resumed stage. */\n\treadonly message?: string;\n\treadonly legacyRecovery?: { readonly olderWorkersStopped: true };\n}\n\nexport type WorkflowRunControlStatus = \"ok\" | \"running\" | \"paused\" | \"partial\" | \"noop\" | \"cancelled\";\n\n/** A run that a batch pause or quit could not stop; it may still be active. */\nexport interface WorkflowRunControlFailedRun {\n\treadonly runId: string;\n\t/** Machine-readable refusal, such as `not_found`, `no_active_stages` or `pause_failed`. */\n\treadonly reason: string;\n\treadonly message?: string;\n}\n\n/**\n * The acknowledged result of a pause, quit or resume request, as the `workflow`\n * tool reports it. `runId` is `--all` for a batch request. `noop` means the request was\n * understood and found nothing to change; `partial` means only part of the\n * request took effect. For a batch pause or quit, `failedRuns` names every run that\n * could not be stopped, so a `partial` outcome is never a complete stop.\n */\nexport interface WorkflowRunControlOutcome {\n\treadonly action: \"pause\" | \"quit\" | \"resume\";\n\treadonly runId: string;\n\treadonly status: WorkflowRunControlStatus;\n\treadonly message: string;\n\treadonly stageId?: string;\n\treadonly workflowStatus?: WorkflowRunStatus;\n\treadonly abandoned?: boolean;\n\treadonly failedRuns?: readonly WorkflowRunControlFailedRun[];\n}\n\n/** Typed run management for the workflow runs owned by one session, as registered by the workflows extension. */\nexport interface WorkflowRunControl {\n\tlistRuns(filter?: WorkflowRunListFilter): Promise<readonly WorkflowRunSummary[]>;\n\tgetRun(runId: string): Promise<WorkflowRunDetail>;\n\tgetStages(runId: string, filter?: WorkflowStageListFilter): Promise<readonly WorkflowRunStageSummary[]>;\n\tpause(runId: string, options?: WorkflowRunPauseOptions): Promise<WorkflowRunControlOutcome>;\n\tpause(target: WorkflowRunAllTarget): Promise<WorkflowRunControlOutcome>;\n\tquit(target: string | WorkflowRunAllTarget): Promise<WorkflowRunControlOutcome>;\n\tresume(runId: string, options?: WorkflowRunResumeOptions): Promise<WorkflowRunControlOutcome>;\n}\n\n/** `session.workflows`: run management plus observation of the workflow runs owned by one session. */\nexport interface SessionWorkflows extends WorkflowRunControl {\n\t/**\n\t * Follow root activity and graph changes. Delivers a snapshot frame first, then FIFO\n\t * `changed` and `removed` frames; the subscription follows extension reloads.\n\t */\n\tobserve(observer: WorkflowActivityObserver): WorkflowActivitySubscription;\n}\n\nexport interface WorkflowRunControlRegistration {\n\tdispose(): void;\n}\n\nexport type WorkflowRunControlErrorCode =\n\t| \"WORKFLOW_RUN_NOT_FOUND\"\n\t| \"WORKFLOW_RUN_OWNED_ELSEWHERE\"\n\t| \"WORKFLOW_RUN_NOT_RESUMABLE\"\n\t| \"WORKFLOW_STAGE_NOT_FOUND\"\n\t| \"WORKFLOW_STAGE_AMBIGUOUS\"\n\t| \"WORKFLOW_STAGE_RESUME_UNSUPPORTED\"\n\t| \"WORKFLOW_RUN_DATABASE\"\n\t| \"WORKFLOW_RUN_CONTROL_FAILED\"\n\t| \"WORKFLOW_RUN_CONTROL_UNAVAILABLE\";\n\nexport interface WorkflowRunControlErrorOptions extends ErrorOptions {\n\treadonly runId?: string;\n\treadonly failedRuns?: readonly WorkflowRunControlFailedRun[];\n}\n\n/** Base class for every failure reported by {@link SessionWorkflows}; branch on `code`. */\nexport class WorkflowRunControlError extends Error {\n\treadonly code: WorkflowRunControlErrorCode;\n\treadonly runId?: string;\n\t/** Runs a batch pause or quit could not stop, when the whole batch was refused. */\n\treadonly failedRuns?: readonly WorkflowRunControlFailedRun[];\n\n\tconstructor(code: WorkflowRunControlErrorCode, message: string, options: WorkflowRunControlErrorOptions = {}) {\n\t\tsuper(message, options);\n\t\tthis.name = \"WorkflowRunControlError\";\n\t\tthis.code = code;\n\t\tif (options.runId !== undefined) this.runId = options.runId;\n\t\tif (options.failedRuns !== undefined) this.failedRuns = options.failedRuns;\n\t}\n}\n\n/** The run id is unknown, malformed, or an ambiguous prefix. */\nexport class WorkflowRunNotFoundError extends WorkflowRunControlError {\n\tconstructor(message: string, options?: WorkflowRunControlErrorOptions) {\n\t\tsuper(\"WORKFLOW_RUN_NOT_FOUND\", message, options);\n\t\tthis.name = \"WorkflowRunNotFoundError\";\n\t}\n}\n\n/** The run belongs to another session or is executing in another live Atomic process. */\nexport class WorkflowRunOwnershipError extends WorkflowRunControlError {\n\tconstructor(message: string, options?: WorkflowRunControlErrorOptions) {\n\t\tsuper(\"WORKFLOW_RUN_OWNED_ELSEWHERE\", message, options);\n\t\tthis.name = \"WorkflowRunOwnershipError\";\n\t}\n}\n\n/** The run has no continuation to resume: it completed, was killed, or has no durable progress. */\nexport class WorkflowRunNotResumableError extends WorkflowRunControlError {\n\tconstructor(message: string, options?: WorkflowRunControlErrorOptions) {\n\t\tsuper(\"WORKFLOW_RUN_NOT_RESUMABLE\", message, options);\n\t\tthis.name = \"WorkflowRunNotResumableError\";\n\t}\n}\n\n/** The stage identifier matches no stage or tool node of the run. */\nexport class WorkflowStageNotFoundError extends WorkflowRunControlError {\n\tconstructor(message: string, options?: WorkflowRunControlErrorOptions) {\n\t\tsuper(\"WORKFLOW_STAGE_NOT_FOUND\", message, options);\n\t\tthis.name = \"WorkflowStageNotFoundError\";\n\t}\n}\n\n/** The stage identifier matches more than one stage or tool node; pass a more specific identifier. */\nexport class WorkflowStageAmbiguousError extends WorkflowRunControlError {\n\tconstructor(message: string, options?: WorkflowRunControlErrorOptions) {\n\t\tsuper(\"WORKFLOW_STAGE_AMBIGUOUS\", message, options);\n\t\tthis.name = \"WorkflowStageAmbiguousError\";\n\t}\n}\n\n/** A durable run can only be resumed whole; resume it without a stage identifier. */\nexport class WorkflowStageResumeUnsupportedError extends WorkflowRunControlError {\n\tconstructor(message: string, options?: WorkflowRunControlErrorOptions) {\n\t\tsuper(\"WORKFLOW_STAGE_RESUME_UNSUPPORTED\", message, options);\n\t\tthis.name = \"WorkflowStageResumeUnsupportedError\";\n\t}\n}\n\n/** Workflow durability (the run database) is unavailable, shut down, or failed. */\nexport class WorkflowRunDatabaseError extends WorkflowRunControlError {\n\tconstructor(message: string, options?: WorkflowRunControlErrorOptions) {\n\t\tsuper(\"WORKFLOW_RUN_DATABASE\", message, options);\n\t\tthis.name = \"WorkflowRunDatabaseError\";\n\t}\n}\n\n/** The workflows extension is not loaded for this session, or the session was disposed. */\nexport class WorkflowRunControlUnavailableError extends WorkflowRunControlError {\n\tconstructor(\n\t\tmessage = \"Workflow run control is unavailable for this session.\",\n\t\toptions?: WorkflowRunControlErrorOptions,\n\t) {\n\t\tsuper(\"WORKFLOW_RUN_CONTROL_UNAVAILABLE\", message, options);\n\t\tthis.name = \"WorkflowRunControlUnavailableError\";\n\t}\n}\n"]}
|
package/dist/core/messages.d.ts
CHANGED
|
@@ -66,6 +66,7 @@ export declare function messageIsLlmVisible(message: AgentMessage, deletedBlockI
|
|
|
66
66
|
*/
|
|
67
67
|
export declare function bashExecutionToText(msg: BashExecutionMessage): string;
|
|
68
68
|
export declare const VERBATIM_COMPACTION_PREFIX = "The earlier conversation was compacted. Below is the verbatim transcript of the retained lines; elided spans are marked \"(filtered N lines)\".\n\n";
|
|
69
|
+
export declare const SUMMARY_COMPACTION_PREFIX = "The following is a summary of the earlier conversation:\n\n";
|
|
69
70
|
export declare function isVerbatimCompactionMessage(message: CustomMessage): boolean;
|
|
70
71
|
/**
|
|
71
72
|
* Create the visible custom-role boundary used to replay a verbatim compaction.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"messages.d.ts","sourceRoot":"","sources":["../../src/core/messages.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,OAAO,EAAE,WAAW,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AACnG,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,+BAA+B,CAAC;AAGlE,eAAO,MAAM,qBAAqB,iGAGjC,CAAC;AAEF,eAAO,MAAM,qBAAqB,eAAe,CAAC;AAElD;;GAEG;AACH,MAAM,WAAW,oBAAoB;IACpC,IAAI,EAAE,eAAe,CAAC;IACtB,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,MAAM,GAAG,SAAS,CAAC;IAC7B,SAAS,EAAE,OAAO,CAAC;IACnB,SAAS,EAAE,OAAO,CAAC;IACnB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,SAAS,EAAE,MAAM,CAAC;IAClB,qEAAqE;IACrE,kBAAkB,CAAC,EAAE,OAAO,CAAC;CAC7B;AAED;;;GAGG;AAEH,MAAM,WAAW,aAAa,CAAC,CAAC,GAAG,OAAO;IACzC,IAAI,EAAE,QAAQ,CAAC;IACf,UAAU,EAAE,MAAM,CAAC;IACnB,OAAO,EAAE,MAAM,GAAG,CAAC,WAAW,GAAG,YAAY,CAAC,EAAE,CAAC;IACjD,OAAO,EAAE,OAAO,CAAC;IACjB,OAAO,CA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A0B,CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,oBAAoB,CAOnH;AAED,wDAAwD;AACxD,wBAAgB,mBAAmB,CAClC,UAAU,EAAE,MAAM,EAClB,OAAO,EAAE,MAAM,GAAG,CAAC,WAAW,GAAG,YAAY,CAAC,EAAE,EAChD,OAAO,EAAE,OAAO,EAChB,OAAO,EAAE,OAAO,GAAG,SAAS,EAC5B,SAAS,EAAE,MAAM,EACjB,kBAAkB,CAAC,EAAE,OAAO,EAC5B,iBAAiB,CAAC,EAAE,MAAM,GACxB,0BAA0B,CAY5B;AA2BD;;;;;;;;GAQG;AACH,wBAAgB,qCAAqC,CAAC,QAAQ,SAAS,YAAY,EAAE,QAAQ,EAAE,QAAQ,EAAE,GAAG,QAAQ,EAAE,CAuCrH;AAED;;;;;;;;;;GAUG;AACH,MAAM,WAAW,yBAAyB;IACzC,6EAA6E;IAC7E,cAAc,CAAC,EAAE,OAAO,CAAC;CACzB;AAED,wBAAgB,uBAAuB,CAAC,QAAQ,SAAS,YAAY,EACpE,QAAQ,EAAE,QAAQ,EAAE,EACpB,OAAO,GAAE,yBAA8B,GACrC,CAAC,QAAQ,GAAG,iBAAiB,CAAC,EAAE,CAsElC;AAID;;;;;;;GAOG;AACH,wBAAgB,YAAY,CAAC,QAAQ,EAAE,YAAY,EAAE,GAAG,OAAO,EAAE,CAiDhE"}
|
package/dist/core/messages.js
CHANGED
|
@@ -113,6 +113,7 @@ export function bashExecutionToText(msg) {
|
|
|
113
113
|
return text;
|
|
114
114
|
}
|
|
115
115
|
export const VERBATIM_COMPACTION_PREFIX = 'The earlier conversation was compacted. Below is the verbatim transcript of the retained lines; elided spans are marked "(filtered N lines)".\n\n';
|
|
116
|
+
export const SUMMARY_COMPACTION_PREFIX = "The following is a summary of the earlier conversation:\n\n";
|
|
116
117
|
const verbatimCompactionMessages = new WeakSet();
|
|
117
118
|
export function isVerbatimCompactionMessage(message) {
|
|
118
119
|
return verbatimCompactionMessages.has(message);
|
|
@@ -124,7 +125,10 @@ export function isVerbatimCompactionMessage(message) {
|
|
|
124
125
|
* its image blocks stay intact, so preserved content is not reduced to a placeholder.
|
|
125
126
|
*/
|
|
126
127
|
export function createVerbatimCompactionMessage(compactedText, tokensBefore, timestamp, details, retainedTail) {
|
|
127
|
-
const
|
|
128
|
+
const prefix = typeof details === "object" && details !== null && "backend" in details && details.backend === "summary"
|
|
129
|
+
? SUMMARY_COMPACTION_PREFIX
|
|
130
|
+
: VERBATIM_COMPACTION_PREFIX;
|
|
131
|
+
const content = [{ type: "text", text: prefix + compactedText }];
|
|
128
132
|
for (const block of retainedTail ?? []) {
|
|
129
133
|
const last = content[content.length - 1];
|
|
130
134
|
if (block.type === "text" && last.type === "text")
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"messages.js","sourceRoot":"","sources":["../../src/core/messages.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAIH,OAAO,EAAE,mBAAmB,EAAE,MAAM,2BAA2B,CAAC;AAEhE,MAAM,CAAC,MAAM,qBAAqB,GAAG;;;CAGpC,CAAC;AAEF,MAAM,CAAC,MAAM,qBAAqB,GAAG,YAAY,CAAC;AAsDlD,4FAA4F;AAC5F,MAAM,UAAU,uBAAuB,CAAyB,OAAU;IACzE,QAAQ,OAAO,CAAC,IAAI,EAAE,CAAC;QACtB,KAAK,MAAM,CAAC;QACZ,KAAK,WAAW,CAAC;QACjB,KAAK,YAAY,CAAC;QAClB,KAAK,QAAQ;YACZ,OAAO,OAAO,CAAC,OAAO,IAAI,IAAI,CAAC,CAAC,CAAE,EAAE,GAAG,OAAO,EAAE,OAAO,EAAE,EAAE,EAAQ,CAAC,CAAC,CAAC,OAAO,CAAC;QAC/E;YACC,OAAO,OAAO,CAAC;IACjB,CAAC;AACF,CAAC;AAED,MAAM,UAAU,gCAAgC,CAAC,KAAc;IAC9D,IAAI,CAAC,KAAK,IAAI,OAAO,KAAK,KAAK,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O,EAAE,GAAG,CAAC,EAAE,OAAO,EAAE,2BAA2B,CAAC,CAAC,CAAC,OAAO,CAAC,EAAa,CAAC;YAC7E,CAAC;YACD,KAAK,QAAQ;gBACZ,OAAO,CAAC,CAAC;YACV,KAAK,WAAW,CAAC;YACjB,KAAK,YAAY;gBAChB,OAAO,CAAC,CAAC;YACV,SAAS,CAAC;gBACT,2FAA2F;gBAC3F,MAAM,gBAAgB,GAAU,CAAC,CAAC;gBAClC,KAAK,gBAAgB,CAAC;gBACtB,OAAO,SAAS,CAAC;YAClB,CAAC;QACF,CAAC;IACF,CAAC,CAAC;SACD,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,KAAK,SAAS,CAAC,CAAC;IACjC,OAAO,uBAAuB,CAAC,mBAAmB,CAAC,SAAS,CAAC,CAAC,CAAC;AAChE,CAAC","sourcesContent":["/**\n * Custom message types and transformers for the coding agent.\n *\n * Extends the base AgentMessage type with coding-agent specific message types,\n * and provides a transformer to convert them to LLM-compatible messages.\n */\n\nimport type { ImageContent, Message, TextContent, ToolResultMessage } from \"@bastani/pi-ai/compat\";\nimport type { AgentMessage } from \"@earendil-works/pi-agent-core\";\nimport { uniquifyToolCallIds } from \"./context-tool-pairing.js\";\n\nexport const BRANCH_SUMMARY_PREFIX = `The following is a summary of a branch that this conversation came back from:\n\n<summary>\n`;\n\nexport const BRANCH_SUMMARY_SUFFIX = `</summary>`;\n\n/**\n * Message type for bash executions via the ! command.\n */\nexport interface BashExecutionMessage {\n\trole: \"bashExecution\";\n\tcommand: string;\n\toutput: string;\n\texitCode: number | undefined;\n\tcancelled: boolean;\n\ttruncated: boolean;\n\tfullOutputPath?: string;\n\ttimestamp: number;\n\t/** If true, this message is excluded from LLM context (!! prefix) */\n\texcludeFromContext?: boolean;\n}\n\n/**\n * Message type for extension-injected messages via sendMessage().\n * These are custom messages that extensions can inject into the conversation.\n */\n\nexport interface CustomMessage<T = unknown> {\n\trole: \"custom\";\n\tcustomType: string;\n\tcontent: string | (TextContent | ImageContent)[];\n\tdisplay: boolean;\n\tdetails?: T;\n\ttimestamp: number;\n}\n\nexport type StageAdmittedCustomMessage<T = unknown> = CustomMessage<T> & {\n\t/** Stable producer identity used for exactly-once workflow-stage admission. */\n\tstageAdmissionKey?: string;\n\t/** Whether this admission joined active stage work or started after the assistant had settled. */\n};\n\nexport interface BranchSummaryMessage {\n\trole: \"branchSummary\";\n\tsummary: string;\n\tfromId: string | null;\n\ttimestamp: number;\n}\n\n// Extend CustomAgentMessages via declaration merging\ndeclare module \"@earendil-works/pi-agent-core\" {\n\tinterface CustomAgentMessages {\n\t\tbashExecution: BashExecutionMessage;\n\t\tcustom: CustomMessage;\n\t\tbranchSummary: BranchSummaryMessage;\n\t}\n}\n\n/** Normalize lax JavaScript/legacy message input before it reaches history or providers. */\nexport function normalizeMessageContent<T extends AgentMessage>(message: T): T {\n\tswitch (message.role) {\n\t\tcase \"user\":\n\t\tcase \"assistant\":\n\t\tcase \"toolResult\":\n\t\tcase \"custom\":\n\t\t\treturn message.content == null ? ({ ...message, content: [] } as T) : message;\n\t\tdefault:\n\t\t\treturn message;\n\t}\n}\n\nexport function userLikeContentBlockIsLlmVisible(block: unknown): boolean {\n\tif (!block || typeof block !== \"object\") return false;\n\tconst candidate = block as { type?: unknown; text?: unknown };\n\tif (candidate.type === \"image\") return true;\n\tif (candidate.type === \"text\") return typeof candidate.text === \"string\" && candidate.text.trim().length > 0;\n\t// Future provider-supported blocks must fail visible; only malformed/untyped blocks fail closed.\n\treturn typeof candidate.type === \"string\" && candidate.type.trim().length > 0;\n}\n\n/** Whether user/custom content survives provider conversion as a visible input. */\nexport function userLikeContentIsLlmVisible(\n\tcontent: unknown,\n\tdeletedBlockIndexes: ReadonlySet<number> = new Set<number>(),\n): boolean {\n\tif (typeof content === \"string\") return content.trim().length > 0;\n\tif (!Array.isArray(content)) return false;\n\treturn content.some((block, index) => !deletedBlockIndexes.has(index) && userLikeContentBlockIsLlmVisible(block));\n}\n\n/** Whether an Atomic message emits an LLM-visible user-like turn boundary. */\nexport function messageStartsLlmUserTurn(\n\tmessage: AgentMessage,\n\tdeletedBlockIndexes: ReadonlySet<number> = new Set<number>(),\n): boolean {\n\tswitch (message.role) {\n\t\tcase \"user\":\n\t\t\treturn userLikeContentIsLlmVisible(message.content, deletedBlockIndexes);\n\t\tcase \"custom\":\n\t\t\treturn (\n\t\t\t\t(message as CustomMessage & { excludeFromContext?: boolean }).excludeFromContext !== true &&\n\t\t\t\tuserLikeContentIsLlmVisible(message.content, deletedBlockIndexes)\n\t\t\t);\n\t\tcase \"branchSummary\":\n\t\t\t// Empty summaries are omitted by session reconstruction. Whitespace is\n\t\t\t// visible because the branch-summary wrapper itself is non-whitespace.\n\t\t\treturn typeof message.summary === \"string\" && message.summary.length > 0;\n\t\tcase \"bashExecution\":\n\t\t\treturn message.excludeFromContext !== true;\n\t\tdefault:\n\t\t\treturn false;\n\t}\n}\n\n/** Whether an Atomic message survives conversion into provider-visible context. */\nexport function messageIsLlmVisible(\n\tmessage: AgentMessage,\n\tdeletedBlockIndexes: ReadonlySet<number> = new Set<number>(),\n): boolean {\n\tif (message.role === \"system\" || message.role === \"assistant\" || message.role === \"toolResult\") return true;\n\treturn messageStartsLlmUserTurn(message, deletedBlockIndexes);\n}\n\n/** Filter invalid user-like blocks only in transient provider-bound content. */\nfunction filterUserLikeContentBlocks(content: unknown[]): unknown[] {\n\treturn content.filter(userLikeContentBlockIsLlmVisible);\n}\n\n/** Normalize raw blocks only in the transient LLM-compatible message returned by convertToLlm. */\nfunction normalizeRawRedactedThinking(message: AgentMessage): AgentMessage {\n\tif (message.role !== \"assistant\" || !Array.isArray(message.content)) return message;\n\tlet changed = false;\n\tconst content = message.content.map((block) => {\n\t\tif (!block || typeof block !== \"object\") return block;\n\t\tconst candidate = block as { type?: unknown; data?: unknown };\n\t\tif (candidate.type !== \"redacted_thinking\" || typeof candidate.data !== \"string\") return block;\n\t\tchanged = true;\n\t\treturn {\n\t\t\ttype: \"thinking\" as const,\n\t\t\tthinking: \"\",\n\t\t\tthinkingSignature: candidate.data,\n\t\t\tredacted: true,\n\t\t};\n\t});\n\treturn changed ? ({ ...message, content } as AgentMessage) : message;\n}\n\n/**\n * Convert a BashExecutionMessage to user message text for LLM context.\n */\nexport function bashExecutionToText(msg: BashExecutionMessage): string {\n\tlet text = `Ran \\`${msg.command}\\`\\n`;\n\tif (msg.output) {\n\t\ttext += `\\`\\`\\`\\n${msg.output}\\n\\`\\`\\``;\n\t} else {\n\t\ttext += \"(no output)\";\n\t}\n\tif (msg.cancelled) {\n\t\ttext += \"\\n\\n(command cancelled)\";\n\t} else if (msg.exitCode !== null && msg.exitCode !== undefined && msg.exitCode !== 0) {\n\t\ttext += `\\n\\nCommand exited with code ${msg.exitCode}`;\n\t}\n\tif (msg.truncated && msg.fullOutputPath) {\n\t\ttext += `\\n\\n[Output truncated. Full output: ${msg.fullOutputPath}]`;\n\t}\n\treturn text;\n}\n\nexport const VERBATIM_COMPACTION_PREFIX =\n\t'The earlier conversation was compacted. Below is the verbatim transcript of the retained lines; elided spans are marked \"(filtered N lines)\".\\n\\n';\nconst verbatimCompactionMessages = new WeakSet<CustomMessage>();\n\nexport function isVerbatimCompactionMessage(message: CustomMessage): boolean {\n\treturn verbatimCompactionMessages.has(message);\n}\n\n/**\n * Create the visible custom-role boundary used to replay a verbatim compaction.\n *\n * `retainedTail` holds the serialized kept tail. Its text merges into the boundary text and\n * its image blocks stay intact, so preserved content is not reduced to a placeholder.\n */\nexport function createVerbatimCompactionMessage(\n\tcompactedText: string,\n\ttokensBefore: number,\n\ttimestamp: string,\n\tdetails?: unknown,\n\tretainedTail?: readonly (TextContent | ImageContent)[],\n): CustomMessage {\n\tconst content: (TextContent | ImageContent)[] = [{ type: \"text\", text: VERBATIM_COMPACTION_PREFIX + compactedText }];\n\tfor (const block of retainedTail ?? []) {\n\t\tconst last = content[content.length - 1];\n\t\tif (block.type === \"text\" && last.type === \"text\") last.text += block.text;\n\t\telse content.push({ ...block });\n\t}\n\t// Ensure the authoritative whole-context count survives on the message details so\n\t// the boundary renderer can show it even when the caller supplied its own details\n\t// object. An existing tokensBefore is never overridden (#2052).\n\tconst mergedDetails = (() => {\n\t\tif (details === undefined) return { tokensBefore };\n\t\tif (typeof details !== \"object\" || details === null) return details;\n\t\treturn \"tokensBefore\" in details ? details : { ...details, tokensBefore };\n\t})();\n\tconst message = createCustomMessage(\"compaction\", content, true, mergedDetails, timestamp);\n\tverbatimCompactionMessages.add(message);\n\treturn message;\n}\n\nexport function createBranchSummaryMessage(summary: string, fromId: string, timestamp: string): BranchSummaryMessage {\n\treturn {\n\t\trole: \"branchSummary\",\n\t\tsummary,\n\t\tfromId,\n\t\ttimestamp: new Date(timestamp).getTime(),\n\t};\n}\n\n/** Convert CustomMessageEntry to AgentMessage format */\nexport function createCustomMessage(\n\tcustomType: string,\n\tcontent: string | (TextContent | ImageContent)[],\n\tdisplay: boolean,\n\tdetails: unknown | undefined,\n\ttimestamp: string,\n\texcludeFromContext?: boolean,\n\tstageAdmissionKey?: string,\n): StageAdmittedCustomMessage {\n\tconst message: StageAdmittedCustomMessage & { excludeFromContext?: boolean } = {\n\t\trole: \"custom\",\n\t\tcustomType,\n\t\tcontent: content ?? [],\n\t\tdisplay,\n\t\tdetails,\n\t\t...(stageAdmissionKey === undefined ? {} : { stageAdmissionKey }),\n\t\ttimestamp: new Date(timestamp).getTime(),\n\t};\n\tif (excludeFromContext === true) message.excludeFromContext = true;\n\treturn message;\n}\n\ninterface AssistantToolCallRef {\n\tid: string;\n\tname: string;\n}\n\nfunction collectAssistantToolCalls(message: AgentMessage): AssistantToolCallRef[] {\n\tconst content = (message as { content?: unknown }).content;\n\tconst calls: AssistantToolCallRef[] = [];\n\tif (!Array.isArray(content)) return calls;\n\tfor (const block of content) {\n\t\tif (!block || typeof block !== \"object\") continue;\n\t\tconst candidate = block as { type?: unknown; id?: unknown; name?: unknown };\n\t\tif (candidate.type === \"toolCall\" && typeof candidate.id === \"string\" && typeof candidate.name === \"string\") {\n\t\t\tcalls.push({ id: candidate.id, name: candidate.name });\n\t\t}\n\t}\n\treturn calls;\n}\n\nfunction getToolResultCallId(message: AgentMessage): string | undefined {\n\tif (message.role !== \"toolResult\") return undefined;\n\tconst toolCallId = (message as { toolCallId?: unknown }).toolCallId;\n\treturn typeof toolCallId === \"string\" ? toolCallId : undefined;\n}\n\n/**\n * Keep every tool result adjacent to the assistant turn that announced it.\n *\n * A message admitted while a tool batch is still running (an Intercom delivery, a\n * workflow lifecycle card, a durable stage admission) is persisted between the tool\n * call and its result in raw history. The provider requires the results to follow the\n * call directly, so derived context defers such messages until the batch is answered.\n * The durable transcript keeps its admission order.\n */\nexport function deferMessagesInterleavedWithToolBatch<TMessage extends AgentMessage>(messages: TMessage[]): TMessage[] {\n\tlet pending: Set<string> | undefined;\n\tlet deferred: TMessage[] = [];\n\tlet changed = false;\n\tconst ordered: TMessage[] = [];\n\tconst flushDeferred = (): void => {\n\t\tif (deferred.length > 0) {\n\t\t\tordered.push(...deferred);\n\t\t\tdeferred = [];\n\t\t}\n\t\tpending = undefined;\n\t};\n\tfor (const message of messages) {\n\t\tif (message.role === \"assistant\") {\n\t\t\tflushDeferred();\n\t\t\tordered.push(message);\n\t\t\tconst calls = collectAssistantToolCalls(message);\n\t\t\tpending =\n\t\t\t\tmessage.stopReason === \"toolUse\" && calls.length > 0 ? new Set(calls.map((call) => call.id)) : undefined;\n\t\t\tcontinue;\n\t\t}\n\t\tif (pending) {\n\t\t\tconst toolCallId = getToolResultCallId(message);\n\t\t\tif (toolCallId !== undefined && pending.has(toolCallId)) {\n\t\t\t\tordered.push(message);\n\t\t\t\tpending.delete(toolCallId);\n\t\t\t\tif (pending.size === 0) flushDeferred();\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif (message.role !== \"system\") {\n\t\t\t\tdeferred.push(message);\n\t\t\t\tchanged = true;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t}\n\t\tordered.push(message);\n\t}\n\tflushDeferred();\n\treturn changed ? ordered : messages;\n}\n\n/**\n * Enforce the provider's tool-pairing invariant on a converted message list.\n *\n * A provider rejects orphaned/duplicate `tool_result` blocks and any later turn\n * that crosses an unanswered `tool_use`. Keep exactly the first result for each\n * announced id. If a persisted session continues after its engine died before\n * recording every result, insert provider-only error results before that later\n * turn. The repair exists only in derived context; the durable transcript stays\n * unchanged, and the text makes no claim about whether admitted work completed\n * or produced side effects.\n */\nexport interface ToolCallPairRepairOptions {\n\t/** Close a final unanswered tool call when reopening an inactive session. */\n\trepairTrailing?: boolean;\n}\n\nexport function repairOrphanToolResults<TMessage extends AgentMessage>(\n\tmessages: TMessage[],\n\toptions: ToolCallPairRepairOptions = {},\n): (TMessage | ToolResultMessage)[] {\n\tlet allowedToolCallIds: Set<string> | undefined;\n\tlet answeredToolCallIds: Set<string> | undefined;\n\tlet pendingToolCalls: AssistantToolCallRef[] = [];\n\tlet pendingTimestamp = 0;\n\tlet changed = false;\n\tconst repaired: (TMessage | ToolResultMessage)[] = [];\n\tconst flushUnanswered = (): void => {\n\t\tfor (const call of pendingToolCalls) {\n\t\t\tif (answeredToolCallIds?.has(call.id)) continue;\n\t\t\tconst interrupted: ToolResultMessage = {\n\t\t\t\trole: \"toolResult\",\n\t\t\t\ttoolCallId: call.id,\n\t\t\t\ttoolName: call.name,\n\t\t\t\tcontent: [\n\t\t\t\t\t{\n\t\t\t\t\t\ttype: \"text\",\n\t\t\t\t\t\ttext: \"Tool execution was interrupted after it started; its result is unavailable. Inspect side effects before deciding whether to retry it.\",\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t\tisError: true,\n\t\t\t\ttimestamp: pendingTimestamp,\n\t\t\t};\n\t\t\trepaired.push(interrupted);\n\t\t\tchanged = true;\n\t\t}\n\t\tallowedToolCallIds = undefined;\n\t\tansweredToolCallIds = undefined;\n\t\tpendingToolCalls = [];\n\t};\n\tfor (const message of messages) {\n\t\t// Instruction/tool updates never close a pending tool batch.\n\t\tif (message.role === \"system\") {\n\t\t\trepaired.push(message);\n\t\t\tcontinue;\n\t\t}\n\t\tif (message.role === \"assistant\") {\n\t\t\tflushUnanswered();\n\t\t\tconst announcedToolCalls = collectAssistantToolCalls(message);\n\t\t\t// Only toolUse turns represent admitted executions. Error, aborted, and\n\t\t\t// length-limited turns may contain partial calls that providers discard.\n\t\t\tpendingToolCalls = message.stopReason === \"toolUse\" ? announcedToolCalls : [];\n\t\t\tallowedToolCallIds = new Set(announcedToolCalls.map((call) => call.id));\n\t\t\tansweredToolCallIds = new Set<string>();\n\t\t\tpendingTimestamp = message.timestamp;\n\t\t\trepaired.push(message);\n\t\t\tcontinue;\n\t\t}\n\t\tif (message.role === \"toolResult\") {\n\t\t\tconst toolCallId = getToolResultCallId(message);\n\t\t\tif (toolCallId && allowedToolCallIds?.has(toolCallId) && answeredToolCallIds?.has(toolCallId) === false) {\n\t\t\t\tansweredToolCallIds.add(toolCallId);\n\t\t\t\trepaired.push(message);\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tchanged = true;\n\t\t\tcontinue;\n\t\t}\n\t\t// A context-excluded card admitted while a tool was still running sits between\n\t\t// the call and its result in raw history but never reaches the provider, so it\n\t\t// cannot close the pending batch.\n\t\tif (!messageStartsLlmUserTurn(message)) {\n\t\t\trepaired.push(message);\n\t\t\tcontinue;\n\t\t}\n\t\tflushUnanswered();\n\t\trepaired.push(message);\n\t}\n\tif (options.repairTrailing) flushUnanswered();\n\treturn changed ? repaired : messages;\n}\n\nconst LEGACY_COMPACTION_SUMMARY_ROLE = \"compactionSummary\";\n\n/**\n * Transform AgentMessages (including custom types) to LLM-compatible Messages.\n *\n * This is used by:\n * - Agent's transormToLlm option (for prompt calls and queued messages)\n * - Branch summarization (for summarizing abandoned branches)\n * - Custom extensions and tools\n */\nexport function convertToLlm(messages: AgentMessage[]): Message[] {\n\tconst converted = messages\n\t\t.map((rawMessage): Message | undefined => {\n\t\t\tconst m = normalizeRawRedactedThinking(normalizeMessageContent(rawMessage));\n\t\t\tconst role: string = m.role;\n\t\t\tif (role === LEGACY_COMPACTION_SUMMARY_ROLE) return undefined;\n\t\t\tswitch (m.role) {\n\t\t\t\tcase \"bashExecution\":\n\t\t\t\t\tif (!messageStartsLlmUserTurn(m)) return undefined;\n\t\t\t\t\treturn {\n\t\t\t\t\t\trole: \"user\",\n\t\t\t\t\t\tcontent: [{ type: \"text\", text: bashExecutionToText(m) }],\n\t\t\t\t\t\ttimestamp: m.timestamp,\n\t\t\t\t\t};\n\t\t\t\tcase \"custom\": {\n\t\t\t\t\tif (!messageStartsLlmUserTurn(m)) return undefined;\n\t\t\t\t\tconst content =\n\t\t\t\t\t\ttypeof m.content === \"string\"\n\t\t\t\t\t\t\t? [{ type: \"text\" as const, text: m.content }]\n\t\t\t\t\t\t\t: (filterUserLikeContentBlocks(m.content) as Message[\"content\"]);\n\t\t\t\t\treturn { role: \"user\", content, timestamp: m.timestamp } as Message;\n\t\t\t\t}\n\t\t\t\tcase \"branchSummary\":\n\t\t\t\t\tif (!messageStartsLlmUserTurn(m)) return undefined;\n\t\t\t\t\treturn {\n\t\t\t\t\t\trole: \"user\",\n\t\t\t\t\t\tcontent: [{ type: \"text\" as const, text: BRANCH_SUMMARY_PREFIX + m.summary + BRANCH_SUMMARY_SUFFIX }],\n\t\t\t\t\t\ttimestamp: m.timestamp,\n\t\t\t\t\t};\n\t\t\t\tcase \"user\": {\n\t\t\t\t\tif (!messageStartsLlmUserTurn(m)) return undefined;\n\t\t\t\t\tif (!Array.isArray(m.content)) return m;\n\t\t\t\t\treturn { ...m, content: filterUserLikeContentBlocks(m.content) } as Message;\n\t\t\t\t}\n\t\t\t\tcase \"system\":\n\t\t\t\t\treturn m;\n\t\t\t\tcase \"assistant\":\n\t\t\t\tcase \"toolResult\":\n\t\t\t\t\treturn m;\n\t\t\t\tdefault: {\n\t\t\t\t\t// Exhaustiveness guard: new AgentMessage roles must define provider conversion explicitly.\n\t\t\t\t\tconst _exhaustiveCheck: never = m;\n\t\t\t\t\tvoid _exhaustiveCheck;\n\t\t\t\t\treturn undefined;\n\t\t\t\t}\n\t\t\t}\n\t\t})\n\t\t.filter((m) => m !== undefined);\n\treturn repairOrphanToolResults(uniquifyToolCallIds(converted));\n}\n"]}
|
|
1
|
+
{"version":3,"file":"messages.js","sourceRoot":"","sources":["../../src/core/messages.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAIH,OAAO,EAAE,mBAAmB,EAAE,MAAM,2BAA2B,CAAC;AAEhE,MAAM,CAAC,MAAM,qBAAqB,GAAG;;;CAGpC,CAAC;AAEF,MAAM,CAAC,MAAM,qBAAqB,GAAG,YAAY,CAAC;AAsDlD,4FAA4F;AAC5F,MAAM,UAAU,uBAAuB,CAAyB,OAAU;IACzE,QAAQ,OAAO,CAAC,IAAI,EAAE,CAAC;QACtB,KAAK,MAAM,CAAC;QACZ,KAAK,WAAW,CAAC;QACjB,KAAK,YAAY,CAAC;QAClB,KAAK,QAAQ;YACZ,OAAO,OAAO,CAAC,OAAO,IAAI,IAAI,CAAC,CAAC,CAAE,EAAE,GAAG,OAAO,EAAE,OAAO,EAAE,EAAE,EAAQ,CAAC,CAAC,CAAC,OAAO,CAAC;QAC/E;YACC,OAAO,OAAO,CAAC;IACjB,CAAC;AACF,CAAC;AAED,MAAM,UAAU,gCAAgC,CAAC,KAAc;IAC9D,IAAI,CAAC,KAAK,IAAI,OAAO,KAAK,KAAK,QAAQ;QAAE,OAAO,KAAK,CAAC;IACtD,MAAM,SAAS,GAAG,KAA2C,CAAC;IAC9D,IAAI,SAAS,CAAC,IAAI,KAAK,OAAO;QAAE,OAAO,IAAI,CAAC;IAC5C,IAAI,SAAS,CAAC,IAAI,KAAK,MAAM;QAAE,OAAO,OAAO,SAAS,CAAC,IAAI,KAAK,QAAQ,IAAI,SAAS,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC,MAAM,GAAG,CAAC,CAAC;IAC7G,iGAAiG;IACjG,OAAO,OAAO,SAAS,CAAC,IAAI,KAAK,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AAQ;gBACZ,OAAO,CAAC,CAAC;YACV,KAAK,WAAW,CAAC;YACjB,KAAK,YAAY;gBAChB,OAAO,CAAC,CAAC;YACV,SAAS,CAAC;gBACT,2FAA2F;gBAC3F,MAAM,gBAAgB,GAAU,CAAC,CAAC;gBAClC,KAAK,gBAAgB,CAAC;gBACtB,OAAO,SAAS,CAAC;YAClB,CAAC;QACF,CAAC;IACF,CAAC,CAAC;SACD,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,KAAK,SAAS,CAAC,CAAC;IACjC,OAAO,uBAAuB,CAAC,mBAAmB,CAAC,SAAS,CAAC,CAAC,CAAC;AAChE,CAAC","sourcesContent":["/**\n * Custom message types and transformers for the coding agent.\n *\n * Extends the base AgentMessage type with coding-agent specific message types,\n * and provides a transformer to convert them to LLM-compatible messages.\n */\n\nimport type { ImageContent, Message, TextContent, ToolResultMessage } from \"@bastani/pi-ai/compat\";\nimport type { AgentMessage } from \"@earendil-works/pi-agent-core\";\nimport { uniquifyToolCallIds } from \"./context-tool-pairing.js\";\n\nexport const BRANCH_SUMMARY_PREFIX = `The following is a summary of a branch that this conversation came back from:\n\n<summary>\n`;\n\nexport const BRANCH_SUMMARY_SUFFIX = `</summary>`;\n\n/**\n * Message type for bash executions via the ! command.\n */\nexport interface BashExecutionMessage {\n\trole: \"bashExecution\";\n\tcommand: string;\n\toutput: string;\n\texitCode: number | undefined;\n\tcancelled: boolean;\n\ttruncated: boolean;\n\tfullOutputPath?: string;\n\ttimestamp: number;\n\t/** If true, this message is excluded from LLM context (!! prefix) */\n\texcludeFromContext?: boolean;\n}\n\n/**\n * Message type for extension-injected messages via sendMessage().\n * These are custom messages that extensions can inject into the conversation.\n */\n\nexport interface CustomMessage<T = unknown> {\n\trole: \"custom\";\n\tcustomType: string;\n\tcontent: string | (TextContent | ImageContent)[];\n\tdisplay: boolean;\n\tdetails?: T;\n\ttimestamp: number;\n}\n\nexport type StageAdmittedCustomMessage<T = unknown> = CustomMessage<T> & {\n\t/** Stable producer identity used for exactly-once workflow-stage admission. */\n\tstageAdmissionKey?: string;\n\t/** Whether this admission joined active stage work or started after the assistant had settled. */\n};\n\nexport interface BranchSummaryMessage {\n\trole: \"branchSummary\";\n\tsummary: string;\n\tfromId: string | null;\n\ttimestamp: number;\n}\n\n// Extend CustomAgentMessages via declaration merging\ndeclare module \"@earendil-works/pi-agent-core\" {\n\tinterface CustomAgentMessages {\n\t\tbashExecution: BashExecutionMessage;\n\t\tcustom: CustomMessage;\n\t\tbranchSummary: BranchSummaryMessage;\n\t}\n}\n\n/** Normalize lax JavaScript/legacy message input before it reaches history or providers. */\nexport function normalizeMessageContent<T extends AgentMessage>(message: T): T {\n\tswitch (message.role) {\n\t\tcase \"user\":\n\t\tcase \"assistant\":\n\t\tcase \"toolResult\":\n\t\tcase \"custom\":\n\t\t\treturn message.content == null ? ({ ...message, content: [] } as T) : message;\n\t\tdefault:\n\t\t\treturn message;\n\t}\n}\n\nexport function userLikeContentBlockIsLlmVisible(block: unknown): boolean {\n\tif (!block || typeof block !== \"object\") return false;\n\tconst candidate = block as { type?: unknown; text?: unknown };\n\tif (candidate.type === \"image\") return true;\n\tif (candidate.type === \"text\") return typeof candidate.text === \"string\" && candidate.text.trim().length > 0;\n\t// Future provider-supported blocks must fail visible; only malformed/untyped blocks fail closed.\n\treturn typeof candidate.type === \"string\" && candidate.type.trim().length > 0;\n}\n\n/** Whether user/custom content survives provider conversion as a visible input. */\nexport function userLikeContentIsLlmVisible(\n\tcontent: unknown,\n\tdeletedBlockIndexes: ReadonlySet<number> = new Set<number>(),\n): boolean {\n\tif (typeof content === \"string\") return content.trim().length > 0;\n\tif (!Array.isArray(content)) return false;\n\treturn content.some((block, index) => !deletedBlockIndexes.has(index) && userLikeContentBlockIsLlmVisible(block));\n}\n\n/** Whether an Atomic message emits an LLM-visible user-like turn boundary. */\nexport function messageStartsLlmUserTurn(\n\tmessage: AgentMessage,\n\tdeletedBlockIndexes: ReadonlySet<number> = new Set<number>(),\n): boolean {\n\tswitch (message.role) {\n\t\tcase \"user\":\n\t\t\treturn userLikeContentIsLlmVisible(message.content, deletedBlockIndexes);\n\t\tcase \"custom\":\n\t\t\treturn (\n\t\t\t\t(message as CustomMessage & { excludeFromContext?: boolean }).excludeFromContext !== true &&\n\t\t\t\tuserLikeContentIsLlmVisible(message.content, deletedBlockIndexes)\n\t\t\t);\n\t\tcase \"branchSummary\":\n\t\t\t// Empty summaries are omitted by session reconstruction. Whitespace is\n\t\t\t// visible because the branch-summary wrapper itself is non-whitespace.\n\t\t\treturn typeof message.summary === \"string\" && message.summary.length > 0;\n\t\tcase \"bashExecution\":\n\t\t\treturn message.excludeFromContext !== true;\n\t\tdefault:\n\t\t\treturn false;\n\t}\n}\n\n/** Whether an Atomic message survives conversion into provider-visible context. */\nexport function messageIsLlmVisible(\n\tmessage: AgentMessage,\n\tdeletedBlockIndexes: ReadonlySet<number> = new Set<number>(),\n): boolean {\n\tif (message.role === \"system\" || message.role === \"assistant\" || message.role === \"toolResult\") return true;\n\treturn messageStartsLlmUserTurn(message, deletedBlockIndexes);\n}\n\n/** Filter invalid user-like blocks only in transient provider-bound content. */\nfunction filterUserLikeContentBlocks(content: unknown[]): unknown[] {\n\treturn content.filter(userLikeContentBlockIsLlmVisible);\n}\n\n/** Normalize raw blocks only in the transient LLM-compatible message returned by convertToLlm. */\nfunction normalizeRawRedactedThinking(message: AgentMessage): AgentMessage {\n\tif (message.role !== \"assistant\" || !Array.isArray(message.content)) return message;\n\tlet changed = false;\n\tconst content = message.content.map((block) => {\n\t\tif (!block || typeof block !== \"object\") return block;\n\t\tconst candidate = block as { type?: unknown; data?: unknown };\n\t\tif (candidate.type !== \"redacted_thinking\" || typeof candidate.data !== \"string\") return block;\n\t\tchanged = true;\n\t\treturn {\n\t\t\ttype: \"thinking\" as const,\n\t\t\tthinking: \"\",\n\t\t\tthinkingSignature: candidate.data,\n\t\t\tredacted: true,\n\t\t};\n\t});\n\treturn changed ? ({ ...message, content } as AgentMessage) : message;\n}\n\n/**\n * Convert a BashExecutionMessage to user message text for LLM context.\n */\nexport function bashExecutionToText(msg: BashExecutionMessage): string {\n\tlet text = `Ran \\`${msg.command}\\`\\n`;\n\tif (msg.output) {\n\t\ttext += `\\`\\`\\`\\n${msg.output}\\n\\`\\`\\``;\n\t} else {\n\t\ttext += \"(no output)\";\n\t}\n\tif (msg.cancelled) {\n\t\ttext += \"\\n\\n(command cancelled)\";\n\t} else if (msg.exitCode !== null && msg.exitCode !== undefined && msg.exitCode !== 0) {\n\t\ttext += `\\n\\nCommand exited with code ${msg.exitCode}`;\n\t}\n\tif (msg.truncated && msg.fullOutputPath) {\n\t\ttext += `\\n\\n[Output truncated. Full output: ${msg.fullOutputPath}]`;\n\t}\n\treturn text;\n}\n\nexport const VERBATIM_COMPACTION_PREFIX =\n\t'The earlier conversation was compacted. Below is the verbatim transcript of the retained lines; elided spans are marked \"(filtered N lines)\".\\n\\n';\nexport const SUMMARY_COMPACTION_PREFIX = \"The following is a summary of the earlier conversation:\\n\\n\";\nconst verbatimCompactionMessages = new WeakSet<CustomMessage>();\n\nexport function isVerbatimCompactionMessage(message: CustomMessage): boolean {\n\treturn verbatimCompactionMessages.has(message);\n}\n\n/**\n * Create the visible custom-role boundary used to replay a verbatim compaction.\n *\n * `retainedTail` holds the serialized kept tail. Its text merges into the boundary text and\n * its image blocks stay intact, so preserved content is not reduced to a placeholder.\n */\nexport function createVerbatimCompactionMessage(\n\tcompactedText: string,\n\ttokensBefore: number,\n\ttimestamp: string,\n\tdetails?: unknown,\n\tretainedTail?: readonly (TextContent | ImageContent)[],\n): CustomMessage {\n\tconst prefix =\n\t\ttypeof details === \"object\" && details !== null && \"backend\" in details && details.backend === \"summary\"\n\t\t\t? SUMMARY_COMPACTION_PREFIX\n\t\t\t: VERBATIM_COMPACTION_PREFIX;\n\tconst content: (TextContent | ImageContent)[] = [{ type: \"text\", text: prefix + compactedText }];\n\tfor (const block of retainedTail ?? []) {\n\t\tconst last = content[content.length - 1];\n\t\tif (block.type === \"text\" && last.type === \"text\") last.text += block.text;\n\t\telse content.push({ ...block });\n\t}\n\t// Ensure the authoritative whole-context count survives on the message details so\n\t// the boundary renderer can show it even when the caller supplied its own details\n\t// object. An existing tokensBefore is never overridden (#2052).\n\tconst mergedDetails = (() => {\n\t\tif (details === undefined) return { tokensBefore };\n\t\tif (typeof details !== \"object\" || details === null) return details;\n\t\treturn \"tokensBefore\" in details ? details : { ...details, tokensBefore };\n\t})();\n\tconst message = createCustomMessage(\"compaction\", content, true, mergedDetails, timestamp);\n\tverbatimCompactionMessages.add(message);\n\treturn message;\n}\n\nexport function createBranchSummaryMessage(summary: string, fromId: string, timestamp: string): BranchSummaryMessage {\n\treturn {\n\t\trole: \"branchSummary\",\n\t\tsummary,\n\t\tfromId,\n\t\ttimestamp: new Date(timestamp).getTime(),\n\t};\n}\n\n/** Convert CustomMessageEntry to AgentMessage format */\nexport function createCustomMessage(\n\tcustomType: string,\n\tcontent: string | (TextContent | ImageContent)[],\n\tdisplay: boolean,\n\tdetails: unknown | undefined,\n\ttimestamp: string,\n\texcludeFromContext?: boolean,\n\tstageAdmissionKey?: string,\n): StageAdmittedCustomMessage {\n\tconst message: StageAdmittedCustomMessage & { excludeFromContext?: boolean } = {\n\t\trole: \"custom\",\n\t\tcustomType,\n\t\tcontent: content ?? [],\n\t\tdisplay,\n\t\tdetails,\n\t\t...(stageAdmissionKey === undefined ? {} : { stageAdmissionKey }),\n\t\ttimestamp: new Date(timestamp).getTime(),\n\t};\n\tif (excludeFromContext === true) message.excludeFromContext = true;\n\treturn message;\n}\n\ninterface AssistantToolCallRef {\n\tid: string;\n\tname: string;\n}\n\nfunction collectAssistantToolCalls(message: AgentMessage): AssistantToolCallRef[] {\n\tconst content = (message as { content?: unknown }).content;\n\tconst calls: AssistantToolCallRef[] = [];\n\tif (!Array.isArray(content)) return calls;\n\tfor (const block of content) {\n\t\tif (!block || typeof block !== \"object\") continue;\n\t\tconst candidate = block as { type?: unknown; id?: unknown; name?: unknown };\n\t\tif (candidate.type === \"toolCall\" && typeof candidate.id === \"string\" && typeof candidate.name === \"string\") {\n\t\t\tcalls.push({ id: candidate.id, name: candidate.name });\n\t\t}\n\t}\n\treturn calls;\n}\n\nfunction getToolResultCallId(message: AgentMessage): string | undefined {\n\tif (message.role !== \"toolResult\") return undefined;\n\tconst toolCallId = (message as { toolCallId?: unknown }).toolCallId;\n\treturn typeof toolCallId === \"string\" ? toolCallId : undefined;\n}\n\n/**\n * Keep every tool result adjacent to the assistant turn that announced it.\n *\n * A message admitted while a tool batch is still running (an Intercom delivery, a\n * workflow lifecycle card, a durable stage admission) is persisted between the tool\n * call and its result in raw history. The provider requires the results to follow the\n * call directly, so derived context defers such messages until the batch is answered.\n * The durable transcript keeps its admission order.\n */\nexport function deferMessagesInterleavedWithToolBatch<TMessage extends AgentMessage>(messages: TMessage[]): TMessage[] {\n\tlet pending: Set<string> | undefined;\n\tlet deferred: TMessage[] = [];\n\tlet changed = false;\n\tconst ordered: TMessage[] = [];\n\tconst flushDeferred = (): void => {\n\t\tif (deferred.length > 0) {\n\t\t\tordered.push(...deferred);\n\t\t\tdeferred = [];\n\t\t}\n\t\tpending = undefined;\n\t};\n\tfor (const message of messages) {\n\t\tif (message.role === \"assistant\") {\n\t\t\tflushDeferred();\n\t\t\tordered.push(message);\n\t\t\tconst calls = collectAssistantToolCalls(message);\n\t\t\tpending =\n\t\t\t\tmessage.stopReason === \"toolUse\" && calls.length > 0 ? new Set(calls.map((call) => call.id)) : undefined;\n\t\t\tcontinue;\n\t\t}\n\t\tif (pending) {\n\t\t\tconst toolCallId = getToolResultCallId(message);\n\t\t\tif (toolCallId !== undefined && pending.has(toolCallId)) {\n\t\t\t\tordered.push(message);\n\t\t\t\tpending.delete(toolCallId);\n\t\t\t\tif (pending.size === 0) flushDeferred();\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif (message.role !== \"system\") {\n\t\t\t\tdeferred.push(message);\n\t\t\t\tchanged = true;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t}\n\t\tordered.push(message);\n\t}\n\tflushDeferred();\n\treturn changed ? ordered : messages;\n}\n\n/**\n * Enforce the provider's tool-pairing invariant on a converted message list.\n *\n * A provider rejects orphaned/duplicate `tool_result` blocks and any later turn\n * that crosses an unanswered `tool_use`. Keep exactly the first result for each\n * announced id. If a persisted session continues after its engine died before\n * recording every result, insert provider-only error results before that later\n * turn. The repair exists only in derived context; the durable transcript stays\n * unchanged, and the text makes no claim about whether admitted work completed\n * or produced side effects.\n */\nexport interface ToolCallPairRepairOptions {\n\t/** Close a final unanswered tool call when reopening an inactive session. */\n\trepairTrailing?: boolean;\n}\n\nexport function repairOrphanToolResults<TMessage extends AgentMessage>(\n\tmessages: TMessage[],\n\toptions: ToolCallPairRepairOptions = {},\n): (TMessage | ToolResultMessage)[] {\n\tlet allowedToolCallIds: Set<string> | undefined;\n\tlet answeredToolCallIds: Set<string> | undefined;\n\tlet pendingToolCalls: AssistantToolCallRef[] = [];\n\tlet pendingTimestamp = 0;\n\tlet changed = false;\n\tconst repaired: (TMessage | ToolResultMessage)[] = [];\n\tconst flushUnanswered = (): void => {\n\t\tfor (const call of pendingToolCalls) {\n\t\t\tif (answeredToolCallIds?.has(call.id)) continue;\n\t\t\tconst interrupted: ToolResultMessage = {\n\t\t\t\trole: \"toolResult\",\n\t\t\t\ttoolCallId: call.id,\n\t\t\t\ttoolName: call.name,\n\t\t\t\tcontent: [\n\t\t\t\t\t{\n\t\t\t\t\t\ttype: \"text\",\n\t\t\t\t\t\ttext: \"Tool execution was interrupted after it started; its result is unavailable. Inspect side effects before deciding whether to retry it.\",\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t\tisError: true,\n\t\t\t\ttimestamp: pendingTimestamp,\n\t\t\t};\n\t\t\trepaired.push(interrupted);\n\t\t\tchanged = true;\n\t\t}\n\t\tallowedToolCallIds = undefined;\n\t\tansweredToolCallIds = undefined;\n\t\tpendingToolCalls = [];\n\t};\n\tfor (const message of messages) {\n\t\t// Instruction/tool updates never close a pending tool batch.\n\t\tif (message.role === \"system\") {\n\t\t\trepaired.push(message);\n\t\t\tcontinue;\n\t\t}\n\t\tif (message.role === \"assistant\") {\n\t\t\tflushUnanswered();\n\t\t\tconst announcedToolCalls = collectAssistantToolCalls(message);\n\t\t\t// Only toolUse turns represent admitted executions. Error, aborted, and\n\t\t\t// length-limited turns may contain partial calls that providers discard.\n\t\t\tpendingToolCalls = message.stopReason === \"toolUse\" ? announcedToolCalls : [];\n\t\t\tallowedToolCallIds = new Set(announcedToolCalls.map((call) => call.id));\n\t\t\tansweredToolCallIds = new Set<string>();\n\t\t\tpendingTimestamp = message.timestamp;\n\t\t\trepaired.push(message);\n\t\t\tcontinue;\n\t\t}\n\t\tif (message.role === \"toolResult\") {\n\t\t\tconst toolCallId = getToolResultCallId(message);\n\t\t\tif (toolCallId && allowedToolCallIds?.has(toolCallId) && answeredToolCallIds?.has(toolCallId) === false) {\n\t\t\t\tansweredToolCallIds.add(toolCallId);\n\t\t\t\trepaired.push(message);\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tchanged = true;\n\t\t\tcontinue;\n\t\t}\n\t\t// A context-excluded card admitted while a tool was still running sits between\n\t\t// the call and its result in raw history but never reaches the provider, so it\n\t\t// cannot close the pending batch.\n\t\tif (!messageStartsLlmUserTurn(message)) {\n\t\t\trepaired.push(message);\n\t\t\tcontinue;\n\t\t}\n\t\tflushUnanswered();\n\t\trepaired.push(message);\n\t}\n\tif (options.repairTrailing) flushUnanswered();\n\treturn changed ? repaired : messages;\n}\n\nconst LEGACY_COMPACTION_SUMMARY_ROLE = \"compactionSummary\";\n\n/**\n * Transform AgentMessages (including custom types) to LLM-compatible Messages.\n *\n * This is used by:\n * - Agent's transormToLlm option (for prompt calls and queued messages)\n * - Branch summarization (for summarizing abandoned branches)\n * - Custom extensions and tools\n */\nexport function convertToLlm(messages: AgentMessage[]): Message[] {\n\tconst converted = messages\n\t\t.map((rawMessage): Message | undefined => {\n\t\t\tconst m = normalizeRawRedactedThinking(normalizeMessageContent(rawMessage));\n\t\t\tconst role: string = m.role;\n\t\t\tif (role === LEGACY_COMPACTION_SUMMARY_ROLE) return undefined;\n\t\t\tswitch (m.role) {\n\t\t\t\tcase \"bashExecution\":\n\t\t\t\t\tif (!messageStartsLlmUserTurn(m)) return undefined;\n\t\t\t\t\treturn {\n\t\t\t\t\t\trole: \"user\",\n\t\t\t\t\t\tcontent: [{ type: \"text\", text: bashExecutionToText(m) }],\n\t\t\t\t\t\ttimestamp: m.timestamp,\n\t\t\t\t\t};\n\t\t\t\tcase \"custom\": {\n\t\t\t\t\tif (!messageStartsLlmUserTurn(m)) return undefined;\n\t\t\t\t\tconst content =\n\t\t\t\t\t\ttypeof m.content === \"string\"\n\t\t\t\t\t\t\t? [{ type: \"text\" as const, text: m.content }]\n\t\t\t\t\t\t\t: (filterUserLikeContentBlocks(m.content) as Message[\"content\"]);\n\t\t\t\t\treturn { role: \"user\", content, timestamp: m.timestamp } as Message;\n\t\t\t\t}\n\t\t\t\tcase \"branchSummary\":\n\t\t\t\t\tif (!messageStartsLlmUserTurn(m)) return undefined;\n\t\t\t\t\treturn {\n\t\t\t\t\t\trole: \"user\",\n\t\t\t\t\t\tcontent: [{ type: \"text\" as const, text: BRANCH_SUMMARY_PREFIX + m.summary + BRANCH_SUMMARY_SUFFIX }],\n\t\t\t\t\t\ttimestamp: m.timestamp,\n\t\t\t\t\t};\n\t\t\t\tcase \"user\": {\n\t\t\t\t\tif (!messageStartsLlmUserTurn(m)) return undefined;\n\t\t\t\t\tif (!Array.isArray(m.content)) return m;\n\t\t\t\t\treturn { ...m, content: filterUserLikeContentBlocks(m.content) } as Message;\n\t\t\t\t}\n\t\t\t\tcase \"system\":\n\t\t\t\t\treturn m;\n\t\t\t\tcase \"assistant\":\n\t\t\t\tcase \"toolResult\":\n\t\t\t\t\treturn m;\n\t\t\t\tdefault: {\n\t\t\t\t\t// Exhaustiveness guard: new AgentMessage roles must define provider conversion explicitly.\n\t\t\t\t\tconst _exhaustiveCheck: never = m;\n\t\t\t\t\tvoid _exhaustiveCheck;\n\t\t\t\t\treturn undefined;\n\t\t\t\t}\n\t\t\t}\n\t\t})\n\t\t.filter((m) => m !== undefined);\n\treturn repairOrphanToolResults(uniquifyToolCallIds(converted));\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"remote-catalog-provider.d.ts","sourceRoot":"","sources":["../../src/core/remote-catalog-provider.ts"],"names":[],"mappings":"AAAA,OAAO,EAKN,KAAK,SAAS,EACd,KAAK,QAAQ,EACb,MAAM,gBAAgB,CAAC;AAOxB,eAAO,MAAM,kCAAkC,QAAqB,CAAC;AACrE;;;;;GAKG;AACH,eAAO,MAAM,0BAA0B,EAAE,SAAS,SAAS,EAAoC,CAAC;AAmEhG,4EAA4E;AAC5E,wBAAgB,iBAAiB,CAChC,QAAQ,EAAE,QAAQ,EAClB,cAAc,GAAE,MAAiC,EACjD,gBAAgB,CAAC,EAAE,MAAM,GACvB,QAAQ,
|
|
1
|
+
{"version":3,"file":"remote-catalog-provider.d.ts","sourceRoot":"","sources":["../../src/core/remote-catalog-provider.ts"],"names":[],"mappings":"AAAA,OAAO,EAKN,KAAK,SAAS,EACd,KAAK,QAAQ,EACb,MAAM,gBAAgB,CAAC;AAOxB,eAAO,MAAM,kCAAkC,QAAqB,CAAC;AACrE;;;;;GAKG;AACH,eAAO,MAAM,0BAA0B,EAAE,SAAS,SAAS,EAAoC,CAAC;AAmEhG,4EAA4E;AAC5E,wBAAgB,iBAAiB,CAChC,QAAQ,EAAE,QAAQ,EAClB,cAAc,GAAE,MAAiC,EACjD,gBAAgB,CAAC,EAAE,MAAM,GACvB,QAAQ,CAsGV"}
|
|
@@ -74,6 +74,9 @@ function remoteModels(entry, localGeneratedAt) {
|
|
|
74
74
|
}
|
|
75
75
|
/** Add a persisted pi.dev catalog overlay to a static built-in provider. */
|
|
76
76
|
export function withRemoteCatalog(provider, catalogBaseUrl = DEFAULT_CATALOG_BASE_URL, localGeneratedAt) {
|
|
77
|
+
const models = provider.getAllModels?.() ?? provider.getModels();
|
|
78
|
+
if (models.length > 0 && !models.some(isSupportedModelType))
|
|
79
|
+
return provider;
|
|
77
80
|
let dynamicModels = [];
|
|
78
81
|
return {
|
|
79
82
|
...provider,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"remote-catalog-provider.js","sourceRoot":"","sources":["../../src/core/remote-catalog-provider.ts"],"names":[],"mappings":"AAAA,OAAO,EAEN,YAAY,EACZ,WAAW,GAIX,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACvC,OAAO,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAC;AAC7D,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAE3D,MAAM,wBAAwB,GAAG,gBAAgB,CAAC;AAClD,MAAM,iCAAiC,GAAG,KAAK,CAAC;AAChD,MAAM,CAAC,MAAM,kCAAkC,GAAG,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC;AACrE;;;;;GAKG;AACH,MAAM,CAAC,MAAM,0BAA0B,GAAyB,CAAC,MAAM,EAAE,OAAO,EAAE,YAAY,CAAC,CAAC;AAEhG,SAAS,oBAAoB,CAAC,KAAyB;IACtD,OAAO,CACN,KAAK,CAAC,IAAI,KAAK,SAAS;QACxB,CAAC,OAAO,KAAK,CAAC,IAAI,KAAK,QAAQ,IAAI,0BAA0B,CAAC,QAAQ,CAAC,KAAK,CAAC,IAAiB,CAAC,CAAC,CAChG,CAAC;AACH,CAAC;AAED,SAAS,iBAAiB,CAAC,KAAc;IACxC,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI;QAAE,OAAO,KAAK,CAAC;IAC9D,IAAI,CAAC,CAAC,MAAM,IAAI,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,KAAK,OAAO,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,EAAE,MAAM,CAAC,KAAK,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,YAAY;gBAC3D,IAAI,EAAE,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,SAAS;aAC/C,CAAC;YACF,MAAM,SAAS,GAAG,YAAY,CAAC,KAAK,EAAE,gBAAgB,CAAC,CAAC;YACxD,MAAM,OAAO,CAAC,OAAO,CAAC;gBACrB,OAAO,EAAE,KAAK;gBACd,MAAM,EAAE,GAAG,EAAE;oBACZ,aAAa,GAAG,SAAS,CAAC;gBAC3B,CAAC;aACD,CAAC,CAAC;QACJ,CAAC;KACD,CAAC;AACH,CAAC","sourcesContent":["import {\n\ttype AnyModel,\n\tgetModelType,\n\tisModelType,\n\ttype ModelsStoreEntry,\n\ttype ModelType,\n\ttype Provider,\n} from \"@bastani/pi-ai\";\nimport { VERSION } from \"../config.js\";\nimport { fetchWithRetry } from \"../utils/management-http.ts\";\nimport { getPiUserAgent } from \"../utils/pi-user-agent.ts\";\n\nconst DEFAULT_CATALOG_BASE_URL = \"https://pi.dev\";\nconst REMOTE_CATALOG_ATTEMPT_TIMEOUT_MS = 4_000;\nexport const REMOTE_CATALOG_REFRESH_INTERVAL_MS = 4 * 60 * 60 * 1000;\n/**\n * Model types this client can consume. Sent as `?types=` so the catalog server\n * returns the full-type shard instead of the chat-only one served to clients\n * that predate model types. A server that ignores the parameter still returns\n * the chat-only shard, which this client handles unchanged.\n */\nexport const REMOTE_CATALOG_MODEL_TYPES: readonly ModelType[] = [\"chat\", \"image\", \"classifier\"];\n\nfunction isSupportedModelType(model: { type?: unknown }): boolean {\n\treturn (\n\t\tmodel.type === undefined ||\n\t\t(typeof model.type === \"string\" && REMOTE_CATALOG_MODEL_TYPES.includes(model.type as ModelType))\n\t);\n}\n\nfunction hasOperationShape(model: unknown): boolean {\n\tif (typeof model !== \"object\" || model === null) return false;\n\tif (!(\"type\" in model) || (model.type !== \"image\" && model.type !== \"classifier\")) return true;\n\tif (!(\"cost\" in model)) return false;\n\tconst cost = model.cost;\n\treturn (\n\t\t\"id\" in model &&\n\t\ttypeof model.id === \"string\" &&\n\t\tmodel.id.length > 0 &&\n\t\t\"name\" in model &&\n\t\ttypeof model.name === \"string\" &&\n\t\t\"api\" in model &&\n\t\ttypeof model.api === \"string\" &&\n\t\t\"baseUrl\" in model &&\n\t\ttypeof model.baseUrl === \"string\" &&\n\t\t\"input\" in model &&\n\t\tArray.isArray(model.input) &&\n\t\tcost !== null &&\n\t\ttypeof cost === \"object\" &&\n\t\t[\"input\", \"output\", \"cacheRead\", \"cacheWrite\"].every(\n\t\t\t(key) => key in cost && typeof (cost as Record<string, unknown>)[key] === \"number\",\n\t\t) &&\n\t\t(model.type === \"image\"\n\t\t\t? \"output\" in model && Array.isArray(model.output) && model.output.includes(\"image\")\n\t\t\t: \"contextWindow\" in model && typeof model.contextWindow === \"number\" && model.contextWindow > 0)\n\t);\n}\n\nfunction mergeModels<TModel extends AnyModel>(baseline: readonly TModel[], dynamic: readonly TModel[]): TModel[] {\n\tconst merged = new Map<string, TModel>();\n\tfor (const model of [...baseline, ...dynamic]) merged.set(`${getModelType(model)}\\0${model.id}`, model);\n\treturn [...merged.values()];\n}\n\nfunction parseCatalog(providerId: string, value: unknown): AnyModel[] {\n\tconst entries = Array.isArray(value)\n\t\t? value\n\t\t: typeof value === \"object\" && value !== null && \"models\" in value && Array.isArray(value.models)\n\t\t\t? value.models\n\t\t\t: typeof value === \"object\" && value !== null\n\t\t\t\t? Object.values(value)\n\t\t\t\t: undefined;\n\tif (!entries) throw new Error(`Invalid model catalog for provider \"${providerId}\"`);\n\treturn entries\n\t\t.filter((entry): entry is Record<string, unknown> => typeof entry === \"object\" && entry !== null && \"id\" in entry)\n\t\t.filter(isSupportedModelType)\n\t\t.filter(hasOperationShape)\n\t\t.map((model) => ({ ...model, provider: providerId }) as AnyModel);\n}\n\nfunction remoteModels(entry: ModelsStoreEntry | undefined, localGeneratedAt: number | undefined): readonly AnyModel[] {\n\tif (!entry) return [];\n\tif (localGeneratedAt !== undefined && (entry.lastModified === undefined || entry.lastModified <= localGeneratedAt)) {\n\t\treturn [];\n\t}\n\treturn entry.models;\n}\n\n/** Add a persisted pi.dev catalog overlay to a static built-in provider. */\nexport function withRemoteCatalog(\n\tprovider: Provider,\n\tcatalogBaseUrl: string = DEFAULT_CATALOG_BASE_URL,\n\tlocalGeneratedAt?: number,\n): Provider {\n\tlet dynamicModels: readonly AnyModel[] = [];\n\n\treturn {\n\t\t...provider,\n\t\tgetModels: () =>\n\t\t\tmergeModels(\n\t\t\t\tprovider.getModels(),\n\t\t\t\tdynamicModels.filter((model) => isModelType(model, \"chat\")),\n\t\t\t),\n\t\tgetAllModels: () => mergeModels(provider.getAllModels?.() ?? provider.getModels(), dynamicModels),\n\t\trefreshModels: async (context) => {\n\t\t\t// 0.84.1 hands the snapshot in directly and coalesces concurrent refreshes\n\t\t\t// itself, so the old inflight-promise dedup is gone. Every mutation of\n\t\t\t// dynamicModels now runs inside a generation-checked publish; a false return\n\t\t\t// means a newer refresh already superseded this pass, so it must not continue.\n\t\t\tconst stored = context.stored;\n\t\t\tconst restored = remoteModels(stored, localGeneratedAt).filter(\n\t\t\t\t(model) => model.provider === provider.id && hasOperationShape(model),\n\t\t\t);\n\t\t\tif (\n\t\t\t\t!(await context.publish({\n\t\t\t\t\tupdate: () => {\n\t\t\t\t\t\tdynamicModels = restored;\n\t\t\t\t\t},\n\t\t\t\t}))\n\t\t\t) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif (!context.allowNetwork || context.signal.aborted) return;\n\t\t\tif (\n\t\t\t\t!context.force &&\n\t\t\t\tstored?.checkedAt !== undefined &&\n\t\t\t\tstored.lastModified !== undefined &&\n\t\t\t\tDate.now() - stored.checkedAt < REMOTE_CATALOG_REFRESH_INTERVAL_MS\n\t\t\t) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\t// Only revalidate when a cached body backs the validator, so a 304 can never\n\t\t\t// leave the overlay empty.\n\t\t\tconst validator = stored && stored.models.length > 0 ? stored.etag : undefined;\n\t\t\tconst url = new URL(`/api/models/providers/${encodeURIComponent(provider.id)}`, catalogBaseUrl);\n\t\t\turl.searchParams.set(\"types\", REMOTE_CATALOG_MODEL_TYPES.join(\",\"));\n\t\t\tconst response = await fetchWithRetry(\n\t\t\t\turl,\n\t\t\t\t{\n\t\t\t\t\theaders: {\n\t\t\t\t\t\taccept: \"application/json\",\n\t\t\t\t\t\t\"User-Agent\": getPiUserAgent(VERSION),\n\t\t\t\t\t\t...(validator ? { \"if-none-match\": validator } : {}),\n\t\t\t\t\t},\n\t\t\t\t\tsignal: context.signal,\n\t\t\t\t},\n\t\t\t\t{ attemptTimeoutMs: REMOTE_CATALOG_ATTEMPT_TIMEOUT_MS },\n\t\t\t);\n\t\t\tif (context.signal.aborted) return;\n\t\t\tconst checkedAt = Date.now();\n\t\t\t// Unchanged: dynamicModels already holds the stored overlay, so only the\n\t\t\t// freshness window moves.\n\t\t\tif (response.status === 304 && stored) {\n\t\t\t\tawait context.publish({ persist: { ...stored, checkedAt } });\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif (response.status === 404 || response.status === 501) {\n\t\t\t\tawait context.publish({\n\t\t\t\t\tpersist: {\n\t\t\t\t\t\t...(stored ?? { models: [] }),\n\t\t\t\t\t\tcheckedAt,\n\t\t\t\t\t\tlastModified: 0,\n\t\t\t\t\t\tetag: undefined,\n\t\t\t\t\t},\n\t\t\t\t});\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif (!response.ok) {\n\t\t\t\t// Transient failure: the cached body and its validator stay valid, so keep the\n\t\t\t\t// etag and let the next refresh revalidate instead of downloading the catalog.\n\t\t\t\tawait context.publish({ persist: { ...(stored ?? { models: [] }), checkedAt } });\n\t\t\t\tthrow new Error(`Model catalog request failed for ${provider.id}: ${response.status}`);\n\t\t\t}\n\t\t\tconst refreshed = parseCatalog(provider.id, await response.json());\n\t\t\tconst lastModified = Date.parse(response.headers.get(\"last-modified\") ?? \"\");\n\t\t\tif (context.signal.aborted) return;\n\t\t\tconst entry: ModelsStoreEntry = {\n\t\t\t\tmodels: refreshed,\n\t\t\t\tcheckedAt,\n\t\t\t\tlastModified: Number.isNaN(lastModified) ? 0 : lastModified,\n\t\t\t\tetag: response.headers.get(\"etag\") ?? undefined,\n\t\t\t};\n\t\t\tconst published = remoteModels(entry, localGeneratedAt);\n\t\t\tawait context.publish({\n\t\t\t\tpersist: entry,\n\t\t\t\tupdate: () => {\n\t\t\t\t\tdynamicModels = published;\n\t\t\t\t},\n\t\t\t});\n\t\t},\n\t};\n}\n"]}
|
|
1
|
+
{"version":3,"file":"remote-catalog-provider.js","sourceRoot":"","sources":["../../src/core/remote-catalog-provider.ts"],"names":[],"mappings":"AAAA,OAAO,EAEN,YAAY,EACZ,WAAW,GAIX,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACvC,OAAO,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAC;AAC7D,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAE3D,MAAM,wBAAwB,GAAG,gBAAgB,CAAC;AAClD,MAAM,iCAAiC,GAAG,KAAK,CAAC;AAChD,MAAM,CAAC,MAAM,kCAAkC,GAAG,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC;AACrE;;;;;GAKG;AACH,MAAM,CAAC,MAAM,0BAA0B,GAAyB,CAAC,MAAM,EAAE,OAAO,EAAE,YAAY,CAAC,CAAC;AAEhG,SAAS,oBAAoB,CAAC,KAAyB;IACtD,OAAO,CACN,KAAK,CAAC,IAAI,KAAK,SAAS;QACxB,CAAC,OAAO,KAAK,CAAC,IAAI,KAAK,QAAQ,IAAI,0BAA0B,CAAC,QAAQ,CAAC,KAAK,CAAC,IAAiB,CAAC,CAAC,CAChG,CAAC;AACH,CAAC;AAED,SAAS,iBAAiB,CAAC,KA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AAM,EAAE,CAAC,CAAC;YACxF,CAAC;YACD,MAAM,SAAS,GAAG,YAAY,CAAC,QAAQ,CAAC,EAAE,EAAE,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAC,CAAC;YACnE,MAAM,YAAY,GAAG,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,eAAe,CAAC,IAAI,EAAE,CAAC,CAAC;YAC7E,IAAI,OAAO,CAAC,MAAM,CAAC,OAAO;gBAAE,OAAO;YACnC,MAAM,KAAK,GAAqB;gBAC/B,MAAM,EAAE,SAAS;gBACjB,SAAS;gBACT,YAAY,EAAE,MAAM,CAAC,KAAK,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,YAAY;gBAC3D,IAAI,EAAE,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,SAAS;aAC/C,CAAC;YACF,MAAM,SAAS,GAAG,YAAY,CAAC,KAAK,EAAE,gBAAgB,CAAC,CAAC;YACxD,MAAM,OAAO,CAAC,OAAO,CAAC;gBACrB,OAAO,EAAE,KAAK;gBACd,MAAM,EAAE,GAAG,EAAE;oBACZ,aAAa,GAAG,SAAS,CAAC;gBAC3B,CAAC;aACD,CAAC,CAAC;QACJ,CAAC;KACD,CAAC;AACH,CAAC","sourcesContent":["import {\n\ttype AnyModel,\n\tgetModelType,\n\tisModelType,\n\ttype ModelsStoreEntry,\n\ttype ModelType,\n\ttype Provider,\n} from \"@bastani/pi-ai\";\nimport { VERSION } from \"../config.js\";\nimport { fetchWithRetry } from \"../utils/management-http.ts\";\nimport { getPiUserAgent } from \"../utils/pi-user-agent.ts\";\n\nconst DEFAULT_CATALOG_BASE_URL = \"https://pi.dev\";\nconst REMOTE_CATALOG_ATTEMPT_TIMEOUT_MS = 4_000;\nexport const REMOTE_CATALOG_REFRESH_INTERVAL_MS = 4 * 60 * 60 * 1000;\n/**\n * Model types this client can consume. Sent as `?types=` so the catalog server\n * returns the full-type shard instead of the chat-only one served to clients\n * that predate model types. A server that ignores the parameter still returns\n * the chat-only shard, which this client handles unchanged.\n */\nexport const REMOTE_CATALOG_MODEL_TYPES: readonly ModelType[] = [\"chat\", \"image\", \"classifier\"];\n\nfunction isSupportedModelType(model: { type?: unknown }): boolean {\n\treturn (\n\t\tmodel.type === undefined ||\n\t\t(typeof model.type === \"string\" && REMOTE_CATALOG_MODEL_TYPES.includes(model.type as ModelType))\n\t);\n}\n\nfunction hasOperationShape(model: unknown): boolean {\n\tif (typeof model !== \"object\" || model === null) return false;\n\tif (!(\"type\" in model) || (model.type !== \"image\" && model.type !== \"classifier\")) return true;\n\tif (!(\"cost\" in model)) return false;\n\tconst cost = model.cost;\n\treturn (\n\t\t\"id\" in model &&\n\t\ttypeof model.id === \"string\" &&\n\t\tmodel.id.length > 0 &&\n\t\t\"name\" in model &&\n\t\ttypeof model.name === \"string\" &&\n\t\t\"api\" in model &&\n\t\ttypeof model.api === \"string\" &&\n\t\t\"baseUrl\" in model &&\n\t\ttypeof model.baseUrl === \"string\" &&\n\t\t\"input\" in model &&\n\t\tArray.isArray(model.input) &&\n\t\tcost !== null &&\n\t\ttypeof cost === \"object\" &&\n\t\t[\"input\", \"output\", \"cacheRead\", \"cacheWrite\"].every(\n\t\t\t(key) => key in cost && typeof (cost as Record<string, unknown>)[key] === \"number\",\n\t\t) &&\n\t\t(model.type === \"image\"\n\t\t\t? \"output\" in model && Array.isArray(model.output) && model.output.includes(\"image\")\n\t\t\t: \"contextWindow\" in model && typeof model.contextWindow === \"number\" && model.contextWindow > 0)\n\t);\n}\n\nfunction mergeModels<TModel extends AnyModel>(baseline: readonly TModel[], dynamic: readonly TModel[]): TModel[] {\n\tconst merged = new Map<string, TModel>();\n\tfor (const model of [...baseline, ...dynamic]) merged.set(`${getModelType(model)}\\0${model.id}`, model);\n\treturn [...merged.values()];\n}\n\nfunction parseCatalog(providerId: string, value: unknown): AnyModel[] {\n\tconst entries = Array.isArray(value)\n\t\t? value\n\t\t: typeof value === \"object\" && value !== null && \"models\" in value && Array.isArray(value.models)\n\t\t\t? value.models\n\t\t\t: typeof value === \"object\" && value !== null\n\t\t\t\t? Object.values(value)\n\t\t\t\t: undefined;\n\tif (!entries) throw new Error(`Invalid model catalog for provider \"${providerId}\"`);\n\treturn entries\n\t\t.filter((entry): entry is Record<string, unknown> => typeof entry === \"object\" && entry !== null && \"id\" in entry)\n\t\t.filter(isSupportedModelType)\n\t\t.filter(hasOperationShape)\n\t\t.map((model) => ({ ...model, provider: providerId }) as AnyModel);\n}\n\nfunction remoteModels(entry: ModelsStoreEntry | undefined, localGeneratedAt: number | undefined): readonly AnyModel[] {\n\tif (!entry) return [];\n\tif (localGeneratedAt !== undefined && (entry.lastModified === undefined || entry.lastModified <= localGeneratedAt)) {\n\t\treturn [];\n\t}\n\treturn entry.models;\n}\n\n/** Add a persisted pi.dev catalog overlay to a static built-in provider. */\nexport function withRemoteCatalog(\n\tprovider: Provider,\n\tcatalogBaseUrl: string = DEFAULT_CATALOG_BASE_URL,\n\tlocalGeneratedAt?: number,\n): Provider {\n\tconst models = provider.getAllModels?.() ?? provider.getModels();\n\tif (models.length > 0 && !models.some(isSupportedModelType)) return provider;\n\n\tlet dynamicModels: readonly AnyModel[] = [];\n\n\treturn {\n\t\t...provider,\n\t\tgetModels: () =>\n\t\t\tmergeModels(\n\t\t\t\tprovider.getModels(),\n\t\t\t\tdynamicModels.filter((model) => isModelType(model, \"chat\")),\n\t\t\t),\n\t\tgetAllModels: () => mergeModels(provider.getAllModels?.() ?? provider.getModels(), dynamicModels),\n\t\trefreshModels: async (context) => {\n\t\t\t// 0.84.1 hands the snapshot in directly and coalesces concurrent refreshes\n\t\t\t// itself, so the old inflight-promise dedup is gone. Every mutation of\n\t\t\t// dynamicModels now runs inside a generation-checked publish; a false return\n\t\t\t// means a newer refresh already superseded this pass, so it must not continue.\n\t\t\tconst stored = context.stored;\n\t\t\tconst restored = remoteModels(stored, localGeneratedAt).filter(\n\t\t\t\t(model) => model.provider === provider.id && hasOperationShape(model),\n\t\t\t);\n\t\t\tif (\n\t\t\t\t!(await context.publish({\n\t\t\t\t\tupdate: () => {\n\t\t\t\t\t\tdynamicModels = restored;\n\t\t\t\t\t},\n\t\t\t\t}))\n\t\t\t) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif (!context.allowNetwork || context.signal.aborted) return;\n\t\t\tif (\n\t\t\t\t!context.force &&\n\t\t\t\tstored?.checkedAt !== undefined &&\n\t\t\t\tstored.lastModified !== undefined &&\n\t\t\t\tDate.now() - stored.checkedAt < REMOTE_CATALOG_REFRESH_INTERVAL_MS\n\t\t\t) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\t// Only revalidate when a cached body backs the validator, so a 304 can never\n\t\t\t// leave the overlay empty.\n\t\t\tconst validator = stored && stored.models.length > 0 ? stored.etag : undefined;\n\t\t\tconst url = new URL(`/api/models/providers/${encodeURIComponent(provider.id)}`, catalogBaseUrl);\n\t\t\turl.searchParams.set(\"types\", REMOTE_CATALOG_MODEL_TYPES.join(\",\"));\n\t\t\tconst response = await fetchWithRetry(\n\t\t\t\turl,\n\t\t\t\t{\n\t\t\t\t\theaders: {\n\t\t\t\t\t\taccept: \"application/json\",\n\t\t\t\t\t\t\"User-Agent\": getPiUserAgent(VERSION),\n\t\t\t\t\t\t...(validator ? { \"if-none-match\": validator } : {}),\n\t\t\t\t\t},\n\t\t\t\t\tsignal: context.signal,\n\t\t\t\t},\n\t\t\t\t{ attemptTimeoutMs: REMOTE_CATALOG_ATTEMPT_TIMEOUT_MS },\n\t\t\t);\n\t\t\tif (context.signal.aborted) return;\n\t\t\tconst checkedAt = Date.now();\n\t\t\t// Unchanged: dynamicModels already holds the stored overlay, so only the\n\t\t\t// freshness window moves.\n\t\t\tif (response.status === 304 && stored) {\n\t\t\t\tawait context.publish({ persist: { ...stored, checkedAt } });\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif (response.status === 404 || response.status === 501) {\n\t\t\t\tawait context.publish({\n\t\t\t\t\tpersist: {\n\t\t\t\t\t\t...(stored ?? { models: [] }),\n\t\t\t\t\t\tcheckedAt,\n\t\t\t\t\t\tlastModified: 0,\n\t\t\t\t\t\tetag: undefined,\n\t\t\t\t\t},\n\t\t\t\t});\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif (!response.ok) {\n\t\t\t\t// Transient failure: the cached body and its validator stay valid, so keep the\n\t\t\t\t// etag and let the next refresh revalidate instead of downloading the catalog.\n\t\t\t\tawait context.publish({ persist: { ...(stored ?? { models: [] }), checkedAt } });\n\t\t\t\tthrow new Error(`Model catalog request failed for ${provider.id}: ${response.status}`);\n\t\t\t}\n\t\t\tconst refreshed = parseCatalog(provider.id, await response.json());\n\t\t\tconst lastModified = Date.parse(response.headers.get(\"last-modified\") ?? \"\");\n\t\t\tif (context.signal.aborted) return;\n\t\t\tconst entry: ModelsStoreEntry = {\n\t\t\t\tmodels: refreshed,\n\t\t\t\tcheckedAt,\n\t\t\t\tlastModified: Number.isNaN(lastModified) ? 0 : lastModified,\n\t\t\t\tetag: response.headers.get(\"etag\") ?? undefined,\n\t\t\t};\n\t\t\tconst published = remoteModels(entry, localGeneratedAt);\n\t\t\tawait context.publish({\n\t\t\t\tpersist: entry,\n\t\t\t\tupdate: () => {\n\t\t\t\t\tdynamicModels = published;\n\t\t\t\t},\n\t\t\t});\n\t\t},\n\t};\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"session-manager-history.d.ts","sourceRoot":"","sources":["../../src/core/session-manager-history.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,+BAA+B,CAAC;AAClE,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,kCAAkC,CAAC;AAUlF,OAAO,KAAK,EACX,eAAe,EACf,gBAAgB,EAChB,SAAS,EAET,cAAc,EACd,YAAY,EACZ,iBAAiB,EACjB,eAAe,EACf,MAAM,4BAA4B,CAAC;AA6CpC,wEAAwE;AACxE,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,SAAS,YAAY,EAAE,GAAG,GAAG,CAAC,MAAM,EAAE,gBAAgB,CAAC,CAMnG;AAED,+EAA+E;AAC/E,wBAAgB,gBAAgB,CAAC,QAAQ,EAAE,YAAY,EAAE,EAAE,IAAI,EAAE,gBAAgB,GAAG,YAAY,EAAE,CAmBjG;AA2BD,wBAAgB,gCAAgC,CAC/C,OAAO,EAAE,YAAY,EAAE,GACrB,eAAe,CAAC,yBAAyB,CAAC,GAAG,IAAI,CAQnD;AAED,2FAA2F;AAC3F,wBAAgB,6BAA6B,CAAC,KAAK,EAAE,YAAY,GAAG,YAAY,EAAE,CAiCjF;AAED,sFAAsF;AACtF,wBAAgB,mBAAmB,CAClC,OAAO,EAAE,YAAY,EAAE,EACvB,MAAM,CAAC,EAAE,MAAM,GAAG,IAAI,EACtB,IAAI,4BAAqD,GACvD,YAAY,EAAE,CAgBhB;AAED;;;;;;;;;GASG;AACH,wBAAgB,sBAAsB,CACrC,OAAO,EAAE,YAAY,EAAE,EACvB,MAAM,CAAC,EAAE,MAAM,GAAG,IAAI,EACtB,IAAI,CAAC,EAAE,GAAG,CAAC,MAAM,EAAE,YAAY,CAAC,GAC9B,iBAAiB,
|
|
1
|
+
{"version":3,"file":"session-manager-history.d.ts","sourceRoot":"","sources":["../../src/core/session-manager-history.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,+BAA+B,CAAC;AAClE,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,kCAAkC,CAAC;AAUlF,OAAO,KAAK,EACX,eAAe,EACf,gBAAgB,EAChB,SAAS,EAET,cAAc,EACd,YAAY,EACZ,iBAAiB,EACjB,eAAe,EACf,MAAM,4BAA4B,CAAC;AA6CpC,wEAAwE;AACxE,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,SAAS,YAAY,EAAE,GAAG,GAAG,CAAC,MAAM,EAAE,gBA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AAM,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,EAAE,IAAI,EAAE,GAAG,CAAC,MAAM,EAAE,YAAY,CAAC,GAAG,YAAY,EAAE,CAShH;AAED,wBAAgB,gBAAgB,CAC/B,OAAO,EAAE,YAAY,EAAE,EACvB,UAAU,EAAE,WAAW,CAAC,MAAM,EAAE,MAAM,CAAC,EACvC,mBAAmB,EAAE,WAAW,CAAC,MAAM,EAAE,MAAM,CAAC,GAC9C,eAAe,EAAE,CAqCnB"}
|
|
@@ -182,10 +182,12 @@ export function buildSessionProjection(entries, leafId, byId) {
|
|
|
182
182
|
const contextEntries = buildContextEntries(entries, leaf.id, byId);
|
|
183
183
|
const edits = collectContextEdits(contextEntries);
|
|
184
184
|
const boundary = getLatestCompactionBoundaryEntry(path);
|
|
185
|
-
if (!boundary) {
|
|
185
|
+
if (!boundary || boundary.details?.backend === "summary") {
|
|
186
186
|
const projected = contextEntries.map((sourceEntry) => ({
|
|
187
187
|
sourceEntry,
|
|
188
|
-
messages:
|
|
188
|
+
messages: boundary && sourceEntry.type === "compaction" && sourceEntry.id !== boundary.id
|
|
189
|
+
? []
|
|
190
|
+
: projectContextEntry(sourceEntry, edits.get(sourceEntry.id)),
|
|
189
191
|
}));
|
|
190
192
|
return { entries: projected, messages: projected.flatMap((entry) => entry.messages), thinkingLevel, model };
|
|
191
193
|
}
|