@igorjpimenta/manifold 0.0.0-bootstrap.1 → 0.0.0-stage
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 +2 -1583
- package/package.json +4 -49
- package/.migrations/ops/0000_futuristic_karma.sql +0 -111
- package/.migrations/ops/0001_low_maximus.sql +0 -7
- package/.migrations/ops/meta/0000_snapshot.json +0 -763
- package/.migrations/ops/meta/0001_snapshot.json +0 -173
- package/.migrations/ops/meta/_journal.json +0 -20
- package/.migrations/runtime/0000_real_boomer.sql +0 -180
- package/.migrations/runtime/0001_hot_dakota_north.sql +0 -2
- package/.migrations/runtime/0002_breezy_vertigo.sql +0 -8
- package/.migrations/runtime/0003_dashing_jack_flag.sql +0 -5
- package/.migrations/runtime/0004_panoramic_ego.sql +0 -1
- package/.migrations/runtime/0005_tidy_ben_grimm.sql +0 -10
- package/.migrations/runtime/0006_wet_nightmare.sql +0 -57
- package/.migrations/runtime/0007_ambiguous_chronomancer.sql +0 -8
- package/.migrations/runtime/0008_wealthy_thundra.sql +0 -301
- package/.migrations/runtime/0009_lying_shocker.sql +0 -96
- package/.migrations/runtime/0010_solid_phantom_reporter.sql +0 -160
- package/.migrations/runtime/0011_windy_demogoblin.sql +0 -175
- package/.migrations/runtime/0012_restore_harness_fks.sql +0 -103
- package/.migrations/runtime/meta/0000_snapshot.json +0 -1181
- package/.migrations/runtime/meta/0001_snapshot.json +0 -1209
- package/.migrations/runtime/meta/0002_snapshot.json +0 -1261
- package/.migrations/runtime/meta/0003_snapshot.json +0 -1292
- package/.migrations/runtime/meta/0004_snapshot.json +0 -1240
- package/.migrations/runtime/meta/0006_snapshot.json +0 -1310
- package/.migrations/runtime/meta/0007_snapshot.json +0 -1362
- package/.migrations/runtime/meta/0008_snapshot.json +0 -1742
- package/.migrations/runtime/meta/0009_snapshot.json +0 -2413
- package/.migrations/runtime/meta/0010_snapshot.json +0 -2562
- package/.migrations/runtime/meta/0011_snapshot.json +0 -2812
- package/.migrations/runtime/meta/0012_snapshot.json +0 -2812
- package/.migrations/runtime/meta/_journal.json +0 -97
- package/RELEASING.md +0 -89
- package/agent/fleet.js +0 -100
- package/bin/cli.js +0 -854
- package/bin/manifold.js +0 -4
- package/boot/flow-revival.js +0 -536
- package/budget/index.js +0 -495
- package/budget/lib.js +0 -59
- package/dashboard/cost.js +0 -528
- package/dashboard/dist/assets/index-CUfp63sj.css +0 -1
- package/dashboard/dist/assets/index-Qy9JMpma.js +0 -371
- package/dashboard/dist/index.html +0 -13
- package/dashboard/event-log.js +0 -267
- package/dashboard/index.html +0 -12
- package/dashboard/package-lock.json +0 -2877
- package/dashboard/package.json +0 -37
- package/dashboard/pipeline-graph.js +0 -131
- package/dashboard/postcss.config.js +0 -6
- package/dashboard/search.js +0 -183
- package/dashboard/server.js +0 -1015
- package/dashboard/src/App.tsx +0 -42
- package/dashboard/src/api/client.ts +0 -118
- package/dashboard/src/api/types.ts +0 -510
- package/dashboard/src/api/ws.tsx +0 -112
- package/dashboard/src/components/CancelButton.tsx +0 -63
- package/dashboard/src/components/ClickToCopy.tsx +0 -68
- package/dashboard/src/components/CopyButton.tsx +0 -61
- package/dashboard/src/components/DailyCostTrend.tsx +0 -85
- package/dashboard/src/components/DailyTimeTrend.tsx +0 -94
- package/dashboard/src/components/Funnel.tsx +0 -149
- package/dashboard/src/components/GateForm.tsx +0 -158
- package/dashboard/src/components/GraphView.tsx +0 -302
- package/dashboard/src/components/GroupPathsSummary.tsx +0 -47
- package/dashboard/src/components/Histogram.tsx +0 -292
- package/dashboard/src/components/Layout.tsx +0 -28
- package/dashboard/src/components/NeedsAttention.tsx +0 -98
- package/dashboard/src/components/NodeContextCard.tsx +0 -132
- package/dashboard/src/components/PathTrail.tsx +0 -35
- package/dashboard/src/components/PipelineCostBreakdown.tsx +0 -277
- package/dashboard/src/components/RerunButton.tsx +0 -46
- package/dashboard/src/components/RunComparison.tsx +0 -53
- package/dashboard/src/components/Sparkline.tsx +0 -94
- package/dashboard/src/components/StatStrip.tsx +0 -147
- package/dashboard/src/components/StateTree.tsx +0 -84
- package/dashboard/src/components/StatusBadge.tsx +0 -18
- package/dashboard/src/components/SubflowPathPills.tsx +0 -38
- package/dashboard/src/components/SubflowSummary.tsx +0 -24
- package/dashboard/src/components/SubflowsCard.tsx +0 -327
- package/dashboard/src/components/TodayStrip.tsx +0 -86
- package/dashboard/src/components/TranscriptPane.tsx +0 -99
- package/dashboard/src/components/TranscriptRow.tsx +0 -69
- package/dashboard/src/components/ui/badge.tsx +0 -38
- package/dashboard/src/components/ui/button.tsx +0 -28
- package/dashboard/src/components/ui/card.tsx +0 -42
- package/dashboard/src/components/ui/skeleton.tsx +0 -9
- package/dashboard/src/components/ui/table.tsx +0 -62
- package/dashboard/src/index.css +0 -26
- package/dashboard/src/lib/anomaly.ts +0 -42
- package/dashboard/src/lib/format.ts +0 -30
- package/dashboard/src/lib/step-history.ts +0 -13
- package/dashboard/src/lib/subflow.ts +0 -154
- package/dashboard/src/lib/use-click-outside.ts +0 -28
- package/dashboard/src/lib/use-ignored-clusters.ts +0 -67
- package/dashboard/src/lib/utils.ts +0 -6
- package/dashboard/src/main.tsx +0 -10
- package/dashboard/src/types/shims.d.ts +0 -4
- package/dashboard/src/views/Home.tsx +0 -478
- package/dashboard/src/views/PipelineDetail.tsx +0 -1185
- package/dashboard/src/views/PipelinesList.tsx +0 -111
- package/dashboard/src/views/RunDetail.tsx +0 -248
- package/dashboard/src/views/Search.tsx +0 -196
- package/dashboard/stats.js +0 -668
- package/dashboard/tailwind.config.ts +0 -43
- package/dashboard/tree-stats.js +0 -12
- package/dashboard/tsconfig.json +0 -25
- package/dashboard/views.js +0 -231
- package/dashboard/vite.config.ts +0 -34
- package/drizzle.config.js +0 -12
- package/drizzle.config.ops.js +0 -12
- package/elevation.js +0 -116
- package/engine/admission-promotion-resume.js +0 -127
- package/engine/agent-dispatch.js +0 -64
- package/engine/child-resume-trigger.js +0 -315
- package/engine/executor-budget.js +0 -87
- package/engine/executor-cancel.js +0 -83
- package/engine/executor-errors.js +0 -122
- package/engine/executor-helpers.js +0 -254
- package/engine/executor-nodes.js +0 -292
- package/engine/executor-persist.js +0 -212
- package/engine/executor-subflow-children.js +0 -275
- package/engine/executor.js +0 -1013
- package/engine/global-concurrency.js +0 -33
- package/engine/loader.js +0 -528
- package/engine/needs-resolver.js +0 -229
- package/engine/pipelines-watcher.js +0 -133
- package/engine/result-replay.js +0 -34
- package/engine/revival-messages.js +0 -11
- package/engine/spawn-child.js +0 -55
- package/engine/wait-for-flow-settlement.js +0 -109
- package/events/catalog.js +0 -26
- package/events/emit.js +0 -44
- package/events/kinds.js +0 -118
- package/events/serve-ws.js +0 -74
- package/events/stream.js +0 -35
- package/events/ws-dialog.js +0 -257
- package/events/ws-frame.js +0 -194
- package/events/ws-run-events.js +0 -70
- package/events.js +0 -32
- package/gates/gate-resolver.js +0 -576
- package/gates/paused-flows.js +0 -55
- package/graphql/columns.js +0 -67
- package/graphql/schema.js +0 -333
- package/index.js +0 -49
- package/mcp/http.js +0 -159
- package/mcp/identity.js +0 -94
- package/mcp/stdio.js +0 -80
- package/mcp/tools.js +0 -245
- package/mcp/wire-ops.js +0 -178
- package/routes/bearer-auth.js +0 -57
- package/routes/discuss-audio.js +0 -87
- package/routes/discuss-component.js +0 -39
- package/routes/discuss-draft.js +0 -159
- package/routes/discuss-helpers.js +0 -20
- package/routes/discuss.js +0 -848
- package/routes/failures.js +0 -104
- package/routes/graphql.js +0 -61
- package/routes/health.js +0 -54
- package/routes/operator-discuss.js +0 -193
- package/routes/operator-resume.js +0 -32
- package/routes/operator-retry.js +0 -301
- package/routes/operator.js +0 -539
- package/routes/pipelines.js +0 -118
- package/routes/runs.js +0 -1129
- package/scripts/ci/import-check.mjs +0 -50
- package/scripts/link-core-self.mjs +0 -31
- package/scripts/with-guard.sh +0 -24
- package/server/app.js +0 -503
- package/server/registry.js +0 -53
- package/server/serve.js +0 -163
- package/state/admission-queue-store.js +0 -325
- package/state/attribution-registries.js +0 -102
- package/state/batch-writer.js +0 -162
- package/state/db-guard.js +0 -63
- package/state/db-health.js +0 -27
- package/state/db.js +0 -122
- package/state/discuss-store.js +0 -299
- package/state/failure-store.js +0 -427
- package/state/migrate.js +0 -104
- package/state/node-cost.js +0 -67
- package/state/node-executions.js +0 -775
- package/state/node-health-store.js +0 -124
- package/state/ops-merge.js +0 -93
- package/state/paths.js +0 -146
- package/state/pipeline-dirs.js +0 -99
- package/state/pipeline-registry.js +0 -449
- package/state/run-store.js +0 -697
- package/state/schema.js +0 -438
- package/state/schema.ops.js +0 -44
- package/state/session-index.js +0 -177
- package/state/session-keys.js +0 -39
- package/state/state-store.js +0 -311
- package/state/subflow-state.js +0 -126
- package/state/tool-handoff.js +0 -169
- package/telemetry/budget-alert.js +0 -353
- package/telemetry/cli.js +0 -331
- package/telemetry/grammar.js +0 -119
- package/telemetry/http-budget.js +0 -132
- package/telemetry/http-cost.js +0 -670
- package/telemetry/http-helpers.js +0 -134
- package/telemetry/http-tree.js +0 -349
- package/telemetry/http.js +0 -44
- package/telemetry/index.js +0 -307
- package/telemetry/ingest.js +0 -134
- package/telemetry/labels.js +0 -115
- package/telemetry/pricer.js +0 -77
- package/telemetry/resolver.js +0 -314
- package/telemetry/store.js +0 -147
- package/utils/run-patch.js +0 -43
package/routes/operator.js
DELETED
|
@@ -1,539 +0,0 @@
|
|
|
1
|
-
import { createRetryFailure } from "./operator-retry.js";
|
|
2
|
-
import { createDiscussHandler } from "./operator-discuss.js";
|
|
3
|
-
import { createStateStore } from "../state/state-store.js";
|
|
4
|
-
import { completeCancellation } from "../engine/executor-cancel.js";
|
|
5
|
-
import { getNodeExecutionsStore } from "../state/node-executions.js";
|
|
6
|
-
import { resumeFlowFromGate } from "./operator-resume.js";
|
|
7
|
-
import { authorizeBearerRequest, sendUnauthorized } from "./bearer-auth.js";
|
|
8
|
-
|
|
9
|
-
// Elevated handlers run with ambient operator scope, so the stamped harness
|
|
10
|
-
// identity in the body is the only per-call check available: refuse unstamped
|
|
11
|
-
// calls here rather than letting them run unauthenticated.
|
|
12
|
-
function elevIdentityMissing(body, fields) {
|
|
13
|
-
return fields.filter((f) => typeof body?.[f] !== "string" || !body[f].trim());
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
function refuseElevIdentity(res, missing) {
|
|
17
|
-
res.statusCode = 400;
|
|
18
|
-
res.setHeader("Content-Type", "application/json");
|
|
19
|
-
res.end(JSON.stringify({ ok: false, code: "missing_identity", error: `${missing.join(", ")} required` }));
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
export function registerOperatorRoutes({
|
|
23
|
-
api,
|
|
24
|
-
store,
|
|
25
|
-
readStore,
|
|
26
|
-
executor,
|
|
27
|
-
gateResolver,
|
|
28
|
-
failureStore,
|
|
29
|
-
pipelinesRef,
|
|
30
|
-
ensurePipelinesLoaded,
|
|
31
|
-
invokeElevated,
|
|
32
|
-
ownerSessionKey,
|
|
33
|
-
runStore,
|
|
34
|
-
admissionQueueStore,
|
|
35
|
-
resumeParentRef,
|
|
36
|
-
// The discuss store owns the pending proposal (discuss_state.pending_json).
|
|
37
|
-
discussStore,
|
|
38
|
-
getBroadcast,
|
|
39
|
-
// Injected gateway adapter, not core state: session reads go through
|
|
40
|
-
// here so core never imports the gateway's session store.
|
|
41
|
-
sessions,
|
|
42
|
-
}) {
|
|
43
|
-
const { retryFailureBranch } = createRetryFailure({
|
|
44
|
-
store, readStore, failureStore, pipelinesRef, executor, runStore, ownerSessionKey,
|
|
45
|
-
admissionQueueStore,
|
|
46
|
-
logger: api.logger,
|
|
47
|
-
api,
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
const { handleDiscuss } = createDiscussHandler({
|
|
51
|
-
api, discussStore, sessions,
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
// ── POST /manifold/gate/resolve ───────────────────────────────────────────
|
|
55
|
-
|
|
56
|
-
api.registerHttpRoute({
|
|
57
|
-
path: "/manifold/gate/resolve",
|
|
58
|
-
auth: "plugin",
|
|
59
|
-
match: "exact",
|
|
60
|
-
handler: async (req, res) => {
|
|
61
|
-
if (req.method !== "POST") {
|
|
62
|
-
res.statusCode = 405; res.setHeader("Allow", "POST"); res.end("method not allowed"); return true;
|
|
63
|
-
}
|
|
64
|
-
const authz = authorizeBearerRequest(req, { logger: api.logger });
|
|
65
|
-
if (!authz.ok) { sendUnauthorized(res, authz.reason); return true; }
|
|
66
|
-
api.logger.info("manifold gate/resolve: bearer ok");
|
|
67
|
-
let raw = "";
|
|
68
|
-
for await (const chunk of req) raw += chunk;
|
|
69
|
-
let body;
|
|
70
|
-
try { body = raw ? JSON.parse(raw) : {}; }
|
|
71
|
-
catch { res.statusCode = 400; res.end("invalid json"); return true; }
|
|
72
|
-
try {
|
|
73
|
-
// recordItemDecision can trigger executor.resume(), which may
|
|
74
|
-
// dispatch a kind:"agent" node (e.g. SETTLE_GAP_ANSWER) — that
|
|
75
|
-
// needs operator.write scope, which this auth:"plugin" route never
|
|
76
|
-
// has ambient. Loop back through invokeElevated to a sibling
|
|
77
|
-
// auth:"gateway" route that does, same pattern as /manifold/start.
|
|
78
|
-
const elev = await invokeElevated("/manifold/_elev/gate-resolve", {
|
|
79
|
-
flowId: body.flowId,
|
|
80
|
-
itemId: body.itemId,
|
|
81
|
-
decision: body.decision,
|
|
82
|
-
source: body.source,
|
|
83
|
-
editedText: body.editedText,
|
|
84
|
-
reason: body.reason,
|
|
85
|
-
session: body.session,
|
|
86
|
-
agentId: body.agentId,
|
|
87
|
-
});
|
|
88
|
-
res.statusCode = elev.status || 500;
|
|
89
|
-
res.setHeader("Content-Type", "application/json");
|
|
90
|
-
res.end(elev.body || JSON.stringify({ ok: false, code: "elevation_no_body" }));
|
|
91
|
-
} catch (err) {
|
|
92
|
-
api.logger.warn(`manifold gate/resolve handler error: ${err?.message ?? err}`);
|
|
93
|
-
res.statusCode = 500;
|
|
94
|
-
res.setHeader("Content-Type", "application/json");
|
|
95
|
-
res.end(JSON.stringify({ ok: false, code: "internal", error: err?.message ?? String(err) }));
|
|
96
|
-
}
|
|
97
|
-
return true;
|
|
98
|
-
},
|
|
99
|
-
});
|
|
100
|
-
|
|
101
|
-
// ── POST /manifold/_elev/gate-resolve ─────────────────────────────────────
|
|
102
|
-
|
|
103
|
-
api.registerHttpRoute({
|
|
104
|
-
path: "/manifold/_elev/gate-resolve",
|
|
105
|
-
auth: "gateway",
|
|
106
|
-
match: "exact",
|
|
107
|
-
handler: async (req, res) => {
|
|
108
|
-
if (req.method !== "POST") {
|
|
109
|
-
res.statusCode = 405; res.setHeader("Allow", "POST"); res.end("method not allowed"); return true;
|
|
110
|
-
}
|
|
111
|
-
let raw = "";
|
|
112
|
-
for await (const chunk of req) raw += chunk;
|
|
113
|
-
let body;
|
|
114
|
-
try { body = raw ? JSON.parse(raw) : {}; }
|
|
115
|
-
catch { res.statusCode = 400; res.end("invalid json"); return true; }
|
|
116
|
-
const missingGateIdentity = elevIdentityMissing(body, ["flowId", "session", "agentId"]);
|
|
117
|
-
if (missingGateIdentity.length > 0) { refuseElevIdentity(res, missingGateIdentity); return true; }
|
|
118
|
-
try {
|
|
119
|
-
const result = await gateResolver.recordItemDecision({
|
|
120
|
-
flowId: body.flowId,
|
|
121
|
-
itemId: body.itemId,
|
|
122
|
-
decision: body.decision,
|
|
123
|
-
source: body.source,
|
|
124
|
-
editedText: body.editedText,
|
|
125
|
-
reason: body.reason,
|
|
126
|
-
});
|
|
127
|
-
const status = result.ok ? 200 : (result.code === "flow_not_found" ? 404 : 409);
|
|
128
|
-
res.statusCode = status;
|
|
129
|
-
res.setHeader("Content-Type", "application/json");
|
|
130
|
-
res.end(JSON.stringify(result));
|
|
131
|
-
} catch (err) {
|
|
132
|
-
api.logger.warn(`manifold gate-resolve (elev) handler error: ${err?.message ?? err}`);
|
|
133
|
-
res.statusCode = 500;
|
|
134
|
-
res.setHeader("Content-Type", "application/json");
|
|
135
|
-
res.end(JSON.stringify({ ok: false, code: "internal", error: err?.message ?? String(err) }));
|
|
136
|
-
}
|
|
137
|
-
return true;
|
|
138
|
-
},
|
|
139
|
-
});
|
|
140
|
-
|
|
141
|
-
// ── POST /manifold/cancel ─────────────────────────────────────────────────
|
|
142
|
-
|
|
143
|
-
api.registerHttpRoute({
|
|
144
|
-
path: "/manifold/cancel",
|
|
145
|
-
auth: "plugin",
|
|
146
|
-
match: "exact",
|
|
147
|
-
handler: async (req, res) => {
|
|
148
|
-
if (req.method !== "POST") {
|
|
149
|
-
res.statusCode = 405; res.setHeader("Allow", "POST"); res.end("method not allowed"); return true;
|
|
150
|
-
}
|
|
151
|
-
const authz = authorizeBearerRequest(req, { logger: api.logger });
|
|
152
|
-
if (!authz.ok) { sendUnauthorized(res, authz.reason); return true; }
|
|
153
|
-
let raw = "";
|
|
154
|
-
for await (const chunk of req) raw += chunk;
|
|
155
|
-
let body;
|
|
156
|
-
try { body = raw ? JSON.parse(raw) : {}; }
|
|
157
|
-
catch { res.statusCode = 400; res.end("invalid json"); return true; }
|
|
158
|
-
const flowId = typeof body.flowId === "string" ? body.flowId.trim() : "";
|
|
159
|
-
const reason = typeof body.reason === "string" && body.reason.trim() ? body.reason.trim() : null;
|
|
160
|
-
if (!flowId) {
|
|
161
|
-
res.statusCode = 400;
|
|
162
|
-
res.setHeader("Content-Type", "application/json");
|
|
163
|
-
res.end(JSON.stringify({ ok: false, error: "flowId required" }));
|
|
164
|
-
return true;
|
|
165
|
-
}
|
|
166
|
-
try {
|
|
167
|
-
let result = await executor.cancel(flowId, reason);
|
|
168
|
-
if (!result?.cancelled && result?.reason === "Flow not found.") {
|
|
169
|
-
const sqlFlow = await readStore?.get(flowId);
|
|
170
|
-
if (sqlFlow && !["succeeded", "failed", "cancelled", "skipped"].includes(sqlFlow.status)) {
|
|
171
|
-
// Use a store bound to the flow's actual ownerKey. Legacy flows were
|
|
172
|
-
// created under "graph-flow-owner"; the default store is bound to
|
|
173
|
-
// "manifold-owner". Mismatched ownerKey → setRunning returns applied=false.
|
|
174
|
-
//
|
|
175
|
-
// Must carry the same dependency set as the primary `store` and
|
|
176
|
-
// index.js's own createCancelStore factory (nodeExecutionsStore,
|
|
177
|
-
// resumeParentRef, pipelinesRef, failureStore, admissionQueueStore):
|
|
178
|
-
// state-store.js's cancel()/finish()/fail() silently no-op
|
|
179
|
-
// triggerAdmissionRelease without admissionQueueStore and
|
|
180
|
-
// triggerParentResume without nodeExecutionsStore/resumeParentRef —
|
|
181
|
-
// a fallback missing either leaks the flow's start/child-dispatch
|
|
182
|
-
// admission slot permanently and leaves a waiting parent on
|
|
183
|
-
// "children-pending" forever.
|
|
184
|
-
const flowOwnerKey = sqlFlow.ownerKey ?? ownerSessionKey;
|
|
185
|
-
const cancelStore =
|
|
186
|
-
flowOwnerKey === ownerSessionKey
|
|
187
|
-
? store
|
|
188
|
-
: createStateStore(api, flowOwnerKey, {
|
|
189
|
-
runStore, nodeExecutionsStore: getNodeExecutionsStore(), resumeParentRef,
|
|
190
|
-
pipelinesRef, failureStore, admissionQueueStore, logger: api.logger,
|
|
191
|
-
});
|
|
192
|
-
// Pre-load into the in-process Map so the runtime's cancel() can find it.
|
|
193
|
-
const setResult = await cancelStore.setRunning({
|
|
194
|
-
flowId,
|
|
195
|
-
expectedRevision: sqlFlow.revision,
|
|
196
|
-
lastStep: sqlFlow.lastStep,
|
|
197
|
-
stateJson: sqlFlow.stateJson ?? {},
|
|
198
|
-
});
|
|
199
|
-
if (setResult.applied) {
|
|
200
|
-
// completeCancellation stamps branches + writes stateJson to DB.
|
|
201
|
-
// Pass revision+1 because setRunning just incremented it.
|
|
202
|
-
result = await completeCancellation({
|
|
203
|
-
store: cancelStore,
|
|
204
|
-
flowId,
|
|
205
|
-
stateJson: sqlFlow.stateJson ?? {},
|
|
206
|
-
lastStep: sqlFlow.lastStep,
|
|
207
|
-
revision: sqlFlow.revision + 1,
|
|
208
|
-
cfg: api.config,
|
|
209
|
-
runStore,
|
|
210
|
-
nodeExecutionsStore: getNodeExecutionsStore(),
|
|
211
|
-
reason,
|
|
212
|
-
});
|
|
213
|
-
}
|
|
214
|
-
}
|
|
215
|
-
}
|
|
216
|
-
if (!result?.cancelled) {
|
|
217
|
-
res.statusCode = 409;
|
|
218
|
-
res.setHeader("Content-Type", "application/json");
|
|
219
|
-
res.end(JSON.stringify({ ok: false, code: "cancel_not_applied", reason: result?.reason ?? "unknown" }));
|
|
220
|
-
return true;
|
|
221
|
-
}
|
|
222
|
-
api.logger.info(`manifold cancel: flow=${flowId.slice(0, 8)} via=${authz.via}`);
|
|
223
|
-
res.statusCode = 200;
|
|
224
|
-
res.setHeader("Content-Type", "application/json");
|
|
225
|
-
res.end(JSON.stringify({ ok: true, cancelled: true }));
|
|
226
|
-
} catch (err) {
|
|
227
|
-
api.logger.warn(`manifold cancel handler error: ${err?.message ?? err}`);
|
|
228
|
-
res.statusCode = 500;
|
|
229
|
-
res.setHeader("Content-Type", "application/json");
|
|
230
|
-
res.end(JSON.stringify({ ok: false, code: "internal", error: err?.message ?? String(err) }));
|
|
231
|
-
}
|
|
232
|
-
return true;
|
|
233
|
-
},
|
|
234
|
-
});
|
|
235
|
-
|
|
236
|
-
// ── POST /manifold/start ──────────────────────────────────────────────────
|
|
237
|
-
|
|
238
|
-
api.registerHttpRoute({
|
|
239
|
-
path: "/manifold/start",
|
|
240
|
-
auth: "plugin",
|
|
241
|
-
match: "exact",
|
|
242
|
-
handler: async (req, res) => {
|
|
243
|
-
if (req.method !== "POST") {
|
|
244
|
-
res.statusCode = 405; res.setHeader("Allow", "POST"); res.end("method not allowed"); return true;
|
|
245
|
-
}
|
|
246
|
-
const authz = authorizeBearerRequest(req, { logger: api.logger });
|
|
247
|
-
if (!authz.ok) { sendUnauthorized(res, authz.reason); return true; }
|
|
248
|
-
let raw = "";
|
|
249
|
-
for await (const chunk of req) raw += chunk;
|
|
250
|
-
let body;
|
|
251
|
-
try { body = raw ? JSON.parse(raw) : {}; }
|
|
252
|
-
catch { res.statusCode = 400; res.end("invalid json"); return true; }
|
|
253
|
-
const pipelineId = typeof body.pipelineId === "string" ? body.pipelineId.trim() : "";
|
|
254
|
-
if (!pipelineId) {
|
|
255
|
-
res.statusCode = 400;
|
|
256
|
-
res.setHeader("Content-Type", "application/json");
|
|
257
|
-
res.end(JSON.stringify({ ok: false, error: "pipelineId required" }));
|
|
258
|
-
return true;
|
|
259
|
-
}
|
|
260
|
-
try {
|
|
261
|
-
await ensurePipelinesLoaded?.();
|
|
262
|
-
if (!pipelinesRef.value.has(pipelineId)) {
|
|
263
|
-
res.statusCode = 404;
|
|
264
|
-
res.setHeader("Content-Type", "application/json");
|
|
265
|
-
res.end(JSON.stringify({ ok: false, error: `unknown pipeline: ${pipelineId}`, known: [...pipelinesRef.value.keys()] }));
|
|
266
|
-
return true;
|
|
267
|
-
}
|
|
268
|
-
const args = (body.args && typeof body.args === "object") ? body.args : {};
|
|
269
|
-
const elev = await invokeElevated("/manifold/_elev/start", {
|
|
270
|
-
pipelineId, args, via: authz.via,
|
|
271
|
-
session: body.session, agentId: body.agentId,
|
|
272
|
-
});
|
|
273
|
-
res.statusCode = elev.status || 500;
|
|
274
|
-
res.setHeader("Content-Type", "application/json");
|
|
275
|
-
res.end(elev.body || JSON.stringify({ ok: false, code: "elevation_no_body" }));
|
|
276
|
-
} catch (err) {
|
|
277
|
-
api.logger.warn(`manifold start handler error: ${err?.message ?? err}`);
|
|
278
|
-
res.statusCode = 500;
|
|
279
|
-
res.setHeader("Content-Type", "application/json");
|
|
280
|
-
res.end(JSON.stringify({ ok: false, code: "internal", error: err?.message ?? String(err) }));
|
|
281
|
-
}
|
|
282
|
-
return true;
|
|
283
|
-
},
|
|
284
|
-
});
|
|
285
|
-
|
|
286
|
-
// ── POST /manifold/_elev/start ────────────────────────────────────────────
|
|
287
|
-
|
|
288
|
-
api.registerHttpRoute({
|
|
289
|
-
path: "/manifold/_elev/start",
|
|
290
|
-
auth: "gateway",
|
|
291
|
-
match: "exact",
|
|
292
|
-
handler: async (req, res) => {
|
|
293
|
-
if (req.method !== "POST") {
|
|
294
|
-
res.statusCode = 405; res.setHeader("Allow", "POST"); res.end("method not allowed"); return true;
|
|
295
|
-
}
|
|
296
|
-
let raw = "";
|
|
297
|
-
for await (const chunk of req) raw += chunk;
|
|
298
|
-
let body;
|
|
299
|
-
try { body = raw ? JSON.parse(raw) : {}; }
|
|
300
|
-
catch { res.statusCode = 400; res.end("invalid json"); return true; }
|
|
301
|
-
const pipelineId = typeof body.pipelineId === "string" ? body.pipelineId.trim() : "";
|
|
302
|
-
const args = (body.args && typeof body.args === "object") ? body.args : {};
|
|
303
|
-
const via = typeof body.via === "string" ? body.via : "elev";
|
|
304
|
-
const parentSessionKey = typeof body.parentSessionKey === "string" && body.parentSessionKey.trim()
|
|
305
|
-
? body.parentSessionKey.trim() : null;
|
|
306
|
-
if (!pipelineId) {
|
|
307
|
-
res.statusCode = 400;
|
|
308
|
-
res.setHeader("Content-Type", "application/json");
|
|
309
|
-
res.end(JSON.stringify({ ok: false, error: "pipelineId required" }));
|
|
310
|
-
return true;
|
|
311
|
-
}
|
|
312
|
-
const missingStartIdentity = elevIdentityMissing(body, ["session", "agentId"]);
|
|
313
|
-
if (missingStartIdentity.length > 0) { refuseElevIdentity(res, missingStartIdentity); return true; }
|
|
314
|
-
try {
|
|
315
|
-
await ensurePipelinesLoaded?.();
|
|
316
|
-
if (!pipelinesRef.value.has(pipelineId)) {
|
|
317
|
-
res.statusCode = 404;
|
|
318
|
-
res.setHeader("Content-Type", "application/json");
|
|
319
|
-
res.end(JSON.stringify({ ok: false, error: `unknown pipeline: ${pipelineId}`, known: [...pipelinesRef.value.keys()] }));
|
|
320
|
-
return true;
|
|
321
|
-
}
|
|
322
|
-
const triggeredBy = {
|
|
323
|
-
kind: via.includes("app") ? "operator_http" : via.includes("cron") ? "cron" : via.includes("cli") ? "cli" : "operator_http",
|
|
324
|
-
label: `via ${via}`,
|
|
325
|
-
ts: Date.now(),
|
|
326
|
-
};
|
|
327
|
-
const record = await executor.start(pipelineId, args, triggeredBy);
|
|
328
|
-
try {
|
|
329
|
-
if (parentSessionKey) {
|
|
330
|
-
await api.runtime?.lineage?.recordTrigger?.({
|
|
331
|
-
flowId: record.flowId,
|
|
332
|
-
runId: record.stateJson?.runId ?? null,
|
|
333
|
-
pipelineId,
|
|
334
|
-
parentSessionKey,
|
|
335
|
-
});
|
|
336
|
-
} else {
|
|
337
|
-
const source = triggeredBy.kind === "cli" ? "cli" : triggeredBy.kind === "operator_http" ? "app" : "operator";
|
|
338
|
-
const synthSession = `agent:operator:${source}:${record.flowId}`;
|
|
339
|
-
await api.runtime?.lineage?.recordTrigger?.({
|
|
340
|
-
flowId: record.flowId,
|
|
341
|
-
runId: record.stateJson?.runId ?? null,
|
|
342
|
-
pipelineId,
|
|
343
|
-
parentSessionKey: synthSession,
|
|
344
|
-
rootKind: "explicit",
|
|
345
|
-
rootLabel: pipelineId,
|
|
346
|
-
});
|
|
347
|
-
}
|
|
348
|
-
} catch (err) {
|
|
349
|
-
api.logger.warn(`manifold start: lineage edge skipped: ${err?.message ?? err}`);
|
|
350
|
-
try {
|
|
351
|
-
const freshForLineage = await store.get(record.flowId);
|
|
352
|
-
if (freshForLineage) {
|
|
353
|
-
await store.setRunning({
|
|
354
|
-
flowId: record.flowId,
|
|
355
|
-
expectedRevision: freshForLineage.revision,
|
|
356
|
-
lastStep: freshForLineage.lastStep,
|
|
357
|
-
stateJson: { ...freshForLineage.stateJson, _lineageError: { ts: Date.now(), message: err?.message ?? String(err) } },
|
|
358
|
-
});
|
|
359
|
-
}
|
|
360
|
-
} catch { /* non-fatal; lineage attribution already lost */ }
|
|
361
|
-
}
|
|
362
|
-
setImmediate(() => {
|
|
363
|
-
executor.runFlow(record.flowId, "fresh").catch((err) => {
|
|
364
|
-
api.logger.warn(`manifold start: runFlow [${record.flowId.slice(0, 8)}] error: ${err?.message ?? err}`);
|
|
365
|
-
});
|
|
366
|
-
});
|
|
367
|
-
if (triggeredBy.kind === "cron") {
|
|
368
|
-
try { getBroadcast?.()?.("cron.job.fired", { flowId: record.flowId, pipelineId, firedAt: Date.now() }); } catch {}
|
|
369
|
-
}
|
|
370
|
-
api.logger.info(`manifold start: pipeline=${pipelineId} flow=${record.flowId.slice(0, 8)} via=${via} (elev)`);
|
|
371
|
-
res.statusCode = 200;
|
|
372
|
-
res.setHeader("Content-Type", "application/json");
|
|
373
|
-
res.end(JSON.stringify({ ok: true, pipelineId, flowId: record.flowId }));
|
|
374
|
-
} catch (err) {
|
|
375
|
-
api.logger.warn(`manifold start (elev) handler error: ${err?.message ?? err}`);
|
|
376
|
-
res.statusCode = 500;
|
|
377
|
-
res.setHeader("Content-Type", "application/json");
|
|
378
|
-
res.end(JSON.stringify({ ok: false, code: "internal", error: err?.message ?? String(err) }));
|
|
379
|
-
}
|
|
380
|
-
return true;
|
|
381
|
-
},
|
|
382
|
-
});
|
|
383
|
-
|
|
384
|
-
// ── POST /manifold/resume-from-gate ──────────────────────────────────────
|
|
385
|
-
|
|
386
|
-
api.registerHttpRoute({
|
|
387
|
-
path: "/manifold/resume-from-gate",
|
|
388
|
-
auth: "gateway",
|
|
389
|
-
match: "exact",
|
|
390
|
-
handler: async (req, res) => {
|
|
391
|
-
if (req.method !== "POST") { res.statusCode = 405; res.setHeader("Allow", "POST"); res.end("method not allowed"); return true; }
|
|
392
|
-
let raw = "";
|
|
393
|
-
for await (const chunk of req) raw += chunk;
|
|
394
|
-
let body;
|
|
395
|
-
try { body = raw ? JSON.parse(raw) : {}; }
|
|
396
|
-
catch { res.statusCode = 400; res.end("invalid json"); return true; }
|
|
397
|
-
const flowId = typeof body.flowId === "string" ? body.flowId : "";
|
|
398
|
-
if (!flowId) {
|
|
399
|
-
res.statusCode = 400; res.setHeader("Content-Type", "application/json");
|
|
400
|
-
res.end(JSON.stringify({ ok: false, error: "flowId required" })); return true;
|
|
401
|
-
}
|
|
402
|
-
// Core resume lives in routes/operator-resume.js (shared with the
|
|
403
|
-
// budget decide route, which calls it in-process); this stays a thin
|
|
404
|
-
// validating wrapper mapping outcomes to status codes.
|
|
405
|
-
const result = await resumeFlowFromGate({
|
|
406
|
-
store, readStore, admissionQueueStore, runStore, executor,
|
|
407
|
-
logger: api.logger, api, flowId, nodeId: body.nodeId, decision: body.decision,
|
|
408
|
-
});
|
|
409
|
-
if (!result.ok && result.code === "flow_not_found") {
|
|
410
|
-
res.statusCode = 404; res.setHeader("Content-Type", "application/json");
|
|
411
|
-
res.end(JSON.stringify({ ok: false, error: "flow not found" })); return true;
|
|
412
|
-
}
|
|
413
|
-
if (!result.ok) {
|
|
414
|
-
res.statusCode = 409; res.setHeader("Content-Type", "application/json");
|
|
415
|
-
res.end(JSON.stringify({ ok: false, error: result.code })); return true;
|
|
416
|
-
}
|
|
417
|
-
if (!result.queued) {
|
|
418
|
-
setImmediate(() => {
|
|
419
|
-
executor.resume(flowId).catch((err) => {
|
|
420
|
-
api.logger.warn(`manifold resume-from-gate: runFlow [${flowId.slice(0, 8)}] error: ${err?.message ?? err}`);
|
|
421
|
-
});
|
|
422
|
-
});
|
|
423
|
-
}
|
|
424
|
-
api.logger.info(`manifold: resume-from-gate flow=${flowId.slice(0, 8)} node=${body.nodeId ?? "?"} decision=${body.decision ?? "?"}${result.queued ? " (queued for admission)" : ""}`);
|
|
425
|
-
res.statusCode = 200; res.setHeader("Content-Type", "application/json");
|
|
426
|
-
res.end(JSON.stringify({ ok: true, flowId, queued: result.queued })); return true;
|
|
427
|
-
},
|
|
428
|
-
});
|
|
429
|
-
|
|
430
|
-
// ── POST /manifold/_elev/rerun ────────────────────────────────────────────
|
|
431
|
-
|
|
432
|
-
api.registerHttpRoute({
|
|
433
|
-
path: "/manifold/_elev/rerun",
|
|
434
|
-
auth: "gateway",
|
|
435
|
-
match: "exact",
|
|
436
|
-
handler: async (req, res) => {
|
|
437
|
-
if (req.method !== "POST") {
|
|
438
|
-
res.statusCode = 405; res.setHeader("Allow", "POST"); res.end("method not allowed"); return true;
|
|
439
|
-
}
|
|
440
|
-
let raw = "";
|
|
441
|
-
for await (const chunk of req) raw += chunk;
|
|
442
|
-
let body;
|
|
443
|
-
try { body = raw ? JSON.parse(raw) : {}; }
|
|
444
|
-
catch { res.statusCode = 400; res.end("invalid json"); return true; }
|
|
445
|
-
const sourceFlowId = typeof body.sourceFlowId === "string" ? body.sourceFlowId.trim() : "";
|
|
446
|
-
if (!sourceFlowId) {
|
|
447
|
-
res.statusCode = 400; res.setHeader("Content-Type", "application/json");
|
|
448
|
-
res.end(JSON.stringify({ ok: false, error: "sourceFlowId required" })); return true;
|
|
449
|
-
}
|
|
450
|
-
const argsOverride = (body && "args" in body) ? body.args : undefined;
|
|
451
|
-
if (argsOverride !== undefined && (argsOverride === null || typeof argsOverride !== "object" || Array.isArray(argsOverride))) {
|
|
452
|
-
res.statusCode = 400; res.setHeader("Content-Type", "application/json");
|
|
453
|
-
res.end(JSON.stringify({ ok: false, error: "args must be a JSON object" })); return true;
|
|
454
|
-
}
|
|
455
|
-
const missingRerunIdentity = elevIdentityMissing(body, ["session", "agentId"]);
|
|
456
|
-
if (missingRerunIdentity.length > 0) { refuseElevIdentity(res, missingRerunIdentity); return true; }
|
|
457
|
-
const sourceFlow = await readStore.get(sourceFlowId);
|
|
458
|
-
if (!sourceFlow) {
|
|
459
|
-
res.statusCode = 404; res.setHeader("Content-Type", "application/json");
|
|
460
|
-
res.end(JSON.stringify({ ok: false, error: `source flow not found: ${sourceFlowId}` })); return true;
|
|
461
|
-
}
|
|
462
|
-
let record;
|
|
463
|
-
try {
|
|
464
|
-
record = executor.rerunFromSource(sourceFlow, argsOverride);
|
|
465
|
-
} catch (err) {
|
|
466
|
-
const msg = err?.message ?? String(err);
|
|
467
|
-
if (msg.includes("active flow")) { res.statusCode = 409; res.setHeader("Content-Type", "application/json"); res.end(JSON.stringify({ ok: false, error: msg })); return true; }
|
|
468
|
-
if (msg.includes("not found")) { res.statusCode = 404; res.setHeader("Content-Type", "application/json"); res.end(JSON.stringify({ ok: false, error: msg })); return true; }
|
|
469
|
-
api.logger.warn(`manifold rerun (elev) handler error: ${msg}`);
|
|
470
|
-
res.statusCode = 500; res.setHeader("Content-Type", "application/json");
|
|
471
|
-
res.end(JSON.stringify({ ok: false, code: "internal", error: msg })); return true;
|
|
472
|
-
}
|
|
473
|
-
setImmediate(() => {
|
|
474
|
-
executor.runFlow(record.flowId, "fresh").catch((err) => {
|
|
475
|
-
api.logger.warn(`manifold rerun (elev): runFlow [${record.flowId.slice(0, 8)}] error: ${err?.message ?? err}`);
|
|
476
|
-
});
|
|
477
|
-
});
|
|
478
|
-
api.logger.info(`manifold rerun (elev): source=${sourceFlow.flowId.slice(0, 8)} → new=${record.flowId.slice(0, 8)} pipeline=${record.stateJson?.pipelineId ?? "?"}`);
|
|
479
|
-
res.statusCode = 200; res.setHeader("Content-Type", "application/json");
|
|
480
|
-
res.end(JSON.stringify({ ok: true, flowId: record.flowId, pipelineId: record.stateJson?.pipelineId ?? null, rerunOf: sourceFlow.flowId }));
|
|
481
|
-
return true;
|
|
482
|
-
},
|
|
483
|
-
});
|
|
484
|
-
|
|
485
|
-
// ── POST /manifold/_elev/retry-failure ────────────────────────────────────
|
|
486
|
-
|
|
487
|
-
api.registerHttpRoute({
|
|
488
|
-
path: "/manifold/_elev/retry-failure",
|
|
489
|
-
auth: "gateway",
|
|
490
|
-
match: "exact",
|
|
491
|
-
handler: async (req, res) => {
|
|
492
|
-
if (req.method !== "POST") {
|
|
493
|
-
res.statusCode = 405; res.setHeader("Allow", "POST"); res.end("method not allowed"); return true;
|
|
494
|
-
}
|
|
495
|
-
let raw = "";
|
|
496
|
-
for await (const chunk of req) raw += chunk;
|
|
497
|
-
let body;
|
|
498
|
-
try { body = raw ? JSON.parse(raw) : {}; }
|
|
499
|
-
catch { res.statusCode = 400; res.end("invalid json"); return true; }
|
|
500
|
-
const id = typeof body.id === "string" ? body.id.trim() : "";
|
|
501
|
-
if (!id) {
|
|
502
|
-
res.statusCode = 400; res.setHeader("Content-Type", "application/json");
|
|
503
|
-
res.end(JSON.stringify({ ok: false, error: "id required" })); return true;
|
|
504
|
-
}
|
|
505
|
-
const missingRetryIdentity = elevIdentityMissing(body, ["session", "agentId"]);
|
|
506
|
-
if (missingRetryIdentity.length > 0) { refuseElevIdentity(res, missingRetryIdentity); return true; }
|
|
507
|
-
const via = typeof body.via === "string" ? body.via : "elev";
|
|
508
|
-
const result = await retryFailureBranch({ id, via });
|
|
509
|
-
res.statusCode = result.code === "ok" ? 200 : result.code === "not_found" ? 404 : result.code === "conflict" ? 409 : 500;
|
|
510
|
-
res.setHeader("Content-Type", "application/json");
|
|
511
|
-
res.end(JSON.stringify(result));
|
|
512
|
-
return true;
|
|
513
|
-
},
|
|
514
|
-
});
|
|
515
|
-
|
|
516
|
-
// ── POST /manifold/_elev/discuss ──────────────────────────────────────────
|
|
517
|
-
|
|
518
|
-
api.registerHttpRoute({
|
|
519
|
-
path: "/manifold/_elev/discuss",
|
|
520
|
-
auth: "gateway",
|
|
521
|
-
match: "exact",
|
|
522
|
-
handler: async (req, res) => {
|
|
523
|
-
if (req.method !== "POST") {
|
|
524
|
-
res.statusCode = 405; res.setHeader("Allow", "POST"); res.end("method not allowed"); return true;
|
|
525
|
-
}
|
|
526
|
-
let raw = "";
|
|
527
|
-
for await (const chunk of req) raw += chunk;
|
|
528
|
-
let body;
|
|
529
|
-
try { body = raw ? JSON.parse(raw) : {}; }
|
|
530
|
-
catch { res.statusCode = 400; res.end("invalid json"); return true; }
|
|
531
|
-
const { status, body: responseBody } = await handleDiscuss(body);
|
|
532
|
-
res.statusCode = status;
|
|
533
|
-
res.setHeader("Content-Type", "application/json");
|
|
534
|
-
res.end(JSON.stringify(responseBody));
|
|
535
|
-
return true;
|
|
536
|
-
},
|
|
537
|
-
});
|
|
538
|
-
|
|
539
|
-
}
|
package/routes/pipelines.js
DELETED
|
@@ -1,118 +0,0 @@
|
|
|
1
|
-
import { authorizeBearerRequest, sendUnauthorized } from "./bearer-auth.js";
|
|
2
|
-
|
|
3
|
-
export function registerPipelineRoutes({ api, pipelinesRef, readStore, ensurePipelinesLoaded }) {
|
|
4
|
-
// GET /manifold/pipelines — catalog of pipeline definitions joined with
|
|
5
|
-
// run-history vitals. Mirrors the dashboard's /api/pipelines but trimmed
|
|
6
|
-
// to what a pipelines list view needs at a glance (lastRunAt,
|
|
7
|
-
// todayCount, succeeded/failed today, success-rate over a recent window).
|
|
8
|
-
// No cost (slow JSONL walking lives in the per-pipeline detail route).
|
|
9
|
-
// Historical pipelines (no def on disk but runs in db) are appended last.
|
|
10
|
-
api.registerHttpRoute({
|
|
11
|
-
path: "/manifold/pipelines",
|
|
12
|
-
auth: "plugin",
|
|
13
|
-
match: "exact",
|
|
14
|
-
handler: async (req, res) => {
|
|
15
|
-
if (req.method !== "GET") {
|
|
16
|
-
res.statusCode = 405;
|
|
17
|
-
res.setHeader("Allow", "GET");
|
|
18
|
-
res.end("method not allowed");
|
|
19
|
-
return true;
|
|
20
|
-
}
|
|
21
|
-
const authz = authorizeBearerRequest(req, { logger: api.logger });
|
|
22
|
-
if (!authz.ok) { sendUnauthorized(res, authz.reason); return true; }
|
|
23
|
-
|
|
24
|
-
try {
|
|
25
|
-
await ensurePipelinesLoaded?.();
|
|
26
|
-
const nowMs = Date.now();
|
|
27
|
-
// Caller-supplied "today" boundary so clients can bucket by
|
|
28
|
-
// their local-day midnight (the operator thinks in their own TZ).
|
|
29
|
-
// Falls back to UTC midnight to keep behaviour identical for
|
|
30
|
-
// any caller that doesn't send it (parity with the dashboard).
|
|
31
|
-
const url = new URL(req.url, `http://${req.headers.host || "localhost"}`);
|
|
32
|
-
const todayParam = url.searchParams.get("todayStartMs");
|
|
33
|
-
const parsedToday = todayParam ? Number(todayParam) : null;
|
|
34
|
-
const todayStartMs = Number.isFinite(parsedToday) && parsedToday > 0
|
|
35
|
-
? parsedToday
|
|
36
|
-
: (() => { const d = new Date(nowMs); return new Date(d.getFullYear(), d.getMonth(), d.getDate()).getTime(); })();
|
|
37
|
-
const sevenDaysMs = nowMs - 7 * 86_400_000;
|
|
38
|
-
|
|
39
|
-
// SQL GROUP BY + window function replace the JS aggregation loop —
|
|
40
|
-
// two queries instead of iterating 7K rows in JS.
|
|
41
|
-
const agg = await readStore.listAllPipelineStats({ todayStartMs, sevenDaysMs });
|
|
42
|
-
|
|
43
|
-
// _synthetic: true — a subflow node's .flow registered as its own
|
|
44
|
-
// addressable pipeline (`${pipelineId}::${nodeId}`) so childFlows
|
|
45
|
-
// can start a real child flow_run against it (see engine/loader.js).
|
|
46
|
-
// Purely an internal dispatch target, never a pipeline an operator
|
|
47
|
-
// runs or sees on its own — must not appear in the catalog.
|
|
48
|
-
const implemented = [...pipelinesRef.value.values()].filter((p) => !p._synthetic).map((p) => {
|
|
49
|
-
const a = agg.get(p.id) ?? null;
|
|
50
|
-
const nodeCount = Object.keys(p.nodes ?? {}).length;
|
|
51
|
-
return {
|
|
52
|
-
id: p.id,
|
|
53
|
-
goal: p.goal ?? null,
|
|
54
|
-
file: p._filepath ? p._filepath.replace(/^.*\//, "") : null,
|
|
55
|
-
nodeCount,
|
|
56
|
-
historical: false,
|
|
57
|
-
cronJobId: typeof p.cronJobId === "string" ? p.cronJobId : null,
|
|
58
|
-
lastRunAtMs: a?.lastRunAtMs ?? null,
|
|
59
|
-
lastRunStatus: a?.lastRunStatus ?? null,
|
|
60
|
-
todayTotal: a?.todayTotal ?? 0,
|
|
61
|
-
todaySucceeded: a?.todaySucceeded ?? 0,
|
|
62
|
-
todayFailed: a?.todayFailed ?? 0,
|
|
63
|
-
todayActive: a?.todayActive ?? 0,
|
|
64
|
-
last7dTotal: a?.last7dTotal ?? 0,
|
|
65
|
-
last7dSucceeded: a?.last7dSucceeded ?? 0,
|
|
66
|
-
last7dFailed: a?.last7dFailed ?? 0,
|
|
67
|
-
totalRuns: a?.totalRuns ?? 0,
|
|
68
|
-
};
|
|
69
|
-
});
|
|
70
|
-
const implementedIds = new Set(implemented.map((p) => p.id));
|
|
71
|
-
const historical = [];
|
|
72
|
-
for (const [pid, a] of agg.entries()) {
|
|
73
|
-
if (implementedIds.has(pid)) continue;
|
|
74
|
-
historical.push({
|
|
75
|
-
id: pid,
|
|
76
|
-
goal: null,
|
|
77
|
-
file: null,
|
|
78
|
-
nodeCount: 0,
|
|
79
|
-
historical: true,
|
|
80
|
-
cronJobId: null,
|
|
81
|
-
lastRunAtMs: a.lastRunAtMs,
|
|
82
|
-
lastRunStatus: a.lastRunStatus,
|
|
83
|
-
todayTotal: a.todayTotal,
|
|
84
|
-
todaySucceeded: a.todaySucceeded,
|
|
85
|
-
todayFailed: a.todayFailed,
|
|
86
|
-
todayActive: a.todayActive,
|
|
87
|
-
last7dTotal: a.last7dTotal,
|
|
88
|
-
last7dSucceeded: a.last7dSucceeded,
|
|
89
|
-
last7dFailed: a.last7dFailed,
|
|
90
|
-
totalRuns: a.totalRuns,
|
|
91
|
-
});
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
// Sort by recent activity: implemented-with-runs first (by
|
|
95
|
-
// lastRunAt desc), then implemented-no-runs (alpha), then
|
|
96
|
-
// historical last (lastRunAt desc).
|
|
97
|
-
const sortKey = (p) => p.lastRunAtMs ?? 0;
|
|
98
|
-
const live = implemented.filter((p) => p.lastRunAtMs).sort((a, b) => sortKey(b) - sortKey(a));
|
|
99
|
-
const idle = implemented.filter((p) => !p.lastRunAtMs).sort((a, b) => a.id.localeCompare(b.id));
|
|
100
|
-
historical.sort((a, b) => sortKey(b) - sortKey(a));
|
|
101
|
-
|
|
102
|
-
res.statusCode = 200;
|
|
103
|
-
res.setHeader("Content-Type", "application/json");
|
|
104
|
-
res.end(JSON.stringify({
|
|
105
|
-
pipelines: [...live, ...idle, ...historical],
|
|
106
|
-
todayStartMs,
|
|
107
|
-
generatedAtMs: nowMs,
|
|
108
|
-
}));
|
|
109
|
-
} catch (err) {
|
|
110
|
-
api.logger.warn(`manifold pipelines handler error: ${err?.message ?? err}`);
|
|
111
|
-
res.statusCode = 500;
|
|
112
|
-
res.setHeader("Content-Type", "application/json");
|
|
113
|
-
res.end(JSON.stringify({ ok: false, code: "internal", error: err?.message ?? String(err) }));
|
|
114
|
-
}
|
|
115
|
-
return true;
|
|
116
|
-
},
|
|
117
|
-
});
|
|
118
|
-
}
|