@sema-agent/server 1.314.0 → 1.316.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.
Files changed (146) hide show
  1. package/dist/approval-hmac.d.ts +17 -0
  2. package/dist/approval-hmac.js +27 -0
  3. package/dist/config-center/apply-effective.d.ts +22 -0
  4. package/dist/config-center/apply-effective.js +283 -0
  5. package/dist/config-center/http-client.d.ts +23 -0
  6. package/dist/config-center/http-client.js +109 -0
  7. package/dist/config-center/restart-signal.d.ts +12 -0
  8. package/dist/config-center/restart-signal.js +70 -0
  9. package/dist/config-center/skills-mcp.d.ts +13 -0
  10. package/dist/config-center/skills-mcp.js +113 -0
  11. package/dist/config-center/types.d.ts +143 -0
  12. package/dist/config-center/types.js +2 -0
  13. package/dist/fleet/fleet-bus.js +92 -83
  14. package/dist/hooks/hook-runner.js +18 -9
  15. package/dist/http/idempotency.d.ts +1 -0
  16. package/dist/http/idempotency.js +3 -0
  17. package/dist/http/principal-gate.d.ts +12 -0
  18. package/dist/http/principal-gate.js +52 -0
  19. package/dist/http/route-ctx.d.ts +67 -0
  20. package/dist/http/route-ctx.js +2 -0
  21. package/dist/http/routes/attachments.d.ts +4 -0
  22. package/dist/http/routes/attachments.js +106 -0
  23. package/dist/http/routes/capabilities.d.ts +4 -0
  24. package/dist/http/routes/capabilities.js +111 -0
  25. package/dist/http/routes/images.d.ts +20 -0
  26. package/dist/http/routes/images.js +572 -0
  27. package/dist/http/routes/memory-policy.d.ts +4 -0
  28. package/dist/http/routes/memory-policy.js +105 -0
  29. package/dist/http/routes/observability.d.ts +4 -0
  30. package/dist/http/routes/observability.js +63 -0
  31. package/dist/http/routes/session-sync.d.ts +36 -0
  32. package/dist/http/routes/session-sync.js +513 -0
  33. package/dist/http/routes/sessions-list.d.ts +4 -0
  34. package/dist/http/routes/sessions-list.js +117 -0
  35. package/dist/http/routes/sessions.d.ts +17 -0
  36. package/dist/http/routes/sessions.js +746 -0
  37. package/dist/http/send.d.ts +6 -0
  38. package/dist/http/send.js +19 -0
  39. package/dist/http/server.d.ts +101 -76
  40. package/dist/http/server.js +129 -2410
  41. package/dist/http/sse-log.d.ts +25 -0
  42. package/dist/http/sse-log.js +59 -0
  43. package/dist/http/workspace-content.d.ts +3 -0
  44. package/dist/http/workspace-content.js +20 -0
  45. package/dist/index.d.ts +1 -1
  46. package/dist/leader/leader.js +5 -2
  47. package/dist/leader/wire.js +169 -165
  48. package/dist/main.js +462 -451
  49. package/dist/plugins/approval-store-sql.d.ts +52 -0
  50. package/dist/plugins/approval-store-sql.js +119 -0
  51. package/dist/plugins/breaker-state-sql.d.ts +29 -0
  52. package/dist/plugins/breaker-state-sql.js +104 -0
  53. package/dist/plugins/checkpoint-store-sql.d.ts +67 -0
  54. package/dist/plugins/checkpoint-store-sql.js +224 -0
  55. package/dist/plugins/file-snapshot-store-sql.d.ts +38 -0
  56. package/dist/plugins/file-snapshot-store-sql.js +210 -0
  57. package/dist/plugins/image-bake-store-sql.d.ts +53 -0
  58. package/dist/plugins/image-bake-store-sql.js +463 -0
  59. package/dist/plugins/image-index-sql.d.ts +33 -0
  60. package/dist/plugins/image-index-sql.js +328 -0
  61. package/dist/plugins/k8s-bg-scripts.d.ts +19 -0
  62. package/dist/plugins/k8s-bg-scripts.js +129 -0
  63. package/dist/plugins/k8s-exec-protocol.d.ts +20 -0
  64. package/dist/plugins/k8s-exec-protocol.js +87 -0
  65. package/dist/plugins/outcome-ledger-sql.d.ts +70 -0
  66. package/dist/plugins/outcome-ledger-sql.js +158 -0
  67. package/dist/plugins/pg-approval-store.d.ts +1 -27
  68. package/dist/plugins/pg-approval-store.js +1 -83
  69. package/dist/plugins/pg-breaker-state.d.ts +1 -19
  70. package/dist/plugins/pg-breaker-state.js +1 -88
  71. package/dist/plugins/pg-checkpoint-store.d.ts +1 -33
  72. package/dist/plugins/pg-checkpoint-store.js +1 -189
  73. package/dist/plugins/pg-cost-quota.js +3 -143
  74. package/dist/plugins/pg-file-snapshot-store.d.ts +1 -27
  75. package/dist/plugins/pg-file-snapshot-store.js +1 -190
  76. package/dist/plugins/pg-image-bake.d.ts +1 -40
  77. package/dist/plugins/pg-image-bake.js +1 -420
  78. package/dist/plugins/pg-image-index.d.ts +1 -21
  79. package/dist/plugins/pg-image-index.js +1 -217
  80. package/dist/plugins/pg-outcome-ledger.d.ts +2 -22
  81. package/dist/plugins/pg-outcome-ledger.js +1 -104
  82. package/dist/plugins/pg-rate-limiter.d.ts +2 -32
  83. package/dist/plugins/pg-rate-limiter.js +4 -147
  84. package/dist/plugins/pg-resume-anchor-store.d.ts +1 -13
  85. package/dist/plugins/pg-resume-anchor-store.js +1 -22
  86. package/dist/plugins/pg-run-store.d.ts +1 -75
  87. package/dist/plugins/pg-run-store.js +1 -287
  88. package/dist/plugins/pg-session-policy-store.d.ts +1 -11
  89. package/dist/plugins/pg-session-policy-store.js +1 -90
  90. package/dist/plugins/pg-tool-result-store.d.ts +1 -15
  91. package/dist/plugins/pg-tool-result-store.js +1 -52
  92. package/dist/plugins/pg-workflow-journal-store.d.ts +1 -20
  93. package/dist/plugins/pg-workflow-journal-store.js +1 -34
  94. package/dist/plugins/pg-workflow-run-store.d.ts +1 -55
  95. package/dist/plugins/pg-workflow-run-store.js +1 -220
  96. package/dist/plugins/remote-env-k8s.d.ts +5 -38
  97. package/dist/plugins/remote-env-k8s.js +7 -213
  98. package/dist/plugins/resume-anchor-store-sql.d.ts +23 -0
  99. package/dist/plugins/resume-anchor-store-sql.js +38 -0
  100. package/dist/plugins/run-store-sql.d.ts +89 -0
  101. package/dist/plugins/run-store-sql.js +397 -0
  102. package/dist/plugins/session-policy-store-sql.d.ts +22 -0
  103. package/dist/plugins/session-policy-store-sql.js +109 -0
  104. package/dist/plugins/sql-driver.d.ts +25 -0
  105. package/dist/plugins/sql-driver.js +59 -0
  106. package/dist/plugins/tidb-approval-store.d.ts +1 -39
  107. package/dist/plugins/tidb-approval-store.js +1 -71
  108. package/dist/plugins/tidb-breaker-state.d.ts +1 -17
  109. package/dist/plugins/tidb-breaker-state.js +1 -74
  110. package/dist/plugins/tidb-checkpoint-store.d.ts +1 -49
  111. package/dist/plugins/tidb-checkpoint-store.js +1 -191
  112. package/dist/plugins/tidb-file-snapshot-store.d.ts +1 -27
  113. package/dist/plugins/tidb-file-snapshot-store.js +1 -192
  114. package/dist/plugins/tidb-image-bake.d.ts +1 -38
  115. package/dist/plugins/tidb-image-bake.js +1 -348
  116. package/dist/plugins/tidb-image-index.d.ts +1 -19
  117. package/dist/plugins/tidb-image-index.js +1 -149
  118. package/dist/plugins/tidb-outcome-ledger.d.ts +1 -57
  119. package/dist/plugins/tidb-outcome-ledger.js +1 -97
  120. package/dist/plugins/tidb-resume-anchor-store.d.ts +1 -13
  121. package/dist/plugins/tidb-resume-anchor-store.js +1 -22
  122. package/dist/plugins/tidb-run-store.d.ts +1 -75
  123. package/dist/plugins/tidb-run-store.js +1 -306
  124. package/dist/plugins/tidb-session-policy-store.d.ts +1 -11
  125. package/dist/plugins/tidb-session-policy-store.js +1 -86
  126. package/dist/plugins/tidb-tool-result-store.d.ts +1 -13
  127. package/dist/plugins/tidb-tool-result-store.js +1 -38
  128. package/dist/plugins/tidb-workflow-journal-store.d.ts +1 -20
  129. package/dist/plugins/tidb-workflow-journal-store.js +1 -34
  130. package/dist/plugins/tidb-workflow-run-store.d.ts +1 -61
  131. package/dist/plugins/tidb-workflow-run-store.js +1 -231
  132. package/dist/plugins/tool-result-store-sql.d.ts +25 -0
  133. package/dist/plugins/tool-result-store-sql.js +69 -0
  134. package/dist/plugins/workflow-journal-store-sql.d.ts +30 -0
  135. package/dist/plugins/workflow-journal-store-sql.js +53 -0
  136. package/dist/plugins/workflow-run-store-sql.d.ts +85 -0
  137. package/dist/plugins/workflow-run-store-sql.js +299 -0
  138. package/dist/plugins/write-behind-counter.d.ts +14 -3
  139. package/dist/plugins/write-behind-counter.js +39 -12
  140. package/dist/principal-jwt.d.ts +44 -0
  141. package/dist/principal-jwt.js +95 -0
  142. package/dist/security.d.ts +2 -58
  143. package/dist/security.js +3 -118
  144. package/dist/sema-registry.d.ts +5 -200
  145. package/dist/sema-registry.js +4 -567
  146. package/package.json +1 -1
@@ -0,0 +1,117 @@
1
+ import { isUuidV7 } from "../../security.js";
2
+ import { sendJson } from "../send.js";
3
+ export async function handleSessionsList(req, res, url, ctx) {
4
+ const miss = { fell: false };
5
+ await handleSessionsListBody(req, res, url, ctx, miss);
6
+ return !miss.fell;
7
+ }
8
+ async function handleSessionsListBody(req, res, url, ctx, miss) {
9
+ const { deps } = ctx;
10
+ const { isFleetWide, sessionOwnerScope } = ctx.helpers;
11
+ if (req.method === "GET" && url === "/v1/sessions") {
12
+ const { fleetWide, gateOwner } = sessionOwnerScope(req);
13
+ if (!fleetWide && gateOwner === null) {
14
+ sendJson(res, 401, { error: "unauthorized" });
15
+ return;
16
+ }
17
+ const lister = deps.sessionStorage?.listSessions?.bind(deps.sessionStorage) ?? deps.runStore?.listSessions?.bind(deps.runStore);
18
+ if (!lister) {
19
+ sendJson(res, 501, { error: "session list requires a durable session store (SESSION_BACKEND=tidb)" });
20
+ return;
21
+ }
22
+ await handleSessionList(res, lister, new URL(req.url ?? "", "http://x").searchParams, gateOwner);
23
+ return;
24
+ }
25
+ if (req.method === "GET" && url === "/v1/sendfile-links") {
26
+ const { fleetWide, gateOwner } = sessionOwnerScope(req);
27
+ if (!fleetWide && gateOwner === null) {
28
+ sendJson(res, 401, { error: "unauthorized" });
29
+ return;
30
+ }
31
+ if (!deps.sendFileLedger) {
32
+ sendJson(res, 501, { error: "sendfile ledger requires a store backend (DB_BACKEND=tidb|pg|local) and the SendUserFile issuer configured" });
33
+ return;
34
+ }
35
+ const query = new URL(req.url ?? "", "http://x").searchParams;
36
+ const limitRaw = query.get("limit");
37
+ if (limitRaw !== null && !(/^[0-9]+$/.test(limitRaw) && Number(limitRaw) >= 1 && Number(limitRaw) <= 100)) {
38
+ sendJson(res, 400, { error: "limit must be a decimal integer in 1..100" });
39
+ return;
40
+ }
41
+ const limit = limitRaw === null ? 50 : Number(limitRaw);
42
+ const beforeRaw = query.get("before");
43
+ if (beforeRaw !== null && !isUuidV7(beforeRaw)) {
44
+ sendJson(res, 400, { error: "before must be a uuidv7 link id (the `id`/`nextBefore` of a previous page)" });
45
+ return;
46
+ }
47
+ const before = beforeRaw ?? undefined;
48
+ let scope;
49
+ if (gateOwner !== null) {
50
+ scope = gateOwner;
51
+ }
52
+ else {
53
+ const scopeRaw = query.get("scope");
54
+ if (scopeRaw === null) {
55
+ scope = "_";
56
+ }
57
+ else {
58
+ const s = scopeRaw.trim();
59
+ if (s === "" || s.length > 190) {
60
+ sendJson(res, 400, { error: "scope must be a non-blank tenant principal of at most 190 characters (the sendfile_link.scope column width)" });
61
+ return;
62
+ }
63
+ scope = s;
64
+ }
65
+ }
66
+ const rows = await deps.sendFileLedger.listByScope(scope, limit + 1, before);
67
+ const hasMore = rows.length > limit;
68
+ const page = hasMore ? rows.slice(0, limit) : rows;
69
+ sendJson(res, 200, {
70
+ links: page.map((r) => ({
71
+ id: r.id,
72
+ filename: r.filename,
73
+ size: r.size,
74
+ ttlSec: r.ttlSec,
75
+ track: r.track,
76
+ bucket: r.bucket,
77
+ key: r.objectKey,
78
+ createdAt: new Date(r.createdAt).toISOString(),
79
+ ...(r.taskId !== undefined ? { taskId: r.taskId } : {}),
80
+ ...(r.sessionId !== undefined ? { sessionId: r.sessionId } : {}),
81
+ })),
82
+ ...(hasMore ? { nextBefore: page[page.length - 1].id } : {}),
83
+ });
84
+ return;
85
+ }
86
+ miss.fell = true;
87
+ }
88
+ function encodeSessionCursor(c) {
89
+ return Buffer.from(JSON.stringify(c)).toString("base64url");
90
+ }
91
+ function decodeSessionCursor(s) {
92
+ if (!s)
93
+ return undefined;
94
+ try {
95
+ const o = JSON.parse(Buffer.from(s, "base64url").toString());
96
+ return o.lastActivityAt && o.sessionId && !Number.isNaN(Date.parse(o.lastActivityAt))
97
+ ? { lastActivityAt: o.lastActivityAt, sessionId: o.sessionId }
98
+ : undefined;
99
+ }
100
+ catch {
101
+ return undefined;
102
+ }
103
+ }
104
+ async function handleSessionList(res, lister, query, forceOwner) {
105
+ const owner = forceOwner != null ? forceOwner : (query.get("owner") ?? undefined);
106
+ const limit = Math.min(100, Math.max(1, Number(query.get("limit") ?? 50) || 50));
107
+ const cursor = decodeSessionCursor(query.get("cursor"));
108
+ const qRaw = (query.get("q") ?? "").trim();
109
+ const q = qRaw ? qRaw.slice(0, 256) : undefined;
110
+ const rows = await lister({ ...(owner ? { owner } : {}), ...(cursor ? { cursor } : {}), limit: limit + 1, ...(q ? { q } : {}) });
111
+ const hasMore = rows.length > limit;
112
+ const page = hasMore ? rows.slice(0, limit) : rows;
113
+ const last = page[page.length - 1];
114
+ const nextCursor = hasMore && last ? encodeSessionCursor({ lastActivityAt: last.lastActivityAt, sessionId: last.sessionId }) : undefined;
115
+ sendJson(res, 200, { sessions: page, ...(nextCursor ? { nextCursor } : {}) });
116
+ }
117
+ //# sourceMappingURL=sessions-list.js.map
@@ -0,0 +1,17 @@
1
+ import type { IncomingMessage, ServerResponse } from "node:http";
2
+ import type { RouteCtx } from "../route-ctx.js";
3
+ export interface SessionsLocal {
4
+ sseConnections: number;
5
+ sseOwnerLookups: number;
6
+ mcpStatusCache: Map<string, {
7
+ at: number;
8
+ panel: Promise<{
9
+ servers: unknown[];
10
+ asOf: string;
11
+ degraded?: boolean;
12
+ }>;
13
+ }>;
14
+ }
15
+ export declare function createSessionsLocal(): SessionsLocal;
16
+ export declare function handleSessions(req: IncomingMessage, res: ServerResponse, url: string, ctx: RouteCtx): Promise<boolean>;
17
+ //# sourceMappingURL=sessions.d.ts.map