@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
@@ -1,151 +1,3 @@
1
- import { createHash } from "node:crypto";
2
- import { mapImageRow as mapRow, } from "./store-contracts.js";
1
+ export { TiDBImageIndex } from "./image-index-sql.js";
3
2
  export { mapImageRow as mapRow } from "./store-contracts.js";
4
- const MAX_LIMIT = 200;
5
- const DEFAULT_LIMIT = 50;
6
- function visibilityClause(viewer) {
7
- if (viewer.operator)
8
- return { sql: "1=1", params: [] };
9
- if (viewer.tenantId)
10
- return { sql: "(visibility='public' OR tenant_id=?)", params: [viewer.tenantId] };
11
- return { sql: "visibility='public'", params: [] };
12
- }
13
- function encodeCursor(e) {
14
- return Buffer.from(`${e.createdAt}|${e.id}`, "utf8").toString("base64url");
15
- }
16
- function decodeCursor(c) {
17
- try {
18
- const [createdAt, id] = Buffer.from(c, "base64url").toString("utf8").split("|");
19
- if (!createdAt || !id)
20
- return null;
21
- return { createdAt, id };
22
- }
23
- catch {
24
- return null;
25
- }
26
- }
27
- export class TiDBImageIndex {
28
- pool;
29
- constructor(pool) {
30
- this.pool = pool;
31
- }
32
- static idFor(repo, digest) {
33
- return createHash("sha256").update(`${repo}@${digest}`).digest("hex").slice(0, 64);
34
- }
35
- async upsert(e) {
36
- const id = TiDBImageIndex.idFor(e.repo, e.digest);
37
- const now = new Date();
38
- await this.pool.query(`INSERT INTO sandbox_image_index
39
- (id, profile, bands, repo, tag, digest, toolchain_versions, capabilities, pod_contract, size_bytes,
40
- status, visibility, tenant_id, manifest_sha, recipe_git_sha, generator_version, build_date, supersedes,
41
- signed, created_at, updated_at)
42
- VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)
43
- ON DUPLICATE KEY UPDATE
44
- profile=VALUES(profile), bands=VALUES(bands), tag=VALUES(tag), toolchain_versions=VALUES(toolchain_versions),
45
- capabilities=VALUES(capabilities), pod_contract=VALUES(pod_contract), size_bytes=VALUES(size_bytes),
46
- status=VALUES(status), visibility=VALUES(visibility), tenant_id=VALUES(tenant_id),
47
- manifest_sha=VALUES(manifest_sha), recipe_git_sha=VALUES(recipe_git_sha),
48
- generator_version=VALUES(generator_version), build_date=VALUES(build_date), supersedes=VALUES(supersedes),
49
- signed=VALUES(signed), updated_at=VALUES(updated_at)`, [
50
- id, e.profile, JSON.stringify(e.bands ?? []), e.repo, e.tag, e.digest,
51
- JSON.stringify(e.toolchainVersions ?? {}), JSON.stringify(e.capabilities ?? {}),
52
- JSON.stringify(e.podContract ?? {}), e.sizeBytes,
53
- e.status, e.visibility, e.tenantId ?? null, e.manifestSha ?? null, e.recipeGitSha ?? null,
54
- e.generatorVersion ?? null, e.buildDate ? new Date(e.buildDate) : null, e.supersedes ?? null,
55
- e.signed ? 1 : 0, now, now,
56
- ]);
57
- return id;
58
- }
59
- async registerBuilding(e) {
60
- const id = TiDBImageIndex.idFor(e.repo, e.digest);
61
- const now = new Date();
62
- await this.pool.query(`INSERT INTO sandbox_image_index
63
- (id, profile, bands, repo, tag, digest, toolchain_versions, capabilities, pod_contract, size_bytes,
64
- status, visibility, tenant_id, manifest_sha, recipe_git_sha, generator_version, build_date, supersedes,
65
- signed, created_at, updated_at)
66
- VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)
67
- ON DUPLICATE KEY UPDATE
68
- profile=VALUES(profile), bands=VALUES(bands), tag=VALUES(tag), toolchain_versions=VALUES(toolchain_versions),
69
- capabilities=VALUES(capabilities), pod_contract=VALUES(pod_contract), size_bytes=VALUES(size_bytes),
70
- status=IF(sandbox_image_index.status='published', sandbox_image_index.status, VALUES(status)),
71
- visibility=IF(sandbox_image_index.status='published', sandbox_image_index.visibility, VALUES(visibility)),
72
- tenant_id=IF(sandbox_image_index.status='published', sandbox_image_index.tenant_id, VALUES(tenant_id)),
73
- manifest_sha=VALUES(manifest_sha), recipe_git_sha=VALUES(recipe_git_sha),
74
- generator_version=VALUES(generator_version), build_date=VALUES(build_date), supersedes=VALUES(supersedes),
75
- signed=IF(sandbox_image_index.status='published', sandbox_image_index.signed, VALUES(signed)), updated_at=VALUES(updated_at)`, [
76
- id, e.profile, JSON.stringify(e.bands ?? []), e.repo, e.tag, e.digest,
77
- JSON.stringify(e.toolchainVersions ?? {}), JSON.stringify(e.capabilities ?? {}),
78
- JSON.stringify(e.podContract ?? {}), e.sizeBytes,
79
- e.status, e.visibility, e.tenantId ?? null, e.manifestSha ?? null, e.recipeGitSha ?? null,
80
- e.generatorVersion ?? null, e.buildDate ? new Date(e.buildDate) : null, e.supersedes ?? null,
81
- e.signed ? 1 : 0, now, now,
82
- ]);
83
- return id;
84
- }
85
- async getById(id) {
86
- const [rows] = await this.pool.query(`SELECT * FROM sandbox_image_index WHERE id=? LIMIT 1`, [id]);
87
- return rows[0] ? mapRow(rows[0]) : null;
88
- }
89
- async getByDigest(digest) {
90
- const [rows] = await this.pool.query(`SELECT * FROM sandbox_image_index WHERE digest=? ORDER BY updated_at DESC LIMIT 1`, [digest]);
91
- return rows[0] ? mapRow(rows[0]) : null;
92
- }
93
- async latestPublished(profile, viewer) {
94
- const vis = visibilityClause(viewer);
95
- const [rows] = await this.pool.query(`SELECT * FROM sandbox_image_index
96
- WHERE profile=? AND status='published' AND ${vis.sql}
97
- ORDER BY (build_date IS NULL), build_date DESC, created_at DESC LIMIT 1`, [profile, ...vis.params]);
98
- return rows[0] ? mapRow(rows[0]) : null;
99
- }
100
- async list(filter) {
101
- const limit = Math.min(Math.max(1, filter.limit ?? DEFAULT_LIMIT), MAX_LIMIT);
102
- const vis = visibilityClause(filter);
103
- const where = [vis.sql];
104
- const params = [...vis.params];
105
- if (filter.profile) {
106
- where.push("profile=?");
107
- params.push(filter.profile);
108
- }
109
- if (filter.status) {
110
- where.push("status=?");
111
- params.push(filter.status);
112
- }
113
- if (filter.capability) {
114
- where.push("JSON_EXTRACT(capabilities, ?) = true");
115
- params.push(`$.${filter.capability}`);
116
- }
117
- if (filter.cursor) {
118
- const c = decodeCursor(filter.cursor);
119
- if (c) {
120
- where.push("(created_at < ? OR (created_at = ? AND id < ?))");
121
- params.push(new Date(c.createdAt), new Date(c.createdAt), c.id);
122
- }
123
- }
124
- const sql = `SELECT * FROM sandbox_image_index WHERE ${where.join(" AND ")} ` +
125
- `ORDER BY created_at DESC, id DESC LIMIT ?`;
126
- const [rows] = await this.pool.query(sql, [...params, limit + 1]);
127
- let entries = rows.map(mapRow);
128
- let nextCursor = null;
129
- if (entries.length > limit) {
130
- entries = entries.slice(0, limit);
131
- const last = entries[entries.length - 1];
132
- nextCursor = encodeCursor({ createdAt: last.createdAt, id: last.id });
133
- }
134
- if (filter.latestOnly) {
135
- const seen = new Set();
136
- entries = entries.filter((e) => (seen.has(e.profile) ? false : (seen.add(e.profile), true)));
137
- }
138
- return { entries, nextCursor };
139
- }
140
- async setStatus(id, status, opts) {
141
- const sets = ["status=?", "updated_at=?"];
142
- const params = [status, new Date()];
143
- if (opts && "supersedes" in opts) {
144
- sets.push("supersedes=?");
145
- params.push(opts.supersedes ?? null);
146
- }
147
- params.push(id);
148
- await this.pool.query(`UPDATE sandbox_image_index SET ${sets.join(", ")} WHERE id=?`, params);
149
- }
150
- }
151
3
  //# sourceMappingURL=tidb-image-index.js.map
@@ -1,58 +1,2 @@
1
- import type { Pool } from "mysql2/promise";
2
- import type { TaskOutcome as CoreTaskOutcome } from "@sema-agent/core";
3
- export interface MechanicalOutcome {
4
- route?: "single" | "fanout";
5
- workerCount?: number;
6
- oraclePassed?: number;
7
- oracleTotal?: number;
8
- assembleExit?: number;
9
- lintExit?: number;
10
- mergeOk?: boolean;
11
- replanTriggers?: string[];
12
- costMicroUsd?: number;
13
- turns?: number;
14
- }
15
- export interface LlmAssistedOutcome {
16
- stuckEvents?: number;
17
- verifier?: {
18
- verdict: string;
19
- confidence: number;
20
- };
21
- }
22
- export interface SignatureInputs {
23
- taskType?: string;
24
- toolset?: string[];
25
- targetLang?: string;
26
- moduleCount?: number;
27
- tag?: string;
28
- }
29
- export type RunStatus = "completed-graded" | "infra-aborted";
30
- export interface TaskOutcome {
31
- taskId?: string;
32
- model: string;
33
- runStatus?: RunStatus;
34
- signatureInputs: SignatureInputs;
35
- mechanical: MechanicalOutcome;
36
- llmAssisted?: LlmAssistedOutcome;
37
- core?: unknown;
38
- }
39
- export declare function taskSignature(s: SignatureInputs): string;
40
- export declare function deriveOutcome(m: MechanicalOutcome, runStatus?: RunStatus): "pass" | "partial" | "fail" | "aborted";
41
- export declare function coreOutcomeToLedgerRow(o: CoreTaskOutcome): TaskOutcome;
42
- export declare class TiDBOutcomeLedger {
43
- private readonly pool;
44
- constructor(pool: Pool);
45
- record(o: TaskOutcome): Promise<string>;
46
- recordCore(o: CoreTaskOutcome): Promise<void>;
47
- summary(opts?: {
48
- taskSignature?: string;
49
- includeAborted?: boolean;
50
- }): Promise<Array<{
51
- taskSignature: string;
52
- model: string;
53
- n: number;
54
- passRate: number;
55
- meanCostMicroUsd: number;
56
- }>>;
57
- }
1
+ export { TiDBOutcomeLedger, taskSignature, deriveOutcome, coreOutcomeToLedgerRow, type MechanicalOutcome, type LlmAssistedOutcome, type SignatureInputs, type RunStatus, type TaskOutcome, } from "./outcome-ledger-sql.js";
58
2
  //# sourceMappingURL=tidb-outcome-ledger.d.ts.map
@@ -1,98 +1,2 @@
1
- import { randomUUID } from "node:crypto";
2
- import { createHash } from "node:crypto";
3
- export function taskSignature(s) {
4
- if (s.tag)
5
- return `tag:${s.tag}`;
6
- const canon = JSON.stringify({
7
- taskType: s.taskType ?? "",
8
- toolset: [...(s.toolset ?? [])].sort(),
9
- targetLang: s.targetLang ?? "",
10
- moduleCount: s.moduleCount ?? 0,
11
- });
12
- return `h:${createHash("sha256").update(canon).digest("hex").slice(0, 16)}`;
13
- }
14
- export function deriveOutcome(m, runStatus = "completed-graded") {
15
- if (runStatus === "infra-aborted")
16
- return "aborted";
17
- const oracleGreen = m.oracleTotal != null && m.oracleTotal > 0 && m.oraclePassed === m.oracleTotal;
18
- const buildGreen = (m.assembleExit == null || m.assembleExit === 0) && (m.lintExit == null || m.lintExit === 0);
19
- const mergeGreen = m.mergeOk !== false;
20
- if (oracleGreen && buildGreen && mergeGreen)
21
- return "pass";
22
- const anyGreen = oracleGreen || (m.oraclePassed != null && m.oraclePassed > 0) || m.mergeOk === true;
23
- return anyGreen ? "partial" : "fail";
24
- }
25
- export function coreOutcomeToLedgerRow(o) {
26
- const passed = typeof o.oracle?.oraclePassed === "number" ? o.oracle.oraclePassed : o.oracle?.green ? 1 : 0;
27
- const total = typeof o.oracle?.oracleTotal === "number" ? o.oracle.oracleTotal : 1;
28
- return {
29
- taskId: o.runId.slice(0, 64),
30
- model: (o.model ?? "unknown").slice(0, 190),
31
- signatureInputs: {
32
- tag: o.taskSignature.slice(0, 186),
33
- ...(o.signatureInputs?.toolset ? { toolset: o.signatureInputs.toolset } : {}),
34
- ...(o.signatureInputs?.targetLang ? { targetLang: o.signatureInputs.targetLang } : {}),
35
- ...(o.signatureInputs?.moduleCount !== undefined ? { moduleCount: o.signatureInputs.moduleCount } : {}),
36
- },
37
- mechanical: {
38
- oraclePassed: passed,
39
- oracleTotal: total,
40
- ...(o.costMicroUsd !== undefined ? { costMicroUsd: o.costMicroUsd } : {}),
41
- ...(o.turns !== undefined ? { turns: o.turns } : {}),
42
- },
43
- core: o,
44
- };
45
- }
46
- export class TiDBOutcomeLedger {
47
- pool;
48
- constructor(pool) {
49
- this.pool = pool;
50
- }
51
- async record(o) {
52
- const id = randomUUID().replace(/-/g, "").slice(0, 32);
53
- const sig = taskSignature(o.signatureInputs);
54
- const m = o.mechanical;
55
- const runStatus = o.runStatus ?? "completed-graded";
56
- await this.pool.query(`INSERT INTO outcome_ledger
57
- (id, task_signature, model, task_id, run_status, route, worker_count, oracle_passed, oracle_total,
58
- assemble_exit, lint_exit, merge_ok, replan_triggers, cost_micro_usd, turns, outcome,
59
- llm_assisted, signature_inputs, core_outcome, created_at)
60
- VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)`, [
61
- id, sig, o.model, o.taskId ?? null, runStatus, m.route ?? null, m.workerCount ?? null,
62
- m.oraclePassed ?? null, m.oracleTotal ?? null, m.assembleExit ?? null, m.lintExit ?? null,
63
- m.mergeOk == null ? null : m.mergeOk ? 1 : 0,
64
- m.replanTriggers ? JSON.stringify(m.replanTriggers) : null,
65
- m.costMicroUsd ?? null, m.turns ?? null, deriveOutcome(m, runStatus),
66
- o.llmAssisted ? JSON.stringify(o.llmAssisted) : null,
67
- JSON.stringify(o.signatureInputs), o.core != null ? JSON.stringify(o.core) : null, new Date(),
68
- ]);
69
- return id;
70
- }
71
- async recordCore(o) {
72
- await this.record(coreOutcomeToLedgerRow(o));
73
- }
74
- async summary(opts = {}) {
75
- const clauses = [];
76
- const params = [];
77
- if (!opts.includeAborted)
78
- clauses.push("run_status = 'completed-graded'");
79
- if (opts.taskSignature) {
80
- clauses.push("task_signature = ?");
81
- params.push(opts.taskSignature);
82
- }
83
- const where = clauses.length ? `WHERE ${clauses.join(" AND ")}` : "";
84
- const [rows] = await this.pool.query(`SELECT task_signature, model, COUNT(*) n,
85
- AVG(outcome = 'pass') pass_rate, AVG(cost_micro_usd) mean_cost
86
- FROM outcome_ledger ${where}
87
- GROUP BY task_signature, model
88
- ORDER BY task_signature, model`, params);
89
- return rows.map((r) => ({
90
- taskSignature: String(r.task_signature),
91
- model: String(r.model),
92
- n: Number(r.n),
93
- passRate: Number(r.pass_rate),
94
- meanCostMicroUsd: Number(r.mean_cost ?? 0),
95
- }));
96
- }
97
- }
1
+ export { TiDBOutcomeLedger, taskSignature, deriveOutcome, coreOutcomeToLedgerRow, } from "./outcome-ledger-sql.js";
98
2
  //# sourceMappingURL=tidb-outcome-ledger.js.map
@@ -1,14 +1,2 @@
1
- import type { Pool } from "mysql2/promise";
2
- export declare class TiDBResumeAnchorStore {
3
- private readonly pool;
4
- constructor(pool: Pool);
5
- put(sessionId: string, eventId: string, entryId: string, owner: string | null): Promise<void>;
6
- resolve(sessionId: string, eventId: string, owner: string | null): Promise<string | undefined>;
7
- listBySession(sessionId: string): Promise<Array<{
8
- eventId: string;
9
- entryId: string;
10
- owner: string | null;
11
- }>>;
12
- deleteBySession(sessionId: string): Promise<number>;
13
- }
1
+ export { TiDBResumeAnchorStore } from "./resume-anchor-store-sql.js";
14
2
  //# sourceMappingURL=tidb-resume-anchor-store.d.ts.map
@@ -1,23 +1,2 @@
1
- export class TiDBResumeAnchorStore {
2
- pool;
3
- constructor(pool) {
4
- this.pool = pool;
5
- }
6
- async put(sessionId, eventId, entryId, owner) {
7
- await this.pool.query("INSERT INTO resume_anchor (session_id, event_id, entry_id, owner, created_at) VALUES (?,?,?,?,?) " +
8
- "ON DUPLICATE KEY UPDATE entry_id = VALUES(entry_id), owner = VALUES(owner)", [sessionId, eventId, entryId, owner, new Date()]);
9
- }
10
- async resolve(sessionId, eventId, owner) {
11
- const [rows] = await this.pool.query("SELECT entry_id FROM resume_anchor WHERE session_id = ? AND event_id = ? AND owner <=> ?", [sessionId, eventId, owner]);
12
- return rows[0] ? String(rows[0].entry_id) : undefined;
13
- }
14
- async listBySession(sessionId) {
15
- const [rows] = await this.pool.query("SELECT event_id, entry_id, owner FROM resume_anchor WHERE session_id = ?", [sessionId]);
16
- return rows.map((r) => ({ eventId: String(r.event_id), entryId: String(r.entry_id), owner: r.owner == null ? null : String(r.owner) }));
17
- }
18
- async deleteBySession(sessionId) {
19
- const [r] = await this.pool.query("DELETE FROM resume_anchor WHERE session_id = ?", [sessionId]);
20
- return r.affectedRows;
21
- }
22
- }
1
+ export { TiDBResumeAnchorStore } from "./resume-anchor-store-sql.js";
23
2
  //# sourceMappingURL=tidb-resume-anchor-store.js.map
@@ -1,77 +1,3 @@
1
- import type { TaskResult, TaskStatus } from "@sema-agent/core";
2
- import { type UsageRow } from "../usage-analytics.js";
3
- import type { Pool } from "mysql2/promise";
4
- import type { RunRecord, SessionSummary, RunEvent } from "./store-contracts.js";
1
+ export { TiDBRunStore } from "./run-store-sql.js";
5
2
  export type { RunRecord, SessionSummary, RunEvent } from "./store-contracts.js";
6
- export declare class TiDBRunStore {
7
- private readonly pool;
8
- constructor(pool: Pool);
9
- createRun(taskId: string, sessionId: string, owner: string | null, instanceId: string, meta?: {
10
- jobId?: string | null;
11
- source?: string | null;
12
- objectivePreview?: string | null;
13
- }): Promise<{
14
- ok: true;
15
- } | {
16
- ok: false;
17
- activeTaskId: string;
18
- }>;
19
- requestCancel(taskId: string, owner: string | null): Promise<boolean>;
20
- isCancelRequested(taskId: string, owner: string | null): Promise<boolean>;
21
- requestPreempt(taskId: string, owner: string | null): Promise<boolean>;
22
- isPreemptRequested(taskId: string, owner: string | null): Promise<boolean>;
23
- heartbeat(taskId: string, owner: string | null): Promise<void>;
24
- appendEvent(taskId: string, seq: number, type: string, data: unknown): Promise<void>;
25
- maxSeq(taskId: string): Promise<number>;
26
- private tx;
27
- setTerminal(taskId: string, status: TaskStatus, result: TaskResult | null, error: string | null): Promise<void>;
28
- setSuspended(taskId: string): Promise<void>;
29
- setNeedsReview(taskId: string): Promise<void>;
30
- markResuming(taskId: string): Promise<boolean>;
31
- getActiveTaskId(sessionId: string): Promise<string | undefined>;
32
- private rowToRun;
33
- getRun(taskId: string): Promise<RunRecord | undefined>;
34
- listRuns(opts: {
35
- status?: string;
36
- jobId?: string;
37
- source?: string;
38
- owner?: string;
39
- cursor?: {
40
- createdAt: string;
41
- taskId: string;
42
- };
43
- limit: number;
44
- }): Promise<RunRecord[]>;
45
- listSessions(opts: {
46
- owner?: string;
47
- cursor?: {
48
- lastActivityAt: string;
49
- sessionId: string;
50
- };
51
- limit: number;
52
- q?: string;
53
- }): Promise<SessionSummary[]>;
54
- deleteBySession(sessionId: string, owner: string | null): Promise<{
55
- removed: number;
56
- } | {
57
- active: string;
58
- }>;
59
- sourceSummary(sinceMs: number): Promise<Array<{
60
- source: string | null;
61
- status: string;
62
- count: number;
63
- }>>;
64
- usageScan(fromMs: number, toMs: number, opts?: {
65
- owner?: string;
66
- limit?: number;
67
- }): Promise<{
68
- rows: UsageRow[];
69
- truncated: boolean;
70
- }>;
71
- retainedFrom(taskId: string): Promise<number>;
72
- getEvents(taskId: string, afterSeq: number): Promise<RunEvent[]>;
73
- reapStale(olderThanMs: number): Promise<number>;
74
- reapSuspended(olderThanMs: number): Promise<number>;
75
- failSuspendedWithExpiredCheckpoint(): Promise<number>;
76
- }
77
3
  //# sourceMappingURL=tidb-run-store.d.ts.map