deepline 0.1.12 → 0.1.20

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 (82) hide show
  1. package/README.md +14 -6
  2. package/dist/cli/index.js +1346 -717
  3. package/dist/cli/index.mjs +1342 -713
  4. package/dist/index.d.mts +199 -23
  5. package/dist/index.d.ts +199 -23
  6. package/dist/index.js +221 -14
  7. package/dist/index.mjs +221 -14
  8. package/dist/repo/apps/play-runner-workers/src/coordinator-entry.ts +214 -77
  9. package/dist/repo/apps/play-runner-workers/src/dedup-do.ts +85 -60
  10. package/dist/repo/apps/play-runner-workers/src/entry.ts +385 -66
  11. package/dist/repo/sdk/src/client.ts +237 -0
  12. package/dist/repo/sdk/src/config.ts +125 -8
  13. package/dist/repo/sdk/src/http.ts +29 -5
  14. package/dist/repo/sdk/src/play.ts +19 -36
  15. package/dist/repo/sdk/src/plays/bundle-play-file.ts +22 -8
  16. package/dist/repo/sdk/src/plays/local-file-discovery.ts +207 -160
  17. package/dist/repo/sdk/src/types.ts +25 -0
  18. package/dist/repo/sdk/src/version.ts +2 -2
  19. package/dist/repo/shared_libs/play-runtime/tool-result.ts +237 -145
  20. package/dist/repo/shared_libs/plays/bundling/index.ts +206 -229
  21. package/dist/repo/shared_libs/plays/dataset.ts +28 -0
  22. package/dist/repo/shared_libs/plays/row-identity.ts +59 -4
  23. package/package.json +5 -4
  24. package/dist/cli/index.js.map +0 -1
  25. package/dist/cli/index.mjs.map +0 -1
  26. package/dist/index.js.map +0 -1
  27. package/dist/index.mjs.map +0 -1
  28. package/dist/repo/apps/play-runner-workers/src/runtime/README.md +0 -21
  29. package/dist/repo/apps/play-runner-workers/src/runtime/batching.ts +0 -177
  30. package/dist/repo/apps/play-runner-workers/src/runtime/execution-plan.ts +0 -52
  31. package/dist/repo/apps/play-runner-workers/src/runtime/tool-batch.ts +0 -100
  32. package/dist/repo/sdk/src/cli/commands/auth.ts +0 -500
  33. package/dist/repo/sdk/src/cli/commands/billing.ts +0 -188
  34. package/dist/repo/sdk/src/cli/commands/csv.ts +0 -123
  35. package/dist/repo/sdk/src/cli/commands/db.ts +0 -119
  36. package/dist/repo/sdk/src/cli/commands/feedback.ts +0 -40
  37. package/dist/repo/sdk/src/cli/commands/org.ts +0 -117
  38. package/dist/repo/sdk/src/cli/commands/play.ts +0 -3441
  39. package/dist/repo/sdk/src/cli/commands/tools.ts +0 -687
  40. package/dist/repo/sdk/src/cli/dataset-stats.ts +0 -415
  41. package/dist/repo/sdk/src/cli/index.ts +0 -148
  42. package/dist/repo/sdk/src/cli/progress.ts +0 -149
  43. package/dist/repo/sdk/src/cli/skills-sync.ts +0 -141
  44. package/dist/repo/sdk/src/cli/trace.ts +0 -61
  45. package/dist/repo/sdk/src/cli/utils.ts +0 -145
  46. package/dist/repo/sdk/src/compat.ts +0 -77
  47. package/dist/repo/shared_libs/observability/node-tracing.ts +0 -129
  48. package/dist/repo/shared_libs/observability/tracing.ts +0 -98
  49. package/dist/repo/shared_libs/play-runtime/context.ts +0 -4242
  50. package/dist/repo/shared_libs/play-runtime/ctx-contract.ts +0 -250
  51. package/dist/repo/shared_libs/play-runtime/ctx-types.ts +0 -725
  52. package/dist/repo/shared_libs/play-runtime/dataset-id.ts +0 -10
  53. package/dist/repo/shared_libs/play-runtime/db-session-crypto.ts +0 -304
  54. package/dist/repo/shared_libs/play-runtime/db-session.ts +0 -462
  55. package/dist/repo/shared_libs/play-runtime/live-events.ts +0 -214
  56. package/dist/repo/shared_libs/play-runtime/live-state-contract.ts +0 -50
  57. package/dist/repo/shared_libs/play-runtime/map-execution-frame.ts +0 -114
  58. package/dist/repo/shared_libs/play-runtime/map-row-identity.ts +0 -158
  59. package/dist/repo/shared_libs/play-runtime/progress-emitter.ts +0 -172
  60. package/dist/repo/shared_libs/play-runtime/protocol.ts +0 -121
  61. package/dist/repo/shared_libs/play-runtime/public-play-contract.ts +0 -42
  62. package/dist/repo/shared_libs/play-runtime/result-normalization.ts +0 -33
  63. package/dist/repo/shared_libs/play-runtime/runtime-api.ts +0 -1873
  64. package/dist/repo/shared_libs/play-runtime/runtime-constraints.ts +0 -2
  65. package/dist/repo/shared_libs/play-runtime/runtime-pg-driver-neon-serverless.ts +0 -201
  66. package/dist/repo/shared_libs/play-runtime/runtime-pg-driver-pg.ts +0 -48
  67. package/dist/repo/shared_libs/play-runtime/runtime-pg-driver.ts +0 -84
  68. package/dist/repo/shared_libs/play-runtime/static-pipeline-types.ts +0 -147
  69. package/dist/repo/shared_libs/play-runtime/suspension.ts +0 -68
  70. package/dist/repo/shared_libs/play-runtime/tracing.ts +0 -31
  71. package/dist/repo/shared_libs/play-runtime/waterfall-replay.ts +0 -75
  72. package/dist/repo/shared_libs/play-runtime/worker-api-types.ts +0 -140
  73. package/dist/repo/shared_libs/plays/artifact-transport.ts +0 -14
  74. package/dist/repo/shared_libs/plays/artifact-types.ts +0 -49
  75. package/dist/repo/shared_libs/plays/compiler-manifest.ts +0 -186
  76. package/dist/repo/shared_libs/plays/definition.ts +0 -264
  77. package/dist/repo/shared_libs/plays/file-refs.ts +0 -11
  78. package/dist/repo/shared_libs/plays/rate-limit-scheduler.ts +0 -206
  79. package/dist/repo/shared_libs/plays/resolve-static-pipeline.ts +0 -164
  80. package/dist/repo/shared_libs/plays/runtime-validation.ts +0 -395
  81. package/dist/repo/shared_libs/temporal/constants.ts +0 -39
  82. package/dist/repo/shared_libs/temporal/preview-config.ts +0 -153
@@ -1,68 +1,34 @@
1
- export type ToolResultExecutionMetadata = {
2
- idempotent: true;
3
- cached: boolean;
4
- source: 'live' | 'checkpoint' | 'cache';
5
- cacheKey?: string;
6
- };
7
-
8
- export type ToolResultTargetMetadata = {
9
- path: string;
10
- };
11
-
12
- export type ToolResultListMetadata = {
13
- path: string;
14
- count: number | null;
15
- keys: Record<string, string>;
16
- };
17
-
18
- export type ToolExtractedValue<T = unknown> = {
19
- path: string;
20
- get(): T | null;
21
- };
22
-
23
- export type ToolResultEnvelope<
24
- TData = unknown,
25
- TMeta = Record<string, unknown>,
26
- > = {
27
- data: TData;
28
- meta?: TMeta;
29
- };
30
-
31
- export type ToolResultMetadata = {
32
- toolId: string;
33
- execution: ToolResultExecutionMetadata;
34
- targets: Record<string, ToolResultTargetMetadata>;
35
- lists: Record<string, ToolResultListMetadata>;
36
- };
37
-
38
- export type ToolResultMetadataInput = {
39
- toolId: string;
40
- resultIdentityGetters?: Record<string, readonly string[]>;
41
- listExtractorPaths?: readonly string[];
42
- listIdentityGetters?: Record<string, readonly string[]>;
43
- };
44
-
45
- export type ToolExecuteResult<
46
- TData = unknown,
47
- TMeta = Record<string, unknown>,
48
- > = {
49
- status: string;
50
- result: ToolResultEnvelope<TData, TMeta>;
51
- extracted: Record<string, ToolExtractedValue>;
52
- lists: Record<
53
- string,
54
- ToolResultListMetadata & {
55
- get(): Record<string, unknown>[];
56
- }
57
- >;
58
- };
59
-
60
- type PathSegment = string | number;
1
+ export type {
2
+ ToolExecuteResult,
3
+ ToolResultExecutionMetadata,
4
+ ToolResultMetadata,
5
+ ToolResultMetadataInput,
6
+ ToolResultListMetadata,
7
+ ToolResultListAccessor,
8
+ ToolResultTargetMetadata,
9
+ ToolResultTargetAccessor,
10
+ } from './tool-result-types';
11
+
12
+ import type {
13
+ ToolExecuteResult,
14
+ ToolResultExecutionMetadata,
15
+ ToolResultListAccessor,
16
+ ToolResultListMetadata,
17
+ ToolResultEnvelope,
18
+ ToolResultMetadataInput,
19
+ ToolResultTargetAccessor,
20
+ ToolResultTargetMetadata,
21
+ } from './tool-result-types';
22
+
23
+ type PathSegment = string | number | '*';
61
24
 
62
25
  const TARGET_FALLBACK_KEYS: Record<string, readonly RegExp[]> = {
63
26
  email: [/^email$/i, /^address$/i, /email/i],
64
27
  phone: [/^phone$/i, /mobile/i, /phone/i, /telephone/i],
65
28
  linkedin: [/^linkedin_url$/i, /^linkedin$/i, /linkedin/i],
29
+ company_linkedin_url: [/company.*linkedin/i, /linkedin.*company/i],
30
+ company_domain: [/^company_domain$/i, /company.*domain/i],
31
+ company_name: [/^company_name$/i, /company.*name/i],
66
32
  domain: [/^domain$/i, /company_domain/i, /domain/i],
67
33
  status: [/^email_status$/i, /^status$/i],
68
34
  email_status: [/^email_status$/i, /^status$/i],
@@ -83,12 +49,14 @@ function isMeaningfulValue(value: unknown): boolean {
83
49
  function parsePath(path: string): PathSegment[] {
84
50
  const segments: PathSegment[] = [];
85
51
  for (const rawPart of path.split('.').filter(Boolean)) {
86
- const bracketPattern = /([^\[\]]+)|\[(\d+)\]/g;
52
+ const bracketPattern = /([^\[\]]+)|\[(\d+|\*)\]/g;
87
53
  let matched = false;
88
54
  for (const match of rawPart.matchAll(bracketPattern)) {
89
55
  matched = true;
90
56
  if (match[1]) {
91
57
  segments.push(match[1]);
58
+ } else if (match[2] === '*') {
59
+ segments.push('*');
92
60
  } else if (match[2]) {
93
61
  segments.push(Number(match[2]));
94
62
  }
@@ -105,16 +73,85 @@ function pathToString(segments: readonly PathSegment[]): string {
105
73
  .map((segment, index) =>
106
74
  typeof segment === 'number'
107
75
  ? `[${segment}]`
108
- : index === 0
109
- ? segment
110
- : `.${segment}`,
76
+ : segment === '*'
77
+ ? '[*]'
78
+ : index === 0
79
+ ? segment
80
+ : `.${segment}`,
111
81
  )
112
82
  .join('');
113
83
  }
114
84
 
85
+ function valuesAtSegments(
86
+ current: unknown,
87
+ segments: readonly PathSegment[],
88
+ path: readonly PathSegment[] = [],
89
+ ): Array<{ value: unknown; path: string }> {
90
+ if (segments.length === 0) {
91
+ return [{ value: current, path: pathToString(path) }];
92
+ }
93
+ const [segment, ...rest] = segments;
94
+ if (segment === '*') {
95
+ if (!Array.isArray(current)) return [];
96
+ return current.flatMap((entry, index) =>
97
+ valuesAtSegments(entry, rest, [...path, index]),
98
+ );
99
+ }
100
+ if (typeof segment === 'number') {
101
+ if (!Array.isArray(current)) return [];
102
+ return valuesAtSegments(current[segment], rest, [...path, segment]);
103
+ }
104
+ if (!isRecord(current)) return [];
105
+ return valuesAtSegments(current[segment], rest, [...path, segment]);
106
+ }
107
+
108
+ function getValuesAtPath(root: unknown, path: string): unknown[] {
109
+ return valuesAtSegments(root, parsePath(path)).map((entry) => entry.value);
110
+ }
111
+
112
+ function toResultEnvelope(value: unknown): ToolResultEnvelope {
113
+ if (isRecord(value) && 'data' in value) {
114
+ const envelope: ToolResultEnvelope = { data: value.data };
115
+ if ('meta' in value) envelope.meta = value.meta as Record<string, unknown>;
116
+ return envelope;
117
+ }
118
+ return { data: value };
119
+ }
120
+
121
+ function normalizeResultPath(path: string): string {
122
+ const trimmed = String(path || '')
123
+ .trim()
124
+ .replace(/^\./, '');
125
+ if (!trimmed) return '';
126
+ return trimmed.startsWith('result.') ? trimmed : `result.${trimmed}`;
127
+ }
128
+
129
+ function normalizeRelativePath(path: string): string {
130
+ return String(path || '')
131
+ .trim()
132
+ .replace(/^result\./, '')
133
+ .replace(/^\./, '');
134
+ }
135
+
136
+ function getFirstMeaningfulValueAtPath(
137
+ root: unknown,
138
+ path: string,
139
+ ): ToolResultTargetMetadata | null {
140
+ for (const entry of valuesAtSegments(root, parsePath(path))) {
141
+ if (isMeaningfulValue(entry.value)) {
142
+ return { value: entry.value, path: entry.path };
143
+ }
144
+ }
145
+ return null;
146
+ }
147
+
115
148
  function getAtPath(root: unknown, path: string): unknown {
149
+ const segments = parsePath(path);
150
+ if (segments.includes('*')) {
151
+ return getValuesAtPath(root, path).filter(isMeaningfulValue);
152
+ }
116
153
  let current = root;
117
- for (const segment of parsePath(path)) {
154
+ for (const segment of segments) {
118
155
  if (typeof segment === 'number') {
119
156
  if (!Array.isArray(current)) return undefined;
120
157
  current = current[segment];
@@ -126,20 +163,15 @@ function getAtPath(root: unknown, path: string): unknown {
126
163
  return current;
127
164
  }
128
165
 
129
- function asResultPath(path: string): string {
130
- const normalized = path.trim().replace(/^result\./, '');
131
- return normalized ? `result.${normalized}` : 'result';
132
- }
133
-
134
- function toResultEnvelope(value: unknown): ToolResultEnvelope {
135
- if (isRecord(value) && 'data' in value) {
136
- const envelope: ToolResultEnvelope = { data: value.data };
137
- if ('meta' in value) {
138
- envelope.meta = value.meta as Record<string, unknown>;
139
- }
140
- return envelope;
166
+ function normalizeString(value: unknown): string | null {
167
+ if (typeof value === 'string') {
168
+ const trimmed = value.trim();
169
+ return trimmed ? trimmed : null;
141
170
  }
142
- return { data: value };
171
+ if (typeof value === 'number' && Number.isFinite(value)) {
172
+ return String(value);
173
+ }
174
+ return null;
143
175
  }
144
176
 
145
177
  function normalizeRows(value: unknown): Record<string, unknown>[] | null {
@@ -152,14 +184,10 @@ function findFirstTargetByPath(
152
184
  paths: readonly string[] | undefined,
153
185
  ): ToolResultTargetMetadata | null {
154
186
  for (const path of paths ?? []) {
155
- const normalizedPath = String(path || '')
156
- .trim()
157
- .replace(/^result\./, '');
187
+ const normalizedPath = normalizeResultPath(path);
158
188
  if (!normalizedPath) continue;
159
- const value = getAtPath(result, normalizedPath);
160
- if (isMeaningfulValue(value)) {
161
- return { path: asResultPath(normalizedPath) };
162
- }
189
+ const match = getFirstMeaningfulValueAtPath(result, normalizedPath);
190
+ if (match) return match;
163
191
  }
164
192
  return null;
165
193
  }
@@ -191,7 +219,7 @@ function findFirstTargetByKey(
191
219
  patterns.some((pattern) => pattern.test(key)) &&
192
220
  isMeaningfulValue(value)
193
221
  ) {
194
- return { path: asResultPath(pathToString([...path, key])) };
222
+ return { value, path: pathToString([...path, key]) };
195
223
  }
196
224
  }
197
225
  for (const [key, value] of Object.entries(result)) {
@@ -213,23 +241,32 @@ function resolveListRows(
213
241
  { path: string; rows: Record<string, unknown>[] }
214
242
  > = {};
215
243
  for (const rawPath of listExtractorPaths ?? []) {
216
- const path = String(rawPath || '')
217
- .trim()
218
- .replace(/^result\./, '');
244
+ const path = normalizeResultPath(rawPath);
219
245
  if (!path) continue;
220
- let resolvedPath = path;
221
- let rows = normalizeRows(getAtPath(result, resolvedPath));
222
- if (!rows && !path.startsWith('data.')) {
223
- resolvedPath = `data.${path}`;
224
- rows = normalizeRows(getAtPath(result, resolvedPath));
246
+ const candidates = [
247
+ path,
248
+ path.replace(/^result\./, 'result.data.'),
249
+ ].filter(
250
+ (candidate, index, all) =>
251
+ candidate && all.indexOf(candidate) === index,
252
+ );
253
+ let resolvedPath: string | null = null;
254
+ let rows: Record<string, unknown>[] | null = null;
255
+ for (const candidate of candidates) {
256
+ rows = normalizeRows(getAtPath(result, candidate));
257
+ if (rows) {
258
+ resolvedPath = candidate;
259
+ break;
260
+ }
225
261
  }
226
262
  if (!rows) continue;
227
- const name = resolvedPath
263
+ const storedPath = resolvedPath ?? path;
264
+ const name = storedPath
228
265
  .split('.')
229
266
  .filter(Boolean)
230
267
  .at(-1)
231
268
  ?.replace(/\[\d+\]$/, '');
232
- lists[name || resolvedPath] = { path: resolvedPath, rows };
269
+ lists[name || storedPath] = { path: storedPath, rows };
233
270
  }
234
271
  return lists;
235
272
  }
@@ -246,9 +283,7 @@ function deriveListKeys(input: {
246
283
  )) {
247
284
  const firstPath = paths
248
285
  .map((rawPath) =>
249
- String(rawPath || '')
250
- .trim()
251
- .replace(/^result\./, ''),
286
+ normalizeRelativePath(rawPath),
252
287
  )
253
288
  .find(Boolean);
254
289
  if (firstPath) {
@@ -266,23 +301,29 @@ function deriveListKeys(input: {
266
301
  for (const rawPath of paths) {
267
302
  const path = String(rawPath || '')
268
303
  .trim()
269
- .replace(/^result\./, '');
304
+ .replace(/^\./, '');
270
305
  if (!path) continue;
306
+ const resultPath = normalizeResultPath(path);
271
307
  const directPrefix = `${listPrefix}.`;
272
- if (path.startsWith(directPrefix)) {
273
- keys[target] = path
308
+ if (resultPath.startsWith(directPrefix)) {
309
+ keys[target] = resultPath
274
310
  .slice(directPrefix.length)
275
311
  .replace(/^\[\d+\]\.?/, '');
276
312
  break;
277
313
  }
278
314
  const indexedPrefix = `${listPrefix}[0].`;
279
- if (path.startsWith(indexedPrefix)) {
280
- keys[target] = path.slice(indexedPrefix.length);
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);
281
322
  break;
282
323
  }
283
324
  const dottedIndexPrefix = `${listPrefix}.0.`;
284
- if (path.startsWith(dottedIndexPrefix)) {
285
- keys[target] = path.slice(dottedIndexPrefix.length);
325
+ if (resultPath.startsWith(dottedIndexPrefix)) {
326
+ keys[target] = resultPath.slice(dottedIndexPrefix.length);
286
327
  break;
287
328
  }
288
329
  }
@@ -332,7 +373,7 @@ function buildLists(
332
373
  const resolved = resolveListRows(result, metadata.listExtractorPaths);
333
374
  for (const [name, list] of Object.entries(resolved)) {
334
375
  lists[name] = {
335
- path: asResultPath(list.path),
376
+ path: list.path,
336
377
  count: list.rows.length,
337
378
  keys: deriveListKeys({
338
379
  listPath: list.path,
@@ -345,29 +386,49 @@ function buildLists(
345
386
  return lists;
346
387
  }
347
388
 
348
- function attachDescriptorMethods<TResult>(
349
- wrapper: ToolExecuteResult<TResult>,
350
- ): ToolExecuteResult<TResult> {
351
- for (const descriptor of Object.values(wrapper.extracted)) {
352
- Object.defineProperty(descriptor, 'get', {
353
- configurable: true,
354
- enumerable: false,
355
- value: () => {
356
- const value = getAtPath(wrapper, descriptor.path);
357
- return isMeaningfulValue(value) ? value : null;
358
- },
359
- });
360
- }
361
-
362
- for (const descriptor of Object.values(wrapper.lists)) {
363
- Object.defineProperty(descriptor, 'get', {
364
- configurable: true,
365
- enumerable: false,
366
- value: () => normalizeRows(getAtPath(wrapper, descriptor.path)) ?? [],
367
- });
368
- }
389
+ function buildExtractedAccessors(
390
+ targets: Record<string, ToolResultTargetMetadata>,
391
+ ): Record<string, ToolResultTargetAccessor> {
392
+ return Object.fromEntries(
393
+ Object.entries(targets).map(([target, metadata]) => {
394
+ const accessor = { path: metadata.path } as ToolResultTargetAccessor;
395
+ Object.defineProperties(accessor, {
396
+ value: {
397
+ value: metadata.value,
398
+ enumerable: false,
399
+ },
400
+ get: {
401
+ value() {
402
+ return metadata.value ?? null;
403
+ },
404
+ enumerable: false,
405
+ },
406
+ });
407
+ return [target, accessor];
408
+ }),
409
+ );
410
+ }
369
411
 
370
- return wrapper;
412
+ function buildListAccessors(
413
+ result: unknown,
414
+ lists: Record<string, ToolResultListMetadata>,
415
+ ): Record<string, ToolResultListAccessor> {
416
+ return Object.fromEntries(
417
+ Object.entries(lists).map(([name, metadata]) => {
418
+ const accessor = {
419
+ path: metadata.path,
420
+ count: metadata.count,
421
+ keys: metadata.keys,
422
+ } as ToolResultListAccessor;
423
+ Object.defineProperty(accessor, 'get', {
424
+ value() {
425
+ return normalizeRows(getAtPath(result, metadata.path)) ?? [];
426
+ },
427
+ enumerable: false,
428
+ });
429
+ return [name, accessor];
430
+ }),
431
+ );
371
432
  }
372
433
 
373
434
  export function createToolExecuteResult<TResult = unknown>(input: {
@@ -376,17 +437,30 @@ export function createToolExecuteResult<TResult = unknown>(input: {
376
437
  metadata: ToolResultMetadataInput;
377
438
  execution: ToolResultExecutionMetadata;
378
439
  }): ToolExecuteResult<TResult> {
379
- void input.execution;
380
- const result = toResultEnvelope(input.result) as ToolResultEnvelope<TResult>;
381
- const extracted = buildTargets(result, input.metadata.resultIdentityGetters);
382
- const lists = buildLists(result, input.metadata);
383
- const wrapper: ToolExecuteResult<TResult> = {
440
+ const result = toResultEnvelope(input.result);
441
+ const resultRoot = { result };
442
+ const targets = buildTargets(
443
+ resultRoot,
444
+ input.metadata.resultIdentityGetters,
445
+ );
446
+ const lists = buildLists(resultRoot, input.metadata);
447
+ const metadata = {
448
+ toolId: input.metadata.toolId,
449
+ execution: input.execution,
450
+ targets,
451
+ lists,
452
+ };
453
+ const wrapper = {
384
454
  status: input.status,
385
455
  result,
386
- extracted: extracted as Record<string, ToolExtractedValue>,
387
- lists: lists as ToolExecuteResult<TResult>['lists'],
388
- };
389
- return attachDescriptorMethods(wrapper);
456
+ extracted: buildExtractedAccessors(targets),
457
+ lists: buildListAccessors(resultRoot, lists),
458
+ } as ToolExecuteResult<TResult>;
459
+ Object.defineProperty(wrapper, '_metadata', {
460
+ value: metadata,
461
+ enumerable: false,
462
+ });
463
+ return wrapper;
390
464
  }
391
465
 
392
466
  export function isToolExecuteResult(
@@ -395,11 +469,9 @@ export function isToolExecuteResult(
395
469
  return (
396
470
  isRecord(value) &&
397
471
  typeof value.status === 'string' &&
398
- 'result' in value &&
399
- isRecord(value.result) &&
400
- 'data' in value.result &&
401
- 'extracted' in value &&
402
- isRecord(value.extracted)
472
+ '_metadata' in value &&
473
+ isRecord(value._metadata) &&
474
+ 'result' in value
403
475
  );
404
476
  }
405
477
 
@@ -407,6 +479,26 @@ export function cloneToolExecuteResultWithExecution<TResult>(
407
479
  value: ToolExecuteResult<TResult>,
408
480
  execution: ToolResultExecutionMetadata,
409
481
  ): ToolExecuteResult<TResult> {
410
- void execution;
411
- return attachDescriptorMethods(value);
482
+ return createToolExecuteResult<TResult>({
483
+ status: value.status,
484
+ result: value.result as TResult,
485
+ metadata: {
486
+ toolId: value._metadata.toolId,
487
+ resultIdentityGetters: Object.fromEntries(
488
+ Object.entries(value._metadata.targets).map(([target, info]) => [
489
+ target,
490
+ [info.path],
491
+ ]),
492
+ ),
493
+ listExtractorPaths: Object.values(value._metadata.lists).map(
494
+ (list) => list.path,
495
+ ),
496
+ listIdentityGetters: Object.fromEntries(
497
+ Object.values(value._metadata.lists)
498
+ .flatMap((list) => Object.entries(list.keys))
499
+ .map(([target, path]) => [target, [path]]),
500
+ ),
501
+ },
502
+ execution,
503
+ });
412
504
  }