@meistrari/tela-sdk-js 2.4.3 → 2.6.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 +1926 -384
- package/dist/index.d.cts +2374 -532
- package/dist/index.d.mts +2374 -532
- package/dist/index.d.ts +2374 -532
- package/dist/index.mjs +1930 -392
- package/package.json +2 -2
package/dist/index.d.cts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import
|
|
2
|
-
import _zod__default, { ZodError, z } from 'zod';
|
|
1
|
+
import z, { z as z$1 } from 'zod';
|
|
3
2
|
import Emittery from 'emittery';
|
|
3
|
+
import { JSONSchema } from 'zod/v4/core';
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* Base HTTP client with retry logic, request/response transformation, and streaming support.
|
|
@@ -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,24 @@ 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 a workstation task fails on the server.
|
|
151
|
+
*
|
|
152
|
+
* @category Errors
|
|
153
|
+
*/
|
|
154
|
+
declare class TaskFailedError extends TelaError {
|
|
155
|
+
readonly rawTask: Record<string, any>;
|
|
156
|
+
constructor(rawTask: Record<string, any>, message?: string, cause?: Error);
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* Thrown when batch execution fails on the server.
|
|
160
|
+
*
|
|
161
|
+
* @category Errors
|
|
162
|
+
*/
|
|
163
|
+
declare class BatchExecutionFailedError extends TelaError {
|
|
164
|
+
readonly rawResponse: Record<string, any>;
|
|
165
|
+
constructor(rawResponse: Record<string, any>);
|
|
166
|
+
}
|
|
148
167
|
/**
|
|
149
168
|
* Base class for all API-related errors.
|
|
150
169
|
*
|
|
@@ -247,7 +266,7 @@ type TelaFileOptions = BaseTelaFileOptions | TelaFileOptionsWithMimeType;
|
|
|
247
266
|
* which can be a URL string, Uint8Array, ReadableStream, ReadStream, Blob, or File.
|
|
248
267
|
*/
|
|
249
268
|
type TelaFileInput = string | Uint8Array | ReadableStream | Blob | File;
|
|
250
|
-
declare function TelaFileSchema():
|
|
269
|
+
declare function TelaFileSchema(): z.ZodCustom<TelaFile, TelaFile>;
|
|
251
270
|
/**
|
|
252
271
|
* Represents a file with support for various types including URLs, binary data, streams, and Blobs.
|
|
253
272
|
*
|
|
@@ -384,17 +403,488 @@ declare class TelaFile {
|
|
|
384
403
|
*/
|
|
385
404
|
private isValidVaultReference;
|
|
386
405
|
}
|
|
406
|
+
declare function isTelaFile(obj: unknown): obj is TelaFile;
|
|
407
|
+
declare function isTelaFileArray(obj: unknown): obj is TelaFile[];
|
|
387
408
|
|
|
388
409
|
/**
|
|
389
|
-
*
|
|
410
|
+
* Represents a variable that can be used in a canvas template.
|
|
411
|
+
*/
|
|
412
|
+
type CanvasVariable = {
|
|
413
|
+
/**
|
|
414
|
+
* The name of the variable.
|
|
415
|
+
*/
|
|
416
|
+
name: string;
|
|
417
|
+
/**
|
|
418
|
+
* The type of the variable (e.g., 'string', 'number', 'file').
|
|
419
|
+
*/
|
|
420
|
+
type: string;
|
|
421
|
+
/**
|
|
422
|
+
* Whether this variable is required for canvas execution.
|
|
423
|
+
*/
|
|
424
|
+
required: boolean;
|
|
425
|
+
/**
|
|
426
|
+
* Description of the variable's purpose.
|
|
427
|
+
*/
|
|
428
|
+
description: string;
|
|
429
|
+
/**
|
|
430
|
+
* Processing options for the variable.
|
|
431
|
+
*/
|
|
432
|
+
processingOptions: {
|
|
433
|
+
/**
|
|
434
|
+
* Whether multimodal content (images, files) is allowed.
|
|
435
|
+
*/
|
|
436
|
+
allowMultimodal: boolean;
|
|
437
|
+
};
|
|
438
|
+
};
|
|
439
|
+
|
|
440
|
+
/**
|
|
441
|
+
* Represents a specific version of a canvas/prompt from the Tela API.
|
|
442
|
+
*/
|
|
443
|
+
type PromptVersion = {
|
|
444
|
+
/**
|
|
445
|
+
* Unique identifier for this prompt version.
|
|
446
|
+
*/
|
|
447
|
+
id: string;
|
|
448
|
+
/**
|
|
449
|
+
* The raw content of the prompt.
|
|
450
|
+
*/
|
|
451
|
+
content: string;
|
|
452
|
+
/**
|
|
453
|
+
* The markdown-formatted content of the prompt.
|
|
454
|
+
*/
|
|
455
|
+
markdownContent: any;
|
|
456
|
+
/**
|
|
457
|
+
* The ID of the parent prompt.
|
|
458
|
+
*/
|
|
459
|
+
promptId: string;
|
|
460
|
+
/**
|
|
461
|
+
* Variables available in this prompt version.
|
|
462
|
+
*/
|
|
463
|
+
variables: Array<CanvasVariable>;
|
|
464
|
+
/**
|
|
465
|
+
* The title/name of the prompt.
|
|
466
|
+
*/
|
|
467
|
+
title: string;
|
|
468
|
+
/**
|
|
469
|
+
* Configuration settings for this prompt version.
|
|
470
|
+
*/
|
|
471
|
+
configuration: {
|
|
472
|
+
/**
|
|
473
|
+
* The AI model to use (e.g., 'gpt-4', 'claude-3').
|
|
474
|
+
*/
|
|
475
|
+
model: string;
|
|
476
|
+
/**
|
|
477
|
+
* The type of prompt ('chat' or 'completion').
|
|
478
|
+
*/
|
|
479
|
+
type: string;
|
|
480
|
+
/**
|
|
481
|
+
* Temperature setting for response randomness (0-1).
|
|
482
|
+
*/
|
|
483
|
+
temperature: number;
|
|
484
|
+
/**
|
|
485
|
+
* Structured output configuration.
|
|
486
|
+
*/
|
|
487
|
+
structuredOutput: {
|
|
488
|
+
/**
|
|
489
|
+
* JSON schema for validating structured output.
|
|
490
|
+
*/
|
|
491
|
+
schema: JSONSchema.JSONSchema;
|
|
492
|
+
/**
|
|
493
|
+
* Whether structured output is enabled.
|
|
494
|
+
*/
|
|
495
|
+
enabled: boolean;
|
|
496
|
+
};
|
|
497
|
+
};
|
|
498
|
+
/**
|
|
499
|
+
* Whether this version is promoted to production.
|
|
500
|
+
*/
|
|
501
|
+
promoted: boolean;
|
|
502
|
+
/**
|
|
503
|
+
* Whether this is a draft version.
|
|
504
|
+
*/
|
|
505
|
+
draft: boolean;
|
|
506
|
+
/**
|
|
507
|
+
* ID of the workspace this prompt belongs to.
|
|
508
|
+
*/
|
|
509
|
+
workspaceId: string;
|
|
510
|
+
/**
|
|
511
|
+
* Workflow specification if this is a workflow-based prompt.
|
|
512
|
+
*/
|
|
513
|
+
workflowSpec: any;
|
|
514
|
+
/**
|
|
515
|
+
* Graph representation of the workflow.
|
|
516
|
+
*/
|
|
517
|
+
graph: any;
|
|
518
|
+
/**
|
|
519
|
+
* Whether this prompt is a workflow.
|
|
520
|
+
*/
|
|
521
|
+
isWorkflow: boolean;
|
|
522
|
+
/**
|
|
523
|
+
* User ID who created this version.
|
|
524
|
+
*/
|
|
525
|
+
createdBy: string;
|
|
526
|
+
/**
|
|
527
|
+
* User ID who last updated this version.
|
|
528
|
+
*/
|
|
529
|
+
updatedBy: string;
|
|
530
|
+
/**
|
|
531
|
+
* User ID who deleted this version, if applicable.
|
|
532
|
+
*/
|
|
533
|
+
deletedBy: any;
|
|
534
|
+
/**
|
|
535
|
+
* ISO timestamp when this version was created.
|
|
536
|
+
*/
|
|
537
|
+
createdAt: string;
|
|
538
|
+
/**
|
|
539
|
+
* ISO timestamp when this version was last updated.
|
|
540
|
+
*/
|
|
541
|
+
updatedAt: string;
|
|
542
|
+
/**
|
|
543
|
+
* ISO timestamp when this version was deleted, if applicable.
|
|
544
|
+
*/
|
|
545
|
+
deletedAt: any;
|
|
546
|
+
/**
|
|
547
|
+
* Messages in the conversation for this prompt version.
|
|
548
|
+
*/
|
|
549
|
+
messages: Array<{
|
|
550
|
+
/**
|
|
551
|
+
* Unique message identifier.
|
|
552
|
+
*/
|
|
553
|
+
id: string;
|
|
554
|
+
/**
|
|
555
|
+
* The raw content of the message.
|
|
556
|
+
*/
|
|
557
|
+
content: string;
|
|
558
|
+
/**
|
|
559
|
+
* The markdown-formatted content of the message.
|
|
560
|
+
*/
|
|
561
|
+
markdownContent: string;
|
|
562
|
+
/**
|
|
563
|
+
* Role of the message sender (e.g., 'user', 'assistant').
|
|
564
|
+
*/
|
|
565
|
+
role: string;
|
|
566
|
+
/**
|
|
567
|
+
* ID of the prompt version this message belongs to.
|
|
568
|
+
*/
|
|
569
|
+
promptVersionId: string;
|
|
570
|
+
/**
|
|
571
|
+
* Order index of this message in the conversation.
|
|
572
|
+
*/
|
|
573
|
+
index: number;
|
|
574
|
+
/**
|
|
575
|
+
* User ID who created this message.
|
|
576
|
+
*/
|
|
577
|
+
createdBy: string;
|
|
578
|
+
/**
|
|
579
|
+
* User ID who last updated this message.
|
|
580
|
+
*/
|
|
581
|
+
updatedBy: string;
|
|
582
|
+
/**
|
|
583
|
+
* ISO timestamp when this message was created.
|
|
584
|
+
*/
|
|
585
|
+
createdAt: string;
|
|
586
|
+
/**
|
|
587
|
+
* ISO timestamp when this message was last updated.
|
|
588
|
+
*/
|
|
589
|
+
updatedAt: string;
|
|
590
|
+
/**
|
|
591
|
+
* ISO timestamp when this message was deleted, if applicable.
|
|
592
|
+
*/
|
|
593
|
+
deletedAt: any;
|
|
594
|
+
}>;
|
|
595
|
+
};
|
|
596
|
+
|
|
597
|
+
/**
|
|
598
|
+
* Schema validation and matching utilities.
|
|
390
599
|
*
|
|
391
|
-
* This module
|
|
392
|
-
*
|
|
393
|
-
* manages file uploads and result validation.
|
|
600
|
+
* This module provides utilities for validating and comparing client-side
|
|
601
|
+
* schemas with server-side schemas, detecting mismatches and type differences.
|
|
394
602
|
*
|
|
395
|
-
* @module
|
|
603
|
+
* @module Utilities
|
|
396
604
|
*/
|
|
397
605
|
|
|
606
|
+
declare const zod: {
|
|
607
|
+
file: typeof TelaFileSchema;
|
|
608
|
+
core: typeof z$1.core;
|
|
609
|
+
globalRegistry: z$1.core.$ZodRegistry<z$1.core.GlobalMeta, z$1.core.$ZodType<unknown, unknown, z$1.core.$ZodTypeInternals<unknown, unknown>>>;
|
|
610
|
+
registry: typeof z$1.core.registry;
|
|
611
|
+
config: typeof z$1.core.config;
|
|
612
|
+
$output: typeof z$1.core.$output;
|
|
613
|
+
$input: typeof z$1.core.$input;
|
|
614
|
+
$brand: typeof z$1.core.$brand;
|
|
615
|
+
clone: typeof z$1.core.util.clone;
|
|
616
|
+
regexes: typeof z$1.core.regexes;
|
|
617
|
+
treeifyError: typeof z$1.core.treeifyError;
|
|
618
|
+
prettifyError: typeof z$1.core.prettifyError;
|
|
619
|
+
formatError: typeof z$1.core.formatError;
|
|
620
|
+
flattenError: typeof z$1.core.flattenError;
|
|
621
|
+
toJSONSchema: typeof z$1.core.toJSONSchema;
|
|
622
|
+
TimePrecision: {
|
|
623
|
+
readonly Any: null;
|
|
624
|
+
readonly Minute: -1;
|
|
625
|
+
readonly Second: 0;
|
|
626
|
+
readonly Millisecond: 3;
|
|
627
|
+
readonly Microsecond: 6;
|
|
628
|
+
};
|
|
629
|
+
util: typeof z$1.core.util;
|
|
630
|
+
NEVER: never;
|
|
631
|
+
locales: typeof z$1.core.locales;
|
|
632
|
+
ZodISODateTime: z$1.core.$constructor<z$1.ZodISODateTime, z$1.core.$ZodISODateTimeDef>;
|
|
633
|
+
ZodISODate: z$1.core.$constructor<z$1.ZodISODate, z$1.core.$ZodStringFormatDef<"date">>;
|
|
634
|
+
ZodISOTime: z$1.core.$constructor<z$1.ZodISOTime, z$1.core.$ZodISOTimeDef>;
|
|
635
|
+
ZodISODuration: z$1.core.$constructor<z$1.ZodISODuration, z$1.core.$ZodStringFormatDef<"duration">>;
|
|
636
|
+
iso: typeof z$1.iso;
|
|
637
|
+
coerce: typeof z$1.coerce;
|
|
638
|
+
string(params?: string | z$1.core.$ZodStringParams): z$1.ZodString;
|
|
639
|
+
string<T extends string>(params?: string | z$1.core.$ZodStringParams): z$1.core.$ZodType<T, T>;
|
|
640
|
+
email(params?: string | z$1.core.$ZodEmailParams): z$1.ZodEmail;
|
|
641
|
+
guid(params?: string | z$1.core.$ZodGUIDParams): z$1.ZodGUID;
|
|
642
|
+
uuid(params?: string | z$1.core.$ZodUUIDParams): z$1.ZodUUID;
|
|
643
|
+
uuidv4(params?: string | z$1.core.$ZodUUIDv4Params): z$1.ZodUUID;
|
|
644
|
+
uuidv6(params?: string | z$1.core.$ZodUUIDv6Params): z$1.ZodUUID;
|
|
645
|
+
uuidv7(params?: string | z$1.core.$ZodUUIDv7Params): z$1.ZodUUID;
|
|
646
|
+
url(params?: string | z$1.core.$ZodURLParams): z$1.ZodURL;
|
|
647
|
+
httpUrl(params?: string | Omit<z$1.core.$ZodURLParams, "protocol" | "hostname">): z$1.ZodURL;
|
|
648
|
+
emoji(params?: string | z$1.core.$ZodEmojiParams): z$1.ZodEmoji;
|
|
649
|
+
nanoid(params?: string | z$1.core.$ZodNanoIDParams): z$1.ZodNanoID;
|
|
650
|
+
cuid(params?: string | z$1.core.$ZodCUIDParams): z$1.ZodCUID;
|
|
651
|
+
cuid2(params?: string | z$1.core.$ZodCUID2Params): z$1.ZodCUID2;
|
|
652
|
+
ulid(params?: string | z$1.core.$ZodULIDParams): z$1.ZodULID;
|
|
653
|
+
xid(params?: string | z$1.core.$ZodXIDParams): z$1.ZodXID;
|
|
654
|
+
ksuid(params?: string | z$1.core.$ZodKSUIDParams): z$1.ZodKSUID;
|
|
655
|
+
ipv4(params?: string | z$1.core.$ZodIPv4Params): z$1.ZodIPv4;
|
|
656
|
+
ipv6(params?: string | z$1.core.$ZodIPv6Params): z$1.ZodIPv6;
|
|
657
|
+
cidrv4(params?: string | z$1.core.$ZodCIDRv4Params): z$1.ZodCIDRv4;
|
|
658
|
+
cidrv6(params?: string | z$1.core.$ZodCIDRv6Params): z$1.ZodCIDRv6;
|
|
659
|
+
base64(params?: string | z$1.core.$ZodBase64Params): z$1.ZodBase64;
|
|
660
|
+
base64url(params?: string | z$1.core.$ZodBase64URLParams): z$1.ZodBase64URL;
|
|
661
|
+
e164(params?: string | z$1.core.$ZodE164Params): z$1.ZodE164;
|
|
662
|
+
jwt(params?: string | z$1.core.$ZodJWTParams): z$1.ZodJWT;
|
|
663
|
+
stringFormat<Format extends string>(format: Format, fnOrRegex: ((arg: string) => z$1.core.util.MaybeAsync<unknown>) | RegExp, _params?: string | z$1.core.$ZodStringFormatParams): z$1.ZodCustomStringFormat<Format>;
|
|
664
|
+
hostname(_params?: string | z$1.core.$ZodStringFormatParams): z$1.ZodCustomStringFormat<"hostname">;
|
|
665
|
+
hex(_params?: string | z$1.core.$ZodStringFormatParams): z$1.ZodCustomStringFormat<"hex">;
|
|
666
|
+
hash<Alg extends z$1.core.util.HashAlgorithm, Enc extends z$1.core.util.HashEncoding = "hex">(alg: Alg, params?: {
|
|
667
|
+
enc?: Enc;
|
|
668
|
+
} & z$1.core.$ZodStringFormatParams): z$1.ZodCustomStringFormat<`${Alg}_${Enc}`>;
|
|
669
|
+
number(params?: string | z$1.core.$ZodNumberParams): z$1.ZodNumber;
|
|
670
|
+
int(params?: string | z$1.core.$ZodCheckNumberFormatParams): z$1.ZodInt;
|
|
671
|
+
float32(params?: string | z$1.core.$ZodCheckNumberFormatParams): z$1.ZodFloat32;
|
|
672
|
+
float64(params?: string | z$1.core.$ZodCheckNumberFormatParams): z$1.ZodFloat64;
|
|
673
|
+
int32(params?: string | z$1.core.$ZodCheckNumberFormatParams): z$1.ZodInt32;
|
|
674
|
+
uint32(params?: string | z$1.core.$ZodCheckNumberFormatParams): z$1.ZodUInt32;
|
|
675
|
+
boolean(params?: string | z$1.core.$ZodBooleanParams): z$1.ZodBoolean;
|
|
676
|
+
bigint(params?: string | z$1.core.$ZodBigIntParams): z$1.ZodBigInt;
|
|
677
|
+
int64(params?: string | z$1.core.$ZodBigIntFormatParams): z$1.ZodBigIntFormat;
|
|
678
|
+
uint64(params?: string | z$1.core.$ZodBigIntFormatParams): z$1.ZodBigIntFormat;
|
|
679
|
+
symbol(params?: string | z$1.core.$ZodSymbolParams): z$1.ZodSymbol;
|
|
680
|
+
any(): z$1.ZodAny;
|
|
681
|
+
unknown(): z$1.ZodUnknown;
|
|
682
|
+
never(params?: string | z$1.core.$ZodNeverParams): z$1.ZodNever;
|
|
683
|
+
date(params?: string | z$1.core.$ZodDateParams): z$1.ZodDate;
|
|
684
|
+
array<T extends z$1.core.SomeType>(element: T, params?: string | z$1.core.$ZodArrayParams): z$1.ZodArray<T>;
|
|
685
|
+
keyof<T extends z$1.ZodObject>(schema: T): z$1.ZodEnum<z$1.core.util.KeysEnum<T["_zod"]["output"]>>;
|
|
686
|
+
object<T extends z$1.core.$ZodLooseShape = Partial<Record<never, z$1.core.SomeType>>>(shape?: T, params?: string | z$1.core.$ZodObjectParams): z$1.ZodObject<z$1.core.util.Writeable<T>, z$1.core.$strip>;
|
|
687
|
+
strictObject<T extends z$1.core.$ZodLooseShape>(shape: T, params?: string | z$1.core.$ZodObjectParams): z$1.ZodObject<T, z$1.core.$strict>;
|
|
688
|
+
looseObject<T extends z$1.core.$ZodLooseShape>(shape: T, params?: string | z$1.core.$ZodObjectParams): z$1.ZodObject<T, z$1.core.$loose>;
|
|
689
|
+
union<const T extends readonly z$1.core.SomeType[]>(options: T, params?: string | z$1.core.$ZodUnionParams): z$1.ZodUnion<T>;
|
|
690
|
+
discriminatedUnion<Types extends readonly [z$1.core.$ZodTypeDiscriminable, ...z$1.core.$ZodTypeDiscriminable[]], Disc extends string>(discriminator: Disc, options: Types, params?: string | z$1.core.$ZodDiscriminatedUnionParams): z$1.ZodDiscriminatedUnion<Types, Disc>;
|
|
691
|
+
intersection<T extends z$1.core.SomeType, U extends z$1.core.SomeType>(left: T, right: U): z$1.ZodIntersection<T, U>;
|
|
692
|
+
tuple<T extends readonly [z$1.core.SomeType, ...z$1.core.SomeType[]]>(items: T, params?: string | z$1.core.$ZodTupleParams): z$1.ZodTuple<T, null>;
|
|
693
|
+
tuple<T extends readonly [z$1.core.SomeType, ...z$1.core.SomeType[]], Rest extends z$1.core.SomeType>(items: T, rest: Rest, params?: string | z$1.core.$ZodTupleParams): z$1.ZodTuple<T, Rest>;
|
|
694
|
+
tuple(items: [], params?: string | z$1.core.$ZodTupleParams): z$1.ZodTuple<[], null>;
|
|
695
|
+
record<Key extends z$1.core.$ZodRecordKey, Value extends z$1.core.SomeType>(keyType: Key, valueType: Value, params?: string | z$1.core.$ZodRecordParams): z$1.ZodRecord<Key, Value>;
|
|
696
|
+
partialRecord<Key extends z$1.core.$ZodRecordKey, Value extends z$1.core.SomeType>(keyType: Key, valueType: Value, params?: string | z$1.core.$ZodRecordParams): z$1.ZodRecord<Key & z$1.core.$partial, Value>;
|
|
697
|
+
map<Key extends z$1.core.SomeType, Value extends z$1.core.SomeType>(keyType: Key, valueType: Value, params?: string | z$1.core.$ZodMapParams): z$1.ZodMap<Key, Value>;
|
|
698
|
+
set<Value extends z$1.core.SomeType>(valueType: Value, params?: string | z$1.core.$ZodSetParams): z$1.ZodSet<Value>;
|
|
699
|
+
nativeEnum<T extends z$1.core.util.EnumLike>(entries: T, params?: string | z$1.core.$ZodEnumParams): z$1.ZodEnum<T>;
|
|
700
|
+
literal<const T extends ReadonlyArray<z$1.core.util.Literal>>(value: T, params?: string | z$1.core.$ZodLiteralParams): z$1.ZodLiteral<T[number]>;
|
|
701
|
+
literal<const T extends z$1.core.util.Literal>(value: T, params?: string | z$1.core.$ZodLiteralParams): z$1.ZodLiteral<T>;
|
|
702
|
+
transform<I = unknown, O = I>(fn: (input: I, ctx: z$1.core.ParsePayload) => O): z$1.ZodTransform<Awaited<O>, I>;
|
|
703
|
+
optional<T extends z$1.core.SomeType>(innerType: T): z$1.ZodOptional<T>;
|
|
704
|
+
nullable<T extends z$1.core.SomeType>(innerType: T): z$1.ZodNullable<T>;
|
|
705
|
+
nullish<T extends z$1.core.SomeType>(innerType: T): z$1.ZodOptional<z$1.ZodNullable<T>>;
|
|
706
|
+
_default<T extends z$1.core.SomeType>(innerType: T, defaultValue: z$1.core.util.NoUndefined<z$1.core.output<T>> | (() => z$1.core.util.NoUndefined<z$1.core.output<T>>)): z$1.ZodDefault<T>;
|
|
707
|
+
prefault<T extends z$1.core.SomeType>(innerType: T, defaultValue: z$1.core.input<T> | (() => z$1.core.input<T>)): z$1.ZodPrefault<T>;
|
|
708
|
+
nonoptional<T extends z$1.core.SomeType>(innerType: T, params?: string | z$1.core.$ZodNonOptionalParams): z$1.ZodNonOptional<T>;
|
|
709
|
+
success<T extends z$1.core.SomeType>(innerType: T): z$1.ZodSuccess<T>;
|
|
710
|
+
nan(params?: string | z$1.core.$ZodNaNParams): z$1.ZodNaN;
|
|
711
|
+
pipe<const A extends z$1.core.SomeType, B extends z$1.core.$ZodType<unknown, z$1.core.output<A>> = z$1.core.$ZodType<unknown, z$1.core.output<A>, z$1.core.$ZodTypeInternals<unknown, z$1.core.output<A>>>>(in_: A, out: B | z$1.core.$ZodType<unknown, z$1.core.output<A>>): z$1.ZodPipe<A, B>;
|
|
712
|
+
codec<const A extends z$1.core.SomeType, B extends z$1.core.SomeType = z$1.core.$ZodType<unknown, unknown, z$1.core.$ZodTypeInternals<unknown, unknown>>>(in_: A, out: B, params: {
|
|
713
|
+
decode: (value: z$1.core.output<A>, payload: z$1.core.ParsePayload<z$1.core.output<A>>) => z$1.core.util.MaybeAsync<z$1.core.input<B>>;
|
|
714
|
+
encode: (value: z$1.core.input<B>, payload: z$1.core.ParsePayload<z$1.core.input<B>>) => z$1.core.util.MaybeAsync<z$1.core.output<A>>;
|
|
715
|
+
}): z$1.ZodCodec<A, B>;
|
|
716
|
+
readonly<T extends z$1.core.SomeType>(innerType: T): z$1.ZodReadonly<T>;
|
|
717
|
+
templateLiteral<const Parts extends z$1.core.$ZodTemplateLiteralPart[]>(parts: Parts, params?: string | z$1.core.$ZodTemplateLiteralParams): z$1.ZodTemplateLiteral<z$1.core.$PartsToTemplateLiteral<Parts>>;
|
|
718
|
+
lazy<T extends z$1.core.SomeType>(getter: () => T): z$1.ZodLazy<T>;
|
|
719
|
+
promise<T extends z$1.core.SomeType>(innerType: T): z$1.ZodPromise<T>;
|
|
720
|
+
_function(): z$1.ZodFunction;
|
|
721
|
+
_function<const In extends ReadonlyArray<z$1.core.$ZodType>>(params: {
|
|
722
|
+
input: In;
|
|
723
|
+
}): z$1.ZodFunction<z$1.ZodTuple<In, null>, z$1.core.$ZodFunctionOut>;
|
|
724
|
+
_function<const In extends ReadonlyArray<z$1.core.$ZodType>, const Out extends z$1.core.$ZodFunctionOut = z$1.core.$ZodFunctionOut>(params: {
|
|
725
|
+
input: In;
|
|
726
|
+
output: Out;
|
|
727
|
+
}): z$1.ZodFunction<z$1.ZodTuple<In, null>, Out>;
|
|
728
|
+
_function<const In extends z$1.core.$ZodFunctionIn = z$1.core.$ZodFunctionArgs>(params: {
|
|
729
|
+
input: In;
|
|
730
|
+
}): z$1.ZodFunction<In, z$1.core.$ZodFunctionOut>;
|
|
731
|
+
_function<const Out extends z$1.core.$ZodFunctionOut = z$1.core.$ZodFunctionOut>(params: {
|
|
732
|
+
output: Out;
|
|
733
|
+
}): z$1.ZodFunction<z$1.core.$ZodFunctionIn, Out>;
|
|
734
|
+
_function<In extends z$1.core.$ZodFunctionIn = z$1.core.$ZodFunctionArgs, Out extends z$1.core.$ZodType = z$1.core.$ZodType<unknown, unknown, z$1.core.$ZodTypeInternals<unknown, unknown>>>(params?: {
|
|
735
|
+
input: In;
|
|
736
|
+
output: Out;
|
|
737
|
+
}): z$1.ZodFunction<In, Out>;
|
|
738
|
+
check<O = unknown>(fn: z$1.core.CheckFn<O>): z$1.core.$ZodCheck<O>;
|
|
739
|
+
custom<O>(fn?: (data: unknown) => unknown, _params?: string | z$1.core.$ZodCustomParams | undefined): z$1.ZodCustom<O, O>;
|
|
740
|
+
refine<T>(fn: (arg: NoInfer<T>) => z$1.core.util.MaybeAsync<unknown>, _params?: string | z$1.core.$ZodCustomParams): z$1.core.$ZodCheck<T>;
|
|
741
|
+
superRefine<T>(fn: (arg: T, payload: z$1.core.$RefinementCtx<T>) => void | Promise<void>): z$1.core.$ZodCheck<T>;
|
|
742
|
+
json(params?: string | z$1.core.$ZodCustomParams): z$1.ZodJSONSchema;
|
|
743
|
+
preprocess<A, U extends z$1.core.SomeType, B = unknown>(fn: (arg: B, ctx: z$1.core.$RefinementCtx) => A, schema: U): z$1.ZodPipe<z$1.ZodTransform<A, B>, U>;
|
|
744
|
+
ZodType: z$1.core.$constructor<z$1.ZodType>;
|
|
745
|
+
_ZodString: z$1.core.$constructor<z$1._ZodString>;
|
|
746
|
+
ZodString: z$1.core.$constructor<z$1.ZodString>;
|
|
747
|
+
ZodStringFormat: z$1.core.$constructor<z$1.ZodStringFormat>;
|
|
748
|
+
ZodEmail: z$1.core.$constructor<z$1.ZodEmail>;
|
|
749
|
+
ZodGUID: z$1.core.$constructor<z$1.ZodGUID>;
|
|
750
|
+
ZodUUID: z$1.core.$constructor<z$1.ZodUUID>;
|
|
751
|
+
ZodURL: z$1.core.$constructor<z$1.ZodURL>;
|
|
752
|
+
ZodEmoji: z$1.core.$constructor<z$1.ZodEmoji>;
|
|
753
|
+
ZodNanoID: z$1.core.$constructor<z$1.ZodNanoID>;
|
|
754
|
+
ZodCUID: z$1.core.$constructor<z$1.ZodCUID>;
|
|
755
|
+
ZodCUID2: z$1.core.$constructor<z$1.ZodCUID2>;
|
|
756
|
+
ZodULID: z$1.core.$constructor<z$1.ZodULID>;
|
|
757
|
+
ZodXID: z$1.core.$constructor<z$1.ZodXID>;
|
|
758
|
+
ZodKSUID: z$1.core.$constructor<z$1.ZodKSUID>;
|
|
759
|
+
ZodIPv4: z$1.core.$constructor<z$1.ZodIPv4>;
|
|
760
|
+
ZodIPv6: z$1.core.$constructor<z$1.ZodIPv6>;
|
|
761
|
+
ZodCIDRv4: z$1.core.$constructor<z$1.ZodCIDRv4>;
|
|
762
|
+
ZodCIDRv6: z$1.core.$constructor<z$1.ZodCIDRv6>;
|
|
763
|
+
ZodBase64: z$1.core.$constructor<z$1.ZodBase64>;
|
|
764
|
+
ZodBase64URL: z$1.core.$constructor<z$1.ZodBase64URL>;
|
|
765
|
+
ZodE164: z$1.core.$constructor<z$1.ZodE164>;
|
|
766
|
+
ZodJWT: z$1.core.$constructor<z$1.ZodJWT>;
|
|
767
|
+
ZodCustomStringFormat: z$1.core.$constructor<z$1.ZodCustomStringFormat>;
|
|
768
|
+
ZodNumber: z$1.core.$constructor<z$1.ZodNumber>;
|
|
769
|
+
ZodNumberFormat: z$1.core.$constructor<z$1.ZodNumberFormat>;
|
|
770
|
+
ZodBoolean: z$1.core.$constructor<z$1.ZodBoolean>;
|
|
771
|
+
ZodBigInt: z$1.core.$constructor<z$1.ZodBigInt>;
|
|
772
|
+
ZodBigIntFormat: z$1.core.$constructor<z$1.ZodBigIntFormat>;
|
|
773
|
+
ZodSymbol: z$1.core.$constructor<z$1.ZodSymbol>;
|
|
774
|
+
ZodUndefined: z$1.core.$constructor<z$1.ZodUndefined>;
|
|
775
|
+
undefined: typeof z$1.undefined;
|
|
776
|
+
ZodNull: z$1.core.$constructor<z$1.ZodNull>;
|
|
777
|
+
null: typeof z$1.null;
|
|
778
|
+
ZodAny: z$1.core.$constructor<z$1.ZodAny>;
|
|
779
|
+
ZodUnknown: z$1.core.$constructor<z$1.ZodUnknown>;
|
|
780
|
+
ZodNever: z$1.core.$constructor<z$1.ZodNever>;
|
|
781
|
+
ZodVoid: z$1.core.$constructor<z$1.ZodVoid>;
|
|
782
|
+
void: typeof z$1.void;
|
|
783
|
+
ZodDate: z$1.core.$constructor<z$1.ZodDate>;
|
|
784
|
+
ZodArray: z$1.core.$constructor<z$1.ZodArray>;
|
|
785
|
+
ZodObject: z$1.core.$constructor<z$1.ZodObject>;
|
|
786
|
+
ZodUnion: z$1.core.$constructor<z$1.ZodUnion>;
|
|
787
|
+
ZodDiscriminatedUnion: z$1.core.$constructor<z$1.ZodDiscriminatedUnion>;
|
|
788
|
+
ZodIntersection: z$1.core.$constructor<z$1.ZodIntersection>;
|
|
789
|
+
ZodTuple: z$1.core.$constructor<z$1.ZodTuple>;
|
|
790
|
+
ZodRecord: z$1.core.$constructor<z$1.ZodRecord>;
|
|
791
|
+
ZodMap: z$1.core.$constructor<z$1.ZodMap>;
|
|
792
|
+
ZodSet: z$1.core.$constructor<z$1.ZodSet>;
|
|
793
|
+
ZodEnum: z$1.core.$constructor<z$1.ZodEnum>;
|
|
794
|
+
enum: typeof z$1.enum;
|
|
795
|
+
ZodLiteral: z$1.core.$constructor<z$1.ZodLiteral>;
|
|
796
|
+
ZodFile: z$1.core.$constructor<z$1.ZodFile>;
|
|
797
|
+
ZodTransform: z$1.core.$constructor<z$1.ZodTransform>;
|
|
798
|
+
ZodOptional: z$1.core.$constructor<z$1.ZodOptional>;
|
|
799
|
+
ZodNullable: z$1.core.$constructor<z$1.ZodNullable>;
|
|
800
|
+
ZodDefault: z$1.core.$constructor<z$1.ZodDefault>;
|
|
801
|
+
ZodPrefault: z$1.core.$constructor<z$1.ZodPrefault>;
|
|
802
|
+
ZodNonOptional: z$1.core.$constructor<z$1.ZodNonOptional>;
|
|
803
|
+
ZodSuccess: z$1.core.$constructor<z$1.ZodSuccess>;
|
|
804
|
+
ZodCatch: z$1.core.$constructor<z$1.ZodCatch>;
|
|
805
|
+
catch: typeof z$1.catch;
|
|
806
|
+
ZodNaN: z$1.core.$constructor<z$1.ZodNaN>;
|
|
807
|
+
ZodPipe: z$1.core.$constructor<z$1.ZodPipe>;
|
|
808
|
+
ZodCodec: z$1.core.$constructor<z$1.ZodCodec>;
|
|
809
|
+
ZodReadonly: z$1.core.$constructor<z$1.ZodReadonly>;
|
|
810
|
+
ZodTemplateLiteral: z$1.core.$constructor<z$1.ZodTemplateLiteral>;
|
|
811
|
+
ZodLazy: z$1.core.$constructor<z$1.ZodLazy>;
|
|
812
|
+
ZodPromise: z$1.core.$constructor<z$1.ZodPromise>;
|
|
813
|
+
ZodFunction: z$1.core.$constructor<z$1.ZodFunction>;
|
|
814
|
+
function: typeof z$1._function;
|
|
815
|
+
ZodCustom: z$1.core.$constructor<z$1.ZodCustom>;
|
|
816
|
+
instanceof: typeof z$1.instanceof;
|
|
817
|
+
stringbool: (_params?: string | z$1.core.$ZodStringBoolParams) => z$1.ZodCodec<z$1.ZodString, z$1.ZodBoolean>;
|
|
818
|
+
lt: typeof z$1.core._lt;
|
|
819
|
+
lte: typeof z$1.core._lte;
|
|
820
|
+
gt: typeof z$1.core._gt;
|
|
821
|
+
gte: typeof z$1.core._gte;
|
|
822
|
+
positive: typeof z$1.core._positive;
|
|
823
|
+
negative: typeof z$1.core._negative;
|
|
824
|
+
nonpositive: typeof z$1.core._nonpositive;
|
|
825
|
+
nonnegative: typeof z$1.core._nonnegative;
|
|
826
|
+
multipleOf: typeof z$1.core._multipleOf;
|
|
827
|
+
maxSize: typeof z$1.core._maxSize;
|
|
828
|
+
minSize: typeof z$1.core._minSize;
|
|
829
|
+
size: typeof z$1.core._size;
|
|
830
|
+
maxLength: typeof z$1.core._maxLength;
|
|
831
|
+
minLength: typeof z$1.core._minLength;
|
|
832
|
+
length: typeof z$1.core._length;
|
|
833
|
+
regex: typeof z$1.core._regex;
|
|
834
|
+
lowercase: typeof z$1.core._lowercase;
|
|
835
|
+
uppercase: typeof z$1.core._uppercase;
|
|
836
|
+
includes: typeof z$1.core._includes;
|
|
837
|
+
startsWith: typeof z$1.core._startsWith;
|
|
838
|
+
endsWith: typeof z$1.core._endsWith;
|
|
839
|
+
property: typeof z$1.core._property;
|
|
840
|
+
mime: typeof z$1.core._mime;
|
|
841
|
+
overwrite: typeof z$1.core._overwrite;
|
|
842
|
+
normalize: typeof z$1.core._normalize;
|
|
843
|
+
trim: typeof z$1.core._trim;
|
|
844
|
+
toLowerCase: typeof z$1.core._toLowerCase;
|
|
845
|
+
toUpperCase: typeof z$1.core._toUpperCase;
|
|
846
|
+
ZodError: z$1.core.$constructor<z$1.ZodError>;
|
|
847
|
+
ZodRealError: z$1.core.$constructor<z$1.ZodError>;
|
|
848
|
+
parse: <T extends z$1.core.$ZodType>(schema: T, value: unknown, _ctx?: z$1.core.ParseContext<z$1.core.$ZodIssue>, _params?: {
|
|
849
|
+
callee?: z$1.core.util.AnyFunc;
|
|
850
|
+
Err?: z$1.core.$ZodErrorClass;
|
|
851
|
+
}) => z$1.core.output<T>;
|
|
852
|
+
parseAsync: <T extends z$1.core.$ZodType>(schema: T, value: unknown, _ctx?: z$1.core.ParseContext<z$1.core.$ZodIssue>, _params?: {
|
|
853
|
+
callee?: z$1.core.util.AnyFunc;
|
|
854
|
+
Err?: z$1.core.$ZodErrorClass;
|
|
855
|
+
}) => Promise<z$1.core.output<T>>;
|
|
856
|
+
safeParse: <T extends z$1.core.$ZodType>(schema: T, value: unknown, _ctx?: z$1.core.ParseContext<z$1.core.$ZodIssue>) => z$1.ZodSafeParseResult<z$1.core.output<T>>;
|
|
857
|
+
safeParseAsync: <T extends z$1.core.$ZodType>(schema: T, value: unknown, _ctx?: z$1.core.ParseContext<z$1.core.$ZodIssue>) => Promise<z$1.ZodSafeParseResult<z$1.core.output<T>>>;
|
|
858
|
+
encode: <T extends z$1.core.$ZodType>(schema: T, value: z$1.core.output<T>, _ctx?: z$1.core.ParseContext<z$1.core.$ZodIssue>) => z$1.core.input<T>;
|
|
859
|
+
decode: <T extends z$1.core.$ZodType>(schema: T, value: z$1.core.input<T>, _ctx?: z$1.core.ParseContext<z$1.core.$ZodIssue>) => z$1.core.output<T>;
|
|
860
|
+
encodeAsync: <T extends z$1.core.$ZodType>(schema: T, value: z$1.core.output<T>, _ctx?: z$1.core.ParseContext<z$1.core.$ZodIssue>) => Promise<z$1.core.input<T>>;
|
|
861
|
+
decodeAsync: <T extends z$1.core.$ZodType>(schema: T, value: z$1.core.input<T>, _ctx?: z$1.core.ParseContext<z$1.core.$ZodIssue>) => Promise<z$1.core.output<T>>;
|
|
862
|
+
safeEncode: <T extends z$1.core.$ZodType>(schema: T, value: z$1.core.output<T>, _ctx?: z$1.core.ParseContext<z$1.core.$ZodIssue>) => z$1.ZodSafeParseResult<z$1.core.input<T>>;
|
|
863
|
+
safeDecode: <T extends z$1.core.$ZodType>(schema: T, value: z$1.core.input<T>, _ctx?: z$1.core.ParseContext<z$1.core.$ZodIssue>) => z$1.ZodSafeParseResult<z$1.core.output<T>>;
|
|
864
|
+
safeEncodeAsync: <T extends z$1.core.$ZodType>(schema: T, value: z$1.core.output<T>, _ctx?: z$1.core.ParseContext<z$1.core.$ZodIssue>) => Promise<z$1.ZodSafeParseResult<z$1.core.input<T>>>;
|
|
865
|
+
safeDecodeAsync: <T extends z$1.core.$ZodType>(schema: T, value: z$1.core.input<T>, _ctx?: z$1.core.ParseContext<z$1.core.$ZodIssue>) => Promise<z$1.ZodSafeParseResult<z$1.core.output<T>>>;
|
|
866
|
+
setErrorMap(map: z$1.core.$ZodErrorMap): void;
|
|
867
|
+
getErrorMap(): z$1.core.$ZodErrorMap<z$1.core.$ZodIssue> | undefined;
|
|
868
|
+
ZodIssueCode: {
|
|
869
|
+
readonly invalid_type: "invalid_type";
|
|
870
|
+
readonly too_big: "too_big";
|
|
871
|
+
readonly too_small: "too_small";
|
|
872
|
+
readonly invalid_format: "invalid_format";
|
|
873
|
+
readonly not_multiple_of: "not_multiple_of";
|
|
874
|
+
readonly unrecognized_keys: "unrecognized_keys";
|
|
875
|
+
readonly invalid_union: "invalid_union";
|
|
876
|
+
readonly invalid_key: "invalid_key";
|
|
877
|
+
readonly invalid_element: "invalid_element";
|
|
878
|
+
readonly invalid_value: "invalid_value";
|
|
879
|
+
readonly custom: "custom";
|
|
880
|
+
};
|
|
881
|
+
ZodFirstPartyTypeKind: typeof z$1.ZodFirstPartyTypeKind;
|
|
882
|
+
};
|
|
883
|
+
type SchemaBuilder = typeof zod;
|
|
884
|
+
type SchemaFunction<T> = (schema: SchemaBuilder) => T;
|
|
885
|
+
type Output<T> = T extends z$1.ZodType ? z$1.infer<T> : T;
|
|
886
|
+
type ZodTypeOrRecord = z$1.ZodType | Record<string, unknown>;
|
|
887
|
+
|
|
398
888
|
interface BaseExecutionParams {
|
|
399
889
|
/**
|
|
400
890
|
* The version ID of the canvas to use for this chat completion.
|
|
@@ -471,6 +961,99 @@ interface BaseExecutionParams {
|
|
|
471
961
|
*/
|
|
472
962
|
tags?: string[];
|
|
473
963
|
}
|
|
964
|
+
|
|
965
|
+
/**
|
|
966
|
+
* Helper type to add request ID to a response type.
|
|
967
|
+
*
|
|
968
|
+
* The `requestId` field contains the value from the `x-request-id` HTTP header
|
|
969
|
+
* returned by the API for that specific request.
|
|
970
|
+
*
|
|
971
|
+
* @template T - The base response type.
|
|
972
|
+
*/
|
|
973
|
+
type WithRequestId<T> = T & {
|
|
974
|
+
requestId?: string;
|
|
975
|
+
};
|
|
976
|
+
|
|
977
|
+
declare const TaskStatus: z$1.ZodEnum<{
|
|
978
|
+
created: "created";
|
|
979
|
+
failed: "failed";
|
|
980
|
+
running: "running";
|
|
981
|
+
validating: "validating";
|
|
982
|
+
completed: "completed";
|
|
983
|
+
cancelled: "cancelled";
|
|
984
|
+
}>;
|
|
985
|
+
type TaskStatus = z$1.infer<typeof TaskStatus>;
|
|
986
|
+
declare const TaskDefinition: z$1.ZodObject<{
|
|
987
|
+
id: z$1.ZodString;
|
|
988
|
+
reference: z$1.ZodNumber;
|
|
989
|
+
name: z$1.ZodString;
|
|
990
|
+
status: z$1.ZodEnum<{
|
|
991
|
+
created: "created";
|
|
992
|
+
failed: "failed";
|
|
993
|
+
running: "running";
|
|
994
|
+
validating: "validating";
|
|
995
|
+
completed: "completed";
|
|
996
|
+
cancelled: "cancelled";
|
|
997
|
+
}>;
|
|
998
|
+
rawInput: z$1.ZodObject<{
|
|
999
|
+
async: z$1.ZodBoolean;
|
|
1000
|
+
stream: z$1.ZodBoolean;
|
|
1001
|
+
variables: z$1.ZodRecord<z$1.ZodString, z$1.ZodUnknown>;
|
|
1002
|
+
applicationId: z$1.ZodString;
|
|
1003
|
+
}, z$1.core.$strip>;
|
|
1004
|
+
inputContent: z$1.ZodAny;
|
|
1005
|
+
outputContent: z$1.ZodObject<{
|
|
1006
|
+
role: z$1.ZodLiteral<"assistant">;
|
|
1007
|
+
content: z$1.ZodUnknown;
|
|
1008
|
+
toolCalls: z$1.ZodArray<z$1.ZodAny>;
|
|
1009
|
+
functionCall: z$1.ZodAny;
|
|
1010
|
+
}, z$1.core.$strip>;
|
|
1011
|
+
originalOutputContent: z$1.ZodObject<{
|
|
1012
|
+
role: z$1.ZodLiteral<"assistant">;
|
|
1013
|
+
content: z$1.ZodUnknown;
|
|
1014
|
+
toolCalls: z$1.ZodArray<z$1.ZodAny>;
|
|
1015
|
+
functionCall: z$1.ZodAny;
|
|
1016
|
+
}, z$1.core.$strip>;
|
|
1017
|
+
createdBy: z$1.ZodString;
|
|
1018
|
+
approvedBy: z$1.ZodAny;
|
|
1019
|
+
approvedAt: z$1.ZodAny;
|
|
1020
|
+
completionRunId: z$1.ZodString;
|
|
1021
|
+
workflowRunId: z$1.ZodAny;
|
|
1022
|
+
promptVersionId: z$1.ZodString;
|
|
1023
|
+
promptApplicationId: z$1.ZodString;
|
|
1024
|
+
workspaceId: z$1.ZodString;
|
|
1025
|
+
metadata: z$1.ZodAny;
|
|
1026
|
+
tags: z$1.ZodArray<z$1.ZodString>;
|
|
1027
|
+
createdAt: z$1.ZodString;
|
|
1028
|
+
updatedAt: z$1.ZodString;
|
|
1029
|
+
deletedAt: z$1.ZodAny;
|
|
1030
|
+
requestId: z$1.ZodString;
|
|
1031
|
+
}, z$1.core.$strip>;
|
|
1032
|
+
type TaskDefinition<TOutput = unknown> = Omit<z$1.infer<typeof TaskDefinition>, 'outputContent' | 'originalOutputContent'> & {
|
|
1033
|
+
outputContent: {
|
|
1034
|
+
role: 'assistant';
|
|
1035
|
+
content: TOutput;
|
|
1036
|
+
toolCalls: Array<any>;
|
|
1037
|
+
functionCall: any;
|
|
1038
|
+
};
|
|
1039
|
+
originalOutputContent: {
|
|
1040
|
+
role: 'assistant';
|
|
1041
|
+
content: TOutput;
|
|
1042
|
+
toolCalls: Array<any>;
|
|
1043
|
+
functionCall: any;
|
|
1044
|
+
};
|
|
1045
|
+
};
|
|
1046
|
+
|
|
1047
|
+
/**
|
|
1048
|
+
* Canvas execution module for managing canvas execution lifecycle and modes.
|
|
1049
|
+
*
|
|
1050
|
+
* This module handles the execution of canvas templates with support for
|
|
1051
|
+
* synchronous, asynchronous (with polling), and streaming modes. It also
|
|
1052
|
+
* manages file uploads and result validation.
|
|
1053
|
+
*
|
|
1054
|
+
* @module Resources
|
|
1055
|
+
*/
|
|
1056
|
+
|
|
474
1057
|
/**
|
|
475
1058
|
* Configuration for asynchronous canvas execution with polling.
|
|
476
1059
|
* The execution starts immediately but results must be retrieved via polling.
|
|
@@ -486,15 +1069,15 @@ interface AsyncExecutionParams extends BaseExecutionParams {
|
|
|
486
1069
|
*/
|
|
487
1070
|
webhookUrl?: string;
|
|
488
1071
|
/**
|
|
489
|
-
* Time in milliseconds between polling attempts.
|
|
1072
|
+
* Time (in milliseconds if number) between polling attempts (e.g. "1s", "1m", "1h", "1d").
|
|
490
1073
|
* @default 1000
|
|
491
1074
|
*/
|
|
492
|
-
pollingInterval?: number;
|
|
1075
|
+
pollingInterval?: string | number;
|
|
493
1076
|
/**
|
|
494
|
-
* Maximum time in milliseconds to wait for completion before timing out.
|
|
1077
|
+
* Maximum time (in milliseconds if number) to wait for completion before timing out (e.g. "1s", "1m", "1h", "1d").
|
|
495
1078
|
* @default 60000
|
|
496
1079
|
*/
|
|
497
|
-
pollingTimeout?: number;
|
|
1080
|
+
pollingTimeout?: string | number;
|
|
498
1081
|
/**
|
|
499
1082
|
* Stream mode is not available for async executions.
|
|
500
1083
|
*/
|
|
@@ -556,19 +1139,13 @@ type AsyncCompletionCreateResult = {
|
|
|
556
1139
|
inputContent: {
|
|
557
1140
|
files: Array<any>;
|
|
558
1141
|
messages: Array<any>;
|
|
559
|
-
variables:
|
|
560
|
-
body: string;
|
|
561
|
-
title: string;
|
|
562
|
-
};
|
|
1142
|
+
variables: Record<string, unknown>;
|
|
563
1143
|
};
|
|
564
1144
|
outputContent: null;
|
|
565
1145
|
rawInput: {
|
|
566
1146
|
async: boolean;
|
|
567
1147
|
canvas_id: string;
|
|
568
|
-
variables:
|
|
569
|
-
body: string;
|
|
570
|
-
title: string;
|
|
571
|
-
};
|
|
1148
|
+
variables: Record<string, unknown>;
|
|
572
1149
|
};
|
|
573
1150
|
rawOutput: any;
|
|
574
1151
|
compatibilityDate: string;
|
|
@@ -615,51 +1192,11 @@ type AsyncCompletionCreateResult = {
|
|
|
615
1192
|
updatedAt: string;
|
|
616
1193
|
deletedAt: any;
|
|
617
1194
|
};
|
|
618
|
-
type TaskCreationResult = {
|
|
619
|
-
id: string;
|
|
620
|
-
reference: number;
|
|
621
|
-
name: string;
|
|
622
|
-
status: ExecutionStatus;
|
|
623
|
-
rawInput: {
|
|
624
|
-
async: boolean;
|
|
625
|
-
stream: boolean;
|
|
626
|
-
variables: Record<string, unknown>;
|
|
627
|
-
applicationId: string;
|
|
628
|
-
};
|
|
629
|
-
inputContent: any;
|
|
630
|
-
outputContent: any;
|
|
631
|
-
originalOutputContent: any;
|
|
632
|
-
createdBy: string;
|
|
633
|
-
approvedBy: any;
|
|
634
|
-
approvedAt: any;
|
|
635
|
-
completionRunId: string;
|
|
636
|
-
workflowRunId: any;
|
|
637
|
-
promptVersionId: string;
|
|
638
|
-
promptApplicationId: string;
|
|
639
|
-
workspaceId: string;
|
|
640
|
-
metadata: any;
|
|
641
|
-
tags: Array<string>;
|
|
642
|
-
createdAt: string;
|
|
643
|
-
updatedAt: string;
|
|
644
|
-
deletedAt: any;
|
|
645
|
-
requestId: string;
|
|
646
|
-
};
|
|
647
1195
|
/**
|
|
648
1196
|
* Raw API response type. Represents the unprocessed response from the Tela API.
|
|
649
1197
|
* This type will be refined in future versions with proper typing.
|
|
650
1198
|
*/
|
|
651
1199
|
type RawAPIResult = any;
|
|
652
|
-
/**
|
|
653
|
-
* Helper type to add request ID to a response type.
|
|
654
|
-
*
|
|
655
|
-
* The `requestId` field contains the value from the `x-request-id` HTTP header
|
|
656
|
-
* returned by the API for that specific request.
|
|
657
|
-
*
|
|
658
|
-
* @template T - The base response type.
|
|
659
|
-
*/
|
|
660
|
-
type WithRequestId<T> = T & {
|
|
661
|
-
requestId?: string;
|
|
662
|
-
};
|
|
663
1200
|
/**
|
|
664
1201
|
* Result returned when polling for asynchronous execution status.
|
|
665
1202
|
*
|
|
@@ -793,7 +1330,7 @@ declare class CanvasExecution<TParams extends ExecutionParams = SyncExecutionPar
|
|
|
793
1330
|
* @param outputSchema - Zod schema or object schema for validating/parsing output.
|
|
794
1331
|
* @param client - HTTP client instance for making API requests.
|
|
795
1332
|
*/
|
|
796
|
-
constructor(variables: TInput, params: TParams | undefined, outputSchema:
|
|
1333
|
+
constructor(variables: TInput, params: TParams | undefined, outputSchema: z.ZodType | Record<string, unknown>, client: BaseClient, isTask?: boolean);
|
|
797
1334
|
/**
|
|
798
1335
|
* Fetches an existing asynchronous execution by its ID.
|
|
799
1336
|
*
|
|
@@ -822,9 +1359,9 @@ declare class CanvasExecution<TParams extends ExecutionParams = SyncExecutionPar
|
|
|
822
1359
|
* console.log(execution.status) // 'running' or 'succeeded' or 'failed'
|
|
823
1360
|
* ```
|
|
824
1361
|
*/
|
|
825
|
-
static fetch<TOutput = unknown>(id: string, outputSchema:
|
|
826
|
-
pollingInterval?: number;
|
|
827
|
-
pollingTimeout?: number;
|
|
1362
|
+
static fetch<TOutput = unknown>(id: string, outputSchema: z.ZodType | Record<string, unknown>, client: BaseClient, options?: {
|
|
1363
|
+
pollingInterval?: string | number;
|
|
1364
|
+
pollingTimeout?: string | number;
|
|
828
1365
|
isTask?: boolean;
|
|
829
1366
|
}): Promise<CanvasExecution<AsyncExecutionParams, unknown, TOutput>>;
|
|
830
1367
|
/**
|
|
@@ -947,7 +1484,7 @@ declare class CanvasExecution<TParams extends ExecutionParams = SyncExecutionPar
|
|
|
947
1484
|
*
|
|
948
1485
|
* @returns The task creation result or undefined.
|
|
949
1486
|
*/
|
|
950
|
-
get task():
|
|
1487
|
+
get task(): TaskDefinition | undefined;
|
|
951
1488
|
/**
|
|
952
1489
|
* Gets the raw API response without any processing or validation.
|
|
953
1490
|
* Automatically starts execution and waits for completion (including polling for async executions).
|
|
@@ -974,7 +1511,58 @@ declare class CanvasExecution<TParams extends ExecutionParams = SyncExecutionPar
|
|
|
974
1511
|
*/
|
|
975
1512
|
start(): Promise<CanvasExecutionResult<TParams, TOutput> | AsyncGenerator<Partial<TOutput>, any, any> | (AsyncCompletionCreateResult & {
|
|
976
1513
|
requestId?: string;
|
|
977
|
-
}) | (
|
|
1514
|
+
}) | (Omit<{
|
|
1515
|
+
id: string;
|
|
1516
|
+
reference: number;
|
|
1517
|
+
name: string;
|
|
1518
|
+
status: "created" | "failed" | "running" | "validating" | "completed" | "cancelled";
|
|
1519
|
+
rawInput: {
|
|
1520
|
+
async: boolean;
|
|
1521
|
+
stream: boolean;
|
|
1522
|
+
variables: Record<string, unknown>;
|
|
1523
|
+
applicationId: string;
|
|
1524
|
+
};
|
|
1525
|
+
inputContent: any;
|
|
1526
|
+
outputContent: {
|
|
1527
|
+
role: "assistant";
|
|
1528
|
+
content: unknown;
|
|
1529
|
+
toolCalls: any[];
|
|
1530
|
+
functionCall: any;
|
|
1531
|
+
};
|
|
1532
|
+
originalOutputContent: {
|
|
1533
|
+
role: "assistant";
|
|
1534
|
+
content: unknown;
|
|
1535
|
+
toolCalls: any[];
|
|
1536
|
+
functionCall: any;
|
|
1537
|
+
};
|
|
1538
|
+
createdBy: string;
|
|
1539
|
+
approvedBy: any;
|
|
1540
|
+
approvedAt: any;
|
|
1541
|
+
completionRunId: string;
|
|
1542
|
+
workflowRunId: any;
|
|
1543
|
+
promptVersionId: string;
|
|
1544
|
+
promptApplicationId: string;
|
|
1545
|
+
workspaceId: string;
|
|
1546
|
+
metadata: any;
|
|
1547
|
+
tags: string[];
|
|
1548
|
+
createdAt: string;
|
|
1549
|
+
updatedAt: string;
|
|
1550
|
+
deletedAt: any;
|
|
1551
|
+
requestId: string;
|
|
1552
|
+
}, "outputContent" | "originalOutputContent"> & {
|
|
1553
|
+
outputContent: {
|
|
1554
|
+
role: "assistant";
|
|
1555
|
+
content: unknown;
|
|
1556
|
+
toolCalls: Array<any>;
|
|
1557
|
+
functionCall: any;
|
|
1558
|
+
};
|
|
1559
|
+
originalOutputContent: {
|
|
1560
|
+
role: "assistant";
|
|
1561
|
+
content: unknown;
|
|
1562
|
+
toolCalls: Array<any>;
|
|
1563
|
+
functionCall: any;
|
|
1564
|
+
};
|
|
1565
|
+
} & {
|
|
978
1566
|
requestId?: string;
|
|
979
1567
|
})>;
|
|
980
1568
|
/**
|
|
@@ -1124,468 +1712,1717 @@ declare class CanvasExecution<TParams extends ExecutionParams = SyncExecutionPar
|
|
|
1124
1712
|
private uploadFiles;
|
|
1125
1713
|
}
|
|
1126
1714
|
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1715
|
+
type CompletionRunResult<TOutput> = {
|
|
1716
|
+
id: string;
|
|
1717
|
+
status: string;
|
|
1718
|
+
inputContent: {
|
|
1719
|
+
files: Array<any>;
|
|
1720
|
+
messages: Array<any>;
|
|
1721
|
+
variables: Record<string, unknown>;
|
|
1722
|
+
};
|
|
1723
|
+
outputContent: {
|
|
1724
|
+
role: string;
|
|
1725
|
+
content: TOutput;
|
|
1726
|
+
toolCalls: Array<any>;
|
|
1727
|
+
functionCall: any;
|
|
1728
|
+
};
|
|
1729
|
+
rawInput: {
|
|
1730
|
+
tags: Array<string>;
|
|
1731
|
+
async: boolean;
|
|
1732
|
+
canvasId: string;
|
|
1733
|
+
variables: Record<string, unknown>;
|
|
1734
|
+
};
|
|
1735
|
+
rawOutput: {
|
|
1736
|
+
id: string;
|
|
1737
|
+
usage: {
|
|
1738
|
+
cost: {
|
|
1739
|
+
totalCost: number;
|
|
1740
|
+
promptCost: number;
|
|
1741
|
+
completionCost: number;
|
|
1742
|
+
};
|
|
1743
|
+
totalTokens: number;
|
|
1744
|
+
promptTokens: number;
|
|
1745
|
+
completionTokens: number;
|
|
1746
|
+
};
|
|
1747
|
+
object: string;
|
|
1748
|
+
choices: Array<{
|
|
1749
|
+
message: {
|
|
1750
|
+
role: string;
|
|
1751
|
+
content: TOutput;
|
|
1752
|
+
toolCalls: Array<any>;
|
|
1753
|
+
functionCall: any;
|
|
1754
|
+
};
|
|
1755
|
+
}>;
|
|
1756
|
+
created: number;
|
|
1757
|
+
};
|
|
1758
|
+
compatibilityDate: string;
|
|
1759
|
+
metadata: {
|
|
1760
|
+
promptVersion: {
|
|
1761
|
+
modelConfigurations: {
|
|
1762
|
+
type: string;
|
|
1763
|
+
model: string;
|
|
1764
|
+
temperature: number;
|
|
1765
|
+
structuredOutput: {
|
|
1766
|
+
schema: {
|
|
1767
|
+
type: string;
|
|
1768
|
+
title: string;
|
|
1769
|
+
required: Array<string>;
|
|
1770
|
+
properties: Record<string, unknown>;
|
|
1771
|
+
description: string;
|
|
1772
|
+
};
|
|
1773
|
+
enabled: boolean;
|
|
1774
|
+
};
|
|
1775
|
+
};
|
|
1776
|
+
variablesDefinitions: Array<{
|
|
1777
|
+
name: string;
|
|
1778
|
+
type: string;
|
|
1779
|
+
required: boolean;
|
|
1780
|
+
processingOptions: {
|
|
1781
|
+
allowMultimodal: boolean;
|
|
1782
|
+
};
|
|
1783
|
+
}>;
|
|
1784
|
+
};
|
|
1785
|
+
};
|
|
1786
|
+
tags: Array<string>;
|
|
1787
|
+
creditsUsed: number;
|
|
1788
|
+
promptId: string;
|
|
1789
|
+
promptVersionId: string;
|
|
1790
|
+
promptApplicationId: any;
|
|
1791
|
+
workspaceId: string;
|
|
1792
|
+
createdAt: string;
|
|
1793
|
+
updatedAt: string;
|
|
1794
|
+
deletedAt: any;
|
|
1795
|
+
};
|
|
1796
|
+
|
|
1797
|
+
/**
|
|
1798
|
+
* Helper type for accepting either a single value or an array of values.
|
|
1799
|
+
*
|
|
1800
|
+
* @template T - The base type.
|
|
1801
|
+
*/
|
|
1802
|
+
type MaybeArray<T> = T | T[];
|
|
1803
|
+
/**
|
|
1804
|
+
* Canvas identification methods for batch operations.
|
|
1805
|
+
* Use either canvas ID with optional version, or application ID.
|
|
1806
|
+
*/
|
|
1807
|
+
type CanvasIdentifier = {
|
|
1808
|
+
id: string;
|
|
1809
|
+
versionId?: string;
|
|
1810
|
+
} | {
|
|
1811
|
+
applicationId: string;
|
|
1812
|
+
};
|
|
1813
|
+
/**
|
|
1814
|
+
* Status of a batch execution.
|
|
1815
|
+
*
|
|
1816
|
+
* Lifecycle progression:
|
|
1817
|
+
* - `created` - Batch queued on server (initial state)
|
|
1818
|
+
* - `validating` - Input file validation in progress
|
|
1819
|
+
* - `running` - Batch actively processing executions
|
|
1820
|
+
* - `completed` - All executions finished successfully
|
|
1821
|
+
* - `failed` - Batch failed (validation error or server failure)
|
|
1822
|
+
* - `canceled` - Batch canceled by user
|
|
1823
|
+
*
|
|
1824
|
+
* @see {@link BatchExecution.status} for accessing current status
|
|
1825
|
+
*/
|
|
1826
|
+
type BatchExecutionStatus = 'created' | 'validating' | 'running' | 'failed' | 'completed' | 'canceled';
|
|
1827
|
+
/**
|
|
1828
|
+
* Raw API response for batch execution operations.
|
|
1829
|
+
* Contains batch metadata, status, and progress information.
|
|
1830
|
+
*/
|
|
1831
|
+
type BatchResponse = {
|
|
1832
|
+
/**
|
|
1833
|
+
* The type of batch task (always 'async-completion').
|
|
1147
1834
|
*/
|
|
1148
|
-
|
|
1835
|
+
task: string;
|
|
1149
1836
|
/**
|
|
1150
|
-
*
|
|
1837
|
+
* Vault URL of the input JSONL file.
|
|
1151
1838
|
*/
|
|
1152
|
-
|
|
1839
|
+
inputFile: string;
|
|
1153
1840
|
/**
|
|
1154
|
-
*
|
|
1841
|
+
* Webhook URL for completion notifications, if configured.
|
|
1155
1842
|
*/
|
|
1156
|
-
|
|
1843
|
+
webhookUrl: string | null;
|
|
1157
1844
|
/**
|
|
1158
|
-
*
|
|
1845
|
+
* Current status of the batch execution.
|
|
1159
1846
|
*/
|
|
1160
|
-
|
|
1847
|
+
status: BatchExecutionStatus;
|
|
1848
|
+
/**
|
|
1849
|
+
* Unique identifier for this batch execution.
|
|
1850
|
+
*/
|
|
1851
|
+
id: string;
|
|
1852
|
+
/**
|
|
1853
|
+
* Vault URL of the output JSONL file, available when completed.
|
|
1854
|
+
*/
|
|
1855
|
+
outputFile: string | null;
|
|
1856
|
+
/**
|
|
1857
|
+
* Progress statistics, available when running or completed.
|
|
1858
|
+
*/
|
|
1859
|
+
state: {
|
|
1161
1860
|
/**
|
|
1162
|
-
*
|
|
1861
|
+
* Number of failed executions.
|
|
1163
1862
|
*/
|
|
1164
|
-
|
|
1165
|
-
|
|
1863
|
+
failed: number;
|
|
1864
|
+
/**
|
|
1865
|
+
* Number of completed executions.
|
|
1866
|
+
*/
|
|
1867
|
+
completed: number;
|
|
1868
|
+
/**
|
|
1869
|
+
* Total number of executions in the batch.
|
|
1870
|
+
*/
|
|
1871
|
+
total: number;
|
|
1872
|
+
} | null;
|
|
1873
|
+
/**
|
|
1874
|
+
* ISO timestamp when the batch was created.
|
|
1875
|
+
*/
|
|
1876
|
+
createdAt: string;
|
|
1877
|
+
/**
|
|
1878
|
+
* ISO timestamp when the batch was last updated.
|
|
1879
|
+
*/
|
|
1880
|
+
updatedAt: string;
|
|
1881
|
+
/**
|
|
1882
|
+
* ISO timestamp when the batch completed, if applicable.
|
|
1883
|
+
*/
|
|
1884
|
+
completedAt: string | null;
|
|
1885
|
+
/**
|
|
1886
|
+
* ISO timestamp when the batch was canceled, if applicable.
|
|
1887
|
+
*/
|
|
1888
|
+
canceledAt: string | null;
|
|
1889
|
+
/**
|
|
1890
|
+
* ISO timestamp when the batch failed, if applicable.
|
|
1891
|
+
*/
|
|
1892
|
+
failedAt: string | null;
|
|
1166
1893
|
};
|
|
1167
|
-
|
|
1894
|
+
/**
|
|
1895
|
+
* Represents a single item to be executed in a batch.
|
|
1896
|
+
*
|
|
1897
|
+
* @template TInput - The input variables type for the canvas.
|
|
1898
|
+
*/
|
|
1899
|
+
interface BatchItem<TInput> {
|
|
1168
1900
|
/**
|
|
1169
|
-
*
|
|
1901
|
+
* Optional unique identifier for this execution.
|
|
1902
|
+
* If not provided, a random UUID will be generated automatically.
|
|
1903
|
+
* Used to retrieve individual results from the batch output.
|
|
1170
1904
|
*/
|
|
1171
|
-
|
|
1905
|
+
referenceId?: string;
|
|
1172
1906
|
/**
|
|
1173
|
-
*
|
|
1907
|
+
* Input variables for this execution, matching the canvas input schema.
|
|
1174
1908
|
*/
|
|
1175
|
-
|
|
1909
|
+
variables: TInput;
|
|
1910
|
+
}
|
|
1911
|
+
/**
|
|
1912
|
+
* Parameters excluded from batch execution (managed internally).
|
|
1913
|
+
*/
|
|
1914
|
+
type ExcludedParams = 'versionId' | 'canvasId' | 'applicationId' | 'async' | 'stream' | 'webhookUrl' | 'skipResultValidation';
|
|
1915
|
+
/**
|
|
1916
|
+
* Configuration options for batch execution.
|
|
1917
|
+
*
|
|
1918
|
+
* Batch executions are always asynchronous and return results via output file.
|
|
1919
|
+
* Unlike single executions, batches do not support streaming or synchronous modes.
|
|
1920
|
+
*
|
|
1921
|
+
* @category Canvas
|
|
1922
|
+
*/
|
|
1923
|
+
interface BatchParams extends Omit<BaseExecutionParams, ExcludedParams> {
|
|
1176
1924
|
/**
|
|
1177
|
-
*
|
|
1925
|
+
* Time (in milliseconds if number) between polling attempts (e.g. "1s", "1m", "1h", "1d").
|
|
1926
|
+
* Controls how frequently the SDK checks batch completion status.
|
|
1927
|
+
* @default "1s"
|
|
1178
1928
|
*/
|
|
1179
|
-
|
|
1929
|
+
pollingInterval?: string | number;
|
|
1180
1930
|
/**
|
|
1181
|
-
*
|
|
1931
|
+
* Maximum time (in milliseconds if number) to wait for completion before timing out (e.g. "1s", "1m", "1h", "1d").
|
|
1932
|
+
* After timeout, polling stops but the batch continues processing on the server.
|
|
1933
|
+
* @default "1m"
|
|
1182
1934
|
*/
|
|
1183
|
-
|
|
1935
|
+
pollingTimeout?: string | number;
|
|
1184
1936
|
/**
|
|
1185
|
-
*
|
|
1937
|
+
* Optional webhook URL to receive completion notifications.
|
|
1938
|
+
* The server will POST to this URL when the batch completes, fails, or is canceled.
|
|
1186
1939
|
*/
|
|
1187
|
-
|
|
1940
|
+
webhookUrl?: string;
|
|
1941
|
+
}
|
|
1942
|
+
/**
|
|
1943
|
+
* Promise-like wrapper for batch execution that provides direct result access.
|
|
1944
|
+
*
|
|
1945
|
+
* Enables flexible usage patterns:
|
|
1946
|
+
* - Await for execution object: `const exec = await batch.execute()`
|
|
1947
|
+
* - Direct result access: `const result = await batch.execute().result`
|
|
1948
|
+
*
|
|
1949
|
+
* @template TOutput - The output type for batch results.
|
|
1950
|
+
*
|
|
1951
|
+
* @category Canvas
|
|
1952
|
+
*/
|
|
1953
|
+
type BatchExecutionPromiseLike<TOutput> = PromiseLike<BatchExecution<TOutput>> & {
|
|
1188
1954
|
/**
|
|
1189
|
-
*
|
|
1955
|
+
* Direct access to the batch result, automatically starting polling.
|
|
1190
1956
|
*/
|
|
1191
|
-
|
|
1957
|
+
result: Promise<BatchExecutionResult<TOutput>>;
|
|
1958
|
+
};
|
|
1959
|
+
/**
|
|
1960
|
+
* Wraps the completed batch execution response with convenient result access methods.
|
|
1961
|
+
*
|
|
1962
|
+
* Provides multiple ways to access batch results:
|
|
1963
|
+
* - Download entire output file: `downloadOutputFile()`
|
|
1964
|
+
* - Stream results incrementally: `iterateResults()`
|
|
1965
|
+
* - Get all results as array: `getResults()`
|
|
1966
|
+
* - Fetch individual result by reference ID: `getResult(referenceId)`
|
|
1967
|
+
*
|
|
1968
|
+
* @category Canvas
|
|
1969
|
+
*
|
|
1970
|
+
* @template TOutput - The output type for individual results.
|
|
1971
|
+
*
|
|
1972
|
+
* @example
|
|
1973
|
+
* ```typescript
|
|
1974
|
+
* const execution = await batch.execute()
|
|
1975
|
+
* const result = await execution.result
|
|
1976
|
+
*
|
|
1977
|
+
* // Access batch metadata
|
|
1978
|
+
* console.log(`Status: ${result.status}`)
|
|
1979
|
+
* console.log(`Progress: ${result.state.completed}/${result.state.total}`)
|
|
1980
|
+
*
|
|
1981
|
+
* // Iterate through results
|
|
1982
|
+
* for await (const item of result.iterateResults()) {
|
|
1983
|
+
* console.log(item)
|
|
1984
|
+
* }
|
|
1985
|
+
* ```
|
|
1986
|
+
*/
|
|
1987
|
+
declare class BatchExecutionResult<TOutput> {
|
|
1988
|
+
private readonly _client;
|
|
1989
|
+
private readonly _response;
|
|
1192
1990
|
/**
|
|
1193
|
-
*
|
|
1991
|
+
* Creates a new batch execution result wrapper.
|
|
1992
|
+
*
|
|
1993
|
+
* @param client - HTTP client for making API requests.
|
|
1994
|
+
* @param response - Raw batch execution response from the server.
|
|
1995
|
+
* @internal
|
|
1996
|
+
*/
|
|
1997
|
+
constructor(client: BaseClient, response: WithRequestId<BatchResponse>);
|
|
1998
|
+
get requestId(): string | undefined;
|
|
1999
|
+
/**
|
|
2000
|
+
* Gets the unique identifier for this batch execution.
|
|
2001
|
+
*
|
|
2002
|
+
* @returns The batch execution ID.
|
|
2003
|
+
*/
|
|
2004
|
+
get id(): string;
|
|
2005
|
+
/**
|
|
2006
|
+
* Gets the current status of the batch execution.
|
|
2007
|
+
*
|
|
2008
|
+
* @returns The batch status.
|
|
2009
|
+
*/
|
|
2010
|
+
get status(): BatchExecutionStatus;
|
|
2011
|
+
/**
|
|
2012
|
+
* Gets the progress statistics for this batch.
|
|
2013
|
+
*
|
|
2014
|
+
* @returns Object containing completed, failed, and total execution counts, or null if not available.
|
|
2015
|
+
*/
|
|
2016
|
+
get state(): {
|
|
2017
|
+
/**
|
|
2018
|
+
* Number of failed executions.
|
|
2019
|
+
*/
|
|
2020
|
+
failed: number;
|
|
2021
|
+
/**
|
|
2022
|
+
* Number of completed executions.
|
|
2023
|
+
*/
|
|
2024
|
+
completed: number;
|
|
2025
|
+
/**
|
|
2026
|
+
* Total number of executions in the batch.
|
|
2027
|
+
*/
|
|
2028
|
+
total: number;
|
|
2029
|
+
} | null;
|
|
2030
|
+
/**
|
|
2031
|
+
* Gets the vault URL of the output JSONL file containing all results.
|
|
2032
|
+
*
|
|
2033
|
+
* @returns The output file URL, or null if batch is not completed.
|
|
2034
|
+
*/
|
|
2035
|
+
get outputFile(): string | null;
|
|
2036
|
+
/**
|
|
2037
|
+
* Gets the raw API response without any processing.
|
|
2038
|
+
*
|
|
2039
|
+
* @returns The complete batch response object.
|
|
2040
|
+
*/
|
|
2041
|
+
get rawResponse(): WithRequestId<BatchResponse>;
|
|
2042
|
+
/**
|
|
2043
|
+
* Gets the timestamp when this batch was created.
|
|
2044
|
+
*
|
|
2045
|
+
* @returns Creation date.
|
|
2046
|
+
*/
|
|
2047
|
+
get createdAt(): Date;
|
|
2048
|
+
/**
|
|
2049
|
+
* Gets the timestamp when this batch was last updated.
|
|
2050
|
+
*
|
|
2051
|
+
* @returns Last update date.
|
|
2052
|
+
*/
|
|
2053
|
+
get updatedAt(): Date;
|
|
2054
|
+
/**
|
|
2055
|
+
* Gets the timestamp when this batch completed successfully.
|
|
2056
|
+
*
|
|
2057
|
+
* @returns Completion date, or null if not completed.
|
|
2058
|
+
*/
|
|
2059
|
+
get completedAt(): Date | null;
|
|
2060
|
+
/**
|
|
2061
|
+
* Gets the timestamp when this batch was canceled.
|
|
2062
|
+
*
|
|
2063
|
+
* @returns Cancellation date, or null if not canceled.
|
|
2064
|
+
*/
|
|
2065
|
+
get canceledAt(): Date | null;
|
|
2066
|
+
/**
|
|
2067
|
+
* Gets the timestamp when this batch failed.
|
|
2068
|
+
*
|
|
2069
|
+
* @returns Failure date, or null if not failed.
|
|
2070
|
+
*/
|
|
2071
|
+
get failedAt(): Date | null;
|
|
2072
|
+
/**
|
|
2073
|
+
* Downloads the complete output file as a Blob.
|
|
2074
|
+
*
|
|
2075
|
+
* The output file is a JSONL (JSON Lines) file where each line contains
|
|
2076
|
+
* one execution result with its reference ID, status, and output.
|
|
2077
|
+
*
|
|
2078
|
+
* @throws {Error} If batch is not completed or output file is unavailable.
|
|
2079
|
+
* @returns A promise resolving to the output file as a Blob.
|
|
2080
|
+
*
|
|
2081
|
+
* @example
|
|
2082
|
+
* ```typescript
|
|
2083
|
+
* const file = await result.downloadOutputFile()
|
|
2084
|
+
* const text = await file.text()
|
|
2085
|
+
* console.log(text) // JSONL content
|
|
2086
|
+
* ```
|
|
2087
|
+
*/
|
|
2088
|
+
downloadOutputFile(): Promise<Blob>;
|
|
2089
|
+
/**
|
|
2090
|
+
* Streams the output file as a ReadableStream for memory-efficient processing.
|
|
2091
|
+
*
|
|
2092
|
+
* Useful for large batches where loading the entire file into memory is not practical.
|
|
2093
|
+
*
|
|
2094
|
+
* @throws {Error} If batch is not completed or output file is unavailable.
|
|
2095
|
+
* @returns A promise resolving to a ReadableStream of the output file.
|
|
2096
|
+
*
|
|
2097
|
+
* @example
|
|
2098
|
+
* ```typescript
|
|
2099
|
+
* const stream = await result.streamOutputFile()
|
|
2100
|
+
* // Process stream with custom logic
|
|
2101
|
+
* ```
|
|
2102
|
+
*/
|
|
2103
|
+
streamOutputFile(): Promise<ReadableStream>;
|
|
2104
|
+
/**
|
|
2105
|
+
* Downloads and parses all results into an array.
|
|
2106
|
+
*
|
|
2107
|
+
* Loads the entire output file into memory, parses each line, and extracts
|
|
2108
|
+
* the output content. For large batches, consider using `iterateResults()` instead.
|
|
2109
|
+
*
|
|
2110
|
+
* @throws {Error} If batch is not completed, output file is unavailable, or parsing fails.
|
|
2111
|
+
* @returns A promise resolving to an array of all execution outputs.
|
|
2112
|
+
*
|
|
2113
|
+
* @example
|
|
2114
|
+
* ```typescript
|
|
2115
|
+
* const results = await result.getResults()
|
|
2116
|
+
* console.log(`Got ${results.length} results`)
|
|
2117
|
+
* results.forEach((output, i) => console.log(`Result ${i}:`, output))
|
|
2118
|
+
* ```
|
|
2119
|
+
*/
|
|
2120
|
+
getResults(): Promise<TOutput[]>;
|
|
2121
|
+
/**
|
|
2122
|
+
* Asynchronously iterates over raw result items from the output file.
|
|
2123
|
+
*
|
|
2124
|
+
* Streams and parses the output file line-by-line, yielding raw JSON objects.
|
|
2125
|
+
* Each yielded object contains the full result structure including metadata.
|
|
2126
|
+
*
|
|
2127
|
+
* @param params - Iteration options.
|
|
2128
|
+
* @param params.abortController - Optional AbortController to cancel iteration.
|
|
2129
|
+
* @throws {Error} If batch is not completed or output file is unavailable.
|
|
2130
|
+
* @yields Raw result objects from the JSONL file.
|
|
2131
|
+
*
|
|
2132
|
+
* @example
|
|
2133
|
+
* ```typescript
|
|
2134
|
+
* for await (const rawResult of result.iterateRawResults()) {
|
|
2135
|
+
* console.log('Reference ID:', rawResult.reference_id)
|
|
2136
|
+
* console.log('Status:', rawResult.status)
|
|
2137
|
+
* console.log('Output:', rawResult.result.outputContent.content)
|
|
2138
|
+
* }
|
|
2139
|
+
* ```
|
|
2140
|
+
*/
|
|
2141
|
+
iterateRawResults(params?: {
|
|
2142
|
+
abortController?: AbortController;
|
|
2143
|
+
}): AsyncGenerator<unknown, void, unknown>;
|
|
2144
|
+
/**
|
|
2145
|
+
* Asynchronously iterates over parsed output content from the batch results.
|
|
2146
|
+
*
|
|
2147
|
+
* Streams and parses the output file line-by-line, yielding only the output content
|
|
2148
|
+
* (not the full result metadata). Memory-efficient for large batches.
|
|
2149
|
+
*
|
|
2150
|
+
* @param params - Iteration options.
|
|
2151
|
+
* @param params.abortController - Optional AbortController to cancel iteration.
|
|
2152
|
+
* @throws {Error} If batch is not completed, output file is unavailable, or parsing fails.
|
|
2153
|
+
* @yields Parsed output content from each execution.
|
|
2154
|
+
*
|
|
2155
|
+
* @example
|
|
2156
|
+
* ```typescript
|
|
2157
|
+
* const controller = new AbortController()
|
|
2158
|
+
*
|
|
2159
|
+
* for await (const output of result.iterateResults({ abortController: controller })) {
|
|
2160
|
+
* console.log(output)
|
|
2161
|
+
* if (someCondition) {
|
|
2162
|
+
* controller.abort() // Stop iteration early
|
|
2163
|
+
* }
|
|
2164
|
+
* }
|
|
2165
|
+
* ```
|
|
2166
|
+
*/
|
|
2167
|
+
iterateResults(params?: {
|
|
2168
|
+
abortController?: AbortController;
|
|
2169
|
+
}): AsyncGenerator<Awaited<TOutput>, void, unknown>;
|
|
2170
|
+
/**
|
|
2171
|
+
* Fetches the raw result metadata for a specific execution by its reference ID.
|
|
2172
|
+
*
|
|
2173
|
+
* Queries the API for the execution result using the reference ID tag.
|
|
2174
|
+
* Returns the complete execution metadata including input, output, and usage statistics.
|
|
2175
|
+
*
|
|
2176
|
+
* @param referenceId - The reference ID of the execution to retrieve.
|
|
2177
|
+
* @throws {Error} If no result found with the given reference ID.
|
|
2178
|
+
* @returns A promise resolving to the raw execution result object.
|
|
2179
|
+
*
|
|
2180
|
+
* @example
|
|
2181
|
+
* ```typescript
|
|
2182
|
+
* const rawResult = await result.getRawResult('my-ref-id')
|
|
2183
|
+
* console.log('Credits used:', rawResult.creditsUsed)
|
|
2184
|
+
* console.log('Execution status:', rawResult.status)
|
|
2185
|
+
* ```
|
|
2186
|
+
*/
|
|
2187
|
+
getRawResult(referenceId: string): Promise<CompletionRunResult<TOutput>>;
|
|
2188
|
+
/**
|
|
2189
|
+
* Fetches the output content for a specific execution by its reference ID.
|
|
2190
|
+
*
|
|
2191
|
+
* Convenience method that retrieves the raw result and extracts just the output content.
|
|
2192
|
+
*
|
|
2193
|
+
* @param referenceId - The reference ID of the execution to retrieve.
|
|
2194
|
+
* @throws {Error} If no result found with the given reference ID.
|
|
2195
|
+
* @returns A promise resolving to the execution output content.
|
|
2196
|
+
*
|
|
2197
|
+
* @example
|
|
2198
|
+
* ```typescript
|
|
2199
|
+
* const output = await result.getResult('my-ref-id')
|
|
2200
|
+
* console.log('Output:', output)
|
|
2201
|
+
* ```
|
|
2202
|
+
*/
|
|
2203
|
+
getResult(referenceId: string): Promise<TOutput>;
|
|
2204
|
+
/**
|
|
2205
|
+
* Validates that the output file is available for access.
|
|
2206
|
+
*
|
|
2207
|
+
* @throws {Error} If batch is not completed or output file is missing.
|
|
2208
|
+
* @private
|
|
2209
|
+
*/
|
|
2210
|
+
private validateOutputFile;
|
|
2211
|
+
}
|
|
2212
|
+
/**
|
|
2213
|
+
* Event types emitted by BatchExecution during its lifecycle.
|
|
2214
|
+
*
|
|
2215
|
+
* @template TOutput - The output type.
|
|
2216
|
+
*
|
|
2217
|
+
* @property poll - Emitted during polling with current status and progress. Includes `requestId` from the polling request.
|
|
2218
|
+
* @property success - Emitted when batch completes successfully with the result object. Includes `requestId` from the final request.
|
|
2219
|
+
* @property error - Emitted when batch fails with the error object.
|
|
2220
|
+
* @property statusChange - Emitted when batch status transitions to a new state, includes new status and response.
|
|
2221
|
+
*
|
|
2222
|
+
* @category Canvas
|
|
2223
|
+
*/
|
|
2224
|
+
type BatchExecutionEvents<TOutput> = {
|
|
2225
|
+
poll: WithRequestId<BatchResponse>;
|
|
2226
|
+
success: BatchExecutionResult<TOutput>;
|
|
2227
|
+
error: BatchExecutionFailedError;
|
|
2228
|
+
statusChange: [BatchExecutionStatus, WithRequestId<BatchResponse>];
|
|
2229
|
+
};
|
|
2230
|
+
/**
|
|
2231
|
+
* Manages the execution lifecycle of a batch operation.
|
|
2232
|
+
*
|
|
2233
|
+
* Handles polling for batch completion, progress tracking, and result retrieval.
|
|
2234
|
+
* Provides an event-driven API for monitoring batch progress in real-time.
|
|
2235
|
+
*
|
|
2236
|
+
* ## Status Tracking
|
|
2237
|
+
*
|
|
2238
|
+
* The batch status can be accessed via the `status` property and tracks the lifecycle:
|
|
2239
|
+
*
|
|
2240
|
+
* - **Batch executions**: `created` → `validating` → `running` → `completed` or `failed`
|
|
2241
|
+
* - **Can be canceled**: At any time before completion using `cancel()`
|
|
2242
|
+
*
|
|
2243
|
+
* Status is set to `failed` when:
|
|
2244
|
+
* - Input file validation fails
|
|
2245
|
+
* - Batch processing encounters an error
|
|
2246
|
+
* - Server reports failure status
|
|
2247
|
+
*
|
|
2248
|
+
* Status is set to `completed` when:
|
|
2249
|
+
* - All executions in the batch finish processing
|
|
2250
|
+
* - Output file is generated and available
|
|
2251
|
+
*
|
|
2252
|
+
* ## Event System
|
|
2253
|
+
*
|
|
2254
|
+
* Events are emitted during polling to track progress:
|
|
2255
|
+
* - `statusChange` - Status transitions (created → validating → running → completed)
|
|
2256
|
+
* - `poll` - Each polling attempt with current progress
|
|
2257
|
+
* - `success` - Completion with the BatchExecutionResult
|
|
2258
|
+
* - `error` - Failure notification
|
|
2259
|
+
*
|
|
2260
|
+
* **Important:** Events are only emitted while polling is active. You must either call `poll()` or
|
|
2261
|
+
* await `execution.result` to start polling.
|
|
2262
|
+
*
|
|
2263
|
+
* @category Canvas
|
|
2264
|
+
*
|
|
2265
|
+
* @typeParam TOutput - The output result type for individual executions
|
|
2266
|
+
*
|
|
2267
|
+
* @fires poll - Emitted during polling with current status and progress. Includes `requestId` from the polling request.
|
|
2268
|
+
* @fires success - Emitted when batch completes successfully with the result object. Includes `requestId` from the final request.
|
|
2269
|
+
* @fires error - Emitted when batch fails (only if error listeners are registered, otherwise throws)
|
|
2270
|
+
* @fires statusChange - Emitted when batch status transitions to a new state
|
|
2271
|
+
*
|
|
2272
|
+
* @example
|
|
2273
|
+
* ```typescript
|
|
2274
|
+
* const execution = await batch.execute()
|
|
2275
|
+
*
|
|
2276
|
+
* // Track progress with events
|
|
2277
|
+
* execution.on('statusChange', ([status, response]) => {
|
|
2278
|
+
* console.log(`Status: ${status}`)
|
|
2279
|
+
* if (response.state) {
|
|
2280
|
+
* console.log(`Progress: ${response.state.completed}/${response.state.total}`)
|
|
2281
|
+
* }
|
|
2282
|
+
* })
|
|
2283
|
+
*
|
|
2284
|
+
* execution.on('success', (result) => {
|
|
2285
|
+
* console.log('Batch completed!')
|
|
2286
|
+
* console.log('Request ID:', result.requestId)
|
|
2287
|
+
* })
|
|
2288
|
+
*
|
|
2289
|
+
* // Start polling without waiting
|
|
2290
|
+
* execution.poll()
|
|
2291
|
+
* ```
|
|
2292
|
+
*/
|
|
2293
|
+
declare class BatchExecution<TOutput> extends Emittery<BatchExecutionEvents<TOutput>> {
|
|
2294
|
+
private readonly _client;
|
|
2295
|
+
private readonly _id;
|
|
2296
|
+
private readonly _params;
|
|
2297
|
+
private readonly _abortController;
|
|
2298
|
+
private readonly _creationResponse;
|
|
2299
|
+
private _status;
|
|
2300
|
+
private _resultPromise;
|
|
2301
|
+
/**
|
|
2302
|
+
* Creates a new batch execution instance.
|
|
2303
|
+
*
|
|
2304
|
+
* @param id - Unique identifier for this batch execution.
|
|
2305
|
+
* @param client - HTTP client for making API requests.
|
|
2306
|
+
* @param params - Batch execution parameters.
|
|
2307
|
+
* @param creationResponse - Initial response from batch creation.
|
|
2308
|
+
* @internal
|
|
2309
|
+
*/
|
|
2310
|
+
constructor(id: string, client: BaseClient, params: BatchParams | undefined, creationResponse: WithRequestId<BatchResponse>);
|
|
2311
|
+
/**
|
|
2312
|
+
* Gets the latest known status of the batch execution.
|
|
2313
|
+
*
|
|
2314
|
+
* Status values and transitions:
|
|
2315
|
+
* - `created` → `validating` → `running` → `completed` or `failed`
|
|
2316
|
+
* - Can transition to `canceled` from any non-terminal state
|
|
2317
|
+
*
|
|
2318
|
+
* Use the `statusChange` event to track status transitions in real-time.
|
|
2319
|
+
*
|
|
2320
|
+
* @returns The current status of the batch execution.
|
|
2321
|
+
*
|
|
2322
|
+
* @example
|
|
2323
|
+
* ```typescript
|
|
2324
|
+
* const execution = await batch.execute()
|
|
2325
|
+
* console.log(execution.status) // 'created'
|
|
2326
|
+
*
|
|
2327
|
+
* execution.on('statusChange', ([status]) => {
|
|
2328
|
+
* console.log('New status:', status)
|
|
2329
|
+
* })
|
|
2330
|
+
*
|
|
2331
|
+
* await execution.result
|
|
2332
|
+
* console.log(execution.status) // 'completed' or 'failed'
|
|
2333
|
+
* ```
|
|
2334
|
+
*/
|
|
2335
|
+
get status(): BatchExecutionStatus;
|
|
2336
|
+
/**
|
|
2337
|
+
* Gets the unique identifier for this batch execution.
|
|
2338
|
+
*
|
|
2339
|
+
* @returns The batch execution ID.
|
|
2340
|
+
*/
|
|
2341
|
+
get id(): string;
|
|
2342
|
+
/**
|
|
2343
|
+
* Gets the batch execution parameters.
|
|
2344
|
+
*
|
|
2345
|
+
* @returns The batch parameters.
|
|
2346
|
+
*/
|
|
2347
|
+
get params(): BatchParams;
|
|
2348
|
+
/**
|
|
2349
|
+
* Cancels the batch execution.
|
|
2350
|
+
*
|
|
2351
|
+
* Sends a cancellation request to the server and aborts any ongoing polling.
|
|
2352
|
+
* The batch will stop processing, but already-completed executions remain available.
|
|
2353
|
+
*
|
|
2354
|
+
* @returns A promise that resolves when the cancellation request completes.
|
|
2355
|
+
*
|
|
2356
|
+
* @example
|
|
2357
|
+
* ```typescript
|
|
2358
|
+
* const execution = await batch.execute()
|
|
2359
|
+
* execution.poll()
|
|
2360
|
+
*
|
|
2361
|
+
* // Cancel after some condition
|
|
2362
|
+
* if (shouldCancel) {
|
|
2363
|
+
* await execution.cancel()
|
|
2364
|
+
* console.log(execution.status) // 'canceled'
|
|
2365
|
+
* }
|
|
2366
|
+
* ```
|
|
2367
|
+
*/
|
|
2368
|
+
cancel(): Promise<void>;
|
|
2369
|
+
/**
|
|
2370
|
+
* Starts polling for the batch result without waiting for the promise to resolve.
|
|
2371
|
+
* This allows users to track batch progress via events rather than awaiting a promise.
|
|
2372
|
+
*
|
|
2373
|
+
* The following events will be emitted during polling:
|
|
2374
|
+
* - `statusChange`: Emitted when the batch status changes (e.g., 'created' → 'running' → 'completed')
|
|
2375
|
+
* - `poll`: Emitted on each polling attempt with the server response
|
|
2376
|
+
* - `success`: Emitted when the batch completes successfully with the final result
|
|
2377
|
+
* - `error`: Emitted if the batch fails
|
|
2378
|
+
*
|
|
2379
|
+
* **Important:** Events are only emitted while polling is active. You must call `poll()` or
|
|
2380
|
+
* await `execution.result` to start polling. Simply setting up event listeners without starting
|
|
2381
|
+
* polling will not trigger any events.
|
|
2382
|
+
*
|
|
2383
|
+
* @example
|
|
2384
|
+
* ```typescript
|
|
2385
|
+
* const execution = await batch.execute()
|
|
2386
|
+
*
|
|
2387
|
+
* // Set up event listeners
|
|
2388
|
+
* execution.on('statusChange', ([status, response]) => {
|
|
2389
|
+
* console.log(`Status: ${status}`)
|
|
2390
|
+
* if (response.state) {
|
|
2391
|
+
* const { completed, total } = response.state
|
|
2392
|
+
* console.log(`Progress: ${completed}/${total}`)
|
|
2393
|
+
* }
|
|
2394
|
+
* })
|
|
2395
|
+
*
|
|
2396
|
+
* execution.on('success', (result) => {
|
|
2397
|
+
* console.log('Batch completed!')
|
|
2398
|
+
* console.log('Request ID:', result.requestId)
|
|
2399
|
+
* })
|
|
2400
|
+
*
|
|
2401
|
+
* execution.on('error', (error) => {
|
|
2402
|
+
* console.error('Batch failed:', error)
|
|
2403
|
+
* })
|
|
2404
|
+
*
|
|
2405
|
+
* // Start polling without waiting
|
|
2406
|
+
* execution.poll()
|
|
2407
|
+
* ```
|
|
2408
|
+
*/
|
|
2409
|
+
poll(): void;
|
|
2410
|
+
/**
|
|
2411
|
+
* Sets the batch status and emits statusChange event if changed.
|
|
2412
|
+
*
|
|
2413
|
+
* @param status - The new status.
|
|
2414
|
+
* @param response - The response containing the status.
|
|
2415
|
+
* @private
|
|
2416
|
+
*/
|
|
2417
|
+
private setStatus;
|
|
2418
|
+
/**
|
|
2419
|
+
* Starts polling the server for batch completion.
|
|
2420
|
+
* Continues polling until the batch completes, fails, or times out.
|
|
2421
|
+
*
|
|
2422
|
+
* @throws {BatchExecutionFailedError} If the batch fails on the server.
|
|
2423
|
+
* @throws {Error} If the polling operation times out.
|
|
2424
|
+
* @returns A promise resolving to the final batch result.
|
|
2425
|
+
* @private
|
|
2426
|
+
*/
|
|
2427
|
+
private startPolling;
|
|
2428
|
+
/**
|
|
2429
|
+
* Gets the batch execution result. Automatically starts polling if not already started.
|
|
2430
|
+
*
|
|
2431
|
+
* @returns A promise resolving to the batch execution result.
|
|
2432
|
+
*
|
|
2433
|
+
* @example
|
|
2434
|
+
* ```typescript
|
|
2435
|
+
* const execution = await batch.execute()
|
|
2436
|
+
* const result = await execution.result
|
|
2437
|
+
*
|
|
2438
|
+
* // Access results
|
|
2439
|
+
* const outputs = await result.getResults()
|
|
2440
|
+
* console.log(`Got ${outputs.length} results`)
|
|
2441
|
+
* ```
|
|
2442
|
+
*/
|
|
2443
|
+
get result(): Promise<BatchExecutionResult<TOutput>>;
|
|
2444
|
+
}
|
|
2445
|
+
/**
|
|
2446
|
+
* Builder class for creating and executing batch operations on a canvas.
|
|
2447
|
+
*
|
|
2448
|
+
* The Batch class provides a fluent API for building up a collection of executions
|
|
2449
|
+
* to be processed in parallel. Items can be added incrementally, and the batch is
|
|
2450
|
+
* executed only when `execute()` is called.
|
|
2451
|
+
*
|
|
2452
|
+
* ## Usage Pattern
|
|
2453
|
+
*
|
|
2454
|
+
* 1. Create batch via `canvas.createBatch()`
|
|
2455
|
+
* 2. Add items via `add()` method (can be called multiple times)
|
|
2456
|
+
* 3. Execute batch via `execute()` method
|
|
2457
|
+
* 4. Monitor progress via events or await result
|
|
2458
|
+
*
|
|
2459
|
+
* ## Reference IDs
|
|
2460
|
+
*
|
|
2461
|
+
* Each batch item can have an optional reference ID for later retrieval.
|
|
2462
|
+
* If not provided, UUIDs are generated automatically. Reference IDs are useful
|
|
2463
|
+
* for correlating results with input data.
|
|
2464
|
+
*
|
|
2465
|
+
* @category Canvas
|
|
2466
|
+
*
|
|
2467
|
+
* @typeParam TInput - The input variables type for the canvas
|
|
2468
|
+
* @typeParam TOutput - The output result type for individual executions
|
|
2469
|
+
*
|
|
2470
|
+
* @example
|
|
2471
|
+
* ```typescript
|
|
2472
|
+
* const batch = canvas.createBatch({
|
|
2473
|
+
* pollingInterval: '1s',
|
|
2474
|
+
* pollingTimeout: '5m',
|
|
2475
|
+
* })
|
|
2476
|
+
*
|
|
2477
|
+
* // Add items individually
|
|
2478
|
+
* batch.add({
|
|
2479
|
+
* referenceId: 'item-1',
|
|
2480
|
+
* variables: { query: 'First query' }
|
|
2481
|
+
* })
|
|
2482
|
+
*
|
|
2483
|
+
* // Or add multiple items at once
|
|
2484
|
+
* batch.add([
|
|
2485
|
+
* { variables: { query: 'Second query' } },
|
|
2486
|
+
* { variables: { query: 'Third query' } }
|
|
2487
|
+
* ])
|
|
2488
|
+
*
|
|
2489
|
+
* // Execute and track progress
|
|
2490
|
+
* const execution = await batch.execute()
|
|
2491
|
+
* execution.on('statusChange', ([status, response]) => {
|
|
2492
|
+
* if (response.state) {
|
|
2493
|
+
* console.log(`Progress: ${response.state.completed}/${response.state.total}`)
|
|
2494
|
+
* }
|
|
2495
|
+
* })
|
|
2496
|
+
*
|
|
2497
|
+
* const result = await execution.result
|
|
2498
|
+
* const outputs = await result.getResults()
|
|
2499
|
+
* ```
|
|
2500
|
+
*/
|
|
2501
|
+
declare class Batch<TInput, TOutput> {
|
|
2502
|
+
private readonly _client;
|
|
2503
|
+
private readonly _canvasIdentifier;
|
|
2504
|
+
private readonly _items;
|
|
2505
|
+
private readonly _params;
|
|
2506
|
+
/**
|
|
2507
|
+
* Creates a new batch builder.
|
|
2508
|
+
*
|
|
2509
|
+
* @param client - HTTP client for making API requests.
|
|
2510
|
+
* @param canvasIdentifier - Canvas identification (ID + version or application ID).
|
|
2511
|
+
* @param params - Optional batch execution parameters.
|
|
2512
|
+
* @internal
|
|
2513
|
+
*/
|
|
2514
|
+
constructor(client: BaseClient, canvasIdentifier: CanvasIdentifier, params?: BatchParams);
|
|
2515
|
+
/**
|
|
2516
|
+
* Gets the current list of items in this batch.
|
|
2517
|
+
*
|
|
2518
|
+
* @returns Array of batch items.
|
|
2519
|
+
*/
|
|
2520
|
+
get items(): BatchItem<TInput>[];
|
|
2521
|
+
/**
|
|
2522
|
+
* Gets the batch execution parameters.
|
|
2523
|
+
*
|
|
2524
|
+
* @returns The batch parameters.
|
|
2525
|
+
*/
|
|
2526
|
+
get params(): BatchParams;
|
|
2527
|
+
/**
|
|
2528
|
+
* Gets the canvas identifier in the format expected by the API.
|
|
2529
|
+
*
|
|
2530
|
+
* @returns Canvas identifier object.
|
|
2531
|
+
* @private
|
|
2532
|
+
*/
|
|
2533
|
+
private get canvasIdentifier();
|
|
2534
|
+
/**
|
|
2535
|
+
* Adds one or more items to the batch.
|
|
2536
|
+
*
|
|
2537
|
+
* Items without a reference ID will have UUIDs generated automatically.
|
|
2538
|
+
* This method can be called multiple times to build up the batch incrementally.
|
|
2539
|
+
*
|
|
2540
|
+
* @param item - Single item or array of items to add to the batch.
|
|
2541
|
+
*
|
|
2542
|
+
* @example
|
|
2543
|
+
* ```typescript
|
|
2544
|
+
* // Add single item
|
|
2545
|
+
* batch.add({
|
|
2546
|
+
* referenceId: 'my-custom-id',
|
|
2547
|
+
* variables: { query: 'Hello' }
|
|
2548
|
+
* })
|
|
2549
|
+
*
|
|
2550
|
+
* // Add multiple items
|
|
2551
|
+
* batch.add([
|
|
2552
|
+
* { variables: { query: 'First' } },
|
|
2553
|
+
* { variables: { query: 'Second' } },
|
|
2554
|
+
* { variables: { query: 'Third' } }
|
|
2555
|
+
* ])
|
|
2556
|
+
*
|
|
2557
|
+
* console.log(`Batch has ${batch.items.length} items`)
|
|
2558
|
+
* ```
|
|
2559
|
+
*/
|
|
2560
|
+
add(item: MaybeArray<BatchItem<TInput>>): void;
|
|
2561
|
+
/**
|
|
2562
|
+
* Executes the batch by uploading the input file and creating a batch execution on the server.
|
|
2563
|
+
*
|
|
2564
|
+
* Returns a promise-like object that allows flexible usage patterns:
|
|
2565
|
+
* - Await for execution object: `const exec = await batch.execute()`
|
|
2566
|
+
* - Direct result access: `const result = await batch.execute().result`
|
|
2567
|
+
*
|
|
2568
|
+
* The batch items are serialized to JSONL format, uploaded to vault storage,
|
|
2569
|
+
* and submitted to the batch API for processing.
|
|
2570
|
+
*
|
|
2571
|
+
* @returns A promise-like object with a `result` property for direct result access.
|
|
2572
|
+
*
|
|
2573
|
+
* @example
|
|
2574
|
+
* ```typescript
|
|
2575
|
+
* // Direct result access (recommended for simple cases)
|
|
2576
|
+
* const result = await batch.execute().result
|
|
2577
|
+
* const outputs = await result.getResults()
|
|
2578
|
+
*
|
|
2579
|
+
* // Get execution object for event monitoring
|
|
2580
|
+
* const execution = await batch.execute()
|
|
2581
|
+
*
|
|
2582
|
+
* execution.on('statusChange', ([status, response]) => {
|
|
2583
|
+
* console.log(`Status: ${status}`)
|
|
2584
|
+
* if (response.state) {
|
|
2585
|
+
* console.log(`Progress: ${response.state.completed}/${response.state.total}`)
|
|
2586
|
+
* }
|
|
2587
|
+
* })
|
|
2588
|
+
*
|
|
2589
|
+
* execution.on('success', (result) => {
|
|
2590
|
+
* console.log('Batch completed!', result.requestId)
|
|
2591
|
+
* })
|
|
2592
|
+
*
|
|
2593
|
+
* const result = await execution.result
|
|
2594
|
+
*
|
|
2595
|
+
* // Iterate through results
|
|
2596
|
+
* for await (const output of result.iterateResults()) {
|
|
2597
|
+
* console.log(output)
|
|
2598
|
+
* }
|
|
2599
|
+
* ```
|
|
2600
|
+
*/
|
|
2601
|
+
execute(): BatchExecutionPromiseLike<TOutput>;
|
|
2602
|
+
}
|
|
2603
|
+
|
|
2604
|
+
/**
|
|
2605
|
+
* Canvas resource for managing prompt templates and their execution.
|
|
2606
|
+
*
|
|
2607
|
+
* This module provides the core Canvas class for retrieving and executing
|
|
2608
|
+
* prompt templates from the Tela API, with support for schema validation,
|
|
2609
|
+
* type safety, and multiple execution modes.
|
|
2610
|
+
*
|
|
2611
|
+
* @module Resources
|
|
2612
|
+
*/
|
|
2613
|
+
|
|
2614
|
+
interface CanvasOptions<TInput, TOutput> {
|
|
2615
|
+
/**
|
|
2616
|
+
* Id of the canvas that will be used to create the completion.
|
|
2617
|
+
*/
|
|
2618
|
+
id?: string;
|
|
2619
|
+
/**
|
|
2620
|
+
* Id of the version of the canvas. If not provided, the latest promoted version will be used.
|
|
2621
|
+
*/
|
|
2622
|
+
versionId?: string;
|
|
2623
|
+
/**
|
|
2624
|
+
* Id of the application that the canvas belongs to.
|
|
2625
|
+
*/
|
|
2626
|
+
applicationId?: string;
|
|
2627
|
+
/**
|
|
2628
|
+
* Name of the canvas. Useful for debugging.
|
|
2629
|
+
*/
|
|
2630
|
+
name?: string;
|
|
2631
|
+
/**
|
|
2632
|
+
* Input schema of the canvas.
|
|
2633
|
+
*/
|
|
2634
|
+
input?: SchemaFunction<TInput>;
|
|
2635
|
+
/**
|
|
2636
|
+
* Output schema of the canvas.
|
|
2637
|
+
*/
|
|
2638
|
+
output?: SchemaFunction<TOutput>;
|
|
2639
|
+
/**
|
|
2640
|
+
* Base client for making requests to the Tela API.
|
|
2641
|
+
*/
|
|
2642
|
+
client: BaseClient;
|
|
2643
|
+
/**
|
|
2644
|
+
* Variables of the canvas.
|
|
2645
|
+
*/
|
|
2646
|
+
variables: Array<CanvasVariable>;
|
|
2647
|
+
/**
|
|
2648
|
+
* Whether the canvas is a workflow.
|
|
2649
|
+
*/
|
|
2650
|
+
isWorkflow: boolean;
|
|
2651
|
+
}
|
|
2652
|
+
type CanvasGetOptions<TInput extends ZodTypeOrRecord, TOutput extends ZodTypeOrRecord> = Omit<CanvasOptions<TInput, TOutput>, 'client' | 'variables' | 'isWorkflow'> & {
|
|
2653
|
+
/**
|
|
2654
|
+
* Whether to skip schema validation warnings during canvas retrieval.
|
|
2655
|
+
* When true, no warnings will be logged for schema mismatches.
|
|
2656
|
+
* @default false
|
|
2657
|
+
*/
|
|
2658
|
+
skipSchemaValidation?: boolean;
|
|
2659
|
+
};
|
|
2660
|
+
type CanvasExecutionPromiseLike<TParams extends ExecutionParams = SyncExecutionParams, TInput = unknown, TOutput = unknown> = PromiseLike<CanvasExecution<TParams, TInput, TOutput>> & {
|
|
2661
|
+
result: Promise<CanvasExecutionResult<TParams, TOutput>>;
|
|
2662
|
+
};
|
|
2663
|
+
/**
|
|
2664
|
+
* Represents a canvas (prompt template) from the Tela API.
|
|
2665
|
+
*
|
|
2666
|
+
* Canvas instances are retrieved using `tela.canvas.get()` and provide methods
|
|
2667
|
+
* for executing prompts with various modes (sync, async, streaming).
|
|
2668
|
+
*
|
|
2669
|
+
* @category Canvas
|
|
2670
|
+
*
|
|
2671
|
+
* @typeParam TInput - The input schema type (Zod schema or plain object type)
|
|
2672
|
+
* @typeParam TOutput - The output schema type (Zod schema or plain object type)
|
|
2673
|
+
*/
|
|
2674
|
+
declare class Canvas<TInput extends ZodTypeOrRecord, TOutput extends ZodTypeOrRecord> {
|
|
2675
|
+
private readonly _id;
|
|
2676
|
+
private readonly _versionId;
|
|
2677
|
+
private readonly _applicationId;
|
|
2678
|
+
private readonly _name;
|
|
2679
|
+
private readonly _input;
|
|
2680
|
+
private readonly _output;
|
|
2681
|
+
private readonly _client;
|
|
2682
|
+
private readonly _variables;
|
|
2683
|
+
private readonly _isWorkflow;
|
|
2684
|
+
/**
|
|
2685
|
+
* Creates a new instance of the Canvas class. Usage of this constructor is not recommended.
|
|
2686
|
+
* Use the `tela.getCanvas` method instead.
|
|
2687
|
+
*
|
|
2688
|
+
* @private
|
|
2689
|
+
*/
|
|
2690
|
+
private constructor();
|
|
2691
|
+
/**
|
|
2692
|
+
* Gets a canvas by its ID.
|
|
2693
|
+
*
|
|
2694
|
+
* @param options - The options to use to get the canvas.
|
|
2695
|
+
* @param options.id - The ID of the canvas to get.
|
|
2696
|
+
* @param options.versionId - The version ID of the canvas to get.
|
|
2697
|
+
* @param options.applicationId - The application ID of the canvas to get.
|
|
2698
|
+
* @param options.client - The client to use to make the request.
|
|
2699
|
+
* @param options.input - The input schema of the canvas to get.
|
|
2700
|
+
* @param options.output - The output schema of the canvas to get.
|
|
2701
|
+
* @returns The canvas.
|
|
2702
|
+
*/
|
|
2703
|
+
static get<TInput extends ZodTypeOrRecord, TOutput extends ZodTypeOrRecord>(options: CanvasGetOptions<TInput, TOutput> & {
|
|
2704
|
+
client: BaseClient;
|
|
2705
|
+
}): Promise<Canvas<TInput, TOutput>>;
|
|
2706
|
+
/**
|
|
2707
|
+
* Gets the unique identifier of this canvas.
|
|
2708
|
+
*
|
|
2709
|
+
* @returns The canvas ID.
|
|
2710
|
+
*/
|
|
2711
|
+
get id(): string;
|
|
2712
|
+
/**
|
|
2713
|
+
* Gets the name of this canvas, if provided.
|
|
2714
|
+
*
|
|
2715
|
+
* @returns The canvas name or undefined.
|
|
2716
|
+
*/
|
|
2717
|
+
get name(): string;
|
|
2718
|
+
/**
|
|
2719
|
+
* Gets the version identifier of this canvas, if specified.
|
|
2720
|
+
* When undefined, the latest promoted version is used.
|
|
2721
|
+
*
|
|
2722
|
+
* @returns The version ID or undefined.
|
|
2723
|
+
*/
|
|
2724
|
+
get versionId(): string;
|
|
2725
|
+
get applicationId(): string;
|
|
2726
|
+
/**
|
|
2727
|
+
* Gets the variables of this canvas.
|
|
2728
|
+
*
|
|
2729
|
+
* @returns The variables of the canvas.
|
|
2730
|
+
*/
|
|
2731
|
+
get variables(): Array<CanvasVariable>;
|
|
2732
|
+
/**
|
|
2733
|
+
* Gets whether this canvas is a workflow.
|
|
2734
|
+
*
|
|
2735
|
+
* @returns True if the canvas is a workflow.
|
|
2736
|
+
*/
|
|
2737
|
+
get isWorkflow(): boolean;
|
|
2738
|
+
/**
|
|
2739
|
+
* Gets whether this canvas is a workstation.
|
|
2740
|
+
* This is true if an application ID is provided.
|
|
2741
|
+
*
|
|
2742
|
+
* @returns True if the canvas is a workstation.
|
|
2743
|
+
*/
|
|
2744
|
+
get isWorkstation(): boolean;
|
|
2745
|
+
/**
|
|
2746
|
+
* Validates and parses input variables using the canvas input schema.
|
|
2747
|
+
*
|
|
2748
|
+
* @param variables - Raw input variables to validate.
|
|
2749
|
+
* @returns Parsed and validated variables.
|
|
2750
|
+
* @throws {ZodError} If validation fails when a Zod schema is configured.
|
|
2751
|
+
*/
|
|
2752
|
+
private parseVariables;
|
|
2753
|
+
/**
|
|
2754
|
+
* Executes this canvas with the provided input variables.
|
|
2755
|
+
* Creates and starts a canvas execution, handling variable validation and schema parsing.
|
|
2756
|
+
*
|
|
2757
|
+
* Returns a promise-like object that allows flexible usage patterns:
|
|
2758
|
+
* - Await for the execution object: `const exec = await canvas.execute(vars)`
|
|
2759
|
+
* - Direct result access: `const result = await canvas.execute(vars).result`
|
|
2760
|
+
* - Stream iteration: `for await (const chunk of canvas.execute(vars, { stream: true }).result)`
|
|
2761
|
+
*
|
|
2762
|
+
* @param variables - Input variables to pass to the canvas template.
|
|
2763
|
+
* @param params - Optional execution parameters (sync/async/stream configuration).
|
|
2764
|
+
* @returns A promise-like object with a `result` property for direct result access.
|
|
2765
|
+
*
|
|
2766
|
+
* @example
|
|
2767
|
+
* ```typescript
|
|
2768
|
+
* // Direct result access (recommended for simple cases)
|
|
2769
|
+
* const result = await canvas.execute({ query: "Hello" }).result;
|
|
2770
|
+
*
|
|
2771
|
+
* // Get execution object for control (e.g., to abort)
|
|
2772
|
+
* const execution = await canvas.execute({ query: "Hello" });
|
|
2773
|
+
* const result = await execution.result;
|
|
2774
|
+
*
|
|
2775
|
+
* // Asynchronous execution with polling
|
|
2776
|
+
* const result = await canvas.execute(
|
|
2777
|
+
* { query: "Hello" },
|
|
2778
|
+
* { async: true, pollingInterval: 500 }
|
|
2779
|
+
* ).result;
|
|
2780
|
+
*
|
|
2781
|
+
* // Streaming execution
|
|
2782
|
+
* for await (const chunk of canvas.execute(
|
|
2783
|
+
* { query: "Hello" },
|
|
2784
|
+
* { stream: true }
|
|
2785
|
+
* ).result) {
|
|
2786
|
+
* console.log(chunk);
|
|
2787
|
+
* }
|
|
2788
|
+
*
|
|
2789
|
+
* // Execution with tags
|
|
2790
|
+
* const result = await canvas.execute(
|
|
2791
|
+
* { query: "Hello" },
|
|
2792
|
+
* { tags: ["production", "analytics"] }
|
|
2793
|
+
* ).result;
|
|
2794
|
+
* ```
|
|
2795
|
+
*/
|
|
2796
|
+
execute(variables: z$1.input<TInput>, params?: SyncExecutionParams): CanvasExecutionPromiseLike<SyncExecutionParams, Output<TInput>, Output<TOutput>>;
|
|
2797
|
+
execute(variables: z$1.input<TInput>, params?: AsyncExecutionParams): CanvasExecutionPromiseLike<AsyncExecutionParams, Output<TInput>, Output<TOutput>>;
|
|
2798
|
+
execute(variables: z$1.input<TInput>, params?: StreamExecutionParams): CanvasExecutionPromiseLike<StreamExecutionParams, Output<TInput>, Output<TOutput>>;
|
|
2799
|
+
/**
|
|
2800
|
+
* Fetches an existing async execution by its ID.
|
|
2801
|
+
*
|
|
2802
|
+
* This method retrieves the current state of an async execution that was previously
|
|
2803
|
+
* started on this canvas. Only async executions can be fetched, as they are the only
|
|
2804
|
+
* ones with persistent UUIDs on the server.
|
|
2805
|
+
*
|
|
2806
|
+
* @param id - The UUID of the async execution to fetch.
|
|
2807
|
+
* @param options - Optional configuration for polling behavior.
|
|
2808
|
+
* @param options.pollingInterval - Time in milliseconds between polling attempts (default: 1000).
|
|
2809
|
+
* @param options.pollingTimeout - Maximum time in milliseconds to wait for completion (default: 60000).
|
|
2810
|
+
* @throws {InvalidExecutionModeError} If the provided ID is not a valid UUID.
|
|
2811
|
+
* @returns A promise resolving to a CanvasExecution instance with the fetched state.
|
|
2812
|
+
*
|
|
2813
|
+
* @example
|
|
2814
|
+
* ```typescript
|
|
2815
|
+
* // Start an async execution
|
|
2816
|
+
* const execution = await canvas.execute({ query: 'test' }, { async: true })
|
|
2817
|
+
* const executionId = execution.id
|
|
2818
|
+
*
|
|
2819
|
+
* // Later, fetch the execution by ID
|
|
2820
|
+
* const fetched = await canvas.getExecution(executionId)
|
|
2821
|
+
* console.log(fetched.status) // 'running', 'succeeded', or 'failed'
|
|
2822
|
+
*
|
|
2823
|
+
* // Use poll() for event-driven progress tracking
|
|
2824
|
+
* fetched.on('statusChange', (status) => console.log('Status:', status))
|
|
2825
|
+
* fetched.poll()
|
|
2826
|
+
* ```
|
|
2827
|
+
*/
|
|
2828
|
+
getExecution(id: string, options?: {
|
|
2829
|
+
pollingInterval?: string | number;
|
|
2830
|
+
pollingTimeout?: string | number;
|
|
2831
|
+
}): Promise<CanvasExecution<AsyncExecutionParams, unknown, Output<TOutput>>>;
|
|
2832
|
+
/**
|
|
2833
|
+
* Prepares to execute this canvas in batch.
|
|
2834
|
+
*
|
|
2835
|
+
* @param params - The parameters for the batch.
|
|
2836
|
+
* @param params.pollingInterval - The interval between polling attempts.
|
|
2837
|
+
* @param params.pollingTimeout - The timeout for the batch.
|
|
2838
|
+
* @param params.webhookUrl - The webhook URL for the batch.
|
|
2839
|
+
*
|
|
2840
|
+
* @example
|
|
2841
|
+
* ```typescript
|
|
2842
|
+
* const batch = canvas.createBatch({
|
|
2843
|
+
* pollingInterval: '1s',
|
|
2844
|
+
* pollingTimeout: '1m',
|
|
2845
|
+
* webhookUrl: 'https://example.com/webhook',
|
|
2846
|
+
* })
|
|
2847
|
+
*
|
|
2848
|
+
* batch.add({
|
|
2849
|
+
* referenceId: crypto.randomUUID(), // Optional
|
|
2850
|
+
* variables: { query: 'Hello' },
|
|
2851
|
+
* })
|
|
2852
|
+
*
|
|
2853
|
+
* const execution = await batch.execute()
|
|
2854
|
+
* const result = await execution.result
|
|
2855
|
+
* const resultFile = await execution.downloadOutputFile()
|
|
2856
|
+
* ```
|
|
2857
|
+
*
|
|
2858
|
+
* @returns The batch instance that can be used to manage the batch.
|
|
2859
|
+
*/
|
|
2860
|
+
createBatch(params?: BatchParams): Batch<Output<TInput>, Output<TOutput>>;
|
|
2861
|
+
}
|
|
2862
|
+
|
|
2863
|
+
/**
|
|
2864
|
+
* Parameters for creating a task.
|
|
2865
|
+
*
|
|
2866
|
+
* @category Workstation
|
|
2867
|
+
*/
|
|
2868
|
+
type TaskParams = {
|
|
2869
|
+
label?: string;
|
|
2870
|
+
tags?: string[];
|
|
2871
|
+
};
|
|
2872
|
+
/**
|
|
2873
|
+
* A promise-like object that resolves to a Task instance and provides direct access to the result.
|
|
2874
|
+
*
|
|
2875
|
+
* @template TInput - The input variables type
|
|
2876
|
+
* @template TOutput - The output result type
|
|
2877
|
+
*
|
|
2878
|
+
* @category Workstation
|
|
2879
|
+
*/
|
|
2880
|
+
type TaskPromiseLike<TInput = unknown, TOutput = unknown> = PromiseLike<Task<TInput, TOutput>> & {
|
|
2881
|
+
result: Promise<TOutput>;
|
|
2882
|
+
};
|
|
2883
|
+
/**
|
|
2884
|
+
* Event types emitted by Task during its lifecycle.
|
|
2885
|
+
*
|
|
2886
|
+
* @template TOutput - The output type.
|
|
2887
|
+
*
|
|
2888
|
+
* @property poll - Emitted during polling with current status and output. Includes `requestId` from the polling request.
|
|
2889
|
+
* @property success - Emitted when task completes successfully with the final result.
|
|
2890
|
+
* @property error - Emitted when task fails with the error object.
|
|
2891
|
+
* @property statusChange - Emitted when task status transitions to a new state.
|
|
2892
|
+
*
|
|
2893
|
+
* @category Workstation
|
|
2894
|
+
*/
|
|
2895
|
+
type TaskEvents<TOutput = unknown> = {
|
|
2896
|
+
poll: WithRequestId<TaskDefinition<TOutput>>;
|
|
2897
|
+
success: TOutput;
|
|
2898
|
+
error: TaskFailedError;
|
|
2899
|
+
statusChange: TaskStatus;
|
|
2900
|
+
};
|
|
2901
|
+
/**
|
|
2902
|
+
* Represents a workstation task with event-driven status tracking and result polling.
|
|
2903
|
+
*
|
|
2904
|
+
* Tasks are always asynchronous and require polling to retrieve results. The Task class
|
|
2905
|
+
* provides an event system for monitoring task lifecycle and automatic output validation.
|
|
2906
|
+
*
|
|
2907
|
+
* ## Status Tracking
|
|
2908
|
+
*
|
|
2909
|
+
* Task status can be accessed via the `status` property and tracks the lifecycle:
|
|
2910
|
+
* - `created` → `running` → `completed` or `failed`
|
|
2911
|
+
*
|
|
2912
|
+
* Status is set to `failed` when:
|
|
2913
|
+
* - API request fails
|
|
2914
|
+
* - Validation fails
|
|
2915
|
+
* - Polling reports failure status
|
|
2916
|
+
*
|
|
2917
|
+
* Status is set to `completed` only after:
|
|
2918
|
+
* - API request succeeds AND
|
|
2919
|
+
* - Output validation passes (if schema provided)
|
|
2920
|
+
*
|
|
2921
|
+
* @category Workstation
|
|
2922
|
+
*
|
|
2923
|
+
* @typeParam TInput - The input variables type
|
|
2924
|
+
* @typeParam TOutput - The output result type
|
|
2925
|
+
*
|
|
2926
|
+
* @fires poll - Emitted during polling with current status and output. Includes `requestId` from the polling request.
|
|
2927
|
+
* @fires success - Emitted when task completes successfully with the final result. Includes `requestId` from the final request.
|
|
2928
|
+
* @fires error - Emitted when task fails (only if error listeners are registered, otherwise throws)
|
|
2929
|
+
* @fires statusChange - Emitted when task status transitions to a new state
|
|
2930
|
+
*
|
|
2931
|
+
* @example
|
|
2932
|
+
* ```typescript
|
|
2933
|
+
* const task = await workstation.createTask({ query: 'test' })
|
|
2934
|
+
*
|
|
2935
|
+
* // Track status changes
|
|
2936
|
+
* task.on('statusChange', (status) => {
|
|
2937
|
+
* console.log(`Status: ${status}`) // created → running → completed
|
|
2938
|
+
* })
|
|
2939
|
+
*
|
|
2940
|
+
* // Monitor polling progress
|
|
2941
|
+
* task.on('poll', (pollResult) => {
|
|
2942
|
+
* console.log('Polling...', pollResult.requestId)
|
|
2943
|
+
* })
|
|
2944
|
+
*
|
|
2945
|
+
* // Handle success
|
|
2946
|
+
* task.on('success', (result) => {
|
|
2947
|
+
* console.log('Result:', result)
|
|
2948
|
+
* })
|
|
2949
|
+
*
|
|
2950
|
+
* // Handle errors
|
|
2951
|
+
* task.on('error', (error) => {
|
|
2952
|
+
* console.error('Failed:', error)
|
|
2953
|
+
* })
|
|
2954
|
+
*
|
|
2955
|
+
* // Start polling without waiting
|
|
2956
|
+
* task.poll()
|
|
2957
|
+
* ```
|
|
2958
|
+
*/
|
|
2959
|
+
declare class Task<TInput = unknown, TOutput = unknown> extends Emittery<TaskEvents<TOutput>> {
|
|
2960
|
+
private readonly _variables;
|
|
2961
|
+
private readonly _task;
|
|
2962
|
+
private readonly _abortController;
|
|
2963
|
+
private readonly _client;
|
|
2964
|
+
private readonly _outputSchema;
|
|
2965
|
+
private readonly _skipResultValidation;
|
|
2966
|
+
private _resultPromise;
|
|
2967
|
+
private _status;
|
|
2968
|
+
private _requestId;
|
|
2969
|
+
constructor(client: BaseClient, variables: TInput, task: TaskDefinition, requestId?: string, outputSchema?: z.ZodType | Record<string, unknown>, skipResultValidation?: boolean);
|
|
2970
|
+
/**
|
|
2971
|
+
* Gets the unique task ID assigned by the server.
|
|
2972
|
+
*
|
|
2973
|
+
* @returns The task ID.
|
|
2974
|
+
*/
|
|
2975
|
+
get id(): string;
|
|
2976
|
+
/**
|
|
2977
|
+
* Gets the request ID from the `x-request-id` header of the task creation request.
|
|
2978
|
+
*
|
|
2979
|
+
* This is the request ID from the initial POST /task request that created the task.
|
|
2980
|
+
* Each API request has its own unique request ID.
|
|
2981
|
+
*
|
|
2982
|
+
* For polling operations, different request IDs are available:
|
|
2983
|
+
* - `task.requestId` - ID from the task creation request
|
|
2984
|
+
* - `pollResult.requestId` - ID from each polling request (in poll events)
|
|
2985
|
+
* - `result.requestId` - ID from the final successful polling request (in success events)
|
|
2986
|
+
*
|
|
2987
|
+
* @returns A promise that resolves to the request ID from the task creation request.
|
|
2988
|
+
*
|
|
2989
|
+
* @example
|
|
2990
|
+
* ```typescript
|
|
2991
|
+
* const task = await workstation.createTask({ query: 'test' })
|
|
2992
|
+
* const requestId = await task.requestId
|
|
2993
|
+
* console.log('Request ID:', requestId)
|
|
2994
|
+
* ```
|
|
2995
|
+
*/
|
|
2996
|
+
get requestId(): string | undefined;
|
|
2997
|
+
/**
|
|
2998
|
+
* Gets the latest known status of the task.
|
|
2999
|
+
*
|
|
3000
|
+
* Status values and transitions:
|
|
3001
|
+
* - `created` → `running` → `completed` or `failed`
|
|
3002
|
+
*
|
|
3003
|
+
* **Important:** Status is set to `completed` only after successful validation.
|
|
3004
|
+
* If validation fails, status will be `failed` even if the API request succeeded.
|
|
3005
|
+
*
|
|
3006
|
+
* Use the `statusChange` event to track status transitions in real-time.
|
|
3007
|
+
*
|
|
3008
|
+
* @returns The current status of the task.
|
|
3009
|
+
*
|
|
3010
|
+
* @example
|
|
3011
|
+
* ```typescript
|
|
3012
|
+
* const task = await workstation.createTask({ query: 'test' })
|
|
3013
|
+
* console.log(task.status) // 'created'
|
|
3014
|
+
*
|
|
3015
|
+
* await task.result
|
|
3016
|
+
* console.log(task.status) // 'completed' or 'failed'
|
|
3017
|
+
* ```
|
|
3018
|
+
*/
|
|
3019
|
+
get status(): TaskStatus;
|
|
3020
|
+
/**
|
|
3021
|
+
* Sets the status of the task and emits statusChange event.
|
|
3022
|
+
*
|
|
3023
|
+
* @param status - The new status of the task.
|
|
3024
|
+
* @private
|
|
3025
|
+
*/
|
|
3026
|
+
private set status(value);
|
|
3027
|
+
/**
|
|
3028
|
+
* Gets the input variables provided to this task.
|
|
3029
|
+
*
|
|
3030
|
+
* @returns The variables object.
|
|
3031
|
+
*/
|
|
3032
|
+
get variables(): TInput;
|
|
3033
|
+
/**
|
|
3034
|
+
* Gets the task label (alias for name).
|
|
3035
|
+
*
|
|
3036
|
+
* @returns The task name.
|
|
3037
|
+
*/
|
|
3038
|
+
get label(): string;
|
|
3039
|
+
/**
|
|
3040
|
+
* Gets the task name.
|
|
3041
|
+
*
|
|
3042
|
+
* @returns The task name.
|
|
3043
|
+
*/
|
|
3044
|
+
get name(): string;
|
|
3045
|
+
/**
|
|
3046
|
+
* Gets the task tags.
|
|
3047
|
+
*
|
|
3048
|
+
* @returns The task tags.
|
|
3049
|
+
*/
|
|
3050
|
+
get tags(): string[];
|
|
3051
|
+
/**
|
|
3052
|
+
* Gets the raw task definition from the server.
|
|
3053
|
+
*
|
|
3054
|
+
* @returns The raw task definition.
|
|
3055
|
+
*/
|
|
3056
|
+
get rawTask(): TaskDefinition;
|
|
3057
|
+
/**
|
|
3058
|
+
* Starts polling for the task result without waiting for the promise to resolve.
|
|
3059
|
+
* This allows users to track task progress via events rather than awaiting a promise.
|
|
3060
|
+
*
|
|
3061
|
+
* The following events will be emitted during polling:
|
|
3062
|
+
* - `statusChange`: Emitted when the task status changes (e.g., 'created' → 'running' → 'completed')
|
|
3063
|
+
* - `poll`: Emitted on each polling attempt with the server response
|
|
3064
|
+
* - `success`: Emitted when the task completes successfully with the final result
|
|
3065
|
+
* - `error`: Emitted if the task fails
|
|
3066
|
+
*
|
|
3067
|
+
* **Important:** Events are only emitted while polling is active. You must call `poll()` or
|
|
3068
|
+
* await `task.result` to start polling. Simply setting up event listeners without starting
|
|
3069
|
+
* polling will not trigger any events.
|
|
3070
|
+
*
|
|
3071
|
+
* @example
|
|
3072
|
+
* ```typescript
|
|
3073
|
+
* const task = await workstation.createTask({ query: 'test' })
|
|
3074
|
+
*
|
|
3075
|
+
* // Set up event listeners
|
|
3076
|
+
* task.on('statusChange', (status) => {
|
|
3077
|
+
* console.log('Status:', status)
|
|
3078
|
+
* })
|
|
3079
|
+
*
|
|
3080
|
+
* task.on('success', (result) => {
|
|
3081
|
+
* console.log('Completed:', result)
|
|
3082
|
+
* })
|
|
3083
|
+
*
|
|
3084
|
+
* task.on('error', (error) => {
|
|
3085
|
+
* console.error('Failed:', error)
|
|
3086
|
+
* })
|
|
3087
|
+
*
|
|
3088
|
+
* // Start polling without waiting
|
|
3089
|
+
* task.poll()
|
|
3090
|
+
* ```
|
|
1194
3091
|
*/
|
|
1195
|
-
|
|
3092
|
+
poll(): void;
|
|
1196
3093
|
/**
|
|
1197
|
-
*
|
|
3094
|
+
* Gets the task result. Automatically starts polling if not already started.
|
|
3095
|
+
*
|
|
3096
|
+
* @returns A promise that resolves to the validated task output.
|
|
3097
|
+
*
|
|
3098
|
+
* @example
|
|
3099
|
+
* ```typescript
|
|
3100
|
+
* const task = await workstation.createTask({ query: 'test' })
|
|
3101
|
+
* const result = await task.result
|
|
3102
|
+
* console.log(result)
|
|
3103
|
+
* ```
|
|
1198
3104
|
*/
|
|
1199
|
-
|
|
3105
|
+
get result(): Promise<TOutput>;
|
|
1200
3106
|
/**
|
|
1201
|
-
*
|
|
3107
|
+
* Starts the polling process to retrieve task results.
|
|
3108
|
+
* Emits events during the polling lifecycle and validates output before resolving.
|
|
3109
|
+
*
|
|
3110
|
+
* @returns A promise that resolves to the validated task output.
|
|
3111
|
+
* @private
|
|
1202
3112
|
*/
|
|
1203
|
-
|
|
3113
|
+
private startPolling;
|
|
1204
3114
|
}
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
3115
|
+
|
|
3116
|
+
/**
|
|
3117
|
+
* Internal configuration options for creating a Workstation instance.
|
|
3118
|
+
*
|
|
3119
|
+
* @internal
|
|
3120
|
+
*/
|
|
3121
|
+
type WorkstationOptions<TInput extends ZodTypeOrRecord, TOutput extends ZodTypeOrRecord> = {
|
|
3122
|
+
client: BaseClient;
|
|
3123
|
+
applicationId: string;
|
|
3124
|
+
promptVersion: PromptVersion;
|
|
3125
|
+
input?: SchemaFunction<TInput>;
|
|
3126
|
+
output?: SchemaFunction<TOutput>;
|
|
1212
3127
|
};
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
readonly
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
readonly
|
|
1236
|
-
readonly
|
|
1237
|
-
}
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
|
|
1323
|
-
|
|
1324
|
-
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
|
|
1335
|
-
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
custom<O>(fn?: (data: unknown) => unknown, _params?: string | _zod.core.$ZodCustomParams | undefined): _zod.ZodCustom<O, O>;
|
|
1349
|
-
refine<T>(fn: (arg: NoInfer<T>) => _zod.core.util.MaybeAsync<unknown>, _params?: string | _zod.core.$ZodCustomParams): _zod.core.$ZodCheck<T>;
|
|
1350
|
-
superRefine<T>(fn: (arg: T, payload: _zod.core.$RefinementCtx<T>) => void | Promise<void>): _zod.core.$ZodCheck<T>;
|
|
1351
|
-
json(params?: string | _zod.core.$ZodCustomParams): _zod.ZodJSONSchema;
|
|
1352
|
-
preprocess<A, U extends _zod.core.SomeType, B = unknown>(fn: (arg: B, ctx: _zod.core.$RefinementCtx) => A, schema: U): _zod.ZodPipe<_zod.ZodTransform<A, B>, U>;
|
|
1353
|
-
ZodType: _zod.core.$constructor<_zod.ZodType>;
|
|
1354
|
-
_ZodString: _zod.core.$constructor<_zod._ZodString>;
|
|
1355
|
-
ZodString: _zod.core.$constructor<_zod.ZodString>;
|
|
1356
|
-
ZodStringFormat: _zod.core.$constructor<_zod.ZodStringFormat>;
|
|
1357
|
-
ZodEmail: _zod.core.$constructor<_zod.ZodEmail>;
|
|
1358
|
-
ZodGUID: _zod.core.$constructor<_zod.ZodGUID>;
|
|
1359
|
-
ZodUUID: _zod.core.$constructor<_zod.ZodUUID>;
|
|
1360
|
-
ZodURL: _zod.core.$constructor<_zod.ZodURL>;
|
|
1361
|
-
ZodEmoji: _zod.core.$constructor<_zod.ZodEmoji>;
|
|
1362
|
-
ZodNanoID: _zod.core.$constructor<_zod.ZodNanoID>;
|
|
1363
|
-
ZodCUID: _zod.core.$constructor<_zod.ZodCUID>;
|
|
1364
|
-
ZodCUID2: _zod.core.$constructor<_zod.ZodCUID2>;
|
|
1365
|
-
ZodULID: _zod.core.$constructor<_zod.ZodULID>;
|
|
1366
|
-
ZodXID: _zod.core.$constructor<_zod.ZodXID>;
|
|
1367
|
-
ZodKSUID: _zod.core.$constructor<_zod.ZodKSUID>;
|
|
1368
|
-
ZodIPv4: _zod.core.$constructor<_zod.ZodIPv4>;
|
|
1369
|
-
ZodIPv6: _zod.core.$constructor<_zod.ZodIPv6>;
|
|
1370
|
-
ZodCIDRv4: _zod.core.$constructor<_zod.ZodCIDRv4>;
|
|
1371
|
-
ZodCIDRv6: _zod.core.$constructor<_zod.ZodCIDRv6>;
|
|
1372
|
-
ZodBase64: _zod.core.$constructor<_zod.ZodBase64>;
|
|
1373
|
-
ZodBase64URL: _zod.core.$constructor<_zod.ZodBase64URL>;
|
|
1374
|
-
ZodE164: _zod.core.$constructor<_zod.ZodE164>;
|
|
1375
|
-
ZodJWT: _zod.core.$constructor<_zod.ZodJWT>;
|
|
1376
|
-
ZodCustomStringFormat: _zod.core.$constructor<_zod.ZodCustomStringFormat>;
|
|
1377
|
-
ZodNumber: _zod.core.$constructor<_zod.ZodNumber>;
|
|
1378
|
-
ZodNumberFormat: _zod.core.$constructor<_zod.ZodNumberFormat>;
|
|
1379
|
-
ZodBoolean: _zod.core.$constructor<_zod.ZodBoolean>;
|
|
1380
|
-
ZodBigInt: _zod.core.$constructor<_zod.ZodBigInt>;
|
|
1381
|
-
ZodBigIntFormat: _zod.core.$constructor<_zod.ZodBigIntFormat>;
|
|
1382
|
-
ZodSymbol: _zod.core.$constructor<_zod.ZodSymbol>;
|
|
1383
|
-
ZodUndefined: _zod.core.$constructor<_zod.ZodUndefined>;
|
|
1384
|
-
undefined: typeof _zod.undefined;
|
|
1385
|
-
ZodNull: _zod.core.$constructor<_zod.ZodNull>;
|
|
1386
|
-
null: typeof _zod.null;
|
|
1387
|
-
ZodAny: _zod.core.$constructor<_zod.ZodAny>;
|
|
1388
|
-
ZodUnknown: _zod.core.$constructor<_zod.ZodUnknown>;
|
|
1389
|
-
ZodNever: _zod.core.$constructor<_zod.ZodNever>;
|
|
1390
|
-
ZodVoid: _zod.core.$constructor<_zod.ZodVoid>;
|
|
1391
|
-
void: typeof _zod.void;
|
|
1392
|
-
ZodDate: _zod.core.$constructor<_zod.ZodDate>;
|
|
1393
|
-
ZodArray: _zod.core.$constructor<_zod.ZodArray>;
|
|
1394
|
-
ZodObject: _zod.core.$constructor<_zod.ZodObject>;
|
|
1395
|
-
ZodUnion: _zod.core.$constructor<_zod.ZodUnion>;
|
|
1396
|
-
ZodDiscriminatedUnion: _zod.core.$constructor<_zod.ZodDiscriminatedUnion>;
|
|
1397
|
-
ZodIntersection: _zod.core.$constructor<_zod.ZodIntersection>;
|
|
1398
|
-
ZodTuple: _zod.core.$constructor<_zod.ZodTuple>;
|
|
1399
|
-
ZodRecord: _zod.core.$constructor<_zod.ZodRecord>;
|
|
1400
|
-
ZodMap: _zod.core.$constructor<_zod.ZodMap>;
|
|
1401
|
-
ZodSet: _zod.core.$constructor<_zod.ZodSet>;
|
|
1402
|
-
ZodEnum: _zod.core.$constructor<_zod.ZodEnum>;
|
|
1403
|
-
enum: typeof _zod.enum;
|
|
1404
|
-
ZodLiteral: _zod.core.$constructor<_zod.ZodLiteral>;
|
|
1405
|
-
ZodFile: _zod.core.$constructor<_zod.ZodFile>;
|
|
1406
|
-
ZodTransform: _zod.core.$constructor<_zod.ZodTransform>;
|
|
1407
|
-
ZodOptional: _zod.core.$constructor<_zod.ZodOptional>;
|
|
1408
|
-
ZodNullable: _zod.core.$constructor<_zod.ZodNullable>;
|
|
1409
|
-
ZodDefault: _zod.core.$constructor<_zod.ZodDefault>;
|
|
1410
|
-
ZodPrefault: _zod.core.$constructor<_zod.ZodPrefault>;
|
|
1411
|
-
ZodNonOptional: _zod.core.$constructor<_zod.ZodNonOptional>;
|
|
1412
|
-
ZodSuccess: _zod.core.$constructor<_zod.ZodSuccess>;
|
|
1413
|
-
ZodCatch: _zod.core.$constructor<_zod.ZodCatch>;
|
|
1414
|
-
catch: typeof _zod.catch;
|
|
1415
|
-
ZodNaN: _zod.core.$constructor<_zod.ZodNaN>;
|
|
1416
|
-
ZodPipe: _zod.core.$constructor<_zod.ZodPipe>;
|
|
1417
|
-
ZodCodec: _zod.core.$constructor<_zod.ZodCodec>;
|
|
1418
|
-
ZodReadonly: _zod.core.$constructor<_zod.ZodReadonly>;
|
|
1419
|
-
ZodTemplateLiteral: _zod.core.$constructor<_zod.ZodTemplateLiteral>;
|
|
1420
|
-
ZodLazy: _zod.core.$constructor<_zod.ZodLazy>;
|
|
1421
|
-
ZodPromise: _zod.core.$constructor<_zod.ZodPromise>;
|
|
1422
|
-
ZodFunction: _zod.core.$constructor<_zod.ZodFunction>;
|
|
1423
|
-
function: typeof _zod._function;
|
|
1424
|
-
ZodCustom: _zod.core.$constructor<_zod.ZodCustom>;
|
|
1425
|
-
instanceof: typeof _zod.instanceof;
|
|
1426
|
-
stringbool: (_params?: string | _zod.core.$ZodStringBoolParams) => _zod.ZodCodec<_zod.ZodString, _zod.ZodBoolean>;
|
|
1427
|
-
lt: typeof _zod.core._lt;
|
|
1428
|
-
lte: typeof _zod.core._lte;
|
|
1429
|
-
gt: typeof _zod.core._gt;
|
|
1430
|
-
gte: typeof _zod.core._gte;
|
|
1431
|
-
positive: typeof _zod.core._positive;
|
|
1432
|
-
negative: typeof _zod.core._negative;
|
|
1433
|
-
nonpositive: typeof _zod.core._nonpositive;
|
|
1434
|
-
nonnegative: typeof _zod.core._nonnegative;
|
|
1435
|
-
multipleOf: typeof _zod.core._multipleOf;
|
|
1436
|
-
maxSize: typeof _zod.core._maxSize;
|
|
1437
|
-
minSize: typeof _zod.core._minSize;
|
|
1438
|
-
size: typeof _zod.core._size;
|
|
1439
|
-
maxLength: typeof _zod.core._maxLength;
|
|
1440
|
-
minLength: typeof _zod.core._minLength;
|
|
1441
|
-
length: typeof _zod.core._length;
|
|
1442
|
-
regex: typeof _zod.core._regex;
|
|
1443
|
-
lowercase: typeof _zod.core._lowercase;
|
|
1444
|
-
uppercase: typeof _zod.core._uppercase;
|
|
1445
|
-
includes: typeof _zod.core._includes;
|
|
1446
|
-
startsWith: typeof _zod.core._startsWith;
|
|
1447
|
-
endsWith: typeof _zod.core._endsWith;
|
|
1448
|
-
property: typeof _zod.core._property;
|
|
1449
|
-
mime: typeof _zod.core._mime;
|
|
1450
|
-
overwrite: typeof _zod.core._overwrite;
|
|
1451
|
-
normalize: typeof _zod.core._normalize;
|
|
1452
|
-
trim: typeof _zod.core._trim;
|
|
1453
|
-
toLowerCase: typeof _zod.core._toLowerCase;
|
|
1454
|
-
toUpperCase: typeof _zod.core._toUpperCase;
|
|
1455
|
-
ZodError: _zod.core.$constructor<ZodError>;
|
|
1456
|
-
ZodRealError: _zod.core.$constructor<ZodError>;
|
|
1457
|
-
parse: <T extends _zod.core.$ZodType>(schema: T, value: unknown, _ctx?: _zod.core.ParseContext<_zod.core.$ZodIssue>, _params?: {
|
|
1458
|
-
callee?: _zod.core.util.AnyFunc;
|
|
1459
|
-
Err?: _zod.core.$ZodErrorClass;
|
|
1460
|
-
}) => _zod.core.output<T>;
|
|
1461
|
-
parseAsync: <T extends _zod.core.$ZodType>(schema: T, value: unknown, _ctx?: _zod.core.ParseContext<_zod.core.$ZodIssue>, _params?: {
|
|
1462
|
-
callee?: _zod.core.util.AnyFunc;
|
|
1463
|
-
Err?: _zod.core.$ZodErrorClass;
|
|
1464
|
-
}) => Promise<_zod.core.output<T>>;
|
|
1465
|
-
safeParse: <T extends _zod.core.$ZodType>(schema: T, value: unknown, _ctx?: _zod.core.ParseContext<_zod.core.$ZodIssue>) => _zod.ZodSafeParseResult<_zod.core.output<T>>;
|
|
1466
|
-
safeParseAsync: <T extends _zod.core.$ZodType>(schema: T, value: unknown, _ctx?: _zod.core.ParseContext<_zod.core.$ZodIssue>) => Promise<_zod.ZodSafeParseResult<_zod.core.output<T>>>;
|
|
1467
|
-
encode: <T extends _zod.core.$ZodType>(schema: T, value: _zod.core.output<T>, _ctx?: _zod.core.ParseContext<_zod.core.$ZodIssue>) => _zod.core.input<T>;
|
|
1468
|
-
decode: <T extends _zod.core.$ZodType>(schema: T, value: _zod.core.input<T>, _ctx?: _zod.core.ParseContext<_zod.core.$ZodIssue>) => _zod.core.output<T>;
|
|
1469
|
-
encodeAsync: <T extends _zod.core.$ZodType>(schema: T, value: _zod.core.output<T>, _ctx? /**
|
|
1470
|
-
* Unique identifier for this prompt version.
|
|
1471
|
-
*/: _zod.core.ParseContext<_zod.core.$ZodIssue>) => Promise<_zod.core.input<T>>;
|
|
1472
|
-
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>>;
|
|
1473
|
-
safeEncode: <T extends _zod.core.$ZodType>(schema: T, value: _zod.core.output<T>, _ctx? /**
|
|
1474
|
-
* Variables available in this prompt version.
|
|
1475
|
-
*/: _zod.core.ParseContext<_zod.core.$ZodIssue>) => _zod.ZodSafeParseResult<_zod.core.input<T>>;
|
|
1476
|
-
safeDecode: <T extends _zod.core.$ZodType>(schema: T, value: _zod.core.input<T>, _ctx? /**
|
|
1477
|
-
* Configuration settings for this prompt version.
|
|
1478
|
-
*/: _zod.core.ParseContext<_zod.core.$ZodIssue>) => _zod.ZodSafeParseResult<_zod.core.output<T>>;
|
|
1479
|
-
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>>>;
|
|
1480
|
-
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>>>;
|
|
1481
|
-
setErrorMap(map: _zod.core.$ZodErrorMap): void;
|
|
1482
|
-
getErrorMap(): _zod.core.$ZodErrorMap<_zod.core.$ZodIssue> | undefined;
|
|
1483
|
-
ZodIssueCode: {
|
|
1484
|
-
readonly invalid_type: "invalid_type";
|
|
1485
|
-
readonly too_big: "too_big";
|
|
1486
|
-
readonly too_small: "too_small";
|
|
1487
|
-
readonly invalid_format: "invalid_format";
|
|
1488
|
-
readonly not_multiple_of: "not_multiple_of";
|
|
1489
|
-
readonly unrecognized_keys: "unrecognized_keys";
|
|
1490
|
-
readonly invalid_union: "invalid_union";
|
|
1491
|
-
readonly invalid_key: "invalid_key";
|
|
1492
|
-
readonly invalid_element: "invalid_element";
|
|
1493
|
-
readonly invalid_value: "invalid_value";
|
|
1494
|
-
readonly custom: "custom";
|
|
1495
|
-
};
|
|
1496
|
-
ZodFirstPartyTypeKind: typeof _zod.ZodFirstPartyTypeKind;
|
|
3128
|
+
/**
|
|
3129
|
+
* Zod schema for task list filtering options.
|
|
3130
|
+
*
|
|
3131
|
+
* Filters tasks by various criteria including ID, name, status, and timestamps.
|
|
3132
|
+
* Date ranges can be specified using `since` and `until` fields.
|
|
3133
|
+
*/
|
|
3134
|
+
declare const TaskListFilters: z.ZodPipe<z.ZodObject<{
|
|
3135
|
+
id: z.ZodOptional<z.ZodArray<z.ZodUUID>>;
|
|
3136
|
+
name: z.ZodOptional<z.ZodString>;
|
|
3137
|
+
status: z.ZodOptional<z.ZodArray<z.ZodEnum<{
|
|
3138
|
+
created: "created";
|
|
3139
|
+
failed: "failed";
|
|
3140
|
+
running: "running";
|
|
3141
|
+
validating: "validating";
|
|
3142
|
+
completed: "completed";
|
|
3143
|
+
cancelled: "cancelled";
|
|
3144
|
+
}>>>;
|
|
3145
|
+
approvedAt: z.ZodOptional<z.ZodObject<{
|
|
3146
|
+
since: z.ZodOptional<z.ZodUnion<readonly [z.ZodPipe<z.ZodDate, z.ZodTransform<string, Date>>, z.ZodISODateTime]>>;
|
|
3147
|
+
until: z.ZodOptional<z.ZodUnion<readonly [z.ZodPipe<z.ZodDate, z.ZodTransform<string, Date>>, z.ZodISODateTime]>>;
|
|
3148
|
+
}, z.core.$strip>>;
|
|
3149
|
+
createdAt: z.ZodOptional<z.ZodObject<{
|
|
3150
|
+
since: z.ZodOptional<z.ZodUnion<readonly [z.ZodPipe<z.ZodDate, z.ZodTransform<string, Date>>, z.ZodISODateTime]>>;
|
|
3151
|
+
until: z.ZodOptional<z.ZodUnion<readonly [z.ZodPipe<z.ZodDate, z.ZodTransform<string, Date>>, z.ZodISODateTime]>>;
|
|
3152
|
+
}, z.core.$strip>>;
|
|
3153
|
+
updatedAt: z.ZodOptional<z.ZodObject<{
|
|
3154
|
+
since: z.ZodOptional<z.ZodUnion<readonly [z.ZodPipe<z.ZodDate, z.ZodTransform<string, Date>>, z.ZodISODateTime]>>;
|
|
3155
|
+
until: z.ZodOptional<z.ZodUnion<readonly [z.ZodPipe<z.ZodDate, z.ZodTransform<string, Date>>, z.ZodISODateTime]>>;
|
|
3156
|
+
}, z.core.$strip>>;
|
|
3157
|
+
approvedBy: z.ZodOptional<z.ZodString>;
|
|
3158
|
+
createdBy: z.ZodOptional<z.ZodString>;
|
|
3159
|
+
completionRunId: z.ZodOptional<z.ZodUUID>;
|
|
3160
|
+
promptVersionId: z.ZodOptional<z.ZodUUID>;
|
|
3161
|
+
}, z.core.$loose>, z.ZodTransform<{
|
|
3162
|
+
id?: string[] | undefined;
|
|
3163
|
+
status?: ("created" | "failed" | "running" | "validating" | "completed" | "cancelled")[] | undefined;
|
|
3164
|
+
approvedBy?: string | undefined;
|
|
3165
|
+
createdBy?: string | undefined;
|
|
3166
|
+
completionRunId?: string | undefined;
|
|
3167
|
+
promptVersionId?: string | undefined;
|
|
3168
|
+
updatedAtSince?: string | undefined;
|
|
3169
|
+
updatedAtUntil?: string | undefined;
|
|
3170
|
+
createdAtSince?: string | undefined;
|
|
3171
|
+
createdAtUntil?: string | undefined;
|
|
3172
|
+
approvedAtSince?: string | undefined;
|
|
3173
|
+
approvedAtUntil?: string | undefined;
|
|
3174
|
+
taskName: string | undefined;
|
|
3175
|
+
}, {
|
|
3176
|
+
[x: string]: unknown;
|
|
3177
|
+
id?: string[] | undefined;
|
|
3178
|
+
name?: string | undefined;
|
|
3179
|
+
status?: ("created" | "failed" | "running" | "validating" | "completed" | "cancelled")[] | undefined;
|
|
3180
|
+
approvedAt?: {
|
|
3181
|
+
since?: string | undefined;
|
|
3182
|
+
until?: string | undefined;
|
|
3183
|
+
} | undefined;
|
|
3184
|
+
createdAt?: {
|
|
3185
|
+
since?: string | undefined;
|
|
3186
|
+
until?: string | undefined;
|
|
3187
|
+
} | undefined;
|
|
3188
|
+
updatedAt?: {
|
|
3189
|
+
since?: string | undefined;
|
|
3190
|
+
until?: string | undefined;
|
|
3191
|
+
} | undefined;
|
|
3192
|
+
approvedBy?: string | undefined;
|
|
3193
|
+
createdBy?: string | undefined;
|
|
3194
|
+
completionRunId?: string | undefined;
|
|
3195
|
+
promptVersionId?: string | undefined;
|
|
3196
|
+
}>>;
|
|
3197
|
+
/**
|
|
3198
|
+
* Type definition for task list filters (input form).
|
|
3199
|
+
*
|
|
3200
|
+
* @see {@link TaskListFilters} for the Zod schema
|
|
3201
|
+
*/
|
|
3202
|
+
type TaskListFilters = z.input<typeof TaskListFilters>;
|
|
3203
|
+
/**
|
|
3204
|
+
* Zod schema for task list pagination and sorting options.
|
|
3205
|
+
*
|
|
3206
|
+
* Controls the number of results, offset, and sort order.
|
|
3207
|
+
*/
|
|
3208
|
+
declare const TaskListOptions: z.ZodPipe<z.ZodObject<{
|
|
3209
|
+
limit: z.ZodOptional<z.ZodNumber>;
|
|
3210
|
+
offset: z.ZodOptional<z.ZodNumber>;
|
|
3211
|
+
order: z.ZodOptional<z.ZodObject<{
|
|
3212
|
+
by: z.ZodEnum<{
|
|
3213
|
+
name: "name";
|
|
3214
|
+
status: "status";
|
|
3215
|
+
reference: "reference";
|
|
3216
|
+
approvedAt: "approvedAt";
|
|
3217
|
+
createdAt: "createdAt";
|
|
3218
|
+
updatedAt: "updatedAt";
|
|
3219
|
+
}>;
|
|
3220
|
+
direction: z.ZodEnum<{
|
|
3221
|
+
asc: "asc";
|
|
3222
|
+
desc: "desc";
|
|
3223
|
+
}>;
|
|
3224
|
+
}, z.core.$strip>>;
|
|
3225
|
+
}, z.core.$loose>, z.ZodTransform<{
|
|
3226
|
+
limit?: number | undefined;
|
|
3227
|
+
offset?: number | undefined;
|
|
3228
|
+
orderBy: "name" | "status" | "reference" | "approvedAt" | "createdAt" | "updatedAt" | undefined;
|
|
3229
|
+
orderDirection: "asc" | "desc" | undefined;
|
|
3230
|
+
}, {
|
|
3231
|
+
[x: string]: unknown;
|
|
3232
|
+
limit?: number | undefined;
|
|
3233
|
+
offset?: number | undefined;
|
|
3234
|
+
order?: {
|
|
3235
|
+
by: "name" | "status" | "reference" | "approvedAt" | "createdAt" | "updatedAt";
|
|
3236
|
+
direction: "asc" | "desc";
|
|
3237
|
+
} | undefined;
|
|
3238
|
+
}>>;
|
|
3239
|
+
/**
|
|
3240
|
+
* Type definition for task list options (input form).
|
|
3241
|
+
*
|
|
3242
|
+
* @see {@link TaskListOptions} for the Zod schema
|
|
3243
|
+
*/
|
|
3244
|
+
type TaskListOptions = z.input<typeof TaskListOptions>;
|
|
3245
|
+
/**
|
|
3246
|
+
* Metadata returned with task list queries, including pagination information.
|
|
3247
|
+
*/
|
|
3248
|
+
type TaskListMeta = {
|
|
3249
|
+
/** Total number of tasks matching the filter criteria */
|
|
3250
|
+
totalCount: number;
|
|
3251
|
+
/** Maximum number of tasks returned per page */
|
|
3252
|
+
limit: number;
|
|
3253
|
+
/** Starting position in the result set */
|
|
3254
|
+
offset: number;
|
|
3255
|
+
/** Current page number (1-indexed) */
|
|
3256
|
+
currentPage: number;
|
|
3257
|
+
/** Total number of pages available */
|
|
3258
|
+
totalPages: number;
|
|
3259
|
+
/** The reference number of the last task in the current page */
|
|
3260
|
+
lastReference: number;
|
|
3261
|
+
/** Navigation links for pagination */
|
|
3262
|
+
links: Links;
|
|
1497
3263
|
};
|
|
1498
|
-
|
|
1499
|
-
|
|
1500
|
-
|
|
1501
|
-
type
|
|
1502
|
-
|
|
1503
|
-
|
|
3264
|
+
/**
|
|
3265
|
+
* Parameters included in pagination links.
|
|
3266
|
+
*/
|
|
3267
|
+
type LinkParams = {
|
|
3268
|
+
/** The workstation application ID */
|
|
3269
|
+
promptApplicationId: string;
|
|
3270
|
+
/** Number of items per page */
|
|
3271
|
+
limit: number;
|
|
3272
|
+
/** Starting offset for the page */
|
|
3273
|
+
offset: number;
|
|
1504
3274
|
};
|
|
1505
3275
|
/**
|
|
1506
|
-
*
|
|
3276
|
+
* Navigation links for paginated task lists.
|
|
3277
|
+
*/
|
|
3278
|
+
type Links = {
|
|
3279
|
+
/** Parameters for the first page */
|
|
3280
|
+
first: LinkParams;
|
|
3281
|
+
/** Parameters for the last page */
|
|
3282
|
+
last: LinkParams;
|
|
3283
|
+
/** Parameters for the next page, or null if on last page */
|
|
3284
|
+
next: LinkParams | null;
|
|
3285
|
+
/** Parameters for the previous page, or null if on first page */
|
|
3286
|
+
previous: LinkParams | null;
|
|
3287
|
+
};
|
|
3288
|
+
/**
|
|
3289
|
+
* Options for retrieving a workstation instance.
|
|
3290
|
+
*/
|
|
3291
|
+
type WorkstationGetOptions<TInput extends ZodTypeOrRecord, TOutput extends ZodTypeOrRecord> = Omit<WorkstationOptions<TInput, TOutput>, 'client' | 'promptVersion'> & {
|
|
3292
|
+
/** Whether to skip schema validation against the server configuration. Defaults to false. */
|
|
3293
|
+
skipSchemaValidation?: boolean;
|
|
3294
|
+
};
|
|
3295
|
+
/**
|
|
3296
|
+
* Represents a workstation (prompt application) in the Tela platform.
|
|
1507
3297
|
*
|
|
1508
|
-
*
|
|
1509
|
-
*
|
|
3298
|
+
* A Workstation enables creating and managing tasks (async workflow executions)
|
|
3299
|
+
* with input/output schema validation using Zod.
|
|
1510
3300
|
*
|
|
1511
|
-
* @
|
|
3301
|
+
* @template TInput - Zod schema type for task input variables
|
|
3302
|
+
* @template TOutput - Zod schema type for task output results
|
|
1512
3303
|
*
|
|
1513
|
-
* @
|
|
1514
|
-
*
|
|
3304
|
+
* @example
|
|
3305
|
+
* ```typescript
|
|
3306
|
+
* // Get a workstation with schemas
|
|
3307
|
+
* const workstation = await tela.workstation.get({
|
|
3308
|
+
* applicationId: 'app-id',
|
|
3309
|
+
* input: schema => schema.object({
|
|
3310
|
+
* query: schema.string(),
|
|
3311
|
+
* }),
|
|
3312
|
+
* output: schema => schema.object({
|
|
3313
|
+
* result: schema.string(),
|
|
3314
|
+
* }),
|
|
3315
|
+
* })
|
|
3316
|
+
*
|
|
3317
|
+
* // Create a task
|
|
3318
|
+
* const task = await workstation.createTask({ query: 'test' })
|
|
3319
|
+
*
|
|
3320
|
+
* // Get the result
|
|
3321
|
+
* const result = await task.result
|
|
3322
|
+
* ```
|
|
1515
3323
|
*/
|
|
1516
|
-
declare class
|
|
3324
|
+
declare class Workstation<TInput extends ZodTypeOrRecord, TOutput extends ZodTypeOrRecord> {
|
|
1517
3325
|
private readonly _id;
|
|
1518
|
-
private readonly
|
|
1519
|
-
private readonly
|
|
1520
|
-
private readonly _name;
|
|
3326
|
+
private readonly _promptVersion;
|
|
3327
|
+
private readonly _client;
|
|
1521
3328
|
private readonly _input;
|
|
1522
3329
|
private readonly _output;
|
|
1523
|
-
private readonly _client;
|
|
1524
|
-
private readonly _variables;
|
|
1525
|
-
private readonly _isWorkflow;
|
|
1526
|
-
/**
|
|
1527
|
-
* Creates a new instance of the Canvas class. Usage of this constructor is not recommended.
|
|
1528
|
-
* Use the `tela.getCanvas` method instead.
|
|
1529
|
-
*
|
|
1530
|
-
* @private
|
|
1531
|
-
*/
|
|
1532
|
-
private constructor();
|
|
1533
3330
|
/**
|
|
1534
|
-
*
|
|
3331
|
+
* Creates a new Workstation instance.
|
|
1535
3332
|
*
|
|
1536
|
-
* @
|
|
1537
|
-
* @
|
|
1538
|
-
* @param options.versionId - The version ID of the canvas to get.
|
|
1539
|
-
* @param options.applicationId - The application ID of the canvas to get.
|
|
1540
|
-
* @param options.client - The client to use to make the request.
|
|
1541
|
-
* @param options.input - The input schema of the canvas to get.
|
|
1542
|
-
* @param options.output - The output schema of the canvas to get.
|
|
1543
|
-
* @returns The canvas.
|
|
3333
|
+
* Use {@link Workstation.get} instead.
|
|
3334
|
+
* @internal
|
|
1544
3335
|
*/
|
|
1545
|
-
|
|
1546
|
-
client: BaseClient;
|
|
1547
|
-
}): Promise<Canvas<TInput, TOutput>>;
|
|
3336
|
+
constructor({ client, applicationId, promptVersion, input, output }: WorkstationOptions<TInput, TOutput>);
|
|
1548
3337
|
/**
|
|
1549
|
-
*
|
|
1550
|
-
*
|
|
1551
|
-
* @returns The canvas ID.
|
|
3338
|
+
* The unique identifier for this workstation (application ID).
|
|
1552
3339
|
*/
|
|
1553
3340
|
get id(): string;
|
|
1554
3341
|
/**
|
|
1555
|
-
*
|
|
1556
|
-
*
|
|
1557
|
-
* @returns The canvas name or undefined.
|
|
3342
|
+
* The prompt version configuration for this workstation.
|
|
1558
3343
|
*/
|
|
1559
|
-
get
|
|
3344
|
+
get promptVersion(): PromptVersion;
|
|
1560
3345
|
/**
|
|
1561
|
-
*
|
|
1562
|
-
* When undefined, the latest promoted version is used.
|
|
3346
|
+
* Retrieves a workstation by application ID and optionally validates schemas.
|
|
1563
3347
|
*
|
|
1564
|
-
*
|
|
1565
|
-
*/
|
|
1566
|
-
get versionId(): string;
|
|
1567
|
-
get applicationId(): string;
|
|
1568
|
-
/**
|
|
1569
|
-
* Gets the variables of this canvas.
|
|
3348
|
+
* This is the recommended way to create a Workstation instance.
|
|
1570
3349
|
*
|
|
1571
|
-
* @
|
|
3350
|
+
* @param options - Configuration options
|
|
3351
|
+
* @param options.client - The BaseClient instance for API communication
|
|
3352
|
+
* @param options.applicationId - The unique ID of the workstation
|
|
3353
|
+
* @param options.input - Optional input schema function
|
|
3354
|
+
* @param options.output - Optional output schema function
|
|
3355
|
+
* @param options.skipSchemaValidation - Whether to skip schema validation (defaults to false)
|
|
3356
|
+
* @returns A promise that resolves to a Workstation instance
|
|
3357
|
+
*
|
|
3358
|
+
* @throws {Error} If schema validation fails (when schemas are provided and skipSchemaValidation is false)
|
|
3359
|
+
*
|
|
3360
|
+
* @example
|
|
3361
|
+
* ```typescript
|
|
3362
|
+
* const workstation = await Workstation.get({
|
|
3363
|
+
* client,
|
|
3364
|
+
* applicationId: 'app-123',
|
|
3365
|
+
* input: schema => schema.object({
|
|
3366
|
+
* query: schema.string(),
|
|
3367
|
+
* }),
|
|
3368
|
+
* output: schema => schema.object({
|
|
3369
|
+
* answer: schema.string(),
|
|
3370
|
+
* }),
|
|
3371
|
+
* })
|
|
3372
|
+
* ```
|
|
1572
3373
|
*/
|
|
1573
|
-
get
|
|
3374
|
+
static get<TInput extends ZodTypeOrRecord, TOutput extends ZodTypeOrRecord>(options: WorkstationGetOptions<TInput, TOutput> & {
|
|
3375
|
+
client: BaseClient;
|
|
3376
|
+
}): Promise<Workstation<TInput, TOutput>>;
|
|
1574
3377
|
/**
|
|
1575
|
-
*
|
|
3378
|
+
* Creates a new task for this workstation and returns a promise-like object.
|
|
1576
3379
|
*
|
|
1577
|
-
*
|
|
3380
|
+
* The returned object can be awaited directly to get the Task instance, or you can
|
|
3381
|
+
* access `.result` to get the final task output directly.
|
|
3382
|
+
*
|
|
3383
|
+
* @param variables - Input variables for the task (must match the input schema)
|
|
3384
|
+
* @param params - Optional task parameters (label, tags, skipResultValidation)
|
|
3385
|
+
* @returns A promise-like object that resolves to the Task instance
|
|
3386
|
+
*
|
|
3387
|
+
* @example
|
|
3388
|
+
* ```typescript
|
|
3389
|
+
* // Get the task instance
|
|
3390
|
+
* const task = await workstation.createTask({ query: 'test' })
|
|
3391
|
+
*
|
|
3392
|
+
* // Or get the result directly
|
|
3393
|
+
* const result = await workstation.createTask({ query: 'test' }).result
|
|
3394
|
+
* ```
|
|
1578
3395
|
*/
|
|
1579
|
-
|
|
3396
|
+
createTask(variables: z.input<TInput>, params?: TaskParams & {
|
|
3397
|
+
skipResultValidation?: boolean;
|
|
3398
|
+
}): TaskPromiseLike<TInput, TOutput>;
|
|
1580
3399
|
/**
|
|
1581
|
-
*
|
|
1582
|
-
* This is true if an application ID is provided.
|
|
3400
|
+
* Retrieves an existing task by its ID.
|
|
1583
3401
|
*
|
|
1584
|
-
*
|
|
3402
|
+
* This is useful for resuming monitoring of a task that was created earlier.
|
|
3403
|
+
*
|
|
3404
|
+
* @param id - The task ID to retrieve
|
|
3405
|
+
* @param options - Optional configuration
|
|
3406
|
+
* @param options.skipResultValidation - Whether to skip output validation
|
|
3407
|
+
* @returns A promise that resolves to the Task instance
|
|
3408
|
+
*
|
|
3409
|
+
* @example
|
|
3410
|
+
* ```typescript
|
|
3411
|
+
* const task = await workstation.getTask('task-id')
|
|
3412
|
+
*
|
|
3413
|
+
* // Set up event listeners
|
|
3414
|
+
* task.on('statusChange', (status) => console.log('Status:', status))
|
|
3415
|
+
* task.on('success', (result) => console.log('Result:', result))
|
|
3416
|
+
*
|
|
3417
|
+
* // Start polling
|
|
3418
|
+
* task.poll()
|
|
3419
|
+
* ```
|
|
1585
3420
|
*/
|
|
1586
|
-
|
|
3421
|
+
getTask(id: string, options?: {
|
|
3422
|
+
skipResultValidation?: boolean;
|
|
3423
|
+
}): Promise<Task<TInput, TOutput>>;
|
|
1587
3424
|
/**
|
|
1588
|
-
* Validates and parses input variables using the
|
|
3425
|
+
* Validates and parses input variables using the workstation input schema.
|
|
1589
3426
|
*
|
|
1590
3427
|
* @param variables - Raw input variables to validate.
|
|
1591
3428
|
* @returns Parsed and validated variables.
|
|
@@ -1593,84 +3430,82 @@ declare class Canvas<TInput extends ZodTypeOrRecord, TOutput extends ZodTypeOrRe
|
|
|
1593
3430
|
*/
|
|
1594
3431
|
private parseVariables;
|
|
1595
3432
|
/**
|
|
1596
|
-
*
|
|
1597
|
-
*
|
|
3433
|
+
* Processes variables and uploads any TelaFile instances to the server.
|
|
3434
|
+
* Replaces TelaFile objects with their uploaded URLs while preserving other values.
|
|
1598
3435
|
*
|
|
1599
|
-
*
|
|
1600
|
-
|
|
1601
|
-
|
|
1602
|
-
|
|
3436
|
+
* @returns A promise resolving to the processed variables object.
|
|
3437
|
+
*/
|
|
3438
|
+
private resolveVariables;
|
|
3439
|
+
/**
|
|
3440
|
+
* Lists tasks for this workstation with optional filtering and pagination.
|
|
1603
3441
|
*
|
|
1604
|
-
*
|
|
1605
|
-
*
|
|
1606
|
-
*
|
|
3442
|
+
* Returns a page of tasks matching the specified filters, along with metadata
|
|
3443
|
+
* for pagination.
|
|
3444
|
+
*
|
|
3445
|
+
* @param params - Query parameters
|
|
3446
|
+
* @param params.filters - Optional filters to apply (ID, name, status, dates, etc.)
|
|
3447
|
+
* @param params.options - Optional pagination and sorting options
|
|
3448
|
+
* @param params.rawQuery - Raw query object (internal use, overrides filters/options)
|
|
3449
|
+
* @returns A promise that resolves to an object containing tasks and pagination metadata
|
|
1607
3450
|
*
|
|
1608
3451
|
* @example
|
|
1609
3452
|
* ```typescript
|
|
1610
|
-
* //
|
|
1611
|
-
* const
|
|
1612
|
-
*
|
|
1613
|
-
*
|
|
1614
|
-
*
|
|
1615
|
-
* const result = await execution.result;
|
|
1616
|
-
*
|
|
1617
|
-
* // Asynchronous execution with polling
|
|
1618
|
-
* const result = await canvas.execute(
|
|
1619
|
-
* { query: "Hello" },
|
|
1620
|
-
* { async: true, pollingInterval: 500 }
|
|
1621
|
-
* ).result;
|
|
1622
|
-
*
|
|
1623
|
-
* // Streaming execution
|
|
1624
|
-
* for await (const chunk of canvas.execute(
|
|
1625
|
-
* { query: "Hello" },
|
|
1626
|
-
* { stream: true }
|
|
1627
|
-
* ).result) {
|
|
1628
|
-
* console.log(chunk);
|
|
1629
|
-
* }
|
|
3453
|
+
* // Get first 10 completed tasks
|
|
3454
|
+
* const { tasks, meta } = await workstation.listTasks({
|
|
3455
|
+
* filters: { status: ['completed'] },
|
|
3456
|
+
* options: { limit: 10, offset: 0 },
|
|
3457
|
+
* })
|
|
1630
3458
|
*
|
|
1631
|
-
* //
|
|
1632
|
-
* const
|
|
1633
|
-
*
|
|
1634
|
-
*
|
|
1635
|
-
*
|
|
3459
|
+
* // Sort by creation date
|
|
3460
|
+
* const { tasks, meta } = await workstation.listTasks({
|
|
3461
|
+
* options: {
|
|
3462
|
+
* order: { by: 'createdAt', direction: 'desc' },
|
|
3463
|
+
* limit: 20,
|
|
3464
|
+
* },
|
|
3465
|
+
* })
|
|
1636
3466
|
* ```
|
|
1637
3467
|
*/
|
|
1638
|
-
|
|
1639
|
-
|
|
1640
|
-
|
|
3468
|
+
listTasks({ filters, options, rawQuery }: {
|
|
3469
|
+
filters?: TaskListFilters;
|
|
3470
|
+
options?: TaskListOptions;
|
|
3471
|
+
rawQuery?: Record<string, any>;
|
|
3472
|
+
}): Promise<{
|
|
3473
|
+
tasks: Task<TInput, TOutput>[];
|
|
3474
|
+
meta: TaskListMeta;
|
|
3475
|
+
}>;
|
|
1641
3476
|
/**
|
|
1642
|
-
*
|
|
3477
|
+
* Asynchronously iterates through all tasks matching the specified filters.
|
|
1643
3478
|
*
|
|
1644
|
-
* This
|
|
1645
|
-
*
|
|
1646
|
-
* ones with persistent UUIDs on the server.
|
|
3479
|
+
* This generator automatically handles pagination, fetching additional pages
|
|
3480
|
+
* as needed. Each iteration yields a task and the current page metadata.
|
|
1647
3481
|
*
|
|
1648
|
-
* @param
|
|
1649
|
-
* @param
|
|
1650
|
-
* @param options
|
|
1651
|
-
* @
|
|
1652
|
-
* @throws {InvalidExecutionModeError} If the provided ID is not a valid UUID.
|
|
1653
|
-
* @returns A promise resolving to a CanvasExecution instance with the fetched state.
|
|
3482
|
+
* @param params - Query parameters
|
|
3483
|
+
* @param params.filters - Optional filters to apply (ID, name, status, dates, etc.)
|
|
3484
|
+
* @param params.options - Optional initial pagination and sorting options
|
|
3485
|
+
* @yields A tuple of [task, metadata] for each task
|
|
1654
3486
|
*
|
|
1655
3487
|
* @example
|
|
1656
3488
|
* ```typescript
|
|
1657
|
-
* //
|
|
1658
|
-
*
|
|
1659
|
-
*
|
|
1660
|
-
*
|
|
1661
|
-
*
|
|
1662
|
-
*
|
|
1663
|
-
*
|
|
3489
|
+
* // Iterate through all pending tasks
|
|
3490
|
+
* for await (const [task, meta] of workstation.iterateTasks({
|
|
3491
|
+
* filters: { status: ['pending'] },
|
|
3492
|
+
* })) {
|
|
3493
|
+
* console.log(`Task ${task.id}: ${task.status}`)
|
|
3494
|
+
* console.log(`Page ${meta.currentPage} of ${meta.totalPages}`)
|
|
3495
|
+
* }
|
|
1664
3496
|
*
|
|
1665
|
-
* //
|
|
1666
|
-
*
|
|
1667
|
-
*
|
|
3497
|
+
* // Process tasks in batches
|
|
3498
|
+
* for await (const [task, meta] of workstation.iterateTasks({
|
|
3499
|
+
* options: { limit: 50 },
|
|
3500
|
+
* })) {
|
|
3501
|
+
* await processTask(task)
|
|
3502
|
+
* }
|
|
1668
3503
|
* ```
|
|
1669
3504
|
*/
|
|
1670
|
-
|
|
1671
|
-
|
|
1672
|
-
|
|
1673
|
-
}):
|
|
3505
|
+
iterateTasks({ filters, options }: {
|
|
3506
|
+
filters?: TaskListFilters;
|
|
3507
|
+
options?: TaskListOptions;
|
|
3508
|
+
}): AsyncGenerator<readonly [Task<TInput, TOutput>, TaskListMeta], void, unknown>;
|
|
1674
3509
|
}
|
|
1675
3510
|
|
|
1676
3511
|
/**
|
|
@@ -1769,7 +3604,10 @@ declare class TelaSDK extends BaseClient {
|
|
|
1769
3604
|
* ```
|
|
1770
3605
|
*/
|
|
1771
3606
|
canvas: {
|
|
1772
|
-
get: <TInput extends z.ZodType | Record<string, unknown> = Record<string, unknown>, TOutput extends z.ZodType | Record<string, unknown> = Record<string, unknown>>(options: CanvasGetOptions<TInput, TOutput>) => Promise<Canvas<TInput, TOutput>>;
|
|
3607
|
+
get: <TInput extends z$1.ZodType | Record<string, unknown> = Record<string, unknown>, TOutput extends z$1.ZodType | Record<string, unknown> = Record<string, unknown>>(options: CanvasGetOptions<TInput, TOutput>) => Promise<Canvas<TInput, TOutput>>;
|
|
3608
|
+
};
|
|
3609
|
+
workstation: {
|
|
3610
|
+
get: <TInput extends z$1.ZodType | Record<string, unknown> = Record<string, unknown>, TOutput extends z$1.ZodType | Record<string, unknown> = Record<string, unknown>>(options: WorkstationGetOptions<TInput, TOutput>) => Promise<Workstation<TInput, TOutput>>;
|
|
1773
3611
|
};
|
|
1774
3612
|
static TelaSDK: typeof TelaSDK;
|
|
1775
3613
|
static DEFAULT_TIMEOUT: number;
|
|
@@ -1807,6 +3645,10 @@ declare class TelaSDK extends BaseClient {
|
|
|
1807
3645
|
static MissingApiKeyOrJWTError: typeof MissingApiKeyOrJWTError;
|
|
1808
3646
|
/** Thrown when both an API key and a JWT are provided. */
|
|
1809
3647
|
static ConflictApiKeyAndJWTError: typeof ConflictApiKeyAndJWTError;
|
|
3648
|
+
/** Thrown when a canvas execution fails on the server. */
|
|
3649
|
+
static ExecutionFailedError: typeof ExecutionFailedError;
|
|
3650
|
+
/** Thrown when a workstation task fails on the server. */
|
|
3651
|
+
static TaskFailedError: typeof TaskFailedError;
|
|
1810
3652
|
}
|
|
1811
3653
|
/**
|
|
1812
3654
|
* Creates a new instance of the TelaSDK.
|
|
@@ -1816,4 +3658,4 @@ declare class TelaSDK extends BaseClient {
|
|
|
1816
3658
|
*/
|
|
1817
3659
|
declare function createTelaClient(opts: TelaSDKOptions): TelaSDK;
|
|
1818
3660
|
|
|
1819
|
-
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 };
|
|
3661
|
+
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, TaskFailedError, TelaError, TelaFile, type TelaFileInput, type TelaFileOptions, type TelaFileOptionsWithMimeType, TelaFileSchema, TelaSDK, type TelaSDKOptions, UnprocessableEntityError, UserAbortError, createTelaClient, isTelaFile, isTelaFileArray, toError };
|