@tangle-network/agent-runtime 0.349.0 → 0.350.2

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 (126) hide show
  1. package/dist/{activation-tNGW73Y9.js → activation-CfJMyzEs.js} +12 -14
  2. package/dist/{activation-tNGW73Y9.js.map → activation-CfJMyzEs.js.map} +1 -1
  3. package/dist/{activation-wBipBkCf.d.ts → activation-DyiHrTlS.d.ts} +2 -24
  4. package/dist/agent.d.ts +8 -12
  5. package/dist/agent.js +9 -12
  6. package/dist/agent.js.map +1 -1
  7. package/dist/{analyst-loop-DZw5QWT9.js → analyst-loop-BZvXCDKy.js} +2 -3
  8. package/dist/{analyst-loop-DZw5QWT9.js.map → analyst-loop-BZvXCDKy.js.map} +1 -1
  9. package/dist/analyst-loop.d.ts +3 -5
  10. package/dist/analyst-loop.js +1 -2
  11. package/dist/{bundle-1xaJEgjq.js → bundle-Ze8pd07a.js} +3 -4
  12. package/dist/{bundle-1xaJEgjq.js.map → bundle-Ze8pd07a.js.map} +1 -1
  13. package/dist/candidate-execution/index.d.ts +13 -33
  14. package/dist/candidate-execution/index.js +16 -18
  15. package/dist/candidate-execution/index.js.map +1 -1
  16. package/dist/{coordination-manager-B2Z_MmL9.js → coordination-manager-BkVfWlMz.js} +101 -132
  17. package/dist/{coordination-manager-B2Z_MmL9.js.map → coordination-manager-BkVfWlMz.js.map} +1 -1
  18. package/dist/{delegate-Dr-63jFl.js → delegate-DgEie4ad.js} +19 -21
  19. package/dist/delegate-DgEie4ad.js.map +1 -0
  20. package/dist/durable.d.ts +13 -23
  21. package/dist/durable.js +48 -43
  22. package/dist/durable.js.map +1 -1
  23. package/dist/{errors-DodWX-cb.js → errors-wuhGvpE3.js} +2 -3
  24. package/dist/{errors-DodWX-cb.js.map → errors-wuhGvpE3.js.map} +1 -1
  25. package/dist/{graph-DPejYB3C.js → graph-Cx0FhKSE.js} +191 -14
  26. package/dist/graph-Cx0FhKSE.js.map +1 -0
  27. package/dist/{improve-DwSahPi1.js → improve-i0HU1-aa.js} +35 -53
  28. package/dist/{improve-DwSahPi1.js.map → improve-i0HU1-aa.js.map} +1 -1
  29. package/dist/{improvement-adapter-sIthWkcN.d.ts → improvement-adapter-D5GRU1eY.d.ts} +2 -6
  30. package/dist/index.d.ts +41 -89
  31. package/dist/index.js +43 -61
  32. package/dist/index.js.map +1 -1
  33. package/dist/intelligence.d.ts +39 -59
  34. package/dist/intelligence.js +23 -33
  35. package/dist/intelligence.js.map +1 -1
  36. package/dist/kernel.d.ts +5 -5
  37. package/dist/kernel.js +11 -11
  38. package/dist/{loop-runner-CP6MfO1b.js → loop-runner-BwN9MhdP.js} +5 -6
  39. package/dist/{loop-runner-CP6MfO1b.js.map → loop-runner-BwN9MhdP.js.map} +1 -1
  40. package/dist/{loop-runner-C6pGq-2l.d.ts → loop-runner-DvfOXVx9.d.ts} +3 -5
  41. package/dist/loop-runner-bin.d.ts +5 -8
  42. package/dist/loop-runner-bin.js +2 -3
  43. package/dist/mcp/bin.js +6 -8
  44. package/dist/mcp/bin.js.map +1 -1
  45. package/dist/mcp/index.d.ts +8 -18
  46. package/dist/mcp/index.js +17 -25
  47. package/dist/mcp/index.js.map +1 -1
  48. package/dist/mcp/memory-bin.js +4 -6
  49. package/dist/mcp/memory-bin.js.map +1 -1
  50. package/dist/{model-policy-CyCUwHed.js → model-policy-GSxWwP-b.js} +11 -13
  51. package/dist/{model-policy-CyCUwHed.js.map → model-policy-GSxWwP-b.js.map} +1 -1
  52. package/dist/placement.d.ts +12 -14
  53. package/dist/placement.js +1 -2
  54. package/dist/platform.d.ts +7 -13
  55. package/dist/platform.js +3 -6
  56. package/dist/platform.js.map +1 -1
  57. package/dist/{prepare-B9wWffjO.js → prepare-DE8TQnLu.js} +49 -69
  58. package/dist/{prepare-B9wWffjO.js.map → prepare-DE8TQnLu.js.map} +1 -1
  59. package/dist/{profile-JLJd2wFG.js → profile-CAhZDW2T.js} +58 -92
  60. package/dist/profile-CAhZDW2T.js.map +1 -0
  61. package/dist/{profile-materialization-bPm0gGLO.d.ts → profile-materialization-BRY22Oh8.d.ts} +1 -3
  62. package/dist/profiles.d.ts +25 -12
  63. package/dist/profiles.js +52 -11
  64. package/dist/profiles.js.map +1 -1
  65. package/dist/{protected-model-port-DVVh-hEk.d.ts → protected-model-port-IKqhTypD.d.ts} +2 -14
  66. package/dist/{protected-redaction-DFCeo4vg.js → protected-redaction-DilFZch5.js} +2 -3
  67. package/dist/{protected-redaction-DFCeo4vg.js.map → protected-redaction-DilFZch5.js.map} +1 -1
  68. package/dist/{provision-supervisor-C4v2vqDo.js → provision-supervisor-Bde_FF0R.js} +11 -15
  69. package/dist/{provision-supervisor-C4v2vqDo.js.map → provision-supervisor-Bde_FF0R.js.map} +1 -1
  70. package/dist/{record-events-D93DkpAx.js → record-events-B2GUgYdz.js} +12 -14
  71. package/dist/{record-events-D93DkpAx.js.map → record-events-B2GUgYdz.js.map} +1 -1
  72. package/dist/{run-cancellation-CzFhQGMa.js → run-cancellation-BLy_Zz-w.js} +6 -7
  73. package/dist/{run-cancellation-CzFhQGMa.js.map → run-cancellation-BLy_Zz-w.js.map} +1 -1
  74. package/dist/{runtime-CsvGCQpl.js → runtime-6Ec9sHRe.js} +648 -215
  75. package/dist/runtime-6Ec9sHRe.js.map +1 -0
  76. package/dist/{runtime-hooks-tXpAarhW.js → runtime-hooks-CsW2pfFk.js} +2 -3
  77. package/dist/{runtime-hooks-tXpAarhW.js.map → runtime-hooks-CsW2pfFk.js.map} +1 -1
  78. package/dist/{runtime-hooks-nsqxSUFL.d.ts → runtime-hooks-ZQqPw-0g.d.ts} +1 -3
  79. package/dist/{sandbox-profile-compat-DtuJWFrM.js → sandbox-profile-compat-BxMQ1VXv.js} +61 -43
  80. package/dist/sandbox-profile-compat-BxMQ1VXv.js.map +1 -0
  81. package/dist/{search-executor-CCb82Umc.js → search-executor-B7g_5Wjl.js} +10 -15
  82. package/dist/{search-executor-CCb82Umc.js.map → search-executor-B7g_5Wjl.js.map} +1 -1
  83. package/dist/{server-CKPwZU-I.js → server-fvEMwGMQ.js} +19 -30
  84. package/dist/{server-CKPwZU-I.js.map → server-fvEMwGMQ.js.map} +1 -1
  85. package/dist/{structural-rollout-DylC_fwU.js → structural-rollout-B86bSixU.js} +69 -70
  86. package/dist/structural-rollout-B86bSixU.js.map +1 -0
  87. package/dist/{substrate-CGDFTSRh.js → substrate-Db2pp6y3.js} +2 -3
  88. package/dist/{substrate-CGDFTSRh.js.map → substrate-Db2pp6y3.js.map} +1 -1
  89. package/dist/{supervise-BGfm2GlY.js → supervise-CaeZcgAW.js} +460 -195
  90. package/dist/supervise-CaeZcgAW.js.map +1 -0
  91. package/dist/{supervisor-wS9Ehz_x.js → supervisor-C1OePYE-.js} +511 -626
  92. package/dist/supervisor-C1OePYE-.js.map +1 -0
  93. package/dist/{task-queue-0fKkoweu.d.ts → task-queue-kefGy79U.d.ts} +1 -3
  94. package/dist/task-queue.d.ts +1 -1
  95. package/dist/task-queue.js +1 -2
  96. package/dist/testing.d.ts +7 -15
  97. package/dist/testing.js +241 -244
  98. package/dist/testing.js.map +1 -1
  99. package/dist/tool-loop.d.ts +16 -19
  100. package/dist/tool-loop.js +2 -3
  101. package/dist/{tool-server-XV4aJwoQ.js → tool-server-CwuYeW_Z.js} +3 -4
  102. package/dist/{tool-server-XV4aJwoQ.js.map → tool-server-CwuYeW_Z.js.map} +1 -1
  103. package/dist/{top-snapshot-CflmaDgk.js → top-snapshot-ChwpTr7A.js} +4 -5
  104. package/dist/{top-snapshot-CflmaDgk.js.map → top-snapshot-ChwpTr7A.js.map} +1 -1
  105. package/dist/tui/bin.js +7 -9
  106. package/dist/tui/bin.js.map +1 -1
  107. package/dist/tui/index.d.ts +3 -5
  108. package/dist/tui/index.js +2 -2
  109. package/dist/{types-C8BGOCBn.d.ts → types-Fowuwdz2.d.ts} +364 -483
  110. package/dist/{types-Cwrea-bU.d.ts → types-qsqfyQoY.d.ts} +1 -3
  111. package/dist/workspace-store/index.d.ts +12 -22
  112. package/dist/workspace-store/index.js +4 -7
  113. package/dist/workspace-store/index.js.map +1 -1
  114. package/dist/{workspace-streams-BiS4ABah.d.ts → workspace-streams-Dq2Fzk3c.d.ts} +1 -11
  115. package/package.json +25 -25
  116. package/skills/agent-graphs/SKILL.md +17 -4
  117. package/skills/be-ambitious/SKILL.md +46 -0
  118. package/skills/graph-designer/SKILL.md +9 -2
  119. package/dist/delegate-Dr-63jFl.js.map +0 -1
  120. package/dist/graph-DPejYB3C.js.map +0 -1
  121. package/dist/profile-JLJd2wFG.js.map +0 -1
  122. package/dist/runtime-CsvGCQpl.js.map +0 -1
  123. package/dist/sandbox-profile-compat-DtuJWFrM.js.map +0 -1
  124. package/dist/structural-rollout-DylC_fwU.js.map +0 -1
  125. package/dist/supervise-BGfm2GlY.js.map +0 -1
  126. package/dist/supervisor-wS9Ehz_x.js.map +0 -1
package/dist/platform.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { isRecord } from "@tangle-network/agent-core";
2
- //#region src/platform/auth.ts
2
+ // src/platform/auth.ts
3
3
  /**
4
4
  * Server-side client for the Tangle platform's cross-site SSO bridge.
5
5
  *
@@ -101,8 +101,7 @@ var PlatformAuthClient = class {
101
101
  return parseExchangeResult(body, res.status);
102
102
  }
103
103
  };
104
- //#endregion
105
- //#region src/platform/integrations.ts
104
+ // src/platform/integrations.ts
106
105
  /** Thrown when a `PlatformHubClient` request returns a non-success status. */
107
106
  var PlatformHubError = class extends Error {
108
107
  status;
@@ -230,8 +229,7 @@ var PlatformHubClient = class {
230
229
  return parsed.data;
231
230
  }
232
231
  };
233
- //#endregion
234
- //#region src/platform/oidc.ts
232
+ // src/platform/oidc.ts
235
233
  /**
236
234
  * OpenID Connect client for the Tangle authorization server. Identity tokens
237
235
  * are not platform API keys. Resource scopes and audiences must be registered
@@ -476,7 +474,6 @@ var PlatformOidcClient = class {
476
474
  });
477
475
  }
478
476
  };
479
- //#endregion
480
477
  export { PlatformAuthClient, PlatformAuthError, PlatformHubClient, PlatformHubError, PlatformOidcClient, createPkcePair };
481
478
 
482
479
  //# sourceMappingURL=platform.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"platform.js","names":["isNonemptyString"],"sources":["../src/platform/auth.ts","../src/platform/integrations.ts","../src/platform/oidc.ts"],"sourcesContent":["/**\n * Server-side client for the Tangle platform's cross-site SSO bridge.\n *\n * Consumer apps (gtm-agent, tax-agent, legal-agent, creative-agent, …)\n * use this to:\n * 1. Build an /authorize URL that lands the user on id.tangle.tools\n * and brings them back with a single-use code.\n * 2. Exchange that code for an API key + the user's identity.\n *\n * The platform endpoint contract is documented in\n * the cross-site route in agent-container's platform API. This client only\n * speaks HTTP — no SDK weight, no transitive deps.\n */\n\nimport { isRecord } from '@tangle-network/agent-core'\n\nexport interface PlatformAuthClientOptions {\n /** Platform base URL, e.g. `https://id.tangle.tools`. */\n baseUrl: string\n /** App id as registered in the platform's TRUSTED_APPS registry. */\n appId: string\n /** Override the global fetch (useful for tests + edge runtimes). */\n fetchImpl?: typeof fetch\n}\n\nexport interface AuthorizeUrlOptions {\n /** Required CSRF token; the consumer verifies it on the callback. */\n state: string\n /**\n * Final redirect URI. Must be one of the URIs registered for `appId`\n * on the platform. Omit to use the first registered URI.\n */\n redirectUri?: string\n /** Force the login screen even if a session is already active. */\n prompt?: 'login'\n /** Pre-fill the email field on the login screen. */\n email?: string\n}\n\nexport interface ExchangeCodeResult {\n apiKey: string\n emailVerified: true\n user: {\n id: string\n email: string\n name?: string | null\n }\n /** Null when the platform could not provide a subscription. This is not a paid-access grant. */\n plan: {\n tier: string\n } | null\n}\n\n/** Thrown when a `PlatformAuthClient` request returns a non-success status. */\nexport class PlatformAuthError extends Error {\n constructor(\n message: string,\n public readonly status: number,\n public readonly body: unknown,\n ) {\n super(message)\n this.name = 'PlatformAuthError'\n }\n}\n\nfunction isNonemptyString(value: unknown): value is string {\n return typeof value === 'string' && value.trim().length > 0\n}\n\n/** Validate the platform's verified identity before consumers create a local session. */\nfunction parseExchangeResult(body: unknown, status: number): ExchangeCodeResult {\n const invalid = (): never => {\n // A successful but malformed response can contain the one-time API secret.\n throw new PlatformAuthError(\n 'Platform exchange response has no valid verified identity',\n status,\n { code: 'INVALID_EXCHANGE_RESPONSE' },\n )\n }\n if (\n !isRecord(body) ||\n !isNonemptyString(body.apiKey) ||\n body.emailVerified !== true ||\n !isRecord(body.user)\n )\n return invalid()\n const user = body.user\n if (!isNonemptyString(user.id) || !isNonemptyString(user.email)) return invalid()\n const email = user.email.trim()\n if (\n email.length > 320 ||\n !/^[^\\s@]+@[^\\s@]+\\.[^\\s@]+$/.test(email) ||\n /(?:@users\\.noreply\\.tangle\\.tools$|^0x[a-f0-9]{40}@tangle\\.tools$)/i.test(email)\n )\n return invalid()\n if (user.name !== undefined && user.name !== null && typeof user.name !== 'string')\n return invalid()\n let plan: ExchangeCodeResult['plan'] = null\n if (body.subscription !== undefined) {\n if (!isRecord(body.subscription) || !isNonemptyString(body.subscription.plan)) return invalid()\n plan = { tier: body.subscription.plan }\n }\n return {\n apiKey: body.apiKey,\n emailVerified: true,\n user: { id: user.id, email, ...(user.name !== undefined ? { name: user.name } : {}) },\n plan,\n }\n}\n\n/** HTTP client for the Tangle Platform SSO: builds authorize URLs and exchanges auth codes for API keys. */\nexport class PlatformAuthClient {\n private readonly baseUrl: string\n private readonly appId: string\n private readonly fetchImpl: typeof fetch\n\n constructor(options: PlatformAuthClientOptions) {\n if (!options.baseUrl) throw new Error('PlatformAuthClient: baseUrl is required')\n if (!options.appId) throw new Error('PlatformAuthClient: appId is required')\n this.baseUrl = options.baseUrl.replace(/\\/+$/, '')\n this.appId = options.appId\n this.fetchImpl =\n options.fetchImpl ??\n ((url: Parameters<typeof fetch>[0], init?: Parameters<typeof fetch>[1]) => fetch(url, init))\n }\n\n /**\n * Build the URL the user is redirected to in order to start SSO.\n * The platform redirects back to one of `appId`'s registered\n * `redirectUris` with `?code=...&app=...&state=...`.\n */\n authorizeUrl(options: AuthorizeUrlOptions): string {\n if (!options.state) {\n throw new Error('PlatformAuthClient.authorizeUrl: state is required for CSRF')\n }\n const url = new URL('/cross-site/authorize', this.baseUrl)\n url.searchParams.set('app', this.appId)\n url.searchParams.set('state', options.state)\n if (options.redirectUri) url.searchParams.set('redirect', options.redirectUri)\n if (options.prompt) url.searchParams.set('prompt', options.prompt)\n if (options.email) url.searchParams.set('email', options.email)\n return url.toString()\n }\n\n /**\n * Exchange a single-use auth code (delivered to the consumer's\n * callback by the platform) for an API key + the user's identity.\n * Codes are single-use and expire ~5 minutes after issue.\n */\n async exchange(code: string): Promise<ExchangeCodeResult> {\n if (!code) throw new Error('PlatformAuthClient.exchange: code is required')\n const res = await this.fetchImpl(`${this.baseUrl}/cross-site/exchange`, {\n method: 'POST',\n headers: { 'content-type': 'application/json' },\n body: JSON.stringify({ code, app: this.appId }),\n })\n const body = await res.json().catch(() => null)\n if (!res.ok) {\n const message =\n body && typeof body === 'object' && 'error' in body && typeof body.error === 'string'\n ? body.error\n : `Platform exchange failed (${res.status})`\n throw new PlatformAuthError(message, res.status, body)\n }\n return parseExchangeResult(body, res.status)\n }\n}\n","/**\n * Server-side client for the Tangle platform's integration hub\n * (`/v1/hub/*`). Consumer apps use this instead of rolling their own\n * OAuth + connection tables.\n *\n * Auth: the caller supplies a bearer (either the user's API key from\n * cross-site exchange, or a platform service token) on construction.\n *\n * Endpoint contract (authoritative): the platform API's hub contract\n * and hub route (both in agent-container's platform API). The platform wraps every response in\n * `{ success, data }`; non-2xx or `success:false` surfaces as `PlatformHubError`\n * carrying the real upstream status.\n */\n\nexport interface PlatformHubClientOptions {\n /** Platform base URL, e.g. `https://id.tangle.tools`. */\n baseUrl: string\n /** Bearer credential — user API key or service token. */\n bearer: string\n /** Override fetch (tests + edge runtimes). */\n fetchImpl?: typeof fetch\n}\n\n/** A live integration connection, as returned by `/v1/hub/connections`. */\nexport interface PlatformConnection {\n id: string\n providerId: string\n displayName: string\n accountDisplay: string | null\n scopes: string[]\n status: 'active' | 'revoked' | 'unhealthy' | 'reconnect_required' | (string & {})\n health: 'unknown' | 'healthy' | 'unhealthy' | 'rate_limited' | (string & {})\n createdAt: string\n updatedAt: string\n lastUsedAt: string | null\n}\n\n/** A connectable provider in the catalog (`/v1/hub/providers`). */\nexport interface PlatformCatalogProvider {\n providerId: string\n title?: string\n authKind?: string\n category?: string\n scopes?: string[]\n capabilityCount?: number\n native?: boolean\n /** Whether the OAuth app's credentials are wired — the UI offers Connect\n * only when true. */\n configured?: boolean\n [k: string]: unknown\n}\n\nexport interface CatalogResult {\n providers: PlatformCatalogProvider[]\n /** Count of substrate-bundled connectors behind the catalog. */\n substrateBundled?: number\n [k: string]: unknown\n}\n\nexport interface StartAuthInput {\n /** The provider to connect (goes in the URL path). */\n providerId: string\n /** Accepted for interface compatibility; the platform's start endpoint is\n * provider-level and does not consume a connector id. */\n connectorId?: string\n /** Where the platform redirects the user back to after OAuth. */\n returnUrl: string\n /** Accepted for interface compatibility; not consumed by the start endpoint. */\n requestedScopes?: string[]\n /** CLI flow flag — affects the platform's post-auth redirect handling. */\n cli?: boolean\n}\n\nexport interface StartAuthResult {\n /** The URL to send the user to. Normalized across the platform's two start\n * branches: github returns `authorizationUrl`, substrate returns\n * `redirectUrl`. */\n authorizationUrl: string\n state: string\n expiresAt?: string\n scopes?: string[]\n}\n\nexport interface ConnectionHealth {\n status: 'unknown' | 'healthy' | 'unhealthy' | 'rate_limited' | (string & {})\n checkedAt: string\n error?: { code: string; message: string }\n}\n\nexport interface ConnectionHealthResult {\n connection: PlatformConnection\n health: ConnectionHealth\n}\n\n/** Last-known health for a connection, derived from the connection row. */\nexport interface HealthCheck {\n connectionId: string\n providerId: string\n /** Mirrors `PlatformConnection.health`. */\n status: ConnectionHealth['status']\n checkedAt?: string\n}\n\nexport interface MintTokenInput {\n /** The hub action the token authorizes (e.g. `slack.chat.postMessage`). */\n actionPath: string\n /** Bind to a specific connection, or … */\n connectionId?: string\n /** … resolve the connection by provider for the calling user. */\n provider?: string\n}\n\nexport interface MintTokenResult {\n tokenId: string\n token: string\n expiresAt: string\n}\n\nexport interface ExecInput {\n /** The hub action path to execute. */\n path: string\n input?: unknown\n connectionId?: string\n}\n\nexport interface PlatformHubStatus {\n contract?: unknown\n principal: { kind: string; userId: string; [k: string]: unknown }\n connections: { connectedProviderCount: number; unhealthyProviderCount: number }\n}\n\n/** Thrown when a `PlatformHubClient` request returns a non-success status. */\nexport class PlatformHubError extends Error {\n constructor(\n message: string,\n public readonly status: number,\n public readonly code: string | undefined,\n public readonly body: unknown,\n ) {\n super(message)\n this.name = 'PlatformHubError'\n }\n}\n\ninterface PlatformEnvelope<T> {\n success: boolean\n data?: T\n error?: { code?: string; message?: string } | string\n}\n\n/** HTTP client for the Tangle Platform Hub API: provider catalog, connection flow, and status. */\nexport class PlatformHubClient {\n private readonly baseUrl: string\n private readonly bearer: string\n private readonly fetchImpl: typeof fetch\n\n constructor(options: PlatformHubClientOptions) {\n if (!options.baseUrl) throw new Error('PlatformHubClient: baseUrl is required')\n if (!options.bearer) throw new Error('PlatformHubClient: bearer is required')\n this.baseUrl = options.baseUrl.replace(/\\/+$/, '')\n this.bearer = options.bearer\n this.fetchImpl =\n options.fetchImpl ??\n ((url: Parameters<typeof fetch>[0], init?: Parameters<typeof fetch>[1]) => fetch(url, init))\n }\n\n /** GET /v1/hub/providers — the connectable provider catalog. */\n catalog(): Promise<CatalogResult> {\n return this.request('GET', '/v1/hub/providers')\n }\n\n /** GET /v1/hub/connections — the calling user's live connections. */\n async listConnections(): Promise<PlatformConnection[]> {\n const data = await this.request<{ connections: PlatformConnection[] }>(\n 'GET',\n '/v1/hub/connections',\n )\n return data.connections\n }\n\n /** DELETE /v1/hub/connections/:connectionId — revoke + disable a connection. */\n revokeConnection(connectionId: string): Promise<{ connection: PlatformConnection }> {\n return this.request('DELETE', `/v1/hub/connections/${encodeURIComponent(connectionId)}`)\n }\n\n /**\n * POST /v1/hub/connections/:provider/start — begin OAuth/grant. The provider\n * is taken from the URL; the body carries `returnUrl` (+ `cli`). The platform's\n * two start branches name the URL field differently (github → `authorizationUrl`,\n * substrate → `redirectUrl`); this normalizes to `authorizationUrl`.\n */\n async startAuth(input: StartAuthInput): Promise<StartAuthResult> {\n const body: { returnUrl: string; cli?: boolean } = { returnUrl: input.returnUrl }\n if (input.cli !== undefined) body.cli = input.cli\n const data = await this.request<{\n authorizationUrl?: string\n redirectUrl?: string\n state: string\n expiresAt?: string\n scopes?: string[]\n }>('POST', `/v1/hub/connections/${encodeURIComponent(input.providerId)}/start`, body)\n const authorizationUrl = data.authorizationUrl ?? data.redirectUrl\n if (!authorizationUrl) {\n throw new PlatformHubError(\n 'Platform hub start response missing an authorization URL',\n 502,\n 'HUB_INVALID_START_RESPONSE',\n data,\n )\n }\n return { authorizationUrl, state: data.state, expiresAt: data.expiresAt, scopes: data.scopes }\n }\n\n /**\n * Last-known health for every connection. The platform has no global\n * healthcheck listing — health rides on each connection row — so this derives\n * the list from `listConnections()` (one request, no extra round-trips).\n */\n async listHealthchecks(): Promise<HealthCheck[]> {\n const connections = await this.listConnections()\n return connections.map((c) => ({\n connectionId: c.id,\n providerId: c.providerId,\n status: c.health,\n checkedAt: c.updatedAt,\n }))\n }\n\n /**\n * POST /v1/hub/connections/:connectionId/health — trigger a fresh health\n * probe for one connection and return its updated state.\n */\n checkConnectionHealth(connectionId: string): Promise<ConnectionHealthResult> {\n return this.request('POST', `/v1/hub/connections/${encodeURIComponent(connectionId)}/health`)\n }\n\n /**\n * Trigger a fresh health probe across all of the user's connections. The\n * platform exposes health per-connection only, so this fans out over\n * `listConnections()`. `scheduled` is the number of probes dispatched.\n */\n async runHealthchecks(): Promise<{ scheduled: number }> {\n const connections = await this.listConnections()\n await Promise.allSettled(connections.map((c) => this.checkConnectionHealth(c.id)))\n return { scheduled: connections.length }\n }\n\n /** GET /v1/hub/status — principal + aggregate connection counts. */\n status(): Promise<PlatformHubStatus> {\n return this.request('GET', '/v1/hub/status')\n }\n\n /**\n * POST /v1/hub/tokens — mint a short-lived, action-scoped capability token a\n * sandbox can use to invoke one hub action on the user's behalf without\n * seeing the underlying provider credential.\n */\n mintToken(input: MintTokenInput): Promise<MintTokenResult> {\n return this.request('POST', '/v1/hub/tokens', input)\n }\n\n /** POST /v1/hub/exec — execute a hub action and return its result. */\n async exec(input: ExecInput): Promise<unknown> {\n const data = await this.request<{ result: unknown }>('POST', '/v1/hub/exec', input)\n return data.result\n }\n\n private async request<T>(\n method: 'GET' | 'POST' | 'DELETE' | 'PUT',\n path: string,\n body?: unknown,\n ): Promise<T> {\n const headers: Record<string, string> = {\n authorization: `Bearer ${this.bearer}`,\n accept: 'application/json',\n }\n if (body !== undefined) headers['content-type'] = 'application/json'\n\n const res = await this.fetchImpl(`${this.baseUrl}${path}`, {\n method,\n headers,\n body: body !== undefined ? JSON.stringify(body) : undefined,\n })\n const text = await res.text()\n let parsed: PlatformEnvelope<T> | null = null\n if (text) {\n try {\n parsed = JSON.parse(text)\n } catch {\n // fall through to error handling below\n }\n }\n if (!res.ok || (parsed && parsed.success === false)) {\n const code = parsed?.error && typeof parsed.error === 'object' ? parsed.error.code : undefined\n const message =\n (parsed?.error && typeof parsed.error === 'object' && parsed.error.message) ||\n (typeof parsed?.error === 'string' ? parsed.error : `Platform hub error (${res.status})`)\n throw new PlatformHubError(message, res.status, code, parsed ?? text)\n }\n if (!parsed) {\n throw new PlatformHubError(\n `Platform hub returned non-JSON success (${res.status})`,\n res.status,\n undefined,\n text,\n )\n }\n if (parsed.data === undefined) {\n throw new PlatformHubError(\n 'Platform hub envelope missing `data`',\n res.status,\n undefined,\n parsed,\n )\n }\n return parsed.data\n }\n}\n","/**\n * OpenID Connect client for the Tangle authorization server. Identity tokens\n * are not platform API keys. Resource scopes and audiences must be registered\n * by the provider before a consumer can use these tokens at a paid API.\n */\n\nimport { isRecord } from '@tangle-network/agent-core'\nimport { PlatformAuthError } from './auth.js'\n\nexport interface PlatformOidcClientOptions {\n baseUrl: string\n clientId: string\n /** Omit only for clients registered with token_endpoint_auth_method=none. */\n clientSecret?: string\n /** Required for authorization code; not required for the device grant. */\n redirectUri?: string\n scope?: string\n /** RFC 8707 resource identifiers registered at the authorization server. */\n resources?: readonly string[]\n fetchImpl?: typeof fetch\n}\n\nexport interface OidcAuthorizeUrlOptions {\n state: string\n codeChallenge: string\n /** Only supply a nonce when the consumer also validates the ID token. */\n nonce?: string\n prompt?: 'login' | 'consent' | 'none'\n loginHint?: string\n}\n\nexport interface OidcTokens {\n accessToken: string\n tokenType: string\n expiresIn?: number\n refreshToken?: string\n idToken?: string\n scope?: string\n}\n\nexport interface OidcUser {\n id: string\n email: string\n emailVerified: true\n name?: string\n}\n\nexport interface OidcExchangeResult {\n tokens: OidcTokens\n user: OidcUser\n}\n\n/** Keep deviceCode secret. Only userCode and the verification URLs are displayed. */\nexport interface OidcDeviceAuthorization {\n deviceCode: string\n userCode: string\n verificationUri: string\n verificationUriComplete?: string\n expiresIn: number\n /** Absolute deadline preserves expiry when a polling process resumes. */\n expiresAt: number\n interval: number\n}\n\nconst DEFAULT_SCOPE = 'openid profile email offline_access'\nconst DEVICE_GRANT = 'urn:ietf:params:oauth:grant-type:device_code'\n\nfunction isNonemptyString(value: unknown): value is string {\n return typeof value === 'string' && value.trim().length > 0\n}\n\nfunction base64url(bytes: Uint8Array): string {\n let binary = ''\n for (const byte of bytes) binary += String.fromCharCode(byte)\n return btoa(binary).replace(/\\+/g, '-').replace(/\\//g, '_').replace(/=+$/, '')\n}\n\n/** Create an RFC 7636 verifier and its S256 challenge with Web Crypto. */\nexport async function createPkcePair(): Promise<{ verifier: string; challenge: string }> {\n const verifier = base64url(crypto.getRandomValues(new Uint8Array(32)))\n const digest = await crypto.subtle.digest('SHA-256', new TextEncoder().encode(verifier))\n return { verifier, challenge: base64url(new Uint8Array(digest)) }\n}\n\nfunction oauthError(body: unknown, fallback: string): string {\n if (!isRecord(body)) return fallback\n if (isNonemptyString(body.error_description)) return body.error_description\n if (isNonemptyString(body.error)) return body.error\n return fallback\n}\n\nfunction parseTokens(body: unknown, status: number): OidcTokens {\n if (!isRecord(body) || !isNonemptyString(body.access_token)) {\n throw new PlatformAuthError('Platform token response is malformed', status, {\n code: 'INVALID_TOKEN_RESPONSE',\n })\n }\n return {\n accessToken: body.access_token,\n tokenType: isNonemptyString(body.token_type) ? body.token_type : 'Bearer',\n ...(typeof body.expires_in === 'number' ? { expiresIn: body.expires_in } : {}),\n ...(isNonemptyString(body.refresh_token) ? { refreshToken: body.refresh_token } : {}),\n ...(isNonemptyString(body.id_token) ? { idToken: body.id_token } : {}),\n ...(isNonemptyString(body.scope) ? { scope: body.scope } : {}),\n }\n}\n\nfunction formComponent(value: string): string {\n return new URLSearchParams({ v: value }).toString().slice(2)\n}\n\nfunction pause(ms: number, signal?: AbortSignal): Promise<void> {\n signal?.throwIfAborted()\n return new Promise((resolve, reject) => {\n const finish = () => {\n signal?.removeEventListener('abort', abort)\n resolve()\n }\n const timer = setTimeout(finish, ms)\n const abort = () => {\n clearTimeout(timer)\n signal?.removeEventListener('abort', abort)\n reject(signal?.reason ?? new Error('Device authorization cancelled'))\n }\n signal?.addEventListener('abort', abort, { once: true })\n })\n}\n\n/** OIDC code + PKCE, refresh/revoke and discovery-bound RFC 8628 device grants. */\nexport class PlatformOidcClient {\n private readonly baseUrl: string\n private readonly clientId: string\n private readonly clientSecret: string | undefined\n private readonly redirectUri: string | undefined\n private readonly scope: string\n private readonly resources: readonly string[]\n private readonly fetchImpl: typeof fetch\n\n constructor(options: PlatformOidcClientOptions) {\n if (!options.baseUrl) throw new Error('PlatformOidcClient: baseUrl is required')\n if (!options.clientId) throw new Error('PlatformOidcClient: clientId is required')\n this.baseUrl = options.baseUrl.replace(/\\/+$/, '')\n this.clientId = options.clientId\n this.clientSecret = options.clientSecret || undefined\n this.redirectUri = options.redirectUri\n this.scope = options.scope ?? DEFAULT_SCOPE\n this.resources = [...new Set(options.resources ?? [])]\n for (const resource of this.resources) {\n const url = new URL(resource)\n if (url.hash || url.username || url.password) {\n throw new Error('PlatformOidcClient: resource must not contain a fragment or credentials')\n }\n }\n this.fetchImpl = options.fetchImpl ?? ((input, init) => fetch(input, init))\n }\n\n authorizeUrl(options: OidcAuthorizeUrlOptions): string {\n if (!this.redirectUri)\n throw new Error('PlatformOidcClient: redirectUri is required for authorization code')\n if (!options.state)\n throw new Error('PlatformOidcClient.authorizeUrl: state is required for CSRF')\n if (!options.codeChallenge)\n throw new Error('PlatformOidcClient.authorizeUrl: codeChallenge is required for PKCE')\n const url = new URL('/api/auth/oauth2/authorize', this.baseUrl)\n url.searchParams.set('client_id', this.clientId)\n url.searchParams.set('redirect_uri', this.redirectUri)\n url.searchParams.set('response_type', 'code')\n url.searchParams.set('scope', this.scope)\n url.searchParams.set('state', options.state)\n url.searchParams.set('code_challenge', options.codeChallenge)\n url.searchParams.set('code_challenge_method', 'S256')\n for (const resource of this.resources) url.searchParams.append('resource', resource)\n if (options.nonce) url.searchParams.set('nonce', options.nonce)\n if (options.prompt) url.searchParams.set('prompt', options.prompt)\n if (options.loginHint) url.searchParams.set('login_hint', options.loginHint)\n return url.toString()\n }\n\n async exchange(code: string, codeVerifier: string): Promise<OidcExchangeResult> {\n if (!this.redirectUri)\n throw new Error('PlatformOidcClient: redirectUri is required for authorization code')\n if (!code) throw new Error('PlatformOidcClient.exchange: code is required')\n if (!codeVerifier)\n throw new Error('PlatformOidcClient.exchange: codeVerifier is required for PKCE')\n const tokens = await this.token({\n grant_type: 'authorization_code',\n code,\n redirect_uri: this.redirectUri,\n code_verifier: codeVerifier,\n })\n return { tokens, user: await this.userinfo(tokens.accessToken) }\n }\n\n /** Save the replacement refresh token. Never retry an old token as a new grant. */\n async refresh(refreshToken: string): Promise<OidcTokens> {\n if (!refreshToken) throw new Error('PlatformOidcClient.refresh: refreshToken is required')\n return this.token({ grant_type: 'refresh_token', refresh_token: refreshToken })\n }\n\n async userinfo(accessToken: string): Promise<OidcUser> {\n if (!accessToken) throw new Error('PlatformOidcClient.userinfo: accessToken is required')\n const res = await this.fetchImpl(`${this.baseUrl}/api/auth/oauth2/userinfo`, {\n headers: { authorization: `Bearer ${accessToken}` },\n redirect: 'error',\n })\n const body: unknown = await res.json().catch(() => null)\n if (!res.ok)\n throw new PlatformAuthError(\n oauthError(body, `Platform userinfo failed (${res.status})`),\n res.status,\n body,\n )\n if (\n !isRecord(body) ||\n !isNonemptyString(body.sub) ||\n !isNonemptyString(body.email) ||\n body.email_verified !== true\n ) {\n throw new PlatformAuthError('Platform userinfo has no verified identity', res.status, {\n code: 'INVALID_USERINFO_RESPONSE',\n })\n }\n return {\n id: body.sub,\n email: body.email,\n emailVerified: true,\n ...(isNonemptyString(body.name) ? { name: body.name } : {}),\n }\n }\n\n /** RFC 7009. A local logout alone is not a provider disconnect. */\n async revoke(token: string, tokenTypeHint?: 'access_token' | 'refresh_token'): Promise<void> {\n if (!token) throw new Error('PlatformOidcClient.revoke: token is required')\n const res = await this.post(\n `${this.baseUrl}/api/auth/oauth2/revoke`,\n {\n token,\n ...(tokenTypeHint ? { token_type_hint: tokenTypeHint } : {}),\n },\n undefined,\n false,\n )\n if (!res.ok) {\n const body: unknown = await res.json().catch(() => null)\n throw new PlatformAuthError(\n oauthError(body, `Platform revoke failed (${res.status})`),\n res.status,\n body,\n )\n }\n }\n\n /**\n * Start a device grant only when this issuer advertises the OAuth-integrated\n * device endpoint. No fallback to /cross-site/device or a standalone session\n * device endpoint: those issue different credentials.\n */\n async deviceAuthorize(options: { signal?: AbortSignal } = {}): Promise<OidcDeviceAuthorization> {\n const discovery = await this.fetchImpl(\n `${this.baseUrl}/api/auth/.well-known/openid-configuration`,\n {\n redirect: 'error',\n signal: options.signal,\n },\n )\n const metadata: unknown = await discovery.json().catch(() => null)\n const issuer = `${this.baseUrl}/api/auth`\n if (\n !discovery.ok ||\n !isRecord(metadata) ||\n metadata.issuer !== issuer ||\n metadata.token_endpoint !== `${issuer}/oauth2/token` ||\n !Array.isArray(metadata.grant_types_supported) ||\n !metadata.grant_types_supported.includes(DEVICE_GRANT) ||\n !isNonemptyString(metadata.device_authorization_endpoint)\n ) {\n throw new PlatformAuthError(\n 'Issuer does not advertise an OAuth device grant',\n discovery.status,\n { code: 'OAUTH_DEVICE_GRANT_UNAVAILABLE' },\n )\n }\n const endpoint = new URL(metadata.device_authorization_endpoint)\n const origin = new URL(this.baseUrl).origin\n if (endpoint.origin !== origin || endpoint.username || endpoint.password || endpoint.hash) {\n throw new PlatformAuthError('Device endpoint is outside the configured issuer', 400, {\n code: 'INVALID_DEVICE_ENDPOINT',\n })\n }\n const startedAt = Date.now()\n const res = await this.post(endpoint.href, { scope: this.scope }, options.signal)\n const body: unknown = await res.json().catch(() => null)\n if (!res.ok)\n throw new PlatformAuthError(\n oauthError(body, `Device authorization failed (${res.status})`),\n res.status,\n body,\n )\n if (\n !isRecord(body) ||\n !isNonemptyString(body.device_code) ||\n !isNonemptyString(body.user_code) ||\n !isNonemptyString(body.verification_uri) ||\n typeof body.expires_in !== 'number' ||\n !Number.isSafeInteger(body.expires_in) ||\n body.expires_in <= 0 ||\n (body.interval !== undefined &&\n (typeof body.interval !== 'number' ||\n !Number.isSafeInteger(body.interval) ||\n body.interval <= 0))\n ) {\n throw new PlatformAuthError('Malformed device authorization response', res.status, {\n code: 'INVALID_DEVICE_RESPONSE',\n })\n }\n for (const value of [body.verification_uri, body.verification_uri_complete]) {\n if (value === undefined) continue\n if (!isNonemptyString(value))\n throw new PlatformAuthError('Invalid device verification URI', 400, {\n code: 'INVALID_DEVICE_RESPONSE',\n })\n const uri = new URL(value)\n if (uri.origin !== origin || uri.username || uri.password || uri.hash) {\n throw new PlatformAuthError('Device verification URI is outside the issuer', 400, {\n code: 'INVALID_DEVICE_RESPONSE',\n })\n }\n }\n return {\n deviceCode: body.device_code,\n userCode: body.user_code,\n verificationUri: body.verification_uri,\n ...(isNonemptyString(body.verification_uri_complete)\n ? { verificationUriComplete: body.verification_uri_complete }\n : {}),\n expiresIn: body.expires_in,\n expiresAt: startedAt + body.expires_in * 1000,\n interval: typeof body.interval === 'number' ? body.interval : 5,\n }\n }\n\n /** RFC 8628 pending/slow_down handling, expiry, cancellation and timeout backoff. */\n async pollDeviceAuthorization(\n grant: OidcDeviceAuthorization,\n options: { signal?: AbortSignal } = {},\n ): Promise<OidcTokens> {\n if (\n !grant.deviceCode ||\n !Number.isFinite(grant.expiresAt) ||\n !Number.isFinite(grant.interval) ||\n grant.interval <= 0\n ) {\n throw new Error('PlatformOidcClient.pollDeviceAuthorization: invalid device grant')\n }\n let intervalMs = grant.interval * 1000\n while (Date.now() < grant.expiresAt) {\n options.signal?.throwIfAborted()\n await pause(Math.min(intervalMs, Math.max(0, grant.expiresAt - Date.now())), options.signal)\n const remaining = grant.expiresAt - Date.now()\n if (remaining <= 0) break\n const timeout = AbortSignal.timeout(Math.max(1, Math.min(30_000, Math.floor(remaining))))\n const signal = options.signal ? AbortSignal.any([options.signal, timeout]) : timeout\n try {\n return await this.token({ grant_type: DEVICE_GRANT, device_code: grant.deviceCode }, signal)\n } catch (error) {\n options.signal?.throwIfAborted()\n if (timeout.aborted) {\n intervalMs *= 2\n continue\n }\n if (!(error instanceof PlatformAuthError) || !isRecord(error.body)) throw error\n if (error.body.error === 'authorization_pending') continue\n if (error.body.error === 'slow_down') {\n intervalMs += 5_000\n continue\n }\n throw error\n }\n }\n throw new PlatformAuthError('Device authorization expired', 400, { error: 'expired_token' })\n }\n\n private async token(params: Record<string, string>, signal?: AbortSignal): Promise<OidcTokens> {\n const res = await this.post(`${this.baseUrl}/api/auth/oauth2/token`, params, signal)\n const body: unknown = await res.json().catch(() => null)\n if (!res.ok)\n throw new PlatformAuthError(\n oauthError(body, `Platform token request failed (${res.status})`),\n res.status,\n body,\n )\n return parseTokens(body, res.status)\n }\n\n private post(\n url: string,\n params: Record<string, string>,\n signal?: AbortSignal,\n includeResources = true,\n ): Promise<Response> {\n const body = new URLSearchParams(params)\n const headers: Record<string, string> = { 'content-type': 'application/x-www-form-urlencoded' }\n if (this.clientSecret) {\n // RFC 6749 section 2.3.1: form-encode each component before HTTP Basic.\n headers.authorization = `Basic ${btoa(`${formComponent(this.clientId)}:${formComponent(this.clientSecret)}`)}`\n } else body.set('client_id', this.clientId)\n if (includeResources) for (const resource of this.resources) body.append('resource', resource)\n return this.fetchImpl(url, { method: 'POST', headers, body, redirect: 'error', signal })\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAsDA,IAAa,oBAAb,cAAuC,MAAM;CAGzB;CACA;CAHlB,YACE,SACA,QACA,MACA;EACA,MAAM,OAAO;EAHG,KAAA,SAAA;EACA,KAAA,OAAA;EAGhB,KAAK,OAAO;CACd;AACF;AAEA,SAASA,mBAAiB,OAAiC;CACzD,OAAO,OAAO,UAAU,YAAY,MAAM,KAAK,CAAC,CAAC,SAAS;AAC5D;;AAGA,SAAS,oBAAoB,MAAe,QAAoC;CAC9E,MAAM,gBAAuB;EAE3B,MAAM,IAAI,kBACR,6DACA,QACA,EAAE,MAAM,4BAA4B,CACtC;CACF;CACA,IACE,CAAC,SAAS,IAAI,KACd,CAACA,mBAAiB,KAAK,MAAM,KAC7B,KAAK,kBAAkB,QACvB,CAAC,SAAS,KAAK,IAAI,GAEnB,OAAO,QAAQ;CACjB,MAAM,OAAO,KAAK;CAClB,IAAI,CAACA,mBAAiB,KAAK,EAAE,KAAK,CAACA,mBAAiB,KAAK,KAAK,GAAG,OAAO,QAAQ;CAChF,MAAM,QAAQ,KAAK,MAAM,KAAK;CAC9B,IACE,MAAM,SAAS,OACf,CAAC,6BAA6B,KAAK,KAAK,KACxC,sEAAsE,KAAK,KAAK,GAEhF,OAAO,QAAQ;CACjB,IAAI,KAAK,SAAS,KAAA,KAAa,KAAK,SAAS,QAAQ,OAAO,KAAK,SAAS,UACxE,OAAO,QAAQ;CACjB,IAAI,OAAmC;CACvC,IAAI,KAAK,iBAAiB,KAAA,GAAW;EACnC,IAAI,CAAC,SAAS,KAAK,YAAY,KAAK,CAACA,mBAAiB,KAAK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AAC,SAAS,MAAM,IAAI,GAAG,MAAM;IAC1E,IAAI,MAAM,KAAK,UAAU,yBAAyB;IAClD,IAAI,MAAM,KAAK,UAAU,aAAa;KACpC,cAAc;KACd;IACF;IACA,MAAM;GACR;EACF;EACA,MAAM,IAAI,kBAAkB,gCAAgC,KAAK,EAAE,OAAO,gBAAgB,CAAC;CAC7F;CAEA,MAAc,MAAM,QAAgC,QAA2C;EAC7F,MAAM,MAAM,MAAM,KAAK,KAAK,GAAG,KAAK,QAAQ,yBAAyB,QAAQ,MAAM;EACnF,MAAM,OAAgB,MAAM,IAAI,KAAK,CAAC,CAAC,YAAY,IAAI;EACvD,IAAI,CAAC,IAAI,IACP,MAAM,IAAI,kBACR,WAAW,MAAM,kCAAkC,IAAI,OAAO,EAAE,GAChE,IAAI,QACJ,IACF;EACF,OAAO,YAAY,MAAM,IAAI,MAAM;CACrC;CAEA,KACE,KACA,QACA,QACA,mBAAmB,MACA;EACnB,MAAM,OAAO,IAAI,gBAAgB,MAAM;EACvC,MAAM,UAAkC,EAAE,gBAAgB,oCAAoC;EAC9F,IAAI,KAAK,cAEP,QAAQ,gBAAgB,SAAS,KAAK,GAAG,cAAc,KAAK,QAAQ,EAAE,GAAG,cAAc,KAAK,YAAY,GAAG;OACtG,KAAK,IAAI,aAAa,KAAK,QAAQ;EAC1C,IAAI,kBAAkB,KAAK,MAAM,YAAY,KAAK,WAAW,KAAK,OAAO,YAAY,QAAQ;EAC7F,OAAO,KAAK,UAAU,KAAK;GAAE,QAAQ;GAAQ;GAAS;GAAM,UAAU;GAAS;EAAO,CAAC;CACzF;AACF"}
1
+ {"version":3,"file":"platform.js","names":["isNonemptyString"],"sources":["../src/platform/auth.ts","../src/platform/integrations.ts","../src/platform/oidc.ts"],"sourcesContent":["/**\n * Server-side client for the Tangle platform's cross-site SSO bridge.\n *\n * Consumer apps (gtm-agent, tax-agent, legal-agent, creative-agent, …)\n * use this to:\n * 1. Build an /authorize URL that lands the user on id.tangle.tools\n * and brings them back with a single-use code.\n * 2. Exchange that code for an API key + the user's identity.\n *\n * The platform endpoint contract is documented in\n * the cross-site route in agent-container's platform API. This client only\n * speaks HTTP — no SDK weight, no transitive deps.\n */\n\nimport { isRecord } from '@tangle-network/agent-core'\n\nexport interface PlatformAuthClientOptions {\n /** Platform base URL, e.g. `https://id.tangle.tools`. */\n baseUrl: string\n /** App id as registered in the platform's TRUSTED_APPS registry. */\n appId: string\n /** Override the global fetch (useful for tests + edge runtimes). */\n fetchImpl?: typeof fetch\n}\n\nexport interface AuthorizeUrlOptions {\n /** Required CSRF token; the consumer verifies it on the callback. */\n state: string\n /**\n * Final redirect URI. Must be one of the URIs registered for `appId`\n * on the platform. Omit to use the first registered URI.\n */\n redirectUri?: string\n /** Force the login screen even if a session is already active. */\n prompt?: 'login'\n /** Pre-fill the email field on the login screen. */\n email?: string\n}\n\nexport interface ExchangeCodeResult {\n apiKey: string\n emailVerified: true\n user: {\n id: string\n email: string\n name?: string | null\n }\n /** Null when the platform could not provide a subscription. This is not a paid-access grant. */\n plan: {\n tier: string\n } | null\n}\n\n/** Thrown when a `PlatformAuthClient` request returns a non-success status. */\nexport class PlatformAuthError extends Error {\n constructor(\n message: string,\n public readonly status: number,\n public readonly body: unknown,\n ) {\n super(message)\n this.name = 'PlatformAuthError'\n }\n}\n\nfunction isNonemptyString(value: unknown): value is string {\n return typeof value === 'string' && value.trim().length > 0\n}\n\n/** Validate the platform's verified identity before consumers create a local session. */\nfunction parseExchangeResult(body: unknown, status: number): ExchangeCodeResult {\n const invalid = (): never => {\n // A successful but malformed response can contain the one-time API secret.\n throw new PlatformAuthError(\n 'Platform exchange response has no valid verified identity',\n status,\n { code: 'INVALID_EXCHANGE_RESPONSE' },\n )\n }\n if (\n !isRecord(body) ||\n !isNonemptyString(body.apiKey) ||\n body.emailVerified !== true ||\n !isRecord(body.user)\n )\n return invalid()\n const user = body.user\n if (!isNonemptyString(user.id) || !isNonemptyString(user.email)) return invalid()\n const email = user.email.trim()\n if (\n email.length > 320 ||\n !/^[^\\s@]+@[^\\s@]+\\.[^\\s@]+$/.test(email) ||\n /(?:@users\\.noreply\\.tangle\\.tools$|^0x[a-f0-9]{40}@tangle\\.tools$)/i.test(email)\n )\n return invalid()\n if (user.name !== undefined && user.name !== null && typeof user.name !== 'string')\n return invalid()\n let plan: ExchangeCodeResult['plan'] = null\n if (body.subscription !== undefined) {\n if (!isRecord(body.subscription) || !isNonemptyString(body.subscription.plan)) return invalid()\n plan = { tier: body.subscription.plan }\n }\n return {\n apiKey: body.apiKey,\n emailVerified: true,\n user: { id: user.id, email, ...(user.name !== undefined ? { name: user.name } : {}) },\n plan,\n }\n}\n\n/** HTTP client for the Tangle Platform SSO: builds authorize URLs and exchanges auth codes for API keys. */\nexport class PlatformAuthClient {\n private readonly baseUrl: string\n private readonly appId: string\n private readonly fetchImpl: typeof fetch\n\n constructor(options: PlatformAuthClientOptions) {\n if (!options.baseUrl) throw new Error('PlatformAuthClient: baseUrl is required')\n if (!options.appId) throw new Error('PlatformAuthClient: appId is required')\n this.baseUrl = options.baseUrl.replace(/\\/+$/, '')\n this.appId = options.appId\n this.fetchImpl =\n options.fetchImpl ??\n ((url: Parameters<typeof fetch>[0], init?: Parameters<typeof fetch>[1]) => fetch(url, init))\n }\n\n /**\n * Build the URL the user is redirected to in order to start SSO.\n * The platform redirects back to one of `appId`'s registered\n * `redirectUris` with `?code=...&app=...&state=...`.\n */\n authorizeUrl(options: AuthorizeUrlOptions): string {\n if (!options.state) {\n throw new Error('PlatformAuthClient.authorizeUrl: state is required for CSRF')\n }\n const url = new URL('/cross-site/authorize', this.baseUrl)\n url.searchParams.set('app', this.appId)\n url.searchParams.set('state', options.state)\n if (options.redirectUri) url.searchParams.set('redirect', options.redirectUri)\n if (options.prompt) url.searchParams.set('prompt', options.prompt)\n if (options.email) url.searchParams.set('email', options.email)\n return url.toString()\n }\n\n /**\n * Exchange a single-use auth code (delivered to the consumer's\n * callback by the platform) for an API key + the user's identity.\n * Codes are single-use and expire ~5 minutes after issue.\n */\n async exchange(code: string): Promise<ExchangeCodeResult> {\n if (!code) throw new Error('PlatformAuthClient.exchange: code is required')\n const res = await this.fetchImpl(`${this.baseUrl}/cross-site/exchange`, {\n method: 'POST',\n headers: { 'content-type': 'application/json' },\n body: JSON.stringify({ code, app: this.appId }),\n })\n const body = await res.json().catch(() => null)\n if (!res.ok) {\n const message =\n body && typeof body === 'object' && 'error' in body && typeof body.error === 'string'\n ? body.error\n : `Platform exchange failed (${res.status})`\n throw new PlatformAuthError(message, res.status, body)\n }\n return parseExchangeResult(body, res.status)\n }\n}\n","/**\n * Server-side client for the Tangle platform's integration hub\n * (`/v1/hub/*`). Consumer apps use this instead of rolling their own\n * OAuth + connection tables.\n *\n * Auth: the caller supplies a bearer (either the user's API key from\n * cross-site exchange, or a platform service token) on construction.\n *\n * Endpoint contract (authoritative): the platform API's hub contract\n * and hub route (both in agent-container's platform API). The platform wraps every response in\n * `{ success, data }`; non-2xx or `success:false` surfaces as `PlatformHubError`\n * carrying the real upstream status.\n */\n\nexport interface PlatformHubClientOptions {\n /** Platform base URL, e.g. `https://id.tangle.tools`. */\n baseUrl: string\n /** Bearer credential — user API key or service token. */\n bearer: string\n /** Override fetch (tests + edge runtimes). */\n fetchImpl?: typeof fetch\n}\n\n/** A live integration connection, as returned by `/v1/hub/connections`. */\nexport interface PlatformConnection {\n id: string\n providerId: string\n displayName: string\n accountDisplay: string | null\n scopes: string[]\n status: 'active' | 'revoked' | 'unhealthy' | 'reconnect_required' | (string & {})\n health: 'unknown' | 'healthy' | 'unhealthy' | 'rate_limited' | (string & {})\n createdAt: string\n updatedAt: string\n lastUsedAt: string | null\n}\n\n/** A connectable provider in the catalog (`/v1/hub/providers`). */\nexport interface PlatformCatalogProvider {\n providerId: string\n title?: string\n authKind?: string\n category?: string\n scopes?: string[]\n capabilityCount?: number\n native?: boolean\n /** Whether the OAuth app's credentials are wired — the UI offers Connect\n * only when true. */\n configured?: boolean\n [k: string]: unknown\n}\n\nexport interface CatalogResult {\n providers: PlatformCatalogProvider[]\n /** Count of substrate-bundled connectors behind the catalog. */\n substrateBundled?: number\n [k: string]: unknown\n}\n\nexport interface StartAuthInput {\n /** The provider to connect (goes in the URL path). */\n providerId: string\n /** Accepted for interface compatibility; the platform's start endpoint is\n * provider-level and does not consume a connector id. */\n connectorId?: string\n /** Where the platform redirects the user back to after OAuth. */\n returnUrl: string\n /** Accepted for interface compatibility; not consumed by the start endpoint. */\n requestedScopes?: string[]\n /** CLI flow flag — affects the platform's post-auth redirect handling. */\n cli?: boolean\n}\n\nexport interface StartAuthResult {\n /** The URL to send the user to. Normalized across the platform's two start\n * branches: github returns `authorizationUrl`, substrate returns\n * `redirectUrl`. */\n authorizationUrl: string\n state: string\n expiresAt?: string\n scopes?: string[]\n}\n\nexport interface ConnectionHealth {\n status: 'unknown' | 'healthy' | 'unhealthy' | 'rate_limited' | (string & {})\n checkedAt: string\n error?: { code: string; message: string }\n}\n\nexport interface ConnectionHealthResult {\n connection: PlatformConnection\n health: ConnectionHealth\n}\n\n/** Last-known health for a connection, derived from the connection row. */\nexport interface HealthCheck {\n connectionId: string\n providerId: string\n /** Mirrors `PlatformConnection.health`. */\n status: ConnectionHealth['status']\n checkedAt?: string\n}\n\nexport interface MintTokenInput {\n /** The hub action the token authorizes (e.g. `slack.chat.postMessage`). */\n actionPath: string\n /** Bind to a specific connection, or … */\n connectionId?: string\n /** … resolve the connection by provider for the calling user. */\n provider?: string\n}\n\nexport interface MintTokenResult {\n tokenId: string\n token: string\n expiresAt: string\n}\n\nexport interface ExecInput {\n /** The hub action path to execute. */\n path: string\n input?: unknown\n connectionId?: string\n}\n\nexport interface PlatformHubStatus {\n contract?: unknown\n principal: { kind: string; userId: string; [k: string]: unknown }\n connections: { connectedProviderCount: number; unhealthyProviderCount: number }\n}\n\n/** Thrown when a `PlatformHubClient` request returns a non-success status. */\nexport class PlatformHubError extends Error {\n constructor(\n message: string,\n public readonly status: number,\n public readonly code: string | undefined,\n public readonly body: unknown,\n ) {\n super(message)\n this.name = 'PlatformHubError'\n }\n}\n\ninterface PlatformEnvelope<T> {\n success: boolean\n data?: T\n error?: { code?: string; message?: string } | string\n}\n\n/** HTTP client for the Tangle Platform Hub API: provider catalog, connection flow, and status. */\nexport class PlatformHubClient {\n private readonly baseUrl: string\n private readonly bearer: string\n private readonly fetchImpl: typeof fetch\n\n constructor(options: PlatformHubClientOptions) {\n if (!options.baseUrl) throw new Error('PlatformHubClient: baseUrl is required')\n if (!options.bearer) throw new Error('PlatformHubClient: bearer is required')\n this.baseUrl = options.baseUrl.replace(/\\/+$/, '')\n this.bearer = options.bearer\n this.fetchImpl =\n options.fetchImpl ??\n ((url: Parameters<typeof fetch>[0], init?: Parameters<typeof fetch>[1]) => fetch(url, init))\n }\n\n /** GET /v1/hub/providers — the connectable provider catalog. */\n catalog(): Promise<CatalogResult> {\n return this.request('GET', '/v1/hub/providers')\n }\n\n /** GET /v1/hub/connections — the calling user's live connections. */\n async listConnections(): Promise<PlatformConnection[]> {\n const data = await this.request<{ connections: PlatformConnection[] }>(\n 'GET',\n '/v1/hub/connections',\n )\n return data.connections\n }\n\n /** DELETE /v1/hub/connections/:connectionId — revoke + disable a connection. */\n revokeConnection(connectionId: string): Promise<{ connection: PlatformConnection }> {\n return this.request('DELETE', `/v1/hub/connections/${encodeURIComponent(connectionId)}`)\n }\n\n /**\n * POST /v1/hub/connections/:provider/start — begin OAuth/grant. The provider\n * is taken from the URL; the body carries `returnUrl` (+ `cli`). The platform's\n * two start branches name the URL field differently (github → `authorizationUrl`,\n * substrate → `redirectUrl`); this normalizes to `authorizationUrl`.\n */\n async startAuth(input: StartAuthInput): Promise<StartAuthResult> {\n const body: { returnUrl: string; cli?: boolean } = { returnUrl: input.returnUrl }\n if (input.cli !== undefined) body.cli = input.cli\n const data = await this.request<{\n authorizationUrl?: string\n redirectUrl?: string\n state: string\n expiresAt?: string\n scopes?: string[]\n }>('POST', `/v1/hub/connections/${encodeURIComponent(input.providerId)}/start`, body)\n const authorizationUrl = data.authorizationUrl ?? data.redirectUrl\n if (!authorizationUrl) {\n throw new PlatformHubError(\n 'Platform hub start response missing an authorization URL',\n 502,\n 'HUB_INVALID_START_RESPONSE',\n data,\n )\n }\n return { authorizationUrl, state: data.state, expiresAt: data.expiresAt, scopes: data.scopes }\n }\n\n /**\n * Last-known health for every connection. The platform has no global\n * healthcheck listing — health rides on each connection row — so this derives\n * the list from `listConnections()` (one request, no extra round-trips).\n */\n async listHealthchecks(): Promise<HealthCheck[]> {\n const connections = await this.listConnections()\n return connections.map((c) => ({\n connectionId: c.id,\n providerId: c.providerId,\n status: c.health,\n checkedAt: c.updatedAt,\n }))\n }\n\n /**\n * POST /v1/hub/connections/:connectionId/health — trigger a fresh health\n * probe for one connection and return its updated state.\n */\n checkConnectionHealth(connectionId: string): Promise<ConnectionHealthResult> {\n return this.request('POST', `/v1/hub/connections/${encodeURIComponent(connectionId)}/health`)\n }\n\n /**\n * Trigger a fresh health probe across all of the user's connections. The\n * platform exposes health per-connection only, so this fans out over\n * `listConnections()`. `scheduled` is the number of probes dispatched.\n */\n async runHealthchecks(): Promise<{ scheduled: number }> {\n const connections = await this.listConnections()\n await Promise.allSettled(connections.map((c) => this.checkConnectionHealth(c.id)))\n return { scheduled: connections.length }\n }\n\n /** GET /v1/hub/status — principal + aggregate connection counts. */\n status(): Promise<PlatformHubStatus> {\n return this.request('GET', '/v1/hub/status')\n }\n\n /**\n * POST /v1/hub/tokens — mint a short-lived, action-scoped capability token a\n * sandbox can use to invoke one hub action on the user's behalf without\n * seeing the underlying provider credential.\n */\n mintToken(input: MintTokenInput): Promise<MintTokenResult> {\n return this.request('POST', '/v1/hub/tokens', input)\n }\n\n /** POST /v1/hub/exec — execute a hub action and return its result. */\n async exec(input: ExecInput): Promise<unknown> {\n const data = await this.request<{ result: unknown }>('POST', '/v1/hub/exec', input)\n return data.result\n }\n\n private async request<T>(\n method: 'GET' | 'POST' | 'DELETE' | 'PUT',\n path: string,\n body?: unknown,\n ): Promise<T> {\n const headers: Record<string, string> = {\n authorization: `Bearer ${this.bearer}`,\n accept: 'application/json',\n }\n if (body !== undefined) headers['content-type'] = 'application/json'\n\n const res = await this.fetchImpl(`${this.baseUrl}${path}`, {\n method,\n headers,\n body: body !== undefined ? JSON.stringify(body) : undefined,\n })\n const text = await res.text()\n let parsed: PlatformEnvelope<T> | null = null\n if (text) {\n try {\n parsed = JSON.parse(text)\n } catch {\n // fall through to error handling below\n }\n }\n if (!res.ok || (parsed && parsed.success === false)) {\n const code = parsed?.error && typeof parsed.error === 'object' ? parsed.error.code : undefined\n const message =\n (parsed?.error && typeof parsed.error === 'object' && parsed.error.message) ||\n (typeof parsed?.error === 'string' ? parsed.error : `Platform hub error (${res.status})`)\n throw new PlatformHubError(message, res.status, code, parsed ?? text)\n }\n if (!parsed) {\n throw new PlatformHubError(\n `Platform hub returned non-JSON success (${res.status})`,\n res.status,\n undefined,\n text,\n )\n }\n if (parsed.data === undefined) {\n throw new PlatformHubError(\n 'Platform hub envelope missing `data`',\n res.status,\n undefined,\n parsed,\n )\n }\n return parsed.data\n }\n}\n","/**\n * OpenID Connect client for the Tangle authorization server. Identity tokens\n * are not platform API keys. Resource scopes and audiences must be registered\n * by the provider before a consumer can use these tokens at a paid API.\n */\n\nimport { isRecord } from '@tangle-network/agent-core'\nimport { PlatformAuthError } from './auth.js'\n\nexport interface PlatformOidcClientOptions {\n baseUrl: string\n clientId: string\n /** Omit only for clients registered with token_endpoint_auth_method=none. */\n clientSecret?: string\n /** Required for authorization code; not required for the device grant. */\n redirectUri?: string\n scope?: string\n /** RFC 8707 resource identifiers registered at the authorization server. */\n resources?: readonly string[]\n fetchImpl?: typeof fetch\n}\n\nexport interface OidcAuthorizeUrlOptions {\n state: string\n codeChallenge: string\n /** Only supply a nonce when the consumer also validates the ID token. */\n nonce?: string\n prompt?: 'login' | 'consent' | 'none'\n loginHint?: string\n}\n\nexport interface OidcTokens {\n accessToken: string\n tokenType: string\n expiresIn?: number\n refreshToken?: string\n idToken?: string\n scope?: string\n}\n\nexport interface OidcUser {\n id: string\n email: string\n emailVerified: true\n name?: string\n}\n\nexport interface OidcExchangeResult {\n tokens: OidcTokens\n user: OidcUser\n}\n\n/** Keep deviceCode secret. Only userCode and the verification URLs are displayed. */\nexport interface OidcDeviceAuthorization {\n deviceCode: string\n userCode: string\n verificationUri: string\n verificationUriComplete?: string\n expiresIn: number\n /** Absolute deadline preserves expiry when a polling process resumes. */\n expiresAt: number\n interval: number\n}\n\nconst DEFAULT_SCOPE = 'openid profile email offline_access'\nconst DEVICE_GRANT = 'urn:ietf:params:oauth:grant-type:device_code'\n\nfunction isNonemptyString(value: unknown): value is string {\n return typeof value === 'string' && value.trim().length > 0\n}\n\nfunction base64url(bytes: Uint8Array): string {\n let binary = ''\n for (const byte of bytes) binary += String.fromCharCode(byte)\n return btoa(binary).replace(/\\+/g, '-').replace(/\\//g, '_').replace(/=+$/, '')\n}\n\n/** Create an RFC 7636 verifier and its S256 challenge with Web Crypto. */\nexport async function createPkcePair(): Promise<{ verifier: string; challenge: string }> {\n const verifier = base64url(crypto.getRandomValues(new Uint8Array(32)))\n const digest = await crypto.subtle.digest('SHA-256', new TextEncoder().encode(verifier))\n return { verifier, challenge: base64url(new Uint8Array(digest)) }\n}\n\nfunction oauthError(body: unknown, fallback: string): string {\n if (!isRecord(body)) return fallback\n if (isNonemptyString(body.error_description)) return body.error_description\n if (isNonemptyString(body.error)) return body.error\n return fallback\n}\n\nfunction parseTokens(body: unknown, status: number): OidcTokens {\n if (!isRecord(body) || !isNonemptyString(body.access_token)) {\n throw new PlatformAuthError('Platform token response is malformed', status, {\n code: 'INVALID_TOKEN_RESPONSE',\n })\n }\n return {\n accessToken: body.access_token,\n tokenType: isNonemptyString(body.token_type) ? body.token_type : 'Bearer',\n ...(typeof body.expires_in === 'number' ? { expiresIn: body.expires_in } : {}),\n ...(isNonemptyString(body.refresh_token) ? { refreshToken: body.refresh_token } : {}),\n ...(isNonemptyString(body.id_token) ? { idToken: body.id_token } : {}),\n ...(isNonemptyString(body.scope) ? { scope: body.scope } : {}),\n }\n}\n\nfunction formComponent(value: string): string {\n return new URLSearchParams({ v: value }).toString().slice(2)\n}\n\nfunction pause(ms: number, signal?: AbortSignal): Promise<void> {\n signal?.throwIfAborted()\n return new Promise((resolve, reject) => {\n const finish = () => {\n signal?.removeEventListener('abort', abort)\n resolve()\n }\n const timer = setTimeout(finish, ms)\n const abort = () => {\n clearTimeout(timer)\n signal?.removeEventListener('abort', abort)\n reject(signal?.reason ?? new Error('Device authorization cancelled'))\n }\n signal?.addEventListener('abort', abort, { once: true })\n })\n}\n\n/** OIDC code + PKCE, refresh/revoke and discovery-bound RFC 8628 device grants. */\nexport class PlatformOidcClient {\n private readonly baseUrl: string\n private readonly clientId: string\n private readonly clientSecret: string | undefined\n private readonly redirectUri: string | undefined\n private readonly scope: string\n private readonly resources: readonly string[]\n private readonly fetchImpl: typeof fetch\n\n constructor(options: PlatformOidcClientOptions) {\n if (!options.baseUrl) throw new Error('PlatformOidcClient: baseUrl is required')\n if (!options.clientId) throw new Error('PlatformOidcClient: clientId is required')\n this.baseUrl = options.baseUrl.replace(/\\/+$/, '')\n this.clientId = options.clientId\n this.clientSecret = options.clientSecret || undefined\n this.redirectUri = options.redirectUri\n this.scope = options.scope ?? DEFAULT_SCOPE\n this.resources = [...new Set(options.resources ?? [])]\n for (const resource of this.resources) {\n const url = new URL(resource)\n if (url.hash || url.username || url.password) {\n throw new Error('PlatformOidcClient: resource must not contain a fragment or credentials')\n }\n }\n this.fetchImpl = options.fetchImpl ?? ((input, init) => fetch(input, init))\n }\n\n authorizeUrl(options: OidcAuthorizeUrlOptions): string {\n if (!this.redirectUri)\n throw new Error('PlatformOidcClient: redirectUri is required for authorization code')\n if (!options.state)\n throw new Error('PlatformOidcClient.authorizeUrl: state is required for CSRF')\n if (!options.codeChallenge)\n throw new Error('PlatformOidcClient.authorizeUrl: codeChallenge is required for PKCE')\n const url = new URL('/api/auth/oauth2/authorize', this.baseUrl)\n url.searchParams.set('client_id', this.clientId)\n url.searchParams.set('redirect_uri', this.redirectUri)\n url.searchParams.set('response_type', 'code')\n url.searchParams.set('scope', this.scope)\n url.searchParams.set('state', options.state)\n url.searchParams.set('code_challenge', options.codeChallenge)\n url.searchParams.set('code_challenge_method', 'S256')\n for (const resource of this.resources) url.searchParams.append('resource', resource)\n if (options.nonce) url.searchParams.set('nonce', options.nonce)\n if (options.prompt) url.searchParams.set('prompt', options.prompt)\n if (options.loginHint) url.searchParams.set('login_hint', options.loginHint)\n return url.toString()\n }\n\n async exchange(code: string, codeVerifier: string): Promise<OidcExchangeResult> {\n if (!this.redirectUri)\n throw new Error('PlatformOidcClient: redirectUri is required for authorization code')\n if (!code) throw new Error('PlatformOidcClient.exchange: code is required')\n if (!codeVerifier)\n throw new Error('PlatformOidcClient.exchange: codeVerifier is required for PKCE')\n const tokens = await this.token({\n grant_type: 'authorization_code',\n code,\n redirect_uri: this.redirectUri,\n code_verifier: codeVerifier,\n })\n return { tokens, user: await this.userinfo(tokens.accessToken) }\n }\n\n /** Save the replacement refresh token. Never retry an old token as a new grant. */\n async refresh(refreshToken: string): Promise<OidcTokens> {\n if (!refreshToken) throw new Error('PlatformOidcClient.refresh: refreshToken is required')\n return this.token({ grant_type: 'refresh_token', refresh_token: refreshToken })\n }\n\n async userinfo(accessToken: string): Promise<OidcUser> {\n if (!accessToken) throw new Error('PlatformOidcClient.userinfo: accessToken is required')\n const res = await this.fetchImpl(`${this.baseUrl}/api/auth/oauth2/userinfo`, {\n headers: { authorization: `Bearer ${accessToken}` },\n redirect: 'error',\n })\n const body: unknown = await res.json().catch(() => null)\n if (!res.ok)\n throw new PlatformAuthError(\n oauthError(body, `Platform userinfo failed (${res.status})`),\n res.status,\n body,\n )\n if (\n !isRecord(body) ||\n !isNonemptyString(body.sub) ||\n !isNonemptyString(body.email) ||\n body.email_verified !== true\n ) {\n throw new PlatformAuthError('Platform userinfo has no verified identity', res.status, {\n code: 'INVALID_USERINFO_RESPONSE',\n })\n }\n return {\n id: body.sub,\n email: body.email,\n emailVerified: true,\n ...(isNonemptyString(body.name) ? { name: body.name } : {}),\n }\n }\n\n /** RFC 7009. A local logout alone is not a provider disconnect. */\n async revoke(token: string, tokenTypeHint?: 'access_token' | 'refresh_token'): Promise<void> {\n if (!token) throw new Error('PlatformOidcClient.revoke: token is required')\n const res = await this.post(\n `${this.baseUrl}/api/auth/oauth2/revoke`,\n {\n token,\n ...(tokenTypeHint ? { token_type_hint: tokenTypeHint } : {}),\n },\n undefined,\n false,\n )\n if (!res.ok) {\n const body: unknown = await res.json().catch(() => null)\n throw new PlatformAuthError(\n oauthError(body, `Platform revoke failed (${res.status})`),\n res.status,\n body,\n )\n }\n }\n\n /**\n * Start a device grant only when this issuer advertises the OAuth-integrated\n * device endpoint. No fallback to /cross-site/device or a standalone session\n * device endpoint: those issue different credentials.\n */\n async deviceAuthorize(options: { signal?: AbortSignal } = {}): Promise<OidcDeviceAuthorization> {\n const discovery = await this.fetchImpl(\n `${this.baseUrl}/api/auth/.well-known/openid-configuration`,\n {\n redirect: 'error',\n signal: options.signal,\n },\n )\n const metadata: unknown = await discovery.json().catch(() => null)\n const issuer = `${this.baseUrl}/api/auth`\n if (\n !discovery.ok ||\n !isRecord(metadata) ||\n metadata.issuer !== issuer ||\n metadata.token_endpoint !== `${issuer}/oauth2/token` ||\n !Array.isArray(metadata.grant_types_supported) ||\n !metadata.grant_types_supported.includes(DEVICE_GRANT) ||\n !isNonemptyString(metadata.device_authorization_endpoint)\n ) {\n throw new PlatformAuthError(\n 'Issuer does not advertise an OAuth device grant',\n discovery.status,\n { code: 'OAUTH_DEVICE_GRANT_UNAVAILABLE' },\n )\n }\n const endpoint = new URL(metadata.device_authorization_endpoint)\n const origin = new URL(this.baseUrl).origin\n if (endpoint.origin !== origin || endpoint.username || endpoint.password || endpoint.hash) {\n throw new PlatformAuthError('Device endpoint is outside the configured issuer', 400, {\n code: 'INVALID_DEVICE_ENDPOINT',\n })\n }\n const startedAt = Date.now()\n const res = await this.post(endpoint.href, { scope: this.scope }, options.signal)\n const body: unknown = await res.json().catch(() => null)\n if (!res.ok)\n throw new PlatformAuthError(\n oauthError(body, `Device authorization failed (${res.status})`),\n res.status,\n body,\n )\n if (\n !isRecord(body) ||\n !isNonemptyString(body.device_code) ||\n !isNonemptyString(body.user_code) ||\n !isNonemptyString(body.verification_uri) ||\n typeof body.expires_in !== 'number' ||\n !Number.isSafeInteger(body.expires_in) ||\n body.expires_in <= 0 ||\n (body.interval !== undefined &&\n (typeof body.interval !== 'number' ||\n !Number.isSafeInteger(body.interval) ||\n body.interval <= 0))\n ) {\n throw new PlatformAuthError('Malformed device authorization response', res.status, {\n code: 'INVALID_DEVICE_RESPONSE',\n })\n }\n for (const value of [body.verification_uri, body.verification_uri_complete]) {\n if (value === undefined) continue\n if (!isNonemptyString(value))\n throw new PlatformAuthError('Invalid device verification URI', 400, {\n code: 'INVALID_DEVICE_RESPONSE',\n })\n const uri = new URL(value)\n if (uri.origin !== origin || uri.username || uri.password || uri.hash) {\n throw new PlatformAuthError('Device verification URI is outside the issuer', 400, {\n code: 'INVALID_DEVICE_RESPONSE',\n })\n }\n }\n return {\n deviceCode: body.device_code,\n userCode: body.user_code,\n verificationUri: body.verification_uri,\n ...(isNonemptyString(body.verification_uri_complete)\n ? { verificationUriComplete: body.verification_uri_complete }\n : {}),\n expiresIn: body.expires_in,\n expiresAt: startedAt + body.expires_in * 1000,\n interval: typeof body.interval === 'number' ? body.interval : 5,\n }\n }\n\n /** RFC 8628 pending/slow_down handling, expiry, cancellation and timeout backoff. */\n async pollDeviceAuthorization(\n grant: OidcDeviceAuthorization,\n options: { signal?: AbortSignal } = {},\n ): Promise<OidcTokens> {\n if (\n !grant.deviceCode ||\n !Number.isFinite(grant.expiresAt) ||\n !Number.isFinite(grant.interval) ||\n grant.interval <= 0\n ) {\n throw new Error('PlatformOidcClient.pollDeviceAuthorization: invalid device grant')\n }\n let intervalMs = grant.interval * 1000\n while (Date.now() < grant.expiresAt) {\n options.signal?.throwIfAborted()\n await pause(Math.min(intervalMs, Math.max(0, grant.expiresAt - Date.now())), options.signal)\n const remaining = grant.expiresAt - Date.now()\n if (remaining <= 0) break\n const timeout = AbortSignal.timeout(Math.max(1, Math.min(30_000, Math.floor(remaining))))\n const signal = options.signal ? AbortSignal.any([options.signal, timeout]) : timeout\n try {\n return await this.token({ grant_type: DEVICE_GRANT, device_code: grant.deviceCode }, signal)\n } catch (error) {\n options.signal?.throwIfAborted()\n if (timeout.aborted) {\n intervalMs *= 2\n continue\n }\n if (!(error instanceof PlatformAuthError) || !isRecord(error.body)) throw error\n if (error.body.error === 'authorization_pending') continue\n if (error.body.error === 'slow_down') {\n intervalMs += 5_000\n continue\n }\n throw error\n }\n }\n throw new PlatformAuthError('Device authorization expired', 400, { error: 'expired_token' })\n }\n\n private async token(params: Record<string, string>, signal?: AbortSignal): Promise<OidcTokens> {\n const res = await this.post(`${this.baseUrl}/api/auth/oauth2/token`, params, signal)\n const body: unknown = await res.json().catch(() => null)\n if (!res.ok)\n throw new PlatformAuthError(\n oauthError(body, `Platform token request failed (${res.status})`),\n res.status,\n body,\n )\n return parseTokens(body, res.status)\n }\n\n private post(\n url: string,\n params: Record<string, string>,\n signal?: AbortSignal,\n includeResources = true,\n ): Promise<Response> {\n const body = new URLSearchParams(params)\n const headers: Record<string, string> = { 'content-type': 'application/x-www-form-urlencoded' }\n if (this.clientSecret) {\n // RFC 6749 section 2.3.1: form-encode each component before HTTP Basic.\n headers.authorization = `Basic ${btoa(`${formComponent(this.clientId)}:${formComponent(this.clientSecret)}`)}`\n } else body.set('client_id', this.clientId)\n if (includeResources) for (const resource of this.resources) body.append('resource', resource)\n return this.fetchImpl(url, { method: 'POST', headers, body, redirect: 'error', signal })\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAsDA,IAAa,oBAAb,cAAuC,MAAM;CAGzB;CACA;CAHlB,YACE,SACA,QACA,MACA;EACA,MAA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M,OAAgB,MAAM,IAAI,KAAK,CAAC,CAAC,YAAY,IAAI;EACvD,IAAI,CAAC,IAAI,IACP,MAAM,IAAI,kBACR,WAAW,MAAM,kCAAkC,IAAI,OAAO,EAAE,GAChE,IAAI,QACJ,IACF;EACF,OAAO,YAAY,MAAM,IAAI,MAAM;CACrC;CAEA,KACE,KACA,QACA,QACA,mBAAmB,MACA;EACnB,MAAM,OAAO,IAAI,gBAAgB,MAAM;EACvC,MAAM,UAAkC,EAAE,gBAAgB,oCAAoC;EAC9F,IAAI,KAAK,cAEP,QAAQ,gBAAgB,SAAS,KAAK,GAAG,cAAc,KAAK,QAAQ,EAAE,GAAG,cAAc,KAAK,YAAY,GAAG;OACtG,KAAK,IAAI,aAAa,KAAK,QAAQ;EAC1C,IAAI,kBAAkB,KAAK,MAAM,YAAY,KAAK,WAAW,KAAK,OAAO,YAAY,QAAQ;EAC7F,OAAO,KAAK,UAAU,KAAK;GAAE,QAAQ;GAAQ;GAAS;GAAM,UAAU;GAAS;EAAO,CAAC;CACzF;AACF"}
@@ -1,6 +1,6 @@
1
- import { A as verifyMaterializedProfileWorkspace, B as sha256Bytes$1, D as readMaterializedWorkspaceFiles, F as canonicalCandidateDocument, H as hasControlCharacter, I as deepFreezeCandidate, L as embeddedCandidateArtifact, M as verifyWorkspaceSnapshotArtifacts, N as canonicalCandidateBytes$1, O as readVerifiedArtifact, P as canonicalCandidateDigest$1, R as immutableCandidateValue, S as isWellFormedUnicode, X as errorMessage, b as persistCandidateOutputArtifact, d as readCandidateGitHubResource, f as verifyCandidateCode, j as verifyMaterializedWorkspace, k as verifyBytes, m as verifyTaskOutcomePatch, p as verifyTaskCheckout, w as artifactCacheKey, x as assertExactObjectKeys, z as omitTopLevelDigest } from "./sandbox-profile-compat-DtuJWFrM.js";
2
- import { _ as parseAgentCandidateProfileActivation, c as buildLaunch, f as exactProfileExecutorFiles, h as modelRoutes, l as candidateEntrypointReceipt, m as materializeAgentCandidateProfilePlan, n as PI_CANDIDATE_SESSION_DIR_ENV, r as absoluteExecutionCwd, s as assertCandidateProfileExecutionSupport, t as PI_CANDIDATE_AGENT_DIR_ENV, u as candidateProfileAgentPaths, x as requirePublicCandidateConfigValue } from "./profile-JLJd2wFG.js";
3
- import { i as redactProtectedValue, n as createProtectedRecordRedactor, r as redactProtectedReason, t as assertNoProtectedBytes } from "./protected-redaction-DFCeo4vg.js";
1
+ import { A as verifyMaterializedProfileWorkspace, B as sha256Bytes$1, D as readMaterializedWorkspaceFiles, F as canonicalCandidateDocument, H as hasControlCharacter, I as deepFreezeCandidate, L as embeddedCandidateArtifact, M as verifyWorkspaceSnapshotArtifacts, N as canonicalCandidateBytes$1, O as readVerifiedArtifact, P as canonicalCandidateDigest$1, R as immutableCandidateValue, S as isWellFormedUnicode, Z as errorMessage, b as persistCandidateOutputArtifact, d as readCandidateGitHubResource, f as verifyCandidateCode, j as verifyMaterializedWorkspace, k as verifyBytes, m as verifyTaskOutcomePatch, p as verifyTaskCheckout, w as artifactCacheKey, x as assertExactObjectKeys, z as omitTopLevelDigest } from "./sandbox-profile-compat-BxMQ1VXv.js";
2
+ import { _ as parseAgentCandidateProfileActivation, c as buildLaunch, f as exactProfileExecutorFiles, h as modelRoutes, l as candidateEntrypointReceipt, m as materializeAgentCandidateProfilePlan, n as PI_CANDIDATE_SESSION_DIR_ENV, r as absoluteExecutionCwd, s as assertCandidateProfileExecutionSupport, t as PI_CANDIDATE_AGENT_DIR_ENV, u as candidateProfileAgentPaths, x as requirePublicCandidateConfigValue } from "./profile-CAhZDW2T.js";
3
+ import { i as redactProtectedValue, n as createProtectedRecordRedactor, r as redactProtectedReason, t as assertNoProtectedBytes } from "./protected-redaction-DilFZch5.js";
4
4
  import { agentCandidateArtifactRefSchema, agentCandidateBenchmarkResultEvidenceSchema, agentCandidateBenchmarkSuiteSchema, agentCandidateBenchmarkTaskSchema, agentCandidateBundleSchema, agentCandidateContainerSchema, agentCandidateExecutionLimitsSchema, agentCandidateExecutionPlanEvidenceSchema, agentCandidateExecutionPlanMaterialSchema, agentCandidateMaterializationReceiptSchema, agentCandidateModelAccessNetworkSchema, agentCandidateModelSettlementEvidenceSchema, agentCandidateProfilePlanEvidenceSchema, agentCandidateResolvedModelSchema, agentCandidateRunCellSchema, agentCandidateRunReceiptSchema, agentCandidateTaskOutcomeEvidenceSchema, agentCandidateTaskOutcomeSpecSchema, agentCandidateTerminationSchema, agentCandidateWorkspaceManifestMaterialSchema, agentCandidateWorkspaceSnapshotEvidenceSchema, sha256DigestSchema } from "@tangle-network/agent-interface";
5
5
  import { REDACTION_VERSION, isLlmSpan } from "@tangle-network/agent-eval";
6
6
  import { createHash, randomBytes, timingSafeEqual } from "node:crypto";
@@ -10,7 +10,7 @@ import { applyAgentCandidateWorkspacePlan } from "@tangle-network/agent-profile-
10
10
  import { isDeepStrictEqual } from "node:util";
11
11
  import { tmpdir } from "node:os";
12
12
  import { hashKnowledgeBase } from "@tangle-network/agent-knowledge";
13
- //#region src/candidate-execution/execution-roots.ts
13
+ // src/candidate-execution/execution-roots.ts
14
14
  /** Validate the canonical identity and isolation boundary for execution roots. */
15
15
  function assertAgentCandidateExecutionRoots(roots) {
16
16
  const entries = [
@@ -40,8 +40,7 @@ function executionPathsOverlap(left, right) {
40
40
  const b = posix.normalize(right);
41
41
  return a === b || b.startsWith(a === "/" ? "/" : `${a}/`) || a.startsWith(b === "/" ? "/" : `${b}/`);
42
42
  }
43
- //#endregion
44
- //#region src/candidate-execution/types.ts
43
+ // src/candidate-execution/types.ts
45
44
  const verifiedCandidateBrand = Symbol("verifiedAgentCandidate");
46
45
  const preparedCandidateBrand = Symbol("preparedAgentCandidate");
47
46
  const verifiedTaskOutcomeBrand = Symbol("verifiedTaskOutcome");
@@ -60,8 +59,7 @@ const CANDIDATE_TRACE_ENV = {
60
59
  materializationReceiptDigest: "TANGLE_CANDIDATE_MATERIALIZATION_RECEIPT_DIGEST",
61
60
  traceRunId: "TANGLE_TRACE_RUN_ID"
62
61
  };
63
- //#endregion
64
- //#region src/candidate-execution/verify.ts
62
+ // src/candidate-execution/verify.ts
65
63
  const verifiedCandidateState = /* @__PURE__ */ new WeakMap();
66
64
  /** Surfaces admitted by Runtime's verifier before an environment adapter is selected. */
67
65
  const AGENT_CANDIDATE_EXECUTION_SUPPORT = Object.freeze({
@@ -174,8 +172,7 @@ function candidateResources(bundle) {
174
172
  function resourceKey(resource) {
175
173
  return canonicalCandidateDigest$1(resource);
176
174
  }
177
- //#endregion
178
- //#region src/candidate-execution/knowledge.ts
175
+ // src/candidate-execution/knowledge.ts
179
176
  /** Environment variable containing the materialized candidate knowledge root. */
180
177
  const CANDIDATE_KNOWLEDGE_ROOT_ENV = "TANGLE_CANDIDATE_KNOWLEDGE_ROOT";
181
178
  /** Environment variable containing the materialized retrieval configuration path. */
@@ -225,10 +222,9 @@ async function prepareAgentCandidateKnowledge(candidate, ports, arm) {
225
222
  });
226
223
  }
227
224
  }
228
- //#endregion
229
- //#region src/candidate-execution/exact-process-executor.ts
225
+ // src/candidate-execution/exact-process-executor.ts
230
226
  const DEFAULT_PROVISION_TIMEOUT_MS = 12e4;
231
- const DEFAULT_RECOVERY_RETENTION_MS = 15 * 6e4;
227
+ const DEFAULT_RECOVERY_RETENTION_MS = 9e5;
232
228
  /** Adapt one neutral exact-process provider to Runtime's trusted candidate boundary. */
233
229
  function exactProcessProviderAsCandidateExecutor(options) {
234
230
  return new ExactProcessAgentCandidateExecutor(options);
@@ -266,7 +262,7 @@ var ExactProcessAgentCandidateExecutor = class {
266
262
  if (this.states.has(key)) throw new Error("candidate execution environment is already active");
267
263
  const image = exactImage(request.executionPlan.value.material.container.image, request.executionPlan.value.material.container.manifestDigest);
268
264
  const maxLifetimeMs = environmentLifetimeMs(request.hardLimits.timeoutMs, this.recoveryRetentionMs);
269
- const createInputDigest = canonicalCandidateDigest$1(immutableCandidateValue({
265
+ const createMaterial = immutableCandidateValue({
270
266
  kind: "agent-candidate-exact-process-create",
271
267
  provider: this.options.provider.name,
272
268
  executionId: request.executionId,
@@ -281,7 +277,8 @@ var ExactProcessAgentCandidateExecutor = class {
281
277
  maxBytes: outcome.maxBytes
282
278
  },
283
279
  ...this.providerOptions ? { providerOptions: this.providerOptions } : {}
284
- }));
280
+ });
281
+ const createInputDigest = canonicalCandidateDigest$1(createMaterial);
285
282
  const metadata = immutableCandidateValue({
286
283
  kind: "agent-candidate-execution",
287
284
  provider: this.options.provider.name,
@@ -689,8 +686,7 @@ function beneath(root, relativePath) {
689
686
  function isSha256Digest$1(value) {
690
687
  return typeof value === "string" && /^sha256:[a-f0-9]{64}$/.test(value);
691
688
  }
692
- //#endregion
693
- //#region src/candidate-execution/model-settlement.ts
689
+ // src/candidate-execution/model-settlement.ts
694
690
  const USD_NANOS = 1e9;
695
691
  /** Validate and detach the evaluator gateway's terminal, revoked call ledger. */
696
692
  function sealAgentCandidateModelSettlement(settlement, expected) {
@@ -877,10 +873,9 @@ function safeAdd(left, right, label) {
877
873
  if (!Number.isSafeInteger(total)) throw new Error(`${label} exceeds safe integer range`);
878
874
  return total;
879
875
  }
880
- //#endregion
881
- //#region src/candidate-execution/protected-model-port.ts
876
+ // src/candidate-execution/protected-model-port.ts
882
877
  const MAX_RECENT_SETTLEMENTS = 4096;
883
- const RECOVERED_SETTLEMENT_RETENTION_MS = 900 * 1e3;
878
+ const RECOVERED_SETTLEMENT_RETENTION_MS = 9e5;
884
879
  /**
885
880
  * Bind a protected model-grant service to the immutable candidate runtime.
886
881
  *
@@ -897,7 +892,8 @@ function createProtectedAgentCandidateModelPort(options) {
897
892
  return {
898
893
  resolve: async (input) => {
899
894
  const request = immutableCandidateValue(input);
900
- return immutableCandidateValue(validateResolvedModel(await options.resolveModel(request), request));
895
+ const resolved = validateResolvedModel(await options.resolveModel(request), request);
896
+ return immutableCandidateValue(resolved);
901
897
  },
902
898
  reserveGrant: async (input) => {
903
899
  pruneExpiredState(reservations, expiredReservations, recentSettlements, Date.now());
@@ -1179,8 +1175,7 @@ function modelLimits(limits) {
1179
1175
  maxCostUsd: limits.maxCostUsd
1180
1176
  };
1181
1177
  }
1182
- //#endregion
1183
- //#region src/candidate-execution/claim-file-formats.ts
1178
+ // src/candidate-execution/claim-file-formats.ts
1184
1179
  function sealCandidatePreparationEvidence(value, executionPlanDigest) {
1185
1180
  if (value === null || typeof value !== "object" || Array.isArray(value)) throw new Error("candidate execution preparation evidence must be an object");
1186
1181
  const record = value;
@@ -1193,8 +1188,7 @@ function sealCandidatePreparationEvidence(value, executionPlanDigest) {
1193
1188
  materializationReceipt
1194
1189
  });
1195
1190
  }
1196
- //#endregion
1197
- //#region src/candidate-execution/claim-terminal.ts
1191
+ // src/candidate-execution/claim-terminal.ts
1198
1192
  const SHA256_PATTERN$1 = /^sha256:[a-f0-9]{64}$/;
1199
1193
  function terminalRecord(claim, result) {
1200
1194
  const terminal = sealTerminalResult(result);
@@ -1476,8 +1470,7 @@ function assertSha256Digest$1(value, field) {
1476
1470
  function assertCount(value, label) {
1477
1471
  if (!Number.isSafeInteger(value) || value < 0) throw new Error(`candidate execution ${label} must be a non-negative safe integer`);
1478
1472
  }
1479
- //#endregion
1480
- //#region src/candidate-execution/cleanup.ts
1473
+ // src/candidate-execution/cleanup.ts
1481
1474
  const DEFAULT_CANDIDATE_CLEANUP_TIMEOUT_MS = 3e4;
1482
1475
  function candidateCleanupTimeout(timeoutMs) {
1483
1476
  const effective = timeoutMs ?? DEFAULT_CANDIDATE_CLEANUP_TIMEOUT_MS;
@@ -1539,8 +1532,7 @@ var CandidateResultTimeoutError = class extends Error {
1539
1532
  this.name = "CandidateResultTimeoutError";
1540
1533
  }
1541
1534
  };
1542
- //#endregion
1543
- //#region src/candidate-execution/claim.ts
1535
+ // src/candidate-execution/claim.ts
1544
1536
  /** Durable one-shot lifecycle for candidate execution attempts. */
1545
1537
  function attemptRecord(claim, phase, staged, terminal) {
1546
1538
  return Object.freeze({
@@ -1879,8 +1871,7 @@ const candidateClaimFileInternals = Object.freeze({
1879
1871
  sealClaim,
1880
1872
  sealLease
1881
1873
  });
1882
- //#endregion
1883
- //#region src/candidate-execution/execution-window.ts
1874
+ // src/candidate-execution/execution-window.ts
1884
1875
  const CANDIDATE_TERMINAL_PERSISTENCE_MARGIN_MS = 1e4;
1885
1876
  const CANDIDATE_POST_RUN_CLEANUP_PHASES = 4;
1886
1877
  /** Process stop, access closure, model evidence, and task/result evidence. */
@@ -1901,8 +1892,7 @@ function candidateTerminalWindowMs(cleanupTimeoutMs) {
1901
1892
  if (!Number.isSafeInteger(windowMs) || windowMs > 2147483647) throw new Error("candidate terminal window exceeds the supported timer range");
1902
1893
  return windowMs;
1903
1894
  }
1904
- //#endregion
1905
- //#region src/candidate-execution/prepared-state.ts
1895
+ // src/candidate-execution/prepared-state.ts
1906
1896
  const stateByExecution = /* @__PURE__ */ new WeakMap();
1907
1897
  const lifecycleByExecution = /* @__PURE__ */ new WeakMap();
1908
1898
  function createPreparedCandidateExecution(input) {
@@ -2037,7 +2027,8 @@ function detachPreparedCandidateState(input) {
2037
2027
  const profilePlan = immutableCandidateValue(agentCandidateProfilePlanEvidenceSchema.parse(input.profilePlan.value));
2038
2028
  const profileActivation = parseAgentCandidateProfileActivation(input.profileActivation, profilePlan.digest);
2039
2029
  const executionPlan = immutableCandidateValue(agentCandidateExecutionPlanEvidenceSchema.parse(input.executionPlan.value));
2040
- const materializationReceipt = canonicalCandidateDocument(omitTopLevelDigest(immutableCandidateValue(agentCandidateMaterializationReceiptSchema.parse(input.materializationReceipt.value))));
2030
+ const receiptValue = immutableCandidateValue(agentCandidateMaterializationReceiptSchema.parse(input.materializationReceipt.value));
2031
+ const materializationReceipt = canonicalCandidateDocument(omitTopLevelDigest(receiptValue));
2041
2032
  if (materializationReceipt.digest !== input.materializationReceipt.digest) throw new Error("materialization receipt digest changed while sealing prepared execution");
2042
2033
  return Object.freeze({
2043
2034
  ports: input.ports,
@@ -2087,7 +2078,8 @@ function detachPreparedCandidateState(input) {
2087
2078
  }
2088
2079
  function assertPrivateCandidateIntegrity(state) {
2089
2080
  assertAgentCandidateExecutionRoots(state.roots.execution);
2090
- if (canonicalCandidateDigest$1(omitTopLevelDigest(state.bundle)) !== state.bundle.digest) throw new Error("prepared candidate bundle no longer matches its digest");
2081
+ const bundleMaterial = omitTopLevelDigest(state.bundle);
2082
+ if (canonicalCandidateDigest$1(bundleMaterial) !== state.bundle.digest) throw new Error("prepared candidate bundle no longer matches its digest");
2091
2083
  assertPlanEvidence(state.profilePlan.value, state.profilePlan.bytes, "profile plan");
2092
2084
  parseAgentCandidateProfileActivation(state.profileActivation, state.profilePlan.value.digest);
2093
2085
  assertPlanEvidence(state.executionPlan.value, state.executionPlan.bytes, "execution plan");
@@ -2248,8 +2240,7 @@ function assertProtectedEnvironment(state, modelEnvironment, memoryEnvironment)
2248
2240
  seen.add(name);
2249
2241
  }
2250
2242
  }
2251
- //#endregion
2252
- //#region src/candidate-execution/claim-plan.ts
2243
+ // src/candidate-execution/claim-plan.ts
2253
2244
  /** Extract the complete durable claim from a prepared execution. */
2254
2245
  function candidateExecutionClaim(prepared, preparationEvidence) {
2255
2246
  const state = assertPreparedCandidateIntegrity(prepared);
@@ -2333,8 +2324,7 @@ function retryLineageDigest(prepared, resultTimeoutMs) {
2333
2324
  }
2334
2325
  });
2335
2326
  }
2336
- //#endregion
2337
- //#region src/candidate-execution/finalize.ts
2327
+ // src/candidate-execution/finalize.ts
2338
2328
  /** Builds a candidate run receipt exclusively from protected trace and memory evidence. */
2339
2329
  async function finalizeAgentCandidateRun(state, capture, traceStore, traceIdentity, settlement, evidence, protectedValues, writeRedactionReport, signal) {
2340
2330
  let termination;
@@ -2373,7 +2363,7 @@ async function finalizeAgentCandidateRun(state, capture, traceStore, traceIdenti
2373
2363
  }, protectedValues);
2374
2364
  const combinedByRule = { ...writeRedactionReport?.byRule ?? {} };
2375
2365
  for (const [rule, count] of Object.entries(redacted.report.byRule)) combinedByRule[rule] = (combinedByRule[rule] ?? 0) + count;
2376
- const traceBytes = canonicalCandidateBytes$1({
2366
+ const traceMaterial = {
2377
2367
  ...redacted.value,
2378
2368
  evaluatorLimits: { resultTimeoutMs: state.resultTimeoutMs },
2379
2369
  redaction: {
@@ -2381,7 +2371,8 @@ async function finalizeAgentCandidateRun(state, capture, traceStore, traceIdenti
2381
2371
  redactionCount: (writeRedactionReport?.redactionCount ?? 0) + redacted.report.redactionCount,
2382
2372
  byRule: combinedByRule
2383
2373
  }
2384
- });
2374
+ };
2375
+ const traceBytes = canonicalCandidateBytes$1(traceMaterial);
2385
2376
  assertNoProtectedBytes(traceBytes, protectedValues);
2386
2377
  const trace = {
2387
2378
  artifact: await persistCandidateOutputArtifact(evidence.outputArtifacts, {
@@ -2514,8 +2505,7 @@ function failedAgentCandidateRun(state, reason, termination, usage = null) {
2514
2505
  function compareStrings(a, b) {
2515
2506
  return a < b ? -1 : a > b ? 1 : 0;
2516
2507
  }
2517
- //#endregion
2518
- //#region src/candidate-execution/benchmark-grader.ts
2508
+ // src/candidate-execution/benchmark-grader.ts
2519
2509
  /**
2520
2510
  * Admit verified grader bytes to the evaluator runner and reject any result
2521
2511
  * that is not bound to those bytes, the exact task outcome, and its raw output.
@@ -2560,12 +2550,13 @@ async function runBoundCandidateBenchmarkGrader(input) {
2560
2550
  }
2561
2551
  function snapshotGraderDescriptor(grader, expected) {
2562
2552
  if (!grader.name || !grader.version) throw new Error("candidate benchmark grader name and version must be non-empty");
2563
- if (canonicalCandidateDigest$1({
2553
+ const actual = {
2564
2554
  name: grader.name,
2565
2555
  version: grader.version,
2566
2556
  format: "tangle-grader",
2567
2557
  artifact: grader.artifact
2568
- }) !== canonicalCandidateDigest$1(expected)) throw new Error("candidate benchmark grader does not match the signed task grader");
2558
+ };
2559
+ if (canonicalCandidateDigest$1(actual) !== canonicalCandidateDigest$1(expected)) throw new Error("candidate benchmark grader does not match the signed task grader");
2569
2560
  return immutableCandidateValue(expected);
2570
2561
  }
2571
2562
  function emptyFixedSpend() {
@@ -2598,8 +2589,7 @@ function assertExactRunnerResult(value) {
2598
2589
  const bindingKeys = Object.keys(result.binding).sort();
2599
2590
  if (bindingKeys.length !== 3 || bindingKeys[0] !== "implementationDigest" || bindingKeys[1] !== "outputDigest" || bindingKeys[2] !== "taskOutcomeDigest") throw new Error("candidate benchmark grader binding returned unknown or missing fields");
2600
2591
  }
2601
- //#endregion
2602
- //#region src/candidate-execution/executor-capture-evidence.ts
2592
+ // src/candidate-execution/executor-capture-evidence.ts
2603
2593
  /** Persist structurally valid post-stop bytes without claiming they passed outcome verification. */
2604
2594
  async function persistAgentCandidateExecutorCapture(identity, expected, capture, outputArtifacts, signal) {
2605
2595
  const executorEvidence = capture.evidence ? await persistCandidateOutputArtifact(outputArtifacts, {
@@ -2681,8 +2671,7 @@ async function persistWorkspaceCapture(executionId, manifestPurpose, archivePurp
2681
2671
  archive
2682
2672
  };
2683
2673
  }
2684
- //#endregion
2685
- //#region src/candidate-execution/outcome-evidence.ts
2674
+ // src/candidate-execution/outcome-evidence.ts
2686
2675
  /** Persist the closed evaluator model ledger as canonical receipt evidence. */
2687
2676
  async function persistCandidateModelSettlement(state, settlement, outputArtifacts) {
2688
2677
  return await persistCandidateModelSettlementEvidence({
@@ -3033,8 +3022,7 @@ async function persistFailureEvidence(state, reason, failureClass, termination,
3033
3022
  bytes
3034
3023
  });
3035
3024
  }
3036
- //#endregion
3037
- //#region src/candidate-execution/execute-cleanup.ts
3025
+ // src/candidate-execution/execute-cleanup.ts
3038
3026
  /**
3039
3027
  * Failure and cleanup paths of an execution: closing isolated memory, settling the model grant,
3040
3028
  * recording a failed attempt's terminal result, and reporting why a run failed.
@@ -3129,8 +3117,7 @@ function protectedEnvironmentValues(activation, memoryActivation) {
3129
3117
  function joinErrors(...errors) {
3130
3118
  return errors.filter((error) => error !== void 0).map(errorMessage).join("; ");
3131
3119
  }
3132
- //#endregion
3133
- //#region src/candidate-execution/executor-capture.ts
3120
+ // src/candidate-execution/executor-capture.ts
3134
3121
  const sealedFinalCaptureBrand = Symbol("sealedAgentCandidateExecutorFinalCapture");
3135
3122
  /** Validate and detach the only candidate-authored fields accepted from execution. */
3136
3123
  function sealAgentCandidateProtectedRunCapture(value) {
@@ -3212,8 +3199,7 @@ function requireRecord(value, label) {
3212
3199
  if (!value || typeof value !== "object" || Array.isArray(value)) throw new Error(`${label} must be an object`);
3213
3200
  return value;
3214
3201
  }
3215
- //#endregion
3216
- //#region src/candidate-execution/execute-executor.ts
3202
+ // src/candidate-execution/execute-executor.ts
3217
3203
  /** Run the executor until it returns or the deadline passes, then stop and capture it. */
3218
3204
  async function runAndStopExecutor(executor, request, expectedOutcome, traceStore, deadlineAtMs, cleanupTimeoutMs) {
3219
3205
  const timeoutMs = request.hardLimits.timeoutMs;
@@ -3385,8 +3371,7 @@ var CandidateExecutionDeadlineError = class extends Error {
3385
3371
  this.name = "CandidateExecutionDeadlineError";
3386
3372
  }
3387
3373
  };
3388
- //#endregion
3389
- //#region src/candidate-execution/protected-trace-store.ts
3374
+ // src/candidate-execution/protected-trace-store.ts
3390
3375
  /** Keep the identity key in evaluator-owned closures and expose only the redacting store to code. */
3391
3376
  function createProtectedAgentCandidateTraceAccess(inner, protectedValues) {
3392
3377
  const redactor = createProtectedRecordRedactor(protectedValues);
@@ -3436,8 +3421,7 @@ function createProtectedAgentCandidateTraceAccess(inner, protectedValues) {
3436
3421
  report: () => redactor.report()
3437
3422
  });
3438
3423
  }
3439
- //#endregion
3440
- //#region src/candidate-execution/execute.ts
3424
+ // src/candidate-execution/execute.ts
3441
3425
  /** Executes and finalizes one durably claimed candidate without exposing an unproven result. */
3442
3426
  async function executePreparedAgentCandidate(prepared, options) {
3443
3427
  const initialState = assertPreparedCandidateIntegrity(prepared);
@@ -3698,8 +3682,7 @@ async function finalizeEvidence(run, options, claimed, settled, modelSettlement)
3698
3682
  return failedAgentCandidateRun(state, redactProtectedReason(errorMessage(error), protectedValues), execution.termination, settlement.usage);
3699
3683
  }
3700
3684
  }
3701
- //#endregion
3702
- //#region src/candidate-execution/prepare-plan.ts
3685
+ // src/candidate-execution/prepare-plan.ts
3703
3686
  /**
3704
3687
  * The evaluator-owned documents of a preparation: the launch environment, the execution plan,
3705
3688
  * the materialization receipt, and the trace bindings that tie a run back to them.
@@ -3867,8 +3850,7 @@ function assertEnvironmentDisjoint(publicEnv, traceEnv) {
3867
3850
  seen.add(name);
3868
3851
  }
3869
3852
  }
3870
- //#endregion
3871
- //#region src/candidate-execution/prepare-workspaces.ts
3853
+ // src/candidate-execution/prepare-workspaces.ts
3872
3854
  /**
3873
3855
  * The three host staging roots of a preparation: the task workspace, the candidate workspace,
3874
3856
  * and the profile workspace, each materialized and verified against its signed material.
@@ -3946,10 +3928,9 @@ async function assertEmptyDirectory(path) {
3946
3928
  if (!stats.isDirectory() || stats.isSymbolicLink()) throw new Error("profile staging root must be a real directory");
3947
3929
  if ((await readdir(path)).length !== 0) throw new Error("profile staging root must be empty before materialization");
3948
3930
  }
3949
- //#endregion
3950
- //#region src/candidate-execution/prepare.ts
3951
- const MIN_RESERVATION_TTL_MS = 15 * 6e4;
3952
- const PREPARED_HOLD_MARGIN_MS = 5 * 6e4;
3931
+ // src/candidate-execution/prepare.ts
3932
+ const MIN_RESERVATION_TTL_MS = 9e5;
3933
+ const PREPARED_HOLD_MARGIN_MS = 3e5;
3953
3934
  /** Materializes a verified candidate into one immutable evaluator-owned execution plan. */
3954
3935
  async function prepareAgentCandidateExecution(candidate, task, ports, options = {}) {
3955
3936
  const { cleanupTimeoutMs, resultTimeoutMs, reservationWindowMs } = checkPreparation(candidate, task, ports, options);
@@ -4335,7 +4316,6 @@ async function cleanupFailedPreparation(held, error) {
4335
4316
  const cleanupErrors = (await Promise.allSettled(cleanup)).filter((result) => result.status === "rejected").map((result) => result.reason);
4336
4317
  if (cleanupErrors.length > 0) throw new Error(`candidate preparation failed and protected access cleanup failed: ${cleanupErrors.map(errorMessage).join("; ")}`, { cause: error });
4337
4318
  }
4338
- //#endregion
4339
4319
  export { verifiedResourceTextByDigest as C, AGENT_CANDIDATE_EXECUTION_SUPPORT as S, sealTerminalDigest as _, consumePreparedCandidateExecution as a, sealAgentCandidateModelSettlement as b, withinCandidateCleanupDeadline as c, assertTerminalMatchesClaim as d, assertTerminalMatchesStaged as f, requireStagedTerminal as g, rejectedStage as h, beginPreparedCandidateDisposal as i, assertRecoveryMatchesStaged as l, rejectedFinish as m, executePreparedAgentCandidate as n, candidateClaimFileInternals as o, recoveredTerminalRecord as p, assertPreparedCandidateIntegrity as r, candidateCleanupDeadline as s, prepareAgentCandidateExecution as t, assertTerminalAllowedInPhase as u, terminalRecord as v, verifyAgentCandidateBundle as w, exactProcessProviderAsCandidateExecutor as x, createProtectedAgentCandidateModelPort as y };
4340
4320
 
4341
- //# sourceMappingURL=prepare-B9wWffjO.js.map
4321
+ //# sourceMappingURL=prepare-DE8TQnLu.js.map