@sema-agent/server 1.310.0 → 1.312.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/auth-keys.d.ts +14 -0
- package/dist/auth-keys.js +31 -0
- package/dist/brain.d.ts +1 -1
- package/dist/capabilities/center-prompts.d.ts +3 -28
- package/dist/capabilities/center-prompts.js +2 -107
- package/dist/capabilities/select-environment-tool.d.ts +1 -1
- package/dist/config-lkg.js +1 -1
- package/dist/config-types.d.ts +306 -0
- package/dist/config-types.js +2 -0
- package/dist/config.d.ts +4 -305
- package/dist/config.js +1 -1
- package/dist/env-facts.d.ts +1 -1
- package/dist/hooks/hook-llm.d.ts +1 -1
- package/dist/http/server.d.ts +5 -85
- package/dist/http/wire-types.d.ts +84 -0
- package/dist/http/wire-types.js +2 -0
- package/dist/images/manifest.d.ts +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +1 -1
- package/dist/main.js +134 -143
- package/dist/per-task-image.d.ts +2 -2
- package/dist/plugins/file-run-store.d.ts +1 -1
- package/dist/plugins/local-session-store.d.ts +2 -2
- package/dist/plugins/local-session-store.js +1 -1
- package/dist/plugins/memory-run-store.d.ts +1 -1
- package/dist/plugins/pg-approval-store.js +1 -27
- package/dist/plugins/pg-checkpoint-store.js +1 -5
- package/dist/plugins/pg-image-bake.d.ts +2 -2
- package/dist/plugins/pg-image-bake.js +2 -54
- package/dist/plugins/pg-image-index.d.ts +2 -2
- package/dist/plugins/pg-image-index.js +1 -44
- package/dist/plugins/pg-pool.d.ts +1 -1
- package/dist/plugins/pg-run-store.d.ts +1 -1
- package/dist/plugins/pg-run-store.js +2 -16
- package/dist/plugins/pg-session-storage.d.ts +2 -2
- package/dist/plugins/pg-session-storage.js +3 -7
- package/dist/plugins/pg-tool-result-store.js +1 -1
- package/dist/plugins/session-store.d.ts +1 -1
- package/dist/plugins/sql-escape.d.ts +2 -0
- package/dist/plugins/sql-escape.js +4 -0
- package/dist/plugins/sql-row-helpers.d.ts +7 -0
- package/dist/plugins/sql-row-helpers.js +43 -0
- package/dist/plugins/store-backend.d.ts +1 -1
- package/dist/plugins/store-contracts.d.ts +205 -0
- package/dist/plugins/store-contracts.js +61 -0
- package/dist/plugins/tidb-approval-store.d.ts +1 -0
- package/dist/plugins/tidb-approval-store.js +2 -11
- package/dist/plugins/tidb-checkpoint-store.js +1 -5
- package/dist/plugins/tidb-image-bake.d.ts +3 -64
- package/dist/plugins/tidb-image-bake.js +3 -54
- package/dist/plugins/tidb-image-index.d.ts +3 -52
- package/dist/plugins/tidb-image-index.js +2 -43
- package/dist/plugins/tidb-pool.d.ts +1 -1
- package/dist/plugins/tidb-run-store.d.ts +2 -32
- package/dist/plugins/tidb-run-store.js +2 -16
- package/dist/plugins/tidb-session-storage.js +1 -5
- package/dist/plugins/tidb-session-store.d.ts +2 -2
- package/dist/plugins/tidb-session-store.js +2 -2
- package/dist/plugins/tidb-tool-result-store.d.ts +1 -1
- package/dist/plugins/tidb-tool-result-store.js +2 -3
- package/dist/prompts-domain-validate.d.ts +29 -0
- package/dist/prompts-domain-validate.js +109 -0
- package/dist/security.d.ts +6 -16
- package/dist/security.js +1 -30
- package/dist/sema-registry.d.ts +1 -1
- package/dist/session-sync-kernel.d.ts +47 -0
- package/dist/session-sync-kernel.js +47 -0
- package/dist/session-sync.d.ts +3 -45
- package/dist/session-sync.js +2 -46
- package/dist/trace/artifacts.d.ts +1 -1
- package/dist/trace/project.d.ts +1 -1
- package/package.json +1 -1
|
@@ -1,24 +1,10 @@
|
|
|
1
1
|
import { projectUsageStats, USAGE_SCAN_LIMIT } from "../usage-analytics.js";
|
|
2
|
-
import { escapeLike } from "./
|
|
2
|
+
import { escapeLike } from "./sql-escape.js";
|
|
3
3
|
import { pgSafeJsonStringify, pgSanitizeText } from "./pg-safe-json.js";
|
|
4
|
-
|
|
5
|
-
if (v == null)
|
|
6
|
-
return null;
|
|
7
|
-
if (typeof v !== "string")
|
|
8
|
-
return v;
|
|
9
|
-
try {
|
|
10
|
-
return JSON.parse(v);
|
|
11
|
-
}
|
|
12
|
-
catch {
|
|
13
|
-
return null;
|
|
14
|
-
}
|
|
15
|
-
}
|
|
4
|
+
import { parseJsonLenient as parseJson, toIso as iso } from "./sql-row-helpers.js";
|
|
16
5
|
function isDupKey(err) {
|
|
17
6
|
return Boolean(err) && err.code === "23505";
|
|
18
7
|
}
|
|
19
|
-
function iso(v) {
|
|
20
|
-
return v instanceof Date ? v.toISOString() : String(v);
|
|
21
|
-
}
|
|
22
8
|
export class PgRunStore {
|
|
23
9
|
pool;
|
|
24
10
|
constructor(pool) {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { BaseSessionStorage, type PromptEpochDescriptor, type AcquiredSession, type SessionMetadata, type SessionStore, type SessionTreeEntry, type SessionWriteOptions } from "@sema-agent/core";
|
|
2
2
|
import type { Pool, PoolClient } from "pg";
|
|
3
|
-
import type { SessionSummary } from "./
|
|
4
|
-
import { type StagingHandle } from "../session-sync.js";
|
|
3
|
+
import type { SessionSummary } from "./store-contracts.js";
|
|
4
|
+
import { type StagingHandle } from "../session-sync-kernel.js";
|
|
5
5
|
export declare const PG_SESSION_SCHEMA: string[];
|
|
6
6
|
export declare function ensureSchema(pool: Pool | PoolClient): Promise<void>;
|
|
7
7
|
export declare class PgSessionStorage extends BaseSessionStorage {
|
|
@@ -1,17 +1,13 @@
|
|
|
1
1
|
import { emitLeafAdvance } from "../session-leaf-bus.js";
|
|
2
2
|
import { BaseSessionStorage, StoredSession, SessionError, uuidv7, validateEntriesForImport, leafIdAfterEntry, normalizePromptEpoch, } from "@sema-agent/core";
|
|
3
|
-
import { escapeLike } from "./
|
|
3
|
+
import { escapeLike } from "./sql-escape.js";
|
|
4
4
|
import { pgSafeJsonStringify } from "./pg-safe-json.js";
|
|
5
|
-
import {
|
|
5
|
+
import { toIso } from "./sql-row-helpers.js";
|
|
6
|
+
import { classifySyncRelationshipByIds, SyncConflictError, stagingIdFor, STAGING_ID_MARKER, } from "../session-sync-kernel.js";
|
|
6
7
|
const STAGING_GC_GRACE_MS = 3_600_000;
|
|
7
8
|
function isDupKey(err) {
|
|
8
9
|
return Boolean(err) && err.code === "23505";
|
|
9
10
|
}
|
|
10
|
-
function toIso(v) {
|
|
11
|
-
if (v instanceof Date)
|
|
12
|
-
return v.toISOString();
|
|
13
|
-
return String(v);
|
|
14
|
-
}
|
|
15
11
|
function parseEntry(p) {
|
|
16
12
|
return (typeof p === "string" ? JSON.parse(p) : p);
|
|
17
13
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type SessionStore } from "@sema-agent/core";
|
|
2
|
-
import type { ServiceConfig } from "../config.js";
|
|
2
|
+
import type { ServiceConfig } from "../config-types.js";
|
|
3
3
|
import type { StoreBackend } from "./store-backend.js";
|
|
4
4
|
export declare function createSessionStore(config: ServiceConfig, backend?: StoreBackend, metrics?: {
|
|
5
5
|
inc(name: string, labels?: Record<string, string>, n?: number): void;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export declare function parseJsonLenient<T>(v: unknown): T | null;
|
|
2
|
+
export declare function parseJsonStrict<T>(v: unknown): T | null;
|
|
3
|
+
export declare function parseJsonOr<T>(v: unknown, fallback: T): T;
|
|
4
|
+
export declare function toIso(v: unknown): string;
|
|
5
|
+
export declare function toIsoOrNull(v: unknown): string | null;
|
|
6
|
+
export declare function normalizeIsoOrNull(v: unknown): string | null;
|
|
7
|
+
//# sourceMappingURL=sql-row-helpers.d.ts.map
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
export function parseJsonLenient(v) {
|
|
2
|
+
if (v == null)
|
|
3
|
+
return null;
|
|
4
|
+
if (typeof v !== "string")
|
|
5
|
+
return v;
|
|
6
|
+
try {
|
|
7
|
+
return JSON.parse(v);
|
|
8
|
+
}
|
|
9
|
+
catch {
|
|
10
|
+
return null;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
export function parseJsonStrict(v) {
|
|
14
|
+
if (v == null)
|
|
15
|
+
return null;
|
|
16
|
+
return (typeof v === "string" ? JSON.parse(v) : v);
|
|
17
|
+
}
|
|
18
|
+
export function parseJsonOr(v, fallback) {
|
|
19
|
+
if (v == null)
|
|
20
|
+
return fallback;
|
|
21
|
+
if (typeof v !== "string")
|
|
22
|
+
return v;
|
|
23
|
+
try {
|
|
24
|
+
return JSON.parse(v);
|
|
25
|
+
}
|
|
26
|
+
catch {
|
|
27
|
+
return fallback;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
export function toIso(v) {
|
|
31
|
+
return v instanceof Date ? v.toISOString() : String(v);
|
|
32
|
+
}
|
|
33
|
+
export function toIsoOrNull(v) {
|
|
34
|
+
if (v == null)
|
|
35
|
+
return null;
|
|
36
|
+
return v instanceof Date ? v.toISOString() : String(v);
|
|
37
|
+
}
|
|
38
|
+
export function normalizeIsoOrNull(v) {
|
|
39
|
+
if (v == null)
|
|
40
|
+
return null;
|
|
41
|
+
return v instanceof Date ? v.toISOString() : new Date(v).toISOString();
|
|
42
|
+
}
|
|
43
|
+
//# sourceMappingURL=sql-row-helpers.js.map
|
|
@@ -11,7 +11,7 @@ import { type ApprovalExemptionStore } from "./approval-exemption-store.js";
|
|
|
11
11
|
import { type SendFileLedger } from "./send-file-ledger.js";
|
|
12
12
|
import { TiDBResumeAnchorStore } from "./tidb-resume-anchor-store.js";
|
|
13
13
|
import { PgResumeAnchorStore } from "./pg-resume-anchor-store.js";
|
|
14
|
-
import type { ServiceConfig } from "../config.js";
|
|
14
|
+
import type { ServiceConfig } from "../config-types.js";
|
|
15
15
|
import { TiDBRunStore } from "./tidb-run-store.js";
|
|
16
16
|
import { PgRunStore } from "./pg-run-store.js";
|
|
17
17
|
import { TiDBCheckpointStore } from "./tidb-checkpoint-store.js";
|
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
import type { TaskResult, TaskStatus } from "@sema-agent/core";
|
|
2
|
+
export interface RunRecord {
|
|
3
|
+
taskId: string;
|
|
4
|
+
sessionId: string;
|
|
5
|
+
owner: string | null;
|
|
6
|
+
status: "running" | TaskStatus;
|
|
7
|
+
result: TaskResult | null;
|
|
8
|
+
error: string | null;
|
|
9
|
+
errorCode: string | null;
|
|
10
|
+
jobId: string | null;
|
|
11
|
+
source: string | null;
|
|
12
|
+
instanceId: string | null;
|
|
13
|
+
objectivePreview: string | null;
|
|
14
|
+
createdAt: string;
|
|
15
|
+
updatedAt: string;
|
|
16
|
+
}
|
|
17
|
+
export interface SessionSummary {
|
|
18
|
+
sessionId: string;
|
|
19
|
+
owner: string | null;
|
|
20
|
+
lastActivityAt: string;
|
|
21
|
+
firstActivityAt: string;
|
|
22
|
+
runCount: number;
|
|
23
|
+
objectivePreview: string | null;
|
|
24
|
+
lastStatus: string;
|
|
25
|
+
lastRunId: string | null;
|
|
26
|
+
title: string | null;
|
|
27
|
+
}
|
|
28
|
+
export interface RunEvent {
|
|
29
|
+
seq: number;
|
|
30
|
+
type: string;
|
|
31
|
+
data: unknown;
|
|
32
|
+
ts: string;
|
|
33
|
+
}
|
|
34
|
+
export type BakeStatus = "queued" | "running" | "done" | "failed";
|
|
35
|
+
export type BakeState = "PENDING" | "BUILDING" | "PUSHING" | "VERIFYING" | "REGISTERING" | "COMPLETE" | "FAILED" | "CANCELLED";
|
|
36
|
+
export type BakeErrorCode = "band-conflict" | "duplicate" | "disk" | "timeout" | "cancelled" | null;
|
|
37
|
+
export interface BakeRecord {
|
|
38
|
+
bakeId: string;
|
|
39
|
+
profile: string;
|
|
40
|
+
bands: string[] | null;
|
|
41
|
+
baseRef: string | null;
|
|
42
|
+
push: boolean;
|
|
43
|
+
dryRun: boolean;
|
|
44
|
+
logs: boolean;
|
|
45
|
+
argv: string[];
|
|
46
|
+
status: BakeStatus;
|
|
47
|
+
state: BakeState | null;
|
|
48
|
+
digest: string | null;
|
|
49
|
+
repo: string | null;
|
|
50
|
+
ref: string | null;
|
|
51
|
+
indexId: string | null;
|
|
52
|
+
exitCode: number | null;
|
|
53
|
+
error: string | null;
|
|
54
|
+
errorCode: BakeErrorCode;
|
|
55
|
+
manifestSha: string | null;
|
|
56
|
+
tag: string | null;
|
|
57
|
+
idemKey: string | null;
|
|
58
|
+
ingestSecret: string | null;
|
|
59
|
+
runnerId: string | null;
|
|
60
|
+
leaseUntil: string | null;
|
|
61
|
+
cancelRequested: boolean;
|
|
62
|
+
requestedBy: string | null;
|
|
63
|
+
createdAt: string;
|
|
64
|
+
updatedAt: string;
|
|
65
|
+
}
|
|
66
|
+
export interface BakeEvent {
|
|
67
|
+
seq: number;
|
|
68
|
+
lineOrd: number | null;
|
|
69
|
+
kind: string;
|
|
70
|
+
level: string | null;
|
|
71
|
+
data: unknown;
|
|
72
|
+
ts: string;
|
|
73
|
+
}
|
|
74
|
+
export interface CreateBakeInput {
|
|
75
|
+
profile: string;
|
|
76
|
+
bands: string[] | null;
|
|
77
|
+
baseRef: string | null;
|
|
78
|
+
push: boolean;
|
|
79
|
+
dryRun: boolean;
|
|
80
|
+
logs: boolean;
|
|
81
|
+
argv: string[];
|
|
82
|
+
idemKey: string | null;
|
|
83
|
+
requestedBy: string | null;
|
|
84
|
+
}
|
|
85
|
+
export interface BakeTerminal {
|
|
86
|
+
status: "done" | "failed";
|
|
87
|
+
state: BakeState;
|
|
88
|
+
digest?: string | null;
|
|
89
|
+
repo?: string | null;
|
|
90
|
+
ref?: string | null;
|
|
91
|
+
indexId?: string | null;
|
|
92
|
+
exitCode?: number | null;
|
|
93
|
+
error?: string | null;
|
|
94
|
+
errorCode?: BakeErrorCode;
|
|
95
|
+
manifestSha?: string | null;
|
|
96
|
+
tag?: string | null;
|
|
97
|
+
}
|
|
98
|
+
export interface BakeRow {
|
|
99
|
+
bake_id: string;
|
|
100
|
+
profile: string;
|
|
101
|
+
bands: unknown;
|
|
102
|
+
base_ref: string | null;
|
|
103
|
+
push: number;
|
|
104
|
+
dry_run: number;
|
|
105
|
+
logs: number;
|
|
106
|
+
argv: unknown;
|
|
107
|
+
status: string;
|
|
108
|
+
state: string | null;
|
|
109
|
+
digest: string | null;
|
|
110
|
+
repo: string | null;
|
|
111
|
+
ref: string | null;
|
|
112
|
+
index_id: string | null;
|
|
113
|
+
exit_code: number | string | null;
|
|
114
|
+
error: string | null;
|
|
115
|
+
error_code: string | null;
|
|
116
|
+
manifest_sha: string | null;
|
|
117
|
+
tag: string | null;
|
|
118
|
+
idem_key: string | null;
|
|
119
|
+
ingest_secret: string | null;
|
|
120
|
+
runner_id: string | null;
|
|
121
|
+
lease_until: Date | string | null;
|
|
122
|
+
cancel_requested: number;
|
|
123
|
+
requested_by: string | null;
|
|
124
|
+
created_at: Date | string;
|
|
125
|
+
updated_at: Date | string;
|
|
126
|
+
}
|
|
127
|
+
export declare function mapBakeRow(r: BakeRow): BakeRecord;
|
|
128
|
+
export declare const BAKE_SELECT_COLS: string;
|
|
129
|
+
export type ImageNestedBuildMode = "none" | "docker-cli-only" | "rootless-buildkit" | "privileged-dind";
|
|
130
|
+
export interface ImageCapabilities {
|
|
131
|
+
browser?: boolean;
|
|
132
|
+
db?: boolean;
|
|
133
|
+
nestedBuild?: boolean;
|
|
134
|
+
nestedBuildMode?: ImageNestedBuildMode;
|
|
135
|
+
}
|
|
136
|
+
export interface ImagePodContract {
|
|
137
|
+
devShmMB?: number;
|
|
138
|
+
minMemMB?: number;
|
|
139
|
+
minCpu?: string;
|
|
140
|
+
readyTimeoutSec?: number;
|
|
141
|
+
securityContext?: Record<string, unknown>;
|
|
142
|
+
}
|
|
143
|
+
export type ImageStatus = "building" | "published" | "deprecated" | "failed";
|
|
144
|
+
export type ImageVisibility = "public" | "tenant";
|
|
145
|
+
export interface ImageIndexEntry {
|
|
146
|
+
id: string;
|
|
147
|
+
profile: string;
|
|
148
|
+
bands: string[];
|
|
149
|
+
repo: string;
|
|
150
|
+
tag: string;
|
|
151
|
+
digest: string;
|
|
152
|
+
toolchainVersions: Record<string, string>;
|
|
153
|
+
capabilities: ImageCapabilities;
|
|
154
|
+
podContract: ImagePodContract;
|
|
155
|
+
sizeBytes: number | null;
|
|
156
|
+
status: ImageStatus;
|
|
157
|
+
visibility: ImageVisibility;
|
|
158
|
+
tenantId: string | null;
|
|
159
|
+
manifestSha: string | null;
|
|
160
|
+
recipeGitSha: string | null;
|
|
161
|
+
generatorVersion: string | null;
|
|
162
|
+
buildDate: string | null;
|
|
163
|
+
supersedes: string | null;
|
|
164
|
+
signed: boolean;
|
|
165
|
+
createdAt: string;
|
|
166
|
+
updatedAt: string;
|
|
167
|
+
}
|
|
168
|
+
export type ImageIndexUpsert = Omit<ImageIndexEntry, "id" | "createdAt" | "updatedAt">;
|
|
169
|
+
export interface ImageViewer {
|
|
170
|
+
operator?: boolean;
|
|
171
|
+
tenantId?: string | null;
|
|
172
|
+
}
|
|
173
|
+
export interface ImageListFilter extends ImageViewer {
|
|
174
|
+
profile?: string;
|
|
175
|
+
status?: ImageStatus;
|
|
176
|
+
capability?: keyof ImageCapabilities;
|
|
177
|
+
latestOnly?: boolean;
|
|
178
|
+
limit?: number;
|
|
179
|
+
cursor?: string;
|
|
180
|
+
}
|
|
181
|
+
export interface ImageRow {
|
|
182
|
+
id: string;
|
|
183
|
+
profile: string;
|
|
184
|
+
bands: unknown;
|
|
185
|
+
repo: string;
|
|
186
|
+
tag: string;
|
|
187
|
+
digest: string;
|
|
188
|
+
toolchain_versions: unknown;
|
|
189
|
+
capabilities: unknown;
|
|
190
|
+
pod_contract: unknown;
|
|
191
|
+
size_bytes: number | string | null;
|
|
192
|
+
status: string;
|
|
193
|
+
visibility: string;
|
|
194
|
+
tenant_id: string | null;
|
|
195
|
+
manifest_sha: string | null;
|
|
196
|
+
recipe_git_sha: string | null;
|
|
197
|
+
generator_version: string | null;
|
|
198
|
+
build_date: Date | string | null;
|
|
199
|
+
supersedes: string | null;
|
|
200
|
+
signed: number;
|
|
201
|
+
created_at: Date | string;
|
|
202
|
+
updated_at: Date | string;
|
|
203
|
+
}
|
|
204
|
+
export declare function mapImageRow(r: ImageRow): ImageIndexEntry;
|
|
205
|
+
//# sourceMappingURL=store-contracts.d.ts.map
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { parseJsonOr, toIso as iso, normalizeIsoOrNull as isoOrNull } from "./sql-row-helpers.js";
|
|
2
|
+
export function mapBakeRow(r) {
|
|
3
|
+
return {
|
|
4
|
+
bakeId: r.bake_id,
|
|
5
|
+
profile: r.profile,
|
|
6
|
+
bands: r.bands == null ? null : parseJsonOr(r.bands, []),
|
|
7
|
+
baseRef: r.base_ref,
|
|
8
|
+
push: !!r.push,
|
|
9
|
+
dryRun: !!r.dry_run,
|
|
10
|
+
logs: !!r.logs,
|
|
11
|
+
argv: parseJsonOr(r.argv, []),
|
|
12
|
+
status: r.status,
|
|
13
|
+
state: r.state ?? null,
|
|
14
|
+
digest: r.digest,
|
|
15
|
+
repo: r.repo,
|
|
16
|
+
ref: r.ref,
|
|
17
|
+
indexId: r.index_id,
|
|
18
|
+
exitCode: r.exit_code === null ? null : Number(r.exit_code),
|
|
19
|
+
error: r.error,
|
|
20
|
+
errorCode: r.error_code ?? null,
|
|
21
|
+
manifestSha: r.manifest_sha,
|
|
22
|
+
tag: r.tag,
|
|
23
|
+
idemKey: r.idem_key,
|
|
24
|
+
ingestSecret: r.ingest_secret,
|
|
25
|
+
runnerId: r.runner_id,
|
|
26
|
+
leaseUntil: isoOrNull(r.lease_until),
|
|
27
|
+
cancelRequested: !!r.cancel_requested,
|
|
28
|
+
requestedBy: r.requested_by,
|
|
29
|
+
createdAt: iso(r.created_at),
|
|
30
|
+
updatedAt: iso(r.updated_at),
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
export const BAKE_SELECT_COLS = "bake_id, profile, bands, base_ref, push, dry_run, logs, argv, status, state, digest, repo, ref, index_id, " +
|
|
34
|
+
"exit_code, error, error_code, manifest_sha, tag, idem_key, ingest_secret, runner_id, lease_until, " +
|
|
35
|
+
"cancel_requested, requested_by, created_at, updated_at";
|
|
36
|
+
export function mapImageRow(r) {
|
|
37
|
+
return {
|
|
38
|
+
id: r.id,
|
|
39
|
+
profile: r.profile,
|
|
40
|
+
bands: parseJsonOr(r.bands, []),
|
|
41
|
+
repo: r.repo,
|
|
42
|
+
tag: r.tag,
|
|
43
|
+
digest: r.digest,
|
|
44
|
+
toolchainVersions: parseJsonOr(r.toolchain_versions, {}),
|
|
45
|
+
capabilities: parseJsonOr(r.capabilities, {}),
|
|
46
|
+
podContract: parseJsonOr(r.pod_contract, {}),
|
|
47
|
+
sizeBytes: r.size_bytes === null ? null : Number(r.size_bytes),
|
|
48
|
+
status: r.status,
|
|
49
|
+
visibility: r.visibility,
|
|
50
|
+
tenantId: r.tenant_id,
|
|
51
|
+
manifestSha: r.manifest_sha,
|
|
52
|
+
recipeGitSha: r.recipe_git_sha,
|
|
53
|
+
generatorVersion: r.generator_version,
|
|
54
|
+
buildDate: isoOrNull(r.build_date),
|
|
55
|
+
supersedes: r.supersedes,
|
|
56
|
+
signed: !!r.signed,
|
|
57
|
+
createdAt: isoOrNull(r.created_at) ?? new Date(0).toISOString(),
|
|
58
|
+
updatedAt: isoOrNull(r.updated_at) ?? new Date(0).toISOString(),
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
//# sourceMappingURL=store-contracts.js.map
|
|
@@ -36,4 +36,5 @@ export declare class TiDBApprovalStore {
|
|
|
36
36
|
listPendingAll(): Promise<ApprovalRow[]>;
|
|
37
37
|
expireStale(olderThanMs: number): Promise<number>;
|
|
38
38
|
}
|
|
39
|
+
export declare function mapRow(r: Record<string, unknown>): ApprovalRow;
|
|
39
40
|
//# sourceMappingURL=tidb-approval-store.d.ts.map
|
|
@@ -1,13 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
if (v == null)
|
|
3
|
-
return null;
|
|
4
|
-
return (typeof v === "string" ? JSON.parse(v) : v);
|
|
5
|
-
}
|
|
6
|
-
function iso(v) {
|
|
7
|
-
if (v == null)
|
|
8
|
-
return null;
|
|
9
|
-
return v instanceof Date ? v.toISOString() : String(v);
|
|
10
|
-
}
|
|
1
|
+
import { parseJsonStrict as parseJson, toIsoOrNull as iso } from "./sql-row-helpers.js";
|
|
11
2
|
export class TiDBApprovalStore {
|
|
12
3
|
pool;
|
|
13
4
|
constructor(pool) {
|
|
@@ -62,7 +53,7 @@ export class TiDBApprovalStore {
|
|
|
62
53
|
return res.affectedRows;
|
|
63
54
|
}
|
|
64
55
|
}
|
|
65
|
-
function mapRow(r) {
|
|
56
|
+
export function mapRow(r) {
|
|
66
57
|
return {
|
|
67
58
|
id: String(r.id),
|
|
68
59
|
taskId: r.task_id ?? null,
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { createHash } from "node:crypto";
|
|
2
2
|
import { CheckpointError, validatePendingSteer, checkpointVersionOf, winnerFromOutcome, summarizeCheckpoint, MAX_SUPPORTED_CHECKPOINT_VERSION } from "@sema-agent/core";
|
|
3
3
|
import { redactDeep } from "../trace/redact.js";
|
|
4
|
+
import { parseJsonStrict as parseJson } from "./sql-row-helpers.js";
|
|
4
5
|
const MAX_TOOL_INPUT_CHARS = 8192;
|
|
5
6
|
export const TERMINAL_BACKSTOP_MS = Math.max(60_000, Number(process.env.APPROVAL_TERMINAL_BACKSTOP_MS) || 30 * 86_400_000);
|
|
6
7
|
export const TERMINAL_GRACE_MS = 3_600_000;
|
|
@@ -188,9 +189,4 @@ export class TiDBCheckpointStore {
|
|
|
188
189
|
return res.affectedRows;
|
|
189
190
|
}
|
|
190
191
|
}
|
|
191
|
-
function parseJson(v) {
|
|
192
|
-
if (v == null)
|
|
193
|
-
return null;
|
|
194
|
-
return (typeof v === "string" ? JSON.parse(v) : v);
|
|
195
|
-
}
|
|
196
192
|
//# sourceMappingURL=tidb-checkpoint-store.js.map
|
|
@@ -1,68 +1,7 @@
|
|
|
1
1
|
import type { Pool } from "mysql2/promise";
|
|
2
|
-
|
|
3
|
-
export type
|
|
4
|
-
export
|
|
5
|
-
export interface BakeRecord {
|
|
6
|
-
bakeId: string;
|
|
7
|
-
profile: string;
|
|
8
|
-
bands: string[] | null;
|
|
9
|
-
baseRef: string | null;
|
|
10
|
-
push: boolean;
|
|
11
|
-
dryRun: boolean;
|
|
12
|
-
logs: boolean;
|
|
13
|
-
argv: string[];
|
|
14
|
-
status: BakeStatus;
|
|
15
|
-
state: BakeState | null;
|
|
16
|
-
digest: string | null;
|
|
17
|
-
repo: string | null;
|
|
18
|
-
ref: string | null;
|
|
19
|
-
indexId: string | null;
|
|
20
|
-
exitCode: number | null;
|
|
21
|
-
error: string | null;
|
|
22
|
-
errorCode: BakeErrorCode;
|
|
23
|
-
manifestSha: string | null;
|
|
24
|
-
tag: string | null;
|
|
25
|
-
idemKey: string | null;
|
|
26
|
-
ingestSecret: string | null;
|
|
27
|
-
runnerId: string | null;
|
|
28
|
-
leaseUntil: string | null;
|
|
29
|
-
cancelRequested: boolean;
|
|
30
|
-
requestedBy: string | null;
|
|
31
|
-
createdAt: string;
|
|
32
|
-
updatedAt: string;
|
|
33
|
-
}
|
|
34
|
-
export interface BakeEvent {
|
|
35
|
-
seq: number;
|
|
36
|
-
lineOrd: number | null;
|
|
37
|
-
kind: string;
|
|
38
|
-
level: string | null;
|
|
39
|
-
data: unknown;
|
|
40
|
-
ts: string;
|
|
41
|
-
}
|
|
42
|
-
export interface CreateBakeInput {
|
|
43
|
-
profile: string;
|
|
44
|
-
bands: string[] | null;
|
|
45
|
-
baseRef: string | null;
|
|
46
|
-
push: boolean;
|
|
47
|
-
dryRun: boolean;
|
|
48
|
-
logs: boolean;
|
|
49
|
-
argv: string[];
|
|
50
|
-
idemKey: string | null;
|
|
51
|
-
requestedBy: string | null;
|
|
52
|
-
}
|
|
53
|
-
export interface BakeTerminal {
|
|
54
|
-
status: "done" | "failed";
|
|
55
|
-
state: BakeState;
|
|
56
|
-
digest?: string | null;
|
|
57
|
-
repo?: string | null;
|
|
58
|
-
ref?: string | null;
|
|
59
|
-
indexId?: string | null;
|
|
60
|
-
exitCode?: number | null;
|
|
61
|
-
error?: string | null;
|
|
62
|
-
errorCode?: BakeErrorCode;
|
|
63
|
-
manifestSha?: string | null;
|
|
64
|
-
tag?: string | null;
|
|
65
|
-
}
|
|
2
|
+
import { type BakeStatus, type BakeState, type BakeRecord, type BakeEvent, type CreateBakeInput, type BakeTerminal } from "./store-contracts.js";
|
|
3
|
+
export type { BakeStatus, BakeState, BakeErrorCode, BakeRecord, BakeEvent, CreateBakeInput, BakeTerminal, BakeRow, } from "./store-contracts.js";
|
|
4
|
+
export { mapBakeRow as mapRow, BAKE_SELECT_COLS as SELECT_COLS } from "./store-contracts.js";
|
|
66
5
|
export declare class TiDBImageBake {
|
|
67
6
|
private readonly pool;
|
|
68
7
|
private readonly poolName;
|
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import { uuidv7 } from "@sema-agent/core";
|
|
2
2
|
import { randomBytes } from "node:crypto";
|
|
3
|
+
import { parseJsonOr as parseJson, toIso as iso } from "./sql-row-helpers.js";
|
|
4
|
+
import { mapBakeRow as mapRow, BAKE_SELECT_COLS as SELECT_COLS, } from "./store-contracts.js";
|
|
5
|
+
export { mapBakeRow as mapRow, BAKE_SELECT_COLS as SELECT_COLS } from "./store-contracts.js";
|
|
3
6
|
function isDupKey(err) {
|
|
4
7
|
return Boolean(err) && err.code === "ER_DUP_ENTRY";
|
|
5
8
|
}
|
|
@@ -11,60 +14,6 @@ function dupKeyName(err) {
|
|
|
11
14
|
return "primary";
|
|
12
15
|
return "other";
|
|
13
16
|
}
|
|
14
|
-
function iso(v) {
|
|
15
|
-
return v instanceof Date ? v.toISOString() : String(v);
|
|
16
|
-
}
|
|
17
|
-
function isoOrNull(v) {
|
|
18
|
-
if (v == null)
|
|
19
|
-
return null;
|
|
20
|
-
return v instanceof Date ? v.toISOString() : new Date(v).toISOString();
|
|
21
|
-
}
|
|
22
|
-
function parseJson(v, fallback) {
|
|
23
|
-
if (v == null)
|
|
24
|
-
return fallback;
|
|
25
|
-
if (typeof v !== "string")
|
|
26
|
-
return v;
|
|
27
|
-
try {
|
|
28
|
-
return JSON.parse(v);
|
|
29
|
-
}
|
|
30
|
-
catch {
|
|
31
|
-
return fallback;
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
function mapRow(r) {
|
|
35
|
-
return {
|
|
36
|
-
bakeId: r.bake_id,
|
|
37
|
-
profile: r.profile,
|
|
38
|
-
bands: r.bands == null ? null : parseJson(r.bands, []),
|
|
39
|
-
baseRef: r.base_ref,
|
|
40
|
-
push: !!r.push,
|
|
41
|
-
dryRun: !!r.dry_run,
|
|
42
|
-
logs: !!r.logs,
|
|
43
|
-
argv: parseJson(r.argv, []),
|
|
44
|
-
status: r.status,
|
|
45
|
-
state: r.state ?? null,
|
|
46
|
-
digest: r.digest,
|
|
47
|
-
repo: r.repo,
|
|
48
|
-
ref: r.ref,
|
|
49
|
-
indexId: r.index_id,
|
|
50
|
-
exitCode: r.exit_code === null ? null : Number(r.exit_code),
|
|
51
|
-
error: r.error,
|
|
52
|
-
errorCode: r.error_code ?? null,
|
|
53
|
-
manifestSha: r.manifest_sha,
|
|
54
|
-
tag: r.tag,
|
|
55
|
-
idemKey: r.idem_key,
|
|
56
|
-
ingestSecret: r.ingest_secret,
|
|
57
|
-
runnerId: r.runner_id,
|
|
58
|
-
leaseUntil: isoOrNull(r.lease_until),
|
|
59
|
-
cancelRequested: !!r.cancel_requested,
|
|
60
|
-
requestedBy: r.requested_by,
|
|
61
|
-
createdAt: iso(r.created_at),
|
|
62
|
-
updatedAt: iso(r.updated_at),
|
|
63
|
-
};
|
|
64
|
-
}
|
|
65
|
-
const SELECT_COLS = "bake_id, profile, bands, base_ref, push, dry_run, logs, argv, status, state, digest, repo, ref, index_id, " +
|
|
66
|
-
"exit_code, error, error_code, manifest_sha, tag, idem_key, ingest_secret, runner_id, lease_until, " +
|
|
67
|
-
"cancel_requested, requested_by, created_at, updated_at";
|
|
68
17
|
export class TiDBImageBake {
|
|
69
18
|
pool;
|
|
70
19
|
poolName;
|
|
@@ -1,56 +1,7 @@
|
|
|
1
1
|
import type { Pool } from "mysql2/promise";
|
|
2
|
-
|
|
3
|
-
export
|
|
4
|
-
|
|
5
|
-
db?: boolean;
|
|
6
|
-
nestedBuild?: boolean;
|
|
7
|
-
nestedBuildMode?: ImageNestedBuildMode;
|
|
8
|
-
}
|
|
9
|
-
export interface ImagePodContract {
|
|
10
|
-
devShmMB?: number;
|
|
11
|
-
minMemMB?: number;
|
|
12
|
-
minCpu?: string;
|
|
13
|
-
readyTimeoutSec?: number;
|
|
14
|
-
securityContext?: Record<string, unknown>;
|
|
15
|
-
}
|
|
16
|
-
export type ImageStatus = "building" | "published" | "deprecated" | "failed";
|
|
17
|
-
export type ImageVisibility = "public" | "tenant";
|
|
18
|
-
export interface ImageIndexEntry {
|
|
19
|
-
id: string;
|
|
20
|
-
profile: string;
|
|
21
|
-
bands: string[];
|
|
22
|
-
repo: string;
|
|
23
|
-
tag: string;
|
|
24
|
-
digest: string;
|
|
25
|
-
toolchainVersions: Record<string, string>;
|
|
26
|
-
capabilities: ImageCapabilities;
|
|
27
|
-
podContract: ImagePodContract;
|
|
28
|
-
sizeBytes: number | null;
|
|
29
|
-
status: ImageStatus;
|
|
30
|
-
visibility: ImageVisibility;
|
|
31
|
-
tenantId: string | null;
|
|
32
|
-
manifestSha: string | null;
|
|
33
|
-
recipeGitSha: string | null;
|
|
34
|
-
generatorVersion: string | null;
|
|
35
|
-
buildDate: string | null;
|
|
36
|
-
supersedes: string | null;
|
|
37
|
-
signed: boolean;
|
|
38
|
-
createdAt: string;
|
|
39
|
-
updatedAt: string;
|
|
40
|
-
}
|
|
41
|
-
export type ImageIndexUpsert = Omit<ImageIndexEntry, "id" | "createdAt" | "updatedAt">;
|
|
42
|
-
export interface ImageViewer {
|
|
43
|
-
operator?: boolean;
|
|
44
|
-
tenantId?: string | null;
|
|
45
|
-
}
|
|
46
|
-
export interface ImageListFilter extends ImageViewer {
|
|
47
|
-
profile?: string;
|
|
48
|
-
status?: ImageStatus;
|
|
49
|
-
capability?: keyof ImageCapabilities;
|
|
50
|
-
latestOnly?: boolean;
|
|
51
|
-
limit?: number;
|
|
52
|
-
cursor?: string;
|
|
53
|
-
}
|
|
2
|
+
import { type ImageStatus, type ImageIndexEntry, type ImageIndexUpsert, type ImageViewer, type ImageListFilter } from "./store-contracts.js";
|
|
3
|
+
export type { ImageNestedBuildMode, ImageCapabilities, ImagePodContract, ImageStatus, ImageVisibility, ImageIndexEntry, ImageIndexUpsert, ImageViewer, ImageListFilter, ImageRow, } from "./store-contracts.js";
|
|
4
|
+
export { mapImageRow as mapRow } from "./store-contracts.js";
|
|
54
5
|
export declare class TiDBImageIndex {
|
|
55
6
|
private readonly pool;
|
|
56
7
|
constructor(pool: Pool);
|