deepline 0.1.11 → 0.1.12

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 (34) hide show
  1. package/README.md +4 -4
  2. package/dist/cli/index.js +509 -353
  3. package/dist/cli/index.js.map +1 -1
  4. package/dist/cli/index.mjs +513 -358
  5. package/dist/cli/index.mjs.map +1 -1
  6. package/dist/index.d.mts +250 -307
  7. package/dist/index.d.ts +250 -307
  8. package/dist/index.js +174 -315
  9. package/dist/index.js.map +1 -1
  10. package/dist/index.mjs +174 -314
  11. package/dist/index.mjs.map +1 -1
  12. package/dist/repo/apps/play-runner-workers/src/coordinator-entry.ts +23 -13
  13. package/dist/repo/apps/play-runner-workers/src/entry.ts +581 -1220
  14. package/dist/repo/sdk/src/cli/commands/play.ts +381 -247
  15. package/dist/repo/sdk/src/cli/commands/tools.ts +1 -1
  16. package/dist/repo/sdk/src/cli/dataset-stats.ts +86 -12
  17. package/dist/repo/sdk/src/client.ts +54 -51
  18. package/dist/repo/sdk/src/index.ts +7 -16
  19. package/dist/repo/sdk/src/play.ts +122 -140
  20. package/dist/repo/sdk/src/plays/bundle-play-file.ts +6 -3
  21. package/dist/repo/sdk/src/tool-output.ts +0 -146
  22. package/dist/repo/sdk/src/types.ts +2 -0
  23. package/dist/repo/sdk/src/version.ts +1 -1
  24. package/dist/repo/sdk/src/worker-play-entry.ts +3 -0
  25. package/dist/repo/shared_libs/play-runtime/context.ts +510 -267
  26. package/dist/repo/shared_libs/play-runtime/csv-rename.ts +180 -0
  27. package/dist/repo/shared_libs/play-runtime/ctx-types.ts +13 -1
  28. package/dist/repo/shared_libs/play-runtime/tool-result.ts +139 -114
  29. package/dist/repo/shared_libs/plays/bundling/index.ts +68 -5
  30. package/dist/repo/shared_libs/plays/compiler-manifest.ts +1 -1
  31. package/dist/repo/shared_libs/plays/dataset.ts +1 -1
  32. package/dist/repo/shared_libs/plays/runtime-validation.ts +8 -28
  33. package/package.json +1 -1
  34. package/dist/repo/apps/play-runner-workers/src/runtime/tool-result.ts +0 -184
package/dist/index.d.ts CHANGED
@@ -603,6 +603,8 @@ interface PlayDescription {
603
603
  aliases: string[];
604
604
  inputSchema?: Record<string, unknown> | null;
605
605
  outputSchema?: Record<string, unknown> | null;
606
+ csvInput?: Record<string, unknown> | null;
607
+ rowOutputSchema?: Record<string, unknown> | null;
606
608
  runCommand: string;
607
609
  examples: string[];
608
610
  currentPublishedVersion?: number | null;
@@ -793,6 +795,16 @@ interface PlayStagedFileRef {
793
795
  bytes: number;
794
796
  }
795
797
 
798
+ type ToolExecution<TData = unknown, TMeta = Record<string, unknown>> = {
799
+ status: string;
800
+ job_id?: string;
801
+ result: {
802
+ data: TData;
803
+ meta?: TMeta;
804
+ };
805
+ billing?: Record<string, unknown>;
806
+ [key: string]: unknown;
807
+ };
796
808
  /**
797
809
  * Low-level client for the Deepline REST API.
798
810
  *
@@ -824,6 +836,7 @@ declare class DeeplineClient {
824
836
  /** The resolved base URL this client is targeting (e.g. `"http://localhost:3000"`). */
825
837
  get baseUrl(): string;
826
838
  private compactSchema;
839
+ private schemaMetadata;
827
840
  private playRunCommand;
828
841
  private summarizePlayListItem;
829
842
  private summarizePlayDetail;
@@ -861,44 +874,14 @@ declare class DeeplineClient {
861
874
  */
862
875
  getTool(toolId: string): Promise<ToolMetadata>;
863
876
  /**
864
- * Execute a tool and return the extracted result.
877
+ * Execute a tool and return the standard execution envelope.
865
878
  *
866
- * Sends the input payload to the tool and returns the `.result` field from the
867
- * response. For the full response envelope (including job_id, credits, etc.),
868
- * use {@link executeToolRaw}.
869
- *
870
- * @param toolId - Tool identifier (e.g. `"test_company_search"`)
871
- * @param input - Tool-specific input parameters
872
- * @returns The tool's output (shape varies by tool)
873
- * @throws {@link DeeplineError} if the tool execution fails
874
- *
875
- * @example
876
- * ```typescript
877
- * const company = await client.executeTool('test_company_search', {
878
- * domain: 'stripe.com',
879
- * });
880
- * console.log(company); // { name: "Stripe", industry: "Financial Services", ... }
881
- * ```
879
+ * The `result.data` field contains the provider payload. `result.meta`
880
+ * contains provider/upstream metadata such as HTTP status or paging details.
881
+ * Top-level fields such as `status`, `job_id`, and `billing` describe the
882
+ * Deepline execution.
882
883
  */
883
- executeTool(toolId: string, input: Record<string, unknown>): Promise<unknown>;
884
- /**
885
- * Execute a tool and return the full response envelope.
886
- *
887
- * Unlike {@link executeTool}, this returns the complete API response including
888
- * `job_id`, `status`, `credits`, and the raw `result` object.
889
- *
890
- * @param toolId - Tool identifier
891
- * @param input - Tool-specific input parameters
892
- * @returns Full response with job metadata and result
893
- *
894
- * @example
895
- * ```typescript
896
- * const raw = await client.executeToolRaw('test_company_search', { domain: 'stripe.com' });
897
- * console.log(`Job: ${raw.job_id}, Credits: ${raw.credits}`);
898
- * console.log(`Result:`, raw.result);
899
- * ```
900
- */
901
- executeToolRaw(toolId: string, input: Record<string, unknown>): Promise<Record<string, unknown>>;
884
+ executeTool<TData = unknown, TMeta = Record<string, unknown>>(toolId: string, input: Record<string, unknown>): Promise<ToolExecution<TData, TMeta>>;
902
885
  queryCustomerDb(input: {
903
886
  sql: string;
904
887
  maxRows?: number;
@@ -1325,7 +1308,7 @@ declare class DeeplineClient {
1325
1308
  }>;
1326
1309
  }
1327
1310
 
1328
- declare const SDK_VERSION = "0.1.11";
1311
+ declare const SDK_VERSION = "0.1.12";
1329
1312
  declare const SDK_API_CONTRACT = "2026-04-plays-v1";
1330
1313
 
1331
1314
  /**
@@ -1468,164 +1451,6 @@ declare const PROD_URL = "https://code.deepline.com";
1468
1451
  */
1469
1452
  declare function resolveConfig(options?: DeeplineClientOptions): ResolvedConfig;
1470
1453
 
1471
- /**
1472
- * Result of converting a tool response to a list of records.
1473
- *
1474
- * @example
1475
- * ```typescript
1476
- * const conversion = tryConvertToList(toolResponse, {
1477
- * listExtractorPaths: ['people', 'result.data'],
1478
- * });
1479
- * if (conversion) {
1480
- * console.log(`Found ${conversion.rows.length} rows via ${conversion.strategy}`);
1481
- * console.log(`Source path: ${conversion.sourcePath}`);
1482
- * }
1483
- * ```
1484
- */
1485
- type ListConversionResult = {
1486
- /** Normalized array of record objects. Scalars are wrapped as `{ value: <scalar> }`. */
1487
- rows: Array<Record<string, unknown>>;
1488
- /**
1489
- * How the list was found:
1490
- * - `'configured_paths'` — matched one of the `listExtractorPaths`
1491
- * - `'auto_detected'` — found via recursive DFS (longest array wins)
1492
- */
1493
- strategy: 'configured_paths' | 'auto_detected';
1494
- /** Dotted path to where the list was found (e.g. `"result.data"`, `"people"`). */
1495
- sourcePath: string | null;
1496
- };
1497
- type Scalar = string | number | boolean | null;
1498
- /** Ergonomic wrapper returned by high-level SDK tool execution. */
1499
- type ToolCallResult = {
1500
- /** Raw tool response. Use this when a provider-specific shape matters. */
1501
- readonly value: unknown;
1502
- /** Best-effort email extraction from common response shapes. */
1503
- getEmail(): string | null;
1504
- /** Best-effort phone extraction from common response shapes. */
1505
- getPhone(): string | null;
1506
- /** Best-effort list extraction. Returns rows only; use `tryConvertToList` for metadata. */
1507
- tryList(options?: {
1508
- listExtractorPaths?: string[];
1509
- }): Array<Record<string, unknown>> | null;
1510
- };
1511
- /** Wrap a raw tool response with the high-level SDK result API. */
1512
- declare function createToolCallResult(value: unknown, options?: {
1513
- listExtractorPaths?: string[];
1514
- }): ToolCallResult;
1515
- /**
1516
- * Extract a list of records from a tool response.
1517
- *
1518
- * Handles the common problem of tools returning data in varied shapes.
1519
- * First tries configured `listExtractorPaths` (from tool metadata), then
1520
- * falls back to automatic detection via recursive DFS.
1521
- *
1522
- * ## Extraction strategy
1523
- *
1524
- * 1. **Configured paths** — If `listExtractorPaths` is provided, each path is
1525
- * tried against multiple candidate roots (raw payload, `.result`, `.result.data`).
1526
- * First match wins.
1527
- *
1528
- * 2. **Auto-detection** — If no configured path matches, recursively searches
1529
- * the response for the largest array of objects (up to depth 5).
1530
- *
1531
- * @param payload - Raw tool response
1532
- * @param options - Optional extraction configuration
1533
- * @returns Extracted list with metadata, or `null` if no list found
1534
- *
1535
- * @example Using configured paths (from tool metadata)
1536
- * ```typescript
1537
- * const meta = await client.getTool('apollo_people_search');
1538
- * const result = await client.executeTool('apollo_people_search', { query: 'cto' });
1539
- *
1540
- * const list = tryConvertToList(result, {
1541
- * listExtractorPaths: meta.listExtractorPaths,
1542
- * });
1543
- * if (list) {
1544
- * console.log(`${list.rows.length} people found via ${list.strategy}`);
1545
- * // Write to CSV
1546
- * const csv = writeCsvOutputFile(list.rows, 'apollo-people');
1547
- * console.log(`Saved to ${csv.path}`);
1548
- * }
1549
- * ```
1550
- *
1551
- * @example Auto-detection (no configured paths)
1552
- * ```typescript
1553
- * const result = await client.executeTool('some_tool', { query: 'test' });
1554
- * const list = tryConvertToList(result);
1555
- * // Finds the largest array of objects anywhere in the response
1556
- * ```
1557
- */
1558
- declare function tryConvertToList(payload: unknown, options?: {
1559
- listExtractorPaths?: string[];
1560
- }): ListConversionResult | null;
1561
- /**
1562
- * Write a JSON payload to a timestamped file.
1563
- *
1564
- * Output location: `~/.local/share/deepline/data/{stem}_{timestamp}.json`
1565
- *
1566
- * @param payload - Any JSON-serializable value
1567
- * @param stem - Filename prefix (e.g. tool ID or play name)
1568
- * @returns Absolute path to the written file
1569
- *
1570
- * @example
1571
- * ```typescript
1572
- * const result = await client.executeTool('test_company_search', { domain: 'stripe.com' });
1573
- * const path = writeJsonOutputFile(result, 'test_company_search');
1574
- * console.log(`Saved to ${path}`);
1575
- * // ~/.local/share/deepline/data/test_company_search_1713456789000.json
1576
- * ```
1577
- */
1578
- declare function writeJsonOutputFile(payload: unknown, stem: string): string;
1579
- /**
1580
- * Write an array of records to a CSV file.
1581
- *
1582
- * Columns are ordered by first appearance across all rows. Cells containing
1583
- * commas, quotes, or newlines are properly escaped. Objects and arrays are
1584
- * JSON-serialized.
1585
- *
1586
- * Output location: `~/.local/share/deepline/data/{stem}_{timestamp}.csv`
1587
- *
1588
- * @param rows - Array of record objects
1589
- * @param stem - Filename prefix
1590
- * @returns File metadata including path, row count, columns, and a 5×5 preview
1591
- *
1592
- * @example
1593
- * ```typescript
1594
- * const list = tryConvertToList(toolResponse);
1595
- * if (list) {
1596
- * const csv = writeCsvOutputFile(list.rows, 'search-results');
1597
- * console.log(`Wrote ${csv.rowCount} rows, ${csv.columns.length} columns`);
1598
- * console.log(`File: ${csv.path}`);
1599
- * console.log(`Preview:\n${csv.preview}`);
1600
- * }
1601
- * ```
1602
- */
1603
- declare function writeCsvOutputFile(rows: Array<Record<string, unknown>>, stem: string): {
1604
- path: string;
1605
- rowCount: number;
1606
- columns: string[];
1607
- preview: string;
1608
- };
1609
- /**
1610
- * Extract scalar (non-nested) fields from a tool response for summary display.
1611
- *
1612
- * Searches through candidate roots (raw → `.result` → `.result.data`) and
1613
- * returns the first set of scalar fields found. Useful for displaying a
1614
- * quick summary of single-record responses.
1615
- *
1616
- * @param payload - Raw tool response
1617
- * @returns Object containing only scalar fields (string, number, boolean, null)
1618
- *
1619
- * @example
1620
- * ```typescript
1621
- * const result = await client.executeTool('test_company_search', { domain: 'stripe.com' });
1622
- * const summary = extractSummaryFields(result);
1623
- * // { name: "Stripe", industry: "Financial Services", employeeCount: 8000 }
1624
- * // (nested objects and arrays are excluded)
1625
- * ```
1626
- */
1627
- declare function extractSummaryFields(payload: unknown): Record<string, Scalar>;
1628
-
1629
1454
  interface PlayR2FileRef {
1630
1455
  storageKind: 'r2';
1631
1456
  storageKey: string;
@@ -1733,45 +1558,31 @@ type PlayBindings = {
1733
1558
  type LoosePlayObject = {
1734
1559
  [key: string]: LoosePlayObject;
1735
1560
  };
1561
+ type ToolExtractedValue<T = unknown> = {
1562
+ path: string;
1563
+ get(): T | null;
1564
+ };
1565
+ type ToolResultEnvelope<TData = unknown, TMeta = Record<string, unknown>> = {
1566
+ data: TData;
1567
+ meta?: TMeta;
1568
+ };
1569
+ type ToolExecuteResult<TData = unknown, TMeta = Record<string, unknown>> = {
1570
+ status: string;
1571
+ result: ToolResultEnvelope<TData, TMeta>;
1572
+ extracted: Record<string, ToolExtractedValue>;
1573
+ lists: Record<string, {
1574
+ path: string;
1575
+ count: number | null;
1576
+ keys: Record<string, string>;
1577
+ get(): Record<string, unknown>[];
1578
+ }>;
1579
+ };
1736
1580
  type ToolExecutionRequest = {
1737
1581
  id: string;
1738
1582
  tool: string;
1739
1583
  input: Record<string, unknown>;
1740
1584
  description?: string;
1741
1585
  };
1742
- type SdkToolExecutionRequest = {
1743
- tool: string;
1744
- input: Record<string, unknown>;
1745
- };
1746
- type ToolExecuteResult<TResult = unknown> = {
1747
- status: string;
1748
- result: TResult;
1749
- _metadata: {
1750
- toolId: string;
1751
- execution: {
1752
- idempotent: true;
1753
- cached: boolean;
1754
- source: 'live' | 'checkpoint' | 'cache';
1755
- cacheKey?: string;
1756
- };
1757
- targets: Record<string, {
1758
- value: unknown;
1759
- path: string;
1760
- }>;
1761
- lists: Record<string, {
1762
- path: string;
1763
- count: number | null;
1764
- keys: Record<string, string>;
1765
- }>;
1766
- };
1767
- get<T = unknown>(target: string): T | null;
1768
- getEmail(): string | null;
1769
- getPhone(): string | null;
1770
- getLinkedin(): string | null;
1771
- list<T = Record<string, unknown>>(name?: string): T[] | null;
1772
- listPick<const TKeys extends readonly string[]>(keys: TKeys, name?: string): Array<Record<TKeys[number], unknown>> | null;
1773
- listKeys(name?: string): Record<string, string>;
1774
- };
1775
1586
  type StepResolver<Row, Value> = (row: Row, ctx: DeeplinePlayRuntimeContext, index: number) => Value | Promise<Value>;
1776
1587
  type ConditionalStepResolver<Row, Value, Else = null> = {
1777
1588
  readonly kind: 'conditional';
@@ -1799,17 +1610,40 @@ type PlayStepProgramStep = {
1799
1610
  readonly resolver: StepResolver<Record<string, unknown>, unknown> | ConditionalStepResolver<Record<string, unknown>, unknown> | StepProgramResolver<Record<string, unknown>, unknown>;
1800
1611
  };
1801
1612
  type MapStepResolver<Row, Value> = StepResolver<Row, Value> | ConditionalStepResolver<Row, Value> | StepProgramResolver<Row, Value>;
1802
- type MapRowKey<InputRow extends object> = (keyof InputRow & string) | readonly (keyof InputRow & string)[] | ((row: InputRow, index: number) => string | number | readonly unknown[]);
1803
- type MapDefinitionOptions<InputRow extends object> = {
1804
- staleAfterSeconds?: number;
1805
- key?: MapRowKey<InputRow>;
1806
- };
1807
- type MapRunOptions = {
1808
- description?: string;
1809
- };
1810
1613
  type MapStepBuilder<InputRow extends object, OutputRow extends object> = {
1811
1614
  step<Name extends string, Value>(name: Name, resolver: MapStepResolver<OutputRow, Value>): MapStepBuilder<InputRow, OutputRow & Record<Name, Value>>;
1812
- run(options?: MapRunOptions): Promise<PlayDataset<OutputRow>>;
1615
+ run(options?: {
1616
+ description?: string;
1617
+ staleAfterSeconds?: number;
1618
+ concurrency?: number;
1619
+ key?: (keyof InputRow & string) | readonly (keyof InputRow & string)[] | ((row: InputRow, index: number) => string | number | readonly unknown[]);
1620
+ }): Promise<PlayDataset<OutputRow>>;
1621
+ };
1622
+ type CsvRenameMap = Record<string, string | readonly string[]>;
1623
+ /**
1624
+ * Runtime file-like input. At runtime this is the staged file path/reference
1625
+ * string. The type parameter carries static metadata for describe/CLI tooling.
1626
+ */
1627
+ type FileInput<TMetadata = unknown> = string & {
1628
+ readonly __deeplineFileInputMetadata?: TMetadata;
1629
+ };
1630
+ /**
1631
+ * CSV file input whose rows are described by `TRow`.
1632
+ *
1633
+ * The CLI should expose this as the field name from the play input object,
1634
+ * stage local paths passed to that flag, and use `TRow` for row-contract
1635
+ * discovery.
1636
+ */
1637
+ type CsvInput<TRow extends object = Record<string, unknown>> = FileInput<{
1638
+ readonly kind: 'csv';
1639
+ readonly row: TRow;
1640
+ }>;
1641
+ type ColumnMap<TRow extends object> = Partial<Record<Extract<keyof TRow, string>, string | readonly string[]>>;
1642
+ type CsvOptions = {
1643
+ description?: string;
1644
+ columns?: CsvRenameMap;
1645
+ rename?: CsvRenameMap;
1646
+ required?: readonly string[];
1813
1647
  };
1814
1648
  /**
1815
1649
  * Runtime context available inside a play function.
@@ -1821,21 +1655,15 @@ type MapStepBuilder<InputRow extends object, OutputRow extends object> = {
1821
1655
  * ```typescript
1822
1656
  * definePlay('example', async (ctx, input: { domain: string }) => {
1823
1657
  * // Call a tool
1824
- * const company = await ctx.tools.execute({
1825
- * id: 'company_search',
1826
- * tool: 'test_company_search',
1827
- * input: { domain: input.domain },
1658
+ * const company = await ctx.tools.execute('company_search', 'test_company_search', { domain: input.domain }, {
1828
1659
  * description: 'Look up company details by domain.',
1829
1660
  * });
1830
1661
  *
1831
1662
  * // Fan-out: process items with named steps
1832
1663
  * const enriched = await ctx
1833
- * .map('companies', [{ domain: 'a.com' }, { domain: 'b.com' }], { key: 'domain' })
1664
+ * .map('companies', [{ domain: 'a.com' }, { domain: 'b.com' }])
1834
1665
  * .step('company', (row, rowCtx) =>
1835
- * rowCtx.tool({
1836
- * id: 'company_search',
1837
- * tool: 'test_company_search',
1838
- * input: { domain: row.domain },
1666
+ * rowCtx.tool('company_search', 'test_company_search', { domain: row.domain }, {
1839
1667
  * description: 'Look up company details by domain.',
1840
1668
  * }))
1841
1669
  * .run({ description: 'Look up company details.' });
@@ -1870,9 +1698,7 @@ interface DeeplinePlayRuntimeContext {
1870
1698
  *
1871
1699
  * @returns Parsed dataset rows
1872
1700
  */
1873
- csv<T = Record<string, unknown>>(path: string, options?: {
1874
- description?: string;
1875
- }): Promise<PlayDataset<T>>;
1701
+ csv<T = Record<string, unknown>>(path: string, options?: CsvOptions): Promise<PlayDataset<T>>;
1876
1702
  /**
1877
1703
  * Fan-out: process each item through one or more named columns.
1878
1704
  *
@@ -1881,9 +1707,8 @@ interface DeeplinePlayRuntimeContext {
1881
1707
  * play context — call tools, run waterfalls, do arbitrary logic.
1882
1708
  *
1883
1709
  * Items are processed in parallel (paced by the rate-limit scheduler).
1884
- * The first argument identifies the logical map/table namespace. Use
1885
- * `options.key` to pin durable row identity to stable input fields instead of
1886
- * hashing the full input row.
1710
+ * `key` identifies the logical output dataset/table. Row identity is derived
1711
+ * automatically from item content unless advanced run options override it.
1887
1712
  * `options.staleAfterSeconds` intentionally partitions the durable cache on a
1888
1713
  * relative time window. Use `86400` for daily reruns; retries inside the same
1889
1714
  * window still replay safely.
@@ -1893,19 +1718,16 @@ interface DeeplinePlayRuntimeContext {
1893
1718
  * play dataset handle.
1894
1719
  *
1895
1720
  * @typeParam T - Row type
1896
- * @param key - Logical map key used to isolate row identities (e.g. `'main_table'`, `'email_lookup'`)
1721
+ * @param key - Logical output dataset/table name (e.g. `'companies'`, `'email_lookup'`)
1897
1722
  * @param items - Input rows or dataset handle
1898
1723
  * @returns Dataset of rows merged with the computed column values
1899
1724
  *
1900
1725
  * @example Single tool per row
1901
1726
  * ```typescript
1902
1727
  * const results = await ctx
1903
- * .map('leads', leads, { key: 'domain' })
1728
+ * .map('companies', leads)
1904
1729
  * .step('company', (row, ctx) =>
1905
- * ctx.tools.execute({
1906
- * id: 'company_search',
1907
- * tool: 'test_company_search',
1908
- * input: { domain: row.domain },
1730
+ * ctx.tools.execute('company_search', 'test_company_search', { domain: row.domain }, {
1909
1731
  * description: 'Look up company details by domain.',
1910
1732
  * }))
1911
1733
  * .run({ description: 'Look up companies.' });
@@ -1915,12 +1737,9 @@ interface DeeplinePlayRuntimeContext {
1915
1737
  * @example Multiple columns with pre/post logic
1916
1738
  * ```typescript
1917
1739
  * const results = await ctx
1918
- * .map('leads', leads, { key: 'lead_id' })
1740
+ * .map('leads', leads)
1919
1741
  * .step('company', (row, ctx) =>
1920
- * ctx.tools.execute({
1921
- * id: 'company_search',
1922
- * tool: 'test_company_search',
1923
- * input: { domain: row.domain },
1742
+ * ctx.tools.execute('company_search', 'test_company_search', { domain: row.domain }, {
1924
1743
  * description: 'Look up company details by domain.',
1925
1744
  * }))
1926
1745
  * .step('score', (row) =>
@@ -1928,25 +1747,31 @@ interface DeeplinePlayRuntimeContext {
1928
1747
  * .run({ description: 'Enrich leads.' });
1929
1748
  * ```
1930
1749
  */
1931
- map<TItem extends object>(key: string, items: PlayDatasetInput<TItem>, options?: MapDefinitionOptions<TItem>): MapStepBuilder<TItem, TItem>;
1750
+ map<TItem extends object>(key: string, items: PlayDatasetInput<TItem>): MapStepBuilder<TItem, TItem>;
1932
1751
  /** Tool execution namespace. */
1933
1752
  tools: {
1934
1753
  /**
1935
- * Execute a single tool by stable durable execution id and tool ID.
1754
+ * Execute a single tool by stable step key and tool ID.
1936
1755
  *
1937
- * @param request - Tool execution request. `id` is the durable execution id;
1938
- * omit it in row/map steps when the surrounding step id is the execution id.
1756
+ * @param key - Stable step key for idempotent execution
1757
+ * @param toolId - Tool identifier (e.g. `'test_company_search'`)
1758
+ * @param input - Tool-specific input parameters
1939
1759
  * @returns The tool's output
1940
1760
  */
1941
1761
  execute<TOutput = LoosePlayObject>(request: ToolExecutionRequest): Promise<ToolExecuteResult<TOutput>>;
1762
+ execute<TOutput = LoosePlayObject>(key: string, toolId: string, input: Record<string, unknown>, options?: {
1763
+ description?: string;
1764
+ }): Promise<ToolExecuteResult<TOutput>>;
1942
1765
  };
1943
1766
  /**
1944
- * Execute a single tool by stable durable execution id and tool ID.
1767
+ * Execute a single tool by stable step key and tool ID.
1945
1768
  *
1946
- * Shorthand for `ctx.tools.execute({ id, tool, input })`; this is the
1947
- * preferred spelling in row-level step programs.
1769
+ * Shorthand for `ctx.tools.execute(...)`; this is the preferred spelling in
1770
+ * row-level step programs.
1948
1771
  */
1949
- tool<TOutput = LoosePlayObject>(request: ToolExecutionRequest): Promise<ToolExecuteResult<TOutput>>;
1772
+ tool<TOutput = LoosePlayObject>(key: string, toolId: string, input: Record<string, unknown>, options?: {
1773
+ description?: string;
1774
+ }): Promise<ToolExecuteResult<TOutput>>;
1950
1775
  step<T>(id: string, run: () => T | Promise<T>): Promise<T>;
1951
1776
  fetch(key: string, url: string | URL, init?: RequestInit): Promise<{
1952
1777
  ok: boolean;
@@ -2164,13 +1989,9 @@ declare function when<Row, Value>(predicate: (row: Row, index: number) => boolea
2164
1989
  * import { definePlay } from 'deepline';
2165
1990
  *
2166
1991
  * const myPlay = definePlay('my-play', async (ctx, input: { domain: string }) => {
2167
- * const company = await ctx.tools.execute({
2168
- * id: 'company_search',
2169
- * tool: 'test_company_search',
2170
- * input: { domain: input.domain },
1992
+ * return await ctx.tools.execute('company_search', 'test_company_search', { domain: input.domain }, {
2171
1993
  * description: 'Look up company details by domain.',
2172
1994
  * });
2173
- * return { company: company.result };
2174
1995
  * });
2175
1996
  *
2176
1997
  * // Type is: DefinedPlay<{ domain: string }, unknown>
@@ -2208,10 +2029,7 @@ type PlayMetadata = {
2208
2029
  *
2209
2030
  * // Tools
2210
2031
  * const tools = await ctx.tools.list();
2211
- * const result = await ctx.tools.execute({
2212
- * tool: 'test_company_search',
2213
- * input: { domain: 'stripe.com' },
2214
- * });
2032
+ * const result = await ctx.tools.execute('test_company_search', { domain: 'stripe.com' });
2215
2033
  *
2216
2034
  * // Plays
2217
2035
  * const job = await ctx.play('email-waterfall').run({ domain: 'stripe.com' });
@@ -2228,12 +2046,8 @@ declare class DeeplineContext {
2228
2046
  * ```typescript
2229
2047
  * const tools = await ctx.tools.list();
2230
2048
  * const meta = await ctx.tools.get('apollo_people_search');
2231
- * const result = await ctx.tools.execute({
2232
- * tool: 'test_company_search',
2233
- * input: { domain: 'stripe.com' },
2234
- * });
2235
- * const rows = result.tryList({ listExtractorPaths: ['people'] });
2236
- * const email = result.getEmail();
2049
+ * const companyLookup = await ctx.tools.execute('test_company_search', { domain: 'stripe.com' });
2050
+ * const company = companyLookup.result.data;
2237
2051
  * ```
2238
2052
  */
2239
2053
  get tools(): {
@@ -2241,8 +2055,8 @@ declare class DeeplineContext {
2241
2055
  list: () => Promise<ToolDefinition[]>;
2242
2056
  /** Get detailed metadata for a tool. */
2243
2057
  get: (toolId: string) => Promise<ToolMetadata>;
2244
- /** Execute a tool and return an ergonomic result wrapper. */
2245
- execute: (request: SdkToolExecutionRequest) => Promise<ToolCallResult>;
2058
+ /** Execute a tool and return the standard execution envelope. */
2059
+ execute: (toolId: string, input: Record<string, unknown>) => Promise<ToolExecuteResult>;
2246
2060
  };
2247
2061
  get plays(): {
2248
2062
  list: () => Promise<PlayListItem[]>;
@@ -2276,10 +2090,7 @@ declare class DeeplineContext {
2276
2090
  *
2277
2091
  * const ctx = await Deepline.connect();
2278
2092
  * const tools = await ctx.tools.list();
2279
- * const result = await ctx.tools.execute({
2280
- * tool: 'test_company_search',
2281
- * input: { domain: 'stripe.com' },
2282
- * });
2093
+ * const result = await ctx.tools.execute('test_company_search', { domain: 'stripe.com' });
2283
2094
  * ```
2284
2095
  */
2285
2096
  declare class Deepline {
@@ -2331,13 +2142,10 @@ declare function defineInput<TInput>(schema: Record<string, unknown>): PlayInput
2331
2142
  *
2332
2143
  * export default definePlay('company-lookup', async (ctx, input: { domain: string }) => {
2333
2144
  * ctx.log(`Searching for ${input.domain}`);
2334
- * const company = await ctx.tools.execute({
2335
- * id: 'company_search',
2336
- * tool: 'test_company_search',
2337
- * input: { domain: input.domain },
2145
+ * const company = await ctx.tools.execute('company_search', 'test_company_search', { domain: input.domain }, {
2338
2146
  * description: 'Look up company details by domain.',
2339
2147
  * });
2340
- * return { company: company.result };
2148
+ * return company;
2341
2149
  * });
2342
2150
  * ```
2343
2151
  *
@@ -2347,12 +2155,9 @@ declare function defineInput<TInput>(schema: Record<string, unknown>): PlayInput
2347
2155
  * const leads = await ctx.csv('leads.csv');
2348
2156
  * ctx.log(`Processing ${leads.length} rows`);
2349
2157
  * const results = await ctx
2350
- * .map('domain', leads)
2158
+ * .map('companies', leads)
2351
2159
  * .step('company', (row, ctx) =>
2352
- * ctx.tools.execute({
2353
- * id: 'company_search',
2354
- * tool: 'test_company_search',
2355
- * input: { domain: row.domain },
2160
+ * ctx.tools.execute('company_search', 'test_company_search', { domain: row.domain }, {
2356
2161
  * description: 'Look up company details by domain.',
2357
2162
  * }))
2358
2163
  * .run({ description: 'Enrich lead companies.' });
@@ -2363,10 +2168,7 @@ declare function defineInput<TInput>(schema: Record<string, unknown>): PlayInput
2363
2168
  * @example With cron binding
2364
2169
  * ```typescript
2365
2170
  * export default definePlay('daily-report', async (ctx) => {
2366
- * const data = await ctx.tools.execute({
2367
- * id: 'crm_export',
2368
- * tool: 'crm_export',
2369
- * input: { since: 'yesterday' },
2171
+ * const data = await ctx.tools.execute('crm_export', 'crm_export', { since: 'yesterday' }, {
2370
2172
  * description: 'Export yesterday CRM records.',
2371
2173
  * });
2372
2174
  * return data;
@@ -2421,4 +2223,145 @@ declare const defineWorkflow: typeof definePlay;
2421
2223
  */
2422
2224
  declare function getDefinedPlayMetadata(value: unknown): PlayMetadata | null;
2423
2225
 
2424
- export { AuthError, type ClearPlayHistoryRequest, type ClearPlayHistoryResult, type ConditionalStepResolver, ConfigError, Deepline, DeeplineClient, type DeeplineClientOptions, DeeplineContext, DeeplineError, type DeeplineNamedPlay, type DeeplinePlayRuntimeContext, type DefinePlayConfig, type DefinedPlay, type LiveEventEnvelope, type MapDefinitionOptions, type MapRowKey, type MapRunOptions, type MapStepBuilder, type MapStepResolver, PROD_URL, type PlayBindings, type PlayDataset, type PlayDatasetInput, type PlayInputContract, type PlayJob, type PlayListItem, type PlayLiveEvent, type PlayRevisionSummary, type PlayRunResult, type PlayRunStart, type PlayStatus, type PlayStepProgramStep, type PrebuiltPlayRef, type PublishPlayVersionRequest, type PublishPlayVersionResult, RateLimitError, type ResolvedConfig, SDK_API_CONTRACT, SDK_VERSION, type StartPlayRunRequest, type StepProgram, type StepProgramResolver, type StepResolver, type ToolCallResult, type ToolDefinition, type ToolExecuteResult, type ToolMetadata, createToolCallResult, defineInput, definePlay, defineWorkflow, extractSummaryFields, getDefinedPlayMetadata, resolveConfig, steps, tryConvertToList, when, writeCsvOutputFile, writeJsonOutputFile };
2226
+ /**
2227
+ * Result of converting a tool response to a list of records.
2228
+ *
2229
+ * @example
2230
+ * ```typescript
2231
+ * const conversion = tryConvertToList(toolResponse, {
2232
+ * listExtractorPaths: ['people', 'result.data'],
2233
+ * });
2234
+ * if (conversion) {
2235
+ * console.log(`Found ${conversion.rows.length} rows via ${conversion.strategy}`);
2236
+ * console.log(`Source path: ${conversion.sourcePath}`);
2237
+ * }
2238
+ * ```
2239
+ */
2240
+ type ListConversionResult = {
2241
+ /** Normalized array of record objects. Scalars are wrapped as `{ value: <scalar> }`. */
2242
+ rows: Array<Record<string, unknown>>;
2243
+ /**
2244
+ * How the list was found:
2245
+ * - `'configured_paths'` — matched one of the `listExtractorPaths`
2246
+ * - `'auto_detected'` — found via recursive DFS (longest array wins)
2247
+ */
2248
+ strategy: 'configured_paths' | 'auto_detected';
2249
+ /** Dotted path to where the list was found (e.g. `"result.data"`, `"people"`). */
2250
+ sourcePath: string | null;
2251
+ };
2252
+ type Scalar = string | number | boolean | null;
2253
+ /**
2254
+ * Extract a list of records from a tool response.
2255
+ *
2256
+ * Handles the common problem of tools returning data in varied shapes.
2257
+ * First tries configured `listExtractorPaths` (from tool metadata), then
2258
+ * falls back to automatic detection via recursive DFS.
2259
+ *
2260
+ * ## Extraction strategy
2261
+ *
2262
+ * 1. **Configured paths** — If `listExtractorPaths` is provided, each path is
2263
+ * tried against multiple candidate roots (raw payload, `.result`, `.result.data`).
2264
+ * First match wins.
2265
+ *
2266
+ * 2. **Auto-detection** — If no configured path matches, recursively searches
2267
+ * the response for the largest array of objects (up to depth 5).
2268
+ *
2269
+ * @param payload - Raw tool response
2270
+ * @param options - Optional extraction configuration
2271
+ * @returns Extracted list with metadata, or `null` if no list found
2272
+ *
2273
+ * @example Using configured paths (from tool metadata)
2274
+ * ```typescript
2275
+ * const meta = await client.getTool('apollo_people_search');
2276
+ * const result = await client.executeTool('apollo_people_search', { query: 'cto' });
2277
+ *
2278
+ * const list = tryConvertToList(result, {
2279
+ * listExtractorPaths: meta.listExtractorPaths,
2280
+ * });
2281
+ * if (list) {
2282
+ * console.log(`${list.rows.length} people found via ${list.strategy}`);
2283
+ * // Write to CSV
2284
+ * const csv = writeCsvOutputFile(list.rows, 'apollo-people');
2285
+ * console.log(`Saved to ${csv.path}`);
2286
+ * }
2287
+ * ```
2288
+ *
2289
+ * @example Auto-detection (no configured paths)
2290
+ * ```typescript
2291
+ * const result = await client.executeTool('some_tool', { query: 'test' });
2292
+ * const list = tryConvertToList(result);
2293
+ * // Finds the largest array of objects anywhere in the response
2294
+ * ```
2295
+ */
2296
+ declare function tryConvertToList(payload: unknown, options?: {
2297
+ listExtractorPaths?: string[];
2298
+ }): ListConversionResult | null;
2299
+ /**
2300
+ * Write a JSON payload to a timestamped file.
2301
+ *
2302
+ * Output location: `~/.local/share/deepline/data/{stem}_{timestamp}.json`
2303
+ *
2304
+ * @param payload - Any JSON-serializable value
2305
+ * @param stem - Filename prefix (e.g. tool ID or play name)
2306
+ * @returns Absolute path to the written file
2307
+ *
2308
+ * @example
2309
+ * ```typescript
2310
+ * const result = await client.executeTool('test_company_search', { domain: 'stripe.com' });
2311
+ * const path = writeJsonOutputFile(result, 'test_company_search');
2312
+ * console.log(`Saved to ${path}`);
2313
+ * // ~/.local/share/deepline/data/test_company_search_1713456789000.json
2314
+ * ```
2315
+ */
2316
+ declare function writeJsonOutputFile(payload: unknown, stem: string): string;
2317
+ /**
2318
+ * Write an array of records to a CSV file.
2319
+ *
2320
+ * Columns are ordered by first appearance across all rows. Cells containing
2321
+ * commas, quotes, or newlines are properly escaped. Objects and arrays are
2322
+ * JSON-serialized.
2323
+ *
2324
+ * Output location: `~/.local/share/deepline/data/{stem}_{timestamp}.csv`
2325
+ *
2326
+ * @param rows - Array of record objects
2327
+ * @param stem - Filename prefix
2328
+ * @returns File metadata including path, row count, columns, and a 5×5 preview
2329
+ *
2330
+ * @example
2331
+ * ```typescript
2332
+ * const list = tryConvertToList(toolResponse);
2333
+ * if (list) {
2334
+ * const csv = writeCsvOutputFile(list.rows, 'search-results');
2335
+ * console.log(`Wrote ${csv.rowCount} rows, ${csv.columns.length} columns`);
2336
+ * console.log(`File: ${csv.path}`);
2337
+ * console.log(`Preview:\n${csv.preview}`);
2338
+ * }
2339
+ * ```
2340
+ */
2341
+ declare function writeCsvOutputFile(rows: Array<Record<string, unknown>>, stem: string): {
2342
+ path: string;
2343
+ rowCount: number;
2344
+ columns: string[];
2345
+ preview: string;
2346
+ };
2347
+ /**
2348
+ * Extract scalar (non-nested) fields from a tool response for summary display.
2349
+ *
2350
+ * Searches through candidate roots (raw → `.result` → `.result.data`) and
2351
+ * returns the first set of scalar fields found. Useful for displaying a
2352
+ * quick summary of single-record responses.
2353
+ *
2354
+ * @param payload - Raw tool response
2355
+ * @returns Object containing only scalar fields (string, number, boolean, null)
2356
+ *
2357
+ * @example
2358
+ * ```typescript
2359
+ * const result = await client.executeTool('test_company_search', { domain: 'stripe.com' });
2360
+ * const summary = extractSummaryFields(result);
2361
+ * // { name: "Stripe", industry: "Financial Services", employeeCount: 8000 }
2362
+ * // (nested objects and arrays are excluded)
2363
+ * ```
2364
+ */
2365
+ declare function extractSummaryFields(payload: unknown): Record<string, Scalar>;
2366
+
2367
+ export { AuthError, type ClearPlayHistoryRequest, type ClearPlayHistoryResult, type ColumnMap, type ConditionalStepResolver, ConfigError, type CsvInput, Deepline, DeeplineClient, type DeeplineClientOptions, DeeplineContext, DeeplineError, type DeeplineNamedPlay, type DeeplinePlayRuntimeContext, type DefinePlayConfig, type DefinedPlay, type FileInput, type LiveEventEnvelope, type MapStepBuilder, type MapStepResolver, PROD_URL, type PlayBindings, type PlayDataset, type PlayDatasetInput, type PlayInputContract, type PlayJob, type PlayListItem, type PlayLiveEvent, type PlayRevisionSummary, type PlayRunResult, type PlayRunStart, type PlayStatus, type PlayStepProgramStep, type PrebuiltPlayRef, type PublishPlayVersionRequest, type PublishPlayVersionResult, RateLimitError, type ResolvedConfig, SDK_API_CONTRACT, SDK_VERSION, type StartPlayRunRequest, type StepProgram, type StepProgramResolver, type StepResolver, type ToolDefinition, type ToolExecuteResult, type ToolExecution, type ToolMetadata, defineInput, definePlay, defineWorkflow, extractSummaryFields, getDefinedPlayMetadata, resolveConfig, steps, tryConvertToList, when, writeCsvOutputFile, writeJsonOutputFile };