deepline 0.1.11 → 0.1.19
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/README.md +18 -10
- package/dist/cli/index.js +1795 -1052
- package/dist/cli/index.mjs +1795 -1053
- package/dist/index.d.mts +427 -308
- package/dist/index.d.ts +427 -308
- package/dist/index.js +391 -326
- package/dist/index.mjs +391 -325
- package/dist/repo/apps/play-runner-workers/src/coordinator-entry.ts +88 -22
- package/dist/repo/apps/play-runner-workers/src/entry.ts +804 -1253
- package/dist/repo/sdk/src/client.ts +287 -47
- package/dist/repo/sdk/src/config.ts +125 -8
- package/dist/repo/sdk/src/http.ts +10 -2
- package/dist/repo/sdk/src/index.ts +7 -16
- package/dist/repo/sdk/src/play.ts +105 -140
- package/dist/repo/sdk/src/plays/bundle-play-file.ts +23 -6
- package/dist/repo/sdk/src/plays/local-file-discovery.ts +207 -160
- package/dist/repo/sdk/src/tool-output.ts +0 -146
- package/dist/repo/sdk/src/types.ts +27 -0
- package/dist/repo/sdk/src/version.ts +2 -2
- package/dist/repo/sdk/src/worker-play-entry.ts +3 -0
- package/dist/repo/shared_libs/play-runtime/csv-rename.ts +180 -0
- package/dist/repo/shared_libs/play-runtime/tool-result.ts +250 -133
- package/dist/repo/shared_libs/plays/bundling/index.ts +274 -234
- package/dist/repo/shared_libs/plays/dataset.ts +29 -1
- package/package.json +5 -4
- package/dist/cli/index.js.map +0 -1
- package/dist/cli/index.mjs.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/index.mjs.map +0 -1
- package/dist/repo/apps/play-runner-workers/src/runtime/README.md +0 -21
- package/dist/repo/apps/play-runner-workers/src/runtime/batching.ts +0 -177
- package/dist/repo/apps/play-runner-workers/src/runtime/execution-plan.ts +0 -52
- package/dist/repo/apps/play-runner-workers/src/runtime/tool-batch.ts +0 -100
- package/dist/repo/apps/play-runner-workers/src/runtime/tool-result.ts +0 -184
- package/dist/repo/sdk/src/cli/commands/auth.ts +0 -500
- package/dist/repo/sdk/src/cli/commands/billing.ts +0 -188
- package/dist/repo/sdk/src/cli/commands/csv.ts +0 -123
- package/dist/repo/sdk/src/cli/commands/db.ts +0 -119
- package/dist/repo/sdk/src/cli/commands/feedback.ts +0 -40
- package/dist/repo/sdk/src/cli/commands/org.ts +0 -117
- package/dist/repo/sdk/src/cli/commands/play.ts +0 -3307
- package/dist/repo/sdk/src/cli/commands/tools.ts +0 -687
- package/dist/repo/sdk/src/cli/dataset-stats.ts +0 -341
- package/dist/repo/sdk/src/cli/index.ts +0 -148
- package/dist/repo/sdk/src/cli/progress.ts +0 -149
- package/dist/repo/sdk/src/cli/skills-sync.ts +0 -141
- package/dist/repo/sdk/src/cli/trace.ts +0 -61
- package/dist/repo/sdk/src/cli/utils.ts +0 -145
- package/dist/repo/sdk/src/compat.ts +0 -77
- package/dist/repo/shared_libs/observability/node-tracing.ts +0 -129
- package/dist/repo/shared_libs/observability/tracing.ts +0 -98
- package/dist/repo/shared_libs/play-runtime/context.ts +0 -3999
- package/dist/repo/shared_libs/play-runtime/ctx-contract.ts +0 -250
- package/dist/repo/shared_libs/play-runtime/ctx-types.ts +0 -713
- package/dist/repo/shared_libs/play-runtime/dataset-id.ts +0 -10
- package/dist/repo/shared_libs/play-runtime/db-session-crypto.ts +0 -304
- package/dist/repo/shared_libs/play-runtime/db-session.ts +0 -462
- package/dist/repo/shared_libs/play-runtime/live-events.ts +0 -214
- package/dist/repo/shared_libs/play-runtime/live-state-contract.ts +0 -50
- package/dist/repo/shared_libs/play-runtime/map-execution-frame.ts +0 -114
- package/dist/repo/shared_libs/play-runtime/map-row-identity.ts +0 -158
- package/dist/repo/shared_libs/play-runtime/progress-emitter.ts +0 -172
- package/dist/repo/shared_libs/play-runtime/protocol.ts +0 -121
- package/dist/repo/shared_libs/play-runtime/public-play-contract.ts +0 -42
- package/dist/repo/shared_libs/play-runtime/result-normalization.ts +0 -33
- package/dist/repo/shared_libs/play-runtime/runtime-api.ts +0 -1873
- package/dist/repo/shared_libs/play-runtime/runtime-constraints.ts +0 -2
- package/dist/repo/shared_libs/play-runtime/runtime-pg-driver-neon-serverless.ts +0 -201
- package/dist/repo/shared_libs/play-runtime/runtime-pg-driver-pg.ts +0 -48
- package/dist/repo/shared_libs/play-runtime/runtime-pg-driver.ts +0 -84
- package/dist/repo/shared_libs/play-runtime/static-pipeline-types.ts +0 -147
- package/dist/repo/shared_libs/play-runtime/suspension.ts +0 -68
- package/dist/repo/shared_libs/play-runtime/tracing.ts +0 -31
- package/dist/repo/shared_libs/play-runtime/waterfall-replay.ts +0 -75
- package/dist/repo/shared_libs/play-runtime/worker-api-types.ts +0 -140
- package/dist/repo/shared_libs/plays/artifact-transport.ts +0 -14
- package/dist/repo/shared_libs/plays/artifact-types.ts +0 -49
- package/dist/repo/shared_libs/plays/compiler-manifest.ts +0 -186
- package/dist/repo/shared_libs/plays/definition.ts +0 -264
- package/dist/repo/shared_libs/plays/file-refs.ts +0 -11
- package/dist/repo/shared_libs/plays/rate-limit-scheduler.ts +0 -206
- package/dist/repo/shared_libs/plays/resolve-static-pipeline.ts +0 -164
- package/dist/repo/shared_libs/plays/runtime-validation.ts +0 -415
- package/dist/repo/shared_libs/temporal/constants.ts +0 -39
- package/dist/repo/shared_libs/temporal/preview-config.ts +0 -153
package/dist/index.d.mts
CHANGED
|
@@ -264,6 +264,25 @@ interface ToolDefinition {
|
|
|
264
264
|
resultIdentityGetters?: Record<string, string[]>;
|
|
265
265
|
/** Whether the output is a direct object or wrapped in a `result` envelope. */
|
|
266
266
|
rowContextShape?: 'direct' | 'result_envelope';
|
|
267
|
+
/** Search relevance score returned by ranked tool search. */
|
|
268
|
+
search_score?: number;
|
|
269
|
+
/** Search match snippets returned by ranked tool search. */
|
|
270
|
+
search_matches?: Array<{
|
|
271
|
+
field: string;
|
|
272
|
+
value: string;
|
|
273
|
+
term?: string;
|
|
274
|
+
}>;
|
|
275
|
+
}
|
|
276
|
+
interface ToolSearchOptions {
|
|
277
|
+
query?: string;
|
|
278
|
+
categories?: string;
|
|
279
|
+
searchTerms?: string;
|
|
280
|
+
searchMode?: 'v1' | 'v2';
|
|
281
|
+
includeSearchDebug?: boolean;
|
|
282
|
+
}
|
|
283
|
+
interface ToolSearchResult {
|
|
284
|
+
tools: ToolDefinition[];
|
|
285
|
+
search_fallback_to_category?: boolean;
|
|
267
286
|
}
|
|
268
287
|
/**
|
|
269
288
|
* Extended tool metadata including pricing, samples, and failure modes.
|
|
@@ -344,6 +363,8 @@ interface PlayProgressStatus {
|
|
|
344
363
|
totalRows?: number;
|
|
345
364
|
/** Accumulated log lines from `ctx.log()`. Grows monotonically. */
|
|
346
365
|
logs: string[];
|
|
366
|
+
/** Zero-based offset of the first returned log line when a tail cursor is used. */
|
|
367
|
+
logOffset?: number;
|
|
347
368
|
/** Error message if the play has failed. */
|
|
348
369
|
error?: string;
|
|
349
370
|
}
|
|
@@ -603,6 +624,8 @@ interface PlayDescription {
|
|
|
603
624
|
aliases: string[];
|
|
604
625
|
inputSchema?: Record<string, unknown> | null;
|
|
605
626
|
outputSchema?: Record<string, unknown> | null;
|
|
627
|
+
csvInput?: Record<string, unknown> | null;
|
|
628
|
+
rowOutputSchema?: Record<string, unknown> | null;
|
|
606
629
|
runCommand: string;
|
|
607
630
|
examples: string[];
|
|
608
631
|
currentPublishedVersion?: number | null;
|
|
@@ -722,6 +745,8 @@ interface StartPlayRunRequest {
|
|
|
722
745
|
artifactStorageKey?: string;
|
|
723
746
|
/** Source snapshot already validated while registering this artifact. */
|
|
724
747
|
sourceCode?: string;
|
|
748
|
+
/** Source graph snapshots for local helper files included in cloud preflight. */
|
|
749
|
+
sourceFiles?: Record<string, string>;
|
|
725
750
|
/** Static pipeline already produced while registering this artifact. */
|
|
726
751
|
staticPipeline?: unknown;
|
|
727
752
|
/** Artifact content hash already validated while registering this artifact. */
|
|
@@ -793,6 +818,52 @@ interface PlayStagedFileRef {
|
|
|
793
818
|
bytes: number;
|
|
794
819
|
}
|
|
795
820
|
|
|
821
|
+
type ExecuteToolRawOptions = {
|
|
822
|
+
includeToolMetadata?: boolean;
|
|
823
|
+
};
|
|
824
|
+
type ToolExecution<TData = unknown, TMeta = Record<string, unknown>> = {
|
|
825
|
+
status: string;
|
|
826
|
+
job_id?: string;
|
|
827
|
+
result: {
|
|
828
|
+
data: TData;
|
|
829
|
+
meta?: TMeta;
|
|
830
|
+
};
|
|
831
|
+
billing?: Record<string, unknown>;
|
|
832
|
+
[key: string]: unknown;
|
|
833
|
+
};
|
|
834
|
+
type RunsListOptions = {
|
|
835
|
+
play: string;
|
|
836
|
+
status?: string;
|
|
837
|
+
};
|
|
838
|
+
type RunsTailOptions = {
|
|
839
|
+
cursor?: string | number;
|
|
840
|
+
afterLogIndex?: number;
|
|
841
|
+
waitMs?: number;
|
|
842
|
+
terminalOnly?: boolean;
|
|
843
|
+
compact?: boolean;
|
|
844
|
+
};
|
|
845
|
+
type RunsLogsOptions = {
|
|
846
|
+
limit?: number;
|
|
847
|
+
};
|
|
848
|
+
type RunsLogsResult = {
|
|
849
|
+
runId: string;
|
|
850
|
+
totalCount: number;
|
|
851
|
+
returnedCount: number;
|
|
852
|
+
firstSequence: number | null;
|
|
853
|
+
lastSequence: number | null;
|
|
854
|
+
truncated: boolean;
|
|
855
|
+
hasMore: boolean;
|
|
856
|
+
entries: string[];
|
|
857
|
+
};
|
|
858
|
+
type RunsNamespace = {
|
|
859
|
+
get: (runId: string) => Promise<PlayStatus>;
|
|
860
|
+
list: (options: RunsListOptions) => Promise<PlayRunListItem[]>;
|
|
861
|
+
tail: (runId: string, options?: RunsTailOptions) => Promise<PlayStatus>;
|
|
862
|
+
logs: (runId: string, options?: RunsLogsOptions) => Promise<RunsLogsResult>;
|
|
863
|
+
stop: (runId: string, options?: {
|
|
864
|
+
reason?: string;
|
|
865
|
+
}) => Promise<StopPlayRunResult>;
|
|
866
|
+
};
|
|
796
867
|
/**
|
|
797
868
|
* Low-level client for the Deepline REST API.
|
|
798
869
|
*
|
|
@@ -816,6 +887,7 @@ interface PlayStagedFileRef {
|
|
|
816
887
|
declare class DeeplineClient {
|
|
817
888
|
private readonly http;
|
|
818
889
|
private readonly config;
|
|
890
|
+
readonly runs: RunsNamespace;
|
|
819
891
|
/**
|
|
820
892
|
* @param options - Optional overrides for API key, base URL, timeout, and retries.
|
|
821
893
|
* @throws {@link ConfigError} if no API key can be resolved from any source.
|
|
@@ -824,6 +896,7 @@ declare class DeeplineClient {
|
|
|
824
896
|
/** The resolved base URL this client is targeting (e.g. `"http://localhost:3000"`). */
|
|
825
897
|
get baseUrl(): string;
|
|
826
898
|
private compactSchema;
|
|
899
|
+
private schemaMetadata;
|
|
827
900
|
private playRunCommand;
|
|
828
901
|
private summarizePlayListItem;
|
|
829
902
|
private summarizePlayDetail;
|
|
@@ -843,6 +916,13 @@ declare class DeeplineClient {
|
|
|
843
916
|
* ```
|
|
844
917
|
*/
|
|
845
918
|
listTools(): Promise<ToolDefinition[]>;
|
|
919
|
+
/**
|
|
920
|
+
* Search available tools using Deepline's ranked backend search.
|
|
921
|
+
*
|
|
922
|
+
* This is the same discovery surface used by the legacy CLI: it ranks across
|
|
923
|
+
* tool metadata, categories, agent guidance, and input schema fields.
|
|
924
|
+
*/
|
|
925
|
+
searchTools(options?: ToolSearchOptions): Promise<ToolSearchResult>;
|
|
846
926
|
/**
|
|
847
927
|
* Get detailed metadata for a single tool.
|
|
848
928
|
*
|
|
@@ -861,44 +941,15 @@ declare class DeeplineClient {
|
|
|
861
941
|
*/
|
|
862
942
|
getTool(toolId: string): Promise<ToolMetadata>;
|
|
863
943
|
/**
|
|
864
|
-
* Execute a tool and return the
|
|
865
|
-
*
|
|
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
|
-
* ```
|
|
882
|
-
*/
|
|
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
|
|
944
|
+
* Execute a tool and return the standard execution envelope.
|
|
893
945
|
*
|
|
894
|
-
*
|
|
895
|
-
*
|
|
896
|
-
*
|
|
897
|
-
*
|
|
898
|
-
* console.log(`Result:`, raw.result);
|
|
899
|
-
* ```
|
|
946
|
+
* The `result.data` field contains the provider payload. `result.meta`
|
|
947
|
+
* contains provider/upstream metadata such as HTTP status or paging details.
|
|
948
|
+
* Top-level fields such as `status`, `job_id`, and `billing` describe the
|
|
949
|
+
* Deepline execution.
|
|
900
950
|
*/
|
|
901
|
-
|
|
951
|
+
executeTool<TData = unknown, TMeta = Record<string, unknown>>(toolId: string, input: Record<string, unknown>, options?: ExecuteToolRawOptions): Promise<ToolExecution<TData, TMeta>>;
|
|
952
|
+
executeToolRaw<TData = unknown, TMeta = Record<string, unknown>>(toolId: string, input: Record<string, unknown>, options?: ExecuteToolRawOptions): Promise<ToolExecution<TData, TMeta>>;
|
|
902
953
|
queryCustomerDb(input: {
|
|
903
954
|
sql: string;
|
|
904
955
|
maxRows?: number;
|
|
@@ -949,6 +1000,7 @@ declare class DeeplineClient {
|
|
|
949
1000
|
registerPlayArtifact(input: {
|
|
950
1001
|
name: string;
|
|
951
1002
|
sourceCode: string;
|
|
1003
|
+
sourceFiles?: Record<string, string>;
|
|
952
1004
|
artifact: Record<string, unknown>;
|
|
953
1005
|
compilerManifest?: PlayCompilerManifest;
|
|
954
1006
|
publish?: boolean;
|
|
@@ -971,6 +1023,7 @@ declare class DeeplineClient {
|
|
|
971
1023
|
registerPlayArtifacts(artifacts: Array<{
|
|
972
1024
|
name: string;
|
|
973
1025
|
sourceCode: string;
|
|
1026
|
+
sourceFiles?: Record<string, string>;
|
|
974
1027
|
artifact: Record<string, unknown>;
|
|
975
1028
|
compilerManifest?: PlayCompilerManifest;
|
|
976
1029
|
publish?: boolean;
|
|
@@ -996,6 +1049,7 @@ declare class DeeplineClient {
|
|
|
996
1049
|
compilePlayManifest(input: {
|
|
997
1050
|
name: string;
|
|
998
1051
|
sourceCode: string;
|
|
1052
|
+
sourceFiles?: Record<string, string>;
|
|
999
1053
|
artifact: Record<string, unknown>;
|
|
1000
1054
|
importedPlayDependencies?: PlayCompilerManifest[];
|
|
1001
1055
|
}): Promise<PlayCompilerManifest>;
|
|
@@ -1009,11 +1063,13 @@ declare class DeeplineClient {
|
|
|
1009
1063
|
checkPlayArtifact(input: {
|
|
1010
1064
|
name?: string;
|
|
1011
1065
|
sourceCode: string;
|
|
1066
|
+
sourceFiles?: Record<string, string>;
|
|
1012
1067
|
artifact: Record<string, unknown>;
|
|
1013
1068
|
}): Promise<PlayCheckResult>;
|
|
1014
1069
|
startPlayRunFromBundle(input: {
|
|
1015
1070
|
name: string;
|
|
1016
1071
|
sourceCode: string;
|
|
1072
|
+
sourceFiles?: Record<string, string>;
|
|
1017
1073
|
artifact: Record<string, unknown>;
|
|
1018
1074
|
compilerManifest?: PlayCompilerManifest;
|
|
1019
1075
|
input?: Record<string, unknown>;
|
|
@@ -1047,6 +1103,7 @@ declare class DeeplineClient {
|
|
|
1047
1103
|
*/
|
|
1048
1104
|
submitPlay(code: string, csvPath: string | null, name?: string, options?: {
|
|
1049
1105
|
sourceCode?: string;
|
|
1106
|
+
sourceFiles?: Record<string, string>;
|
|
1050
1107
|
artifact?: Record<string, unknown>;
|
|
1051
1108
|
compilerManifest?: PlayCompilerManifest;
|
|
1052
1109
|
input?: Record<string, unknown>;
|
|
@@ -1181,6 +1238,58 @@ declare class DeeplineClient {
|
|
|
1181
1238
|
* ```
|
|
1182
1239
|
*/
|
|
1183
1240
|
listPlayRuns(playName: string): Promise<PlayRunListItem[]>;
|
|
1241
|
+
/**
|
|
1242
|
+
* Get a run by id using the public runs resource model.
|
|
1243
|
+
*
|
|
1244
|
+
* This is the SDK equivalent of:
|
|
1245
|
+
*
|
|
1246
|
+
* ```bash
|
|
1247
|
+
* deepline runs get <run-id> --json
|
|
1248
|
+
* ```
|
|
1249
|
+
*/
|
|
1250
|
+
getRunStatus(runId: string): Promise<PlayStatus>;
|
|
1251
|
+
/**
|
|
1252
|
+
* List play runs using the public runs resource model.
|
|
1253
|
+
*
|
|
1254
|
+
* This is the SDK equivalent of:
|
|
1255
|
+
*
|
|
1256
|
+
* ```bash
|
|
1257
|
+
* deepline runs list --play <play-name> --status failed --json
|
|
1258
|
+
* ```
|
|
1259
|
+
*/
|
|
1260
|
+
listRuns(options: RunsListOptions): Promise<PlayRunListItem[]>;
|
|
1261
|
+
/**
|
|
1262
|
+
* Fetch the lightweight tail status for a run using the public runs resource model.
|
|
1263
|
+
*
|
|
1264
|
+
* This is the SDK equivalent of:
|
|
1265
|
+
*
|
|
1266
|
+
* ```bash
|
|
1267
|
+
* deepline runs tail <run-id> --json
|
|
1268
|
+
* ```
|
|
1269
|
+
*/
|
|
1270
|
+
tailRun(runId: string, options?: RunsTailOptions): Promise<PlayStatus>;
|
|
1271
|
+
/**
|
|
1272
|
+
* Fetch persisted logs for a run using the public runs resource model.
|
|
1273
|
+
*
|
|
1274
|
+
* This is the SDK equivalent of:
|
|
1275
|
+
*
|
|
1276
|
+
* ```bash
|
|
1277
|
+
* deepline runs logs <run-id> --limit 200 --json
|
|
1278
|
+
* ```
|
|
1279
|
+
*/
|
|
1280
|
+
getRunLogs(runId: string, options?: RunsLogsOptions): Promise<RunsLogsResult>;
|
|
1281
|
+
/**
|
|
1282
|
+
* Stop a run by id using the public runs resource model.
|
|
1283
|
+
*
|
|
1284
|
+
* This is the SDK equivalent of:
|
|
1285
|
+
*
|
|
1286
|
+
* ```bash
|
|
1287
|
+
* deepline runs stop <run-id> --reason "stale lock" --json
|
|
1288
|
+
* ```
|
|
1289
|
+
*/
|
|
1290
|
+
stopRun(runId: string, options?: {
|
|
1291
|
+
reason?: string;
|
|
1292
|
+
}): Promise<StopPlayRunResult>;
|
|
1184
1293
|
listPlays(): Promise<PlayListItem[]>;
|
|
1185
1294
|
searchPlays(options: {
|
|
1186
1295
|
query: string;
|
|
@@ -1325,8 +1434,8 @@ declare class DeeplineClient {
|
|
|
1325
1434
|
}>;
|
|
1326
1435
|
}
|
|
1327
1436
|
|
|
1328
|
-
declare const SDK_VERSION = "0.1.
|
|
1329
|
-
declare const SDK_API_CONTRACT = "2026-
|
|
1437
|
+
declare const SDK_VERSION = "0.1.19";
|
|
1438
|
+
declare const SDK_API_CONTRACT = "2026-05-runs-v2";
|
|
1330
1439
|
|
|
1331
1440
|
/**
|
|
1332
1441
|
* Base error class for all Deepline SDK errors.
|
|
@@ -1468,164 +1577,6 @@ declare const PROD_URL = "https://code.deepline.com";
|
|
|
1468
1577
|
*/
|
|
1469
1578
|
declare function resolveConfig(options?: DeeplineClientOptions): ResolvedConfig;
|
|
1470
1579
|
|
|
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
1580
|
interface PlayR2FileRef {
|
|
1630
1581
|
storageKind: 'r2';
|
|
1631
1582
|
storageKey: string;
|
|
@@ -1649,6 +1600,20 @@ type PlayDatasetBacking = {
|
|
|
1649
1600
|
storage: 'r2_file';
|
|
1650
1601
|
file: PlayExecutionFileRef;
|
|
1651
1602
|
};
|
|
1603
|
+
type PlayDatasetWorkProgressSummary = {
|
|
1604
|
+
total: number;
|
|
1605
|
+
executed: number;
|
|
1606
|
+
reused: number;
|
|
1607
|
+
skipped: number;
|
|
1608
|
+
pending: number;
|
|
1609
|
+
failed: number;
|
|
1610
|
+
degraded?: boolean;
|
|
1611
|
+
duplicates?: {
|
|
1612
|
+
exact?: number;
|
|
1613
|
+
semantic?: number;
|
|
1614
|
+
rejected?: number;
|
|
1615
|
+
};
|
|
1616
|
+
};
|
|
1652
1617
|
type PlayDatasetInput<T> = ReadonlyArray<T> | Iterable<T> | AsyncIterable<T> | PlayDataset<T>;
|
|
1653
1618
|
interface PlayDataset<T> extends AsyncIterable<T> {
|
|
1654
1619
|
readonly [PLAY_DATASET_BRAND]: true;
|
|
@@ -1674,10 +1639,65 @@ interface PlayDataset<T> extends AsyncIterable<T> {
|
|
|
1674
1639
|
sourceLabel?: string | null;
|
|
1675
1640
|
tableNamespace?: string | null;
|
|
1676
1641
|
columns?: string[];
|
|
1642
|
+
_metadata?: {
|
|
1643
|
+
workProgress?: PlayDatasetWorkProgressSummary;
|
|
1644
|
+
};
|
|
1677
1645
|
preview: T[];
|
|
1678
1646
|
};
|
|
1679
1647
|
}
|
|
1680
1648
|
|
|
1649
|
+
type ToolResultExecutionMetadata = {
|
|
1650
|
+
idempotent: true;
|
|
1651
|
+
cached: boolean;
|
|
1652
|
+
source: 'live' | 'checkpoint' | 'cache';
|
|
1653
|
+
cacheKey?: string;
|
|
1654
|
+
};
|
|
1655
|
+
type ToolResultTargetMetadata = {
|
|
1656
|
+
value: unknown;
|
|
1657
|
+
path: string;
|
|
1658
|
+
};
|
|
1659
|
+
type ToolResultListMetadata = {
|
|
1660
|
+
path: string;
|
|
1661
|
+
count: number | null;
|
|
1662
|
+
keys: Record<string, string>;
|
|
1663
|
+
};
|
|
1664
|
+
type ToolResultTargetAccessor<T = unknown> = ToolResultTargetMetadata & {
|
|
1665
|
+
get(): T | null;
|
|
1666
|
+
};
|
|
1667
|
+
type ToolResultListAccessor<T = Record<string, unknown>> = ToolResultListMetadata & {
|
|
1668
|
+
get(): T[];
|
|
1669
|
+
};
|
|
1670
|
+
type ToolResultEnvelope<TData = unknown, TMeta = Record<string, unknown>> = {
|
|
1671
|
+
data: TData;
|
|
1672
|
+
meta?: TMeta;
|
|
1673
|
+
};
|
|
1674
|
+
type ToolExecuteResultBase<TResult = unknown, TMeta = Record<string, unknown>> = {
|
|
1675
|
+
status: string;
|
|
1676
|
+
result: ToolResultEnvelope<TResult, TMeta>;
|
|
1677
|
+
_metadata: {
|
|
1678
|
+
toolId: string;
|
|
1679
|
+
execution: ToolResultExecutionMetadata;
|
|
1680
|
+
targets: Record<string, {
|
|
1681
|
+
value: unknown;
|
|
1682
|
+
path: string;
|
|
1683
|
+
}>;
|
|
1684
|
+
lists: Record<string, {
|
|
1685
|
+
path: string;
|
|
1686
|
+
count: number | null;
|
|
1687
|
+
keys: Record<string, string>;
|
|
1688
|
+
}>;
|
|
1689
|
+
};
|
|
1690
|
+
};
|
|
1691
|
+
type ToolExecuteResultAccessors<TExtracted extends Record<string, unknown> = Record<string, unknown>, TLists extends Record<string, Record<string, unknown>> = Record<string, Record<string, unknown>>> = {
|
|
1692
|
+
extracted: {
|
|
1693
|
+
[K in keyof TExtracted]: ToolResultTargetAccessor<TExtracted[K]>;
|
|
1694
|
+
};
|
|
1695
|
+
lists: {
|
|
1696
|
+
[K in keyof TLists]: ToolResultListAccessor<TLists[K]>;
|
|
1697
|
+
};
|
|
1698
|
+
};
|
|
1699
|
+
type ToolExecuteResult<TResult = unknown, TMeta = Record<string, unknown>, TExtracted extends Record<string, unknown> = Record<string, unknown>, TLists extends Record<string, Record<string, unknown>> = Record<string, Record<string, unknown>>> = ToolExecuteResultBase<TResult, TMeta> & ToolExecuteResultAccessors<TExtracted, TLists>;
|
|
1700
|
+
|
|
1681
1701
|
/**
|
|
1682
1702
|
* Optional trigger bindings for a play.
|
|
1683
1703
|
*
|
|
@@ -1733,45 +1753,13 @@ type PlayBindings = {
|
|
|
1733
1753
|
type LoosePlayObject = {
|
|
1734
1754
|
[key: string]: LoosePlayObject;
|
|
1735
1755
|
};
|
|
1756
|
+
|
|
1736
1757
|
type ToolExecutionRequest = {
|
|
1737
1758
|
id: string;
|
|
1738
1759
|
tool: string;
|
|
1739
1760
|
input: Record<string, unknown>;
|
|
1740
1761
|
description?: string;
|
|
1741
1762
|
};
|
|
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
1763
|
type StepResolver<Row, Value> = (row: Row, ctx: DeeplinePlayRuntimeContext, index: number) => Value | Promise<Value>;
|
|
1776
1764
|
type ConditionalStepResolver<Row, Value, Else = null> = {
|
|
1777
1765
|
readonly kind: 'conditional';
|
|
@@ -1799,17 +1787,39 @@ type PlayStepProgramStep = {
|
|
|
1799
1787
|
readonly resolver: StepResolver<Record<string, unknown>, unknown> | ConditionalStepResolver<Record<string, unknown>, unknown> | StepProgramResolver<Record<string, unknown>, unknown>;
|
|
1800
1788
|
};
|
|
1801
1789
|
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
1790
|
type MapStepBuilder<InputRow extends object, OutputRow extends object> = {
|
|
1811
1791
|
step<Name extends string, Value>(name: Name, resolver: MapStepResolver<OutputRow, Value>): MapStepBuilder<InputRow, OutputRow & Record<Name, Value>>;
|
|
1812
|
-
run(options?:
|
|
1792
|
+
run(options?: {
|
|
1793
|
+
description?: string;
|
|
1794
|
+
staleAfterSeconds?: number;
|
|
1795
|
+
key?: (keyof InputRow & string) | readonly (keyof InputRow & string)[] | ((row: InputRow, index: number) => string | number | readonly unknown[]);
|
|
1796
|
+
}): Promise<PlayDataset<OutputRow>>;
|
|
1797
|
+
};
|
|
1798
|
+
type CsvRenameMap = Record<string, string | readonly string[]>;
|
|
1799
|
+
/**
|
|
1800
|
+
* Runtime file-like input. At runtime this is the staged file path/reference
|
|
1801
|
+
* string. The type parameter carries static metadata for describe/CLI tooling.
|
|
1802
|
+
*/
|
|
1803
|
+
type FileInput<TMetadata = unknown> = string & {
|
|
1804
|
+
readonly __deeplineFileInputMetadata?: TMetadata;
|
|
1805
|
+
};
|
|
1806
|
+
/**
|
|
1807
|
+
* CSV file input whose rows are described by `TRow`.
|
|
1808
|
+
*
|
|
1809
|
+
* The CLI should expose this as the field name from the play input object,
|
|
1810
|
+
* stage local paths passed to that flag, and use `TRow` for row-contract
|
|
1811
|
+
* discovery.
|
|
1812
|
+
*/
|
|
1813
|
+
type CsvInput<TRow extends object = Record<string, unknown>> = FileInput<{
|
|
1814
|
+
readonly kind: 'csv';
|
|
1815
|
+
readonly row: TRow;
|
|
1816
|
+
}>;
|
|
1817
|
+
type ColumnMap<TRow extends object> = Partial<Record<Extract<keyof TRow, string>, string | readonly string[]>>;
|
|
1818
|
+
type CsvOptions = {
|
|
1819
|
+
description?: string;
|
|
1820
|
+
columns?: CsvRenameMap;
|
|
1821
|
+
rename?: CsvRenameMap;
|
|
1822
|
+
required?: readonly string[];
|
|
1813
1823
|
};
|
|
1814
1824
|
/**
|
|
1815
1825
|
* Runtime context available inside a play function.
|
|
@@ -1821,21 +1831,15 @@ type MapStepBuilder<InputRow extends object, OutputRow extends object> = {
|
|
|
1821
1831
|
* ```typescript
|
|
1822
1832
|
* definePlay('example', async (ctx, input: { domain: string }) => {
|
|
1823
1833
|
* // Call a tool
|
|
1824
|
-
* const company = await ctx.tools.execute({
|
|
1825
|
-
* id: 'company_search',
|
|
1826
|
-
* tool: 'test_company_search',
|
|
1827
|
-
* input: { domain: input.domain },
|
|
1834
|
+
* const company = await ctx.tools.execute('company_search', 'test_company_search', { domain: input.domain }, {
|
|
1828
1835
|
* description: 'Look up company details by domain.',
|
|
1829
1836
|
* });
|
|
1830
1837
|
*
|
|
1831
1838
|
* // Fan-out: process items with named steps
|
|
1832
1839
|
* const enriched = await ctx
|
|
1833
|
-
* .map('companies', [{ domain: 'a.com' }, { domain: 'b.com' }]
|
|
1840
|
+
* .map('companies', [{ domain: 'a.com' }, { domain: 'b.com' }])
|
|
1834
1841
|
* .step('company', (row, rowCtx) =>
|
|
1835
|
-
* rowCtx.tool({
|
|
1836
|
-
* id: 'company_search',
|
|
1837
|
-
* tool: 'test_company_search',
|
|
1838
|
-
* input: { domain: row.domain },
|
|
1842
|
+
* rowCtx.tool('company_search', 'test_company_search', { domain: row.domain }, {
|
|
1839
1843
|
* description: 'Look up company details by domain.',
|
|
1840
1844
|
* }))
|
|
1841
1845
|
* .run({ description: 'Look up company details.' });
|
|
@@ -1870,9 +1874,7 @@ interface DeeplinePlayRuntimeContext {
|
|
|
1870
1874
|
*
|
|
1871
1875
|
* @returns Parsed dataset rows
|
|
1872
1876
|
*/
|
|
1873
|
-
csv<T = Record<string, unknown>>(path: string, options?:
|
|
1874
|
-
description?: string;
|
|
1875
|
-
}): Promise<PlayDataset<T>>;
|
|
1877
|
+
csv<T = Record<string, unknown>>(path: string, options?: CsvOptions): Promise<PlayDataset<T>>;
|
|
1876
1878
|
/**
|
|
1877
1879
|
* Fan-out: process each item through one or more named columns.
|
|
1878
1880
|
*
|
|
@@ -1881,9 +1883,8 @@ interface DeeplinePlayRuntimeContext {
|
|
|
1881
1883
|
* play context — call tools, run waterfalls, do arbitrary logic.
|
|
1882
1884
|
*
|
|
1883
1885
|
* Items are processed in parallel (paced by the rate-limit scheduler).
|
|
1884
|
-
*
|
|
1885
|
-
*
|
|
1886
|
-
* hashing the full input row.
|
|
1886
|
+
* `key` identifies the logical output dataset/table. Row identity is derived
|
|
1887
|
+
* automatically from item content unless advanced run options override it.
|
|
1887
1888
|
* `options.staleAfterSeconds` intentionally partitions the durable cache on a
|
|
1888
1889
|
* relative time window. Use `86400` for daily reruns; retries inside the same
|
|
1889
1890
|
* window still replay safely.
|
|
@@ -1893,19 +1894,16 @@ interface DeeplinePlayRuntimeContext {
|
|
|
1893
1894
|
* play dataset handle.
|
|
1894
1895
|
*
|
|
1895
1896
|
* @typeParam T - Row type
|
|
1896
|
-
* @param key - Logical
|
|
1897
|
+
* @param key - Logical output dataset/table name (e.g. `'companies'`, `'email_lookup'`)
|
|
1897
1898
|
* @param items - Input rows or dataset handle
|
|
1898
1899
|
* @returns Dataset of rows merged with the computed column values
|
|
1899
1900
|
*
|
|
1900
1901
|
* @example Single tool per row
|
|
1901
1902
|
* ```typescript
|
|
1902
1903
|
* const results = await ctx
|
|
1903
|
-
* .map('
|
|
1904
|
+
* .map('companies', leads)
|
|
1904
1905
|
* .step('company', (row, ctx) =>
|
|
1905
|
-
* ctx.tools.execute({
|
|
1906
|
-
* id: 'company_search',
|
|
1907
|
-
* tool: 'test_company_search',
|
|
1908
|
-
* input: { domain: row.domain },
|
|
1906
|
+
* ctx.tools.execute('company_search', 'test_company_search', { domain: row.domain }, {
|
|
1909
1907
|
* description: 'Look up company details by domain.',
|
|
1910
1908
|
* }))
|
|
1911
1909
|
* .run({ description: 'Look up companies.' });
|
|
@@ -1915,12 +1913,9 @@ interface DeeplinePlayRuntimeContext {
|
|
|
1915
1913
|
* @example Multiple columns with pre/post logic
|
|
1916
1914
|
* ```typescript
|
|
1917
1915
|
* const results = await ctx
|
|
1918
|
-
* .map('leads', leads
|
|
1916
|
+
* .map('leads', leads)
|
|
1919
1917
|
* .step('company', (row, ctx) =>
|
|
1920
|
-
* ctx.tools.execute({
|
|
1921
|
-
* id: 'company_search',
|
|
1922
|
-
* tool: 'test_company_search',
|
|
1923
|
-
* input: { domain: row.domain },
|
|
1918
|
+
* ctx.tools.execute('company_search', 'test_company_search', { domain: row.domain }, {
|
|
1924
1919
|
* description: 'Look up company details by domain.',
|
|
1925
1920
|
* }))
|
|
1926
1921
|
* .step('score', (row) =>
|
|
@@ -1928,25 +1923,31 @@ interface DeeplinePlayRuntimeContext {
|
|
|
1928
1923
|
* .run({ description: 'Enrich leads.' });
|
|
1929
1924
|
* ```
|
|
1930
1925
|
*/
|
|
1931
|
-
map<TItem extends object>(key: string, items: PlayDatasetInput<TItem
|
|
1926
|
+
map<TItem extends object>(key: string, items: PlayDatasetInput<TItem>): MapStepBuilder<TItem, TItem>;
|
|
1932
1927
|
/** Tool execution namespace. */
|
|
1933
1928
|
tools: {
|
|
1934
1929
|
/**
|
|
1935
|
-
* Execute a single tool by stable
|
|
1930
|
+
* Execute a single tool by stable step key and tool ID.
|
|
1936
1931
|
*
|
|
1937
|
-
* @param
|
|
1938
|
-
*
|
|
1932
|
+
* @param key - Stable step key for idempotent execution
|
|
1933
|
+
* @param toolId - Tool identifier (e.g. `'test_company_search'`)
|
|
1934
|
+
* @param input - Tool-specific input parameters
|
|
1939
1935
|
* @returns The tool's output
|
|
1940
1936
|
*/
|
|
1941
1937
|
execute<TOutput = LoosePlayObject>(request: ToolExecutionRequest): Promise<ToolExecuteResult<TOutput>>;
|
|
1938
|
+
execute<TOutput = LoosePlayObject>(key: string, toolId: string, input: Record<string, unknown>, options?: {
|
|
1939
|
+
description?: string;
|
|
1940
|
+
}): Promise<ToolExecuteResult<TOutput>>;
|
|
1942
1941
|
};
|
|
1943
1942
|
/**
|
|
1944
|
-
* Execute a single tool by stable
|
|
1943
|
+
* Execute a single tool by stable step key and tool ID.
|
|
1945
1944
|
*
|
|
1946
|
-
* Shorthand for `ctx.tools.execute(
|
|
1947
|
-
*
|
|
1945
|
+
* Shorthand for `ctx.tools.execute(...)`; this is the preferred spelling in
|
|
1946
|
+
* row-level step programs.
|
|
1948
1947
|
*/
|
|
1949
|
-
tool<TOutput = LoosePlayObject>(
|
|
1948
|
+
tool<TOutput = LoosePlayObject>(key: string, toolId: string, input: Record<string, unknown>, options?: {
|
|
1949
|
+
description?: string;
|
|
1950
|
+
}): Promise<ToolExecuteResult<TOutput>>;
|
|
1950
1951
|
step<T>(id: string, run: () => T | Promise<T>): Promise<T>;
|
|
1951
1952
|
fetch(key: string, url: string | URL, init?: RequestInit): Promise<{
|
|
1952
1953
|
ok: boolean;
|
|
@@ -2164,13 +2165,9 @@ declare function when<Row, Value>(predicate: (row: Row, index: number) => boolea
|
|
|
2164
2165
|
* import { definePlay } from 'deepline';
|
|
2165
2166
|
*
|
|
2166
2167
|
* const myPlay = definePlay('my-play', async (ctx, input: { domain: string }) => {
|
|
2167
|
-
*
|
|
2168
|
-
* id: 'company_search',
|
|
2169
|
-
* tool: 'test_company_search',
|
|
2170
|
-
* input: { domain: input.domain },
|
|
2168
|
+
* return await ctx.tools.execute('company_search', 'test_company_search', { domain: input.domain }, {
|
|
2171
2169
|
* description: 'Look up company details by domain.',
|
|
2172
2170
|
* });
|
|
2173
|
-
* return { company: company.result };
|
|
2174
2171
|
* });
|
|
2175
2172
|
*
|
|
2176
2173
|
* // Type is: DefinedPlay<{ domain: string }, unknown>
|
|
@@ -2208,10 +2205,7 @@ type PlayMetadata = {
|
|
|
2208
2205
|
*
|
|
2209
2206
|
* // Tools
|
|
2210
2207
|
* const tools = await ctx.tools.list();
|
|
2211
|
-
* const result = await ctx.tools.execute({
|
|
2212
|
-
* tool: 'test_company_search',
|
|
2213
|
-
* input: { domain: 'stripe.com' },
|
|
2214
|
-
* });
|
|
2208
|
+
* const result = await ctx.tools.execute('test_company_search', { domain: 'stripe.com' });
|
|
2215
2209
|
*
|
|
2216
2210
|
* // Plays
|
|
2217
2211
|
* const job = await ctx.play('email-waterfall').run({ domain: 'stripe.com' });
|
|
@@ -2228,12 +2222,8 @@ declare class DeeplineContext {
|
|
|
2228
2222
|
* ```typescript
|
|
2229
2223
|
* const tools = await ctx.tools.list();
|
|
2230
2224
|
* const meta = await ctx.tools.get('apollo_people_search');
|
|
2231
|
-
* const
|
|
2232
|
-
*
|
|
2233
|
-
* input: { domain: 'stripe.com' },
|
|
2234
|
-
* });
|
|
2235
|
-
* const rows = result.tryList({ listExtractorPaths: ['people'] });
|
|
2236
|
-
* const email = result.getEmail();
|
|
2225
|
+
* const companyLookup = await ctx.tools.execute('test_company_search', { domain: 'stripe.com' });
|
|
2226
|
+
* const company = companyLookup.result.data;
|
|
2237
2227
|
* ```
|
|
2238
2228
|
*/
|
|
2239
2229
|
get tools(): {
|
|
@@ -2241,8 +2231,8 @@ declare class DeeplineContext {
|
|
|
2241
2231
|
list: () => Promise<ToolDefinition[]>;
|
|
2242
2232
|
/** Get detailed metadata for a tool. */
|
|
2243
2233
|
get: (toolId: string) => Promise<ToolMetadata>;
|
|
2244
|
-
/** Execute a tool and return
|
|
2245
|
-
execute: (
|
|
2234
|
+
/** Execute a tool and return the standard execution envelope. */
|
|
2235
|
+
execute: (toolId: string, input: Record<string, unknown>) => Promise<ToolExecuteResult>;
|
|
2246
2236
|
};
|
|
2247
2237
|
get plays(): {
|
|
2248
2238
|
list: () => Promise<PlayListItem[]>;
|
|
@@ -2276,10 +2266,7 @@ declare class DeeplineContext {
|
|
|
2276
2266
|
*
|
|
2277
2267
|
* const ctx = await Deepline.connect();
|
|
2278
2268
|
* const tools = await ctx.tools.list();
|
|
2279
|
-
* const result = await ctx.tools.execute({
|
|
2280
|
-
* tool: 'test_company_search',
|
|
2281
|
-
* input: { domain: 'stripe.com' },
|
|
2282
|
-
* });
|
|
2269
|
+
* const result = await ctx.tools.execute('test_company_search', { domain: 'stripe.com' });
|
|
2283
2270
|
* ```
|
|
2284
2271
|
*/
|
|
2285
2272
|
declare class Deepline {
|
|
@@ -2331,13 +2318,10 @@ declare function defineInput<TInput>(schema: Record<string, unknown>): PlayInput
|
|
|
2331
2318
|
*
|
|
2332
2319
|
* export default definePlay('company-lookup', async (ctx, input: { domain: string }) => {
|
|
2333
2320
|
* 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 },
|
|
2321
|
+
* const company = await ctx.tools.execute('company_search', 'test_company_search', { domain: input.domain }, {
|
|
2338
2322
|
* description: 'Look up company details by domain.',
|
|
2339
2323
|
* });
|
|
2340
|
-
* return
|
|
2324
|
+
* return company;
|
|
2341
2325
|
* });
|
|
2342
2326
|
* ```
|
|
2343
2327
|
*
|
|
@@ -2347,12 +2331,9 @@ declare function defineInput<TInput>(schema: Record<string, unknown>): PlayInput
|
|
|
2347
2331
|
* const leads = await ctx.csv('leads.csv');
|
|
2348
2332
|
* ctx.log(`Processing ${leads.length} rows`);
|
|
2349
2333
|
* const results = await ctx
|
|
2350
|
-
* .map('
|
|
2334
|
+
* .map('companies', leads)
|
|
2351
2335
|
* .step('company', (row, ctx) =>
|
|
2352
|
-
* ctx.tools.execute({
|
|
2353
|
-
* id: 'company_search',
|
|
2354
|
-
* tool: 'test_company_search',
|
|
2355
|
-
* input: { domain: row.domain },
|
|
2336
|
+
* ctx.tools.execute('company_search', 'test_company_search', { domain: row.domain }, {
|
|
2356
2337
|
* description: 'Look up company details by domain.',
|
|
2357
2338
|
* }))
|
|
2358
2339
|
* .run({ description: 'Enrich lead companies.' });
|
|
@@ -2363,10 +2344,7 @@ declare function defineInput<TInput>(schema: Record<string, unknown>): PlayInput
|
|
|
2363
2344
|
* @example With cron binding
|
|
2364
2345
|
* ```typescript
|
|
2365
2346
|
* 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' },
|
|
2347
|
+
* const data = await ctx.tools.execute('crm_export', 'crm_export', { since: 'yesterday' }, {
|
|
2370
2348
|
* description: 'Export yesterday CRM records.',
|
|
2371
2349
|
* });
|
|
2372
2350
|
* return data;
|
|
@@ -2421,4 +2399,145 @@ declare const defineWorkflow: typeof definePlay;
|
|
|
2421
2399
|
*/
|
|
2422
2400
|
declare function getDefinedPlayMetadata(value: unknown): PlayMetadata | null;
|
|
2423
2401
|
|
|
2424
|
-
|
|
2402
|
+
/**
|
|
2403
|
+
* Result of converting a tool response to a list of records.
|
|
2404
|
+
*
|
|
2405
|
+
* @example
|
|
2406
|
+
* ```typescript
|
|
2407
|
+
* const conversion = tryConvertToList(toolResponse, {
|
|
2408
|
+
* listExtractorPaths: ['people', 'result.data'],
|
|
2409
|
+
* });
|
|
2410
|
+
* if (conversion) {
|
|
2411
|
+
* console.log(`Found ${conversion.rows.length} rows via ${conversion.strategy}`);
|
|
2412
|
+
* console.log(`Source path: ${conversion.sourcePath}`);
|
|
2413
|
+
* }
|
|
2414
|
+
* ```
|
|
2415
|
+
*/
|
|
2416
|
+
type ListConversionResult = {
|
|
2417
|
+
/** Normalized array of record objects. Scalars are wrapped as `{ value: <scalar> }`. */
|
|
2418
|
+
rows: Array<Record<string, unknown>>;
|
|
2419
|
+
/**
|
|
2420
|
+
* How the list was found:
|
|
2421
|
+
* - `'configured_paths'` — matched one of the `listExtractorPaths`
|
|
2422
|
+
* - `'auto_detected'` — found via recursive DFS (longest array wins)
|
|
2423
|
+
*/
|
|
2424
|
+
strategy: 'configured_paths' | 'auto_detected';
|
|
2425
|
+
/** Dotted path to where the list was found (e.g. `"result.data"`, `"people"`). */
|
|
2426
|
+
sourcePath: string | null;
|
|
2427
|
+
};
|
|
2428
|
+
type Scalar = string | number | boolean | null;
|
|
2429
|
+
/**
|
|
2430
|
+
* Extract a list of records from a tool response.
|
|
2431
|
+
*
|
|
2432
|
+
* Handles the common problem of tools returning data in varied shapes.
|
|
2433
|
+
* First tries configured `listExtractorPaths` (from tool metadata), then
|
|
2434
|
+
* falls back to automatic detection via recursive DFS.
|
|
2435
|
+
*
|
|
2436
|
+
* ## Extraction strategy
|
|
2437
|
+
*
|
|
2438
|
+
* 1. **Configured paths** — If `listExtractorPaths` is provided, each path is
|
|
2439
|
+
* tried against multiple candidate roots (raw payload, `.result`, `.result.data`).
|
|
2440
|
+
* First match wins.
|
|
2441
|
+
*
|
|
2442
|
+
* 2. **Auto-detection** — If no configured path matches, recursively searches
|
|
2443
|
+
* the response for the largest array of objects (up to depth 5).
|
|
2444
|
+
*
|
|
2445
|
+
* @param payload - Raw tool response
|
|
2446
|
+
* @param options - Optional extraction configuration
|
|
2447
|
+
* @returns Extracted list with metadata, or `null` if no list found
|
|
2448
|
+
*
|
|
2449
|
+
* @example Using configured paths (from tool metadata)
|
|
2450
|
+
* ```typescript
|
|
2451
|
+
* const meta = await client.getTool('apollo_people_search');
|
|
2452
|
+
* const result = await client.executeTool('apollo_people_search', { query: 'cto' });
|
|
2453
|
+
*
|
|
2454
|
+
* const list = tryConvertToList(result, {
|
|
2455
|
+
* listExtractorPaths: meta.listExtractorPaths,
|
|
2456
|
+
* });
|
|
2457
|
+
* if (list) {
|
|
2458
|
+
* console.log(`${list.rows.length} people found via ${list.strategy}`);
|
|
2459
|
+
* // Write to CSV
|
|
2460
|
+
* const csv = writeCsvOutputFile(list.rows, 'apollo-people');
|
|
2461
|
+
* console.log(`Saved to ${csv.path}`);
|
|
2462
|
+
* }
|
|
2463
|
+
* ```
|
|
2464
|
+
*
|
|
2465
|
+
* @example Auto-detection (no configured paths)
|
|
2466
|
+
* ```typescript
|
|
2467
|
+
* const result = await client.executeTool('some_tool', { query: 'test' });
|
|
2468
|
+
* const list = tryConvertToList(result);
|
|
2469
|
+
* // Finds the largest array of objects anywhere in the response
|
|
2470
|
+
* ```
|
|
2471
|
+
*/
|
|
2472
|
+
declare function tryConvertToList(payload: unknown, options?: {
|
|
2473
|
+
listExtractorPaths?: string[];
|
|
2474
|
+
}): ListConversionResult | null;
|
|
2475
|
+
/**
|
|
2476
|
+
* Write a JSON payload to a timestamped file.
|
|
2477
|
+
*
|
|
2478
|
+
* Output location: `~/.local/share/deepline/data/{stem}_{timestamp}.json`
|
|
2479
|
+
*
|
|
2480
|
+
* @param payload - Any JSON-serializable value
|
|
2481
|
+
* @param stem - Filename prefix (e.g. tool ID or play name)
|
|
2482
|
+
* @returns Absolute path to the written file
|
|
2483
|
+
*
|
|
2484
|
+
* @example
|
|
2485
|
+
* ```typescript
|
|
2486
|
+
* const result = await client.executeTool('test_company_search', { domain: 'stripe.com' });
|
|
2487
|
+
* const path = writeJsonOutputFile(result, 'test_company_search');
|
|
2488
|
+
* console.log(`Saved to ${path}`);
|
|
2489
|
+
* // ~/.local/share/deepline/data/test_company_search_1713456789000.json
|
|
2490
|
+
* ```
|
|
2491
|
+
*/
|
|
2492
|
+
declare function writeJsonOutputFile(payload: unknown, stem: string): string;
|
|
2493
|
+
/**
|
|
2494
|
+
* Write an array of records to a CSV file.
|
|
2495
|
+
*
|
|
2496
|
+
* Columns are ordered by first appearance across all rows. Cells containing
|
|
2497
|
+
* commas, quotes, or newlines are properly escaped. Objects and arrays are
|
|
2498
|
+
* JSON-serialized.
|
|
2499
|
+
*
|
|
2500
|
+
* Output location: `~/.local/share/deepline/data/{stem}_{timestamp}.csv`
|
|
2501
|
+
*
|
|
2502
|
+
* @param rows - Array of record objects
|
|
2503
|
+
* @param stem - Filename prefix
|
|
2504
|
+
* @returns File metadata including path, row count, columns, and a 5×5 preview
|
|
2505
|
+
*
|
|
2506
|
+
* @example
|
|
2507
|
+
* ```typescript
|
|
2508
|
+
* const list = tryConvertToList(toolResponse);
|
|
2509
|
+
* if (list) {
|
|
2510
|
+
* const csv = writeCsvOutputFile(list.rows, 'search-results');
|
|
2511
|
+
* console.log(`Wrote ${csv.rowCount} rows, ${csv.columns.length} columns`);
|
|
2512
|
+
* console.log(`File: ${csv.path}`);
|
|
2513
|
+
* console.log(`Preview:\n${csv.preview}`);
|
|
2514
|
+
* }
|
|
2515
|
+
* ```
|
|
2516
|
+
*/
|
|
2517
|
+
declare function writeCsvOutputFile(rows: Array<Record<string, unknown>>, stem: string): {
|
|
2518
|
+
path: string;
|
|
2519
|
+
rowCount: number;
|
|
2520
|
+
columns: string[];
|
|
2521
|
+
preview: string;
|
|
2522
|
+
};
|
|
2523
|
+
/**
|
|
2524
|
+
* Extract scalar (non-nested) fields from a tool response for summary display.
|
|
2525
|
+
*
|
|
2526
|
+
* Searches through candidate roots (raw → `.result` → `.result.data`) and
|
|
2527
|
+
* returns the first set of scalar fields found. Useful for displaying a
|
|
2528
|
+
* quick summary of single-record responses.
|
|
2529
|
+
*
|
|
2530
|
+
* @param payload - Raw tool response
|
|
2531
|
+
* @returns Object containing only scalar fields (string, number, boolean, null)
|
|
2532
|
+
*
|
|
2533
|
+
* @example
|
|
2534
|
+
* ```typescript
|
|
2535
|
+
* const result = await client.executeTool('test_company_search', { domain: 'stripe.com' });
|
|
2536
|
+
* const summary = extractSummaryFields(result);
|
|
2537
|
+
* // { name: "Stripe", industry: "Financial Services", employeeCount: 8000 }
|
|
2538
|
+
* // (nested objects and arrays are excluded)
|
|
2539
|
+
* ```
|
|
2540
|
+
*/
|
|
2541
|
+
declare function extractSummaryFields(payload: unknown): Record<string, Scalar>;
|
|
2542
|
+
|
|
2543
|
+
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 };
|