@meistrari/tela-sdk-js 2.4.2 → 2.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +1009 -145
- package/dist/index.d.cts +1027 -51
- package/dist/index.d.mts +1027 -51
- package/dist/index.d.ts +1027 -51
- package/dist/index.mjs +1009 -146
- package/package.json +2 -1
package/dist/index.d.ts
CHANGED
|
@@ -22,6 +22,7 @@ type RequestOptions<Req = unknown | Record<string, unknown>> = {
|
|
|
22
22
|
stream?: boolean | undefined;
|
|
23
23
|
timeout?: number;
|
|
24
24
|
signal?: AbortSignal | undefined | null;
|
|
25
|
+
transformCase?: boolean;
|
|
25
26
|
};
|
|
26
27
|
interface BaseClientOptions {
|
|
27
28
|
baseURL: string;
|
|
@@ -145,6 +146,15 @@ declare class ExecutionFailedError extends TelaError {
|
|
|
145
146
|
readonly rawOutput: Record<string, any>;
|
|
146
147
|
constructor(rawOutput: Record<string, any>);
|
|
147
148
|
}
|
|
149
|
+
/**
|
|
150
|
+
* Thrown when batch execution fails on the server.
|
|
151
|
+
*
|
|
152
|
+
* @category Errors
|
|
153
|
+
*/
|
|
154
|
+
declare class BatchExecutionFailedError extends TelaError {
|
|
155
|
+
readonly rawResponse: Record<string, any>;
|
|
156
|
+
constructor(rawResponse: Record<string, any>);
|
|
157
|
+
}
|
|
148
158
|
/**
|
|
149
159
|
* Base class for all API-related errors.
|
|
150
160
|
*
|
|
@@ -385,16 +395,6 @@ declare class TelaFile {
|
|
|
385
395
|
private isValidVaultReference;
|
|
386
396
|
}
|
|
387
397
|
|
|
388
|
-
/**
|
|
389
|
-
* Canvas execution module for managing canvas execution lifecycle and modes.
|
|
390
|
-
*
|
|
391
|
-
* This module handles the execution of canvas templates with support for
|
|
392
|
-
* synchronous, asynchronous (with polling), and streaming modes. It also
|
|
393
|
-
* manages file uploads and result validation.
|
|
394
|
-
*
|
|
395
|
-
* @module Resources
|
|
396
|
-
*/
|
|
397
|
-
|
|
398
398
|
interface BaseExecutionParams {
|
|
399
399
|
/**
|
|
400
400
|
* The version ID of the canvas to use for this chat completion.
|
|
@@ -471,6 +471,29 @@ interface BaseExecutionParams {
|
|
|
471
471
|
*/
|
|
472
472
|
tags?: string[];
|
|
473
473
|
}
|
|
474
|
+
|
|
475
|
+
/**
|
|
476
|
+
* Helper type to add request ID to a response type.
|
|
477
|
+
*
|
|
478
|
+
* The `requestId` field contains the value from the `x-request-id` HTTP header
|
|
479
|
+
* returned by the API for that specific request.
|
|
480
|
+
*
|
|
481
|
+
* @template T - The base response type.
|
|
482
|
+
*/
|
|
483
|
+
type WithRequestId<T> = T & {
|
|
484
|
+
requestId?: string;
|
|
485
|
+
};
|
|
486
|
+
|
|
487
|
+
/**
|
|
488
|
+
* Canvas execution module for managing canvas execution lifecycle and modes.
|
|
489
|
+
*
|
|
490
|
+
* This module handles the execution of canvas templates with support for
|
|
491
|
+
* synchronous, asynchronous (with polling), and streaming modes. It also
|
|
492
|
+
* manages file uploads and result validation.
|
|
493
|
+
*
|
|
494
|
+
* @module Resources
|
|
495
|
+
*/
|
|
496
|
+
|
|
474
497
|
/**
|
|
475
498
|
* Configuration for asynchronous canvas execution with polling.
|
|
476
499
|
* The execution starts immediately but results must be retrieved via polling.
|
|
@@ -486,15 +509,15 @@ interface AsyncExecutionParams extends BaseExecutionParams {
|
|
|
486
509
|
*/
|
|
487
510
|
webhookUrl?: string;
|
|
488
511
|
/**
|
|
489
|
-
* Time in milliseconds between polling attempts.
|
|
512
|
+
* Time (in milliseconds if number) between polling attempts (e.g. "1s", "1m", "1h", "1d").
|
|
490
513
|
* @default 1000
|
|
491
514
|
*/
|
|
492
|
-
pollingInterval?: number;
|
|
515
|
+
pollingInterval?: string | number;
|
|
493
516
|
/**
|
|
494
|
-
* Maximum time in milliseconds to wait for completion before timing out.
|
|
517
|
+
* Maximum time (in milliseconds if number) to wait for completion before timing out (e.g. "1s", "1m", "1h", "1d").
|
|
495
518
|
* @default 60000
|
|
496
519
|
*/
|
|
497
|
-
pollingTimeout?: number;
|
|
520
|
+
pollingTimeout?: string | number;
|
|
498
521
|
/**
|
|
499
522
|
* Stream mode is not available for async executions.
|
|
500
523
|
*/
|
|
@@ -553,7 +576,7 @@ type ExecutionStatus = 'succeeded' | 'failed' | 'running' | 'created' | 'streami
|
|
|
553
576
|
type AsyncCompletionCreateResult = {
|
|
554
577
|
id: string;
|
|
555
578
|
status: ExecutionStatus;
|
|
556
|
-
|
|
579
|
+
inputContent: {
|
|
557
580
|
files: Array<any>;
|
|
558
581
|
messages: Array<any>;
|
|
559
582
|
variables: {
|
|
@@ -561,8 +584,8 @@ type AsyncCompletionCreateResult = {
|
|
|
561
584
|
title: string;
|
|
562
585
|
};
|
|
563
586
|
};
|
|
564
|
-
|
|
565
|
-
|
|
587
|
+
outputContent: null;
|
|
588
|
+
rawInput: {
|
|
566
589
|
async: boolean;
|
|
567
590
|
canvas_id: string;
|
|
568
591
|
variables: {
|
|
@@ -570,8 +593,8 @@ type AsyncCompletionCreateResult = {
|
|
|
570
593
|
title: string;
|
|
571
594
|
};
|
|
572
595
|
};
|
|
573
|
-
|
|
574
|
-
|
|
596
|
+
rawOutput: any;
|
|
597
|
+
compatibilityDate: string;
|
|
575
598
|
metadata: Array<{
|
|
576
599
|
promptVersion: {
|
|
577
600
|
modelConfigurations: {
|
|
@@ -607,30 +630,48 @@ type AsyncCompletionCreateResult = {
|
|
|
607
630
|
};
|
|
608
631
|
}>;
|
|
609
632
|
credits_used: number;
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
633
|
+
promptId: string;
|
|
634
|
+
promptVersionId: string;
|
|
635
|
+
promptApplicationId: string;
|
|
636
|
+
workspaceId: string;
|
|
637
|
+
createdAt: string;
|
|
638
|
+
updatedAt: string;
|
|
639
|
+
deletedAt: any;
|
|
640
|
+
};
|
|
641
|
+
type TaskCreationResult = {
|
|
642
|
+
id: string;
|
|
643
|
+
reference: number;
|
|
644
|
+
name: string;
|
|
645
|
+
status: ExecutionStatus;
|
|
646
|
+
rawInput: {
|
|
647
|
+
async: boolean;
|
|
648
|
+
stream: boolean;
|
|
649
|
+
variables: Record<string, unknown>;
|
|
650
|
+
applicationId: string;
|
|
651
|
+
};
|
|
652
|
+
inputContent: any;
|
|
653
|
+
outputContent: any;
|
|
654
|
+
originalOutputContent: any;
|
|
655
|
+
createdBy: string;
|
|
656
|
+
approvedBy: any;
|
|
657
|
+
approvedAt: any;
|
|
658
|
+
completionRunId: string;
|
|
659
|
+
workflowRunId: any;
|
|
660
|
+
promptVersionId: string;
|
|
661
|
+
promptApplicationId: string;
|
|
662
|
+
workspaceId: string;
|
|
663
|
+
metadata: any;
|
|
664
|
+
tags: Array<string>;
|
|
665
|
+
createdAt: string;
|
|
666
|
+
updatedAt: string;
|
|
667
|
+
deletedAt: any;
|
|
668
|
+
requestId: string;
|
|
617
669
|
};
|
|
618
670
|
/**
|
|
619
671
|
* Raw API response type. Represents the unprocessed response from the Tela API.
|
|
620
672
|
* This type will be refined in future versions with proper typing.
|
|
621
673
|
*/
|
|
622
674
|
type RawAPIResult = any;
|
|
623
|
-
/**
|
|
624
|
-
* Helper type to add request ID to a response type.
|
|
625
|
-
*
|
|
626
|
-
* The `requestId` field contains the value from the `x-request-id` HTTP header
|
|
627
|
-
* returned by the API for that specific request.
|
|
628
|
-
*
|
|
629
|
-
* @template T - The base response type.
|
|
630
|
-
*/
|
|
631
|
-
type WithRequestId<T> = T & {
|
|
632
|
-
requestId?: string;
|
|
633
|
-
};
|
|
634
675
|
/**
|
|
635
676
|
* Result returned when polling for asynchronous execution status.
|
|
636
677
|
*
|
|
@@ -750,10 +791,12 @@ declare class CanvasExecution<TParams extends ExecutionParams = SyncExecutionPar
|
|
|
750
791
|
private readonly _outputSchema;
|
|
751
792
|
private readonly _skipResultValidation;
|
|
752
793
|
private readonly _abortController;
|
|
794
|
+
private readonly _isTask;
|
|
753
795
|
private _resultPromise;
|
|
754
796
|
private _stream;
|
|
755
797
|
private _rawResultValue;
|
|
756
798
|
private _requestId;
|
|
799
|
+
private _task;
|
|
757
800
|
/**
|
|
758
801
|
* Creates a new canvas execution instance.
|
|
759
802
|
*
|
|
@@ -762,7 +805,7 @@ declare class CanvasExecution<TParams extends ExecutionParams = SyncExecutionPar
|
|
|
762
805
|
* @param outputSchema - Zod schema or object schema for validating/parsing output.
|
|
763
806
|
* @param client - HTTP client instance for making API requests.
|
|
764
807
|
*/
|
|
765
|
-
constructor(variables: TInput, params: TParams | undefined, outputSchema: _zod__default.ZodType | Record<string, unknown>, client: BaseClient);
|
|
808
|
+
constructor(variables: TInput, params: TParams | undefined, outputSchema: _zod__default.ZodType | Record<string, unknown>, client: BaseClient, isTask?: boolean);
|
|
766
809
|
/**
|
|
767
810
|
* Fetches an existing asynchronous execution by its ID.
|
|
768
811
|
*
|
|
@@ -776,6 +819,7 @@ declare class CanvasExecution<TParams extends ExecutionParams = SyncExecutionPar
|
|
|
776
819
|
* @param options - Optional configuration for polling behavior.
|
|
777
820
|
* @param options.pollingInterval - Time in milliseconds between polling attempts (default: 1000).
|
|
778
821
|
* @param options.pollingTimeout - Maximum time in milliseconds to wait for completion (default: 60000).
|
|
822
|
+
* @param options.isTask - Whether the execution is a task of a workstation.
|
|
779
823
|
* @throws {InvalidExecutionModeError} If the provided ID is not a valid UUID.
|
|
780
824
|
* @returns A promise resolving to a CanvasExecution instance with the fetched state.
|
|
781
825
|
*
|
|
@@ -791,8 +835,9 @@ declare class CanvasExecution<TParams extends ExecutionParams = SyncExecutionPar
|
|
|
791
835
|
* ```
|
|
792
836
|
*/
|
|
793
837
|
static fetch<TOutput = unknown>(id: string, outputSchema: _zod__default.ZodType | Record<string, unknown>, client: BaseClient, options?: {
|
|
794
|
-
pollingInterval?: number;
|
|
795
|
-
pollingTimeout?: number;
|
|
838
|
+
pollingInterval?: string | number;
|
|
839
|
+
pollingTimeout?: string | number;
|
|
840
|
+
isTask?: boolean;
|
|
796
841
|
}): Promise<CanvasExecution<AsyncExecutionParams, unknown, TOutput>>;
|
|
797
842
|
/**
|
|
798
843
|
* Gets the unique execution ID assigned by the server.
|
|
@@ -909,6 +954,12 @@ declare class CanvasExecution<TParams extends ExecutionParams = SyncExecutionPar
|
|
|
909
954
|
* @returns True if stream mode is enabled.
|
|
910
955
|
*/
|
|
911
956
|
get isStream(): boolean;
|
|
957
|
+
/**
|
|
958
|
+
* Gets the task associated with this execution if it was created from an application.
|
|
959
|
+
*
|
|
960
|
+
* @returns The task creation result or undefined.
|
|
961
|
+
*/
|
|
962
|
+
get task(): TaskCreationResult | undefined;
|
|
912
963
|
/**
|
|
913
964
|
* Gets the raw API response without any processing or validation.
|
|
914
965
|
* Automatically starts execution and waits for completion (including polling for async executions).
|
|
@@ -933,7 +984,11 @@ declare class CanvasExecution<TParams extends ExecutionParams = SyncExecutionPar
|
|
|
933
984
|
*
|
|
934
985
|
* @returns A promise or async generator depending on execution mode.
|
|
935
986
|
*/
|
|
936
|
-
start(): Promise<CanvasExecutionResult<TParams, TOutput> | AsyncGenerator<Partial<TOutput>, any, any> |
|
|
987
|
+
start(): Promise<CanvasExecutionResult<TParams, TOutput> | AsyncGenerator<Partial<TOutput>, any, any> | (AsyncCompletionCreateResult & {
|
|
988
|
+
requestId?: string;
|
|
989
|
+
}) | (TaskCreationResult & {
|
|
990
|
+
requestId?: string;
|
|
991
|
+
})>;
|
|
937
992
|
/**
|
|
938
993
|
* Gets the execution result. For async executions, automatically starts polling.
|
|
939
994
|
* For sync executions, returns the result promise. For streams, returns the generator.
|
|
@@ -1081,6 +1136,895 @@ declare class CanvasExecution<TParams extends ExecutionParams = SyncExecutionPar
|
|
|
1081
1136
|
private uploadFiles;
|
|
1082
1137
|
}
|
|
1083
1138
|
|
|
1139
|
+
type CompletionRunResult<TOutput> = {
|
|
1140
|
+
id: string;
|
|
1141
|
+
status: string;
|
|
1142
|
+
inputContent: {
|
|
1143
|
+
files: Array<any>;
|
|
1144
|
+
messages: Array<any>;
|
|
1145
|
+
variables: Record<string, unknown>;
|
|
1146
|
+
};
|
|
1147
|
+
outputContent: {
|
|
1148
|
+
role: string;
|
|
1149
|
+
content: TOutput;
|
|
1150
|
+
toolCalls: Array<any>;
|
|
1151
|
+
functionCall: any;
|
|
1152
|
+
};
|
|
1153
|
+
rawInput: {
|
|
1154
|
+
tags: Array<string>;
|
|
1155
|
+
async: boolean;
|
|
1156
|
+
canvasId: string;
|
|
1157
|
+
variables: Record<string, unknown>;
|
|
1158
|
+
};
|
|
1159
|
+
rawOutput: {
|
|
1160
|
+
id: string;
|
|
1161
|
+
usage: {
|
|
1162
|
+
cost: {
|
|
1163
|
+
totalCost: number;
|
|
1164
|
+
promptCost: number;
|
|
1165
|
+
completionCost: number;
|
|
1166
|
+
};
|
|
1167
|
+
totalTokens: number;
|
|
1168
|
+
promptTokens: number;
|
|
1169
|
+
completionTokens: number;
|
|
1170
|
+
};
|
|
1171
|
+
object: string;
|
|
1172
|
+
choices: Array<{
|
|
1173
|
+
message: {
|
|
1174
|
+
role: string;
|
|
1175
|
+
content: TOutput;
|
|
1176
|
+
toolCalls: Array<any>;
|
|
1177
|
+
functionCall: any;
|
|
1178
|
+
};
|
|
1179
|
+
}>;
|
|
1180
|
+
created: number;
|
|
1181
|
+
};
|
|
1182
|
+
compatibilityDate: string;
|
|
1183
|
+
metadata: {
|
|
1184
|
+
promptVersion: {
|
|
1185
|
+
modelConfigurations: {
|
|
1186
|
+
type: string;
|
|
1187
|
+
model: string;
|
|
1188
|
+
temperature: number;
|
|
1189
|
+
structuredOutput: {
|
|
1190
|
+
schema: {
|
|
1191
|
+
type: string;
|
|
1192
|
+
title: string;
|
|
1193
|
+
required: Array<string>;
|
|
1194
|
+
properties: Record<string, unknown>;
|
|
1195
|
+
description: string;
|
|
1196
|
+
};
|
|
1197
|
+
enabled: boolean;
|
|
1198
|
+
};
|
|
1199
|
+
};
|
|
1200
|
+
variablesDefinitions: Array<{
|
|
1201
|
+
name: string;
|
|
1202
|
+
type: string;
|
|
1203
|
+
required: boolean;
|
|
1204
|
+
processingOptions: {
|
|
1205
|
+
allowMultimodal: boolean;
|
|
1206
|
+
};
|
|
1207
|
+
}>;
|
|
1208
|
+
};
|
|
1209
|
+
};
|
|
1210
|
+
tags: Array<string>;
|
|
1211
|
+
creditsUsed: number;
|
|
1212
|
+
promptId: string;
|
|
1213
|
+
promptVersionId: string;
|
|
1214
|
+
promptApplicationId: any;
|
|
1215
|
+
workspaceId: string;
|
|
1216
|
+
createdAt: string;
|
|
1217
|
+
updatedAt: string;
|
|
1218
|
+
deletedAt: any;
|
|
1219
|
+
};
|
|
1220
|
+
|
|
1221
|
+
/**
|
|
1222
|
+
* Helper type for accepting either a single value or an array of values.
|
|
1223
|
+
*
|
|
1224
|
+
* @template T - The base type.
|
|
1225
|
+
*/
|
|
1226
|
+
type MaybeArray<T> = T | T[];
|
|
1227
|
+
/**
|
|
1228
|
+
* Canvas identification methods for batch operations.
|
|
1229
|
+
* Use either canvas ID with optional version, or application ID.
|
|
1230
|
+
*/
|
|
1231
|
+
type CanvasIdentifier = {
|
|
1232
|
+
id: string;
|
|
1233
|
+
versionId?: string;
|
|
1234
|
+
} | {
|
|
1235
|
+
applicationId: string;
|
|
1236
|
+
};
|
|
1237
|
+
/**
|
|
1238
|
+
* Status of a batch execution.
|
|
1239
|
+
*
|
|
1240
|
+
* Lifecycle progression:
|
|
1241
|
+
* - `created` - Batch queued on server (initial state)
|
|
1242
|
+
* - `validating` - Input file validation in progress
|
|
1243
|
+
* - `running` - Batch actively processing executions
|
|
1244
|
+
* - `completed` - All executions finished successfully
|
|
1245
|
+
* - `failed` - Batch failed (validation error or server failure)
|
|
1246
|
+
* - `canceled` - Batch canceled by user
|
|
1247
|
+
*
|
|
1248
|
+
* @see {@link BatchExecution.status} for accessing current status
|
|
1249
|
+
*/
|
|
1250
|
+
type BatchExecutionStatus = 'created' | 'validating' | 'running' | 'failed' | 'completed' | 'canceled';
|
|
1251
|
+
/**
|
|
1252
|
+
* Raw API response for batch execution operations.
|
|
1253
|
+
* Contains batch metadata, status, and progress information.
|
|
1254
|
+
*/
|
|
1255
|
+
type BatchResponse = {
|
|
1256
|
+
/**
|
|
1257
|
+
* The type of batch task (always 'async-completion').
|
|
1258
|
+
*/
|
|
1259
|
+
task: string;
|
|
1260
|
+
/**
|
|
1261
|
+
* Vault URL of the input JSONL file.
|
|
1262
|
+
*/
|
|
1263
|
+
inputFile: string;
|
|
1264
|
+
/**
|
|
1265
|
+
* Webhook URL for completion notifications, if configured.
|
|
1266
|
+
*/
|
|
1267
|
+
webhookUrl: string | null;
|
|
1268
|
+
/**
|
|
1269
|
+
* Current status of the batch execution.
|
|
1270
|
+
*/
|
|
1271
|
+
status: BatchExecutionStatus;
|
|
1272
|
+
/**
|
|
1273
|
+
* Unique identifier for this batch execution.
|
|
1274
|
+
*/
|
|
1275
|
+
id: string;
|
|
1276
|
+
/**
|
|
1277
|
+
* Vault URL of the output JSONL file, available when completed.
|
|
1278
|
+
*/
|
|
1279
|
+
outputFile: string | null;
|
|
1280
|
+
/**
|
|
1281
|
+
* Progress statistics, available when running or completed.
|
|
1282
|
+
*/
|
|
1283
|
+
state: {
|
|
1284
|
+
/**
|
|
1285
|
+
* Number of failed executions.
|
|
1286
|
+
*/
|
|
1287
|
+
failed: number;
|
|
1288
|
+
/**
|
|
1289
|
+
* Number of completed executions.
|
|
1290
|
+
*/
|
|
1291
|
+
completed: number;
|
|
1292
|
+
/**
|
|
1293
|
+
* Total number of executions in the batch.
|
|
1294
|
+
*/
|
|
1295
|
+
total: number;
|
|
1296
|
+
} | null;
|
|
1297
|
+
/**
|
|
1298
|
+
* ISO timestamp when the batch was created.
|
|
1299
|
+
*/
|
|
1300
|
+
createdAt: string;
|
|
1301
|
+
/**
|
|
1302
|
+
* ISO timestamp when the batch was last updated.
|
|
1303
|
+
*/
|
|
1304
|
+
updatedAt: string;
|
|
1305
|
+
/**
|
|
1306
|
+
* ISO timestamp when the batch completed, if applicable.
|
|
1307
|
+
*/
|
|
1308
|
+
completedAt: string | null;
|
|
1309
|
+
/**
|
|
1310
|
+
* ISO timestamp when the batch was canceled, if applicable.
|
|
1311
|
+
*/
|
|
1312
|
+
canceledAt: string | null;
|
|
1313
|
+
/**
|
|
1314
|
+
* ISO timestamp when the batch failed, if applicable.
|
|
1315
|
+
*/
|
|
1316
|
+
failedAt: string | null;
|
|
1317
|
+
};
|
|
1318
|
+
/**
|
|
1319
|
+
* Represents a single item to be executed in a batch.
|
|
1320
|
+
*
|
|
1321
|
+
* @template TInput - The input variables type for the canvas.
|
|
1322
|
+
*/
|
|
1323
|
+
interface BatchItem<TInput> {
|
|
1324
|
+
/**
|
|
1325
|
+
* Optional unique identifier for this execution.
|
|
1326
|
+
* If not provided, a random UUID will be generated automatically.
|
|
1327
|
+
* Used to retrieve individual results from the batch output.
|
|
1328
|
+
*/
|
|
1329
|
+
referenceId?: string;
|
|
1330
|
+
/**
|
|
1331
|
+
* Input variables for this execution, matching the canvas input schema.
|
|
1332
|
+
*/
|
|
1333
|
+
variables: TInput;
|
|
1334
|
+
}
|
|
1335
|
+
/**
|
|
1336
|
+
* Parameters excluded from batch execution (managed internally).
|
|
1337
|
+
*/
|
|
1338
|
+
type ExcludedParams = 'versionId' | 'canvasId' | 'applicationId' | 'async' | 'stream' | 'webhookUrl' | 'skipResultValidation';
|
|
1339
|
+
/**
|
|
1340
|
+
* Configuration options for batch execution.
|
|
1341
|
+
*
|
|
1342
|
+
* Batch executions are always asynchronous and return results via output file.
|
|
1343
|
+
* Unlike single executions, batches do not support streaming or synchronous modes.
|
|
1344
|
+
*
|
|
1345
|
+
* @category Canvas
|
|
1346
|
+
*/
|
|
1347
|
+
interface BatchParams extends Omit<BaseExecutionParams, ExcludedParams> {
|
|
1348
|
+
/**
|
|
1349
|
+
* Time (in milliseconds if number) between polling attempts (e.g. "1s", "1m", "1h", "1d").
|
|
1350
|
+
* Controls how frequently the SDK checks batch completion status.
|
|
1351
|
+
* @default "1s"
|
|
1352
|
+
*/
|
|
1353
|
+
pollingInterval?: string | number;
|
|
1354
|
+
/**
|
|
1355
|
+
* Maximum time (in milliseconds if number) to wait for completion before timing out (e.g. "1s", "1m", "1h", "1d").
|
|
1356
|
+
* After timeout, polling stops but the batch continues processing on the server.
|
|
1357
|
+
* @default "1m"
|
|
1358
|
+
*/
|
|
1359
|
+
pollingTimeout?: string | number;
|
|
1360
|
+
/**
|
|
1361
|
+
* Optional webhook URL to receive completion notifications.
|
|
1362
|
+
* The server will POST to this URL when the batch completes, fails, or is canceled.
|
|
1363
|
+
*/
|
|
1364
|
+
webhookUrl?: string;
|
|
1365
|
+
}
|
|
1366
|
+
/**
|
|
1367
|
+
* Promise-like wrapper for batch execution that provides direct result access.
|
|
1368
|
+
*
|
|
1369
|
+
* Enables flexible usage patterns:
|
|
1370
|
+
* - Await for execution object: `const exec = await batch.execute()`
|
|
1371
|
+
* - Direct result access: `const result = await batch.execute().result`
|
|
1372
|
+
*
|
|
1373
|
+
* @template TOutput - The output type for batch results.
|
|
1374
|
+
*
|
|
1375
|
+
* @category Canvas
|
|
1376
|
+
*/
|
|
1377
|
+
type BatchExecutionPromiseLike<TOutput> = PromiseLike<BatchExecution<TOutput>> & {
|
|
1378
|
+
/**
|
|
1379
|
+
* Direct access to the batch result, automatically starting polling.
|
|
1380
|
+
*/
|
|
1381
|
+
result: Promise<BatchExecutionResult<TOutput>>;
|
|
1382
|
+
};
|
|
1383
|
+
/**
|
|
1384
|
+
* Wraps the completed batch execution response with convenient result access methods.
|
|
1385
|
+
*
|
|
1386
|
+
* Provides multiple ways to access batch results:
|
|
1387
|
+
* - Download entire output file: `downloadOutputFile()`
|
|
1388
|
+
* - Stream results incrementally: `iterateResults()`
|
|
1389
|
+
* - Get all results as array: `getResults()`
|
|
1390
|
+
* - Fetch individual result by reference ID: `getResult(referenceId)`
|
|
1391
|
+
*
|
|
1392
|
+
* @category Canvas
|
|
1393
|
+
*
|
|
1394
|
+
* @template TOutput - The output type for individual results.
|
|
1395
|
+
*
|
|
1396
|
+
* @example
|
|
1397
|
+
* ```typescript
|
|
1398
|
+
* const execution = await batch.execute()
|
|
1399
|
+
* const result = await execution.result
|
|
1400
|
+
*
|
|
1401
|
+
* // Access batch metadata
|
|
1402
|
+
* console.log(`Status: ${result.status}`)
|
|
1403
|
+
* console.log(`Progress: ${result.state.completed}/${result.state.total}`)
|
|
1404
|
+
*
|
|
1405
|
+
* // Iterate through results
|
|
1406
|
+
* for await (const item of result.iterateResults()) {
|
|
1407
|
+
* console.log(item)
|
|
1408
|
+
* }
|
|
1409
|
+
* ```
|
|
1410
|
+
*/
|
|
1411
|
+
declare class BatchExecutionResult<TOutput> {
|
|
1412
|
+
private readonly _client;
|
|
1413
|
+
private readonly _response;
|
|
1414
|
+
/**
|
|
1415
|
+
* Creates a new batch execution result wrapper.
|
|
1416
|
+
*
|
|
1417
|
+
* @param client - HTTP client for making API requests.
|
|
1418
|
+
* @param response - Raw batch execution response from the server.
|
|
1419
|
+
* @internal
|
|
1420
|
+
*/
|
|
1421
|
+
constructor(client: BaseClient, response: WithRequestId<BatchResponse>);
|
|
1422
|
+
get requestId(): string | undefined;
|
|
1423
|
+
/**
|
|
1424
|
+
* Gets the unique identifier for this batch execution.
|
|
1425
|
+
*
|
|
1426
|
+
* @returns The batch execution ID.
|
|
1427
|
+
*/
|
|
1428
|
+
get id(): string;
|
|
1429
|
+
/**
|
|
1430
|
+
* Gets the current status of the batch execution.
|
|
1431
|
+
*
|
|
1432
|
+
* @returns The batch status.
|
|
1433
|
+
*/
|
|
1434
|
+
get status(): BatchExecutionStatus;
|
|
1435
|
+
/**
|
|
1436
|
+
* Gets the progress statistics for this batch.
|
|
1437
|
+
*
|
|
1438
|
+
* @returns Object containing completed, failed, and total execution counts, or null if not available.
|
|
1439
|
+
*/
|
|
1440
|
+
get state(): {
|
|
1441
|
+
/**
|
|
1442
|
+
* Number of failed executions.
|
|
1443
|
+
*/
|
|
1444
|
+
failed: number;
|
|
1445
|
+
/**
|
|
1446
|
+
* Number of completed executions.
|
|
1447
|
+
*/
|
|
1448
|
+
completed: number;
|
|
1449
|
+
/**
|
|
1450
|
+
* Total number of executions in the batch.
|
|
1451
|
+
*/
|
|
1452
|
+
total: number;
|
|
1453
|
+
} | null;
|
|
1454
|
+
/**
|
|
1455
|
+
* Gets the vault URL of the output JSONL file containing all results.
|
|
1456
|
+
*
|
|
1457
|
+
* @returns The output file URL, or null if batch is not completed.
|
|
1458
|
+
*/
|
|
1459
|
+
get outputFile(): string | null;
|
|
1460
|
+
/**
|
|
1461
|
+
* Gets the raw API response without any processing.
|
|
1462
|
+
*
|
|
1463
|
+
* @returns The complete batch response object.
|
|
1464
|
+
*/
|
|
1465
|
+
get rawResponse(): WithRequestId<BatchResponse>;
|
|
1466
|
+
/**
|
|
1467
|
+
* Gets the timestamp when this batch was created.
|
|
1468
|
+
*
|
|
1469
|
+
* @returns Creation date.
|
|
1470
|
+
*/
|
|
1471
|
+
get createdAt(): Date;
|
|
1472
|
+
/**
|
|
1473
|
+
* Gets the timestamp when this batch was last updated.
|
|
1474
|
+
*
|
|
1475
|
+
* @returns Last update date.
|
|
1476
|
+
*/
|
|
1477
|
+
get updatedAt(): Date;
|
|
1478
|
+
/**
|
|
1479
|
+
* Gets the timestamp when this batch completed successfully.
|
|
1480
|
+
*
|
|
1481
|
+
* @returns Completion date, or null if not completed.
|
|
1482
|
+
*/
|
|
1483
|
+
get completedAt(): Date | null;
|
|
1484
|
+
/**
|
|
1485
|
+
* Gets the timestamp when this batch was canceled.
|
|
1486
|
+
*
|
|
1487
|
+
* @returns Cancellation date, or null if not canceled.
|
|
1488
|
+
*/
|
|
1489
|
+
get canceledAt(): Date | null;
|
|
1490
|
+
/**
|
|
1491
|
+
* Gets the timestamp when this batch failed.
|
|
1492
|
+
*
|
|
1493
|
+
* @returns Failure date, or null if not failed.
|
|
1494
|
+
*/
|
|
1495
|
+
get failedAt(): Date | null;
|
|
1496
|
+
/**
|
|
1497
|
+
* Downloads the complete output file as a Blob.
|
|
1498
|
+
*
|
|
1499
|
+
* The output file is a JSONL (JSON Lines) file where each line contains
|
|
1500
|
+
* one execution result with its reference ID, status, and output.
|
|
1501
|
+
*
|
|
1502
|
+
* @throws {Error} If batch is not completed or output file is unavailable.
|
|
1503
|
+
* @returns A promise resolving to the output file as a Blob.
|
|
1504
|
+
*
|
|
1505
|
+
* @example
|
|
1506
|
+
* ```typescript
|
|
1507
|
+
* const file = await result.downloadOutputFile()
|
|
1508
|
+
* const text = await file.text()
|
|
1509
|
+
* console.log(text) // JSONL content
|
|
1510
|
+
* ```
|
|
1511
|
+
*/
|
|
1512
|
+
downloadOutputFile(): Promise<Blob>;
|
|
1513
|
+
/**
|
|
1514
|
+
* Streams the output file as a ReadableStream for memory-efficient processing.
|
|
1515
|
+
*
|
|
1516
|
+
* Useful for large batches where loading the entire file into memory is not practical.
|
|
1517
|
+
*
|
|
1518
|
+
* @throws {Error} If batch is not completed or output file is unavailable.
|
|
1519
|
+
* @returns A promise resolving to a ReadableStream of the output file.
|
|
1520
|
+
*
|
|
1521
|
+
* @example
|
|
1522
|
+
* ```typescript
|
|
1523
|
+
* const stream = await result.streamOutputFile()
|
|
1524
|
+
* // Process stream with custom logic
|
|
1525
|
+
* ```
|
|
1526
|
+
*/
|
|
1527
|
+
streamOutputFile(): Promise<ReadableStream>;
|
|
1528
|
+
/**
|
|
1529
|
+
* Downloads and parses all results into an array.
|
|
1530
|
+
*
|
|
1531
|
+
* Loads the entire output file into memory, parses each line, and extracts
|
|
1532
|
+
* the output content. For large batches, consider using `iterateResults()` instead.
|
|
1533
|
+
*
|
|
1534
|
+
* @throws {Error} If batch is not completed, output file is unavailable, or parsing fails.
|
|
1535
|
+
* @returns A promise resolving to an array of all execution outputs.
|
|
1536
|
+
*
|
|
1537
|
+
* @example
|
|
1538
|
+
* ```typescript
|
|
1539
|
+
* const results = await result.getResults()
|
|
1540
|
+
* console.log(`Got ${results.length} results`)
|
|
1541
|
+
* results.forEach((output, i) => console.log(`Result ${i}:`, output))
|
|
1542
|
+
* ```
|
|
1543
|
+
*/
|
|
1544
|
+
getResults(): Promise<TOutput[]>;
|
|
1545
|
+
/**
|
|
1546
|
+
* Asynchronously iterates over raw result items from the output file.
|
|
1547
|
+
*
|
|
1548
|
+
* Streams and parses the output file line-by-line, yielding raw JSON objects.
|
|
1549
|
+
* Each yielded object contains the full result structure including metadata.
|
|
1550
|
+
*
|
|
1551
|
+
* @param params - Iteration options.
|
|
1552
|
+
* @param params.abortController - Optional AbortController to cancel iteration.
|
|
1553
|
+
* @throws {Error} If batch is not completed or output file is unavailable.
|
|
1554
|
+
* @yields Raw result objects from the JSONL file.
|
|
1555
|
+
*
|
|
1556
|
+
* @example
|
|
1557
|
+
* ```typescript
|
|
1558
|
+
* for await (const rawResult of result.iterateRawResults()) {
|
|
1559
|
+
* console.log('Reference ID:', rawResult.reference_id)
|
|
1560
|
+
* console.log('Status:', rawResult.status)
|
|
1561
|
+
* console.log('Output:', rawResult.result.outputContent.content)
|
|
1562
|
+
* }
|
|
1563
|
+
* ```
|
|
1564
|
+
*/
|
|
1565
|
+
iterateRawResults(params?: {
|
|
1566
|
+
abortController?: AbortController;
|
|
1567
|
+
}): AsyncGenerator<unknown, void, unknown>;
|
|
1568
|
+
/**
|
|
1569
|
+
* Asynchronously iterates over parsed output content from the batch results.
|
|
1570
|
+
*
|
|
1571
|
+
* Streams and parses the output file line-by-line, yielding only the output content
|
|
1572
|
+
* (not the full result metadata). Memory-efficient for large batches.
|
|
1573
|
+
*
|
|
1574
|
+
* @param params - Iteration options.
|
|
1575
|
+
* @param params.abortController - Optional AbortController to cancel iteration.
|
|
1576
|
+
* @throws {Error} If batch is not completed, output file is unavailable, or parsing fails.
|
|
1577
|
+
* @yields Parsed output content from each execution.
|
|
1578
|
+
*
|
|
1579
|
+
* @example
|
|
1580
|
+
* ```typescript
|
|
1581
|
+
* const controller = new AbortController()
|
|
1582
|
+
*
|
|
1583
|
+
* for await (const output of result.iterateResults({ abortController: controller })) {
|
|
1584
|
+
* console.log(output)
|
|
1585
|
+
* if (someCondition) {
|
|
1586
|
+
* controller.abort() // Stop iteration early
|
|
1587
|
+
* }
|
|
1588
|
+
* }
|
|
1589
|
+
* ```
|
|
1590
|
+
*/
|
|
1591
|
+
iterateResults(params?: {
|
|
1592
|
+
abortController?: AbortController;
|
|
1593
|
+
}): AsyncGenerator<Awaited<TOutput>, void, unknown>;
|
|
1594
|
+
/**
|
|
1595
|
+
* Fetches the raw result metadata for a specific execution by its reference ID.
|
|
1596
|
+
*
|
|
1597
|
+
* Queries the API for the execution result using the reference ID tag.
|
|
1598
|
+
* Returns the complete execution metadata including input, output, and usage statistics.
|
|
1599
|
+
*
|
|
1600
|
+
* @param referenceId - The reference ID of the execution to retrieve.
|
|
1601
|
+
* @throws {Error} If no result found with the given reference ID.
|
|
1602
|
+
* @returns A promise resolving to the raw execution result object.
|
|
1603
|
+
*
|
|
1604
|
+
* @example
|
|
1605
|
+
* ```typescript
|
|
1606
|
+
* const rawResult = await result.getRawResult('my-ref-id')
|
|
1607
|
+
* console.log('Credits used:', rawResult.creditsUsed)
|
|
1608
|
+
* console.log('Execution status:', rawResult.status)
|
|
1609
|
+
* ```
|
|
1610
|
+
*/
|
|
1611
|
+
getRawResult(referenceId: string): Promise<CompletionRunResult<TOutput>>;
|
|
1612
|
+
/**
|
|
1613
|
+
* Fetches the output content for a specific execution by its reference ID.
|
|
1614
|
+
*
|
|
1615
|
+
* Convenience method that retrieves the raw result and extracts just the output content.
|
|
1616
|
+
*
|
|
1617
|
+
* @param referenceId - The reference ID of the execution to retrieve.
|
|
1618
|
+
* @throws {Error} If no result found with the given reference ID.
|
|
1619
|
+
* @returns A promise resolving to the execution output content.
|
|
1620
|
+
*
|
|
1621
|
+
* @example
|
|
1622
|
+
* ```typescript
|
|
1623
|
+
* const output = await result.getResult('my-ref-id')
|
|
1624
|
+
* console.log('Output:', output)
|
|
1625
|
+
* ```
|
|
1626
|
+
*/
|
|
1627
|
+
getResult(referenceId: string): Promise<TOutput>;
|
|
1628
|
+
/**
|
|
1629
|
+
* Validates that the output file is available for access.
|
|
1630
|
+
*
|
|
1631
|
+
* @throws {Error} If batch is not completed or output file is missing.
|
|
1632
|
+
* @private
|
|
1633
|
+
*/
|
|
1634
|
+
private validateOutputFile;
|
|
1635
|
+
}
|
|
1636
|
+
/**
|
|
1637
|
+
* Event types emitted by BatchExecution during its lifecycle.
|
|
1638
|
+
*
|
|
1639
|
+
* @template TOutput - The output type.
|
|
1640
|
+
*
|
|
1641
|
+
* @property poll - Emitted during polling with current status and progress. Includes `requestId` from the polling request.
|
|
1642
|
+
* @property success - Emitted when batch completes successfully with the result object. Includes `requestId` from the final request.
|
|
1643
|
+
* @property error - Emitted when batch fails with the error object.
|
|
1644
|
+
* @property statusChange - Emitted when batch status transitions to a new state, includes new status and response.
|
|
1645
|
+
*
|
|
1646
|
+
* @category Canvas
|
|
1647
|
+
*/
|
|
1648
|
+
type BatchExecutionEvents<TOutput> = {
|
|
1649
|
+
poll: WithRequestId<BatchResponse>;
|
|
1650
|
+
success: BatchExecutionResult<TOutput>;
|
|
1651
|
+
error: BatchExecutionFailedError;
|
|
1652
|
+
statusChange: [BatchExecutionStatus, WithRequestId<BatchResponse>];
|
|
1653
|
+
};
|
|
1654
|
+
/**
|
|
1655
|
+
* Manages the execution lifecycle of a batch operation.
|
|
1656
|
+
*
|
|
1657
|
+
* Handles polling for batch completion, progress tracking, and result retrieval.
|
|
1658
|
+
* Provides an event-driven API for monitoring batch progress in real-time.
|
|
1659
|
+
*
|
|
1660
|
+
* ## Status Tracking
|
|
1661
|
+
*
|
|
1662
|
+
* The batch status can be accessed via the `status` property and tracks the lifecycle:
|
|
1663
|
+
*
|
|
1664
|
+
* - **Batch executions**: `created` → `validating` → `running` → `completed` or `failed`
|
|
1665
|
+
* - **Can be canceled**: At any time before completion using `cancel()`
|
|
1666
|
+
*
|
|
1667
|
+
* Status is set to `failed` when:
|
|
1668
|
+
* - Input file validation fails
|
|
1669
|
+
* - Batch processing encounters an error
|
|
1670
|
+
* - Server reports failure status
|
|
1671
|
+
*
|
|
1672
|
+
* Status is set to `completed` when:
|
|
1673
|
+
* - All executions in the batch finish processing
|
|
1674
|
+
* - Output file is generated and available
|
|
1675
|
+
*
|
|
1676
|
+
* ## Event System
|
|
1677
|
+
*
|
|
1678
|
+
* Events are emitted during polling to track progress:
|
|
1679
|
+
* - `statusChange` - Status transitions (created → validating → running → completed)
|
|
1680
|
+
* - `poll` - Each polling attempt with current progress
|
|
1681
|
+
* - `success` - Completion with the BatchExecutionResult
|
|
1682
|
+
* - `error` - Failure notification
|
|
1683
|
+
*
|
|
1684
|
+
* **Important:** Events are only emitted while polling is active. You must either call `poll()` or
|
|
1685
|
+
* await `execution.result` to start polling.
|
|
1686
|
+
*
|
|
1687
|
+
* @category Canvas
|
|
1688
|
+
*
|
|
1689
|
+
* @typeParam TOutput - The output result type for individual executions
|
|
1690
|
+
*
|
|
1691
|
+
* @fires poll - Emitted during polling with current status and progress. Includes `requestId` from the polling request.
|
|
1692
|
+
* @fires success - Emitted when batch completes successfully with the result object. Includes `requestId` from the final request.
|
|
1693
|
+
* @fires error - Emitted when batch fails (only if error listeners are registered, otherwise throws)
|
|
1694
|
+
* @fires statusChange - Emitted when batch status transitions to a new state
|
|
1695
|
+
*
|
|
1696
|
+
* @example
|
|
1697
|
+
* ```typescript
|
|
1698
|
+
* const execution = await batch.execute()
|
|
1699
|
+
*
|
|
1700
|
+
* // Track progress with events
|
|
1701
|
+
* execution.on('statusChange', ([status, response]) => {
|
|
1702
|
+
* console.log(`Status: ${status}`)
|
|
1703
|
+
* if (response.state) {
|
|
1704
|
+
* console.log(`Progress: ${response.state.completed}/${response.state.total}`)
|
|
1705
|
+
* }
|
|
1706
|
+
* })
|
|
1707
|
+
*
|
|
1708
|
+
* execution.on('success', (result) => {
|
|
1709
|
+
* console.log('Batch completed!')
|
|
1710
|
+
* console.log('Request ID:', result.requestId)
|
|
1711
|
+
* })
|
|
1712
|
+
*
|
|
1713
|
+
* // Start polling without waiting
|
|
1714
|
+
* execution.poll()
|
|
1715
|
+
* ```
|
|
1716
|
+
*/
|
|
1717
|
+
declare class BatchExecution<TOutput> extends Emittery<BatchExecutionEvents<TOutput>> {
|
|
1718
|
+
private readonly _client;
|
|
1719
|
+
private readonly _id;
|
|
1720
|
+
private readonly _params;
|
|
1721
|
+
private readonly _abortController;
|
|
1722
|
+
private readonly _creationResponse;
|
|
1723
|
+
private _status;
|
|
1724
|
+
private _resultPromise;
|
|
1725
|
+
/**
|
|
1726
|
+
* Creates a new batch execution instance.
|
|
1727
|
+
*
|
|
1728
|
+
* @param id - Unique identifier for this batch execution.
|
|
1729
|
+
* @param client - HTTP client for making API requests.
|
|
1730
|
+
* @param params - Batch execution parameters.
|
|
1731
|
+
* @param creationResponse - Initial response from batch creation.
|
|
1732
|
+
* @internal
|
|
1733
|
+
*/
|
|
1734
|
+
constructor(id: string, client: BaseClient, params: BatchParams | undefined, creationResponse: WithRequestId<BatchResponse>);
|
|
1735
|
+
/**
|
|
1736
|
+
* Gets the latest known status of the batch execution.
|
|
1737
|
+
*
|
|
1738
|
+
* Status values and transitions:
|
|
1739
|
+
* - `created` → `validating` → `running` → `completed` or `failed`
|
|
1740
|
+
* - Can transition to `canceled` from any non-terminal state
|
|
1741
|
+
*
|
|
1742
|
+
* Use the `statusChange` event to track status transitions in real-time.
|
|
1743
|
+
*
|
|
1744
|
+
* @returns The current status of the batch execution.
|
|
1745
|
+
*
|
|
1746
|
+
* @example
|
|
1747
|
+
* ```typescript
|
|
1748
|
+
* const execution = await batch.execute()
|
|
1749
|
+
* console.log(execution.status) // 'created'
|
|
1750
|
+
*
|
|
1751
|
+
* execution.on('statusChange', ([status]) => {
|
|
1752
|
+
* console.log('New status:', status)
|
|
1753
|
+
* })
|
|
1754
|
+
*
|
|
1755
|
+
* await execution.result
|
|
1756
|
+
* console.log(execution.status) // 'completed' or 'failed'
|
|
1757
|
+
* ```
|
|
1758
|
+
*/
|
|
1759
|
+
get status(): BatchExecutionStatus;
|
|
1760
|
+
/**
|
|
1761
|
+
* Gets the unique identifier for this batch execution.
|
|
1762
|
+
*
|
|
1763
|
+
* @returns The batch execution ID.
|
|
1764
|
+
*/
|
|
1765
|
+
get id(): string;
|
|
1766
|
+
/**
|
|
1767
|
+
* Gets the batch execution parameters.
|
|
1768
|
+
*
|
|
1769
|
+
* @returns The batch parameters.
|
|
1770
|
+
*/
|
|
1771
|
+
get params(): BatchParams;
|
|
1772
|
+
/**
|
|
1773
|
+
* Cancels the batch execution.
|
|
1774
|
+
*
|
|
1775
|
+
* Sends a cancellation request to the server and aborts any ongoing polling.
|
|
1776
|
+
* The batch will stop processing, but already-completed executions remain available.
|
|
1777
|
+
*
|
|
1778
|
+
* @returns A promise that resolves when the cancellation request completes.
|
|
1779
|
+
*
|
|
1780
|
+
* @example
|
|
1781
|
+
* ```typescript
|
|
1782
|
+
* const execution = await batch.execute()
|
|
1783
|
+
* execution.poll()
|
|
1784
|
+
*
|
|
1785
|
+
* // Cancel after some condition
|
|
1786
|
+
* if (shouldCancel) {
|
|
1787
|
+
* await execution.cancel()
|
|
1788
|
+
* console.log(execution.status) // 'canceled'
|
|
1789
|
+
* }
|
|
1790
|
+
* ```
|
|
1791
|
+
*/
|
|
1792
|
+
cancel(): Promise<void>;
|
|
1793
|
+
/**
|
|
1794
|
+
* Starts polling for the batch result without waiting for the promise to resolve.
|
|
1795
|
+
* This allows users to track batch progress via events rather than awaiting a promise.
|
|
1796
|
+
*
|
|
1797
|
+
* The following events will be emitted during polling:
|
|
1798
|
+
* - `statusChange`: Emitted when the batch status changes (e.g., 'created' → 'running' → 'completed')
|
|
1799
|
+
* - `poll`: Emitted on each polling attempt with the server response
|
|
1800
|
+
* - `success`: Emitted when the batch completes successfully with the final result
|
|
1801
|
+
* - `error`: Emitted if the batch fails
|
|
1802
|
+
*
|
|
1803
|
+
* **Important:** Events are only emitted while polling is active. You must call `poll()` or
|
|
1804
|
+
* await `execution.result` to start polling. Simply setting up event listeners without starting
|
|
1805
|
+
* polling will not trigger any events.
|
|
1806
|
+
*
|
|
1807
|
+
* @example
|
|
1808
|
+
* ```typescript
|
|
1809
|
+
* const execution = await batch.execute()
|
|
1810
|
+
*
|
|
1811
|
+
* // Set up event listeners
|
|
1812
|
+
* execution.on('statusChange', ([status, response]) => {
|
|
1813
|
+
* console.log(`Status: ${status}`)
|
|
1814
|
+
* if (response.state) {
|
|
1815
|
+
* const { completed, total } = response.state
|
|
1816
|
+
* console.log(`Progress: ${completed}/${total}`)
|
|
1817
|
+
* }
|
|
1818
|
+
* })
|
|
1819
|
+
*
|
|
1820
|
+
* execution.on('success', (result) => {
|
|
1821
|
+
* console.log('Batch completed!')
|
|
1822
|
+
* console.log('Request ID:', result.requestId)
|
|
1823
|
+
* })
|
|
1824
|
+
*
|
|
1825
|
+
* execution.on('error', (error) => {
|
|
1826
|
+
* console.error('Batch failed:', error)
|
|
1827
|
+
* })
|
|
1828
|
+
*
|
|
1829
|
+
* // Start polling without waiting
|
|
1830
|
+
* execution.poll()
|
|
1831
|
+
* ```
|
|
1832
|
+
*/
|
|
1833
|
+
poll(): void;
|
|
1834
|
+
/**
|
|
1835
|
+
* Sets the batch status and emits statusChange event if changed.
|
|
1836
|
+
*
|
|
1837
|
+
* @param status - The new status.
|
|
1838
|
+
* @param response - The response containing the status.
|
|
1839
|
+
* @private
|
|
1840
|
+
*/
|
|
1841
|
+
private setStatus;
|
|
1842
|
+
/**
|
|
1843
|
+
* Starts polling the server for batch completion.
|
|
1844
|
+
* Continues polling until the batch completes, fails, or times out.
|
|
1845
|
+
*
|
|
1846
|
+
* @throws {BatchExecutionFailedError} If the batch fails on the server.
|
|
1847
|
+
* @throws {Error} If the polling operation times out.
|
|
1848
|
+
* @returns A promise resolving to the final batch result.
|
|
1849
|
+
* @private
|
|
1850
|
+
*/
|
|
1851
|
+
private startPolling;
|
|
1852
|
+
/**
|
|
1853
|
+
* Gets the batch execution result. Automatically starts polling if not already started.
|
|
1854
|
+
*
|
|
1855
|
+
* @returns A promise resolving to the batch execution result.
|
|
1856
|
+
*
|
|
1857
|
+
* @example
|
|
1858
|
+
* ```typescript
|
|
1859
|
+
* const execution = await batch.execute()
|
|
1860
|
+
* const result = await execution.result
|
|
1861
|
+
*
|
|
1862
|
+
* // Access results
|
|
1863
|
+
* const outputs = await result.getResults()
|
|
1864
|
+
* console.log(`Got ${outputs.length} results`)
|
|
1865
|
+
* ```
|
|
1866
|
+
*/
|
|
1867
|
+
get result(): Promise<BatchExecutionResult<TOutput>>;
|
|
1868
|
+
}
|
|
1869
|
+
/**
|
|
1870
|
+
* Builder class for creating and executing batch operations on a canvas.
|
|
1871
|
+
*
|
|
1872
|
+
* The Batch class provides a fluent API for building up a collection of executions
|
|
1873
|
+
* to be processed in parallel. Items can be added incrementally, and the batch is
|
|
1874
|
+
* executed only when `execute()` is called.
|
|
1875
|
+
*
|
|
1876
|
+
* ## Usage Pattern
|
|
1877
|
+
*
|
|
1878
|
+
* 1. Create batch via `canvas.createBatch()`
|
|
1879
|
+
* 2. Add items via `add()` method (can be called multiple times)
|
|
1880
|
+
* 3. Execute batch via `execute()` method
|
|
1881
|
+
* 4. Monitor progress via events or await result
|
|
1882
|
+
*
|
|
1883
|
+
* ## Reference IDs
|
|
1884
|
+
*
|
|
1885
|
+
* Each batch item can have an optional reference ID for later retrieval.
|
|
1886
|
+
* If not provided, UUIDs are generated automatically. Reference IDs are useful
|
|
1887
|
+
* for correlating results with input data.
|
|
1888
|
+
*
|
|
1889
|
+
* @category Canvas
|
|
1890
|
+
*
|
|
1891
|
+
* @typeParam TInput - The input variables type for the canvas
|
|
1892
|
+
* @typeParam TOutput - The output result type for individual executions
|
|
1893
|
+
*
|
|
1894
|
+
* @example
|
|
1895
|
+
* ```typescript
|
|
1896
|
+
* const batch = canvas.createBatch({
|
|
1897
|
+
* pollingInterval: '1s',
|
|
1898
|
+
* pollingTimeout: '5m',
|
|
1899
|
+
* })
|
|
1900
|
+
*
|
|
1901
|
+
* // Add items individually
|
|
1902
|
+
* batch.add({
|
|
1903
|
+
* referenceId: 'item-1',
|
|
1904
|
+
* variables: { query: 'First query' }
|
|
1905
|
+
* })
|
|
1906
|
+
*
|
|
1907
|
+
* // Or add multiple items at once
|
|
1908
|
+
* batch.add([
|
|
1909
|
+
* { variables: { query: 'Second query' } },
|
|
1910
|
+
* { variables: { query: 'Third query' } }
|
|
1911
|
+
* ])
|
|
1912
|
+
*
|
|
1913
|
+
* // Execute and track progress
|
|
1914
|
+
* const execution = await batch.execute()
|
|
1915
|
+
* execution.on('statusChange', ([status, response]) => {
|
|
1916
|
+
* if (response.state) {
|
|
1917
|
+
* console.log(`Progress: ${response.state.completed}/${response.state.total}`)
|
|
1918
|
+
* }
|
|
1919
|
+
* })
|
|
1920
|
+
*
|
|
1921
|
+
* const result = await execution.result
|
|
1922
|
+
* const outputs = await result.getResults()
|
|
1923
|
+
* ```
|
|
1924
|
+
*/
|
|
1925
|
+
declare class Batch<TInput, TOutput> {
|
|
1926
|
+
private readonly _client;
|
|
1927
|
+
private readonly _canvasIdentifier;
|
|
1928
|
+
private readonly _items;
|
|
1929
|
+
private readonly _params;
|
|
1930
|
+
/**
|
|
1931
|
+
* Creates a new batch builder.
|
|
1932
|
+
*
|
|
1933
|
+
* @param client - HTTP client for making API requests.
|
|
1934
|
+
* @param canvasIdentifier - Canvas identification (ID + version or application ID).
|
|
1935
|
+
* @param params - Optional batch execution parameters.
|
|
1936
|
+
* @internal
|
|
1937
|
+
*/
|
|
1938
|
+
constructor(client: BaseClient, canvasIdentifier: CanvasIdentifier, params?: BatchParams);
|
|
1939
|
+
/**
|
|
1940
|
+
* Gets the current list of items in this batch.
|
|
1941
|
+
*
|
|
1942
|
+
* @returns Array of batch items.
|
|
1943
|
+
*/
|
|
1944
|
+
get items(): BatchItem<TInput>[];
|
|
1945
|
+
/**
|
|
1946
|
+
* Gets the batch execution parameters.
|
|
1947
|
+
*
|
|
1948
|
+
* @returns The batch parameters.
|
|
1949
|
+
*/
|
|
1950
|
+
get params(): BatchParams;
|
|
1951
|
+
/**
|
|
1952
|
+
* Gets the canvas identifier in the format expected by the API.
|
|
1953
|
+
*
|
|
1954
|
+
* @returns Canvas identifier object.
|
|
1955
|
+
* @private
|
|
1956
|
+
*/
|
|
1957
|
+
private get canvasIdentifier();
|
|
1958
|
+
/**
|
|
1959
|
+
* Adds one or more items to the batch.
|
|
1960
|
+
*
|
|
1961
|
+
* Items without a reference ID will have UUIDs generated automatically.
|
|
1962
|
+
* This method can be called multiple times to build up the batch incrementally.
|
|
1963
|
+
*
|
|
1964
|
+
* @param item - Single item or array of items to add to the batch.
|
|
1965
|
+
*
|
|
1966
|
+
* @example
|
|
1967
|
+
* ```typescript
|
|
1968
|
+
* // Add single item
|
|
1969
|
+
* batch.add({
|
|
1970
|
+
* referenceId: 'my-custom-id',
|
|
1971
|
+
* variables: { query: 'Hello' }
|
|
1972
|
+
* })
|
|
1973
|
+
*
|
|
1974
|
+
* // Add multiple items
|
|
1975
|
+
* batch.add([
|
|
1976
|
+
* { variables: { query: 'First' } },
|
|
1977
|
+
* { variables: { query: 'Second' } },
|
|
1978
|
+
* { variables: { query: 'Third' } }
|
|
1979
|
+
* ])
|
|
1980
|
+
*
|
|
1981
|
+
* console.log(`Batch has ${batch.items.length} items`)
|
|
1982
|
+
* ```
|
|
1983
|
+
*/
|
|
1984
|
+
add(item: MaybeArray<BatchItem<TInput>>): void;
|
|
1985
|
+
/**
|
|
1986
|
+
* Executes the batch by uploading the input file and creating a batch execution on the server.
|
|
1987
|
+
*
|
|
1988
|
+
* Returns a promise-like object that allows flexible usage patterns:
|
|
1989
|
+
* - Await for execution object: `const exec = await batch.execute()`
|
|
1990
|
+
* - Direct result access: `const result = await batch.execute().result`
|
|
1991
|
+
*
|
|
1992
|
+
* The batch items are serialized to JSONL format, uploaded to vault storage,
|
|
1993
|
+
* and submitted to the batch API for processing.
|
|
1994
|
+
*
|
|
1995
|
+
* @returns A promise-like object with a `result` property for direct result access.
|
|
1996
|
+
*
|
|
1997
|
+
* @example
|
|
1998
|
+
* ```typescript
|
|
1999
|
+
* // Direct result access (recommended for simple cases)
|
|
2000
|
+
* const result = await batch.execute().result
|
|
2001
|
+
* const outputs = await result.getResults()
|
|
2002
|
+
*
|
|
2003
|
+
* // Get execution object for event monitoring
|
|
2004
|
+
* const execution = await batch.execute()
|
|
2005
|
+
*
|
|
2006
|
+
* execution.on('statusChange', ([status, response]) => {
|
|
2007
|
+
* console.log(`Status: ${status}`)
|
|
2008
|
+
* if (response.state) {
|
|
2009
|
+
* console.log(`Progress: ${response.state.completed}/${response.state.total}`)
|
|
2010
|
+
* }
|
|
2011
|
+
* })
|
|
2012
|
+
*
|
|
2013
|
+
* execution.on('success', (result) => {
|
|
2014
|
+
* console.log('Batch completed!', result.requestId)
|
|
2015
|
+
* })
|
|
2016
|
+
*
|
|
2017
|
+
* const result = await execution.result
|
|
2018
|
+
*
|
|
2019
|
+
* // Iterate through results
|
|
2020
|
+
* for await (const output of result.iterateResults()) {
|
|
2021
|
+
* console.log(output)
|
|
2022
|
+
* }
|
|
2023
|
+
* ```
|
|
2024
|
+
*/
|
|
2025
|
+
execute(): BatchExecutionPromiseLike<TOutput>;
|
|
2026
|
+
}
|
|
2027
|
+
|
|
1084
2028
|
/**
|
|
1085
2029
|
* Canvas resource for managing prompt templates and their execution.
|
|
1086
2030
|
*
|
|
@@ -1423,16 +2367,12 @@ declare const zod: {
|
|
|
1423
2367
|
safeParseAsync: <T extends _zod.core.$ZodType>(schema: T, value: unknown, _ctx?: _zod.core.ParseContext<_zod.core.$ZodIssue>) => Promise<_zod.ZodSafeParseResult<_zod.core.output<T>>>;
|
|
1424
2368
|
encode: <T extends _zod.core.$ZodType>(schema: T, value: _zod.core.output<T>, _ctx?: _zod.core.ParseContext<_zod.core.$ZodIssue>) => _zod.core.input<T>;
|
|
1425
2369
|
decode: <T extends _zod.core.$ZodType>(schema: T, value: _zod.core.input<T>, _ctx?: _zod.core.ParseContext<_zod.core.$ZodIssue>) => _zod.core.output<T>;
|
|
1426
|
-
encodeAsync: <T extends _zod.core.$ZodType>(schema: T, value: _zod.core.output<T>, _ctx
|
|
1427
|
-
* Unique identifier for this prompt version.
|
|
1428
|
-
*/: _zod.core.ParseContext<_zod.core.$ZodIssue>) => Promise<_zod.core.input<T>>;
|
|
2370
|
+
encodeAsync: <T extends _zod.core.$ZodType>(schema: T, value: _zod.core.output<T>, _ctx?: _zod.core.ParseContext<_zod.core.$ZodIssue>) => Promise<_zod.core.input<T>>;
|
|
1429
2371
|
decodeAsync: <T extends _zod.core.$ZodType>(schema: T, value: _zod.core.input<T>, _ctx?: _zod.core.ParseContext<_zod.core.$ZodIssue>) => Promise<_zod.core.output<T>>;
|
|
1430
2372
|
safeEncode: <T extends _zod.core.$ZodType>(schema: T, value: _zod.core.output<T>, _ctx? /**
|
|
1431
|
-
*
|
|
2373
|
+
* The ID of the parent prompt.
|
|
1432
2374
|
*/: _zod.core.ParseContext<_zod.core.$ZodIssue>) => _zod.ZodSafeParseResult<_zod.core.input<T>>;
|
|
1433
|
-
safeDecode: <T extends _zod.core.$ZodType>(schema: T, value: _zod.core.input<T>, _ctx
|
|
1434
|
-
* Configuration settings for this prompt version.
|
|
1435
|
-
*/: _zod.core.ParseContext<_zod.core.$ZodIssue>) => _zod.ZodSafeParseResult<_zod.core.output<T>>;
|
|
2375
|
+
safeDecode: <T extends _zod.core.$ZodType>(schema: T, value: _zod.core.input<T>, _ctx?: _zod.core.ParseContext<_zod.core.$ZodIssue>) => _zod.ZodSafeParseResult<_zod.core.output<T>>;
|
|
1436
2376
|
safeEncodeAsync: <T extends _zod.core.$ZodType>(schema: T, value: _zod.core.output<T>, _ctx?: _zod.core.ParseContext<_zod.core.$ZodIssue>) => Promise<_zod.ZodSafeParseResult<_zod.core.input<T>>>;
|
|
1437
2377
|
safeDecodeAsync: <T extends _zod.core.$ZodType>(schema: T, value: _zod.core.input<T>, _ctx?: _zod.core.ParseContext<_zod.core.$ZodIssue>) => Promise<_zod.ZodSafeParseResult<_zod.core.output<T>>>;
|
|
1438
2378
|
setErrorMap(map: _zod.core.$ZodErrorMap): void;
|
|
@@ -1534,6 +2474,13 @@ declare class Canvas<TInput extends ZodTypeOrRecord, TOutput extends ZodTypeOrRe
|
|
|
1534
2474
|
* @returns True if the canvas is a workflow.
|
|
1535
2475
|
*/
|
|
1536
2476
|
get isWorkflow(): boolean;
|
|
2477
|
+
/**
|
|
2478
|
+
* Gets whether this canvas is a workstation.
|
|
2479
|
+
* This is true if an application ID is provided.
|
|
2480
|
+
*
|
|
2481
|
+
* @returns True if the canvas is a workstation.
|
|
2482
|
+
*/
|
|
2483
|
+
get isWorkstation(): boolean;
|
|
1537
2484
|
/**
|
|
1538
2485
|
* Validates and parses input variables using the canvas input schema.
|
|
1539
2486
|
*
|
|
@@ -1618,9 +2565,38 @@ declare class Canvas<TInput extends ZodTypeOrRecord, TOutput extends ZodTypeOrRe
|
|
|
1618
2565
|
* ```
|
|
1619
2566
|
*/
|
|
1620
2567
|
getExecution(id: string, options?: {
|
|
1621
|
-
pollingInterval?: number;
|
|
1622
|
-
pollingTimeout?: number;
|
|
2568
|
+
pollingInterval?: string | number;
|
|
2569
|
+
pollingTimeout?: string | number;
|
|
1623
2570
|
}): Promise<CanvasExecution<AsyncExecutionParams, unknown, Output<TOutput>>>;
|
|
2571
|
+
/**
|
|
2572
|
+
* Prepares to execute this canvas in batch.
|
|
2573
|
+
*
|
|
2574
|
+
* @param params - The parameters for the batch.
|
|
2575
|
+
* @param params.pollingInterval - The interval between polling attempts.
|
|
2576
|
+
* @param params.pollingTimeout - The timeout for the batch.
|
|
2577
|
+
* @param params.webhookUrl - The webhook URL for the batch.
|
|
2578
|
+
*
|
|
2579
|
+
* @example
|
|
2580
|
+
* ```typescript
|
|
2581
|
+
* const batch = canvas.createBatch({
|
|
2582
|
+
* pollingInterval: '1s',
|
|
2583
|
+
* pollingTimeout: '1m',
|
|
2584
|
+
* webhookUrl: 'https://example.com/webhook',
|
|
2585
|
+
* })
|
|
2586
|
+
*
|
|
2587
|
+
* batch.add({
|
|
2588
|
+
* referenceId: crypto.randomUUID(), // Optional
|
|
2589
|
+
* variables: { query: 'Hello' },
|
|
2590
|
+
* })
|
|
2591
|
+
*
|
|
2592
|
+
* const execution = await batch.execute()
|
|
2593
|
+
* const result = await execution.result
|
|
2594
|
+
* const resultFile = await execution.downloadOutputFile()
|
|
2595
|
+
* ```
|
|
2596
|
+
*
|
|
2597
|
+
* @returns The batch instance that can be used to manage the batch.
|
|
2598
|
+
*/
|
|
2599
|
+
createBatch(params?: BatchParams): Batch<Output<TInput>, Output<TOutput>>;
|
|
1624
2600
|
}
|
|
1625
2601
|
|
|
1626
2602
|
/**
|
|
@@ -1766,4 +2742,4 @@ declare class TelaSDK extends BaseClient {
|
|
|
1766
2742
|
*/
|
|
1767
2743
|
declare function createTelaClient(opts: TelaSDKOptions): TelaSDK;
|
|
1768
2744
|
|
|
1769
|
-
export { APIError, AuthenticationError, AuthorizationError, BadRequestError, BaseClient, type BaseClientOptions, type BaseTelaFileOptions, ConflictApiKeyAndJWTError, ConflictError, ConnectionError, ConnectionTimeout, EmptyFileError, ExecutionFailedError, ExecutionNotStartedError, FileUploadError, type HTTPMethods, InternalServerError, InvalidExecutionModeError, InvalidFileURL, MissingApiKeyOrJWTError, NotFoundError, RateLimitError, type RequestOptions, type SchemaBuilder, TelaError, TelaFile, type TelaFileInput, type TelaFileOptions, type TelaFileOptionsWithMimeType, TelaFileSchema, TelaSDK, type TelaSDKOptions, UnprocessableEntityError, UserAbortError, createTelaClient, toError };
|
|
2745
|
+
export { APIError, AuthenticationError, AuthorizationError, BadRequestError, BaseClient, type BaseClientOptions, type BaseTelaFileOptions, BatchExecutionFailedError, ConflictApiKeyAndJWTError, ConflictError, ConnectionError, ConnectionTimeout, EmptyFileError, ExecutionFailedError, ExecutionNotStartedError, FileUploadError, type HTTPMethods, InternalServerError, InvalidExecutionModeError, InvalidFileURL, MissingApiKeyOrJWTError, NotFoundError, RateLimitError, type RequestOptions, type SchemaBuilder, TelaError, TelaFile, type TelaFileInput, type TelaFileOptions, type TelaFileOptionsWithMimeType, TelaFileSchema, TelaSDK, type TelaSDKOptions, UnprocessableEntityError, UserAbortError, createTelaClient, toError };
|