deepline 0.1.83 → 0.1.88

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.
@@ -99,6 +99,13 @@ type ExecuteToolRawOptions = {
99
99
  includeToolMetadata?: boolean;
100
100
  };
101
101
 
102
+ /**
103
+ * Standard provider/tool execution envelope returned by low-level SDK calls.
104
+ *
105
+ * `toolResponse.raw` contains the provider result. `extractedValues` and
106
+ * `extractedLists` contain Deepline-normalized getters when the tool exposes
107
+ * them. Billing fields are Deepline-facing and must not expose provider spend.
108
+ */
102
109
  export type ToolExecution<TData = unknown, TMeta = Record<string, unknown>> = {
103
110
  status: string;
104
111
  job_id?: string;
@@ -113,19 +120,23 @@ export type ToolExecution<TData = unknown, TMeta = Record<string, unknown>> = {
113
120
  [key: string]: unknown;
114
121
  };
115
122
 
123
+ /** Filters for `client.runs.list(...)`. */
116
124
  export type RunsListOptions = {
117
125
  play: string;
118
126
  status?: string;
119
127
  };
120
128
 
129
+ /** Streaming options for `client.runs.tail(...)`. */
121
130
  export type RunsTailOptions = {
122
131
  signal?: AbortSignal;
123
132
  };
124
133
 
134
+ /** Log fetch options for `client.runs.logs(...)`. */
125
135
  export type RunsLogsOptions = {
126
136
  limit?: number;
127
137
  };
128
138
 
139
+ /** Persisted log response for one play run. */
129
140
  export type RunsLogsResult = {
130
141
  runId: string;
131
142
  totalCount: number;
@@ -137,6 +148,7 @@ export type RunsLogsResult = {
137
148
  entries: string[];
138
149
  };
139
150
 
151
+ /** One persisted runtime-sheet row returned by `client.runs.exportDatasetRows(...)`. */
140
152
  export type PlaySheetRow = {
141
153
  key?: string;
142
154
  status?: string;
@@ -144,6 +156,7 @@ export type PlaySheetRow = {
144
156
  [key: string]: unknown;
145
157
  };
146
158
 
159
+ /** Runtime-sheet rows and aggregate progress for one dataset/table namespace. */
147
160
  export type PlaySheetRowsResult = {
148
161
  rows: PlaySheetRow[];
149
162
  summary?: {
@@ -175,11 +188,25 @@ export type PlaySecretMetadata = {
175
188
  lastUsedAt?: number;
176
189
  };
177
190
 
191
+ /**
192
+ * Public runs namespace exposed as `client.runs`.
193
+ *
194
+ * This namespace mirrors the canonical `/api/v2/runs` resource family and is
195
+ * the preferred low-level surface for polling, streaming, stopping, reading
196
+ * logs, and exporting durable dataset rows.
197
+ *
198
+ * @sdkReference client 020 client.runs
199
+ */
178
200
  export type RunsNamespace = {
201
+ /** Get current run status by public run id. */
179
202
  get: (runId: string, options?: { full?: boolean }) => Promise<PlayStatus>;
203
+ /** List runs for one play, optionally filtered by status. */
180
204
  list: (options: RunsListOptions) => Promise<PlayRunListItem[]>;
205
+ /** Stream run events and return the latest/terminal run status. */
181
206
  tail: (runId: string, options?: RunsTailOptions) => Promise<PlayStatus>;
207
+ /** Fetch persisted log lines for a run. */
182
208
  logs: (runId: string, options?: RunsLogsOptions) => Promise<RunsLogsResult>;
209
+ /** Export persisted rows for a runtime-sheet dataset/table namespace. */
183
210
  exportDatasetRows: (input: {
184
211
  playName: string;
185
212
  tableNamespace: string;
@@ -187,6 +214,7 @@ export type RunsNamespace = {
187
214
  limit?: number;
188
215
  offset?: number;
189
216
  }) => Promise<PlaySheetRowsResult>;
217
+ /** Stop a running/waiting run. */
190
218
  stop: (
191
219
  runId: string,
192
220
  options?: { reason?: string },
@@ -197,6 +225,27 @@ function isRecord(value: unknown): value is Record<string, unknown> {
197
225
  return Boolean(value && typeof value === 'object' && !Array.isArray(value));
198
226
  }
199
227
 
228
+ function isPrebuiltPlayDescription(
229
+ play: Pick<PlayDescription, 'origin' | 'ownerType'>,
230
+ ): boolean {
231
+ return play.origin === 'prebuilt' || play.ownerType === 'deepline';
232
+ }
233
+
234
+ function preferPrebuiltPlayDescriptions<T extends PlayDescription>(
235
+ plays: T[],
236
+ ): T[] {
237
+ const prebuilt: T[] = [];
238
+ const owned: T[] = [];
239
+ for (const play of plays) {
240
+ if (isPrebuiltPlayDescription(play)) {
241
+ prebuilt.push(play);
242
+ } else {
243
+ owned.push(play);
244
+ }
245
+ }
246
+ return [...prebuilt, ...owned];
247
+ }
248
+
200
249
  function isPlayRunPackage(value: unknown): value is PlayRunPackage {
201
250
  return Boolean(
202
251
  value &&
@@ -433,13 +482,21 @@ function playRunStatusFromState(state: PlayLiveStatusState): PlayStatus {
433
482
  * baseUrl: 'http://localhost:3000',
434
483
  * });
435
484
  * ```
485
+ *
486
+ * @sdkReference client 010
436
487
  */
437
488
  export class DeeplineClient {
438
489
  private readonly http: HttpClient;
439
490
  private readonly config: ResolvedConfig;
491
+ /** Canonical run lifecycle namespace backed by `/api/v2/runs`. */
440
492
  readonly runs: RunsNamespace;
441
493
 
442
494
  /**
495
+ * Create a low-level SDK client.
496
+ *
497
+ * Most callers can omit options and let the SDK resolve auth/config from
498
+ * environment variables and CLI-managed credentials.
499
+ *
443
500
  * @param options - Optional overrides for API key, base URL, timeout, and retries.
444
501
  * @throws {@link ConfigError} if no API key can be resolved from any source.
445
502
  */
@@ -599,6 +656,7 @@ export class DeeplineClient {
599
656
  // Secrets
600
657
  // ——————————————————————————————————————————————————————————
601
658
 
659
+ /** List secret metadata visible to the current workspace. */
602
660
  async listSecrets(): Promise<PlaySecretMetadata[]> {
603
661
  const response = await this.http.get<{ secrets?: PlaySecretMetadata[] }>(
604
662
  '/api/v2/secrets',
@@ -606,6 +664,12 @@ export class DeeplineClient {
606
664
  return Array.isArray(response.secrets) ? response.secrets : [];
607
665
  }
608
666
 
667
+ /**
668
+ * Check whether a named secret exists, is active, and has a stored value.
669
+ *
670
+ * @param name - Secret name. It is normalized to uppercase before lookup.
671
+ * @returns Matching active secret metadata, or `null`.
672
+ */
609
673
  async checkSecret(name: string): Promise<PlaySecretMetadata | null> {
610
674
  const normalized = name.trim().toUpperCase();
611
675
  const secrets = await this.listSecrets();
@@ -742,6 +806,12 @@ export class DeeplineClient {
742
806
  );
743
807
  }
744
808
 
809
+ /**
810
+ * Back-compatible alias for {@link executeTool}.
811
+ *
812
+ * Retained for callers that still use the older raw naming while the response
813
+ * envelope remains the same.
814
+ */
745
815
  async executeToolRaw<TData = unknown, TMeta = Record<string, unknown>>(
746
816
  toolId: string,
747
817
  input: Record<string, unknown>,
@@ -750,6 +820,12 @@ export class DeeplineClient {
750
820
  return this.executeTool<TData, TMeta>(toolId, input, options);
751
821
  }
752
822
 
823
+ /**
824
+ * Run a bounded SQL query against the customer data plane.
825
+ *
826
+ * Use this from trusted backend or agent contexts only. The API enforces
827
+ * workspace scoping and row limits.
828
+ */
753
829
  async queryCustomerDb(input: {
754
830
  sql: string;
755
831
  maxRows?: number;
@@ -843,6 +919,17 @@ export class DeeplineClient {
843
919
  return normalizePlayRunStart(response);
844
920
  }
845
921
 
922
+ /**
923
+ * Start a play run and stream live runtime events from the same request.
924
+ *
925
+ * Use this when a caller wants low-level event handling instead of submitting
926
+ * first and then connecting to `streamPlayRunEvents(runId)`.
927
+ *
928
+ * @param request - Play run configuration.
929
+ * @param options - Optional streaming options.
930
+ * @param options.signal - Optional abort signal for the streaming request.
931
+ * @returns Async stream of play-scoped live events.
932
+ */
846
933
  async *startPlayRunStream(
847
934
  request: StartPlayRunRequest,
848
935
  options?: { signal?: AbortSignal },
@@ -940,6 +1027,12 @@ export class DeeplineClient {
940
1027
  });
941
1028
  }
942
1029
 
1030
+ /**
1031
+ * Register multiple bundled play artifacts in one request.
1032
+ *
1033
+ * Used by packaging and prebuilt publication flows. Each artifact is compiled
1034
+ * first when a compiler manifest is not already supplied.
1035
+ */
943
1036
  async registerPlayArtifacts(
944
1037
  artifacts: Array<{
945
1038
  name: string;
@@ -986,6 +1079,13 @@ export class DeeplineClient {
986
1079
  });
987
1080
  }
988
1081
 
1082
+ /**
1083
+ * Compile a bundled play artifact into the server-side compiler manifest.
1084
+ *
1085
+ * The manifest records imports, trigger bindings, static pipeline shape, and
1086
+ * runtime metadata needed before a play artifact can be checked, registered,
1087
+ * or run.
1088
+ */
989
1089
  async compilePlayManifest(input: {
990
1090
  name: string;
991
1091
  sourceCode: string;
@@ -1029,6 +1129,12 @@ export class DeeplineClient {
1029
1129
  return this.http.post('/api/v2/plays/check', input);
1030
1130
  }
1031
1131
 
1132
+ /**
1133
+ * Compile legacy enrich command arguments into a runtime plan.
1134
+ *
1135
+ * This is primarily used by CLI compatibility paths that translate older
1136
+ * enrichment commands onto the play runtime.
1137
+ */
1032
1138
  async compileEnrichPlan(input: {
1033
1139
  plan_args?: string[];
1034
1140
  config?: unknown;
@@ -1036,6 +1142,12 @@ export class DeeplineClient {
1036
1142
  return this.http.post('/api/v2/enrich/compile', input);
1037
1143
  }
1038
1144
 
1145
+ /**
1146
+ * Register an already-bundled play artifact and start a run from it.
1147
+ *
1148
+ * This is the low-level file-backed run path used by SDK/CLI packaging
1149
+ * wrappers after local bundling has produced the runtime artifact.
1150
+ */
1039
1151
  async startPlayRunFromBundle(input: {
1040
1152
  name: string;
1041
1153
  sourceCode: string;
@@ -1247,6 +1359,12 @@ export class DeeplineClient {
1247
1359
  return response.files;
1248
1360
  }
1249
1361
 
1362
+ /**
1363
+ * Resolve staged play files by content hash without uploading bytes.
1364
+ *
1365
+ * Missing files are returned so callers can upload only the files the server
1366
+ * does not already have.
1367
+ */
1250
1368
  async resolveStagedPlayFiles(
1251
1369
  files: Array<{
1252
1370
  logicalPath: string;
@@ -1513,6 +1631,12 @@ export class DeeplineClient {
1513
1631
  };
1514
1632
  }
1515
1633
 
1634
+ /**
1635
+ * Export persisted runtime-sheet rows for a play dataset/table namespace.
1636
+ *
1637
+ * This is the SDK form of exporting `ctx.dataset(...).run()` output for a
1638
+ * specific play and optional run id.
1639
+ */
1516
1640
  async getPlaySheetRows(input: {
1517
1641
  playName: string;
1518
1642
  tableNamespace: string;
@@ -1552,6 +1676,12 @@ export class DeeplineClient {
1552
1676
  );
1553
1677
  }
1554
1678
 
1679
+ /**
1680
+ * List callable plays visible to the workspace.
1681
+ *
1682
+ * Pass `origin: "prebuilt"` for Deepline-managed prebuilts or
1683
+ * `origin: "owned"` for org-owned plays.
1684
+ */
1555
1685
  async listPlays(options?: {
1556
1686
  origin?: 'prebuilt' | 'owned';
1557
1687
  grep?: string;
@@ -1571,18 +1701,36 @@ export class DeeplineClient {
1571
1701
  return response.plays ?? [];
1572
1702
  }
1573
1703
 
1704
+ /**
1705
+ * Search callable plays and return compact play descriptions.
1706
+ *
1707
+ * Prebuilt plays are preferred by default because they have maintained
1708
+ * contracts and stable run behavior.
1709
+ */
1574
1710
  async searchPlays(options: {
1575
1711
  query: string;
1576
1712
  compact?: boolean;
1713
+ scope?: 'prebuilt' | 'owned' | 'all';
1577
1714
  }): Promise<PlayDescription[]> {
1578
1715
  const params = new URLSearchParams();
1579
1716
  params.set('search', options.query.trim());
1717
+ const scope = options.scope ?? 'prebuilt';
1718
+ if (scope !== 'all') {
1719
+ params.set('origin', scope);
1720
+ }
1580
1721
  const response = await this.http.get<{ plays: PlayListItem[] }>(
1581
1722
  `/api/v2/plays?${params.toString()}`,
1582
1723
  );
1583
- return (response.plays ?? []).map((play) =>
1724
+ const plays = (response.plays ?? []).map((play) =>
1584
1725
  this.summarizePlayListItem(play, options),
1585
1726
  );
1727
+ if (scope === 'prebuilt') {
1728
+ return plays.filter(isPrebuiltPlayDescription);
1729
+ }
1730
+ if (scope === 'owned') {
1731
+ return plays.filter((play) => !isPrebuiltPlayDescription(play));
1732
+ }
1733
+ return preferPrebuiltPlayDescriptions(plays);
1586
1734
  }
1587
1735
 
1588
1736
  /**
@@ -1607,6 +1755,12 @@ export class DeeplineClient {
1607
1755
  return this.http.get<PlayDetail>(`/api/v2/plays/${encodedName}`);
1608
1756
  }
1609
1757
 
1758
+ /**
1759
+ * Get a normalized play description suitable for agents and CLIs.
1760
+ *
1761
+ * The description includes runnable examples, input/output summaries, clone
1762
+ * guidance, revision state, and latest run metadata when available.
1763
+ */
1610
1764
  async describePlay(
1611
1765
  name: string,
1612
1766
  options?: { compact?: boolean },
@@ -29,6 +29,7 @@ import { baseUrlSlug } from './config.js';
29
29
  import {
30
30
  COORDINATOR_INTERNAL_TOKEN_HEADER,
31
31
  COORDINATOR_URL_OVERRIDE_HEADER,
32
+ SYNTHETIC_RUN_HEADER,
32
33
  WORKER_CALLBACK_URL_OVERRIDE_HEADER,
33
34
  } from '../../shared_libs/play-runtime/coordinator-headers.js';
34
35
 
@@ -149,6 +150,16 @@ export class HttpClient {
149
150
  if (workerCallbackUrl?.trim()) {
150
151
  headers[WORKER_CALLBACK_URL_OVERRIDE_HEADER] = workerCallbackUrl.trim();
151
152
  }
153
+ // Automated test harnesses (e.g. tests/v2-plays) set DEEPLINE_SYNTHETIC_RUN
154
+ // so their intentionally failing plays do not page the SDK CLI error
155
+ // channel. Honored server-side only in non-prod (see plays/run route).
156
+ const syntheticRun =
157
+ typeof process !== 'undefined'
158
+ ? process.env?.DEEPLINE_SYNTHETIC_RUN
159
+ : undefined;
160
+ if (syntheticRun && syntheticRun.trim() && syntheticRun.trim() !== '0') {
161
+ headers[SYNTHETIC_RUN_HEADER] = '1';
162
+ }
152
163
  return headers;
153
164
  }
154
165
 
@@ -55,7 +55,17 @@
55
55
 
56
56
  // ——— Client ———
57
57
  export { DeeplineClient } from './client.js';
58
- export type { PlayStatus, ToolExecution } from './client.js';
58
+ export type {
59
+ PlayStatus,
60
+ PlaySheetRow,
61
+ PlaySheetRowsResult,
62
+ RunsListOptions,
63
+ RunsLogsOptions,
64
+ RunsLogsResult,
65
+ RunsNamespace,
66
+ RunsTailOptions,
67
+ ToolExecution,
68
+ } from './client.js';
59
69
  export { SDK_API_CONTRACT, SDK_VERSION } from './version.js';
60
70
  export {
61
71
  DEEPLINE_TOOL_CATEGORIES,
@@ -91,10 +101,15 @@ export { resolveConfig, PROD_URL } from './config.js';
91
101
  export {
92
102
  Deepline,
93
103
  DeeplineContext,
104
+ DEEPLINE_EXTRACTOR_TARGETS,
105
+ DEEPLINE_EXTRACTOR_TARGET_DEFINITIONS,
94
106
  defineInput,
95
107
  definePlay,
96
108
  defineWorkflow,
109
+ JOB_CHANGE_STATUS_VALUES,
110
+ PHONE_STATUS_VALUES,
97
111
  getDefinedPlayMetadata,
112
+ isDeeplineExtractorTarget,
98
113
  runIf,
99
114
  steps,
100
115
  } from './play.js';
@@ -124,31 +139,50 @@ export type {
124
139
  PublishPlayVersionResult,
125
140
  StartPlayRunRequest,
126
141
  PlayListItem,
142
+ CustomerDbQueryResult,
127
143
  DeeplineToolCategory,
128
144
  PlayBootstrapFinderKind,
129
145
  PlayBootstrapEntityKind,
146
+ StopPlayRunResult,
147
+ ToolSearchOptions,
148
+ ToolSearchResult,
130
149
  } from './types.js';
131
150
 
132
151
  export type {
133
152
  DefinePlayConfig,
153
+ CsvOptions,
134
154
  DeeplineNamedPlay,
155
+ DeeplinePlaysNamespace,
135
156
  DeeplinePlayRuntimeContext,
157
+ DeeplineToolsNamespace,
136
158
  DefinedPlay,
137
159
  ColumnMap,
138
160
  ColumnResolver,
139
161
  CsvInput,
140
162
  DatasetBuilder,
163
+ DatasetColumnDefinition,
164
+ DatasetColumnRunInput,
141
165
  PlayBindings,
142
166
  FileInput,
143
167
  PlayInputContract,
144
168
  PlayJob,
145
169
  ConditionalStepResolver,
170
+ PreviousCell,
146
171
  PlayDataset,
147
172
  PlayDatasetInput,
148
173
  PlayStepProgramStep,
149
174
  PrebuiltPlayRef,
175
+ StaleAfterSeconds,
176
+ StepOptions,
150
177
  StepProgram,
151
178
  StepProgramResolver,
152
179
  StepResolver,
153
180
  ToolExecuteResult,
181
+ ToolExecutionRequest,
182
+ DeeplineEmailStatusGetterValue,
183
+ DeeplineExtractorTarget,
184
+ DeeplineGetterValue,
185
+ DeeplineGetterValueMap,
186
+ JobChangeStatus,
187
+ PhoneStatus,
154
188
  } from './play.js';