deepline 0.1.4 → 0.1.8

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.
@@ -169,7 +169,7 @@ function resolveConfig(options) {
169
169
  }
170
170
 
171
171
  // src/version.ts
172
- var SDK_VERSION = "0.1.4";
172
+ var SDK_VERSION = "0.1.8";
173
173
  var SDK_API_CONTRACT = "2026-04-plays-v1";
174
174
 
175
175
  // ../shared_libs/play-runtime/coordinator-headers.ts
@@ -2483,6 +2483,7 @@ function registerOrgCommands(program) {
2483
2483
  import { createHash as createHash3 } from "crypto";
2484
2484
  import {
2485
2485
  existsSync as existsSync4,
2486
+ mkdirSync as mkdirSync3,
2486
2487
  readFileSync as readFileSync3,
2487
2488
  readdirSync,
2488
2489
  realpathSync,
@@ -2593,6 +2594,13 @@ function formatTypeScriptDiagnostic(diagnostic) {
2593
2594
  }
2594
2595
  return `${diagnostic.file.fileName}:${line + 1}:${character + 1} ${message}`;
2595
2596
  }
2597
+ function resolveBundledTypeRoots() {
2598
+ try {
2599
+ return [dirname3(dirname3(playArtifactRequire.resolve("@types/node/package.json")))];
2600
+ } catch {
2601
+ return [];
2602
+ }
2603
+ }
2596
2604
  function typecheckPlaySource(input, adapter) {
2597
2605
  const rootNames = Array.from(
2598
2606
  /* @__PURE__ */ new Set([
@@ -2618,7 +2626,8 @@ function typecheckPlaySource(input, adapter) {
2618
2626
  allowImportingTsExtensions: true,
2619
2627
  allowJs: true,
2620
2628
  resolveJsonModule: true,
2621
- types: ["node"]
2629
+ types: ["node"],
2630
+ typeRoots: resolveBundledTypeRoots()
2622
2631
  });
2623
2632
  return ts.getPreEmitDiagnostics(program).map(formatTypeScriptDiagnostic).filter((message) => Boolean(message));
2624
2633
  }
@@ -3811,6 +3820,21 @@ var CliProgress = class {
3811
3820
  this.worker?.terminate().catch(() => void 0);
3812
3821
  this.worker = null;
3813
3822
  process.stderr.write(`\r\x1B[2K${message}
3823
+ `);
3824
+ if (activeMessage) {
3825
+ this.startWorker().postMessage({ type: "phase", message: activeMessage });
3826
+ }
3827
+ }
3828
+ writeLine(line, stream = process.stderr) {
3829
+ if (!this.enabled || !this.interactive) {
3830
+ stream.write(`${line}
3831
+ `);
3832
+ return;
3833
+ }
3834
+ const activeMessage = this.lastMessage;
3835
+ this.worker?.terminate().catch(() => void 0);
3836
+ this.worker = null;
3837
+ stream.write(`\r\x1B[2K${line}
3814
3838
  `);
3815
3839
  if (activeMessage) {
3816
3840
  this.startWorker().postMessage({ type: "phase", message: activeMessage });
@@ -3984,6 +4008,67 @@ function defaultMaterializedPlayPath(reference) {
3984
4008
  const safeName = playName.trim().toLowerCase().replace(/[^a-z0-9-]/g, "-").replace(/-+/g, "-").replace(/^-|-$/g, "");
3985
4009
  return resolve7(`${safeName || "play"}.play.ts`);
3986
4010
  }
4011
+ function sanitizeGeneratedPlayName(value) {
4012
+ return value.trim().toLowerCase().replace(/^prebuilt\//, "").replace(/[^a-z0-9-]/g, "-").replace(/-+/g, "-").replace(/^-|-$/g, "") || "play";
4013
+ }
4014
+ function buildGeneratedCsvWrapperSource(input) {
4015
+ return `import { definePlay } from 'deepline';
4016
+
4017
+ export default definePlay(
4018
+ ${JSON.stringify(input.wrapperName)},
4019
+ async (ctx, input: Record<string, unknown> & { file: string }) => {
4020
+ const rows = await ctx.csv<Record<string, unknown>>(input.file);
4021
+ const constants = Object.fromEntries(
4022
+ Object.entries(input).filter(([key]) => key !== 'file'),
4023
+ );
4024
+
4025
+ const mappedRows = await ctx
4026
+ .map('csv_rows', rows, {
4027
+ key: (row, index) =>
4028
+ String(
4029
+ row.id ??
4030
+ row.lead_id ??
4031
+ row.email ??
4032
+ row.linkedin_url ??
4033
+ row.domain ??
4034
+ index,
4035
+ ),
4036
+ })
4037
+ .step('result', (row, rowCtx) =>
4038
+ rowCtx.runPlay(
4039
+ 'row_play',
4040
+ ${JSON.stringify(input.playRef)},
4041
+ {
4042
+ ...constants,
4043
+ ...row,
4044
+ },
4045
+ {
4046
+ description: 'Run the source play for this CSV row.',
4047
+ },
4048
+ ),
4049
+ )
4050
+ .run({ description: 'Run the source play once per CSV row.' });
4051
+
4052
+ return { rows: mappedRows };
4053
+ },
4054
+ );
4055
+ `;
4056
+ }
4057
+ function writeGeneratedCsvWrapperPlay(playRef) {
4058
+ const baseName = sanitizeGeneratedPlayName(
4059
+ parseReferencedPlayTarget(playRef).unqualifiedPlayName
4060
+ );
4061
+ const wrapperName = `${baseName}-csv`;
4062
+ const outputDir = resolve7(".deepline", "generated");
4063
+ const outputPath = join6(outputDir, `${wrapperName}.play.ts`);
4064
+ mkdirSync3(outputDir, { recursive: true });
4065
+ writeFileSync4(
4066
+ outputPath,
4067
+ buildGeneratedCsvWrapperSource({ wrapperName, playRef }),
4068
+ "utf-8"
4069
+ );
4070
+ return outputPath;
4071
+ }
3987
4072
  function materializeRemotePlaySource(input) {
3988
4073
  if (isFileTarget(input.target)) {
3989
4074
  return null;
@@ -4499,9 +4584,16 @@ async function startAndWaitForPlayCompletionByStream(input) {
4499
4584
  const workflowId = lastKnownWorkflowId || "pending";
4500
4585
  if (workflowId !== "pending" && !emittedDashboardUrl) {
4501
4586
  const dashboardUrl = getDashboardUrlFromLiveEvent(event) ?? buildPlayDashboardUrl(input.client.baseUrl, input.playName);
4502
- input.progress.phase(
4503
- `loading play on ${dashboardUrl}`
4504
- );
4587
+ if (!input.jsonOutput) {
4588
+ writeStartedPlayRun({
4589
+ runId: workflowId,
4590
+ playName: input.playName,
4591
+ dashboardUrl,
4592
+ jsonOutput: false,
4593
+ progress: input.progress
4594
+ });
4595
+ }
4596
+ input.progress.phase(`loading play on ${dashboardUrl}`);
4505
4597
  emittedDashboardUrl = true;
4506
4598
  }
4507
4599
  assertPlayWaitNotTimedOut({
@@ -4612,9 +4704,8 @@ async function waitForPlayCompletionByPolling(input) {
4612
4704
  const now = Date.now();
4613
4705
  if (now - lastTransientPollWarningAt >= 3e4) {
4614
4706
  const message = error instanceof Error ? error.message : String(error);
4615
- process.stderr.write(
4616
- `[play tail] transient status poll failed; retrying: ${message}
4617
- `
4707
+ input.progress.writeLine(
4708
+ `[play tail] transient status poll failed; retrying: ${message}`
4618
4709
  );
4619
4710
  lastTransientPollWarningAt = now;
4620
4711
  }
@@ -5004,7 +5095,12 @@ function writeStartedPlayRun(input) {
5004
5095
  if (input.dashboardUrl) {
5005
5096
  lines.push(` play page: ${input.dashboardUrl}`);
5006
5097
  }
5007
- console.log(lines.join("\n"));
5098
+ const output = lines.join("\n");
5099
+ if (input.progress) {
5100
+ input.progress.writeLine(output, process.stdout);
5101
+ return;
5102
+ }
5103
+ console.log(output);
5008
5104
  }
5009
5105
  function parsePlayRunOptions(args) {
5010
5106
  const usage = "Usage: deepline plays run <play-name> [--input '{...}'] [--csv file.csv] [--live|--latest|--revision-id <id>] [--watch] [--out output.csv] [--tail-timeout-ms 30000] [--force]\n deepline plays run <play-file.ts> [--input '{...}'] [--csv file.csv] [--watch] [--out output.csv] [--tail-timeout-ms 30000] [--force]\n deepline plays run --file <play-file.ts> [--input '{...}'] [--csv file.csv] [--watch] [--out output.csv] [--tail-timeout-ms 30000] [--force]\n deepline plays run --name <name> [--input '{...}'] [--csv file.csv] [--live|--latest|--revision-id <id>] [--watch] [--out output.csv] [--tail-timeout-ms 30000] [--force] [--json]";
@@ -5323,7 +5419,8 @@ async function handleFileBackedRun(options) {
5323
5419
  status: started.status,
5324
5420
  statusUrl: started.statusUrl,
5325
5421
  dashboardUrl,
5326
- jsonOutput: options.jsonOutput
5422
+ jsonOutput: options.jsonOutput,
5423
+ progress
5327
5424
  });
5328
5425
  return 0;
5329
5426
  }
@@ -5383,6 +5480,22 @@ async function handleNamedRun(options) {
5383
5480
  waitTimeoutMs: options.waitTimeoutMs,
5384
5481
  progress
5385
5482
  });
5483
+ if (finalStatus.status !== "completed" && options.csvPath) {
5484
+ progress.phase("generating csv wrapper play");
5485
+ const generatedPlayPath = writeGeneratedCsvWrapperPlay(
5486
+ options.target.name
5487
+ );
5488
+ progress.writeLogLine(
5489
+ `Generated CSV wrapper play: ${generatedPlayPath}`
5490
+ );
5491
+ progress.phase("running generated csv wrapper play");
5492
+ return handleFileBackedRun({
5493
+ ...options,
5494
+ target: { kind: "file", path: generatedPlayPath },
5495
+ revisionId: null,
5496
+ revisionSelector: null
5497
+ });
5498
+ }
5386
5499
  const exportedPath = exportPlayStatusRows(finalStatus, options.outPath);
5387
5500
  if (finalStatus.status === "completed") {
5388
5501
  progress.complete();
@@ -5407,7 +5520,8 @@ async function handleNamedRun(options) {
5407
5520
  status: started.status,
5408
5521
  statusUrl: started.statusUrl,
5409
5522
  dashboardUrl,
5410
- jsonOutput: options.jsonOutput
5523
+ jsonOutput: options.jsonOutput,
5524
+ progress
5411
5525
  });
5412
5526
  return 0;
5413
5527
  }
@@ -6196,7 +6310,7 @@ Examples:
6196
6310
  }
6197
6311
 
6198
6312
  // src/tool-output.ts
6199
- import { mkdirSync as mkdirSync3, writeFileSync as writeFileSync5 } from "fs";
6313
+ import { mkdirSync as mkdirSync4, writeFileSync as writeFileSync5 } from "fs";
6200
6314
  import { homedir as homedir3 } from "os";
6201
6315
  import { join as join7 } from "path";
6202
6316
  function isPlainObject(value) {
@@ -6274,7 +6388,7 @@ function tryConvertToList(payload, options) {
6274
6388
  }
6275
6389
  function ensureOutputDir() {
6276
6390
  const outputDir = join7(homedir3(), ".local", "share", "deepline", "data");
6277
- mkdirSync3(outputDir, { recursive: true });
6391
+ mkdirSync4(outputDir, { recursive: true });
6278
6392
  return outputDir;
6279
6393
  }
6280
6394
  function writeJsonOutputFile(payload, stem) {
@@ -6886,7 +7000,7 @@ async function executeTool(args) {
6886
7000
 
6887
7001
  // src/cli/skills-sync.ts
6888
7002
  import { spawn } from "child_process";
6889
- import { existsSync as existsSync5, mkdirSync as mkdirSync4, readFileSync as readFileSync4, writeFileSync as writeFileSync6 } from "fs";
7003
+ import { existsSync as existsSync5, mkdirSync as mkdirSync5, readFileSync as readFileSync4, writeFileSync as writeFileSync6 } from "fs";
6890
7004
  import { homedir as homedir4 } from "os";
6891
7005
  import { dirname as dirname7, join as join8 } from "path";
6892
7006
  var CHECK_TIMEOUT_MS2 = 3e3;
@@ -6912,7 +7026,7 @@ function readLocalSkillsVersion(baseUrl) {
6912
7026
  }
6913
7027
  function writeLocalSkillsVersion(baseUrl, version) {
6914
7028
  const path = sdkSkillsVersionPath(baseUrl);
6915
- mkdirSync4(dirname7(path), { recursive: true });
7029
+ mkdirSync5(dirname7(path), { recursive: true });
6916
7030
  writeFileSync6(path, `${version}
6917
7031
  `, "utf-8");
6918
7032
  }
@@ -6993,11 +7107,12 @@ async function syncSdkSkillsIfNeeded(baseUrl) {
6993
7107
  const localVersion = readLocalSkillsVersion(baseUrl);
6994
7108
  const update = await fetchSkillsUpdate(baseUrl, localVersion);
6995
7109
  if (!update?.needsUpdate || !update.remoteVersion) return;
6996
- process.stderr.write("SDK skills changed; syncing deepline-sdk skill...\n");
7110
+ const progress = getActiveCliProgress();
7111
+ progress?.writeLine("SDK skills changed; syncing deepline-sdk skill...") ?? process.stderr.write("SDK skills changed; syncing deepline-sdk skill...\n");
6997
7112
  const installed = await runSkillsInstall(baseUrl);
6998
7113
  if (!installed) return;
6999
7114
  writeLocalSkillsVersion(baseUrl, update.remoteVersion);
7000
- process.stderr.write("SDK skills are up to date.\n");
7115
+ progress?.writeLine("SDK skills are up to date.") ?? process.stderr.write("SDK skills are up to date.\n");
7001
7116
  }
7002
7117
 
7003
7118
  // src/cli/index.ts
@@ -7098,6 +7213,7 @@ Output:
7098
7213
  ok: false,
7099
7214
  error: error instanceof Error ? error.message : String(error)
7100
7215
  });
7216
+ progress?.fail();
7101
7217
  if (process.argv.includes("--json")) {
7102
7218
  printJsonError(error);
7103
7219
  } else if (error instanceof Error) {