@creatornader/agent-bridge 0.2.0 → 0.3.1
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/CHANGELOG.md +86 -4
- package/README.md +567 -55
- package/ROADMAP.md +114 -0
- package/SECURITY.md +90 -0
- package/SKILL.md +68 -2
- package/bin/agent-bridge +2 -2
- package/clients/claude-desktop.json +3 -1
- package/dist/archive.d.ts +163 -0
- package/dist/archive.js +50 -0
- package/dist/archive.js.map +1 -0
- package/dist/bridge-domain-CBX3IVqC.d.ts +153 -0
- package/dist/{bridge-service-CfqMcMAn.d.ts → bridge-service-hX1ZQp4W.d.ts} +15 -5
- package/dist/bridge-store-DPVSCwfs.d.ts +102 -0
- package/dist/bridge.d.ts +76 -17
- package/dist/bridge.js +52 -24
- package/dist/chunk-2DFNOLMO.js +618 -0
- package/dist/chunk-2DFNOLMO.js.map +1 -0
- package/dist/{chunk-KVR4JBRF.js → chunk-2EVLG3YA.js} +2 -2
- package/dist/{chunk-KVR4JBRF.js.map → chunk-2EVLG3YA.js.map} +1 -1
- package/dist/chunk-45BZGB77.js +709 -0
- package/dist/chunk-45BZGB77.js.map +1 -0
- package/dist/chunk-4VB44KJU.js +230 -0
- package/dist/chunk-4VB44KJU.js.map +1 -0
- package/dist/chunk-5GMB3A77.js +1013 -0
- package/dist/chunk-5GMB3A77.js.map +1 -0
- package/dist/chunk-A6W4QALF.js +1258 -0
- package/dist/chunk-A6W4QALF.js.map +1 -0
- package/dist/chunk-BZLMF5O5.js +328 -0
- package/dist/chunk-BZLMF5O5.js.map +1 -0
- package/dist/{chunk-AXL2I7FH.js → chunk-CEXBMOI5.js} +240 -79
- package/dist/chunk-CEXBMOI5.js.map +1 -0
- package/dist/chunk-GADH244D.js +527 -0
- package/dist/chunk-GADH244D.js.map +1 -0
- package/dist/chunk-MBPZXTJA.js +2428 -0
- package/dist/chunk-MBPZXTJA.js.map +1 -0
- package/dist/chunk-NCO7RLBM.js +146 -0
- package/dist/chunk-NCO7RLBM.js.map +1 -0
- package/dist/chunk-Q6PPMXJC.js +1050 -0
- package/dist/chunk-Q6PPMXJC.js.map +1 -0
- package/dist/{chunk-4KAOBC5X.js → chunk-SPSMZOCJ.js} +190 -165
- package/dist/chunk-SPSMZOCJ.js.map +1 -0
- package/dist/chunk-UAHMP6GC.js +54 -0
- package/dist/chunk-UAHMP6GC.js.map +1 -0
- package/dist/{chunk-YD6YJATN.js → chunk-VOQIDTCJ.js} +4 -2
- package/dist/chunk-VOQIDTCJ.js.map +1 -0
- package/dist/chunk-WAI2IYIQ.js +554 -0
- package/dist/chunk-WAI2IYIQ.js.map +1 -0
- package/dist/cli.d.ts +2 -1
- package/dist/cli.js +3555 -214
- package/dist/cli.js.map +1 -1
- package/dist/client-config.d.ts +1 -1
- package/dist/client-config.js +1 -1
- package/dist/client-runtime.d.ts +10 -6
- package/dist/client-runtime.js +9 -6
- package/dist/contracts/generate.d.ts +2 -0
- package/dist/contracts/generate.js +247 -0
- package/dist/contracts/generate.js.map +1 -0
- package/dist/dr.d.ts +324 -0
- package/dist/dr.js +124 -0
- package/dist/dr.js.map +1 -0
- package/dist/gateway-CggQ8vTC.d.ts +78 -0
- package/dist/gateway-main.js +190 -8
- package/dist/gateway-main.js.map +1 -1
- package/dist/gateway.d.ts +4 -3
- package/dist/gateway.js +4 -3
- package/dist/index.js +11 -8
- package/dist/index.js.map +1 -1
- package/dist/postgres-bridge-store-Bfd3hRId.d.ts +49 -0
- package/dist/server.d.ts +3 -2
- package/dist/server.js +13 -8
- package/dist/sqlite.d.ts +94 -12
- package/dist/sqlite.js +7 -4
- package/docs/architecture-v2.md +394 -0
- package/docs/decisions/0001-protocol-layers-and-acknowledgment-semantics.md +85 -0
- package/docs/decisions/0002-canonical-operation-contract-registry.md +46 -0
- package/docs/decisions/0003-host-adapters-and-consumer-instance-keys.md +88 -0
- package/docs/ecosystem.md +86 -0
- package/docs/postmortems/2026-07-08-wrapper-source-drift.md +82 -0
- package/docs/troubleshooting.md +89 -0
- package/llms.txt +107 -6
- package/openapi/agent-bridge-v2.openapi.json +9610 -0
- package/package.json +24 -4
- package/schemas/agent-bridge-v2.capabilities.json +1829 -0
- package/schemas/agent-bridge-v2.mcp.json +2074 -0
- package/schemas/agent-bridge-v2.schema.json +4560 -0
- package/sql/migrations/008_message_projects.sql +36 -0
- package/sql/migrations/009_mailbox_query_indexes.sql +28 -0
- package/sql/migrations/010_publisher_delivery_policy.sql +210 -0
- package/sql/migrations/011_credential_security.sql +875 -0
- package/sql/migrations/012_request_authority.sql +177 -0
- package/sql/migrations/013_row_isolation.sql +495 -0
- package/sql/migrations/014_owner_control_plane.sql +1641 -0
- package/sql/migrations/015_portable_archives.sql +1813 -0
- package/sql/migrations/016_native_dr_fence.sql +1005 -0
- package/bin/CLAUDE.md +0 -11
- package/dist/bridge-domain-BcnBeHOn.d.ts +0 -97
- package/dist/bridge-store-BuGjxTn4.d.ts +0 -61
- package/dist/chunk-4KAOBC5X.js.map +0 -1
- package/dist/chunk-6MAZ6YLZ.js +0 -146
- package/dist/chunk-6MAZ6YLZ.js.map +0 -1
- package/dist/chunk-AXL2I7FH.js.map +0 -1
- package/dist/chunk-BV6W4AJK.js +0 -211
- package/dist/chunk-BV6W4AJK.js.map +0 -1
- package/dist/chunk-CKSKUBDQ.js +0 -153
- package/dist/chunk-CKSKUBDQ.js.map +0 -1
- package/dist/chunk-JOUBDRYX.js +0 -272
- package/dist/chunk-JOUBDRYX.js.map +0 -1
- package/dist/chunk-JTC5YURG.js +0 -49
- package/dist/chunk-JTC5YURG.js.map +0 -1
- package/dist/chunk-O26W5QHS.js +0 -409
- package/dist/chunk-O26W5QHS.js.map +0 -1
- package/dist/chunk-WEULPMUY.js +0 -988
- package/dist/chunk-WEULPMUY.js.map +0 -1
- package/dist/chunk-YD6YJATN.js.map +0 -1
- package/dist/gateway-BULozv3K.d.ts +0 -54
|
@@ -0,0 +1,1050 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import {
|
|
3
|
+
assertEdgeUpgradeCandidate,
|
|
4
|
+
installEdgeMarkers,
|
|
5
|
+
retrySqliteBusy
|
|
6
|
+
} from "./chunk-5GMB3A77.js";
|
|
7
|
+
import {
|
|
8
|
+
preparePrivateSqliteLocation,
|
|
9
|
+
securePrivatePath,
|
|
10
|
+
verifyPrivatePathAccess
|
|
11
|
+
} from "./chunk-NCO7RLBM.js";
|
|
12
|
+
import {
|
|
13
|
+
cursorScope,
|
|
14
|
+
decodeCursor,
|
|
15
|
+
encodeCursor
|
|
16
|
+
} from "./chunk-BZLMF5O5.js";
|
|
17
|
+
|
|
18
|
+
// src/sqlite-edge-store.ts
|
|
19
|
+
import { createHash, randomUUID } from "crypto";
|
|
20
|
+
import { existsSync, lstatSync } from "fs";
|
|
21
|
+
import { createRequire } from "module";
|
|
22
|
+
var require2 = createRequire(import.meta.url);
|
|
23
|
+
function openDatabase(path) {
|
|
24
|
+
const { DatabaseSync } = require2("node:sqlite");
|
|
25
|
+
return new DatabaseSync(path);
|
|
26
|
+
}
|
|
27
|
+
var MAX_SEQUENCE = 9223372036854775807n;
|
|
28
|
+
var schema = `
|
|
29
|
+
PRAGMA journal_mode = WAL;
|
|
30
|
+
PRAGMA synchronous = FULL;
|
|
31
|
+
PRAGMA foreign_keys = ON;
|
|
32
|
+
CREATE TABLE IF NOT EXISTS edge_scopes (
|
|
33
|
+
scope_key TEXT PRIMARY KEY,
|
|
34
|
+
endpoint_hash TEXT NOT NULL,
|
|
35
|
+
workspace TEXT NOT NULL,
|
|
36
|
+
agent TEXT NOT NULL,
|
|
37
|
+
pull_cursor TEXT,
|
|
38
|
+
last_sync_at TEXT,
|
|
39
|
+
last_error TEXT,
|
|
40
|
+
last_outbound_sync_at TEXT,
|
|
41
|
+
last_inbound_sync_at TEXT,
|
|
42
|
+
last_attempt_at TEXT,
|
|
43
|
+
cache_contract INTEGER NOT NULL DEFAULT 1
|
|
44
|
+
);
|
|
45
|
+
CREATE TABLE IF NOT EXISTS edge_outbox (
|
|
46
|
+
position INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
47
|
+
scope_key TEXT NOT NULL REFERENCES edge_scopes(scope_key),
|
|
48
|
+
message_id TEXT NOT NULL,
|
|
49
|
+
idempotency_key TEXT NOT NULL,
|
|
50
|
+
payload_hash TEXT NOT NULL,
|
|
51
|
+
draft_json TEXT NOT NULL,
|
|
52
|
+
state TEXT NOT NULL CHECK(state IN ('pending', 'blocked')),
|
|
53
|
+
attempts INTEGER NOT NULL DEFAULT 0,
|
|
54
|
+
available_at TEXT NOT NULL,
|
|
55
|
+
lease_token TEXT,
|
|
56
|
+
lease_expires_at TEXT,
|
|
57
|
+
last_error TEXT,
|
|
58
|
+
blocked_at TEXT,
|
|
59
|
+
created_at TEXT NOT NULL,
|
|
60
|
+
UNIQUE(scope_key, message_id),
|
|
61
|
+
UNIQUE(scope_key, idempotency_key)
|
|
62
|
+
);
|
|
63
|
+
CREATE INDEX IF NOT EXISTS edge_outbox_due
|
|
64
|
+
ON edge_outbox(scope_key, state, available_at, position);
|
|
65
|
+
CREATE TABLE IF NOT EXISTS edge_inbox (
|
|
66
|
+
scope_key TEXT NOT NULL REFERENCES edge_scopes(scope_key),
|
|
67
|
+
message_id TEXT NOT NULL,
|
|
68
|
+
remote_sequence TEXT NOT NULL,
|
|
69
|
+
sequence_key TEXT NOT NULL,
|
|
70
|
+
workspace TEXT NOT NULL,
|
|
71
|
+
project TEXT,
|
|
72
|
+
source TEXT NOT NULL,
|
|
73
|
+
type TEXT NOT NULL,
|
|
74
|
+
thread_id TEXT,
|
|
75
|
+
created_at TEXT NOT NULL,
|
|
76
|
+
expires_at TEXT,
|
|
77
|
+
message_json TEXT NOT NULL,
|
|
78
|
+
PRIMARY KEY(scope_key, message_id),
|
|
79
|
+
UNIQUE(scope_key, sequence_key)
|
|
80
|
+
);
|
|
81
|
+
CREATE INDEX IF NOT EXISTS edge_inbox_cursor
|
|
82
|
+
ON edge_inbox(scope_key, sequence_key);
|
|
83
|
+
CREATE INDEX IF NOT EXISTS edge_inbox_source
|
|
84
|
+
ON edge_inbox(scope_key, source, sequence_key);
|
|
85
|
+
CREATE INDEX IF NOT EXISTS edge_inbox_thread
|
|
86
|
+
ON edge_inbox(scope_key, thread_id, sequence_key);
|
|
87
|
+
CREATE INDEX IF NOT EXISTS edge_inbox_created
|
|
88
|
+
ON edge_inbox(scope_key, created_at, sequence_key);
|
|
89
|
+
`;
|
|
90
|
+
var EdgeConflictError = class extends Error {
|
|
91
|
+
constructor() {
|
|
92
|
+
super(...arguments);
|
|
93
|
+
this.code = "edge_idempotency_conflict";
|
|
94
|
+
}
|
|
95
|
+
};
|
|
96
|
+
function canonical(value) {
|
|
97
|
+
if (value === void 0) return "null";
|
|
98
|
+
if (value === null || typeof value !== "object") return JSON.stringify(value);
|
|
99
|
+
if (Array.isArray(value)) return `[${value.map(canonical).join(",")}]`;
|
|
100
|
+
return `{${Object.keys(value).filter((key) => value[key] !== void 0).sort().map((key) => `${JSON.stringify(key)}:${canonical(value[key])}`).join(",")}}`;
|
|
101
|
+
}
|
|
102
|
+
function intent(message) {
|
|
103
|
+
const deliveryPolicy = message.deliveryPolicy ?? (message.targets.length ? { mode: "leased", maxAttempts: 5, retryBaseDelayMs: 1e3, retryMaxDelayMs: 6e4, retryJitterRatio: 0.2 } : { mode: "mailbox" });
|
|
104
|
+
return {
|
|
105
|
+
workspace: message.workspace,
|
|
106
|
+
project: message.project ?? null,
|
|
107
|
+
source: message.source,
|
|
108
|
+
type: message.type,
|
|
109
|
+
content: message.content,
|
|
110
|
+
contentType: message.contentType,
|
|
111
|
+
data: message.data ?? null,
|
|
112
|
+
targets: [...message.targets].sort(),
|
|
113
|
+
threadId: message.threadId ?? null,
|
|
114
|
+
replyToId: message.replyToId ?? null,
|
|
115
|
+
correlationId: message.correlationId ?? null,
|
|
116
|
+
causationId: message.causationId ?? null,
|
|
117
|
+
priority: message.priority,
|
|
118
|
+
expiresAt: message.expiresAt ?? null,
|
|
119
|
+
atribReceiptId: message.atribReceiptId ?? null,
|
|
120
|
+
informedBy: [...message.informedBy ?? []].sort(),
|
|
121
|
+
metadata: message.metadata ?? null,
|
|
122
|
+
deliveryPolicy
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
function edgeMessageFingerprint(message) {
|
|
126
|
+
return createHash("sha256").update(canonical(intent(message))).digest("hex");
|
|
127
|
+
}
|
|
128
|
+
function stableIdempotency(message) {
|
|
129
|
+
return message.idempotencyKey ? message : { ...message, idempotencyKey: `agent-bridge:id:${message.id}` };
|
|
130
|
+
}
|
|
131
|
+
function edgeScopeKey(scope) {
|
|
132
|
+
return createHash("sha256").update(`${scope.endpoint.replace(/\/$/, "")}\0${scope.principal.workspace}\0${scope.principal.agent}`).digest("hex");
|
|
133
|
+
}
|
|
134
|
+
function sequenceKey(sequence) {
|
|
135
|
+
if (!/^(0|[1-9][0-9]*)$/.test(sequence) || BigInt(sequence) > MAX_SEQUENCE) {
|
|
136
|
+
throw new EdgeConflictError("remote sequence is invalid");
|
|
137
|
+
}
|
|
138
|
+
return sequence.padStart(19, "0");
|
|
139
|
+
}
|
|
140
|
+
function parseDraft(value) {
|
|
141
|
+
return JSON.parse(String(value));
|
|
142
|
+
}
|
|
143
|
+
function parseMessage(value) {
|
|
144
|
+
return JSON.parse(String(value));
|
|
145
|
+
}
|
|
146
|
+
var SQLiteEdgeStore = class {
|
|
147
|
+
constructor(path, scope, busyTimeoutMs = 2e3) {
|
|
148
|
+
this.path = path;
|
|
149
|
+
this.scope = scope;
|
|
150
|
+
this.busyTimeoutMs = busyTimeoutMs;
|
|
151
|
+
this.initialized = false;
|
|
152
|
+
const selected = preparePrivateSqliteLocation(path, true);
|
|
153
|
+
this.databasePath = selected;
|
|
154
|
+
this.preexistingFiles = new Set(selected === ":memory:" ? [] : [selected, `${selected}-wal`, `${selected}-shm`].filter(existsSync));
|
|
155
|
+
const before = selected === ":memory:" || !existsSync(selected) ? void 0 : lstatSync(selected);
|
|
156
|
+
this.db = openDatabase(selected);
|
|
157
|
+
try {
|
|
158
|
+
this.db.exec(`PRAGMA busy_timeout = ${Math.max(1, Math.trunc(this.busyTimeoutMs))}`);
|
|
159
|
+
this.restrictFiles();
|
|
160
|
+
if (before) {
|
|
161
|
+
const after = lstatSync(selected);
|
|
162
|
+
if (after.dev !== before.dev || after.ino !== before.ino) throw new Error("SQLite edge database path identity changed while opening");
|
|
163
|
+
}
|
|
164
|
+
} catch (error) {
|
|
165
|
+
this.db.close();
|
|
166
|
+
throw error;
|
|
167
|
+
}
|
|
168
|
+
this.key = edgeScopeKey(scope);
|
|
169
|
+
}
|
|
170
|
+
restrictFiles() {
|
|
171
|
+
if (this.databasePath === ":memory:") return;
|
|
172
|
+
for (const path of [this.databasePath, `${this.databasePath}-wal`, `${this.databasePath}-shm`]) {
|
|
173
|
+
if (!existsSync(path)) continue;
|
|
174
|
+
if (path === this.databasePath && this.preexistingFiles.has(path)) verifyPrivatePathAccess(path, "file");
|
|
175
|
+
else securePrivatePath(path, "file");
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
get scopeKey() {
|
|
179
|
+
return this.key;
|
|
180
|
+
}
|
|
181
|
+
async initialize() {
|
|
182
|
+
if (this.initialized) return;
|
|
183
|
+
if (!this.initialization) {
|
|
184
|
+
this.initialization = this.initializeOnce().then(() => {
|
|
185
|
+
this.initialized = true;
|
|
186
|
+
}).catch((error) => {
|
|
187
|
+
this.initialization = void 0;
|
|
188
|
+
throw error;
|
|
189
|
+
});
|
|
190
|
+
}
|
|
191
|
+
return this.initialization;
|
|
192
|
+
}
|
|
193
|
+
async initializeOnce() {
|
|
194
|
+
assertEdgeUpgradeCandidate(this.db);
|
|
195
|
+
await retrySqliteBusy(() => this.db.exec(schema), this.busyTimeoutMs);
|
|
196
|
+
await retrySqliteBusy(() => this.db.exec("BEGIN IMMEDIATE"), this.busyTimeoutMs);
|
|
197
|
+
try {
|
|
198
|
+
const scopeColumns = this.db.prepare("PRAGMA table_info(edge_scopes)").all();
|
|
199
|
+
if (!scopeColumns.some((column) => column.name === "cache_contract")) {
|
|
200
|
+
this.db.exec("ALTER TABLE edge_scopes ADD COLUMN cache_contract INTEGER NOT NULL DEFAULT 0");
|
|
201
|
+
}
|
|
202
|
+
for (const name of ["last_outbound_sync_at", "last_inbound_sync_at", "last_attempt_at"]) {
|
|
203
|
+
if (!scopeColumns.some((column) => column.name === name)) {
|
|
204
|
+
this.db.exec(`ALTER TABLE edge_scopes ADD COLUMN ${name} TEXT`);
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
const columns = this.db.prepare("PRAGMA table_info(edge_inbox)").all();
|
|
208
|
+
if (!columns.some((column) => column.name === "project")) {
|
|
209
|
+
this.db.exec("ALTER TABLE edge_inbox ADD COLUMN project TEXT");
|
|
210
|
+
}
|
|
211
|
+
this.db.exec("CREATE INDEX IF NOT EXISTS edge_inbox_project ON edge_inbox(scope_key, project, sequence_key)");
|
|
212
|
+
const outboxColumns = this.db.prepare("PRAGMA table_info(edge_outbox)").all();
|
|
213
|
+
if (!outboxColumns.some((column) => column.name === "blocked_at")) {
|
|
214
|
+
this.db.exec("ALTER TABLE edge_outbox ADD COLUMN blocked_at TEXT");
|
|
215
|
+
}
|
|
216
|
+
installEdgeMarkers(this.db);
|
|
217
|
+
this.db.exec("COMMIT");
|
|
218
|
+
} catch (error) {
|
|
219
|
+
this.db.exec("ROLLBACK");
|
|
220
|
+
throw error;
|
|
221
|
+
}
|
|
222
|
+
this.restrictFiles();
|
|
223
|
+
const endpointHash = createHash("sha256").update(this.scope.endpoint.replace(/\/$/, "")).digest("hex");
|
|
224
|
+
this.db.prepare(`INSERT INTO edge_scopes (scope_key, endpoint_hash, workspace, agent)
|
|
225
|
+
VALUES (?, ?, ?, ?) ON CONFLICT(scope_key) DO NOTHING`).run(this.key, endpointHash, this.scope.principal.workspace, this.scope.principal.agent);
|
|
226
|
+
const contract = this.db.prepare("SELECT cache_contract FROM edge_scopes WHERE scope_key=?").get(this.key);
|
|
227
|
+
if (Number(contract.cache_contract) < 1) {
|
|
228
|
+
this.db.exec("BEGIN IMMEDIATE");
|
|
229
|
+
try {
|
|
230
|
+
this.db.prepare("UPDATE edge_scopes SET pull_cursor=NULL, cache_contract=1 WHERE scope_key=?").run(this.key);
|
|
231
|
+
this.db.exec("COMMIT");
|
|
232
|
+
} catch (error) {
|
|
233
|
+
this.db.exec("ROLLBACK");
|
|
234
|
+
throw error;
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
async ready() {
|
|
239
|
+
await this.initialize();
|
|
240
|
+
}
|
|
241
|
+
async enqueue(input, now = /* @__PURE__ */ new Date()) {
|
|
242
|
+
await this.ready();
|
|
243
|
+
const draft = stableIdempotency(input);
|
|
244
|
+
const payloadHash = edgeMessageFingerprint(draft);
|
|
245
|
+
const serialized = canonical(draft);
|
|
246
|
+
const nowText = now.toISOString();
|
|
247
|
+
this.db.exec("BEGIN IMMEDIATE");
|
|
248
|
+
try {
|
|
249
|
+
const existing = this.db.prepare(`SELECT * FROM edge_outbox
|
|
250
|
+
WHERE scope_key=? AND (message_id=? OR idempotency_key=?) ORDER BY position LIMIT 1`).get(this.key, draft.id, draft.idempotencyKey);
|
|
251
|
+
if (existing) {
|
|
252
|
+
if (String(existing.payload_hash) !== payloadHash) {
|
|
253
|
+
throw new EdgeConflictError("message ID or idempotency key is already bound to different content");
|
|
254
|
+
}
|
|
255
|
+
this.db.exec("COMMIT");
|
|
256
|
+
return { draft: parseDraft(existing.draft_json), created: false };
|
|
257
|
+
}
|
|
258
|
+
this.db.prepare(`INSERT INTO edge_outbox
|
|
259
|
+
(scope_key, message_id, idempotency_key, payload_hash, draft_json, state, available_at, created_at)
|
|
260
|
+
VALUES (?, ?, ?, ?, ?, 'pending', ?, ?)`).run(this.key, draft.id, draft.idempotencyKey, payloadHash, serialized, nowText, nowText);
|
|
261
|
+
this.db.exec("COMMIT");
|
|
262
|
+
return { draft, created: true };
|
|
263
|
+
} catch (error) {
|
|
264
|
+
this.db.exec("ROLLBACK");
|
|
265
|
+
throw error;
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
async claimNext(now = /* @__PURE__ */ new Date(), leaseMs = 3e4) {
|
|
269
|
+
await this.ready();
|
|
270
|
+
const nowText = now.toISOString();
|
|
271
|
+
this.db.exec("BEGIN IMMEDIATE");
|
|
272
|
+
try {
|
|
273
|
+
const head = this.db.prepare(`SELECT * FROM edge_outbox
|
|
274
|
+
WHERE scope_key=? AND state='pending' AND available_at<=?
|
|
275
|
+
AND (lease_expires_at IS NULL OR lease_expires_at<=?)
|
|
276
|
+
ORDER BY position LIMIT 1`).get(this.key, nowText, nowText);
|
|
277
|
+
if (!head) {
|
|
278
|
+
this.db.exec("COMMIT");
|
|
279
|
+
return void 0;
|
|
280
|
+
}
|
|
281
|
+
const leaseToken = randomUUID();
|
|
282
|
+
const leaseExpiresAt = new Date(now.getTime() + leaseMs).toISOString();
|
|
283
|
+
const updated = this.db.prepare(`UPDATE edge_outbox
|
|
284
|
+
SET lease_token=?, lease_expires_at=? WHERE scope_key=? AND position=?
|
|
285
|
+
AND (lease_expires_at IS NULL OR lease_expires_at<=?)`).run(leaseToken, leaseExpiresAt, this.key, Number(head.position), nowText);
|
|
286
|
+
if (!updated.changes) {
|
|
287
|
+
this.db.exec("COMMIT");
|
|
288
|
+
return void 0;
|
|
289
|
+
}
|
|
290
|
+
this.db.exec("COMMIT");
|
|
291
|
+
return {
|
|
292
|
+
position: Number(head.position),
|
|
293
|
+
draft: parseDraft(head.draft_json),
|
|
294
|
+
payloadHash: String(head.payload_hash),
|
|
295
|
+
attempts: Number(head.attempts),
|
|
296
|
+
leaseToken,
|
|
297
|
+
createdAt: String(head.created_at)
|
|
298
|
+
};
|
|
299
|
+
} catch (error) {
|
|
300
|
+
this.db.exec("ROLLBACK");
|
|
301
|
+
throw error;
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
async retry(record, error, availableAt) {
|
|
305
|
+
await this.ready();
|
|
306
|
+
this.db.prepare(`UPDATE edge_outbox SET attempts=attempts+1, available_at=?,
|
|
307
|
+
lease_token=NULL, lease_expires_at=NULL, last_error=?
|
|
308
|
+
WHERE scope_key=? AND position=? AND lease_token=?`).run(availableAt.toISOString(), error.slice(0, 256), this.key, record.position, record.leaseToken);
|
|
309
|
+
await this.noteError(error);
|
|
310
|
+
}
|
|
311
|
+
async block(record, error, now = /* @__PURE__ */ new Date()) {
|
|
312
|
+
await this.ready();
|
|
313
|
+
this.db.prepare(`UPDATE edge_outbox SET state='blocked', attempts=attempts+1,
|
|
314
|
+
lease_token=NULL, lease_expires_at=NULL, last_error=?, blocked_at=?
|
|
315
|
+
WHERE scope_key=? AND position=? AND lease_token=?`).run(error.slice(0, 256), now.toISOString(), this.key, record.position, record.leaseToken);
|
|
316
|
+
await this.noteError(error);
|
|
317
|
+
}
|
|
318
|
+
async commit(record, message, now = /* @__PURE__ */ new Date()) {
|
|
319
|
+
await this.ready();
|
|
320
|
+
this.db.exec("BEGIN IMMEDIATE");
|
|
321
|
+
try {
|
|
322
|
+
this.cacheOne(message);
|
|
323
|
+
const deleted = this.db.prepare(`DELETE FROM edge_outbox
|
|
324
|
+
WHERE scope_key=? AND position=? AND lease_token=?`).run(this.key, record.position, record.leaseToken);
|
|
325
|
+
if (deleted.changes !== 1) throw new EdgeConflictError("outbox lease was lost before commit");
|
|
326
|
+
this.db.prepare(`UPDATE edge_scopes SET last_sync_at=?, last_error=NULL WHERE scope_key=?`).run(now.toISOString(), this.key);
|
|
327
|
+
this.db.prepare("UPDATE edge_scopes SET last_outbound_sync_at=? WHERE scope_key=?").run(now.toISOString(), this.key);
|
|
328
|
+
this.db.exec("COMMIT");
|
|
329
|
+
} catch (error) {
|
|
330
|
+
this.db.exec("ROLLBACK");
|
|
331
|
+
throw error;
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
cacheOne(message) {
|
|
335
|
+
const serialized = canonical(message);
|
|
336
|
+
const key = sequenceKey(message.sequence);
|
|
337
|
+
const byId = this.db.prepare(`SELECT remote_sequence, message_json FROM edge_inbox
|
|
338
|
+
WHERE scope_key=? AND message_id=?`).get(this.key, message.id);
|
|
339
|
+
const bySequence = this.db.prepare(`SELECT message_id, message_json FROM edge_inbox
|
|
340
|
+
WHERE scope_key=? AND sequence_key=?`).get(this.key, key);
|
|
341
|
+
if (byId || bySequence) {
|
|
342
|
+
if (!byId || String(byId.remote_sequence) !== message.sequence || String(byId.message_json) !== serialized || bySequence && String(bySequence.message_id) !== message.id) {
|
|
343
|
+
throw new EdgeConflictError("cached message conflicts with immutable remote history");
|
|
344
|
+
}
|
|
345
|
+
return;
|
|
346
|
+
}
|
|
347
|
+
this.db.prepare(`INSERT INTO edge_inbox
|
|
348
|
+
(scope_key, message_id, remote_sequence, sequence_key, workspace, project, source, type,
|
|
349
|
+
thread_id, created_at, expires_at, message_json)
|
|
350
|
+
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`).run(
|
|
351
|
+
this.key,
|
|
352
|
+
message.id,
|
|
353
|
+
message.sequence,
|
|
354
|
+
key,
|
|
355
|
+
message.workspace,
|
|
356
|
+
message.project ?? null,
|
|
357
|
+
message.source,
|
|
358
|
+
message.type,
|
|
359
|
+
message.threadId ?? null,
|
|
360
|
+
message.createdAt,
|
|
361
|
+
message.expiresAt ?? null,
|
|
362
|
+
serialized
|
|
363
|
+
);
|
|
364
|
+
}
|
|
365
|
+
async cachePage(messages, cursor, now = /* @__PURE__ */ new Date()) {
|
|
366
|
+
await this.ready();
|
|
367
|
+
const scope = cursorScope(this.scope.principal, { mailbox: "all", includeExpired: true });
|
|
368
|
+
this.db.exec("BEGIN IMMEDIATE");
|
|
369
|
+
try {
|
|
370
|
+
for (const message of messages) this.cacheOne(message);
|
|
371
|
+
const current = this.db.prepare("SELECT pull_cursor FROM edge_scopes WHERE scope_key=?").get(this.key);
|
|
372
|
+
const currentCursor = current.pull_cursor ? String(current.pull_cursor) : void 0;
|
|
373
|
+
const nextCursor = !cursor ? currentCursor : !currentCursor || sequenceKey(decodeCursor(cursor, scope)) >= sequenceKey(decodeCursor(currentCursor, scope)) ? cursor : currentCursor;
|
|
374
|
+
this.db.prepare(`UPDATE edge_scopes SET pull_cursor=?, last_sync_at=?, last_error=NULL
|
|
375
|
+
WHERE scope_key=?`).run(nextCursor ?? null, now.toISOString(), this.key);
|
|
376
|
+
this.db.prepare("UPDATE edge_scopes SET last_inbound_sync_at=? WHERE scope_key=?").run(now.toISOString(), this.key);
|
|
377
|
+
this.db.exec("COMMIT");
|
|
378
|
+
} catch (error) {
|
|
379
|
+
this.db.exec("ROLLBACK");
|
|
380
|
+
throw error;
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
async cacheLatest(messages, now = /* @__PURE__ */ new Date()) {
|
|
384
|
+
await this.ready();
|
|
385
|
+
this.db.exec("BEGIN IMMEDIATE");
|
|
386
|
+
try {
|
|
387
|
+
for (const message of messages) this.cacheOne(message);
|
|
388
|
+
this.db.prepare(`UPDATE edge_scopes SET last_sync_at=?, last_error=NULL WHERE scope_key=?`).run(now.toISOString(), this.key);
|
|
389
|
+
this.db.prepare("UPDATE edge_scopes SET last_inbound_sync_at=? WHERE scope_key=?").run(now.toISOString(), this.key);
|
|
390
|
+
this.db.exec("COMMIT");
|
|
391
|
+
} catch (error) {
|
|
392
|
+
this.db.exec("ROLLBACK");
|
|
393
|
+
throw error;
|
|
394
|
+
}
|
|
395
|
+
}
|
|
396
|
+
async list(query = {}) {
|
|
397
|
+
await this.ready();
|
|
398
|
+
const scope = cursorScope(this.scope.principal, query);
|
|
399
|
+
const inputSequence = query.latest ? void 0 : decodeCursor(query.cursor, scope) ?? "0";
|
|
400
|
+
const cachedHighWater = query.latest ? void 0 : this.db.prepare(`SELECT remote_sequence
|
|
401
|
+
FROM edge_inbox WHERE scope_key=? ORDER BY sequence_key DESC LIMIT 1`).get(this.key);
|
|
402
|
+
const syncState = query.latest ? void 0 : this.db.prepare(
|
|
403
|
+
"SELECT pull_cursor FROM edge_scopes WHERE scope_key=?"
|
|
404
|
+
).get(this.key);
|
|
405
|
+
const syncScope = cursorScope(this.scope.principal, {
|
|
406
|
+
mailbox: "all",
|
|
407
|
+
includeExpired: true
|
|
408
|
+
});
|
|
409
|
+
const syncSequence = syncState?.pull_cursor ? decodeCursor(String(syncState.pull_cursor), syncScope) ?? "0" : "0";
|
|
410
|
+
const highWaterSequence = query.latest ? void 0 : [
|
|
411
|
+
inputSequence ?? "0",
|
|
412
|
+
syncSequence,
|
|
413
|
+
cachedHighWater?.remote_sequence ? String(cachedHighWater.remote_sequence) : "0"
|
|
414
|
+
].reduce((highest, candidate) => sequenceKey(candidate) > sequenceKey(highest) ? candidate : highest, "0");
|
|
415
|
+
const clauses = ["scope_key=?"];
|
|
416
|
+
const args = [this.key];
|
|
417
|
+
if (!query.latest) {
|
|
418
|
+
clauses.push("sequence_key>?");
|
|
419
|
+
args.push(sequenceKey(inputSequence ?? "0"));
|
|
420
|
+
}
|
|
421
|
+
if (!query.includeExpired) {
|
|
422
|
+
clauses.push("(expires_at IS NULL OR expires_at>?)");
|
|
423
|
+
args.push((/* @__PURE__ */ new Date()).toISOString());
|
|
424
|
+
}
|
|
425
|
+
if (query.types?.length) {
|
|
426
|
+
clauses.push(`type IN (${query.types.map(() => "?").join(",")})`);
|
|
427
|
+
args.push(...query.types);
|
|
428
|
+
}
|
|
429
|
+
if (query.source) {
|
|
430
|
+
clauses.push("source=?");
|
|
431
|
+
args.push(query.source);
|
|
432
|
+
}
|
|
433
|
+
const mailbox = query.mailbox ?? "inbox";
|
|
434
|
+
if (mailbox === "sent") {
|
|
435
|
+
clauses.push("source=?");
|
|
436
|
+
args.push(this.scope.principal.agent);
|
|
437
|
+
} else if (mailbox !== "all") {
|
|
438
|
+
clauses.push("(json_array_length(json_extract(message_json, '$.targets'))=0 OR EXISTS (SELECT 1 FROM json_each(json_extract(message_json, '$.targets')) WHERE value=?))");
|
|
439
|
+
args.push(this.scope.principal.agent);
|
|
440
|
+
} else {
|
|
441
|
+
clauses.push("(source=? OR json_array_length(json_extract(message_json, '$.targets'))=0 OR EXISTS (SELECT 1 FROM json_each(json_extract(message_json, '$.targets')) WHERE value=?))");
|
|
442
|
+
args.push(this.scope.principal.agent, this.scope.principal.agent);
|
|
443
|
+
}
|
|
444
|
+
if (query.project) {
|
|
445
|
+
clauses.push("project=?");
|
|
446
|
+
args.push(query.project);
|
|
447
|
+
}
|
|
448
|
+
if (query.since) {
|
|
449
|
+
clauses.push("created_at>=?");
|
|
450
|
+
args.push(query.since);
|
|
451
|
+
}
|
|
452
|
+
if (query.threadId) {
|
|
453
|
+
clauses.push("thread_id=?");
|
|
454
|
+
args.push(query.threadId);
|
|
455
|
+
}
|
|
456
|
+
const limit = Math.min(Math.max(Math.trunc(query.limit ?? 50), 1), 200);
|
|
457
|
+
const rows = this.db.prepare(`SELECT message_json FROM edge_inbox
|
|
458
|
+
WHERE ${clauses.join(" AND ")} ORDER BY sequence_key ${query.latest ? "DESC" : "ASC"} LIMIT ?`).all(...args, limit);
|
|
459
|
+
const messages = rows.map((row) => parseMessage(row.message_json));
|
|
460
|
+
const cursorMessage = query.latest ? messages[0] : messages[messages.length - 1];
|
|
461
|
+
if (query.latest || messages.length === limit) {
|
|
462
|
+
return { messages, cursor: cursorMessage ? encodeCursor(cursorMessage.sequence, scope) : query.cursor };
|
|
463
|
+
}
|
|
464
|
+
return {
|
|
465
|
+
messages,
|
|
466
|
+
cursor: highWaterSequence && highWaterSequence !== "0" ? encodeCursor(highWaterSequence, scope) : query.cursor
|
|
467
|
+
};
|
|
468
|
+
}
|
|
469
|
+
async pullCursor() {
|
|
470
|
+
await this.ready();
|
|
471
|
+
const row = this.db.prepare("SELECT pull_cursor FROM edge_scopes WHERE scope_key=?").get(this.key);
|
|
472
|
+
return row.pull_cursor ? String(row.pull_cursor) : void 0;
|
|
473
|
+
}
|
|
474
|
+
async noteError(error) {
|
|
475
|
+
await this.ready();
|
|
476
|
+
this.db.prepare("UPDATE edge_scopes SET last_error=? WHERE scope_key=?").run(error.slice(0, 256), this.key);
|
|
477
|
+
}
|
|
478
|
+
async noteAttempt(now = /* @__PURE__ */ new Date()) {
|
|
479
|
+
await this.ready();
|
|
480
|
+
this.db.prepare("UPDATE edge_scopes SET last_attempt_at=? WHERE scope_key=?").run(now.toISOString(), this.key);
|
|
481
|
+
}
|
|
482
|
+
async stats(now = /* @__PURE__ */ new Date()) {
|
|
483
|
+
await this.ready();
|
|
484
|
+
const nowText = now.toISOString();
|
|
485
|
+
const counts = this.db.prepare(`SELECT
|
|
486
|
+
sum(CASE WHEN state='pending' THEN 1 ELSE 0 END) AS pending,
|
|
487
|
+
sum(CASE WHEN state='pending' AND available_at<=? AND (lease_expires_at IS NULL OR lease_expires_at<=?) THEN 1 ELSE 0 END) AS due,
|
|
488
|
+
sum(CASE WHEN state='pending' AND available_at>? AND (lease_expires_at IS NULL OR lease_expires_at<=?) THEN 1 ELSE 0 END) AS scheduled,
|
|
489
|
+
sum(CASE WHEN state='pending' AND lease_expires_at>? THEN 1 ELSE 0 END) AS leased,
|
|
490
|
+
sum(CASE WHEN state='blocked' THEN 1 ELSE 0 END) AS blocked,
|
|
491
|
+
min(CASE WHEN state='pending' AND available_at<=? AND (lease_expires_at IS NULL OR lease_expires_at<=?) THEN available_at END) AS oldest_due,
|
|
492
|
+
min(CASE WHEN state='pending' AND available_at>? AND (lease_expires_at IS NULL OR lease_expires_at<=?) THEN available_at END) AS next_retry,
|
|
493
|
+
min(CASE WHEN state='blocked' THEN blocked_at END) AS oldest_blocked,
|
|
494
|
+
sum(CASE WHEN state='blocked' AND blocked_at IS NULL THEN 1 ELSE 0 END) AS blocked_age_unknown,
|
|
495
|
+
max(CASE WHEN state='blocked' THEN attempts ELSE 0 END) AS blocked_max_attempts
|
|
496
|
+
FROM edge_outbox WHERE scope_key=?`).get(nowText, nowText, nowText, nowText, nowText, nowText, nowText, nowText, nowText, this.key);
|
|
497
|
+
const blocked = this.db.prepare("SELECT last_error FROM edge_outbox WHERE scope_key=? AND state='blocked' ORDER BY coalesce(blocked_at,created_at) LIMIT 1").get(this.key);
|
|
498
|
+
const cache = this.db.prepare("SELECT count(*) AS count FROM edge_inbox WHERE scope_key=?").get(this.key);
|
|
499
|
+
const state = this.db.prepare(`SELECT pull_cursor, last_sync_at, last_error,
|
|
500
|
+
last_outbound_sync_at,last_inbound_sync_at,last_attempt_at
|
|
501
|
+
FROM edge_scopes WHERE scope_key=?`).get(this.key);
|
|
502
|
+
const oldestDueAt = counts.oldest_due ? String(counts.oldest_due) : void 0;
|
|
503
|
+
const oldestBlockedAt = Number(counts.blocked_age_unknown ?? 0) > 0 ? void 0 : counts.oldest_blocked ? String(counts.oldest_blocked) : void 0;
|
|
504
|
+
return {
|
|
505
|
+
pending: Number(counts.pending ?? 0),
|
|
506
|
+
due: Number(counts.due ?? 0),
|
|
507
|
+
scheduled: Number(counts.scheduled ?? 0),
|
|
508
|
+
leased: Number(counts.leased ?? 0),
|
|
509
|
+
blocked: Number(counts.blocked ?? 0),
|
|
510
|
+
cached: Number(cache.count ?? 0),
|
|
511
|
+
pullCursor: state.pull_cursor ? String(state.pull_cursor) : void 0,
|
|
512
|
+
lastSyncAt: state.last_sync_at ? String(state.last_sync_at) : void 0,
|
|
513
|
+
lastError: state.last_error ? String(state.last_error) : void 0,
|
|
514
|
+
oldestDueAt,
|
|
515
|
+
queueLagMs: oldestDueAt ? Math.max(0, now.getTime() - Date.parse(oldestDueAt)) : 0,
|
|
516
|
+
oldestBlockedAt,
|
|
517
|
+
blockedAgeMs: oldestBlockedAt ? Math.max(0, now.getTime() - Date.parse(oldestBlockedAt)) : null,
|
|
518
|
+
blockedMaxAttempts: Number(counts.blocked_max_attempts ?? 0),
|
|
519
|
+
blockedLastError: blocked?.last_error ? String(blocked.last_error) : void 0,
|
|
520
|
+
nextRetryAt: counts.next_retry ? String(counts.next_retry) : void 0,
|
|
521
|
+
lastOutboundSyncAt: state.last_outbound_sync_at ? String(state.last_outbound_sync_at) : void 0,
|
|
522
|
+
lastInboundSyncAt: state.last_inbound_sync_at ? String(state.last_inbound_sync_at) : void 0,
|
|
523
|
+
lastAttemptAt: state.last_attempt_at ? String(state.last_attempt_at) : void 0
|
|
524
|
+
};
|
|
525
|
+
}
|
|
526
|
+
async close() {
|
|
527
|
+
this.db.close();
|
|
528
|
+
}
|
|
529
|
+
};
|
|
530
|
+
|
|
531
|
+
// src/syncing-bridge-store.ts
|
|
532
|
+
function statusOf(error) {
|
|
533
|
+
if (!error || typeof error !== "object" || !("status" in error)) return void 0;
|
|
534
|
+
const status = Number(error.status);
|
|
535
|
+
return Number.isFinite(status) ? status : void 0;
|
|
536
|
+
}
|
|
537
|
+
function codeOf(error) {
|
|
538
|
+
if (error && typeof error === "object" && "code" in error) {
|
|
539
|
+
const code = error.code;
|
|
540
|
+
if (typeof code === "string" && code) return code.slice(0, 128);
|
|
541
|
+
}
|
|
542
|
+
return error instanceof Error ? error.name.slice(0, 128) : "sync_error";
|
|
543
|
+
}
|
|
544
|
+
function isRetryableSyncError(error) {
|
|
545
|
+
const status = statusOf(error);
|
|
546
|
+
const code = codeOf(error);
|
|
547
|
+
if (["network_error", "request_timeout"].includes(code)) return true;
|
|
548
|
+
if (["invalid_input", "idempotency_conflict", "edge_idempotency_conflict", "principal_mismatch", "protocol_mismatch", "store_closed"].includes(code)) return false;
|
|
549
|
+
return status === 0 || status === 408 || status === 425 || status === 429 || status !== void 0 && status >= 500;
|
|
550
|
+
}
|
|
551
|
+
function provisional(draft, createdAt) {
|
|
552
|
+
return { ...draft, sequence: "0", createdAt };
|
|
553
|
+
}
|
|
554
|
+
var SyncingBridgeStore = class {
|
|
555
|
+
constructor(edge, remote, principal, options = {}) {
|
|
556
|
+
this.edge = edge;
|
|
557
|
+
this.remote = remote;
|
|
558
|
+
this.principal = principal;
|
|
559
|
+
this.stopped = false;
|
|
560
|
+
this.closeController = new AbortController();
|
|
561
|
+
this.wakeRequested = false;
|
|
562
|
+
this.remoteReachable = null;
|
|
563
|
+
this.now = options.now ?? (() => /* @__PURE__ */ new Date());
|
|
564
|
+
this.random = options.random ?? Math.random;
|
|
565
|
+
this.baseDelayMs = options.baseDelayMs ?? 1e3;
|
|
566
|
+
this.maxDelayMs = options.maxDelayMs ?? 5 * 6e4;
|
|
567
|
+
this.leaseMs = options.leaseMs ?? 3e4;
|
|
568
|
+
this.autoSync = options.autoSync ?? true;
|
|
569
|
+
this.idleDelayMs = Math.max(this.baseDelayMs + 1, options.idleDelayMs ?? 3e4);
|
|
570
|
+
this.loopState = this.autoSync ? "idle" : "disabled";
|
|
571
|
+
}
|
|
572
|
+
async initialize() {
|
|
573
|
+
await this.edge.initialize();
|
|
574
|
+
if (this.autoSync) this.startTransportLoop();
|
|
575
|
+
}
|
|
576
|
+
startTransportLoop() {
|
|
577
|
+
if (this.background) return;
|
|
578
|
+
this.background = this.transportLoop().catch((error) => {
|
|
579
|
+
this.backgroundError = error;
|
|
580
|
+
this.loopState = "failed";
|
|
581
|
+
});
|
|
582
|
+
}
|
|
583
|
+
async wait(delayMs) {
|
|
584
|
+
if (this.stopped) return;
|
|
585
|
+
if (this.wakeRequested) {
|
|
586
|
+
this.wakeRequested = false;
|
|
587
|
+
return;
|
|
588
|
+
}
|
|
589
|
+
await new Promise((resolve) => {
|
|
590
|
+
this.wake = resolve;
|
|
591
|
+
this.wakeTimer = setTimeout(resolve, delayMs);
|
|
592
|
+
this.wakeTimer.unref?.();
|
|
593
|
+
});
|
|
594
|
+
this.wake = void 0;
|
|
595
|
+
this.wakeTimer = void 0;
|
|
596
|
+
}
|
|
597
|
+
wakeTransport() {
|
|
598
|
+
if (this.wake) {
|
|
599
|
+
if (this.wakeTimer) clearTimeout(this.wakeTimer);
|
|
600
|
+
this.wake();
|
|
601
|
+
} else this.wakeRequested = true;
|
|
602
|
+
}
|
|
603
|
+
fatal(error) {
|
|
604
|
+
if (this.backgroundError instanceof Error) return this.backgroundError;
|
|
605
|
+
const cause = error instanceof Error ? error : new Error(String(error));
|
|
606
|
+
const fatal = Object.assign(new Error(`fatal local edge failure: ${cause.message}`), {
|
|
607
|
+
code: "local_edge_commit_failed",
|
|
608
|
+
cause
|
|
609
|
+
});
|
|
610
|
+
this.backgroundError = fatal;
|
|
611
|
+
return fatal;
|
|
612
|
+
}
|
|
613
|
+
assertHealthy() {
|
|
614
|
+
if (this.backgroundError) throw this.backgroundError;
|
|
615
|
+
}
|
|
616
|
+
async transportLoop() {
|
|
617
|
+
let failures = 0;
|
|
618
|
+
await this.wait(this.delay(0));
|
|
619
|
+
while (!this.stopped) {
|
|
620
|
+
this.loopState = "running";
|
|
621
|
+
const report = await this.sync({ maxPush: 100, maxPages: 1, signal: this.closeController.signal });
|
|
622
|
+
if (this.stopped) break;
|
|
623
|
+
if (report.failureRetryable === false) {
|
|
624
|
+
this.backgroundError = Object.assign(
|
|
625
|
+
new Error(`gateway synchronization failed permanently: ${report.lastError ?? "sync_error"}`),
|
|
626
|
+
{ code: report.lastError ?? "sync_error" }
|
|
627
|
+
);
|
|
628
|
+
this.loopState = "failed";
|
|
629
|
+
return;
|
|
630
|
+
}
|
|
631
|
+
failures = report.online ? 0 : Math.min(failures + 1, 20);
|
|
632
|
+
this.loopState = report.online ? "idle" : "backoff";
|
|
633
|
+
await this.wait(report.pending > 0 ? this.delay(Math.max(0, failures - 1)) : this.idleDelayMs);
|
|
634
|
+
}
|
|
635
|
+
}
|
|
636
|
+
async verifyRemote() {
|
|
637
|
+
await this.ensureRemote();
|
|
638
|
+
}
|
|
639
|
+
async ensureRemote(signal) {
|
|
640
|
+
if (!this.remoteReady) {
|
|
641
|
+
this.remoteReady = this.remote.initialize({ signal }).catch((error) => {
|
|
642
|
+
this.remoteReady = void 0;
|
|
643
|
+
throw error;
|
|
644
|
+
});
|
|
645
|
+
}
|
|
646
|
+
try {
|
|
647
|
+
await this.remoteReady;
|
|
648
|
+
this.remoteReachable = true;
|
|
649
|
+
} catch (error) {
|
|
650
|
+
this.remoteReachable = false;
|
|
651
|
+
throw error;
|
|
652
|
+
}
|
|
653
|
+
}
|
|
654
|
+
assertPrincipal(principal, includeInstance = true) {
|
|
655
|
+
if (principal.workspace !== this.principal.workspace || principal.agent !== this.principal.agent || includeInstance && principal.instance !== this.principal.instance) {
|
|
656
|
+
const error = new Error("principal does not match the synchronized edge scope");
|
|
657
|
+
Object.assign(error, { status: 403, code: "principal_mismatch" });
|
|
658
|
+
throw error;
|
|
659
|
+
}
|
|
660
|
+
}
|
|
661
|
+
delay(attempts) {
|
|
662
|
+
const exponential = Math.min(this.maxDelayMs, this.baseDelayMs * 2 ** Math.min(attempts, 20));
|
|
663
|
+
const jitter = 0.8 + this.random() * 0.4;
|
|
664
|
+
return Math.max(1, Math.round(exponential * jitter));
|
|
665
|
+
}
|
|
666
|
+
cancelled(signal) {
|
|
667
|
+
return this.stopped || Boolean(signal?.aborted);
|
|
668
|
+
}
|
|
669
|
+
async flushOne(signal) {
|
|
670
|
+
await this.edge.noteAttempt(this.now());
|
|
671
|
+
try {
|
|
672
|
+
await this.ensureRemote(signal);
|
|
673
|
+
} catch (error) {
|
|
674
|
+
await this.edge.noteError(codeOf(error));
|
|
675
|
+
return {
|
|
676
|
+
state: "retry",
|
|
677
|
+
error: error instanceof Error ? error : new Error(String(error)),
|
|
678
|
+
retryable: isRetryableSyncError(error)
|
|
679
|
+
};
|
|
680
|
+
}
|
|
681
|
+
const record = await this.edge.claimNext(this.now(), this.leaseMs);
|
|
682
|
+
if (!record) return { state: "empty" };
|
|
683
|
+
try {
|
|
684
|
+
const result = await this.remote.insertMessage(record.draft, { signal });
|
|
685
|
+
this.remoteReachable = true;
|
|
686
|
+
if (result.message.id !== record.draft.id) {
|
|
687
|
+
const error = new Error("idempotency key resolved to a different message ID");
|
|
688
|
+
Object.assign(error, { status: 409, code: "idempotency_conflict" });
|
|
689
|
+
await this.edge.block(record, codeOf(error), this.now());
|
|
690
|
+
return { state: "blocked", error, messageId: record.draft.id };
|
|
691
|
+
}
|
|
692
|
+
if (edgeMessageFingerprint(result.message) !== record.payloadHash) {
|
|
693
|
+
const error = new Error("idempotency key resolved to different message content");
|
|
694
|
+
Object.assign(error, { status: 409, code: "idempotency_conflict" });
|
|
695
|
+
await this.edge.block(record, codeOf(error), this.now());
|
|
696
|
+
return { state: "blocked", error, messageId: record.draft.id };
|
|
697
|
+
}
|
|
698
|
+
try {
|
|
699
|
+
await this.edge.commit(record, result.message, this.now());
|
|
700
|
+
} catch (error) {
|
|
701
|
+
return { state: "fatal", error: this.fatal(error) };
|
|
702
|
+
}
|
|
703
|
+
return { state: "committed", result, messageId: record.draft.id };
|
|
704
|
+
} catch (error) {
|
|
705
|
+
const caught = error instanceof Error ? error : new Error(String(error));
|
|
706
|
+
this.remoteReachable = isRetryableSyncError(error) ? false : true;
|
|
707
|
+
if (this.cancelled(signal)) {
|
|
708
|
+
await this.edge.retry(record, "request_cancelled", this.now());
|
|
709
|
+
return { state: "retry", error: caught, retryable: true };
|
|
710
|
+
}
|
|
711
|
+
if (isRetryableSyncError(error)) {
|
|
712
|
+
await this.edge.retry(
|
|
713
|
+
record,
|
|
714
|
+
codeOf(error),
|
|
715
|
+
new Date(this.now().getTime() + this.delay(record.attempts))
|
|
716
|
+
);
|
|
717
|
+
return { state: "retry", error: caught, retryable: true };
|
|
718
|
+
}
|
|
719
|
+
await this.edge.block(record, codeOf(error), this.now());
|
|
720
|
+
return { state: "blocked", error: caught, messageId: record.draft.id };
|
|
721
|
+
}
|
|
722
|
+
}
|
|
723
|
+
async insertMessage(message) {
|
|
724
|
+
this.assertHealthy();
|
|
725
|
+
this.assertPrincipal({ workspace: message.workspace, agent: message.source }, false);
|
|
726
|
+
let remoteError;
|
|
727
|
+
try {
|
|
728
|
+
await this.ensureRemote();
|
|
729
|
+
} catch (error) {
|
|
730
|
+
if (!isRetryableSyncError(error)) throw error;
|
|
731
|
+
remoteError = error;
|
|
732
|
+
}
|
|
733
|
+
const queued = await this.edge.enqueue(message, this.now());
|
|
734
|
+
const draft = queued.draft;
|
|
735
|
+
if (remoteError) {
|
|
736
|
+
await this.edge.noteError(codeOf(remoteError));
|
|
737
|
+
this.wakeTransport();
|
|
738
|
+
return {
|
|
739
|
+
message: provisional(draft, this.now().toISOString()),
|
|
740
|
+
created: queued.created,
|
|
741
|
+
disposition: "queued",
|
|
742
|
+
authoritative: false
|
|
743
|
+
};
|
|
744
|
+
}
|
|
745
|
+
const flushed = await this.flushOne();
|
|
746
|
+
if (flushed.state === "fatal") throw flushed.error;
|
|
747
|
+
if (flushed.state === "blocked" && flushed.messageId === draft.id) throw flushed.error;
|
|
748
|
+
if (flushed.state === "retry" && !flushed.retryable) throw flushed.error;
|
|
749
|
+
if (flushed.state === "committed" && flushed.messageId === draft.id) {
|
|
750
|
+
return { ...flushed.result, disposition: "committed", authoritative: true };
|
|
751
|
+
}
|
|
752
|
+
this.wakeTransport();
|
|
753
|
+
return {
|
|
754
|
+
message: provisional(draft, this.now().toISOString()),
|
|
755
|
+
created: queued.created,
|
|
756
|
+
disposition: "queued",
|
|
757
|
+
authoritative: false
|
|
758
|
+
};
|
|
759
|
+
}
|
|
760
|
+
async pull(maxPages, signal) {
|
|
761
|
+
let pulled = 0;
|
|
762
|
+
for (let pageNumber = 0; pageNumber < maxPages; pageNumber += 1) {
|
|
763
|
+
if (this.cancelled(signal)) break;
|
|
764
|
+
const before = await this.edge.pullCursor();
|
|
765
|
+
let page;
|
|
766
|
+
try {
|
|
767
|
+
await this.ensureRemote(signal);
|
|
768
|
+
page = await this.remote.listMessages(this.principal, {
|
|
769
|
+
cursor: before,
|
|
770
|
+
limit: 200,
|
|
771
|
+
includeExpired: true,
|
|
772
|
+
mailbox: "all"
|
|
773
|
+
}, { signal });
|
|
774
|
+
this.remoteReachable = true;
|
|
775
|
+
} catch (error) {
|
|
776
|
+
this.remoteReachable = isRetryableSyncError(error) ? false : true;
|
|
777
|
+
await this.edge.noteError(codeOf(error));
|
|
778
|
+
return {
|
|
779
|
+
online: false,
|
|
780
|
+
pulled,
|
|
781
|
+
error: error instanceof Error ? error : new Error(String(error)),
|
|
782
|
+
retryable: isRetryableSyncError(error)
|
|
783
|
+
};
|
|
784
|
+
}
|
|
785
|
+
try {
|
|
786
|
+
await this.edge.cachePage(page.messages, page.cursor, this.now());
|
|
787
|
+
} catch (error) {
|
|
788
|
+
throw this.fatal(error);
|
|
789
|
+
}
|
|
790
|
+
pulled += page.messages.length;
|
|
791
|
+
if (page.messages.length < 200 || !page.cursor || page.cursor === before) break;
|
|
792
|
+
}
|
|
793
|
+
return { online: true, pulled };
|
|
794
|
+
}
|
|
795
|
+
async sync(options = {}) {
|
|
796
|
+
this.assertHealthy();
|
|
797
|
+
await this.edge.initialize();
|
|
798
|
+
await this.edge.noteAttempt(this.now());
|
|
799
|
+
const maxPush = Math.min(Math.max(Math.trunc(options.maxPush ?? 100), 0), 1e3);
|
|
800
|
+
const maxPages = Math.min(Math.max(Math.trunc(options.maxPages ?? 20), 0), 100);
|
|
801
|
+
let pushed = 0;
|
|
802
|
+
let deduplicated = 0;
|
|
803
|
+
let online = true;
|
|
804
|
+
let lastError;
|
|
805
|
+
let failureRetryable;
|
|
806
|
+
if (options.signal?.aborted) {
|
|
807
|
+
const stats2 = await this.edge.stats(this.now());
|
|
808
|
+
return {
|
|
809
|
+
online: false,
|
|
810
|
+
pushed: 0,
|
|
811
|
+
deduplicated: 0,
|
|
812
|
+
pulled: 0,
|
|
813
|
+
pending: stats2.pending,
|
|
814
|
+
blocked: stats2.blocked,
|
|
815
|
+
cached: stats2.cached,
|
|
816
|
+
cursor: stats2.pullCursor,
|
|
817
|
+
lastSyncedAt: stats2.lastSyncAt,
|
|
818
|
+
lastError: "request_cancelled",
|
|
819
|
+
failureRetryable: true
|
|
820
|
+
};
|
|
821
|
+
}
|
|
822
|
+
for (let index = 0; index < maxPush; index += 1) {
|
|
823
|
+
if (this.cancelled(options.signal)) break;
|
|
824
|
+
const result = await this.flushOne(options.signal);
|
|
825
|
+
if (result.state === "empty") break;
|
|
826
|
+
if (result.state === "committed") {
|
|
827
|
+
pushed += 1;
|
|
828
|
+
if (!result.result.created) deduplicated += 1;
|
|
829
|
+
continue;
|
|
830
|
+
}
|
|
831
|
+
if (result.state === "fatal") throw result.error;
|
|
832
|
+
lastError = codeOf(result.error);
|
|
833
|
+
failureRetryable = result.state === "retry" ? result.retryable : void 0;
|
|
834
|
+
if (result.state === "retry") online = false;
|
|
835
|
+
if (result.state === "retry") break;
|
|
836
|
+
}
|
|
837
|
+
let pulled = 0;
|
|
838
|
+
if (maxPages > 0 && !this.cancelled(options.signal)) {
|
|
839
|
+
const pull = await this.pull(maxPages, options.signal);
|
|
840
|
+
online = online && pull.online;
|
|
841
|
+
pulled = pull.pulled;
|
|
842
|
+
if (pull.error) {
|
|
843
|
+
lastError = codeOf(pull.error);
|
|
844
|
+
failureRetryable = pull.retryable;
|
|
845
|
+
}
|
|
846
|
+
}
|
|
847
|
+
const stats = await this.edge.stats(this.now());
|
|
848
|
+
return {
|
|
849
|
+
online,
|
|
850
|
+
pushed,
|
|
851
|
+
deduplicated,
|
|
852
|
+
pulled,
|
|
853
|
+
pending: stats.pending,
|
|
854
|
+
blocked: stats.blocked,
|
|
855
|
+
cached: stats.cached,
|
|
856
|
+
cursor: stats.pullCursor,
|
|
857
|
+
lastSyncedAt: stats.lastSyncAt,
|
|
858
|
+
lastError: lastError ?? stats.lastError,
|
|
859
|
+
failureRetryable
|
|
860
|
+
};
|
|
861
|
+
}
|
|
862
|
+
async listMessages(principal, query = {}) {
|
|
863
|
+
this.assertHealthy();
|
|
864
|
+
this.assertPrincipal(principal);
|
|
865
|
+
await this.sync({ maxPush: 20, maxPages: 0 });
|
|
866
|
+
let remotePage;
|
|
867
|
+
try {
|
|
868
|
+
await this.ensureRemote();
|
|
869
|
+
remotePage = await this.remote.listMessages(principal, query);
|
|
870
|
+
} catch (error) {
|
|
871
|
+
const retryable = isRetryableSyncError(error);
|
|
872
|
+
this.remoteReachable = retryable ? false : true;
|
|
873
|
+
if (!retryable) throw error;
|
|
874
|
+
await this.edge.noteError(codeOf(error));
|
|
875
|
+
let cached;
|
|
876
|
+
let stats;
|
|
877
|
+
try {
|
|
878
|
+
cached = await this.edge.list(query);
|
|
879
|
+
stats = await this.edge.stats(this.now());
|
|
880
|
+
} catch (cacheError) {
|
|
881
|
+
throw this.fatal(cacheError);
|
|
882
|
+
}
|
|
883
|
+
return {
|
|
884
|
+
...cached,
|
|
885
|
+
source: "cache",
|
|
886
|
+
stale: true,
|
|
887
|
+
degraded: true,
|
|
888
|
+
acknowledgements: query.receiptState && query.receiptState !== "any" || "unacknowledgedBy" in query ? "unknown" : "authoritative",
|
|
889
|
+
lastSyncedAt: stats.lastSyncAt
|
|
890
|
+
};
|
|
891
|
+
}
|
|
892
|
+
try {
|
|
893
|
+
this.remoteReachable = true;
|
|
894
|
+
await this.edge.cacheLatest(remotePage.messages, this.now());
|
|
895
|
+
const stats = await this.edge.stats(this.now());
|
|
896
|
+
return {
|
|
897
|
+
...remotePage,
|
|
898
|
+
source: "remote",
|
|
899
|
+
stale: false,
|
|
900
|
+
degraded: false,
|
|
901
|
+
acknowledgements: "authoritative",
|
|
902
|
+
lastSyncedAt: stats.lastSyncAt
|
|
903
|
+
};
|
|
904
|
+
} catch (error) {
|
|
905
|
+
throw this.fatal(error);
|
|
906
|
+
}
|
|
907
|
+
}
|
|
908
|
+
async recordReceipt(principal, messageIds, readAt) {
|
|
909
|
+
this.assertPrincipal(principal, false);
|
|
910
|
+
await this.ensureRemote();
|
|
911
|
+
return this.remote.recordReceipt(principal, messageIds, readAt);
|
|
912
|
+
}
|
|
913
|
+
async claimDelivery(principal, options) {
|
|
914
|
+
this.assertPrincipal(principal);
|
|
915
|
+
await this.ensureRemote();
|
|
916
|
+
return this.remote.claimDelivery(principal, options);
|
|
917
|
+
}
|
|
918
|
+
async renewDelivery(principal, deliveryId, leaseToken, leaseMs) {
|
|
919
|
+
this.assertPrincipal(principal);
|
|
920
|
+
await this.ensureRemote();
|
|
921
|
+
return this.remote.renewDelivery(principal, deliveryId, leaseToken, leaseMs);
|
|
922
|
+
}
|
|
923
|
+
async settleDelivery(principal, deliveryId, leaseToken, state, error, _retryPolicy) {
|
|
924
|
+
this.assertPrincipal(principal);
|
|
925
|
+
await this.ensureRemote();
|
|
926
|
+
return this.remote.settleDelivery(principal, deliveryId, leaseToken, state, error);
|
|
927
|
+
}
|
|
928
|
+
async listDeliveries(principal, query = {}) {
|
|
929
|
+
this.assertPrincipal(principal);
|
|
930
|
+
await this.ensureRemote();
|
|
931
|
+
if (!this.remote.listDeliveries) throw new Error("delivery listing is not supported");
|
|
932
|
+
return this.remote.listDeliveries(principal, query);
|
|
933
|
+
}
|
|
934
|
+
async listDeliveryEvents(principal, id, query = {}) {
|
|
935
|
+
this.assertPrincipal(principal);
|
|
936
|
+
await this.ensureRemote();
|
|
937
|
+
if (!this.remote.listDeliveryEvents) throw new Error("delivery event listing is not supported");
|
|
938
|
+
return this.remote.listDeliveryEvents(principal, id, query);
|
|
939
|
+
}
|
|
940
|
+
async cancelDelivery(principal, id) {
|
|
941
|
+
this.assertPrincipal(principal);
|
|
942
|
+
await this.ensureRemote();
|
|
943
|
+
if (!this.remote.cancelDelivery) throw new Error("delivery cancellation is not supported");
|
|
944
|
+
return this.remote.cancelDelivery(principal, id);
|
|
945
|
+
}
|
|
946
|
+
async requeueDelivery(principal, id) {
|
|
947
|
+
this.assertPrincipal(principal);
|
|
948
|
+
await this.ensureRemote();
|
|
949
|
+
if (!this.remote.requeueDelivery) throw new Error("delivery requeue is not supported");
|
|
950
|
+
return this.remote.requeueDelivery(principal, id);
|
|
951
|
+
}
|
|
952
|
+
async diagnostics(principal, options = {}) {
|
|
953
|
+
this.assertPrincipal(principal);
|
|
954
|
+
const edge = await this.edge.stats(this.now());
|
|
955
|
+
let remote;
|
|
956
|
+
let remoteError;
|
|
957
|
+
if (options.mode === "probe") {
|
|
958
|
+
try {
|
|
959
|
+
if (this.remote.diagnostics) remote = await this.remote.diagnostics(principal);
|
|
960
|
+
else await this.ensureRemote();
|
|
961
|
+
this.remoteReachable = true;
|
|
962
|
+
} catch (error) {
|
|
963
|
+
const retryable = isRetryableSyncError(error);
|
|
964
|
+
this.remoteReachable = retryable ? false : true;
|
|
965
|
+
remoteError = codeOf(error);
|
|
966
|
+
}
|
|
967
|
+
}
|
|
968
|
+
return {
|
|
969
|
+
schemaVersion: remote?.schemaVersion ?? "postgres-v2",
|
|
970
|
+
deliverySupported: remote?.deliverySupported ?? true,
|
|
971
|
+
pending: remote?.pending ?? null,
|
|
972
|
+
claimed: remote?.claimed ?? null,
|
|
973
|
+
retrying: remote?.retrying ?? null,
|
|
974
|
+
dead: remote?.dead ?? null,
|
|
975
|
+
cancelled: remote?.cancelled ?? null,
|
|
976
|
+
oldestAvailableAt: remote?.oldestAvailableAt,
|
|
977
|
+
due: remote?.due ?? null,
|
|
978
|
+
scheduled: remote?.scheduled ?? null,
|
|
979
|
+
expiredLeases: remote?.expiredLeases ?? null,
|
|
980
|
+
oldestDueAt: remote?.oldestDueAt,
|
|
981
|
+
queueLagMs: remote?.queueLagMs ?? null,
|
|
982
|
+
principal: { workspace: principal.workspace, agent: principal.agent },
|
|
983
|
+
remoteReachable: options.mode === "probe" ? this.remoteReachable : null,
|
|
984
|
+
outboxPending: edge.pending,
|
|
985
|
+
outboxBlocked: edge.blocked,
|
|
986
|
+
cachedMessages: edge.cached,
|
|
987
|
+
lastSyncAt: edge.lastSyncAt,
|
|
988
|
+
lastSyncError: edge.lastError,
|
|
989
|
+
outboxDue: edge.due,
|
|
990
|
+
outboxScheduled: edge.scheduled,
|
|
991
|
+
outboxLeased: edge.leased,
|
|
992
|
+
outboxOldestDueAt: edge.oldestDueAt,
|
|
993
|
+
outboxQueueLagMs: edge.queueLagMs,
|
|
994
|
+
outboxOldestBlockedAt: edge.oldestBlockedAt,
|
|
995
|
+
outboxBlockedAgeMs: edge.blockedAgeMs,
|
|
996
|
+
outboxBlockedMaxAttempts: edge.blockedMaxAttempts,
|
|
997
|
+
outboxBlockedLastError: edge.blockedLastError,
|
|
998
|
+
outboxNextRetryAt: edge.nextRetryAt,
|
|
999
|
+
lastOutboundSyncAt: edge.lastOutboundSyncAt,
|
|
1000
|
+
lastInboundSyncAt: edge.lastInboundSyncAt,
|
|
1001
|
+
lastSyncAttemptAt: edge.lastAttemptAt,
|
|
1002
|
+
syncLoopState: this.backgroundError ? "failed" : this.loopState,
|
|
1003
|
+
syncLoopError: this.backgroundError ? codeOf(this.backgroundError) : void 0,
|
|
1004
|
+
remoteError
|
|
1005
|
+
};
|
|
1006
|
+
}
|
|
1007
|
+
async heartbeat(principal, leaseMs, runtimeType, capabilities = []) {
|
|
1008
|
+
this.assertPrincipal(principal);
|
|
1009
|
+
await this.ensureRemote();
|
|
1010
|
+
if (!this.remote.heartbeat) throw new Error("presence is not supported by the remote provider");
|
|
1011
|
+
return this.remote.heartbeat(principal, leaseMs, runtimeType, capabilities);
|
|
1012
|
+
}
|
|
1013
|
+
async listPresence(principal) {
|
|
1014
|
+
this.assertPrincipal(principal);
|
|
1015
|
+
await this.ensureRemote();
|
|
1016
|
+
if (!this.remote.listPresence) throw new Error("presence is not supported by the remote provider");
|
|
1017
|
+
return this.remote.listPresence(principal);
|
|
1018
|
+
}
|
|
1019
|
+
async close() {
|
|
1020
|
+
this.stopped = true;
|
|
1021
|
+
this.loopState = "stopped";
|
|
1022
|
+
this.closeController.abort(new Error("synchronization stopped"));
|
|
1023
|
+
if (this.wakeTimer) clearTimeout(this.wakeTimer);
|
|
1024
|
+
this.wake?.();
|
|
1025
|
+
const results = await Promise.allSettled([
|
|
1026
|
+
this.remote.close?.() ?? Promise.resolve(),
|
|
1027
|
+
this.background ?? Promise.resolve()
|
|
1028
|
+
]);
|
|
1029
|
+
const failures = results.filter((result) => result.status === "rejected").map((result) => result.reason);
|
|
1030
|
+
if (this.backgroundError) failures.push(this.backgroundError);
|
|
1031
|
+
try {
|
|
1032
|
+
await this.edge.close();
|
|
1033
|
+
} catch (error) {
|
|
1034
|
+
failures.push(error);
|
|
1035
|
+
}
|
|
1036
|
+
if (failures.length === 1) throw failures[0];
|
|
1037
|
+
if (failures.length > 1) throw Object.assign(new Error("failed to close synchronized bridge store"), { errors: failures });
|
|
1038
|
+
}
|
|
1039
|
+
};
|
|
1040
|
+
|
|
1041
|
+
export {
|
|
1042
|
+
EdgeConflictError,
|
|
1043
|
+
edgeMessageFingerprint,
|
|
1044
|
+
stableIdempotency,
|
|
1045
|
+
edgeScopeKey,
|
|
1046
|
+
SQLiteEdgeStore,
|
|
1047
|
+
isRetryableSyncError,
|
|
1048
|
+
SyncingBridgeStore
|
|
1049
|
+
};
|
|
1050
|
+
//# sourceMappingURL=chunk-Q6PPMXJC.js.map
|