@sema-agent/server 1.315.0 → 1.317.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 +9 -0
- package/README.zh-CN.md +7 -0
- package/dist/config-types.d.ts +1 -1
- package/dist/config.d.ts +14 -0
- package/dist/config.js +148 -45
- package/dist/elicitation.js +2 -2
- package/dist/http/idempotency.d.ts +1 -0
- package/dist/http/idempotency.js +3 -0
- package/dist/http/principal-gate.d.ts +12 -0
- package/dist/http/principal-gate.js +52 -0
- package/dist/http/route-ctx.d.ts +116 -0
- package/dist/http/route-ctx.js +2 -0
- package/dist/http/routes/approvals-assistant.d.ts +11 -0
- package/dist/http/routes/approvals-assistant.js +530 -0
- package/dist/http/routes/attachments.d.ts +4 -0
- package/dist/http/routes/attachments.js +106 -0
- package/dist/http/routes/capabilities.d.ts +4 -0
- package/dist/http/routes/capabilities.js +111 -0
- package/dist/http/routes/fleet.d.ts +4 -0
- package/dist/http/routes/fleet.js +147 -0
- package/dist/http/routes/images.d.ts +20 -0
- package/dist/http/routes/images.js +572 -0
- package/dist/http/routes/leader.d.ts +4 -0
- package/dist/http/routes/leader.js +48 -0
- package/dist/http/routes/memory-policy.d.ts +4 -0
- package/dist/http/routes/memory-policy.js +105 -0
- package/dist/http/routes/notify-wake.d.ts +4 -0
- package/dist/http/routes/notify-wake.js +133 -0
- package/dist/http/routes/observability.d.ts +4 -0
- package/dist/http/routes/observability.js +63 -0
- package/dist/http/routes/runs.d.ts +19 -0
- package/dist/http/routes/runs.js +967 -0
- package/dist/http/routes/session-sync.d.ts +36 -0
- package/dist/http/routes/session-sync.js +513 -0
- package/dist/http/routes/sessions-list.d.ts +4 -0
- package/dist/http/routes/sessions-list.js +117 -0
- package/dist/http/routes/sessions.d.ts +17 -0
- package/dist/http/routes/sessions.js +746 -0
- package/dist/http/routes/side-query.d.ts +4 -0
- package/dist/http/routes/side-query.js +88 -0
- package/dist/http/routes/tasks.d.ts +4 -0
- package/dist/http/routes/tasks.js +632 -0
- package/dist/http/routes/trace-usage.d.ts +4 -0
- package/dist/http/routes/trace-usage.js +239 -0
- package/dist/http/routes/workflows.d.ts +5 -0
- package/dist/http/routes/workflows.js +337 -0
- package/dist/http/run-meta.d.ts +11 -0
- package/dist/http/run-meta.js +16 -0
- package/dist/http/send.d.ts +7 -0
- package/dist/http/send.js +34 -0
- package/dist/http/server.d.ts +12 -12
- package/dist/http/server.js +289 -5502
- package/dist/http/sse-log.d.ts +25 -0
- package/dist/http/sse-log.js +59 -0
- package/dist/http/wire-types.d.ts +6 -0
- package/dist/http/workspace-content.d.ts +3 -0
- package/dist/http/workspace-content.js +20 -0
- package/dist/leader/endpoint.js +4 -4
- package/dist/main.js +5 -5
- package/dist/plugins/approval-store-sql.d.ts +52 -0
- package/dist/plugins/approval-store-sql.js +119 -0
- package/dist/plugins/breaker-state-sql.d.ts +29 -0
- package/dist/plugins/breaker-state-sql.js +104 -0
- package/dist/plugins/file-snapshot-store-sql.d.ts +38 -0
- package/dist/plugins/file-snapshot-store-sql.js +210 -0
- package/dist/plugins/image-index-sql.d.ts +33 -0
- package/dist/plugins/image-index-sql.js +328 -0
- package/dist/plugins/outcome-ledger-sql.d.ts +70 -0
- package/dist/plugins/outcome-ledger-sql.js +158 -0
- package/dist/plugins/pg-approval-store.d.ts +1 -27
- package/dist/plugins/pg-approval-store.js +1 -83
- package/dist/plugins/pg-breaker-state.d.ts +1 -19
- package/dist/plugins/pg-breaker-state.js +1 -88
- package/dist/plugins/pg-file-snapshot-store.d.ts +1 -27
- package/dist/plugins/pg-file-snapshot-store.js +1 -190
- package/dist/plugins/pg-image-index.d.ts +1 -21
- package/dist/plugins/pg-image-index.js +1 -217
- package/dist/plugins/pg-outcome-ledger.d.ts +2 -22
- package/dist/plugins/pg-outcome-ledger.js +1 -104
- package/dist/plugins/pg-resume-anchor-store.d.ts +1 -13
- package/dist/plugins/pg-resume-anchor-store.js +1 -22
- package/dist/plugins/pg-run-store.d.ts +1 -75
- package/dist/plugins/pg-run-store.js +1 -287
- package/dist/plugins/pg-session-policy-store.d.ts +1 -11
- package/dist/plugins/pg-session-policy-store.js +1 -90
- package/dist/plugins/pg-tool-result-store.d.ts +1 -15
- package/dist/plugins/pg-tool-result-store.js +1 -52
- package/dist/plugins/pg-workflow-journal-store.d.ts +1 -20
- package/dist/plugins/pg-workflow-journal-store.js +1 -34
- package/dist/plugins/pg-workflow-run-store.d.ts +1 -55
- package/dist/plugins/pg-workflow-run-store.js +1 -220
- package/dist/plugins/remote-env-host.js +4 -3
- package/dist/plugins/resume-anchor-store-sql.d.ts +23 -0
- package/dist/plugins/resume-anchor-store-sql.js +38 -0
- package/dist/plugins/run-store-sql.d.ts +89 -0
- package/dist/plugins/run-store-sql.js +397 -0
- package/dist/plugins/session-policy-store-sql.d.ts +22 -0
- package/dist/plugins/session-policy-store-sql.js +109 -0
- package/dist/plugins/tidb-approval-store.d.ts +1 -39
- package/dist/plugins/tidb-approval-store.js +1 -71
- package/dist/plugins/tidb-breaker-state.d.ts +1 -17
- package/dist/plugins/tidb-breaker-state.js +1 -74
- package/dist/plugins/tidb-file-snapshot-store.d.ts +1 -27
- package/dist/plugins/tidb-file-snapshot-store.js +1 -192
- package/dist/plugins/tidb-image-index.d.ts +1 -19
- package/dist/plugins/tidb-image-index.js +1 -149
- package/dist/plugins/tidb-outcome-ledger.d.ts +1 -57
- package/dist/plugins/tidb-outcome-ledger.js +1 -97
- package/dist/plugins/tidb-resume-anchor-store.d.ts +1 -13
- package/dist/plugins/tidb-resume-anchor-store.js +1 -22
- package/dist/plugins/tidb-run-store.d.ts +1 -75
- package/dist/plugins/tidb-run-store.js +1 -306
- package/dist/plugins/tidb-session-policy-store.d.ts +1 -11
- package/dist/plugins/tidb-session-policy-store.js +1 -86
- package/dist/plugins/tidb-tool-result-store.d.ts +1 -13
- package/dist/plugins/tidb-tool-result-store.js +1 -38
- package/dist/plugins/tidb-workflow-journal-store.d.ts +1 -20
- package/dist/plugins/tidb-workflow-journal-store.js +1 -34
- package/dist/plugins/tidb-workflow-run-store.d.ts +1 -61
- package/dist/plugins/tidb-workflow-run-store.js +1 -231
- package/dist/plugins/tool-result-store-sql.d.ts +25 -0
- package/dist/plugins/tool-result-store-sql.js +69 -0
- package/dist/plugins/workflow-journal-store-sql.d.ts +30 -0
- package/dist/plugins/workflow-journal-store-sql.js +53 -0
- package/dist/plugins/workflow-run-store-sql.d.ts +85 -0
- package/dist/plugins/workflow-run-store-sql.js +299 -0
- package/dist/question.js +2 -2
- package/dist/run-local.js +1 -1
- package/dist/tool-approval.js +2 -2
- package/dist/trace/ledger-sink.js +1 -1
- package/dist/trace/project.d.ts +1 -0
- package/dist/trace/project.js +3 -0
- package/package.json +1 -1
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import { DEFAULT_EFFORT_LEVELS } from "@sema-agent/core";
|
|
2
|
+
import { cwdHonored } from "../../task-cwd.js";
|
|
3
|
+
import { mcpInjectionHonored } from "../../task-mcp.js";
|
|
4
|
+
import { sendJson, sendError } from "../send.js";
|
|
5
|
+
export async function handleCapabilities(req, res, url, ctx) {
|
|
6
|
+
const miss = { fell: false };
|
|
7
|
+
await handleCapabilitiesBody(req, res, url, ctx, miss);
|
|
8
|
+
return !miss.fell;
|
|
9
|
+
}
|
|
10
|
+
async function handleCapabilitiesBody(req, res, url, ctx, miss) {
|
|
11
|
+
const { deps } = ctx;
|
|
12
|
+
if (req.method === "GET" && url.startsWith("/v1/capabilities/scenarios/")) {
|
|
13
|
+
const name = url.slice("/v1/capabilities/scenarios/".length).split("?")[0];
|
|
14
|
+
const detail = deps.scenarioDetails?.[name];
|
|
15
|
+
if (!detail) {
|
|
16
|
+
sendError(res, 404, "scenario_not_found", "scenario not found");
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
sendJson(res, 200, detail);
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
if (req.method === "GET" && url === "/v1/capabilities") {
|
|
23
|
+
sendJson(res, 200, {
|
|
24
|
+
...deps.capabilities,
|
|
25
|
+
asyncRuns: Boolean(deps.runStore),
|
|
26
|
+
artifacts: Boolean(deps.runStore),
|
|
27
|
+
approvals: Boolean(deps.checkpointStore),
|
|
28
|
+
sessions: Boolean(deps.sessionAudit),
|
|
29
|
+
sessionEvents: Boolean(deps.sessionWatch && deps.sessionStorage?.getLeafId && deps.sessionStorage?.ownerOf),
|
|
30
|
+
fleet: deps.fleetBus
|
|
31
|
+
? { stream: true, sessionScope: true, observe: true, resume: "snapshot", bgNotifyFailClosed: true, steerPriority: "advisory" }
|
|
32
|
+
: false,
|
|
33
|
+
workspace: (() => {
|
|
34
|
+
const wfs = deps.fileSnapshotStore;
|
|
35
|
+
return wfs && typeof wfs.listKeys === "function" && typeof wfs.exportManifest === "function" && typeof wfs.getBlob === "function" && Boolean(deps.sessionStorage?.ownerOf)
|
|
36
|
+
? { browse: true, archive: true, maxFileBytes: deps.config.workspaceFileMaxBytes ?? 8 * 1024 * 1024 }
|
|
37
|
+
: false;
|
|
38
|
+
})(),
|
|
39
|
+
leader: Boolean(deps.leaderEndpoint),
|
|
40
|
+
memory: false,
|
|
41
|
+
memoryWrite: false,
|
|
42
|
+
policy: true,
|
|
43
|
+
usage: Boolean(deps.costQuota),
|
|
44
|
+
permissionModeWrite: false,
|
|
45
|
+
modelSelection: true,
|
|
46
|
+
effortSelection: true,
|
|
47
|
+
toolOutput: true,
|
|
48
|
+
messageIdentity: true,
|
|
49
|
+
forwardSubagentEvents: true,
|
|
50
|
+
scratchpadDir: true,
|
|
51
|
+
subagentSteer: Boolean(deps.subagentSteerRegistry) && Boolean(deps.runStore),
|
|
52
|
+
subagentResume: Boolean(deps.subagentSteerRegistry) && Boolean(deps.runStore),
|
|
53
|
+
taskSettings: { permissions: true, permissionMode: true, model: true, outputStyle: true, env: false, hooks: deps.config.requirePrincipal !== true },
|
|
54
|
+
appendSystemPrompt: true,
|
|
55
|
+
compactionModel: true,
|
|
56
|
+
subagentOutput: Boolean(deps.subagentTaskOutput) && Boolean(deps.runStore),
|
|
57
|
+
subagentStream: Boolean(deps.subagentTaskOutput) && Boolean(deps.runStore),
|
|
58
|
+
taskHandles: Boolean(deps.taskHandleOutput) && Boolean(deps.taskHandleStop) && Boolean(deps.runStore),
|
|
59
|
+
taskAgents: deps.config.requirePrincipal !== true,
|
|
60
|
+
retainBackgroundProcesses: deps.config.requirePrincipal !== true,
|
|
61
|
+
interactiveTools: true,
|
|
62
|
+
projectContext: cwdHonored(deps.config),
|
|
63
|
+
mcpInjection: mcpInjectionHonored(deps.config),
|
|
64
|
+
modelUsage: Boolean(deps.runStore && deps.modelUsage),
|
|
65
|
+
sessionInit: true,
|
|
66
|
+
mcp: true,
|
|
67
|
+
mcpElicitation: Boolean(deps.elicitation),
|
|
68
|
+
askUserQuestion: Boolean(deps.question),
|
|
69
|
+
toolApproval: Boolean(deps.toolApproval),
|
|
70
|
+
sideQuery: true,
|
|
71
|
+
sessionList: Boolean(deps.sessionStorage?.listSessions ?? deps.runStore?.listSessions),
|
|
72
|
+
sessionSearch: Boolean(deps.sessionStorage?.listSessions ?? deps.runStore?.listSessions),
|
|
73
|
+
sessionFork: Boolean(deps.sessionStorage?.fork),
|
|
74
|
+
sessionDelete: Boolean(deps.purgeSession),
|
|
75
|
+
resumeAt: Boolean(deps.resumeAnchorStore && deps.sessionStorage?.getLeafId),
|
|
76
|
+
promptSuggestions: true,
|
|
77
|
+
sessionPolicy: Boolean(deps.sessionPolicyStore),
|
|
78
|
+
rewindFiles: Boolean(deps.fileSnapshotStore),
|
|
79
|
+
rewindFilesTo: Boolean(deps.fileSnapshotStore && deps.resumeAnchorStore && deps.sessionStorage?.getLeafId),
|
|
80
|
+
scheduler: Boolean(deps.config.schedulerEnabled && deps.config.requirePrincipal !== true && deps.config.remoteExec?.provider === "host"),
|
|
81
|
+
sessionSync: Boolean(deps.backend && deps.sessionStorage?.exportEntries && deps.fileSnapshotStore),
|
|
82
|
+
sendUserFile: Boolean(deps.sendUserFile && deps.config.sendUserFile?.publicEndpoint),
|
|
83
|
+
s3PublicEndpoint: deps.config.sendUserFile?.publicEndpoint ?? null,
|
|
84
|
+
sendUserFileLedger: Boolean(deps.sendFileLedger),
|
|
85
|
+
workflows: deps.workflowsCapable ?? Boolean(deps.workflowRunStore),
|
|
86
|
+
workflowsList: Boolean(deps.workflowRunStore),
|
|
87
|
+
manualCompact: Boolean(deps.runStore),
|
|
88
|
+
});
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
if (req.method === "GET" && url === "/v1/models") {
|
|
92
|
+
const models = Object.entries(deps.config.models)
|
|
93
|
+
.filter(([name]) => name !== "default")
|
|
94
|
+
.map(([name, m]) => ({
|
|
95
|
+
name,
|
|
96
|
+
id: m.id,
|
|
97
|
+
provider: m.provider,
|
|
98
|
+
reasoning: m.reasoning,
|
|
99
|
+
vision: Array.isArray(m.input) ? m.input.includes("image") : false,
|
|
100
|
+
...(m.contextWindow ? { contextWindow: m.contextWindow } : {}),
|
|
101
|
+
...(m.maxTokens ? { maxOutputTokens: m.maxTokens } : {}),
|
|
102
|
+
...(m.reasoning ? { supportedEffortLevels: [...DEFAULT_EFFORT_LEVELS] } : {}),
|
|
103
|
+
}));
|
|
104
|
+
const nonAlias = Object.entries(deps.config.models).filter(([n]) => n !== "default");
|
|
105
|
+
const defaultName = (nonAlias.find(([, m]) => m === deps.config.model) ?? nonAlias.find(([, m]) => m.id === deps.config.model.id))?.[0];
|
|
106
|
+
sendJson(res, 200, { models, default: deps.config.model.id, defaultModel: { id: deps.config.model.id, ...(defaultName ? { name: defaultName } : {}) } });
|
|
107
|
+
return;
|
|
108
|
+
}
|
|
109
|
+
miss.fell = true;
|
|
110
|
+
}
|
|
111
|
+
//# sourceMappingURL=capabilities.js.map
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { IncomingMessage, ServerResponse } from "node:http";
|
|
2
|
+
import type { RouteCtx } from "../route-ctx.js";
|
|
3
|
+
export declare function handleFleet(req: IncomingMessage, res: ServerResponse, url: string, ctx: RouteCtx): Promise<boolean>;
|
|
4
|
+
//# sourceMappingURL=fleet.d.ts.map
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
import { taskNotificationFoldKey } from "../../orchestration/workflow-completion-inbox.js";
|
|
2
|
+
import { sendJson, sendError, sseHeaders } from "../send.js";
|
|
3
|
+
import { gatedPrincipal } from "../principal-gate.js";
|
|
4
|
+
export async function handleFleet(req, res, url, ctx) {
|
|
5
|
+
const miss = { fell: false };
|
|
6
|
+
await handleFleetBody(req, res, url, ctx, miss);
|
|
7
|
+
return !miss.fell;
|
|
8
|
+
}
|
|
9
|
+
async function handleFleetBody(req, res, url, ctx, miss) {
|
|
10
|
+
const { deps } = ctx;
|
|
11
|
+
const { sessionOwnerScope } = ctx.helpers;
|
|
12
|
+
void url;
|
|
13
|
+
if (req.method === "GET" && new URL(req.url ?? "", "http://x").pathname === "/v1/fleet/stream") {
|
|
14
|
+
if (!deps.fleetBus) {
|
|
15
|
+
sendError(res, 501, "capability.self_orchestration_required", "fleet stream requires self-orchestration / fleet wiring");
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
const { fleetWide } = sessionOwnerScope(req);
|
|
19
|
+
const principal = gatedPrincipal(req, deps.config);
|
|
20
|
+
if (deps.config.requirePrincipal && !principal && !fleetWide) {
|
|
21
|
+
sendError(res, 401, "auth.principal_required", `missing principal header '${deps.config.principalHeader}'`);
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
const fleetParams = new URL(req.url ?? "", "http://x").searchParams;
|
|
25
|
+
const callerSession = fleetParams.get("session");
|
|
26
|
+
const observeOnly = fleetParams.get("observe") === "1";
|
|
27
|
+
await streamFleet(req, res, deps.fleetBus, fleetWide ? null : (principal ?? "default"), callerSession || null, observeOnly ? undefined : deps.workflowCompletionInbox);
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
miss.fell = true;
|
|
31
|
+
}
|
|
32
|
+
function streamFleet(req, res, bus, callerScope, callerSession = null, completionInbox) {
|
|
33
|
+
return new Promise((resolve) => {
|
|
34
|
+
sseHeaders(res);
|
|
35
|
+
res.write(`event: meta\ndata: ${JSON.stringify({ version: 1, scoped: callerScope !== null, sessionScoped: callerSession !== null, bgNotifyFailClosed: true })}\n\n`);
|
|
36
|
+
const seenTasks = new Set();
|
|
37
|
+
const seenWf = new Set();
|
|
38
|
+
const sessionOk = (rowSession) => callerSession === null || rowSession === undefined || rowSession === callerSession;
|
|
39
|
+
const visT = (r) => (callerScope === null || r.scope === callerScope) && sessionOk(r.sessionId);
|
|
40
|
+
const visW = (r) => (callerScope === null || r.scope === callerScope) && sessionOk(r.sessionId);
|
|
41
|
+
const stripT = (r) => {
|
|
42
|
+
const { scope: _s, sessionId: _sid, ...rest } = r;
|
|
43
|
+
if (callerSession !== null && r.sessionId === undefined) {
|
|
44
|
+
const { description: _d, agentType: _at, agentName: _an, currentAction: _ca, ...keep } = rest;
|
|
45
|
+
return { ...keep, name: "(unattributed)" };
|
|
46
|
+
}
|
|
47
|
+
return rest;
|
|
48
|
+
};
|
|
49
|
+
const stripW = (r) => {
|
|
50
|
+
const { scope: _s, sessionId: _sid, ...rest } = r;
|
|
51
|
+
if (callerSession !== null && r.sessionId === undefined) {
|
|
52
|
+
const { description: _d, ...keep } = rest;
|
|
53
|
+
return { ...keep, name: "(unattributed)" };
|
|
54
|
+
}
|
|
55
|
+
return rest;
|
|
56
|
+
};
|
|
57
|
+
const send = (event, data) => { if (!res.writableEnded)
|
|
58
|
+
res.write(`event: ${event}\ndata: ${JSON.stringify(data)}\n\n`); };
|
|
59
|
+
const snap = bus.snapshot();
|
|
60
|
+
const tasks = snap.tasks.filter(visT);
|
|
61
|
+
const workflows = snap.workflows.filter(visW);
|
|
62
|
+
tasks.forEach((r) => seenTasks.add(r.id));
|
|
63
|
+
workflows.forEach((r) => seenWf.add(r.id));
|
|
64
|
+
send("snapshot", { tasks: tasks.map(stripT), workflows: workflows.map(stripW), ts: snap.ts });
|
|
65
|
+
const unsubscribe = bus.subscribe((frame) => {
|
|
66
|
+
switch (frame.type) {
|
|
67
|
+
case "task":
|
|
68
|
+
if (visT(frame.row)) {
|
|
69
|
+
seenTasks.add(frame.row.id);
|
|
70
|
+
send("task", { row: stripT(frame.row), ts: frame.ts });
|
|
71
|
+
}
|
|
72
|
+
break;
|
|
73
|
+
case "workflow":
|
|
74
|
+
if (visW(frame.row)) {
|
|
75
|
+
seenWf.add(frame.row.id);
|
|
76
|
+
send("workflow", { row: stripW(frame.row), ts: frame.ts });
|
|
77
|
+
}
|
|
78
|
+
break;
|
|
79
|
+
case "task_remove":
|
|
80
|
+
if (seenTasks.delete(frame.id))
|
|
81
|
+
send("task_remove", { id: frame.id, ts: frame.ts });
|
|
82
|
+
break;
|
|
83
|
+
case "workflow_remove":
|
|
84
|
+
if (seenWf.delete(frame.id))
|
|
85
|
+
send("workflow_remove", { id: frame.id, ts: frame.ts });
|
|
86
|
+
break;
|
|
87
|
+
case "hook_notice": {
|
|
88
|
+
const hn = frame.notice;
|
|
89
|
+
const hScopeOk = callerScope === null || hn.ownerScope === callerScope;
|
|
90
|
+
const hSessionOk = callerSession === null || hn.ownerSessionId === callerSession;
|
|
91
|
+
if (hScopeOk && hSessionOk) {
|
|
92
|
+
const { ownerScope: _hs, ownerSessionId: _hsid, ...wire } = hn;
|
|
93
|
+
send("hook_notice", { type: "hook_notice", ...wire, ts: frame.ts });
|
|
94
|
+
}
|
|
95
|
+
break;
|
|
96
|
+
}
|
|
97
|
+
case "bg_notification": {
|
|
98
|
+
const n = frame.notification;
|
|
99
|
+
const scopeOk = callerScope === null || n.ownerScope === callerScope;
|
|
100
|
+
const sessionInjectOk = callerSession === null || n.ownerSessionId === callerSession;
|
|
101
|
+
if (scopeOk && sessionInjectOk) {
|
|
102
|
+
const { ownerScope: _os, ownerSessionId: _osid, ...wire } = n;
|
|
103
|
+
send("bg_notification", { type: "bg_notification", ...wire, ts: frame.ts });
|
|
104
|
+
if (completionInbox && n.ownerSessionId && callerSession !== null && callerSession === n.ownerSessionId && !res.writableEnded) {
|
|
105
|
+
const ownerSid = n.ownerSessionId;
|
|
106
|
+
const family = taskNotificationFoldKey({ task_id: n.taskId, status: n.status, ...(n.seq !== undefined ? { seq: n.seq } : {}) });
|
|
107
|
+
const familyUuid = n.sessionId !== undefined && n.sessionId !== n.taskId
|
|
108
|
+
? taskNotificationFoldKey({ task_id: n.sessionId, status: n.status, ...(n.seq !== undefined ? { seq: n.seq } : {}) })
|
|
109
|
+
: undefined;
|
|
110
|
+
const ackIfAlive = () => {
|
|
111
|
+
if (res.writableEnded || res.socket?.destroyed)
|
|
112
|
+
return;
|
|
113
|
+
void completionInbox.markTerminalServed(ownerSid, family).catch(() => undefined);
|
|
114
|
+
if (familyUuid !== undefined)
|
|
115
|
+
void completionInbox.markTerminalServed(ownerSid, familyUuid).catch(() => undefined);
|
|
116
|
+
};
|
|
117
|
+
res.write(`: ack
|
|
118
|
+
|
|
119
|
+
`, ackIfAlive);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
break;
|
|
123
|
+
}
|
|
124
|
+
default:
|
|
125
|
+
break;
|
|
126
|
+
}
|
|
127
|
+
});
|
|
128
|
+
const hb = setInterval(() => { if (!res.writableEnded)
|
|
129
|
+
res.write(`event: heartbeat\ndata: {}\n\n`); }, 15_000);
|
|
130
|
+
if (typeof hb.unref === "function")
|
|
131
|
+
hb.unref();
|
|
132
|
+
let done = false;
|
|
133
|
+
const shutdown = () => {
|
|
134
|
+
if (done)
|
|
135
|
+
return;
|
|
136
|
+
done = true;
|
|
137
|
+
clearInterval(hb);
|
|
138
|
+
unsubscribe();
|
|
139
|
+
if (!res.writableEnded)
|
|
140
|
+
res.end();
|
|
141
|
+
resolve();
|
|
142
|
+
};
|
|
143
|
+
req.on("close", shutdown);
|
|
144
|
+
res.on("close", shutdown);
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
//# sourceMappingURL=fleet.js.map
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { IncomingMessage, ServerResponse } from "node:http";
|
|
2
|
+
import { RateLimiter } from "../../observability/rate-limit.js";
|
|
3
|
+
import type { BakeState, BakeErrorCode } from "../../plugins/store-contracts.js";
|
|
4
|
+
import type { FlatServiceDeps } from "../server.js";
|
|
5
|
+
import type { RouteCtx } from "../route-ctx.js";
|
|
6
|
+
export interface ImagesLocal {
|
|
7
|
+
bakeSubmitLimiter: RateLimiter;
|
|
8
|
+
}
|
|
9
|
+
export declare function createImagesLocal(deps: FlatServiceDeps): ImagesLocal;
|
|
10
|
+
export declare function coarseStatusForState(state: BakeState): "running" | "done" | "failed";
|
|
11
|
+
export declare function errorCodeForExit(exitCode: number | null | undefined, cancelled: boolean): BakeErrorCode;
|
|
12
|
+
export declare const IMAGE_DIGEST_RE: RegExp;
|
|
13
|
+
export declare const IMAGE_PROFILE_RE: RegExp;
|
|
14
|
+
export declare const BAKE_ID_RE: RegExp;
|
|
15
|
+
export declare const BAKE_EVENTS_RE: RegExp;
|
|
16
|
+
export declare const BAKE_CANCEL_RE: RegExp;
|
|
17
|
+
export declare const BAKE_CLAIM_RE: RegExp;
|
|
18
|
+
export declare const BAKE_INGEST_RE: RegExp;
|
|
19
|
+
export declare function handleImages(req: IncomingMessage, res: ServerResponse, url: string, ctx: RouteCtx): Promise<boolean>;
|
|
20
|
+
//# sourceMappingURL=images.d.ts.map
|