@nathanstephenson/flow 0.1.10-beta.1 → 0.1.10-beta.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.
Files changed (73) hide show
  1. package/README.md +18 -0
  2. package/build/backend-worker-chunks/{chunk-CYE5L6Z5.mjs → chunk-LO7O6NAM.mjs} +9 -7
  3. package/build/backend-worker-chunks/{claude-UXZDJKZQ.mjs → claude-6L5KCQWJ.mjs} +99 -21
  4. package/build/backend-worker-chunks/{pi-UKRC4DDM.mjs → pi-QNU2YE4G.mjs} +45 -13
  5. package/build/backend-worker.mjs +48 -7
  6. package/dist/backend/claude/background-calls.js +7 -3
  7. package/dist/backend/claude/index.js +72 -10
  8. package/dist/backend/claude/subagents.js +30 -9
  9. package/dist/backend/fake/index.js +36 -6
  10. package/dist/backend/pi/index.js +34 -2
  11. package/dist/backend/pi/state.js +16 -1
  12. package/dist/backend/pi/subagents.js +7 -3
  13. package/dist/backend/worker/claude-state.js +22 -0
  14. package/dist/backend/worker/entry.js +25 -6
  15. package/dist/backend/worker/index.js +30 -5
  16. package/dist/backend/worker/protocol.js +1 -1
  17. package/dist/backend/worker/rpc.js +13 -0
  18. package/dist/backend/worker/sandbox-mcp.js +18 -7
  19. package/dist/backend/workflow-tools.js +9 -7
  20. package/dist/build-id +1 -1
  21. package/dist/cli/bootstrap.js +1 -1
  22. package/dist/client/reduce.js +29 -3
  23. package/dist/client/subagent-tree.js +49 -0
  24. package/dist/daemon/git.js +10 -7
  25. package/dist/daemon/host.js +226 -26
  26. package/dist/daemon/runtime.js +71 -3
  27. package/dist/daemon/server.js +3 -0
  28. package/dist/daemon/store.js +2 -0
  29. package/dist/daemon/workflow-builder-guidance.js +1 -1
  30. package/dist/daemon/workflow-builder.js +36 -11
  31. package/dist/daemon/workflow-environment.js +191 -0
  32. package/dist/daemon/workflow-execution-launch.js +77 -0
  33. package/dist/daemon/workflow-execution-resources.js +76 -0
  34. package/dist/daemon/workflow-execution-routes.js +9 -6
  35. package/dist/daemon/workflow-execution-values.js +128 -0
  36. package/dist/daemon/workflow-executions.js +382 -300
  37. package/dist/daemon/workflow-routes.js +39 -0
  38. package/dist/daemon/workflow-schedule-driver.js +247 -0
  39. package/dist/daemon/workflow-schedule-routes.js +137 -0
  40. package/dist/daemon/workflow-schedules.js +341 -0
  41. package/dist/isolation/sandbox.js +30 -14
  42. package/dist/isolation/shared-sandbox.js +3 -3
  43. package/dist/protocol/events.js +2 -0
  44. package/dist/protocol/workflow-schedules.js +1 -0
  45. package/dist/tui/render.js +7 -1
  46. package/dist/workflows/calls.js +53 -0
  47. package/dist/workflows/errors.js +2 -0
  48. package/dist/workflows/executors.js +1 -1
  49. package/dist/workflows/graph.js +78 -4
  50. package/dist/workflows/invocations.js +23 -0
  51. package/dist/workflows/owner.js +45 -0
  52. package/dist/workflows/records.js +124 -8
  53. package/dist/workflows/recovery.js +37 -1
  54. package/dist/workflows/schedule-errors.js +2 -0
  55. package/dist/workflows/schedule-store.js +385 -0
  56. package/dist/workflows/scheduler.js +351 -92
  57. package/dist/workflows/schedules.js +129 -0
  58. package/dist/workflows/schema.js +2 -0
  59. package/dist/workflows/store.js +110 -11
  60. package/package.json +2 -1
  61. package/web/dist/assets/index-BGu3YSP7.css +2 -0
  62. package/web/dist/assets/index-Miy2nveb.js +40 -0
  63. package/web/dist/assets/{settings-mcp-Clp_jMWW.js → settings-mcp-Vf_fCXyE.js} +1 -1
  64. package/web/dist/assets/settings-workflows-DVKxJWQm.js +23 -0
  65. package/web/dist/assets/workflows-Dobqzjg-.js +146 -0
  66. package/web/dist/assets/workflows-pane-KB-Q76KZ.js +1 -0
  67. package/web/dist/index.html +4 -3
  68. package/web/dist/assets/index-DRfeO6GJ.js +0 -40
  69. package/web/dist/assets/index-DgQFpKbn.css +0 -2
  70. package/web/dist/assets/settings-workflows-H-6eCff3.js +0 -23
  71. package/web/dist/assets/workflow-editors-CsbVx4WJ.js +0 -139
  72. package/web/dist/assets/workflows-Bv0sj7d0.js +0 -7
  73. package/web/dist/assets/workflows-pane-DHm44w7P.js +0 -1
@@ -0,0 +1,128 @@
1
+ import { realpathSync } from 'node:fs';
2
+ import { invocationExecution } from "../workflows/invocations.js";
3
+ import { WorkflowStepError } from "../workflows/scheduler.js";
4
+ import { redactCredentials } from "./credential-redaction.js";
5
+ import { WorkflowValidationError } from "../workflows/errors.js";
6
+ export { WorkflowValidationError } from "../workflows/errors.js";
7
+ export class WorkflowConflict extends Error {
8
+ constructor() { super('Workflow decision or slot is no longer available'); }
9
+ }
10
+ export function sameProject(project, scope) {
11
+ try {
12
+ return realpathSync(project) === scope;
13
+ }
14
+ catch {
15
+ return false;
16
+ }
17
+ }
18
+ export function redact(value, secrets) { return redactCredentials(value, secrets); }
19
+ export function redactEvent(event, secrets, publicId) {
20
+ const visit = (item, path = []) => {
21
+ if (typeof item === 'string') {
22
+ const key = path.at(-1);
23
+ if (path.length === 1 && ['type', 'state', 'on', 'decision', 'reason', 'level', 'trigger', 'effort'].includes(key))
24
+ return item;
25
+ if (['id', 'callId', 'askId', 'subagentId', 'turnId'].includes(key) && (path.length === 1 || path[0] === 'producer'))
26
+ return publicId(item);
27
+ return redact(item, secrets);
28
+ }
29
+ if (Array.isArray(item))
30
+ return item.map(value => visit(value, path));
31
+ if (item && typeof item === 'object')
32
+ return Object.fromEntries(Object.entries(item).map(([key, value]) => [key,
33
+ path.length === 0 && ['input', 'update', 'result'].includes(key) ? redact(value, secrets) : visit(value, [...path, key]),
34
+ ]));
35
+ return item;
36
+ };
37
+ return visit(event);
38
+ }
39
+ export function confirmedAgentStep(step, models) {
40
+ const model = models.find(candidate => candidate.id === step.model);
41
+ return model && !model.effortLevels?.length && step.effort !== 'off' ? { ...step, effort: 'off' } : step;
42
+ }
43
+ export function withConfirmedNoControlOff(definition, models) {
44
+ const steps = definition.steps.map(step => step.kind === 'agent' ? confirmedAgentStep(step, models) : step);
45
+ return steps.some((step, index) => step !== definition.steps[index]) ? { ...definition, steps } : definition;
46
+ }
47
+ function publicStep({ secrets, ...step }) { return step; }
48
+ export function publicDefinition(definition) {
49
+ return { ...definition, steps: definition.steps.map(publicStep) };
50
+ }
51
+ export function publicExecutionData(record) {
52
+ const corrections = (updates) => updates?.map(update => ({ ...update, previousStep: publicStep(update.previousStep), nextStep: publicStep(update.nextStep) }));
53
+ return {
54
+ ...record,
55
+ definition: publicDefinition(record.definition),
56
+ definitionUpdates: corrections(record.definitionUpdates),
57
+ retainedDefinitions: record.retainedDefinitions && Object.fromEntries(Object.entries(record.retainedDefinitions).map(([id, definition]) => [id, publicDefinition(definition)])),
58
+ invocations: record.invocations && Object.fromEntries(Object.entries(record.invocations).map(([id, invocation]) => [id, { ...invocation, definitionUpdates: corrections(invocation.definitionUpdates) }])),
59
+ };
60
+ }
61
+ export function assertNoSecrets(value, secrets, checkKeys = false) {
62
+ const visit = (item) => {
63
+ if (typeof item === 'string')
64
+ return redact(item, secrets) !== item;
65
+ if (Array.isArray(item))
66
+ return item.some(visit);
67
+ return !!item && typeof item === 'object' && Object.entries(item).some(([key, value]) => (checkKeys && visit(key)) || visit(value));
68
+ };
69
+ if (visit(value))
70
+ throw new WorkflowValidationError('Saved workflow data cannot contain secret values');
71
+ }
72
+ export function safeError(error, values) {
73
+ const message = redact(error instanceof Error ? error.message : String(error), values);
74
+ return error instanceof WorkflowStepError ? new WorkflowStepError(message, error.partialOutput === undefined ? undefined : redact(error.partialOutput, values)) : new Error(message);
75
+ }
76
+ export function outcomeNamingData(record) {
77
+ const stepNames = new Map(record.definition.steps.map(step => [step.id, step.name]));
78
+ function* results() {
79
+ for (const id in record.steps) {
80
+ const output = record.steps[id].output;
81
+ if (output !== undefined)
82
+ yield { step: stepNames.get(id) ?? id, output };
83
+ }
84
+ }
85
+ function* errors() {
86
+ for (const id in record.steps)
87
+ for (const attempt of record.steps[id].attempts) {
88
+ if (attempt.error !== undefined)
89
+ yield {
90
+ step: stepNames.get(id) ?? id, attempt: attempt.number, error: attempt.error,
91
+ ...(attempt.partialOutput === undefined ? {} : { partialOutput: attempt.partialOutput }),
92
+ };
93
+ }
94
+ }
95
+ return { results: record.result === undefined ? results() : record.result, errors: errors() };
96
+ }
97
+ export function uniqueCredentials(values) { return [...new Set(values.filter(Boolean))]; }
98
+ export function relayContext(record, stepId, attempt, invocationId) {
99
+ const step = record.definition.steps.find(item => item.id === stepId);
100
+ return `Workflow “${record.definition.name}” · Step “${step?.name ?? stepId}” · Attempt ${attempt}${invocationId ? ` · Invocation ${invocationId}` : ''}${record.testStepId ? ' · Step test' : ''}`;
101
+ }
102
+ export function relaySignal(request, parent) { return parent ? AbortSignal.any([request, parent]) : request; }
103
+ export function selectWorkflowInvocation(root, invocationId) {
104
+ return invocationId === undefined ? root : { ...invocationExecution(root, invocationId), id: root.id };
105
+ }
106
+ export function attemptIdentity(context) {
107
+ return { stepId: context.step.id, attempt: context.attempt ?? 1, ...(context.invocationId === undefined ? {} : { invocationId: context.invocationId }) };
108
+ }
109
+ export function spendKey(stepId, invocationId) { return invocationId === undefined ? stepId : JSON.stringify([invocationId, stepId]); }
110
+ export function sumSpend(values) {
111
+ const result = { tokens: 0, cached: 0, costUSD: 0, models: [] };
112
+ for (const value of values) {
113
+ result.tokens += value.tokens;
114
+ result.cached += value.cached;
115
+ result.costUSD += value.costUSD;
116
+ for (const model of value.models) {
117
+ const existing = result.models.find(item => item.id === model.id);
118
+ if (existing) {
119
+ existing.tokens += model.tokens;
120
+ existing.cached += model.cached;
121
+ existing.costUSD += model.costUSD;
122
+ }
123
+ else
124
+ result.models.push({ ...model });
125
+ }
126
+ }
127
+ return result;
128
+ }