@tangle-network/agent-app 0.63.29 → 0.63.31

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 (147) hide show
  1. package/dist/{DesignCanvas-3DGZQOD7.js → DesignCanvas-VKZ7Y3JU.js} +2 -3
  2. package/dist/{DesignCanvasEditor-OG4QY5WJ.js → DesignCanvasEditor-3V53YLLZ.js} +2 -3
  3. package/dist/agent-profiles/d1.js +4 -3
  4. package/dist/agent-profiles/d1.js.map +1 -1
  5. package/dist/agent-profiles/index.js +4 -3
  6. package/dist/alerting/github.d.ts +33 -0
  7. package/dist/alerting/index.d.ts +1 -0
  8. package/dist/alerting/index.js +47 -0
  9. package/dist/alerting/index.js.map +1 -1
  10. package/dist/app-auth/index.js +1 -2
  11. package/dist/app-auth/index.js.map +1 -1
  12. package/dist/assistant/index.js +4 -4
  13. package/dist/billing/index.d.ts +15 -0
  14. package/dist/billing/index.js +5 -3
  15. package/dist/chat-routes/default-backend.d.ts +19 -2
  16. package/dist/chat-routes/hybrid-producer.d.ts +7 -2
  17. package/dist/chat-routes/index.js +16 -15
  18. package/dist/chat-routes/index.js.map +1 -1
  19. package/dist/chat-routes/route-storage.d.ts +1 -1
  20. package/dist/chat-routes/router-producer.d.ts +2 -1
  21. package/dist/chat-routes/turn-route-contracts.d.ts +1 -1
  22. package/dist/chat-store/index.js +34 -4
  23. package/dist/chat-store/index.js.map +1 -1
  24. package/dist/chat-store/schema.d.ts +286 -0
  25. package/dist/{chunk-6JEDSKFH.js → chunk-2SDX3OC4.js} +32 -24
  26. package/dist/{chunk-6JEDSKFH.js.map → chunk-2SDX3OC4.js.map} +1 -1
  27. package/dist/{chunk-DCJCZ7EP.js → chunk-4CEIZZTH.js} +44 -26
  28. package/dist/chunk-4CEIZZTH.js.map +1 -0
  29. package/dist/{chunk-WL7PZK7Q.js → chunk-4PIN6QYQ.js} +43 -1
  30. package/dist/chunk-4PIN6QYQ.js.map +1 -0
  31. package/dist/{chunk-6UMIOEDR.js → chunk-AZRPDSRQ.js} +3 -3
  32. package/dist/{chunk-6LMM3OVX.js → chunk-BMCC2BUP.js} +3 -3
  33. package/dist/{chunk-36HSG7HU.js → chunk-CRZXEKCX.js} +2 -2
  34. package/dist/chunk-F4XBNR5L.js +16 -0
  35. package/dist/chunk-F4XBNR5L.js.map +1 -0
  36. package/dist/chunk-GY4IPYG4.js +40 -0
  37. package/dist/chunk-GY4IPYG4.js.map +1 -0
  38. package/dist/{chunk-QUT3T2IN.js → chunk-L3QR274L.js} +11 -3
  39. package/dist/chunk-L3QR274L.js.map +1 -0
  40. package/dist/{chunk-6OG4244Y.js → chunk-MTKD2FN5.js} +2 -251
  41. package/dist/chunk-MTKD2FN5.js.map +1 -0
  42. package/dist/{chunk-56JUV4DK.js → chunk-NDXQFEZQ.js} +3332 -3014
  43. package/dist/chunk-NDXQFEZQ.js.map +1 -0
  44. package/dist/chunk-NSWLZTJX.js +645 -0
  45. package/dist/chunk-NSWLZTJX.js.map +1 -0
  46. package/dist/chunk-PU6AWIRE.js +252 -0
  47. package/dist/chunk-PU6AWIRE.js.map +1 -0
  48. package/dist/{chunk-JKECSYDB.js → chunk-PV3GSLUY.js} +3 -3
  49. package/dist/{chunk-7Y7U7U7X.js → chunk-Q7RSHLEV.js} +5 -3
  50. package/dist/{chunk-7Y7U7U7X.js.map → chunk-Q7RSHLEV.js.map} +1 -1
  51. package/dist/{chunk-HRBF4B5L.js → chunk-TUJ4277Q.js} +1 -14
  52. package/dist/chunk-TUJ4277Q.js.map +1 -0
  53. package/dist/{chunk-57XPEL7X.js → chunk-V42C72V5.js} +25 -2
  54. package/dist/chunk-V42C72V5.js.map +1 -0
  55. package/dist/{chunk-FCYHDENJ.js → chunk-VOIVDEAV.js} +2 -2
  56. package/dist/{chunk-ACB7KOQ6.js → chunk-WSQSKYXP.js} +4 -4
  57. package/dist/{chunk-F6J5J4H6.js → chunk-WYQTPFPI.js} +26 -2
  58. package/dist/chunk-WYQTPFPI.js.map +1 -0
  59. package/dist/{chunk-PFTOGTHH.js → chunk-Z3IJ7XEW.js} +3 -3
  60. package/dist/{chunk-ZD2AUFIT.js → chunk-ZGGEYYEQ.js} +3 -3
  61. package/dist/{chunk-O5AUJQIA.js → chunk-ZNWJJRHP.js} +2 -2
  62. package/dist/design-canvas/index.js +1 -2
  63. package/dist/design-canvas/index.js.map +1 -1
  64. package/dist/design-canvas-react/engine.js +1 -2
  65. package/dist/design-canvas-react/index.js +2 -3
  66. package/dist/design-canvas-react/index.js.map +1 -1
  67. package/dist/design-canvas-react/lazy.js +1 -1
  68. package/dist/media/generate-request.d.ts +27 -1
  69. package/dist/media/index.js +36 -426
  70. package/dist/media/index.js.map +1 -1
  71. package/dist/media/router-generation.d.ts +7 -0
  72. package/dist/model-resolution/index.js +1 -1
  73. package/dist/operator/gateway-keys.d.ts +44 -0
  74. package/dist/operator/index.d.ts +1 -0
  75. package/dist/operator/index.js +55 -1
  76. package/dist/operator/index.js.map +1 -1
  77. package/dist/plans/decision.d.ts +31 -0
  78. package/dist/plans/drizzle.js +1 -1
  79. package/dist/plans/index.js +5 -1
  80. package/dist/platform/billing.d.ts +3 -2
  81. package/dist/platform/deployment.d.ts +21 -0
  82. package/dist/platform/index.d.ts +1 -0
  83. package/dist/platform/index.js +30 -10
  84. package/dist/platform/index.js.map +1 -1
  85. package/dist/preset-cloudflare/index.js +9 -8
  86. package/dist/preset-cloudflare/index.js.map +1 -1
  87. package/dist/public-consultation/index.d.ts +1 -1
  88. package/dist/public-consultation/index.js +14 -13
  89. package/dist/public-consultation/index.js.map +1 -1
  90. package/dist/sandbox/computer-files.d.ts +67 -0
  91. package/dist/sandbox/computer-receipts.d.ts +46 -0
  92. package/dist/sandbox/computer-step.d.ts +78 -0
  93. package/dist/sandbox/index.d.ts +5 -0
  94. package/dist/sandbox/index.js +34 -5
  95. package/dist/sandbox/router-model-policy.d.ts +31 -0
  96. package/dist/sandbox/router-models.d.ts +26 -0
  97. package/dist/sandbox/sandbox-run-tool.d.ts +5 -4
  98. package/dist/sequences/index.js +1 -2
  99. package/dist/sequences/index.js.map +1 -1
  100. package/dist/spend/drizzle.d.ts +195 -0
  101. package/dist/spend/drizzle.js +22 -0
  102. package/dist/spend/drizzle.js.map +1 -1
  103. package/dist/stream/index.js +2 -2
  104. package/dist/studio/generated-media/flows.d.ts +240 -0
  105. package/dist/studio/generated-media/index.d.ts +3 -1
  106. package/dist/studio/generated-media/index.js +357 -138
  107. package/dist/studio/generated-media/index.js.map +1 -1
  108. package/dist/studio/index.js +18 -16
  109. package/dist/studio-react/index.js +28 -26
  110. package/dist/studio-react/index.js.map +1 -1
  111. package/dist/teams/index.d.ts +1 -0
  112. package/dist/teams/index.js +16 -0
  113. package/dist/teams/index.js.map +1 -1
  114. package/dist/teams/invitations-api.js +1 -1
  115. package/dist/teams/members-api.d.ts +5 -3
  116. package/dist/teams/members-api.js +1 -1
  117. package/dist/teams/thread-access.d.ts +22 -0
  118. package/dist/tools/index.js +5 -4
  119. package/dist/web/index.js +4 -6
  120. package/dist/web-react/index.js +4 -4
  121. package/dist/work-product/index.js +3 -2
  122. package/dist/work-product/index.js.map +1 -1
  123. package/dist/workspace-export/d1.d.ts +1 -1
  124. package/dist/workspace-export/index.js +9 -2
  125. package/dist/workspace-export/index.js.map +1 -1
  126. package/package.json +1 -1
  127. package/dist/chunk-56JUV4DK.js.map +0 -1
  128. package/dist/chunk-57XPEL7X.js.map +0 -1
  129. package/dist/chunk-6OG4244Y.js.map +0 -1
  130. package/dist/chunk-6Z7TZVKZ.js +0 -26
  131. package/dist/chunk-6Z7TZVKZ.js.map +0 -1
  132. package/dist/chunk-DCJCZ7EP.js.map +0 -1
  133. package/dist/chunk-F6J5J4H6.js.map +0 -1
  134. package/dist/chunk-HRBF4B5L.js.map +0 -1
  135. package/dist/chunk-QUT3T2IN.js.map +0 -1
  136. package/dist/chunk-WL7PZK7Q.js.map +0 -1
  137. /package/dist/{DesignCanvas-3DGZQOD7.js.map → DesignCanvas-VKZ7Y3JU.js.map} +0 -0
  138. /package/dist/{DesignCanvasEditor-OG4QY5WJ.js.map → DesignCanvasEditor-3V53YLLZ.js.map} +0 -0
  139. /package/dist/{chunk-6UMIOEDR.js.map → chunk-AZRPDSRQ.js.map} +0 -0
  140. /package/dist/{chunk-6LMM3OVX.js.map → chunk-BMCC2BUP.js.map} +0 -0
  141. /package/dist/{chunk-36HSG7HU.js.map → chunk-CRZXEKCX.js.map} +0 -0
  142. /package/dist/{chunk-JKECSYDB.js.map → chunk-PV3GSLUY.js.map} +0 -0
  143. /package/dist/{chunk-FCYHDENJ.js.map → chunk-VOIVDEAV.js.map} +0 -0
  144. /package/dist/{chunk-ACB7KOQ6.js.map → chunk-WSQSKYXP.js.map} +0 -0
  145. /package/dist/{chunk-PFTOGTHH.js.map → chunk-Z3IJ7XEW.js.map} +0 -0
  146. /package/dist/{chunk-ZD2AUFIT.js.map → chunk-ZGGEYYEQ.js.map} +0 -0
  147. /package/dist/{chunk-O5AUJQIA.js.map → chunk-ZNWJJRHP.js.map} +0 -0
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/model-resolution/failover.ts"],"sourcesContent":["/**\n * Model failover — the answer to \"one upstream hit a quota wall and the customer\n * got a Bad Gateway even though the router had abundant healthy capacity\".\n *\n * This is deliberately NOT a health probe. Probing before every turn buys a\n * round-trip of latency on the happy path and still races the outage (a model\n * healthy at probe time can 502 a second later). Failover is REACTIVE: run the\n * preferred model, and on an upstream-outage signal move to the next model in\n * the chain. Zero added latency when the preferred model works.\n *\n * Two facts drive the design, both measured against a live box during the\n * 2026-07-25 Anthropic/DeepSeek outage:\n *\n * 1. An outage is NOT always a thrown error. The sandbox resolves with a\n * payload — `{ success: false, errorCode: 'provider_inference_unavailable' }`\n * — so a classifier that only inspects `catch` misses the customer-visible\n * case entirely. `isUpstreamUnavailable` inspects resolved values too.\n * 2. Catalog membership is NOT liveness. The router's `/v1/models` still listed\n * every dead model during the outage, so `validateChatModelId` admitted\n * `claude-sonnet-4-6` while every call to it returned 502. Nothing upstream\n * of the actual call can be trusted to tell you a model is serving.\n *\n * Substrate-free: the caller injects `run`, so this composes with a sandbox\n * turn, a router chat completion, or a test fake without importing any of them.\n */\n\nimport {\n checkModelPolicy,\n type ModelPolicy,\n} from '../policy-filters/index'\n\n/**\n * Error codes that mean \"this model's upstream is unavailable — a different\n * model may still work\". Deliberately excludes codes that would fail identically\n * on every model (bad request, auth, content filter): retrying those down a\n * chain burns latency and money to reach the same failure.\n */\nexport const UPSTREAM_UNAVAILABLE_CODES: readonly string[] = [\n 'provider_inference_unavailable',\n 'provider_quota_exhausted',\n 'upstream_unavailable',\n 'insufficient_quota',\n 'model_not_available',\n 'server_error',\n 'bad_gateway',\n 'service_unavailable',\n]\n\n/** HTTP statuses that indicate an upstream capacity/availability problem. */\nexport const UPSTREAM_UNAVAILABLE_STATUSES: readonly number[] = [429, 500, 502, 503, 504]\n\n/**\n * Statuses that mean the REQUEST is wrong, so every model in the chain would\n * fail on it identically. Listed explicitly rather than as \"any 4xx\" because\n * 404 is NOT one of them: a model the endpoint cannot find is model-scoped, and\n * the next model in the chain may well be there. 429 is absent for the same\n * reason in reverse — it is a capacity signal and lives in the list above.\n */\nconst REQUEST_ERROR_STATUSES: readonly number[] = [400, 401, 403, 405, 413, 422]\n\n/**\n * Message fragments emitted by real upstreams during this class of outage.\n * Matched case-insensitively as a last resort, after code and status.\n */\nconst UPSTREAM_UNAVAILABLE_MESSAGES: readonly string[] = [\n 'bad gateway',\n 'service unavailable',\n 'inference temporarily unavailable',\n 'provider inference is unavailable',\n 'insufficient balance',\n 'usage limits',\n 'quota exceeded',\n 'rate limit',\n 'overloaded',\n 'temporarily unavailable',\n // Model-SCOPED unavailability. A different model in the chain can still\n // serve, so this belongs here and not with the client errors. Measured on a\n // real box 2026-07-27: the sandbox now reports an unservable model as a\n // terminal `error` whose data is `{\"message\":\"Session error:\n // {\\\"error\\\":{\\\"name\\\":\\\"UnknownError\\\",\\\"data\\\":{\\\"message\\\":\\\"Model not\n // found: openai-compat/zai/glm-4.7.\\\"}}}\"}` — no `code`, no numeric status,\n // and none of the fragments above. The shipped live product-path proof went\n // red on exactly this: `usedFallback:false`, `failed:true`, an error row to\n // the customer where a fallback was available and would have answered.\n 'model not found',\n 'is not currently available',\n]\n\n/**\n * Textual forms an HTTP status arrives in when NO numeric field carries it.\n *\n * The case that forced this is the opaque Cloudflare 502. Captured verbatim\n * from `router.tangle.tools` (cf-ray\n * `a21d793899f6cef3-DEN`): `HTTP/2 502`, `content-type: text/plain;\n * charset=UTF-8`, a 16-byte body reading `error code: 502\\n`, `server:\n * cloudflare`, and **zero `x-tangle-*` headers** where a healthy 200 from the\n * same endpoint carries nine of them.\n *\n * That capture was originally read as \"zero headers means the origin never\n * executed\". It does not, and the correction matters more than the original\n * guess did. Matching client-observed cf-rays against the origin's own access\n * log (tangle-router #307) showed all 62 of those responses WERE produced by\n * the router — `content-type: application/json`, an `X-Generation-Id`, and a\n * routing trace showing the upstream had returned 200 — and Cloudflare\n * replaced the body and every response header with its own error page, because\n * an origin 502 reads to the edge as the origin having failed.\n *\n * The classifier's BEHAVIOR here was right for the wrong reason, and stays\n * exactly as it is. What changes is why: the rescue is needed not because the\n * origin is unreachable, but because a response the origin carefully\n * structured arrives at the client as sixteen unlabelled bytes. The router now\n * emits 503 instead of 502 on those paths so the body survives, but this\n * pattern must remain — it is the client's only handle on any origin 5xx the\n * edge decides to rewrite, including from a router that has not deployed the\n * fix yet.\n *\n * Every pattern below matches a string a real producer emits:\n * - `error code: 502` — Cloudflare's edge body (the capture above).\n * - `(HTTP 502)` — `src/runtime/openai-stream.ts` wrapping a non-ok response.\n * - `returned 502` — `src/runtime/model-catalog.ts`.\n * - `failed with status 502` — `src/turn-stream/adapters.ts`.\n * - `502 Bad Gateway` — an HTTP/1.1 status line. HTTP/2 carries no reason\n * phrase at all, which is precisely why matching the phrase alone (the\n * `'bad gateway'` fragment below) read the capture as a non-outage.\n */\nconst HTTP_STATUS_HINT_PATTERNS: readonly RegExp[] = [\n /\\berror\\s+code:?\\s*([1-5]\\d{2})\\b/i,\n /\\bhttp(?:\\/[\\d.]+)?[\\s:]\\s*([1-5]\\d{2})\\b/i,\n /\\bstatus(?:\\s*code)?[\\s:=]\\s*([1-5]\\d{2})\\b/i,\n /\\b(?:returned|responded(?:\\s+with)?)\\s+([1-5]\\d{2})\\b/i,\n /\\b([1-5]\\d{2})\\s+(?:bad\\s+gateway|service\\s+unavailable|gateway\\s+time-?out|internal\\s+server\\s+error|too\\s+many\\s+requests)\\b/i,\n]\n\n/**\n * The HTTP status a message states in prose, or `undefined` when it states\n * none. Deliberately NOT \"any three digits in the string\" — an unanchored digit\n * scan would read a token count or a duration as a status.\n */\nexport function readHttpStatusHint(text: string): number | undefined {\n for (const pattern of HTTP_STATUS_HINT_PATTERNS) {\n const match = pattern.exec(text)\n if (match?.[1]) return Number(match[1])\n }\n return undefined\n}\n\nfunction readString(source: Record<string, unknown>, key: string): string | undefined {\n const value = source[key]\n return typeof value === 'string' && value.trim().length > 0 ? value : undefined\n}\n\n/** Read a recognized upstream code, including the terminal message-only shape. */\nexport function readUpstreamUnavailableCode(signal: unknown): string | undefined {\n if (signal === null || typeof signal !== 'object') return undefined\n const record = signal as Record<string, unknown>\n const nested = record.error\n const nestedRecord = nested !== null && typeof nested === 'object' ? (nested as Record<string, unknown>) : undefined\n const code =\n readString(record, 'errorCode') ??\n readString(record, 'code') ??\n (nestedRecord ? (readString(nestedRecord, 'code') ?? readString(nestedRecord, 'type')) : undefined)\n if (code && UPSTREAM_UNAVAILABLE_CODES.includes(code)) return code\n\n const message =\n readString(record, 'message') ??\n readString(record, 'error') ??\n (nestedRecord ? readString(nestedRecord, 'message') : undefined)\n return message && /\\(\\s*provider_quota_exhausted\\s*\\)/i.test(message)\n ? 'provider_quota_exhausted'\n : undefined\n}\n\n/**\n * True when `signal` — a thrown error OR a resolved result payload — indicates\n * the model's upstream is unavailable and another model is worth trying.\n *\n * Checked in order of decreasing confidence: explicit code, HTTP status, then\n * message text. A resolved payload only counts as a failure when it carries an\n * explicit failure marker (`success: false`, or an `error`/`errorCode` field) —\n * a successful result is never misread as an outage.\n */\nexport function isUpstreamUnavailable(signal: unknown): boolean {\n if (signal === null || typeof signal !== 'object') return false\n const record = signal as Record<string, unknown>\n\n // A resolved payload that explicitly reports success is never an outage.\n if (record.success === true) return false\n\n const nested = record.error\n const nestedRecord = nested !== null && typeof nested === 'object' ? (nested as Record<string, unknown>) : undefined\n if (readUpstreamUnavailableCode(record)) return true\n\n for (const key of ['status', 'statusCode', 'httpStatus']) {\n const value = record[key]\n if (typeof value === 'number' && UPSTREAM_UNAVAILABLE_STATUSES.includes(value)) return true\n }\n\n const message =\n readString(record, 'message') ??\n readString(record, 'error') ??\n (nestedRecord ? readString(nestedRecord, 'message') : undefined)\n if (!message) return false\n\n // A status carried as PROSE, checked before the fragment list because it is\n // the stronger signal and it cuts BOTH ways. An edge 502 names no exception\n // type and sets no numeric field, so without this the shipped classifier read\n // `error code: 502` as a non-outage and handed the customer a Bad Gateway\n // instead of trying the next model — the exact failure the router cannot\n // rescue from inside its own origin.\n const hinted = readHttpStatusHint(message)\n if (hinted !== undefined) {\n if (UPSTREAM_UNAVAILABLE_STATUSES.includes(hinted)) return true\n // An explicit REQUEST-error status is decisive the OTHER way. A 400\n // carrying a validation message must surface rather than walk the chain,\n // even when its body happens to contain a word from the fragment list —\n // the router's own `Function tools with reasoning_effort are not supported`\n // 400 is a request-shaping bug that fails identically on every model.\n if (REQUEST_ERROR_STATUSES.includes(hinted)) return false\n }\n\n const lowered = message.toLowerCase()\n return UPSTREAM_UNAVAILABLE_MESSAGES.some((fragment) => lowered.includes(fragment))\n}\n\n/** One model tried, and how it went. */\nexport interface ModelFailoverAttempt {\n model: string\n ok: boolean\n /** Why this model was abandoned. Absent when `ok`. */\n reason?: string\n /** Recognized upstream code carried by this failed attempt. */\n errorCode?: string\n}\n\n/** The outcome of a failover run: the value plus the full attempt trail. */\nexport interface ModelFailoverResult<T> {\n value: T\n /** The model that actually produced `value`. */\n model: string\n attempts: ModelFailoverAttempt[]\n /** True when the preferred (first) model did not serve the request. */\n usedFallback: boolean\n}\n\n/** Every model in the chain failed; carries the trail for logging. */\nexport class ModelFailoverExhaustedError extends Error {\n readonly attempts: ModelFailoverAttempt[]\n /** Last recognized upstream code across the exhausted chain, when present. */\n readonly upstreamCode?: string\n constructor(attempts: ModelFailoverAttempt[]) {\n const trail = attempts.map((a) => `${a.model}: ${a.reason ?? 'failed'}`).join(' | ')\n super(`All ${attempts.length} model(s) failed. ${trail}`)\n this.name = 'ModelFailoverExhaustedError'\n this.attempts = attempts\n this.upstreamCode = [...attempts].reverse().find((attempt) => attempt.errorCode)?.errorCode\n }\n}\n\n/** Inputs to {@link runWithModelFailover}. */\nexport interface RunWithModelFailoverInput<T> {\n /** Preferred model first, then fallbacks in descending preference. */\n models: readonly string[]\n /** Executes one turn with the given model. */\n run: (model: string) => Promise<T>\n /**\n * Product admission policy applied to EVERY chain member before it runs.\n * Without this a compliant model 502ing mid-turn would silently re-run the\n * turn's data through a non-compliant fallback: availability is not\n * eligibility. A member the policy refuses is SKIPPED (recorded in the\n * attempt trail with the refusal as its reason) and the walk continues; when\n * no member is admitted the run ends in {@link ModelFailoverExhaustedError}\n * like any other exhausted chain. Fail-closed — a member carrying no policy\n * metadata is refused.\n */\n policy?: ModelPolicy\n /**\n * Classifies a resolved result as an upstream outage. Defaults to\n * {@link isUpstreamUnavailable}, which understands the sandbox's\n * `{ success: false, errorCode }` payload.\n */\n isUnavailableResult?: (result: T) => boolean\n /** Classifies a thrown error. Defaults to {@link isUpstreamUnavailable}. */\n isUnavailableError?: (error: unknown) => boolean\n /** Observability hook fired each time a model is abandoned — including a\n * policy refusal, whose `reason` is the policy's own refusal text. */\n onFallback?: (attempt: ModelFailoverAttempt, nextModel: string) => void\n}\n\nfunction describe(signal: unknown): string {\n if (signal instanceof Error) return signal.message\n if (signal !== null && typeof signal === 'object') {\n const record = signal as Record<string, unknown>\n const message = readString(record, 'error') ?? readString(record, 'message') ?? readString(record, 'errorCode')\n if (message) return message\n }\n return String(signal)\n}\n\n/**\n * Run `run` against the first model in `models` that does not report an upstream\n * outage, falling through the chain in order.\n *\n * A non-outage failure (bad request, auth, content filter) is re-thrown\n * immediately rather than retried down the chain — those fail identically on\n * every model, so walking the chain would only multiply latency and spend.\n *\n * @throws ModelFailoverExhaustedError when every model reports an outage or is\n * refused by the configured admission policy.\n */\nexport async function runWithModelFailover<T>(\n input: RunWithModelFailoverInput<T>,\n): Promise<ModelFailoverResult<T>> {\n const models = input.models.map((m) => m.trim()).filter((m) => m.length > 0)\n if (models.length === 0) throw new Error('runWithModelFailover requires at least one model')\n\n const isUnavailableResult = input.isUnavailableResult ?? ((r: T) => isUpstreamUnavailable(r))\n const isUnavailableError = input.isUnavailableError ?? isUpstreamUnavailable\n const attempts: ModelFailoverAttempt[] = []\n\n for (let index = 0; index < models.length; index += 1) {\n const model = models[index]!\n\n // Policy BEFORE run: a chain member the deployment does not admit never\n // sees the turn's data. The refusal is one failed attempt — the walk\n // continues to the next member, and an all-refused chain exhausts exactly\n // like an all-dead one.\n if (input.policy) {\n const decision = await checkModelPolicy(model, input.policy.catalog, input.policy.filter, input.policy.context)\n if (!decision.allowed) {\n const attempt: ModelFailoverAttempt = { model, ok: false, reason: decision.reason }\n attempts.push(attempt)\n const next = models[index + 1]\n if (next) input.onFallback?.(attempt, next)\n continue\n }\n }\n\n let result: T\n try {\n result = await input.run(model)\n } catch (error) {\n if (!isUnavailableError(error)) throw error\n const errorCode = readUpstreamUnavailableCode(error)\n const attempt: ModelFailoverAttempt = {\n model,\n ok: false,\n reason: describe(error),\n ...(errorCode ? { errorCode } : {}),\n }\n attempts.push(attempt)\n const next = models[index + 1]\n if (next) input.onFallback?.(attempt, next)\n continue\n }\n\n if (isUnavailableResult(result)) {\n const errorCode = readUpstreamUnavailableCode(result)\n const attempt: ModelFailoverAttempt = {\n model,\n ok: false,\n reason: describe(result),\n ...(errorCode ? { errorCode } : {}),\n }\n attempts.push(attempt)\n const next = models[index + 1]\n if (next) input.onFallback?.(attempt, next)\n continue\n }\n\n attempts.push({ model, ok: true })\n return { value: result, model, attempts, usedFallback: index > 0 }\n }\n\n throw new ModelFailoverExhaustedError(attempts)\n}\n\n/**\n * Build a failover chain: the preferred model first, then `fallbacks`, with\n * duplicates removed so a model is never retried twice in one turn.\n */\nexport function buildModelChain(preferred: string, fallbacks: readonly string[]): string[] {\n const chain: string[] = []\n for (const model of [preferred, ...fallbacks]) {\n const cleaned = typeof model === 'string' ? model.trim() : ''\n if (cleaned.length > 0 && !chain.includes(cleaned)) chain.push(cleaned)\n }\n return chain\n}\n"],"mappings":";;;;;AAqCO,IAAM,6BAAgD;AAAA,EAC3D;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;AAGO,IAAM,gCAAmD,CAAC,KAAK,KAAK,KAAK,KAAK,GAAG;AASxF,IAAM,yBAA4C,CAAC,KAAK,KAAK,KAAK,KAAK,KAAK,GAAG;AAM/E,IAAM,gCAAmD;AAAA,EACvD;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAUA;AAAA,EACA;AACF;AAuCA,IAAM,4BAA+C;AAAA,EACnD;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;AAOO,SAAS,mBAAmB,MAAkC;AACnE,aAAW,WAAW,2BAA2B;AAC/C,UAAM,QAAQ,QAAQ,KAAK,IAAI;AAC/B,QAAI,QAAQ,CAAC,EAAG,QAAO,OAAO,MAAM,CAAC,CAAC;AAAA,EACxC;AACA,SAAO;AACT;AAEA,SAAS,WAAW,QAAiC,KAAiC;AACpF,QAAM,QAAQ,OAAO,GAAG;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A,QAAM,IAAI,4BAA4B,QAAQ;AAChD;AAMO,SAAS,gBAAgB,WAAmB,WAAwC;AACzF,QAAM,QAAkB,CAAC;AACzB,aAAW,SAAS,CAAC,WAAW,GAAG,SAAS,GAAG;AAC7C,UAAM,UAAU,OAAO,UAAU,WAAW,MAAM,KAAK,IAAI;AAC3D,QAAI,QAAQ,SAAS,KAAK,CAAC,MAAM,SAAS,OAAO,EAAG,OAAM,KAAK,OAAO;AAAA,EACxE;AACA,SAAO;AACT;","names":[]}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/plans/decision.ts","../src/plans/index.ts"],"sourcesContent":["/**\n * The product half of deciding a durable plan: validate what the user clicked,\n * project the sandbox SDK's plan snapshot onto the chat projection, and\n * classify a 409 as a decision that already happened. Pure; no I/O.\n */\nimport type { ChatPlan, ChatPlanStatus } from './index'\n\n/** The SDK's plan snapshot, as the fields the projection reads. */\nexport interface DurablePlanLike {\n id: string\n revision: number\n title?: string\n body: string\n submittedAt: string\n status: ChatPlan['status']\n decidedAt?: string\n feedback?: string\n supersededAt?: string\n supersededByPlanId?: string\n withdrawnAt?: string\n reason?: string\n}\n\nexport type PlanDecisionOutcome = 'approved' | 'rejected'\n\nexport type PlanDecisionBody =\n | {\n ok: true\n workspaceId: string\n threadId: string\n planId: string\n revision: number\n outcome: PlanDecisionOutcome\n feedback?: string\n }\n | { ok: false; error: string }\n\n/** Validate a plan-decision request body. Rejection requires feedback: without\n * it the agent has nothing to revise against. */\nexport function parsePlanDecisionBody(body: Record<string, unknown>): PlanDecisionBody {\n const workspaceId = typeof body.workspaceId === 'string' ? body.workspaceId.trim() : ''\n const threadId = typeof body.threadId === 'string' ? body.threadId.trim() : ''\n const planId = typeof body.planId === 'string' ? body.planId.trim() : ''\n const revision = body.revision\n const outcome = body.outcome\n if (!workspaceId) return { ok: false, error: 'Missing workspaceId' }\n if (!threadId) return { ok: false, error: 'Missing threadId' }\n if (!planId) return { ok: false, error: 'Missing planId' }\n if (!Number.isInteger(revision) || Number(revision) < 1) {\n return { ok: false, error: 'Invalid revision: expected a positive integer' }\n }\n if (outcome !== 'approved' && outcome !== 'rejected') {\n return { ok: false, error: 'Invalid outcome: expected approved or rejected' }\n }\n if (outcome === 'rejected') {\n const feedback = typeof body.feedback === 'string' ? body.feedback.trim() : ''\n if (!feedback) return { ok: false, error: 'Plan rejection feedback is required' }\n return { ok: true, workspaceId, threadId, planId, revision: Number(revision), outcome, feedback }\n }\n return { ok: true, workspaceId, threadId, planId, revision: Number(revision), outcome }\n}\n\n/** Project the SDK's plan onto the chat projection. A status whose required\n * fields are missing is a broken projection, not a plan to render. */\nexport function toChatPlan(plan: DurablePlanLike): ChatPlan {\n const common = {\n planId: plan.id,\n revision: plan.revision,\n ...(plan.title ? { title: plan.title } : {}),\n body: plan.body,\n submittedAt: plan.submittedAt,\n }\n if (plan.status === 'preparing') return { ...common, status: 'preparing' }\n if (plan.status === 'pending') return { ...common, status: 'pending' }\n if (plan.status === 'approved' && plan.decidedAt) {\n return { ...common, status: 'approved', decidedAt: plan.decidedAt }\n }\n if (plan.status === 'rejected' && plan.decidedAt && plan.feedback) {\n return { ...common, status: 'rejected', decidedAt: plan.decidedAt, feedback: plan.feedback }\n }\n if (plan.status === 'superseded' && plan.supersededAt && plan.supersededByPlanId) {\n return {\n ...common,\n status: 'superseded',\n supersededAt: plan.supersededAt,\n supersededByPlanId: plan.supersededByPlanId,\n }\n }\n if (plan.status === 'withdrawn' && plan.withdrawnAt && plan.reason) {\n return { ...common, status: 'withdrawn', withdrawnAt: plan.withdrawnAt, withdrawnReason: plan.reason }\n }\n throw new Error(`Sandbox returned an incomplete ${plan.status} plan projection`)\n}\n\n/** A 409 from the sandbox is a decision that already happened; classify which\n * one so the caller can reconcile instead of reporting a failure. */\nexport function durablePlanConflictCode(error: {\n status?: number\n code?: string\n message: string\n}): 'plan_already_decided' | 'plan_superseded' | 'plan_withdrawn' | null {\n if (error.status !== 409) return null\n if (error.code === 'PLAN_ALREADY_DECIDED' || /already (approved|rejected|decided)/i.test(error.message)) {\n return 'plan_already_decided'\n }\n if (error.code === 'PLAN_SUPERSEDED' || /superseded/i.test(error.message)) return 'plan_superseded'\n if (error.code === 'PLAN_WITHDRAWN' || /withdrawn/i.test(error.message)) return 'plan_withdrawn'\n return null\n}\n\nconst TERMINAL_PLAN_STATUSES: readonly ChatPlanStatus[] = ['approved', 'rejected', 'superseded', 'withdrawn']\n\nexport function isTerminalPlanStatus(status: ChatPlanStatus): boolean {\n return TERMINAL_PLAN_STATUSES.includes(status)\n}\n","/**\n * Durable-plan application-shell contract.\n *\n * The sandbox SDK owns the authoritative plan lifecycle and decision APIs.\n * This module only projects that substrate state into chat events and\n * persisted message parts that products can render and restore.\n */\n\nexport const PLAN_SUBMITTED_EVENT = 'plan.submitted' as const\n\n/** Sandbox plan lifecycle. `preparing` is the transient submission state and\n * is retained in the projection even though the chat card normally starts at\n * `pending`. */\nexport type ChatPlanStatus = 'preparing' | 'pending' | 'approved' | 'rejected' | 'superseded' | 'withdrawn'\n\ntype ChatPlanBase = {\n /** The sandbox SDK calls this field `id`; the transcript projection names\n * it explicitly so it cannot collide with a message-part id. */\n planId: string\n revision: number\n title?: string\n body: string\n submittedAt: string\n /** Provider/Sandbox metadata is deliberately opaque to this package. */\n metadata?: Record<string, unknown>\n decidedBy?: string\n}\n\n/** Browser/persisted projection of the sandbox SDK's durable-plan union. */\nexport type ChatPlan = ChatPlanBase & (\n | { status: 'preparing' }\n | { status: 'pending' }\n | { status: 'approved'; decidedAt: string }\n | { status: 'rejected'; decidedAt: string; feedback: string }\n | { status: 'superseded'; supersededAt: string; supersededByPlanId: string }\n | { status: 'withdrawn'; withdrawnAt: string; withdrawnReason: string }\n)\n\n/** Canonical transcript part for one durable plan. */\nexport type ChatPlanPersistedPart = ChatPlan & { type: 'plan' }\n\n/** Resolve the result of parsing a plan submission into success with value or failure with error */\nexport type ParsePlanSubmittedResult =\n | { succeeded: true; value: ChatPlan }\n | { succeeded: false; error: string }\n\nconst PLAN_STATUSES: ReadonlySet<string> = new Set([\n 'preparing',\n 'pending',\n 'approved',\n 'rejected',\n 'superseded',\n 'withdrawn',\n])\n\nfunction asRecord(value: unknown): Record<string, unknown> | null {\n return value && typeof value === 'object' && !Array.isArray(value)\n ? value as Record<string, unknown>\n : null\n}\n\nfunction requiredString(record: Record<string, unknown>, key: string): string | null {\n const value = record[key]\n return typeof value === 'string' && value ? value : null\n}\n\nfunction parsePlan(record: Record<string, unknown>, defaultStatus?: ChatPlanStatus): ChatPlan | null {\n const planId = requiredString(record, 'planId') ?? requiredString(record, 'id')\n const revision = record.revision\n const body = requiredString(record, 'body')\n const submittedAt = requiredString(record, 'submittedAt')\n const status = typeof record.status === 'string' ? record.status : defaultStatus\n if (\n !planId ||\n typeof revision !== 'number' ||\n !Number.isInteger(revision) ||\n revision < 1 ||\n !body ||\n !submittedAt ||\n !status ||\n !PLAN_STATUSES.has(status)\n ) {\n return null\n }\n\n const common = {\n planId,\n revision,\n ...(typeof record.title === 'string' && record.title ? { title: record.title } : {}),\n body,\n submittedAt,\n ...(record.metadata && typeof record.metadata === 'object' && !Array.isArray(record.metadata)\n ? { metadata: record.metadata as Record<string, unknown> }\n : {}),\n ...(typeof record.decidedBy === 'string' && record.decidedBy ? { decidedBy: record.decidedBy } : {}),\n }\n\n if (status === 'preparing') return { ...common, status: 'preparing' }\n if (status === 'pending') return { ...common, status: 'pending' }\n if (status === 'approved') {\n const decidedAt = requiredString(record, 'decidedAt')\n return decidedAt ? { ...common, status, decidedAt } : null\n }\n if (status === 'rejected') {\n const decidedAt = requiredString(record, 'decidedAt')\n const feedback = requiredString(record, 'feedback')\n return decidedAt && feedback ? { ...common, status, decidedAt, feedback } : null\n }\n if (status === 'superseded') {\n const supersededAt = requiredString(record, 'supersededAt')\n const supersededByPlanId = requiredString(record, 'supersededByPlanId')\n return supersededAt && supersededByPlanId\n ? { ...common, status, supersededAt, supersededByPlanId }\n : null\n }\n\n const withdrawnAt = requiredString(record, 'withdrawnAt')\n const withdrawnReason = requiredString(record, 'withdrawnReason') ?? requiredString(record, 'reason')\n return withdrawnAt && withdrawnReason\n ? { ...common, status: 'withdrawn', withdrawnAt, withdrawnReason }\n : null\n}\n\n/** Generate a unique key string for a given plan identifier */\nexport function planPartKey(planId: string): string {\n return `plan:${planId}`\n}\n\n/** Generate a unique key string for a plan based on its ID and revision number */\nexport function planRevisionKey(planId: string, revision: number): string {\n return `plan:${planId}:revision:${revision}`\n}\n\n/**\n * The follow-up turn the Sandbox platform enqueues when one plan revision is\n * decided. It is revision-qualified because deciding revision 2 must not reuse\n * revision 1's execution and assistant row. The platform mints the same value.\n */\nexport function planFollowUpTurnId(planId: string, revision: number, outcome: 'approved' | 'rejected'): string {\n return `${planRevisionKey(planId, revision)}:${outcome}`\n}\n\n/** Plan status is monotonic: only a pending plan can settle. */\nexport function canTransitionPlanStatus(from: ChatPlanStatus, to: ChatPlanStatus): boolean {\n if (from === to) return true\n if (from === 'preparing') return to === 'pending' || to === 'superseded' || to === 'withdrawn'\n if (from === 'pending') return to === 'approved' || to === 'rejected' || to === 'superseded' || to === 'withdrawn'\n return false\n}\n\n/** Resolve a ChatPlan into its persisted part representation for storage or transmission */\nexport function planToPersistedPart(plan: ChatPlan): ChatPlanPersistedPart {\n return { type: 'plan', ...plan }\n}\n\n/** Resolve a persisted part object into a ChatPlan or return null if the type is not 'plan */\nexport function persistedPartToPlan(part: Record<string, unknown>): ChatPlan | null {\n if (String(part.type ?? '') !== 'plan') return null\n return parsePlan(part)\n}\n\n/** Parses both direct sandbox events (`data.plan`) and session envelopes\n * (`properties.plan`). Session identity is carried by the surrounding stream\n * and is deliberately not required in the payload. */\nexport function parsePlanSubmittedEvent(event: unknown): ParsePlanSubmittedResult {\n const root = asRecord(event)\n if (!root || root.type !== PLAN_SUBMITTED_EVENT) {\n return { succeeded: false, error: 'event is not plan.submitted' }\n }\n const plan = asRecord(asRecord(root.properties)?.plan) ?? asRecord(asRecord(root.data)?.plan)\n if (!plan) {\n return { succeeded: false, error: 'plan.submitted event carried no plan' }\n }\n const parsed = parsePlan(plan, 'pending')\n return parsed\n ? { succeeded: true, value: parsed }\n : { succeeded: false, error: 'plan.submitted event carried a malformed plan' }\n}\nexport * from './decision'\n"],"mappings":";AAuCO,SAAS,sBAAsB,MAAiD;AACrF,QAAM,cAAc,OAAO,KAAK,gBAAgB,WAAW,KAAK,YAAY,KAAK,IAAI;AACrF,QAAM,WAAW,OAAO,KAAK,aAAa,WAAW,KAAK,SAAS,KAAK,IAAI;AAC5E,QAAM,SAAS,OAAO,KAAK,WAAW,WAAW,KAAK,OAAO,KAAK,IAAI;AACtE,QAAM,WAAW,KAAK;AACtB,QAAM,UAAU,KAAK;AACrB,MAAI,CAAC,YAAa,QAAO,EAAE,IAAI,OAAO,OAAO,sBAAsB;AACnE,MAAI,CAAC,SAAU,QAAO,EAAE,IAAI,OAAO,OAAO,mBAAmB;AAC7D,MAAI,CAAC,OAAQ,QAAO,EAAE,IAAI,OAAO,OAAO,iBAAiB;AACzD,MAAI,CAAC,OAAO,UAAU,QAAQ,KAAK,OAAO,QAAQ,IAAI,GAAG;AACvD,WAAO,EAAE,IAAI,OAAO,OAAO,gDAAgD;AAAA,EAC7E;AACA,MAAI,YAAY,cAAc,YAAY,YAAY;AACpD,WAAO,EAAE,IAAI,OAAO,OAAO,iDAAiD;AAAA,EAC9E;AACA,MAAI,YAAY,YAAY;AAC1B,UAAM,WAAW,OAAO,KAAK,aAAa,WAAW,KAAK,SAAS,KAAK,IAAI;AAC5E,QAAI,CAAC,SAAU,QAAO,EAAE,IAAI,OAAO,OAAO,sCAAsC;AAChF,WAAO,EAAE,IAAI,MAAM,aAAa,UAAU,QAAQ,UAAU,OAAO,QAAQ,GAAG,SAAS,SAAS;AAAA,EAClG;AACA,SAAO,EAAE,IAAI,MAAM,aAAa,UAAU,QAAQ,UAAU,OAAO,QAAQ,GAAG,QAAQ;AACxF;AAIO,SAAS,WAAW,MAAiC;AAC1D,QAAM,SAAS;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