@astrasyncai/verification-gateway 4.5.0 → 4.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (75) hide show
  1. package/dist/adapters/express.js +1 -1
  2. package/dist/adapters/express.js.map +1 -1
  3. package/dist/adapters/express.mjs +1 -1
  4. package/dist/adapters/express.mjs.map +1 -1
  5. package/dist/adapters/mcp.d.mts +3 -394
  6. package/dist/adapters/mcp.d.ts +3 -394
  7. package/dist/adapters/mcp.js +1 -1
  8. package/dist/adapters/mcp.js.map +1 -1
  9. package/dist/adapters/mcp.mjs +1 -1
  10. package/dist/adapters/mcp.mjs.map +1 -1
  11. package/dist/adapters/nextjs.js +1 -1
  12. package/dist/adapters/nextjs.js.map +1 -1
  13. package/dist/adapters/nextjs.mjs +1 -1
  14. package/dist/adapters/nextjs.mjs.map +1 -1
  15. package/dist/adapters/sdk.js +1 -1
  16. package/dist/adapters/sdk.js.map +1 -1
  17. package/dist/adapters/sdk.mjs +1 -1
  18. package/dist/adapters/sdk.mjs.map +1 -1
  19. package/dist/agent/index.js +1 -1
  20. package/dist/agent/index.js.map +1 -1
  21. package/dist/agent/index.mjs +1 -1
  22. package/dist/agent/index.mjs.map +1 -1
  23. package/dist/bin/astrasync-claude-hook.js +1 -1
  24. package/dist/bin/astrasync-codex-hook.js +1 -1
  25. package/dist/bin/astrasync-guard.js +1 -1
  26. package/dist/bin/astrasync.js +2 -1
  27. package/dist/browser/background.js +1 -1
  28. package/dist/browser/background.js.map +1 -1
  29. package/dist/browser/background.mjs +1 -1
  30. package/dist/browser/background.mjs.map +1 -1
  31. package/dist/cli/index.js +1 -1
  32. package/dist/cli/index.js.map +1 -1
  33. package/dist/cli/index.mjs +1 -1
  34. package/dist/cli/index.mjs.map +1 -1
  35. package/dist/codex/index.js +1 -1
  36. package/dist/codex/index.js.map +1 -1
  37. package/dist/codex/index.mjs +1 -1
  38. package/dist/codex/index.mjs.map +1 -1
  39. package/dist/cursor/extension.js +1 -1
  40. package/dist/cursor/extension.js.map +1 -1
  41. package/dist/cursor/extension.mjs +1 -1
  42. package/dist/cursor/extension.mjs.map +1 -1
  43. package/dist/edge-config.js +1 -1
  44. package/dist/edge-config.js.map +1 -1
  45. package/dist/edge-config.mjs +1 -1
  46. package/dist/edge-config.mjs.map +1 -1
  47. package/dist/edge-core/index.js +1 -1
  48. package/dist/edge-core/index.js.map +1 -1
  49. package/dist/edge-core/index.mjs +1 -1
  50. package/dist/edge-core/index.mjs.map +1 -1
  51. package/dist/gateway/gateway.js +1 -1
  52. package/dist/gateway/gateway.js.map +1 -1
  53. package/dist/gateway/gateway.mjs +1 -1
  54. package/dist/gateway/gateway.mjs.map +1 -1
  55. package/dist/index.d.mts +3 -3
  56. package/dist/index.d.ts +3 -3
  57. package/dist/index.js +12 -1
  58. package/dist/index.js.map +1 -1
  59. package/dist/index.mjs +7 -1
  60. package/dist/index.mjs.map +1 -1
  61. package/dist/mcp--DgKOwfu.d.ts +396 -0
  62. package/dist/mcp-BgBJu4Jl.d.mts +396 -0
  63. package/dist/registration/index.js +2 -1
  64. package/dist/registration/index.js.map +1 -1
  65. package/dist/registration/index.mjs +2 -1
  66. package/dist/registration/index.mjs.map +1 -1
  67. package/dist/transport/index.js +1 -1
  68. package/dist/transport/index.js.map +1 -1
  69. package/dist/transport/index.mjs +1 -1
  70. package/dist/transport/index.mjs.map +1 -1
  71. package/dist/verify.js +1 -1
  72. package/dist/verify.js.map +1 -1
  73. package/dist/verify.mjs +1 -1
  74. package/dist/verify.mjs.map +1 -1
  75. package/package.json +1 -1
@@ -0,0 +1,396 @@
1
+ import { Request, Response, RequestHandler } from 'express';
2
+ import { a as AccessLevel, G as GatewayConfig, x as VerificationResult } from './types-C0zfSXMB.mjs';
3
+
4
+ /**
5
+ * X-Astra-Verified-Hop — cross-hop verify-access dedupe marker.
6
+ *
7
+ * Header carrying upstream verify-access proof so an inner-hop endpoint can
8
+ * dedupe (skip verify-access when the same ASTRA-id was already verified a
9
+ * few ms earlier). Emitted by the MCP adapter toward tool fetches and by the
10
+ * edge gateway toward the origin at authenticate/authorize depth. Value
11
+ * format:
12
+ *
13
+ * {astraId};{sessionId};{checkedAt-ms}
14
+ *
15
+ * Receivers MUST validate that `checkedAt` is recent (≤ 60s window
16
+ * recommended) and that `astraId` matches the agent identity claimed on the
17
+ * inner hop. The header alone is NOT proof-of-identity — it's an UNSIGNED
18
+ * dedupe advisory: trust it (`trustVerifiedHop`) only where every network
19
+ * path to the inner hop crosses a stripping gateway or an equivalent trusted
20
+ * boundary, exactly like the unsigned X-AstraSync-* attestation headers.
21
+ * Pair with the existing X-Astra-Id auth.
22
+ */
23
+ declare const MCP_VERIFIED_HOP_HEADER = "X-Astra-Verified-Hop";
24
+ /** Default acceptable age (ms) for an X-Astra-Verified-Hop header. */
25
+ declare const MCP_VERIFIED_HOP_MAX_AGE_MS = 60000;
26
+ interface VerifiedHopMarker {
27
+ astraId: string;
28
+ sessionId?: string;
29
+ checkedAt: number;
30
+ }
31
+ declare function serializeVerifiedHop(marker: VerifiedHopMarker): string;
32
+ declare function parseVerifiedHop(value: string | undefined | null): VerifiedHopMarker | null;
33
+ /**
34
+ * Returns true when `marker.astraId` matches the inner-hop's claimed
35
+ * ASTRA-id AND the marker is recent enough. Inner-hop middleware uses this
36
+ * to skip a duplicate verify-access call.
37
+ */
38
+ declare function isVerifiedHopValidFor(marker: VerifiedHopMarker | null, expectedAstraId: string, opts?: {
39
+ maxAgeMs?: number;
40
+ now?: number;
41
+ }): boolean;
42
+
43
+ /**
44
+ * MCP server-side helpers — companion to `transport/mcp.ts` (which handles the
45
+ * agent-side `_meta.astrasync` block).
46
+ *
47
+ * Surfaces a body-aware policy hook the existing `createMiddleware` couldn't
48
+ * provide — MCP traffic is JSON-RPC over a single endpoint (`/mcp`), so the
49
+ * default route-pattern gating is too coarse: every request looks the same
50
+ * URL-wise, but `initialize` is low-risk handshake while `tools/call` of a
51
+ * payment tool is high-risk. Cohort-3 beta merchants flagged this 🟡 in the
52
+ * v2.9.5 round.
53
+ *
54
+ * What lives here:
55
+ * - `parseMcpJsonRpc(body)` — peels JSON-RPC method + tool name + agent
56
+ * id without committing to a particular MCP
57
+ * server framework.
58
+ * - `mcpToPdlss(parsed)` — canonical mapping JSON-RPC method → PDLSS
59
+ * purpose / action / resource. Doc-stable
60
+ * so audits can correlate.
61
+ * - `mcpRiskTier(parsed)` — recommended `minAccessLevel` per method
62
+ * so a single MCP middleware can split
63
+ * `initialize` / `tools/list` (low gate)
64
+ * from `tools/call` (high gate).
65
+ * - `MCP_VERIFIED_HOP_HEADER` — header convention for the dedupe pattern
66
+ * when an MCP tool calls an inner REST hop.
67
+ * - `serialize/parseVerifiedHop` helpers.
68
+ *
69
+ * The Express MCP adapter is in `adapters/mcp.ts` and consumes these.
70
+ */
71
+
72
+ /**
73
+ * Output of `parseMcpJsonRpc`. Self-describing so the middleware doesn't have
74
+ * to re-introspect the body to figure out gating.
75
+ */
76
+ interface ParsedMcpRequest {
77
+ /** JSON-RPC method (e.g. `tools/call`, `initialize`, `tools/list`). */
78
+ method: string;
79
+ /** Set when method === 'tools/call'; the tool name from `params.name`. */
80
+ toolName?: string;
81
+ /** Initialize-specific protocolVersion handshake info, when present. */
82
+ protocolVersion?: string;
83
+ /**
84
+ * Agent id read from the body, in priority order:
85
+ * 1. `params._meta.astrasync.agentId` (the canonical SDK location, see
86
+ * `transport/mcp.ts → setMcpMeta`)
87
+ * 2. `params.arguments.agent_id` (legacy / hand-written tool callers)
88
+ * Header-supplied id (X-Astra-Id) is read separately by the adapter and
89
+ * compared to this for the mismatch check.
90
+ */
91
+ agentIdFromBody?: string;
92
+ /**
93
+ * Purpose extracted from the MCP body
94
+ * with the symmetric precedence chain. Sourced from `_meta.astrasync.purpose`
95
+ * (canonical SDK location) OR `params.arguments.purpose` (legacy /
96
+ * conventional callers). The discriminator is on `purposeSourceFromBody`.
97
+ * Adapter combines this with the `X-Astra-Purpose` header (header wins)
98
+ * before mapping; final fallback at `mcpToPdlss` is `undefined`.
99
+ */
100
+ purposeFromBody?: string;
101
+ /** Which body location resolved `purposeFromBody`. */
102
+ purposeSourceFromBody?: 'meta' | 'tool_argument';
103
+ /**
104
+ * Action extracted from the MCP body with the same
105
+ * symmetric chain as purpose. Sourced from `_meta.astrasync.action`
106
+ * (canonical) OR `params.arguments.action` (legacy). Adapter combines
107
+ * with the `X-Astra-Action` header (header wins) before mapping; final
108
+ * fallback at `mcpToPdlss` is the transport-layer default
109
+ * (`tools/call:<toolname>` or just `<method>`).
110
+ */
111
+ actionFromBody?: string;
112
+ /** Which body location resolved `actionFromBody`. */
113
+ actionSourceFromBody?: 'meta' | 'tool_argument';
114
+ /** True for handshake methods that must succeed before any tool call. */
115
+ isInitialize: boolean;
116
+ /** True for `tools/call`. */
117
+ isToolCall: boolean;
118
+ /** True for low-risk introspection (`tools/list`, `prompts/list`, etc.). */
119
+ isIntrospection: boolean;
120
+ }
121
+ /**
122
+ * Peel the JSON-RPC envelope. Returns `null` if the body isn't a JSON-RPC
123
+ * request (callers can short-circuit with a 400 or treat as untyped traffic).
124
+ *
125
+ * Accepts both single-request and notification shapes. Batch requests are
126
+ * NOT supported here — the verify-access contract is single-agent-per-call;
127
+ * a batch body should be split before policy gating.
128
+ */
129
+ declare function parseMcpJsonRpc(body: unknown): ParsedMcpRequest | null;
130
+ /**
131
+ * PDLSS mapping for an MCP request. The platform's PDLSS taxonomy is
132
+ * `purpose / action / resource`; for MCP traffic the audit-useful dimensions
133
+ * are the JSON-RPC method and (for `tools/call`) the tool name.
134
+ *
135
+ * v2.5.0 rules:
136
+ * - `resource` defaults to the HTTP request path (e.g. `/mcp`). Per-tool
137
+ * overrides via `toolGates` config let merchants map tools to specific
138
+ * backend resources (e.g. `/api/catalog`).
139
+ * - `purpose` defaults to `undefined` (backend evaluator applies
140
+ * skip-when-undefined). Per-tool overrides via `toolGates` config let
141
+ * merchants declare the semantic purpose each tool fulfils.
142
+ * - `action` comes only from declarations (toolGate config, header, or
143
+ * body). For `tools/call` with none declared it is `undefined` —
144
+ * evaluation is purpose-only, because a raw tool name is a transport
145
+ * token, not a PDLSS action, and sending it as one guarantees an
146
+ * action-policy mismatch. For other JSON-RPC methods the method string
147
+ * is used.
148
+ */
149
+ interface McpPdlssMapping {
150
+ purpose: string | undefined;
151
+ /**
152
+ * `undefined` when a `tools/call` request declared no action anywhere —
153
+ * the verify-access call then evaluates purpose-only. Tool names never
154
+ * travel as PDLSS actions.
155
+ */
156
+ action: string | undefined;
157
+ resource: string;
158
+ purposeSource: 'header' | 'meta' | 'tool_argument' | 'tool_gate' | undefined;
159
+ actionSource: 'header' | 'meta' | 'tool_argument' | 'tool_gate' | 'transport_layer' | undefined;
160
+ }
161
+ /**
162
+ * v2.5.0 — PDLSS field derivation for MCP requests.
163
+ *
164
+ * Purpose precedence:
165
+ * - If `toolGate.purpose` is provided, it is authoritative (header/body ignored).
166
+ * - Otherwise: header → body `_meta` → body `arguments` → `undefined`.
167
+ *
168
+ * Resource precedence:
169
+ * - `toolGate.resource` if provided, else `requestPath`.
170
+ *
171
+ * Action precedence (3.1.0 — toolGate override added for
172
+ * symmetry with purpose; 4.1.0 — the bare-tool-name fallback for
173
+ * `tools/call` was removed):
174
+ * - `toolGate.action` authoritative → header → body `_meta` → body
175
+ * `arguments` → then: `undefined` for `tools/call` (purpose-only
176
+ * evaluation — tool names are transport tokens, never PDLSS actions),
177
+ * or the JSON-RPC method string for other methods (transport_layer).
178
+ *
179
+ * @param requestPath The HTTP request path (e.g. '/mcp'). Required.
180
+ * @param toolGate Resolved per-tool config from `toolGates`, if present.
181
+ */
182
+ declare function mcpToPdlss(parsed: ParsedMcpRequest, requestPath: string, headerPurpose?: string, headerAction?: string, toolGate?: {
183
+ purpose?: string;
184
+ action?: string;
185
+ resource?: string;
186
+ }): McpPdlssMapping;
187
+ /**
188
+ * Recommended minimum access level per method type. The MCP middleware uses
189
+ * this to split low-risk handshake / introspection traffic from high-risk
190
+ * tool execution.
191
+ *
192
+ * - `initialize` / `notifications/initialized` → `none` (handshake must work for unregistered probes)
193
+ * - `tools/list` / `prompts/list` / `resources/list` → `none` (introspection is public-surface)
194
+ * - `ping` → `none`
195
+ * - `resources/read` → `read-only`
196
+ * - `tools/call` → `standard` (default — overridable per-tool)
197
+ * - everything else → `standard` (least-privilege fallback)
198
+ */
199
+ declare function mcpRiskTier(parsed: ParsedMcpRequest): AccessLevel;
200
+
201
+ /**
202
+ * AstraSync Universal Verification Gateway — MCP middleware
203
+ *
204
+ * Express-shaped middleware tailored to the JSON-RPC body of an MCP
205
+ * (Model Context Protocol) endpoint. Closes the cohort-3 gaps the default
206
+ * `createMiddleware` couldn't:
207
+ *
208
+ * (a) **Body-aware gating**. All MCP traffic targets the same `/mcp` URL.
209
+ * The default route-pattern matcher can't tell `initialize` (low risk)
210
+ * from `tools/call start_checkout` (high risk). This middleware peels
211
+ * the JSON-RPC body and applies a per-method risk tier.
212
+ *
213
+ * (b) **PDLSS mapping**. Derives purpose, action, and resource from
214
+ * `toolGates` config and request context. See `transport/mcp-server.ts`
215
+ * `mcpToPdlss()` for the exact mapping.
216
+ *
217
+ * (c) **Inner-hop dedupe**. Outbound responses set
218
+ * `X-Astra-Verified-Hop` so a downstream REST endpoint that the tool
219
+ * calls can skip a duplicate verify-access. The receiving REST
220
+ * middleware checks `parseVerifiedHop` and skips when valid.
221
+ *
222
+ * (d) **Header-vs-body identity precedence**. Reads ASTRA-id from
223
+ * `X-Astra-Id` first, body second. If both are present and disagree,
224
+ * returns a structured 400 by default (configurable). Pre-fix,
225
+ * integrators had to re-discover this on their own.
226
+ *
227
+ * Usage:
228
+ *
229
+ * ```typescript
230
+ * import express from 'express';
231
+ * import { createMcpMiddleware } from '@astrasyncai/verification-gateway/mcp';
232
+ *
233
+ * const app = express();
234
+ * app.use(express.json());
235
+ *
236
+ * app.post(
237
+ * '/mcp',
238
+ * createMcpMiddleware({
239
+ * apiBaseUrl: 'https://astrasync.ai/api',
240
+ * apiKey: process.env.ASTRASYNC_API_KEY,
241
+ * // Per-tool gates — tools not listed get the default tier from
242
+ * // `mcpRiskTier` (`tools/call` → 'standard'). Use the object form:
243
+ * // gated tools need a PDLSS purpose (and ideally an action).
244
+ * toolGates: {
245
+ * browse_catalog: { minAccessLevel: 'read-only', purpose: 'shopping' },
246
+ * start_checkout: {
247
+ * minAccessLevel: 'standard',
248
+ * purpose: 'shopping',
249
+ * action: 'shopping.purchase',
250
+ * },
251
+ * },
252
+ * }),
253
+ * yourMcpServerHandler,
254
+ * );
255
+ * ```
256
+ */
257
+
258
+ declare global {
259
+ namespace Express {
260
+ interface Request {
261
+ mcpRequest?: ParsedMcpRequest;
262
+ }
263
+ }
264
+ }
265
+ /**
266
+ * Extended per-tool gate with optional PDLSS purpose + action + resource
267
+ * overrides.
268
+ *
269
+ * When `purpose` is set, it is authoritative for that tool — the agent's
270
+ * `X-Astra-Purpose` header is ignored. This lets the merchant declare what
271
+ * semantic purpose each tool fulfils rather than trusting agent self-declaration.
272
+ *
273
+ * When `action` is set (symmetric with `purpose`), it is
274
+ * authoritative over `X-Astra-Action` / body declarations, letting the
275
+ * merchant pin a dotted-verb action (e.g. `shopping.search`) for a tool
276
+ * whose callers would otherwise leave the action undeclared (purpose-only
277
+ * evaluation — raw tool names never travel as PDLSS actions).
278
+ *
279
+ * When `resource` is set, it overrides the default (`req.path`) for that
280
+ * tool's verify-access call — e.g. mapping `list_products` to `/api/catalog`.
281
+ */
282
+ interface ToolGateConfig {
283
+ minAccessLevel: AccessLevel;
284
+ purpose?: string;
285
+ action?: string;
286
+ resource?: string;
287
+ }
288
+ interface McpMiddlewareOptions extends GatewayConfig {
289
+ /**
290
+ * Per-tool gating for `tools/call` invocations. Tools not listed inherit
291
+ * the default tier from `mcpRiskTier` (`tools/call` → `'standard'`).
292
+ *
293
+ * Use the **object form** — it lets the merchant declare the PDLSS
294
+ * `purpose` (required for any gated tool: the backend rejects gated calls
295
+ * with no resolvable purpose) and pin a dotted-verb `action`:
296
+ * ```typescript
297
+ * toolGates: {
298
+ * list_products: { minAccessLevel: 'read-only',
299
+ * purpose: 'shopping',
300
+ * action: 'shopping.search',
301
+ * resource: '/api/catalog' },
302
+ * start_checkout: { minAccessLevel: 'standard',
303
+ * purpose: 'shopping',
304
+ * action: 'shopping.purchase',
305
+ * resource: '/api/checkout/*' },
306
+ * }
307
+ * ```
308
+ *
309
+ * The bare access-level string shorthand (`browse_catalog: 'read-only'`)
310
+ * is a legacy form and a known footgun: it carries no purpose, so the call
311
+ * only succeeds when the AGENT declares one (an `X-Astra-Purpose` header
312
+ * or `params._meta.astrasync.purpose`) — otherwise it fails fast with a
313
+ * `PDLSS_PURPOSE_REQUIRED` 400. It also declares no action, so evaluation
314
+ * is purpose-only (the SDK never sends the raw tool name as the PDLSS
315
+ * action). `createMcpMiddleware` logs a warning at construction for every
316
+ * bare-string gate.
317
+ *
318
+ * When `tools/call` arrives for a tool not declared in `toolGates`, the SDK
319
+ * falls back to a risk-tier default based on the method classification
320
+ * (`mcpRiskTier`). For `tools/call` the fallback is `'standard'`. Best
321
+ * practice: declare every tool you expose explicitly.
322
+ *
323
+ * The action axis for non-tools/call MCP methods (`tools/list`,
324
+ * `resources/list`, `prompts/list`, etc.) is the literal JSON-RPC method
325
+ * name (e.g. `'tools/list'`). Merchants gating MCP traffic by action should
326
+ * declare per-tool gates in `toolGates`, not endpoint-level `allowedActions`
327
+ * — the latter applies to REST-style action values, not MCP method strings.
328
+ */
329
+ toolGates?: Record<string, AccessLevel | ToolGateConfig>;
330
+ /**
331
+ * Per-method override (e.g. tighten `tools/list` to `'read-only'` if you
332
+ * don't want unregistered probes seeing your tool catalogue). Matches by
333
+ * exact JSON-RPC method string.
334
+ */
335
+ methodGates?: Record<string, AccessLevel>;
336
+ /**
337
+ * What to do when the agent id supplied in the X-Astra-Id header
338
+ * disagrees with the agent id in the JSON-RPC body
339
+ * (`params._meta.astrasync.agentId` or `params.arguments.agent_id`).
340
+ *
341
+ * - `'reject'` (default) — return 400 `AGENT_ID_MISMATCH`. Safest.
342
+ * - `'prefer-header'` — log + verify against the header value. Keeps
343
+ * bodies that were authored before X-Astra-Id was the canonical
344
+ * identity slot working.
345
+ * - `'prefer-body'` — log + verify against the body value. Useful in
346
+ * reverse-proxy setups that strip auth headers.
347
+ */
348
+ onAgentIdMismatch?: 'reject' | 'prefer-header' | 'prefer-body';
349
+ /** Skip verification + dedupe entirely. For testing. */
350
+ skip?: boolean;
351
+ /** Custom denied handler. Defaults to a structured JSON-RPC error response. */
352
+ onDenied?: (result: VerificationResult, req: Request, res: Response) => void;
353
+ /**
354
+ * If `true`, trust an inbound `X-Astra-Verified-Hop` header to skip
355
+ * verify-access when it carries a recent marker for the resolved agent.
356
+ *
357
+ * **DEFAULT FLIPPED TO `false` in SDK 2.4.13.** The marker
358
+ * is plaintext semicolon-delimited with no HMAC, so any client that sets
359
+ * the header (with the right format + fresh timestamp + matching ASTRA-id)
360
+ * skipped verify-access entirely. The per-process verify-access result
361
+ * cache already dedupes legitimate repeat calls — this optimization
362
+ * provided no additional savings, only a bypass surface.
363
+ *
364
+ * Set this to `true` ONLY if you control every upstream MCP hop that sets
365
+ * the header AND you trust the network path between hops (mTLS, internal
366
+ * VPC, etc.). For most installs, leave at the safe default.
367
+ *
368
+ * A future SDK release will either remove this option entirely OR add
369
+ * HMAC signing to the marker.
370
+ */
371
+ trustVerifiedHop?: boolean;
372
+ /** Window for accepting an upstream verified-hop marker. Default 60_000ms. */
373
+ verifiedHopMaxAgeMs?: number;
374
+ /**
375
+ * Automatically record grant/deny decisions for every MCP call. Default
376
+ * `true` — matches the express adapter.
377
+ */
378
+ recordDecisions?: boolean;
379
+ /** Forward runtime challenge (default `true`). */
380
+ enableRuntimeChallenge?: boolean;
381
+ /**
382
+ * Posture when the MCP middleware itself throws an internal error.
383
+ * Default `'open'` for backward compatibility in SDK 2.4.13. Shadow logs
384
+ * record what WOULD be denied with `failOnError: 'closed'` so merchants
385
+ * can grep correlationId for impact analysis during the observation
386
+ * window. Default flips to `'closed'` in a follow-up release.
387
+ */
388
+ failOnError?: 'open' | 'closed';
389
+ }
390
+ /**
391
+ * Create the MCP middleware. Attach AFTER `express.json()` — the body must
392
+ * already be a parsed object.
393
+ */
394
+ declare function createMcpMiddleware(options: McpMiddlewareOptions): RequestHandler;
395
+
396
+ export { MCP_VERIFIED_HOP_HEADER as M, type ParsedMcpRequest as P, type ToolGateConfig as T, type VerifiedHopMarker as V, MCP_VERIFIED_HOP_MAX_AGE_MS as a, type McpMiddlewareOptions as b, createMcpMiddleware as c, mcpToPdlss as d, parseVerifiedHop as e, isVerifiedHopValidFor as i, mcpRiskTier as m, parseMcpJsonRpc as p, serializeVerifiedHop as s };
@@ -42,7 +42,7 @@ __export(registration_exports, {
42
42
  module.exports = __toCommonJS(registration_exports);
43
43
 
44
44
  // src/version.ts
45
- var SDK_VERSION = "4.5.0";
45
+ var SDK_VERSION = "4.5.1";
46
46
 
47
47
  // src/http.ts
48
48
  var SDK_USER_AGENT = `astrasync-sdk/${SDK_VERSION}`;
@@ -418,6 +418,7 @@ function buildGuidance(params) {
418
418
  steps: [
419
419
  "Credentialed path (recommended): have your human mint an agent-scoped API key at Settings \u2192 API Keys, then re-call register_agent with apiKey set. An agent holding its own scoped kya_ key is fine and intended.",
420
420
  "No-credentials path: call request_registration({ name, ownerEmail, ... }) with the human owner's email \u2014 the only bootstrap credential. No API key is involved.",
421
+ "Include as much metadata as you can in the registration \u2014 especially model ({ modelName, modelProvider }) and framework ({ frameworkName, frameworkVersion }). Declared platform/model metadata directly improves your trust score and attributes your traffic correctly.",
421
422
  "The owner approves via an emailed link (first time, they create an account and complete a quick verification).",
422
423
  "Use poll_registration({ requestId }) once the owner confirms approval to retrieve the astraId.",
423
424
  "Never transmit a password or private key over the MCP wire \u2014 those are never required."
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/registration/index.ts","../../src/version.ts","../../src/http.ts","../../src/registration/errors.ts","../../src/registration/api.ts","../../src/registration/guidance.ts"],"sourcesContent":["export { AstraSync } from './api';\nexport {\n AstraSyncError,\n KYDRequiredError,\n AuthenticationError,\n RegistrationDeniedError,\n RegistrationExpiredError,\n RegistrationTimeoutError,\n} from './errors';\nexport { buildGuidance } from './guidance';\nexport type { GuidanceEnvelope, BuildGuidanceParams } from './guidance';\nexport type {\n AstraSyncConfig,\n RegisterOptions,\n RegisterResult,\n WaitForApprovalOptions,\n PendingRegistrationResponse,\n PollRegistrationResult,\n RegistrationResponse,\n AgentRecord,\n VerifyResponse,\n HealthResponse,\n PDLSSConfig,\n PDLSSPurpose,\n PDLSSDuration,\n PDLSSLimits,\n PDLSSScope,\n PDLSSSelfInstantiation,\n ModelConfig,\n FrameworkConfig,\n AgentProtocol,\n} from './types';\n","/**\n * Single source-of-truth for the SDK's\n * package version emitted on verify-access bodies (and any future\n * telemetry). Bumped alongside `package.json#version` on every release.\n *\n * Why a constant rather than `import pkg from '../package.json'`:\n * - `tsconfig.json` sets `rootDir: ./src`; importing the sibling\n * package.json fails the build with \"outside rootDir\".\n * - Build-time string replacement (tsup `define`, esbuild banner, etc.)\n * adds toolchain coupling for a trivial gain.\n * - Embedded readonly constant works in every environment (Node, browser,\n * bundlers, Deno) without runtime fs / network access.\n *\n * Release discipline: a CI lint can grep `package.json#version` against\n * this constant if the two ever diverge in the wild. A manual bump\n * is fine — bumping both in the release-ceremony commit keeps them\n * lockstep.\n */\nexport const SDK_VERSION = '4.5.0';\n","/**\n * Shared outbound-HTTP wrapper — every request the SDK makes to the\n * AstraSync backend (or anywhere else) goes through `sdkFetch` so it\n * carries an identifying User-Agent.\n *\n * Why: Node's global fetch defaults to `user-agent: node`, which is\n * indistinguishable from every other Node client on the wire. Visit\n * Intelligence observed our own SDK/beacon traffic as anonymous \"node\"\n * visits. Self-identification is the platform's own medicine.\n *\n * Browser note: some browsers filter the User-Agent request header\n * silently (never throwing), so this is a no-op there — which is correct:\n * in a browser the page's real UA is the honest identity.\n */\n\nimport { SDK_VERSION } from './version';\n\nexport const SDK_USER_AGENT = `astrasync-sdk/${SDK_VERSION}`;\n\n/**\n * Add the SDK User-Agent without changing the SHAPE of the caller's headers\n * (plain records stay plain records) — interceptors, adapters, and tests\n * read `init.headers` as a record, and `Headers` would also lowercase names.\n */\nfunction withUserAgent(initHeaders: HeadersInit | undefined): HeadersInit {\n if (!initHeaders) return { 'user-agent': SDK_USER_AGENT };\n if (initHeaders instanceof Headers) {\n const copy = new Headers(initHeaders);\n if (!copy.has('user-agent')) copy.set('user-agent', SDK_USER_AGENT);\n return copy;\n }\n if (Array.isArray(initHeaders)) {\n const has = initHeaders.some(([name]) => name.toLowerCase() === 'user-agent');\n return has ? initHeaders : [...initHeaders, ['user-agent', SDK_USER_AGENT]];\n }\n const has = Object.keys(initHeaders).some((name) => name.toLowerCase() === 'user-agent');\n return has ? initHeaders : { 'user-agent': SDK_USER_AGENT, ...initHeaders };\n}\n\nexport const sdkFetch: typeof fetch = (input, init) =>\n fetch(input, { ...init, headers: withUserAgent(init?.headers) });\n","import type { ApiErrorResponse } from './types';\n\n/** Base error class for AstraSync SDK errors. */\nexport class AstraSyncError extends Error {\n public readonly code?: string;\n public readonly statusCode: number;\n\n constructor(message: string, statusCode: number, code?: string) {\n super(message);\n this.name = 'AstraSyncError';\n this.statusCode = statusCode;\n this.code = code;\n }\n}\n\n/** Thrown when KYD verification is required before agent registration. */\nexport class KYDRequiredError extends AstraSyncError {\n public readonly kydUrl: string;\n public readonly ownerNotified: boolean;\n\n constructor(response: ApiErrorResponse) {\n const kydUrl = response.kydUrl || 'https://astrasync.ai/developer-profile';\n super(\n `KYD verification required before registering agents.\\nComplete your KYD profile at: ${kydUrl}`,\n 403,\n 'KYD_REQUIRED'\n );\n this.name = 'KYDRequiredError';\n this.kydUrl = kydUrl;\n this.ownerNotified = response.ownerNotified || false;\n }\n}\n\n/** Thrown when authentication fails. */\nexport class AuthenticationError extends AstraSyncError {\n constructor(message: string) {\n super(message, 401, 'AUTH_FAILED');\n this.name = 'AuthenticationError';\n }\n}\n\n/**\n * Thrown by `register({ waitForApproval: true })` when the owner denies the\n * pending registration request. The `reason` field, when present, mirrors the\n * deny note the owner left in the dashboard.\n */\nexport class RegistrationDeniedError extends AstraSyncError {\n public readonly requestId: string;\n public readonly reason?: string;\n\n constructor(requestId: string, reason?: string) {\n super(\n `Registration request ${requestId} was denied by the account owner.${reason ? ` Reason: ${reason}` : ''}`,\n 403,\n 'REGISTRATION_DENIED'\n );\n this.name = 'RegistrationDeniedError';\n this.requestId = requestId;\n this.reason = reason;\n }\n}\n\n/**\n * Thrown by `register({ waitForApproval: true })` when the pending request\n * passes its 14-day TTL with no owner decision. The agent must re-submit.\n */\nexport class RegistrationExpiredError extends AstraSyncError {\n public readonly requestId: string;\n\n constructor(requestId: string) {\n super(\n `Registration request ${requestId} expired before the owner approved it. Submit a new registration request.`,\n 410,\n 'REGISTRATION_EXPIRED'\n );\n this.name = 'RegistrationExpiredError';\n this.requestId = requestId;\n }\n}\n\n/**\n * Thrown by `register({ waitForApproval: true })` when the caller's local\n * `timeoutMs` elapses before the owner makes a decision. The request is still\n * live server-side — poll `pollRegistration(requestId)` to resume waiting, or\n * call `waitForApproval` again with a longer timeout.\n */\nexport class RegistrationTimeoutError extends AstraSyncError {\n public readonly requestId: string;\n\n constructor(requestId: string) {\n super(\n `Timed out waiting for owner approval of registration request ${requestId}. The request is still active server-side; poll the request to resume waiting.`,\n 408,\n 'REGISTRATION_TIMEOUT'\n );\n this.name = 'RegistrationTimeoutError';\n this.requestId = requestId;\n }\n}\n","import { sdkFetch } from '../http';\nimport type {\n AstraSyncConfig,\n RegisterOptions,\n RegisterResult,\n WaitForApprovalOptions,\n PendingRegistrationResponse,\n PollRegistrationResult,\n RegistrationResponse,\n VerifyResponse,\n HealthResponse,\n ApiErrorResponse,\n AgentRecord,\n} from './types';\nimport {\n AstraSyncError,\n KYDRequiredError,\n AuthenticationError,\n RegistrationDeniedError,\n RegistrationExpiredError,\n RegistrationTimeoutError,\n} from './errors';\n\nconst DEFAULT_BASE_URL = 'https://astrasync.ai';\n\nconst sleep = (ms: number): Promise<void> => new Promise((r) => setTimeout(r, ms));\n\n/**\n * AstraSync SDK client for registering and managing AI agents.\n *\n * @example\n * ```typescript\n * const client = new AstraSync({ apiKey: 'kya_your_api_key' });\n * const result = await client.register({\n * name: 'My Agent',\n * model: { modelName: 'gpt-4o', modelProvider: 'openai', modelType: 'llm' },\n * });\n * ```\n *\n * For staging, pass `baseUrl: 'https://staging.astrasync.ai'`.\n */\nexport class AstraSync {\n private readonly baseUrl: string;\n private readonly apiKey?: string;\n private readonly email?: string;\n private readonly password?: string;\n private readonly privateKey?: string;\n private cachedJwt?: string;\n private jwtExpiresAt?: number;\n\n constructor(config: AstraSyncConfig = {}) {\n let raw = (config.baseUrl || process.env.ASTRASYNC_API_URL || DEFAULT_BASE_URL).replace(\n /\\/+$/,\n ''\n );\n // Round-10 (O2): tolerate the verify-side convention. `GatewayConfig.apiBaseUrl`\n // is documented as `https://astrasync.ai/api` (with /api), but\n // `AstraSyncConfig.baseUrl` is documented as the bare origin. Partners\n // passing the verify-style URL to the registration client hit a 404\n // because we'd then append `/api/agents/register` → double /api. Strip\n // a trailing `/api` and warn once so the partner can fix the source.\n if (raw.toLowerCase().endsWith('/api')) {\n raw = raw.slice(0, -'/api'.length);\n if (config.baseUrl && !config.silent) {\n // eslint-disable-next-line no-console\n console.warn(\n `[AstraSync] baseUrl '${config.baseUrl}' had a trailing /api — stripped to '${raw}'. ` +\n `Pass the bare origin (e.g. 'https://astrasync.ai' or 'https://staging.astrasync.ai') ` +\n `to AstraSync(). The /api suffix is the verify-gateway (GatewayConfig.apiBaseUrl) convention.`\n );\n }\n }\n this.baseUrl = raw;\n\n // Env fallback is opt-OUT: server-side wrappers (MCP tool handlers,\n // gateway adapters) pass `disableEnvFallback: true` so a no-credentials\n // call from a user-facing flow cannot silently authenticate as the host\n // process's platform-attribution key. CLIs / scripts that legitimately\n // rely on ASTRASYNC_API_KEY keep working under the default.\n this.apiKey = config.disableEnvFallback\n ? config.apiKey\n : config.apiKey || process.env.ASTRASYNC_API_KEY;\n this.email = config.email;\n this.password = config.password;\n this.privateKey = config.privateKey;\n\n // Defense-in-depth: warn when env fallback actually fires under the\n // default (non-strict) config. Surfaces the \"I'm running as platform\"\n // foot-gun before it becomes a security bug. Gated by !silent.\n if (\n !config.apiKey &&\n !config.disableEnvFallback &&\n process.env.ASTRASYNC_API_KEY &&\n !config.silent\n ) {\n // eslint-disable-next-line no-console\n console.warn(\n '[AstraSync] No apiKey passed to constructor; using process.env.ASTRASYNC_API_KEY. ' +\n 'If this code wraps user-facing flows (e.g. MCP tool handlers), pass ' +\n 'disableEnvFallback: true to prevent ambient credentials from impersonating callers. ' +\n 'See https://astrasync.ai/docs/agent-access#disableenvfallback for details.'\n );\n }\n\n if (!this.apiKey && !this.email) {\n throw new AuthenticationError(\n 'Authentication required. Provide apiKey, or email+password. ' +\n 'Set ASTRASYNC_API_KEY env var or pass config to constructor.'\n );\n }\n\n if (this.email && !this.password) {\n throw new AuthenticationError('Password is required when using email authentication.');\n }\n }\n\n /**\n * Register a new AI agent on the AstraSync KYA Platform.\n *\n * The backend response depends on auth context:\n * - **Crypto-keypair signed** (`privateKey` configured): synchronous 201,\n * returns `{ status: 'active', agent }`.\n * - **API-key only** (no signature): 202 pending, returns\n * `{ status: 'pending_approval', requestId, pollUrl, expiresAt }`. The\n * owner is notified by email and a dashboard alert is emitted; the agent\n * becomes active only after the owner approves.\n *\n * Blocking mode: pass `{ waitForApproval: true }` to have the SDK poll the\n * request until it resolves, then return the live agent record. The promise\n * rejects with `RegistrationDeniedError`, `RegistrationExpiredError`, or\n * `RegistrationTimeoutError` on the corresponding terminal states.\n *\n * @example Non-blocking (default — best for serverless / scheduled agents):\n * ```typescript\n * const result = await sdk.register({ name, pdlss });\n * if (result.status === 'pending_approval') {\n * storeRequestId(result.requestId);\n * return; // function exits; resume later via pollRegistration()\n * }\n * ```\n *\n * @example Blocking (best for long-running services + CLI):\n * ```typescript\n * const agent = await sdk.register({\n * name, pdlss, waitForApproval: true, timeoutMs: 600_000,\n * onPending: ({ ageMs }) => console.log(`waiting ${ageMs}ms`),\n * });\n * ```\n */\n async register(\n options: RegisterOptions & WaitForApprovalOptions\n ): Promise<RegisterResult | AgentRecord> {\n const body: Record<string, unknown> = {\n name: options.name,\n ...(options.description && { description: options.description }),\n ...(options.agentType && { agentType: options.agentType }),\n ...(options.apiEndpoint && { apiEndpoint: options.apiEndpoint }),\n ...(options.model && { model: options.model }),\n ...(options.framework && { framework: options.framework }),\n ...(options.protocols && { protocols: options.protocols }),\n ...(options.metadata && { metadata: options.metadata }),\n ...(options.pdlss && { pdlss: options.pdlss }),\n };\n\n const { status, body: raw } = await this.requestWithStatus<\n RegistrationResponse | PendingRegistrationResponse\n >('POST', '/api/agents/register', body);\n\n if (status === 201) {\n const activeBody = raw as RegistrationResponse;\n const active: RegisterResult = {\n status: 'active',\n agent: activeBody.data.agent,\n // Round-12 (F16): pass backend advisories through verbatim.\n // Pre-fix the SDK whitelisted five fields and silently dropped\n // `warnings`, which left partners with no signal that\n // `no_callback_endpoint` (or future advisories) had fired.\n ...(activeBody.warnings && { warnings: activeBody.warnings }),\n };\n return active;\n }\n\n // 202 Accepted — owner approval required.\n const pendingBody = raw as PendingRegistrationResponse;\n const pending: RegisterResult = {\n status: 'pending_approval',\n requestId: pendingBody.requestId,\n expiresAt: pendingBody.expiresAt,\n pollUrl: pendingBody.pollUrl,\n message: pendingBody.message,\n // Round-12 (F16): same pass-through on the pending path.\n ...(pendingBody.warnings && { warnings: pendingBody.warnings }),\n };\n\n if (!options.waitForApproval) return pending;\n\n return this.waitForApproval(pendingBody.requestId, options);\n }\n\n /**\n * Poll the current state of a pending-approval registration request.\n *\n * Useful for caller-driven polling when `waitForApproval: false` (the\n * default). The endpoint is unauthenticated — pass the `requestId` that\n * was returned from the 202 response.\n *\n * @returns `state: 'pending'` while awaiting; `'approved'` carries the\n * minted agent in `agent`; `'denied'` may carry the owner's\n * `reason`; `'expired'` is terminal after 14 days.\n */\n async pollRegistration(requestId: string): Promise<PollRegistrationResult> {\n const url = `${this.baseUrl}/api/agents/request-registration/${requestId}`;\n const res = await sdkFetch(url, { headers: { Accept: 'application/json' } });\n if (!res.ok) {\n const errBody = (await res.json().catch(() => ({}))) as ApiErrorResponse;\n throw new AstraSyncError(\n errBody.error || `pollRegistration failed: ${res.status}`,\n res.status,\n errBody.code\n );\n }\n return (await res.json()) as PollRegistrationResult;\n }\n\n /**\n * Block until a pending registration request resolves to a terminal state.\n * Resolves to the live `AgentRecord` on approval; rejects with the matching\n * Registration*Error on deny/expire/timeout. Usually called via\n * `register({ waitForApproval: true })`, but exposed for callers that want\n * to fire-and-forget the initial register call and resume waiting later\n * (e.g. after restoring a stored `requestId` on cold start).\n */\n async waitForApproval(\n requestId: string,\n options: WaitForApprovalOptions = {}\n ): Promise<AgentRecord> {\n const timeoutMs = options.timeoutMs ?? 10 * 60 * 1000;\n const pollIntervalMs = options.pollIntervalMs ?? 5_000;\n const start = Date.now();\n const deadline = start + timeoutMs;\n\n while (Date.now() < deadline) {\n const result = await this.pollRegistration(requestId);\n const ageMs = Date.now() - start;\n options.onPending?.({ requestId, ageMs });\n\n if (result.state === 'approved') {\n if (!result.agent) {\n throw new AstraSyncError(\n `Registration ${requestId} reported approved but no agent payload returned.`,\n 500\n );\n }\n return result.agent;\n }\n if (result.state === 'denied') {\n throw new RegistrationDeniedError(requestId, result.reason);\n }\n if (result.state === 'expired') {\n throw new RegistrationExpiredError(requestId);\n }\n await sleep(pollIntervalMs);\n }\n throw new RegistrationTimeoutError(requestId);\n }\n\n /**\n * Look up an agent's public profile by ASTRA ID or UUID.\n */\n async verify(agentId: string): Promise<VerifyResponse> {\n return this.request<VerifyResponse>('GET', `/api/agents/verify/${agentId}`);\n }\n\n /**\n * Check API health.\n */\n async health(): Promise<HealthResponse> {\n const res = await sdkFetch(`${this.baseUrl}/api/health/`);\n if (!res.ok) {\n throw new AstraSyncError(`Health check failed: ${res.status}`, res.status);\n }\n return res.json() as Promise<HealthResponse>;\n }\n\n // ── Private helpers ──────────────────────────────────────────────\n\n private async request<T>(method: string, endpoint: string, body?: unknown): Promise<T> {\n const { body: parsed } = await this.requestWithStatus<T>(method, endpoint, body);\n return parsed;\n }\n\n /**\n * Variant of {@link request} that also returns the HTTP status code, so\n * callers can branch on 201 vs 202 (or other success codes) without losing\n * type information about the response body.\n */\n private async requestWithStatus<T>(\n method: string,\n endpoint: string,\n body?: unknown\n ): Promise<{ status: number; body: T }> {\n const url = `${this.baseUrl}${endpoint}`;\n const headers: Record<string, string> = {\n 'Content-Type': 'application/json',\n };\n\n // Set auth header\n const token = await this.getAuthToken();\n headers['Authorization'] = `Bearer ${token}`;\n\n // Sign request if private key is configured\n if (this.privateKey) {\n const signature = await this.signRequest(method, endpoint, body || {});\n headers['X-AstraSync-Signature'] = signature;\n }\n\n const res = await sdkFetch(url, {\n method,\n headers,\n ...(body ? { body: JSON.stringify(body) } : {}),\n });\n\n if (!res.ok) {\n const errorBody = (await res\n .json()\n .catch(() => ({ error: res.statusText }))) as ApiErrorResponse;\n\n // Handle KYD_REQUIRED specifically\n if (res.status === 403 && errorBody.code === 'KYD_REQUIRED') {\n throw new KYDRequiredError(errorBody);\n }\n\n throw new AstraSyncError(\n errorBody.error || `Request failed: ${res.status}`,\n res.status,\n errorBody.code\n );\n }\n\n return { status: res.status, body: (await res.json()) as T };\n }\n\n private async getAuthToken(): Promise<string> {\n // API key auth — use directly\n if (this.apiKey) {\n return this.apiKey;\n }\n\n // Email+password — login and cache JWT\n if (this.cachedJwt && this.jwtExpiresAt && Date.now() < this.jwtExpiresAt) {\n return this.cachedJwt;\n }\n\n const res = await sdkFetch(`${this.baseUrl}/api/auth/login`, {\n method: 'POST',\n headers: { 'Content-Type': 'application/json' },\n body: JSON.stringify({ email: this.email, password: this.password }),\n });\n\n if (!res.ok) {\n const errorBody = (await res.json().catch(() => ({}))) as Record<string, unknown>;\n throw new AuthenticationError(\n (errorBody.message as string) || (errorBody.error as string) || 'Login failed'\n );\n }\n\n const data = (await res.json()) as { data: { token: string } };\n this.cachedJwt = data.data.token;\n // Cache for 6 days (tokens expire in 7)\n this.jwtExpiresAt = Date.now() + 6 * 24 * 60 * 60 * 1000;\n\n return this.cachedJwt;\n }\n\n /**\n * Sign a request using secp256k1 (ethers.js).\n * Canonical message format: METHOD:ENDPOINT:SORTED_JSON_BODY\n * Must match apps/backend/src/services/signature-verify.service.ts exactly.\n */\n private async signRequest(method: string, endpoint: string, body: unknown): Promise<string> {\n const { Wallet } = await import('ethers');\n const sorted = this.sortObjectKeys(body);\n const canonical = `${method}:${endpoint}:${JSON.stringify(sorted)}`;\n const wallet = new Wallet(this.privateKey!);\n return wallet.signMessage(canonical);\n }\n\n /** Recursively sort object keys for canonical JSON representation. */\n private sortObjectKeys(obj: unknown): unknown {\n if (obj === null || typeof obj !== 'object') {\n return obj;\n }\n if (Array.isArray(obj)) {\n return obj.map((item) => this.sortObjectKeys(item));\n }\n const sorted: Record<string, unknown> = {};\n for (const key of Object.keys(obj).sort()) {\n sorted[key] = this.sortObjectKeys((obj as Record<string, unknown>)[key]);\n }\n return sorted;\n }\n}\n","/**\n * Guidance envelope for credentials-required cases.\n *\n * A single shared source of truth so partners writing their own wrappers\n * (custom MCP servers, Express middleware around registration, gateway\n * adapters) consume a single source of truth instead of re-implementing the\n * five-step boilerplate.\n *\n * The envelope is what an agent (or wrapping MCP client) sees when it calls\n * `register_agent` with no AstraSync credentials. It tells the calling agent\n * (a) what failed (`status: 'credentials_required'`), (b) the keyless\n * registration ACTION endpoint (`registrationUrl` — POST-able, not the human\n * dashboard), (c) where the relevant docs are (`documentationUrl`), and (d) the\n * ordered next-actions (`steps`).\n */\n\nexport interface GuidanceEnvelope {\n /**\n * Single-literal today. Expand to a union (e.g.\n * `'credentials_required' | 'kyd_required' | …`) when a second guidance\n * status emerges. Don't pre-emptively widen — the literal pins the shape.\n */\n status: 'credentials_required';\n message: string;\n guidance: {\n message: string;\n registrationUrl: string;\n documentationUrl: string;\n steps: string[];\n };\n}\n\nexport interface BuildGuidanceParams {\n /**\n * Bare origin of the AstraSync deployment the caller should register at,\n * e.g. `https://astrasync.ai` or `https://staging.astrasync.ai`. No\n * trailing slash, no `/api` suffix — registrationUrl and documentationUrl\n * are templated relative to this origin.\n */\n origin: string;\n /**\n * Overrides the top-level `message` (the short summary the agent sees).\n * Defaults to the error message from the SDK's `AuthenticationError`\n * when present, else a generic \"credentials required\" line.\n */\n message?: string;\n /**\n * Overrides the documentation path. Defaults to `/docs/agent-access`.\n */\n documentationPath?: string;\n}\n\n/**\n * Build the credentials-required guidance envelope.\n *\n * This is the canonical builder — MCP wrappers (`agent-registration.ts`),\n * Express middleware in custom integrations, and any other partner-side\n * wrapper that needs to surface \"you need to register\" should call this\n * rather than reconstructing the shape inline. Inline reconstruction\n * historically led to drift between wrappers; this consolidates it.\n *\n * @example\n * ```ts\n * import { buildGuidance } from '@astrasyncai/verification-gateway';\n *\n * try {\n * const sdk = new AstraSync({ apiKey: callerApiKey, disableEnvFallback: true });\n * // ...\n * } catch (err) {\n * if (err instanceof AuthenticationError) {\n * return buildGuidance({ origin: 'https://astrasync.ai', message: err.message });\n * }\n * throw err;\n * }\n * ```\n */\nexport function buildGuidance(params: BuildGuidanceParams): GuidanceEnvelope {\n const origin = params.origin.replace(/\\/+$/, '');\n const docsPath = params.documentationPath ?? '/docs/agent-access';\n const message = params.message ?? 'AstraSync registration requires credentials.';\n\n return {\n status: 'credentials_required',\n message,\n guidance: {\n message:\n \"Register either with an agent-scoped API key (the recommended credentialed path) OR, if you hold no credentials, via the owner's email using request_registration. Never send a password or private key over the wire.\",\n // 3.0.0: registrationUrl is the agent-actionable KEYLESS endpoint, not the\n // human dashboard `/agents/register` (an auth-walled page an agent can't\n // use). documentationUrl carries the machine-readable contract.\n registrationUrl: `${origin}/api/agents/request-registration`,\n documentationUrl: `${origin}${docsPath.startsWith('/') ? docsPath : `/${docsPath}`}`,\n steps: [\n 'Credentialed path (recommended): have your human mint an agent-scoped API key at Settings → API Keys, then re-call register_agent with apiKey set. An agent holding its own scoped kya_ key is fine and intended.',\n \"No-credentials path: call request_registration({ name, ownerEmail, ... }) with the human owner's email — the only bootstrap credential. No API key is involved.\",\n 'The owner approves via an emailed link (first time, they create an account and complete a quick verification).',\n 'Use poll_registration({ requestId }) once the owner confirms approval to retrieve the astraId.',\n 'Never transmit a password or private key over the MCP wire — those are never required.',\n ],\n },\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACkBO,IAAM,cAAc;;;ACDpB,IAAM,iBAAiB,iBAAiB,WAAW;AAO1D,SAAS,cAAc,aAAmD;AACxE,MAAI,CAAC,YAAa,QAAO,EAAE,cAAc,eAAe;AACxD,MAAI,uBAAuB,SAAS;AAClC,UAAM,OAAO,IAAI,QAAQ,WAAW;AACpC,QAAI,CAAC,KAAK,IAAI,YAAY,EAAG,MAAK,IAAI,cAAc,cAAc;AAClE,WAAO;AAAA,EACT;AACA,MAAI,MAAM,QAAQ,WAAW,GAAG;AAC9B,UAAMA,OAAM,YAAY,KAAK,CAAC,CAAC,IAAI,MAAM,KAAK,YAAY,MAAM,YAAY;AAC5E,WAAOA,OAAM,cAAc,CAAC,GAAG,aAAa,CAAC,cAAc,cAAc,CAAC;AAAA,EAC5E;AACA,QAAM,MAAM,OAAO,KAAK,WAAW,EAAE,KAAK,CAAC,SAAS,KAAK,YAAY,MAAM,YAAY;AACvF,SAAO,MAAM,cAAc,EAAE,cAAc,gBAAgB,GAAG,YAAY;AAC5E;AAEO,IAAM,WAAyB,CAAC,OAAO,SAC5C,MAAM,OAAO,EAAE,GAAG,MAAM,SAAS,cAAc,MAAM,OAAO,EAAE,CAAC;;;ACrC1D,IAAM,iBAAN,cAA6B,MAAM;AAAA,EAIxC,YAAY,SAAiB,YAAoB,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,KAAK,eAAe,IAAI,CAAC;AAAA,IACpD;AACA,UAAM,SAAkC,CAAC;AACzC,eAAW,OAAO,OAAO,KAAK,GAAG,EAAE,KAAK,GAAG;AACzC,aAAO,GAAG,IAAI,KAAK,eAAgB,IAAgC,GAAG,CAAC;AAAA,IACzE;AACA,WAAO;AAAA,EACT;AACF;;;ACrUO,SAAS,cAAc,QAA+C;AAC3E,QAAM,SAAS,OAAO,OAAO,QAAQ,QAAQ,EAAE;AAC/C,QAAM,WAAW,OAAO,qBAAqB;AAC7C,QAAM,UAAU,OAAO,WAAW;AAElC,SAAO;AAAA,IACL,QAAQ;AAAA,IACR;AAAA,IACA,UAAU;AAAA,MACR,SACE;AAAA;AAAA;AAAA;AAAA,MAIF,iBAAiB,GAAG,MAAM;AAAA,MAC1B,kBAAkB,GAAG,MAAM,GAAG,SAAS,WAAW,GAAG,IAAI,WAAW,IAAI,QAAQ,EAAE;AAAA,MAClF,OAAO;AAAA,QACL;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,MACF;AAAA,IACF;AAAA,EACF;AACF;","names":["has"]}
1
+ {"version":3,"sources":["../../src/registration/index.ts","../../src/version.ts","../../src/http.ts","../../src/registration/errors.ts","../../src/registration/api.ts","../../src/registration/guidance.ts"],"sourcesContent":["export { AstraSync } from './api';\nexport {\n AstraSyncError,\n KYDRequiredError,\n AuthenticationError,\n RegistrationDeniedError,\n RegistrationExpiredError,\n RegistrationTimeoutError,\n} from './errors';\nexport { buildGuidance } from './guidance';\nexport type { GuidanceEnvelope, BuildGuidanceParams } from './guidance';\nexport type {\n AstraSyncConfig,\n RegisterOptions,\n RegisterResult,\n WaitForApprovalOptions,\n PendingRegistrationResponse,\n PollRegistrationResult,\n RegistrationResponse,\n AgentRecord,\n VerifyResponse,\n HealthResponse,\n PDLSSConfig,\n PDLSSPurpose,\n PDLSSDuration,\n PDLSSLimits,\n PDLSSScope,\n PDLSSSelfInstantiation,\n ModelConfig,\n FrameworkConfig,\n AgentProtocol,\n} from './types';\n","/**\n * Single source-of-truth for the SDK's\n * package version emitted on verify-access bodies (and any future\n * telemetry). Bumped alongside `package.json#version` on every release.\n *\n * Why a constant rather than `import pkg from '../package.json'`:\n * - `tsconfig.json` sets `rootDir: ./src`; importing the sibling\n * package.json fails the build with \"outside rootDir\".\n * - Build-time string replacement (tsup `define`, esbuild banner, etc.)\n * adds toolchain coupling for a trivial gain.\n * - Embedded readonly constant works in every environment (Node, browser,\n * bundlers, Deno) without runtime fs / network access.\n *\n * Release discipline: a CI lint can grep `package.json#version` against\n * this constant if the two ever diverge in the wild. A manual bump\n * is fine — bumping both in the release-ceremony commit keeps them\n * lockstep.\n */\nexport const SDK_VERSION = '4.5.1';\n","/**\n * Shared outbound-HTTP wrapper — every request the SDK makes to the\n * AstraSync backend (or anywhere else) goes through `sdkFetch` so it\n * carries an identifying User-Agent.\n *\n * Why: Node's global fetch defaults to `user-agent: node`, which is\n * indistinguishable from every other Node client on the wire. Visit\n * Intelligence observed our own SDK/beacon traffic as anonymous \"node\"\n * visits. Self-identification is the platform's own medicine.\n *\n * Browser note: some browsers filter the User-Agent request header\n * silently (never throwing), so this is a no-op there — which is correct:\n * in a browser the page's real UA is the honest identity.\n */\n\nimport { SDK_VERSION } from './version';\n\nexport const SDK_USER_AGENT = `astrasync-sdk/${SDK_VERSION}`;\n\n/**\n * Add the SDK User-Agent without changing the SHAPE of the caller's headers\n * (plain records stay plain records) — interceptors, adapters, and tests\n * read `init.headers` as a record, and `Headers` would also lowercase names.\n */\nfunction withUserAgent(initHeaders: HeadersInit | undefined): HeadersInit {\n if (!initHeaders) return { 'user-agent': SDK_USER_AGENT };\n if (initHeaders instanceof Headers) {\n const copy = new Headers(initHeaders);\n if (!copy.has('user-agent')) copy.set('user-agent', SDK_USER_AGENT);\n return copy;\n }\n if (Array.isArray(initHeaders)) {\n const has = initHeaders.some(([name]) => name.toLowerCase() === 'user-agent');\n return has ? initHeaders : [...initHeaders, ['user-agent', SDK_USER_AGENT]];\n }\n const has = Object.keys(initHeaders).some((name) => name.toLowerCase() === 'user-agent');\n return has ? initHeaders : { 'user-agent': SDK_USER_AGENT, ...initHeaders };\n}\n\nexport const sdkFetch: typeof fetch = (input, init) =>\n fetch(input, { ...init, headers: withUserAgent(init?.headers) });\n","import type { ApiErrorResponse } from './types';\n\n/** Base error class for AstraSync SDK errors. */\nexport class AstraSyncError extends Error {\n public readonly code?: string;\n public readonly statusCode: number;\n\n constructor(message: string, statusCode: number, code?: string) {\n super(message);\n this.name = 'AstraSyncError';\n this.statusCode = statusCode;\n this.code = code;\n }\n}\n\n/** Thrown when KYD verification is required before agent registration. */\nexport class KYDRequiredError extends AstraSyncError {\n public readonly kydUrl: string;\n public readonly ownerNotified: boolean;\n\n constructor(response: ApiErrorResponse) {\n const kydUrl = response.kydUrl || 'https://astrasync.ai/developer-profile';\n super(\n `KYD verification required before registering agents.\\nComplete your KYD profile at: ${kydUrl}`,\n 403,\n 'KYD_REQUIRED'\n );\n this.name = 'KYDRequiredError';\n this.kydUrl = kydUrl;\n this.ownerNotified = response.ownerNotified || false;\n }\n}\n\n/** Thrown when authentication fails. */\nexport class AuthenticationError extends AstraSyncError {\n constructor(message: string) {\n super(message, 401, 'AUTH_FAILED');\n this.name = 'AuthenticationError';\n }\n}\n\n/**\n * Thrown by `register({ waitForApproval: true })` when the owner denies the\n * pending registration request. The `reason` field, when present, mirrors the\n * deny note the owner left in the dashboard.\n */\nexport class RegistrationDeniedError extends AstraSyncError {\n public readonly requestId: string;\n public readonly reason?: string;\n\n constructor(requestId: string, reason?: string) {\n super(\n `Registration request ${requestId} was denied by the account owner.${reason ? ` Reason: ${reason}` : ''}`,\n 403,\n 'REGISTRATION_DENIED'\n );\n this.name = 'RegistrationDeniedError';\n this.requestId = requestId;\n this.reason = reason;\n }\n}\n\n/**\n * Thrown by `register({ waitForApproval: true })` when the pending request\n * passes its 14-day TTL with no owner decision. The agent must re-submit.\n */\nexport class RegistrationExpiredError extends AstraSyncError {\n public readonly requestId: string;\n\n constructor(requestId: string) {\n super(\n `Registration request ${requestId} expired before the owner approved it. Submit a new registration request.`,\n 410,\n 'REGISTRATION_EXPIRED'\n );\n this.name = 'RegistrationExpiredError';\n this.requestId = requestId;\n }\n}\n\n/**\n * Thrown by `register({ waitForApproval: true })` when the caller's local\n * `timeoutMs` elapses before the owner makes a decision. The request is still\n * live server-side — poll `pollRegistration(requestId)` to resume waiting, or\n * call `waitForApproval` again with a longer timeout.\n */\nexport class RegistrationTimeoutError extends AstraSyncError {\n public readonly requestId: string;\n\n constructor(requestId: string) {\n super(\n `Timed out waiting for owner approval of registration request ${requestId}. The request is still active server-side; poll the request to resume waiting.`,\n 408,\n 'REGISTRATION_TIMEOUT'\n );\n this.name = 'RegistrationTimeoutError';\n this.requestId = requestId;\n }\n}\n","import { sdkFetch } from '../http';\nimport type {\n AstraSyncConfig,\n RegisterOptions,\n RegisterResult,\n WaitForApprovalOptions,\n PendingRegistrationResponse,\n PollRegistrationResult,\n RegistrationResponse,\n VerifyResponse,\n HealthResponse,\n ApiErrorResponse,\n AgentRecord,\n} from './types';\nimport {\n AstraSyncError,\n KYDRequiredError,\n AuthenticationError,\n RegistrationDeniedError,\n RegistrationExpiredError,\n RegistrationTimeoutError,\n} from './errors';\n\nconst DEFAULT_BASE_URL = 'https://astrasync.ai';\n\nconst sleep = (ms: number): Promise<void> => new Promise((r) => setTimeout(r, ms));\n\n/**\n * AstraSync SDK client for registering and managing AI agents.\n *\n * @example\n * ```typescript\n * const client = new AstraSync({ apiKey: 'kya_your_api_key' });\n * const result = await client.register({\n * name: 'My Agent',\n * model: { modelName: 'gpt-4o', modelProvider: 'openai', modelType: 'llm' },\n * });\n * ```\n *\n * For staging, pass `baseUrl: 'https://staging.astrasync.ai'`.\n */\nexport class AstraSync {\n private readonly baseUrl: string;\n private readonly apiKey?: string;\n private readonly email?: string;\n private readonly password?: string;\n private readonly privateKey?: string;\n private cachedJwt?: string;\n private jwtExpiresAt?: number;\n\n constructor(config: AstraSyncConfig = {}) {\n let raw = (config.baseUrl || process.env.ASTRASYNC_API_URL || DEFAULT_BASE_URL).replace(\n /\\/+$/,\n ''\n );\n // Round-10 (O2): tolerate the verify-side convention. `GatewayConfig.apiBaseUrl`\n // is documented as `https://astrasync.ai/api` (with /api), but\n // `AstraSyncConfig.baseUrl` is documented as the bare origin. Partners\n // passing the verify-style URL to the registration client hit a 404\n // because we'd then append `/api/agents/register` → double /api. Strip\n // a trailing `/api` and warn once so the partner can fix the source.\n if (raw.toLowerCase().endsWith('/api')) {\n raw = raw.slice(0, -'/api'.length);\n if (config.baseUrl && !config.silent) {\n // eslint-disable-next-line no-console\n console.warn(\n `[AstraSync] baseUrl '${config.baseUrl}' had a trailing /api — stripped to '${raw}'. ` +\n `Pass the bare origin (e.g. 'https://astrasync.ai' or 'https://staging.astrasync.ai') ` +\n `to AstraSync(). The /api suffix is the verify-gateway (GatewayConfig.apiBaseUrl) convention.`\n );\n }\n }\n this.baseUrl = raw;\n\n // Env fallback is opt-OUT: server-side wrappers (MCP tool handlers,\n // gateway adapters) pass `disableEnvFallback: true` so a no-credentials\n // call from a user-facing flow cannot silently authenticate as the host\n // process's platform-attribution key. CLIs / scripts that legitimately\n // rely on ASTRASYNC_API_KEY keep working under the default.\n this.apiKey = config.disableEnvFallback\n ? config.apiKey\n : config.apiKey || process.env.ASTRASYNC_API_KEY;\n this.email = config.email;\n this.password = config.password;\n this.privateKey = config.privateKey;\n\n // Defense-in-depth: warn when env fallback actually fires under the\n // default (non-strict) config. Surfaces the \"I'm running as platform\"\n // foot-gun before it becomes a security bug. Gated by !silent.\n if (\n !config.apiKey &&\n !config.disableEnvFallback &&\n process.env.ASTRASYNC_API_KEY &&\n !config.silent\n ) {\n // eslint-disable-next-line no-console\n console.warn(\n '[AstraSync] No apiKey passed to constructor; using process.env.ASTRASYNC_API_KEY. ' +\n 'If this code wraps user-facing flows (e.g. MCP tool handlers), pass ' +\n 'disableEnvFallback: true to prevent ambient credentials from impersonating callers. ' +\n 'See https://astrasync.ai/docs/agent-access#disableenvfallback for details.'\n );\n }\n\n if (!this.apiKey && !this.email) {\n throw new AuthenticationError(\n 'Authentication required. Provide apiKey, or email+password. ' +\n 'Set ASTRASYNC_API_KEY env var or pass config to constructor.'\n );\n }\n\n if (this.email && !this.password) {\n throw new AuthenticationError('Password is required when using email authentication.');\n }\n }\n\n /**\n * Register a new AI agent on the AstraSync KYA Platform.\n *\n * The backend response depends on auth context:\n * - **Crypto-keypair signed** (`privateKey` configured): synchronous 201,\n * returns `{ status: 'active', agent }`.\n * - **API-key only** (no signature): 202 pending, returns\n * `{ status: 'pending_approval', requestId, pollUrl, expiresAt }`. The\n * owner is notified by email and a dashboard alert is emitted; the agent\n * becomes active only after the owner approves.\n *\n * Blocking mode: pass `{ waitForApproval: true }` to have the SDK poll the\n * request until it resolves, then return the live agent record. The promise\n * rejects with `RegistrationDeniedError`, `RegistrationExpiredError`, or\n * `RegistrationTimeoutError` on the corresponding terminal states.\n *\n * @example Non-blocking (default — best for serverless / scheduled agents):\n * ```typescript\n * const result = await sdk.register({ name, pdlss });\n * if (result.status === 'pending_approval') {\n * storeRequestId(result.requestId);\n * return; // function exits; resume later via pollRegistration()\n * }\n * ```\n *\n * @example Blocking (best for long-running services + CLI):\n * ```typescript\n * const agent = await sdk.register({\n * name, pdlss, waitForApproval: true, timeoutMs: 600_000,\n * onPending: ({ ageMs }) => console.log(`waiting ${ageMs}ms`),\n * });\n * ```\n */\n async register(\n options: RegisterOptions & WaitForApprovalOptions\n ): Promise<RegisterResult | AgentRecord> {\n const body: Record<string, unknown> = {\n name: options.name,\n ...(options.description && { description: options.description }),\n ...(options.agentType && { agentType: options.agentType }),\n ...(options.apiEndpoint && { apiEndpoint: options.apiEndpoint }),\n ...(options.model && { model: options.model }),\n ...(options.framework && { framework: options.framework }),\n ...(options.protocols && { protocols: options.protocols }),\n ...(options.metadata && { metadata: options.metadata }),\n ...(options.pdlss && { pdlss: options.pdlss }),\n };\n\n const { status, body: raw } = await this.requestWithStatus<\n RegistrationResponse | PendingRegistrationResponse\n >('POST', '/api/agents/register', body);\n\n if (status === 201) {\n const activeBody = raw as RegistrationResponse;\n const active: RegisterResult = {\n status: 'active',\n agent: activeBody.data.agent,\n // Round-12 (F16): pass backend advisories through verbatim.\n // Pre-fix the SDK whitelisted five fields and silently dropped\n // `warnings`, which left partners with no signal that\n // `no_callback_endpoint` (or future advisories) had fired.\n ...(activeBody.warnings && { warnings: activeBody.warnings }),\n };\n return active;\n }\n\n // 202 Accepted — owner approval required.\n const pendingBody = raw as PendingRegistrationResponse;\n const pending: RegisterResult = {\n status: 'pending_approval',\n requestId: pendingBody.requestId,\n expiresAt: pendingBody.expiresAt,\n pollUrl: pendingBody.pollUrl,\n message: pendingBody.message,\n // Round-12 (F16): same pass-through on the pending path.\n ...(pendingBody.warnings && { warnings: pendingBody.warnings }),\n };\n\n if (!options.waitForApproval) return pending;\n\n return this.waitForApproval(pendingBody.requestId, options);\n }\n\n /**\n * Poll the current state of a pending-approval registration request.\n *\n * Useful for caller-driven polling when `waitForApproval: false` (the\n * default). The endpoint is unauthenticated — pass the `requestId` that\n * was returned from the 202 response.\n *\n * @returns `state: 'pending'` while awaiting; `'approved'` carries the\n * minted agent in `agent`; `'denied'` may carry the owner's\n * `reason`; `'expired'` is terminal after 14 days.\n */\n async pollRegistration(requestId: string): Promise<PollRegistrationResult> {\n const url = `${this.baseUrl}/api/agents/request-registration/${requestId}`;\n const res = await sdkFetch(url, { headers: { Accept: 'application/json' } });\n if (!res.ok) {\n const errBody = (await res.json().catch(() => ({}))) as ApiErrorResponse;\n throw new AstraSyncError(\n errBody.error || `pollRegistration failed: ${res.status}`,\n res.status,\n errBody.code\n );\n }\n return (await res.json()) as PollRegistrationResult;\n }\n\n /**\n * Block until a pending registration request resolves to a terminal state.\n * Resolves to the live `AgentRecord` on approval; rejects with the matching\n * Registration*Error on deny/expire/timeout. Usually called via\n * `register({ waitForApproval: true })`, but exposed for callers that want\n * to fire-and-forget the initial register call and resume waiting later\n * (e.g. after restoring a stored `requestId` on cold start).\n */\n async waitForApproval(\n requestId: string,\n options: WaitForApprovalOptions = {}\n ): Promise<AgentRecord> {\n const timeoutMs = options.timeoutMs ?? 10 * 60 * 1000;\n const pollIntervalMs = options.pollIntervalMs ?? 5_000;\n const start = Date.now();\n const deadline = start + timeoutMs;\n\n while (Date.now() < deadline) {\n const result = await this.pollRegistration(requestId);\n const ageMs = Date.now() - start;\n options.onPending?.({ requestId, ageMs });\n\n if (result.state === 'approved') {\n if (!result.agent) {\n throw new AstraSyncError(\n `Registration ${requestId} reported approved but no agent payload returned.`,\n 500\n );\n }\n return result.agent;\n }\n if (result.state === 'denied') {\n throw new RegistrationDeniedError(requestId, result.reason);\n }\n if (result.state === 'expired') {\n throw new RegistrationExpiredError(requestId);\n }\n await sleep(pollIntervalMs);\n }\n throw new RegistrationTimeoutError(requestId);\n }\n\n /**\n * Look up an agent's public profile by ASTRA ID or UUID.\n */\n async verify(agentId: string): Promise<VerifyResponse> {\n return this.request<VerifyResponse>('GET', `/api/agents/verify/${agentId}`);\n }\n\n /**\n * Check API health.\n */\n async health(): Promise<HealthResponse> {\n const res = await sdkFetch(`${this.baseUrl}/api/health/`);\n if (!res.ok) {\n throw new AstraSyncError(`Health check failed: ${res.status}`, res.status);\n }\n return res.json() as Promise<HealthResponse>;\n }\n\n // ── Private helpers ──────────────────────────────────────────────\n\n private async request<T>(method: string, endpoint: string, body?: unknown): Promise<T> {\n const { body: parsed } = await this.requestWithStatus<T>(method, endpoint, body);\n return parsed;\n }\n\n /**\n * Variant of {@link request} that also returns the HTTP status code, so\n * callers can branch on 201 vs 202 (or other success codes) without losing\n * type information about the response body.\n */\n private async requestWithStatus<T>(\n method: string,\n endpoint: string,\n body?: unknown\n ): Promise<{ status: number; body: T }> {\n const url = `${this.baseUrl}${endpoint}`;\n const headers: Record<string, string> = {\n 'Content-Type': 'application/json',\n };\n\n // Set auth header\n const token = await this.getAuthToken();\n headers['Authorization'] = `Bearer ${token}`;\n\n // Sign request if private key is configured\n if (this.privateKey) {\n const signature = await this.signRequest(method, endpoint, body || {});\n headers['X-AstraSync-Signature'] = signature;\n }\n\n const res = await sdkFetch(url, {\n method,\n headers,\n ...(body ? { body: JSON.stringify(body) } : {}),\n });\n\n if (!res.ok) {\n const errorBody = (await res\n .json()\n .catch(() => ({ error: res.statusText }))) as ApiErrorResponse;\n\n // Handle KYD_REQUIRED specifically\n if (res.status === 403 && errorBody.code === 'KYD_REQUIRED') {\n throw new KYDRequiredError(errorBody);\n }\n\n throw new AstraSyncError(\n errorBody.error || `Request failed: ${res.status}`,\n res.status,\n errorBody.code\n );\n }\n\n return { status: res.status, body: (await res.json()) as T };\n }\n\n private async getAuthToken(): Promise<string> {\n // API key auth — use directly\n if (this.apiKey) {\n return this.apiKey;\n }\n\n // Email+password — login and cache JWT\n if (this.cachedJwt && this.jwtExpiresAt && Date.now() < this.jwtExpiresAt) {\n return this.cachedJwt;\n }\n\n const res = await sdkFetch(`${this.baseUrl}/api/auth/login`, {\n method: 'POST',\n headers: { 'Content-Type': 'application/json' },\n body: JSON.stringify({ email: this.email, password: this.password }),\n });\n\n if (!res.ok) {\n const errorBody = (await res.json().catch(() => ({}))) as Record<string, unknown>;\n throw new AuthenticationError(\n (errorBody.message as string) || (errorBody.error as string) || 'Login failed'\n );\n }\n\n const data = (await res.json()) as { data: { token: string } };\n this.cachedJwt = data.data.token;\n // Cache for 6 days (tokens expire in 7)\n this.jwtExpiresAt = Date.now() + 6 * 24 * 60 * 60 * 1000;\n\n return this.cachedJwt;\n }\n\n /**\n * Sign a request using secp256k1 (ethers.js).\n * Canonical message format: METHOD:ENDPOINT:SORTED_JSON_BODY\n * Must match apps/backend/src/services/signature-verify.service.ts exactly.\n */\n private async signRequest(method: string, endpoint: string, body: unknown): Promise<string> {\n const { Wallet } = await import('ethers');\n const sorted = this.sortObjectKeys(body);\n const canonical = `${method}:${endpoint}:${JSON.stringify(sorted)}`;\n const wallet = new Wallet(this.privateKey!);\n return wallet.signMessage(canonical);\n }\n\n /** Recursively sort object keys for canonical JSON representation. */\n private sortObjectKeys(obj: unknown): unknown {\n if (obj === null || typeof obj !== 'object') {\n return obj;\n }\n if (Array.isArray(obj)) {\n return obj.map((item) => this.sortObjectKeys(item));\n }\n const sorted: Record<string, unknown> = {};\n for (const key of Object.keys(obj).sort()) {\n sorted[key] = this.sortObjectKeys((obj as Record<string, unknown>)[key]);\n }\n return sorted;\n }\n}\n","/**\n * Guidance envelope for credentials-required cases.\n *\n * A single shared source of truth so partners writing their own wrappers\n * (custom MCP servers, Express middleware around registration, gateway\n * adapters) consume a single source of truth instead of re-implementing the\n * five-step boilerplate.\n *\n * The envelope is what an agent (or wrapping MCP client) sees when it calls\n * `register_agent` with no AstraSync credentials. It tells the calling agent\n * (a) what failed (`status: 'credentials_required'`), (b) the keyless\n * registration ACTION endpoint (`registrationUrl` — POST-able, not the human\n * dashboard), (c) where the relevant docs are (`documentationUrl`), and (d) the\n * ordered next-actions (`steps`).\n */\n\nexport interface GuidanceEnvelope {\n /**\n * Single-literal today. Expand to a union (e.g.\n * `'credentials_required' | 'kyd_required' | …`) when a second guidance\n * status emerges. Don't pre-emptively widen — the literal pins the shape.\n */\n status: 'credentials_required';\n message: string;\n guidance: {\n message: string;\n registrationUrl: string;\n documentationUrl: string;\n steps: string[];\n };\n}\n\nexport interface BuildGuidanceParams {\n /**\n * Bare origin of the AstraSync deployment the caller should register at,\n * e.g. `https://astrasync.ai` or `https://staging.astrasync.ai`. No\n * trailing slash, no `/api` suffix — registrationUrl and documentationUrl\n * are templated relative to this origin.\n */\n origin: string;\n /**\n * Overrides the top-level `message` (the short summary the agent sees).\n * Defaults to the error message from the SDK's `AuthenticationError`\n * when present, else a generic \"credentials required\" line.\n */\n message?: string;\n /**\n * Overrides the documentation path. Defaults to `/docs/agent-access`.\n */\n documentationPath?: string;\n}\n\n/**\n * Build the credentials-required guidance envelope.\n *\n * This is the canonical builder — MCP wrappers (`agent-registration.ts`),\n * Express middleware in custom integrations, and any other partner-side\n * wrapper that needs to surface \"you need to register\" should call this\n * rather than reconstructing the shape inline. Inline reconstruction\n * historically led to drift between wrappers; this consolidates it.\n *\n * @example\n * ```ts\n * import { buildGuidance } from '@astrasyncai/verification-gateway';\n *\n * try {\n * const sdk = new AstraSync({ apiKey: callerApiKey, disableEnvFallback: true });\n * // ...\n * } catch (err) {\n * if (err instanceof AuthenticationError) {\n * return buildGuidance({ origin: 'https://astrasync.ai', message: err.message });\n * }\n * throw err;\n * }\n * ```\n */\nexport function buildGuidance(params: BuildGuidanceParams): GuidanceEnvelope {\n const origin = params.origin.replace(/\\/+$/, '');\n const docsPath = params.documentationPath ?? '/docs/agent-access';\n const message = params.message ?? 'AstraSync registration requires credentials.';\n\n return {\n status: 'credentials_required',\n message,\n guidance: {\n message:\n \"Register either with an agent-scoped API key (the recommended credentialed path) OR, if you hold no credentials, via the owner's email using request_registration. Never send a password or private key over the wire.\",\n // 3.0.0: registrationUrl is the agent-actionable KEYLESS endpoint, not the\n // human dashboard `/agents/register` (an auth-walled page an agent can't\n // use). documentationUrl carries the machine-readable contract.\n registrationUrl: `${origin}/api/agents/request-registration`,\n documentationUrl: `${origin}${docsPath.startsWith('/') ? docsPath : `/${docsPath}`}`,\n steps: [\n 'Credentialed path (recommended): have your human mint an agent-scoped API key at Settings → API Keys, then re-call register_agent with apiKey set. An agent holding its own scoped kya_ key is fine and intended.',\n \"No-credentials path: call request_registration({ name, ownerEmail, ... }) with the human owner's email — the only bootstrap credential. No API key is involved.\",\n 'Include as much metadata as you can in the registration — especially model ({ modelName, modelProvider }) and framework ({ frameworkName, frameworkVersion }). Declared platform/model metadata directly improves your trust score and attributes your traffic correctly.',\n 'The owner approves via an emailed link (first time, they create an account and complete a quick verification).',\n 'Use poll_registration({ requestId }) once the owner confirms approval to retrieve the astraId.',\n 'Never transmit a password or private key over the MCP wire — those are never required.',\n ],\n },\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;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AAM,UAAU,OAAO,WAAW;AAElC,SAAO;AAAA,IACL,QAAQ;AAAA,IACR;AAAA,IACA,UAAU;AAAA,MACR,SACE;AAAA;AAAA;AAAA;AAAA,MAIF,iBAAiB,GAAG,MAAM;AAAA,MAC1B,kBAAkB,GAAG,MAAM,GAAG,SAAS,WAAW,GAAG,IAAI,WAAW,IAAI,QAAQ,EAAE;AAAA,MAClF,OAAO;AAAA,QACL;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,MACF;AAAA,IACF;AAAA,EACF;AACF;","names":["has"]}
@@ -1,5 +1,5 @@
1
1
  // src/version.ts
2
- var SDK_VERSION = "4.5.0";
2
+ var SDK_VERSION = "4.5.1";
3
3
 
4
4
  // src/http.ts
5
5
  var SDK_USER_AGENT = `astrasync-sdk/${SDK_VERSION}`;
@@ -375,6 +375,7 @@ function buildGuidance(params) {
375
375
  steps: [
376
376
  "Credentialed path (recommended): have your human mint an agent-scoped API key at Settings \u2192 API Keys, then re-call register_agent with apiKey set. An agent holding its own scoped kya_ key is fine and intended.",
377
377
  "No-credentials path: call request_registration({ name, ownerEmail, ... }) with the human owner's email \u2014 the only bootstrap credential. No API key is involved.",
378
+ "Include as much metadata as you can in the registration \u2014 especially model ({ modelName, modelProvider }) and framework ({ frameworkName, frameworkVersion }). Declared platform/model metadata directly improves your trust score and attributes your traffic correctly.",
378
379
  "The owner approves via an emailed link (first time, they create an account and complete a quick verification).",
379
380
  "Use poll_registration({ requestId }) once the owner confirms approval to retrieve the astraId.",
380
381
  "Never transmit a password or private key over the MCP wire \u2014 those are never required."