@qlairoslabs/acp-client 0.7.4 → 0.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (53) hide show
  1. package/CHANGELOG-audit.md +58 -0
  2. package/CONSUMER_GUIDE.md +452 -19
  3. package/package.json +6 -1
  4. package/src/agent-adapter-registry.ts +66 -0
  5. package/src/agent-conversation-continuation.ts +121 -0
  6. package/src/agent-conversation-contracts.ts +279 -0
  7. package/src/agent-conversation-errors.ts +31 -0
  8. package/src/agent-conversation-owner.ts +55 -0
  9. package/src/agent-conversation-presentation.ts +217 -0
  10. package/src/agent-conversation-queue.ts +44 -0
  11. package/src/agent-conversation.ts +41 -0
  12. package/src/agent-ids.ts +50 -0
  13. package/src/agent-session.ts +973 -673
  14. package/src/agent.ts +1175 -0
  15. package/src/audit/config.ts +186 -0
  16. package/src/audit/contracts.ts +59 -0
  17. package/src/audit/index.ts +50 -0
  18. package/src/audit/projection.ts +125 -0
  19. package/src/audit/reader.ts +371 -0
  20. package/src/audit/runtime.ts +1060 -0
  21. package/src/checkpointing/config.ts +91 -0
  22. package/src/checkpointing/contracts.ts +45 -0
  23. package/src/checkpointing/coordinator.ts +100 -0
  24. package/src/checkpointing/ids.ts +5 -0
  25. package/src/checkpointing/index.ts +6 -0
  26. package/src/checkpointing/persistence/sqlite-repository.ts +159 -0
  27. package/src/checkpointing/recovery.ts +114 -0
  28. package/src/checkpointing/strategy.ts +139 -0
  29. package/src/identity.ts +62 -0
  30. package/src/index.ts +117 -0
  31. package/src/internal-inference/config.ts +68 -0
  32. package/src/internal-inference/contracts.ts +218 -0
  33. package/src/internal-inference/coordination/handles.ts +133 -0
  34. package/src/internal-inference/coordination/manager.ts +487 -0
  35. package/src/internal-inference/ids.ts +10 -0
  36. package/src/internal-inference/index.ts +10 -0
  37. package/src/internal-inference/persistence/records.ts +132 -0
  38. package/src/internal-inference/persistence/repository.ts +35 -0
  39. package/src/internal-inference/persistence/sqlite-repository.ts +551 -0
  40. package/src/internal-inference/runtime/harness-runtime.ts +78 -0
  41. package/src/internal-inference/strategy/registry.ts +42 -0
  42. package/src/metering/engine.ts +47 -0
  43. package/src/metering/record.ts +4 -1
  44. package/src/observation/contracts.ts +10 -0
  45. package/src/observation/index.ts +8 -0
  46. package/src/observation/subscription-hub.ts +43 -0
  47. package/src/persistence/activity-projection.ts +26 -12
  48. package/src/persistence/backend.ts +774 -0
  49. package/src/persistence/index.ts +99 -0
  50. package/src/persistence/sqlite-backend.ts +1927 -0
  51. package/src/persistence/sqlite-conversation-records.ts +425 -0
  52. package/src/persistence/sqlite-owner-lock.ts +106 -0
  53. package/src/persistence/sqlite-schema.ts +561 -0
@@ -0,0 +1,425 @@
1
+ import type { Database } from "bun:sqlite";
2
+ import type { AgentConversationId, AgentSessionId } from "../agent-ids.ts";
3
+ import type {
4
+ ConversationRecord,
5
+ ConversationRecordKind,
6
+ NewConversationRecord,
7
+ PersistedContent,
8
+ PersistenceJsonValue,
9
+ } from "./backend.ts";
10
+
11
+ export interface ConversationRecordRow {
12
+ readonly row_id: number;
13
+ readonly record_id: string;
14
+ readonly agent_session_id: string;
15
+ readonly agent_conversation_id: string;
16
+ readonly sequence: number;
17
+ readonly kind: string;
18
+ readonly timestamp: string;
19
+ readonly operation_id: string | null;
20
+ readonly metadata: string | null;
21
+ }
22
+
23
+ type SqlValue = string | number | bigint | boolean | Uint8Array | null;
24
+
25
+ export function operationIdFromRecord(record: NewConversationRecord): string | null {
26
+ if (record.kind === "metering") return record.operationId;
27
+ if (!record.metadata) return null;
28
+ try {
29
+ const metadata = JSON.parse(record.metadata) as { operationId?: unknown };
30
+ return typeof metadata?.operationId === "string" && metadata.operationId.trim()
31
+ ? metadata.operationId
32
+ : null;
33
+ } catch {
34
+ return null;
35
+ }
36
+ }
37
+
38
+ export function insertConversationRecordDetail(
39
+ database: Database,
40
+ rowId: number,
41
+ record: NewConversationRecord,
42
+ ): void {
43
+ switch (record.kind) {
44
+ case "message": {
45
+ const content = encodeContent(record.content);
46
+ run(database,
47
+ `INSERT INTO conversation_messages(
48
+ record_row_id, role, participant_id, content_text, content_json, status, search_text
49
+ ) VALUES (?, ?, ?, ?, ?, ?, ?)`,
50
+ rowId,
51
+ record.role,
52
+ record.participantId ?? null,
53
+ content.text,
54
+ content.json,
55
+ record.status ?? null,
56
+ searchableContent(record.content),
57
+ );
58
+ return;
59
+ }
60
+ case "tool_call": {
61
+ const output = encodeOptionalContent(record.output);
62
+ run(database,
63
+ `INSERT INTO conversation_tool_call_events(
64
+ record_row_id, tool_call_id, state, name, input_json,
65
+ output_text, output_json, error, search_text
66
+ ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)`,
67
+ rowId,
68
+ record.toolCallId,
69
+ record.state,
70
+ record.name ?? null,
71
+ encodeJson(record.input),
72
+ output.text,
73
+ output.json,
74
+ record.error ?? null,
75
+ joinSearchText([
76
+ record.name,
77
+ searchableJson(record.input),
78
+ record.output === undefined ? undefined : searchableContent(record.output),
79
+ record.error,
80
+ ]),
81
+ );
82
+ return;
83
+ }
84
+ case "permission":
85
+ run(database,
86
+ `INSERT INTO conversation_permission_events(
87
+ record_row_id, permission_id, state, request_json, outcome
88
+ ) VALUES (?, ?, ?, ?, ?)`,
89
+ rowId,
90
+ record.permissionId,
91
+ record.state,
92
+ encodeJson(record.request),
93
+ record.outcome ?? null,
94
+ );
95
+ return;
96
+ case "configuration":
97
+ run(database,
98
+ `INSERT INTO conversation_configuration_events(
99
+ record_row_id, operation, config_id, value_json, status, error
100
+ ) VALUES (?, ?, ?, ?, ?, ?)`,
101
+ rowId,
102
+ record.operation,
103
+ record.configId ?? null,
104
+ encodeJson(record.value),
105
+ record.status,
106
+ record.error ?? null,
107
+ );
108
+ return;
109
+ case "protocol":
110
+ run(database,
111
+ `INSERT INTO conversation_protocol_records(
112
+ record_row_id, direction, method, message_json
113
+ ) VALUES (?, ?, ?, ?)`,
114
+ rowId,
115
+ record.direction,
116
+ record.method ?? null,
117
+ encodeJson(record.message),
118
+ );
119
+ return;
120
+ case "native_action":
121
+ run(database,
122
+ `INSERT INTO conversation_native_action_events(
123
+ record_row_id, action, transition_id, state, input_json, output_json, error
124
+ ) VALUES (?, ?, ?, ?, ?, ?, ?)`,
125
+ rowId,
126
+ record.action,
127
+ record.transitionId ?? null,
128
+ record.state,
129
+ encodeJson(record.input),
130
+ encodeJson(record.output),
131
+ record.error ?? null,
132
+ );
133
+ return;
134
+ case "agent_action":
135
+ run(database,
136
+ `INSERT INTO conversation_agent_action_events(
137
+ record_row_id, action, state, input_json, output_json, error
138
+ ) VALUES (?, ?, ?, ?, ?, ?)`,
139
+ rowId,
140
+ record.action,
141
+ record.state,
142
+ encodeJson(record.input),
143
+ encodeJson(record.output),
144
+ record.error ?? null,
145
+ );
146
+ return;
147
+ case "thinking": {
148
+ const content = encodeContent(record.content);
149
+ run(database,
150
+ `INSERT INTO conversation_thinking_events(
151
+ record_row_id, thinking_id, state, content_text, content_json
152
+ ) VALUES (?, ?, ?, ?, ?)`,
153
+ rowId,
154
+ record.thinkingId,
155
+ record.state,
156
+ content.text,
157
+ content.json,
158
+ );
159
+ return;
160
+ }
161
+ case "activity": {
162
+ const content = encodeOptionalContent(record.content);
163
+ run(database,
164
+ `INSERT INTO conversation_activity_events(
165
+ record_row_id, activity_id, activity_type, state,
166
+ content_text, content_json, data_json, search_text
167
+ ) VALUES (?, ?, ?, ?, ?, ?, ?, ?)`,
168
+ rowId,
169
+ record.activityId,
170
+ record.activityType,
171
+ record.state,
172
+ content.text,
173
+ content.json,
174
+ encodeJson(record.data),
175
+ joinSearchText([
176
+ record.activityType,
177
+ record.content === undefined ? undefined : searchableContent(record.content),
178
+ searchableJson(record.data),
179
+ ]),
180
+ );
181
+ return;
182
+ }
183
+ case "metering":
184
+ run(database,
185
+ `INSERT INTO conversation_metering_references(
186
+ record_row_id, operation_id, metering_record_id, status
187
+ ) VALUES (?, ?, ?, ?)`,
188
+ rowId,
189
+ record.operationId,
190
+ record.meteringRecordId,
191
+ record.status,
192
+ );
193
+ return;
194
+ }
195
+ }
196
+
197
+ export function hydrateConversationRecords(
198
+ database: Database,
199
+ rows: readonly ConversationRecordRow[],
200
+ ): readonly ConversationRecord[] {
201
+ if (rows.length === 0) return Object.freeze([]);
202
+ const details = new Map<number, Record<string, unknown>>();
203
+ for (const kind of uniqueKinds(rows)) {
204
+ const ids = rows.filter((row) => row.kind === kind).map((row) => Number(row.row_id));
205
+ const table = DETAIL_TABLES[kind];
206
+ if (!table) throw new Error(`persisted conversation record has unknown kind: ${kind}`);
207
+ const found = database.query<Record<string, unknown>, number[]>(
208
+ `SELECT * FROM ${table} WHERE record_row_id IN (${ids.map(() => "?").join(", ")})`,
209
+ ).all(...ids);
210
+ for (const detail of found) details.set(Number(detail.record_row_id), detail);
211
+ }
212
+ return Object.freeze(rows.map((row) => {
213
+ const detail = details.get(Number(row.row_id));
214
+ if (!detail) {
215
+ throw new Error(`conversation record ${row.record_id} has no ${row.kind} detail row`);
216
+ }
217
+ return recordFromRows(row, detail);
218
+ }));
219
+ }
220
+
221
+ export function sameConversationRecord(
222
+ persisted: ConversationRecord,
223
+ candidate: NewConversationRecord,
224
+ ): boolean {
225
+ const { sequence: _sequence, ...withoutSequence } = persisted;
226
+ return stableJson(withoutSequence) === stableJson(candidate);
227
+ }
228
+
229
+ const DETAIL_TABLES: Readonly<Record<ConversationRecordKind, string>> = Object.freeze({
230
+ message: "conversation_messages",
231
+ tool_call: "conversation_tool_call_events",
232
+ permission: "conversation_permission_events",
233
+ configuration: "conversation_configuration_events",
234
+ protocol: "conversation_protocol_records",
235
+ native_action: "conversation_native_action_events",
236
+ agent_action: "conversation_agent_action_events",
237
+ thinking: "conversation_thinking_events",
238
+ activity: "conversation_activity_events",
239
+ metering: "conversation_metering_references",
240
+ });
241
+
242
+ function recordFromRows(
243
+ row: ConversationRecordRow,
244
+ detail: Record<string, unknown>,
245
+ ): ConversationRecord {
246
+ const envelope = {
247
+ recordId: row.record_id,
248
+ agentSessionId: row.agent_session_id as AgentSessionId,
249
+ agentConversationId: row.agent_conversation_id as AgentConversationId,
250
+ sequence: Number(row.sequence),
251
+ kind: row.kind,
252
+ timestamp: row.timestamp,
253
+ ...(row.metadata !== null ? { metadata: row.metadata } : {}),
254
+ };
255
+ switch (row.kind as ConversationRecordKind) {
256
+ case "message":
257
+ return Object.freeze({
258
+ ...envelope,
259
+ kind: "message",
260
+ role: string(detail.role) as "assistant" | "user",
261
+ ...(detail.participant_id !== null ? { participantId: string(detail.participant_id) } : {}),
262
+ content: decodeContent(detail.content_text, detail.content_json),
263
+ ...(detail.status !== null ? { status: string(detail.status) as "in_progress" | "completed" | "cancelled" | "failed" } : {}),
264
+ });
265
+ case "tool_call":
266
+ return Object.freeze({
267
+ ...envelope,
268
+ kind: "tool_call",
269
+ toolCallId: string(detail.tool_call_id),
270
+ state: string(detail.state) as "announced" | "input" | "completed" | "failed",
271
+ ...(detail.name !== null ? { name: string(detail.name) } : {}),
272
+ ...(detail.input_json !== null ? { input: decodeJson(detail.input_json) } : {}),
273
+ ...(hasContent(detail.output_text, detail.output_json)
274
+ ? { output: decodeContent(detail.output_text, detail.output_json) }
275
+ : {}),
276
+ ...(detail.error !== null ? { error: string(detail.error) } : {}),
277
+ });
278
+ case "permission":
279
+ return Object.freeze({
280
+ ...envelope,
281
+ kind: "permission",
282
+ permissionId: string(detail.permission_id),
283
+ state: string(detail.state) as "requested" | "resolved",
284
+ ...(detail.request_json !== null ? { request: decodeJson(detail.request_json) } : {}),
285
+ ...(detail.outcome !== null ? { outcome: string(detail.outcome) as "approved" | "denied" | "cancelled" } : {}),
286
+ });
287
+ case "configuration":
288
+ return Object.freeze({
289
+ ...envelope,
290
+ kind: "configuration",
291
+ operation: string(detail.operation) as "set" | "restore" | "accept_effective" | "replace",
292
+ ...(detail.config_id !== null ? { configId: string(detail.config_id) } : {}),
293
+ ...(detail.value_json !== null ? { value: decodeJson(detail.value_json) } : {}),
294
+ status: string(detail.status) as "started" | "completed" | "failed",
295
+ ...(detail.error !== null ? { error: string(detail.error) } : {}),
296
+ });
297
+ case "protocol":
298
+ return Object.freeze({
299
+ ...envelope,
300
+ kind: "protocol",
301
+ direction: string(detail.direction) as "in" | "out" | "error",
302
+ ...(detail.method !== null ? { method: string(detail.method) } : {}),
303
+ ...(detail.message_json !== null ? { message: decodeJson(detail.message_json) } : {}),
304
+ });
305
+ case "native_action":
306
+ return Object.freeze({
307
+ ...envelope,
308
+ kind: "native_action",
309
+ action: string(detail.action),
310
+ ...(detail.transition_id !== null ? { transitionId: string(detail.transition_id) } : {}),
311
+ state: string(detail.state) as "started" | "checkpoint" | "completed" | "failed",
312
+ ...(detail.input_json !== null ? { input: decodeJson(detail.input_json) } : {}),
313
+ ...(detail.output_json !== null ? { output: decodeJson(detail.output_json) } : {}),
314
+ ...(detail.error !== null ? { error: string(detail.error) } : {}),
315
+ });
316
+ case "agent_action":
317
+ return Object.freeze({
318
+ ...envelope,
319
+ kind: "agent_action",
320
+ action: string(detail.action),
321
+ state: string(detail.state) as "requested" | "completed" | "failed",
322
+ ...(detail.input_json !== null ? { input: decodeJson(detail.input_json) } : {}),
323
+ ...(detail.output_json !== null ? { output: decodeJson(detail.output_json) } : {}),
324
+ ...(detail.error !== null ? { error: string(detail.error) } : {}),
325
+ });
326
+ case "thinking":
327
+ return Object.freeze({
328
+ ...envelope,
329
+ kind: "thinking",
330
+ thinkingId: string(detail.thinking_id),
331
+ state: string(detail.state) as "in_progress" | "completed" | "failed",
332
+ content: decodeContent(detail.content_text, detail.content_json),
333
+ });
334
+ case "activity":
335
+ return Object.freeze({
336
+ ...envelope,
337
+ kind: "activity",
338
+ activityId: string(detail.activity_id),
339
+ activityType: string(detail.activity_type),
340
+ state: string(detail.state) as "in_progress" | "completed" | "failed",
341
+ ...(hasContent(detail.content_text, detail.content_json)
342
+ ? { content: decodeContent(detail.content_text, detail.content_json) }
343
+ : {}),
344
+ ...(detail.data_json !== null ? { data: decodeJson(detail.data_json) } : {}),
345
+ });
346
+ case "metering":
347
+ return Object.freeze({
348
+ ...envelope,
349
+ kind: "metering",
350
+ operationId: string(detail.operation_id),
351
+ meteringRecordId: string(detail.metering_record_id),
352
+ status: string(detail.status) as "available" | "partial" | "unavailable",
353
+ });
354
+ }
355
+ }
356
+
357
+ function encodeContent(content: PersistedContent): { text: string | null; json: string | null } {
358
+ return typeof content === "string"
359
+ ? { text: content, json: null }
360
+ : { text: null, json: JSON.stringify(content) };
361
+ }
362
+
363
+ function encodeOptionalContent(content: PersistedContent | undefined) {
364
+ return content === undefined ? { text: null, json: null } : encodeContent(content);
365
+ }
366
+
367
+ function decodeContent(text: unknown, json: unknown): PersistedContent {
368
+ if (text !== null) return string(text);
369
+ if (json !== null) return decodeJson(json) as PersistedContent;
370
+ throw new Error("persisted content has neither text nor structured data");
371
+ }
372
+
373
+ function hasContent(text: unknown, json: unknown): boolean {
374
+ return text !== null || json !== null;
375
+ }
376
+
377
+ function encodeJson(value: PersistenceJsonValue | undefined): string | null {
378
+ return value === undefined ? null : JSON.stringify(value);
379
+ }
380
+
381
+ function decodeJson(value: unknown): PersistenceJsonValue {
382
+ return JSON.parse(string(value)) as PersistenceJsonValue;
383
+ }
384
+
385
+ function searchableContent(content: PersistedContent): string {
386
+ return typeof content === "string" ? content : searchableJson(content);
387
+ }
388
+
389
+ function searchableJson(value: PersistenceJsonValue | undefined): string {
390
+ if (value === undefined || value === null) return "";
391
+ if (typeof value === "string" || typeof value === "number" || typeof value === "boolean") {
392
+ return String(value);
393
+ }
394
+ if (Array.isArray(value)) return joinSearchText(value.map((item) => searchableJson(item)));
395
+ return joinSearchText(Object.values(value).map((item) => searchableJson(item)));
396
+ }
397
+
398
+ function joinSearchText(values: readonly (string | undefined)[]): string {
399
+ return values.filter((value): value is string => Boolean(value?.trim())).join("\n");
400
+ }
401
+
402
+ function uniqueKinds(rows: readonly ConversationRecordRow[]): ConversationRecordKind[] {
403
+ return [...new Set(rows.map((row) => row.kind as ConversationRecordKind))];
404
+ }
405
+
406
+ function stableJson(value: unknown): string {
407
+ if (Array.isArray(value)) return `[${value.map(stableJson).join(",")}]`;
408
+ if (value && typeof value === "object") {
409
+ return `{${Object.entries(value as Record<string, unknown>)
410
+ .filter(([, child]) => child !== undefined)
411
+ .sort(([left], [right]) => left.localeCompare(right))
412
+ .map(([key, child]) => `${JSON.stringify(key)}:${stableJson(child)}`)
413
+ .join(",")}}`;
414
+ }
415
+ return JSON.stringify(value);
416
+ }
417
+
418
+ function string(value: unknown): string {
419
+ if (typeof value !== "string") throw new Error("persisted conversation detail is malformed");
420
+ return value;
421
+ }
422
+
423
+ function run(database: Database, sql: string, ...values: SqlValue[]): void {
424
+ database.query(sql).run(...values);
425
+ }
@@ -0,0 +1,106 @@
1
+ import { Database } from "bun:sqlite";
2
+ import { chmod } from "node:fs/promises";
3
+ import { randomUUID } from "node:crypto";
4
+
5
+ const heldOwnershipKeys = new Set<string>();
6
+
7
+ export class SqliteOwnerLockConflictError extends Error {
8
+ readonly ownershipKey: string;
9
+ readonly lockPath: string;
10
+
11
+ constructor(ownershipKey: string, lockPath: string, options?: ErrorOptions) {
12
+ super(`SQLite ownership is already held for ${ownershipKey}`, options);
13
+ this.name = "SqliteOwnerLockConflictError";
14
+ this.ownershipKey = ownershipKey;
15
+ this.lockPath = lockPath;
16
+ }
17
+ }
18
+
19
+ /**
20
+ * Process-lifetime ownership backed by SQLite's own cross-process file locks.
21
+ *
22
+ * The sidecar contains no application state. Its live connection is the lock, while the
23
+ * file itself may safely remain after close or process termination.
24
+ */
25
+ export class SqliteOwnerLock {
26
+ private closed = false;
27
+
28
+ private constructor(
29
+ readonly ownershipKey: string,
30
+ readonly lockPath: string,
31
+ private readonly database: Database,
32
+ ) {}
33
+
34
+ static async acquire(ownershipKey: string, lockPath: string): Promise<SqliteOwnerLock> {
35
+ if (heldOwnershipKeys.has(ownershipKey)) {
36
+ throw new SqliteOwnerLockConflictError(ownershipKey, lockPath);
37
+ }
38
+
39
+ let database: Database | undefined;
40
+ try {
41
+ database = new Database(lockPath, { create: true, readwrite: true, strict: true });
42
+ database.exec("PRAGMA busy_timeout = 0");
43
+ const lockingMode = database.query<{ locking_mode: string }, []>(
44
+ "PRAGMA locking_mode = EXCLUSIVE",
45
+ ).get()?.locking_mode;
46
+ if (lockingMode?.toLowerCase() !== "exclusive") {
47
+ throw new Error(`SQLite ownership sidecar did not enter exclusive mode: ${lockPath}`);
48
+ }
49
+
50
+ database.exec("BEGIN EXCLUSIVE");
51
+ database.exec(`
52
+ CREATE TABLE IF NOT EXISTS owner_probe (
53
+ singleton INTEGER PRIMARY KEY CHECK (singleton = 1),
54
+ owner_token TEXT NOT NULL,
55
+ acquired_at TEXT NOT NULL
56
+ )
57
+ `);
58
+ database.query<unknown, [string, string]>(
59
+ `INSERT INTO owner_probe(singleton, owner_token, acquired_at)
60
+ VALUES (1, ?, ?)
61
+ ON CONFLICT(singleton) DO UPDATE SET
62
+ owner_token = excluded.owner_token,
63
+ acquired_at = excluded.acquired_at`,
64
+ ).run(randomUUID(), new Date().toISOString());
65
+ database.exec("COMMIT");
66
+
67
+ // Retain the Database instance: exclusive mode keeps its file lock until close.
68
+ await chmod(lockPath, 0o600);
69
+ heldOwnershipKeys.add(ownershipKey);
70
+ return new SqliteOwnerLock(ownershipKey, lockPath, database);
71
+ } catch (error) {
72
+ if (database?.inTransaction) {
73
+ try {
74
+ database.exec("ROLLBACK");
75
+ } catch {
76
+ // Preserve the acquisition failure.
77
+ }
78
+ }
79
+ try {
80
+ database?.close();
81
+ } catch {
82
+ // Preserve the acquisition failure.
83
+ }
84
+ if (error instanceof SqliteOwnerLockConflictError || isSqliteLockConflict(error)) {
85
+ throw new SqliteOwnerLockConflictError(ownershipKey, lockPath, { cause: error });
86
+ }
87
+ throw error;
88
+ }
89
+ }
90
+
91
+ close(): void {
92
+ if (this.closed) return;
93
+ this.closed = true;
94
+ try {
95
+ this.database.close();
96
+ } finally {
97
+ heldOwnershipKeys.delete(this.ownershipKey);
98
+ }
99
+ }
100
+ }
101
+
102
+ function isSqliteLockConflict(error: unknown): boolean {
103
+ if (!error || typeof error !== "object") return false;
104
+ const code = "code" in error ? String(error.code) : "";
105
+ return code === "SQLITE_BUSY" || code === "SQLITE_LOCKED";
106
+ }