@nathanstephenson/flow 0.1.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 +641 -0
- package/build/workflow-runtime.cjs +213964 -0
- package/dist/backend/claude/async-queue.js +44 -0
- package/dist/backend/claude/auto-compaction.js +10 -0
- package/dist/backend/claude/background-calls.js +116 -0
- package/dist/backend/claude/enquiries.js +162 -0
- package/dist/backend/claude/index.js +1138 -0
- package/dist/backend/claude/mcp.js +55 -0
- package/dist/backend/claude/permissions.js +106 -0
- package/dist/backend/claude/streamed-message.js +120 -0
- package/dist/backend/claude/subagents.js +128 -0
- package/dist/backend/claude/workflow-parent.js +12 -0
- package/dist/backend/claude/workflow-processes.js +95 -0
- package/dist/backend/claude/workflow-subagent.js +234 -0
- package/dist/backend/effort.js +30 -0
- package/dist/backend/fake/index.js +570 -0
- package/dist/backend/mcp.js +190 -0
- package/dist/backend/pi/auto-compaction.js +16 -0
- package/dist/backend/pi/background-calls.js +56 -0
- package/dist/backend/pi/enquiries.js +63 -0
- package/dist/backend/pi/index.js +597 -0
- package/dist/backend/pi/mcp.js +35 -0
- package/dist/backend/pi/subagents.js +23 -0
- package/dist/backend/pi/work.js +104 -0
- package/dist/backend/pi/workflow-parent.js +21 -0
- package/dist/backend/pi/workflow-subagent.js +199 -0
- package/dist/backend/registry.js +34 -0
- package/dist/backend/types.js +1 -0
- package/dist/backend/workflow-tools.js +25 -0
- package/dist/build-id +1 -0
- package/dist/cli/application.js +397 -0
- package/dist/cli/bootstrap.js +535 -0
- package/dist/cli/host-control.js +100 -0
- package/dist/cli/install-guard.js +270 -0
- package/dist/cli/install-process.js +52 -0
- package/dist/cli/main.js +12 -0
- package/dist/cli/update.js +128 -0
- package/dist/client/connection.js +183 -0
- package/dist/client/context-usage.js +66 -0
- package/dist/client/diff.js +36 -0
- package/dist/client/enquiry.js +105 -0
- package/dist/client/markdown.js +192 -0
- package/dist/client/model-choices.js +32 -0
- package/dist/client/permission.js +60 -0
- package/dist/client/project-name.js +19 -0
- package/dist/client/reduce.js +463 -0
- package/dist/client/relative-time.js +30 -0
- package/dist/client/scope-kind.js +28 -0
- package/dist/client/search.js +136 -0
- package/dist/client/session-label.js +9 -0
- package/dist/client/status.js +84 -0
- package/dist/client/tool-chains.js +52 -0
- package/dist/client/tool-summary.js +98 -0
- package/dist/daemon/auth.js +590 -0
- package/dist/daemon/config-store.js +183 -0
- package/dist/daemon/config.js +687 -0
- package/dist/daemon/credential-redaction.js +9 -0
- package/dist/daemon/git.js +312 -0
- package/dist/daemon/host-control-routes.js +29 -0
- package/dist/daemon/host.js +2343 -0
- package/dist/daemon/http.js +19 -0
- package/dist/daemon/log.js +44 -0
- package/dist/daemon/mcp-auth.js +164 -0
- package/dist/daemon/models.js +85 -0
- package/dist/daemon/ownership.js +104 -0
- package/dist/daemon/projects.js +317 -0
- package/dist/daemon/publish.js +289 -0
- package/dist/daemon/pull-request.js +198 -0
- package/dist/daemon/runtime.js +100 -0
- package/dist/daemon/secret-store.js +65 -0
- package/dist/daemon/server.js +827 -0
- package/dist/daemon/shell.js +220 -0
- package/dist/daemon/skills.js +104 -0
- package/dist/daemon/stack-metadata.js +24 -0
- package/dist/daemon/stack.js +743 -0
- package/dist/daemon/store.js +130 -0
- package/dist/daemon/summariser.js +476 -0
- package/dist/daemon/workflow-execution-routes.js +105 -0
- package/dist/daemon/workflow-executions.js +1018 -0
- package/dist/daemon/workflow-mcp.js +20 -0
- package/dist/daemon/workflow-routes.js +102 -0
- package/dist/protocol/attachments.js +59 -0
- package/dist/protocol/commands.js +1 -0
- package/dist/protocol/events.js +20 -0
- package/dist/protocol/fonts.js +26 -0
- package/dist/protocol/git.js +12 -0
- package/dist/protocol/mcp.js +51 -0
- package/dist/protocol/projects.js +21 -0
- package/dist/protocol/publish.js +1 -0
- package/dist/protocol/pull-request.js +1 -0
- package/dist/protocol/secrets.js +4 -0
- package/dist/protocol/settings.js +63 -0
- package/dist/protocol/shells.js +8 -0
- package/dist/protocol/skills.js +16 -0
- package/dist/protocol/stack.js +41 -0
- package/dist/protocol/workflow-executions.js +1 -0
- package/dist/protocol/workflows.js +1 -0
- package/dist/tui/app.js +518 -0
- package/dist/tui/keys.js +54 -0
- package/dist/tui/render.js +366 -0
- package/dist/web/assets.js +10 -0
- package/dist/web/embedded.js +12 -0
- package/dist/web/manifest.js +70 -0
- package/dist/workflows/decisions.js +65 -0
- package/dist/workflows/executors.js +132 -0
- package/dist/workflows/graph.js +276 -0
- package/dist/workflows/json-schema.js +49 -0
- package/dist/workflows/loops.js +102 -0
- package/dist/workflows/mcp.js +18 -0
- package/dist/workflows/records.js +111 -0
- package/dist/workflows/recovery.js +25 -0
- package/dist/workflows/runtime-asset.js +17 -0
- package/dist/workflows/runtime-libs.js +1 -0
- package/dist/workflows/runtime-settings.js +23 -0
- package/dist/workflows/runtime.js +343 -0
- package/dist/workflows/scheduler.js +573 -0
- package/dist/workflows/schema.js +161 -0
- package/dist/workflows/store.js +93 -0
- package/package.json +87 -0
- package/web/dist/assets/__vite-browser-external-2447137e-BvRk9kiK.js +0 -0
- package/web/dist/assets/ghostty-vt-DOMeXDrv.wasm +0 -0
- package/web/dist/assets/index-BC0gLS53.js +106 -0
- package/web/dist/assets/index-CCeZYKES.css +2 -0
- package/web/dist/assets/inter-cyrillic-ext-wght-normal-BOeWTOD4.woff2 +0 -0
- package/web/dist/assets/inter-cyrillic-wght-normal-DqGufNeO.woff2 +0 -0
- package/web/dist/assets/inter-greek-ext-wght-normal-DlzME5K_.woff2 +0 -0
- package/web/dist/assets/inter-greek-wght-normal-CkhJZR-_.woff2 +0 -0
- package/web/dist/assets/inter-latin-ext-wght-normal-DO1Apj_S.woff2 +0 -0
- package/web/dist/assets/inter-latin-wght-normal-Dx4kXJAl.woff2 +0 -0
- package/web/dist/assets/inter-vietnamese-wght-normal-CBcvBZtf.woff2 +0 -0
- package/web/dist/assets/rolldown-runtime-B0Z9INg1.js +1 -0
- package/web/dist/assets/select-6i3wxovH.js +1 -0
- package/web/dist/assets/settings-mcp-CcT0ADJR.js +1 -0
- package/web/dist/assets/settings-secrets-CK4uF7fd.js +1 -0
- package/web/dist/assets/settings-workflows-CrbZF-nM.js +23 -0
- package/web/dist/assets/switch-ftZleVB8.js +6 -0
- package/web/dist/assets/workflow-editors-naPqAmYO.js +65 -0
- package/web/dist/assets/workflows-D4T4Gy_7.css +1 -0
- package/web/dist/assets/workflows-hh6ioeEA.js +7 -0
- package/web/dist/assets/workflows-pane-Db-MHf7Z.js +1 -0
- package/web/dist/index.html +31 -0
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { validateDefinition } from "../workflows/graph.js";
|
|
2
|
+
import { WorkflowConflict } from "./workflow-executions.js";
|
|
3
|
+
import { workflowRequestError } from "./workflow-routes.js";
|
|
4
|
+
export async function workflowExecutionRoutes(request, response, pathname, service, store) {
|
|
5
|
+
const match = /^\/api\/sessions\/([a-zA-Z0-9_-]+)\/workflows(?:\/([a-zA-Z0-9_-]+)(?:\/(cancel|recover|activity))?)?$/.exec(pathname);
|
|
6
|
+
const discovery = /^\/api\/sessions\/([a-zA-Z0-9_-]+)\/workflow-mcp(?:\/([a-zA-Z0-9_-]+))?$/.exec(pathname);
|
|
7
|
+
const test = pathname === '/api/workflows/test' && request.method === 'POST';
|
|
8
|
+
const runtime = pathname === '/api/workflow-runtime';
|
|
9
|
+
if (!match && !test && !runtime && !discovery)
|
|
10
|
+
return false;
|
|
11
|
+
const reply = (status, body) => { response.writeHead(status, { 'content-type': 'application/json' }); response.end(JSON.stringify(body)); };
|
|
12
|
+
if (!service || !store) {
|
|
13
|
+
reply(404, { error: 'Workflow execution is unavailable' });
|
|
14
|
+
return true;
|
|
15
|
+
}
|
|
16
|
+
try {
|
|
17
|
+
if (request.method === 'GET' && discovery)
|
|
18
|
+
reply(200, discovery[2] ? await service.discoverMcp(discovery[1], discovery[2]) : service.mcpConnections(discovery[1]));
|
|
19
|
+
else if (request.method === 'GET' && runtime)
|
|
20
|
+
reply(200, service.status());
|
|
21
|
+
else if (request.method === 'GET' && match?.[3] === 'activity') {
|
|
22
|
+
const query = new URL(request.url, 'http://localhost').searchParams;
|
|
23
|
+
reply(200, await service.activity(match[1], match[2], {
|
|
24
|
+
...(query.has('after') ? { after: Number(query.get('after')) } : {}),
|
|
25
|
+
...(query.has('before') ? { before: Number(query.get('before')) } : {}),
|
|
26
|
+
...(query.get('latest') === 'true' ? { latest: true } : {}),
|
|
27
|
+
limit: Number(query.get('limit') ?? 100),
|
|
28
|
+
...(query.has('stepId') ? { stepId: query.get('stepId') } : {}),
|
|
29
|
+
...(query.has('attempt') ? { attempt: Number(query.get('attempt')) } : {}),
|
|
30
|
+
}));
|
|
31
|
+
}
|
|
32
|
+
else if (request.method === 'GET' && match && !match[3])
|
|
33
|
+
reply(200, match[2] ? service.view(match[1], match[2]) : service.list(match[1]));
|
|
34
|
+
else if (request.method === 'POST' && !runtime) {
|
|
35
|
+
const chunks = [];
|
|
36
|
+
for await (const chunk of request) {
|
|
37
|
+
const bytes = Buffer.from(chunk);
|
|
38
|
+
chunks.push(bytes);
|
|
39
|
+
}
|
|
40
|
+
const body = chunks.length ? JSON.parse(Buffer.concat(chunks).toString('utf8')) : {};
|
|
41
|
+
if (!body || typeof body !== 'object' || Array.isArray(body))
|
|
42
|
+
throw new Error();
|
|
43
|
+
const keys = (...names) => { if (Object.keys(body).some(key => !names.includes(key)))
|
|
44
|
+
throw new Error(); };
|
|
45
|
+
const string = (key) => { if (typeof body[key] !== 'string' || !body[key].length)
|
|
46
|
+
throw new Error(); return body[key]; };
|
|
47
|
+
const input = () => { if (!Object.hasOwn(body, 'input'))
|
|
48
|
+
throw new Error(); return body.input; };
|
|
49
|
+
if (test) {
|
|
50
|
+
keys('definition', 'sessionId', 'stepId', 'input');
|
|
51
|
+
reply(200, await service.start({ sessionId: string('sessionId'), definition: validateDefinition(body.definition).definition, input: input(), stepId: string('stepId') }));
|
|
52
|
+
}
|
|
53
|
+
else if (!match[2]) {
|
|
54
|
+
keys('workflowId', 'input', 'launchId', 'nameSession');
|
|
55
|
+
if (body.nameSession !== undefined && body.nameSession !== true)
|
|
56
|
+
throw new Error();
|
|
57
|
+
const launchId = body.launchId === undefined ? undefined : string('launchId');
|
|
58
|
+
reply(200, await service.start({ sessionId: match[1], definition: store.getDefinition(string('workflowId')), input: input(), nameSession: body.nameSession === true, ...(launchId ? { launchId } : {}) }));
|
|
59
|
+
}
|
|
60
|
+
else {
|
|
61
|
+
const sessionId = match[1], executionId = match[2];
|
|
62
|
+
switch (match[3]) {
|
|
63
|
+
case 'cancel':
|
|
64
|
+
keys();
|
|
65
|
+
reply(200, await service.cancel(sessionId, executionId));
|
|
66
|
+
break;
|
|
67
|
+
case 'recover': {
|
|
68
|
+
if (body.kind === 'continue')
|
|
69
|
+
keys('kind');
|
|
70
|
+
else if (body.kind === 'extend-loop') {
|
|
71
|
+
keys('kind', 'headerId', 'activation', 'try', 'guidance');
|
|
72
|
+
string('headerId');
|
|
73
|
+
if (![body.activation, body.try].every(value => Number.isSafeInteger(value) && value > 0))
|
|
74
|
+
throw new Error();
|
|
75
|
+
if (body.guidance !== undefined && (typeof body.guidance !== 'string' || body.guidance.length > 100_000))
|
|
76
|
+
throw new Error();
|
|
77
|
+
}
|
|
78
|
+
else if (body.kind === 'retry') {
|
|
79
|
+
keys('kind', 'stepId');
|
|
80
|
+
string('stepId');
|
|
81
|
+
}
|
|
82
|
+
else if (body.kind === 'supply') {
|
|
83
|
+
keys('kind', 'stepId', 'output');
|
|
84
|
+
string('stepId');
|
|
85
|
+
if (!Object.hasOwn(body, 'output'))
|
|
86
|
+
throw new Error();
|
|
87
|
+
}
|
|
88
|
+
else
|
|
89
|
+
throw new Error();
|
|
90
|
+
reply(200, await service.recover(sessionId, executionId, body));
|
|
91
|
+
break;
|
|
92
|
+
}
|
|
93
|
+
default: reply(405, { error: 'Method not allowed' });
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
else
|
|
98
|
+
reply(405, { error: 'Method not allowed' });
|
|
99
|
+
}
|
|
100
|
+
catch (error) {
|
|
101
|
+
const code = error?.code;
|
|
102
|
+
reply(error instanceof WorkflowConflict ? 409 : code === 'ENOENT' ? 404 : code ? 500 : 400, { error: code ? 'Workflow resource unavailable' : workflowRequestError(error) });
|
|
103
|
+
}
|
|
104
|
+
return true;
|
|
105
|
+
}
|