@osolmaz/pi-workflows 0.13.2 → 0.13.3
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 +5 -3
- package/dist/builtins/autodoc.workflow.d.ts +5 -5
- package/dist/builtins/autoimplement.workflow.d.ts +65 -61
- package/dist/builtins/autoimplement.workflow.js +47 -8
- package/dist/builtins/autoimplement.workflow.js.map +1 -1
- package/dist/builtins/autoplan.workflow.d.ts +5 -5
- package/dist/builtins/catalog.js +1 -1
- package/dist/builtins/change-verification.workflow.d.ts +1 -1
- package/dist/builtins/plain-summary.workflow.d.ts +1 -1
- package/dist/builtins/plan-approval.workflow.d.ts +1 -1
- package/dist/builtins/plan-change.workflow.d.ts +23 -23
- package/dist/builtins/sanity-check.workflow.d.ts +3 -3
- package/dist/builtins/workspace-preparation.workflow.d.ts +1 -1
- package/dist/controllers/index.d.ts +2 -2
- package/dist/controllers/index.js.map +1 -1
- package/dist/controllers/sqlite.js +85 -23
- package/dist/controllers/sqlite.js.map +1 -1
- package/dist/controllers/types.d.ts +34 -0
- package/dist/controllers/workflow-engine-scheduler.d.ts +5 -1
- package/dist/controllers/workflow-engine-scheduler.js +83 -1
- package/dist/controllers/workflow-engine-scheduler.js.map +1 -1
- package/dist/controllers/workflows.d.ts +8 -1
- package/dist/controllers/workflows.js +36 -0
- package/dist/controllers/workflows.js.map +1 -1
- package/dist/extension/controller-host.d.ts +2 -1
- package/dist/extension/controller-host.js +1 -1
- package/dist/extension/controller-host.js.map +1 -1
- package/dist/extension/follow-up-coordinator.d.ts +27 -0
- package/dist/extension/follow-up-coordinator.js +131 -0
- package/dist/extension/follow-up-coordinator.js.map +1 -0
- package/dist/extension/index.d.ts +9 -0
- package/dist/extension/index.js +460 -75
- package/dist/extension/index.js.map +1 -1
- package/dist/extension/session-events.d.ts +2 -3
- package/dist/extension/session-events.js +11 -10
- package/dist/extension/session-events.js.map +1 -1
- package/dist/extension/widget.js +9 -0
- package/dist/extension/widget.js.map +1 -1
- package/dist/state/database.d.ts +2 -1
- package/dist/state/database.js +11 -13
- package/dist/state/database.js.map +1 -1
- package/dist/state/json.js +6 -1
- package/dist/state/json.js.map +1 -1
- package/dist/state/mutation.d.ts +1 -1
- package/dist/state/mutation.js.map +1 -1
- package/dist/state/prune.d.ts +18 -0
- package/dist/state/prune.js +373 -0
- package/dist/state/prune.js.map +1 -0
- package/dist/state/schema.d.ts +1 -1
- package/dist/state/schema.js +116 -18
- package/dist/state/schema.js.map +1 -1
- package/dist/viewer/cli.d.ts +3 -1
- package/dist/viewer/cli.js +55 -4
- package/dist/viewer/cli.js.map +1 -1
- package/dist/viewer/render.js +19 -1
- package/dist/viewer/render.js.map +1 -1
- package/dist/workflows/composition.d.ts +2 -0
- package/dist/workflows/composition.js +15 -0
- package/dist/workflows/composition.js.map +1 -1
- package/dist/workflows/definition.d.ts +6 -3
- package/dist/workflows/definition.js +3 -0
- package/dist/workflows/definition.js.map +1 -1
- package/dist/workflows/engine.d.ts +6 -1
- package/dist/workflows/engine.js +301 -35
- package/dist/workflows/engine.js.map +1 -1
- package/dist/workflows/human-decision.d.ts +1 -0
- package/dist/workflows/human-decision.js +25 -9
- package/dist/workflows/human-decision.js.map +1 -1
- package/dist/workflows/index.d.ts +3 -1
- package/dist/workflows/index.js +2 -0
- package/dist/workflows/index.js.map +1 -1
- package/dist/workflows/json-patch.d.ts +47 -0
- package/dist/workflows/json-patch.js +298 -0
- package/dist/workflows/json-patch.js.map +1 -0
- package/dist/workflows/schema.js +29 -1
- package/dist/workflows/schema.js.map +1 -1
- package/dist/workflows/settings.d.ts +128 -0
- package/dist/workflows/settings.js +199 -0
- package/dist/workflows/settings.js.map +1 -0
- package/dist/workflows/store.d.ts +75 -2
- package/dist/workflows/store.js +1349 -89
- package/dist/workflows/store.js.map +1 -1
- package/dist/workflows/tool-input.d.ts +22 -0
- package/dist/workflows/tool-input.js +43 -0
- package/dist/workflows/tool-input.js.map +1 -1
- package/dist/workflows/types.d.ts +40 -5
- package/docs/2026-08-25-workflow-follow-ups.md +132 -0
- package/docs/2026-08-25-workflow-settings.md +169 -0
- package/docs/DEFERRED_TURNS.md +6 -0
- package/docs/DESIGN_PHILOSOPHY.md +2 -0
- package/docs/SQLITE_STATE.md +31 -18
- package/docs/WORKFLOW_COMPOSITION.md +15 -0
- package/docs/WORKFLOW_STEP_MESSAGES.md +4 -2
- package/docs/plans/2026-08-25-live-workflow-settings-plan.md +532 -0
- package/docs/plans/2026-08-25-workflow-run-storage-plan.md +67 -0
- package/docs/tui-viewer.md +7 -6
- package/docs/workflows.md +22 -1
- package/examples/workflows/live-settings.workflow.ts +93 -0
- package/herdr-plugin.toml +1 -1
- package/package.json +1 -1
- package/src/builtins/autoimplement.workflow.ts +56 -8
- package/src/builtins/catalog.ts +1 -1
- package/src/controllers/index.ts +6 -0
- package/src/controllers/sqlite.ts +129 -35
- package/src/controllers/types.ts +40 -0
- package/src/controllers/workflow-engine-scheduler.ts +103 -1
- package/src/controllers/workflows.ts +68 -0
- package/src/extension/controller-host.ts +6 -1
- package/src/extension/follow-up-coordinator.ts +151 -0
- package/src/extension/index.ts +538 -88
- package/src/extension/session-events.ts +15 -13
- package/src/extension/widget.ts +8 -0
- package/src/state/database.ts +12 -12
- package/src/state/json.ts +6 -1
- package/src/state/mutation.ts +4 -1
- package/src/state/prune.ts +502 -0
- package/src/state/schema.ts +116 -18
- package/src/viewer/cli.ts +52 -5
- package/src/viewer/render.ts +43 -1
- package/src/workflows/composition.ts +19 -0
- package/src/workflows/definition.ts +19 -5
- package/src/workflows/engine.ts +363 -35
- package/src/workflows/human-decision.ts +41 -11
- package/src/workflows/index.ts +43 -0
- package/src/workflows/json-patch.ts +375 -0
- package/src/workflows/schema.ts +31 -1
- package/src/workflows/settings.ts +430 -0
- package/src/workflows/store.ts +1977 -184
- package/src/workflows/tool-input.ts +58 -0
- package/src/workflows/types.ts +43 -4
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
import { canonicalJson } from "../state/json.js";
|
|
2
|
+
import { MAX_WORKFLOW_SETTINGS_BYTES, applyJsonPatchOperation, cloneJson, jsonPointerTarget, parseJsonPointer, validateJsonPatch, } from "./json-patch.js";
|
|
3
|
+
export function workflowSettingsScopeId(originRunId, mountPath, invocation) {
|
|
4
|
+
if (!Number.isInteger(invocation) || invocation <= 0) {
|
|
5
|
+
throw new Error("Workflow settings invocation must be a positive integer");
|
|
6
|
+
}
|
|
7
|
+
return `${originRunId}:${mountPath || "$root"}:${invocation}`;
|
|
8
|
+
}
|
|
9
|
+
export function workflowSettings(options) {
|
|
10
|
+
if (typeof options.parse !== "function") {
|
|
11
|
+
throw new Error("Invalid workflow settings: parse must be a function");
|
|
12
|
+
}
|
|
13
|
+
if (!Array.isArray(options.paths)) {
|
|
14
|
+
throw new Error("Invalid workflow settings: paths must be an array");
|
|
15
|
+
}
|
|
16
|
+
validatePathRules(options.paths);
|
|
17
|
+
if (options.description !== undefined && options.description.trim().length === 0) {
|
|
18
|
+
throw new Error("Invalid workflow settings: description must not be empty");
|
|
19
|
+
}
|
|
20
|
+
if (options.validateChange !== undefined && typeof options.validateChange !== "function") {
|
|
21
|
+
throw new Error("Invalid workflow settings: validateChange must be a function");
|
|
22
|
+
}
|
|
23
|
+
return Object.freeze({
|
|
24
|
+
...options,
|
|
25
|
+
paths: Object.freeze(options.paths.map((rule) => freezeRule(rule))),
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
export function allowSettingsPath(path, permissions) {
|
|
29
|
+
parseJsonPointer(path);
|
|
30
|
+
validatePathPermissions(path, permissions);
|
|
31
|
+
return { path, permissions };
|
|
32
|
+
}
|
|
33
|
+
export function settingsRoute(definition) {
|
|
34
|
+
if (typeof definition.run !== "function") {
|
|
35
|
+
throw new Error("Invalid settings route: run must be a function");
|
|
36
|
+
}
|
|
37
|
+
return { nodeType: "compute", settingsRoute: true, ...definition };
|
|
38
|
+
}
|
|
39
|
+
export async function resolveInitialWorkflowSettings(definition, input) {
|
|
40
|
+
const raw = typeof definition.initial === "function"
|
|
41
|
+
? await definition.initial(input)
|
|
42
|
+
: definition.initial;
|
|
43
|
+
return await parseWorkflowSettingsValue(definition, raw);
|
|
44
|
+
}
|
|
45
|
+
export async function parseWorkflowSettingsValue(definition, raw) {
|
|
46
|
+
const parsed = await definition.parse(raw);
|
|
47
|
+
const json = cloneJson(parsed);
|
|
48
|
+
assertSettingsSize(json);
|
|
49
|
+
return { patch: [], settings: parsed, json };
|
|
50
|
+
}
|
|
51
|
+
export async function applyWorkflowSettingsPatch(definition, before, patchValue, actor, source) {
|
|
52
|
+
const patch = validateJsonPatch(patchValue);
|
|
53
|
+
let current = cloneJson(before);
|
|
54
|
+
for (const operation of patch) {
|
|
55
|
+
authorizeOperation(definition.paths, current, operation, actor.type);
|
|
56
|
+
current = applyJsonPatchOperation(current, operation);
|
|
57
|
+
}
|
|
58
|
+
assertSettingsSize(current);
|
|
59
|
+
const parsed = await definition.parse(cloneJson(current));
|
|
60
|
+
const normalized = cloneJson(parsed);
|
|
61
|
+
assertSettingsSize(normalized);
|
|
62
|
+
if (canonicalJson(normalized) !== canonicalJson(current)) {
|
|
63
|
+
throw new Error("Workflow settings parser must validate without changing the patched value");
|
|
64
|
+
}
|
|
65
|
+
await definition.validateChange?.({
|
|
66
|
+
before: cloneJson(before),
|
|
67
|
+
after: parsed,
|
|
68
|
+
actor,
|
|
69
|
+
source,
|
|
70
|
+
patch,
|
|
71
|
+
});
|
|
72
|
+
return { patch, settings: parsed, json: normalized };
|
|
73
|
+
}
|
|
74
|
+
export function settingsRuleForPath(rules, pointer) {
|
|
75
|
+
const path = parseJsonPointer(pointer);
|
|
76
|
+
let match;
|
|
77
|
+
let matchLength = -1;
|
|
78
|
+
for (const rule of rules) {
|
|
79
|
+
const prefix = parseJsonPointer(rule.path);
|
|
80
|
+
if (prefix.length >= matchLength && prefix.every((segment, index) => path[index] === segment)) {
|
|
81
|
+
if (prefix.length > matchLength) {
|
|
82
|
+
match = rule;
|
|
83
|
+
matchLength = prefix.length;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
return match;
|
|
88
|
+
}
|
|
89
|
+
function authorizeOperation(rules, document, operation, actor) {
|
|
90
|
+
switch (operation.op) {
|
|
91
|
+
case "test":
|
|
92
|
+
requirePermission(rules, operation.path, "read", actor);
|
|
93
|
+
return;
|
|
94
|
+
case "add":
|
|
95
|
+
requirePermission(rules, operation.path, destinationPermission(document, operation.path), actor);
|
|
96
|
+
return;
|
|
97
|
+
case "remove":
|
|
98
|
+
requirePermission(rules, operation.path, "remove", actor);
|
|
99
|
+
return;
|
|
100
|
+
case "replace":
|
|
101
|
+
requirePermission(rules, operation.path, "replace", actor);
|
|
102
|
+
return;
|
|
103
|
+
case "copy":
|
|
104
|
+
requirePermission(rules, operation.from, "read", actor);
|
|
105
|
+
requirePermission(rules, operation.path, destinationPermission(document, operation.path), actor);
|
|
106
|
+
return;
|
|
107
|
+
case "move":
|
|
108
|
+
requirePermission(rules, operation.from, "read", actor);
|
|
109
|
+
requirePermission(rules, operation.from, "remove", actor);
|
|
110
|
+
requirePermission(rules, operation.path, destinationPermission(document, operation.path), actor);
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
function destinationPermission(document, pointer) {
|
|
115
|
+
const segments = parseJsonPointer(pointer);
|
|
116
|
+
if (segments.length === 0)
|
|
117
|
+
return "replace";
|
|
118
|
+
const parentPointer = segments.length === 1 ? "" : `/${segments.slice(0, -1).map(encodeSegment).join("/")}`;
|
|
119
|
+
const parent = jsonPointerTarget(document, parentPointer);
|
|
120
|
+
if (!parent.exists)
|
|
121
|
+
return "add";
|
|
122
|
+
if (Array.isArray(parent.value))
|
|
123
|
+
return "add";
|
|
124
|
+
return jsonPointerTarget(document, pointer).exists ? "replace" : "add";
|
|
125
|
+
}
|
|
126
|
+
function requirePermission(rules, pointer, permission, actor) {
|
|
127
|
+
const rule = settingsRuleForPath(rules, pointer);
|
|
128
|
+
if (rule?.permissions[permission]?.includes(actor) !== true) {
|
|
129
|
+
throw new Error(`Workflow settings ${permission} is not allowed at ${JSON.stringify(pointer)} for actor ${actor}`);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
function validatePathRules(rules) {
|
|
133
|
+
const byPath = new Map();
|
|
134
|
+
for (const rule of rules) {
|
|
135
|
+
if (rule === null || typeof rule !== "object" || Array.isArray(rule)) {
|
|
136
|
+
throw new Error("Invalid workflow settings: each path rule must be an object");
|
|
137
|
+
}
|
|
138
|
+
parseJsonPointer(rule.path);
|
|
139
|
+
validatePathPermissions(rule.path, rule.permissions);
|
|
140
|
+
const normalized = freezeRule(rule);
|
|
141
|
+
const prior = byPath.get(rule.path);
|
|
142
|
+
if (prior !== undefined &&
|
|
143
|
+
canonicalJson(prior.permissions) !== canonicalJson(normalized.permissions)) {
|
|
144
|
+
throw new Error(`Conflicting workflow settings rules for ${JSON.stringify(rule.path)}`);
|
|
145
|
+
}
|
|
146
|
+
byPath.set(rule.path, normalized);
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
function validatePathPermissions(path, permissions) {
|
|
150
|
+
if (permissions === null || typeof permissions !== "object" || Array.isArray(permissions)) {
|
|
151
|
+
throw new Error(`Workflow settings path ${JSON.stringify(path)} permissions must be an object`);
|
|
152
|
+
}
|
|
153
|
+
if (Object.keys(permissions).length === 0) {
|
|
154
|
+
throw new Error(`Workflow settings path ${JSON.stringify(path)} grants no permissions`);
|
|
155
|
+
}
|
|
156
|
+
for (const [permission, actors] of Object.entries(permissions)) {
|
|
157
|
+
if (!isSettingsPermission(permission)) {
|
|
158
|
+
throw new Error(`Unknown workflow settings permission: ${permission}`);
|
|
159
|
+
}
|
|
160
|
+
if (!Array.isArray(actors) || actors.length === 0) {
|
|
161
|
+
throw new Error(`Workflow settings permission ${permission} at ${JSON.stringify(path)} requires actors`);
|
|
162
|
+
}
|
|
163
|
+
for (const actor of actors)
|
|
164
|
+
assertActorType(actor);
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
function freezeRule(rule) {
|
|
168
|
+
const permissions = {};
|
|
169
|
+
for (const [permission, actors] of Object.entries(rule.permissions)) {
|
|
170
|
+
if (!isSettingsPermission(permission) || !Array.isArray(actors))
|
|
171
|
+
continue;
|
|
172
|
+
permissions[permission] = Object.freeze([...new Set(actors)]);
|
|
173
|
+
}
|
|
174
|
+
return Object.freeze({ path: rule.path, permissions: Object.freeze(permissions) });
|
|
175
|
+
}
|
|
176
|
+
function assertSettingsSize(value) {
|
|
177
|
+
if (Buffer.byteLength(canonicalJson(value), "utf8") > MAX_WORKFLOW_SETTINGS_BYTES) {
|
|
178
|
+
throw new Error(`Workflow settings cannot exceed ${MAX_WORKFLOW_SETTINGS_BYTES} bytes`);
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
function assertActorType(value) {
|
|
182
|
+
if (value !== "session" &&
|
|
183
|
+
value !== "host" &&
|
|
184
|
+
value !== "controller" &&
|
|
185
|
+
value !== "channel" &&
|
|
186
|
+
value !== "human" &&
|
|
187
|
+
value !== "policy" &&
|
|
188
|
+
value !== "control" &&
|
|
189
|
+
value !== "system") {
|
|
190
|
+
throw new Error(`Unknown workflow settings actor: ${JSON.stringify(value)}`);
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
function isSettingsPermission(value) {
|
|
194
|
+
return value === "read" || value === "add" || value === "remove" || value === "replace";
|
|
195
|
+
}
|
|
196
|
+
function encodeSegment(segment) {
|
|
197
|
+
return segment.replaceAll("~", "~0").replaceAll("/", "~1");
|
|
198
|
+
}
|
|
199
|
+
//# sourceMappingURL=settings.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"settings.js","sourceRoot":"","sources":["../../src/workflows/settings.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAkB,MAAM,kBAAkB,CAAC;AAEjE,OAAO,EACL,2BAA2B,EAC3B,uBAAuB,EACvB,SAAS,EACT,iB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 @@
|
|
|
1
1
|
import { StateDatabase } from "../state/database.js";
|
|
2
|
-
import { type
|
|
2
|
+
import { type JsonValue } from "../state/json.js";
|
|
3
|
+
import { type LeaseClaim, type MutationActor, type OwnerType } from "../state/mutation.js";
|
|
4
|
+
import { type InitialWorkflowSettingsScope, type WorkflowFollowUpQueueRecord, type WorkflowFollowUpRecord, type WorkflowQueueFollowUpRequest, type WorkflowRemoveFollowUpRequest, type WorkflowSettingsChangeRequest, type WorkflowSettingsChangeResult, type WorkflowSettingsDefinition, type WorkflowSettingsScopeRecord } from "./settings.js";
|
|
3
5
|
import type { WorkflowDefinition, WorkflowDefinitionSnapshot, WorkflowRunState, WorkflowSessionBinding, WorkflowSessionCapture, WorkflowSessionEntryRecord, WorkflowSessionEventRecord, WorkflowTraceEvent, WorkflowTraceEventDraft, WorkflowUpdateInput, WorkflowUpdateRecord } from "./types.js";
|
|
4
6
|
export declare const RUN_STATE_SCHEMA: "pi-workflows.run-state.v1";
|
|
5
7
|
export declare const DEFINITION_SNAPSHOT_SCHEMA: "pi-workflows.definition-snapshot.v1";
|
|
@@ -44,19 +46,58 @@ export type LoadedWorkflowRun = {
|
|
|
44
46
|
sessionCapture: WorkflowSessionCapture | null;
|
|
45
47
|
sessionIntegrity: SessionCaptureIntegrity;
|
|
46
48
|
sessionSegments: SessionCaptureSegment[];
|
|
49
|
+
settingsScopes?: WorkflowSettingsScopeRecord[];
|
|
50
|
+
followUpQueue?: WorkflowFollowUpQueueRecord | null;
|
|
47
51
|
};
|
|
48
52
|
export type ReadWorkflowRunOptions = {
|
|
49
53
|
includeTrace?: boolean;
|
|
50
54
|
};
|
|
55
|
+
export type InitializeWorkflowRunOptions = {
|
|
56
|
+
initialSettings?: InitialWorkflowSettingsScope[];
|
|
57
|
+
};
|
|
51
58
|
export declare class WorkflowRunStore {
|
|
52
59
|
readonly databasePath: string;
|
|
53
60
|
readonly state: StateDatabase;
|
|
54
61
|
private readonly authorityProvider;
|
|
55
62
|
private readonly contexts;
|
|
56
63
|
private readonly ownsState;
|
|
64
|
+
private readonly mutations;
|
|
57
65
|
constructor(databasePath?: string, options?: WorkflowRunStoreOptions);
|
|
58
66
|
close(): void;
|
|
59
|
-
initializeRun(workflow: WorkflowDefinition, state: WorkflowRunState): Promise<string>;
|
|
67
|
+
initializeRun(workflow: WorkflowDefinition, state: WorkflowRunState, options?: InitializeWorkflowRunOptions): Promise<string>;
|
|
68
|
+
ensureSettingsScope(options: {
|
|
69
|
+
runId: string;
|
|
70
|
+
mountPath: string;
|
|
71
|
+
invocation: number;
|
|
72
|
+
settings: JsonValue;
|
|
73
|
+
}): WorkflowSettingsScopeRecord;
|
|
74
|
+
getSettingsScope(scopeId: string): WorkflowSettingsScopeRecord | undefined;
|
|
75
|
+
getSettingsScopeAtChange(scopeId: string, changeNumber: number): WorkflowSettingsScopeRecord | undefined;
|
|
76
|
+
listSettingsScopes(runId: string): WorkflowSettingsScopeRecord[];
|
|
77
|
+
private settingsScopesForRunView;
|
|
78
|
+
findSettingsScope(runId: string, mountPath: string, invocation: number): WorkflowSettingsScopeRecord | undefined;
|
|
79
|
+
changeSettings<TSettings, TInput = unknown>(definition: WorkflowSettingsDefinition<TSettings, TInput>, request: WorkflowSettingsChangeRequest): Promise<WorkflowSettingsChangeResult>;
|
|
80
|
+
queueFollowUp(request: WorkflowQueueFollowUpRequest): {
|
|
81
|
+
followUp: WorkflowFollowUpRecord;
|
|
82
|
+
adopted: boolean;
|
|
83
|
+
};
|
|
84
|
+
removeFollowUp(request: WorkflowRemoveFollowUpRequest): WorkflowFollowUpRecord;
|
|
85
|
+
originSessionId(runId: string): string | undefined;
|
|
86
|
+
readFollowUpQueue(runId: string): WorkflowFollowUpQueueRecord | undefined;
|
|
87
|
+
listPendingPresentations(targetSessionId: string): string[];
|
|
88
|
+
settleFollowUpPresentation(options: {
|
|
89
|
+
runId: string;
|
|
90
|
+
state: "settled" | "unavailable";
|
|
91
|
+
presentationEntryId?: string;
|
|
92
|
+
assistantEntryId?: string;
|
|
93
|
+
reason?: string;
|
|
94
|
+
}): WorkflowFollowUpQueueRecord;
|
|
95
|
+
claimNextFollowUp(targetSessionId: string, ownerId: string, leaseMs?: number): {
|
|
96
|
+
followUp: WorkflowFollowUpRecord;
|
|
97
|
+
claim: LeaseClaim;
|
|
98
|
+
} | undefined;
|
|
99
|
+
markFollowUpSent(followUpId: string, claim: LeaseClaim, sessionEntryId: string): WorkflowFollowUpRecord;
|
|
100
|
+
releaseFollowUpClaim(claim: LeaseClaim): void;
|
|
60
101
|
prepareRunResume(runId: string): Promise<LoadedWorkflowRun>;
|
|
61
102
|
markRunInterrupted(runId: string, reason?: string): Promise<LoadedWorkflowRun | null>;
|
|
62
103
|
publishUpdate(runId: string, state: WorkflowRunState, nodeId: string, attemptId: string, update: WorkflowUpdateInput, options?: {
|
|
@@ -89,15 +130,47 @@ export declare class WorkflowRunStore {
|
|
|
89
130
|
private assertWriteAuthority;
|
|
90
131
|
private persistRunState;
|
|
91
132
|
private enqueueRunSettlementEffect;
|
|
133
|
+
private initializeRunSettingsAndFollowUps;
|
|
134
|
+
private ensureFollowUpQueue;
|
|
135
|
+
private logicalOriginRunId;
|
|
136
|
+
private requireRunAcceptsSettings;
|
|
137
|
+
private verifySettingsProjections;
|
|
138
|
+
private settingsScopeRow;
|
|
139
|
+
private requireSettingsScopeRow;
|
|
140
|
+
private settingsScopeRecord;
|
|
141
|
+
private settingsChangeRow;
|
|
142
|
+
private settingsChangeRecord;
|
|
143
|
+
private assertSameSettingsChange;
|
|
144
|
+
private followUpQueueRow;
|
|
145
|
+
private requireFollowUpQueueRow;
|
|
146
|
+
private followUpRowByRequest;
|
|
147
|
+
private followUpRow;
|
|
148
|
+
private requireFollowUpRow;
|
|
149
|
+
private followUpRecord;
|
|
150
|
+
private assertSameFollowUp;
|
|
151
|
+
private assertFollowUpRemovalAuthority;
|
|
152
|
+
private hasLiveLease;
|
|
153
|
+
private nextFollowUpOrder;
|
|
154
|
+
private assertSettingsRouteCurrent;
|
|
155
|
+
private transitionFollowUpsForRunState;
|
|
92
156
|
private syncNodeAttempts;
|
|
93
157
|
private syncRunSteps;
|
|
158
|
+
private syncAttemptEntries;
|
|
159
|
+
private findAttemptPromptEntry;
|
|
160
|
+
private readAttemptOutput;
|
|
94
161
|
private ensureAttempt;
|
|
95
162
|
private nextAttemptNumber;
|
|
96
163
|
private nextUpdateSequence;
|
|
164
|
+
private insertRunSources;
|
|
165
|
+
private syncContinuationIdentity;
|
|
97
166
|
private readRunRow;
|
|
98
167
|
private requireRunRow;
|
|
99
168
|
private readRunState;
|
|
100
169
|
private readSteps;
|
|
170
|
+
private readRunSources;
|
|
171
|
+
private carriedStepCount;
|
|
172
|
+
private readActiveAttempt;
|
|
173
|
+
private readHumanDecisionReceipt;
|
|
101
174
|
private readUpdates;
|
|
102
175
|
private readJsonAs;
|
|
103
176
|
private readText;
|