@sema-agent/server 1.315.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.
- 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 +67 -0
- package/dist/http/route-ctx.js +2 -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/images.d.ts +20 -0
- package/dist/http/routes/images.js +572 -0
- package/dist/http/routes/memory-policy.d.ts +4 -0
- package/dist/http/routes/memory-policy.js +105 -0
- package/dist/http/routes/observability.d.ts +4 -0
- package/dist/http/routes/observability.js +63 -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/send.d.ts +6 -0
- package/dist/http/send.js +19 -0
- package/dist/http/server.d.ts +6 -7
- package/dist/http/server.js +125 -2413
- package/dist/http/sse-log.d.ts +25 -0
- package/dist/http/sse-log.js +59 -0
- package/dist/http/workspace-content.d.ts +3 -0
- package/dist/http/workspace-content.js +20 -0
- 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/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/package.json +1 -1
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { Pool as MySqlPool } from "mysql2/promise";
|
|
2
|
+
import type { Pool as PgPool, PoolClient } from "pg";
|
|
3
|
+
import { type ImageStatus, type ImageIndexEntry, type ImageIndexUpsert, type ImageViewer, type ImageListFilter } from "./store-contracts.js";
|
|
4
|
+
import { type SqlDriver } from "./sql-driver.js";
|
|
5
|
+
export type { ImageNestedBuildMode, ImageCapabilities, ImagePodContract, ImageStatus, ImageVisibility, ImageIndexEntry, ImageIndexUpsert, ImageViewer, ImageListFilter, ImageRow, } from "./store-contracts.js";
|
|
6
|
+
export { mapImageRow as mapRow } from "./store-contracts.js";
|
|
7
|
+
export declare const PG_IMAGE_INDEX_SCHEMA: string[];
|
|
8
|
+
export declare function ensureSchema(pool: PgPool | PoolClient): Promise<void>;
|
|
9
|
+
export declare class SqlImageIndex {
|
|
10
|
+
protected readonly db: SqlDriver;
|
|
11
|
+
constructor(db: SqlDriver);
|
|
12
|
+
private q;
|
|
13
|
+
static idFor(repo: string, digest: string): string;
|
|
14
|
+
upsert(e: ImageIndexUpsert): Promise<string>;
|
|
15
|
+
registerBuilding(e: ImageIndexUpsert): Promise<string>;
|
|
16
|
+
getById(id: string): Promise<ImageIndexEntry | null>;
|
|
17
|
+
getByDigest(digest: string): Promise<ImageIndexEntry | null>;
|
|
18
|
+
latestPublished(profile: string, viewer: ImageViewer): Promise<ImageIndexEntry | null>;
|
|
19
|
+
list(filter: ImageListFilter): Promise<{
|
|
20
|
+
entries: ImageIndexEntry[];
|
|
21
|
+
nextCursor: string | null;
|
|
22
|
+
}>;
|
|
23
|
+
setStatus(id: string, status: ImageStatus, opts?: {
|
|
24
|
+
supersedes?: string | null;
|
|
25
|
+
}): Promise<void>;
|
|
26
|
+
}
|
|
27
|
+
export declare class TiDBImageIndex extends SqlImageIndex {
|
|
28
|
+
constructor(pool: MySqlPool);
|
|
29
|
+
}
|
|
30
|
+
export declare class PgImageIndex extends SqlImageIndex {
|
|
31
|
+
constructor(pool: PgPool);
|
|
32
|
+
}
|
|
33
|
+
//# sourceMappingURL=image-index-sql.d.ts.map
|
|
@@ -0,0 +1,328 @@
|
|
|
1
|
+
import { createHash } from "node:crypto";
|
|
2
|
+
import { pgSafeJsonStringify, pgSanitizeText, pgHasUnstorable, PgUnstorableError } from "./pg-safe-json.js";
|
|
3
|
+
import { mapImageRow as mapRow, } from "./store-contracts.js";
|
|
4
|
+
import { mysqlDriver, pgDriver } from "./sql-driver.js";
|
|
5
|
+
export { mapImageRow as mapRow } from "./store-contracts.js";
|
|
6
|
+
export const PG_IMAGE_INDEX_SCHEMA = [
|
|
7
|
+
`CREATE TABLE IF NOT EXISTS sandbox_image_index (
|
|
8
|
+
id VARCHAR(64) NOT NULL,
|
|
9
|
+
profile VARCHAR(64) NOT NULL,
|
|
10
|
+
bands JSONB,
|
|
11
|
+
repo VARCHAR(255) NOT NULL,
|
|
12
|
+
tag VARCHAR(128) NOT NULL,
|
|
13
|
+
digest VARCHAR(80) NOT NULL,
|
|
14
|
+
toolchain_versions JSONB,
|
|
15
|
+
capabilities JSONB,
|
|
16
|
+
pod_contract JSONB,
|
|
17
|
+
size_bytes BIGINT,
|
|
18
|
+
status VARCHAR(16) NOT NULL DEFAULT 'building',
|
|
19
|
+
visibility VARCHAR(16) NOT NULL DEFAULT 'public',
|
|
20
|
+
tenant_id VARCHAR(64),
|
|
21
|
+
manifest_sha VARCHAR(64),
|
|
22
|
+
recipe_git_sha VARCHAR(64),
|
|
23
|
+
generator_version VARCHAR(32),
|
|
24
|
+
build_date TIMESTAMPTZ(3),
|
|
25
|
+
supersedes VARCHAR(64),
|
|
26
|
+
signed SMALLINT NOT NULL DEFAULT 0,
|
|
27
|
+
created_at TIMESTAMPTZ(3) NOT NULL,
|
|
28
|
+
updated_at TIMESTAMPTZ(3) NOT NULL,
|
|
29
|
+
PRIMARY KEY (id)
|
|
30
|
+
)`,
|
|
31
|
+
`CREATE UNIQUE INDEX IF NOT EXISTS uq_repo_digest ON sandbox_image_index (repo, digest)`,
|
|
32
|
+
`CREATE INDEX IF NOT EXISTS idx_profile_status ON sandbox_image_index (profile, status, visibility)`,
|
|
33
|
+
`CREATE INDEX IF NOT EXISTS idx_digest ON sandbox_image_index (digest)`,
|
|
34
|
+
`CREATE INDEX IF NOT EXISTS idx_tenant ON sandbox_image_index (tenant_id, status)`,
|
|
35
|
+
];
|
|
36
|
+
export async function ensureSchema(pool) {
|
|
37
|
+
for (const stmt of PG_IMAGE_INDEX_SCHEMA)
|
|
38
|
+
await pool.query(stmt);
|
|
39
|
+
}
|
|
40
|
+
const MAX_LIMIT = 200;
|
|
41
|
+
const DEFAULT_LIMIT = 50;
|
|
42
|
+
function visibilityClauseTidb(viewer) {
|
|
43
|
+
if (viewer.operator)
|
|
44
|
+
return { sql: "1=1", params: [] };
|
|
45
|
+
if (viewer.tenantId)
|
|
46
|
+
return { sql: "(visibility='public' OR tenant_id=?)", params: [viewer.tenantId] };
|
|
47
|
+
return { sql: "visibility='public'", params: [] };
|
|
48
|
+
}
|
|
49
|
+
function visibilityClausePg(viewer, startIdx) {
|
|
50
|
+
if (viewer.operator)
|
|
51
|
+
return { sql: "1=1", params: [], nextIdx: startIdx };
|
|
52
|
+
if (viewer.tenantId)
|
|
53
|
+
return {
|
|
54
|
+
sql: `(visibility = 'public' OR tenant_id = $${startIdx})`,
|
|
55
|
+
params: [viewer.tenantId],
|
|
56
|
+
nextIdx: startIdx + 1,
|
|
57
|
+
};
|
|
58
|
+
return { sql: "visibility = 'public'", params: [], nextIdx: startIdx };
|
|
59
|
+
}
|
|
60
|
+
function encodeCursor(e) {
|
|
61
|
+
return Buffer.from(`${e.createdAt}|${e.id}`, "utf8").toString("base64url");
|
|
62
|
+
}
|
|
63
|
+
function decodeCursor(c) {
|
|
64
|
+
try {
|
|
65
|
+
const [createdAt, id] = Buffer.from(c, "base64url").toString("utf8").split("|");
|
|
66
|
+
if (!createdAt || !id)
|
|
67
|
+
return null;
|
|
68
|
+
return { createdAt, id };
|
|
69
|
+
}
|
|
70
|
+
catch {
|
|
71
|
+
return null;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
function tidbUpsertParams(e, id, now) {
|
|
75
|
+
return [
|
|
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
|
+
}
|
|
84
|
+
const PG_UPSERT_COLS = "(id, profile, bands, repo, tag, digest, toolchain_versions, capabilities, pod_contract, size_bytes, " +
|
|
85
|
+
"status, visibility, tenant_id, manifest_sha, recipe_git_sha, generator_version, build_date, supersedes, " +
|
|
86
|
+
"signed, created_at, updated_at)";
|
|
87
|
+
const PG_UPSERT_VALUES = "($1,$2,$3::jsonb,$4,$5,$6,$7::jsonb,$8::jsonb,$9::jsonb,$10,$11,$12,$13,$14,$15,$16,$17,$18,$19,$20,$21)";
|
|
88
|
+
function pgUpsertParams(e, id, now) {
|
|
89
|
+
return [
|
|
90
|
+
id,
|
|
91
|
+
pgSanitizeText(e.profile),
|
|
92
|
+
pgSafeJsonStringify(e.bands ?? []),
|
|
93
|
+
e.repo,
|
|
94
|
+
pgSanitizeText(e.tag),
|
|
95
|
+
e.digest,
|
|
96
|
+
pgSafeJsonStringify(e.toolchainVersions ?? {}),
|
|
97
|
+
pgSafeJsonStringify(e.capabilities ?? {}),
|
|
98
|
+
pgSafeJsonStringify(e.podContract ?? {}),
|
|
99
|
+
e.sizeBytes,
|
|
100
|
+
e.status,
|
|
101
|
+
e.visibility,
|
|
102
|
+
e.tenantId ?? null,
|
|
103
|
+
e.manifestSha ?? null,
|
|
104
|
+
e.recipeGitSha == null ? null : pgSanitizeText(e.recipeGitSha),
|
|
105
|
+
e.generatorVersion == null ? null : pgSanitizeText(e.generatorVersion),
|
|
106
|
+
e.buildDate ? new Date(e.buildDate) : null,
|
|
107
|
+
e.supersedes == null ? null : pgSanitizeText(e.supersedes),
|
|
108
|
+
e.signed ? 1 : 0,
|
|
109
|
+
now,
|
|
110
|
+
now,
|
|
111
|
+
];
|
|
112
|
+
}
|
|
113
|
+
export class SqlImageIndex {
|
|
114
|
+
db;
|
|
115
|
+
constructor(db) {
|
|
116
|
+
this.db = db;
|
|
117
|
+
}
|
|
118
|
+
q(tidb, pg) {
|
|
119
|
+
return this.db.dialect === "tidb" ? tidb : pg;
|
|
120
|
+
}
|
|
121
|
+
static idFor(repo, digest) {
|
|
122
|
+
return createHash("sha256").update(`${repo}@${digest}`).digest("hex").slice(0, 64);
|
|
123
|
+
}
|
|
124
|
+
async upsert(e) {
|
|
125
|
+
if (this.db.dialect === "pg") {
|
|
126
|
+
if (pgHasUnstorable(e.repo))
|
|
127
|
+
throw new PgUnstorableError("image repo (identity)");
|
|
128
|
+
if (e.tenantId != null && pgHasUnstorable(e.tenantId))
|
|
129
|
+
throw new PgUnstorableError("image tenantId (identity)");
|
|
130
|
+
}
|
|
131
|
+
const id = SqlImageIndex.idFor(e.repo, e.digest);
|
|
132
|
+
const now = new Date();
|
|
133
|
+
await this.db.query(this.q(`INSERT INTO sandbox_image_index
|
|
134
|
+
(id, profile, bands, repo, tag, digest, toolchain_versions, capabilities, pod_contract, size_bytes,
|
|
135
|
+
status, visibility, tenant_id, manifest_sha, recipe_git_sha, generator_version, build_date, supersedes,
|
|
136
|
+
signed, created_at, updated_at)
|
|
137
|
+
VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)
|
|
138
|
+
ON DUPLICATE KEY UPDATE
|
|
139
|
+
profile=VALUES(profile), bands=VALUES(bands), tag=VALUES(tag), toolchain_versions=VALUES(toolchain_versions),
|
|
140
|
+
capabilities=VALUES(capabilities), pod_contract=VALUES(pod_contract), size_bytes=VALUES(size_bytes),
|
|
141
|
+
status=VALUES(status), visibility=VALUES(visibility), tenant_id=VALUES(tenant_id),
|
|
142
|
+
manifest_sha=VALUES(manifest_sha), recipe_git_sha=VALUES(recipe_git_sha),
|
|
143
|
+
generator_version=VALUES(generator_version), build_date=VALUES(build_date), supersedes=VALUES(supersedes),
|
|
144
|
+
signed=VALUES(signed), updated_at=VALUES(updated_at)`, `INSERT INTO sandbox_image_index ${PG_UPSERT_COLS}
|
|
145
|
+
VALUES ${PG_UPSERT_VALUES}
|
|
146
|
+
ON CONFLICT (id) DO UPDATE SET
|
|
147
|
+
profile = EXCLUDED.profile, bands = EXCLUDED.bands, tag = EXCLUDED.tag,
|
|
148
|
+
toolchain_versions = EXCLUDED.toolchain_versions, capabilities = EXCLUDED.capabilities,
|
|
149
|
+
pod_contract = EXCLUDED.pod_contract, size_bytes = EXCLUDED.size_bytes,
|
|
150
|
+
status = EXCLUDED.status, visibility = EXCLUDED.visibility, tenant_id = EXCLUDED.tenant_id,
|
|
151
|
+
manifest_sha = EXCLUDED.manifest_sha, recipe_git_sha = EXCLUDED.recipe_git_sha,
|
|
152
|
+
generator_version = EXCLUDED.generator_version, build_date = EXCLUDED.build_date,
|
|
153
|
+
supersedes = EXCLUDED.supersedes, signed = EXCLUDED.signed, updated_at = EXCLUDED.updated_at`), this.db.dialect === "tidb" ? tidbUpsertParams(e, id, now) : pgUpsertParams(e, id, now));
|
|
154
|
+
return id;
|
|
155
|
+
}
|
|
156
|
+
async registerBuilding(e) {
|
|
157
|
+
if (this.db.dialect === "pg") {
|
|
158
|
+
if (pgHasUnstorable(e.repo))
|
|
159
|
+
throw new PgUnstorableError("image repo (identity)");
|
|
160
|
+
if (e.tenantId != null && pgHasUnstorable(e.tenantId))
|
|
161
|
+
throw new PgUnstorableError("image tenantId (identity)");
|
|
162
|
+
}
|
|
163
|
+
const id = SqlImageIndex.idFor(e.repo, e.digest);
|
|
164
|
+
const now = new Date();
|
|
165
|
+
await this.db.query(this.q(`INSERT INTO sandbox_image_index
|
|
166
|
+
(id, profile, bands, repo, tag, digest, toolchain_versions, capabilities, pod_contract, size_bytes,
|
|
167
|
+
status, visibility, tenant_id, manifest_sha, recipe_git_sha, generator_version, build_date, supersedes,
|
|
168
|
+
signed, created_at, updated_at)
|
|
169
|
+
VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)
|
|
170
|
+
ON DUPLICATE KEY UPDATE
|
|
171
|
+
profile=VALUES(profile), bands=VALUES(bands), tag=VALUES(tag), toolchain_versions=VALUES(toolchain_versions),
|
|
172
|
+
capabilities=VALUES(capabilities), pod_contract=VALUES(pod_contract), size_bytes=VALUES(size_bytes),
|
|
173
|
+
status=IF(sandbox_image_index.status='published', sandbox_image_index.status, VALUES(status)),
|
|
174
|
+
visibility=IF(sandbox_image_index.status='published', sandbox_image_index.visibility, VALUES(visibility)),
|
|
175
|
+
tenant_id=IF(sandbox_image_index.status='published', sandbox_image_index.tenant_id, VALUES(tenant_id)),
|
|
176
|
+
manifest_sha=VALUES(manifest_sha), recipe_git_sha=VALUES(recipe_git_sha),
|
|
177
|
+
generator_version=VALUES(generator_version), build_date=VALUES(build_date), supersedes=VALUES(supersedes),
|
|
178
|
+
signed=IF(sandbox_image_index.status='published', sandbox_image_index.signed, VALUES(signed)), updated_at=VALUES(updated_at)`, `INSERT INTO sandbox_image_index ${PG_UPSERT_COLS}
|
|
179
|
+
VALUES ${PG_UPSERT_VALUES}
|
|
180
|
+
ON CONFLICT (id) DO UPDATE SET
|
|
181
|
+
profile = EXCLUDED.profile, bands = EXCLUDED.bands, tag = EXCLUDED.tag,
|
|
182
|
+
toolchain_versions = EXCLUDED.toolchain_versions, capabilities = EXCLUDED.capabilities,
|
|
183
|
+
pod_contract = EXCLUDED.pod_contract, size_bytes = EXCLUDED.size_bytes,
|
|
184
|
+
status = CASE WHEN sandbox_image_index.status = 'published'
|
|
185
|
+
THEN sandbox_image_index.status ELSE EXCLUDED.status END,
|
|
186
|
+
visibility = CASE WHEN sandbox_image_index.status = 'published'
|
|
187
|
+
THEN sandbox_image_index.visibility ELSE EXCLUDED.visibility END,
|
|
188
|
+
tenant_id = CASE WHEN sandbox_image_index.status = 'published'
|
|
189
|
+
THEN sandbox_image_index.tenant_id ELSE EXCLUDED.tenant_id END,
|
|
190
|
+
manifest_sha = EXCLUDED.manifest_sha, recipe_git_sha = EXCLUDED.recipe_git_sha,
|
|
191
|
+
generator_version = EXCLUDED.generator_version, build_date = EXCLUDED.build_date,
|
|
192
|
+
supersedes = EXCLUDED.supersedes,
|
|
193
|
+
signed = CASE WHEN sandbox_image_index.status = 'published'
|
|
194
|
+
THEN sandbox_image_index.signed ELSE EXCLUDED.signed END,
|
|
195
|
+
updated_at = EXCLUDED.updated_at`), this.db.dialect === "tidb" ? tidbUpsertParams(e, id, now) : pgUpsertParams(e, id, now));
|
|
196
|
+
return id;
|
|
197
|
+
}
|
|
198
|
+
async getById(id) {
|
|
199
|
+
const { rows } = await this.db.query(this.q("SELECT * FROM sandbox_image_index WHERE id=? LIMIT 1", "SELECT * FROM sandbox_image_index WHERE id = $1 LIMIT 1"), [id]);
|
|
200
|
+
return rows[0] ? mapRow(rows[0]) : null;
|
|
201
|
+
}
|
|
202
|
+
async getByDigest(digest) {
|
|
203
|
+
const { rows } = await this.db.query(this.q("SELECT * FROM sandbox_image_index WHERE digest=? ORDER BY updated_at DESC LIMIT 1", "SELECT * FROM sandbox_image_index WHERE digest = $1 ORDER BY updated_at DESC LIMIT 1"), [digest]);
|
|
204
|
+
return rows[0] ? mapRow(rows[0]) : null;
|
|
205
|
+
}
|
|
206
|
+
async latestPublished(profile, viewer) {
|
|
207
|
+
if (this.db.dialect === "tidb") {
|
|
208
|
+
const vis = visibilityClauseTidb(viewer);
|
|
209
|
+
const { rows } = await this.db.query(`SELECT * FROM sandbox_image_index
|
|
210
|
+
WHERE profile=? AND status='published' AND ${vis.sql}
|
|
211
|
+
ORDER BY (build_date IS NULL), build_date DESC, created_at DESC LIMIT 1`, [profile, ...vis.params]);
|
|
212
|
+
return rows[0] ? mapRow(rows[0]) : null;
|
|
213
|
+
}
|
|
214
|
+
const vis = visibilityClausePg(viewer, 2);
|
|
215
|
+
const { rows } = await this.db.query(`SELECT * FROM sandbox_image_index
|
|
216
|
+
WHERE profile = $1 AND status = 'published' AND ${vis.sql}
|
|
217
|
+
ORDER BY build_date DESC NULLS LAST, created_at DESC LIMIT 1`, [profile, ...vis.params]);
|
|
218
|
+
return rows[0] ? mapRow(rows[0]) : null;
|
|
219
|
+
}
|
|
220
|
+
async list(filter) {
|
|
221
|
+
const limit = Math.min(Math.max(1, filter.limit ?? DEFAULT_LIMIT), MAX_LIMIT);
|
|
222
|
+
let rawRows;
|
|
223
|
+
if (this.db.dialect === "tidb") {
|
|
224
|
+
const vis = visibilityClauseTidb(filter);
|
|
225
|
+
const where = [vis.sql];
|
|
226
|
+
const params = [...vis.params];
|
|
227
|
+
if (filter.profile) {
|
|
228
|
+
where.push("profile=?");
|
|
229
|
+
params.push(filter.profile);
|
|
230
|
+
}
|
|
231
|
+
if (filter.status) {
|
|
232
|
+
where.push("status=?");
|
|
233
|
+
params.push(filter.status);
|
|
234
|
+
}
|
|
235
|
+
if (filter.capability) {
|
|
236
|
+
where.push("JSON_EXTRACT(capabilities, ?) = true");
|
|
237
|
+
params.push(`$.${filter.capability}`);
|
|
238
|
+
}
|
|
239
|
+
if (filter.cursor) {
|
|
240
|
+
const c = decodeCursor(filter.cursor);
|
|
241
|
+
if (c) {
|
|
242
|
+
where.push("(created_at < ? OR (created_at = ? AND id < ?))");
|
|
243
|
+
params.push(new Date(c.createdAt), new Date(c.createdAt), c.id);
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
const sql = `SELECT * FROM sandbox_image_index WHERE ${where.join(" AND ")} ` +
|
|
247
|
+
`ORDER BY created_at DESC, id DESC LIMIT ?`;
|
|
248
|
+
const { rows } = await this.db.query(sql, [...params, limit + 1]);
|
|
249
|
+
rawRows = rows;
|
|
250
|
+
}
|
|
251
|
+
else {
|
|
252
|
+
const vis = visibilityClausePg(filter, 1);
|
|
253
|
+
const where = [vis.sql];
|
|
254
|
+
const params = [...vis.params];
|
|
255
|
+
let idx = vis.nextIdx;
|
|
256
|
+
if (filter.profile) {
|
|
257
|
+
where.push(`profile = $${idx++}`);
|
|
258
|
+
params.push(filter.profile);
|
|
259
|
+
}
|
|
260
|
+
if (filter.status) {
|
|
261
|
+
where.push(`status = $${idx++}`);
|
|
262
|
+
params.push(filter.status);
|
|
263
|
+
}
|
|
264
|
+
if (filter.capability) {
|
|
265
|
+
where.push(`capabilities -> $${idx++} = 'true'::jsonb`);
|
|
266
|
+
params.push(filter.capability);
|
|
267
|
+
}
|
|
268
|
+
if (filter.cursor) {
|
|
269
|
+
const c = decodeCursor(filter.cursor);
|
|
270
|
+
if (c) {
|
|
271
|
+
where.push(`(created_at < $${idx} OR (created_at = $${idx + 1} AND id < $${idx + 2}))`);
|
|
272
|
+
params.push(new Date(c.createdAt), new Date(c.createdAt), c.id);
|
|
273
|
+
idx += 3;
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
const sql = `SELECT * FROM sandbox_image_index WHERE ${where.join(" AND ")} ` +
|
|
277
|
+
`ORDER BY created_at DESC, id DESC LIMIT $${idx}`;
|
|
278
|
+
params.push(limit + 1);
|
|
279
|
+
const { rows } = await this.db.query(sql, params);
|
|
280
|
+
rawRows = rows;
|
|
281
|
+
}
|
|
282
|
+
let entries = rawRows.map(mapRow);
|
|
283
|
+
let nextCursor = null;
|
|
284
|
+
if (entries.length > limit) {
|
|
285
|
+
entries = entries.slice(0, limit);
|
|
286
|
+
const last = entries[entries.length - 1];
|
|
287
|
+
nextCursor = encodeCursor({ createdAt: last.createdAt, id: last.id });
|
|
288
|
+
}
|
|
289
|
+
if (filter.latestOnly) {
|
|
290
|
+
const seen = new Set();
|
|
291
|
+
entries = entries.filter((e) => (seen.has(e.profile) ? false : (seen.add(e.profile), true)));
|
|
292
|
+
}
|
|
293
|
+
return { entries, nextCursor };
|
|
294
|
+
}
|
|
295
|
+
async setStatus(id, status, opts) {
|
|
296
|
+
if (this.db.dialect === "tidb") {
|
|
297
|
+
const sets = ["status=?", "updated_at=?"];
|
|
298
|
+
const params = [status, new Date()];
|
|
299
|
+
if (opts && "supersedes" in opts) {
|
|
300
|
+
sets.push("supersedes=?");
|
|
301
|
+
params.push(opts.supersedes ?? null);
|
|
302
|
+
}
|
|
303
|
+
params.push(id);
|
|
304
|
+
await this.db.query(`UPDATE sandbox_image_index SET ${sets.join(", ")} WHERE id=?`, params);
|
|
305
|
+
return;
|
|
306
|
+
}
|
|
307
|
+
const sets = ["status = $1", "updated_at = $2"];
|
|
308
|
+
const params = [status, new Date()];
|
|
309
|
+
let idx = 3;
|
|
310
|
+
if (opts && "supersedes" in opts) {
|
|
311
|
+
sets.push(`supersedes = $${idx++}`);
|
|
312
|
+
params.push(opts.supersedes ?? null);
|
|
313
|
+
}
|
|
314
|
+
params.push(id);
|
|
315
|
+
await this.db.query(`UPDATE sandbox_image_index SET ${sets.join(", ")} WHERE id = $${idx}`, params);
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
export class TiDBImageIndex extends SqlImageIndex {
|
|
319
|
+
constructor(pool) {
|
|
320
|
+
super(mysqlDriver(pool));
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
export class PgImageIndex extends SqlImageIndex {
|
|
324
|
+
constructor(pool) {
|
|
325
|
+
super(pgDriver(pool));
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
//# sourceMappingURL=image-index-sql.js.map
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import type { Pool as MySqlPool } from "mysql2/promise";
|
|
2
|
+
import type { Pool as PgPool, PoolClient } from "pg";
|
|
3
|
+
import type { TaskOutcome as CoreTaskOutcome } from "@sema-agent/core";
|
|
4
|
+
import { type SqlDriver } from "./sql-driver.js";
|
|
5
|
+
export interface MechanicalOutcome {
|
|
6
|
+
route?: "single" | "fanout";
|
|
7
|
+
workerCount?: number;
|
|
8
|
+
oraclePassed?: number;
|
|
9
|
+
oracleTotal?: number;
|
|
10
|
+
assembleExit?: number;
|
|
11
|
+
lintExit?: number;
|
|
12
|
+
mergeOk?: boolean;
|
|
13
|
+
replanTriggers?: string[];
|
|
14
|
+
costMicroUsd?: number;
|
|
15
|
+
turns?: number;
|
|
16
|
+
}
|
|
17
|
+
export interface LlmAssistedOutcome {
|
|
18
|
+
stuckEvents?: number;
|
|
19
|
+
verifier?: {
|
|
20
|
+
verdict: string;
|
|
21
|
+
confidence: number;
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
export interface SignatureInputs {
|
|
25
|
+
taskType?: string;
|
|
26
|
+
toolset?: string[];
|
|
27
|
+
targetLang?: string;
|
|
28
|
+
moduleCount?: number;
|
|
29
|
+
tag?: string;
|
|
30
|
+
}
|
|
31
|
+
export type RunStatus = "completed-graded" | "infra-aborted";
|
|
32
|
+
export interface TaskOutcome {
|
|
33
|
+
taskId?: string;
|
|
34
|
+
model: string;
|
|
35
|
+
runStatus?: RunStatus;
|
|
36
|
+
signatureInputs: SignatureInputs;
|
|
37
|
+
mechanical: MechanicalOutcome;
|
|
38
|
+
llmAssisted?: LlmAssistedOutcome;
|
|
39
|
+
core?: unknown;
|
|
40
|
+
}
|
|
41
|
+
export declare function taskSignature(s: SignatureInputs): string;
|
|
42
|
+
export declare function deriveOutcome(m: MechanicalOutcome, runStatus?: RunStatus): "pass" | "partial" | "fail" | "aborted";
|
|
43
|
+
export declare function coreOutcomeToLedgerRow(o: CoreTaskOutcome): TaskOutcome;
|
|
44
|
+
export declare const PG_OUTCOME_LEDGER_SCHEMA: string[];
|
|
45
|
+
export declare function ensurePgOutcomeLedgerSchema(pool: PgPool | PoolClient): Promise<void>;
|
|
46
|
+
export declare class SqlOutcomeLedger {
|
|
47
|
+
private readonly db;
|
|
48
|
+
constructor(db: SqlDriver);
|
|
49
|
+
private q;
|
|
50
|
+
private json;
|
|
51
|
+
record(o: TaskOutcome): Promise<string>;
|
|
52
|
+
recordCore(o: CoreTaskOutcome): Promise<void>;
|
|
53
|
+
summary(opts?: {
|
|
54
|
+
taskSignature?: string;
|
|
55
|
+
includeAborted?: boolean;
|
|
56
|
+
}): Promise<Array<{
|
|
57
|
+
taskSignature: string;
|
|
58
|
+
model: string;
|
|
59
|
+
n: number;
|
|
60
|
+
passRate: number;
|
|
61
|
+
meanCostMicroUsd: number;
|
|
62
|
+
}>>;
|
|
63
|
+
}
|
|
64
|
+
export declare class TiDBOutcomeLedger extends SqlOutcomeLedger {
|
|
65
|
+
constructor(pool: MySqlPool);
|
|
66
|
+
}
|
|
67
|
+
export declare class PgOutcomeLedger extends SqlOutcomeLedger {
|
|
68
|
+
constructor(pool: PgPool);
|
|
69
|
+
}
|
|
70
|
+
//# sourceMappingURL=outcome-ledger-sql.d.ts.map
|
|
@@ -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
|