@creatornader/agent-bridge 0.2.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/CHANGELOG.md +60 -0
- package/LICENSE +216 -0
- package/README.md +338 -0
- package/SKILL.md +24 -0
- package/bin/CLAUDE.md +11 -0
- package/bin/agent-bridge +7 -0
- package/clients/claude-code.json +20 -0
- package/clients/claude-desktop.json +20 -0
- package/clients/codex.json +20 -0
- package/clients/generic-mcp.json +13 -0
- package/clients/openclaw.json +13 -0
- package/dist/bridge-domain-BcnBeHOn.d.ts +97 -0
- package/dist/bridge-service-CfqMcMAn.d.ts +28 -0
- package/dist/bridge-store-BuGjxTn4.d.ts +61 -0
- package/dist/bridge.d.ts +102 -0
- package/dist/bridge.js +83 -0
- package/dist/bridge.js.map +1 -0
- package/dist/chunk-4KAOBC5X.js +773 -0
- package/dist/chunk-4KAOBC5X.js.map +1 -0
- package/dist/chunk-6MAZ6YLZ.js +146 -0
- package/dist/chunk-6MAZ6YLZ.js.map +1 -0
- package/dist/chunk-AXL2I7FH.js +423 -0
- package/dist/chunk-AXL2I7FH.js.map +1 -0
- package/dist/chunk-BV6W4AJK.js +211 -0
- package/dist/chunk-BV6W4AJK.js.map +1 -0
- package/dist/chunk-CKSKUBDQ.js +153 -0
- package/dist/chunk-CKSKUBDQ.js.map +1 -0
- package/dist/chunk-JOUBDRYX.js +272 -0
- package/dist/chunk-JOUBDRYX.js.map +1 -0
- package/dist/chunk-JTC5YURG.js +49 -0
- package/dist/chunk-JTC5YURG.js.map +1 -0
- package/dist/chunk-KVR4JBRF.js +80 -0
- package/dist/chunk-KVR4JBRF.js.map +1 -0
- package/dist/chunk-O26W5QHS.js +409 -0
- package/dist/chunk-O26W5QHS.js.map +1 -0
- package/dist/chunk-WEULPMUY.js +988 -0
- package/dist/chunk-WEULPMUY.js.map +1 -0
- package/dist/chunk-YD6YJATN.js +48 -0
- package/dist/chunk-YD6YJATN.js.map +1 -0
- package/dist/cli.d.ts +3 -0
- package/dist/cli.js +670 -0
- package/dist/cli.js.map +1 -0
- package/dist/client-config.d.ts +30 -0
- package/dist/client-config.js +10 -0
- package/dist/client-config.js.map +1 -0
- package/dist/client-runtime.d.ts +15 -0
- package/dist/client-runtime.js +15 -0
- package/dist/client-runtime.js.map +1 -0
- package/dist/gateway-BULozv3K.d.ts +54 -0
- package/dist/gateway-main.d.ts +2 -0
- package/dist/gateway-main.js +105 -0
- package/dist/gateway-main.js.map +1 -0
- package/dist/gateway.d.ts +4 -0
- package/dist/gateway.js +10 -0
- package/dist/gateway.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +18 -0
- package/dist/index.js.map +1 -0
- package/dist/server.d.ts +34 -0
- package/dist/server.js +19 -0
- package/dist/server.js.map +1 -0
- package/dist/sqlite.d.ts +156 -0
- package/dist/sqlite.js +24 -0
- package/dist/sqlite.js.map +1 -0
- package/llms.txt +39 -0
- package/package.json +104 -0
- package/sql/migrations/001_schema_state.sql +34 -0
- package/sql/migrations/002_workspaces_agents_credentials.sql +77 -0
- package/sql/migrations/003_messages_receipts_deliveries.sql +116 -0
- package/sql/migrations/004_message_query_indexes.sql +31 -0
- package/sql/migrations/005_delivery_events_presence.sql +79 -0
- package/sql/migrations/006_legacy_shared_context_import.sql +139 -0
- package/sql/migrations/007_runtime_role.sql +59 -0
- package/sql/setup.sql +68 -0
|
@@ -0,0 +1,423 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import {
|
|
3
|
+
decodeCursor,
|
|
4
|
+
encodeCursor
|
|
5
|
+
} from "./chunk-BV6W4AJK.js";
|
|
6
|
+
|
|
7
|
+
// src/legacy-compat.ts
|
|
8
|
+
function legacyMessageIdFromSequence(value) {
|
|
9
|
+
const text = String(value);
|
|
10
|
+
if (!/^-?\d+$/.test(text)) throw new Error("legacy message ID must be an integer");
|
|
11
|
+
if (typeof value === "number" && !Number.isSafeInteger(value)) {
|
|
12
|
+
throw new Error("legacy message ID must be decoded without precision loss");
|
|
13
|
+
}
|
|
14
|
+
const numeric = BigInt(text);
|
|
15
|
+
if (numeric >= 0n && numeric <= 0xffffffffffffn) {
|
|
16
|
+
return `00000000-0000-8000-8000-${numeric.toString(16).padStart(12, "0")}`;
|
|
17
|
+
}
|
|
18
|
+
if (numeric < -0x8000000000000000n || numeric > 0x7fffffffffffffffn) {
|
|
19
|
+
throw new Error("legacy message ID exceeds bigint range");
|
|
20
|
+
}
|
|
21
|
+
const unsigned = numeric < 0 ? numeric + 0x10000000000000000n : numeric;
|
|
22
|
+
const encoded = unsigned.toString(16).padStart(16, "0").padStart(18, "0");
|
|
23
|
+
return `00000000-0000-8${encoded.slice(0, 3)}-9${encoded.slice(3, 6)}-${encoded.slice(6)}`;
|
|
24
|
+
}
|
|
25
|
+
function legacySequenceFromMessageId(value) {
|
|
26
|
+
const small = value.match(/^00000000-0000-8000-8000-([0-9a-f]{12})$/i);
|
|
27
|
+
if (small) return BigInt(`0x${small[1]}`).toString();
|
|
28
|
+
const large = value.match(/^00000000-0000-8([0-9a-f]{3})-9([0-9a-f]{3})-([0-9a-f]{12})$/i);
|
|
29
|
+
if (!large) return void 0;
|
|
30
|
+
const encoded = `${large[1]}${large[2]}${large[3]}`;
|
|
31
|
+
if (!encoded.startsWith("00")) return void 0;
|
|
32
|
+
const unsigned = BigInt(`0x${encoded.slice(2)}`);
|
|
33
|
+
return (unsigned >= 0x8000000000000000n ? unsigned - 0x10000000000000000n : unsigned).toString();
|
|
34
|
+
}
|
|
35
|
+
function legacyNumericMessageId(value) {
|
|
36
|
+
const text = String(value);
|
|
37
|
+
return /^-?\d+$/.test(text) ? legacyMessageIdFromSequence(value) : text;
|
|
38
|
+
}
|
|
39
|
+
function legacyContextMetadata(message) {
|
|
40
|
+
const metadata = message.metadata && typeof message.metadata === "object" && !Array.isArray(message.metadata) ? message.metadata : {};
|
|
41
|
+
const existingEnvelope = metadata.message_envelope && typeof metadata.message_envelope === "object" && !Array.isArray(metadata.message_envelope) ? metadata.message_envelope : {};
|
|
42
|
+
const envelope = {
|
|
43
|
+
...existingEnvelope,
|
|
44
|
+
schema: "agent-bridge.message-envelope.v1",
|
|
45
|
+
message_id: message.id,
|
|
46
|
+
source_agent: message.source,
|
|
47
|
+
kind: message.type,
|
|
48
|
+
priority: message.priority,
|
|
49
|
+
target_agents: message.targets,
|
|
50
|
+
payload_mime: message.contentType
|
|
51
|
+
};
|
|
52
|
+
if (message.workspace !== "*") envelope.project = message.workspace;
|
|
53
|
+
if (message.threadId) envelope.thread_id = message.threadId;
|
|
54
|
+
if (message.replyToId) envelope.reply_to_id = message.replyToId;
|
|
55
|
+
if (message.correlationId) envelope.correlation_id = message.correlationId;
|
|
56
|
+
if (message.causationId) envelope.causation_id = message.causationId;
|
|
57
|
+
if (message.data !== void 0) envelope.payload = message.data;
|
|
58
|
+
if (message.expiresAt) envelope.expires_at = message.expiresAt;
|
|
59
|
+
if (message.atribReceiptId) envelope.atrib_receipt_id = message.atribReceiptId;
|
|
60
|
+
if (message.informedBy?.length) envelope.informed_by = message.informedBy;
|
|
61
|
+
return { ...metadata, message_envelope: envelope };
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// src/legacy-supabase-store.ts
|
|
65
|
+
var UUID_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
|
|
66
|
+
var LegacySupabaseError = class extends Error {
|
|
67
|
+
constructor(status, code) {
|
|
68
|
+
super(`Legacy Supabase request failed: ${code}`);
|
|
69
|
+
this.status = status;
|
|
70
|
+
this.code = code;
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
function messageId(row) {
|
|
74
|
+
const envelopeId = row.metadata?.message_envelope?.message_id;
|
|
75
|
+
return typeof envelopeId === "string" && UUID_RE.test(envelopeId) ? envelopeId : legacyMessageIdFromSequence(String(row.id));
|
|
76
|
+
}
|
|
77
|
+
function isVisible(row, principal, query) {
|
|
78
|
+
const envelope = row.metadata?.message_envelope;
|
|
79
|
+
const targets = Array.isArray(envelope?.target_agents) ? envelope.target_agents : [];
|
|
80
|
+
if (targets.length && !targets.includes(principal.agent)) return false;
|
|
81
|
+
const type = envelope?.kind ?? row.category;
|
|
82
|
+
if (query.types?.length && !query.types.includes(type)) return false;
|
|
83
|
+
if (query.threadId && envelope?.thread_id !== query.threadId) return false;
|
|
84
|
+
const expiresAt = envelope?.expires_at;
|
|
85
|
+
if (!query.includeExpired && expiresAt && new Date(expiresAt).getTime() <= Date.now()) return false;
|
|
86
|
+
return true;
|
|
87
|
+
}
|
|
88
|
+
function asMessage(row, principal) {
|
|
89
|
+
const envelope = row.metadata?.message_envelope;
|
|
90
|
+
return {
|
|
91
|
+
id: messageId(row),
|
|
92
|
+
sequence: String(row.id),
|
|
93
|
+
workspace: row.project ?? principal.workspace,
|
|
94
|
+
source: row.source,
|
|
95
|
+
type: envelope?.kind ?? row.category,
|
|
96
|
+
content: row.content,
|
|
97
|
+
contentType: envelope?.payload_mime ?? "text/plain",
|
|
98
|
+
data: envelope?.payload,
|
|
99
|
+
targets: envelope?.target_agents ?? [],
|
|
100
|
+
threadId: envelope?.thread_id,
|
|
101
|
+
replyToId: envelope?.reply_to_id,
|
|
102
|
+
correlationId: envelope?.correlation_id,
|
|
103
|
+
causationId: envelope?.causation_id,
|
|
104
|
+
priority: row.priority ?? "info",
|
|
105
|
+
expiresAt: envelope?.expires_at,
|
|
106
|
+
idempotencyKey: envelope?.idempotency_key,
|
|
107
|
+
atribReceiptId: row.atrib_receipt_id ?? envelope?.atrib_receipt_id,
|
|
108
|
+
informedBy: envelope?.informed_by,
|
|
109
|
+
metadata: row.metadata,
|
|
110
|
+
createdAt: row.created_at
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
var LegacySupabaseRestStore = class {
|
|
114
|
+
constructor(url, key, fetchImpl = fetch, timeoutMs = 1e4) {
|
|
115
|
+
this.url = url;
|
|
116
|
+
this.key = key;
|
|
117
|
+
this.fetchImpl = fetchImpl;
|
|
118
|
+
this.timeoutMs = timeoutMs;
|
|
119
|
+
this.legacyIds = /* @__PURE__ */ new Map();
|
|
120
|
+
this.initialized = false;
|
|
121
|
+
const parsed = new URL(url);
|
|
122
|
+
const loopback = parsed.hostname === "localhost" || parsed.hostname === "127.0.0.1" || parsed.hostname === "[::1]";
|
|
123
|
+
if (parsed.protocol !== "https:" && !(parsed.protocol === "http:" && loopback)) {
|
|
124
|
+
throw new Error("Agent Bridge requires HTTPS for non-loopback legacy providers");
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
async initialize() {
|
|
128
|
+
if (this.initialized) return;
|
|
129
|
+
await this.request("/shared_context?select=id&limit=1");
|
|
130
|
+
this.initialized = true;
|
|
131
|
+
}
|
|
132
|
+
async request(path, init = {}) {
|
|
133
|
+
try {
|
|
134
|
+
const response = await this.fetchImpl(`${this.url.replace(/\/$/, "")}/rest/v1${path}`, {
|
|
135
|
+
...init,
|
|
136
|
+
signal: init.signal ?? AbortSignal.timeout(this.timeoutMs),
|
|
137
|
+
headers: {
|
|
138
|
+
apikey: this.key,
|
|
139
|
+
Authorization: `Bearer ${this.key}`,
|
|
140
|
+
"Content-Type": "application/json",
|
|
141
|
+
Prefer: "return=representation",
|
|
142
|
+
...init.headers ?? {}
|
|
143
|
+
}
|
|
144
|
+
});
|
|
145
|
+
if (!response.ok) {
|
|
146
|
+
throw new LegacySupabaseError(response.status, "provider_error");
|
|
147
|
+
}
|
|
148
|
+
const text = await response.text();
|
|
149
|
+
return text ? JSON.parse(text) : null;
|
|
150
|
+
} catch (error) {
|
|
151
|
+
if (error instanceof LegacySupabaseError) throw error;
|
|
152
|
+
if (error instanceof Error && (error.name === "TimeoutError" || error.name === "AbortError")) {
|
|
153
|
+
throw new LegacySupabaseError(504, "request_timeout");
|
|
154
|
+
}
|
|
155
|
+
throw new LegacySupabaseError(0, "network_error");
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
async insertMessage(input) {
|
|
159
|
+
if (input.idempotencyKey) {
|
|
160
|
+
throw new Error(
|
|
161
|
+
"legacy Supabase mode cannot enforce idempotency keys; migrate to shared mode"
|
|
162
|
+
);
|
|
163
|
+
}
|
|
164
|
+
const lookup = encodeURIComponent(
|
|
165
|
+
JSON.stringify({ message_envelope: { message_id: input.id } })
|
|
166
|
+
);
|
|
167
|
+
const existing = await this.request(
|
|
168
|
+
`/shared_context?metadata=cs.${lookup}&order=id.asc&limit=1`
|
|
169
|
+
);
|
|
170
|
+
if (existing[0]) {
|
|
171
|
+
this.legacyIds.set(messageId(existing[0]), String(existing[0].id));
|
|
172
|
+
return { created: false, message: asMessage(existing[0], { workspace: input.workspace, agent: input.source }) };
|
|
173
|
+
}
|
|
174
|
+
const existingMetadata = input.metadata && typeof input.metadata === "object" && !Array.isArray(input.metadata) ? input.metadata : {};
|
|
175
|
+
const existingEnvelope = existingMetadata.message_envelope && typeof existingMetadata.message_envelope === "object" ? existingMetadata.message_envelope : {};
|
|
176
|
+
const body = {
|
|
177
|
+
source: input.source,
|
|
178
|
+
category: input.type,
|
|
179
|
+
content: input.content,
|
|
180
|
+
priority: input.priority,
|
|
181
|
+
project: input.workspace === "*" ? null : input.workspace,
|
|
182
|
+
metadata: {
|
|
183
|
+
...existingMetadata,
|
|
184
|
+
message_envelope: {
|
|
185
|
+
...existingEnvelope,
|
|
186
|
+
schema: "agent-bridge.message-envelope.v1",
|
|
187
|
+
message_id: input.id,
|
|
188
|
+
source_agent: input.source,
|
|
189
|
+
kind: input.type,
|
|
190
|
+
payload_mime: input.contentType,
|
|
191
|
+
payload: input.data,
|
|
192
|
+
target_agents: input.targets,
|
|
193
|
+
thread_id: input.threadId,
|
|
194
|
+
reply_to_id: input.replyToId,
|
|
195
|
+
correlation_id: input.correlationId,
|
|
196
|
+
causation_id: input.causationId,
|
|
197
|
+
expires_at: input.expiresAt,
|
|
198
|
+
informed_by: input.informedBy
|
|
199
|
+
}
|
|
200
|
+
},
|
|
201
|
+
atrib_receipt_id: input.atribReceiptId
|
|
202
|
+
};
|
|
203
|
+
const rows = await this.request("/shared_context", {
|
|
204
|
+
method: "POST",
|
|
205
|
+
body: JSON.stringify(body)
|
|
206
|
+
});
|
|
207
|
+
const row = rows[0];
|
|
208
|
+
this.legacyIds.set(input.id, String(row.id));
|
|
209
|
+
return {
|
|
210
|
+
created: true,
|
|
211
|
+
message: { ...input, sequence: String(row.id), createdAt: row.created_at }
|
|
212
|
+
};
|
|
213
|
+
}
|
|
214
|
+
async listMessages(principal, query = {}) {
|
|
215
|
+
const limit = query.limit ?? 50;
|
|
216
|
+
let after = decodeCursor(query.cursor) ?? "0";
|
|
217
|
+
let before;
|
|
218
|
+
let latestCursor;
|
|
219
|
+
const messages = [];
|
|
220
|
+
while (messages.length < limit) {
|
|
221
|
+
const batchLimit = Math.min(Math.max(limit * 2, 50), 200);
|
|
222
|
+
const workspaceFilter = principal.workspace === "*" ? "" : `&project=eq.${encodeURIComponent(principal.workspace)}`;
|
|
223
|
+
const sourceFilter = query.source ? `&source=eq.${encodeURIComponent(query.source)}` : "";
|
|
224
|
+
const sinceFilter = query.since ? `&created_at=gte.${encodeURIComponent(query.since)}` : "";
|
|
225
|
+
const unacknowledgedFilter = query.unacknowledgedBy ? `&acked_by=not.cs.%7B${encodeURIComponent(query.unacknowledgedBy)}%7D` : "";
|
|
226
|
+
const cursorFilter = query.latest ? before ? `&id=lt.${encodeURIComponent(before)}` : "" : `&id=gt.${encodeURIComponent(after)}`;
|
|
227
|
+
const rows = await this.request(
|
|
228
|
+
`/shared_context?select=*${cursorFilter}${workspaceFilter}${sourceFilter}${sinceFilter}${unacknowledgedFilter}&order=id.${query.latest ? "desc" : "asc"}&limit=${batchLimit}`
|
|
229
|
+
);
|
|
230
|
+
if (!rows.length) break;
|
|
231
|
+
if (query.latest && latestCursor === void 0) latestCursor = String(rows[0].id);
|
|
232
|
+
for (const row of rows) {
|
|
233
|
+
after = String(row.id);
|
|
234
|
+
const id = messageId(row);
|
|
235
|
+
this.legacyIds.set(id, after);
|
|
236
|
+
if (isVisible(row, principal, query)) messages.push(asMessage(row, principal));
|
|
237
|
+
if (messages.length === limit) break;
|
|
238
|
+
}
|
|
239
|
+
if (query.latest) before = String(rows[rows.length - 1].id);
|
|
240
|
+
if (rows.length < batchLimit || messages.length === limit) break;
|
|
241
|
+
}
|
|
242
|
+
const next = query.latest ? latestCursor : after === "0" ? void 0 : after;
|
|
243
|
+
return { messages, cursor: next ? encodeCursor(next) : query.cursor };
|
|
244
|
+
}
|
|
245
|
+
async recordReceipt(_workspace, ids, principal) {
|
|
246
|
+
const entryIds = await Promise.all(ids.map(async (id) => {
|
|
247
|
+
const mapped = this.legacyIds.get(id);
|
|
248
|
+
if (mapped) return mapped;
|
|
249
|
+
const lookup = encodeURIComponent(JSON.stringify({ message_envelope: { message_id: id } }));
|
|
250
|
+
const rows = await this.request(`/shared_context?select=id,metadata&metadata=cs.${lookup}&limit=2`);
|
|
251
|
+
if (Array.isArray(rows) && rows.length === 1) {
|
|
252
|
+
const sequence = String(rows[0].id);
|
|
253
|
+
this.legacyIds.set(id, sequence);
|
|
254
|
+
return sequence;
|
|
255
|
+
}
|
|
256
|
+
if (Array.isArray(rows) && rows.length > 1) {
|
|
257
|
+
throw new LegacySupabaseError(409, "ambiguous_message_id");
|
|
258
|
+
}
|
|
259
|
+
const decodedSequence = legacySequenceFromMessageId(id);
|
|
260
|
+
if (decodedSequence !== void 0) return decodedSequence;
|
|
261
|
+
throw new LegacySupabaseError(404, "message_not_found");
|
|
262
|
+
}));
|
|
263
|
+
return this.request("/rpc/ack_context", {
|
|
264
|
+
method: "POST",
|
|
265
|
+
body: JSON.stringify({ entry_ids: entryIds, agent_name: principal })
|
|
266
|
+
});
|
|
267
|
+
}
|
|
268
|
+
async recordLegacyReceipt(ids, principal) {
|
|
269
|
+
const entryIds = ids.map((id) => {
|
|
270
|
+
if (!/^\d+$/.test(id)) throw new Error("legacy receipt IDs must be numeric");
|
|
271
|
+
const value = BigInt(id);
|
|
272
|
+
if (value > 0x7fffffffffffffffn) throw new Error("legacy receipt ID exceeds bigint range");
|
|
273
|
+
return value.toString();
|
|
274
|
+
});
|
|
275
|
+
return this.request("/rpc/ack_context", {
|
|
276
|
+
method: "POST",
|
|
277
|
+
body: JSON.stringify({ entry_ids: entryIds, agent_name: principal })
|
|
278
|
+
});
|
|
279
|
+
}
|
|
280
|
+
async claimDelivery(_principal, _options) {
|
|
281
|
+
throw new Error("legacy Supabase adapter does not support deliveries");
|
|
282
|
+
}
|
|
283
|
+
async renewDelivery(_principal, _deliveryId, _leaseToken, _leaseMs) {
|
|
284
|
+
throw new Error("legacy Supabase adapter does not support deliveries");
|
|
285
|
+
}
|
|
286
|
+
async settleDelivery(_principal, _deliveryId, _leaseToken, _state, _error, _retryPolicy) {
|
|
287
|
+
throw new Error("legacy Supabase adapter does not support deliveries");
|
|
288
|
+
}
|
|
289
|
+
async diagnostics(_principal) {
|
|
290
|
+
return { schemaVersion: "legacy-v1", deliverySupported: false, pending: null, claimed: null, retrying: null, dead: null };
|
|
291
|
+
}
|
|
292
|
+
};
|
|
293
|
+
|
|
294
|
+
// src/http-bridge-store.ts
|
|
295
|
+
var BridgeHttpError = class extends Error {
|
|
296
|
+
constructor(status, code) {
|
|
297
|
+
super(`Agent Bridge request failed: ${code}`);
|
|
298
|
+
this.status = status;
|
|
299
|
+
this.code = code;
|
|
300
|
+
}
|
|
301
|
+
};
|
|
302
|
+
var HttpBridgeStore = class {
|
|
303
|
+
constructor(options) {
|
|
304
|
+
this.options = options;
|
|
305
|
+
const url = new URL(options.baseUrl);
|
|
306
|
+
const loopback = url.hostname === "localhost" || url.hostname === "127.0.0.1" || url.hostname === "[::1]";
|
|
307
|
+
if (url.protocol !== "https:" && !(url.protocol === "http:" && loopback) && !options.allowInsecureRemoteHttp) {
|
|
308
|
+
throw new Error("Agent Bridge requires HTTPS for non-loopback gateways");
|
|
309
|
+
}
|
|
310
|
+
this.fetchImpl = options.fetch ?? fetch;
|
|
311
|
+
}
|
|
312
|
+
async initialize() {
|
|
313
|
+
await this.request("/readyz", { authenticated: false });
|
|
314
|
+
const status = await this.request("/v2/status");
|
|
315
|
+
this.assertBoundPrincipal(status);
|
|
316
|
+
}
|
|
317
|
+
assertBoundPrincipal(status) {
|
|
318
|
+
const principal = status?.principal;
|
|
319
|
+
if (!principal || principal.workspace !== this.options.principal.workspace || principal.agent !== this.options.principal.agent) {
|
|
320
|
+
throw new BridgeHttpError(403, "principal_mismatch");
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
async request(path, options = {}) {
|
|
324
|
+
try {
|
|
325
|
+
const signal = AbortSignal.timeout(this.options.timeoutMs ?? 1e4);
|
|
326
|
+
const response = await this.fetchImpl(`${this.options.baseUrl.replace(/\/$/, "")}${path}`, {
|
|
327
|
+
method: options.method ?? "GET",
|
|
328
|
+
signal,
|
|
329
|
+
headers: {
|
|
330
|
+
...options.authenticated === false ? {} : { authorization: `Bearer ${this.options.token}` },
|
|
331
|
+
...this.options.principal.instance ? { "x-agent-bridge-instance": this.options.principal.instance } : {},
|
|
332
|
+
...options.body === void 0 ? {} : { "content-type": "application/json" }
|
|
333
|
+
},
|
|
334
|
+
body: options.body === void 0 ? void 0 : JSON.stringify(options.body)
|
|
335
|
+
});
|
|
336
|
+
const payload = await response.json().catch(() => ({}));
|
|
337
|
+
if (!response.ok) throw new BridgeHttpError(response.status, payload?.error?.code ?? "request_failed");
|
|
338
|
+
return payload;
|
|
339
|
+
} catch (error) {
|
|
340
|
+
if (error instanceof BridgeHttpError) throw error;
|
|
341
|
+
if (error instanceof Error && (error.name === "TimeoutError" || error.name === "AbortError")) {
|
|
342
|
+
throw new BridgeHttpError(504, "request_timeout");
|
|
343
|
+
}
|
|
344
|
+
throw new BridgeHttpError(0, "network_error");
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
assertPrincipal(principal, includeInstance = true) {
|
|
348
|
+
const expected = this.options.principal;
|
|
349
|
+
if (principal.workspace !== expected.workspace || principal.agent !== expected.agent || includeInstance && principal.instance !== expected.instance) {
|
|
350
|
+
throw new BridgeHttpError(403, "principal_mismatch");
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
async insertMessage(message) {
|
|
354
|
+
this.assertPrincipal({ workspace: message.workspace, agent: message.source }, false);
|
|
355
|
+
const { workspace: _workspace, source: _source, ...draft } = message;
|
|
356
|
+
return this.request("/v2/messages", { method: "POST", body: draft });
|
|
357
|
+
}
|
|
358
|
+
async listMessages(principal, query = {}) {
|
|
359
|
+
this.assertPrincipal(principal);
|
|
360
|
+
const params = new URLSearchParams();
|
|
361
|
+
if (query.cursor) params.set("cursor", query.cursor);
|
|
362
|
+
if (query.limit) params.set("limit", String(query.limit));
|
|
363
|
+
if (query.includeExpired) params.set("includeExpired", "true");
|
|
364
|
+
if (query.source) params.set("source", query.source);
|
|
365
|
+
if (query.since) params.set("since", query.since);
|
|
366
|
+
if (query.unacknowledgedBy) params.set("unacknowledgedBy", query.unacknowledgedBy);
|
|
367
|
+
if (query.threadId) params.set("threadId", query.threadId);
|
|
368
|
+
if (query.latest) params.set("latest", "true");
|
|
369
|
+
for (const type of query.types ?? []) params.append("type", type);
|
|
370
|
+
return this.request(`/v2/history${params.size ? `?${params}` : ""}`);
|
|
371
|
+
}
|
|
372
|
+
async recordReceipt(workspace, ids, principal) {
|
|
373
|
+
this.assertPrincipal({ workspace, agent: principal }, false);
|
|
374
|
+
return (await this.request("/v2/receipts", { method: "POST", body: { messageIds: ids } })).recorded;
|
|
375
|
+
}
|
|
376
|
+
async diagnostics(principal) {
|
|
377
|
+
this.assertPrincipal(principal);
|
|
378
|
+
const status = await this.request("/v2/status");
|
|
379
|
+
this.assertBoundPrincipal(status);
|
|
380
|
+
return status;
|
|
381
|
+
}
|
|
382
|
+
async claimDelivery(principal, options) {
|
|
383
|
+
this.assertPrincipal(principal);
|
|
384
|
+
return (await this.request("/v2/deliveries/claim", { method: "POST", body: options }))?.delivery ?? null;
|
|
385
|
+
}
|
|
386
|
+
async renewDelivery(principal, id, token, leaseMs) {
|
|
387
|
+
this.assertPrincipal(principal);
|
|
388
|
+
try {
|
|
389
|
+
return await this.request(`/v2/deliveries/${id}/extend`, { method: "POST", body: { leaseToken: token, leaseMs } });
|
|
390
|
+
} catch (error) {
|
|
391
|
+
if (error instanceof BridgeHttpError && error.status === 409) return null;
|
|
392
|
+
throw error;
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
async settleDelivery(principal, id, token, state, error, retryPolicy) {
|
|
396
|
+
this.assertPrincipal(principal);
|
|
397
|
+
const action = state === "acked" ? "ack" : "nack";
|
|
398
|
+
try {
|
|
399
|
+
return await this.request(`/v2/deliveries/${id}/${action}`, { method: "POST", body: { leaseToken: token, error, dead: state === "dead", retryPolicy } });
|
|
400
|
+
} catch (caught) {
|
|
401
|
+
if (caught instanceof BridgeHttpError && caught.status === 409) return null;
|
|
402
|
+
throw caught;
|
|
403
|
+
}
|
|
404
|
+
}
|
|
405
|
+
async heartbeat(principal, leaseMs, runtimeType, capabilities = []) {
|
|
406
|
+
this.assertPrincipal(principal);
|
|
407
|
+
return this.request("/v2/presence/heartbeat", { method: "POST", body: { leaseMs, runtimeType, capabilities } });
|
|
408
|
+
}
|
|
409
|
+
async listPresence(principal) {
|
|
410
|
+
this.assertPrincipal(principal);
|
|
411
|
+
return (await this.request("/v2/presence")).agents;
|
|
412
|
+
}
|
|
413
|
+
};
|
|
414
|
+
|
|
415
|
+
export {
|
|
416
|
+
legacyNumericMessageId,
|
|
417
|
+
legacyContextMetadata,
|
|
418
|
+
LegacySupabaseError,
|
|
419
|
+
LegacySupabaseRestStore,
|
|
420
|
+
BridgeHttpError,
|
|
421
|
+
HttpBridgeStore
|
|
422
|
+
};
|
|
423
|
+
//# sourceMappingURL=chunk-AXL2I7FH.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/legacy-compat.ts","../src/legacy-supabase-store.ts","../src/http-bridge-store.ts"],"sourcesContent":["import type { BridgeMessage, JsonValue } from \"./bridge-domain.js\";\n\nexport function legacyMessageIdFromSequence(value: string | number): string {\n const text = String(value);\n if (!/^-?\\d+$/.test(text)) throw new Error(\"legacy message ID must be an integer\");\n if (typeof value === \"number\" && !Number.isSafeInteger(value)) {\n throw new Error(\"legacy message ID must be decoded without precision loss\");\n }\n const numeric = BigInt(text);\n if (numeric >= 0n && numeric <= 0xffffffffffffn) {\n return `00000000-0000-8000-8000-${numeric.toString(16).padStart(12, \"0\")}`;\n }\n if (numeric < -0x8000000000000000n || numeric > 0x7fffffffffffffffn) {\n throw new Error(\"legacy message ID exceeds bigint range\");\n }\n const unsigned = numeric < 0 ? numeric + 0x10000000000000000n : numeric;\n const encoded = unsigned.toString(16).padStart(16, \"0\").padStart(18, \"0\");\n return `00000000-0000-8${encoded.slice(0, 3)}-9${encoded.slice(3, 6)}-${encoded.slice(6)}`;\n}\n\nexport function legacySequenceFromMessageId(value: string): string | undefined {\n const small = value.match(/^00000000-0000-8000-8000-([0-9a-f]{12})$/i);\n if (small) return BigInt(`0x${small[1]}`).toString();\n const large = value.match(/^00000000-0000-8([0-9a-f]{3})-9([0-9a-f]{3})-([0-9a-f]{12})$/i);\n if (!large) return undefined;\n const encoded = `${large[1]}${large[2]}${large[3]}`;\n if (!encoded.startsWith(\"00\")) return undefined;\n const unsigned = BigInt(`0x${encoded.slice(2)}`);\n return (unsigned >= 0x8000000000000000n\n ? unsigned - 0x10000000000000000n\n : unsigned).toString();\n}\n\nexport function legacyNumericMessageId(value: string | number): string {\n const text = String(value);\n return /^-?\\d+$/.test(text) ? legacyMessageIdFromSequence(value) : text;\n}\n\nexport function legacyContextMetadata(message: BridgeMessage): Record<string, JsonValue> {\n const metadata = message.metadata &&\n typeof message.metadata === \"object\" &&\n !Array.isArray(message.metadata)\n ? message.metadata\n : {};\n const existingEnvelope = metadata.message_envelope &&\n typeof metadata.message_envelope === \"object\" &&\n !Array.isArray(metadata.message_envelope)\n ? metadata.message_envelope\n : {};\n const envelope: Record<string, JsonValue> = {\n ...existingEnvelope,\n schema: \"agent-bridge.message-envelope.v1\",\n message_id: message.id,\n source_agent: message.source,\n kind: message.type,\n priority: message.priority,\n target_agents: message.targets,\n payload_mime: message.contentType,\n };\n if (message.workspace !== \"*\") envelope.project = message.workspace;\n if (message.threadId) envelope.thread_id = message.threadId;\n if (message.replyToId) envelope.reply_to_id = message.replyToId;\n if (message.correlationId) envelope.correlation_id = message.correlationId;\n if (message.causationId) envelope.causation_id = message.causationId;\n if (message.data !== undefined) envelope.payload = message.data;\n if (message.expiresAt) envelope.expires_at = message.expiresAt;\n if (message.atribReceiptId) envelope.atrib_receipt_id = message.atribReceiptId;\n if (message.informedBy?.length) envelope.informed_by = message.informedBy;\n return { ...metadata, message_envelope: envelope };\n}\n","import { decodeCursor, encodeCursor, type BridgeDelivery, type BridgeMessage, type BridgePrincipal, type RetryPolicy } from \"./bridge-domain.js\";\nimport type {\n BridgeStore,\n BridgeDiagnostics,\n ClaimOptions,\n InsertMessageResult,\n MessagePage,\n MessageQuery,\n} from \"./bridge-store.js\";\nimport { legacyMessageIdFromSequence, legacySequenceFromMessageId } from \"./legacy-compat.js\";\n\ntype LegacyRow = Record<string, any>;\nconst UUID_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;\n\nexport class LegacySupabaseError extends Error {\n constructor(readonly status: number, readonly code: string) {\n super(`Legacy Supabase request failed: ${code}`);\n }\n}\n\nfunction messageId(row: LegacyRow): string {\n const envelopeId = row.metadata?.message_envelope?.message_id;\n return typeof envelopeId === \"string\" && UUID_RE.test(envelopeId)\n ? envelopeId\n : legacyMessageIdFromSequence(String(row.id));\n}\n\nfunction isVisible(row: LegacyRow, principal: BridgePrincipal, query: MessageQuery): boolean {\n const envelope = row.metadata?.message_envelope;\n const targets = Array.isArray(envelope?.target_agents) ? envelope.target_agents : [];\n if (targets.length && !targets.includes(principal.agent)) return false;\n\n const type = envelope?.kind ?? row.category;\n if (query.types?.length && !query.types.includes(type)) return false;\n if (query.threadId && envelope?.thread_id !== query.threadId) return false;\n\n const expiresAt = envelope?.expires_at;\n if (!query.includeExpired && expiresAt && new Date(expiresAt).getTime() <= Date.now()) return false;\n return true;\n}\n\nfunction asMessage(row: LegacyRow, principal: BridgePrincipal): BridgeMessage {\n const envelope = row.metadata?.message_envelope;\n return {\n id: messageId(row),\n sequence: String(row.id),\n workspace: row.project ?? principal.workspace,\n source: row.source,\n type: envelope?.kind ?? row.category,\n content: row.content,\n contentType: envelope?.payload_mime ?? \"text/plain\",\n data: envelope?.payload,\n targets: envelope?.target_agents ?? [],\n threadId: envelope?.thread_id,\n replyToId: envelope?.reply_to_id,\n correlationId: envelope?.correlation_id,\n causationId: envelope?.causation_id,\n priority: row.priority ?? \"info\",\n expiresAt: envelope?.expires_at,\n idempotencyKey: envelope?.idempotency_key,\n atribReceiptId: row.atrib_receipt_id ?? envelope?.atrib_receipt_id,\n informedBy: envelope?.informed_by,\n metadata: row.metadata,\n createdAt: row.created_at,\n };\n}\n\nexport class LegacySupabaseRestStore implements BridgeStore {\n private readonly legacyIds = new Map<string, string>();\n private initialized = false;\n\n constructor(\n private readonly url: string,\n private readonly key: string,\n private readonly fetchImpl: typeof fetch = fetch,\n private readonly timeoutMs = 10_000,\n ) {\n const parsed = new URL(url);\n const loopback = parsed.hostname === \"localhost\" || parsed.hostname === \"127.0.0.1\" || parsed.hostname === \"[::1]\";\n if (parsed.protocol !== \"https:\" && !(parsed.protocol === \"http:\" && loopback)) {\n throw new Error(\"Agent Bridge requires HTTPS for non-loopback legacy providers\");\n }\n }\n\n async initialize(): Promise<void> {\n if (this.initialized) return;\n await this.request(\"/shared_context?select=id&limit=1\");\n this.initialized = true;\n }\n\n private async request(path: string, init: RequestInit = {}): Promise<any> {\n try {\n const response = await this.fetchImpl(`${this.url.replace(/\\/$/, \"\")}/rest/v1${path}`, {\n ...init,\n signal: init.signal ?? AbortSignal.timeout(this.timeoutMs),\n headers: {\n apikey: this.key,\n Authorization: `Bearer ${this.key}`,\n \"Content-Type\": \"application/json\",\n Prefer: \"return=representation\",\n ...(init.headers ?? {}),\n },\n });\n if (!response.ok) {\n throw new LegacySupabaseError(response.status, \"provider_error\");\n }\n const text = await response.text();\n return text ? JSON.parse(text) : null;\n } catch (error) {\n if (error instanceof LegacySupabaseError) throw error;\n if (error instanceof Error && (error.name === \"TimeoutError\" || error.name === \"AbortError\")) {\n throw new LegacySupabaseError(504, \"request_timeout\");\n }\n throw new LegacySupabaseError(0, \"network_error\");\n }\n }\n\n async insertMessage(\n input: Omit<BridgeMessage, \"sequence\" | \"createdAt\">,\n ): Promise<InsertMessageResult> {\n if (input.idempotencyKey) {\n throw new Error(\n \"legacy Supabase mode cannot enforce idempotency keys; migrate to shared mode\",\n );\n }\n const lookup = encodeURIComponent(\n JSON.stringify({ message_envelope: { message_id: input.id } }),\n );\n const existing = await this.request(\n `/shared_context?metadata=cs.${lookup}&order=id.asc&limit=1`,\n );\n if (existing[0]) {\n this.legacyIds.set(messageId(existing[0]), String(existing[0].id));\n return { created: false, message: asMessage(existing[0], { workspace: input.workspace, agent: input.source }) };\n }\n\n const existingMetadata = input.metadata &&\n typeof input.metadata === \"object\" &&\n !Array.isArray(input.metadata)\n ? input.metadata\n : {};\n const existingEnvelope = existingMetadata.message_envelope &&\n typeof existingMetadata.message_envelope === \"object\"\n ? existingMetadata.message_envelope as Record<string, unknown>\n : {};\n const body = {\n source: input.source,\n category: input.type,\n content: input.content,\n priority: input.priority,\n project: input.workspace === \"*\" ? null : input.workspace,\n metadata: {\n ...existingMetadata,\n message_envelope: {\n ...existingEnvelope,\n schema: \"agent-bridge.message-envelope.v1\",\n message_id: input.id,\n source_agent: input.source,\n kind: input.type,\n payload_mime: input.contentType,\n payload: input.data,\n target_agents: input.targets,\n thread_id: input.threadId,\n reply_to_id: input.replyToId,\n correlation_id: input.correlationId,\n causation_id: input.causationId,\n expires_at: input.expiresAt,\n informed_by: input.informedBy,\n },\n },\n atrib_receipt_id: input.atribReceiptId,\n };\n const rows = await this.request(\"/shared_context\", {\n method: \"POST\",\n body: JSON.stringify(body),\n });\n const row = rows[0];\n this.legacyIds.set(input.id, String(row.id));\n return {\n created: true,\n message: { ...input, sequence: String(row.id), createdAt: row.created_at },\n };\n }\n\n async listMessages(\n principal: BridgePrincipal,\n query: MessageQuery = {},\n ): Promise<MessagePage> {\n const limit = query.limit ?? 50;\n let after = decodeCursor(query.cursor) ?? \"0\";\n let before: string | undefined;\n let latestCursor: string | undefined;\n const messages: BridgeMessage[] = [];\n\n while (messages.length < limit) {\n const batchLimit = Math.min(Math.max(limit * 2, 50), 200);\n const workspaceFilter = principal.workspace === \"*\"\n ? \"\"\n : `&project=eq.${encodeURIComponent(principal.workspace)}`;\n const sourceFilter = query.source\n ? `&source=eq.${encodeURIComponent(query.source)}`\n : \"\";\n const sinceFilter = query.since\n ? `&created_at=gte.${encodeURIComponent(query.since)}`\n : \"\";\n const unacknowledgedFilter = query.unacknowledgedBy\n ? `&acked_by=not.cs.%7B${encodeURIComponent(query.unacknowledgedBy)}%7D`\n : \"\";\n const cursorFilter = query.latest\n ? before ? `&id=lt.${encodeURIComponent(before)}` : \"\"\n : `&id=gt.${encodeURIComponent(after)}`;\n const rows = (await this.request(\n `/shared_context?select=*${cursorFilter}` +\n `${workspaceFilter}${sourceFilter}${sinceFilter}${unacknowledgedFilter}` +\n `&order=id.${query.latest ? \"desc\" : \"asc\"}&limit=${batchLimit}`,\n )) as LegacyRow[];\n if (!rows.length) break;\n if (query.latest && latestCursor === undefined) latestCursor = String(rows[0].id);\n\n for (const row of rows) {\n after = String(row.id);\n const id = messageId(row);\n this.legacyIds.set(id, after);\n if (isVisible(row, principal, query)) messages.push(asMessage(row, principal));\n if (messages.length === limit) break;\n }\n if (query.latest) before = String(rows[rows.length - 1]!.id);\n if (rows.length < batchLimit || messages.length === limit) break;\n }\n\n const next = query.latest ? latestCursor : after === \"0\" ? undefined : after;\n return { messages, cursor: next ? encodeCursor(next) : query.cursor };\n }\n\n async recordReceipt(_workspace: string, ids: string[], principal: string): Promise<number> {\n const entryIds = await Promise.all(ids.map(async (id) => {\n const mapped = this.legacyIds.get(id);\n if (mapped) return mapped;\n const lookup = encodeURIComponent(JSON.stringify({ message_envelope: { message_id: id } }));\n const rows = await this.request(`/shared_context?select=id,metadata&metadata=cs.${lookup}&limit=2`);\n if (Array.isArray(rows) && rows.length === 1) {\n const sequence = String(rows[0].id);\n this.legacyIds.set(id, sequence);\n return sequence;\n }\n if (Array.isArray(rows) && rows.length > 1) {\n throw new LegacySupabaseError(409, \"ambiguous_message_id\");\n }\n const decodedSequence = legacySequenceFromMessageId(id);\n if (decodedSequence !== undefined) return decodedSequence;\n throw new LegacySupabaseError(404, \"message_not_found\");\n }));\n return this.request(\"/rpc/ack_context\", {\n method: \"POST\",\n body: JSON.stringify({ entry_ids: entryIds, agent_name: principal }),\n });\n }\n\n async recordLegacyReceipt(ids: string[], principal: string): Promise<number> {\n const entryIds = ids.map((id) => {\n if (!/^\\d+$/.test(id)) throw new Error(\"legacy receipt IDs must be numeric\");\n const value = BigInt(id);\n if (value > 0x7fffffffffffffffn) throw new Error(\"legacy receipt ID exceeds bigint range\");\n return value.toString();\n });\n return this.request(\"/rpc/ack_context\", {\n method: \"POST\",\n body: JSON.stringify({ entry_ids: entryIds, agent_name: principal }),\n });\n }\n\n async claimDelivery(\n _principal: BridgePrincipal,\n _options: ClaimOptions,\n ): Promise<BridgeDelivery | null> {\n throw new Error(\"legacy Supabase adapter does not support deliveries\");\n }\n\n async renewDelivery(\n _principal: BridgePrincipal,\n _deliveryId: string,\n _leaseToken: string,\n _leaseMs: number,\n ): Promise<BridgeDelivery | null> {\n throw new Error(\"legacy Supabase adapter does not support deliveries\");\n }\n\n async settleDelivery(\n _principal: BridgePrincipal,\n _deliveryId: string,\n _leaseToken: string,\n _state: \"acked\" | \"retrying\" | \"dead\",\n _error: string | undefined,\n _retryPolicy: RetryPolicy,\n ): Promise<BridgeDelivery | null> {\n throw new Error(\"legacy Supabase adapter does not support deliveries\");\n }\n\n async diagnostics(_principal: BridgePrincipal): Promise<BridgeDiagnostics> {\n return { schemaVersion: \"legacy-v1\", deliverySupported: false, pending: null, claimed: null, retrying: null, dead: null };\n }\n}\n","import type { AgentPresence, BridgeDelivery, BridgeMessage, BridgePrincipal, RetryPolicy } from \"./bridge-domain.js\";\nimport type { BridgeDiagnostics, BridgeStore, ClaimOptions, InsertMessageResult, MessagePage, MessageQuery } from \"./bridge-store.js\";\n\nexport interface HttpBridgeStoreOptions {\n baseUrl: string;\n token: string;\n principal: BridgePrincipal;\n timeoutMs?: number;\n allowInsecureRemoteHttp?: boolean;\n fetch?: typeof fetch;\n}\n\nexport class BridgeHttpError extends Error {\n constructor(readonly status: number, readonly code: string) { super(`Agent Bridge request failed: ${code}`); }\n}\n\nexport class HttpBridgeStore implements BridgeStore {\n private readonly fetchImpl: typeof fetch;\n constructor(private readonly options: HttpBridgeStoreOptions) {\n const url = new URL(options.baseUrl);\n const loopback = url.hostname === \"localhost\" || url.hostname === \"127.0.0.1\" || url.hostname === \"[::1]\";\n if (url.protocol !== \"https:\" && !(url.protocol === \"http:\" && loopback) && !options.allowInsecureRemoteHttp) {\n throw new Error(\"Agent Bridge requires HTTPS for non-loopback gateways\");\n }\n this.fetchImpl = options.fetch ?? fetch;\n }\n async initialize(): Promise<void> {\n await this.request(\"/readyz\", { authenticated: false });\n const status = await this.request(\"/v2/status\");\n this.assertBoundPrincipal(status);\n }\n\n private assertBoundPrincipal(status: any): void {\n const principal = status?.principal;\n if (\n !principal ||\n principal.workspace !== this.options.principal.workspace ||\n principal.agent !== this.options.principal.agent\n ) {\n throw new BridgeHttpError(403, \"principal_mismatch\");\n }\n }\n\n private async request(path: string, options: { method?: string; body?: unknown; authenticated?: boolean } = {}): Promise<any> {\n try {\n const signal = AbortSignal.timeout(this.options.timeoutMs ?? 10_000);\n const response = await this.fetchImpl(`${this.options.baseUrl.replace(/\\/$/, \"\")}${path}`, {\n method: options.method ?? \"GET\", signal,\n headers: {\n ...(options.authenticated === false ? {} : { authorization: `Bearer ${this.options.token}` }),\n ...(this.options.principal.instance ? { \"x-agent-bridge-instance\": this.options.principal.instance } : {}),\n ...(options.body === undefined ? {} : { \"content-type\": \"application/json\" }),\n },\n body: options.body === undefined ? undefined : JSON.stringify(options.body),\n });\n const payload = await response.json().catch(() => ({}));\n if (!response.ok) throw new BridgeHttpError(response.status, payload?.error?.code ?? \"request_failed\");\n return payload;\n } catch (error) {\n if (error instanceof BridgeHttpError) throw error;\n if (error instanceof Error && (error.name === \"TimeoutError\" || error.name === \"AbortError\")) {\n throw new BridgeHttpError(504, \"request_timeout\");\n }\n throw new BridgeHttpError(0, \"network_error\");\n }\n }\n\n private assertPrincipal(principal: BridgePrincipal, includeInstance = true): void {\n const expected = this.options.principal;\n if (\n principal.workspace !== expected.workspace ||\n principal.agent !== expected.agent ||\n (includeInstance && principal.instance !== expected.instance)\n ) {\n throw new BridgeHttpError(403, \"principal_mismatch\");\n }\n }\n\n async insertMessage(message: Omit<BridgeMessage, \"sequence\" | \"createdAt\">): Promise<InsertMessageResult> {\n this.assertPrincipal({ workspace: message.workspace, agent: message.source }, false);\n const { workspace: _workspace, source: _source, ...draft } = message;\n return this.request(\"/v2/messages\", { method: \"POST\", body: draft });\n }\n async listMessages(principal: BridgePrincipal, query: MessageQuery = {}): Promise<MessagePage> {\n this.assertPrincipal(principal);\n const params = new URLSearchParams();\n if (query.cursor) params.set(\"cursor\", query.cursor);\n if (query.limit) params.set(\"limit\", String(query.limit));\n if (query.includeExpired) params.set(\"includeExpired\", \"true\");\n if (query.source) params.set(\"source\", query.source);\n if (query.since) params.set(\"since\", query.since);\n if (query.unacknowledgedBy) params.set(\"unacknowledgedBy\", query.unacknowledgedBy);\n if (query.threadId) params.set(\"threadId\", query.threadId);\n if (query.latest) params.set(\"latest\", \"true\");\n for (const type of query.types ?? []) params.append(\"type\", type);\n return this.request(`/v2/history${params.size ? `?${params}` : \"\"}`);\n }\n async recordReceipt(workspace: string, ids: string[], principal: string): Promise<number> {\n this.assertPrincipal({ workspace, agent: principal }, false);\n return (await this.request(\"/v2/receipts\", { method: \"POST\", body: { messageIds: ids } })).recorded;\n }\n async diagnostics(principal: BridgePrincipal): Promise<BridgeDiagnostics> {\n this.assertPrincipal(principal);\n const status = await this.request(\"/v2/status\");\n this.assertBoundPrincipal(status);\n return status;\n }\n async claimDelivery(principal: BridgePrincipal, options: ClaimOptions): Promise<BridgeDelivery | null> {\n this.assertPrincipal(principal);\n return (await this.request(\"/v2/deliveries/claim\", { method: \"POST\", body: options }))?.delivery ?? null;\n }\n async renewDelivery(principal: BridgePrincipal, id: string, token: string, leaseMs: number): Promise<BridgeDelivery | null> {\n this.assertPrincipal(principal);\n try {\n return await this.request(`/v2/deliveries/${id}/extend`, { method: \"POST\", body: { leaseToken: token, leaseMs } });\n } catch (error) {\n if (error instanceof BridgeHttpError && error.status === 409) return null;\n throw error;\n }\n }\n async settleDelivery(principal: BridgePrincipal, id: string, token: string, state: \"acked\" | \"retrying\" | \"dead\", error: string | undefined, retryPolicy: RetryPolicy): Promise<BridgeDelivery | null> {\n this.assertPrincipal(principal);\n const action = state === \"acked\" ? \"ack\" : \"nack\";\n try {\n return await this.request(`/v2/deliveries/${id}/${action}`, { method: \"POST\", body: { leaseToken: token, error, dead: state === \"dead\", retryPolicy } });\n } catch (caught) {\n if (caught instanceof BridgeHttpError && caught.status === 409) return null;\n throw caught;\n }\n }\n async heartbeat(principal: BridgePrincipal, leaseMs: number, runtimeType?: string, capabilities: string[] = []): Promise<AgentPresence> {\n this.assertPrincipal(principal);\n return this.request(\"/v2/presence/heartbeat\", { method: \"POST\", body: { leaseMs, runtimeType, capabilities } });\n }\n async listPresence(principal: BridgePrincipal): Promise<AgentPresence[]> {\n this.assertPrincipal(principal);\n return (await this.request(\"/v2/presence\")).agents;\n }\n}\n"],"mappings":";;;;;;;A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