@osolmaz/pi-workflows 0.14.0 → 0.15.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +78 -110
- package/dist/builtins/autoimplement.workflow.js +3 -1
- package/dist/builtins/autoimplement.workflow.js.map +1 -1
- package/dist/builtins/change-verification.workflow.js +7 -2
- package/dist/builtins/change-verification.workflow.js.map +1 -1
- package/dist/builtins/metadata.d.ts +22 -0
- package/dist/builtins/metadata.js +10 -0
- package/dist/builtins/metadata.js.map +1 -0
- package/dist/builtins/monitor.workflow.js +4 -1
- package/dist/builtins/monitor.workflow.js.map +1 -1
- package/dist/builtins/sanity-check.workflow.js +4 -1
- package/dist/builtins/sanity-check.workflow.js.map +1 -1
- package/dist/builtins/workspace-preparation.workflow.js +3 -1
- package/dist/builtins/workspace-preparation.workflow.js.map +1 -1
- package/dist/controllers/index.d.ts +0 -1
- package/dist/controllers/index.js +0 -1
- package/dist/controllers/index.js.map +1 -1
- package/dist/controllers/sqlite.d.ts +51 -0
- package/dist/controllers/sqlite.js +433 -57
- package/dist/controllers/sqlite.js.map +1 -1
- package/dist/controllers/store.d.ts +1 -0
- package/dist/extension/controller-command.d.ts +22 -0
- package/dist/extension/controller-command.js +32 -0
- package/dist/extension/controller-command.js.map +1 -0
- package/dist/extension/index.d.ts +2 -9
- package/dist/extension/index.js +876 -3447
- package/dist/extension/index.js.map +1 -1
- package/dist/extension/message-card.d.ts +13 -0
- package/dist/extension/message-card.js +46 -0
- package/dist/extension/message-card.js.map +1 -0
- package/dist/extension/step-message.d.ts +5 -6
- package/dist/extension/step-message.js +41 -52
- package/dist/extension/step-message.js.map +1 -1
- package/dist/host/child-worker-supervisor.d.ts +50 -0
- package/dist/host/child-worker-supervisor.js +159 -0
- package/dist/host/child-worker-supervisor.js.map +1 -0
- package/dist/host/client.d.ts +48 -0
- package/dist/host/client.js +216 -0
- package/dist/host/client.js.map +1 -0
- package/dist/host/controller-worker-entry.d.ts +2 -0
- package/dist/host/controller-worker-entry.js +244 -0
- package/dist/host/controller-worker-entry.js.map +1 -0
- package/dist/host/controller-worker-protocol.d.ts +36 -0
- package/dist/host/controller-worker-protocol.js +49 -0
- package/dist/host/controller-worker-protocol.js.map +1 -0
- package/dist/host/controller-worker-supervisor.d.ts +21 -0
- package/dist/host/controller-worker-supervisor.js +54 -0
- package/dist/host/controller-worker-supervisor.js.map +1 -0
- package/dist/host/host-entry.d.ts +2 -0
- package/dist/host/host-entry.js +23 -0
- package/dist/host/host-entry.js.map +1 -0
- package/dist/host/processes.d.ts +17 -12
- package/dist/host/processes.js +154 -50
- package/dist/host/processes.js.map +1 -1
- package/dist/host/protocol.d.ts +38 -0
- package/dist/host/protocol.js +156 -0
- package/dist/host/protocol.js.map +1 -0
- package/dist/host/resolver-entry.d.ts +49 -0
- package/dist/host/resolver-entry.js +149 -0
- package/dist/host/resolver-entry.js.map +1 -0
- package/dist/host/rpc-executor.d.ts +14 -3
- package/dist/host/rpc-executor.js +63 -30
- package/dist/host/rpc-executor.js.map +1 -1
- package/dist/host/runner.d.ts +95 -29
- package/dist/host/runner.js +2311 -348
- package/dist/host/runner.js.map +1 -1
- package/dist/host/state.d.ts +174 -0
- package/dist/host/state.js +689 -0
- package/dist/host/state.js.map +1 -0
- package/dist/host/worker-entry.d.ts +10 -0
- package/dist/host/worker-entry.js +446 -0
- package/dist/host/worker-entry.js.map +1 -0
- package/dist/host/worker-protocol.d.ts +31 -0
- package/dist/host/worker-protocol.js +122 -0
- package/dist/host/worker-protocol.js.map +1 -0
- package/dist/host/worker-store.d.ts +80 -0
- package/dist/host/worker-store.js +91 -0
- package/dist/host/worker-store.js.map +1 -0
- package/dist/host/worker-supervisor.d.ts +22 -0
- package/dist/host/worker-supervisor.js +54 -0
- package/dist/host/worker-supervisor.js.map +1 -0
- package/dist/render/canvas.d.ts +2 -1
- package/dist/render/canvas.js +40 -15
- package/dist/render/canvas.js.map +1 -1
- package/dist/render/graph-render.d.ts +7 -3
- package/dist/render/graph-render.js +125 -74
- package/dist/render/graph-render.js.map +1 -1
- package/dist/state/database.js +3 -1
- package/dist/state/database.js.map +1 -1
- package/dist/state/index.d.ts +1 -0
- package/dist/state/index.js +1 -0
- package/dist/state/index.js.map +1 -1
- package/dist/state/schema.d.ts +1 -1
- package/dist/state/schema.js +171 -3
- package/dist/state/schema.js.map +1 -1
- package/dist/state/viewer.d.ts +46 -0
- package/dist/state/viewer.js +249 -0
- package/dist/state/viewer.js.map +1 -0
- package/dist/viewer/cli.d.ts +1 -1
- package/dist/viewer/cli.js +47 -18
- package/dist/viewer/cli.js.map +1 -1
- package/dist/workflows/composition.js +25 -2
- package/dist/workflows/composition.js.map +1 -1
- package/dist/workflows/definition.d.ts +3 -1
- package/dist/workflows/definition.js +25 -0
- package/dist/workflows/definition.js.map +1 -1
- package/dist/workflows/engine.d.ts +1 -0
- package/dist/workflows/engine.js +157 -42
- package/dist/workflows/engine.js.map +1 -1
- package/dist/workflows/errors.d.ts +3 -1
- package/dist/workflows/errors.js +4 -7
- package/dist/workflows/errors.js.map +1 -1
- package/dist/workflows/human-decision.d.ts +3 -0
- package/dist/workflows/human-decision.js +31 -0
- package/dist/workflows/human-decision.js.map +1 -1
- package/dist/workflows/index.d.ts +1 -1
- package/dist/workflows/index.js +1 -1
- package/dist/workflows/index.js.map +1 -1
- package/dist/workflows/schema.js +17 -6
- package/dist/workflows/schema.js.map +1 -1
- package/dist/{viewer → workflows}/session-reducer.d.ts +3 -1
- package/dist/{viewer → workflows}/session-reducer.js +4 -0
- package/dist/workflows/session-reducer.js.map +1 -0
- package/dist/workflows/store.d.ts +87 -1
- package/dist/workflows/store.js +892 -93
- package/dist/workflows/store.js.map +1 -1
- package/dist/workflows/tool-input.d.ts +0 -26
- package/dist/workflows/tool-input.js +2 -50
- package/dist/workflows/tool-input.js.map +1 -1
- package/dist/workflows/types.d.ts +36 -4
- package/docs/2026-08-30-out-of-process-workflow-host-plan.md +353 -0
- package/docs/CONTROLLERS.md +11 -11
- package/docs/DEFERRED_TURNS.md +23 -2
- package/docs/SQLITE_STATE.md +41 -31
- package/docs/WORKFLOW_HOST.md +452 -0
- package/docs/development.md +46 -30
- package/docs/live-replay-protocol.md +129 -100
- package/docs/plans/2026-08-27-workflow-terminal-restart-plan.md +42 -0
- package/docs/plans/2026-08-28-piw-incremental-viewer-plan.md +293 -0
- package/docs/plans/piw-viewer-experience-implementation-plan.md +11 -1
- package/docs/plans/tui-viewer-implementation-plan.md +5 -0
- package/docs/tui-viewer.md +18 -3
- package/docs/workflows.md +162 -210
- package/examples/workflows/command-batch.workflow.ts +2 -0
- package/examples/workflows/shell.workflow.ts +2 -1
- package/herdr-plugin.toml +1 -1
- package/package.json +1 -1
- package/src/builtins/autoimplement.workflow.ts +3 -0
- package/src/builtins/change-verification.workflow.ts +7 -2
- package/src/builtins/metadata.ts +9 -0
- package/src/builtins/monitor.workflow.ts +4 -0
- package/src/builtins/sanity-check.workflow.ts +4 -0
- package/src/builtins/workspace-preparation.workflow.ts +3 -1
- package/src/controllers/index.ts +0 -5
- package/src/controllers/sqlite.ts +709 -76
- package/src/controllers/store.ts +1 -0
- package/src/extension/controller-command.ts +45 -0
- package/src/extension/index.ts +944 -4163
- package/src/extension/message-card.ts +61 -0
- package/src/extension/step-message.ts +58 -63
- package/src/host/child-worker-supervisor.ts +183 -0
- package/src/host/client.ts +293 -0
- package/src/host/controller-worker-entry.ts +311 -0
- package/src/host/controller-worker-protocol.ts +104 -0
- package/src/host/controller-worker-supervisor.ts +79 -0
- package/src/host/host-entry.ts +23 -0
- package/src/host/processes.ts +171 -54
- package/src/host/protocol.ts +196 -0
- package/src/host/resolver-entry.ts +241 -0
- package/src/host/rpc-executor.ts +76 -34
- package/src/host/runner.ts +2813 -422
- package/src/host/state.ts +1160 -0
- package/src/host/worker-entry.ts +533 -0
- package/src/host/worker-protocol.ts +165 -0
- package/src/host/worker-store.ts +229 -0
- package/src/host/worker-supervisor.ts +74 -0
- package/src/render/canvas.ts +44 -10
- package/src/render/graph-render.ts +145 -90
- package/src/state/database.ts +2 -1
- package/src/state/index.ts +14 -0
- package/src/state/schema.ts +171 -3
- package/src/state/viewer.ts +356 -0
- package/src/viewer/cli.ts +49 -17
- package/src/workflows/composition.ts +36 -2
- package/src/workflows/definition.ts +32 -0
- package/src/workflows/engine.ts +157 -54
- package/src/workflows/errors.ts +11 -2
- package/src/workflows/human-decision.ts +49 -0
- package/src/workflows/index.ts +2 -0
- package/src/workflows/schema.ts +19 -6
- package/src/{viewer → workflows}/session-reducer.ts +11 -1
- package/src/workflows/store.ts +1316 -108
- package/src/workflows/tool-input.ts +3 -69
- package/src/workflows/types.ts +32 -4
- package/dist/controllers/workflow-engine-scheduler.d.ts +0 -29
- package/dist/controllers/workflow-engine-scheduler.js +0 -175
- package/dist/controllers/workflow-engine-scheduler.js.map +0 -1
- package/dist/extension/controller-host.d.ts +0 -48
- package/dist/extension/controller-host.js +0 -110
- package/dist/extension/controller-host.js.map +0 -1
- package/dist/extension/deferred-turn-coordinator.d.ts +0 -32
- package/dist/extension/deferred-turn-coordinator.js +0 -143
- package/dist/extension/deferred-turn-coordinator.js.map +0 -1
- package/dist/extension/deferred-turn.d.ts +0 -44
- package/dist/extension/deferred-turn.js +0 -110
- package/dist/extension/deferred-turn.js.map +0 -1
- package/dist/extension/executor.d.ts +0 -86
- package/dist/extension/executor.js +0 -311
- package/dist/extension/executor.js.map +0 -1
- package/dist/extension/follow-up-coordinator.d.ts +0 -27
- package/dist/extension/follow-up-coordinator.js +0 -131
- package/dist/extension/follow-up-coordinator.js.map +0 -1
- package/dist/extension/recorder.d.ts +0 -84
- package/dist/extension/recorder.js +0 -528
- package/dist/extension/recorder.js.map +0 -1
- package/dist/extension/restart-policy.d.ts +0 -38
- package/dist/extension/restart-policy.js +0 -116
- package/dist/extension/restart-policy.js.map +0 -1
- package/dist/extension/session-events.d.ts +0 -133
- package/dist/extension/session-events.js +0 -61
- package/dist/extension/session-events.js.map +0 -1
- package/dist/extension/terminal-decision.d.ts +0 -51
- package/dist/extension/terminal-decision.js +0 -110
- package/dist/extension/terminal-decision.js.map +0 -1
- package/dist/viewer/session-reducer.js.map +0 -1
- package/src/controllers/workflow-engine-scheduler.ts +0 -246
- package/src/extension/controller-host.ts +0 -167
- package/src/extension/deferred-turn-coordinator.ts +0 -171
- package/src/extension/deferred-turn.ts +0 -166
- package/src/extension/executor.ts +0 -411
- package/src/extension/follow-up-coordinator.ts +0 -151
- package/src/extension/recorder.ts +0 -655
- package/src/extension/restart-policy.ts +0 -163
- package/src/extension/session-events.ts +0 -121
- package/src/extension/terminal-decision.ts +0 -172
|
@@ -1,143 +0,0 @@
|
|
|
1
|
-
import { randomUUID } from "node:crypto";
|
|
2
|
-
import { deferredTurnMessageId } from "./deferred-turn.js";
|
|
3
|
-
export class DeferredTurnCoordinator {
|
|
4
|
-
store;
|
|
5
|
-
branchResolution;
|
|
6
|
-
leaseMs;
|
|
7
|
-
deferredNatural = new Map();
|
|
8
|
-
constructor(options) {
|
|
9
|
-
this.store = options.store;
|
|
10
|
-
this.branchResolution = options.branchResolution;
|
|
11
|
-
this.leaseMs = options.leaseMs;
|
|
12
|
-
}
|
|
13
|
-
sendNatural(delivery, idle) {
|
|
14
|
-
const store = this.store();
|
|
15
|
-
const intent = store?.findPendingWorkflowTurnIntent({
|
|
16
|
-
runId: delivery.runId,
|
|
17
|
-
targetSessionId: delivery.targetSessionId,
|
|
18
|
-
});
|
|
19
|
-
if (store === null || store === undefined || intent === undefined) {
|
|
20
|
-
delivery.send();
|
|
21
|
-
return "sent";
|
|
22
|
-
}
|
|
23
|
-
if (!idle) {
|
|
24
|
-
this.deferredNatural.set(intent.intentId, delivery);
|
|
25
|
-
return "deferred";
|
|
26
|
-
}
|
|
27
|
-
const result = this.deliverNatural(intent.intentId, delivery);
|
|
28
|
-
if (result === "deferred")
|
|
29
|
-
this.deferredNatural.set(intent.intentId, delivery);
|
|
30
|
-
return result;
|
|
31
|
-
}
|
|
32
|
-
flushNatural(idle) {
|
|
33
|
-
if (!idle)
|
|
34
|
-
return 0;
|
|
35
|
-
let sent = 0;
|
|
36
|
-
for (const [intentId, delivery] of this.deferredNatural) {
|
|
37
|
-
const result = this.deliverNatural(intentId, delivery);
|
|
38
|
-
if (result !== "deferred") {
|
|
39
|
-
this.deferredNatural.delete(intentId);
|
|
40
|
-
}
|
|
41
|
-
if (result === "sent")
|
|
42
|
-
sent += 1;
|
|
43
|
-
}
|
|
44
|
-
return sent;
|
|
45
|
-
}
|
|
46
|
-
deliverFallbacks(delivery, idle) {
|
|
47
|
-
const store = this.store();
|
|
48
|
-
if (!idle || store === null)
|
|
49
|
-
return 0;
|
|
50
|
-
const claimToken = randomUUID();
|
|
51
|
-
const intents = store.claimEligibleWorkflowTurnIntents({
|
|
52
|
-
targetSessionId: delivery.targetSessionId,
|
|
53
|
-
claimToken,
|
|
54
|
-
leaseMs: this.leaseMs,
|
|
55
|
-
});
|
|
56
|
-
let sent = 0;
|
|
57
|
-
for (const [index, intent] of intents.entries()) {
|
|
58
|
-
const branch = this.branchResolution(intent.intentId);
|
|
59
|
-
if (branch !== null) {
|
|
60
|
-
store.resolveWorkflowTurnIntent({
|
|
61
|
-
intentId: intent.intentId,
|
|
62
|
-
targetSessionId: delivery.targetSessionId,
|
|
63
|
-
claimToken,
|
|
64
|
-
resolution: branch.resolution,
|
|
65
|
-
messageId: branch.messageId,
|
|
66
|
-
});
|
|
67
|
-
continue;
|
|
68
|
-
}
|
|
69
|
-
try {
|
|
70
|
-
delivery.send(intent);
|
|
71
|
-
store.resolveWorkflowTurnIntent({
|
|
72
|
-
intentId: intent.intentId,
|
|
73
|
-
targetSessionId: delivery.targetSessionId,
|
|
74
|
-
claimToken,
|
|
75
|
-
resolution: "fallback",
|
|
76
|
-
messageId: deferredTurnMessageId(intent.intentId, "fallback"),
|
|
77
|
-
});
|
|
78
|
-
sent += 1;
|
|
79
|
-
}
|
|
80
|
-
catch (error) {
|
|
81
|
-
for (const pending of intents.slice(index)) {
|
|
82
|
-
store.releaseWorkflowTurnIntentClaim({
|
|
83
|
-
intentId: pending.intentId,
|
|
84
|
-
targetSessionId: delivery.targetSessionId,
|
|
85
|
-
claimToken,
|
|
86
|
-
});
|
|
87
|
-
}
|
|
88
|
-
throw error;
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
return sent;
|
|
92
|
-
}
|
|
93
|
-
clearDeferred() {
|
|
94
|
-
this.deferredNatural.clear();
|
|
95
|
-
}
|
|
96
|
-
deliverNatural(intentId, delivery) {
|
|
97
|
-
const store = this.store();
|
|
98
|
-
if (store === null)
|
|
99
|
-
return "deferred";
|
|
100
|
-
const claimToken = randomUUID();
|
|
101
|
-
const intent = store.claimWorkflowTurnIntent({
|
|
102
|
-
intentId,
|
|
103
|
-
targetSessionId: delivery.targetSessionId,
|
|
104
|
-
claimToken,
|
|
105
|
-
leaseMs: this.leaseMs,
|
|
106
|
-
});
|
|
107
|
-
if (intent === undefined) {
|
|
108
|
-
const current = store.getWorkflowTurnIntent(intentId);
|
|
109
|
-
return current?.resolvedAt === null ? "deferred" : "suppressed";
|
|
110
|
-
}
|
|
111
|
-
const branch = this.branchResolution(intent.intentId);
|
|
112
|
-
if (branch !== null) {
|
|
113
|
-
store.resolveWorkflowTurnIntent({
|
|
114
|
-
intentId: intent.intentId,
|
|
115
|
-
targetSessionId: delivery.targetSessionId,
|
|
116
|
-
claimToken,
|
|
117
|
-
resolution: branch.resolution,
|
|
118
|
-
messageId: branch.messageId,
|
|
119
|
-
});
|
|
120
|
-
return "suppressed";
|
|
121
|
-
}
|
|
122
|
-
try {
|
|
123
|
-
delivery.send(intent.intentId);
|
|
124
|
-
store.resolveWorkflowTurnIntent({
|
|
125
|
-
intentId: intent.intentId,
|
|
126
|
-
targetSessionId: delivery.targetSessionId,
|
|
127
|
-
claimToken,
|
|
128
|
-
resolution: delivery.resolution,
|
|
129
|
-
messageId: deferredTurnMessageId(intent.intentId, delivery.resolution),
|
|
130
|
-
});
|
|
131
|
-
return "sent";
|
|
132
|
-
}
|
|
133
|
-
catch (error) {
|
|
134
|
-
store.releaseWorkflowTurnIntentClaim({
|
|
135
|
-
intentId: intent.intentId,
|
|
136
|
-
targetSessionId: delivery.targetSessionId,
|
|
137
|
-
claimToken,
|
|
138
|
-
});
|
|
139
|
-
throw error;
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
//# sourceMappingURL=deferred-turn-coordinator.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"deferred-turn-coordinator.js","sourceRoot":"","sources":["../../src/extension/deferred-turn-coordinator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAMzC,OAAO,EAAE,qBAAqB,EAAE,MAAM,oBAAoB,CAAC;AAmB3D,MAAM,OAAO,uBAAuB;IACjB,KAAK,CAAqC;IAC1C,gBAAgB,CAAsD;IACtE,OAAO,CAAS;IAChB,eAAe,GAAG,IAAI,GAAG,EAA2B,CAAC;IAEtE,YAAY,OAIX;QACC,IAAI,CAAC,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC;QAC3B,IAAI,CAAC,gBAAgB,GAAG,OAAO,CAAC,gBAAgB,CAAC;QACjD,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC;IACjC,CAAC;IAED,WAAW,CAAC,QAAyB,EAAE,IAAa;QAClD,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,EAAE,CAAC;QAC3B,MAAM,MAAM,GAAG,KAAK,EAAE,6BAA6B,CAAC;YAClD,KAAK,EAAE,QAAQ,CAAC,KAAK;YACrB,eAAe,EAAE,QAAQ,CAAC,eAAe;SAC1C,CAAC,CAAC;QACH,IAAI,KAAK,KAAK,IAAI,IAAI,KAAK,KAAK,SAAS,IAAI,MAAM,KAAK,SAAS,EAAE,CAAC;YAClE,QAAQ,CAAC,IAAI,EAAE,CAAC;YAChB,OAAO,MAAM,CAAC;QAChB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EAAE,QAAQ,CAAC,UAAU;gBAC/B,SAAS,EAAE,qBAAqB,CAAC,MAAM,CAAC,QAAQ,EAAE,QAAQ,CAAC,UAAU,CAAC;aACvE,CAAC,CAAC;YACH,OAAO,MAAM,CAAC;QAChB,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,KAAK,CAAC,8BAA8B,CAAC;gBACnC,QAAQ,EAAE,MAAM,CAAC,QAAQ;gBACzB,eAAe,EAAE,QAAQ,CAAC,eAAe;gBACzC,UAAU;aACX,CAAC,CAAC;YACH,MAAM,KAAK,CAAC;QACd,CAAC;IACH,CAAC;CACF"}
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import type { WorkflowTurnIntentCause, WorkflowTurnIntentFacts, WorkflowTurnIntentRecord, WorkflowTurnIntentResolution } from "../controllers/sqlite.js";
|
|
2
|
-
export declare const DEFERRED_TURN_MESSAGE_TYPE = "pi-workflows-deferred-turn";
|
|
3
|
-
export declare const DEFERRED_TURN_MESSAGE_SCHEMA = "pi-workflows.deferred-turn-message.v1";
|
|
4
|
-
export type DeferredTurnSource = {
|
|
5
|
-
runId: string;
|
|
6
|
-
workflowName: string;
|
|
7
|
-
targetSessionId: string;
|
|
8
|
-
cause: WorkflowTurnIntentCause;
|
|
9
|
-
sourceEventId: string;
|
|
10
|
-
observedState: string;
|
|
11
|
-
nodeId?: string | null;
|
|
12
|
-
attemptId?: string | null;
|
|
13
|
-
reason?: string | null;
|
|
14
|
-
handoff?: boolean;
|
|
15
|
-
};
|
|
16
|
-
export type DeferredTurnDescriptor = {
|
|
17
|
-
intentId: string;
|
|
18
|
-
sourceEventId: string;
|
|
19
|
-
runId: string;
|
|
20
|
-
workflowRef: string;
|
|
21
|
-
targetSessionId: string;
|
|
22
|
-
cause: WorkflowTurnIntentCause;
|
|
23
|
-
nodeId: string | null;
|
|
24
|
-
attemptId: string | null;
|
|
25
|
-
fallbackFacts: WorkflowTurnIntentFacts;
|
|
26
|
-
};
|
|
27
|
-
export type DeferredTurnMessageDetails = {
|
|
28
|
-
schema: typeof DEFERRED_TURN_MESSAGE_SCHEMA;
|
|
29
|
-
turnIntentId: string;
|
|
30
|
-
runId: string;
|
|
31
|
-
cause: WorkflowTurnIntentCause;
|
|
32
|
-
};
|
|
33
|
-
export declare function deferredTurnSourceEventId(options: {
|
|
34
|
-
runId: string;
|
|
35
|
-
cause: WorkflowTurnIntentCause;
|
|
36
|
-
nodeId?: string | null;
|
|
37
|
-
attemptId?: string | null;
|
|
38
|
-
source?: string;
|
|
39
|
-
}): string;
|
|
40
|
-
export declare function createDeferredTurnDescriptor(source: DeferredTurnSource): DeferredTurnDescriptor;
|
|
41
|
-
export declare function createDeferredTurnFacts(source: DeferredTurnSource): WorkflowTurnIntentFacts;
|
|
42
|
-
export declare function deferredTurnMessageId(intentId: string, resolution: WorkflowTurnIntentResolution): string;
|
|
43
|
-
export declare function deferredTurnMessageDetails(intent: WorkflowTurnIntentRecord): DeferredTurnMessageDetails;
|
|
44
|
-
export declare function buildDeferredTurnContent(intent: WorkflowTurnIntentRecord): string;
|
|
@@ -1,110 +0,0 @@
|
|
|
1
|
-
import { createHash } from "node:crypto";
|
|
2
|
-
export const DEFERRED_TURN_MESSAGE_TYPE = "pi-workflows-deferred-turn";
|
|
3
|
-
export const DEFERRED_TURN_MESSAGE_SCHEMA = "pi-workflows.deferred-turn-message.v1";
|
|
4
|
-
const FACTS_SCHEMA = "pi-workflows.deferred-turn-facts.v1";
|
|
5
|
-
const MAX_REASON_CHARS = 8_192;
|
|
6
|
-
export function deferredTurnSourceEventId(options) {
|
|
7
|
-
const parts = [
|
|
8
|
-
options.runId,
|
|
9
|
-
options.source ?? "run",
|
|
10
|
-
options.nodeId ?? "$run",
|
|
11
|
-
options.attemptId ?? "$none",
|
|
12
|
-
options.cause,
|
|
13
|
-
];
|
|
14
|
-
return `turn-source:${digest(parts)}`;
|
|
15
|
-
}
|
|
16
|
-
export function createDeferredTurnDescriptor(source) {
|
|
17
|
-
const nodeId = source.nodeId ?? null;
|
|
18
|
-
const attemptId = source.attemptId ?? null;
|
|
19
|
-
const fallbackFacts = createDeferredTurnFacts(source);
|
|
20
|
-
return {
|
|
21
|
-
intentId: `deferred-turn:${digest([
|
|
22
|
-
source.targetSessionId,
|
|
23
|
-
source.runId,
|
|
24
|
-
source.sourceEventId,
|
|
25
|
-
nodeId ?? "$run",
|
|
26
|
-
attemptId ?? "$none",
|
|
27
|
-
source.cause,
|
|
28
|
-
])}`,
|
|
29
|
-
sourceEventId: source.sourceEventId,
|
|
30
|
-
runId: source.runId,
|
|
31
|
-
workflowRef: source.workflowName,
|
|
32
|
-
targetSessionId: source.targetSessionId,
|
|
33
|
-
cause: source.cause,
|
|
34
|
-
nodeId,
|
|
35
|
-
attemptId,
|
|
36
|
-
fallbackFacts,
|
|
37
|
-
};
|
|
38
|
-
}
|
|
39
|
-
export function createDeferredTurnFacts(source) {
|
|
40
|
-
return {
|
|
41
|
-
schema: FACTS_SCHEMA,
|
|
42
|
-
workflowName: source.workflowName,
|
|
43
|
-
runId: source.runId,
|
|
44
|
-
observedState: source.observedState,
|
|
45
|
-
cause: source.cause,
|
|
46
|
-
nodeId: source.nodeId ?? null,
|
|
47
|
-
attemptId: source.attemptId ?? null,
|
|
48
|
-
reason: boundedReason(source.reason),
|
|
49
|
-
handoff: source.handoff ?? false,
|
|
50
|
-
};
|
|
51
|
-
}
|
|
52
|
-
export function deferredTurnMessageId(intentId, resolution) {
|
|
53
|
-
return `turn-message:${digest([intentId, resolution])}`;
|
|
54
|
-
}
|
|
55
|
-
export function deferredTurnMessageDetails(intent) {
|
|
56
|
-
return {
|
|
57
|
-
schema: DEFERRED_TURN_MESSAGE_SCHEMA,
|
|
58
|
-
turnIntentId: intent.intentId,
|
|
59
|
-
runId: intent.runId,
|
|
60
|
-
cause: intent.cause,
|
|
61
|
-
};
|
|
62
|
-
}
|
|
63
|
-
export function buildDeferredTurnContent(intent) {
|
|
64
|
-
const facts = intent.fallbackFacts;
|
|
65
|
-
const source = [
|
|
66
|
-
facts.nodeId === null ? null : `node ${facts.nodeId}`,
|
|
67
|
-
facts.attemptId === null ? null : `attempt ${facts.attemptId}`,
|
|
68
|
-
]
|
|
69
|
-
.filter((part) => part !== null)
|
|
70
|
-
.join(", ");
|
|
71
|
-
const reason = facts.reason === null
|
|
72
|
-
? ""
|
|
73
|
-
: ` Reason: ${facts.reason}${/[.!?]$/.test(facts.reason) ? "" : "."}`;
|
|
74
|
-
const sourceText = source.length === 0 ? "" : ` Source: ${source}.`;
|
|
75
|
-
if (facts.cause === "launchFailed") {
|
|
76
|
-
return [
|
|
77
|
-
`Workflow ${facts.workflowName} failed to start (run ${facts.runId}).`,
|
|
78
|
-
`${sourceText}${reason}`.trim(),
|
|
79
|
-
"Inspect the durable workflow state before you explain the outcome or start a corrected workflow.",
|
|
80
|
-
]
|
|
81
|
-
.filter((part) => part.length > 0)
|
|
82
|
-
.join(" ");
|
|
83
|
-
}
|
|
84
|
-
if (facts.handoff) {
|
|
85
|
-
return [
|
|
86
|
-
`Workflow ${facts.workflowName} was handed to another runner (run ${facts.runId}).`,
|
|
87
|
-
`Observed state: ${facts.observedState}.${sourceText}${reason}`,
|
|
88
|
-
"Inspect the durable workflow state before you explain the outcome or take any authorized corrective action.",
|
|
89
|
-
].join(" ");
|
|
90
|
-
}
|
|
91
|
-
return [
|
|
92
|
-
`Workflow ${facts.workflowName} ended with state ${facts.observedState} (run ${facts.runId}).`,
|
|
93
|
-
`${sourceText}${reason}`.trim(),
|
|
94
|
-
"Inspect the durable workflow state before you explain the outcome or take any authorized corrective action.",
|
|
95
|
-
]
|
|
96
|
-
.filter((part) => part.length > 0)
|
|
97
|
-
.join(" ");
|
|
98
|
-
}
|
|
99
|
-
function boundedReason(value) {
|
|
100
|
-
if (value === null || value === undefined)
|
|
101
|
-
return null;
|
|
102
|
-
const trimmed = value.trim();
|
|
103
|
-
if (trimmed.length === 0)
|
|
104
|
-
return null;
|
|
105
|
-
return trimmed.length <= MAX_REASON_CHARS ? trimmed : trimmed.slice(0, MAX_REASON_CHARS);
|
|
106
|
-
}
|
|
107
|
-
function digest(parts) {
|
|
108
|
-
return createHash("sha256").update(JSON.stringify(parts)).digest("hex");
|
|
109
|
-
}
|
|
110
|
-
//# sourceMappingURL=deferred-turn.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"deferred-turn.js","sourceRoot":"","sources":["../../src/extension/deferred-turn.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAQzC,MAAM,CAAC,MAAM,0BAA0B,GAAG,4BAA4B,CAAC;AACvE,MAAM,CAAC,MAAM,4BAA4B,GAAG,uCAAuC,CAAC;AACpF,MAAM,YAAY,GAAG,qCAAqC,CAAC;AAC3D,MAAM,gBAAgB,GAAG,KAAK,CAAC;AAkC/B,MAAM,UAAU,yBAAyB,CAAC,OAMzC;IACC,MAAM,KAAK,GAAG;QACZ,OAAO,CAAC,KAAK;QACb,OAAO,CAAC,MAAM,IAAI,KAAK;QACvB,OAAO,CAAC,MAAM,IAAI,MAAM;QACxB,OAAO,CAAC,SAAS,IAAI,OAAO;QAC5B,OAAO,CAAC,KAAK;KACd,CAAC;IACF,OAAO,eAAe,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC;AACxC,CAAC;AAED,MAAM,UAAU,4BAA4B,CAAC,MAA0B;IACrE,MAAM,MAAM,GAAG,MAAM,CAAC,MAAM,IAAI,IAAI,CAAC;IACrC,MAAM,SAAS,GAAG,MAAM,CAAC,SAAS,IAAI,IAAI,CAAC;IAC3C,MAAM,aAAa,GAAG,uBAAuB,CAAC,MAAM,CAAC,CAAC;IACtD,OAAO;QACL,QAAQ,EAAE,iBAAiB,MAAM,CAAC;YAChC,MAAM,CAAC,eAAe;YACtB,MAAM,CAAC,KAAK;YACZ,MAAM,CAAC,aAAa;YACpB,MAAM,IAAI,MAAM;YAChB,SAAS,IAAI,OAAO;YACpB,MAAM,CAAC,KAAK;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C,YAAY,qBAAqB,KAAK,CAAC,aAAa,SAAS,KAAK,CAAC,KAAK,IAAI;QAC9F,GAAG,UAAU,GAAG,MAAM,EAAE,CAAC,IAAI,EAAE;QAC/B,6GAA6G;KAC9G;SACE,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC;SACjC,IAAI,CAAC,GAAG,CAAC,CAAC;AACf,CAAC;AAED,SAAS,aAAa,CAAC,KAAgC;IACrD,IAAI,KAAK,KAAK,IAAI,IAAI,KAAK,KAAK,SAAS;QAAE,OAAO,IAAI,CAAC;IACvD,MAAM,OAAO,GAAG,KAAK,CAAC,IAAI,EAAE,CAAC;IAC7B,IAAI,OAAO,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,IAAI,CAAC;IACtC,OAAO,OAAO,CAAC,MAAM,IAAI,gBAAgB,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,EAAE,gBAAgB,CAAC,CAAC;AAC3F,CAAC;AAED,SAAS,MAAM,CAAC,KAAwB;IACtC,OAAO,UAAU,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;AAC1E,CAAC"}
|
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
import type { AgentStepExecutor, AgentStepRequest, AgentStepSubmission, ConversationRange } from "../workflows/types.js";
|
|
2
|
-
export type SubmissionResult = {
|
|
3
|
-
accepted: true;
|
|
4
|
-
message: string;
|
|
5
|
-
} | {
|
|
6
|
-
accepted: false;
|
|
7
|
-
message: string;
|
|
8
|
-
};
|
|
9
|
-
export type PromptDeliveryKind = "step" | "reminder" | "resume";
|
|
10
|
-
export type PromptDelivery = {
|
|
11
|
-
prompt: string;
|
|
12
|
-
contract: AgentStepRequest["contract"];
|
|
13
|
-
presentation?: AgentStepRequest["presentation"];
|
|
14
|
-
kind: PromptDeliveryKind;
|
|
15
|
-
/** True when the agent is known to be mid-run, so delivery must be queued. */
|
|
16
|
-
streaming: boolean;
|
|
17
|
-
};
|
|
18
|
-
/**
|
|
19
|
-
* Bracketing hooks for conversation linkage: a mark is taken when the step
|
|
20
|
-
* prompt is first delivered, and the recorded entry range since that mark is
|
|
21
|
-
* attached to the accepted submission.
|
|
22
|
-
*/
|
|
23
|
-
export type ConversationHooks = {
|
|
24
|
-
beginAttempt?: (contract: AgentStepRequest["contract"]) => void;
|
|
25
|
-
recoverAssistant?: (contract: AgentStepRequest["contract"]) => AgentStepSubmission | undefined;
|
|
26
|
-
mark: () => number;
|
|
27
|
-
rangeSince: (mark: number) => ConversationRange | undefined;
|
|
28
|
-
};
|
|
29
|
-
export type ConversationStepExecutorOptions = {
|
|
30
|
-
/** Deliver a prompt into the pi conversation. */
|
|
31
|
-
sendPrompt: (delivery: PromptDelivery) => void;
|
|
32
|
-
/** Reminders sent when the agent settles without submitting. Default 2. */
|
|
33
|
-
maxNudges?: number;
|
|
34
|
-
/** Conversation linkage hooks, wired to the session recorder. */
|
|
35
|
-
conversation?: ConversationHooks;
|
|
36
|
-
/** Called when the engine aborts a pending agent step. */
|
|
37
|
-
onAbort?: (contract: AgentStepRequest["contract"], reason: unknown) => void;
|
|
38
|
-
};
|
|
39
|
-
/**
|
|
40
|
-
* AgentStepExecutor that runs steps inside the current pi conversation. The
|
|
41
|
-
* engine hands it a prompt; it delivers the prompt as a model-facing workflow
|
|
42
|
-
* message and resolves once the model submits an accepted output through the `workflow`
|
|
43
|
-
* tool. If the agent settles without submitting, it nudges the model a
|
|
44
|
-
* bounded number of times before failing the step.
|
|
45
|
-
*/
|
|
46
|
-
export declare class ConversationStepExecutor implements AgentStepExecutor {
|
|
47
|
-
readonly assistantMessageMode: "visible";
|
|
48
|
-
private readonly sendPrompt;
|
|
49
|
-
private readonly maxNudges;
|
|
50
|
-
private readonly conversation;
|
|
51
|
-
private readonly onAbort;
|
|
52
|
-
private pending;
|
|
53
|
-
private streaming;
|
|
54
|
-
private heldByUser;
|
|
55
|
-
constructor(options: ConversationStepExecutorOptions);
|
|
56
|
-
/** Track agent streaming state (wire to agent_start / agent_settled). */
|
|
57
|
-
setStreaming(streaming: boolean): void;
|
|
58
|
-
get pendingStepId(): string | null;
|
|
59
|
-
get pendingCompletion(): "submit" | "assistant" | null;
|
|
60
|
-
/**
|
|
61
|
-
* Hold the pending step for the user: no nudges are sent while held, so an
|
|
62
|
-
* escape-interrupted conversation stays quiet until the user resumes.
|
|
63
|
-
*/
|
|
64
|
-
hold(): void;
|
|
65
|
-
get held(): boolean;
|
|
66
|
-
/**
|
|
67
|
-
* Release a user hold. When a step is still pending, its prompt is
|
|
68
|
-
* re-delivered so the model picks the step back up.
|
|
69
|
-
*/
|
|
70
|
-
release(): void;
|
|
71
|
-
runAgentStep(request: AgentStepRequest, signal: AbortSignal): Promise<AgentStepSubmission>;
|
|
72
|
-
/** Called by the `workflow` tool when the model submits a step output. */
|
|
73
|
-
submit(stepId: string, attemptId: string, output: unknown): Promise<SubmissionResult>;
|
|
74
|
-
/** Keep the latest finalized assistant message for an assistant-output step. */
|
|
75
|
-
handleMessageEnd(message: unknown): void;
|
|
76
|
-
/**
|
|
77
|
-
* Called when the agent settles. Returns true when a nudge was sent, false
|
|
78
|
-
* when there was nothing to do. Submitted steps use bounded nudges;
|
|
79
|
-
* assistant-output steps accept or fail the one visible response.
|
|
80
|
-
*/
|
|
81
|
-
handleAgentSettled(): boolean;
|
|
82
|
-
private delivery;
|
|
83
|
-
private clearPending;
|
|
84
|
-
}
|
|
85
|
-
/** Extract the exact visible text blocks from one finalized assistant message. */
|
|
86
|
-
export declare function visibleAssistantText(message: unknown, maxChars?: number): string;
|