@creatornader/agent-bridge 0.3.1 → 0.4.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 +150 -1
- package/README.md +239 -5
- package/ROADMAP.md +59 -7
- package/SECURITY.md +55 -5
- package/SKILL.md +103 -0
- package/dist/archive.d.ts +2 -2
- package/dist/archive.js +2 -2
- package/dist/{bridge-service-hX1ZQp4W.d.ts → bridge-service-YTjGr91A.d.ts} +1 -1
- package/dist/{bridge-store-DPVSCwfs.d.ts → bridge-store-Boaj-ZbO.d.ts} +2 -0
- package/dist/bridge.d.ts +17 -7
- package/dist/bridge.js +15 -7
- package/dist/{chunk-WAI2IYIQ.js → chunk-3YHVUPU2.js} +48 -5
- package/dist/chunk-3YHVUPU2.js.map +1 -0
- package/dist/{chunk-45BZGB77.js → chunk-6BTJE6D4.js} +168 -7
- package/dist/chunk-6BTJE6D4.js.map +1 -0
- package/dist/{chunk-5GMB3A77.js → chunk-DQOZJJZ2.js} +22 -10
- package/dist/chunk-DQOZJJZ2.js.map +1 -0
- package/dist/{chunk-NCO7RLBM.js → chunk-GTK4KOED.js} +108 -8
- package/dist/chunk-GTK4KOED.js.map +1 -0
- package/dist/{chunk-GADH244D.js → chunk-IHZFI7TH.js} +12 -4
- package/dist/chunk-IHZFI7TH.js.map +1 -0
- package/dist/{chunk-CEXBMOI5.js → chunk-LAHNQZDN.js} +2 -2
- package/dist/{chunk-UAHMP6GC.js → chunk-MCKKVNCE.js} +9 -6
- package/dist/chunk-MCKKVNCE.js.map +1 -0
- package/dist/{chunk-MBPZXTJA.js → chunk-PDIHDBP3.js} +173 -20
- package/dist/chunk-PDIHDBP3.js.map +1 -0
- package/dist/{chunk-Q6PPMXJC.js → chunk-SV3SVBYS.js} +377 -21
- package/dist/chunk-SV3SVBYS.js.map +1 -0
- package/dist/{chunk-SPSMZOCJ.js → chunk-SYGONYMM.js} +4 -4
- package/dist/{chunk-A6W4QALF.js → chunk-TC6A7GMF.js} +2 -2
- package/dist/cli.js +5865 -436
- package/dist/cli.js.map +1 -1
- package/dist/client-runtime.d.ts +4 -2
- package/dist/client-runtime.js +6 -6
- package/dist/contracts/generate.js +1 -1
- package/dist/dr.d.ts +9 -2
- package/dist/dr.js +6 -4
- package/dist/{gateway-CggQ8vTC.d.ts → gateway-BQHpV-MZ.d.ts} +27 -3
- package/dist/gateway-main.js +69 -5
- package/dist/gateway-main.js.map +1 -1
- package/dist/gateway.d.ts +3 -3
- package/dist/gateway.js +2 -2
- package/dist/index.js +7 -7
- package/dist/{postgres-bridge-store-Bfd3hRId.d.ts → postgres-bridge-store-WASumj26.d.ts} +1 -1
- package/dist/server.js +7 -7
- package/dist/sqlite-edge-store-Bc15DvpX.d.ts +148 -0
- package/dist/sqlite.d.ts +19 -80
- package/dist/sqlite.js +11 -3
- package/docs/architecture-v2.md +256 -10
- package/docs/decisions/0004-client-lifecycle-and-endpoint-migration.md +204 -0
- package/docs/deployment.md +205 -0
- package/docs/troubleshooting.md +23 -0
- package/llms.txt +67 -0
- package/openapi/agent-bridge-v2.openapi.json +1023 -0
- package/package.json +6 -2
- package/schemas/agent-bridge-v2.capabilities.json +24 -0
- package/schemas/agent-bridge-v2.mcp.json +6 -0
- package/schemas/agent-bridge-v2.schema.json +163 -0
- package/sql/migrations/017_gateway_authority_binding.sql +99 -0
- package/sql/migrations/018_endpoint_migration_challenges.sql +1028 -0
- package/sql/migrations/019_endpoint_migration_same_successor.sql +324 -0
- package/dist/chunk-45BZGB77.js.map +0 -1
- package/dist/chunk-5GMB3A77.js.map +0 -1
- package/dist/chunk-GADH244D.js.map +0 -1
- package/dist/chunk-MBPZXTJA.js.map +0 -1
- package/dist/chunk-NCO7RLBM.js.map +0 -1
- package/dist/chunk-Q6PPMXJC.js.map +0 -1
- package/dist/chunk-UAHMP6GC.js.map +0 -1
- package/dist/chunk-WAI2IYIQ.js.map +0 -1
- /package/dist/{chunk-CEXBMOI5.js.map → chunk-LAHNQZDN.js.map} +0 -0
- /package/dist/{chunk-SPSMZOCJ.js.map → chunk-SYGONYMM.js.map} +0 -0
- /package/dist/{chunk-A6W4QALF.js.map → chunk-TC6A7GMF.js.map} +0 -0
package/SECURITY.md
CHANGED
|
@@ -14,19 +14,24 @@ fixed. The npm package and GitHub release page are the public version authoritie
|
|
|
14
14
|
|
|
15
15
|
## Release integrity
|
|
16
16
|
|
|
17
|
-
GitHub immutable releases are enabled, and GitHub reports release `v0.3.
|
|
17
|
+
GitHub immutable releases are enabled, and GitHub reports release `v0.3.1` as
|
|
18
18
|
immutable. A repository ruleset also blocks updates and deletion for every `v*` tag
|
|
19
|
-
without a bypass actor. The `v0.3.
|
|
19
|
+
without a bypass actor. The `v0.3.1` tag is unsigned.
|
|
20
20
|
|
|
21
21
|
npm publication uses a protected GitHub environment, an OIDC trusted-publisher
|
|
22
22
|
binding, and provenance for the package artifact. Verify the package digest and
|
|
23
|
-
attestation before treating provenance as source identity. The
|
|
23
|
+
attestation before treating provenance as source identity. The
|
|
24
|
+
[`v0.3.1` release run](https://github.com/creatornader/agent-bridge/actions/runs/29465467036)
|
|
25
|
+
used package commit `d17ba544d31beaa33b4955e41c3b3d4e3f141900`.
|
|
26
|
+
|
|
27
|
+
The historical `v0.3.0`
|
|
24
28
|
[recovery run](https://github.com/creatornader/agent-bridge/actions/runs/29461308262)
|
|
25
29
|
checked out package commit `95eb861`, while its attestation names recovery commit
|
|
26
30
|
`c23d9df` as the workflow identity. GitHub Actions logs expire, so the
|
|
27
31
|
[release notes](https://github.com/creatornader/agent-bridge/releases/tag/v0.3.0)
|
|
28
|
-
also record this boundary.
|
|
29
|
-
|
|
32
|
+
also record this boundary. Recovery dispatches must run at the release tag. The
|
|
33
|
+
workflow also requires a successful `test.yml` run from `main` for the exact package
|
|
34
|
+
commit before packaging.
|
|
30
35
|
|
|
31
36
|
## Report a vulnerability
|
|
32
37
|
|
|
@@ -46,6 +51,13 @@ Local mode relies on operating-system account isolation and private file permiss
|
|
|
46
51
|
Anyone who can act as the same operating-system user can generally read or replace that
|
|
47
52
|
user's Agent Bridge state. Local mode is not a hostile multi-user boundary.
|
|
48
53
|
|
|
54
|
+
Managed-client mutations may cache a successful native Windows ACL check while one
|
|
55
|
+
operation lock remains held. The cache is bound to the verified directory identity and is
|
|
56
|
+
discarded with the lock. New locks, resumed operations, and passive inspection check
|
|
57
|
+
the ACL again. POSIX permission checks are not cached. A same-user process can still
|
|
58
|
+
change an ACL on an unchanged object or replace a directory with one that reuses the
|
|
59
|
+
same filesystem identity. Both actions are within the local-mode trust boundary.
|
|
60
|
+
|
|
49
61
|
### Gateway mode
|
|
50
62
|
|
|
51
63
|
Gateway credentials bind one workspace and principal. The gateway derives remote
|
|
@@ -53,10 +65,31 @@ identity from the credential, applies operation scopes and rate policy, and uses
|
|
|
53
65
|
transaction-bound PostgreSQL request authority. Production runtime roles must not be
|
|
54
66
|
superusers or hold `BYPASSRLS`. Put every non-loopback gateway behind TLS.
|
|
55
67
|
|
|
68
|
+
Do not publish PostgreSQL on a public interface. Put it on a private network reachable
|
|
69
|
+
only by the migration, runtime bootstrap, gateway, backup, and recovery jobs that need
|
|
70
|
+
it. The checked-in Compose file binds both published ports to loopback and serves plain
|
|
71
|
+
HTTP for local development. It is not a public deployment template.
|
|
72
|
+
|
|
56
73
|
Keep the schema-owner, runtime, operator, archive, backup, and restore database
|
|
57
74
|
authorities separate. Do not copy one client's token or backend file into another
|
|
58
75
|
client's configuration.
|
|
59
76
|
|
|
77
|
+
Run migrations as a one-shot schema-owner job before starting a new gateway image.
|
|
78
|
+
Take and verify a native DR backup first. Gateway readiness checks the exact migration
|
|
79
|
+
plan and protected catalog state. Once a migration changes the database, starting an
|
|
80
|
+
older image is not a safe rollback. Apply a forward fix or restore the backup into a
|
|
81
|
+
fresh target and switch authority only after verification.
|
|
82
|
+
|
|
83
|
+
Drain old gateway instances before migrations 017 and 018. An old image reports `/readyz` as
|
|
84
|
+
not ready after the new migration is visible, but a process that was already running
|
|
85
|
+
can still serve ordinary requests until traffic is removed or it exits. Start the new
|
|
86
|
+
gateway only after the migration and runtime bootstrap finish.
|
|
87
|
+
|
|
88
|
+
Migration 018 accepts raw endpoint-migration challenges only as SQL function input. It
|
|
89
|
+
stores a domain-separated SHA-256 commitment, never the raw challenge, and excludes
|
|
90
|
+
live challenge rows from native DR data dumps. The challenge proves an active direct
|
|
91
|
+
credential replacement on one authority. It does not authorize endpoint cutover.
|
|
92
|
+
|
|
60
93
|
### Legacy Supabase mode
|
|
61
94
|
|
|
62
95
|
The legacy adapter keeps existing v1 deployments working, but its publishable key can
|
|
@@ -74,6 +107,9 @@ through a separately trusted channel.
|
|
|
74
107
|
PostgreSQL restore executes SQL from the source dump. Use
|
|
75
108
|
`--accept-source-sql-risk` only for a bundle from a trusted source. Never activate the
|
|
76
109
|
source and restored target as authorities at the same time.
|
|
110
|
+
The restored gateway authority UUID identifies the same logical authority. It does not
|
|
111
|
+
prevent an operator from activating a live clone, so the deployment cutover remains an
|
|
112
|
+
operator-controlled safety boundary.
|
|
77
113
|
|
|
78
114
|
### Optional integrations
|
|
79
115
|
|
|
@@ -86,5 +122,19 @@ when wrapper health is uncertain.
|
|
|
86
122
|
- Pass gateway tokens through private enrollment or backend files, not shell arguments.
|
|
87
123
|
- Keep database URLs in the documented environment variables. Do not put them in CLI
|
|
88
124
|
arguments, logs, issues, or examples.
|
|
125
|
+
- Store Compose password files outside version control with owner-only permissions.
|
|
126
|
+
Use the deployment platform's secret manager in production. Do not bake passwords or
|
|
127
|
+
tokens into images, Compose environment blocks, or image layers.
|
|
128
|
+
- File-backed Compose secrets retain host ownership on native Linux. The development
|
|
129
|
+
stack starts a small Node entrypoint as root with `DAC_OVERRIDE`, `SETUID`, and
|
|
130
|
+
`SETGID`, reads one granted secret, then drops supplementary groups and UID/GID to
|
|
131
|
+
1000 before it imports the gateway. The final process has no effective capabilities
|
|
132
|
+
and cannot regain them under `no-new-privileges`. The fixed runtime-bootstrap job
|
|
133
|
+
keeps `DAC_OVERRIDE`, `SETUID`, and `SETGID` while it reads its two secrets, then runs
|
|
134
|
+
`psql` as the PostgreSQL account. It rejects runtime passwords shorter than 32
|
|
135
|
+
characters.
|
|
89
136
|
- Treat client backend files, enrollment files, archives, and DR bundles as secrets.
|
|
90
137
|
- Sanitize `doctor` output and logs before sharing them publicly.
|
|
138
|
+
|
|
139
|
+
A Docker volume provides persistence, not backup. Keep verified native DR bundles on a
|
|
140
|
+
separate failure domain with retention and restore drills appropriate to the deployment.
|
package/SKILL.md
CHANGED
|
@@ -7,6 +7,11 @@ description: Share context and reliable work between agents across runtimes and
|
|
|
7
7
|
|
|
8
8
|
Discover the active v2 operation contract with MCP `capabilities`, CLI `agent-bridge capabilities`, or authenticated `GET /v2/capabilities`. Released 2.0 clients continue to work after the gateway is upgraded. A new 2.1 client must receive complete, consistent negotiation headers that select and advertise 2.1 before it mutates remote state. If the probe is headerless, selects 2.0, or returns partial or contradictory headers, do not mutate. Upgrade the gateway first instead of downgrading the client.
|
|
9
9
|
|
|
10
|
+
An authenticated PostgreSQL gateway status response can include `gatewayAuthorityId`
|
|
11
|
+
and `credentialId`. They are additive in HTTP 2.1. `clients migrate cutover`
|
|
12
|
+
requires and validates both fields before it switches a managed gateway endpoint.
|
|
13
|
+
Do not switch an endpoint by editing its backend file.
|
|
14
|
+
|
|
10
15
|
Use the Agent Bridge MCP tools for normal traffic. Let the active runtime supply its own identity. Do not pass a literal source unless a standalone CLI process has no configured identity.
|
|
11
16
|
|
|
12
17
|
If the MCP server is unavailable or disconnects, report the outage instead of implying
|
|
@@ -51,6 +56,104 @@ If a crash leaves the adjacent enrollment lock, wait at least 60 seconds and pas
|
|
|
51
56
|
`--recover-lock` with the resume or install command. Recovery must prove that the
|
|
52
57
|
same-host process recorded in the lock has stopped. Never remove the lock manually.
|
|
53
58
|
|
|
59
|
+
Before Agent Bridge takes lifecycle ownership of an existing Codex, Claude Code, or
|
|
60
|
+
Claude Desktop registration, run `agent-bridge clients inspect <runtime>` with its
|
|
61
|
+
exact `--identity`, stable `--instance`, and absolute `--backend-config` path. Supply
|
|
62
|
+
the installed command and Claude Code scope when they differ from defaults. Treat
|
|
63
|
+
`drifted` as a stop condition. `agent-bridge clients adopt` returns a plan by default;
|
|
64
|
+
only add `--apply` after reviewing an exact `unmanaged` result. Adoption writes
|
|
65
|
+
credential-free owner-private metadata only. It does not rewrite the MCP registration
|
|
66
|
+
or backend file, and inspection never returns backend values or contacts the gateway.
|
|
67
|
+
Desktop adoption records the normalized config path. Codex adoption records the active
|
|
68
|
+
profile config. Run Claude Code local or project adoption from the directory that
|
|
69
|
+
later lifecycle operations should use; the native CLI exposes no stronger target.
|
|
70
|
+
The backend and its immediate parent must already pass the owner-only no-link policy.
|
|
71
|
+
Treat registration state separately from connectivity health; applied adoption
|
|
72
|
+
re-inspects the registration before it reports success. Enrollment-based first-time
|
|
73
|
+
provisioning continues to refuse registration and backend-file collisions.
|
|
74
|
+
Use `agent-bridge clients operations` or append an operation UUID to inspect local
|
|
75
|
+
crash-safe operation state. Artifact contents remain confined to owner-private files;
|
|
76
|
+
inspection reports resumable, classification-required, blocked, or complete and names
|
|
77
|
+
the exact pending step only. Begin is lock-covered, resume is same-host only, and
|
|
78
|
+
ordered steps use no-replace before and verified after artifacts. Treat corrupt,
|
|
79
|
+
cross-host, or ambiguous state as a stop condition. Cleanup is restartable per artifact
|
|
80
|
+
and `committed` means verified writes plus removed artifacts. The terminal manifest
|
|
81
|
+
keeps a credential-free completion record but no request, step, digest, locator, or
|
|
82
|
+
artifact metadata.
|
|
83
|
+
|
|
84
|
+
For a managed registration, use `clients repair <runtime> --identity <name> --instance
|
|
85
|
+
<key>` to preview its recorded launch contract and backend privacy repair. Add `--apply`
|
|
86
|
+
only after reviewing the plan. Use `clients update` with the same metadata-selected
|
|
87
|
+
runtime and instance to validate a replacement launch contract. The same identity must
|
|
88
|
+
match the stored metadata and the immutable request. Native commands are one executable
|
|
89
|
+
contract. Do not pass arguments, URLs, or credential selectors in `--command`. Repair, update, and uninstall reject
|
|
90
|
+
`--backend-config`, `--scope`, and `--config-path`; `--identity` is an assertion, not a
|
|
91
|
+
locator. A no-op exact registration creates no journal. Native updates remove, prove
|
|
92
|
+
absence, add, and prove the target before metadata changes. Desktop updates replace only
|
|
93
|
+
the Agent Bridge entry and retain unrelated JSON values in memory. It publishes through
|
|
94
|
+
a private operation-scoped temporary file. A concurrent same-user Desktop writer can
|
|
95
|
+
still race this advisory single-file update because Node cannot provide an OS transaction.
|
|
96
|
+
|
|
97
|
+
Use `clients uninstall <runtime> --identity <name> --instance <key>` to preview a
|
|
98
|
+
forward-only removal. With `--apply`, it proves and removes the managed registration,
|
|
99
|
+
deletes the already private backend file, then deletes metadata. It refuses a backend
|
|
100
|
+
that needs privacy repair and never recreates an earlier target after a later failure.
|
|
101
|
+
Desktop removes only its Agent Bridge entry. Backend content never enters the journal.
|
|
102
|
+
|
|
103
|
+
Use `clients rollback <update-operation-id> --identity <name>` to inspect an explicit
|
|
104
|
+
reverse plan for a committed same-host v4 update. Add `--apply` only after reviewing
|
|
105
|
+
that plan. The source record retains only prior nonsecret managed metadata, its exact
|
|
106
|
+
registration contract, and forward-state digests. Rollback verifies those digests
|
|
107
|
+
against the current registration, then creates a separate reverse journal. Native
|
|
108
|
+
rollback removes the forward entry, adds the prior entry, and writes prior metadata
|
|
109
|
+
last. Claude Desktop replaces only its Agent Bridge entry and preserves unrelated JSON.
|
|
110
|
+
Repair has no rollback. Uninstall remains forward-only, so recovery is re-enrollment.
|
|
111
|
+
|
|
112
|
+
Use `clients migrate stage <runtime> --identity <name> --instance <key>
|
|
113
|
+
--enrollment-file <path>` to review a gateway successor prepared from a non-immediate
|
|
114
|
+
rotation enrollment. Add `--apply` only after reviewing the plan. Staging writes a
|
|
115
|
+
private successor backend and a credential-free operation record. It leaves the active
|
|
116
|
+
registration and active backend unchanged. It initializes the source edge gate but
|
|
117
|
+
leaves that gate active. It does not drain, cut over, or prove that two gateway URLs
|
|
118
|
+
reach the same database authority. The source backend must use an absolute, normalized
|
|
119
|
+
edge database path, not `:memory:`. Resume an interrupted stage with `clients resume
|
|
120
|
+
<operation-id> [--recover-lock]`. Use lock
|
|
121
|
+
recovery only after the recorded same-host process has stopped. Never remove a lock
|
|
122
|
+
manually.
|
|
123
|
+
|
|
124
|
+
Use `clients migrate cutover <stage-operation-id> --exclusive-edge` to inspect the
|
|
125
|
+
host switch. Add `--apply` only after checking the plan. The applied command requires
|
|
126
|
+
an active source edge and an active empty target edge. It verifies both HTTP 2.1
|
|
127
|
+
gateways against the recorded workspace, principal, credential IDs, and authority ID.
|
|
128
|
+
It also requires the successor `status:read` and `messages:write` grants, then completes
|
|
129
|
+
a direct predecessor-to-successor route challenge. Once its journal exists, it uses the
|
|
130
|
+
retained normalized source URL with the successor credential for route proofs and
|
|
131
|
+
source-edge replay through the target gateway. It leases and drains the source edge to
|
|
132
|
+
exact zero outbox work before changing a host registration. Native clients remove the
|
|
133
|
+
source and add the target. Claude Desktop replaces its one Agent Bridge entry. Managed
|
|
134
|
+
metadata changes last. The command rechecks gateway authority and the source lease
|
|
135
|
+
before each host write.
|
|
136
|
+
|
|
137
|
+
Every phase needs `--exclusive-edge`. Agent Bridge verifies the managed registrations
|
|
138
|
+
that share the edge file, including hardlink aliases. It cannot enumerate unmanaged
|
|
139
|
+
publishers, so the operator must assert that cohort is exclusive. `clients migrate
|
|
140
|
+
finalize <cutover-operation-id> --exclusive-edge --apply` works after
|
|
141
|
+
grace expires and retires the source edge. To return to a previous endpoint, rotate a
|
|
142
|
+
new owner credential and cut forward to it as a new successor. Resume any interrupted
|
|
143
|
+
v6 phase with `clients resume <operation-id> [--recover-lock]`. A new worker must wait
|
|
144
|
+
for the held drain lease to expire. Dry planning never contacts a gateway or writes
|
|
145
|
+
SQLite. It refuses an edge with live WAL sidecars rather than read stale outbox state.
|
|
146
|
+
|
|
147
|
+
Resume an action-specific operation with the same action, runtime, instance, and
|
|
148
|
+
identity: `--apply --resume <uuid>`. The stored request controls resume. Do not supply
|
|
149
|
+
a new command unless it exactly matches the recorded update request. Use
|
|
150
|
+
`clients resume <uuid> [--recover-lock]` to resume from a recorded v3, supported v4,
|
|
151
|
+
v5 migration-stage, or v6 endpoint-migration request alone. It does not accept
|
|
152
|
+
replacement client authority. Use the generic form after uninstall has
|
|
153
|
+
deleted metadata. `--recover-lock` on an action-specific command also requires
|
|
154
|
+
`--apply`; it only recovers a stale same-host lock after process-death proof. Never
|
|
155
|
+
remove operation locks by hand.
|
|
156
|
+
|
|
54
157
|
Portable archive work is an offline operator task, not normal MCP traffic. Use
|
|
55
158
|
`agent-bridge archive export --provider local|postgres --workspace <workspace>
|
|
56
159
|
--output <file>` to create an archive, then run `agent-bridge archive verify --file
|
package/dist/archive.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { J as JsonValue, i as MessagePriority, f as DeliveryPolicy } from './bridge-domain-CBX3IVqC.js';
|
|
2
|
-
import { P as PgQueryable } from './postgres-bridge-store-
|
|
3
|
-
import './bridge-store-
|
|
2
|
+
import { P as PgQueryable } from './postgres-bridge-store-WASumj26.js';
|
|
3
|
+
import './bridge-store-Boaj-ZbO.js';
|
|
4
4
|
|
|
5
5
|
interface PortableArchiveMessage {
|
|
6
6
|
id: string;
|
package/dist/archive.js
CHANGED
|
@@ -21,8 +21,8 @@ import {
|
|
|
21
21
|
streamPortableArchive,
|
|
22
22
|
validateArchiveWorkspace,
|
|
23
23
|
validatePortableArchiveRequestId
|
|
24
|
-
} from "./chunk-
|
|
25
|
-
import "./chunk-
|
|
24
|
+
} from "./chunk-TC6A7GMF.js";
|
|
25
|
+
import "./chunk-GTK4KOED.js";
|
|
26
26
|
import "./chunk-BZLMF5O5.js";
|
|
27
27
|
export {
|
|
28
28
|
PORTABLE_ARCHIVE_BATCH_BYTES,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { a as BridgeStore, I as InsertMessageResult, d as MessageQuery, M as MessagePage, c as DeliveryQuery, b as DeliveryPage, D as DeliveryEventPage } from './bridge-store-
|
|
1
|
+
import { a as BridgeStore, I as InsertMessageResult, d as MessageQuery, M as MessagePage, c as DeliveryQuery, b as DeliveryPage, D as DeliveryEventPage } from './bridge-store-Boaj-ZbO.js';
|
|
2
2
|
import { c as BridgePrincipal, M as MessageDraft, B as BridgeDelivery, A as AgentPresence } from './bridge-domain-CBX3IVqC.js';
|
|
3
3
|
|
|
4
4
|
type PublicMessageQuery = MessageQuery & {
|
package/dist/bridge.d.ts
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import { b as BridgeMessage, c as BridgePrincipal, B as BridgeDelivery, R as RetryPolicy, A as AgentPresence } from './bridge-domain-CBX3IVqC.js';
|
|
2
2
|
export { a as BridgeDeliveryEvent, d as BridgePrincipalMismatchError, e as BridgeValidationError, D as DeliveryAction, f as DeliveryPolicy, g as DeliveryState, h as DeliveryStateConflictError, J as JsonValue, L as LeasedDeliveryPolicy, M as MessageDraft, i as MessagePriority, j as cursorScope, k as decodeCursor, l as decodeScopedCursor, m as encodeCursor, n as encodeScopedCursor, s as scopedCursorScope, u as uuidv7, v as validateDeliveryCursorPosition, o as validateDeliveryPolicy, p as validateEventCursorPosition, q as validateLeasedDeliveryPolicy, r as validateMessageDraft, t as validatePrincipal, w as validateProject, x as validateUuid } from './bridge-domain-CBX3IVqC.js';
|
|
3
|
-
import { a as BridgeStore, I as InsertMessageResult, d as MessageQuery, M as MessagePage, C as ClaimOptions, B as BridgeDiagnostics, c as DeliveryQuery } from './bridge-store-
|
|
4
|
-
export { D as DeliveryEventPage, b as DeliveryPage } from './bridge-store-
|
|
5
|
-
export { B as BridgeService, P as PublicMessageQuery } from './bridge-service-
|
|
6
|
-
import { P as PgQueryable } from './postgres-bridge-store-
|
|
7
|
-
export { a as PgTransactionClient, b as PostgresBridgeStore } from './postgres-bridge-store-
|
|
8
|
-
export { A as AuthenticatedCredential, C as CredentialResolver, G as GatewayOptions, P as PostgresCredentialResolver, b as bearerToken, c as createGateway, h as hashCredential, s as safeTokenHashEqual } from './gateway-
|
|
9
|
-
export {
|
|
3
|
+
import { a as BridgeStore, I as InsertMessageResult, d as MessageQuery, M as MessagePage, C as ClaimOptions, B as BridgeDiagnostics, c as DeliveryQuery } from './bridge-store-Boaj-ZbO.js';
|
|
4
|
+
export { D as DeliveryEventPage, b as DeliveryPage } from './bridge-store-Boaj-ZbO.js';
|
|
5
|
+
export { B as BridgeService, P as PublicMessageQuery } from './bridge-service-YTjGr91A.js';
|
|
6
|
+
import { P as PgQueryable } from './postgres-bridge-store-WASumj26.js';
|
|
7
|
+
export { a as PgTransactionClient, b as PostgresBridgeStore } from './postgres-bridge-store-WASumj26.js';
|
|
8
|
+
export { A as AuthenticatedCredential, C as CredentialResolver, G as GatewayOptions, P as PostgresCredentialResolver, b as bearerToken, c as createGateway, h as hashCredential, s as safeTokenHashEqual } from './gateway-BQHpV-MZ.js';
|
|
9
|
+
export { E as EdgeConflictError, a as EdgeDrainLease, b as EdgeEnqueueResult, c as EdgeMigrationDrainingError, d as EdgeMigrationGate, e as EdgeMigrationGateState, f as EdgeMigrationLeaseError, g as EdgeMigrationRetiredError, h as EdgeOutboxRecord, i as EdgeReadOnlyInspection, j as EdgeScope, k as EdgeStats, P as PendingMessage, S as SQLiteEdgeStore, l as edgeMessageFingerprint, m as edgeScopeKey, n as inspectEdgeScopeReadOnly, s as stableIdempotency } from './sqlite-edge-store-Bc15DvpX.js';
|
|
10
|
+
export { CachedMessagePage, SQLiteBridgeStore, SyncDiagnostics, SyncInsertResult, SyncReport, SyncingBridgeStore, SyncingBridgeStoreOptions, isRetryableSyncError } from './sqlite.js';
|
|
10
11
|
import 'node:http';
|
|
11
12
|
|
|
12
13
|
declare class LegacySupabaseError extends Error {
|
|
@@ -149,6 +150,15 @@ declare const REQUIRED_MIGRATIONS: readonly [{
|
|
|
149
150
|
}, {
|
|
150
151
|
readonly version: 16;
|
|
151
152
|
readonly name: "native_dr_fence";
|
|
153
|
+
}, {
|
|
154
|
+
readonly version: 17;
|
|
155
|
+
readonly name: "gateway_authority_binding";
|
|
156
|
+
}, {
|
|
157
|
+
readonly version: 18;
|
|
158
|
+
readonly name: "endpoint_migration_challenges";
|
|
159
|
+
}, {
|
|
160
|
+
readonly version: 19;
|
|
161
|
+
readonly name: "endpoint_migration_same_successor";
|
|
152
162
|
}];
|
|
153
163
|
declare function loadMigrationPlan(directory: string): Promise<MigrationPlanEntry[]>;
|
|
154
164
|
declare function migrationsReady(db: PgQueryable, expected: ReadonlyArray<Pick<MigrationPlanEntry, "version" | "name" | "checksum">>): Promise<boolean>;
|
package/dist/bridge.js
CHANGED
|
@@ -4,20 +4,24 @@ import {
|
|
|
4
4
|
HttpBridgeStore,
|
|
5
5
|
LegacySupabaseError,
|
|
6
6
|
LegacySupabaseRestStore
|
|
7
|
-
} from "./chunk-
|
|
7
|
+
} from "./chunk-LAHNQZDN.js";
|
|
8
8
|
import {
|
|
9
9
|
EdgeConflictError,
|
|
10
|
+
EdgeMigrationDrainingError,
|
|
11
|
+
EdgeMigrationLeaseError,
|
|
12
|
+
EdgeMigrationRetiredError,
|
|
10
13
|
SQLiteEdgeStore,
|
|
11
14
|
SyncingBridgeStore,
|
|
12
15
|
edgeMessageFingerprint,
|
|
13
16
|
edgeScopeKey,
|
|
17
|
+
inspectEdgeScopeReadOnly,
|
|
14
18
|
isRetryableSyncError,
|
|
15
19
|
stableIdempotency
|
|
16
|
-
} from "./chunk-
|
|
20
|
+
} from "./chunk-SV3SVBYS.js";
|
|
17
21
|
import {
|
|
18
22
|
SQLiteBridgeStore
|
|
19
|
-
} from "./chunk-
|
|
20
|
-
import "./chunk-
|
|
23
|
+
} from "./chunk-DQOZJJZ2.js";
|
|
24
|
+
import "./chunk-GTK4KOED.js";
|
|
21
25
|
import {
|
|
22
26
|
PostgresBridgeStore
|
|
23
27
|
} from "./chunk-2DFNOLMO.js";
|
|
@@ -29,7 +33,7 @@ import {
|
|
|
29
33
|
rowIsolationReady,
|
|
30
34
|
runMigrations,
|
|
31
35
|
runtimeSchemaReady
|
|
32
|
-
} from "./chunk-
|
|
36
|
+
} from "./chunk-6BTJE6D4.js";
|
|
33
37
|
import "./chunk-VOQIDTCJ.js";
|
|
34
38
|
import {
|
|
35
39
|
PostgresCredentialResolver,
|
|
@@ -37,11 +41,11 @@ import {
|
|
|
37
41
|
createGateway,
|
|
38
42
|
hashCredential,
|
|
39
43
|
safeTokenHashEqual
|
|
40
|
-
} from "./chunk-
|
|
44
|
+
} from "./chunk-3YHVUPU2.js";
|
|
41
45
|
import {
|
|
42
46
|
BridgeService
|
|
43
47
|
} from "./chunk-4VB44KJU.js";
|
|
44
|
-
import "./chunk-
|
|
48
|
+
import "./chunk-IHZFI7TH.js";
|
|
45
49
|
import {
|
|
46
50
|
BridgePrincipalMismatchError,
|
|
47
51
|
BridgeValidationError,
|
|
@@ -69,6 +73,9 @@ export {
|
|
|
69
73
|
BridgeValidationError,
|
|
70
74
|
DeliveryStateConflictError,
|
|
71
75
|
EdgeConflictError,
|
|
76
|
+
EdgeMigrationDrainingError,
|
|
77
|
+
EdgeMigrationLeaseError,
|
|
78
|
+
EdgeMigrationRetiredError,
|
|
72
79
|
HttpBridgeStore,
|
|
73
80
|
LegacySupabaseError,
|
|
74
81
|
LegacySupabaseRestStore,
|
|
@@ -89,6 +96,7 @@ export {
|
|
|
89
96
|
encodeCursor,
|
|
90
97
|
encodeScopedCursor,
|
|
91
98
|
hashCredential,
|
|
99
|
+
inspectEdgeScopeReadOnly,
|
|
92
100
|
isRetryableSyncError,
|
|
93
101
|
loadMigrationPlan,
|
|
94
102
|
migrationsReady,
|
|
@@ -16,7 +16,7 @@ import {
|
|
|
16
16
|
parseResponse,
|
|
17
17
|
validateRequest,
|
|
18
18
|
validateRequestForProtocol
|
|
19
|
-
} from "./chunk-
|
|
19
|
+
} from "./chunk-IHZFI7TH.js";
|
|
20
20
|
import {
|
|
21
21
|
BridgePrincipalMismatchError,
|
|
22
22
|
BridgeValidationError
|
|
@@ -385,7 +385,16 @@ function createGateway(options) {
|
|
|
385
385
|
rowIsolation = false;
|
|
386
386
|
}
|
|
387
387
|
}
|
|
388
|
-
sendOperation(response, 200, "capabilities",
|
|
388
|
+
sendOperation(response, 200, "capabilities", {
|
|
389
|
+
...capabilityDocument({
|
|
390
|
+
surface: "http",
|
|
391
|
+
provider: "gateway",
|
|
392
|
+
selectedProtocolVersion: String(response.getHeader(PROTOCOL_HEADER)),
|
|
393
|
+
requestAuthority: Boolean(options.requestAuthority),
|
|
394
|
+
rowIsolation
|
|
395
|
+
}),
|
|
396
|
+
grantedScopes: [...credential.scopes]
|
|
397
|
+
}, requestId);
|
|
389
398
|
return;
|
|
390
399
|
}
|
|
391
400
|
if (req.method === "GET" && url.pathname === "/v2/status") {
|
|
@@ -393,13 +402,47 @@ function createGateway(options) {
|
|
|
393
402
|
closedQuery(url, "status", []);
|
|
394
403
|
validateRequest("status", {});
|
|
395
404
|
const activeStore = authority?.store ?? options.store;
|
|
405
|
+
const authorityBinding = authority && response.getHeader(PROTOCOL_HEADER) === PROTOCOL_VERSION ? {
|
|
406
|
+
gatewayAuthorityId: authority.gatewayAuthorityId,
|
|
407
|
+
credentialId: authority.credential.id
|
|
408
|
+
} : {};
|
|
396
409
|
if (!activeStore.diagnostics) {
|
|
397
|
-
sendOperation(response, 200, "status", { schemaVersion: "postgres-v2", deliverySupported: false, pending: null, claimed: null, retrying: null, dead: null, principal: credential.principal }, requestId);
|
|
410
|
+
sendOperation(response, 200, "status", { schemaVersion: "postgres-v2", deliverySupported: false, pending: null, claimed: null, retrying: null, dead: null, ...authorityBinding, principal: credential.principal }, requestId);
|
|
398
411
|
} else {
|
|
399
|
-
sendOperation(response, 200, "status", { ...await activeStore.diagnostics(principal), principal: credential.principal }, requestId);
|
|
412
|
+
sendOperation(response, 200, "status", { ...await activeStore.diagnostics(principal), ...authorityBinding, principal: credential.principal }, requestId);
|
|
400
413
|
}
|
|
401
414
|
return;
|
|
402
415
|
}
|
|
416
|
+
if (req.method === "POST" && url.pathname === "/v2/endpoint-migration-challenges") {
|
|
417
|
+
requireCurrentProtocol(response);
|
|
418
|
+
await authorize("issue_endpoint_migration_challenge");
|
|
419
|
+
const input = validateRequestForProtocol("issue_endpoint_migration_challenge", await requestBody(), selectedProtocol(response));
|
|
420
|
+
if (!authority?.endpointMigrationChallenges) throw Object.assign(new Error("endpoint migration challenges require request authority"), { status: 503, code: "security_unavailable" });
|
|
421
|
+
active(abort.signal);
|
|
422
|
+
await authority.beginDomainWork();
|
|
423
|
+
mutationStarted = true;
|
|
424
|
+
sendOperation(response, 200, "issue_endpoint_migration_challenge", await authority.endpointMigrationChallenges.issue({
|
|
425
|
+
challenge: String(input.challenge),
|
|
426
|
+
expectedGatewayAuthorityId: String(input.expectedGatewayAuthorityId),
|
|
427
|
+
verifierCredentialId: String(input.verifierCredentialId)
|
|
428
|
+
}), requestId);
|
|
429
|
+
return;
|
|
430
|
+
}
|
|
431
|
+
if (req.method === "POST" && url.pathname === "/v2/endpoint-migration-challenges/consume") {
|
|
432
|
+
requireCurrentProtocol(response);
|
|
433
|
+
await authorize("consume_endpoint_migration_challenge");
|
|
434
|
+
const input = validateRequestForProtocol("consume_endpoint_migration_challenge", await requestBody(), selectedProtocol(response));
|
|
435
|
+
if (!authority?.endpointMigrationChallenges) throw Object.assign(new Error("endpoint migration challenges require request authority"), { status: 503, code: "security_unavailable" });
|
|
436
|
+
active(abort.signal);
|
|
437
|
+
await authority.beginDomainWork();
|
|
438
|
+
mutationStarted = true;
|
|
439
|
+
sendOperation(response, 200, "consume_endpoint_migration_challenge", await authority.endpointMigrationChallenges.consume({
|
|
440
|
+
challenge: String(input.challenge),
|
|
441
|
+
expectedGatewayAuthorityId: String(input.expectedGatewayAuthorityId),
|
|
442
|
+
issuerCredentialId: String(input.issuerCredentialId)
|
|
443
|
+
}), requestId);
|
|
444
|
+
return;
|
|
445
|
+
}
|
|
403
446
|
if (req.method === "POST" && url.pathname === "/v2/messages") {
|
|
404
447
|
await authorize("publish_message");
|
|
405
448
|
const input = validateRequestForProtocol("publish_message", await requestBody(), String(response.getHeader(PROTOCOL_HEADER)));
|
|
@@ -551,4 +594,4 @@ export {
|
|
|
551
594
|
safeTokenHashEqual,
|
|
552
595
|
createGateway
|
|
553
596
|
};
|
|
554
|
-
//# sourceMappingURL=chunk-
|
|
597
|
+
//# sourceMappingURL=chunk-3YHVUPU2.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/gateway.ts","../src/gateway-auth.ts"],"sourcesContent":["import { randomUUID } from \"node:crypto\";\nimport { createServer, type IncomingMessage, type ServerResponse } from \"node:http\";\nimport { BridgePrincipalMismatchError, BridgeValidationError, type MessageDraft } from \"./bridge-domain.js\";\nimport { BridgeService } from \"./bridge-service.js\";\nimport type { BridgeStore } from \"./bridge-store.js\";\nimport { bearerToken, hashCredential, type CredentialResolver } from \"./gateway-auth.js\";\nimport type { GatewaySecurity } from \"./gateway-security.js\";\nimport type { RequestAuthority, RequestAuthorityContext } from \"./postgres-request-authority.js\";\nimport {\n capabilityDocument,\n ContractResponseError,\n ContractValidationError,\n LEGACY_PROTOCOL_VERSION,\n negotiateProtocolVersion,\n operationContract,\n parseResponse,\n PROTOCOL_HEADER,\n PROTOCOL_VERSION,\n SUPPORTED_PROTOCOL_HEADER,\n SUPPORTED_PROTOCOL_VERSIONS,\n type OperationId,\n validateRequest,\n validateRequestForProtocol,\n} from \"./contracts/registry.js\";\n\nexport interface GatewayOptions {\n store: BridgeStore;\n credentials: CredentialResolver;\n security: GatewaySecurity;\n allowedOrigins?: string[];\n bodyLimitBytes?: number;\n requestDeadlineMs?: number;\n ready?: () => Promise<boolean>;\n /** Reports whether the configured database has verified row isolation. */\n rowIsolationReady?: () => Promise<boolean>;\n /** Production PostgreSQL request authority. Other providers omit this. */\n requestAuthority?: RequestAuthority;\n}\n\ntype Metrics = { requests: number; errors: number; timeouts: number; authFailures: number };\nconst jsonHeaders = { \"content-type\": \"application/json; charset=utf-8\", \"cache-control\": \"no-store\" };\n\ninterface ResponseWriter {\n readonly writableEnded: boolean;\n getHeader(name: string): string | number | readonly string[] | undefined;\n setHeader(name: string, value: string | number | readonly string[]): unknown;\n writeHead(status: number, headers?: any): unknown;\n end(chunk?: any): unknown;\n}\n\nclass BufferedResponse implements ResponseWriter {\n private readonly headers = new Map<string, string | number | readonly string[]>();\n private status: number | undefined;\n private headHeaders: any;\n private body: any;\n\n constructor(private readonly target: ServerResponse) {}\n get writableEnded(): boolean { return this.body !== undefined; }\n getHeader(name: string) { return this.headers.get(name.toLowerCase()) ?? this.target.getHeader(name); }\n setHeader(name: string, value: string | number | readonly string[]) { this.headers.set(name.toLowerCase(), value); return this; }\n writeHead(status: number, headers?: any) {\n this.status = status;\n this.headHeaders = headers;\n return this;\n }\n end(chunk?: any) { this.body = chunk ?? null; return this; }\n flush(): void {\n if (this.target.writableEnded) return;\n for (const [name, value] of this.headers) this.target.setHeader(name, value);\n if (this.status !== undefined) this.target.writeHead(this.status, this.headHeaders);\n if (this.body !== undefined) this.target.end(this.body);\n }\n}\n\nfunction send(res: ResponseWriter, status: number, value: unknown, requestId: string): void {\n if (res.writableEnded) return;\n res.writeHead(status, {\n ...jsonHeaders,\n \"x-request-id\": requestId,\n });\n res.end(JSON.stringify(value));\n}\n\nfunction sendOperation(res: ResponseWriter, status: number, operation: string, value: unknown, requestId: string): void {\n const canonical = parseResponse(operation, value) as Record<string, unknown>;\n const protocolVersion = String(res.getHeader(PROTOCOL_HEADER) ?? PROTOCOL_VERSION);\n if (protocolVersion !== LEGACY_PROTOCOL_VERSION) {\n send(res, status, canonical, requestId);\n return;\n }\n if (operation === \"claim_delivery\") {\n send(res, status, canonical.delivery === null ? null : canonical, requestId);\n return;\n }\n if ([\"cancel_delivery\", \"requeue_delivery\", \"extend_delivery\", \"acknowledge_delivery\", \"negative_acknowledge_delivery\"].includes(operation)) {\n send(res, status, canonical.delivery, requestId);\n return;\n }\n send(res, status, canonical, requestId);\n}\n\nfunction failure(\n res: ResponseWriter,\n status: number,\n code: string,\n requestId: string,\n details: Record<string, unknown> = {},\n): void {\n send(res, status, { error: { code, requestId, ...details } }, requestId);\n}\n\nasync function body(\n req: IncomingMessage,\n limit: number,\n signal: AbortSignal,\n): Promise<Record<string, any>> {\n return new Promise((resolve, reject) => {\n const chunks: Buffer[] = [];\n let size = 0;\n const cleanup = () => {\n req.off(\"data\", onData);\n req.off(\"end\", onEnd);\n req.off(\"error\", onError);\n signal.removeEventListener(\"abort\", onAbort);\n };\n const finish = (callback: () => void) => {\n cleanup();\n callback();\n };\n const onData = (chunk: Buffer | string) => {\n const buffer = Buffer.from(chunk);\n size += buffer.length;\n if (size > limit) {\n finish(() => reject(Object.assign(new Error(\"body too large\"), {\n status: 413,\n code: \"body_too_large\",\n })));\n req.resume();\n return;\n }\n chunks.push(buffer);\n };\n const onEnd = () => finish(() => {\n if (!size) {\n resolve({});\n return;\n }\n try {\n const parsed = JSON.parse(Buffer.concat(chunks).toString(\"utf8\"));\n if (!parsed || Array.isArray(parsed) || typeof parsed !== \"object\") throw new Error();\n resolve(parsed);\n } catch {\n reject(Object.assign(new Error(\"invalid JSON\"), { status: 400, code: \"malformed_json\" }));\n }\n });\n const onError = (error: Error) => finish(() => reject(error));\n const onAbort = () => {\n finish(() => reject(signal.reason));\n req.resume();\n };\n req.on(\"data\", onData);\n req.on(\"end\", onEnd);\n req.on(\"error\", onError);\n signal.addEventListener(\"abort\", onAbort, { once: true });\n if (signal.aborted) onAbort();\n });\n}\n\nasync function jsonBody(\n req: IncomingMessage,\n limit: number,\n signal: AbortSignal,\n): Promise<Record<string, any>> {\n if (hasRequestBody(req) && req.headers[\"content-type\"]?.split(\";\", 1)[0] !== \"application/json\") {\n throw Object.assign(new Error(\"unsupported media type\"), {\n status: 415,\n code: \"unsupported_media_type\",\n });\n }\n return body(req, limit, signal);\n}\n\nfunction numberParam(value: string | null, name: string): number | undefined {\n if (value === null) return undefined;\n const result = Number(value);\n if (!Number.isSafeInteger(result)) throw new BridgeValidationError(`${name} is invalid`);\n return result;\n}\n\nfunction booleanParam(value: string | null, name: string): boolean | undefined {\n if (value === null) return undefined;\n if (value === \"true\") return true;\n if (value === \"false\") return false;\n throw new BridgeValidationError(`${name} must be true or false`);\n}\n\nfunction hasRequestBody(req: IncomingMessage): boolean {\n const length = req.headers[\"content-length\"];\n return req.headers[\"transfer-encoding\"] !== undefined || (length !== undefined && length !== \"0\");\n}\n\nfunction pathBoundInput(\n operation: string,\n deliveryId: string,\n rawInput: Record<string, unknown>,\n protocolVersion?: string,\n): Record<string, unknown> {\n if (Object.prototype.hasOwnProperty.call(rawInput, \"deliveryId\")) {\n throw new ContractValidationError(operation, [{ path: \"/deliveryId\", message: \"deliveryId is supplied by the request path\" }]);\n }\n const value = { ...rawInput, deliveryId };\n return protocolVersion\n ? validateRequestForProtocol(operation, value, protocolVersion)\n : validateRequest(operation, value);\n}\n\nfunction active(signal: AbortSignal): void {\n if (signal.aborted) throw signal.reason;\n}\n\nfunction closedQuery(url: URL, operation: string, allowed: readonly string[]): void {\n const unknown = [...url.searchParams.keys()].find((key) => !allowed.includes(key));\n if (unknown) throw new ContractValidationError(operation, [{ path: `/${unknown}`, message: \"Unexpected query parameter\" }]);\n}\n\nfunction selectedProtocol(res: ResponseWriter): string {\n return String(res.getHeader(PROTOCOL_HEADER) ?? PROTOCOL_VERSION);\n}\n\nfunction requireCurrentProtocol(res: ResponseWriter): void {\n if (selectedProtocol(res) === LEGACY_PROTOCOL_VERSION) {\n const error = new Error(\"Operation is not available in protocol 2.0\") as Error & { status: number; code: string };\n error.status = 404;\n error.code = \"not_found\";\n throw error;\n }\n}\n\nexport function createGateway(options: GatewayOptions) {\n const metrics: Metrics = { requests: 0, errors: 0, timeouts: 0, authFailures: 0 };\n const limit = options.bodyLimitBytes ?? 128 * 1024;\n const deadline = options.requestDeadlineMs ?? 10_000;\n const origins = new Set(options.allowedOrigins ?? []);\n\n return createServer((req, res) => {\n const requestId = randomUUID();\n const abort = new AbortController();\n let mutationStarted = false;\n metrics.requests += 1;\n const requestedProtocol = req.headers[PROTOCOL_HEADER];\n const rawRequestedProtocol = Array.isArray(requestedProtocol) ? requestedProtocol[0] : requestedProtocol;\n const initialProtocol = rawRequestedProtocol === undefined || rawRequestedProtocol.trim() === \"\"\n ? LEGACY_PROTOCOL_VERSION\n : (SUPPORTED_PROTOCOL_VERSIONS as readonly string[]).includes(rawRequestedProtocol.trim())\n ? rawRequestedProtocol.trim()\n : PROTOCOL_VERSION;\n res.setHeader(PROTOCOL_HEADER, initialProtocol);\n res.setHeader(SUPPORTED_PROTOCOL_HEADER, SUPPORTED_PROTOCOL_VERSIONS.join(\",\"));\n const timer = setTimeout(() => {\n abort.abort(new Error(\"request deadline exceeded\"));\n metrics.timeouts += 1; metrics.errors += 1;\n res.once(\"finish\", () => {\n if (!req.complete) req.destroy();\n });\n failure(\n res,\n 504,\n mutationStarted ? \"mutation_outcome_unknown\" : \"request_timeout\",\n requestId,\n );\n }, deadline);\n let parsedBody: Promise<Record<string, any>> | undefined;\n const requestBody = () => parsedBody ??= jsonBody(req, limit, abort.signal);\n\n const dispatch = async (authority?: RequestAuthorityContext, response: ResponseWriter = res): Promise<void> => {\n const url = new URL(req.url ?? \"/\", \"http://gateway.invalid\");\n if (req.method === \"GET\" && url.pathname === \"/readyz\") {\n let ready = false;\n try {\n ready = await (options.ready?.() ?? options.store.initialize().then(() => true));\n } catch {\n ready = false;\n }\n send(response, ready ? 200 : 503, { status: ready ? \"ready\" : \"not_ready\" }, requestId);\n return;\n }\n const origin = req.headers.origin;\n if (origin && !origins.has(origin)) {\n failure(response, 403, \"origin_forbidden\", requestId); return;\n }\n const token = bearerToken(req.headers.authorization);\n if (options.requestAuthority && !authority) {\n if (!token) {\n metrics.authFailures += 1;\n failure(response, 401, \"unauthorized\", requestId); return;\n }\n const preflight = await options.credentials.resolve(token, abort.signal);\n active(abort.signal);\n if (!preflight) {\n metrics.authFailures += 1;\n failure(response, 401, \"unauthorized\", requestId); return;\n }\n if (hasRequestBody(req)) await requestBody();\n active(abort.signal);\n const buffered = new BufferedResponse(res);\n await options.requestAuthority!.run(\n preflight.id,\n hashCredential(token),\n requestId,\n abort.signal,\n (context) => dispatch(context, buffered),\n );\n active(abort.signal);\n buffered.flush();\n return;\n }\n const credential = authority?.credential ?? (token ? await options.credentials.resolve(token, abort.signal) : null);\n active(abort.signal);\n if (!credential) {\n metrics.authFailures += 1;\n failure(response, 401, \"unauthorized\", requestId); return;\n }\n if (!Array.isArray(credential.scopes)) {\n failure(response, 503, \"security_unavailable\", requestId); return;\n }\n const service = new BridgeService(authority?.store ?? options.store);\n const security = authority?.security ?? options.security;\n if (url.pathname.startsWith(\"/v2/\") || url.pathname === \"/metrics\") {\n response.setHeader(PROTOCOL_HEADER, negotiateProtocolVersion(req.headers[PROTOCOL_HEADER]));\n }\n const authorize = async (operationId: OperationId): Promise<void> => {\n const requiredScopes = operationContract(operationId).scopes;\n if (requiredScopes.some((scope) => !credential.scopes.includes(scope))) {\n try {\n await security.recordScopeDenial(credential.id, operationId, requestId, abort.signal);\n } catch {\n throw Object.assign(new Error(\"Scope denial could not be audited\"), {\n status: 503,\n code: \"security_unavailable\",\n });\n }\n throw Object.assign(new Error(\"Credential lacks a required scope\"), {\n status: 403, code: \"insufficient_scope\", requiredScopes,\n });\n }\n let decision;\n try {\n decision = await security.consume(credential.id, operationId, requestId, abort.signal);\n } catch {\n throw Object.assign(new Error(\"Rate limit state is unavailable\"), {\n status: 503,\n code: \"security_unavailable\",\n });\n }\n if (!decision.allowed) {\n const retryAfter = Math.max(1, Math.ceil(decision.retryAfterSeconds));\n response.setHeader(\"retry-after\", String(retryAfter));\n throw Object.assign(new Error(\"Credential rate limit exceeded\"), {\n status: 429, code: \"rate_limited\", retryAfterSeconds: retryAfter,\n });\n }\n };\n if (req.method === \"GET\" && url.pathname === \"/metrics\") {\n await authorize(\"gateway_metrics\");\n validateRequest(\"gateway_metrics\", {});\n const result = Object.entries(metrics).map(([key, value]) => `agent_bridge_gateway_${key}_total ${value}`).join(\"\\n\") + \"\\n\";\n parseResponse(\"gateway_metrics\", result);\n response.writeHead(200, {\n ...jsonHeaders,\n \"content-type\": \"text/plain; version=0.0.4\",\n \"x-request-id\": requestId,\n });\n response.end(result);\n return;\n }\n const instanceHeader = req.headers[\"x-agent-bridge-instance\"];\n const principal = {\n ...credential.principal,\n instance: Array.isArray(instanceHeader) ? instanceHeader[0] : instanceHeader,\n };\n\n if (req.method === \"GET\" && url.pathname === \"/v2/capabilities\") {\n requireCurrentProtocol(response);\n await authorize(\"capabilities\");\n closedQuery(url, \"capabilities\", []);\n validateRequest(\"capabilities\", {});\n let rowIsolation = false;\n if (options.requestAuthority && options.rowIsolationReady) {\n try {\n rowIsolation = await options.rowIsolationReady();\n } catch {\n rowIsolation = false;\n }\n }\n sendOperation(response, 200, \"capabilities\", {\n ...capabilityDocument({\n surface: \"http\",\n provider: \"gateway\",\n selectedProtocolVersion: String(response.getHeader(PROTOCOL_HEADER)),\n requestAuthority: Boolean(options.requestAuthority),\n rowIsolation,\n }),\n grantedScopes: [...credential.scopes],\n }, requestId); return;\n }\n\n if (req.method === \"GET\" && url.pathname === \"/v2/status\") {\n await authorize(\"status\");\n closedQuery(url, \"status\", []);\n validateRequest(\"status\", {});\n const activeStore = authority?.store ?? options.store;\n const authorityBinding = authority && response.getHeader(PROTOCOL_HEADER) === PROTOCOL_VERSION ? {\n gatewayAuthorityId: authority.gatewayAuthorityId,\n credentialId: authority.credential.id,\n } : {};\n if (!activeStore.diagnostics) {\n sendOperation(response, 200, \"status\", { schemaVersion: \"postgres-v2\", deliverySupported: false, pending: null, claimed: null, retrying: null, dead: null, ...authorityBinding, principal: credential.principal }, requestId);\n } else {\n sendOperation(response, 200, \"status\", { ...await activeStore.diagnostics(principal), ...authorityBinding, principal: credential.principal }, requestId);\n }\n return;\n }\n\n if (req.method === \"POST\" && url.pathname === \"/v2/endpoint-migration-challenges\") {\n requireCurrentProtocol(response);\n await authorize(\"issue_endpoint_migration_challenge\");\n const input = validateRequestForProtocol(\"issue_endpoint_migration_challenge\", await requestBody(), selectedProtocol(response));\n if (!authority?.endpointMigrationChallenges) throw Object.assign(new Error(\"endpoint migration challenges require request authority\"), { status: 503, code: \"security_unavailable\" });\n active(abort.signal);\n await authority.beginDomainWork(); mutationStarted = true;\n sendOperation(response, 200, \"issue_endpoint_migration_challenge\", await authority.endpointMigrationChallenges.issue({\n challenge: String(input.challenge),\n expectedGatewayAuthorityId: String(input.expectedGatewayAuthorityId),\n verifierCredentialId: String(input.verifierCredentialId),\n }), requestId); return;\n }\n\n if (req.method === \"POST\" && url.pathname === \"/v2/endpoint-migration-challenges/consume\") {\n requireCurrentProtocol(response);\n await authorize(\"consume_endpoint_migration_challenge\");\n const input = validateRequestForProtocol(\"consume_endpoint_migration_challenge\", await requestBody(), selectedProtocol(response));\n if (!authority?.endpointMigrationChallenges) throw Object.assign(new Error(\"endpoint migration challenges require request authority\"), { status: 503, code: \"security_unavailable\" });\n active(abort.signal);\n await authority.beginDomainWork(); mutationStarted = true;\n sendOperation(response, 200, \"consume_endpoint_migration_challenge\", await authority.endpointMigrationChallenges.consume({\n challenge: String(input.challenge),\n expectedGatewayAuthorityId: String(input.expectedGatewayAuthorityId),\n issuerCredentialId: String(input.issuerCredentialId),\n }), requestId); return;\n }\n\n if (req.method === \"POST\" && url.pathname === \"/v2/messages\") {\n await authorize(\"publish_message\");\n const input = validateRequestForProtocol(\"publish_message\", await requestBody(), String(response.getHeader(PROTOCOL_HEADER)));\n if (input.source !== undefined && input.source !== principal.agent) {\n throw new BridgePrincipalMismatchError(\"source must match the authenticated principal\");\n }\n const { source: _source, ...draft } = input;\n active(abort.signal);\n await authority?.beginDomainWork(); mutationStarted = true;\n sendOperation(response, 201, \"publish_message\", await service.publish(principal, draft as unknown as MessageDraft), requestId); return;\n }\n if (req.method === \"GET\" && url.pathname === \"/v2/history\") {\n await authorize(\"history\");\n closedQuery(url, \"history\", [\"cursor\", \"mailbox\", \"receiptState\", \"limit\", \"type\", \"includeExpired\", \"source\", \"project\", \"since\", \"unacknowledgedBy\", \"unacked_by\", \"threadId\", \"latest\"]);\n const types = url.searchParams.getAll(\"type\");\n const input = validateRequestForProtocol(\"history\", {\n cursor: url.searchParams.get(\"cursor\") ?? undefined,\n mailbox: url.searchParams.get(\"mailbox\") ?? undefined as any,\n receiptState: url.searchParams.get(\"receiptState\") ?? undefined as any,\n limit: numberParam(url.searchParams.get(\"limit\"), \"limit\"),\n types: types.length ? types : undefined,\n includeExpired: booleanParam(url.searchParams.get(\"includeExpired\"), \"includeExpired\"),\n source: url.searchParams.get(\"source\") ?? undefined,\n project: url.searchParams.get(\"project\") ?? undefined,\n since: url.searchParams.get(\"since\") ?? undefined,\n unacknowledgedBy: url.searchParams.get(\"unacknowledgedBy\") ?? url.searchParams.get(\"unacked_by\") ?? undefined,\n threadId: url.searchParams.get(\"threadId\") ?? undefined,\n latest: booleanParam(url.searchParams.get(\"latest\"), \"latest\"),\n }, String(response.getHeader(PROTOCOL_HEADER)));\n sendOperation(response, 200, \"history\", await service.history(principal, input), requestId); return;\n }\n if (req.method === \"POST\" && url.pathname === \"/v2/receipts\") {\n await authorize(\"record_receipt\");\n const input = validateRequest(\"record_receipt\", await requestBody());\n active(abort.signal);\n await authority?.beginDomainWork(); mutationStarted = true;\n sendOperation(response, 200, \"record_receipt\", { recorded: await service.acknowledge(principal, input.messageIds as string[]) }, requestId); return;\n }\n if (req.method === \"POST\" && url.pathname === \"/v2/deliveries/claim\") {\n await authorize(\"claim_delivery\");\n const input = validateRequest(\"claim_delivery\", await requestBody());\n active(abort.signal);\n await authority?.beginDomainWork(); mutationStarted = true;\n sendOperation(response, 200, \"claim_delivery\", await service.claim(principal, input) ?? { delivery: null }, requestId); return;\n }\n if (req.method === \"GET\" && url.pathname === \"/v2/deliveries\") {\n requireCurrentProtocol(response);\n await authorize(\"list_deliveries\");\n closedQuery(url, \"list_deliveries\", [\"cursor\", \"limit\", \"role\", \"messageId\", \"recipient\", \"state\"]);\n const input = validateRequest(\"list_deliveries\", {cursor:url.searchParams.get(\"cursor\")??undefined,limit:numberParam(url.searchParams.get(\"limit\"),\"limit\"),role:url.searchParams.get(\"role\")??undefined,messageId:url.searchParams.get(\"messageId\")??undefined,recipient:url.searchParams.get(\"recipient\")??undefined,states:url.searchParams.getAll(\"state\")});\n sendOperation(response,200,\"list_deliveries\",await service.deliveries(principal,input as any),requestId);return;\n }\n const eventsMatch=url.pathname.match(/^\\/v2\\/deliveries\\/([^/]+)\\/events$/);\n if(req.method===\"GET\"&&eventsMatch){requireCurrentProtocol(response);await authorize(\"list_delivery_events\");closedQuery(url,\"list_delivery_events\",[\"cursor\",\"limit\"]);const input=validateRequest(\"list_delivery_events\",{deliveryId:eventsMatch[1],cursor:url.searchParams.get(\"cursor\")??undefined,limit:numberParam(url.searchParams.get(\"limit\"),\"limit\")});sendOperation(response,200,\"list_delivery_events\",await service.deliveryEvents(principal,eventsMatch[1]!,input as any),requestId);return;}\n const controlMatch=url.pathname.match(/^\\/v2\\/deliveries\\/([^/]+)\\/(cancel|requeue)$/);\n if(req.method===\"POST\"&&controlMatch){requireCurrentProtocol(response);const operation=controlMatch[2]===\"cancel\"?\"cancel_delivery\":\"requeue_delivery\";await authorize(operation);pathBoundInput(operation,controlMatch[1]!,await requestBody());await authority?.beginDomainWork();mutationStarted=true;const result=controlMatch[2]===\"cancel\"?await service.cancel(principal,controlMatch[1]!):await service.requeue(principal,controlMatch[1]!);if(!result)failure(response,404,\"not_found\",requestId);else sendOperation(response,200,operation,{delivery:result},requestId);return;}\n if (req.method === \"POST\" && url.pathname === \"/v2/presence/heartbeat\") {\n await authorize(\"heartbeat\");\n const input = validateRequest(\"heartbeat\", await requestBody());\n active(abort.signal);\n await authority?.beginDomainWork(); mutationStarted = true;\n sendOperation(response, 200, \"heartbeat\", await service.heartbeat(principal, input), requestId); return;\n }\n if (req.method === \"GET\" && url.pathname === \"/v2/presence\") {\n await authorize(\"presence\");\n closedQuery(url, \"presence\", []);\n validateRequest(\"presence\", {});\n sendOperation(response, 200, \"presence\", { agents: await service.presence(principal) }, requestId); return;\n }\n const match = url.pathname.match(/^\\/v2\\/deliveries\\/([^/]+)\\/(extend|ack|nack)$/);\n if (req.method === \"POST\" && match) {\n const operationId = match[2] === \"extend\" ? \"extend_delivery\" : match[2] === \"ack\" ? \"acknowledge_delivery\" : \"negative_acknowledge_delivery\";\n await authorize(operationId);\n const rawInput = await requestBody();\n const protocolVersion = String(response.getHeader(PROTOCOL_HEADER) ?? PROTOCOL_VERSION);\n const input = pathBoundInput(operationId, match[1]!, rawInput, protocolVersion);\n active(abort.signal);\n await authority?.beginDomainWork(); mutationStarted = true;\n const [, id, action] = match;\n const result = action === \"extend\"\n ? await service.extend(principal, id, input.leaseToken as string, input.leaseMs as number)\n : action === \"ack\"\n ? await service.ack(principal, id, input.leaseToken as string)\n : await service.nack(\n principal,\n id,\n input.leaseToken as string,\n (input.error as string | undefined) ?? \"negative acknowledgment\",\n (input.disposition ?? input.dead ?? \"retry\") as \"retry\" | \"dead\" | boolean,\n input.retryPolicy,\n );\n if (!result) failure(response, 409, \"lease_conflict\", requestId);\n else sendOperation(response, 200, operationId, { delivery: result }, requestId);\n return;\n }\n failure(response, 404, \"not_found\", requestId);\n };\n void dispatch().catch((error: any) => {\n if (res.writableEnded) return;\n metrics.errors += 1;\n if (error instanceof ContractValidationError || error instanceof ContractResponseError) {\n failure(res, error.status, error.code, requestId, { operation: error.operation, issues: error.issues });\n } else if (error?.status === 426) {\n failure(res, 426, error.code, requestId, { supportedProtocolVersions: [...SUPPORTED_PROTOCOL_VERSIONS] });\n } else if (error?.code === \"insufficient_scope\") {\n failure(res, 403, error.code, requestId, { details: { requiredScopes: [...error.requiredScopes] } });\n } else if (error?.code === \"rate_limited\") {\n res.setHeader(\"retry-after\", String(error.retryAfterSeconds));\n failure(res, 429, error.code, requestId, { details: { retryAfterSeconds: error.retryAfterSeconds } });\n } else if (error instanceof BridgeValidationError || error instanceof BridgePrincipalMismatchError) {\n failure(res, \"status\" in error ? error.status : 400, error.code, requestId, { message: error.message });\n } else {\n failure(res, error?.status ?? 500, error?.code ?? \"internal_error\", requestId);\n }\n }).finally(() => clearTimeout(timer));\n });\n}\n","import { createHash, timingSafeEqual } from \"node:crypto\";\nimport type { BridgePrincipal } from \"./bridge-domain.js\";\nimport type { AuthorizationScope } from \"./contracts/registry.js\";\nimport type { PgQueryable } from \"./postgres-bridge-store.js\";\n\nexport interface AuthenticatedCredential {\n id: string;\n principal: BridgePrincipal;\n /** Canonical authorization scopes granted to this credential. */\n scopes: readonly AuthorizationScope[];\n}\n\nexport interface CredentialResolver {\n resolve(token: string, signal?: AbortSignal): Promise<AuthenticatedCredential | null>;\n}\n\nexport function hashCredential(token: string): string {\n return createHash(\"sha256\").update(token, \"utf8\").digest(\"hex\");\n}\n\nexport class PostgresCredentialResolver implements CredentialResolver {\n constructor(private readonly db: PgQueryable) {}\n\n async resolve(token: string, signal?: AbortSignal): Promise<AuthenticatedCredential | null> {\n if (signal?.aborted) throw signal.reason;\n const result = await this.db.query<{\n credential_id: string; workspace_id: string; principal: string; scopes: AuthorizationScope[];\n }>(\n `SELECT credential_id,workspace_id,principal,scopes\n FROM agent_bridge.resolve_credential_hash($1::text)`,\n [hashCredential(token)],\n );\n const row = result.rows[0];\n if (signal?.aborted) throw signal.reason;\n return row ? {\n id: row.credential_id,\n principal: { workspace: row.workspace_id, agent: row.principal },\n scopes: row.scopes,\n } : null;\n }\n}\n\nexport function bearerToken(value: string | undefined): string | null {\n if (!value?.startsWith(\"Bearer \")) return null;\n const token = value.slice(7);\n if (!token || token.length > 4096 || /\\s/.test(token)) return null;\n return token;\n}\n\nexport function safeTokenHashEqual(token: string, expectedHash: string): boolean {\n const actual = Buffer.from(hashCredential(token));\n const expected = Buffer.from(expectedHash);\n return actual.length === expected.length && timingSafeEqual(actual, expected);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAAA,S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