deepline 0.3.422 → 0.3.423

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 (148) hide show
  1. package/dist/bundling-sources/sdk/src/client.ts +2 -2
  2. package/dist/bundling-sources/sdk/src/index.ts +2 -0
  3. package/dist/bundling-sources/sdk/src/play.ts +227 -184
  4. package/dist/bundling-sources/sdk/src/plays/local-file-discovery.ts +9 -2
  5. package/dist/bundling-sources/sdk/src/plays/local-play-execution.ts +1 -1
  6. package/dist/bundling-sources/sdk/src/release.ts +1 -1
  7. package/dist/bundling-sources/sdk/src/tool-calls.ts +3 -1
  8. package/dist/bundling-sources/sdk/src/types.ts +5 -5
  9. package/dist/bundling-sources/shared_libs/plays/authoring-contract.ts +37 -36
  10. package/dist/bundling-sources/shared_libs/plays/bundling/index.ts +179 -38
  11. package/dist/bundling-sources/shared_libs/plays/dataset.ts +2 -2
  12. package/dist/bundling-sources/shared_libs/plays/docflow.ts +4 -0
  13. package/dist/bundling-sources/shared_libs/plays/fetch-http-error.ts +1 -1
  14. package/dist/bundling-sources/shared_libs/plays/local-file-discovery.ts +12 -4
  15. package/dist/bundling-sources/shared_libs/plays/play-exports.ts +27 -5
  16. package/dist/bundling-sources/shared_libs/plays/script-entry.ts +992 -0
  17. package/dist/bundling-sources/shared_libs/plays/source-authoring-edition.ts +63 -0
  18. package/dist/bundling-sources/shared_libs/plays/tool-result-types.ts +8 -4
  19. package/dist/bundling-sources/shared_libs/plays/ts-ast.ts +2 -0
  20. package/dist/cli/{auth-DMLBSXLV.mjs → auth-L7Q53QKK.mjs} +4 -4
  21. package/dist/cli/auth-SUNY477Y.js +40 -0
  22. package/dist/cli/{billing-SEXKROBQ.mjs → billing-IH7AKDR2.mjs} +4 -4
  23. package/dist/cli/{billing-IFGFPGJV.js → billing-QNP6YGI2.js} +73 -73
  24. package/dist/cli/{chunk-AARWVK4C.mjs → chunk-2BQUML3X.mjs} +792 -69
  25. package/dist/cli/{chunk-WP7T4BPE.js → chunk-2F5ULM2F.js} +1 -1
  26. package/dist/cli/{chunk-BL3LY54Y.js → chunk-2U3AMRHF.js} +8 -8
  27. package/dist/cli/{chunk-ERFN2QY4.mjs → chunk-3DNKFH2G.mjs} +1 -1
  28. package/dist/cli/{chunk-SDCIROIS.mjs → chunk-44US3EL2.mjs} +5 -5
  29. package/dist/cli/{chunk-S4KGXRCV.js → chunk-4WT5RISA.js} +20 -20
  30. package/dist/cli/{chunk-JRSULUPQ.js → chunk-5DGR3TB6.js} +2 -2
  31. package/dist/cli/{chunk-2JKQORUX.mjs → chunk-6FFORGD2.mjs} +2 -2
  32. package/dist/cli/{chunk-QNBHQM5R.mjs → chunk-ARTGL3FM.mjs} +1 -1
  33. package/dist/cli/{chunk-WGO2DY4L.js → chunk-AVOBDFQ5.js} +11 -11
  34. package/dist/cli/{chunk-V4RAH5D6.js → chunk-DRK6FYJU.js} +26 -26
  35. package/dist/cli/{chunk-63ILLN5H.mjs → chunk-DS7Y7X26.mjs} +2 -2
  36. package/dist/cli/{chunk-CTNA5QY2.mjs → chunk-EER67G2B.mjs} +43 -28
  37. package/dist/cli/{chunk-AYM2KZN3.js → chunk-EWWWOKX2.js} +6 -6
  38. package/dist/cli/{chunk-MLP4CAY7.mjs → chunk-FJRFSBWO.mjs} +4 -4
  39. package/dist/cli/{chunk-27GJKC5Q.js → chunk-GXOQRZXG.js} +2 -2
  40. package/dist/cli/{chunk-CO3VMH33.mjs → chunk-H662SHPT.mjs} +28 -27
  41. package/dist/cli/{chunk-PKBPSMOT.js → chunk-INFLI36H.js} +43 -28
  42. package/dist/cli/{chunk-FEKJENBB.mjs → chunk-IW5QK3K6.mjs} +3 -3
  43. package/dist/cli/{chunk-VT6WJ26Y.mjs → chunk-JDAXVQV7.mjs} +1 -1
  44. package/dist/cli/{chunk-4PG4ARL2.mjs → chunk-KPKU53YO.mjs} +1 -1
  45. package/dist/cli/{chunk-IMZ56EOH.mjs → chunk-LXTSVUZN.mjs} +2 -2
  46. package/dist/cli/{chunk-KXPIFC5S.mjs → chunk-MHG3NND4.mjs} +3 -3
  47. package/dist/cli/{chunk-IHG7UAHD.mjs → chunk-MLJBCS3E.mjs} +32 -13
  48. package/dist/cli/{chunk-LXRDHISW.js → chunk-MMI2DXCW.js} +8 -8
  49. package/dist/cli/{chunk-K4X472AT.js → chunk-NA6SGG7X.js} +260 -259
  50. package/dist/cli/{chunk-M6SXXFMT.mjs → chunk-NFIZ5YED.mjs} +2 -2
  51. package/dist/cli/{chunk-OZHPZCAU.js → chunk-OMWO2JLC.js} +52 -52
  52. package/dist/cli/{chunk-TP26TAAF.mjs → chunk-OPI7UCQG.mjs} +1 -1
  53. package/dist/cli/{chunk-UQQRMCOL.js → chunk-OZLMMMZH.js} +6 -6
  54. package/dist/cli/{chunk-W74RDGRL.mjs → chunk-PH4BP6KM.mjs} +2 -2
  55. package/dist/cli/{chunk-4EV2FKBI.js → chunk-PQ4G6MKI.js} +16 -16
  56. package/dist/cli/{chunk-3CE3WGKP.mjs → chunk-QN6DG4JO.mjs} +2 -2
  57. package/dist/cli/{chunk-4CAVSRQH.mjs → chunk-QWJJMQNE.mjs} +1 -1
  58. package/dist/cli/{chunk-GEJDBXXM.js → chunk-QWRHGGUH.js} +1 -1
  59. package/dist/cli/{chunk-AD47BXN2.js → chunk-R2QWSSAG.js} +8 -8
  60. package/dist/cli/{chunk-2LVM22ZU.js → chunk-RAL75ND3.js} +2 -2
  61. package/dist/cli/{chunk-QADCFSGH.js → chunk-RDIN3NKA.js} +17 -17
  62. package/dist/cli/{chunk-AXDEH2AM.mjs → chunk-S6KG7JCR.mjs} +2 -2
  63. package/dist/cli/{chunk-BQR6UN3C.js → chunk-VUYUI35Q.js} +32 -13
  64. package/dist/cli/{chunk-HCYNAIHZ.js → chunk-W42SSVM7.js} +4 -4
  65. package/dist/cli/{chunk-VRI3ABTK.js → chunk-WJO7KIFT.js} +50 -50
  66. package/dist/cli/{chunk-PXO253DP.mjs → chunk-XSERB7H2.mjs} +1 -1
  67. package/dist/cli/{chunk-KBJP3UAU.js → chunk-YCHR57TD.js} +35 -35
  68. package/dist/cli/{chunk-OQQOXSYA.js → chunk-YHRS6XTB.js} +845 -122
  69. package/dist/cli/{chunk-7OJEYJ6G.mjs → chunk-YNT7PJND.mjs} +3 -3
  70. package/dist/cli/command-docs.js +2 -2
  71. package/dist/cli/command-docs.mjs +1 -1
  72. package/dist/cli/{csv-J7UVP4KB.mjs → csv-5KW7M6ZS.mjs} +3 -3
  73. package/dist/cli/{csv-Y4YWZSLB.js → csv-GF7VRES5.js} +12 -12
  74. package/dist/cli/{db-SVFCM6YZ.js → db-AEDXKB4F.js} +26 -26
  75. package/dist/cli/{db-CQ6NHMLG.mjs → db-NN4JQAC4.mjs} +5 -5
  76. package/dist/cli/{describe-FSDW6LTN.js → describe-5RLXW332.js} +24 -24
  77. package/dist/cli/{describe-Y65BU7ZY.mjs → describe-RX6VROHQ.mjs} +16 -16
  78. package/dist/cli/describe-core.d.mts +2 -2
  79. package/dist/cli/describe-core.d.ts +2 -2
  80. package/dist/cli/describe-core.js +4 -4
  81. package/dist/cli/describe-core.mjs +3 -3
  82. package/dist/cli/{executions-IW762OIJ.mjs → executions-EJZ34VUB.mjs} +4 -4
  83. package/dist/cli/{executions-SJIKBRHT.js → executions-PGIGFDDS.js} +6 -6
  84. package/dist/cli/{feedback-VMJIWAMT.mjs → feedback-6MWOKE7H.mjs} +3 -3
  85. package/dist/cli/{feedback-RCYSUOB3.js → feedback-L2ODMANV.js} +7 -7
  86. package/dist/cli/git-2ZDCRTBD.js +24 -0
  87. package/dist/cli/{git-Q2WY3K6X.mjs → git-456RF3AT.mjs} +4 -4
  88. package/dist/cli/index.js +135 -135
  89. package/dist/cli/index.mjs +37 -37
  90. package/dist/cli/{legacy-noops-U4YPPYXU.js → legacy-noops-MDPB3MIS.js} +7 -7
  91. package/dist/cli/{legacy-noops-JVEE2VHK.mjs → legacy-noops-ZPRBXQDE.mjs} +4 -4
  92. package/dist/cli/{monitors-BMAOQ37R.js → monitors-TXKR5XYW.js} +86 -86
  93. package/dist/cli/{monitors-AY4KQRTC.mjs → monitors-ZLP6A7FT.mjs} +6 -6
  94. package/dist/cli/{org-G5IURX74.js → org-73SQ3AT2.js} +64 -64
  95. package/dist/cli/{org-ME4X6HWH.mjs → org-YZ62BIGM.mjs} +4 -4
  96. package/dist/cli/{play-X5GSZOKZ.js → play-M75EBXEV.js} +606 -567
  97. package/dist/cli/{play-WLYU7WQL.mjs → play-VCYQKCKF.mjs} +113 -74
  98. package/dist/cli/{providers-AHEUVD3R.js → providers-GIINJPWQ.js} +7 -7
  99. package/dist/cli/{providers-2LBMNB7B.mjs → providers-JLA6LST3.mjs} +4 -4
  100. package/dist/cli/{quickstart-DBLYGHJP.mjs → quickstart-AHCU75GG.mjs} +3 -3
  101. package/dist/cli/{quickstart-DP2SKLIG.js → quickstart-HHHLYCHT.js} +5 -5
  102. package/dist/cli/{search-YKJHY3ZJ.mjs → search-5GACUIAX.mjs} +5 -5
  103. package/dist/cli/search-W2PGBXQO.js +30 -0
  104. package/dist/cli/{secrets-2P3I3OEZ.js → secrets-PI7IPCOE.js} +13 -13
  105. package/dist/cli/{secrets-ECLARBO6.mjs → secrets-S2NBKAEN.mjs} +4 -4
  106. package/dist/cli/{sessions-MC4ZCTSN.js → sessions-BK4CSRFS.js} +5 -5
  107. package/dist/cli/{sessions-3GDFID7R.mjs → sessions-IBKYGTBD.mjs} +4 -4
  108. package/dist/cli/{settings-7SVR2OVL.js → settings-2G7TUDM7.js} +75 -75
  109. package/dist/cli/{settings-RTPJXMOA.mjs → settings-JY6UN4KO.mjs} +8 -8
  110. package/dist/cli/{setup-OKAZZGAW.mjs → setup-HS5X3OSN.mjs} +7 -7
  111. package/dist/cli/{setup-4WLIJX36.js → setup-R424FIBF.js} +42 -42
  112. package/dist/cli/skills-M3RZAN4A.js +29 -0
  113. package/dist/cli/{skills-2CVL6RG5.mjs → skills-UIBUDTGN.mjs} +5 -5
  114. package/dist/cli/tools-K2GII2PA.js +44 -0
  115. package/dist/cli/{tools-KAFHP6J4.mjs → tools-SB4FREB6.mjs} +15 -15
  116. package/dist/cli/update-C2ORJRXN.js +31 -0
  117. package/dist/cli/{update-3ZV3W7I4.mjs → update-NJSUE2YU.mjs} +7 -7
  118. package/dist/cli/{workflow-GULDFFP3.js → workflow-3AZWZ4J3.js} +19 -19
  119. package/dist/cli/{workflow-DKSUNZXE.mjs → workflow-HBG76XYX.mjs} +9 -9
  120. package/dist/{client-CCWIUnk7.d.mts → client-BTUOYGID.d.mts} +10 -9
  121. package/dist/{client-vHqBm-OL.d.ts → client-C668iUhZ.d.ts} +10 -9
  122. package/dist/{compiler-manifest-lzWpbV3w.d.mts → compiler-manifest-DaFuA1ki.d.mts} +35 -32
  123. package/dist/{compiler-manifest-lzWpbV3w.d.ts → compiler-manifest-DaFuA1ki.d.ts} +35 -32
  124. package/dist/{index-CtNK-0nI.d.mts → index-0yS9ihly.d.mts} +10 -3
  125. package/dist/{index-C8Cy-YTm.d.ts → index-CRAScKPg.d.ts} +10 -3
  126. package/dist/index.d.mts +120 -150
  127. package/dist/index.d.ts +120 -150
  128. package/dist/index.js +77 -12
  129. package/dist/index.mjs +74 -9
  130. package/dist/install-integrity.json +99 -98
  131. package/dist/plays/bundle-play-file.d.mts +3 -3
  132. package/dist/plays/bundle-play-file.d.ts +3 -3
  133. package/dist/plays/bundle-play-file.mjs +1 -1
  134. package/dist/plays/play-description.d.mts +2 -2
  135. package/dist/plays/play-description.d.ts +2 -2
  136. package/dist/plays/run-request.d.mts +2 -2
  137. package/dist/plays/run-request.d.ts +2 -2
  138. package/dist/release.d.mts +1 -1
  139. package/dist/release.d.ts +1 -1
  140. package/dist/release.js +2 -2
  141. package/dist/release.mjs +1 -1
  142. package/package.json +1 -1
  143. package/dist/cli/auth-HD5AM2WM.js +0 -40
  144. package/dist/cli/git-JAW3UEGA.js +0 -24
  145. package/dist/cli/search-4K3VSDS5.js +0 -30
  146. package/dist/cli/skills-ZNSQOXO2.js +0 -29
  147. package/dist/cli/tools-W4U4FT3R.js +0 -44
  148. package/dist/cli/update-IE2FPLB5.js +0 -31
@@ -630,7 +630,7 @@ export type RunsGetOptions = {
630
630
  };
631
631
 
632
632
  export type RunsChildrenOptions = {
633
- /** Required authored `ctx.runPlayAsync` launch key. */
633
+ /** Required authored `deepline.runPlayAsync` launch key. */
634
634
  launchKey: string;
635
635
  /** Opaque cursor returned by the preceding page. */
636
636
  cursor?: string;
@@ -4911,7 +4911,7 @@ export class DeeplineClient {
4911
4911
  /**
4912
4912
  * Export persisted runtime-sheet rows for a play dataset/table namespace.
4913
4913
  *
4914
- * This is the SDK form of exporting `ctx.dataset(...).run()` output for a
4914
+ * This is the SDK form of exporting `deepline.dataset(...).run()` output for a
4915
4915
  * specific play and optional run id.
4916
4916
  */
4917
4917
  async getPlaySheetRows(input: {
@@ -299,6 +299,8 @@ export {
299
299
  readList,
300
300
  steps,
301
301
  } from './play';
302
+ export { deepline as default, deepline, runScriptPlay } from './play';
303
+ export type { ScriptPlayContext } from './play';
302
304
 
303
305
  // ——— Tool output processing ———
304
306
  export {
@@ -8,9 +8,8 @@
8
8
  *
9
9
  * ## Core concepts
10
10
  *
11
- * - **{@link definePlay}** — Define a play as a typed async function. The returned
12
- * value is both callable (for server-side execution) and has methods for
13
- * remote lifecycle management (run, get, publish, tail).
11
+ * - **{@link deepline}** — The play runtime. A play is a `.play.ts` file of
12
+ * top-level code that imports it; see {@link ScriptPlayContext}.
14
13
  *
15
14
  * - **{@link Deepline.connect}** — Create a client context for programmatic SDK
16
15
  * usage. Returns a {@link DeeplineContext} with tool and play handles.
@@ -20,60 +19,39 @@
20
19
  *
21
20
  * ## Usage patterns
22
21
  *
23
- * ### Define and run a play (file-backed)
22
+ * ### Write and run a play
24
23
  *
25
24
  * ```typescript
26
- * // my-play.play.ts
27
- * import { definePlay } from 'deepline';
28
- *
29
- * export default definePlay('my-play', async (ctx, input: { domain: string }) => {
30
- * ctx.log(`Looking up ${input.domain}`);
31
- * const company = await ctx.tools.execute({
25
+ * // lookup.play.ts
26
+ * import deepline from 'deepline';
27
+ *
28
+ * export default async function ({ domain }: { domain: string }) {
29
+ * const company = await deepline.tools.execute({
30
+ * id: 'company',
31
+ * tool: 'company_lookup',
32
+ * input: { domain },
33
+ * description: 'Look up the company.',
32
34
  * staleAfterSeconds: 0,
33
- * id: 'company_search',
34
- * tool: 'test_company_search',
35
- * input: { domain: input.domain },
36
- * description: 'Look up company details by domain.',
37
35
  * });
38
- * return company;
39
- * });
36
+ * return { company };
37
+ * }
40
38
  * ```
41
39
  *
42
- * Then run via the CLI:
43
- * `deepline plays run --file my-play.play.ts`.
44
- * Installed npm CLIs can also run saved or prebuilt plays by name.
40
+ * Run it with `deepline plays run lookup.play.ts --input '{"domain":"stripe.com"}'`.
45
41
  *
46
42
  * ### Programmatic usage
47
43
  *
48
44
  * ```typescript
49
45
  * import { Deepline } from 'deepline';
50
46
  *
51
- * const deepline = await Deepline.connect();
52
- * const job = await deepline.play('my-play').run({ domain: 'stripe.com' });
47
+ * const client = await Deepline.connect();
48
+ * const job = await client.play('lookup').run({ domain: 'stripe.com' });
53
49
  * const result = await job.get(); // Polls until complete
54
50
  * ```
55
51
  *
56
- * ### With bindings (cron, webhook)
57
- *
58
- * ```typescript
59
- * import { definePlay } from 'deepline';
60
- *
61
- * export default definePlay('daily-sync', async (ctx) => {
62
- * const data = await ctx.tools.execute({
63
- * staleAfterSeconds: 0,
64
- * id: 'crm_export',
65
- * tool: 'crm_export',
66
- * input: {},
67
- * description: 'Export CRM records for the daily sync.',
68
- * });
69
- * return data;
70
- * }, {
71
- * cron: { schedule: '0 9 * * *', timezone: 'America/New_York' },
72
- * });
73
- * ```
74
- *
75
52
  * @module
76
53
  */
54
+ import { AsyncLocalStorage } from 'node:async_hooks';
77
55
  import { DeeplineClient } from './client';
78
56
  import { createPlayClient, type PlayClientOperations } from './plays/client';
79
57
  import { DeeplineError } from './errors';
@@ -189,10 +167,13 @@ export type FetchOptions = PlayAuthoringFetchOptions;
189
167
  export type PlayFetchResponse = PlayAuthoringFetchResponse;
190
168
 
191
169
  /**
192
- * Optional Play configuration, including triggers and runtime limits.
170
+ * Optional Play configuration, declared once at the top of the play file as
171
+ * an object literal: `export const config = { ... };`. Settings: `name`
172
+ * (defaults to the file name), `description`, `displayName`, `cron`,
173
+ * `webhook`, `sqlListeners`, `runtime`, `billing`, `compatibility`. It is
174
+ * read without running the play, so its values must be literals.
193
175
  *
194
- * A play can be triggered three ways, declared as the third argument to
195
- * {@link definePlay}:
176
+ * A play can be triggered three ways:
196
177
  * - `webhook` — an inbound HTTP call (with optional legacy HMAC or Standard
197
178
  * Webhooks signature verification).
198
179
  * - `cron` — a schedule.
@@ -201,17 +182,17 @@ export type PlayFetchResponse = PlayAuthoringFetchResponse;
201
182
  * (e.g. run enrichment every time a watched company posts a new job). Each
202
183
  * listener binds to a monitor tool id + one of its output stream keys (see
203
184
  * `deepline monitors available <id>` for a tool's streams and row columns).
204
- * The changed row is delivered to the handler as the listener event's `after`.
185
+ * The changed row is delivered as the listener event's `after` in the play function's input.
205
186
  *
206
187
  * The default Play runtime is 30 minutes. For bounded long-running batches, add
207
188
  * `runtime: { timeout: '90m', size: 'standard' }`; duration values are whole minutes or hours, up to `4h`.
208
- * It differs from `ctx.tools.execute({ timeoutMs })`, which limits one provider call.
189
+ * It differs from `deepline.tools.execute({ timeoutMs })`, which limits one provider call.
209
190
  *
210
191
  * @example Webhook with HMAC verification. `secretEnv` is the Deepline Secret
211
192
  * name configured with `deepline secrets set`, retained as the legacy field
212
193
  * name for SDK compatibility.
213
194
  * ```typescript
214
- * definePlay('webhook-handler', handler, {
195
+ * export const config = {
215
196
  * webhook: {
216
197
  * hmac: {
217
198
  * algorithm: 'sha256',
@@ -221,12 +202,12 @@ export type PlayFetchResponse = PlayAuthoringFetchResponse;
221
202
  * secretEnv: 'WEBHOOK_SECRET',
222
203
  * },
223
204
  * },
224
- * });
205
+ * };
225
206
  * ```
226
207
  *
227
208
  * @example Svix / Standard Webhooks verification with Deepline Secrets
228
209
  * ```typescript
229
- * definePlay('visitor-webhook', handler, {
210
+ * export const config = {
230
211
  * webhook: {
231
212
  * auth: {
232
213
  * type: 'standard-webhooks',
@@ -234,19 +215,17 @@ export type PlayFetchResponse = PlayAuthoringFetchResponse;
234
215
  * signingSecrets: ['VECTOR_WEBHOOK_SECRET'],
235
216
  * },
236
217
  * },
237
- * });
218
+ * };
238
219
  * ```
239
220
  *
240
221
  * @example Cron schedule
241
222
  * ```typescript
242
- * definePlay('nightly-sync', handler, {
243
- * cron: { schedule: '0 2 * * *', timezone: 'UTC' },
244
- * });
223
+ * export const config = { cron: { schedule: '0 2 * * *', timezone: 'UTC' } };
245
224
  * ```
246
225
  *
247
226
  * @example Monitor-triggered (run a play on a monitor's output)
248
227
  * ```typescript
249
- * definePlay('on-new-job-opening', handler, {
228
+ * export const config = {
250
229
  * sqlListeners: [
251
230
  * {
252
231
  * id: 'jobs',
@@ -255,10 +234,10 @@ export type PlayFetchResponse = PlayAuthoringFetchResponse;
255
234
  * operations: ['INSERT'],
256
235
  * },
257
236
  * ],
258
- * });
237
+ * };
259
238
  * ```
260
239
  *
261
- * @sdkReference runtime 030
240
+ * @sdkReference runtime 006 export const config
262
241
  */
263
242
  export type PlayBindings<TInput = Record<string, unknown>> =
264
243
  PlayAuthoringBindings<TInput>;
@@ -270,7 +249,7 @@ export type SqlListenerDeclaration = PlaySqlListenerDeclaration;
270
249
  export type SqlListenerEvent<T extends object = Record<string, unknown>> =
271
250
  PlaySqlListenerEvent<T>;
272
251
 
273
- /** @deprecated Pass a SQL string directly to ctx.customerDb.query. */
252
+ /** @deprecated Pass a SQL string directly to deepline.customerDb.query. */
274
253
  export type SqlQuery = PlaySqlQuery;
275
254
  export type SecretHandle = PlaySecretHandle;
276
255
  export type SecretPromise = PlaySecretPromise;
@@ -311,7 +290,7 @@ export type {
311
290
  export type { PreviousCell } from '../../shared_libs/plays/cell-staleness.js';
312
291
 
313
292
  /**
314
- * Keyword-style request object for `ctx.tools.execute(...)`.
293
+ * Keyword-style request object for `deepline.tools.execute(...)`.
315
294
  *
316
295
  * The `tool` value comes from live tool discovery. The `id` is the stable
317
296
  * logical call name used for logs, metadata, and result-cache identity. Provider
@@ -397,7 +376,7 @@ export type RunnableStepProgram<TInput, TOutput> = Pick<
397
376
  > & { readonly __inputType?: (input: TInput) => void };
398
377
 
399
378
  /**
400
- * Builder returned by `ctx.dataset(...)` for row-level durable columns.
379
+ * Builder returned by `deepline.dataset(...)` for row-level durable columns.
401
380
  *
402
381
  * @sdkReference runtime 070 .dataset(...).withColumn(name, resolver).run(options)
403
382
  */
@@ -438,58 +417,195 @@ export type CsvInput<TRow extends object = Record<string, unknown>> =
438
417
  export type ColumnMap<TRow extends object> = PlayAuthoringColumnMap<TRow>;
439
418
 
440
419
  /**
441
- * Options for loading a staged CSV with `ctx.csv(...)`.
420
+ * Options for loading a staged CSV with `deepline.csv(...)`.
442
421
  *
443
422
  * @sdkReference runtime 050
444
423
  */
445
424
  export type CsvOptions = PlayAuthoringCsvOptions;
446
425
 
447
426
  /**
448
- * Runtime context available inside a play function.
449
- *
450
- * Provides methods for calling tools, processing data, and emitting logs.
451
- * This context is injected by the Temporal worker — you never construct it directly.
427
+ * The play runtime: every member of `deepline` except `config`, `input` and
428
+ * `output`. Use it to type a helper module's parameter; pass `deepline` in.
452
429
  *
453
430
  * @example
454
431
  * ```typescript
455
- * definePlay('example', async (ctx, input: { domain: string; csv: string }) => {
456
- * // Call a tool
457
- * const company = await ctx.tools.execute({
458
- * id: 'company_search',
459
- * tool: 'test_company_search',
432
+ * // enrich.ts
433
+ * import type { DeeplinePlayRuntimeContext } from 'deepline';
434
+ *
435
+ * export function lookUp(deepline: DeeplinePlayRuntimeContext, domain: string) {
436
+ * return deepline.tools.execute({
437
+ * id: 'company',
438
+ * tool: 'company_lookup',
439
+ * input: { domain },
440
+ * description: 'Look up the company.',
441
+ * });
442
+ * }
443
+ * ```
444
+ */
445
+ export type DeeplinePlayRuntimeContext = PlayAuthoringRuntimeContext<'array'>;
446
+
447
+ /**
448
+ * `import deepline from 'deepline'` — the play runtime. A play is a
449
+ * `.play.ts` file that default-exports an async function of its input; the
450
+ * file name is the play name. The parameter's type is the input contract and
451
+ * the returned object is the result. Every
452
+ * runtime call below is `deepline.<name>`, including inside dataset resolvers
453
+ * and step bodies.
454
+ *
455
+ * ```ts
456
+ * import deepline from 'deepline';
457
+ *
458
+ * export default async function (input: { domain: string }) {
459
+ * const company = await deepline.tools.execute({
460
+ * id: 'company',
461
+ * tool: 'company_lookup',
460
462
  * input: { domain: input.domain },
461
- * description: 'Look up company details by domain.',
463
+ * description: 'Look up the company.',
464
+ * staleAfterSeconds: 0,
462
465
  * });
466
+ * return { company };
467
+ * }
468
+ * ```
463
469
  *
464
- * // Fan-out: process items with named columns
465
- * const enriched = await ctx
466
- * .dataset('companies', [{ domain: 'a.com' }, { domain: 'b.com' }])
467
- * .withColumn('company', (row, rowCtx) =>
468
- * rowCtx.tools.execute({
469
- * id: 'company_search',
470
- * tool: 'test_company_search',
471
- * input: { domain: row.domain },
472
- * description: 'Look up company details by domain.',
473
- * }))
474
- * .run({ description: 'Look up company details.' });
475
- *
476
- * // Load CSV data from a submitted play input field.
477
- * const leads = await ctx.csv(input.csv);
478
- *
479
- * // Emit a log line (visible in `play tail`)
480
- * ctx.log(`Loaded ${await leads.count()} leads`);
470
+ * ```bash
471
+ * deepline plays run lookup.play.ts --input '{"domain":"stripe.com"}'
472
+ * deepline plays run -e 'deepline.log("hello"); return { ok: true };'
473
+ * ```
481
474
  *
482
- * // Wait at least one second before continuing.
483
- * await ctx.sleep(1000);
475
+ * Compose with `import child from './child.play'` and
476
+ * `await deepline.runPlay('key', child, input, { description })`, or by name.
477
+ * `deepline` works only in the play file; pass it to helper modules as an
478
+ * argument typed {@link DeeplinePlayRuntimeContext}. The file exports only
479
+ * the play function and, optionally, its `config`.
484
480
  *
485
- * // Access submitted input through the handler's second argument.
486
- * ctx.log(`Running for ${input.domain}`);
481
+ * @sdkReference runtime 005 deepline
482
+ */
483
+ export type ScriptPlayContext = DeeplinePlayRuntimeContext & {
484
+ /** The same settings as `export const config = { ... }`. */
485
+ config(config: PlayBindings & { name?: string }): void;
486
+ /**
487
+ * The run's input. A play function receives it as its parameter instead;
488
+ * this is not called at the top of a play file.
489
+ */
490
+ input<TInput = Record<string, unknown>>(): TInput;
491
+ /**
492
+ * Sets the play's result; deepline calls after it fail. A play function
493
+ * returns its result instead; this is not called at the top of a play file.
494
+ */
495
+ output(result: PlayReturnObject): void;
496
+ };
497
+
498
+ /** The run a script play is executing in: its context, input and result. */
499
+ type ScriptRun = {
500
+ readonly context: DeeplinePlayRuntimeContext;
501
+ readonly input: unknown;
502
+ /** Set by `deepline.output`, the run's last deepline call. */
503
+ result: PlayReturnObject | null;
504
+ };
505
+
506
+ const scriptRuns = new AsyncLocalStorage<ScriptRun>();
507
+
508
+ /**
509
+ * The run whose context a callback the runtime invokes outside the play's
510
+ * async flow belongs to, such as a dataset `key` function called while rows
511
+ * persist. Each play artifact bundles its own SDK and the runner builds an
512
+ * artifact module per run, so it is the last run started outside any run: a
513
+ * nested inline run must not hand the outer run's callbacks its context.
514
+ */
515
+ let latestScriptRun: ScriptRun | null = null;
516
+
517
+ /** The three script calls; every other member is the run's context. */
518
+ const scriptCalls = {
519
+ // Read statically before the run; nothing to do while it executes.
520
+ config: () => () => undefined,
521
+ input: (run: ScriptRun) => () => run.input,
522
+ // Returns the value so an `$output` diagram node observes the result.
523
+ output: (run: ScriptRun) => (result: PlayReturnObject) =>
524
+ (run.result = playResult(result, 'deepline.output(...)')),
525
+ } satisfies Record<string, (run: ScriptRun) => unknown>;
526
+
527
+ /**
528
+ * Runs a play module's body with `deepline` bound to this run. The bundler
529
+ * wraps the module's code, and the dispatch to its default-exported play
530
+ * function, in this call, so the artifact keeps the runner's
531
+ * `(context, input) => result` contract.
487
532
  *
488
- * return { company, enriched };
489
- * });
490
- * ```
533
+ * @internal
491
534
  */
492
- export type DeeplinePlayRuntimeContext = PlayAuthoringRuntimeContext<'array'>;
535
+ export async function runScriptPlay(
536
+ context: DeeplinePlayRuntimeContext,
537
+ input: unknown,
538
+ body: () => Promise<unknown>,
539
+ ): Promise<PlayReturnObject> {
540
+ const run: ScriptRun = { context, input, result: null };
541
+ if (!scriptRuns.getStore()) latestScriptRun = run;
542
+ // The play function's return, or a top-level `return value`, is the
543
+ // result, as `return` is in a definePlay handler; otherwise output set it.
544
+ const returned = await scriptRuns.run(run, body);
545
+ if (returned !== undefined)
546
+ return playResult(returned, "A play's return value");
547
+ return run.result ?? {};
548
+ }
549
+
550
+ /** A play's result is a plain object, from `return` or `deepline.output`. */
551
+ function playResult(value: unknown, source: string): PlayReturnObject {
552
+ const prototype =
553
+ value !== null && typeof value === 'object'
554
+ ? Object.getPrototypeOf(value)
555
+ : undefined;
556
+ if (prototype !== Object.prototype && prototype !== null) {
557
+ throw new Error(
558
+ `${source} must be a plain object, such as { company }; got ${Array.isArray(value) ? 'an array' : value === null ? 'null' : typeof value}.`,
559
+ );
560
+ }
561
+ return value as PlayReturnObject;
562
+ }
563
+
564
+ /**
565
+ * The live play runtime for a script play. Inside a run it is that run's
566
+ * context (bound per async flow, so concurrent rows and steps keep their own
567
+ * scope); anywhere else, using it is a mistake worth a clear error.
568
+ */
569
+ export const deepline: ScriptPlayContext = new Proxy({} as ScriptPlayContext, {
570
+ get(_target, property) {
571
+ if (typeof property !== 'string' || property === 'then') return undefined;
572
+ // Config is read statically; its call does nothing at run time.
573
+ if (property === 'config') return scriptCalls.config();
574
+ const run = scriptRuns.getStore();
575
+ if (!run) {
576
+ if (!latestScriptRun) {
577
+ throw new Error(
578
+ `deepline.${property} is only available while a play runs. Run the file with: deepline plays run <file>.play.ts`,
579
+ );
580
+ }
581
+ if (Object.hasOwn(scriptCalls, property)) {
582
+ throw new Error(
583
+ `deepline.${property}() belongs in the play's own code, not in a callback the runtime calls later.`,
584
+ );
585
+ }
586
+ return contextMember(latestScriptRun.context, property);
587
+ }
588
+ if (run.result !== null) {
589
+ // Code after output still runs; a deepline call there would do work the
590
+ // result no longer reflects. A `return` ends a play early.
591
+ throw new Error(
592
+ `deepline.${property} was called after deepline.output(...). Return the play's result from its function instead: return { ... }.`,
593
+ );
594
+ }
595
+ if (Object.hasOwn(scriptCalls, property)) {
596
+ return scriptCalls[property as keyof typeof scriptCalls](run);
597
+ }
598
+ return contextMember(run.context, property);
599
+ },
600
+ });
601
+
602
+ function contextMember(
603
+ context: DeeplinePlayRuntimeContext,
604
+ property: string,
605
+ ): unknown {
606
+ const value: unknown = Reflect.get(context, property);
607
+ return typeof value === 'function' ? value.bind(context) : value;
608
+ }
493
609
 
494
610
  /**
495
611
  * Handle to a Play execution: inspect status, stream logs, await output, or cancel.
@@ -501,7 +617,8 @@ export type DeeplinePlayRuntimeContext = PlayAuthoringRuntimeContext<'array'>;
501
617
  *
502
618
  * @example
503
619
  * ```typescript
504
- * const job: PlayJob = await ctx.play('my-play').run({ domain: 'stripe.com' });
620
+ * const client = await Deepline.connect();
621
+ * const job: PlayJob = await client.play('my-play').run({ domain: 'stripe.com' });
505
622
  *
506
623
  * // Poll status
507
624
  * const status = await job.status();
@@ -572,8 +689,8 @@ export interface PlayJob<TOutput = unknown> {
572
689
  *
573
690
  * @example
574
691
  * ```typescript
575
- * const ctx = await Deepline.connect();
576
- * const play = ctx.play<{ domain: string }, Company>('company-lookup');
692
+ * const client = await Deepline.connect();
693
+ * const play = client.play<{ domain: string }, Company>('company-lookup');
577
694
  *
578
695
  * // Get play definition
579
696
  * const detail = await play.get();
@@ -659,8 +776,8 @@ export type DeeplineToolCallOptions = Pick<
659
776
  * Tool/provider operations available from a connected {@link DeeplineContext}.
660
777
  *
661
778
  * This namespace is for regular SDK callers outside a play runtime. Inside a
662
- * `definePlay(...)` body, use `ctx.tools.execute({ id, tool, input, ... })`
663
- * so provider calls become durable runtime checkpoints.
779
+ * play, use `deepline.tools.execute({ id, tool, input, ... })` so provider
780
+ * calls become durable runtime checkpoints.
664
781
  *
665
782
  * @sdkReference tools 010 DeeplineContext.tools
666
783
  */
@@ -678,7 +795,7 @@ export type DeeplineToolsNamespace = {
678
795
  /**
679
796
  * Execute a provider-backed tool from a regular SDK process.
680
797
  *
681
- * For durable play code, prefer `ctx.tools.execute(...)` because the play
798
+ * For durable play code, prefer `deepline.tools.execute(...)` because the play
682
799
  * runtime records the call under a stable id.
683
800
  */
684
801
  execute(
@@ -722,7 +839,7 @@ export type PlayReferenceLike<
722
839
  TInput extends Record<string, unknown> = Record<string, unknown>,
723
840
  > = PlayAuthoringReferenceLike<TInput>;
724
841
 
725
- /** Branded durable identity returned by ctx.runPlayAsync. */
842
+ /** Branded durable identity returned by deepline.runPlayAsync. */
726
843
  export type PlayRunId = PlayAuthoringRunId;
727
844
 
728
845
  /** Serializable reference to an independently scheduled Play Run. */
@@ -741,14 +858,9 @@ export type PlayReturnObject = PlayAuthoringReturnObject;
741
858
  export type PlayInputContract<TInput> = PlayAuthoringInputContract<TInput>;
742
859
 
743
860
  /**
744
- * Object-form play definition accepted by `definePlay(config)`.
861
+ * Object-form config accepted by the older `definePlay(config)` form. Files
862
+ * that export `definePlay(...)` keep working; new plays use {@link deepline}.
745
863
  *
746
- * Use this form when the input contract should be explicit at definition time
747
- * through `defineInput<T>(schema)`, or when configuration reads clearer as one
748
- * object. The shorthand `definePlay(name, fn, bindings?)` is equivalent for
749
- * simple file-backed plays.
750
- *
751
- * @sdkReference runtime 020
752
864
  */
753
865
  export type DefinePlayConfig<
754
866
  TInput,
@@ -1150,7 +1262,7 @@ export class DeeplineContext {
1150
1262
  * Play discovery and named-play handles.
1151
1263
  *
1152
1264
  * Use `plays.list()` for discovery and `plays.get(name)` when you prefer a
1153
- * namespace spelling over `ctx.play(name)`.
1265
+ * namespace spelling over `play(name)`.
1154
1266
  */
1155
1267
  get plays(): DeeplinePlaysNamespace {
1156
1268
  return {
@@ -1166,7 +1278,7 @@ export class DeeplineContext {
1166
1278
  *
1167
1279
  * Known prebuilts are exposed by camel-cased aliases. Any other property is
1168
1280
  * converted into `prebuilt/<property>` so callers can pass the reference to
1169
- * `ctx.runPlay(...)`.
1281
+ * `deepline.runPlay(...)` inside a play.
1170
1282
  */
1171
1283
  get prebuilt(): Record<string, PrebuiltPlayRef> {
1172
1284
  const explicit = {
@@ -1217,7 +1329,7 @@ export class DeeplineContext {
1217
1329
  *
1218
1330
  * @example
1219
1331
  * ```typescript
1220
- * const play = ctx.play<{ domain: string }>('email-waterfall');
1332
+ * const play = client.play<{ domain: string }>('email-waterfall');
1221
1333
  * const job = await play.run({ domain: 'stripe.com' });
1222
1334
  * const result = await job.get();
1223
1335
  * ```
@@ -1231,8 +1343,8 @@ export class DeeplineContext {
1231
1343
  /**
1232
1344
  * Run a named or prebuilt play and wait for its output.
1233
1345
  *
1234
- * This is the high-level SDK equivalent of `ctx.play(name).runSync(input)`.
1235
- * Inside a Play, prefer `ctx.runPlay(key, playRef, input, options)`.
1346
+ * This is the high-level SDK equivalent of `client.play(name).runSync(input)`.
1347
+ * Inside a play, use `deepline.runPlay(key, playRef, input, options)`.
1236
1348
  * The runtime checkpoints the child run under a stable key.
1237
1349
  *
1238
1350
  * @param playOrRef - Play name or prebuilt/reference object.
@@ -1641,12 +1753,8 @@ export function defineInput<TInput>(
1641
1753
  }
1642
1754
 
1643
1755
  /**
1644
- * Define a play — a composable TypeScript workflow for the Deepline platform.
1645
- *
1646
- * The returned value is both a callable function and a named Play handle.
1647
- * The Deepline runtime calls the function with a runtime context.
1648
- * The handle provides `.run()`, `.versions()`, `.get()`, and `.publish()` for remote lifecycle operations.
1649
- * Plays define repeatable data pipelines. The runtime executes them durably with automatic retries and timeouts.
1756
+ * The older play form. Files that export `definePlay(...)` keep working; new
1757
+ * plays are scripts that use {@link deepline}.
1650
1758
  *
1651
1759
  * @typeParam TInput - The input type accepted by the play
1652
1760
  * @typeParam TOutput - The return type of the play
@@ -1655,70 +1763,6 @@ export function defineInput<TInput>(
1655
1763
  * @param fn - Play function.
1656
1764
  * @param bindings - Play configuration, including runtime limits and triggers.
1657
1765
  * @returns A {@link DefinedPlay} that is both callable and has lifecycle methods
1658
- *
1659
- * @example Basic play
1660
- * ```typescript
1661
- * import { definePlay } from 'deepline';
1662
- *
1663
- * export default definePlay('company-lookup', async (ctx, input: { domain: string }) => {
1664
- * ctx.log(`Searching for ${input.domain}`);
1665
- * const company = await ctx.tools.execute({
1666
- * id: 'company_search',
1667
- * tool: 'test_company_search',
1668
- * input: { domain: input.domain },
1669
- * description: 'Look up company details by domain.',
1670
- * });
1671
- * return company;
1672
- * });
1673
- * ```
1674
- *
1675
- * @example CSV processing play
1676
- * ```typescript
1677
- * export default definePlay('bulk-enrich', async (ctx, input: { csv: string }) => {
1678
- * const leads = await ctx.csv(input.csv);
1679
- * ctx.log(`Processing ${await leads.count()} rows`);
1680
- * const results = await ctx
1681
- * .dataset('companies', leads)
1682
- * .withColumn('company', (row, ctx) =>
1683
- * ctx.tools.execute({
1684
- * id: 'company_search',
1685
- * tool: 'test_company_search',
1686
- * input: { domain: row.domain },
1687
- * description: 'Look up company details by domain.',
1688
- * }))
1689
- * .run({ description: 'Enrich lead companies.' });
1690
- * return results;
1691
- * });
1692
- * ```
1693
- *
1694
- * @example With cron binding
1695
- * ```typescript
1696
- * export default definePlay('daily-report', async (ctx) => {
1697
- * const data = await ctx.tools.execute({
1698
- * id: 'crm_export',
1699
- * tool: 'crm_export',
1700
- * input: { since: 'yesterday' },
1701
- * description: 'Export yesterday CRM records.',
1702
- * });
1703
- * return data;
1704
- * }, {
1705
- * cron: { schedule: '0 9 * * *', timezone: 'America/New_York' },
1706
- * });
1707
- * ```
1708
- *
1709
- * @example Programmatic lifecycle
1710
- * ```typescript
1711
- * const myPlay = definePlay('my-play', handler);
1712
- *
1713
- * // Get play definition:
1714
- * const detail = await myPlay.get();
1715
- *
1716
- * // Run remotely:
1717
- * const result = await myPlay.runSync({ domain: 'stripe.com' });
1718
- *
1719
- * // Make the current draft live:
1720
- * await myPlay.publish();
1721
- * ```
1722
1766
  */
1723
1767
  export function definePlay<TInput, TOutput extends PlayReturnObject>(
1724
1768
  config: DefinePlayConfig<TInput, TOutput>,
@@ -1752,7 +1796,6 @@ export function definePlay<
1752
1796
  ): DefinedPlay<PlayHandlerInput<THandler>, PlayHandlerOutput<THandler>>;
1753
1797
  /* eslint-enable @typescript-eslint/no-explicit-any */
1754
1798
  /**
1755
- * @sdkReference runtime 010
1756
1799
  */
1757
1800
  export function definePlay<TInput, TOutput extends PlayReturnObject>(
1758
1801
  nameOrConfig: string | DefinePlayConfig<TInput, TOutput>,