@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,158 @@
|
|
|
1
|
+
import { randomUUID, createHash } from "node:crypto";
|
|
2
|
+
import { pgSafeJsonStringify } from "./pg-safe-json.js";
|
|
3
|
+
import { mysqlDriver, pgDriver } from "./sql-driver.js";
|
|
4
|
+
export function taskSignature(s) {
|
|
5
|
+
if (s.tag)
|
|
6
|
+
return `tag:${s.tag}`;
|
|
7
|
+
const canon = JSON.stringify({
|
|
8
|
+
taskType: s.taskType ?? "",
|
|
9
|
+
toolset: [...(s.toolset ?? [])].sort(),
|
|
10
|
+
targetLang: s.targetLang ?? "",
|
|
11
|
+
moduleCount: s.moduleCount ?? 0,
|
|
12
|
+
});
|
|
13
|
+
return `h:${createHash("sha256").update(canon).digest("hex").slice(0, 16)}`;
|
|
14
|
+
}
|
|
15
|
+
export function deriveOutcome(m, runStatus = "completed-graded") {
|
|
16
|
+
if (runStatus === "infra-aborted")
|
|
17
|
+
return "aborted";
|
|
18
|
+
const oracleGreen = m.oracleTotal != null && m.oracleTotal > 0 && m.oraclePassed === m.oracleTotal;
|
|
19
|
+
const buildGreen = (m.assembleExit == null || m.assembleExit === 0) && (m.lintExit == null || m.lintExit === 0);
|
|
20
|
+
const mergeGreen = m.mergeOk !== false;
|
|
21
|
+
if (oracleGreen && buildGreen && mergeGreen)
|
|
22
|
+
return "pass";
|
|
23
|
+
const anyGreen = oracleGreen || (m.oraclePassed != null && m.oraclePassed > 0) || m.mergeOk === true;
|
|
24
|
+
return anyGreen ? "partial" : "fail";
|
|
25
|
+
}
|
|
26
|
+
export function coreOutcomeToLedgerRow(o) {
|
|
27
|
+
const passed = typeof o.oracle?.oraclePassed === "number" ? o.oracle.oraclePassed : o.oracle?.green ? 1 : 0;
|
|
28
|
+
const total = typeof o.oracle?.oracleTotal === "number" ? o.oracle.oracleTotal : 1;
|
|
29
|
+
return {
|
|
30
|
+
taskId: o.runId.slice(0, 64),
|
|
31
|
+
model: (o.model ?? "unknown").slice(0, 190),
|
|
32
|
+
signatureInputs: {
|
|
33
|
+
tag: o.taskSignature.slice(0, 186),
|
|
34
|
+
...(o.signatureInputs?.toolset ? { toolset: o.signatureInputs.toolset } : {}),
|
|
35
|
+
...(o.signatureInputs?.targetLang ? { targetLang: o.signatureInputs.targetLang } : {}),
|
|
36
|
+
...(o.signatureInputs?.moduleCount !== undefined ? { moduleCount: o.signatureInputs.moduleCount } : {}),
|
|
37
|
+
},
|
|
38
|
+
mechanical: {
|
|
39
|
+
oraclePassed: passed,
|
|
40
|
+
oracleTotal: total,
|
|
41
|
+
...(o.costMicroUsd !== undefined ? { costMicroUsd: o.costMicroUsd } : {}),
|
|
42
|
+
...(o.turns !== undefined ? { turns: o.turns } : {}),
|
|
43
|
+
},
|
|
44
|
+
core: o,
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
export const PG_OUTCOME_LEDGER_SCHEMA = [
|
|
48
|
+
`CREATE TABLE IF NOT EXISTS outcome_ledger (
|
|
49
|
+
id VARCHAR(64) NOT NULL,
|
|
50
|
+
task_signature VARCHAR(190) NOT NULL,
|
|
51
|
+
model VARCHAR(190) NOT NULL,
|
|
52
|
+
task_id VARCHAR(64),
|
|
53
|
+
run_status VARCHAR(20) NOT NULL DEFAULT 'completed-graded',
|
|
54
|
+
route VARCHAR(16),
|
|
55
|
+
worker_count INTEGER,
|
|
56
|
+
oracle_passed INTEGER,
|
|
57
|
+
oracle_total INTEGER,
|
|
58
|
+
assemble_exit INTEGER,
|
|
59
|
+
lint_exit INTEGER,
|
|
60
|
+
merge_ok SMALLINT,
|
|
61
|
+
replan_triggers JSONB,
|
|
62
|
+
cost_micro_usd BIGINT,
|
|
63
|
+
turns INTEGER,
|
|
64
|
+
outcome VARCHAR(8),
|
|
65
|
+
llm_assisted JSONB,
|
|
66
|
+
signature_inputs JSONB,
|
|
67
|
+
-- design/73 §1 bridge: the VERBATIM core TaskOutcome fact (oracleHadRedRun / status / oracle blob) as it
|
|
68
|
+
-- came off core, kept alongside the derived mechanical columns. NULL when the caller recorded through the
|
|
69
|
+
-- non-core \`record()\` path (no core fact to bridge).
|
|
70
|
+
core_outcome JSONB,
|
|
71
|
+
created_at TIMESTAMPTZ(3) NOT NULL,
|
|
72
|
+
PRIMARY KEY (id)
|
|
73
|
+
)`,
|
|
74
|
+
`CREATE INDEX IF NOT EXISTS idx_outcome_ledger_sig_model ON outcome_ledger (task_signature, model, run_status)`,
|
|
75
|
+
`CREATE INDEX IF NOT EXISTS idx_outcome_ledger_outcome ON outcome_ledger (outcome)`,
|
|
76
|
+
`CREATE INDEX IF NOT EXISTS idx_outcome_ledger_created ON outcome_ledger (created_at)`,
|
|
77
|
+
];
|
|
78
|
+
export async function ensurePgOutcomeLedgerSchema(pool) {
|
|
79
|
+
for (const stmt of PG_OUTCOME_LEDGER_SCHEMA)
|
|
80
|
+
await pool.query(stmt);
|
|
81
|
+
}
|
|
82
|
+
export class SqlOutcomeLedger {
|
|
83
|
+
db;
|
|
84
|
+
constructor(db) {
|
|
85
|
+
this.db = db;
|
|
86
|
+
}
|
|
87
|
+
q(tidb, pg) {
|
|
88
|
+
return this.db.dialect === "tidb" ? tidb : pg;
|
|
89
|
+
}
|
|
90
|
+
json(value) {
|
|
91
|
+
return this.db.dialect === "tidb" ? JSON.stringify(value) : pgSafeJsonStringify(value);
|
|
92
|
+
}
|
|
93
|
+
async record(o) {
|
|
94
|
+
const id = randomUUID().replace(/-/g, "").slice(0, 32);
|
|
95
|
+
const sig = taskSignature(o.signatureInputs);
|
|
96
|
+
const m = o.mechanical;
|
|
97
|
+
const runStatus = o.runStatus ?? "completed-graded";
|
|
98
|
+
await this.db.query(this.q(`INSERT INTO outcome_ledger
|
|
99
|
+
(id, task_signature, model, task_id, run_status, route, worker_count, oracle_passed, oracle_total,
|
|
100
|
+
assemble_exit, lint_exit, merge_ok, replan_triggers, cost_micro_usd, turns, outcome,
|
|
101
|
+
llm_assisted, signature_inputs, core_outcome, created_at)
|
|
102
|
+
VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)`, `INSERT INTO outcome_ledger
|
|
103
|
+
(id, task_signature, model, task_id, run_status, route, worker_count, oracle_passed, oracle_total,
|
|
104
|
+
assemble_exit, lint_exit, merge_ok, replan_triggers, cost_micro_usd, turns, outcome,
|
|
105
|
+
llm_assisted, signature_inputs, core_outcome, created_at)
|
|
106
|
+
VALUES ($1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12,$13::jsonb,$14,$15,$16,$17::jsonb,$18::jsonb,$19::jsonb,$20)`), [
|
|
107
|
+
id, sig, o.model, o.taskId ?? null, runStatus, m.route ?? null, m.workerCount ?? null,
|
|
108
|
+
m.oraclePassed ?? null, m.oracleTotal ?? null, m.assembleExit ?? null, m.lintExit ?? null,
|
|
109
|
+
m.mergeOk == null ? null : m.mergeOk ? 1 : 0,
|
|
110
|
+
m.replanTriggers ? this.json(m.replanTriggers) : null,
|
|
111
|
+
m.costMicroUsd ?? null, m.turns ?? null, deriveOutcome(m, runStatus),
|
|
112
|
+
o.llmAssisted ? this.json(o.llmAssisted) : null,
|
|
113
|
+
this.json(o.signatureInputs), o.core != null ? this.json(o.core) : null, new Date(),
|
|
114
|
+
]);
|
|
115
|
+
return id;
|
|
116
|
+
}
|
|
117
|
+
async recordCore(o) {
|
|
118
|
+
await this.record(coreOutcomeToLedgerRow(o));
|
|
119
|
+
}
|
|
120
|
+
async summary(opts = {}) {
|
|
121
|
+
const clauses = [];
|
|
122
|
+
const params = [];
|
|
123
|
+
if (!opts.includeAborted)
|
|
124
|
+
clauses.push("run_status = 'completed-graded'");
|
|
125
|
+
if (opts.taskSignature) {
|
|
126
|
+
params.push(opts.taskSignature);
|
|
127
|
+
clauses.push(this.q("task_signature = ?", `task_signature = $${params.length}`));
|
|
128
|
+
}
|
|
129
|
+
const where = clauses.length ? `WHERE ${clauses.join(" AND ")}` : "";
|
|
130
|
+
const { rows } = await this.db.query(this.q(`SELECT task_signature, model, COUNT(*) n,
|
|
131
|
+
AVG(outcome = 'pass') pass_rate, AVG(cost_micro_usd) mean_cost
|
|
132
|
+
FROM outcome_ledger ${where}
|
|
133
|
+
GROUP BY task_signature, model
|
|
134
|
+
ORDER BY task_signature, model`, `SELECT task_signature, model, COUNT(*) n,
|
|
135
|
+
AVG((outcome = 'pass')::int) pass_rate, AVG(cost_micro_usd) mean_cost
|
|
136
|
+
FROM outcome_ledger ${where}
|
|
137
|
+
GROUP BY task_signature, model
|
|
138
|
+
ORDER BY task_signature, model`), params);
|
|
139
|
+
return rows.map((r) => ({
|
|
140
|
+
taskSignature: String(r.task_signature),
|
|
141
|
+
model: String(r.model),
|
|
142
|
+
n: Number(r.n),
|
|
143
|
+
passRate: Number(r.pass_rate),
|
|
144
|
+
meanCostMicroUsd: Number(r.mean_cost ?? 0),
|
|
145
|
+
}));
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
export class TiDBOutcomeLedger extends SqlOutcomeLedger {
|
|
149
|
+
constructor(pool) {
|
|
150
|
+
super(mysqlDriver(pool));
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
export class PgOutcomeLedger extends SqlOutcomeLedger {
|
|
154
|
+
constructor(pool) {
|
|
155
|
+
super(pgDriver(pool));
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
//# sourceMappingURL=outcome-ledger-sql.js.map
|
|
@@ -1,28 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
import { type ApprovalRow, type ApprovalStatus } from "./tidb-approval-store.js";
|
|
3
|
-
export type { ApprovalRow, ApprovalStatus } from "./tidb-approval-store.js";
|
|
4
|
-
export declare const PG_APPROVAL_SCHEMA: string[];
|
|
5
|
-
export declare function ensureSchema(pool: Pool | PoolClient): Promise<void>;
|
|
6
|
-
export declare class PgApprovalStore {
|
|
7
|
-
private readonly pool;
|
|
8
|
-
constructor(pool: Pool);
|
|
9
|
-
createPending(id: string, scope: string | null, ctx: {
|
|
10
|
-
taskId?: string | null;
|
|
11
|
-
sessionId?: string | null;
|
|
12
|
-
owner?: string | null;
|
|
13
|
-
toolName: string;
|
|
14
|
-
args: unknown;
|
|
15
|
-
}): Promise<void>;
|
|
16
|
-
getStatus(id: string, scope: string | null): Promise<{
|
|
17
|
-
status: ApprovalStatus;
|
|
18
|
-
reason: string | null;
|
|
19
|
-
decidedBy: string | null;
|
|
20
|
-
} | undefined>;
|
|
21
|
-
decide(id: string, scope: string | null, decision: "approved" | "denied" | "expired", reason: string | null, decidedBy: string | null): Promise<boolean>;
|
|
22
|
-
listPending(scope: string | null, owner?: string): Promise<ApprovalRow[]>;
|
|
23
|
-
get(id: string, scope: string | null): Promise<ApprovalRow | undefined>;
|
|
24
|
-
getById(id: string): Promise<ApprovalRow | undefined>;
|
|
25
|
-
listPendingAll(): Promise<ApprovalRow[]>;
|
|
26
|
-
expireStale(olderThanMs: number): Promise<number>;
|
|
27
|
-
}
|
|
1
|
+
export { PgApprovalStore, PG_APPROVAL_SCHEMA, ensureSchema, type ApprovalRow, type ApprovalStatus, } from "./approval-store-sql.js";
|
|
28
2
|
//# sourceMappingURL=pg-approval-store.d.ts.map
|
|
@@ -1,84 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
import { pgProtocolJsonStringify } from "./pg-safe-json.js";
|
|
3
|
-
export const PG_APPROVAL_SCHEMA = [
|
|
4
|
-
`CREATE TABLE IF NOT EXISTS approval (
|
|
5
|
-
id VARCHAR(64) NOT NULL,
|
|
6
|
-
task_id VARCHAR(64),
|
|
7
|
-
session_id VARCHAR(64),
|
|
8
|
-
owner VARCHAR(190),
|
|
9
|
-
-- Single-DB fleet scope guard (tenant isolation). NULLABLE on purpose: a NULL-scope row is an untenanted
|
|
10
|
-
-- run, and every read/decide path matches it with \`scope IS NOT DISTINCT FROM $n\` (the PG twin of TiDB
|
|
11
|
-
-- \`<=>\`) so NULL matches only NULL and one tenant's scope NEVER matches another's.
|
|
12
|
-
scope VARCHAR(190),
|
|
13
|
-
tool_name VARCHAR(190) NOT NULL,
|
|
14
|
-
args JSONB,
|
|
15
|
-
status VARCHAR(16) NOT NULL,
|
|
16
|
-
reason TEXT,
|
|
17
|
-
decided_by VARCHAR(190),
|
|
18
|
-
created_at TIMESTAMPTZ(3) NOT NULL,
|
|
19
|
-
decided_at TIMESTAMPTZ(3),
|
|
20
|
-
PRIMARY KEY (id)
|
|
21
|
-
)`,
|
|
22
|
-
`CREATE INDEX IF NOT EXISTS idx_approval_owner_status ON approval (owner, status)`,
|
|
23
|
-
`CREATE INDEX IF NOT EXISTS idx_approval_status ON approval (status)`,
|
|
24
|
-
`CREATE INDEX IF NOT EXISTS idx_approval_scope_status ON approval (scope, status)`,
|
|
25
|
-
];
|
|
26
|
-
export async function ensureSchema(pool) {
|
|
27
|
-
for (const stmt of PG_APPROVAL_SCHEMA)
|
|
28
|
-
await pool.query(stmt);
|
|
29
|
-
}
|
|
30
|
-
export class PgApprovalStore {
|
|
31
|
-
pool;
|
|
32
|
-
constructor(pool) {
|
|
33
|
-
this.pool = pool;
|
|
34
|
-
}
|
|
35
|
-
async createPending(id, scope, ctx) {
|
|
36
|
-
await this.pool.query("INSERT INTO approval (id, task_id, session_id, owner, scope, tool_name, args, status, created_at) " +
|
|
37
|
-
"VALUES ($1,$2,$3,$4,$5,$6,$7::jsonb,'pending',$8)", [
|
|
38
|
-
id,
|
|
39
|
-
ctx.taskId ?? null,
|
|
40
|
-
ctx.sessionId ?? null,
|
|
41
|
-
ctx.owner ?? null,
|
|
42
|
-
scope,
|
|
43
|
-
ctx.toolName,
|
|
44
|
-
ctx.args == null ? null : pgProtocolJsonStringify(ctx.args, "approval args"),
|
|
45
|
-
new Date(),
|
|
46
|
-
]);
|
|
47
|
-
}
|
|
48
|
-
async getStatus(id, scope) {
|
|
49
|
-
const res = await this.pool.query("SELECT status, reason, decided_by FROM approval WHERE id = $1 AND scope IS NOT DISTINCT FROM $2", [id, scope]);
|
|
50
|
-
const r = res.rows[0];
|
|
51
|
-
if (!r)
|
|
52
|
-
return undefined;
|
|
53
|
-
return { status: r.status, reason: r.reason ?? null, decidedBy: r.decided_by ?? null };
|
|
54
|
-
}
|
|
55
|
-
async decide(id, scope, decision, reason, decidedBy) {
|
|
56
|
-
const res = await this.pool.query("UPDATE approval SET status = $1, reason = $2, decided_by = $3, decided_at = $4 WHERE id = $5 AND scope IS NOT DISTINCT FROM $6 AND status = 'pending'", [decision, reason, decidedBy, new Date(), id, scope]);
|
|
57
|
-
return (res.rowCount ?? 0) === 1;
|
|
58
|
-
}
|
|
59
|
-
async listPending(scope, owner) {
|
|
60
|
-
const res = owner
|
|
61
|
-
? await this.pool.query("SELECT * FROM approval WHERE status = 'pending' AND scope IS NOT DISTINCT FROM $1 AND owner = $2 ORDER BY created_at ASC", [scope, owner])
|
|
62
|
-
: await this.pool.query("SELECT * FROM approval WHERE status = 'pending' AND scope IS NOT DISTINCT FROM $1 ORDER BY created_at ASC", [scope]);
|
|
63
|
-
return res.rows.map(mapRow);
|
|
64
|
-
}
|
|
65
|
-
async get(id, scope) {
|
|
66
|
-
const res = await this.pool.query("SELECT * FROM approval WHERE id = $1 AND scope IS NOT DISTINCT FROM $2", [id, scope]);
|
|
67
|
-
return res.rows[0] ? mapRow(res.rows[0]) : undefined;
|
|
68
|
-
}
|
|
69
|
-
async getById(id) {
|
|
70
|
-
const res = await this.pool.query("SELECT * FROM approval WHERE id = $1", [id]);
|
|
71
|
-
return res.rows[0] ? mapRow(res.rows[0]) : undefined;
|
|
72
|
-
}
|
|
73
|
-
async listPendingAll() {
|
|
74
|
-
const res = await this.pool.query("SELECT * FROM approval WHERE status = 'pending' ORDER BY created_at ASC");
|
|
75
|
-
return res.rows.map(mapRow);
|
|
76
|
-
}
|
|
77
|
-
async expireStale(olderThanMs) {
|
|
78
|
-
const cutoff = new Date(Date.now() - olderThanMs);
|
|
79
|
-
const res = await this.pool.query("UPDATE approval SET status = 'expired', reason = 'timed out before decision', decided_at = $1 " +
|
|
80
|
-
"WHERE status = 'pending' AND created_at < $2", [new Date(), cutoff]);
|
|
81
|
-
return res.rowCount ?? 0;
|
|
82
|
-
}
|
|
83
|
-
}
|
|
1
|
+
export { PgApprovalStore, PG_APPROVAL_SCHEMA, ensureSchema, } from "./approval-store-sql.js";
|
|
84
2
|
//# sourceMappingURL=pg-approval-store.js.map
|
|
@@ -1,20 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
import type { BreakerSnapshot, BreakerState } from "@sema-agent/core";
|
|
3
|
-
export declare const PG_BREAKER_STATE_SCHEMA: string[];
|
|
4
|
-
export declare function ensureSchema(pool: Pool | PoolClient): Promise<void>;
|
|
5
|
-
export declare class PgBreakerState implements BreakerState {
|
|
6
|
-
private readonly pool;
|
|
7
|
-
private readonly onWriteFail?;
|
|
8
|
-
private cache;
|
|
9
|
-
private timer?;
|
|
10
|
-
private readonly pending;
|
|
11
|
-
constructor(pool: Pool, onWriteFail?: ((streak: number) => void) | undefined);
|
|
12
|
-
private writeFailStreak;
|
|
13
|
-
get(key: string): BreakerSnapshot | undefined;
|
|
14
|
-
set(key: string, snap: BreakerSnapshot): void;
|
|
15
|
-
private writeThrough;
|
|
16
|
-
refresh(): Promise<void>;
|
|
17
|
-
startRefresh(intervalMs?: number): this;
|
|
18
|
-
stop(): void;
|
|
19
|
-
}
|
|
1
|
+
export { PgBreakerState, PG_BREAKER_STATE_SCHEMA, ensureSchema } from "./breaker-state-sql.js";
|
|
20
2
|
//# sourceMappingURL=pg-breaker-state.d.ts.map
|
|
@@ -1,89 +1,2 @@
|
|
|
1
|
-
export
|
|
2
|
-
`CREATE TABLE IF NOT EXISTS circuit_breaker (
|
|
3
|
-
breaker_key VARCHAR(190) NOT NULL,
|
|
4
|
-
phase VARCHAR(16) NOT NULL,
|
|
5
|
-
failures INTEGER NOT NULL DEFAULT 0,
|
|
6
|
-
opened_at TIMESTAMPTZ(3),
|
|
7
|
-
updated_at TIMESTAMPTZ(3) NOT NULL,
|
|
8
|
-
PRIMARY KEY (breaker_key)
|
|
9
|
-
)`,
|
|
10
|
-
];
|
|
11
|
-
export async function ensureSchema(pool) {
|
|
12
|
-
for (const stmt of PG_BREAKER_STATE_SCHEMA)
|
|
13
|
-
await pool.query(stmt);
|
|
14
|
-
}
|
|
15
|
-
export class PgBreakerState {
|
|
16
|
-
pool;
|
|
17
|
-
onWriteFail;
|
|
18
|
-
cache = new Map();
|
|
19
|
-
timer;
|
|
20
|
-
pending = new Set();
|
|
21
|
-
constructor(pool, onWriteFail) {
|
|
22
|
-
this.pool = pool;
|
|
23
|
-
this.onWriteFail = onWriteFail;
|
|
24
|
-
}
|
|
25
|
-
writeFailStreak = 0;
|
|
26
|
-
get(key) {
|
|
27
|
-
return this.cache.get(key);
|
|
28
|
-
}
|
|
29
|
-
set(key, snap) {
|
|
30
|
-
this.cache.set(key, snap);
|
|
31
|
-
this.pending.add(key);
|
|
32
|
-
void this.writeThrough(key, snap);
|
|
33
|
-
}
|
|
34
|
-
async writeThrough(key, snap) {
|
|
35
|
-
try {
|
|
36
|
-
await this.pool.query("INSERT INTO circuit_breaker (breaker_key, phase, failures, opened_at, updated_at) VALUES ($1,$2,$3,$4,$5) " +
|
|
37
|
-
"ON CONFLICT (breaker_key) DO UPDATE SET phase=EXCLUDED.phase, failures=EXCLUDED.failures, opened_at=EXCLUDED.opened_at, updated_at=EXCLUDED.updated_at", [key, snap.phase, snap.failures, snap.openedAt != null ? new Date(snap.openedAt) : null, new Date()]);
|
|
38
|
-
this.pending.delete(key);
|
|
39
|
-
if (this.writeFailStreak > 0) {
|
|
40
|
-
this.writeFailStreak = 0;
|
|
41
|
-
try {
|
|
42
|
-
this.onWriteFail?.(0);
|
|
43
|
-
}
|
|
44
|
-
catch { }
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
catch {
|
|
48
|
-
try {
|
|
49
|
-
this.onWriteFail?.(++this.writeFailStreak);
|
|
50
|
-
}
|
|
51
|
-
catch { }
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
async refresh() {
|
|
55
|
-
try {
|
|
56
|
-
const pendingAtStart = new Set(this.pending);
|
|
57
|
-
const guarded = (key) => this.pending.has(key) || pendingAtStart.has(key);
|
|
58
|
-
const res = await this.pool.query("SELECT breaker_key, phase, failures, opened_at FROM circuit_breaker");
|
|
59
|
-
const seen = new Set();
|
|
60
|
-
for (const r of res.rows) {
|
|
61
|
-
const key = String(r.breaker_key);
|
|
62
|
-
seen.add(key);
|
|
63
|
-
if (guarded(key))
|
|
64
|
-
continue;
|
|
65
|
-
this.cache.set(key, {
|
|
66
|
-
phase: r.phase,
|
|
67
|
-
failures: Number(r.failures),
|
|
68
|
-
openedAt: r.opened_at != null ? new Date(r.opened_at).getTime() : undefined,
|
|
69
|
-
});
|
|
70
|
-
}
|
|
71
|
-
for (const key of this.cache.keys())
|
|
72
|
-
if (!seen.has(key) && !guarded(key))
|
|
73
|
-
this.cache.delete(key);
|
|
74
|
-
}
|
|
75
|
-
catch {
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
startRefresh(intervalMs = 5_000) {
|
|
79
|
-
this.timer ??= setInterval(() => void this.refresh(), intervalMs);
|
|
80
|
-
this.timer.unref?.();
|
|
81
|
-
return this;
|
|
82
|
-
}
|
|
83
|
-
stop() {
|
|
84
|
-
if (this.timer)
|
|
85
|
-
clearInterval(this.timer);
|
|
86
|
-
this.timer = undefined;
|
|
87
|
-
}
|
|
88
|
-
}
|
|
1
|
+
export { PgBreakerState, PG_BREAKER_STATE_SCHEMA, ensureSchema } from "./breaker-state-sql.js";
|
|
89
2
|
//# sourceMappingURL=pg-breaker-state.js.map
|
|
@@ -1,28 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
import type { Pool } from "pg";
|
|
3
|
-
import { type BlobBackend } from "./blob-backend.js";
|
|
4
|
-
export declare class PgFileSnapshotStore implements FileSnapshotStore {
|
|
5
|
-
private readonly pool;
|
|
6
|
-
private readonly bounds;
|
|
7
|
-
private readonly inFlight;
|
|
8
|
-
private readonly blobs;
|
|
9
|
-
onSkippedVanished: ((count: number) => void | Promise<void>) | undefined;
|
|
10
|
-
constructor(pool: Pool, blobBackend?: BlobBackend, bounds?: FileSnapshotBounds);
|
|
11
|
-
private putBlobRow;
|
|
12
|
-
putBlob(hash: string, bytes: Uint8Array): Promise<FileSnapshotResult>;
|
|
13
|
-
snapshot(scope: string, key: string, env: ExecutionEnv, root: string, signal?: AbortSignal): Promise<FileSnapshotResult>;
|
|
14
|
-
importManifest(scope: string, key: string, manifest: Map<string, string>, srcGetBlob: (hash: string) => Promise<Uint8Array | undefined>): Promise<FileSnapshotResult>;
|
|
15
|
-
restore(scope: string, key: string, env: ExecutionEnv, root: string, signal?: AbortSignal): Promise<FileSnapshotResult>;
|
|
16
|
-
has(scope: string, key: string): Promise<boolean>;
|
|
17
|
-
listKeys(scope: string): Promise<string[]>;
|
|
18
|
-
exportManifest(scope: string, key: string): Promise<Map<string, string> | null>;
|
|
19
|
-
getBlob(hash: string): Promise<Uint8Array | undefined>;
|
|
20
|
-
hasBlobs(hashes: string[]): Promise<Set<string>>;
|
|
21
|
-
blobSizes(hashes: string[]): Promise<Map<string, number>>;
|
|
22
|
-
reap(scope: string, keepKeys: string[]): Promise<number>;
|
|
23
|
-
deleteBySession(scope: string): Promise<number>;
|
|
24
|
-
private gcOrphanBlobs;
|
|
25
|
-
sweepOrphanBlobs(): Promise<number>;
|
|
26
|
-
private tx;
|
|
27
|
-
}
|
|
1
|
+
export { PgFileSnapshotStore } from "./file-snapshot-store-sql.js";
|
|
28
2
|
//# sourceMappingURL=pg-file-snapshot-store.d.ts.map
|
|
@@ -1,191 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
import { createHash } from "node:crypto";
|
|
3
|
-
import { SqlBlobBackend, sqlBlobSizes } from "./blob-backend.js";
|
|
4
|
-
export class PgFileSnapshotStore {
|
|
5
|
-
pool;
|
|
6
|
-
bounds;
|
|
7
|
-
inFlight = new Set();
|
|
8
|
-
blobs;
|
|
9
|
-
onSkippedVanished = undefined;
|
|
10
|
-
constructor(pool, blobBackend, bounds = DEFAULT_SNAPSHOT_BOUNDS) {
|
|
11
|
-
this.pool = pool;
|
|
12
|
-
this.bounds = bounds;
|
|
13
|
-
this.blobs = blobBackend ?? new SqlBlobBackend("pg", pool);
|
|
14
|
-
}
|
|
15
|
-
async putBlobRow(hash, bytes) {
|
|
16
|
-
await this.blobs.putBlob(hash, bytes);
|
|
17
|
-
}
|
|
18
|
-
async putBlob(hash, bytes) {
|
|
19
|
-
if (createHash("sha256").update(bytes).digest("hex") !== hash) {
|
|
20
|
-
return { ok: false, error: { code: "read_failed", message: `putBlob ${hash} fails content-address integrity — nothing stored` } };
|
|
21
|
-
}
|
|
22
|
-
try {
|
|
23
|
-
await this.putBlobRow(hash, bytes);
|
|
24
|
-
return { ok: true };
|
|
25
|
-
}
|
|
26
|
-
catch (err) {
|
|
27
|
-
return { ok: false, error: { code: "restore_failed", message: `putBlob ${hash} write/upload failed: ${err.message}` } };
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
async snapshot(scope, key, env, root, signal) {
|
|
31
|
-
const flightKey = `${scope} ${key}`;
|
|
32
|
-
if (this.inFlight.has(flightKey))
|
|
33
|
-
return { ok: true };
|
|
34
|
-
this.inFlight.add(flightKey);
|
|
35
|
-
try {
|
|
36
|
-
if (await this.has(scope, key))
|
|
37
|
-
return { ok: true };
|
|
38
|
-
let cap;
|
|
39
|
-
try {
|
|
40
|
-
cap = await captureManifest(env, root, this.bounds, signal, async (hash, bytes) => {
|
|
41
|
-
await this.putBlobRow(hash, bytes);
|
|
42
|
-
});
|
|
43
|
-
}
|
|
44
|
-
catch (err) {
|
|
45
|
-
return { ok: false, error: { code: "restore_failed", message: `snapshot blob write failed: ${err.message}` } };
|
|
46
|
-
}
|
|
47
|
-
if (!cap.ok)
|
|
48
|
-
return { ok: false, error: cap.error };
|
|
49
|
-
if (cap.skippedVanished > 0 && this.onSkippedVanished) {
|
|
50
|
-
try {
|
|
51
|
-
void Promise.resolve(this.onSkippedVanished(cap.skippedVanished)).catch(() => { });
|
|
52
|
-
}
|
|
53
|
-
catch { }
|
|
54
|
-
}
|
|
55
|
-
await this.tx(async (c) => {
|
|
56
|
-
const exists = await c.query("SELECT 1 FROM snapshot_manifest WHERE scope = $1 AND snap_key = $2 LIMIT 1", [scope, key]);
|
|
57
|
-
if (exists.rows[0])
|
|
58
|
-
return;
|
|
59
|
-
for (const [relPath, hash] of cap.value) {
|
|
60
|
-
await c.query("INSERT INTO snapshot_manifest (scope, snap_key, rel_path, blob_hash) VALUES ($1,$2,$3,$4)", [scope, key, relPath, hash]);
|
|
61
|
-
}
|
|
62
|
-
});
|
|
63
|
-
return { ok: true };
|
|
64
|
-
}
|
|
65
|
-
catch (err) {
|
|
66
|
-
return { ok: false, error: { code: "restore_failed", message: `snapshot persist failed: ${err.message}` } };
|
|
67
|
-
}
|
|
68
|
-
finally {
|
|
69
|
-
this.inFlight.delete(flightKey);
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
async importManifest(scope, key, manifest, srcGetBlob) {
|
|
73
|
-
const flightKey = `${scope} ${key}`;
|
|
74
|
-
if (this.inFlight.has(flightKey))
|
|
75
|
-
return { ok: true };
|
|
76
|
-
this.inFlight.add(flightKey);
|
|
77
|
-
try {
|
|
78
|
-
if (await this.has(scope, key))
|
|
79
|
-
return { ok: true };
|
|
80
|
-
for (const hash of new Set(manifest.values())) {
|
|
81
|
-
let bytes;
|
|
82
|
-
try {
|
|
83
|
-
bytes = await srcGetBlob(hash);
|
|
84
|
-
}
|
|
85
|
-
catch (err) {
|
|
86
|
-
return { ok: false, error: { code: "read_failed", message: `source blob ${hash} fetch failed: ${err.message}` } };
|
|
87
|
-
}
|
|
88
|
-
if (!bytes)
|
|
89
|
-
return { ok: false, error: { code: "read_failed", message: `missing source blob ${hash}` } };
|
|
90
|
-
if (createHash("sha256").update(bytes).digest("hex") !== hash) {
|
|
91
|
-
return { ok: false, error: { code: "read_failed", message: `source blob ${hash} fails content-address integrity` } };
|
|
92
|
-
}
|
|
93
|
-
await this.putBlobRow(hash, bytes);
|
|
94
|
-
}
|
|
95
|
-
await this.tx(async (c) => {
|
|
96
|
-
const exists = await c.query("SELECT 1 FROM snapshot_manifest WHERE scope = $1 AND snap_key = $2 LIMIT 1", [scope, key]);
|
|
97
|
-
if (exists.rows[0])
|
|
98
|
-
return;
|
|
99
|
-
for (const [relPath, hash] of manifest) {
|
|
100
|
-
await c.query("INSERT INTO snapshot_manifest (scope, snap_key, rel_path, blob_hash) VALUES ($1,$2,$3,$4)", [scope, key, relPath, hash]);
|
|
101
|
-
}
|
|
102
|
-
});
|
|
103
|
-
return { ok: true };
|
|
104
|
-
}
|
|
105
|
-
catch (err) {
|
|
106
|
-
return { ok: false, error: { code: "restore_failed", message: `import persist failed: ${err.message}` } };
|
|
107
|
-
}
|
|
108
|
-
finally {
|
|
109
|
-
this.inFlight.delete(flightKey);
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
async restore(scope, key, env, root, signal) {
|
|
113
|
-
try {
|
|
114
|
-
const r = await this.pool.query("SELECT rel_path, blob_hash FROM snapshot_manifest WHERE scope = $1 AND snap_key = $2", [scope, key]);
|
|
115
|
-
if (r.rows.length === 0)
|
|
116
|
-
return { ok: false, error: { code: "not_found", message: `no file snapshot for ${scope}/${key}` } };
|
|
117
|
-
const manifest = new Map(r.rows.map((row) => [row.rel_path, row.blob_hash]));
|
|
118
|
-
return await applyManifest(env, root, this.bounds, signal, manifest, (hash) => this.blobs.getBlob(hash));
|
|
119
|
-
}
|
|
120
|
-
catch (err) {
|
|
121
|
-
return { ok: false, error: { code: "restore_failed", message: `restore blob read failed: ${err.message}` } };
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
async has(scope, key) {
|
|
125
|
-
const r = await this.pool.query("SELECT 1 FROM snapshot_manifest WHERE scope = $1 AND snap_key = $2 LIMIT 1", [scope, key]);
|
|
126
|
-
return Boolean(r.rows[0]);
|
|
127
|
-
}
|
|
128
|
-
async listKeys(scope) {
|
|
129
|
-
const r = await this.pool.query("SELECT DISTINCT snap_key FROM snapshot_manifest WHERE scope = $1", [scope]);
|
|
130
|
-
return r.rows.map((row) => row.snap_key);
|
|
131
|
-
}
|
|
132
|
-
async exportManifest(scope, key) {
|
|
133
|
-
const r = await this.pool.query("SELECT rel_path, blob_hash FROM snapshot_manifest WHERE scope = $1 AND snap_key = $2", [scope, key]);
|
|
134
|
-
if (r.rows.length === 0)
|
|
135
|
-
return null;
|
|
136
|
-
return new Map(r.rows.map((row) => [row.rel_path, row.blob_hash]));
|
|
137
|
-
}
|
|
138
|
-
async getBlob(hash) {
|
|
139
|
-
return this.blobs.getBlob(hash);
|
|
140
|
-
}
|
|
141
|
-
async hasBlobs(hashes) {
|
|
142
|
-
return this.blobs.hasBlobs(hashes);
|
|
143
|
-
}
|
|
144
|
-
async blobSizes(hashes) {
|
|
145
|
-
return sqlBlobSizes("pg", this.pool, hashes);
|
|
146
|
-
}
|
|
147
|
-
async reap(scope, keepKeys) {
|
|
148
|
-
return this.tx(async (c) => {
|
|
149
|
-
const keys = await c.query("SELECT DISTINCT snap_key FROM snapshot_manifest WHERE scope = $1", [scope]);
|
|
150
|
-
const drop = keys.rows.map((k) => k.snap_key).filter((k) => !keepKeys.includes(k));
|
|
151
|
-
for (const k of drop)
|
|
152
|
-
await c.query("DELETE FROM snapshot_manifest WHERE scope = $1 AND snap_key = $2", [scope, k]);
|
|
153
|
-
return drop.length;
|
|
154
|
-
});
|
|
155
|
-
}
|
|
156
|
-
async deleteBySession(scope) {
|
|
157
|
-
const r = await this.pool.query("DELETE FROM snapshot_manifest WHERE scope = $1", [scope]);
|
|
158
|
-
return r.rowCount ?? 0;
|
|
159
|
-
}
|
|
160
|
-
async gcOrphanBlobs() {
|
|
161
|
-
const r = await this.pool.query("SELECT blob_hash FROM snapshot_blob WHERE blob_hash NOT IN (SELECT blob_hash FROM snapshot_manifest)").catch(() => undefined);
|
|
162
|
-
const orphans = (r?.rows ?? []).map((row) => row.blob_hash);
|
|
163
|
-
if (orphans.length === 0)
|
|
164
|
-
return 0;
|
|
165
|
-
return this.blobs.deleteBlobs(orphans);
|
|
166
|
-
}
|
|
167
|
-
async sweepOrphanBlobs() {
|
|
168
|
-
return this.gcOrphanBlobs();
|
|
169
|
-
}
|
|
170
|
-
async tx(fn) {
|
|
171
|
-
const c = await this.pool.connect();
|
|
172
|
-
try {
|
|
173
|
-
await c.query("BEGIN");
|
|
174
|
-
const out = await fn(c);
|
|
175
|
-
await c.query("COMMIT");
|
|
176
|
-
return out;
|
|
177
|
-
}
|
|
178
|
-
catch (err) {
|
|
179
|
-
try {
|
|
180
|
-
await c.query("ROLLBACK");
|
|
181
|
-
}
|
|
182
|
-
catch {
|
|
183
|
-
}
|
|
184
|
-
throw err;
|
|
185
|
-
}
|
|
186
|
-
finally {
|
|
187
|
-
c.release();
|
|
188
|
-
}
|
|
189
|
-
}
|
|
190
|
-
}
|
|
1
|
+
export { PgFileSnapshotStore } from "./file-snapshot-store-sql.js";
|
|
191
2
|
//# sourceMappingURL=pg-file-snapshot-store.js.map
|
|
@@ -1,23 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
import { type ImageStatus, type ImageIndexEntry, type ImageIndexUpsert, type ImageViewer, type ImageListFilter } from "./store-contracts.js";
|
|
1
|
+
export { PgImageIndex, PG_IMAGE_INDEX_SCHEMA, ensureSchema } from "./image-index-sql.js";
|
|
3
2
|
export type { ImageNestedBuildMode, ImageCapabilities, ImagePodContract, ImageStatus, ImageVisibility, ImageIndexEntry, ImageIndexUpsert, ImageViewer, ImageListFilter, } from "./store-contracts.js";
|
|
4
|
-
export declare const PG_IMAGE_INDEX_SCHEMA: string[];
|
|
5
|
-
export declare function ensureSchema(pool: Pool | PoolClient): Promise<void>;
|
|
6
|
-
export declare class PgImageIndex {
|
|
7
|
-
private readonly pool;
|
|
8
|
-
constructor(pool: Pool);
|
|
9
|
-
static idFor(repo: string, digest: string): string;
|
|
10
|
-
upsert(e: ImageIndexUpsert): Promise<string>;
|
|
11
|
-
registerBuilding(e: ImageIndexUpsert): Promise<string>;
|
|
12
|
-
getById(id: string): Promise<ImageIndexEntry | null>;
|
|
13
|
-
getByDigest(digest: string): Promise<ImageIndexEntry | null>;
|
|
14
|
-
latestPublished(profile: string, viewer: ImageViewer): Promise<ImageIndexEntry | null>;
|
|
15
|
-
list(filter: ImageListFilter): Promise<{
|
|
16
|
-
entries: ImageIndexEntry[];
|
|
17
|
-
nextCursor: string | null;
|
|
18
|
-
}>;
|
|
19
|
-
setStatus(id: string, status: ImageStatus, opts?: {
|
|
20
|
-
supersedes?: string | null;
|
|
21
|
-
}): Promise<void>;
|
|
22
|
-
}
|
|
23
3
|
//# sourceMappingURL=pg-image-index.d.ts.map
|