deepline 0.1.32 → 0.1.35

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.
@@ -38,6 +38,64 @@ function isRecord(value: unknown): value is Record<string, unknown> {
38
38
  return Boolean(value) && typeof value === 'object' && !Array.isArray(value);
39
39
  }
40
40
 
41
+ export type V2ToolExecuteOutput = {
42
+ raw: unknown;
43
+ meta?: Record<string, unknown>;
44
+ };
45
+
46
+ export function parseV2ToolExecuteOutput(
47
+ data: Record<string, unknown>,
48
+ ): V2ToolExecuteOutput | null {
49
+ const toolExecutionResult = data.toolExecutionResult;
50
+ if (!isRecord(toolExecutionResult)) return null;
51
+ const toolOutput = toolExecutionResult.toolOutput;
52
+ if (!isRecord(toolOutput)) return null;
53
+ const meta = isRecord(toolOutput.meta) ? toolOutput.meta : undefined;
54
+ return {
55
+ raw: Object.prototype.hasOwnProperty.call(toolOutput, 'raw')
56
+ ? toolOutput.raw
57
+ : null,
58
+ ...(meta ? { meta } : {}),
59
+ };
60
+ }
61
+
62
+ export function adaptV2ExecuteResponseToToolResult(
63
+ data: Record<string, unknown>,
64
+ ): { output?: V2ToolExecuteOutput; result: unknown } {
65
+ const output = parseV2ToolExecuteOutput(data);
66
+ if (!output) {
67
+ return { result: data.result ?? data };
68
+ }
69
+ return {
70
+ output,
71
+ result: {
72
+ data: output.raw,
73
+ ...(output.meta ? { meta: output.meta } : {}),
74
+ },
75
+ };
76
+ }
77
+
78
+ export function toV2RawToolOutputPath(path: string): string {
79
+ const normalized = String(path || '')
80
+ .trim()
81
+ .replace(/^\./, '');
82
+ if (!normalized) return 'toolExecutionResult.toolOutput.raw';
83
+ if (
84
+ normalized === 'toolExecutionResult.toolOutput.raw' ||
85
+ normalized.startsWith('toolExecutionResult.toolOutput.raw.')
86
+ ) {
87
+ return normalized;
88
+ }
89
+ const rawPath = normalized
90
+ .replace(/^result\.data\.?/, '')
91
+ .replace(/^result\.?/, '')
92
+ .replace(/^data\.?/, '')
93
+ .replace(/^\./, '');
94
+ return rawPath
95
+ ? `toolExecutionResult.toolOutput.raw.${rawPath}`
96
+ : 'toolExecutionResult.toolOutput.raw';
97
+ }
98
+
41
99
  function isMeaningfulValue(value: unknown): boolean {
42
100
  if (value == null) return false;
43
101
  if (typeof value === 'string') return value.trim().length > 0;
@@ -123,7 +181,37 @@ function normalizeResultPath(path: string): string {
123
181
  .trim()
124
182
  .replace(/^\./, '');
125
183
  if (!trimmed) return '';
126
- return trimmed.startsWith('result.') ? trimmed : `result.${trimmed}`;
184
+ return toV2RawToolOutputPath(trimmed);
185
+ }
186
+
187
+ function toV2RawToolOutputPathPreservingProviderData(path: string): string {
188
+ const normalized = String(path || '')
189
+ .trim()
190
+ .replace(/^\./, '');
191
+ if (!normalized) return 'toolExecutionResult.toolOutput.raw';
192
+ if (
193
+ normalized === 'toolExecutionResult.toolOutput.raw' ||
194
+ normalized.startsWith('toolExecutionResult.toolOutput.raw.')
195
+ ) {
196
+ return normalized;
197
+ }
198
+ const rawPath = normalized
199
+ .replace(/^result\.?/, '')
200
+ .replace(/^\./, '');
201
+ return rawPath
202
+ ? `toolExecutionResult.toolOutput.raw.${rawPath}`
203
+ : 'toolExecutionResult.toolOutput.raw';
204
+ }
205
+
206
+ function candidateResultPaths(path: string): string[] {
207
+ const candidates = [
208
+ normalizeResultPath(path),
209
+ toV2RawToolOutputPathPreservingProviderData(path),
210
+ ];
211
+ return candidates.filter(
212
+ (candidate, index, all) =>
213
+ candidate.length > 0 && all.indexOf(candidate) === index,
214
+ );
127
215
  }
128
216
 
129
217
  function normalizeRelativePath(path: string): string {
@@ -184,10 +272,10 @@ function findFirstTargetByPath(
184
272
  paths: readonly string[] | undefined,
185
273
  ): ToolResultTargetMetadata | null {
186
274
  for (const path of paths ?? []) {
187
- const normalizedPath = normalizeResultPath(path);
188
- if (!normalizedPath) continue;
189
- const match = getFirstMeaningfulValueAtPath(result, normalizedPath);
190
- if (match) return match;
275
+ for (const candidate of candidateResultPaths(path)) {
276
+ const match = getFirstMeaningfulValueAtPath(result, candidate);
277
+ if (match) return match;
278
+ }
191
279
  }
192
280
  return null;
193
281
  }
@@ -244,8 +332,7 @@ function resolveListRows(
244
332
  const path = normalizeResultPath(rawPath);
245
333
  if (!path) continue;
246
334
  const candidates = [
247
- path,
248
- path.replace(/^result\./, 'result.data.'),
335
+ ...candidateResultPaths(rawPath),
249
336
  ].filter(
250
337
  (candidate, index, all) =>
251
338
  candidate && all.indexOf(candidate) === index,
@@ -303,29 +390,31 @@ function deriveListKeys(input: {
303
390
  .trim()
304
391
  .replace(/^\./, '');
305
392
  if (!path) continue;
306
- const resultPath = normalizeResultPath(path);
307
- const directPrefix = `${listPrefix}.`;
308
- if (resultPath.startsWith(directPrefix)) {
309
- keys[target] = resultPath
310
- .slice(directPrefix.length)
311
- .replace(/^\[\d+\]\.?/, '');
312
- break;
313
- }
314
- const indexedPrefix = `${listPrefix}[0].`;
315
- if (resultPath.startsWith(indexedPrefix)) {
316
- keys[target] = resultPath.slice(indexedPrefix.length);
317
- break;
318
- }
319
- const wildcardPrefix = `${listPrefix}[*].`;
320
- if (resultPath.startsWith(wildcardPrefix)) {
321
- keys[target] = resultPath.slice(wildcardPrefix.length);
322
- break;
323
- }
324
- const dottedIndexPrefix = `${listPrefix}.0.`;
325
- if (resultPath.startsWith(dottedIndexPrefix)) {
326
- keys[target] = resultPath.slice(dottedIndexPrefix.length);
327
- break;
393
+ for (const resultPath of candidateResultPaths(path)) {
394
+ const directPrefix = `${listPrefix}.`;
395
+ if (resultPath.startsWith(directPrefix)) {
396
+ keys[target] = resultPath
397
+ .slice(directPrefix.length)
398
+ .replace(/^\[\d+\]\.?/, '');
399
+ break;
400
+ }
401
+ const indexedPrefix = `${listPrefix}[0].`;
402
+ if (resultPath.startsWith(indexedPrefix)) {
403
+ keys[target] = resultPath.slice(indexedPrefix.length);
404
+ break;
405
+ }
406
+ const wildcardPrefix = `${listPrefix}[*].`;
407
+ if (resultPath.startsWith(wildcardPrefix)) {
408
+ keys[target] = resultPath.slice(wildcardPrefix.length);
409
+ break;
410
+ }
411
+ const dottedIndexPrefix = `${listPrefix}.0.`;
412
+ if (resultPath.startsWith(dottedIndexPrefix)) {
413
+ keys[target] = resultPath.slice(dottedIndexPrefix.length);
414
+ break;
415
+ }
328
416
  }
417
+ if (keys[target]) break;
329
418
  }
330
419
  }
331
420
  if (Object.keys(keys).length === 0 && input.rows[0]) {
@@ -438,7 +527,14 @@ export function createToolExecuteResult<TResult = unknown>(input: {
438
527
  execution: ToolResultExecutionMetadata;
439
528
  }): ToolExecuteResult<TResult> {
440
529
  const result = toResultEnvelope(input.result);
441
- const resultRoot = { result };
530
+ const resultRoot = {
531
+ toolExecutionResult: {
532
+ toolOutput: {
533
+ raw: result.data,
534
+ ...(result.meta ? { meta: result.meta } : {}),
535
+ },
536
+ },
537
+ };
442
538
  const targets = buildTargets(
443
539
  resultRoot,
444
540
  input.metadata.resultIdentityGetters,
@@ -452,9 +548,13 @@ export function createToolExecuteResult<TResult = unknown>(input: {
452
548
  };
453
549
  const wrapper = {
454
550
  status: input.status,
455
- result,
456
- extracted: buildExtractedAccessors(targets),
457
- lists: buildListAccessors(resultRoot, lists),
551
+ toolOutput: {
552
+ raw: result.data,
553
+ ...(result.meta ? { meta: result.meta } : {}),
554
+ },
555
+ meta: input.execution,
556
+ extractedValues: buildExtractedAccessors(targets),
557
+ extractedLists: buildListAccessors(resultRoot, lists),
458
558
  } as ToolExecuteResult<TResult>;
459
559
  Object.defineProperty(wrapper, '_metadata', {
460
560
  value: metadata,
@@ -471,7 +571,7 @@ export function isToolExecuteResult(
471
571
  typeof value.status === 'string' &&
472
572
  '_metadata' in value &&
473
573
  isRecord(value._metadata) &&
474
- 'result' in value
574
+ 'toolOutput' in value
475
575
  );
476
576
  }
477
577
 
@@ -481,7 +581,10 @@ export function cloneToolExecuteResultWithExecution<TResult>(
481
581
  ): ToolExecuteResult<TResult> {
482
582
  return createToolExecuteResult<TResult>({
483
583
  status: value.status,
484
- result: value.result as TResult,
584
+ result: {
585
+ data: value.toolOutput.raw,
586
+ ...(value.toolOutput.meta ? { meta: value.toolOutput.meta } : {}),
587
+ } as TResult,
485
588
  metadata: {
486
589
  toolId: value._metadata.toolId,
487
590
  resultIdentityGetters: Object.fromEntries(
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "deepline",
3
- "version": "0.1.32",
3
+ "version": "0.1.35",
4
4
  "description": "Deepline SDK + CLI — B2B data enrichment powered by durable cloud execution",
5
5
  "license": "MIT",
6
6
  "repository": {