@osolmaz/pi-workflows 0.3.0 → 0.5.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 +11 -7
- package/dist/builtins/catalog.d.ts +2 -0
- package/dist/builtins/catalog.js +32 -0
- package/dist/builtins/catalog.js.map +1 -0
- package/dist/builtins/monitor.workflow.d.ts +2 -2
- package/dist/builtins/monitor.workflow.js +25 -25
- package/dist/builtins/monitor.workflow.js.map +1 -1
- package/dist/controllers/index.d.ts +1 -1
- package/dist/controllers/index.js.map +1 -1
- package/dist/controllers/sqlite.d.ts +70 -9
- package/dist/controllers/sqlite.js +209 -35
- package/dist/controllers/sqlite.js.map +1 -1
- package/dist/controllers/workflow-engine-scheduler.d.ts +2 -2
- package/dist/controllers/workflow-engine-scheduler.js +3 -1
- package/dist/controllers/workflow-engine-scheduler.js.map +1 -1
- package/dist/extension/executor.d.ts +3 -0
- package/dist/extension/executor.js +11 -1
- package/dist/extension/executor.js.map +1 -1
- package/dist/extension/index.js +157 -108
- package/dist/extension/index.js.map +1 -1
- package/dist/host/runner.d.ts +1 -0
- package/dist/host/runner.js +68 -20
- package/dist/host/runner.js.map +1 -1
- package/dist/render/graph-render.js +3 -0
- package/dist/render/graph-render.js.map +1 -1
- package/dist/workflows/catalog.d.ts +43 -0
- package/dist/workflows/catalog.js +79 -0
- package/dist/workflows/catalog.js.map +1 -0
- package/dist/workflows/definition.d.ts +2 -1
- package/dist/workflows/definition.js +9 -1
- package/dist/workflows/definition.js.map +1 -1
- package/dist/workflows/engine.d.ts +6 -6
- package/dist/workflows/engine.js +93 -33
- package/dist/workflows/engine.js.map +1 -1
- package/dist/workflows/index.d.ts +3 -3
- package/dist/workflows/index.js +2 -2
- package/dist/workflows/index.js.map +1 -1
- package/dist/workflows/loader.d.ts +18 -16
- package/dist/workflows/loader.js +58 -23
- package/dist/workflows/loader.js.map +1 -1
- package/dist/workflows/migrate-sources.d.ts +42 -0
- package/dist/workflows/migrate-sources.js +133 -0
- package/dist/workflows/migrate-sources.js.map +1 -0
- package/dist/workflows/schema.d.ts +2 -1
- package/dist/workflows/schema.js +14 -1
- package/dist/workflows/schema.js.map +1 -1
- package/dist/workflows/store.js +5 -2
- package/dist/workflows/store.js.map +1 -1
- package/dist/workflows/types.d.ts +44 -5
- package/docs/development.md +5 -3
- package/docs/plans/2026-08-12-coordinated-workflow-timeouts-plan.md +74 -0
- package/docs/plans/2026-08-13-built-in-workflow-catalog-plan.md +97 -0
- package/docs/plans/2026-08-13-session-addressed-workflow-notifications-plan.md +95 -0
- package/docs/run-bundles.md +22 -4
- package/docs/workflows.md +57 -14
- package/package.json +1 -1
- package/src/builtins/catalog.ts +32 -0
- package/src/builtins/monitor.workflow.ts +33 -26
- package/src/controllers/index.ts +1 -0
- package/src/controllers/sqlite.ts +353 -43
- package/src/controllers/workflow-engine-scheduler.ts +5 -2
- package/src/extension/executor.ts +12 -1
- package/src/extension/index.ts +181 -140
- package/src/host/runner.ts +78 -20
- package/src/render/graph-render.ts +3 -0
- package/src/workflows/catalog.ts +135 -0
- package/src/workflows/definition.ts +11 -0
- package/src/workflows/engine.ts +128 -53
- package/src/workflows/index.ts +7 -0
- package/src/workflows/loader.ts +70 -26
- package/src/workflows/migrate-sources.ts +174 -0
- package/src/workflows/schema.ts +16 -1
- package/src/workflows/store.ts +5 -2
- package/src/workflows/types.ts +43 -4
package/README.md
CHANGED
|
@@ -102,8 +102,9 @@ Pi Workflows includes a `monitor` workflow for plain-language requests such as:
|
|
|
102
102
|
|
|
103
103
|
The monitor checks immediately, reports only the states requested by the user,
|
|
104
104
|
waits with a normal shell action, and loops until its stop condition or check
|
|
105
|
-
limit. Its input supports `task`, `everyMinutes`, `reportWhen`, `stopWhen`,
|
|
106
|
-
`maxChecks
|
|
105
|
+
limit. Its input supports `task`, `everyMinutes`, `reportWhen`, `stopWhen`,
|
|
106
|
+
`maxChecks`, and an optional `checkTimeoutMinutes`. Project and global
|
|
107
|
+
workflows can replace the built-in `monitor`
|
|
107
108
|
by using the same file name.
|
|
108
109
|
|
|
109
110
|
A monitor occupies the session's one active workflow slot. If its Pi runner
|
|
@@ -178,10 +179,11 @@ finishes with a JSON output, and edges decide what runs next.
|
|
|
178
179
|
|
|
179
180
|
An `agent` node sends a prompt into the pi conversation and waits for the
|
|
180
181
|
model to submit its output through the `workflow` tool. A `compute` node runs
|
|
181
|
-
a pure TypeScript function.
|
|
182
|
-
|
|
183
|
-
(`
|
|
184
|
-
|
|
182
|
+
a pure TypeScript function. A `notify` node writes a durable message for the
|
|
183
|
+
Pi session that started the run. An `action` node performs a side effect,
|
|
184
|
+
either a TypeScript function (`action({ run })`) or a runtime-owned shell
|
|
185
|
+
command (`shell({ exec, parse })`). A `checkpoint` node ends the run in a
|
|
186
|
+
`waiting` state so a human can pick it up. On top of `agent`, the `decision` helper asks
|
|
185
187
|
the model to pick from a fixed set of choices and validates the answer, and
|
|
186
188
|
`decisionEdge` routes on the result with compile-time case checking.
|
|
187
189
|
|
|
@@ -220,7 +222,9 @@ The standalone CLI provides read-only views with `pi-workflows controllers` and
|
|
|
220
222
|
|
|
221
223
|
## Always-on workflows
|
|
222
224
|
|
|
223
|
-
Runs do not depend on the Pi window. Every `/workflow` run is claimed through a durable queue, so closing Pi mid-run **parks** the run instead of cancelling it
|
|
225
|
+
Runs do not depend on the Pi window. Every `/workflow` run is claimed through a durable queue, so closing Pi mid-run **parks** the run instead of cancelling it. Another interactive session cannot claim it. Reopening the exact session that started the run resumes it. A standalone host can also resume it without changing where reports go. A checkpointed run waits durably until you answer it with `/workflow answer <json>`, which continues the graph in a linked run.
|
|
226
|
+
|
|
227
|
+
Workflow reports use a durable session-addressed outbox. A report waits while its starting session is closed and is delivered only to that session when it opens again. Runs in the same directory do not broadcast messages to each other's conversations.
|
|
224
228
|
|
|
225
229
|
For runs that must continue while Pi is closed, keep the standalone host running:
|
|
226
230
|
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { BuiltinWorkflowCatalog } from "../workflows/catalog.js";
|
|
2
|
+
import monitorWorkflow from "./monitor.workflow.js";
|
|
3
|
+
export const builtinWorkflowCatalog = new BuiltinWorkflowCatalog([
|
|
4
|
+
{
|
|
5
|
+
id: "monitor",
|
|
6
|
+
revision: "2",
|
|
7
|
+
definition: monitorWorkflow,
|
|
8
|
+
legacySources: [
|
|
9
|
+
{
|
|
10
|
+
workflowHash: "7a22158da94d18ec1c9fe42e70d72017a4e0620d5e5142ae839d0cd6eea55c06",
|
|
11
|
+
revision: "2",
|
|
12
|
+
pathSuffixes: [
|
|
13
|
+
"/src/builtins/monitor.workflow.ts",
|
|
14
|
+
"/dist/builtins/monitor.workflow.js",
|
|
15
|
+
"/src/workflows/monitor.workflow.ts",
|
|
16
|
+
"/dist/workflows/monitor.workflow.js",
|
|
17
|
+
],
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
workflowHash: "352fc09c88922c7375281b52f049c1039d05441ce37f2082f5ff07fea66d5318",
|
|
21
|
+
revision: "2",
|
|
22
|
+
pathSuffixes: ["/dist/builtins/monitor.workflow.js"],
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
workflowHash: "dc601e2323a8213f5d52fa555e804ae8ed0846f809b3a1e9e5073a3c9c3a114e",
|
|
26
|
+
revision: "2",
|
|
27
|
+
pathSuffixes: ["/dist/builtins/monitor.workflow.js"],
|
|
28
|
+
},
|
|
29
|
+
],
|
|
30
|
+
},
|
|
31
|
+
]);
|
|
32
|
+
//# sourceMappingURL=catalog.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"catalog.js","sourceRoot":"","sources":["../../src/builtins/catalog.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,MAAM,yBAAyB,CAAC;AACjE,OAAO,eAAe,MAAM,uBAAuB,CAAC;AAEpD,MAAM,CAAC,MAAM,sBAAsB,GAAG,IAAI,sBAAsB,CAAC;IAC/D;QACE,EAAE,EAAE,SAAS;QACb,QAAQ,EAAE,GAAG;QACb,UAAU,EAAE,eAAe;QAC3B,aAAa,EAAE;YACb;gBACE,YAAY,EAAE,kEAAkE;gBAChF,QAAQ,EAAE,GAAG;gBACb,YAAY,EAAE;oBACZ,mCAAmC;oBACnC,oCAAoC;oBACpC,oCAAoC;oBACpC,qCAAqC;iBACtC;aACF;YACD;gBACE,YAAY,EAAE,kEAAkE;gBAChF,QAAQ,EAAE,GAAG;gBACb,YAAY,EAAE,CAAC,oCAAoC,CAAC;aACrD;YACD;gBACE,YAAY,EAAE,kEAAkE;gBAChF,QAAQ,EAAE,GAAG;gBACb,YAAY,EAAE,CAAC,oCAAoC,CAAC;aACrD;SACF;KACF;CACF,CAAC,CAAC"}
|
|
@@ -12,8 +12,8 @@ declare const _default: {
|
|
|
12
12
|
guard: import("../workflows/types.js").ComputeNodeDefinition;
|
|
13
13
|
continue_guard: import("../workflows/types.js").ComputeNodeDefinition;
|
|
14
14
|
check: import("../workflows/types.js").AgentNodeDefinition;
|
|
15
|
-
report_continue: import("../workflows/types.js").
|
|
16
|
-
report_stop: import("../workflows/types.js").
|
|
15
|
+
report_continue: import("../workflows/types.js").NotifyNodeDefinition;
|
|
16
|
+
report_stop: import("../workflows/types.js").NotifyNodeDefinition;
|
|
17
17
|
sleep: import("../workflows/types.js").ShellActionNodeDefinition;
|
|
18
18
|
finish: import("../workflows/types.js").ComputeNodeDefinition;
|
|
19
19
|
};
|
|
@@ -1,6 +1,9 @@
|
|
|
1
|
-
import { agent, compute, defineWorkflow, shell } from "../workflows/
|
|
1
|
+
import { agent, compute, defineWorkflow, notify, shell } from "../workflows/definition.js";
|
|
2
2
|
const MIN_INTERVAL_MINUTES = 1;
|
|
3
3
|
const MAX_INTERVAL_MINUTES = 24 * 60;
|
|
4
|
+
const MIN_CHECK_TIMEOUT_MINUTES = 5;
|
|
5
|
+
const MAX_CHECK_TIMEOUT_MINUTES = 24 * 60;
|
|
6
|
+
const DEFAULT_MIN_CHECK_TIMEOUT_MINUTES = 60;
|
|
4
7
|
const DEFAULT_MAX_CHECKS = 1_000;
|
|
5
8
|
const MAX_CHECKS = 1_000;
|
|
6
9
|
const MAX_OBSERVATION_CHARS = 8_000;
|
|
@@ -46,6 +49,12 @@ function prepareInput(input) {
|
|
|
46
49
|
if (!Number.isInteger(maxChecks) || maxChecks <= 0 || maxChecks > MAX_CHECKS) {
|
|
47
50
|
throw new Error(`maxChecks must be an integer from 1 through ${MAX_CHECKS}`);
|
|
48
51
|
}
|
|
52
|
+
const checkTimeoutMinutes = value.checkTimeoutMinutes ?? Math.max(DEFAULT_MIN_CHECK_TIMEOUT_MINUTES, value.everyMinutes);
|
|
53
|
+
if (!Number.isInteger(checkTimeoutMinutes) ||
|
|
54
|
+
checkTimeoutMinutes < MIN_CHECK_TIMEOUT_MINUTES ||
|
|
55
|
+
checkTimeoutMinutes > MAX_CHECK_TIMEOUT_MINUTES) {
|
|
56
|
+
throw new Error(`checkTimeoutMinutes must be an integer from ${MIN_CHECK_TIMEOUT_MINUTES} through ${MAX_CHECK_TIMEOUT_MINUTES}`);
|
|
57
|
+
}
|
|
49
58
|
return {
|
|
50
59
|
task,
|
|
51
60
|
everyMinutes: value.everyMinutes,
|
|
@@ -56,11 +65,15 @@ function prepareInput(input) {
|
|
|
56
65
|
? "The user cancels the monitor or it reaches its maximum check count."
|
|
57
66
|
: requireBoundedString(value.stopWhen, "stopWhen", 4_000),
|
|
58
67
|
maxChecks,
|
|
68
|
+
checkTimeoutMinutes,
|
|
59
69
|
};
|
|
60
70
|
}
|
|
61
71
|
function configFrom(outputs) {
|
|
62
72
|
return outputs.prepare;
|
|
63
73
|
}
|
|
74
|
+
function agentTimeoutMs({ outputs }) {
|
|
75
|
+
return configFrom(outputs).checkTimeoutMinutes * 60_000;
|
|
76
|
+
}
|
|
64
77
|
function completedChecks(context) {
|
|
65
78
|
return context.state.steps.filter((step) => step.nodeId === "check" && step.outcome === "ok")
|
|
66
79
|
.length;
|
|
@@ -87,21 +100,9 @@ function validateCheck(output) {
|
|
|
87
100
|
reason,
|
|
88
101
|
};
|
|
89
102
|
}
|
|
90
|
-
function
|
|
91
|
-
const value = requireRecord(output, "report acknowledgement");
|
|
92
|
-
if (value.reported !== true) {
|
|
93
|
-
throw new Error("report acknowledgement must set reported to true");
|
|
94
|
-
}
|
|
95
|
-
return { reported: true };
|
|
96
|
-
}
|
|
97
|
-
function reportPrompt(outputs) {
|
|
103
|
+
function reportMessage(outputs) {
|
|
98
104
|
const check = outputs.check;
|
|
99
|
-
return
|
|
100
|
-
"Write one concise normal assistant message to the user with this monitoring update:",
|
|
101
|
-
check.report ?? check.observation,
|
|
102
|
-
"Do not add unrelated detail.",
|
|
103
|
-
"After writing the update, submit the acknowledgement required by the workflow step contract.",
|
|
104
|
-
].join("\n\n");
|
|
105
|
+
return check.report ?? check.observation;
|
|
105
106
|
}
|
|
106
107
|
export default defineWorkflow({
|
|
107
108
|
name: "monitor",
|
|
@@ -147,6 +148,7 @@ export default defineWorkflow({
|
|
|
147
148
|
}),
|
|
148
149
|
check: agent({
|
|
149
150
|
statusDetail: "checking monitored target",
|
|
151
|
+
timeoutMs: agentTimeoutMs,
|
|
150
152
|
prompt: (context) => {
|
|
151
153
|
const config = configFrom(context.outputs);
|
|
152
154
|
const previous = context.outputs.check;
|
|
@@ -166,17 +168,15 @@ export default defineWorkflow({
|
|
|
166
168
|
expectedOutput: '{ "route": "continue_quiet" | "continue_report" | "stop_quiet" | "stop_report", "observation": "current factual state", "report": "required for report routes", "reason": "short reason" }',
|
|
167
169
|
validate: (output) => validateCheck(output),
|
|
168
170
|
}),
|
|
169
|
-
report_continue:
|
|
170
|
-
statusDetail: "
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
validate: (output) => validateReportAck(output),
|
|
171
|
+
report_continue: notify({
|
|
172
|
+
statusDetail: "queueing monitor update",
|
|
173
|
+
message: ({ outputs }) => reportMessage(outputs),
|
|
174
|
+
kind: "progress",
|
|
174
175
|
}),
|
|
175
|
-
report_stop:
|
|
176
|
-
statusDetail: "
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
validate: (output) => validateReportAck(output),
|
|
176
|
+
report_stop: notify({
|
|
177
|
+
statusDetail: "queueing final monitor update",
|
|
178
|
+
message: ({ outputs }) => reportMessage(outputs),
|
|
179
|
+
kind: "final",
|
|
180
180
|
}),
|
|
181
181
|
sleep: shell({
|
|
182
182
|
statusDetail: "waiting for next monitor check",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"monitor.workflow.js","sourceRoot":"","sources":["../../src/builtins/monitor.workflow.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,cAAc,EAAE,KAAK,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"monitor.workflow.js","sourceRoot":"","sources":["../../src/builtins/monitor.workflow.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,cAAc,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,4BAA4B,CAAC;AAG3F,MAAM,oBAAoB,GAAG,CAAC,CAAC;AAC/B,MAAM,oBAAoB,GAAG,EAAE,GAAG,EAAE,CAAC;AACrC,MAAM,yBAAyB,GAAG,CAAC,CAAC;AACpC,MAAM,yBAAyB,GAAG,EAAE,GAAG,EAAE,CAAC;AAC1C,MAAM,iCAAiC,GAAG,EAAE,CAAC;AAC7C,MAAM,kBAAkB,GAAG,KAAK,CAAC;AACjC,MAAM,UAAU,GAAG,KAAK,CAAC;AACzB,MAAM,qBAAqB,GAAG,KAAK,CAAC;AACpC,MAAM,gBAAgB,GAAG,KAAK,CAAC;AAC/B,MAAM,gBAAgB,GAAG,KAAK,CAAC;AAC/B,MAAM,uBAAuB,GAAG,MAAM,CAAC;AACvC,MAAM,sBAAsB,GAAG,CAAC,GAAG,MAAM,CAAC;AA6B1C,MAAM,cAAc,GAAG,IAAI,GAAG,CAAe;IAC3C,gBAAgB;IAChB,iBAAiB;IACjB,YAAY;IAC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AE,gBAAgB,EAAE;QACjD,EAAE,IAAI,EAAE,aAAa,EAAE,EAAE,EAAE,QAAQ,EAAE;QACrC;YACE,IAAI,EAAE,gBAAgB;YACtB,MAAM,EAAE,EAAE,EAAE,EAAE,SAAS,EAAE,KAAK,EAAE,EAAE,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,EAAE;SACrE;QACD,EAAE,IAAI,EAAE,OAAO,EAAE,EAAE,EAAE,OAAO,EAAE;KAC/B;CACF,CAAC,CAAC"}
|
|
@@ -5,7 +5,7 @@ export { ControllerEffectService } from "./effects.js";
|
|
|
5
5
|
export { canonicalJson, jsonFingerprint } from "./json.js";
|
|
6
6
|
export { ControllerManager, type ControllerManagerOptions } from "./manager.js";
|
|
7
7
|
export { createResultHelpers, requeue, requeueAfter, settled } from "./results.js";
|
|
8
|
-
export { SqliteControllerStore, type RunEventRecord, type WorkflowRunQueueRecord, } from "./sqlite.js";
|
|
8
|
+
export { SqliteControllerStore, type RunEventRecord, type WorkflowNotificationRecord, type WorkflowRunQueueRecord, } from "./sqlite.js";
|
|
9
9
|
export { CONTROLLER_STORE_SCHEMA, controllerProjectScope, controllerStoreBaseDir, controllerStorePath, projectControllerStoreBaseDir, projectControllerStorePath, type ControllerStore, type EffectReservation, type QueueItem, type QueueRequeueOptions, type WorkflowRecordUpdate, type WorkflowReservation, } from "./store.js";
|
|
10
10
|
export { controllerFileStem, controllerSearchDirs, discoverControllers, loadControllerFile, loadDiscoveredControllers, type DiscoveredController, } from "./loader.js";
|
|
11
11
|
export { WorkflowEngineScheduler, type ResolvedChildWorkflow, type WorkflowEngineSchedulerOptions, } from "./workflow-engine-scheduler.js";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/controllers/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,+BAA+B,EAC/B,gBAAgB,EAChB,sBAAsB,GACvB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EACL,gBAAgB,EAChB,cAAc,EACd,aAAa,EACb,gBAAgB,EAChB,eAAe,GAChB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EACL,0BAA0B,EAC1B,qBAAqB,EACrB,qBAAqB,EACrB,4BAA4B,GAC7B,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,uBAAuB,EAAE,MAAM,cAAc,CAAC;AACvD,OAAO,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,WAAW,CAAC;AAC3D,OAAO,EAAE,iBAAiB,EAAiC,MAAM,cAAc,CAAC;AAChF,OAAO,EAAE,mBAAmB,EAAE,OAAO,EAAE,YAAY,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACnF,OAAO,EACL,qBAAqB,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/controllers/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,+BAA+B,EAC/B,gBAAgB,EAChB,sBAAsB,GACvB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EACL,gBAAgB,EAChB,cAAc,EACd,aAAa,EACb,gBAAgB,EAChB,eAAe,GAChB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EACL,0BAA0B,EAC1B,qBAAqB,EACrB,qBAAqB,EACrB,4BAA4B,GAC7B,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,uBAAuB,EAAE,MAAM,cAAc,CAAC;AACvD,OAAO,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,WAAW,CAAC;AAC3D,OAAO,EAAE,iBAAiB,EAAiC,MAAM,cAAc,CAAC;AAChF,OAAO,EAAE,mBAAmB,EAAE,OAAO,EAAE,YAAY,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACnF,OAAO,EACL,qBAAqB,GAItB,MAAM,aAAa,CAAC;AACrB,OAAO,EACL,uBAAuB,EACvB,sBAAsB,EACtB,sBAAsB,EACtB,mBAAmB,EACnB,6BAA6B,EAC7B,0BAA0B,GAO3B,MAAM,YAAY,CAAC;AACpB,OAAO,EACL,kBAAkB,EAClB,oBAAoB,EACpB,mBAAmB,EACnB,kBAAkB,EAClB,yBAAyB,GAE1B,MAAM,aAAa,CAAC;AACrB,OAAO,EACL,uBAAuB,GAGxB,MAAM,gCAAgC,CAAC;AACxC,OAAO,EACL,6BAA6B,GAI9B,MAAM,gBAAgB,CAAC"}
|
|
@@ -3,18 +3,35 @@ import type { ChildWorkflowRecord, ControllerEvent, ControllerQueueClaim, Contro
|
|
|
3
3
|
/** A user-started workflow run tracked by the durable run queue. */
|
|
4
4
|
export type WorkflowRunQueueRecord = {
|
|
5
5
|
runId: string;
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
/** Human-readable workflow name used in status and event output. */
|
|
7
|
+
workflowName: string;
|
|
8
|
+
/** Canonical source reference used to reopen the run. */
|
|
9
|
+
workflowSourceRef: string;
|
|
8
10
|
input: unknown;
|
|
9
11
|
status: "claimed" | "parked" | "done";
|
|
10
12
|
runnerId: string | null;
|
|
11
13
|
claimToken: string | null;
|
|
12
14
|
claimExpiresAt: string | null;
|
|
13
15
|
affinityRunnerId: string | null;
|
|
16
|
+
/** Pi session that owns delivery and interactive execution, or null for detached runs. */
|
|
17
|
+
originSessionId: string | null;
|
|
14
18
|
parentRunId: string | null;
|
|
15
19
|
createdAt: string;
|
|
16
20
|
updatedAt: string;
|
|
17
21
|
};
|
|
22
|
+
export type WorkflowNotificationRecord = {
|
|
23
|
+
notificationId: string;
|
|
24
|
+
runId: string;
|
|
25
|
+
nodeId: string;
|
|
26
|
+
attemptId: string;
|
|
27
|
+
notificationIndex: number;
|
|
28
|
+
targetSessionId: string;
|
|
29
|
+
kind: "progress" | "final";
|
|
30
|
+
content: string;
|
|
31
|
+
createdAt: string;
|
|
32
|
+
deliveryClaimExpiresAt: string | null;
|
|
33
|
+
deliveredAt: string | null;
|
|
34
|
+
};
|
|
18
35
|
/** One run lifecycle transition in the cross-session event feed. */
|
|
19
36
|
export type RunEventRecord = {
|
|
20
37
|
seq: number;
|
|
@@ -128,13 +145,14 @@ export declare class SqliteControllerStore implements ControllerStore {
|
|
|
128
145
|
*/
|
|
129
146
|
enqueueWorkflowRun(options: {
|
|
130
147
|
runId: string;
|
|
131
|
-
|
|
132
|
-
|
|
148
|
+
workflowName: string;
|
|
149
|
+
workflowSourceRef: string;
|
|
133
150
|
input: unknown;
|
|
134
151
|
runnerId: string;
|
|
135
152
|
claimToken: string;
|
|
136
153
|
leaseMs: number;
|
|
137
154
|
affinityRunnerId?: string;
|
|
155
|
+
originSessionId?: string;
|
|
138
156
|
parentRunId?: string;
|
|
139
157
|
now?: string;
|
|
140
158
|
}): WorkflowRunQueueRecord;
|
|
@@ -153,6 +171,8 @@ export declare class SqliteControllerStore implements ControllerStore {
|
|
|
153
171
|
claimToken: string;
|
|
154
172
|
leaseMs: number;
|
|
155
173
|
excludeRunIds?: string[];
|
|
174
|
+
/** Interactive sessions provide their id; detached hosts omit it. */
|
|
175
|
+
sessionId?: string;
|
|
156
176
|
now?: string;
|
|
157
177
|
}): WorkflowRunQueueRecord | undefined;
|
|
158
178
|
/** Extend a live claim. Rejects expired or foreign claims. */
|
|
@@ -189,6 +209,27 @@ export declare class SqliteControllerStore implements ControllerStore {
|
|
|
189
209
|
claimToken: string;
|
|
190
210
|
now?: string;
|
|
191
211
|
}): boolean;
|
|
212
|
+
/** Repair a canonical bundle's queue source and claim it only when needed. */
|
|
213
|
+
repairCanonicalWorkflowSourceRun(options: {
|
|
214
|
+
runId: string;
|
|
215
|
+
workflowName: string;
|
|
216
|
+
workflowSourceRef: string;
|
|
217
|
+
runnerId: string;
|
|
218
|
+
claimToken: string;
|
|
219
|
+
leaseMs: number;
|
|
220
|
+
now?: string;
|
|
221
|
+
}): "unchanged" | "claimed" | false;
|
|
222
|
+
/** Claim and rewrite one proved legacy workflow source queue row atomically. */
|
|
223
|
+
claimLegacyWorkflowSourceRun(options: {
|
|
224
|
+
runId: string;
|
|
225
|
+
workflowName: string;
|
|
226
|
+
oldWorkflowPath: string;
|
|
227
|
+
workflowSourceRef: string;
|
|
228
|
+
runnerId: string;
|
|
229
|
+
claimToken: string;
|
|
230
|
+
leaseMs: number;
|
|
231
|
+
now?: string;
|
|
232
|
+
}): boolean;
|
|
192
233
|
/** Append a run lifecycle transition to the event feed. */
|
|
193
234
|
recordRunEvent(options: {
|
|
194
235
|
runId: string;
|
|
@@ -202,11 +243,31 @@ export declare class SqliteControllerStore implements ControllerStore {
|
|
|
202
243
|
listRunEventsAfter(seq: number, options?: {
|
|
203
244
|
limit?: number;
|
|
204
245
|
}): RunEventRecord[];
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
246
|
+
enqueueWorkflowNotification(options: {
|
|
247
|
+
runId: string;
|
|
248
|
+
nodeId: string;
|
|
249
|
+
attemptId: string;
|
|
250
|
+
notificationIndex: number;
|
|
251
|
+
targetSessionId: string;
|
|
252
|
+
kind: "progress" | "final";
|
|
253
|
+
content: string;
|
|
254
|
+
notificationId?: string;
|
|
255
|
+
now?: string;
|
|
256
|
+
}): WorkflowNotificationRecord;
|
|
257
|
+
claimPendingWorkflowNotifications(options: {
|
|
258
|
+
targetSessionId: string;
|
|
259
|
+
claimToken: string;
|
|
260
|
+
leaseMs: number;
|
|
261
|
+
limit?: number;
|
|
262
|
+
now?: string;
|
|
263
|
+
}): WorkflowNotificationRecord[];
|
|
264
|
+
markWorkflowNotificationDelivered(options: {
|
|
265
|
+
notificationId: string;
|
|
266
|
+
targetSessionId: string;
|
|
267
|
+
claimToken: string;
|
|
268
|
+
now?: string;
|
|
269
|
+
}): boolean;
|
|
270
|
+
setWorkflowRunOriginSession(runId: string, originSessionId: string): boolean;
|
|
210
271
|
private requireWorkflowRun;
|
|
211
272
|
private requireEvent;
|
|
212
273
|
}
|