deepline 0.1.33 → 0.1.36

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.
package/dist/index.d.mts CHANGED
@@ -255,17 +255,51 @@ interface ToolDefinition {
255
255
  inputSchema?: Record<string, unknown>;
256
256
  /** JSON Schema describing the tool's output shape. */
257
257
  outputSchema?: Record<string, unknown>;
258
- /**
259
- * Dotted paths for extracting list data from the tool's response.
260
- *
261
- * Used by {@link tryConvertToList} to automatically find the array of results
262
- * in a nested response. Example: `["people", "result.data"]`.
263
- */
264
- listExtractorPaths?: string[];
265
- /** Field mappings for extracting identity fields (email, phone, etc.) from results. */
266
- resultIdentityGetters?: Record<string, string[]>;
267
- /** Whether the output is a direct object or wrapped in a `result` envelope. */
268
- rowContextShape?: 'direct' | 'result_envelope';
258
+ /** Copyable play-runtime guidance for V2 tool execution results. */
259
+ usageGuidance?: {
260
+ execute?: string;
261
+ toolExecutionResult?: {
262
+ type?: 'ToolExecutionResult';
263
+ toolResponse?: {
264
+ raw?: string;
265
+ meta?: string;
266
+ };
267
+ meta?: string;
268
+ extractedLists?: Array<{
269
+ name: string;
270
+ expression: string;
271
+ details?: {
272
+ strategy?: string;
273
+ rawToolOutputPaths?: string[];
274
+ candidatePaths?: string[];
275
+ };
276
+ }> | Record<string, {
277
+ expression: string;
278
+ details?: {
279
+ strategy?: string;
280
+ rawToolOutputPaths?: string[];
281
+ candidatePaths?: string[];
282
+ };
283
+ }>;
284
+ extractedValues?: Array<{
285
+ name: string;
286
+ expression: string;
287
+ details?: {
288
+ strategy?: string;
289
+ rawToolOutputPaths?: string[];
290
+ candidatePaths?: string[];
291
+ };
292
+ }> | Record<string, {
293
+ expression: string;
294
+ details?: {
295
+ strategy?: string;
296
+ rawToolOutputPaths?: string[];
297
+ candidatePaths?: string[];
298
+ };
299
+ }>;
300
+ [key: string]: unknown;
301
+ };
302
+ };
269
303
  /** Search relevance score returned by ranked tool search. */
270
304
  search_score?: number;
271
305
  /** Search match snippets returned by ranked tool search. */
@@ -822,10 +856,13 @@ type ExecuteToolRawOptions = {
822
856
  type ToolExecution<TData = unknown, TMeta = Record<string, unknown>> = {
823
857
  status: string;
824
858
  job_id?: string;
825
- result: {
826
- data: TData;
859
+ meta?: Record<string, unknown>;
860
+ toolResponse: {
861
+ raw: TData;
827
862
  meta?: TMeta;
828
863
  };
864
+ extractedLists?: Record<string, unknown>;
865
+ extractedValues?: Record<string, unknown>;
829
866
  billing?: Record<string, unknown>;
830
867
  [key: string]: unknown;
831
868
  };
@@ -967,10 +1004,10 @@ declare class DeeplineClient {
967
1004
  /**
968
1005
  * Execute a tool and return the standard execution envelope.
969
1006
  *
970
- * The `result.data` field contains the provider payload. `result.meta`
971
- * contains provider/upstream metadata such as HTTP status or paging details.
1007
+ * The `toolResponse.raw` field contains the raw tool response.
1008
+ * `toolResponse.meta` contains tool/provider metadata.
972
1009
  * Top-level fields such as `status`, `job_id`, and `billing` describe the
973
- * Deepline execution.
1010
+ * Deepline execution envelope.
974
1011
  */
975
1012
  executeTool<TData = unknown, TMeta = Record<string, unknown>>(toolId: string, input: Record<string, unknown>, options?: ExecuteToolRawOptions): Promise<ToolExecution<TData, TMeta>>;
976
1013
  executeToolRaw<TData = unknown, TMeta = Record<string, unknown>>(toolId: string, input: Record<string, unknown>, options?: ExecuteToolRawOptions): Promise<ToolExecution<TData, TMeta>>;
@@ -1440,8 +1477,8 @@ declare class DeeplineClient {
1440
1477
  }>;
1441
1478
  }
1442
1479
 
1443
- declare const SDK_VERSION = "0.1.33";
1444
- declare const SDK_API_CONTRACT = "2026-05-host-env-generic-play-input-flags";
1480
+ declare const SDK_VERSION = "0.1.36";
1481
+ declare const SDK_API_CONTRACT = "2026-05-v2-tool-response";
1445
1482
 
1446
1483
  /**
1447
1484
  * Base error class for all Deepline SDK errors.
@@ -1653,13 +1690,20 @@ type ToolResultTargetAccessor<T = unknown> = ToolResultTargetMetadata & {
1653
1690
  type ToolResultListAccessor<T = Record<string, unknown>> = ToolResultListMetadata & {
1654
1691
  get(): T[];
1655
1692
  };
1656
- type ToolResultEnvelope<TData = unknown, TMeta = Record<string, unknown>> = {
1657
- data: TData;
1693
+ type ToolResponseEnvelope<TData = unknown, TMeta = Record<string, unknown>> = {
1694
+ raw: TData;
1658
1695
  meta?: TMeta;
1659
1696
  };
1660
1697
  type ToolExecuteResultBase<TResult = unknown, TMeta = Record<string, unknown>> = {
1661
1698
  status: string;
1662
- result: ToolResultEnvelope<TResult, TMeta>;
1699
+ job_id?: string;
1700
+ /** Deepline-owned execution/result metadata. */
1701
+ meta?: Record<string, unknown>;
1702
+ toolResponse: ToolResponseEnvelope<TResult, TMeta>;
1703
+ extractedValues: Record<string, ToolResultTargetAccessor>;
1704
+ extractedLists: Record<string, ToolResultListAccessor>;
1705
+ /** Convenience alias for play code. Serialized output uses toolResponse. */
1706
+ toolOutput: ToolResponseEnvelope<TResult, TMeta>;
1663
1707
  _metadata: {
1664
1708
  toolId: string;
1665
1709
  execution: ToolResultExecutionMetadata;
@@ -1675,10 +1719,10 @@ type ToolExecuteResultBase<TResult = unknown, TMeta = Record<string, unknown>> =
1675
1719
  };
1676
1720
  };
1677
1721
  type ToolExecuteResultAccessors<TExtracted extends Record<string, unknown> = Record<string, unknown>, TLists extends Record<string, Record<string, unknown>> = Record<string, Record<string, unknown>>> = {
1678
- extracted: {
1722
+ extractedValues: {
1679
1723
  [K in keyof TExtracted]: ToolResultTargetAccessor<TExtracted[K]>;
1680
1724
  };
1681
- lists: {
1725
+ extractedLists: {
1682
1726
  [K in keyof TLists]: ToolResultListAccessor<TLists[K]>;
1683
1727
  };
1684
1728
  };
@@ -1817,7 +1861,10 @@ type CsvOptions = {
1817
1861
  * ```typescript
1818
1862
  * definePlay('example', async (ctx, input: { domain: string }) => {
1819
1863
  * // Call a tool
1820
- * const company = await ctx.tools.execute('company_search', 'test_company_search', { domain: input.domain }, {
1864
+ * const company = await ctx.tools.execute({
1865
+ * id: 'company_search',
1866
+ * tool: 'test_company_search',
1867
+ * input: { domain: input.domain },
1821
1868
  * description: 'Look up company details by domain.',
1822
1869
  * });
1823
1870
  *
@@ -1886,24 +1933,30 @@ interface DeeplinePlayRuntimeContext {
1886
1933
  *
1887
1934
  * @example Single tool per row
1888
1935
  * ```typescript
1889
- * const results = await ctx
1890
- * .map('companies', leads)
1891
- * .step('company', (row, ctx) =>
1892
- * ctx.tools.execute('company_search', 'test_company_search', { domain: row.domain }, {
1893
- * description: 'Look up company details by domain.',
1894
- * }))
1936
+ * const results = await ctx
1937
+ * .map('companies', leads)
1938
+ * .step('company', (row, ctx) =>
1939
+ * ctx.tools.execute({
1940
+ * id: 'company_search',
1941
+ * tool: 'test_company_search',
1942
+ * input: { domain: row.domain },
1943
+ * description: 'Look up company details by domain.',
1944
+ * }))
1895
1945
  * .run({ description: 'Look up companies.' });
1896
1946
  * // [{ domain: 'stripe.com', company: { name: 'Stripe', ... } }, ...]
1897
1947
  * ```
1898
1948
  *
1899
1949
  * @example Multiple columns with pre/post logic
1900
1950
  * ```typescript
1901
- * const results = await ctx
1902
- * .map('leads', leads)
1903
- * .step('company', (row, ctx) =>
1904
- * ctx.tools.execute('company_search', 'test_company_search', { domain: row.domain }, {
1905
- * description: 'Look up company details by domain.',
1906
- * }))
1951
+ * const results = await ctx
1952
+ * .map('leads', leads)
1953
+ * .step('company', (row, ctx) =>
1954
+ * ctx.tools.execute({
1955
+ * id: 'company_search',
1956
+ * tool: 'test_company_search',
1957
+ * input: { domain: row.domain },
1958
+ * description: 'Look up company details by domain.',
1959
+ * }))
1907
1960
  * .step('score', (row) =>
1908
1961
  * row.company?.employeeCount > 100 ? 'enterprise' : 'smb')
1909
1962
  * .run({ description: 'Enrich leads.' });
@@ -1913,17 +1966,14 @@ interface DeeplinePlayRuntimeContext {
1913
1966
  /** Tool execution namespace. */
1914
1967
  tools: {
1915
1968
  /**
1916
- * Execute a single tool by stable step key and tool ID.
1969
+ * Execute a single tool with a keyword-style request object.
1917
1970
  *
1918
- * @param key - Stable step key for idempotent execution
1919
- * @param toolId - Tool identifier (e.g. `'test_company_search'`)
1920
- * @param input - Tool-specific input parameters
1971
+ * @param request.id - Stable step key for idempotent execution
1972
+ * @param request.tool - Tool identifier (e.g. `'test_company_search'`)
1973
+ * @param request.input - Tool-specific input parameters
1921
1974
  * @returns The tool's output
1922
1975
  */
1923
1976
  execute<TOutput = LoosePlayObject>(request: ToolExecutionRequest): Promise<ToolExecuteResult<TOutput>>;
1924
- execute<TOutput = LoosePlayObject>(key: string, toolId: string, input: Record<string, unknown>, options?: {
1925
- description?: string;
1926
- }): Promise<ToolExecuteResult<TOutput>>;
1927
1977
  };
1928
1978
  /**
1929
1979
  * Execute a single tool by stable step key and tool ID.
@@ -2154,7 +2204,10 @@ declare function when<Row, Value>(predicate: (row: Row, index: number) => boolea
2154
2204
  * import { definePlay } from 'deepline';
2155
2205
  *
2156
2206
  * const myPlay = definePlay('my-play', async (ctx, input: { domain: string }) => {
2157
- * return await ctx.tools.execute('company_search', 'test_company_search', { domain: input.domain }, {
2207
+ * return await ctx.tools.execute({
2208
+ * id: 'company_search',
2209
+ * tool: 'test_company_search',
2210
+ * input: { domain: input.domain },
2158
2211
  * description: 'Look up company details by domain.',
2159
2212
  * });
2160
2213
  * });
@@ -2190,14 +2243,14 @@ type PlayMetadata = {
2190
2243
  *
2191
2244
  * @example
2192
2245
  * ```typescript
2193
- * const ctx = await Deepline.connect();
2246
+ * const deepline = await Deepline.connect();
2194
2247
  *
2195
2248
  * // Tools
2196
- * const tools = await ctx.tools.list();
2197
- * const result = await ctx.tools.execute('test_company_search', { domain: 'stripe.com' });
2249
+ * const tools = await deepline.tools.list();
2250
+ * const result = await deepline.tools.execute('test_company_search', { domain: 'stripe.com' });
2198
2251
  *
2199
2252
  * // Plays
2200
- * const job = await ctx.play('email-waterfall').run({ domain: 'stripe.com' });
2253
+ * const job = await deepline.play('email-waterfall').run({ domain: 'stripe.com' });
2201
2254
  * const output = await job.get();
2202
2255
  * ```
2203
2256
  */
@@ -2209,10 +2262,10 @@ declare class DeeplineContext {
2209
2262
  *
2210
2263
  * @example
2211
2264
  * ```typescript
2212
- * const tools = await ctx.tools.list();
2213
- * const meta = await ctx.tools.get('apollo_people_search');
2214
- * const companyLookup = await ctx.tools.execute('test_company_search', { domain: 'stripe.com' });
2215
- * const company = companyLookup.result.data;
2265
+ * const tools = await deepline.tools.list();
2266
+ * const meta = await deepline.tools.get('apollo_people_search');
2267
+ * const companyLookup = await deepline.tools.execute('test_company_search', { domain: 'stripe.com' });
2268
+ * const company = companyLookup.toolResponse.raw;
2216
2269
  * ```
2217
2270
  */
2218
2271
  get tools(): {
@@ -2253,9 +2306,9 @@ declare class DeeplineContext {
2253
2306
  * ```typescript
2254
2307
  * import { Deepline } from 'deepline';
2255
2308
  *
2256
- * const ctx = await Deepline.connect();
2257
- * const tools = await ctx.tools.list();
2258
- * const result = await ctx.tools.execute('test_company_search', { domain: 'stripe.com' });
2309
+ * const deepline = await Deepline.connect();
2310
+ * const tools = await deepline.tools.list();
2311
+ * const result = await deepline.tools.execute('test_company_search', { domain: 'stripe.com' });
2259
2312
  * ```
2260
2313
  */
2261
2314
  declare class Deepline {
@@ -2307,7 +2360,10 @@ declare function defineInput<TInput>(schema: Record<string, unknown>): PlayInput
2307
2360
  *
2308
2361
  * export default definePlay('company-lookup', async (ctx, input: { domain: string }) => {
2309
2362
  * ctx.log(`Searching for ${input.domain}`);
2310
- * const company = await ctx.tools.execute('company_search', 'test_company_search', { domain: input.domain }, {
2363
+ * const company = await ctx.tools.execute({
2364
+ * id: 'company_search',
2365
+ * tool: 'test_company_search',
2366
+ * input: { domain: input.domain },
2311
2367
  * description: 'Look up company details by domain.',
2312
2368
  * });
2313
2369
  * return company;
@@ -2322,7 +2378,10 @@ declare function defineInput<TInput>(schema: Record<string, unknown>): PlayInput
2322
2378
  * const results = await ctx
2323
2379
  * .map('companies', leads)
2324
2380
  * .step('company', (row, ctx) =>
2325
- * ctx.tools.execute('company_search', 'test_company_search', { domain: row.domain }, {
2381
+ * ctx.tools.execute({
2382
+ * id: 'company_search',
2383
+ * tool: 'test_company_search',
2384
+ * input: { domain: row.domain },
2326
2385
  * description: 'Look up company details by domain.',
2327
2386
  * }))
2328
2387
  * .run({ description: 'Enrich lead companies.' });
@@ -2333,7 +2392,10 @@ declare function defineInput<TInput>(schema: Record<string, unknown>): PlayInput
2333
2392
  * @example With cron binding
2334
2393
  * ```typescript
2335
2394
  * export default definePlay('daily-report', async (ctx) => {
2336
- * const data = await ctx.tools.execute('crm_export', 'crm_export', { since: 'yesterday' }, {
2395
+ * const data = await ctx.tools.execute({
2396
+ * id: 'crm_export',
2397
+ * tool: 'crm_export',
2398
+ * input: { since: 'yesterday' },
2337
2399
  * description: 'Export yesterday CRM records.',
2338
2400
  * });
2339
2401
  * return data;
@@ -2394,7 +2456,7 @@ declare function getDefinedPlayMetadata(value: unknown): PlayMetadata | null;
2394
2456
  * @example
2395
2457
  * ```typescript
2396
2458
  * const conversion = tryConvertToList(toolResponse, {
2397
- * listExtractorPaths: ['people', 'result.data'],
2459
+ * listExtractorPaths: ['people', 'output.body'],
2398
2460
  * });
2399
2461
  * if (conversion) {
2400
2462
  * console.log(`Found ${conversion.rows.length} rows via ${conversion.strategy}`);
@@ -2411,7 +2473,7 @@ type ListConversionResult = {
2411
2473
  * - `'auto_detected'` — found via recursive DFS (longest array wins)
2412
2474
  */
2413
2475
  strategy: 'configured_paths' | 'auto_detected';
2414
- /** Dotted path to where the list was found (e.g. `"result.data"`, `"people"`). */
2476
+ /** Dotted path to where the list was found (e.g. `"output.body"`, `"people"`). */
2415
2477
  sourcePath: string | null;
2416
2478
  };
2417
2479
  type Scalar = string | number | boolean | null;
@@ -2425,7 +2487,7 @@ type Scalar = string | number | boolean | null;
2425
2487
  * ## Extraction strategy
2426
2488
  *
2427
2489
  * 1. **Configured paths** — If `listExtractorPaths` is provided, each path is
2428
- * tried against multiple candidate roots (raw payload, `.result`, `.result.data`).
2490
+ * tried against multiple candidate roots (raw payload, `.output.body`, legacy `.result`, legacy `.result.data`).
2429
2491
  * First match wins.
2430
2492
  *
2431
2493
  * 2. **Auto-detection** — If no configured path matches, recursively searches
@@ -2512,7 +2574,7 @@ declare function writeCsvOutputFile(rows: Array<Record<string, unknown>>, stem:
2512
2574
  /**
2513
2575
  * Extract scalar (non-nested) fields from a tool response for summary display.
2514
2576
  *
2515
- * Searches through candidate roots (raw → `.result` → `.result.data`) and
2577
+ * Searches through candidate roots (raw → `.output.body` → legacy `.result` → legacy `.result.data`) and
2516
2578
  * returns the first set of scalar fields found. Useful for displaying a
2517
2579
  * quick summary of single-record responses.
2518
2580
  *