@creatornader/agent-bridge 0.5.2 → 0.6.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 +41 -1
- package/README.md +34 -31
- package/ROADMAP.md +56 -15
- package/SECURITY.md +6 -5
- package/dist/archive.d.ts +2 -2
- package/dist/{bridge-service-CNBKdYXh.d.ts → bridge-service-DjSYfjKt.d.ts} +4 -2
- package/dist/{bridge-store-ByJ6CaJk.d.ts → bridge-store-Bi_LCX8e.d.ts} +5 -1
- package/dist/bridge.d.ts +9 -37
- package/dist/bridge.js +6 -10
- package/dist/chunk-23UDQZMT.js +54 -0
- package/dist/chunk-23UDQZMT.js.map +1 -0
- package/dist/{chunk-AWE3DFZV.js → chunk-4V2PFJEF.js} +11 -4
- package/dist/chunk-4V2PFJEF.js.map +1 -0
- package/dist/{chunk-E4OWHGUE.js → chunk-62C63PIE.js} +8 -8
- package/dist/chunk-62C63PIE.js.map +1 -0
- package/dist/{chunk-HUHG7XTB.js → chunk-AIALYLGQ.js} +30 -193
- package/dist/chunk-AIALYLGQ.js.map +1 -0
- package/dist/{chunk-JUTJRAMA.js → chunk-FGERNG4X.js} +3 -3
- package/dist/{chunk-7VJI2MXI.js → chunk-IF5OKPBK.js} +32 -14
- package/dist/chunk-IF5OKPBK.js.map +1 -0
- package/dist/{chunk-QPC6JHA3.js → chunk-IMJ47WO4.js} +12 -16
- package/dist/chunk-IMJ47WO4.js.map +1 -0
- package/dist/{chunk-2EVLG3YA.js → chunk-UKFRCP6X.js} +10 -7
- package/dist/chunk-UKFRCP6X.js.map +1 -0
- package/dist/chunk-WQ4I5XGF.js +242 -0
- package/dist/chunk-WQ4I5XGF.js.map +1 -0
- package/dist/{chunk-SN7PIVDF.js → chunk-ZUZ7TCIH.js} +13 -1
- package/dist/{chunk-SN7PIVDF.js.map → chunk-ZUZ7TCIH.js.map} +1 -1
- package/dist/cli.js +41 -34
- 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 +3 -3
- package/dist/client-runtime.js +5 -5
- package/dist/contracts/generate.js +2 -3
- package/dist/contracts/generate.js.map +1 -1
- package/dist/dr.d.ts +8 -0
- package/dist/dr.js +1 -1
- package/dist/{gateway-CW-61lvs.d.ts → gateway-BqmcKam8.d.ts} +2 -2
- package/dist/gateway-main.js +3 -3
- package/dist/gateway.d.ts +3 -3
- package/dist/gateway.js +3 -3
- package/dist/index.js +8 -7
- package/dist/index.js.map +1 -1
- package/dist/{postgres-bridge-store-C9KG9Z69.d.ts → postgres-bridge-store-ChoOuFEY.d.ts} +1 -1
- package/dist/server.d.ts +0 -2
- package/dist/server.js +8 -7
- package/dist/{sqlite-edge-store-CdMIOrho.d.ts → sqlite-edge-store-BAFUeysk.d.ts} +1 -1
- package/dist/sqlite.d.ts +7 -3
- package/dist/sqlite.js +1 -1
- package/docs/architecture-v2.md +22 -14
- package/docs/decisions/0001-protocol-layers-and-acknowledgment-semantics.md +2 -1
- package/docs/decisions/0002-canonical-operation-contract-registry.md +6 -1
- package/docs/decisions/0005-retire-direct-supabase-runtime.md +52 -0
- package/docs/deployment.md +17 -12
- package/docs/ecosystem.md +6 -4
- package/docs/troubleshooting.md +15 -0
- package/llms.txt +3 -3
- package/openapi/agent-bridge-v2.openapi.json +3 -6
- package/package.json +3 -3
- package/schemas/agent-bridge-v2.capabilities.json +4 -5
- package/schemas/agent-bridge-v2.mcp.json +6 -12
- package/schemas/agent-bridge-v2.schema.json +12 -24
- package/dist/chunk-2EVLG3YA.js.map +0 -1
- package/dist/chunk-7VJI2MXI.js.map +0 -1
- package/dist/chunk-AWE3DFZV.js.map +0 -1
- package/dist/chunk-E4OWHGUE.js.map +0 -1
- package/dist/chunk-HUHG7XTB.js.map +0 -1
- package/dist/chunk-QPC6JHA3.js.map +0 -1
- package/dist/chunk-Z6JP6MYD.js +0 -584
- package/dist/chunk-Z6JP6MYD.js.map +0 -1
- /package/dist/{chunk-JUTJRAMA.js.map → chunk-FGERNG4X.js.map} +0 -0
|
@@ -34,9 +34,12 @@ function resolveClientConfig(env = process.env, explicitAgent) {
|
|
|
34
34
|
const configPath = clean(env.AGENT_BRIDGE_CONFIG) ?? join(home, ".agent-bridge", "config");
|
|
35
35
|
const file = readClientConfigFile(configPath);
|
|
36
36
|
const value = (key) => clean(env[key]) ?? clean(file[key]);
|
|
37
|
-
const rawProvider = value("AGENT_BRIDGE_PROVIDER") ?? (value("AGENT_BRIDGE_TOKEN") ? "gateway" : value("
|
|
38
|
-
|
|
39
|
-
|
|
37
|
+
const rawProvider = value("AGENT_BRIDGE_PROVIDER") ?? (value("AGENT_BRIDGE_TOKEN") ? "gateway" : value("AGENT_BRIDGE_KEY") ? "legacy-supabase" : "local");
|
|
38
|
+
if (["legacy", "supabase", "legacy-supabase"].includes(rawProvider)) {
|
|
39
|
+
throw new Error("The legacy Supabase provider was removed in Agent Bridge 0.6.0; configure local or gateway mode");
|
|
40
|
+
}
|
|
41
|
+
if (!["local", "gateway"].includes(rawProvider)) throw new Error(`Unsupported AGENT_BRIDGE_PROVIDER: ${rawProvider}`);
|
|
42
|
+
const provider = rawProvider;
|
|
40
43
|
const configuredAgent = clean(env.AGENT_BRIDGE_AGENT);
|
|
41
44
|
const requestedAgent = clean(explicitAgent);
|
|
42
45
|
if (configuredAgent && requestedAgent && configuredAgent !== requestedAgent) {
|
|
@@ -45,9 +48,9 @@ function resolveClientConfig(env = process.env, explicitAgent) {
|
|
|
45
48
|
const agent = requestedAgent ?? configuredAgent;
|
|
46
49
|
if (!agent) throw new Error("AGENT_BRIDGE_AGENT is required");
|
|
47
50
|
const url = value("AGENT_BRIDGE_URL");
|
|
48
|
-
const credential = provider === "gateway" ? value("AGENT_BRIDGE_TOKEN") :
|
|
49
|
-
if (provider
|
|
50
|
-
const workspace =
|
|
51
|
+
const credential = provider === "gateway" ? value("AGENT_BRIDGE_TOKEN") : void 0;
|
|
52
|
+
if (provider === "gateway" && (!url || !credential)) throw new Error("gateway requires AGENT_BRIDGE_URL and AGENT_BRIDGE_TOKEN");
|
|
53
|
+
const workspace = value("AGENT_BRIDGE_WORKSPACE") ?? "default";
|
|
51
54
|
const instance = clean(env.AGENT_BRIDGE_INSTANCE);
|
|
52
55
|
const databasePath = value("AGENT_BRIDGE_DB") ?? join(home, ".agent-bridge", "bridge.sqlite3");
|
|
53
56
|
const edgeDatabasePath = value("AGENT_BRIDGE_EDGE_DB") ?? join(home, ".agent-bridge", "edge.sqlite3");
|
|
@@ -77,4 +80,4 @@ export {
|
|
|
77
80
|
readClientConfigFile,
|
|
78
81
|
resolveClientConfig
|
|
79
82
|
};
|
|
80
|
-
//# sourceMappingURL=chunk-
|
|
83
|
+
//# sourceMappingURL=chunk-UKFRCP6X.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/client-config.ts"],"sourcesContent":["import { existsSync, readFileSync } from \"node:fs\";\nimport { createHash } from \"node:crypto\";\nimport { homedir } from \"node:os\";\nimport { join } from \"node:path\";\nimport type { BridgePrincipal } from \"./bridge-domain.js\";\n\nexport type ClientProvider = \"local\" | \"gateway\";\n\nexport interface ClientEnvironment extends NodeJS.ProcessEnv {\n AGENT_BRIDGE_PROVIDER?: string;\n AGENT_BRIDGE_URL?: string;\n AGENT_BRIDGE_KEY?: string;\n AGENT_BRIDGE_TOKEN?: string;\n AGENT_BRIDGE_AGENT?: string;\n AGENT_BRIDGE_WORKSPACE?: string;\n AGENT_BRIDGE_INSTANCE?: string;\n AGENT_BRIDGE_DB?: string;\n AGENT_BRIDGE_EDGE_DB?: string;\n AGENT_BRIDGE_CONFIG?: string;\n AGENT_BRIDGE_CURSOR?: string;\n}\n\nexport interface ClientConfig {\n provider: ClientProvider;\n principal: BridgePrincipal;\n url?: string;\n credential?: string;\n databasePath: string;\n edgeDatabasePath: string;\n cursorPath: string;\n configPath: string;\n}\n\nfunction pathComponent(value: string): string {\n const readable = value.replace(/[^A-Za-z0-9._-]+/g, \"_\").slice(0, 48) || \"_\";\n const suffix = createHash(\"sha256\").update(value).digest(\"hex\").slice(0, 12);\n return `${readable}-${suffix}`;\n}\n\nfunction clean(value: string | undefined): string | undefined {\n return value?.trim() || undefined;\n}\n\nfunction unquote(value: string): string {\n const input = value.trim();\n if (input.length > 1 && ((input[0] === '\"' && input[input.length - 1] === '\"') || (input[0] === \"'\" && input[input.length - 1] === \"'\"))) return input.slice(1, -1);\n return input;\n}\n\nexport function readClientConfigFile(path: string): Record<string, string> {\n if (!existsSync(path)) return {};\n const result: Record<string, string> = {};\n for (const raw of readFileSync(path, \"utf8\").split(/\\r?\\n/)) {\n const line = raw.trim();\n if (!line || line.startsWith(\"#\")) continue;\n const separator = line.indexOf(\"=\");\n if (separator > 0) result[line.slice(0, separator).trim()] = unquote(line.slice(separator + 1));\n }\n return result;\n}\n\nexport function resolveClientConfig(\n env: ClientEnvironment = process.env,\n explicitAgent?: string,\n): ClientConfig {\n const home = clean(env.HOME) ?? homedir();\n const configPath = clean(env.AGENT_BRIDGE_CONFIG) ?? join(home, \".agent-bridge\", \"config\");\n const file = readClientConfigFile(configPath);\n const value = (key: keyof ClientEnvironment) => clean(env[key]) ?? clean(file[key]);\n const rawProvider = value(\"AGENT_BRIDGE_PROVIDER\") ?? (value(\"AGENT_BRIDGE_TOKEN\") ? \"gateway\" : value(\"AGENT_BRIDGE_KEY\") ? \"legacy-supabase\" : \"local\");\n if ([\"legacy\", \"supabase\", \"legacy-supabase\"].includes(rawProvider)) {\n throw new Error(\"The legacy Supabase provider was removed in Agent Bridge 0.6.0; configure local or gateway mode\");\n }\n if (!([\"local\", \"gateway\"] as string[]).includes(rawProvider)) throw new Error(`Unsupported AGENT_BRIDGE_PROVIDER: ${rawProvider}`);\n const provider = rawProvider as ClientProvider;\n // Identity belongs to the active client process. A shared config file must\n // never make one runtime impersonate the client that initialized the bridge.\n const configuredAgent = clean(env.AGENT_BRIDGE_AGENT);\n const requestedAgent = clean(explicitAgent);\n if (configuredAgent && requestedAgent && configuredAgent !== requestedAgent) {\n throw new Error(`source must match AGENT_BRIDGE_AGENT (${configuredAgent}); got ${requestedAgent}`);\n }\n const agent = requestedAgent ?? configuredAgent;\n if (!agent) throw new Error(\"AGENT_BRIDGE_AGENT is required\");\n const url = value(\"AGENT_BRIDGE_URL\");\n const credential = provider === \"gateway\" ? value(\"AGENT_BRIDGE_TOKEN\") : undefined;\n if (provider === \"gateway\" && (!url || !credential)) throw new Error(\"gateway requires AGENT_BRIDGE_URL and AGENT_BRIDGE_TOKEN\");\n const workspace = value(\"AGENT_BRIDGE_WORKSPACE\") ?? \"default\";\n const instance = clean(env.AGENT_BRIDGE_INSTANCE);\n const databasePath = value(\"AGENT_BRIDGE_DB\") ?? join(home, \".agent-bridge\", \"bridge.sqlite3\");\n const edgeDatabasePath = value(\"AGENT_BRIDGE_EDGE_DB\") ?? join(home, \".agent-bridge\", \"edge.sqlite3\");\n const cursorScope = createHash(\"sha256\")\n .update(`${provider}\\0${provider === \"local\" ? databasePath : url}`)\n .digest(\"hex\")\n .slice(0, 16);\n return {\n provider,\n principal: { workspace, agent, instance },\n url,\n credential,\n databasePath,\n edgeDatabasePath,\n cursorPath: value(\"AGENT_BRIDGE_CURSOR\") ?? join(\n home,\n \".agent-bridge\",\n \"cursors\",\n pathComponent(provider),\n cursorScope,\n pathComponent(workspace),\n pathComponent(agent),\n pathComponent(instance ?? \"default\"),\n ),\n configPath,\n };\n}\n"],"mappings":";;;AAAA,SAAS,YAAY,oBAAoB;AACzC,SAAS,kBAAkB;AAC3B,SAAS,eAAe;AACxB,SAAS,YAAY;AA8BrB,SAAS,cAAc,OAAuB;AAC5C,QAAM,WAAW,MAAM,QAAQ,qBAAqB,GAAG,EAAE,MAAM,GAAG,EAAE,KAAK;AACzE,QAAM,SAAS,WAAW,QAAQ,EAAE,OAAO,KAAK,EAAE,OAAO,KAAK,EAAE,MAAM,GAAG,EAAE;AAC3E,SAAO,GAAG,QAAQ,IAA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ACF;","names":[]}
|
|
@@ -0,0 +1,242 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import {
|
|
3
|
+
ContractResponseError,
|
|
4
|
+
PROTOCOL_HEADER,
|
|
5
|
+
PROTOCOL_VERSION,
|
|
6
|
+
SUPPORTED_PROTOCOL_HEADER,
|
|
7
|
+
SUPPORTED_PROTOCOL_VERSIONS,
|
|
8
|
+
parseResponse
|
|
9
|
+
} from "./chunk-62C63PIE.js";
|
|
10
|
+
|
|
11
|
+
// src/http-bridge-store.ts
|
|
12
|
+
var BridgeHttpError = class extends Error {
|
|
13
|
+
constructor(status, code, requestId, details, message = `Agent Bridge request failed: ${code}`) {
|
|
14
|
+
super(message);
|
|
15
|
+
this.status = status;
|
|
16
|
+
this.code = code;
|
|
17
|
+
this.requestId = requestId;
|
|
18
|
+
this.details = details;
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
var HttpBridgeStore = class {
|
|
22
|
+
constructor(options) {
|
|
23
|
+
this.options = options;
|
|
24
|
+
this.closeController = new AbortController();
|
|
25
|
+
this.closed = false;
|
|
26
|
+
const url = new URL(options.baseUrl);
|
|
27
|
+
const loopback = url.hostname === "localhost" || url.hostname === "127.0.0.1" || url.hostname === "[::1]";
|
|
28
|
+
if (url.protocol !== "https:" && !(url.protocol === "http:" && loopback) && !options.allowInsecureRemoteHttp) {
|
|
29
|
+
throw new Error("Agent Bridge requires HTTPS for non-loopback gateways");
|
|
30
|
+
}
|
|
31
|
+
this.fetchImpl = options.fetch ?? fetch;
|
|
32
|
+
}
|
|
33
|
+
async initialize(options = {}) {
|
|
34
|
+
if (options.mode === "passive") return;
|
|
35
|
+
await this.request(void 0, "/readyz", { authenticated: false, signal: options.signal });
|
|
36
|
+
const status = await this.request("status", "/v2/status", { signal: options.signal });
|
|
37
|
+
this.assertBoundPrincipal(status);
|
|
38
|
+
}
|
|
39
|
+
assertBoundPrincipal(status) {
|
|
40
|
+
const principal = status?.principal;
|
|
41
|
+
if (!principal || principal.workspace !== this.options.principal.workspace || principal.agent !== this.options.principal.agent) {
|
|
42
|
+
throw new BridgeHttpError(403, "principal_mismatch");
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
async request(operationId, path, options = {}) {
|
|
46
|
+
if (options.method === "POST" && !options.skipProtocolProbe) await this.ensureProtocol(options.signal);
|
|
47
|
+
if (this.closed) throw new BridgeHttpError(0, "store_closed");
|
|
48
|
+
if (options.signal?.aborted) throw new BridgeHttpError(0, "request_cancelled");
|
|
49
|
+
const requestController = new AbortController();
|
|
50
|
+
const abort = () => requestController.abort(this.closeController.signal.reason);
|
|
51
|
+
const abortRequest = () => requestController.abort(options.signal?.reason);
|
|
52
|
+
this.closeController.signal.addEventListener("abort", abort, { once: true });
|
|
53
|
+
options.signal?.addEventListener("abort", abortRequest, { once: true });
|
|
54
|
+
let timedOut = false;
|
|
55
|
+
const timeout = setTimeout(() => {
|
|
56
|
+
timedOut = true;
|
|
57
|
+
requestController.abort(new Error("request timeout"));
|
|
58
|
+
}, this.options.timeoutMs ?? 1e4);
|
|
59
|
+
timeout.unref?.();
|
|
60
|
+
try {
|
|
61
|
+
const response = await this.fetchImpl(`${this.options.baseUrl.replace(/\/$/, "")}${path}`, {
|
|
62
|
+
method: options.method ?? "GET",
|
|
63
|
+
signal: requestController.signal,
|
|
64
|
+
headers: {
|
|
65
|
+
[PROTOCOL_HEADER]: this.selectedProtocolVersion ?? PROTOCOL_VERSION,
|
|
66
|
+
...options.authenticated === false ? {} : { authorization: `Bearer ${this.options.token}` },
|
|
67
|
+
...this.options.principal.instance ? { "x-agent-bridge-instance": this.options.principal.instance } : {},
|
|
68
|
+
...options.body === void 0 ? {} : { "content-type": "application/json" }
|
|
69
|
+
},
|
|
70
|
+
body: options.body === void 0 ? void 0 : JSON.stringify(options.body)
|
|
71
|
+
});
|
|
72
|
+
const requestId = response.headers.get("x-request-id") ?? void 0;
|
|
73
|
+
const selectedHeader = response.headers.get(PROTOCOL_HEADER);
|
|
74
|
+
const supportedHeader = response.headers.get(SUPPORTED_PROTOCOL_HEADER);
|
|
75
|
+
const supportedProtocols = supportedHeader?.split(",").map((value) => value.trim()).filter(Boolean) ?? [];
|
|
76
|
+
const inconsistentProtocol = selectedHeader === null || supportedHeader === null || !SUPPORTED_PROTOCOL_VERSIONS.includes(selectedHeader) || !supportedProtocols.includes(selectedHeader) || selectedHeader !== PROTOCOL_VERSION;
|
|
77
|
+
if (operationId && inconsistentProtocol) {
|
|
78
|
+
throw new BridgeHttpError(502, "protocol_mismatch", requestId, {
|
|
79
|
+
expected: PROTOCOL_VERSION,
|
|
80
|
+
selected: selectedHeader,
|
|
81
|
+
supported: supportedHeader
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
const contentType = response.headers.get("content-type") ?? "";
|
|
85
|
+
const payload = contentType.startsWith("application/json") ? await response.json().catch(() => ({})) : await response.text();
|
|
86
|
+
if (!response.ok) {
|
|
87
|
+
const envelope = payload && typeof payload === "object" ? payload.error : void 0;
|
|
88
|
+
throw new BridgeHttpError(
|
|
89
|
+
response.status,
|
|
90
|
+
envelope?.code ?? "request_failed",
|
|
91
|
+
envelope?.requestId ?? requestId,
|
|
92
|
+
envelope?.details ?? envelope,
|
|
93
|
+
envelope?.message ?? `Agent Bridge request failed: ${envelope?.code ?? "request_failed"}`
|
|
94
|
+
);
|
|
95
|
+
}
|
|
96
|
+
if (operationId) this.selectedProtocolVersion = PROTOCOL_VERSION;
|
|
97
|
+
if (!operationId) return payload;
|
|
98
|
+
return parseResponse(operationId, payload);
|
|
99
|
+
} catch (error) {
|
|
100
|
+
if (error instanceof BridgeHttpError) throw error;
|
|
101
|
+
if (error instanceof ContractResponseError) {
|
|
102
|
+
throw new BridgeHttpError(error.status, error.code, void 0, {
|
|
103
|
+
operation: error.operation,
|
|
104
|
+
issues: error.issues
|
|
105
|
+
}, error.message);
|
|
106
|
+
}
|
|
107
|
+
if (this.closed) throw new BridgeHttpError(0, "store_closed");
|
|
108
|
+
if (options.signal?.aborted) throw new BridgeHttpError(0, "request_cancelled");
|
|
109
|
+
if (timedOut) throw new BridgeHttpError(504, "request_timeout");
|
|
110
|
+
if (error instanceof Error && (error.name === "TimeoutError" || error.name === "AbortError")) {
|
|
111
|
+
throw new BridgeHttpError(504, "request_timeout");
|
|
112
|
+
}
|
|
113
|
+
throw new BridgeHttpError(0, "network_error");
|
|
114
|
+
} finally {
|
|
115
|
+
clearTimeout(timeout);
|
|
116
|
+
this.closeController.signal.removeEventListener("abort", abort);
|
|
117
|
+
options.signal?.removeEventListener("abort", abortRequest);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
ensureProtocol(signal) {
|
|
121
|
+
if (this.selectedProtocolVersion) return Promise.resolve(this.selectedProtocolVersion);
|
|
122
|
+
if (!this.protocolProbe) {
|
|
123
|
+
this.protocolProbe = this.request("status", "/v2/status", { signal, skipProtocolProbe: true }).then(() => this.selectedProtocolVersion).finally(() => {
|
|
124
|
+
this.protocolProbe = void 0;
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
return this.protocolProbe;
|
|
128
|
+
}
|
|
129
|
+
async capabilities() {
|
|
130
|
+
return this.request("capabilities", "/v2/capabilities");
|
|
131
|
+
}
|
|
132
|
+
assertPrincipal(principal, includeInstance = true) {
|
|
133
|
+
const expected = this.options.principal;
|
|
134
|
+
if (principal.workspace !== expected.workspace || principal.agent !== expected.agent || includeInstance && principal.instance !== expected.instance) {
|
|
135
|
+
throw new BridgeHttpError(403, "principal_mismatch");
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
async insertMessage(message, options = {}) {
|
|
139
|
+
this.assertPrincipal({ workspace: message.workspace, agent: message.source }, false);
|
|
140
|
+
await this.ensureProtocol(options.signal);
|
|
141
|
+
const { workspace: _workspace, source: _source, ...draft } = message;
|
|
142
|
+
return this.request("publish_message", "/v2/messages", { method: "POST", body: draft, signal: options.signal });
|
|
143
|
+
}
|
|
144
|
+
async listMessages(principal, query = {}, options = {}) {
|
|
145
|
+
this.assertPrincipal(principal);
|
|
146
|
+
const requestQuery = query;
|
|
147
|
+
const params = new URLSearchParams();
|
|
148
|
+
if (requestQuery.cursor) params.set("cursor", requestQuery.cursor);
|
|
149
|
+
if (requestQuery.mailbox) params.set("mailbox", requestQuery.mailbox);
|
|
150
|
+
if (requestQuery.receiptState) params.set("receiptState", requestQuery.receiptState);
|
|
151
|
+
if (requestQuery.limit) params.set("limit", String(requestQuery.limit));
|
|
152
|
+
if (requestQuery.includeExpired) params.set("includeExpired", "true");
|
|
153
|
+
if (requestQuery.source) params.set("source", requestQuery.source);
|
|
154
|
+
if (requestQuery.project) params.set("project", requestQuery.project);
|
|
155
|
+
if (requestQuery.since) params.set("since", requestQuery.since);
|
|
156
|
+
if (requestQuery.threadId) params.set("threadId", requestQuery.threadId);
|
|
157
|
+
if (requestQuery.latest) params.set("latest", "true");
|
|
158
|
+
for (const type of requestQuery.types ?? []) params.append("type", type);
|
|
159
|
+
return this.request("history", `/v2/history${params.size ? `?${params}` : ""}`, { signal: options.signal });
|
|
160
|
+
}
|
|
161
|
+
async recordReceipt(principal, ids) {
|
|
162
|
+
this.assertPrincipal(principal, false);
|
|
163
|
+
return (await this.request("record_receipt", "/v2/receipts", { method: "POST", body: { messageIds: ids } })).recorded;
|
|
164
|
+
}
|
|
165
|
+
async diagnostics(principal) {
|
|
166
|
+
this.assertPrincipal(principal);
|
|
167
|
+
const status = await this.request("status", "/v2/status");
|
|
168
|
+
this.assertBoundPrincipal(status);
|
|
169
|
+
return status;
|
|
170
|
+
}
|
|
171
|
+
async claimDelivery(principal, options) {
|
|
172
|
+
this.assertPrincipal(principal);
|
|
173
|
+
return (await this.request("claim_delivery", "/v2/deliveries/claim", { method: "POST", body: options }))?.delivery ?? null;
|
|
174
|
+
}
|
|
175
|
+
async listDeliveries(principal, query = {}) {
|
|
176
|
+
this.assertPrincipal(principal);
|
|
177
|
+
const params = new URLSearchParams();
|
|
178
|
+
if (query.cursor) params.set("cursor", query.cursor);
|
|
179
|
+
if (query.limit) params.set("limit", String(query.limit));
|
|
180
|
+
if (query.role) params.set("role", query.role);
|
|
181
|
+
if (query.messageId) params.set("messageId", query.messageId);
|
|
182
|
+
if (query.recipient) params.set("recipient", query.recipient);
|
|
183
|
+
for (const state of query.states ?? []) params.append("state", state);
|
|
184
|
+
return this.request("list_deliveries", `/v2/deliveries${params.size ? `?${params}` : ""}`);
|
|
185
|
+
}
|
|
186
|
+
async listDeliveryEvents(principal, id, query = {}) {
|
|
187
|
+
this.assertPrincipal(principal);
|
|
188
|
+
const params = new URLSearchParams();
|
|
189
|
+
if (query.cursor) params.set("cursor", query.cursor);
|
|
190
|
+
if (query.limit) params.set("limit", String(query.limit));
|
|
191
|
+
return this.request("list_delivery_events", `/v2/deliveries/${id}/events${params.size ? `?${params}` : ""}`);
|
|
192
|
+
}
|
|
193
|
+
async cancelDelivery(principal, id) {
|
|
194
|
+
this.assertPrincipal(principal);
|
|
195
|
+
return (await this.request("cancel_delivery", `/v2/deliveries/${id}/cancel`, { method: "POST", body: {} })).delivery;
|
|
196
|
+
}
|
|
197
|
+
async requeueDelivery(principal, id) {
|
|
198
|
+
this.assertPrincipal(principal);
|
|
199
|
+
return (await this.request("requeue_delivery", `/v2/deliveries/${id}/requeue`, { method: "POST", body: {} })).delivery;
|
|
200
|
+
}
|
|
201
|
+
async renewDelivery(principal, id, token, leaseMs) {
|
|
202
|
+
this.assertPrincipal(principal);
|
|
203
|
+
try {
|
|
204
|
+
return (await this.request("extend_delivery", `/v2/deliveries/${id}/extend`, { method: "POST", body: { leaseToken: token, leaseMs } })).delivery;
|
|
205
|
+
} catch (error) {
|
|
206
|
+
if (error instanceof BridgeHttpError && error.status === 409) return null;
|
|
207
|
+
throw error;
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
async settleDelivery(principal, id, token, state, error, _retryPolicy) {
|
|
211
|
+
this.assertPrincipal(principal);
|
|
212
|
+
await this.ensureProtocol();
|
|
213
|
+
const action = state === "acked" ? "ack" : "nack";
|
|
214
|
+
try {
|
|
215
|
+
const operationId = action === "ack" ? "acknowledge_delivery" : "negative_acknowledge_delivery";
|
|
216
|
+
const nackBody = { leaseToken: token, error, disposition: state === "dead" ? "dead" : "retry" };
|
|
217
|
+
return (await this.request(operationId, `/v2/deliveries/${id}/${action}`, { method: "POST", body: action === "ack" ? { leaseToken: token } : nackBody })).delivery;
|
|
218
|
+
} catch (caught) {
|
|
219
|
+
if (caught instanceof BridgeHttpError && caught.status === 409) return null;
|
|
220
|
+
throw caught;
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
async heartbeat(principal, leaseMs, runtimeType, capabilities = []) {
|
|
224
|
+
this.assertPrincipal(principal);
|
|
225
|
+
return this.request("heartbeat", "/v2/presence/heartbeat", { method: "POST", body: { leaseMs, runtimeType, capabilities } });
|
|
226
|
+
}
|
|
227
|
+
async listPresence(principal) {
|
|
228
|
+
this.assertPrincipal(principal);
|
|
229
|
+
return (await this.request("presence", "/v2/presence")).agents;
|
|
230
|
+
}
|
|
231
|
+
async close() {
|
|
232
|
+
if (this.closed) return;
|
|
233
|
+
this.closed = true;
|
|
234
|
+
this.closeController.abort(new Error("store closed"));
|
|
235
|
+
}
|
|
236
|
+
};
|
|
237
|
+
|
|
238
|
+
export {
|
|
239
|
+
BridgeHttpError,
|
|
240
|
+
HttpBridgeStore
|
|
241
|
+
};
|
|
242
|
+
//# sourceMappingURL=chunk-WQ4I5XGF.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/http-bridge-store.ts"],"sourcesContent":["import type { AgentPresence, BridgeDelivery, BridgeMessage, BridgePrincipal } from \"./bridge-domain.js\";\nimport type { BridgeDiagnostics, BridgeStore, ClaimOptions, InsertMessageResult, MessagePage, MessageQuery } from \"./bridge-store.js\";\nimport {\n ContractResponseError,\n parseResponse,\n PROTOCOL_HEADER,\n PROTOCOL_VERSION,\n SUPPORTED_PROTOCOL_HEADER,\n SUPPORTED_PROTOCOL_VERSIONS,\n type OperationId,\n} from \"./contracts/registry.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(\n readonly status: number,\n readonly code: string,\n readonly requestId?: string,\n readonly details?: unknown,\n message = `Agent Bridge request failed: ${code}`,\n ) {\n super(message);\n }\n}\n\nexport class HttpBridgeStore implements BridgeStore {\n private readonly fetchImpl: typeof fetch;\n private readonly closeController = new AbortController();\n private closed = false;\n private selectedProtocolVersion?: string;\n private protocolProbe?: Promise<string>;\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(options: { signal?: AbortSignal; mode?: \"active\" | \"passive\" } = {}): Promise<void> {\n if (options.mode === \"passive\") return;\n await this.request(undefined, \"/readyz\", { authenticated: false, signal: options.signal });\n const status = await this.request(\"status\", \"/v2/status\", { signal: options.signal });\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(operationId: OperationId | undefined, path: string, options: { method?: string; body?: unknown; authenticated?: boolean; signal?: AbortSignal; skipProtocolProbe?: boolean } = {}): Promise<any> {\n if (options.method === \"POST\" && !options.skipProtocolProbe) await this.ensureProtocol(options.signal);\n if (this.closed) throw new BridgeHttpError(0, \"store_closed\");\n if (options.signal?.aborted) throw new BridgeHttpError(0, \"request_cancelled\");\n const requestController = new AbortController();\n const abort = () => requestController.abort(this.closeController.signal.reason);\n const abortRequest = () => requestController.abort(options.signal?.reason);\n this.closeController.signal.addEventListener(\"abort\", abort, { once: true });\n options.signal?.addEventListener(\"abort\", abortRequest, { once: true });\n let timedOut = false;\n const timeout = setTimeout(() => {\n timedOut = true;\n requestController.abort(new Error(\"request timeout\"));\n }, this.options.timeoutMs ?? 10_000);\n timeout.unref?.();\n try {\n const response = await this.fetchImpl(`${this.options.baseUrl.replace(/\\/$/, \"\")}${path}`, {\n method: options.method ?? \"GET\", signal: requestController.signal,\n headers: {\n [PROTOCOL_HEADER]: this.selectedProtocolVersion ?? PROTOCOL_VERSION,\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 requestId = response.headers.get(\"x-request-id\") ?? undefined;\n const selectedHeader = response.headers.get(PROTOCOL_HEADER);\n const supportedHeader = response.headers.get(SUPPORTED_PROTOCOL_HEADER);\n const supportedProtocols = supportedHeader?.split(\",\").map((value) => value.trim()).filter(Boolean) ?? [];\n const inconsistentProtocol = (\n selectedHeader === null || supportedHeader === null ||\n !(SUPPORTED_PROTOCOL_VERSIONS as readonly string[]).includes(selectedHeader) ||\n !supportedProtocols.includes(selectedHeader) ||\n selectedHeader !== PROTOCOL_VERSION\n );\n if (operationId && inconsistentProtocol) {\n throw new BridgeHttpError(502, \"protocol_mismatch\", requestId, {\n expected: PROTOCOL_VERSION,\n selected: selectedHeader,\n supported: supportedHeader,\n });\n }\n const contentType = response.headers.get(\"content-type\") ?? \"\";\n const payload = contentType.startsWith(\"application/json\")\n ? await response.json().catch(() => ({}))\n : await response.text();\n if (!response.ok) {\n const envelope = payload && typeof payload === \"object\" ? (payload as any).error : undefined;\n throw new BridgeHttpError(\n response.status,\n envelope?.code ?? \"request_failed\",\n envelope?.requestId ?? requestId,\n envelope?.details ?? envelope,\n envelope?.message ?? `Agent Bridge request failed: ${envelope?.code ?? \"request_failed\"}`,\n );\n }\n if (operationId) this.selectedProtocolVersion = PROTOCOL_VERSION;\n if (!operationId) return payload;\n return parseResponse(operationId, payload);\n } catch (error) {\n if (error instanceof BridgeHttpError) throw error;\n if (error instanceof ContractResponseError) {\n throw new BridgeHttpError(error.status, error.code, undefined, {\n operation: error.operation,\n issues: error.issues,\n }, error.message);\n }\n if (this.closed) throw new BridgeHttpError(0, \"store_closed\");\n if (options.signal?.aborted) throw new BridgeHttpError(0, \"request_cancelled\");\n if (timedOut) throw new BridgeHttpError(504, \"request_timeout\");\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 } finally {\n clearTimeout(timeout);\n this.closeController.signal.removeEventListener(\"abort\", abort);\n options.signal?.removeEventListener(\"abort\", abortRequest);\n }\n }\n\n private ensureProtocol(signal?: AbortSignal): Promise<string> {\n if (this.selectedProtocolVersion) return Promise.resolve(this.selectedProtocolVersion);\n if (!this.protocolProbe) {\n this.protocolProbe = this.request(\"status\", \"/v2/status\", { signal, skipProtocolProbe: true })\n .then(() => this.selectedProtocolVersion!)\n .finally(() => { this.protocolProbe = undefined; });\n }\n return this.protocolProbe;\n }\n async capabilities(): Promise<unknown> { return this.request(\"capabilities\", \"/v2/capabilities\"); }\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\">, options: { signal?: AbortSignal } = {}): Promise<InsertMessageResult> {\n this.assertPrincipal({ workspace: message.workspace, agent: message.source }, false);\n await this.ensureProtocol(options.signal);\n const { workspace: _workspace, source: _source, ...draft } = message;\n return this.request(\"publish_message\", \"/v2/messages\", { method: \"POST\", body: draft, signal: options.signal });\n }\n async listMessages(principal: BridgePrincipal, query: MessageQuery = {}, options: { signal?: AbortSignal } = {}): Promise<MessagePage> {\n this.assertPrincipal(principal);\n const requestQuery = query;\n const params = new URLSearchParams();\n if (requestQuery.cursor) params.set(\"cursor\", requestQuery.cursor);\n if (requestQuery.mailbox) params.set(\"mailbox\", requestQuery.mailbox);\n if (requestQuery.receiptState) params.set(\"receiptState\", requestQuery.receiptState);\n if (requestQuery.limit) params.set(\"limit\", String(requestQuery.limit));\n if (requestQuery.includeExpired) params.set(\"includeExpired\", \"true\");\n if (requestQuery.source) params.set(\"source\", requestQuery.source);\n if (requestQuery.project) params.set(\"project\", requestQuery.project);\n if (requestQuery.since) params.set(\"since\", requestQuery.since);\n if (requestQuery.threadId) params.set(\"threadId\", requestQuery.threadId);\n if (requestQuery.latest) params.set(\"latest\", \"true\");\n for (const type of requestQuery.types ?? []) params.append(\"type\", type);\n return this.request(\"history\", `/v2/history${params.size ? `?${params}` : \"\"}`, { signal: options.signal });\n }\n async recordReceipt(principal: BridgePrincipal, ids: string[]): Promise<number> {\n this.assertPrincipal(principal, false);\n return (await this.request(\"record_receipt\", \"/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(\"status\", \"/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(\"claim_delivery\", \"/v2/deliveries/claim\", { method: \"POST\", body: options }))?.delivery ?? null;\n }\n async listDeliveries(principal: BridgePrincipal, query: import(\"./bridge-store.js\").DeliveryQuery = {}) {\n this.assertPrincipal(principal); const params=new URLSearchParams(); if(query.cursor)params.set(\"cursor\",query.cursor);if(query.limit)params.set(\"limit\",String(query.limit));if(query.role)params.set(\"role\",query.role);if(query.messageId)params.set(\"messageId\",query.messageId);if(query.recipient)params.set(\"recipient\",query.recipient);for(const state of query.states??[])params.append(\"state\",state);return this.request(\"list_deliveries\",`/v2/deliveries${params.size?`?${params}`:\"\"}`);\n }\n async listDeliveryEvents(principal: BridgePrincipal,id:string,query:{cursor?:string;limit?:number}={}) { this.assertPrincipal(principal);const params=new URLSearchParams();if(query.cursor)params.set(\"cursor\",query.cursor);if(query.limit)params.set(\"limit\",String(query.limit));return this.request(\"list_delivery_events\",`/v2/deliveries/${id}/events${params.size?`?${params}`:\"\"}`); }\n async cancelDelivery(principal:BridgePrincipal,id:string){this.assertPrincipal(principal);return (await this.request(\"cancel_delivery\",`/v2/deliveries/${id}/cancel`,{method:\"POST\",body:{}})).delivery;}\n async requeueDelivery(principal:BridgePrincipal,id:string){this.assertPrincipal(principal);return (await this.request(\"requeue_delivery\",`/v2/deliveries/${id}/requeue`,{method:\"POST\",body:{}})).delivery;}\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(\"extend_delivery\", `/v2/deliveries/${id}/extend`, { method: \"POST\", body: { leaseToken: token, leaseMs } })).delivery;\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, _retryPolicy?: import(\"./bridge-domain.js\").RetryPolicy): Promise<BridgeDelivery | null> {\n this.assertPrincipal(principal);\n await this.ensureProtocol();\n const action = state === \"acked\" ? \"ack\" : \"nack\";\n try {\n const operationId = action === \"ack\" ? \"acknowledge_delivery\" : \"negative_acknowledge_delivery\";\n const nackBody = { leaseToken: token, error, disposition: state === \"dead\" ? \"dead\" : \"retry\" };\n return (await this.request(operationId, `/v2/deliveries/${id}/${action}`, { method: \"POST\", body: action === \"ack\" ? { leaseToken: token } : nackBody })).delivery;\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(\"heartbeat\", \"/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(\"presence\", \"/v2/presence\")).agents;\n }\n async close(): Promise<void> {\n if (this.closed) return;\n this.closed = true;\n this.closeController.abort(new Error(\"store closed\"));\n }\n}\n"],"mappings":";;;;;;;;;;;AAqBO,IAAM,kBAAN,cAA8B,MAAM;AAAA,EACzC,YACW,QACA,MACA,WACA,SACT,UAAU,gCAAgC,IAAI,IAC9C;AACA,UAAM,OAAO;AANJ;AACA;AACA;AACA;AAAA,EAIX;AACF;AAEO,IAAM,kBAAN,MAA6C;AAAA,EAMlD,YAA6B,SAAiC;AAAjC;AAJ7B,SAAiB,kBAAkB,IAAI,gBAAgB;AACvD,SAAQ,SAAS;AAIf,UAAM,MAAM,IAAI,IAAI,QAAQ,OAAO;AACnC,UAAM,WAAW,IAAI,aAAa,eAAe,IAAI,aAAa,eAAe,IAAI,aAAa;AAClG,QAAI,IAAI,aAAa,YAAY,EAAE,IAAI,aAAa,WAAW,aAAa,CAAC,QAAQ,yBAAyB;AAC5G,YAAM,IAAI,MAAM,uDAAuD;AAAA,IACzE;AACA,SAAK,YAAY,QAAQ,SAAS;AAAA,EACpC;AAAA,EACA,MAAM,WAAW,UAAiE,CAAC,GAAkB;AACnG,QAAI,QAAQ,SAAS,UAAW;AAChC,UAAM,KAAK,QAAQ,QAAW,WAAW,EAAE,eAAe,OAAO,QAAQ,QAAQ,OAAO,CAAC;AACzF,U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queueMessage(message) {
|
|
1101
|
+
this.assertHealthy();
|
|
1102
|
+
this.assertPrincipal({ workspace: message.workspace, agent: message.source }, false);
|
|
1103
|
+
await this.edge.assertScopeActive();
|
|
1104
|
+
const queued = await this.edge.enqueue(message, this.now());
|
|
1105
|
+
return {
|
|
1106
|
+
message: provisional(queued.draft, this.now().toISOString()),
|
|
1107
|
+
created: queued.created,
|
|
1108
|
+
disposition: "queued",
|
|
1109
|
+
authoritative: false
|
|
1110
|
+
};
|
|
1111
|
+
}
|
|
1100
1112
|
async pull(maxPages, signal) {
|
|
1101
1113
|
let pulled = 0;
|
|
1102
1114
|
for (let pageNumber = 0; pageNumber < maxPages; pageNumber += 1) {
|
|
@@ -1403,4 +1415,4 @@ export {
|
|
|
1403
1415
|
isRetryableSyncError,
|
|
1404
1416
|
SyncingBridgeStore
|
|
1405
1417
|
};
|
|
1406
|
-
//# sourceMappingURL=chunk-
|
|
1418
|
+
//# sourceMappingURL=chunk-ZUZ7TCIH.js.map
|