@tangle-network/agent-app 0.60.249 → 0.60.251

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 (225) hide show
  1. package/dist/DesignCanvas-L6J72JQ2.js +15 -0
  2. package/dist/DesignCanvasEditor-QFQD63MR.js +18 -0
  3. package/dist/agent-enrollment/drizzle.js +3 -3
  4. package/dist/agent-enrollment/index.js +3 -3
  5. package/dist/app-auth/drizzle.d.ts +561 -0
  6. package/dist/app-auth/drizzle.js +72 -0
  7. package/dist/app-auth/drizzle.js.map +1 -0
  8. package/dist/app-auth/index.js +5 -3
  9. package/dist/app-auth/index.js.map +1 -1
  10. package/dist/app-oauth/drizzle.d.ts +2080 -0
  11. package/dist/app-oauth/drizzle.js +161 -0
  12. package/dist/app-oauth/drizzle.js.map +1 -0
  13. package/dist/app-oauth/index.d.ts +4 -0
  14. package/dist/app-oauth/index.js +8 -222
  15. package/dist/app-oauth/index.js.map +1 -1
  16. package/dist/app-oauth/issuer.d.ts +133 -0
  17. package/dist/app-oauth/issuer.js +247 -0
  18. package/dist/app-oauth/issuer.js.map +1 -0
  19. package/dist/assistant/index.js +13 -13
  20. package/dist/chat-react/index.js +4 -4
  21. package/dist/chat-routes/dispatch-first.d.ts +43 -0
  22. package/dist/chat-routes/index.js +37 -67
  23. package/dist/chat-routes/index.js.map +1 -1
  24. package/dist/chat-routes/promote-file-part.d.ts +2 -3
  25. package/dist/chat-routes/turn-execution.d.ts +3 -1
  26. package/dist/chat-routes/turn-route-contracts.d.ts +31 -0
  27. package/dist/chat-store/index.js +4 -4
  28. package/dist/{chunk-MY3EJJ6Y.js → chunk-4FEH6266.js} +2 -2
  29. package/dist/{chunk-5Y7Z5G3Y.js → chunk-4GCPADYG.js} +20 -336
  30. package/dist/chunk-4GCPADYG.js.map +1 -0
  31. package/dist/{chunk-X556WVBG.js → chunk-4ZSLX3LY.js} +2 -2
  32. package/dist/chunk-57XPEL7X.js +26 -0
  33. package/dist/chunk-57XPEL7X.js.map +1 -0
  34. package/dist/chunk-6Z7TZVKZ.js +26 -0
  35. package/dist/chunk-6Z7TZVKZ.js.map +1 -0
  36. package/dist/{chunk-7KKOFMLD.js → chunk-AWIQQEFP.js} +1 -1
  37. package/dist/chunk-AWIQQEFP.js.map +1 -0
  38. package/dist/{chunk-VBKP2NLI.js → chunk-BTKI4XMM.js} +2 -2
  39. package/dist/{chunk-63QAQP7I.js → chunk-CNBVWPQC.js} +7 -7
  40. package/dist/{chunk-FENBDSIW.js → chunk-CQGEGPY7.js} +75 -3
  41. package/dist/chunk-CQGEGPY7.js.map +1 -0
  42. package/dist/chunk-CTREXL3O.js +335 -0
  43. package/dist/chunk-CTREXL3O.js.map +1 -0
  44. package/dist/chunk-DLWO3J7D.js +238 -0
  45. package/dist/chunk-DLWO3J7D.js.map +1 -0
  46. package/dist/{chunk-LWSJK546.js → chunk-DSMGS4IV.js} +5 -5
  47. package/dist/{chunk-LWSJK546.js.map → chunk-DSMGS4IV.js.map} +1 -1
  48. package/dist/{chunk-BDCC6UVW.js → chunk-EFPIHR6F.js} +161 -40
  49. package/dist/chunk-EFPIHR6F.js.map +1 -0
  50. package/dist/chunk-FRAICFTZ.js +191 -0
  51. package/dist/chunk-FRAICFTZ.js.map +1 -0
  52. package/dist/chunk-GS7VWV26.js +61 -0
  53. package/dist/chunk-GS7VWV26.js.map +1 -0
  54. package/dist/{chunk-NMSAZFRL.js → chunk-H5GQMLHA.js} +2 -2
  55. package/dist/{chunk-OQE6WMDP.js → chunk-HN6MZ2XL.js} +5 -5
  56. package/dist/chunk-HY57QRRW.js +11 -0
  57. package/dist/chunk-HY57QRRW.js.map +1 -0
  58. package/dist/{chunk-TCGZFSN5.js → chunk-KH4QSBNI.js} +2 -2
  59. package/dist/{chunk-JH3CKHF4.js → chunk-KJODHPWM.js} +8 -8
  60. package/dist/chunk-LSBI5MWS.js +66 -0
  61. package/dist/chunk-LSBI5MWS.js.map +1 -0
  62. package/dist/chunk-MDRH3SDA.js +106 -0
  63. package/dist/chunk-MDRH3SDA.js.map +1 -0
  64. package/dist/{chunk-VBWYH7UZ.js → chunk-NHYRIM4I.js} +3 -3
  65. package/dist/{chunk-BYP54FMI.js → chunk-O2RCDK5D.js} +30 -15
  66. package/dist/{chunk-BYP54FMI.js.map → chunk-O2RCDK5D.js.map} +1 -1
  67. package/dist/{chunk-EWOJATDS.js → chunk-PDD5A43Y.js} +3 -3
  68. package/dist/{chunk-23JUSUUB.js → chunk-RZLCBWGG.js} +2 -2
  69. package/dist/chunk-SFZELD6V.js +52 -0
  70. package/dist/chunk-SFZELD6V.js.map +1 -0
  71. package/dist/{chunk-Y4W6GK5X.js → chunk-UGFCLD32.js} +2 -2
  72. package/dist/{chunk-ZGUXI5SI.js → chunk-VUBJZEZB.js} +2 -2
  73. package/dist/{chunk-LQYIBL3G.js → chunk-WL7PZK7Q.js} +71 -1
  74. package/dist/chunk-WL7PZK7Q.js.map +1 -0
  75. package/dist/{chunk-7HZCFG2A.js → chunk-WP2GYFZ4.js} +38 -1
  76. package/dist/chunk-WP2GYFZ4.js.map +1 -0
  77. package/dist/{chunk-JK7R7BZQ.js → chunk-ZWJ3SZ2G.js} +2 -2
  78. package/dist/crypto/digest.d.ts +2 -0
  79. package/dist/crypto/index.d.ts +1 -0
  80. package/dist/crypto/index.js +6 -2
  81. package/dist/design-canvas/index.js +5 -3
  82. package/dist/design-canvas/index.js.map +1 -1
  83. package/dist/design-canvas-react/engine.js +7 -5
  84. package/dist/design-canvas-react/index.js +14 -12
  85. package/dist/design-canvas-react/index.js.map +1 -1
  86. package/dist/design-canvas-react/lazy.js +1 -1
  87. package/dist/eval/index.d.ts +4 -0
  88. package/dist/eval/index.js +125 -0
  89. package/dist/eval/index.js.map +1 -1
  90. package/dist/eval/persona-driver.d.ts +37 -0
  91. package/dist/eval/research-plan.d.ts +25 -0
  92. package/dist/eval/research-plan.js +55 -0
  93. package/dist/eval/research-plan.js.map +1 -0
  94. package/dist/eval/scorecard.d.ts +38 -0
  95. package/dist/forms/blank.d.ts +2 -2
  96. package/dist/forms/index.js +4 -5
  97. package/dist/forms/index.js.map +1 -1
  98. package/dist/hosted-agent/application.js +2 -2
  99. package/dist/interactions/index.js +3 -3
  100. package/dist/knowledge/prelaunch-audit.d.ts +17 -0
  101. package/dist/knowledge/prelaunch-audit.js +67 -0
  102. package/dist/knowledge/prelaunch-audit.js.map +1 -0
  103. package/dist/media/drizzle.d.ts +207 -0
  104. package/dist/media/drizzle.js +26 -0
  105. package/dist/media/drizzle.js.map +1 -0
  106. package/dist/media/generate-request.d.ts +53 -0
  107. package/dist/media/generation-record.d.ts +68 -0
  108. package/dist/media/index.d.ts +13 -0
  109. package/dist/media/index.js +653 -0
  110. package/dist/media/index.js.map +1 -0
  111. package/dist/media/model-catalog.d.ts +109 -0
  112. package/dist/media/router-client.d.ts +40 -0
  113. package/dist/media/router-generation.d.ts +44 -0
  114. package/dist/media/speech-script.d.ts +20 -0
  115. package/dist/openui/index.js +1 -1
  116. package/dist/operator/index.js +4 -5
  117. package/dist/operator/index.js.map +1 -1
  118. package/dist/plans/decision.d.ts +48 -0
  119. package/dist/plans/drizzle.d.ts +25 -0
  120. package/dist/plans/drizzle.js +97 -0
  121. package/dist/plans/drizzle.js.map +1 -0
  122. package/dist/plans/index.d.ts +1 -1
  123. package/dist/plans/index.js +11 -3
  124. package/dist/platform/billing-config.d.ts +22 -0
  125. package/dist/platform/billing-config.js +36 -0
  126. package/dist/platform/billing-config.js.map +1 -0
  127. package/dist/platform/index.js +13 -11
  128. package/dist/platform/index.js.map +1 -1
  129. package/dist/preset-cloudflare/index.js +2 -1
  130. package/dist/preset-cloudflare/index.js.map +1 -1
  131. package/dist/profile/index.js +4 -5
  132. package/dist/profile/index.js.map +1 -1
  133. package/dist/public-consultation/index.js +13 -11
  134. package/dist/public-consultation/index.js.map +1 -1
  135. package/dist/runtime/telemetry-cap.d.ts +24 -0
  136. package/dist/runtime/telemetry-cap.js +36 -0
  137. package/dist/runtime/telemetry-cap.js.map +1 -0
  138. package/dist/sandbox/index.js +12 -9
  139. package/dist/sequences/index.js +4 -2
  140. package/dist/sequences/index.js.map +1 -1
  141. package/dist/skills-placement/box.d.ts +50 -0
  142. package/dist/skills-placement/box.js +204 -0
  143. package/dist/skills-placement/box.js.map +1 -0
  144. package/dist/skills-placement/index.js +8 -96
  145. package/dist/skills-placement/index.js.map +1 -1
  146. package/dist/spend/budget.d.ts +13 -0
  147. package/dist/spend/drizzle.d.ts +55 -0
  148. package/dist/spend/drizzle.js +131 -0
  149. package/dist/spend/drizzle.js.map +1 -0
  150. package/dist/spend/index.d.ts +2 -1
  151. package/dist/spend/index.js +77 -58
  152. package/dist/spend/index.js.map +1 -1
  153. package/dist/spend/platform-settlements.d.ts +46 -0
  154. package/dist/stream/index.js +19 -19
  155. package/dist/studio/generated-media/index.d.ts +6 -0
  156. package/dist/studio/generated-media/index.js +590 -0
  157. package/dist/studio/generated-media/index.js.map +1 -0
  158. package/dist/studio/generated-media/output.d.ts +27 -0
  159. package/dist/studio/generated-media/store.d.ts +175 -0
  160. package/dist/studio-react/download-generations.d.ts +7 -0
  161. package/dist/studio-react/index.d.ts +1 -0
  162. package/dist/studio-react/index.js +85 -0
  163. package/dist/studio-react/index.js.map +1 -1
  164. package/dist/studio-react/use-studio-route.d.ts +44 -0
  165. package/dist/teams/invitations-api.d.ts +4 -0
  166. package/dist/teams/invitations-api.js +44 -32
  167. package/dist/teams/invitations-api.js.map +1 -1
  168. package/dist/theme/dom.d.ts +22 -0
  169. package/dist/theme/dom.js +18 -0
  170. package/dist/theme/dom.js.map +1 -0
  171. package/dist/vault/collaboration.d.ts +83 -0
  172. package/dist/vault/collaboration.js +215 -0
  173. package/dist/vault/collaboration.js.map +1 -0
  174. package/dist/vault/server.js +6 -53
  175. package/dist/vault/server.js.map +1 -1
  176. package/dist/vault/store/coordinator.d.ts +64 -0
  177. package/dist/vault/store/index.d.ts +12 -0
  178. package/dist/vault/store/index.js +1202 -0
  179. package/dist/vault/store/index.js.map +1 -0
  180. package/dist/vault/store/paths.d.ts +65 -0
  181. package/dist/vault/store/revisions.d.ts +211 -0
  182. package/dist/vault/store/sandbox-sync.d.ts +74 -0
  183. package/dist/vault/store/store.d.ts +161 -0
  184. package/dist/vault/store/tree.d.ts +11 -0
  185. package/dist/web/entry-server.d.ts +7 -0
  186. package/dist/web/entry-server.js +29 -0
  187. package/dist/web/entry-server.js.map +1 -0
  188. package/dist/web/fetch-guard.d.ts +6 -0
  189. package/dist/web/index.d.ts +3 -0
  190. package/dist/web/index.js +20 -4
  191. package/dist/web/mime.d.ts +16 -0
  192. package/dist/web/rate-limit.d.ts +25 -0
  193. package/dist/web/timeout.d.ts +9 -0
  194. package/dist/web-react/agent-profile-editor.js +3 -3
  195. package/dist/web-react/api-access-panel.d.ts +4 -2
  196. package/dist/web-react/document.d.ts +41 -0
  197. package/dist/web-react/document.js +103 -0
  198. package/dist/web-react/document.js.map +1 -0
  199. package/dist/web-react/index.js +31 -31
  200. package/dist/workspace-react/index.js +5 -5
  201. package/package.json +95 -4
  202. package/dist/DesignCanvas-OW3W2QXW.js +0 -13
  203. package/dist/DesignCanvasEditor-TCHZF25W.js +0 -16
  204. package/dist/chunk-5Y7Z5G3Y.js.map +0 -1
  205. package/dist/chunk-7HZCFG2A.js.map +0 -1
  206. package/dist/chunk-7KKOFMLD.js.map +0 -1
  207. package/dist/chunk-BDCC6UVW.js.map +0 -1
  208. package/dist/chunk-FENBDSIW.js.map +0 -1
  209. package/dist/chunk-LQYIBL3G.js.map +0 -1
  210. /package/dist/{DesignCanvas-OW3W2QXW.js.map → DesignCanvas-L6J72JQ2.js.map} +0 -0
  211. /package/dist/{DesignCanvasEditor-TCHZF25W.js.map → DesignCanvasEditor-QFQD63MR.js.map} +0 -0
  212. /package/dist/{chunk-MY3EJJ6Y.js.map → chunk-4FEH6266.js.map} +0 -0
  213. /package/dist/{chunk-X556WVBG.js.map → chunk-4ZSLX3LY.js.map} +0 -0
  214. /package/dist/{chunk-VBKP2NLI.js.map → chunk-BTKI4XMM.js.map} +0 -0
  215. /package/dist/{chunk-63QAQP7I.js.map → chunk-CNBVWPQC.js.map} +0 -0
  216. /package/dist/{chunk-NMSAZFRL.js.map → chunk-H5GQMLHA.js.map} +0 -0
  217. /package/dist/{chunk-OQE6WMDP.js.map → chunk-HN6MZ2XL.js.map} +0 -0
  218. /package/dist/{chunk-TCGZFSN5.js.map → chunk-KH4QSBNI.js.map} +0 -0
  219. /package/dist/{chunk-JH3CKHF4.js.map → chunk-KJODHPWM.js.map} +0 -0
  220. /package/dist/{chunk-VBWYH7UZ.js.map → chunk-NHYRIM4I.js.map} +0 -0
  221. /package/dist/{chunk-EWOJATDS.js.map → chunk-PDD5A43Y.js.map} +0 -0
  222. /package/dist/{chunk-23JUSUUB.js.map → chunk-RZLCBWGG.js.map} +0 -0
  223. /package/dist/{chunk-Y4W6GK5X.js.map → chunk-UGFCLD32.js.map} +0 -0
  224. /package/dist/{chunk-ZGUXI5SI.js.map → chunk-VUBJZEZB.js.map} +0 -0
  225. /package/dist/{chunk-JK7R7BZQ.js.map → chunk-ZWJ3SZ2G.js.map} +0 -0
@@ -21,6 +21,8 @@
21
21
  import { type SandboxExecChannel } from '../sandbox/binary-read';
22
22
  import { type ChatAttachmentKind, type ChatAttachmentPart } from '../chat-store/parts';
23
23
  import { type AtomicAttachmentWriter, type WriteAttachmentFn } from './attachment-store';
24
+ import { sniffMimeFromName } from '../web/mime';
25
+ export { sniffMimeFromName };
24
26
  /** Default ceiling on a promoted file's raw (pre-encoding) byte size. */
25
27
  export declare const PROMOTE_MAX_FILE_BYTES: number;
26
28
  /** Define the structure for a raw file part with optional metadata and media type information */
@@ -57,8 +59,6 @@ export interface AttachmentPathArgs {
57
59
  /** `image`/`file` split of the media type. */
58
60
  kind: ChatAttachmentKind;
59
61
  }
60
- /** Default MIME hook: extension → mime, or `text/plain` for the unknown. */
61
- export declare function sniffMimeFromName(filename: string): string;
62
62
  type PromoteFilePartLogger = Pick<Console, 'error'>;
63
63
  interface PromoteFilePartCommonOptions {
64
64
  raw: RawAgentFilePart;
@@ -98,4 +98,3 @@ export declare function promoteAgentFilePart(options: PromoteAgentFilePartOption
98
98
  export declare function promoteAgentFilePart(options: AtomicPromoteAgentFilePartOptions): Promise<PromoteFilePartResult>;
99
99
  /** Promote a part when the caller selects the writer contract at runtime. */
100
100
  export declare function promoteAgentFilePart(options: PromoteAgentFilePartOptions | AtomicPromoteAgentFilePartOptions): Promise<PromoteFilePartResult>;
101
- export {};
@@ -3,10 +3,12 @@ import { type AssistantDraftStore, type DraftPersistenceTuning } from './draft-p
3
3
  import { type AdmittedTurn, type TurnProgress } from './turn-admission';
4
4
  import type { ChatTurnRequestContext, ChatTurnTraceOptions, CreateChatTurnRoutesOptions } from './turn-route-contracts';
5
5
  import type { TurnRoutePhase } from './turn-progress';
6
- /** Work `afterAuthorize` started: `handOff` gives it to `produce`; `release` frees it if nothing took it. */
6
+ /** Work started before `produce` took the turn: `handOff` gives it to `produce`; `release` frees it if nothing took it. */
7
7
  export interface AfterAuthorizeWork {
8
8
  handOff(): void;
9
9
  release(): Promise<void>;
10
+ /** Free this too if the turn ends before `handOff`. */
11
+ add(release: () => void): void;
10
12
  }
11
13
  interface TurnExecutionOptions<TContext> {
12
14
  options: CreateChatTurnRoutesOptions<TContext>;
@@ -271,6 +271,15 @@ export interface ChatTurnProduceArgs<TContext> {
271
271
  * `createChatTurnRoutes` invocation supplies it before `produce` runs.
272
272
  */
273
273
  handoffCompletion?: () => Promise<void>;
274
+ /** Set only under `dispatchFirst`, where `produce` starts before the lock. Resolves to the final args (with
275
+ * `userMessageId`, after `contextGate` and `beforeTurn`) once the admission chain commits, or rejects with
276
+ * `TurnAdmissionRefusedError` when the turn is refused. Start the model call at once; write nothing durable,
277
+ * and read nothing `beforeTurn` adds to `context`, until it resolves. */
278
+ admitted?: Promise<ChatTurnProduceArgs<TContext>>;
279
+ /** Set only under `dispatchFirst`: aborts when the turn is refused after `produce` started, or when the route stops
280
+ * reading the producer (a disconnect under `cancelOnDisconnect`). Pass it to the model call. Under `dispatchFirst`,
281
+ * `handoffCompletion` resolves only after `admitted` does. */
282
+ admissionSignal?: AbortSignal;
274
283
  }
275
284
  /** One event as it crosses the route: the producer's own vocabulary, or an
276
285
  * injected keepalive. Same shape the engine forwards verbatim.
@@ -524,6 +533,28 @@ export interface CreateChatTurnRoutesOptions<TContext = void> {
524
533
  * wrapped in `createSandboxChatProducer`. Router/openai-compat lane: the
525
534
  * product's own producer. May be async (box resolution). */
526
535
  produce(args: ChatTurnProduceArgs<TContext>): ChatTurnRouteProducer | Promise<ChatTurnRouteProducer>;
536
+ /**
537
+ * Start `produce`, and so the model call, right after the history read, while the lock, the history recheck, the
538
+ * user-row insert, `contextGate` and `beforeTurn` run (see `./dispatch-first`). Nothing it emits reaches the member,
539
+ * the turn buffer or the transcript before that chain commits; a refusal aborts it through `args.admissionSignal`
540
+ * and drops its output. `produce` receives `args.admitted` for the final args.
541
+ *
542
+ * Opt in only by naming where billing is enforced before any provider is paid: `'authorize'` (the product's
543
+ * balance and spend checks run there) or `'model-service'` (the Tangle Router holds the spend and refuses an
544
+ * unfunded key before it calls a provider, fail-closed). Entitlement gates the model service cannot know (a seat,
545
+ * a plan feature) belong in `contextGate`, which then runs while the model starts and holds its output until it
546
+ * passes. `beforeTurn` may still mutate `context` but must not return a patch, since the prompt has already been
547
+ * sent; a patch throws. Omit → `produce` runs after admission.
548
+ *
549
+ * `when` picks the turns that dispatch first (default all). Return false for a producer whose dispatch is keyed by
550
+ * the turn's `executionId` (a box session): two sends on one thread resolve the same id, and the refused duplicate
551
+ * would reach the winner's execution before the lock refused it. A Router call per request is safe; the refused
552
+ * duplicate costs only the call its `admissionSignal` cancels.
553
+ */
554
+ dispatchFirst?: {
555
+ billing: 'authorize' | 'model-service';
556
+ when?: (args: ChatTurnProduceArgs<TContext>) => boolean;
557
+ };
527
558
  /** Single-flight lock acquired before any side effect and released once when
528
559
  * the turn settles (including short-circuit/throw). `/turn-stream`'s
529
560
  * `createDurableTurnLock` is the shared DO-backed implementation. Omit →
@@ -15,15 +15,15 @@ import {
15
15
  mentionInputToPart,
16
16
  mentionPartsFromMessageParts,
17
17
  toChatMessageParts
18
- } from "../chunk-23JUSUUB.js";
18
+ } from "../chunk-RZLCBWGG.js";
19
19
  import "../chunk-ZVEEWGDK.js";
20
20
  import "../chunk-5TSRFF5W.js";
21
- import "../chunk-TXD5HXLE.js";
22
21
  import {
23
22
  attachmentPartKey
24
- } from "../chunk-ZGUXI5SI.js";
23
+ } from "../chunk-VUBJZEZB.js";
25
24
  import "../chunk-6VQCFJWP.js";
26
- import "../chunk-LQYIBL3G.js";
25
+ import "../chunk-TXD5HXLE.js";
26
+ import "../chunk-WL7PZK7Q.js";
27
27
 
28
28
  // src/chat-store/core.ts
29
29
  var BULK_DELETE_MAX_THREADS = 200;
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  parseJsonObjectBody
3
- } from "./chunk-7HZCFG2A.js";
3
+ } from "./chunk-WP2GYFZ4.js";
4
4
 
5
5
  // src/hosted-agent/application.ts
6
6
  import {
@@ -121,4 +121,4 @@ export {
121
121
  publicApplicationSenderVerification,
122
122
  createApplicationLineHandler
123
123
  };
124
- //# sourceMappingURL=chunk-MY3EJJ6Y.js.map
124
+ //# sourceMappingURL=chunk-4FEH6266.js.map
@@ -9,15 +9,10 @@ import {
9
9
  sandboxTransientBackoffMs,
10
10
  serializeSandboxProvisioningError
11
11
  } from "./chunk-4LBCTFBP.js";
12
- import {
13
- DEFAULT_HARNESS,
14
- assertHarnessModelCompatible,
15
- isHarness
16
- } from "./chunk-FPNZMIAW.js";
17
12
  import {
18
13
  assertProfilePromptWithinBudget,
19
14
  fingerprintAgentProfile
20
- } from "./chunk-LWSJK546.js";
15
+ } from "./chunk-DSMGS4IV.js";
21
16
  import {
22
17
  buildAppToolMcpServer
23
18
  } from "./chunk-6A7MYOUI.js";
@@ -31,6 +26,20 @@ import {
31
26
  import {
32
27
  formatServerTiming
33
28
  } from "./chunk-ORQD4AUO.js";
29
+ import {
30
+ fail,
31
+ isRuntimeAuthRefreshDenied,
32
+ isRuntimeExecAuthError,
33
+ ok,
34
+ shellSingleQuote,
35
+ splitDeferredProfileFiles,
36
+ writeProfileFilesToBox
37
+ } from "./chunk-CTREXL3O.js";
38
+ import {
39
+ DEFAULT_HARNESS,
40
+ assertHarnessModelCompatible,
41
+ isHarness
42
+ } from "./chunk-FPNZMIAW.js";
34
43
 
35
44
  // src/sandbox/prompt-trace.ts
36
45
  var asRec = (value) => value && typeof value === "object" && !Array.isArray(value) ? value : void 0;
@@ -213,66 +222,6 @@ function workersReuseStore() {
213
222
  return createCacheReuseStore(() => storage.open(CACHE_NAME));
214
223
  }
215
224
 
216
- // src/sandbox/binary-read.ts
217
- function shellQuote(value) {
218
- return `'${value.replaceAll("'", `'"'"'`)}'`;
219
- }
220
- function base64ToBytes(base64) {
221
- const binary = atob(base64);
222
- const bytes = new Uint8Array(binary.length);
223
- for (let i = 0; i < binary.length; i += 1) bytes[i] = binary.charCodeAt(i);
224
- return bytes;
225
- }
226
- function execInSandbox(box, command, options) {
227
- return options?.sessionId ? box.exec(command, { sessionId: options.sessionId }) : box.exec(command);
228
- }
229
- async function statSandboxFileSize(box, absolutePath, options) {
230
- const quotedPath = shellQuote(absolutePath);
231
- let result;
232
- try {
233
- result = await execInSandbox(box, `wc -c < ${quotedPath}`, options);
234
- } catch (err) {
235
- return { succeeded: false, error: err instanceof Error ? err.message : String(err) };
236
- }
237
- if (result.exitCode !== 0) {
238
- return { succeeded: false, error: result.stderr || "unknown error" };
239
- }
240
- const size = Number.parseInt(result.stdout.trim(), 10);
241
- if (!Number.isFinite(size)) {
242
- return { succeeded: false, error: `could not parse file size from "${result.stdout.trim()}"` };
243
- }
244
- return { succeeded: true, value: size };
245
- }
246
- async function readSandboxBinaryBytes(box, absolutePath, expectedSize, options) {
247
- const quotedPath = shellQuote(absolutePath);
248
- let result;
249
- try {
250
- result = await execInSandbox(box, `base64 ${quotedPath}`, options);
251
- } catch (err) {
252
- return { succeeded: false, error: err instanceof Error ? err.message : String(err) };
253
- }
254
- if (result.exitCode !== 0) {
255
- return { succeeded: false, error: result.stderr || "unknown error" };
256
- }
257
- const cleaned = result.stdout.replace(/\s+/g, "");
258
- let bytes;
259
- try {
260
- bytes = base64ToBytes(cleaned);
261
- } catch (err) {
262
- return {
263
- succeeded: false,
264
- error: `could not decode file contents: ${err instanceof Error ? err.message : String(err)}`
265
- };
266
- }
267
- if (bytes.byteLength !== expectedSize) {
268
- return {
269
- succeeded: false,
270
- error: `read returned ${bytes.byteLength} bytes, expected ${expectedSize} \u2014 output truncated in transit`
271
- };
272
- }
273
- return { succeeded: true, value: { bytes, size: expectedSize } };
274
- }
275
-
276
225
  // src/sandbox/model.ts
277
226
  function backendModelFields(model) {
278
227
  return {
@@ -1864,26 +1813,6 @@ async function persistReuseState(shell, box) {
1864
1813
  }
1865
1814
  }
1866
1815
 
1867
- // src/sandbox/shell-path.ts
1868
- function shellSingleQuote(value) {
1869
- return `'${value.replace(/'/g, `'\\''`)}'`;
1870
- }
1871
- function shellPath(path) {
1872
- if (path === "~") return '"$HOME"';
1873
- if (path.startsWith("~/")) {
1874
- const rest = path.slice(2);
1875
- return rest ? `"$HOME"/${shellSingleQuote(rest)}` : '"$HOME"';
1876
- }
1877
- return shellSingleQuote(path);
1878
- }
1879
-
1880
- // src/sandbox/outcome.ts
1881
- var ok = (value) => ({ succeeded: true, value });
1882
- var fail = (error) => ({
1883
- succeeded: false,
1884
- error: error instanceof Error ? error : new Error(String(error))
1885
- });
1886
-
1887
1816
  // src/sandbox/app-tools.ts
1888
1817
  function buildAppToolMcpServers(options) {
1889
1818
  const entries = {};
@@ -1985,246 +1914,6 @@ async function runSandboxToolPathSetup(box, options) {
1985
1914
  return ensureSandboxToolBinDir(box, options);
1986
1915
  }
1987
1916
 
1988
- // src/sandbox/exec-failure.ts
1989
- var ProfileWriteExecTimeoutError = class extends Error {
1990
- constructor(timeoutMs) {
1991
- super(`exec exceeded ${timeoutMs}ms (proxy hang/wedge)`);
1992
- this.name = "ProfileWriteExecTimeoutError";
1993
- }
1994
- };
1995
- var TRANSIENT_EXEC_STATUS_CODES = /* @__PURE__ */ new Set([408, 409, 425, 429, 500, 502, 503, 504]);
1996
- var TRANSIENT_EXEC_CODE_RE = /^(ECONNRESET|ECONNREFUSED|ETIMEDOUT|EPIPE|ECONNABORTED)$/i;
1997
- var TRANSIENT_EXEC_MESSAGE_RE = /\b(408|409|425|429|500|502|503|504)\b|rate.?limit|too many requests|\bfetch failed\b|network error|connection reset|socket hang up|timed? out|service unavailable|bad gateway|gateway timeout|internal server error|\b(?:sidecar|runtime|exec(?:ution)?|terminal|sandbox|service|command(?:s)?|proxy)\b.{0,80}\bnot ready\b|\bnot ready\b.{0,80}\b(?:sidecar|runtime|exec(?:ution)?|terminal|sandbox|service|command(?:s)?|proxy)\b/i;
1998
- function errorStatus(err) {
1999
- const rawStatus = err.status ?? err.statusCode ?? (err.response && typeof err.response === "object" ? err.response.status : void 0);
2000
- if (typeof rawStatus === "number") return rawStatus;
2001
- if (typeof rawStatus === "string" && /^\d+$/.test(rawStatus)) return Number(rawStatus);
2002
- return void 0;
2003
- }
2004
- function retryAfterMs(err, seen = /* @__PURE__ */ new Set()) {
2005
- if (!err || typeof err !== "object") return void 0;
2006
- if (seen.has(err)) return void 0;
2007
- seen.add(err);
2008
- const e = err;
2009
- if (typeof e.retryAfterMs === "number") return e.retryAfterMs;
2010
- return retryAfterMs(e.cause, seen);
2011
- }
2012
- function isTransientExecError(err, seen = /* @__PURE__ */ new Set()) {
2013
- if (!err || typeof err !== "object") return false;
2014
- if (seen.has(err)) return false;
2015
- seen.add(err);
2016
- const e = err;
2017
- const status = errorStatus(e);
2018
- if (status !== void 0 && TRANSIENT_EXEC_STATUS_CODES.has(status)) return true;
2019
- if (typeof e.code === "string") {
2020
- if (TRANSIENT_EXEC_CODE_RE.test(e.code)) return true;
2021
- if (/rate.?limit|too.?many.?requests|429|server.?error|service.?unavailable/i.test(e.code)) return true;
2022
- }
2023
- if (typeof e.message === "string" && TRANSIENT_EXEC_MESSAGE_RE.test(e.message)) return true;
2024
- return isTransientExecError(e.cause, seen);
2025
- }
2026
- function isRuntimeExecAuthError(err, seen = /* @__PURE__ */ new Set()) {
2027
- if (!err || typeof err !== "object") return false;
2028
- if (seen.has(err)) return false;
2029
- seen.add(err);
2030
- const e = err;
2031
- if (errorStatus(e) === 401) return true;
2032
- if (typeof e.code === "string" && /^(AUTH_ERROR|AUTHENTICATION_ERROR|UNAUTHORIZED|UNAUTHENTICATED|ERR_UNAUTHORIZED|ERR_UNAUTHENTICATED|401)$/i.test(e.code)) {
2033
- return true;
2034
- }
2035
- if (typeof e.name === "string" && /^(AuthError|AuthenticationError|UnauthorizedError|UnauthenticatedError|SandboxAuthError)$/i.test(e.name)) {
2036
- return true;
2037
- }
2038
- return isRuntimeExecAuthError(e.cause, seen);
2039
- }
2040
- function isRuntimeAuthRefreshDenied(err) {
2041
- if (!err || typeof err !== "object") return false;
2042
- return isRuntimeExecAuthError(err) || errorStatus(err) === 403;
2043
- }
2044
- function transientExecError(err) {
2045
- if (err instanceof ProfileWriteExecTimeoutError) return { retryable: true };
2046
- if (isTransientExecError(err)) return { retryable: true, retryAfterMs: retryAfterMs(err) };
2047
- return { retryable: false };
2048
- }
2049
-
2050
- // src/sandbox/profile-files.ts
2051
- import { createHash } from "crypto";
2052
- function splitDeferredProfileFiles(profile) {
2053
- const files = profile.resources?.files ?? [];
2054
- const deferredFiles = [];
2055
- const keptFiles = [];
2056
- for (const mount of files) {
2057
- if (mount.resource.kind === "inline") deferredFiles.push(mount);
2058
- else keptFiles.push(mount);
2059
- }
2060
- if (deferredFiles.length === 0) return { leanProfile: profile, deferredFiles };
2061
- const leanProfile = {
2062
- ...profile,
2063
- resources: { ...profile.resources ?? {}, files: keptFiles }
2064
- };
2065
- return { leanProfile, deferredFiles };
2066
- }
2067
- var PROFILE_WRITE_B64_CHUNK_CHARS = 3e3;
2068
- var PROFILE_WRITE_MAX_RETRIES = 4;
2069
- var PROFILE_WRITE_RETRY_BASE_MS = 250;
2070
- var PROFILE_WRITE_RETRY_MAX_MS = 2e3;
2071
- var PROFILE_WRITE_EXEC_TIMEOUT_MS = 3e4;
2072
- var PROFILE_WRITE_PACE_MS = 150;
2073
- var sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
2074
- var PROFILE_BIN_DIR_RE = /(^|\/)(s?bin)\//;
2075
- function execWithTimeout(box, cmd, timeoutMs) {
2076
- return new Promise((resolve, reject) => {
2077
- let settled = false;
2078
- const timer = setTimeout(() => {
2079
- if (settled) return;
2080
- settled = true;
2081
- reject(new ProfileWriteExecTimeoutError(timeoutMs));
2082
- }, timeoutMs);
2083
- box.exec(cmd, { timeoutMs }).then(
2084
- (res) => {
2085
- if (settled) return;
2086
- settled = true;
2087
- clearTimeout(timer);
2088
- resolve(res);
2089
- },
2090
- (err) => {
2091
- if (settled) return;
2092
- settled = true;
2093
- clearTimeout(timer);
2094
- reject(err);
2095
- }
2096
- );
2097
- });
2098
- }
2099
- function fileApiTarget(mount) {
2100
- if (mount.resource.kind !== "inline") return null;
2101
- let rel;
2102
- if (mount.path.startsWith("~/")) rel = mount.path.slice(2);
2103
- else if (mount.path.startsWith("/home/agent/")) rel = mount.path.slice("/home/agent/".length);
2104
- else if (mount.path.startsWith("/") || mount.path.startsWith("~")) return null;
2105
- else rel = mount.path;
2106
- if (rel.length === 0 || rel.startsWith("/") || rel.split("/").some((seg) => seg === ".." || seg === ".sidecar")) {
2107
- return null;
2108
- }
2109
- return rel;
2110
- }
2111
- function isExecutableProfileFile(mount) {
2112
- return mount.executable ?? PROFILE_BIN_DIR_RE.test(mount.path);
2113
- }
2114
- function profileFileMode(mount) {
2115
- return isExecutableProfileFile(mount) ? 493 : void 0;
2116
- }
2117
- var PROFILE_FILE_API_MAX_JSON_BYTES = 1024 * 1024 - 16 * 1024;
2118
- function fitsProfileFileApi(content) {
2119
- const encoder = new TextEncoder();
2120
- if (encoder.encode(content).byteLength * 6 <= PROFILE_FILE_API_MAX_JSON_BYTES) return true;
2121
- return encoder.encode(JSON.stringify(content)).byteLength <= PROFILE_FILE_API_MAX_JSON_BYTES;
2122
- }
2123
- function fileApiSupportsMode(box) {
2124
- const fs = box.fs;
2125
- return fs?.supportsWriteMode === true;
2126
- }
2127
- async function writeProfileFilesToBox(box, files, options = {}) {
2128
- const execTimeoutMs = options.execTimeoutMs ?? PROFILE_WRITE_EXEC_TIMEOUT_MS;
2129
- const paceMs = options.paceMs ?? PROFILE_WRITE_PACE_MS;
2130
- const maxRetries = options.maxRetries ?? PROFILE_WRITE_MAX_RETRIES;
2131
- const fileApiAvailable = typeof box.fs?.writeMany === "function";
2132
- const modeAwareFileApi = fileApiSupportsMode(box);
2133
- const uploadData = box.fs?.uploadData;
2134
- const viaFileApi = [];
2135
- const viaUpload = [];
2136
- const viaExec = [];
2137
- for (const mount of files) {
2138
- if (mount.resource.kind !== "inline") continue;
2139
- const fileApiPath = fileApiAvailable ? fileApiTarget(mount) : null;
2140
- const executable = isExecutableProfileFile(mount);
2141
- if (fileApiPath !== null && (!executable || modeAwareFileApi)) {
2142
- const mode = profileFileMode(mount);
2143
- const content = mount.resource.content ?? "";
2144
- const write = { path: fileApiPath, content, ...mode !== void 0 ? { mode } : {} };
2145
- if (fitsProfileFileApi(content)) viaFileApi.push(write);
2146
- else if (typeof uploadData === "function") viaUpload.push(write);
2147
- else viaExec.push(mount);
2148
- } else viaExec.push(mount);
2149
- }
2150
- if (viaFileApi.length > 0) {
2151
- try {
2152
- await box.fs.writeMany(viaFileApi, { paceMs, maxRetries });
2153
- } catch (err) {
2154
- return fail(new Error("writeProfileFilesToBox: file-API batch write failed", { cause: err }));
2155
- }
2156
- }
2157
- for (const upload of viaUpload) {
2158
- try {
2159
- await uploadData.call(box.fs, upload.path, upload.content, upload.mode !== void 0 ? { mode: upload.mode } : void 0);
2160
- } catch (err) {
2161
- return fail(new Error(`writeProfileFilesToBox: chunked upload failed for ${upload.path}`, { cause: err }));
2162
- }
2163
- }
2164
- let execStarted = false;
2165
- const paceAndRetry = async (run, path) => {
2166
- for (let attempt = 0; ; attempt++) {
2167
- if (execStarted && paceMs > 0) await sleep(paceMs);
2168
- execStarted = true;
2169
- try {
2170
- return ok(await run());
2171
- } catch (err) {
2172
- const { retryable, retryAfterMs: retryAfterMs2 } = transientExecError(err);
2173
- if (retryable && attempt < maxRetries) {
2174
- const backoff = Math.min(PROFILE_WRITE_RETRY_BASE_MS * 2 ** attempt, PROFILE_WRITE_RETRY_MAX_MS);
2175
- await sleep(retryAfterMs2 ?? backoff);
2176
- continue;
2177
- }
2178
- return fail(new Error(`writeProfileFilesToBox: exec failed for ${path}`, { cause: err }));
2179
- }
2180
- }
2181
- };
2182
- for (const mount of viaExec) {
2183
- if (mount.resource.kind !== "inline") continue;
2184
- const content = mount.resource.content ?? "";
2185
- const path = mount.path;
2186
- const b64 = Buffer.from(content, "utf8").toString("base64");
2187
- const b64Chunks = [];
2188
- for (let i = 0; i < b64.length; i += PROFILE_WRITE_B64_CHUNK_CHARS) {
2189
- b64Chunks.push(b64.slice(i, i + PROFILE_WRITE_B64_CHUNK_CHARS));
2190
- }
2191
- const expectedSha256 = createHash("sha256").update(content, "utf8").digest("hex");
2192
- const dir = path.replace(/\/[^/]*$/, "");
2193
- const executable = isExecutableProfileFile(mount);
2194
- const q = shellPath(path);
2195
- const qb64 = shellPath(`${path}.b64`);
2196
- const qtmp = shellPath(`${path}.tmp`);
2197
- const qpartPrefix = shellPath(`${path}.b64.part.`);
2198
- const step = async (cmd) => {
2199
- const res2 = await paceAndRetry(() => execWithTimeout(box, cmd, execTimeoutMs), path);
2200
- if (!res2.succeeded) return res2;
2201
- const exec = res2.value;
2202
- if (exec.exitCode !== 0) {
2203
- return fail(
2204
- new Error(
2205
- `writeProfileFilesToBox: failed to write ${path} (exit ${exec.exitCode}): ${exec.stderr.slice(0, 500)}`
2206
- )
2207
- );
2208
- }
2209
- return ok(void 0);
2210
- };
2211
- const mkdir = dir && dir !== path ? `mkdir -p ${shellPath(dir)}` : ":";
2212
- let res = await step(mkdir);
2213
- if (!res.succeeded) return res;
2214
- for (let i = 0; i < b64Chunks.length; i++) {
2215
- const slice = b64Chunks[i];
2216
- res = await step(`printf '%s' '${slice}' > ${shellPath(`${path}.b64.part.${i}`)}`);
2217
- if (!res.succeeded) return res;
2218
- }
2219
- const chmod = executable ? `chmod +x ${q} || exit 1; ` : "";
2220
- const checksumMismatch = shellSingleQuote(`writeProfileFilesToBox: checksum mismatch for ${path}`);
2221
- const finalCmd = `expected='${expectedSha256}'; if [ -f ${q} ] && [ "$(sha256sum ${q} | awk '{print $1}')" = "$expected" ]; then ${chmod}rm -f ${qb64} ${qtmp}; i=0; while [ "$i" -lt ${b64Chunks.length} ]; do rm -f ${qpartPrefix}$i; i=$((i+1)); done; exit 0; fi; : > ${qb64} && i=0; while [ "$i" -lt ${b64Chunks.length} ]; do cat ${qpartPrefix}$i >> ${qb64} || exit 1; i=$((i+1)); done && base64 -d < ${qb64} > ${qtmp} && [ "$(sha256sum ${qtmp} | awk '{print $1}')" = "$expected" ] || { echo ${checksumMismatch} >&2; exit 1; }; mv ${qtmp} ${q} && ${executable ? `chmod +x ${q} && ` : ""}[ "$(sha256sum ${q} | awk '{print $1}')" = "$expected" ] || { echo ${checksumMismatch} >&2; exit 1; }; rm -f ${qb64} ${qtmp}; i=0; while [ "$i" -lt ${b64Chunks.length} ]; do rm -f ${qpartPrefix}$i; i=$((i+1)); done`;
2222
- res = await step(finalCmd);
2223
- if (!res.succeeded) return res;
2224
- }
2225
- return ok(void 0);
2226
- }
2227
-
2228
1917
  // src/sandbox/lifecycle-errors.ts
2229
1918
  var SandboxEgressPolicyMismatchError = class extends Error {
2230
1919
  stage;
@@ -2281,7 +1970,7 @@ var SandboxBoxBusyError = class extends Error {
2281
1970
  };
2282
1971
 
2283
1972
  // src/sandbox/profile-corpus.ts
2284
- import { createHash as createHash2 } from "crypto";
1973
+ import { createHash } from "crypto";
2285
1974
 
2286
1975
  // src/sandbox/runtime-connection.ts
2287
1976
  var RUNTIME_AUTH_REFRESH_SKEW_MS = 6e4;
@@ -2417,7 +2106,7 @@ function deferredCorpusHash(files) {
2417
2106
  p: f.path,
2418
2107
  c: f.resource.kind === "inline" ? f.resource.content ?? "" : `ref:${f.resource.kind}`
2419
2108
  })).sort((a, b) => a.p < b.p ? -1 : a.p > b.p ? 1 : 0);
2420
- return createHash2("sha256").update(JSON.stringify(norm), "utf8").digest("hex");
2109
+ return createHash("sha256").update(JSON.stringify(norm), "utf8").digest("hex");
2421
2110
  }
2422
2111
  async function materializeDeferredFilesForExistingBox(shell, client, box, stage, name, workspaceId, userId, harness, corpusMarker) {
2423
2112
  if (!shell.deferProfileFiles) return ok(box);
@@ -2572,14 +2261,14 @@ async function peekWorkspaceSandbox(shell, options) {
2572
2261
  }
2573
2262
 
2574
2263
  // src/sandbox/existing-box.ts
2575
- import { createHash as createHash3 } from "crypto";
2264
+ import { createHash as createHash2 } from "crypto";
2576
2265
  async function resolveWorkspaceRuntimeEnv(shell, scope) {
2577
2266
  const env = await shell.runtimeEnv?.(scope) ?? {};
2578
2267
  assertEnvWithinLimits(env);
2579
2268
  return env;
2580
2269
  }
2581
2270
  function runtimeEnvDigest(env) {
2582
- return createHash3("sha256").update(JSON.stringify(canonicalizeJson(env)), "utf8").digest("hex");
2271
+ return createHash2("sha256").update(JSON.stringify(canonicalizeJson(env)), "utf8").digest("hex");
2583
2272
  }
2584
2273
  function hasDeliveredEnv(box, env) {
2585
2274
  const delivered = checksFor(box)?.env;
@@ -3880,9 +3569,6 @@ async function mintSandboxScopedToken(box, options) {
3880
3569
  export {
3881
3570
  traceSandboxPromptEvents,
3882
3571
  createCacheReuseStore,
3883
- shellQuote,
3884
- statSandboxFileSize,
3885
- readSandboxBinaryBytes,
3886
3572
  backendModelFields,
3887
3573
  resolveModelSelection,
3888
3574
  resolveModel,
@@ -3947,8 +3633,6 @@ export {
3947
3633
  buildSandboxToolPathSetupScript,
3948
3634
  ensureSandboxToolBinDir,
3949
3635
  runSandboxToolPathSetup,
3950
- splitDeferredProfileFiles,
3951
- writeProfileFilesToBox,
3952
3636
  SandboxEgressPolicyMismatchError,
3953
3637
  SandboxRuntimeAuthRefreshError,
3954
3638
  SandboxRecoveryFailedError,
@@ -3986,4 +3670,4 @@ export {
3986
3670
  deleteSecret,
3987
3671
  mintSandboxScopedToken
3988
3672
  };
3989
- //# sourceMappingURL=chunk-5Y7Z5G3Y.js.map
3673
+ //# sourceMappingURL=chunk-4GCPADYG.js.map