deepline 0.1.319 → 0.1.320
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/bundling-sources/sdk/src/play.ts +8 -1
- package/dist/bundling-sources/sdk/src/release.ts +1 -1
- package/dist/bundling-sources/shared_libs/play-runtime/context.ts +10 -1
- package/dist/bundling-sources/shared_libs/play-runtime/runtime-api.ts +20 -1
- package/dist/bundling-sources/shared_libs/play-runtime/tool-result.ts +11 -0
- package/dist/bundling-sources/shared_libs/plays/dataset.ts +134 -2
- package/dist/cli/index.js +2 -2
- package/dist/cli/index.mjs +2 -2
- package/dist/index.d.mts +9 -1
- package/dist/index.d.ts +9 -1
- package/dist/index.js +97 -3
- package/dist/index.mjs +97 -3
- package/package.json +1 -1
|
@@ -1862,7 +1862,9 @@ function attachSdkQueryResultDatasetResult(
|
|
|
1862
1862
|
}
|
|
1863
1863
|
const datasetLimit =
|
|
1864
1864
|
finitePositiveInteger(dataset.returned_limit) ?? totalRows;
|
|
1865
|
-
const
|
|
1865
|
+
const effectiveCount = Math.min(totalRows, datasetLimit);
|
|
1866
|
+
const rawRows = rowsFromUnknown(raw?.rows);
|
|
1867
|
+
const previewRows = rawRows.slice(0, 25);
|
|
1866
1868
|
const fetchPage = async (
|
|
1867
1869
|
offset: number,
|
|
1868
1870
|
limit: number,
|
|
@@ -1927,10 +1929,15 @@ function attachSdkQueryResultDatasetResult(
|
|
|
1927
1929
|
datasetId: `sdk-tool-list:${toolId}:${stableHash(datasetScope)}:${datasetLimit}:${safeNonce}`,
|
|
1928
1930
|
count: Math.min(totalRows, datasetLimit),
|
|
1929
1931
|
previewRows,
|
|
1932
|
+
residentRows:
|
|
1933
|
+
rawRows.length >= effectiveCount
|
|
1934
|
+
? rawRows.slice(0, effectiveCount)
|
|
1935
|
+
: null,
|
|
1930
1936
|
sourceLabel: 'query result rows',
|
|
1931
1937
|
tableNamespace: null,
|
|
1932
1938
|
resolvers: {
|
|
1933
1939
|
count: async () => Math.min(totalRows, datasetLimit),
|
|
1940
|
+
at: async (index) => (await fetchPage(index, 1))[0],
|
|
1934
1941
|
peek: async (limit) => collectRows(limit),
|
|
1935
1942
|
materialize: async (limit) => collectRows(limit),
|
|
1936
1943
|
iterate: () =>
|
|
@@ -157,7 +157,7 @@ export const SDK_RELEASE = {
|
|
|
157
157
|
// 0.1.253 makes play-page browser opening opt-in and retires --no-open.
|
|
158
158
|
// 0.1.254 removes the internal operations tree from the published SDK CLI.
|
|
159
159
|
// Operators use the checkout-local deepline-admin binary instead.
|
|
160
|
-
version: '0.1.
|
|
160
|
+
version: '0.1.320',
|
|
161
161
|
contracts: {
|
|
162
162
|
api: {
|
|
163
163
|
name: 'sdk-http-api',
|
|
@@ -3658,6 +3658,7 @@ export class PlayContextImpl {
|
|
|
3658
3658
|
const originalRequestInput = requestInput as Record<string, unknown>;
|
|
3659
3659
|
const datasetLimit =
|
|
3660
3660
|
finitePositiveInteger(dataset.returned_limit) ?? totalRows;
|
|
3661
|
+
const effectiveCount = Math.min(totalRows, datasetLimit);
|
|
3661
3662
|
const previewRows = rows.slice(0, Math.min(rows.length, 25));
|
|
3662
3663
|
const executionNonce =
|
|
3663
3664
|
typeof wrapped.job_id === 'string' && wrapped.job_id.trim()
|
|
@@ -3718,12 +3719,15 @@ export class PlayContextImpl {
|
|
|
3718
3719
|
const playDataset = createDeferredPlayDataset({
|
|
3719
3720
|
datasetKind: 'csv',
|
|
3720
3721
|
datasetId,
|
|
3721
|
-
count:
|
|
3722
|
+
count: effectiveCount,
|
|
3722
3723
|
previewRows,
|
|
3724
|
+
residentRows:
|
|
3725
|
+
rows.length >= effectiveCount ? rows.slice(0, effectiveCount) : null,
|
|
3723
3726
|
sourceLabel: 'query result rows',
|
|
3724
3727
|
tableNamespace: null,
|
|
3725
3728
|
resolvers: {
|
|
3726
3729
|
count: async () => Math.min(totalRows, datasetLimit),
|
|
3730
|
+
at: async (index) => (await fetchPage(index, 1))[0],
|
|
3727
3731
|
peek: async (limit) => collectRows(limit),
|
|
3728
3732
|
materialize: async (limit) => collectRows(limit),
|
|
3729
3733
|
iterate: () =>
|
|
@@ -4803,6 +4807,10 @@ export class PlayContextImpl {
|
|
|
4803
4807
|
},
|
|
4804
4808
|
},
|
|
4805
4809
|
previewRows,
|
|
4810
|
+
residentRows:
|
|
4811
|
+
immediateMaterializedRows.length === successfulCount
|
|
4812
|
+
? immediateMaterializedRows
|
|
4813
|
+
: null,
|
|
4806
4814
|
tableNamespace: resolvedTableNamespace,
|
|
4807
4815
|
workProgress: {
|
|
4808
4816
|
total: totalInputCount,
|
|
@@ -5417,6 +5425,7 @@ export class PlayContextImpl {
|
|
|
5417
5425
|
previewRows: results
|
|
5418
5426
|
.slice(0, 5)
|
|
5419
5427
|
.map((row) => this.toMaterializedOutputRow(row)),
|
|
5428
|
+
residentRows: terminalRows,
|
|
5420
5429
|
tableNamespace: resolvedTableNamespace,
|
|
5421
5430
|
workProgress: {
|
|
5422
5431
|
total: totalInputCount,
|
|
@@ -8139,7 +8139,8 @@ export function createRuntimeBackedPlayDataset(input: {
|
|
|
8139
8139
|
}): PlayDataset<Record<string, unknown>> {
|
|
8140
8140
|
const csvRows =
|
|
8141
8141
|
input.datasetKind === 'csv' &&
|
|
8142
|
-
|
|
8142
|
+
typeof input.initialCount === 'number' &&
|
|
8143
|
+
(input.initialPreviewRows?.length ?? 0) >= input.initialCount
|
|
8143
8144
|
? [...(input.initialPreviewRows ?? [])]
|
|
8144
8145
|
: null;
|
|
8145
8146
|
if (csvRows) {
|
|
@@ -8151,6 +8152,7 @@ export function createRuntimeBackedPlayDataset(input: {
|
|
|
8151
8152
|
),
|
|
8152
8153
|
count: input.initialCount ?? csvRows.length,
|
|
8153
8154
|
previewRows: csvRows.slice(0, 10),
|
|
8155
|
+
residentRows: csvRows,
|
|
8154
8156
|
sourceLabel: input.sourceLabel ?? null,
|
|
8155
8157
|
resolvers: {
|
|
8156
8158
|
count: async () => csvRows.length,
|
|
@@ -8181,6 +8183,7 @@ export function createRuntimeBackedPlayDataset(input: {
|
|
|
8181
8183
|
input.tableNamespace,
|
|
8182
8184
|
),
|
|
8183
8185
|
count: input.initialCount ?? 0,
|
|
8186
|
+
knownCount: input.initialCount ?? null,
|
|
8184
8187
|
backing: {
|
|
8185
8188
|
storage: 'neon_sheet',
|
|
8186
8189
|
sheet: {
|
|
@@ -8222,6 +8225,22 @@ export function createRuntimeBackedPlayDataset(input: {
|
|
|
8222
8225
|
);
|
|
8223
8226
|
return rows.map((row) => row.data);
|
|
8224
8227
|
},
|
|
8228
|
+
at: async (index) => {
|
|
8229
|
+
const session = await getRuntimeDbSession(runtimeContext, {
|
|
8230
|
+
tableNamespace: input.tableNamespace,
|
|
8231
|
+
logicalTable: 'sheet_rows',
|
|
8232
|
+
operations: ['rows.read'],
|
|
8233
|
+
});
|
|
8234
|
+
const rows = await readRuntimeRows(
|
|
8235
|
+
requireRuntimePostgresSession(session),
|
|
8236
|
+
{
|
|
8237
|
+
limit: 1,
|
|
8238
|
+
offset: index,
|
|
8239
|
+
runId: input.runId ?? null,
|
|
8240
|
+
},
|
|
8241
|
+
);
|
|
8242
|
+
return rows[0]?.data;
|
|
8243
|
+
},
|
|
8225
8244
|
materialize: async (limit) => {
|
|
8226
8245
|
const pageSize = 1000;
|
|
8227
8246
|
const materialized: Record<string, unknown>[] = [];
|
|
@@ -42,6 +42,7 @@ import {
|
|
|
42
42
|
createDeferredPlayDataset,
|
|
43
43
|
createPlayDataset,
|
|
44
44
|
isSerializedPlayDataset,
|
|
45
|
+
residentPlayDatasetRows,
|
|
45
46
|
trimSerializedPlayDatasetPreview,
|
|
46
47
|
type PlayDataset,
|
|
47
48
|
type SerializedPlayDataset,
|
|
@@ -1395,6 +1396,15 @@ function serializedListRowsFromResult(input: {
|
|
|
1395
1396
|
]);
|
|
1396
1397
|
const entries = [...names].flatMap((name) => {
|
|
1397
1398
|
const dataset = input.listDatasets?.[name];
|
|
1399
|
+
const liveDataset = input.value.extractedLists[name]?.get();
|
|
1400
|
+
const residentRows = liveDataset
|
|
1401
|
+
? residentPlayDatasetRows(liveDataset)
|
|
1402
|
+
: null;
|
|
1403
|
+
if (residentRows && (!dataset || residentRows.length >= dataset.count)) {
|
|
1404
|
+
return [
|
|
1405
|
+
[name, [...residentRows] as Array<Record<string, unknown>>] as const,
|
|
1406
|
+
];
|
|
1407
|
+
}
|
|
1398
1408
|
const preservedRows = preserved?.[name];
|
|
1399
1409
|
if (preservedRows && (!dataset || preservedRows.length >= dataset.count)) {
|
|
1400
1410
|
return [[name, preservedRows]] as const;
|
|
@@ -1509,6 +1519,7 @@ function createDatasetFromSerializedToolList(
|
|
|
1509
1519
|
count: serialized.count,
|
|
1510
1520
|
backing: serialized.backing,
|
|
1511
1521
|
previewRows: preview,
|
|
1522
|
+
residentRows: isPartialPreview ? null : sourceRows,
|
|
1512
1523
|
sourceLabel: serialized.sourceLabel ?? null,
|
|
1513
1524
|
tableNamespace: serialized.tableNamespace ?? null,
|
|
1514
1525
|
workProgress: serialized._metadata?.workProgress,
|
|
@@ -2,6 +2,7 @@ import type { PlayExecutionFileRef } from './file-refs';
|
|
|
2
2
|
|
|
3
3
|
const PLAY_DATASET_BRAND = Symbol.for('deepline.play.dataset');
|
|
4
4
|
const NODE_INSPECT_CUSTOM = Symbol.for('nodejs.util.inspect.custom');
|
|
5
|
+
const residentRowsByDataset = new WeakMap<object, readonly unknown[]>();
|
|
5
6
|
const DEFAULT_MATERIALIZE_LIMIT = 10_000;
|
|
6
7
|
export const PLAY_DATASET_EXECUTION_PAGE_ROWS = 1_000;
|
|
7
8
|
export const PLAY_DATASET_EXECUTION_PAGE_BYTES = 64 * 1024 * 1024;
|
|
@@ -109,8 +110,12 @@ export type PlayDatasetTransformOptions = {
|
|
|
109
110
|
*
|
|
110
111
|
* @sdkReference runtime 190
|
|
111
112
|
*/
|
|
112
|
-
export interface PlayDataset<T> extends AsyncIterable<T> {
|
|
113
|
+
export interface PlayDataset<T> extends AsyncIterable<T>, Iterable<T> {
|
|
113
114
|
readonly [PLAY_DATASET_BRAND]: true;
|
|
115
|
+
/** Authoritative row count when known without I/O. */
|
|
116
|
+
readonly length: number;
|
|
117
|
+
/** Resident row access. Throws when the requested row requires I/O. */
|
|
118
|
+
readonly [index: number]: T;
|
|
114
119
|
/** Dataset kind. */
|
|
115
120
|
readonly datasetKind: PlayDatasetKind;
|
|
116
121
|
/** Dataset id. */
|
|
@@ -125,6 +130,10 @@ export interface PlayDataset<T> extends AsyncIterable<T> {
|
|
|
125
130
|
count(): Promise<number>;
|
|
126
131
|
/** Preview rows. */
|
|
127
132
|
peek(limit?: number): Promise<T[]>;
|
|
133
|
+
/** First row, loading it asynchronously when necessary. */
|
|
134
|
+
first(): Promise<T | undefined>;
|
|
135
|
+
/** Row at an array-style index, loading it asynchronously when necessary. */
|
|
136
|
+
at(index: number): Promise<T | undefined>;
|
|
128
137
|
map<U>(
|
|
129
138
|
mapper: (row: T, index: number) => U | Promise<U>,
|
|
130
139
|
options?: PlayDatasetTransformOptions,
|
|
@@ -164,6 +173,7 @@ export interface PlayDataset<T> extends AsyncIterable<T> {
|
|
|
164
173
|
type PlayDatasetResolvers<T> = {
|
|
165
174
|
count: () => Promise<number>;
|
|
166
175
|
peek: (limit: number) => Promise<T[]>;
|
|
176
|
+
at?: (index: number) => Promise<T | undefined>;
|
|
167
177
|
materialize: (limit?: number) => Promise<T[]>;
|
|
168
178
|
materializeFullPersistedDataset?: (limit?: number) => Promise<T[]>;
|
|
169
179
|
iterate: () => AsyncIterable<T>;
|
|
@@ -223,6 +233,13 @@ export function isPlayDataset<T>(value: unknown): value is PlayDataset<T> {
|
|
|
223
233
|
);
|
|
224
234
|
}
|
|
225
235
|
|
|
236
|
+
/** Internal compatibility view for preserving proven-complete rows on replay. */
|
|
237
|
+
export function residentPlayDatasetRows<T>(
|
|
238
|
+
dataset: PlayDataset<T>,
|
|
239
|
+
): readonly T[] | null {
|
|
240
|
+
return (residentRowsByDataset.get(dataset as object) as readonly T[]) ?? null;
|
|
241
|
+
}
|
|
242
|
+
|
|
226
243
|
export function isSerializedPlayDataset<T>(
|
|
227
244
|
value: unknown,
|
|
228
245
|
): value is SerializedPlayDataset<T> {
|
|
@@ -317,6 +334,7 @@ export function deserializePlayDatasetCell<T>(
|
|
|
317
334
|
count: rows.length,
|
|
318
335
|
backing: dataset.backing,
|
|
319
336
|
previewRows: rows.slice(0, 10),
|
|
337
|
+
residentRows: rows,
|
|
320
338
|
sourceLabel: dataset.sourceLabel ?? null,
|
|
321
339
|
tableNamespace: dataset.tableNamespace ?? null,
|
|
322
340
|
workProgress: dataset._metadata?.workProgress,
|
|
@@ -355,6 +373,7 @@ export function deserializeLegacyPlayDataset<T>(
|
|
|
355
373
|
count: dataset.count,
|
|
356
374
|
backing: dataset.backing,
|
|
357
375
|
previewRows: rows,
|
|
376
|
+
residentRows: complete ? rows : null,
|
|
358
377
|
sourceLabel: dataset.sourceLabel ?? null,
|
|
359
378
|
tableNamespace: dataset.tableNamespace ?? null,
|
|
360
379
|
workProgress: dataset._metadata?.workProgress,
|
|
@@ -394,6 +413,7 @@ export function trimSerializedPlayDatasetPreview<T>(
|
|
|
394
413
|
}
|
|
395
414
|
|
|
396
415
|
class DeferredPlayDataset<T> implements PlayDataset<T> {
|
|
416
|
+
readonly [index: number]: T;
|
|
397
417
|
readonly [PLAY_DATASET_BRAND] = true as const;
|
|
398
418
|
readonly datasetKind: PlayDatasetKind;
|
|
399
419
|
readonly datasetId: string;
|
|
@@ -404,14 +424,18 @@ class DeferredPlayDataset<T> implements PlayDataset<T> {
|
|
|
404
424
|
private readonly previewColumns?: string[];
|
|
405
425
|
private readonly workProgress?: PlayDatasetWorkProgressSummary;
|
|
406
426
|
private cachedCount: number;
|
|
427
|
+
private knownCount: number | null;
|
|
428
|
+
private readonly residentRows: readonly T[] | null;
|
|
407
429
|
private readonly resolvers: PlayDatasetResolvers<T>;
|
|
408
430
|
|
|
409
431
|
constructor(input: {
|
|
410
432
|
datasetKind: PlayDatasetKind;
|
|
411
433
|
datasetId: string;
|
|
412
434
|
count: number;
|
|
435
|
+
knownCount?: number | null;
|
|
413
436
|
backing?: PlayDatasetBacking;
|
|
414
437
|
previewRows: readonly T[];
|
|
438
|
+
residentRows?: readonly T[] | null;
|
|
415
439
|
sourceLabel?: string | null;
|
|
416
440
|
tableNamespace?: string | null;
|
|
417
441
|
workProgress?: PlayDatasetWorkProgressSummary;
|
|
@@ -420,8 +444,11 @@ class DeferredPlayDataset<T> implements PlayDataset<T> {
|
|
|
420
444
|
this.datasetKind = input.datasetKind;
|
|
421
445
|
this.datasetId = input.datasetId;
|
|
422
446
|
this.cachedCount = input.count;
|
|
447
|
+
this.knownCount =
|
|
448
|
+
input.knownCount === undefined ? input.count : input.knownCount;
|
|
423
449
|
this.backing = input.backing;
|
|
424
450
|
this.previewRows = input.previewRows;
|
|
451
|
+
this.residentRows = input.residentRows ?? null;
|
|
425
452
|
this.previewColumns = inferPreviewColumns(this.previewRows);
|
|
426
453
|
this.sourceLabel = input.sourceLabel ?? null;
|
|
427
454
|
this.tableNamespace = input.tableNamespace ?? null;
|
|
@@ -429,8 +456,18 @@ class DeferredPlayDataset<T> implements PlayDataset<T> {
|
|
|
429
456
|
this.resolvers = input.resolvers;
|
|
430
457
|
}
|
|
431
458
|
|
|
459
|
+
get length(): number {
|
|
460
|
+
if (this.knownCount === null) {
|
|
461
|
+
throw this.requiresAsyncAccess(
|
|
462
|
+
'The row count is not known until this lazy transform executes.',
|
|
463
|
+
);
|
|
464
|
+
}
|
|
465
|
+
return this.knownCount;
|
|
466
|
+
}
|
|
467
|
+
|
|
432
468
|
async count(): Promise<number> {
|
|
433
469
|
this.cachedCount = await this.resolvers.count();
|
|
470
|
+
this.knownCount = this.cachedCount;
|
|
434
471
|
return this.cachedCount;
|
|
435
472
|
}
|
|
436
473
|
|
|
@@ -441,6 +478,29 @@ class DeferredPlayDataset<T> implements PlayDataset<T> {
|
|
|
441
478
|
return await this.resolvers.peek(limit);
|
|
442
479
|
}
|
|
443
480
|
|
|
481
|
+
async first(): Promise<T | undefined> {
|
|
482
|
+
return await this.at(0);
|
|
483
|
+
}
|
|
484
|
+
|
|
485
|
+
async at(index: number): Promise<T | undefined> {
|
|
486
|
+
if (!Number.isFinite(index)) return undefined;
|
|
487
|
+
const integer = Math.trunc(index);
|
|
488
|
+
const count = integer < 0 ? await this.count() : this.knownCount;
|
|
489
|
+
const normalized =
|
|
490
|
+
integer < 0 && count !== null ? count + integer : integer;
|
|
491
|
+
if (normalized < 0 || (count !== null && normalized >= count)) {
|
|
492
|
+
return undefined;
|
|
493
|
+
}
|
|
494
|
+
if (this.residentRows) return this.residentRows[normalized];
|
|
495
|
+
if (this.resolvers.at) return await this.resolvers.at(normalized);
|
|
496
|
+
let current = 0;
|
|
497
|
+
for await (const row of this.resolvers.iterate()) {
|
|
498
|
+
if (current === normalized) return row;
|
|
499
|
+
current += 1;
|
|
500
|
+
}
|
|
501
|
+
return undefined;
|
|
502
|
+
}
|
|
503
|
+
|
|
444
504
|
map<U>(
|
|
445
505
|
mapper: (row: T, index: number) => U | Promise<U>,
|
|
446
506
|
options?: PlayDatasetTransformOptions,
|
|
@@ -531,6 +591,33 @@ class DeferredPlayDataset<T> implements PlayDataset<T> {
|
|
|
531
591
|
}
|
|
532
592
|
}
|
|
533
593
|
|
|
594
|
+
[Symbol.iterator](): Iterator<T> {
|
|
595
|
+
if (!this.residentRows) {
|
|
596
|
+
throw this.requiresAsyncAccess(
|
|
597
|
+
'Synchronous iteration is available only when every row is resident.',
|
|
598
|
+
);
|
|
599
|
+
}
|
|
600
|
+
return this.residentRows[Symbol.iterator]();
|
|
601
|
+
}
|
|
602
|
+
|
|
603
|
+
residentAt(index: number): T | undefined {
|
|
604
|
+
if (this.knownCount !== null && index >= this.knownCount) return undefined;
|
|
605
|
+
if (!this.residentRows) {
|
|
606
|
+
throw this.requiresAsyncAccess(
|
|
607
|
+
`Row ${index} is not resident and may require dataset paging.`,
|
|
608
|
+
);
|
|
609
|
+
}
|
|
610
|
+
return this.residentRows[index];
|
|
611
|
+
}
|
|
612
|
+
|
|
613
|
+
private requiresAsyncAccess(detail: string): Error {
|
|
614
|
+
return new Error(
|
|
615
|
+
`PLAY_DATASET_REQUIRES_ASYNC_ACCESS: ${detail} ` +
|
|
616
|
+
`Dataset Handle ${this.sourceLabel ?? this.datasetId}. ` +
|
|
617
|
+
'Use await dataset.first(), await dataset.at(index), await dataset.materialize(limit), or for await...of.',
|
|
618
|
+
);
|
|
619
|
+
}
|
|
620
|
+
|
|
534
621
|
toJSON() {
|
|
535
622
|
return {
|
|
536
623
|
kind: 'dataset' as const,
|
|
@@ -666,6 +753,7 @@ function createTransformedPlayDataset<T, U>(
|
|
|
666
753
|
key: options?.key,
|
|
667
754
|
}),
|
|
668
755
|
count: 0,
|
|
756
|
+
knownCount: null,
|
|
669
757
|
backing: source.backing,
|
|
670
758
|
sourceLabel,
|
|
671
759
|
tableNamespace: options?.key ?? null,
|
|
@@ -687,17 +775,60 @@ export function createDeferredPlayDataset<T>(input: {
|
|
|
687
775
|
datasetKind: PlayDatasetKind;
|
|
688
776
|
datasetId: string;
|
|
689
777
|
count: number;
|
|
778
|
+
/** Authoritative synchronous count, or null when execution must determine it. */
|
|
779
|
+
knownCount?: number | null;
|
|
690
780
|
backing?: PlayDatasetBacking;
|
|
691
781
|
previewRows?: readonly T[];
|
|
782
|
+
/** Complete in-memory row set. Never pass a bounded preview here. */
|
|
783
|
+
residentRows?: readonly T[] | null;
|
|
692
784
|
sourceLabel?: string | null;
|
|
693
785
|
tableNamespace?: string | null;
|
|
694
786
|
workProgress?: PlayDatasetWorkProgressSummary;
|
|
695
787
|
resolvers: PlayDatasetResolvers<T>;
|
|
696
788
|
}): PlayDataset<T> {
|
|
697
|
-
|
|
789
|
+
if (
|
|
790
|
+
input.residentRows &&
|
|
791
|
+
input.knownCount !== null &&
|
|
792
|
+
input.residentRows.length !== (input.knownCount ?? input.count)
|
|
793
|
+
) {
|
|
794
|
+
throw new Error(
|
|
795
|
+
`Resident Dataset Handle ${input.datasetId} has ${input.residentRows.length} rows but declares ${input.knownCount ?? input.count}.`,
|
|
796
|
+
);
|
|
797
|
+
}
|
|
798
|
+
const target = new DeferredPlayDataset({
|
|
698
799
|
...input,
|
|
699
800
|
previewRows: input.previewRows ?? [],
|
|
700
801
|
});
|
|
802
|
+
const boundMethods = new Map<PropertyKey, unknown>();
|
|
803
|
+
const dataset = new Proxy(target, {
|
|
804
|
+
get(dataset, property) {
|
|
805
|
+
if (typeof property === 'string' && /^(0|[1-9]\d*)$/.test(property)) {
|
|
806
|
+
return dataset.residentAt(Number(property));
|
|
807
|
+
}
|
|
808
|
+
const value = Reflect.get(dataset, property, dataset);
|
|
809
|
+
if (typeof value !== 'function') return value;
|
|
810
|
+
if (!boundMethods.has(property)) {
|
|
811
|
+
boundMethods.set(property, value.bind(dataset));
|
|
812
|
+
}
|
|
813
|
+
return boundMethods.get(property);
|
|
814
|
+
},
|
|
815
|
+
set(_dataset, property) {
|
|
816
|
+
if (
|
|
817
|
+
property === 'length' ||
|
|
818
|
+
(typeof property === 'string' && /^(0|[1-9]\d*)$/.test(property))
|
|
819
|
+
) {
|
|
820
|
+
throw new Error(
|
|
821
|
+
'PLAY_DATASET_READ_ONLY: Dataset Handle rows cannot be assigned directly.',
|
|
822
|
+
);
|
|
823
|
+
}
|
|
824
|
+
return false;
|
|
825
|
+
},
|
|
826
|
+
});
|
|
827
|
+
if (input.residentRows) {
|
|
828
|
+
residentRowsByDataset.set(target, input.residentRows);
|
|
829
|
+
residentRowsByDataset.set(dataset, input.residentRows);
|
|
830
|
+
}
|
|
831
|
+
return dataset;
|
|
701
832
|
}
|
|
702
833
|
|
|
703
834
|
export function createPlayDataset<T>(
|
|
@@ -719,6 +850,7 @@ export function createPlayDataset<T>(
|
|
|
719
850
|
`${metadata?.kind ?? 'map'}:${metadata?.tableNamespace ?? metadata?.sourceLabel ?? 'inline'}`,
|
|
720
851
|
count: materializedRows.length,
|
|
721
852
|
previewRows: materializedRows.slice(0, 5),
|
|
853
|
+
residentRows: materializedRows,
|
|
722
854
|
sourceLabel: metadata?.sourceLabel ?? null,
|
|
723
855
|
tableNamespace: metadata?.tableNamespace ?? null,
|
|
724
856
|
resolvers: {
|
package/dist/cli/index.js
CHANGED
|
@@ -1037,7 +1037,7 @@ var SDK_RELEASE = {
|
|
|
1037
1037
|
// 0.1.253 makes play-page browser opening opt-in and retires --no-open.
|
|
1038
1038
|
// 0.1.254 removes the internal operations tree from the published SDK CLI.
|
|
1039
1039
|
// Operators use the checkout-local deepline-admin binary instead.
|
|
1040
|
-
version: "0.1.
|
|
1040
|
+
version: "0.1.320",
|
|
1041
1041
|
contracts: {
|
|
1042
1042
|
api: {
|
|
1043
1043
|
name: "sdk-http-api",
|
|
@@ -11991,7 +11991,7 @@ async function traceCliSpan(phase, fields, run) {
|
|
|
11991
11991
|
|
|
11992
11992
|
// src/cli/play-check-hints.ts
|
|
11993
11993
|
var EXTRACTED_GETTER_ERROR_HINT = "Deepline hint: extractedValues/extractedLists .get() only works for declared Deepline getters listed by `deepline tools describe <tool> --json`. Use `toolExecutionResult.toolResponse.raw` for provider/tool-specific scalar fields, and `toolExecutionResult.extractedLists.<name>.get()` for declared row/list outputs.";
|
|
11994
|
-
var DATASET_API_HINT = "Deepline hint: PlayDataset is lazy and durable.
|
|
11994
|
+
var DATASET_API_HINT = "Deepline hint: PlayDataset is lazy and durable. Complete resident handles support read-only length/index/iteration. For paged rows use `.first()`, `.at(index)`, `.peek(n)`, `.materialize(limit)`, or async iteration; do not use `.rows` or `.toArray()`.";
|
|
11995
11995
|
var ROW_PROPERTY_HINT = "Deepline hint: this row type only contains fields produced by the CSV/schema and previous map steps. Check source column casing and the exact output field names from earlier steps before scaling.";
|
|
11996
11996
|
var TOOLS_EXECUTE_SIGNATURE_HINT = "Deepline hint: ctx.tools.execute requires a request object: `ctx.tools.execute({ id, tool, input, description })`. The stable `id` is required for logs, metadata, and receipt attachment; provider-call reuse is based on play, tool, semantic input, auth scope, provider action version, and cache policy.";
|
|
11997
11997
|
var RUN_PLAY_SIGNATURE_HINT = "Deepline hint: ctx.runPlay uses a stable key plus a composable child play reference. Direct-run-only or dataset-backed batch plays must be run directly, exported, then consumed by a separate play.";
|
package/dist/cli/index.mjs
CHANGED
|
@@ -1022,7 +1022,7 @@ var SDK_RELEASE = {
|
|
|
1022
1022
|
// 0.1.253 makes play-page browser opening opt-in and retires --no-open.
|
|
1023
1023
|
// 0.1.254 removes the internal operations tree from the published SDK CLI.
|
|
1024
1024
|
// Operators use the checkout-local deepline-admin binary instead.
|
|
1025
|
-
version: "0.1.
|
|
1025
|
+
version: "0.1.320",
|
|
1026
1026
|
contracts: {
|
|
1027
1027
|
api: {
|
|
1028
1028
|
name: "sdk-http-api",
|
|
@@ -12020,7 +12020,7 @@ async function traceCliSpan(phase, fields, run) {
|
|
|
12020
12020
|
|
|
12021
12021
|
// src/cli/play-check-hints.ts
|
|
12022
12022
|
var EXTRACTED_GETTER_ERROR_HINT = "Deepline hint: extractedValues/extractedLists .get() only works for declared Deepline getters listed by `deepline tools describe <tool> --json`. Use `toolExecutionResult.toolResponse.raw` for provider/tool-specific scalar fields, and `toolExecutionResult.extractedLists.<name>.get()` for declared row/list outputs.";
|
|
12023
|
-
var DATASET_API_HINT = "Deepline hint: PlayDataset is lazy and durable.
|
|
12023
|
+
var DATASET_API_HINT = "Deepline hint: PlayDataset is lazy and durable. Complete resident handles support read-only length/index/iteration. For paged rows use `.first()`, `.at(index)`, `.peek(n)`, `.materialize(limit)`, or async iteration; do not use `.rows` or `.toArray()`.";
|
|
12024
12024
|
var ROW_PROPERTY_HINT = "Deepline hint: this row type only contains fields produced by the CSV/schema and previous map steps. Check source column casing and the exact output field names from earlier steps before scaling.";
|
|
12025
12025
|
var TOOLS_EXECUTE_SIGNATURE_HINT = "Deepline hint: ctx.tools.execute requires a request object: `ctx.tools.execute({ id, tool, input, description })`. The stable `id` is required for logs, metadata, and receipt attachment; provider-call reuse is based on play, tool, semantic input, auth scope, provider action version, and cache policy.";
|
|
12026
12026
|
var RUN_PLAY_SIGNATURE_HINT = "Deepline hint: ctx.runPlay uses a stable key plus a composable child play reference. Direct-run-only or dataset-backed batch plays must be run directly, exported, then consumed by a separate play.";
|
package/dist/index.d.mts
CHANGED
|
@@ -3610,8 +3610,12 @@ type PlayDatasetTransformOptions = {
|
|
|
3610
3610
|
*
|
|
3611
3611
|
* @sdkReference runtime 190
|
|
3612
3612
|
*/
|
|
3613
|
-
interface PlayDataset<T> extends AsyncIterable<T> {
|
|
3613
|
+
interface PlayDataset<T> extends AsyncIterable<T>, Iterable<T> {
|
|
3614
3614
|
readonly [PLAY_DATASET_BRAND]: true;
|
|
3615
|
+
/** Authoritative row count when known without I/O. */
|
|
3616
|
+
readonly length: number;
|
|
3617
|
+
/** Resident row access. Throws when the requested row requires I/O. */
|
|
3618
|
+
readonly [index: number]: T;
|
|
3615
3619
|
/** Dataset kind. */
|
|
3616
3620
|
readonly datasetKind: PlayDatasetKind;
|
|
3617
3621
|
/** Dataset id. */
|
|
@@ -3626,6 +3630,10 @@ interface PlayDataset<T> extends AsyncIterable<T> {
|
|
|
3626
3630
|
count(): Promise<number>;
|
|
3627
3631
|
/** Preview rows. */
|
|
3628
3632
|
peek(limit?: number): Promise<T[]>;
|
|
3633
|
+
/** First row, loading it asynchronously when necessary. */
|
|
3634
|
+
first(): Promise<T | undefined>;
|
|
3635
|
+
/** Row at an array-style index, loading it asynchronously when necessary. */
|
|
3636
|
+
at(index: number): Promise<T | undefined>;
|
|
3629
3637
|
map<U>(mapper: (row: T, index: number) => U | Promise<U>, options?: PlayDatasetTransformOptions): PlayDataset<U>;
|
|
3630
3638
|
filter(predicate: (row: T, index: number) => boolean | Promise<boolean>, options?: PlayDatasetTransformOptions): PlayDataset<T>;
|
|
3631
3639
|
slice(start?: number, end?: number, options?: PlayDatasetTransformOptions): PlayDataset<T>;
|
package/dist/index.d.ts
CHANGED
|
@@ -3610,8 +3610,12 @@ type PlayDatasetTransformOptions = {
|
|
|
3610
3610
|
*
|
|
3611
3611
|
* @sdkReference runtime 190
|
|
3612
3612
|
*/
|
|
3613
|
-
interface PlayDataset<T> extends AsyncIterable<T> {
|
|
3613
|
+
interface PlayDataset<T> extends AsyncIterable<T>, Iterable<T> {
|
|
3614
3614
|
readonly [PLAY_DATASET_BRAND]: true;
|
|
3615
|
+
/** Authoritative row count when known without I/O. */
|
|
3616
|
+
readonly length: number;
|
|
3617
|
+
/** Resident row access. Throws when the requested row requires I/O. */
|
|
3618
|
+
readonly [index: number]: T;
|
|
3615
3619
|
/** Dataset kind. */
|
|
3616
3620
|
readonly datasetKind: PlayDatasetKind;
|
|
3617
3621
|
/** Dataset id. */
|
|
@@ -3626,6 +3630,10 @@ interface PlayDataset<T> extends AsyncIterable<T> {
|
|
|
3626
3630
|
count(): Promise<number>;
|
|
3627
3631
|
/** Preview rows. */
|
|
3628
3632
|
peek(limit?: number): Promise<T[]>;
|
|
3633
|
+
/** First row, loading it asynchronously when necessary. */
|
|
3634
|
+
first(): Promise<T | undefined>;
|
|
3635
|
+
/** Row at an array-style index, loading it asynchronously when necessary. */
|
|
3636
|
+
at(index: number): Promise<T | undefined>;
|
|
3629
3637
|
map<U>(mapper: (row: T, index: number) => U | Promise<U>, options?: PlayDatasetTransformOptions): PlayDataset<U>;
|
|
3630
3638
|
filter(predicate: (row: T, index: number) => boolean | Promise<boolean>, options?: PlayDatasetTransformOptions): PlayDataset<T>;
|
|
3631
3639
|
slice(start?: number, end?: number, options?: PlayDatasetTransformOptions): PlayDataset<T>;
|
package/dist/index.js
CHANGED
|
@@ -760,7 +760,7 @@ var SDK_RELEASE = {
|
|
|
760
760
|
// 0.1.253 makes play-page browser opening opt-in and retires --no-open.
|
|
761
761
|
// 0.1.254 removes the internal operations tree from the published SDK CLI.
|
|
762
762
|
// Operators use the checkout-local deepline-admin binary instead.
|
|
763
|
-
version: "0.1.
|
|
763
|
+
version: "0.1.320",
|
|
764
764
|
contracts: {
|
|
765
765
|
api: {
|
|
766
766
|
name: "sdk-http-api",
|
|
@@ -5790,6 +5790,7 @@ function isDeeplineExtractorTarget(value) {
|
|
|
5790
5790
|
// ../shared_libs/plays/dataset.ts
|
|
5791
5791
|
var PLAY_DATASET_BRAND = /* @__PURE__ */ Symbol.for("deepline.play.dataset");
|
|
5792
5792
|
var NODE_INSPECT_CUSTOM = /* @__PURE__ */ Symbol.for("nodejs.util.inspect.custom");
|
|
5793
|
+
var residentRowsByDataset = /* @__PURE__ */ new WeakMap();
|
|
5793
5794
|
var DEFAULT_MATERIALIZE_LIMIT = 1e4;
|
|
5794
5795
|
var PLAY_DATASET_EXECUTION_PAGE_BYTES = 64 * 1024 * 1024;
|
|
5795
5796
|
var PLAY_DATASET_CELL_MAX_BYTES = 5 * 1024 * 1024;
|
|
@@ -5824,21 +5825,34 @@ var DeferredPlayDataset = class {
|
|
|
5824
5825
|
previewColumns;
|
|
5825
5826
|
workProgress;
|
|
5826
5827
|
cachedCount;
|
|
5828
|
+
knownCount;
|
|
5829
|
+
residentRows;
|
|
5827
5830
|
resolvers;
|
|
5828
5831
|
constructor(input) {
|
|
5829
5832
|
this.datasetKind = input.datasetKind;
|
|
5830
5833
|
this.datasetId = input.datasetId;
|
|
5831
5834
|
this.cachedCount = input.count;
|
|
5835
|
+
this.knownCount = input.knownCount === void 0 ? input.count : input.knownCount;
|
|
5832
5836
|
this.backing = input.backing;
|
|
5833
5837
|
this.previewRows = input.previewRows;
|
|
5838
|
+
this.residentRows = input.residentRows ?? null;
|
|
5834
5839
|
this.previewColumns = inferPreviewColumns(this.previewRows);
|
|
5835
5840
|
this.sourceLabel = input.sourceLabel ?? null;
|
|
5836
5841
|
this.tableNamespace = input.tableNamespace ?? null;
|
|
5837
5842
|
this.workProgress = input.workProgress;
|
|
5838
5843
|
this.resolvers = input.resolvers;
|
|
5839
5844
|
}
|
|
5845
|
+
get length() {
|
|
5846
|
+
if (this.knownCount === null) {
|
|
5847
|
+
throw this.requiresAsyncAccess(
|
|
5848
|
+
"The row count is not known until this lazy transform executes."
|
|
5849
|
+
);
|
|
5850
|
+
}
|
|
5851
|
+
return this.knownCount;
|
|
5852
|
+
}
|
|
5840
5853
|
async count() {
|
|
5841
5854
|
this.cachedCount = await this.resolvers.count();
|
|
5855
|
+
this.knownCount = this.cachedCount;
|
|
5842
5856
|
return this.cachedCount;
|
|
5843
5857
|
}
|
|
5844
5858
|
async peek(limit = 10) {
|
|
@@ -5847,6 +5861,26 @@ var DeferredPlayDataset = class {
|
|
|
5847
5861
|
}
|
|
5848
5862
|
return await this.resolvers.peek(limit);
|
|
5849
5863
|
}
|
|
5864
|
+
async first() {
|
|
5865
|
+
return await this.at(0);
|
|
5866
|
+
}
|
|
5867
|
+
async at(index) {
|
|
5868
|
+
if (!Number.isFinite(index)) return void 0;
|
|
5869
|
+
const integer = Math.trunc(index);
|
|
5870
|
+
const count = integer < 0 ? await this.count() : this.knownCount;
|
|
5871
|
+
const normalized = integer < 0 && count !== null ? count + integer : integer;
|
|
5872
|
+
if (normalized < 0 || count !== null && normalized >= count) {
|
|
5873
|
+
return void 0;
|
|
5874
|
+
}
|
|
5875
|
+
if (this.residentRows) return this.residentRows[normalized];
|
|
5876
|
+
if (this.resolvers.at) return await this.resolvers.at(normalized);
|
|
5877
|
+
let current = 0;
|
|
5878
|
+
for await (const row of this.resolvers.iterate()) {
|
|
5879
|
+
if (current === normalized) return row;
|
|
5880
|
+
current += 1;
|
|
5881
|
+
}
|
|
5882
|
+
return void 0;
|
|
5883
|
+
}
|
|
5850
5884
|
map(mapper, options) {
|
|
5851
5885
|
return createTransformedPlayDataset(this, { kind: "map", mapper }, options);
|
|
5852
5886
|
}
|
|
@@ -5908,6 +5942,28 @@ var DeferredPlayDataset = class {
|
|
|
5908
5942
|
yield row;
|
|
5909
5943
|
}
|
|
5910
5944
|
}
|
|
5945
|
+
[Symbol.iterator]() {
|
|
5946
|
+
if (!this.residentRows) {
|
|
5947
|
+
throw this.requiresAsyncAccess(
|
|
5948
|
+
"Synchronous iteration is available only when every row is resident."
|
|
5949
|
+
);
|
|
5950
|
+
}
|
|
5951
|
+
return this.residentRows[Symbol.iterator]();
|
|
5952
|
+
}
|
|
5953
|
+
residentAt(index) {
|
|
5954
|
+
if (this.knownCount !== null && index >= this.knownCount) return void 0;
|
|
5955
|
+
if (!this.residentRows) {
|
|
5956
|
+
throw this.requiresAsyncAccess(
|
|
5957
|
+
`Row ${index} is not resident and may require dataset paging.`
|
|
5958
|
+
);
|
|
5959
|
+
}
|
|
5960
|
+
return this.residentRows[index];
|
|
5961
|
+
}
|
|
5962
|
+
requiresAsyncAccess(detail) {
|
|
5963
|
+
return new Error(
|
|
5964
|
+
`PLAY_DATASET_REQUIRES_ASYNC_ACCESS: ${detail} Dataset Handle ${this.sourceLabel ?? this.datasetId}. Use await dataset.first(), await dataset.at(index), await dataset.materialize(limit), or for await...of.`
|
|
5965
|
+
);
|
|
5966
|
+
}
|
|
5911
5967
|
toJSON() {
|
|
5912
5968
|
return {
|
|
5913
5969
|
kind: "dataset",
|
|
@@ -6009,6 +6065,7 @@ function createTransformedPlayDataset(source, transform, options) {
|
|
|
6009
6065
|
key: options?.key
|
|
6010
6066
|
}),
|
|
6011
6067
|
count: 0,
|
|
6068
|
+
knownCount: null,
|
|
6012
6069
|
backing: source.backing,
|
|
6013
6070
|
sourceLabel,
|
|
6014
6071
|
tableNamespace: options?.key ?? null,
|
|
@@ -6025,10 +6082,42 @@ function createTransformedPlayDataset(source, transform, options) {
|
|
|
6025
6082
|
});
|
|
6026
6083
|
}
|
|
6027
6084
|
function createDeferredPlayDataset(input) {
|
|
6028
|
-
|
|
6085
|
+
if (input.residentRows && input.knownCount !== null && input.residentRows.length !== (input.knownCount ?? input.count)) {
|
|
6086
|
+
throw new Error(
|
|
6087
|
+
`Resident Dataset Handle ${input.datasetId} has ${input.residentRows.length} rows but declares ${input.knownCount ?? input.count}.`
|
|
6088
|
+
);
|
|
6089
|
+
}
|
|
6090
|
+
const target = new DeferredPlayDataset({
|
|
6029
6091
|
...input,
|
|
6030
6092
|
previewRows: input.previewRows ?? []
|
|
6031
6093
|
});
|
|
6094
|
+
const boundMethods = /* @__PURE__ */ new Map();
|
|
6095
|
+
const dataset = new Proxy(target, {
|
|
6096
|
+
get(dataset2, property) {
|
|
6097
|
+
if (typeof property === "string" && /^(0|[1-9]\d*)$/.test(property)) {
|
|
6098
|
+
return dataset2.residentAt(Number(property));
|
|
6099
|
+
}
|
|
6100
|
+
const value = Reflect.get(dataset2, property, dataset2);
|
|
6101
|
+
if (typeof value !== "function") return value;
|
|
6102
|
+
if (!boundMethods.has(property)) {
|
|
6103
|
+
boundMethods.set(property, value.bind(dataset2));
|
|
6104
|
+
}
|
|
6105
|
+
return boundMethods.get(property);
|
|
6106
|
+
},
|
|
6107
|
+
set(_dataset, property) {
|
|
6108
|
+
if (property === "length" || typeof property === "string" && /^(0|[1-9]\d*)$/.test(property)) {
|
|
6109
|
+
throw new Error(
|
|
6110
|
+
"PLAY_DATASET_READ_ONLY: Dataset Handle rows cannot be assigned directly."
|
|
6111
|
+
);
|
|
6112
|
+
}
|
|
6113
|
+
return false;
|
|
6114
|
+
}
|
|
6115
|
+
});
|
|
6116
|
+
if (input.residentRows) {
|
|
6117
|
+
residentRowsByDataset.set(target, input.residentRows);
|
|
6118
|
+
residentRowsByDataset.set(dataset, input.residentRows);
|
|
6119
|
+
}
|
|
6120
|
+
return dataset;
|
|
6032
6121
|
}
|
|
6033
6122
|
function createPlayDataset(rows, metadata) {
|
|
6034
6123
|
const materializedRows = [...rows];
|
|
@@ -6037,6 +6126,7 @@ function createPlayDataset(rows, metadata) {
|
|
|
6037
6126
|
datasetId: metadata?.datasetId ?? `${metadata?.kind ?? "map"}:${metadata?.tableNamespace ?? metadata?.sourceLabel ?? "inline"}`,
|
|
6038
6127
|
count: materializedRows.length,
|
|
6039
6128
|
previewRows: materializedRows.slice(0, 5),
|
|
6129
|
+
residentRows: materializedRows,
|
|
6040
6130
|
sourceLabel: metadata?.sourceLabel ?? null,
|
|
6041
6131
|
tableNamespace: metadata?.tableNamespace ?? null,
|
|
6042
6132
|
resolvers: {
|
|
@@ -7346,7 +7436,9 @@ function attachSdkQueryResultDatasetResult(toolId, result, options) {
|
|
|
7346
7436
|
return result;
|
|
7347
7437
|
}
|
|
7348
7438
|
const datasetLimit = finitePositiveInteger(dataset.returned_limit) ?? totalRows;
|
|
7349
|
-
const
|
|
7439
|
+
const effectiveCount = Math.min(totalRows, datasetLimit);
|
|
7440
|
+
const rawRows = rowsFromUnknown(raw?.rows);
|
|
7441
|
+
const previewRows = rawRows.slice(0, 25);
|
|
7350
7442
|
const fetchPage = async (offset, limit) => {
|
|
7351
7443
|
if (limit <= 0 || offset >= totalRows) return [];
|
|
7352
7444
|
const response = await options.client.executeTool(toolId, options.input, {
|
|
@@ -7393,10 +7485,12 @@ function attachSdkQueryResultDatasetResult(toolId, result, options) {
|
|
|
7393
7485
|
datasetId: `sdk-tool-list:${toolId}:${stableHash(datasetScope)}:${datasetLimit}:${safeNonce}`,
|
|
7394
7486
|
count: Math.min(totalRows, datasetLimit),
|
|
7395
7487
|
previewRows,
|
|
7488
|
+
residentRows: rawRows.length >= effectiveCount ? rawRows.slice(0, effectiveCount) : null,
|
|
7396
7489
|
sourceLabel: "query result rows",
|
|
7397
7490
|
tableNamespace: null,
|
|
7398
7491
|
resolvers: {
|
|
7399
7492
|
count: async () => Math.min(totalRows, datasetLimit),
|
|
7493
|
+
at: async (index) => (await fetchPage(index, 1))[0],
|
|
7400
7494
|
peek: async (limit) => collectRows(limit),
|
|
7401
7495
|
materialize: async (limit) => collectRows(limit),
|
|
7402
7496
|
iterate: () => ({
|
package/dist/index.mjs
CHANGED
|
@@ -686,7 +686,7 @@ var SDK_RELEASE = {
|
|
|
686
686
|
// 0.1.253 makes play-page browser opening opt-in and retires --no-open.
|
|
687
687
|
// 0.1.254 removes the internal operations tree from the published SDK CLI.
|
|
688
688
|
// Operators use the checkout-local deepline-admin binary instead.
|
|
689
|
-
version: "0.1.
|
|
689
|
+
version: "0.1.320",
|
|
690
690
|
contracts: {
|
|
691
691
|
api: {
|
|
692
692
|
name: "sdk-http-api",
|
|
@@ -5716,6 +5716,7 @@ function isDeeplineExtractorTarget(value) {
|
|
|
5716
5716
|
// ../shared_libs/plays/dataset.ts
|
|
5717
5717
|
var PLAY_DATASET_BRAND = /* @__PURE__ */ Symbol.for("deepline.play.dataset");
|
|
5718
5718
|
var NODE_INSPECT_CUSTOM = /* @__PURE__ */ Symbol.for("nodejs.util.inspect.custom");
|
|
5719
|
+
var residentRowsByDataset = /* @__PURE__ */ new WeakMap();
|
|
5719
5720
|
var DEFAULT_MATERIALIZE_LIMIT = 1e4;
|
|
5720
5721
|
var PLAY_DATASET_EXECUTION_PAGE_BYTES = 64 * 1024 * 1024;
|
|
5721
5722
|
var PLAY_DATASET_CELL_MAX_BYTES = 5 * 1024 * 1024;
|
|
@@ -5750,21 +5751,34 @@ var DeferredPlayDataset = class {
|
|
|
5750
5751
|
previewColumns;
|
|
5751
5752
|
workProgress;
|
|
5752
5753
|
cachedCount;
|
|
5754
|
+
knownCount;
|
|
5755
|
+
residentRows;
|
|
5753
5756
|
resolvers;
|
|
5754
5757
|
constructor(input) {
|
|
5755
5758
|
this.datasetKind = input.datasetKind;
|
|
5756
5759
|
this.datasetId = input.datasetId;
|
|
5757
5760
|
this.cachedCount = input.count;
|
|
5761
|
+
this.knownCount = input.knownCount === void 0 ? input.count : input.knownCount;
|
|
5758
5762
|
this.backing = input.backing;
|
|
5759
5763
|
this.previewRows = input.previewRows;
|
|
5764
|
+
this.residentRows = input.residentRows ?? null;
|
|
5760
5765
|
this.previewColumns = inferPreviewColumns(this.previewRows);
|
|
5761
5766
|
this.sourceLabel = input.sourceLabel ?? null;
|
|
5762
5767
|
this.tableNamespace = input.tableNamespace ?? null;
|
|
5763
5768
|
this.workProgress = input.workProgress;
|
|
5764
5769
|
this.resolvers = input.resolvers;
|
|
5765
5770
|
}
|
|
5771
|
+
get length() {
|
|
5772
|
+
if (this.knownCount === null) {
|
|
5773
|
+
throw this.requiresAsyncAccess(
|
|
5774
|
+
"The row count is not known until this lazy transform executes."
|
|
5775
|
+
);
|
|
5776
|
+
}
|
|
5777
|
+
return this.knownCount;
|
|
5778
|
+
}
|
|
5766
5779
|
async count() {
|
|
5767
5780
|
this.cachedCount = await this.resolvers.count();
|
|
5781
|
+
this.knownCount = this.cachedCount;
|
|
5768
5782
|
return this.cachedCount;
|
|
5769
5783
|
}
|
|
5770
5784
|
async peek(limit = 10) {
|
|
@@ -5773,6 +5787,26 @@ var DeferredPlayDataset = class {
|
|
|
5773
5787
|
}
|
|
5774
5788
|
return await this.resolvers.peek(limit);
|
|
5775
5789
|
}
|
|
5790
|
+
async first() {
|
|
5791
|
+
return await this.at(0);
|
|
5792
|
+
}
|
|
5793
|
+
async at(index) {
|
|
5794
|
+
if (!Number.isFinite(index)) return void 0;
|
|
5795
|
+
const integer = Math.trunc(index);
|
|
5796
|
+
const count = integer < 0 ? await this.count() : this.knownCount;
|
|
5797
|
+
const normalized = integer < 0 && count !== null ? count + integer : integer;
|
|
5798
|
+
if (normalized < 0 || count !== null && normalized >= count) {
|
|
5799
|
+
return void 0;
|
|
5800
|
+
}
|
|
5801
|
+
if (this.residentRows) return this.residentRows[normalized];
|
|
5802
|
+
if (this.resolvers.at) return await this.resolvers.at(normalized);
|
|
5803
|
+
let current = 0;
|
|
5804
|
+
for await (const row of this.resolvers.iterate()) {
|
|
5805
|
+
if (current === normalized) return row;
|
|
5806
|
+
current += 1;
|
|
5807
|
+
}
|
|
5808
|
+
return void 0;
|
|
5809
|
+
}
|
|
5776
5810
|
map(mapper, options) {
|
|
5777
5811
|
return createTransformedPlayDataset(this, { kind: "map", mapper }, options);
|
|
5778
5812
|
}
|
|
@@ -5834,6 +5868,28 @@ var DeferredPlayDataset = class {
|
|
|
5834
5868
|
yield row;
|
|
5835
5869
|
}
|
|
5836
5870
|
}
|
|
5871
|
+
[Symbol.iterator]() {
|
|
5872
|
+
if (!this.residentRows) {
|
|
5873
|
+
throw this.requiresAsyncAccess(
|
|
5874
|
+
"Synchronous iteration is available only when every row is resident."
|
|
5875
|
+
);
|
|
5876
|
+
}
|
|
5877
|
+
return this.residentRows[Symbol.iterator]();
|
|
5878
|
+
}
|
|
5879
|
+
residentAt(index) {
|
|
5880
|
+
if (this.knownCount !== null && index >= this.knownCount) return void 0;
|
|
5881
|
+
if (!this.residentRows) {
|
|
5882
|
+
throw this.requiresAsyncAccess(
|
|
5883
|
+
`Row ${index} is not resident and may require dataset paging.`
|
|
5884
|
+
);
|
|
5885
|
+
}
|
|
5886
|
+
return this.residentRows[index];
|
|
5887
|
+
}
|
|
5888
|
+
requiresAsyncAccess(detail) {
|
|
5889
|
+
return new Error(
|
|
5890
|
+
`PLAY_DATASET_REQUIRES_ASYNC_ACCESS: ${detail} Dataset Handle ${this.sourceLabel ?? this.datasetId}. Use await dataset.first(), await dataset.at(index), await dataset.materialize(limit), or for await...of.`
|
|
5891
|
+
);
|
|
5892
|
+
}
|
|
5837
5893
|
toJSON() {
|
|
5838
5894
|
return {
|
|
5839
5895
|
kind: "dataset",
|
|
@@ -5935,6 +5991,7 @@ function createTransformedPlayDataset(source, transform, options) {
|
|
|
5935
5991
|
key: options?.key
|
|
5936
5992
|
}),
|
|
5937
5993
|
count: 0,
|
|
5994
|
+
knownCount: null,
|
|
5938
5995
|
backing: source.backing,
|
|
5939
5996
|
sourceLabel,
|
|
5940
5997
|
tableNamespace: options?.key ?? null,
|
|
@@ -5951,10 +6008,42 @@ function createTransformedPlayDataset(source, transform, options) {
|
|
|
5951
6008
|
});
|
|
5952
6009
|
}
|
|
5953
6010
|
function createDeferredPlayDataset(input) {
|
|
5954
|
-
|
|
6011
|
+
if (input.residentRows && input.knownCount !== null && input.residentRows.length !== (input.knownCount ?? input.count)) {
|
|
6012
|
+
throw new Error(
|
|
6013
|
+
`Resident Dataset Handle ${input.datasetId} has ${input.residentRows.length} rows but declares ${input.knownCount ?? input.count}.`
|
|
6014
|
+
);
|
|
6015
|
+
}
|
|
6016
|
+
const target = new DeferredPlayDataset({
|
|
5955
6017
|
...input,
|
|
5956
6018
|
previewRows: input.previewRows ?? []
|
|
5957
6019
|
});
|
|
6020
|
+
const boundMethods = /* @__PURE__ */ new Map();
|
|
6021
|
+
const dataset = new Proxy(target, {
|
|
6022
|
+
get(dataset2, property) {
|
|
6023
|
+
if (typeof property === "string" && /^(0|[1-9]\d*)$/.test(property)) {
|
|
6024
|
+
return dataset2.residentAt(Number(property));
|
|
6025
|
+
}
|
|
6026
|
+
const value = Reflect.get(dataset2, property, dataset2);
|
|
6027
|
+
if (typeof value !== "function") return value;
|
|
6028
|
+
if (!boundMethods.has(property)) {
|
|
6029
|
+
boundMethods.set(property, value.bind(dataset2));
|
|
6030
|
+
}
|
|
6031
|
+
return boundMethods.get(property);
|
|
6032
|
+
},
|
|
6033
|
+
set(_dataset, property) {
|
|
6034
|
+
if (property === "length" || typeof property === "string" && /^(0|[1-9]\d*)$/.test(property)) {
|
|
6035
|
+
throw new Error(
|
|
6036
|
+
"PLAY_DATASET_READ_ONLY: Dataset Handle rows cannot be assigned directly."
|
|
6037
|
+
);
|
|
6038
|
+
}
|
|
6039
|
+
return false;
|
|
6040
|
+
}
|
|
6041
|
+
});
|
|
6042
|
+
if (input.residentRows) {
|
|
6043
|
+
residentRowsByDataset.set(target, input.residentRows);
|
|
6044
|
+
residentRowsByDataset.set(dataset, input.residentRows);
|
|
6045
|
+
}
|
|
6046
|
+
return dataset;
|
|
5958
6047
|
}
|
|
5959
6048
|
function createPlayDataset(rows, metadata) {
|
|
5960
6049
|
const materializedRows = [...rows];
|
|
@@ -5963,6 +6052,7 @@ function createPlayDataset(rows, metadata) {
|
|
|
5963
6052
|
datasetId: metadata?.datasetId ?? `${metadata?.kind ?? "map"}:${metadata?.tableNamespace ?? metadata?.sourceLabel ?? "inline"}`,
|
|
5964
6053
|
count: materializedRows.length,
|
|
5965
6054
|
previewRows: materializedRows.slice(0, 5),
|
|
6055
|
+
residentRows: materializedRows,
|
|
5966
6056
|
sourceLabel: metadata?.sourceLabel ?? null,
|
|
5967
6057
|
tableNamespace: metadata?.tableNamespace ?? null,
|
|
5968
6058
|
resolvers: {
|
|
@@ -7272,7 +7362,9 @@ function attachSdkQueryResultDatasetResult(toolId, result, options) {
|
|
|
7272
7362
|
return result;
|
|
7273
7363
|
}
|
|
7274
7364
|
const datasetLimit = finitePositiveInteger(dataset.returned_limit) ?? totalRows;
|
|
7275
|
-
const
|
|
7365
|
+
const effectiveCount = Math.min(totalRows, datasetLimit);
|
|
7366
|
+
const rawRows = rowsFromUnknown(raw?.rows);
|
|
7367
|
+
const previewRows = rawRows.slice(0, 25);
|
|
7276
7368
|
const fetchPage = async (offset, limit) => {
|
|
7277
7369
|
if (limit <= 0 || offset >= totalRows) return [];
|
|
7278
7370
|
const response = await options.client.executeTool(toolId, options.input, {
|
|
@@ -7319,10 +7411,12 @@ function attachSdkQueryResultDatasetResult(toolId, result, options) {
|
|
|
7319
7411
|
datasetId: `sdk-tool-list:${toolId}:${stableHash(datasetScope)}:${datasetLimit}:${safeNonce}`,
|
|
7320
7412
|
count: Math.min(totalRows, datasetLimit),
|
|
7321
7413
|
previewRows,
|
|
7414
|
+
residentRows: rawRows.length >= effectiveCount ? rawRows.slice(0, effectiveCount) : null,
|
|
7322
7415
|
sourceLabel: "query result rows",
|
|
7323
7416
|
tableNamespace: null,
|
|
7324
7417
|
resolvers: {
|
|
7325
7418
|
count: async () => Math.min(totalRows, datasetLimit),
|
|
7419
|
+
at: async (index) => (await fetchPage(index, 1))[0],
|
|
7326
7420
|
peek: async (limit) => collectRows(limit),
|
|
7327
7421
|
materialize: async (limit) => collectRows(limit),
|
|
7328
7422
|
iterate: () => ({
|