deepline 0.3.484 → 0.3.486

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 (210) hide show
  1. package/dist/bundling-sources/sdk/src/client-core.ts +91 -30
  2. package/dist/bundling-sources/sdk/src/compat.ts +13 -0
  3. package/dist/bundling-sources/sdk/src/plays/client-core.ts +4 -1
  4. package/dist/bundling-sources/sdk/src/plays/run-request.ts +143 -9
  5. package/dist/bundling-sources/sdk/src/release.ts +1 -1
  6. package/dist/bundling-sources/sdk/src/runs/watch-polling.ts +31 -4
  7. package/dist/bundling-sources/sdk/src/tool-calls.ts +1 -1
  8. package/dist/bundling-sources/sdk/src/types.ts +7 -1
  9. package/dist/bundling-sources/shared_libs/play-data-plane/sheet-column-storage.ts +32 -3
  10. package/dist/bundling-sources/shared_libs/play-runtime/app-runtime-api.ts +126 -41
  11. package/dist/bundling-sources/shared_libs/play-runtime/context.ts +231 -25
  12. package/dist/bundling-sources/shared_libs/play-runtime/daytona-runtime-config.ts +9 -0
  13. package/dist/bundling-sources/shared_libs/play-runtime/deployment/fly-machines.ts +130 -19
  14. package/dist/bundling-sources/shared_libs/play-runtime/deployment/fly-registry.ts +105 -0
  15. package/dist/bundling-sources/shared_libs/play-runtime/execute-server-timing.ts +4 -2
  16. package/dist/bundling-sources/shared_libs/play-runtime/governor/app-runtime-rate-state-backend.ts +194 -56
  17. package/dist/bundling-sources/shared_libs/play-runtime/ledger-safe-payload.ts +8 -4
  18. package/dist/bundling-sources/shared_libs/play-runtime/log-provenance.ts +11 -6
  19. package/dist/bundling-sources/shared_libs/play-runtime/play-runs/sandbox-cleanup/job.ts +3 -0
  20. package/dist/bundling-sources/shared_libs/play-runtime/play-runs/sandbox-cleanup/ports.ts +2 -0
  21. package/dist/bundling-sources/shared_libs/play-runtime/play-runs/sandbox-cleanup/postgres-adapter.ts +2 -1
  22. package/dist/bundling-sources/shared_libs/play-runtime/protocol.ts +30 -0
  23. package/dist/bundling-sources/shared_libs/play-runtime/resource-governor.ts +195 -2
  24. package/dist/bundling-sources/shared_libs/play-runtime/run-failure.ts +20 -1
  25. package/dist/bundling-sources/shared_libs/play-runtime/run-ledger-projection-contract.ts +15 -0
  26. package/dist/bundling-sources/shared_libs/play-runtime/run-snapshot-stream.ts +2 -2
  27. package/dist/bundling-sources/shared_libs/play-runtime/runner-app/index.ts +139 -67
  28. package/dist/bundling-sources/shared_libs/play-runtime/runner-app/progress-sidecar.ts +9 -1
  29. package/dist/bundling-sources/shared_libs/play-runtime/runner-backends/backends/daytona-control-transport.ts +25 -5
  30. package/dist/bundling-sources/shared_libs/play-runtime/runner-backends/backends/daytona-launch-transport.ts +133 -82
  31. package/dist/bundling-sources/shared_libs/play-runtime/runner-backends/backends/daytona-lifecycle.ts +58 -16
  32. package/dist/bundling-sources/shared_libs/play-runtime/runner-backends/backends/daytona-sandbox-absence.ts +171 -0
  33. package/dist/bundling-sources/shared_libs/play-runtime/runner-backends/backends/daytona-session-execution.ts +69 -0
  34. package/dist/bundling-sources/shared_libs/play-runtime/runner-backends/backends/daytona.ts +100 -40
  35. package/dist/bundling-sources/shared_libs/play-runtime/runner-backends/types.ts +8 -0
  36. package/dist/bundling-sources/shared_libs/play-runtime/runtime-api.ts +67 -9
  37. package/dist/bundling-sources/shared_libs/play-runtime/runtime-incident-drills.ts +5 -5
  38. package/dist/bundling-sources/shared_libs/play-runtime/runtime-receipt-store-adapter.ts +6 -3
  39. package/dist/bundling-sources/shared_libs/play-runtime/runtime-sheet-errors.ts +14 -0
  40. package/dist/bundling-sources/shared_libs/play-runtime/runtime-sheet-row-writer.ts +87 -31
  41. package/dist/bundling-sources/shared_libs/play-runtime/sandbox-runs/contract.ts +18 -0
  42. package/dist/bundling-sources/shared_libs/play-runtime/sandbox-runs/index.ts +19 -0
  43. package/dist/bundling-sources/shared_libs/play-runtime/sandbox-runs/runner-backend-adapter.ts +14 -0
  44. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/absurd-runtime-worker.ts +206 -7
  45. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/absurd.ts +39 -0
  46. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/play-run-recovery.ts +12 -1
  47. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/postgres-progress.ts +28 -9
  48. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/postgres-rate-scope.ts +44 -15
  49. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/postgres-rate-state.ts +60 -11
  50. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/postgres.ts +656 -64
  51. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/run-ledger-outbox-recovery.ts +6 -1
  52. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/runtime-event-search.ts +17 -0
  53. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/runtime-sandbox-capacity.ts +25 -33
  54. package/dist/bundling-sources/shared_libs/play-runtime/suspension.ts +12 -0
  55. package/dist/bundling-sources/shared_libs/play-runtime/test-runtime-seams.ts +21 -0
  56. package/dist/bundling-sources/shared_libs/plays/authoring-contract.ts +1 -1
  57. package/dist/bundling-sources/shared_libs/plays/source-authoring-edition.ts +1 -1
  58. package/dist/cli/auth-ARKH3OAU.js +43 -0
  59. package/dist/cli/{auth-EBFOTF7X.mjs → auth-B4DJO4FB.mjs} +5 -5
  60. package/dist/cli/{billing-G2G3EF3I.js → billing-GDWAMARK.js} +80 -80
  61. package/dist/cli/{billing-2ZOIMW5V.mjs → billing-IIQ3VNXU.mjs} +7 -7
  62. package/dist/cli/{chunk-YWC5AN26.mjs → chunk-2DVFQYPG.mjs} +62 -34
  63. package/dist/cli/{chunk-UWOY74RU.js → chunk-5DUP4ZUE.js} +21 -21
  64. package/dist/cli/{chunk-EACX7QXO.mjs → chunk-5QYZ4MEW.mjs} +2 -2
  65. package/dist/cli/{chunk-HEI3BWIV.mjs → chunk-5RLVCOKH.mjs} +1 -1
  66. package/dist/cli/{chunk-TIRSKEZH.mjs → chunk-5Y7LLRWO.mjs} +1 -1
  67. package/dist/cli/{chunk-IXWQOVNW.js → chunk-5YILTBF7.js} +87 -76
  68. package/dist/cli/{chunk-OHKKDPA5.js → chunk-7FTQKEZ6.js} +13 -13
  69. package/dist/cli/{chunk-TN2GW57M.mjs → chunk-A456YVDE.mjs} +1 -1
  70. package/dist/cli/{chunk-GVAENVIG.js → chunk-AUQQVDAB.js} +110 -21
  71. package/dist/cli/{chunk-3XQIVEAT.js → chunk-BJL7RYQN.js} +3 -3
  72. package/dist/cli/{chunk-2AWYJXBX.js → chunk-BNB2RK4L.js} +5 -5
  73. package/dist/cli/{chunk-U7IJAGWB.js → chunk-BYEDI5PM.js} +7 -7
  74. package/dist/cli/{chunk-RLLEH2SP.js → chunk-C4GFBB52.js} +26 -26
  75. package/dist/cli/{chunk-AK7UKQ5R.js → chunk-CSBMKHTV.js} +5 -5
  76. package/dist/cli/{chunk-UT4YMA2N.js → chunk-DFHS5XVZ.js} +5 -4
  77. package/dist/cli/{chunk-XZXIWPT3.mjs → chunk-F3G2HAUQ.mjs} +1 -1
  78. package/dist/cli/{chunk-C62NI2X6.js → chunk-FCAKAW6S.js} +5 -5
  79. package/dist/cli/{chunk-AF7MOUZP.mjs → chunk-FGPJXQEJ.mjs} +2 -2
  80. package/dist/cli/chunk-FSCOYTRV.js +42 -0
  81. package/dist/cli/{chunk-6GRZEYSG.js → chunk-GCEUOHJW.js} +7 -7
  82. package/dist/cli/{chunk-SD7QWZTV.mjs → chunk-INW22YP7.mjs} +1 -1
  83. package/dist/cli/{chunk-OWUZKXE7.mjs → chunk-J7EENGKJ.mjs} +1 -1
  84. package/dist/cli/{chunk-QIDDTIVZ.js → chunk-KPIVQFXZ.js} +322 -294
  85. package/dist/cli/{chunk-4IOY2SCQ.js → chunk-LOX3BISD.js} +4 -4
  86. package/dist/cli/{chunk-WYUCDLVR.mjs → chunk-MJ56FCYU.mjs} +2 -1
  87. package/dist/cli/{chunk-DBJ62RAO.js → chunk-NSPMJLYA.js} +3 -3
  88. package/dist/cli/{chunk-HNRELVCS.mjs → chunk-ONONSV2Q.mjs} +96 -7
  89. package/dist/cli/{chunk-PU52JXKA.mjs → chunk-P6KGYOCM.mjs} +13 -4
  90. package/dist/cli/{chunk-VEVGM6B5.js → chunk-PCYZDTDC.js} +14 -14
  91. package/dist/cli/{chunk-NW4QJE54.js → chunk-PHWFY26F.js} +2 -2
  92. package/dist/cli/{chunk-LTZXLYKE.mjs → chunk-PKOFEHZL.mjs} +93 -17
  93. package/dist/cli/{chunk-7K5CWKKZ.mjs → chunk-PQHDZHZG.mjs} +2 -2
  94. package/dist/cli/{chunk-UKM74PAA.js → chunk-PTM3QRAT.js} +37 -37
  95. package/dist/cli/{chunk-YGN77QA5.mjs → chunk-PV7AYBKQ.mjs} +3 -3
  96. package/dist/cli/{chunk-4OEOM6GP.mjs → chunk-PYDHVRAF.mjs} +5 -5
  97. package/dist/cli/{chunk-FRD5WFT4.js → chunk-QD22TY33.js} +323 -247
  98. package/dist/cli/{chunk-5KNRQWHE.js → chunk-QEQ3KHVY.js} +3 -3
  99. package/dist/cli/{chunk-KGOC6HGI.js → chunk-S5EYODEG.js} +53 -53
  100. package/dist/cli/{chunk-FQK7BULS.js → chunk-S7OILDJH.js} +1 -1
  101. package/dist/cli/{chunk-TRLDJNVE.mjs → chunk-T3Q6BMVH.mjs} +1 -1
  102. package/dist/cli/{chunk-5K5CAND4.mjs → chunk-TBE2K5W4.mjs} +4 -4
  103. package/dist/cli/{chunk-YHA3EV3I.mjs → chunk-TE2QT2MX.mjs} +15 -4
  104. package/dist/cli/{chunk-ZOKM7DVA.js → chunk-TNHY3ATN.js} +8 -8
  105. package/dist/cli/{chunk-4OVHIWE7.mjs → chunk-U23L57VU.mjs} +2 -2
  106. package/dist/cli/{chunk-5GOG5ZGC.mjs → chunk-UEJLWUJ3.mjs} +2 -2
  107. package/dist/cli/{chunk-6NPWXE32.mjs → chunk-VJLL5XIP.mjs} +1 -1
  108. package/dist/cli/{chunk-WXRM3UC6.mjs → chunk-WCOJH4W4.mjs} +3 -3
  109. package/dist/cli/{chunk-4SFC2XUF.mjs → chunk-XAZWUW6I.mjs} +5 -5
  110. package/dist/cli/{chunk-ZM2YPJQJ.js → chunk-XK5DMLZE.js} +5 -1
  111. package/dist/cli/{chunk-LJ5747UC.mjs → chunk-XRDXNAAY.mjs} +5 -1
  112. package/dist/cli/{chunk-V7JCMBLU.mjs → chunk-YIKHNZ6B.mjs} +4 -4
  113. package/dist/cli/{chunk-M4PG7FGC.js → chunk-YS6JOYYS.js} +2 -2
  114. package/dist/cli/{chunk-DEXSQGXB.mjs → chunk-ZMRZ3BXG.mjs} +5 -5
  115. package/dist/cli/{chunk-CYWBAV5H.js → chunk-ZQI26KE4.js} +16 -16
  116. package/dist/cli/{csv-S3CHUKI6.js → csv-3PSMPZM5.js} +13 -13
  117. package/dist/cli/{csv-NLWVWD3H.mjs → csv-LFCT3WQ4.mjs} +4 -4
  118. package/dist/cli/{db-OGRPAEEM.mjs → db-HULKVAMU.mjs} +7 -7
  119. package/dist/cli/{db-WBSKMMOH.js → db-R7I2PPTV.js} +28 -28
  120. package/dist/cli/{describe-FAD3Z7LN.mjs → describe-D55V42LH.mjs} +21 -21
  121. package/dist/cli/describe-H47BLOEP.js +49 -0
  122. package/dist/cli/describe-core.d.mts +3 -3
  123. package/dist/cli/describe-core.d.ts +3 -3
  124. package/dist/cli/describe-core.js +4 -4
  125. package/dist/cli/describe-core.mjs +3 -3
  126. package/dist/cli/{executions-LYCL344R.mjs → executions-ICVVOYVG.mjs} +7 -7
  127. package/dist/cli/{executions-SOAZHCY4.js → executions-O37FN2SK.js} +9 -9
  128. package/dist/cli/{feedback-AVF6V7SV.mjs → feedback-3K3QPGCQ.mjs} +4 -4
  129. package/dist/cli/{feedback-OROUPUNJ.js → feedback-MAZQ7C6S.js} +8 -8
  130. package/dist/cli/{git-J5N5M57H.mjs → git-2MMD5KJS.mjs} +5 -5
  131. package/dist/cli/git-RQ2XLFYZ.js +25 -0
  132. package/dist/cli/index.js +142 -139
  133. package/dist/cli/index.mjs +45 -42
  134. package/dist/cli/{legacy-noops-QAQMZMEG.js → legacy-noops-2OX2Y3Y2.js} +8 -8
  135. package/dist/cli/{legacy-noops-ENRRM7BL.mjs → legacy-noops-VLSWJ6VE.mjs} +5 -5
  136. package/dist/cli/{monitors-CKQ65WRL.mjs → monitors-2NODQQWG.mjs} +8 -8
  137. package/dist/cli/{monitors-SFMQ5LFR.js → monitors-UCSV5FOR.js} +92 -92
  138. package/dist/cli/{org-3UNTDLT2.js → org-4YY73VTW.js} +73 -73
  139. package/dist/cli/{org-K4UIEU5P.mjs → org-W7AUQCDE.mjs} +7 -7
  140. package/dist/cli/{pages-NKZTGB4C.js → pages-FBZEUMXK.js} +18 -18
  141. package/dist/cli/{pages-6GPGBIAH.mjs → pages-ZRP7U5PO.mjs} +7 -7
  142. package/dist/cli/{play-BDEADESI.js → play-LFCTQJXA.js} +858 -632
  143. package/dist/cli/{play-62BEE7IX.mjs → play-XF2BSGTP.mjs} +372 -146
  144. package/dist/cli/{providers-SXGP44GH.js → providers-5456JNHP.js} +10 -10
  145. package/dist/cli/{providers-X3CUWMFP.mjs → providers-SICAPKGI.mjs} +7 -7
  146. package/dist/cli/{quickstart-XQ4426M4.js → quickstart-2KLLIPIU.js} +6 -6
  147. package/dist/cli/{quickstart-7LN22BKX.mjs → quickstart-IBVG6GX6.mjs} +4 -4
  148. package/dist/cli/{run-PBJ4ZJ4W.js → run-DNLDGJRC.js} +41 -41
  149. package/dist/cli/{run-XXSN3B5A.mjs → run-XPIZIQ7H.mjs} +26 -26
  150. package/dist/cli/search-2KQA65LH.js +32 -0
  151. package/dist/cli/{search-M75VMADD.mjs → search-PW22AEAL.mjs} +8 -8
  152. package/dist/cli/{search-output-F6HCFYEI.js → search-output-H6F6QMRF.js} +22 -16
  153. package/dist/cli/{search-output-NUQAKWDM.mjs → search-output-JFD53H2N.mjs} +14 -8
  154. package/dist/cli/{secrets-J2H6V33R.mjs → secrets-542CTZRZ.mjs} +7 -7
  155. package/dist/cli/{secrets-LRYY4QPE.js → secrets-LCCRRAN7.js} +16 -16
  156. package/dist/cli/{sessions-YPF62CZE.js → sessions-5FYDQE3N.js} +6 -6
  157. package/dist/cli/{sessions-IMT336UV.mjs → sessions-CALLS2XD.mjs} +5 -5
  158. package/dist/cli/{settings-PDWVQIGH.mjs → settings-GSKPHUEC.mjs} +12 -12
  159. package/dist/cli/{settings-35YYC5WA.js → settings-ORGKOBP6.js} +79 -79
  160. package/dist/cli/{setup-UR7GOR7H.js → setup-4BUWJKB6.js} +47 -47
  161. package/dist/cli/{setup-DG5DISSE.mjs → setup-V57GHVAF.mjs} +9 -9
  162. package/dist/cli/skills-KYZPPGSN.js +33 -0
  163. package/dist/cli/{skills-U6NJD5J7.mjs → skills-NGLCFQFT.mjs} +7 -7
  164. package/dist/cli/tools-AFYXUEMD.js +56 -0
  165. package/dist/cli/{tools-2HGEOELR.mjs → tools-G2YNCFNX.mjs} +19 -19
  166. package/dist/cli/{update-FRAYBAHK.mjs → update-IZ3Z5T5C.mjs} +9 -9
  167. package/dist/cli/update-T6JJ7A3K.js +33 -0
  168. package/dist/cli/{workflow-JKKLOMBX.js → workflow-7AHST2XV.js} +18 -18
  169. package/dist/cli/{workflow-DDKVTF36.mjs → workflow-L7ROQIM7.mjs} +8 -8
  170. package/dist/{client-DJ3r8VQJ.d.mts → client-BkbDHRIg.d.mts} +1 -1
  171. package/dist/{client-JPSNljtj.d.ts → client-D3hVHXjK.d.ts} +1 -1
  172. package/dist/{client-core-3SJlNsKU.d.mts → client-core-BZoSMKcY.d.mts} +30 -15
  173. package/dist/{client-core-rCoQ5Xz3.d.ts → client-core-DUdVqO_m.d.ts} +30 -15
  174. package/dist/{compiler-manifest-gkO9ZkVg.d.mts → compiler-manifest-BFTwq1HI.d.mts} +1 -1
  175. package/dist/{compiler-manifest-gkO9ZkVg.d.ts → compiler-manifest-BFTwq1HI.d.ts} +1 -1
  176. package/dist/{errors-Cc92LKH-.d.ts → errors-c3pMsylw.d.ts} +1 -1
  177. package/dist/{errors-CeCCOKSA.d.mts → errors-w31ybrQM.d.mts} +1 -1
  178. package/dist/{index-DJQKdV76.d.ts → index-CQ-15-QL.d.ts} +1 -1
  179. package/dist/{index-DsqWJL3Q.d.mts → index-DvNtxucX.d.mts} +1 -1
  180. package/dist/index.d.mts +7 -7
  181. package/dist/index.d.ts +7 -7
  182. package/dist/index.js +10 -10
  183. package/dist/index.mjs +7 -7
  184. package/dist/install-integrity.json +117 -116
  185. package/dist/plays/bundle-play-file.d.mts +3 -3
  186. package/dist/plays/bundle-play-file.d.ts +3 -3
  187. package/dist/plays/bundle-play-file.mjs +2 -2
  188. package/dist/plays/play-description.d.mts +2 -2
  189. package/dist/plays/play-description.d.ts +2 -2
  190. package/dist/plays/run-request.d.mts +2 -2
  191. package/dist/plays/run-request.d.ts +2 -2
  192. package/dist/plays/run-request.js +12 -2
  193. package/dist/plays/run-request.mjs +11 -1
  194. package/dist/release.d.mts +1 -1
  195. package/dist/release.d.ts +1 -1
  196. package/dist/release.js +2 -2
  197. package/dist/release.mjs +1 -1
  198. package/dist/server.d.mts +4 -4
  199. package/dist/server.d.ts +4 -4
  200. package/dist/server.js +6 -6
  201. package/dist/server.mjs +4 -4
  202. package/package.json +1 -1
  203. package/dist/cli/auth-L5CSV3UO.js +0 -43
  204. package/dist/cli/chunk-KA2LNIUP.js +0 -33
  205. package/dist/cli/describe-UIAYCHWW.js +0 -49
  206. package/dist/cli/git-ATMWC27D.js +0 -25
  207. package/dist/cli/search-IGHLRLBD.js +0 -32
  208. package/dist/cli/skills-4U5WC4MJ.js +0 -33
  209. package/dist/cli/tools-PYJTQVVS.js +0 -56
  210. package/dist/cli/update-344OTRFM.js +0 -33
@@ -176,18 +176,22 @@ import {
176
176
  isPlayRunPackage,
177
177
  mintStagedPlayFileUploads,
178
178
  normalizePlayRunStart,
179
+ CLI_PLAY_RUN_CALLER_INTENT_V2_START_STREAM_PATH,
179
180
  CLI_PLAY_RUN_START_STREAM_PATH,
181
+ CliPlayAdmissionCallerIntentV2UnsupportedError,
180
182
  CLI_PLAY_RUN_SUPPORTED_HEADER,
181
183
  CliPlayAdmissionUnsupportedError,
182
184
  PLAY_RUN_START_STREAM_PATH,
183
185
  stagePlayFiles,
184
186
  preparePlayRunAdmission,
187
+ submitPreparedPlayRunAdmission,
185
188
  readPlayRunAdmissionCapability,
186
189
  type MintStagedFileUpload,
187
190
  type PlayRunAdmissionCapability,
188
191
  type PlayRunStartOptions,
189
192
  type ResolvedStartPlayRunRequest,
190
193
  } from './plays/run-request';
194
+ import { SDK_API_MAJOR } from './version';
191
195
  import type { PlayCompilerManifest } from '../../shared_libs/plays/compiler-manifest.js';
192
196
  import type { EnrichCompiledConfig } from './cli/enrich-play-compiler';
193
197
  import { COORDINATOR_INTERNAL_TOKEN_HEADER } from '../../shared_libs/play-runtime/coordinator-headers.js';
@@ -3596,36 +3600,80 @@ export class DeeplineClient {
3596
3600
  */
3597
3601
  async preparePlayRunAdmission(
3598
3602
  request: StartPlayRunRequest,
3599
- options?: {
3600
- cliAdmission?: boolean;
3601
- /** @internal Capability response prefetched by the CLI during local preparation. */
3602
- admissionCapability?:
3603
- | Promise<PlayRunAdmissionCapability>
3604
- | PlayRunAdmissionCapability;
3605
- onSubmission?: (intent: {
3606
- workflowId: string;
3607
- orgId: string;
3608
- request: Record<string, unknown>;
3609
- }) => void | Promise<void>;
3610
- },
3603
+ options?: PlayRunStartOptions,
3611
3604
  ) {
3612
3605
  const resolved = resolveStartPlayRunRequest(request, this.environment);
3613
3606
  const prepared = await preparePlayRunAdmission(
3614
3607
  this.http,
3615
3608
  resolved.request,
3616
3609
  options?.onSubmission,
3617
- {
3618
- ...(options && Object.hasOwn(options, 'admissionCapability')
3619
- ? { admissionCapability: options.admissionCapability }
3620
- : {}),
3621
- },
3610
+ options,
3622
3611
  );
3623
3612
  const bodyJson = JSON.stringify(prepared.body);
3624
- const headers = runtimeSelectionHeaders(resolved.runtime, this.environment);
3613
+ const runtimeHeaders = runtimeSelectionHeaders(
3614
+ resolved.runtime,
3615
+ this.environment,
3616
+ );
3617
+ const headers = options?.cliAdmission
3618
+ ? {
3619
+ ...runtimeHeaders,
3620
+ 'X-Deepline-API-Major': String(SDK_API_MAJOR),
3621
+ }
3622
+ : runtimeHeaders;
3625
3623
  const http = this.http;
3626
3624
  let submitted = false;
3627
3625
  return {
3628
3626
  ...prepared,
3627
+ async start(
3628
+ startOptions?: Pick<PlayRunStartOptions, 'cliAdmission' | 'signal'>,
3629
+ ) {
3630
+ if (submitted && !prepared.supportsCallerIntent) {
3631
+ throw new DeeplineError(
3632
+ 'This server has not enabled caller-owned admission recovery. Do not retry an ambiguous start.',
3633
+ 409,
3634
+ 'PLAY_RUN_ADMISSION_RECOVERY_UNSUPPORTED',
3635
+ );
3636
+ }
3637
+ if (submitted) {
3638
+ // Re-prove the pinned intent before retrying. Caller-intent v2 is
3639
+ // checked by the versioned POST response itself; legacy admission
3640
+ // uses the capability reader.
3641
+ if (!options?.callerIntentV2) {
3642
+ await preparePlayRunAdmission(
3643
+ http,
3644
+ JSON.parse(bodyJson) as ResolvedStartPlayRunRequest,
3645
+ undefined,
3646
+ { signal: startOptions?.signal ?? options?.signal },
3647
+ );
3648
+ }
3649
+ }
3650
+ submitted = true;
3651
+ try {
3652
+ return await submitPreparedPlayRunAdmission(
3653
+ http,
3654
+ JSON.parse(bodyJson) as Record<string, unknown>,
3655
+ prepared.workflowId,
3656
+ prepared.supportsCallerIntent,
3657
+ headers,
3658
+ {
3659
+ cliAdmission: startOptions?.cliAdmission ?? options?.cliAdmission,
3660
+ callerIntentV2: options?.callerIntentV2,
3661
+ signal: startOptions?.signal ?? options?.signal,
3662
+ },
3663
+ );
3664
+ } catch (error) {
3665
+ if (
3666
+ error instanceof CliPlayAdmissionUnsupportedError ||
3667
+ error instanceof CliPlayAdmissionCallerIntentV2UnsupportedError
3668
+ ) {
3669
+ // These errors are raised only after an authoritative 404/405
3670
+ // from the admission route, so the fallback route cannot create
3671
+ // a second run.
3672
+ submitted = false;
3673
+ }
3674
+ throw error;
3675
+ }
3676
+ },
3629
3677
  async *startStream(streamOptions?: { signal?: AbortSignal }) {
3630
3678
  if (submitted && !prepared.supportsCallerIntent) {
3631
3679
  throw new DeeplineError(
@@ -3638,17 +3686,21 @@ export class DeeplineClient {
3638
3686
  // A later transport attempt may reach a rolled-back server or a
3639
3687
  // different workspace. Re-prove support for the pinned intent,
3640
3688
  // without rebuilding it or persisting another submission journal.
3641
- await preparePlayRunAdmission(
3642
- http,
3643
- JSON.parse(bodyJson) as ResolvedStartPlayRunRequest,
3644
- undefined,
3645
- { signal: streamOptions?.signal },
3646
- );
3689
+ if (!options?.callerIntentV2) {
3690
+ await preparePlayRunAdmission(
3691
+ http,
3692
+ JSON.parse(bodyJson) as ResolvedStartPlayRunRequest,
3693
+ undefined,
3694
+ { signal: streamOptions?.signal },
3695
+ );
3696
+ }
3647
3697
  }
3648
3698
  submitted = true;
3649
- const streamPath = options?.cliAdmission
3650
- ? CLI_PLAY_RUN_START_STREAM_PATH
3651
- : PLAY_RUN_START_STREAM_PATH;
3699
+ const streamPath = options?.callerIntentV2
3700
+ ? CLI_PLAY_RUN_CALLER_INTENT_V2_START_STREAM_PATH
3701
+ : options?.cliAdmission
3702
+ ? CLI_PLAY_RUN_START_STREAM_PATH
3703
+ : PLAY_RUN_START_STREAM_PATH;
3652
3704
  let cliAdmissionSupported = false;
3653
3705
  try {
3654
3706
  for await (const event of http.streamSse<PlayLiveEvent>(streamPath, {
@@ -3676,6 +3728,13 @@ export class DeeplineClient {
3676
3728
  error instanceof DeeplineError &&
3677
3729
  (error.statusCode === 404 || error.statusCode === 405)
3678
3730
  ) {
3731
+ if (options.callerIntentV2) {
3732
+ submitted = false;
3733
+ throw new CliPlayAdmissionCallerIntentV2UnsupportedError(
3734
+ error.statusCode,
3735
+ );
3736
+ }
3737
+ submitted = false;
3679
3738
  throw new CliPlayAdmissionUnsupportedError(error.statusCode);
3680
3739
  }
3681
3740
  throw error;
@@ -3689,8 +3748,10 @@ export class DeeplineClient {
3689
3748
  * preparation so the network round trip can overlap with compilation.
3690
3749
  * @internal
3691
3750
  */
3692
- async prefetchPlayRunAdmissionCapability(): Promise<PlayRunAdmissionCapability> {
3693
- return readPlayRunAdmissionCapability(this.http);
3751
+ async prefetchPlayRunAdmissionCapability(options?: {
3752
+ signal?: AbortSignal;
3753
+ }): Promise<PlayRunAdmissionCapability> {
3754
+ return readPlayRunAdmissionCapability(this.http, options);
3694
3755
  }
3695
3756
 
3696
3757
  /**
@@ -4206,7 +4267,7 @@ export class DeeplineClient {
4206
4267
  */
4207
4268
  async getPlayStatus(
4208
4269
  workflowId: string,
4209
- options?: { billing?: boolean; full?: boolean },
4270
+ options?: { billing?: boolean; full?: boolean; runStatus?: boolean },
4210
4271
  ): Promise<PlayStatus> {
4211
4272
  return this.playClient.getPlayStatus(workflowId, options);
4212
4273
  }
@@ -378,6 +378,8 @@ export async function checkSdkCompatibility(
378
378
  timeoutMs?: number;
379
379
  /** Disable cache writes and invalidation for commands that permit no local maintenance. */
380
380
  persistCache?: boolean;
381
+ /** Stop this check when the enclosing CLI operation reaches its deadline. */
382
+ signal?: AbortSignal;
381
383
  /** Optional read-only catalog result carried by the same live check. */
382
384
  catalog?: {
383
385
  toolId: string;
@@ -394,6 +396,9 @@ export async function checkSdkCompatibility(
394
396
  return { response: null, error: null };
395
397
  }
396
398
  const controller = new AbortController();
399
+ const abortFromCaller = () => controller.abort(options.signal?.reason);
400
+ if (options.signal?.aborted) abortFromCaller();
401
+ else options.signal?.addEventListener('abort', abortFromCaller, { once: true });
397
402
  const timeout = setTimeout(
398
403
  () => controller.abort(),
399
404
  options.timeoutMs ?? CHECK_TIMEOUT_MS,
@@ -439,6 +444,7 @@ export async function checkSdkCompatibility(
439
444
  const raw = (await response.json().catch(() => null)) as
440
445
  | (SdkCompatibilityResponse & { catalog_metadata?: unknown })
441
446
  | null;
447
+ options.signal?.throwIfAborted();
442
448
  // Only a policy-shaped body counts as a response. A JSON error page from
443
449
  // a proxy is a failed check: it is never cached, and it falls through to
444
450
  // the cached-policy fallback below like a network error would.
@@ -469,6 +475,12 @@ export async function checkSdkCompatibility(
469
475
  }
470
476
  return { response: data, error: null };
471
477
  } catch (error) {
478
+ if (options.signal?.aborted) {
479
+ return {
480
+ response: null,
481
+ error: error instanceof Error ? error : new Error(String(error)),
482
+ };
483
+ }
472
484
  // Live compat policy must win when the server is reachable: rollback and
473
485
  // support-floor changes are blocking controls. The cache is only a
474
486
  // resilience fallback for transient network failures.
@@ -497,6 +509,7 @@ export async function checkSdkCompatibility(
497
509
  };
498
510
  } finally {
499
511
  clearTimeout(timeout);
512
+ options.signal?.removeEventListener('abort', abortFromCaller);
500
513
  }
501
514
  }
502
515
 
@@ -331,7 +331,7 @@ export class PlayClient {
331
331
 
332
332
  async getPlayStatus(
333
333
  workflowId: string,
334
- options?: { billing?: boolean; full?: boolean },
334
+ options?: { billing?: boolean; full?: boolean; runStatus?: boolean },
335
335
  ): Promise<PlayStatus> {
336
336
  const params = new URLSearchParams();
337
337
  if (options?.billing === false) {
@@ -343,6 +343,9 @@ export class PlayClient {
343
343
  const query = params.size > 0 ? `?${params.toString()}` : '';
344
344
  const response = await this.http.get<Record<string, unknown>>(
345
345
  `/api/v2/runs/${encodeURIComponent(workflowId)}${query}`,
346
+ options?.runStatus === true
347
+ ? { headers: { 'x-deepline-run-status': '1' } }
348
+ : undefined,
346
349
  );
347
350
  return normalizePlayStatus(response);
348
351
  }
@@ -34,9 +34,13 @@ export { DeeplineError };
34
34
  /** Canonical admission; the CLI adapter adds compatibility before this handler. */
35
35
  export const PLAY_RUN_START_PATH = '/api/v2/plays/run';
36
36
  export const CLI_PLAY_RUN_START_PATH = `${PLAY_RUN_START_PATH}/cli`;
37
+ export const CLI_PLAY_RUN_CALLER_INTENT_V2_PATH = `${CLI_PLAY_RUN_START_PATH}/caller-intent-v2`;
37
38
  export const CLI_PLAY_RUN_SUPPORTED_HEADER = 'x-deepline-cli-play-admission';
39
+ export const CLI_PLAY_RUN_CALLER_INTENT_V2_SUPPORTED_HEADER =
40
+ 'x-deepline-cli-play-caller-intent-v2';
38
41
  export const PLAY_RUN_START_STREAM_PATH = `${PLAY_RUN_START_PATH}?stream=true`;
39
42
  export const CLI_PLAY_RUN_START_STREAM_PATH = `${CLI_PLAY_RUN_START_PATH}?stream=true`;
43
+ export const CLI_PLAY_RUN_CALLER_INTENT_V2_START_STREAM_PATH = `${CLI_PLAY_RUN_CALLER_INTENT_V2_PATH}?stream=true`;
40
44
  export const PLAY_FILES_STAGE_PATH = '/api/v2/plays/files/stage';
41
45
  export const PLAY_FILES_STAGE_MINT_PATH = `${PLAY_FILES_STAGE_PATH}/mint`;
42
46
 
@@ -85,15 +89,52 @@ export type ResolvedStartPlayRunRequest = StartPlayRunRequest;
85
89
 
86
90
  export type PlayRunStartOptions = {
87
91
  signal?: AbortSignal;
92
+ /** @internal Deadline for CLI admission preparation and intent persistence. */
93
+ deadlineAt?: number;
94
+ /** @internal Capability read that may overlap with local Play compilation. */
95
+ admissionCapability?:
96
+ | Promise<PlayRunAdmissionCapability>
97
+ | PlayRunAdmissionCapability;
88
98
  onSubmission?: (intent: {
89
99
  workflowId: string;
90
100
  orgId: string;
91
101
  request: Record<string, unknown>;
92
102
  }) => void | Promise<void>;
93
- /** @internal CLI JSON admission checks compatibility in the same request. */
103
+ /** @internal CLI Play admission checks compatibility in the same request. */
94
104
  cliAdmission?: boolean;
105
+ /** @internal Uses the versioned CLI route to avoid a separate capability GET. */
106
+ callerIntentV2?: boolean;
95
107
  };
96
108
 
109
+ async function awaitWithAbort<T>(
110
+ value: PromiseLike<T> | T,
111
+ signal?: AbortSignal,
112
+ ): Promise<T> {
113
+ if (!signal) return await value;
114
+ signal.throwIfAborted();
115
+
116
+ let removeAbortListener = () => {};
117
+ const aborted = new Promise<never>((_resolve, reject) => {
118
+ const onAbort = () => {
119
+ reject(
120
+ signal.reason ??
121
+ Object.assign(new Error('Play admission was aborted.'), {
122
+ name: 'AbortError',
123
+ }),
124
+ );
125
+ };
126
+ signal.addEventListener('abort', onAbort, { once: true });
127
+ removeAbortListener = () => signal.removeEventListener('abort', onAbort);
128
+ if (signal.aborted) onAbort();
129
+ });
130
+
131
+ try {
132
+ return await Promise.race([Promise.resolve(value), aborted]);
133
+ } finally {
134
+ removeAbortListener();
135
+ }
136
+ }
137
+
97
138
  /** Only the transport can prove that the named action never dispatched. */
98
139
  export class CliPlayAdmissionUnsupportedError extends DeeplineError {
99
140
  constructor(status: number) {
@@ -105,6 +146,17 @@ export class CliPlayAdmissionUnsupportedError extends DeeplineError {
105
146
  }
106
147
  }
107
148
 
149
+ /** The route is absent, so no request reached an admission handler. */
150
+ export class CliPlayAdmissionCallerIntentV2UnsupportedError extends DeeplineError {
151
+ constructor(status: number) {
152
+ super(
153
+ 'This server does not support versioned CLI Play admission.',
154
+ status,
155
+ 'CLI_PLAY_CALLER_INTENT_V2_UNSUPPORTED',
156
+ );
157
+ }
158
+ }
159
+
108
160
  /** The exact JSON body `POST /api/v2/plays/run` receives. Key order is part of the contract. */
109
161
  export function buildPlayRunStartBody(
110
162
  request: ResolvedStartPlayRunRequest,
@@ -196,6 +248,8 @@ export async function preparePlayRunAdmission(
196
248
  }) => void | Promise<void>,
197
249
  options?: {
198
250
  signal?: AbortSignal;
251
+ deadlineAt?: number;
252
+ callerIntentV2?: boolean;
199
253
  admissionCapability?:
200
254
  | Promise<PlayRunAdmissionCapability>
201
255
  | PlayRunAdmissionCapability;
@@ -205,17 +259,39 @@ export async function preparePlayRunAdmission(
205
259
  workflowId?: string;
206
260
  supportsCallerIntent: boolean;
207
261
  }> {
262
+ const assertAdmissionActive = () => {
263
+ options?.signal?.throwIfAborted();
264
+ if (options?.deadlineAt !== undefined && Date.now() >= options.deadlineAt) {
265
+ const error = new Error('Play admission exceeded its wait deadline.');
266
+ error.name = 'AbortError';
267
+ throw error;
268
+ }
269
+ };
270
+ const callerIntentV2 = options?.callerIntentV2 === true;
271
+ if (
272
+ callerIntentV2 &&
273
+ (onSubmission || request.maxTotalCredits !== undefined)
274
+ ) {
275
+ throw new DeeplineError(
276
+ 'Versioned CLI Play admission requires a new, unjournaled run without a strict total budget.',
277
+ 409,
278
+ 'CLI_PLAY_CALLER_INTENT_V2_INELIGIBLE',
279
+ );
280
+ }
208
281
  // The reader ships before the writer. An older route ignores workflowId;
209
282
  // that response cannot prove an identity can be reused safely after a timeout.
210
- const capability =
211
- options && Object.hasOwn(options, 'admissionCapability')
212
- ? await options.admissionCapability
283
+ assertAdmissionActive();
284
+ const capability = callerIntentV2
285
+ ? null
286
+ : options && Object.hasOwn(options, 'admissionCapability')
287
+ ? await awaitWithAbort(options.admissionCapability, options.signal)
213
288
  : await readPlayRunAdmissionCapability(http, options);
214
289
  const supportsCallerIntent =
215
- capability?.admissionContract === 'caller-intent-v1';
216
- options?.signal?.throwIfAborted();
290
+ callerIntentV2 || capability?.admissionContract === 'caller-intent-v1';
291
+ assertAdmissionActive();
217
292
  if (
218
293
  supportsCallerIntent &&
294
+ !callerIntentV2 &&
219
295
  (!capability?.orgId ||
220
296
  (request.admissionOrgId && request.admissionOrgId !== capability.orgId))
221
297
  ) {
@@ -265,7 +341,9 @@ export async function preparePlayRunAdmission(
265
341
  JSON.stringify(
266
342
  buildPlayRunStartBody({
267
343
  ...request,
268
- ...(supportsCallerIntent ? { admissionOrgId: capability!.orgId } : {}),
344
+ ...(supportsCallerIntent && !callerIntentV2
345
+ ? { admissionOrgId: capability!.orgId }
346
+ : {}),
269
347
  }),
270
348
  ),
271
349
  ) as Record<string, unknown>;
@@ -292,6 +370,9 @@ export async function preparePlayRunAdmission(
292
370
  'PLAY_RUN_ADMISSION_RECOVERY_UNSUPPORTED',
293
371
  );
294
372
  }
373
+ // A slow capability read must not persist a recoverable intent after the
374
+ // caller's wait deadline has already elapsed.
375
+ assertAdmissionActive();
295
376
  await onSubmission({
296
377
  workflowId,
297
378
  orgId: capability.orgId,
@@ -355,29 +436,70 @@ export async function startPlayRun(
355
436
  options?.onSubmission,
356
437
  options,
357
438
  );
439
+ return submitPreparedPlayRunAdmission(
440
+ http,
441
+ submittedBody,
442
+ workflowId,
443
+ supportsCallerIntent,
444
+ headers,
445
+ options,
446
+ );
447
+ }
448
+
449
+ /** Submit a body prepared once, so an ambiguous retry can keep its identity. */
450
+ export async function submitPreparedPlayRunAdmission(
451
+ http: PlayRunHttp,
452
+ submittedBody: Record<string, unknown>,
453
+ workflowId: string | undefined,
454
+ supportsCallerIntent: boolean,
455
+ headers?: Record<string, string>,
456
+ options?: Pick<
457
+ PlayRunStartOptions,
458
+ 'cliAdmission' | 'callerIntentV2' | 'signal'
459
+ >,
460
+ ): Promise<PlayRunStart> {
358
461
  let cliAdmissionSupported = false;
462
+ let callerIntentV2Supported = false;
359
463
  let response: Record<string, unknown>;
360
464
  try {
361
465
  response = await http.post<Record<string, unknown>>(
362
- options?.cliAdmission ? CLI_PLAY_RUN_START_PATH : PLAY_RUN_START_PATH,
466
+ options?.callerIntentV2
467
+ ? CLI_PLAY_RUN_CALLER_INTENT_V2_PATH
468
+ : options?.cliAdmission
469
+ ? CLI_PLAY_RUN_START_PATH
470
+ : PLAY_RUN_START_PATH,
363
471
  submittedBody,
364
472
  headers,
365
473
  {
366
474
  maxRetries: 0,
367
475
  exactUrlOnly: true,
368
476
  ...(options?.signal ? { signal: options.signal } : {}),
369
- ...(options?.cliAdmission
477
+ ...(options?.cliAdmission || options?.callerIntentV2
370
478
  ? {
371
479
  onResponse: (response: Response) => {
372
480
  cliAdmissionSupported =
373
481
  response.headers.get(CLI_PLAY_RUN_SUPPORTED_HEADER) ===
374
482
  'true';
483
+ callerIntentV2Supported =
484
+ response.headers.get(
485
+ CLI_PLAY_RUN_CALLER_INTENT_V2_SUPPORTED_HEADER,
486
+ ) === 'true';
375
487
  },
376
488
  }
377
489
  : {}),
378
490
  },
379
491
  );
380
492
  } catch (error) {
493
+ if (
494
+ options?.callerIntentV2 &&
495
+ !callerIntentV2Supported &&
496
+ error instanceof DeeplineError &&
497
+ (error.statusCode === 404 || error.statusCode === 405)
498
+ ) {
499
+ throw new CliPlayAdmissionCallerIntentV2UnsupportedError(
500
+ error.statusCode,
501
+ );
502
+ }
381
503
  if (
382
504
  options?.cliAdmission &&
383
505
  !cliAdmissionSupported &&
@@ -419,6 +541,18 @@ export async function startPlayRun(
419
541
  }
420
542
  throw error;
421
543
  }
544
+ if (options?.callerIntentV2 && !callerIntentV2Supported) {
545
+ throw new DeeplineError(
546
+ 'The versioned CLI Play admission response did not prove its contract. Inspect this run before submitting again.',
547
+ undefined,
548
+ 'PLAY_RUN_ADMISSION_CONTRACT_UNKNOWN',
549
+ {
550
+ ...(workflowId ? { runId: workflowId, workflowId } : {}),
551
+ admissionState: 'unknown',
552
+ recoverySupported: supportsCallerIntent,
553
+ },
554
+ );
555
+ }
422
556
  const started = normalizePlayRunStart(response);
423
557
  if (
424
558
  options?.cliAdmission &&
@@ -205,7 +205,7 @@ export const SDK_RELEASE = {
205
205
  // getters keep their established compatibility behavior.
206
206
  // 0.3.1 deprecated the legacy `deepline enrich` command in favor of Plays.
207
207
  // 0.3.90 is the first deliberately versioned SDK release for API v3.
208
- version: '0.3.484',
208
+ version: '0.3.486',
209
209
  updateSummary: {
210
210
  introducedIn: '0.3.90',
211
211
  summary:
@@ -11,8 +11,11 @@ import { isTransientPlayRunReadError } from './read-errors';
11
11
 
12
12
  /** Steady-state cadence for the small authenticated REST snapshot. */
13
13
  export const RUN_WATCH_POLL_INTERVAL_MS = 2_000;
14
- const RUN_WATCH_STARTUP_POLL_INTERVAL_MS = 500;
14
+ // Keep terminal detection responsive during short Plays; long runs use the
15
+ // two-second steady-state cadence below.
16
+ const RUN_WATCH_STARTUP_POLL_INTERVAL_MS = 300;
15
17
  const RUN_WATCH_STARTUP_WINDOW_MS = 6_000;
18
+ export const TERMINAL_LOG_PROJECTION_RETRY_LIMIT = 3;
16
19
 
17
20
  type WatchHttp = {
18
21
  get<T = unknown>(
@@ -207,13 +210,13 @@ export async function* watchRunEvents(
207
210
  let consecutiveFailures = 0;
208
211
  let outageNoticeSent = false;
209
212
  let pollCount = 0;
213
+ let terminalLogProjectionRetries = 0;
210
214
 
211
215
  while (!signal?.aborted) {
212
216
  const pollStartedAt = Date.now();
213
217
  const poll = ++pollCount;
214
- // Keep a moderate cadence through the sandbox startup window. This halves
215
- // short-run snapshot reads while avoiding a two-second detection gap just
216
- // after Daytona finishes starting a fresh sandbox.
218
+ // Keep terminal detection responsive through the sandbox startup window,
219
+ // then reduce snapshot reads for runs that continue beyond it.
217
220
  const pollIntervalMs =
218
221
  options.pollIntervalMs ??
219
222
  (pollStartedAt - watchStartedAt < RUN_WATCH_STARTUP_WINDOW_MS
@@ -301,6 +304,30 @@ export async function* watchRunEvents(
301
304
  }
302
305
  consecutiveFailures = 0;
303
306
 
307
+ // Lifecycle and canonical log projections advance independently. Retry the
308
+ // terminal log projection briefly, then let authoritative terminal status
309
+ // close the watcher with logsUnavailable still visible on the snapshot.
310
+ const terminalLogsPending =
311
+ isTerminalPlayRunLiveStatus(snapshot.status) &&
312
+ snapshot.logsUnavailable &&
313
+ !options.omitTerminalLogs;
314
+ if (terminalLogsPending) {
315
+ if (terminalLogProjectionRetries < TERMINAL_LOG_PROJECTION_RETRY_LIMIT) {
316
+ terminalLogProjectionRetries += 1;
317
+ const remaining = Math.max(
318
+ 0,
319
+ pollIntervalMs - (Date.now() - pollStartedAt),
320
+ );
321
+ if (!(await waitForNextPoll(remaining, signal))) return;
322
+ continue;
323
+ }
324
+ options.onNotice?.(
325
+ `[watch] terminal status is complete, but final logs are unavailable in this watch; fetch retained logs with deepline runs logs ${runId}`,
326
+ );
327
+ } else {
328
+ terminalLogProjectionRetries = 0;
329
+ }
330
+
304
331
  // Give the consumer the same durable status it would otherwise fetch
305
332
  // before emitting terminal events that cause that serial HTTP request.
306
333
  if (terminalStatus) {
@@ -161,7 +161,7 @@ export type ExecuteToolRawOptions = {
161
161
  export type ExecutionRecovery = {
162
162
  /** Stable caller key used to resume or replay this execution. */
163
163
  idempotencyKey: string;
164
- /** Whether the execution is still running, completed, or has an unknown provider outcome. */
164
+ /** State of the provider execution and its durable receipt. */
165
165
  state: 'running' | 'completed' | 'outcome_unknown';
166
166
  /** Whether this response came from an existing durable execution. */
167
167
  replayed: boolean;
@@ -193,7 +193,13 @@ export interface ToolPricingSummary {
193
193
  * Largest single charge any call to this tool settled in the trailing
194
194
  * window. A recorded worst case, not a rate, quote, or ceiling.
195
195
  */
196
- observedMax?: { creditsPerCall: number; windowDays: number };
196
+ observedMax?: {
197
+ creditsPerCall: number;
198
+ windowDays: number;
199
+ /** Mean charge and the number of charges it covers, when counted. */
200
+ avgCreditsPerCall?: number;
201
+ sampleCount?: number;
202
+ };
197
203
  }
198
204
 
199
205
  /** A discoverable provider, returned by {@link DeeplineClient.listProviders}. */
@@ -174,18 +174,35 @@ export const RuntimeSheetColumns = {
174
174
  input: SheetIdentity & {
175
175
  rows:
176
176
  | readonly Record<string, unknown>[]
177
- | (() => Promise<readonly Record<string, unknown>[]>);
177
+ | ((
178
+ inferableFields: readonly string[],
179
+ ) => Promise<readonly Record<string, unknown>[]>);
178
180
  columns: readonly PhysicalSheetColumnProjection[];
179
181
  /** Opt in only when the caller can roll back and restart the whole transaction. */
180
182
  lockMode?: WriteLockMode;
181
183
  },
182
184
  ): Promise<RuntimeSheetColumnTypes> {
183
185
  await lock(client, input, input.lockMode);
184
- const rows =
185
- typeof input.rows === 'function' ? await input.rows() : input.rows;
186
186
  const columns = new Map(
187
187
  (await inspect(client, input)).map((column) => [column.name, column]),
188
188
  );
189
+ const inferableFields = [
190
+ ...new Set(
191
+ input.columns.flatMap((projection) => {
192
+ const column = columns.get(projection.sqlName);
193
+ return column?.marker === UNDECIDED || column?.marker === NATIVE
194
+ ? [projection.fieldName]
195
+ : [];
196
+ }),
197
+ ),
198
+ ];
199
+ // Always evaluate accepted rows, including when no fields need inference.
200
+ // The Adapter owns the acceptance predicate and may lock those rows; its
201
+ // row count also determines whether missing columns must fail loudly.
202
+ const rows =
203
+ typeof input.rows === 'function'
204
+ ? await input.rows(inferableFields)
205
+ : input.rows;
189
206
  for (const projection of rows.length > 0 ? input.columns : []) {
190
207
  const column = columns.get(projection.sqlName);
191
208
  if (!column)
@@ -262,6 +279,18 @@ export const RuntimeSheetColumns = {
262
279
  );
263
280
  },
264
281
 
282
+ /** Project inference inputs without changing accepted-row cardinality. */
283
+ jsonTypeEvidenceSql(input: {
284
+ jsonExpression: string;
285
+ fieldsExpression: string;
286
+ }): string {
287
+ return `COALESCE((
288
+ SELECT jsonb_object_agg(column_type_fields.field, (${input.jsonExpression}) -> column_type_fields.field)
289
+ FROM unnest(${input.fieldsExpression}) AS column_type_fields(field)
290
+ WHERE (${input.jsonExpression}) ? column_type_fields.field
291
+ ), '{}'::jsonb)`;
292
+ },
293
+
265
294
  jsonValueSql(
266
295
  jsonExpression: string,
267
296
  tableReference: string,