deepline 0.3.246 → 0.3.248

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 (67) hide show
  1. package/dist/bundling-sources/sdk/src/client.ts +177 -13
  2. package/dist/bundling-sources/sdk/src/index.ts +8 -0
  3. package/dist/bundling-sources/sdk/src/plays/input-example.ts +40 -0
  4. package/dist/bundling-sources/sdk/src/release.ts +1 -1
  5. package/dist/bundling-sources/sdk/src/runs/overview.ts +457 -0
  6. package/dist/bundling-sources/sdk/src/runs/receipts.ts +23 -0
  7. package/dist/bundling-sources/sdk/src/tool-calls.ts +21 -1
  8. package/dist/bundling-sources/sdk/src/types.ts +16 -1
  9. package/dist/bundling-sources/shared_libs/observability/scheduled-jobs.json +37 -1
  10. package/dist/bundling-sources/shared_libs/observability/scheduled-work-manual.ts +1 -0
  11. package/dist/bundling-sources/shared_libs/play-data-plane/column-names.ts +17 -3
  12. package/dist/bundling-sources/shared_libs/play-data-plane/sheet-contract.ts +40 -8
  13. package/dist/bundling-sources/shared_libs/play-runtime/app-runtime-api.ts +26 -1
  14. package/dist/bundling-sources/shared_libs/play-runtime/context.ts +150 -19
  15. package/dist/bundling-sources/shared_libs/play-runtime/ctx-types.ts +2 -1
  16. package/dist/bundling-sources/shared_libs/play-runtime/daytona-runtime-config.ts +6 -3
  17. package/dist/bundling-sources/shared_libs/play-runtime/daytona-sandbox-janitor.ts +26 -21
  18. package/dist/bundling-sources/shared_libs/play-runtime/daytona-sandbox-reaper.ts +23 -21
  19. package/dist/bundling-sources/shared_libs/play-runtime/deployment/fly-machines.ts +17 -0
  20. package/dist/bundling-sources/shared_libs/play-runtime/log-context.ts +105 -0
  21. package/dist/bundling-sources/shared_libs/play-runtime/output-size-limits.ts +8 -1
  22. package/dist/bundling-sources/shared_libs/play-runtime/protocol.ts +9 -0
  23. package/dist/bundling-sources/shared_libs/play-runtime/run-ledger-event-transport.ts +40 -4
  24. package/dist/bundling-sources/shared_libs/play-runtime/run-ledger.ts +50 -5
  25. package/dist/bundling-sources/shared_libs/play-runtime/run-lifecycle-policy.ts +3 -1
  26. package/dist/bundling-sources/shared_libs/play-runtime/run-log-buffer.ts +28 -1
  27. package/dist/bundling-sources/shared_libs/play-runtime/runner-app/index.ts +14 -1
  28. package/dist/bundling-sources/shared_libs/play-runtime/runner-app/runtime-terminal-push.ts +56 -16
  29. package/dist/bundling-sources/shared_libs/play-runtime/runner-backends/backends/daytona-control-transport.ts +184 -0
  30. package/dist/bundling-sources/shared_libs/play-runtime/runner-backends/backends/daytona-launch-transport.ts +327 -0
  31. package/dist/bundling-sources/shared_libs/play-runtime/runner-backends/backends/daytona-lifecycle.ts +87 -30
  32. package/dist/bundling-sources/shared_libs/play-runtime/runner-backends/backends/daytona-session-execution.ts +24 -13
  33. package/dist/bundling-sources/shared_libs/play-runtime/runner-backends/backends/daytona-start-admission.ts +23 -6
  34. package/dist/bundling-sources/shared_libs/play-runtime/runner-backends/backends/daytona.ts +76 -33
  35. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/absurd-runtime-worker.ts +90 -35
  36. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/postgres-pool.ts +16 -0
  37. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/postgres-progress.ts +62 -21
  38. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/postgres.ts +368 -66
  39. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/receipt-gateway.ts +22 -4
  40. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/run-ledger-outbox-recovery.ts +106 -81
  41. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/runtime-event-search.ts +1347 -0
  42. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/runtime-queue-health.ts +16 -19
  43. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/runtime-receipt-value-storage.ts +14 -6
  44. package/dist/bundling-sources/shared_libs/play-runtime/tool-execute-retry-policy.ts +16 -0
  45. package/dist/bundling-sources/shared_libs/play-runtime/tool-http-errors.ts +40 -0
  46. package/dist/bundling-sources/shared_libs/play-runtime/transient-service-error.ts +3 -2
  47. package/dist/bundling-sources/shared_libs/plays/authoring-contract.ts +5 -2
  48. package/dist/bundling-sources/shared_libs/plays/dataset-summary.ts +11 -7
  49. package/dist/bundling-sources/shared_libs/plays/static-pipeline-storage-codec.ts +5 -2
  50. package/dist/bundling-sources/shared_libs/plays/static-pipeline.ts +11 -2
  51. package/dist/cli/index.js +3504 -2368
  52. package/dist/cli/index.mjs +3188 -2052
  53. package/dist/{compiler-manifest-n8ZtPv2h.d.mts → compiler-manifest-DavmLa8y.d.mts} +1 -0
  54. package/dist/{compiler-manifest-n8ZtPv2h.d.ts → compiler-manifest-DavmLa8y.d.ts} +1 -0
  55. package/dist/index.d.mts +97 -5
  56. package/dist/index.d.ts +97 -5
  57. package/dist/index.js +135 -15
  58. package/dist/index.mjs +135 -15
  59. package/dist/install-integrity.json +9 -2
  60. package/dist/plays/bundle-play-file.d.mts +2 -2
  61. package/dist/plays/bundle-play-file.d.ts +2 -2
  62. package/dist/plays/bundle-play-file.mjs +1 -1
  63. package/dist/release.d.mts +1 -1
  64. package/dist/release.d.ts +1 -1
  65. package/dist/release.js +1 -1
  66. package/dist/release.mjs +1 -1
  67. package/package.json +1 -1
@@ -4,6 +4,7 @@ import type {
4
4
  PlaySettingsPathsPage,
5
5
  } from '../../shared_libs/plays/settings-contract';
6
6
  import { iterateCursorPages } from './pagination.js';
7
+ import { playInputExampleArgs } from './plays/input-example.js';
7
8
  /**
8
9
  * The main API client for interacting with the Deepline platform.
9
10
  *
@@ -114,6 +115,7 @@ import type { PlayStagedFileRef } from './plays/local-file-discovery.js';
114
115
  import type { PlayCompilerManifest } from '../../shared_libs/plays/compiler-manifest.js';
115
116
  import type { EnrichCompiledConfig } from './cli/enrich-play-compiler.js';
116
117
  import {
118
+ COORDINATOR_INTERNAL_TOKEN_HEADER,
117
119
  RUNTIME_ENVIRONMENT_TOKEN_HEADER,
118
120
  RETAINED_PIPELINE_RECEIVERS_HEADER,
119
121
  } from '../../shared_libs/play-runtime/coordinator-headers.js';
@@ -414,6 +416,29 @@ function runtimeSelectionHeaders(
414
416
  };
415
417
  }
416
418
 
419
+ /** The isolated PR estate needs its existing internal credential to read its pinned scheduler scope. */
420
+ function isolatedCiRuntimeEventReadHeaders():
421
+ | Record<string, string>
422
+ | undefined {
423
+ const schema = process.env.DEEPLINE_RUNTIME_SCHEDULER_SCHEMA?.trim();
424
+ if (
425
+ process.env.DEEPLINE_SYNTHETIC_RUN?.trim() !== '1' ||
426
+ !schema ||
427
+ !/^fly_absurd_pr_\d+_\d+(?:_\d+)?$/.test(schema)
428
+ ) {
429
+ return undefined;
430
+ }
431
+ const token = process.env.DEEPLINE_INTERNAL_TOKEN?.trim();
432
+ if (!token) {
433
+ throw new DeeplineError(
434
+ 'DEEPLINE_INTERNAL_TOKEN is required for isolated CI runtime event reads.',
435
+ undefined,
436
+ 'RUNTIME_EVENT_INTERNAL_TOKEN_REQUIRED',
437
+ );
438
+ }
439
+ return { [COORDINATOR_INTERNAL_TOKEN_HEADER]: token };
440
+ }
441
+
417
442
  function normalizeTestPolicyOverrides(
418
443
  value: unknown,
419
444
  source: string,
@@ -691,6 +716,54 @@ export type RunsLogsResult = {
691
716
  logsTruncated?: boolean;
692
717
  };
693
718
 
719
+ /** Bounded org-scoped search over durable Play runtime observations. */
720
+ export type RunsEventSearchOptions = {
721
+ /** Inclusive UTC timestamp; defaults to one hour before the request. */
722
+ since?: string;
723
+ /** Exclusive UTC timestamp; defaults to the request time. */
724
+ until?: string;
725
+ /** Optional run filter. Omit to search across the active organization. */
726
+ runId?: string;
727
+ playName?: string;
728
+ kind?: string;
729
+ /** Flat equality predicate in the supported PostgreSQL JSONPath subset. */
730
+ jsonpath?: string;
731
+ /** Include receipt-backed outputs, capped to ten events and 16 MiB total. */
732
+ includePayloads?: boolean;
733
+ limit?: number;
734
+ cursor?: string;
735
+ /** Explicit Preview selection requires the existing runtime credential. */
736
+ runtime?: PlayRuntimeSelection;
737
+ };
738
+
739
+ export type RunsEventSearchEntry = {
740
+ eventId: string;
741
+ occurredAt: string;
742
+ ingestedAt: string;
743
+ runId: string;
744
+ playName: string;
745
+ kind: string;
746
+ level: string | null;
747
+ message: string | null;
748
+ searchDoc: Record<string, unknown>;
749
+ /** Optional full result, included only when explicitly requested. */
750
+ payload?: RunsEventPayload | null;
751
+ };
752
+
753
+ export type RunsEventSearchResult = {
754
+ events: RunsEventSearchEntry[];
755
+ nextCursor: string | null;
756
+ since: string;
757
+ until: string;
758
+ };
759
+
760
+ export type RunsEventPayload = {
761
+ status: 'completed' | 'failed' | 'skipped';
762
+ output: unknown | null;
763
+ error: string | null;
764
+ errorPayload: unknown | null;
765
+ };
766
+
694
767
  /** Server page cap for GET /api/v2/runs/:runId/logs (ADR-0009). */
695
768
  const RUN_LOGS_PAGE_LIMIT = 1_000;
696
769
 
@@ -768,6 +841,11 @@ export type PlaySecretCheck = {
768
841
  * @sdkReference client 020 client.runs
769
842
  */
770
843
  export type RunsNamespace = {
844
+ /** Read retained tool results associated with a run, in supplied key order. Never executes tools. */
845
+ getReceipts: (
846
+ runId: string,
847
+ options: { keys: string[] },
848
+ ) => Promise<import('./runs/receipts').RunToolReceiptsResponse>;
771
849
  /** Get current run status by public run id. */
772
850
  get: (runId: string, options?: RunsGetOptions) => Promise<PlayStatus>;
773
851
  /**
@@ -795,6 +873,10 @@ export type RunsNamespace = {
795
873
  tail: (runId: string, options?: RunsTailOptions) => Promise<PlayStatus>;
796
874
  /** Fetch persisted log lines for a run. */
797
875
  logs: (runId: string, options?: RunsLogsOptions) => Promise<RunsLogsResult>;
876
+ /** Search recent durable runtime events across runs in the active organization. */
877
+ searchEvents: (
878
+ options?: RunsEventSearchOptions,
879
+ ) => Promise<RunsEventSearchResult>;
798
880
  /** Export persisted rows for a runtime-sheet dataset/table namespace. */
799
881
  exportDatasetRows: (input: {
800
882
  playName: string;
@@ -2680,8 +2762,13 @@ export class DeeplineClient {
2680
2762
  constructor(options?: DeeplineClientOptions) {
2681
2763
  this.config = resolveConfig(options);
2682
2764
  this.http = new HttpClient(this.config);
2683
- this.toolCalls = new ToolCalls(this.http, this.config.timeout);
2765
+ this.toolCalls = new ToolCalls(
2766
+ this.http,
2767
+ this.config.timeout,
2768
+ options?.timeout,
2769
+ );
2684
2770
  this.runs = {
2771
+ getReceipts: (runId, options) => this.getRunReceipts(runId, options),
2685
2772
  get: (runId, options) => this.getRunStatus(runId, options),
2686
2773
  status: (runId) => this.getRunLifecycleStatus(runId),
2687
2774
  list: (options) => this.listRuns(options),
@@ -2689,6 +2776,7 @@ export class DeeplineClient {
2689
2776
  watch: (runId, options) => this.watchRunToTerminal(runId, options),
2690
2777
  tail: (runId, options) => this.tailRun(runId, options),
2691
2778
  logs: (runId, options) => this.getRunLogs(runId, options),
2779
+ searchEvents: (options) => this.searchRunEvents(options),
2692
2780
  input: (runId) => this.getRunInput(runId),
2693
2781
  rerun: (runId, options) => this.rerun(runId, options),
2694
2782
  exportDatasetRows: (input) => this.getPlaySheetRows(input),
@@ -2863,19 +2951,10 @@ export class DeeplineClient {
2863
2951
  }
2864
2952
 
2865
2953
  private playRunCommand(
2866
- play: Pick<PlayListItem, 'name' | 'reference'>,
2867
- options?: { csvInput?: Record<string, unknown> | null },
2954
+ play: Pick<PlayListItem, 'name' | 'reference' | 'inputSchema'>,
2868
2955
  ): string {
2869
2956
  const target = play.reference || play.name;
2870
- if (options?.csvInput) {
2871
- const inputField =
2872
- typeof options.csvInput.inputField === 'string' &&
2873
- options.csvInput.inputField.trim()
2874
- ? options.csvInput.inputField.trim()
2875
- : 'csv';
2876
- return `deepline plays run ${target} --input '${JSON.stringify({ [inputField]: 'leads.csv' })}' --watch`;
2877
- }
2878
- return `deepline plays run ${target} --input '{...}' --watch`;
2957
+ return `deepline plays run ${target}${playInputExampleArgs(play.inputSchema)} --watch`;
2879
2958
  }
2880
2959
 
2881
2960
  private starterPlayPath(
@@ -2926,7 +3005,7 @@ export class DeeplineClient {
2926
3005
  play.currentRevision?.description?.trim() ||
2927
3006
  play.liveRevision?.description?.trim() ||
2928
3007
  null;
2929
- const runCommand = this.playRunCommand(play, { csvInput });
3008
+ const runCommand = this.playRunCommand(play);
2930
3009
  const cloneEditStarter = this.playCloneEditStarter(play);
2931
3010
  return {
2932
3011
  name: play.name,
@@ -4593,6 +4672,50 @@ export class DeeplineClient {
4593
4672
  return { ...response, runs: response.runs ?? [] };
4594
4673
  }
4595
4674
 
4675
+ /** Read batches rather than silently truncating a long key list. */
4676
+ async getRunReceipts(
4677
+ runId: string,
4678
+ options: { keys: string[] },
4679
+ ): Promise<import('./runs/receipts').RunToolReceiptsResponse> {
4680
+ if (
4681
+ !options.keys.length ||
4682
+ options.keys.some(
4683
+ (key) =>
4684
+ typeof key !== 'string' ||
4685
+ !key.trim() ||
4686
+ key.length > 2048 ||
4687
+ /[\r\n\0]/.test(key),
4688
+ )
4689
+ ) {
4690
+ throw Object.assign(
4691
+ new Error(
4692
+ 'Supply nonempty receipt keys, at most 2048 characters each.',
4693
+ ),
4694
+ { exitCode: 2 },
4695
+ );
4696
+ }
4697
+ const receipts: import('./runs/receipts').RunToolReceiptResult[] = [];
4698
+ for (let offset = 0; offset < options.keys.length; offset += 100) {
4699
+ const keys = options.keys.slice(offset, offset + 100);
4700
+ const result = await this.http.post<
4701
+ import('./runs/receipts').RunToolReceiptsResponse
4702
+ >(`/api/v2/runs/${encodeURIComponent(runId)}/receipts/results`, { keys });
4703
+ if (
4704
+ result.runId !== runId ||
4705
+ result.receipts.length !== keys.length ||
4706
+ result.receipts.some(
4707
+ (receipt, index) => receipt.receiptKey !== keys[index],
4708
+ )
4709
+ ) {
4710
+ throw new Error(
4711
+ 'Receipt response does not match the requested run and keys.',
4712
+ );
4713
+ }
4714
+ receipts.push(...result.receipts);
4715
+ }
4716
+ return { runId, receipts };
4717
+ }
4718
+
4596
4719
  /** Get the exact original input retained for a run. This is intentionally separate from status. */
4597
4720
  async getRunInput(runId: string): Promise<{
4598
4721
  runId: string;
@@ -4662,6 +4785,7 @@ export class DeeplineClient {
4662
4785
  const failedLimit = Math.min(RUNS_FAILED_LOG_LIMIT, requestedLimit);
4663
4786
  const page = await this.http.get<RunLogsPageResponse>(
4664
4787
  `/api/v2/runs/${encodeURIComponent(runId)}/logs?view=failed&limit=${failedLimit}`,
4788
+ { retryApiErrors: true },
4665
4789
  );
4666
4790
  return {
4667
4791
  runId: page.runId,
@@ -4691,6 +4815,7 @@ export class DeeplineClient {
4691
4815
  const fetchPage = (afterSeq: number, pageLimit: number) =>
4692
4816
  this.http.get<RunLogsPageResponse>(
4693
4817
  `/api/v2/runs/${encodeURIComponent(runId)}/logs?afterSeq=${afterSeq}&limit=${pageLimit}`,
4818
+ { retryApiErrors: true },
4694
4819
  );
4695
4820
  // Probe for the run's stored extent, then read the LAST `limit` stored
4696
4821
  // lines (matching the historical tail-slice semantics), paginating in
@@ -4730,6 +4855,45 @@ export class DeeplineClient {
4730
4855
  };
4731
4856
  }
4732
4857
 
4858
+ /** Search bounded, structured runtime history without requiring a run id. */
4859
+ async searchRunEvents(
4860
+ options: RunsEventSearchOptions = {},
4861
+ ): Promise<RunsEventSearchResult> {
4862
+ const now = Date.now();
4863
+ const params = new URLSearchParams({
4864
+ since: options.since ?? new Date(now - 60 * 60 * 1000).toISOString(),
4865
+ until: options.until ?? new Date(now).toISOString(),
4866
+ });
4867
+ if (options.runId) params.set('runId', options.runId);
4868
+ if (options.playName) params.set('playName', options.playName);
4869
+ if (options.kind) params.set('kind', options.kind);
4870
+ if (options.jsonpath) params.set('jsonpath', options.jsonpath);
4871
+ if (options.includePayloads) params.set('payloads', 'true');
4872
+ if (options.limit !== undefined) params.set('limit', String(options.limit));
4873
+ if (options.cursor) params.set('cursor', options.cursor);
4874
+ let headers: Record<string, string> | undefined;
4875
+ if (options.runtime !== undefined) {
4876
+ const runtime = normalizePlayRuntimeSelection(options.runtime);
4877
+ if (!runtime) {
4878
+ throw new DeeplineError(
4879
+ 'runs.searchEvents runtime must be a valid Preview selection.',
4880
+ undefined,
4881
+ 'INVALID_RUNTIME_SELECTION',
4882
+ );
4883
+ }
4884
+ params.set('runtime', 'preview');
4885
+ params.set('namespace', runtime.namespace);
4886
+ if (runtime.backend) params.set('backend', runtime.backend);
4887
+ headers = runtimeSelectionHeaders(runtime);
4888
+ } else {
4889
+ headers = isolatedCiRuntimeEventReadHeaders();
4890
+ }
4891
+ return this.http.get<RunsEventSearchResult>(
4892
+ `/api/v2/runs/events?${params.toString()}`,
4893
+ { headers, retryApiErrors: true },
4894
+ );
4895
+ }
4896
+
4733
4897
  /**
4734
4898
  * Export persisted runtime-sheet rows for a play dataset/table namespace.
4735
4899
  *
@@ -136,6 +136,10 @@ export type {
136
136
  PlaysListPage,
137
137
  RunsLogsOptions,
138
138
  RunsLogsResult,
139
+ RunsEventSearchOptions,
140
+ RunsEventSearchEntry,
141
+ RunsEventSearchResult,
142
+ RunsEventPayload,
139
143
  RunsNamespace,
140
144
  RunsWatchOptions,
141
145
  RunsTailOptions,
@@ -350,3 +354,7 @@ export type {
350
354
  JobChangeStatus,
351
355
  PhoneStatus,
352
356
  } from './play.js';
357
+ export type {
358
+ RunToolReceiptResult,
359
+ RunToolReceiptsResponse,
360
+ } from './runs/receipts.js';
@@ -0,0 +1,40 @@
1
+ /** Shared, contract-derived arguments for check/describe/search run examples. */
2
+ export function playInputExampleArgs(
3
+ schema: Record<string, unknown> | null | undefined,
4
+ ): string {
5
+ if (!schema) return " --input '@<input.json>'";
6
+ // Do not guess required inputs hidden behind a reference or intersection.
7
+ if (schema.$ref || schema.allOf) return " --input '@<input.json>'";
8
+ const csv = schema.csvInput as { inputField?: unknown } | undefined;
9
+ const csvField = typeof csv?.inputField === 'string' ? csv.inputField : null;
10
+ const required = Array.isArray(schema.required) ? schema.required : [];
11
+ const csvOnlyRequired = required.every((key) => key === csvField);
12
+ const alternatives = schema.oneOf ?? schema.anyOf;
13
+ const hasCsvAlternative =
14
+ Array.isArray(alternatives) &&
15
+ alternatives.some((branch) => {
16
+ if (!branch || typeof branch !== 'object') return false;
17
+ const keys = (branch as { required?: unknown }).required;
18
+ return (
19
+ Array.isArray(keys) &&
20
+ keys.includes(csvField) &&
21
+ keys.every((key) => key === csvField)
22
+ );
23
+ });
24
+ // Only advertise the universally supported CSV shorthand. Other field names
25
+ // may collide with execution flags (e.g. file/name); JSON is unambiguous.
26
+ if (csvField && csvOnlyRequired && (!alternatives || hasCsvAlternative)) {
27
+ if (csvField === 'csv') return " --csv '<contacts.csv>'";
28
+ const value = JSON.stringify({ [csvField]: '<contacts.csv>' });
29
+ return ` --input '${value.replace(/'/g, "'\\''")}'`;
30
+ }
31
+ if (
32
+ Array.isArray(schema.required) &&
33
+ !required.length &&
34
+ !csv &&
35
+ !alternatives
36
+ ) {
37
+ return '';
38
+ }
39
+ return " --input '@<input.json>'";
40
+ }
@@ -200,7 +200,7 @@ export const SDK_RELEASE = {
200
200
  // getters keep their established compatibility behavior.
201
201
  // 0.3.1 deprecated the legacy `deepline enrich` command in favor of Plays.
202
202
  // 0.3.90 is the first deliberately versioned SDK release for API v3.
203
- version: '0.3.246',
203
+ version: '0.3.248',
204
204
  updateSummary:
205
205
  'Play grep now returns concise results with the matched fields and terms. Automatic CLI updates are enabled by default; use `deepline settings autoupdate off` to opt out, `deepline settings autoupdate on` to re-enable updates, or `deepline settings autoupdate pin <version>` to hold an exact release.',
206
206
  packageCapabilities: {