@meistrari/tela-sdk-js 1.0.2 → 2.1.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.d.cts CHANGED
@@ -1,3 +1,16 @@
1
+ import * as _zod from 'zod';
2
+ import _zod__default, { ZodError, z } from 'zod';
3
+ import Emittery from 'emittery';
4
+
5
+ /**
6
+ * Base HTTP client with retry logic, request/response transformation, and streaming support.
7
+ *
8
+ * This module provides the abstract BaseClient class that handles all HTTP communication
9
+ * with the Tela API, including automatic field transformation, retry logic, timeout handling,
10
+ * and Server-Sent Events streaming.
11
+ *
12
+ * @module Core
13
+ */
1
14
  type HTTPMethods = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE';
2
15
  type RequestOptions<Req = unknown | Record<string, unknown>> = {
3
16
  method?: HTTPMethods;
@@ -15,6 +28,11 @@ interface BaseClientOptions {
15
28
  maxRetries?: number;
16
29
  timeout?: number;
17
30
  }
31
+ /**
32
+ * Abstract base HTTP client with retry logic and request/response transformation.
33
+ *
34
+ * @category Client
35
+ */
18
36
  declare abstract class BaseClient {
19
37
  baseURL: string;
20
38
  maxRetries: number;
@@ -23,7 +41,8 @@ declare abstract class BaseClient {
23
41
  constructor({ baseURL, maxRetries, timeout }: BaseClientOptions);
24
42
  protected createHeaders(opts?: Record<string, string>): Headers;
25
43
  protected getUserAgent(): string;
26
- protected getAuthHeaders(): Record<string, string>;
44
+ protected abstract getAuthHeaders(): Record<string, string>;
45
+ abstract get authToken(): string;
27
46
  get<Req, Res>(path: string, opts?: RequestOptions<Req>): Promise<Res>;
28
47
  post<Req, Res>(path: string, opts?: RequestOptions<Req>): Promise<Res>;
29
48
  put<Req, Res>(path: string, opts?: RequestOptions<Req>): Promise<Res>;
@@ -45,23 +64,92 @@ declare abstract class BaseClient {
45
64
  protected stringifyQuery(query: Record<string, unknown>): string;
46
65
  }
47
66
 
67
+ /**
68
+ * Error classes and exception handling for the Tela SDK.
69
+ *
70
+ * This module provides all custom error classes used throughout the SDK,
71
+ * including API errors, authentication errors, file errors, and execution errors.
72
+ *
73
+ * @module Core
74
+ */
75
+ /**
76
+ * Base error class for all Tela SDK errors.
77
+ *
78
+ * @category Errors
79
+ */
48
80
  declare class TelaError extends Error {
49
81
  }
82
+ /**
83
+ * Thrown when both API key and JWT are provided.
84
+ *
85
+ * @category Errors
86
+ */
50
87
  declare class ConflictApiKeyAndJWTError extends TelaError {
51
88
  constructor();
52
89
  }
90
+ /**
91
+ * Thrown when neither API key nor JWT is provided.
92
+ *
93
+ * @category Errors
94
+ */
53
95
  declare class MissingApiKeyOrJWTError extends TelaError {
54
96
  constructor();
55
97
  }
98
+ /**
99
+ * Thrown when attempting to upload an empty file.
100
+ *
101
+ * @category Errors
102
+ */
56
103
  declare class EmptyFileError extends TelaError {
57
104
  constructor();
58
105
  }
106
+ /**
107
+ * Thrown when an invalid file URL is provided.
108
+ *
109
+ * @category Errors
110
+ */
59
111
  declare class InvalidFileURL extends TelaError {
60
112
  constructor(url: string);
61
113
  }
114
+ /**
115
+ * Thrown when file upload to vault storage fails.
116
+ *
117
+ * @category Errors
118
+ */
62
119
  declare class FileUploadError extends TelaError {
120
+ readonly statusCode: number;
121
+ constructor(message: string, statusCode: number);
122
+ }
123
+ /**
124
+ * Thrown when accessing execution result before execution has started.
125
+ *
126
+ * @category Errors
127
+ */
128
+ declare class ExecutionNotStartedError extends TelaError {
129
+ constructor();
130
+ }
131
+ /**
132
+ * Thrown when invalid execution mode parameters are provided.
133
+ *
134
+ * @category Errors
135
+ */
136
+ declare class InvalidExecutionModeError extends TelaError {
63
137
  constructor(message: string);
64
138
  }
139
+ /**
140
+ * Thrown when canvas execution fails on the server.
141
+ *
142
+ * @category Errors
143
+ */
144
+ declare class ExecutionFailedError extends TelaError {
145
+ readonly rawOutput: Record<string, any>;
146
+ constructor(rawOutput: Record<string, any>);
147
+ }
148
+ /**
149
+ * Base class for all API-related errors.
150
+ *
151
+ * @category Errors
152
+ */
65
153
  declare class APIError extends TelaError {
66
154
  readonly statusCode: number | undefined;
67
155
  readonly error: any;
@@ -111,11 +199,22 @@ declare class RateLimitError extends APIError {
111
199
  declare class InternalServerError extends APIError {
112
200
  readonly statusCode = 500;
113
201
  }
202
+ declare function toError(err: any): Error;
203
+
204
+ /**
205
+ * File handling module for TelaFile wrapper and file upload operations.
206
+ *
207
+ * This module provides the TelaFile class for handling various file input types
208
+ * (URLs, Blobs, Streams, Buffers, vault references) with support for MIME types,
209
+ * page ranges, and file uploads to vault storage.
210
+ *
211
+ * @module Resources
212
+ */
114
213
 
115
214
  /**
116
215
  * Configuration options for `TelaFile`.
117
216
  */
118
- type TelaFileOptions = {
217
+ type BaseTelaFileOptions = {
119
218
  /**
120
219
  * Defines the page range of the document to be processed.
121
220
  *
@@ -133,12 +232,22 @@ type TelaFileOptions = {
133
232
  * Defines the parser provider to be used for the file.
134
233
  */
135
234
  parserType?: string;
235
+ /**
236
+ * Defines the name of the file.
237
+ * If content is an instance of File or Blob, this will override the `name` property of the content.
238
+ */
239
+ name?: string;
136
240
  };
241
+ type TelaFileOptionsWithMimeType = BaseTelaFileOptions & {
242
+ mimeType: string;
243
+ };
244
+ type TelaFileOptions = BaseTelaFileOptions | TelaFileOptionsWithMimeType;
137
245
  /**
138
246
  * Represents the possible types for a file input,
139
247
  * which can be a URL string, Uint8Array, ReadableStream, ReadStream, Blob, or File.
140
248
  */
141
249
  type TelaFileInput = string | Uint8Array | ReadableStream | Blob | File;
250
+ declare function TelaFileSchema(): _zod__default.ZodCustom<TelaFile, TelaFile>;
142
251
  /**
143
252
  * Represents a file with support for various types including URLs, binary data, streams, and Blobs.
144
253
  *
@@ -148,7 +257,7 @@ type TelaFileInput = string | Uint8Array | ReadableStream | Blob | File;
148
257
  * const urlFile = new TelaFile("https://example.com/file.png", { range: { start: 0, end: 1024 } })
149
258
  *
150
259
  * // Using a Uint8Array (buffer)
151
- * const buffer = new Uint8Array([/* binary data * /])
260
+ * const buffer = new Uint8Array(['binary data...'])
152
261
  * const bufferFile = new TelaFile(buffer)
153
262
  *
154
263
  * // Using a ReadStream
@@ -172,12 +281,29 @@ type TelaFileInput = string | Uint8Array | ReadableStream | Blob | File;
172
281
  * // Using a File (in browser environments)
173
282
  * const file = new File(['file content'], 'filename.txt', { type: 'text/plain' })
174
283
  * const fileInstance = new TelaFile(file)
284
+ *
285
+ * // Using multiple files in a collection
286
+ * const files = [
287
+ * new TelaFile("https://example.com/file1.pdf", { range: [0, 1] }),
288
+ * new TelaFile("https://example.com/file2.pdf", { range: [1, 2] })
289
+ * ]
290
+ * // Pass the array of files to a variable
291
+ * const result = await tela.completions.create({
292
+ * canvasId: "your-canvas-id",
293
+ * variables: {
294
+ * documents: files
295
+ * }
296
+ * })
175
297
  * ```
298
+ *
299
+ * @category File
176
300
  */
177
301
  declare class TelaFile {
178
302
  private _file;
179
303
  private _options;
180
304
  private _size;
305
+ private _mimeType;
306
+ private _name;
181
307
  /**
182
308
  * Creates an instance of `TelaFile`.
183
309
  *
@@ -186,7 +312,10 @@ declare class TelaFile {
186
312
  * @throws {InvalidFileURL} If the provided URL is not valid.
187
313
  * @throws {EmptyFileError} If the provided file is empty.
188
314
  */
189
- constructor(file: string | Uint8Array | ReadableStream | Blob | File, options?: TelaFileOptions);
315
+ constructor(file: Blob | File | string, options?: BaseTelaFileOptions);
316
+ constructor(file: Uint8Array | ReadableStream, options: TelaFileOptionsWithMimeType);
317
+ static create(file: Blob | File | string, options?: BaseTelaFileOptions): TelaFile;
318
+ static create(file: Uint8Array | ReadableStream, options: TelaFileOptionsWithMimeType): TelaFile;
190
319
  /**
191
320
  * Retrieves the options provided during instantiation.
192
321
  *
@@ -199,12 +328,30 @@ declare class TelaFile {
199
328
  * @returns `true` if the file source is a valid URL string, otherwise `false`.
200
329
  */
201
330
  get isURL(): boolean;
331
+ /**
332
+ * Determines whether the file source is a valid Vault reference.
333
+ *
334
+ * @returns `true` if the file source is a valid Vault reference, otherwise `false`.
335
+ */
336
+ get isVaultReference(): boolean;
202
337
  /**
203
338
  * Gets the size of the file in bytes.
204
339
  *
205
340
  * @returns The size of the file if available, otherwise `null`.
206
341
  */
207
342
  get size(): number | null;
343
+ /**
344
+ * Gets the name of the file.
345
+ *
346
+ * @returns The name of the file if available, otherwise `null`.
347
+ */
348
+ get name(): string | null;
349
+ /**
350
+ * Gets the type of the file.
351
+ *
352
+ * @returns The type of the file if available, otherwise `null`.
353
+ */
354
+ get type(): string | null;
208
355
  /**
209
356
  * Retrieves the content of the file in a format suitable for uploading.
210
357
  *
@@ -229,170 +376,26 @@ declare class TelaFile {
229
376
  * @returns `true` if the URL is valid, otherwise `false`.
230
377
  */
231
378
  private isValidURL;
232
- }
233
- /**
234
- * Creates a new `TelaFile` instance from the provided file input.
235
- *
236
- * @param file - The file input to create a `TelaFile` instance from.
237
- * @returns A new `TelaFile` instance.
238
- */
239
- declare function createTelaFile(file: TelaFileInput, options?: TelaFileOptions): TelaFile;
240
-
241
- /**
242
- * Base class for all resources.
243
- */
244
- declare class Resource {
245
- protected _client: BaseClient;
246
- constructor(client: BaseClient);
247
- }
248
-
249
- /**
250
- * Represents a stream of items that can be asynchronously iterated over.
251
- */
252
- declare class Stream<Item> implements AsyncIterable<Item> {
253
- private iterator;
254
- /**
255
- * The AbortController associated with this stream.
256
- */
257
- controller: AbortController;
258
- /**
259
- * Creates a new Stream instance.
260
- *
261
- * @param iterator - A function that returns an AsyncIterator<Item>.
262
- * @param controller - The AbortController for this stream.
263
- */
264
- constructor(iterator: () => AsyncIterator<Item>, controller: AbortController);
265
- /**
266
- * Creates a Stream from a server-sent events (SSE) Response.
267
- *
268
- * @param response - The Response object containing the SSE data.
269
- * @param controller - The AbortController for this stream.
270
- * @returns A new Stream instance.
271
- * @throws {Error} If the stream is consumed more than once.
272
- * @throws {APIError} If the SSE data contains an error.
273
- */
274
- static fromSSEResponse<Item>(response: Response, controller: AbortController): Stream<Item>;
275
- /**
276
- * Creates a Stream from a newline-separated ReadableStream where each item is a JSON value.
277
- *
278
- * @param readableStream - The ReadableStream containing newline-separated JSON data.
279
- * @param controller - The AbortController for this stream.
280
- * @returns A new Stream instance.
281
- * @throws {Error} If the stream is consumed more than once.
282
- */
283
- static fromReadableStream<Item>(readableStream: ReadableStream, controller: AbortController): Stream<Item>;
284
- /**
285
- * Implements the AsyncIterable interface, allowing the Stream to be used in a for-await-of loop.
286
- *
287
- * @returns An AsyncIterator for the stream items.
288
- */
289
- [Symbol.asyncIterator](): AsyncIterator<Item>;
290
- /**
291
- * Splits the stream into two streams which can be independently read from at different speeds.
292
- *
293
- * @returns A tuple containing two new Stream instances.
294
- */
295
- tee(): [Stream<Item>, Stream<Item>];
296
379
  /**
297
- * Converts this stream to a newline-separated ReadableStream of JSON stringified values.
298
- * The resulting stream can be converted back to a Stream using `Stream.fromReadableStream()`.
380
+ * Checks if the provided string is a valid Vault reference.
299
381
  *
300
- * @returns A ReadableStream containing newline-separated JSON data.
382
+ * @param url - The Vault reference string to validate.
383
+ * @returns `true` if the Vault reference is valid, otherwise `false`.
301
384
  */
302
- toReadableStream(): ReadableStream;
385
+ private isValidVaultReference;
303
386
  }
304
387
 
305
388
  /**
306
- * Manages chat completion operations.
389
+ * Canvas execution module for managing canvas execution lifecycle and modes.
307
390
  *
308
- * Provides methods to create chat completions, handle streaming responses,
309
- * and manage file uploads associated with chat completions.
391
+ * This module handles the execution of canvas templates with support for
392
+ * synchronous, asynchronous (with polling), and streaming modes. It also
393
+ * manages file uploads and result validation.
310
394
  *
311
- * @example
312
- * ```typescript
313
- * const tela = new TelaSDK({
314
- * apiKey: 'your-api-key',
315
- * });
316
- * const response = await tela.completions.create({
317
- * canvasId: "your-canvas-id",
318
- * messages: [{ role: "user", content: "Hello!" }],
319
- * });
320
- * console.log(response.choices[0].message.content);
321
- * ```
395
+ * @module Resources
322
396
  */
323
- declare class ChatCompletions extends Resource {
324
- /**
325
- * Creates a chat completion with various input options and response formats.
326
- *
327
- * This method supports synchronous responses, streaming responses, and webhook-based asynchronous processing.
328
- *
329
- * @param body - The parameters for creating a chat completion.
330
- * @param opts - Additional request options.
331
- * @returns A Promise that resolves to either a stream of chat completion responses,
332
- * a single chat completion response, or a webhook response, depending on the input parameters.
333
- *
334
- * @example
335
- * ```typescript
336
- * // Synchronous response
337
- * const response = await tela.completions.create({
338
- * canvasId: "your-canvas-id",
339
- * messages: [{ role: "user", content: "Tell me a joke." }],
340
- * });
341
- *
342
- * // Streaming response
343
- * const stream = await tela.completions.create({
344
- * canvasId: "your-canvas-id",
345
- * messages: [{ role: "user", content: "Tell me a story." }],
346
- * stream: true,
347
- * });
348
- *
349
- * // Webhook response
350
- * const webhookResponse = await tela.completions.create({
351
- * canvasId: "your-canvas-id",
352
- * messages: [{ role: "user", content: "Generate a report." }],
353
- * webhookUrl: "https://example.com/webhook",
354
- * });
355
- * ```
356
- */
357
- create<Variables = ChatCompletionVariables, CompletionContent = string>(body: ChatCompletionCreateWebhookParams<Variables>, opts?: RequestOptions<ChatCompletionCreateParams<Variables>>): Promise<ChatCompletionWebhookResponse<CompletionContent>>;
358
- create<Variables = ChatCompletionVariables, CompletionContent = string>(body: CompletionCreateParamsNonStreaming<Variables>, opts?: RequestOptions<ChatCompletionCreateParams<Variables>>): Promise<ChatCompletionCreateResponse<CompletionContent>>;
359
- create<Variables = ChatCompletionVariables, CompletionContent = string>(body: CompletionCreateParamsStreaming<Variables>, opts?: RequestOptions<ChatCompletionCreateParams<Variables>>): Promise<Stream<ChatCompletionCreateStreamingResponse<CompletionContent>>>;
360
- create<Variables = ChatCompletionVariables, CompletionContent = string>(body: ChatCompletionCreateParamsBase<Variables>, opts?: RequestOptions<ChatCompletionCreateParams<Variables>>): Promise<Stream<ChatCompletionCreateStreamingResponse<CompletionContent>> | ChatCompletionCreateResponse<CompletionContent> | ChatCompletionWebhookResponse<CompletionContent>>;
361
- /**
362
- * Uploads a file and returns its URL and options.
363
- *
364
- * This is used internally to handle file uploads associated with chat completions.
365
- *
366
- * @param file - The TelaFile to be uploaded.
367
- * @returns A Promise that resolves to an object containing the file URL and options.
368
- * @throws {FileUploadError} If the file upload fails.
369
- *
370
- * @example
371
- * ```typescript
372
- * const file = new TelaFile({ /* file options *\/ });
373
- * const uploadedFile = await this.uploadFile(file);
374
- * console.log(uploadedFile.file_url);
375
- * ```
376
- */
377
- private uploadFile;
378
- }
379
- type ChatCompletionVariablesValue = string | number | boolean | TelaFile;
380
- /**
381
- * Represents the variables available in the canvas.
382
- * Keys are strings, and values can be strings, numbers, booleans, or TelaFile instances.
383
- */
384
- type ChatCompletionVariables = Record<string, ChatCompletionVariablesValue>;
385
- /**
386
- * Represents the processed variables with file URLs.
387
- * Similar to ChatCompletionVariables, but TelaFile instances are replaced with their URLs.
388
- */
389
- type ChatCompletionVariablesWithFileURL = Record<string, string | number | boolean | {
390
- fileUrl: string;
391
- }>;
392
- /**
393
- * Base parameters for creating a chat completion.
394
- */
395
- interface ChatCompletionCreateParamsBase<Variables = ChatCompletionVariables> {
397
+
398
+ interface BaseExecutionParams {
396
399
  /**
397
400
  * The version ID of the canvas to use for this chat completion.
398
401
  * If not provided, the latest version of the specified canvas will be used.
@@ -409,15 +412,11 @@ interface ChatCompletionCreateParamsBase<Variables = ChatCompletionVariables> {
409
412
  */
410
413
  applicationId?: string;
411
414
  /**
412
- * The URL to receive a webhook notification when the chat completion is finished.
413
- * If provided, the completion will be processed asynchronously.
414
- */
415
- webhookUrl?: string | null | undefined;
416
- /**
417
- * Variables to be passed to the canvas for this chat completion.
418
- * These can be used to customize the behavior of the canvas for this specific request.
415
+ * Optional label for this execution when using applicationId.
416
+ * This label can be used to identify or categorize the execution.
417
+ * Note: This field is only applicable when applicationId is provided.
419
418
  */
420
- variables?: Variables;
419
+ label?: string;
421
420
  /**
422
421
  * An array of previous messages in the conversation.
423
422
  * Each message should have a 'role' (e.g., 'user', 'assistant') and 'content'.
@@ -459,327 +458,1091 @@ interface ChatCompletionCreateParamsBase<Variables = ChatCompletionVariables> {
459
458
  required?: string[];
460
459
  };
461
460
  }>;
462
- /**
463
- * Configuration for generating structured output.
464
- */
465
- structuredOutput?: {
466
- /**
467
- * Whether to enable structured output for this completion.
468
- */
469
- enabled: boolean;
470
- /**
471
- * The schema defining the structure of the output.
472
- * This is used when structured output is enabled.
473
- */
474
- schema?: {
475
- properties: Record<string, unknown>;
476
- type: 'object';
477
- title: string;
478
- description: string;
479
- required: string[];
480
- };
481
- };
482
461
  };
462
+ /**
463
+ * Whether to skip Zod schema validation on execution results.
464
+ * When true, results are typecast to the expected output type without validation.
465
+ * @default false
466
+ */
467
+ skipResultValidation?: boolean;
468
+ /**
469
+ * Optional array of tags to associate with this execution.
470
+ * Tags can be used for filtering, categorization, and analytics.
471
+ */
472
+ tags?: string[];
483
473
  }
484
474
  /**
485
- * Parameters for creating a streaming chat completion.
475
+ * Configuration for asynchronous canvas execution with polling.
476
+ * The execution starts immediately but results must be retrieved via polling.
486
477
  */
487
- interface CompletionCreateParamsStreaming<T> extends ChatCompletionCreateParamsBase<T> {
478
+ interface AsyncExecutionParams extends BaseExecutionParams {
488
479
  /**
489
- * Whether the response should be streamed.
480
+ * Enable asynchronous execution mode.
481
+ * @default false
490
482
  */
491
- stream: true;
483
+ async?: true;
484
+ /**
485
+ * Optional webhook URL to receive completion notifications.
486
+ */
487
+ webhookUrl?: string;
492
488
  /**
493
- * The webhook URL, if you want to receive a webhook when the completion is completed.
489
+ * Time in milliseconds between polling attempts.
490
+ * @default 1000
494
491
  */
495
- webhookUrl?: undefined | null;
492
+ pollingInterval?: number;
493
+ /**
494
+ * Maximum time in milliseconds to wait for completion before timing out.
495
+ * @default 60000
496
+ */
497
+ pollingTimeout?: number;
498
+ /**
499
+ * Stream mode is not available for async executions.
500
+ */
501
+ stream?: never;
496
502
  }
497
503
  /**
498
- * Parameters for creating a non-streaming chat completion.
504
+ * Configuration for streaming canvas execution.
505
+ * Results are returned incrementally as they're generated.
499
506
  */
500
- interface CompletionCreateParamsNonStreaming<T> extends ChatCompletionCreateParamsBase<T> {
507
+ interface StreamExecutionParams extends BaseExecutionParams {
508
+ /**
509
+ * Enable streaming mode.
510
+ */
511
+ stream: true;
501
512
  /**
502
- * Whether the response should be streamed.
513
+ * Async mode is not available for streaming executions.
503
514
  */
504
- stream?: false | undefined | null;
515
+ async?: false;
516
+ /**
517
+ * Webhook URL is not available for streaming executions.
518
+ */
519
+ webhookUrl?: never;
505
520
  }
506
521
  /**
507
- * Parameters for creating a chat completion with a webhook.
522
+ * Configuration for synchronous canvas execution.
523
+ * The execution waits for the complete result before returning.
508
524
  */
509
- interface ChatCompletionCreateWebhookParams<T> extends CompletionCreateParamsNonStreaming<T> {
525
+ interface SyncExecutionParams extends BaseExecutionParams {
526
+ /**
527
+ * Disable asynchronous execution mode.
528
+ * @default false
529
+ */
530
+ async?: false;
510
531
  /**
511
- * The webhook URL, if you want to receive a webhook when the completion is completed.
532
+ * Webhook URL is not available for synchronous executions.
512
533
  */
513
- webhookUrl: string;
534
+ webhookUrl?: never;
535
+ /**
536
+ * Stream mode is not available for synchronous executions.
537
+ */
538
+ stream?: never;
514
539
  }
515
540
  /**
516
- * Union type for all possible chat completion creation parameters.
541
+ * Status of a canvas execution.
542
+ *
543
+ * Possible values:
544
+ * - `created` - Async execution queued on server (initial state)
545
+ * - `running` - Async execution actively processing
546
+ * - `succeeded` - Execution completed successfully (after validation)
547
+ * - `failed` - Execution failed (API error, validation error, or server failure)
548
+ * - `streaming` - Stream execution in progress
549
+ *
550
+ * @see {@link CanvasExecution.status} for status transitions and timing
551
+ */
552
+ type ExecutionStatus = 'succeeded' | 'failed' | 'running' | 'created' | 'streaming';
553
+ type AsyncCompletionCreateResult = {
554
+ id: string;
555
+ status: ExecutionStatus;
556
+ input_content: {
557
+ files: Array<any>;
558
+ messages: Array<any>;
559
+ variables: {
560
+ body: string;
561
+ title: string;
562
+ };
563
+ };
564
+ output_content: null;
565
+ raw_input: {
566
+ async: boolean;
567
+ canvas_id: string;
568
+ variables: {
569
+ body: string;
570
+ title: string;
571
+ };
572
+ };
573
+ raw_output: any;
574
+ compatibility_date: string;
575
+ metadata: Array<{
576
+ promptVersion: {
577
+ modelConfigurations: {
578
+ type: string;
579
+ model: string;
580
+ temperature: number;
581
+ structuredOutput: {
582
+ schema: {
583
+ type: string;
584
+ title: string;
585
+ required: Array<string>;
586
+ properties: {
587
+ clickbaitMessages: {
588
+ id: string;
589
+ type: string;
590
+ items: {
591
+ id: string;
592
+ type: string;
593
+ };
594
+ description: string;
595
+ };
596
+ };
597
+ description: string;
598
+ };
599
+ enabled: boolean;
600
+ };
601
+ };
602
+ variablesDefinitions: Array<{
603
+ name: string;
604
+ type: string;
605
+ required: boolean;
606
+ }>;
607
+ };
608
+ }>;
609
+ credits_used: number;
610
+ prompt_id: string;
611
+ prompt_version_id: string;
612
+ prompt_application_id: any;
613
+ workspace_id: string;
614
+ created_at: string;
615
+ updated_at: string;
616
+ deleted_at: any;
617
+ };
618
+ /**
619
+ * Raw API response type. Represents the unprocessed response from the Tela API.
620
+ * This type will be refined in future versions with proper typing.
517
621
  */
518
- type ChatCompletionCreateParams<T> = CompletionCreateParamsStreaming<T> | CompletionCreateParamsNonStreaming<T> | ChatCompletionCreateWebhookParams<T>;
622
+ type RawAPIResult = any;
519
623
  /**
520
- * Response structure for a created chat completion.
624
+ * Result returned when polling for asynchronous execution status.
625
+ *
626
+ * @template T - The type of the output content.
521
627
  */
522
- type ChatCompletionCreateResponse<T> = {
628
+ type AsyncCompletionPollingResult<T> = {
523
629
  /**
524
- * The ID of the completion.
630
+ * Unique identifier for the execution.
525
631
  */
526
632
  id: string;
527
633
  /**
528
- * The object of the completion.
634
+ * Current status of the execution.
529
635
  */
530
- object: string;
636
+ status: ExecutionStatus;
531
637
  /**
532
- * The created time of the completion.
638
+ * The output content when execution succeeds.
533
639
  */
534
- created: number;
640
+ outputContent: {
641
+ /**
642
+ * The actual content result.
643
+ */
644
+ content: T;
645
+ };
535
646
  /**
536
- * The choices of the completion.
647
+ * Raw output data from the execution.
537
648
  */
538
- choices: Array<{
539
- message: {
540
- role: string;
541
- content: T;
542
- };
543
- }>;
649
+ rawOutput: Record<string, any>;
650
+ };
651
+ /**
652
+ * Union type of all possible execution parameter configurations.
653
+ */
654
+ type ExecutionParams = AsyncExecutionParams | StreamExecutionParams | SyncExecutionParams;
655
+ /**
656
+ * Conditional type that determines the return type based on execution parameters.
657
+ *
658
+ * @category Canvas
659
+ *
660
+ * @template TParams - The execution parameters type.
661
+ * @template TOutput - The output type.
662
+ * @returns AsyncGenerator for streaming executions, Promise otherwise.
663
+ */
664
+ type CanvasExecutionResult<TParams, TOutput = unknown> = TParams extends StreamExecutionParams ? AsyncGenerator<Partial<TOutput>> : Promise<TOutput>;
665
+ type CanvasExecutionEvents<TOutput> = {
666
+ poll: AsyncCompletionPollingResult<TOutput>;
667
+ success: TOutput;
668
+ error: ExecutionFailedError;
669
+ statusChange: ExecutionStatus;
544
670
  };
545
671
  /**
546
- * Response structure for a chat completion streaming response.
672
+ * Manages the execution lifecycle of a canvas.
673
+ *
674
+ * Handles synchronous, asynchronous (with polling), and streaming execution modes.
675
+ * Automatically uploads TelaFile instances and validates results based on output schema.
676
+ *
677
+ * ## Status Tracking
678
+ *
679
+ * The execution status can be accessed via the `status` property and tracks the lifecycle:
680
+ *
681
+ * - **Sync executions**: `succeeded` or `failed` (set after validation completes)
682
+ * - **Async executions**: `created` → `running` → `succeeded` or `failed` (updated during polling)
683
+ * - **Stream executions**: `streaming` (set when stream starts)
684
+ *
685
+ * Status is set to `failed` when:
686
+ * - API request fails
687
+ * - Validation fails (for both sync and async)
688
+ * - Polling reports failure status
689
+ *
690
+ * Status is set to `succeeded` only after:
691
+ * - API request succeeds AND
692
+ * - Output validation passes (if schema provided)
693
+ *
694
+ * @category Canvas
695
+ *
696
+ * @typeParam TParams - The execution parameters type
697
+ * @typeParam TInput - The input variables type
698
+ * @typeParam TOutput - The output result type
699
+ *
700
+ * @fires poll - Emitted during async polling with current status and output (async executions only)
701
+ * @fires success - Emitted when execution completes successfully with the final result
702
+ * @fires error - Emitted when execution fails (only if error listeners are registered, otherwise throws)
703
+ * @fires statusChange - Emitted when execution status transitions to a new state
704
+ *
705
+ * @example
706
+ * ```typescript
707
+ * const execution = await canvas.execute({ query: 'test' }, { async: true })
708
+ *
709
+ * // Track status changes
710
+ * execution.on('statusChange', (status) => {
711
+ * console.log(`Status: ${status}`) // created → running → succeeded
712
+ * })
713
+ *
714
+ * // Access current status at any time
715
+ * console.log(execution.status) // 'running'
716
+ *
717
+ * const result = await execution.result
718
+ * console.log(execution.status) // 'succeeded'
719
+ * ```
547
720
  */
548
- type ChatCompletionCreateStreamingResponse<T> = {
721
+ declare class CanvasExecution<TParams extends ExecutionParams = SyncExecutionParams, TInput = unknown, TOutput = unknown> extends Emittery<CanvasExecutionEvents<TOutput>> {
722
+ private _id;
723
+ private _status;
724
+ private readonly _variables;
725
+ private readonly _params;
726
+ private readonly _client;
727
+ private readonly _outputSchema;
728
+ private readonly _skipResultValidation;
729
+ private readonly _abortController;
730
+ private _resultPromise;
731
+ private _stream;
732
+ private _rawResultValue;
549
733
  /**
550
- * The ID of the completion.
734
+ * Creates a new canvas execution instance.
735
+ *
736
+ * @param variables - Input variables to be passed to the canvas template.
737
+ * @param params - Execution parameters controlling sync/async/stream behavior.
738
+ * @param outputSchema - Zod schema or object schema for validating/parsing output.
739
+ * @param client - HTTP client instance for making API requests.
551
740
  */
552
- id: string;
741
+ constructor(variables: TInput, params: TParams | undefined, outputSchema: _zod__default.ZodType | Record<string, unknown>, client: BaseClient);
553
742
  /**
554
- * The object of the completion.
743
+ * Fetches an existing asynchronous execution by its ID.
744
+ *
745
+ * This method retrieves the current state of an async execution and creates a new
746
+ * CanvasExecution instance with the fetched data. Only async executions can be
747
+ * fetched, as they are the only ones with persistent UUIDs on the server.
748
+ *
749
+ * @param id - The UUID of the async execution to fetch.
750
+ * @param outputSchema - Zod schema or object schema for validating/parsing output.
751
+ * @param client - HTTP client instance for making API requests.
752
+ * @param options - Optional configuration for polling behavior.
753
+ * @param options.pollingInterval - Time in milliseconds between polling attempts (default: 1000).
754
+ * @param options.pollingTimeout - Maximum time in milliseconds to wait for completion (default: 60000).
755
+ * @throws {InvalidExecutionModeError} If the provided ID is not a valid UUID.
756
+ * @returns A promise resolving to a CanvasExecution instance with the fetched state.
757
+ *
758
+ * @example
759
+ * ```typescript
760
+ * const execution = await CanvasExecution.fetch(
761
+ * 'execution-uuid',
762
+ * z.object({ result: z.string() }),
763
+ * client,
764
+ * { pollingInterval: 2000, pollingTimeout: 120000 }
765
+ * )
766
+ * console.log(execution.status) // 'running' or 'succeeded' or 'failed'
767
+ * ```
555
768
  */
556
- object: string;
769
+ static fetch<TOutput = unknown>(id: string, outputSchema: _zod__default.ZodType | Record<string, unknown>, client: BaseClient, options?: {
770
+ pollingInterval?: number;
771
+ pollingTimeout?: number;
772
+ }): Promise<CanvasExecution<AsyncExecutionParams, unknown, TOutput>>;
557
773
  /**
558
- * The created time of the completion.
774
+ * Gets the unique execution ID assigned by the server.
775
+ *
776
+ * Note: Streaming executions do not have an ID as they don't create a tracked execution on the server.
777
+ *
778
+ * @throws {ExecutionNotStartedError} If the execution has not been started yet.
779
+ * @throws {InvalidExecutionModeError} If called on a streaming execution (streams don't have IDs).
780
+ * @returns The execution ID.
559
781
  */
560
- created: number;
782
+ get id(): string;
561
783
  /**
562
- * The model of the completion.
784
+ * Gets the latest known status of the execution.
785
+ *
786
+ * Status values and transitions:
787
+ * - **Sync**: `succeeded` (after validation) or `failed` (on any error)
788
+ * - **Async**: `created` → `running` → `succeeded` or `failed`
789
+ * - **Stream**: `streaming` (once started)
790
+ *
791
+ * **Important:** Status is set to `succeeded` only after successful validation.
792
+ * If validation fails, status will be `failed` even if the API request succeeded.
793
+ *
794
+ * Use the `statusChange` event to track status transitions in real-time.
795
+ *
796
+ * @throws {ExecutionNotStartedError} If the execution has not been started yet.
797
+ * @returns The current status of the execution.
798
+ *
799
+ * @example
800
+ * ```typescript
801
+ * const execution = await canvas.execute({ query: 'test' }, { async: true })
802
+ * console.log(execution.status) // 'created'
803
+ *
804
+ * await execution.result
805
+ * console.log(execution.status) // 'succeeded' or 'failed'
806
+ * ```
563
807
  */
564
- model: string;
808
+ get status(): ExecutionStatus;
565
809
  /**
566
- * The choices of the completion.
810
+ * Sets the status of the execution.
811
+ *
812
+ * @param status - The new status of the execution.
813
+ * @private
567
814
  */
568
- choices: Array<{
569
- delta: {
570
- role: string | null;
571
- content: string | null;
572
- functionCall: {
573
- name: string | null;
574
- arguments: string | null;
575
- } | null;
576
- };
577
- finishReason: string | null;
578
- index: number;
579
- logprobs: number | null;
580
- }>;
815
+ private set status(value);
816
+ /**
817
+ * Gets the input variables provided to this execution.
818
+ *
819
+ * @returns The variables object.
820
+ */
821
+ get variables(): TInput;
581
822
  /**
582
- * The message of the completion.
823
+ * Gets the execution parameters configured for this instance.
824
+ *
825
+ * @returns The execution parameters or undefined.
583
826
  */
584
- message: {
585
- role: string;
586
- content: string | null;
587
- functionCall: {
588
- name: string | null;
589
- arguments: string | null;
590
- } | null;
591
- toolCalls: Array<{
592
- name: string;
593
- arguments: string;
594
- }>;
595
- structuredContent: T;
596
- };
597
- };
827
+ get params(): TParams;
828
+ /**
829
+ * Checks if this execution is configured for asynchronous processing.
830
+ *
831
+ * @returns True if async mode is enabled.
832
+ */
833
+ get isAsync(): boolean;
834
+ /**
835
+ * Checks if this execution is configured for synchronous processing.
836
+ *
837
+ * @returns True if sync mode is enabled (not async).
838
+ */
839
+ get isSync(): boolean;
840
+ /**
841
+ * Checks if this execution is configured for streaming responses.
842
+ *
843
+ * @returns True if stream mode is enabled.
844
+ */
845
+ get isStream(): boolean;
846
+ /**
847
+ * Gets the raw API response without any processing or validation.
848
+ * Automatically starts execution and waits for completion (including polling for async executions).
849
+ *
850
+ * For sync executions, returns the complete API response.
851
+ * For async executions, returns the polling response with status and output.
852
+ *
853
+ * @throws {InvalidExecutionModeError} If called on a streaming execution.
854
+ * @returns A promise resolving to the raw API result.
855
+ */
856
+ get rawResult(): Promise<RawAPIResult>;
857
+ /**
858
+ * Type guard to check if params indicate async execution.
859
+ *
860
+ * @param params - Execution parameters to check.
861
+ * @returns True if params indicate async mode.
862
+ */
863
+ private _isAsync;
864
+ /**
865
+ * Starts the execution based on configured parameters.
866
+ * Routes to the appropriate execution method (sync, async, or stream).
867
+ *
868
+ * @returns A promise or async generator depending on execution mode.
869
+ */
870
+ start(): Promise<CanvasExecutionResult<TParams, TOutput>> | AsyncGenerator<Partial<TOutput>, any, any> | Promise<AsyncGenerator<Partial<TOutput>, any, any>> | Promise<AsyncCompletionCreateResult>;
871
+ /**
872
+ * Gets the execution result. For async executions, automatically starts polling.
873
+ * For sync executions, returns the result promise. For streams, returns the generator.
874
+ *
875
+ * @returns The execution result as a promise or async generator.
876
+ */
877
+ get result(): CanvasExecutionResult<TParams, TOutput>;
878
+ /**
879
+ * Cancels the ongoing execution by aborting all active requests and polling operations.
880
+ */
881
+ cancel(): void;
882
+ /**
883
+ * Starts polling for the execution result without waiting for the promise to resolve.
884
+ * This allows users to track execution progress via events rather than awaiting a promise.
885
+ *
886
+ * The following events will be emitted during polling:
887
+ * - `statusChange`: Emitted when the execution status changes (e.g., 'created' → 'running' → 'succeeded')
888
+ * - `poll`: Emitted on each polling attempt with the server response
889
+ * - `success`: Emitted when the execution completes successfully with the final result
890
+ * - `error`: Emitted if the execution fails
891
+ *
892
+ * **Important:** Events are only emitted while polling is active. You must either call `poll()` or
893
+ * await `execution.result` to start polling. Simply setting up event listeners without starting
894
+ * polling will not trigger any events.
895
+ *
896
+ * **Note:** If the execution has already completed (succeeded or failed) when fetched, the `success`
897
+ * and `error` events will not fire since no polling is needed. Check the `status` property and
898
+ * access the `result` directly for already-completed executions.
899
+ *
900
+ * @throws {InvalidExecutionModeError} If called on a non-async execution (sync or stream).
901
+ * @throws {ExecutionNotStartedError} If the execution has not been started yet (no ID assigned).
902
+ *
903
+ * @example
904
+ * ```typescript
905
+ * const execution = await canvas.getExecution('execution-id')
906
+ *
907
+ * // Check if already completed
908
+ * if (execution.status === 'succeeded' || execution.status === 'failed') {
909
+ * // Access result directly - events won't fire
910
+ * const result = await execution.result
911
+ * console.log('Already completed:', result)
912
+ * } else {
913
+ * // Still running - set up events and start polling
914
+ * execution.on('statusChange', (status) => {
915
+ * console.log('Status:', status)
916
+ * })
917
+ *
918
+ * execution.on('success', (result) => {
919
+ * console.log('Completed:', result)
920
+ * })
921
+ *
922
+ * execution.on('error', (error) => {
923
+ * console.error('Failed:', error)
924
+ * })
925
+ *
926
+ * // Start polling without waiting
927
+ * execution.poll()
928
+ * }
929
+ * ```
930
+ */
931
+ poll(): void;
932
+ /**
933
+ * Builds the base request body shared across all execution types.
934
+ * Includes messages, overrides, tags, label, and structured output configuration.
935
+ *
936
+ * @returns The base request body object.
937
+ */
938
+ private get baseBody();
939
+ /**
940
+ * Processes variables and uploads any TelaFile instances to the server.
941
+ * Replaces TelaFile objects with their uploaded URLs while preserving other values.
942
+ *
943
+ * @returns A promise resolving to the processed variables object.
944
+ */
945
+ private resolveVariables;
946
+ /**
947
+ * Initiates a synchronous execution that waits for the complete result.
948
+ * The result is validated against the output schema if provided.
949
+ *
950
+ * @returns A promise resolving to the parsed execution result.
951
+ */
952
+ private startSync;
953
+ /**
954
+ * Initiates an asynchronous execution that returns immediately with an execution ID.
955
+ * Results must be retrieved separately via polling using the `result` getter.
956
+ *
957
+ * @returns A promise that resolves when the execution is queued.
958
+ */
959
+ private startAsync;
960
+ /**
961
+ * Initiates a streaming execution that returns results incrementally as they're generated.
962
+ *
963
+ * @returns A promise resolving to an async generator yielding result chunks.
964
+ */
965
+ private startStream;
966
+ /**
967
+ * Polls the server for async execution results at regular intervals.
968
+ * Continues polling until the execution completes or the timeout is reached.
969
+ *
970
+ * @throws {Error} If called on a non-async execution.
971
+ * @throws {Error} If the execution fails on the server.
972
+ * @throws {Error} If the polling operation times out.
973
+ * @returns A promise resolving to the final execution result.
974
+ */
975
+ private startPolling;
976
+ /**
977
+ * Uploads a file and returns its URL and options.
978
+ *
979
+ * This is used internally to handle file uploads associated with chat completions.
980
+ *
981
+ * @param file - The TelaFile to be uploaded.
982
+ * @returns A Promise that resolves to an object containing the file URL and options.
983
+ * @throws {FileUploadError} If the file upload fails.
984
+ *
985
+ * @example
986
+ * ```typescript
987
+ * const file = new TelaFile({ /* file options *\/ });
988
+ * const uploadedFile = await this.uploadFile(file);
989
+ * console.log(uploadedFile.fileUrl);
990
+ * ```
991
+ */
992
+ private uploadFile;
993
+ /**
994
+ * Uploads multiple files and returns their URLs and options.
995
+ *
996
+ * This is used internally to handle multiple file uploads associated with chat completions.
997
+ *
998
+ * @param files - An array of TelaFile instances to be uploaded.
999
+ * @returns A Promise that resolves to an array of objects containing file URLs and options.
1000
+ * @throws {FileUploadError} If any file upload fails.
1001
+ */
1002
+ private uploadFiles;
1003
+ }
1004
+
1005
+ /**
1006
+ * Canvas resource for managing prompt templates and their execution.
1007
+ *
1008
+ * This module provides the core Canvas class for retrieving and executing
1009
+ * prompt templates from the Tela API, with support for schema validation,
1010
+ * type safety, and multiple execution modes.
1011
+ *
1012
+ * @module Resources
1013
+ */
1014
+
598
1015
  /**
599
- * Response structure for a chat completion webhook.
600
- * This interface represents the data sent to the webhook URL when a chat completion is finished.
1016
+ * Represents a variable that can be used in a canvas template.
601
1017
  */
602
- interface ChatCompletionWebhookResponse<T> {
1018
+ type CanvasVariable = {
603
1019
  /**
604
- * Unique identifier for this chat completion response.
1020
+ * The name of the variable.
605
1021
  */
606
- id: string;
1022
+ name: string;
607
1023
  /**
608
- * The current status of the chat completion.
609
- * - 'created': The request has been received but processing hasn't started.
610
- * - 'running': The chat completion is currently being processed.
611
- * - 'succeeded': The chat completion has finished successfully.
612
- * - 'failed': The chat completion encountered an error and couldn't complete.
1024
+ * The type of the variable (e.g., 'string', 'number', 'file').
613
1025
  */
614
- status: 'created' | 'failed' | 'running' | 'succeeded';
1026
+ type: string;
615
1027
  /**
616
- * Contains information about the input provided for this chat completion.
1028
+ * Whether this variable is required for canvas execution.
617
1029
  */
618
- inputContent: {
619
- /**
620
- * Variables passed to the chat completion, including any file URLs.
621
- */
622
- variables: ChatCompletionVariablesWithFileURL;
623
- /**
624
- * Array of messages that were part of the input.
625
- */
626
- messages: Array<{
627
- /**
628
- * The role of the message sender (e.g., 'user', 'assistant', 'system').
629
- */
630
- role: string;
631
- /**
632
- * The content of the message. Can be a string for text messages,
633
- * or an object for more complex content types like images.
634
- */
635
- content: string | {
636
- type: 'text';
637
- text: string;
638
- } | {
639
- type: 'image_url';
640
- imageUrl: {
641
- url: string;
642
- detail?: 'auto' | 'high' | 'low';
643
- };
644
- };
645
- /**
646
- * Optional. Information about a function call, if applicable.
647
- */
648
- functionCall?: {
649
- name: string;
650
- arguments: string;
651
- };
652
- }>;
1030
+ required: boolean;
1031
+ /**
1032
+ * Description of the variable's purpose.
1033
+ */
1034
+ description: string;
1035
+ /**
1036
+ * Processing options for the variable.
1037
+ */
1038
+ processingOptions: {
653
1039
  /**
654
- * Information about files used in the chat completion.
1040
+ * Whether multimodal content (images, files) is allowed.
655
1041
  */
656
- files: Array<{
657
- name: string;
658
- usedAt: 'variables' | 'messages';
659
- parsedContent: string;
660
- url: string;
661
- type: 'image' | 'file';
662
- }>;
1042
+ allowMultimodal: boolean;
663
1043
  };
1044
+ };
1045
+ interface CanvasOptions<TInput, TOutput> {
664
1046
  /**
665
- * Contains the output generated by the chat completion.
1047
+ * Id of the canvas that will be used to create the completion.
666
1048
  */
667
- outputContent: {
668
- /**
669
- * The role of the entity providing the output.
670
- */
671
- role: 'system' | 'user' | 'assistant' | 'function';
672
- /**
673
- * Optional. Information about tool calls made during the completion.
674
- */
675
- toolCalls?: Array<{
676
- name: string;
677
- arguments: string;
678
- }>;
679
- /**
680
- * Optional. Additional information about the completion process.
681
- */
682
- information?: {
683
- duration: number;
684
- cost?: number;
685
- inputTokens?: number;
686
- outputTokens?: number;
687
- };
688
- /**
689
- * Indicates whether the output has a structured format.
690
- */
691
- hasStructuredOutput?: boolean;
692
- /**
693
- * The main content of the chat completion output.
694
- */
695
- content: T;
696
- /**
697
- * Optional. The input messages in a string format.
698
- */
699
- inputMessages?: string | undefined;
1049
+ id?: string;
1050
+ /**
1051
+ * Id of the version of the canvas. If not provided, the latest promoted version will be used.
1052
+ */
1053
+ versionId?: string;
1054
+ /**
1055
+ * Id of the application that the canvas belongs to.
1056
+ */
1057
+ applicationId?: string;
1058
+ /**
1059
+ * Name of the canvas. Useful for debugging.
1060
+ */
1061
+ name?: string;
1062
+ /**
1063
+ * Input schema of the canvas.
1064
+ */
1065
+ input?: SchemaFunction<TInput>;
1066
+ /**
1067
+ * Output schema of the canvas.
1068
+ */
1069
+ output?: SchemaFunction<TOutput>;
1070
+ /**
1071
+ * Base client for making requests to the Tela API.
1072
+ */
1073
+ client: BaseClient;
1074
+ /**
1075
+ * Variables of the canvas.
1076
+ */
1077
+ variables: Array<CanvasVariable>;
1078
+ }
1079
+ type CanvasGetOptions<TInput extends ZodTypeOrRecord, TOutput extends ZodTypeOrRecord> = Omit<CanvasOptions<TInput, TOutput>, 'client' | 'variables'> & {
1080
+ /**
1081
+ * Whether to skip schema validation warnings during canvas retrieval.
1082
+ * When true, no warnings will be logged for schema mismatches.
1083
+ * @default false
1084
+ */
1085
+ skipSchemaValidation?: boolean;
1086
+ };
1087
+ declare const zod: {
1088
+ file: typeof TelaFileSchema;
1089
+ z: typeof _zod.z;
1090
+ default: typeof _zod.z;
1091
+ core: typeof _zod.core;
1092
+ globalRegistry: _zod.core.$ZodRegistry<_zod.core.GlobalMeta, _zod.core.$ZodType<unknown, unknown, _zod.core.$ZodTypeInternals<unknown, unknown>>>;
1093
+ registry: typeof _zod.core.registry;
1094
+ config: typeof _zod.core.config;
1095
+ $output: typeof _zod.core.$output;
1096
+ $input: typeof _zod.core.$input;
1097
+ $brand: typeof _zod.core.$brand;
1098
+ clone: typeof _zod.core.util.clone;
1099
+ regexes: typeof _zod.core.regexes;
1100
+ treeifyError: typeof _zod.core.treeifyError;
1101
+ prettifyError: typeof _zod.core.prettifyError;
1102
+ formatError: typeof _zod.core.formatError;
1103
+ flattenError: typeof _zod.core.flattenError;
1104
+ toJSONSchema: typeof _zod.core.toJSONSchema;
1105
+ TimePrecision: {
1106
+ readonly Any: null;
1107
+ readonly Minute: -1;
1108
+ readonly Second: 0;
1109
+ readonly Millisecond: 3;
1110
+ readonly Microsecond: 6;
1111
+ };
1112
+ util: typeof _zod.core.util;
1113
+ NEVER: never;
1114
+ locales: typeof _zod.core.locales;
1115
+ ZodISODateTime: _zod.core.$constructor<_zod.ZodISODateTime, _zod.core.$ZodISODateTimeDef>;
1116
+ ZodISODate: _zod.core.$constructor<_zod.ZodISODate, _zod.core.$ZodStringFormatDef<"date">>;
1117
+ ZodISOTime: _zod.core.$constructor<_zod.ZodISOTime, _zod.core.$ZodISOTimeDef>;
1118
+ ZodISODuration: _zod.core.$constructor<_zod.ZodISODuration, _zod.core.$ZodStringFormatDef<"duration">>;
1119
+ iso: typeof _zod.iso;
1120
+ coerce: typeof _zod.coerce;
1121
+ string(params?: string | _zod.core.$ZodStringParams): _zod.ZodString;
1122
+ string<T extends string>(params?: string | _zod.core.$ZodStringParams): _zod.core.$ZodType<T, T>;
1123
+ email(params?: string | _zod.core.$ZodEmailParams): _zod.ZodEmail;
1124
+ guid(params?: string | _zod.core.$ZodGUIDParams): _zod.ZodGUID;
1125
+ uuid(params?: string | _zod.core.$ZodUUIDParams): _zod.ZodUUID;
1126
+ uuidv4(params?: string | _zod.core.$ZodUUIDv4Params): _zod.ZodUUID;
1127
+ uuidv6(params?: string | _zod.core.$ZodUUIDv6Params): _zod.ZodUUID;
1128
+ uuidv7(params?: string | _zod.core.$ZodUUIDv7Params): _zod.ZodUUID;
1129
+ url(params?: string | _zod.core.$ZodURLParams): _zod.ZodURL;
1130
+ httpUrl(params?: string | Omit<_zod.core.$ZodURLParams, "protocol" | "hostname">): _zod.ZodURL;
1131
+ emoji(params?: string | _zod.core.$ZodEmojiParams): _zod.ZodEmoji;
1132
+ nanoid(params?: string | _zod.core.$ZodNanoIDParams): _zod.ZodNanoID;
1133
+ cuid(params?: string | _zod.core.$ZodCUIDParams): _zod.ZodCUID;
1134
+ cuid2(params?: string | _zod.core.$ZodCUID2Params): _zod.ZodCUID2;
1135
+ ulid(params?: string | _zod.core.$ZodULIDParams): _zod.ZodULID;
1136
+ xid(params?: string | _zod.core.$ZodXIDParams): _zod.ZodXID;
1137
+ ksuid(params?: string | _zod.core.$ZodKSUIDParams): _zod.ZodKSUID;
1138
+ ipv4(params?: string | _zod.core.$ZodIPv4Params): _zod.ZodIPv4;
1139
+ ipv6(params?: string | _zod.core.$ZodIPv6Params): _zod.ZodIPv6;
1140
+ cidrv4(params?: string | _zod.core.$ZodCIDRv4Params): _zod.ZodCIDRv4;
1141
+ cidrv6(params?: string | _zod.core.$ZodCIDRv6Params): _zod.ZodCIDRv6;
1142
+ base64(params?: string | _zod.core.$ZodBase64Params): _zod.ZodBase64;
1143
+ base64url(params?: string | _zod.core.$ZodBase64URLParams): _zod.ZodBase64URL;
1144
+ e164(params?: string | _zod.core.$ZodE164Params): _zod.ZodE164;
1145
+ jwt(params?: string | _zod.core.$ZodJWTParams): _zod.ZodJWT;
1146
+ stringFormat<Format extends string>(format: Format, fnOrRegex: ((arg: string) => _zod.core.util.MaybeAsync<unknown>) | RegExp, _params?: string | _zod.core.$ZodStringFormatParams): _zod.ZodCustomStringFormat<Format>;
1147
+ hostname(_params?: string | _zod.core.$ZodStringFormatParams): _zod.ZodCustomStringFormat<"hostname">;
1148
+ hex(_params?: string | _zod.core.$ZodStringFormatParams): _zod.ZodCustomStringFormat<"hex">;
1149
+ hash<Alg extends _zod.core.util.HashAlgorithm, Enc extends _zod.core.util.HashEncoding = "hex">(alg: Alg, params?: {
1150
+ enc?: Enc;
1151
+ } & _zod.core.$ZodStringFormatParams): _zod.ZodCustomStringFormat<`${Alg}_${Enc}`>;
1152
+ number(params?: string | _zod.core.$ZodNumberParams): _zod.ZodNumber;
1153
+ int(params?: string | _zod.core.$ZodCheckNumberFormatParams): _zod.ZodInt;
1154
+ float32(params?: string | _zod.core.$ZodCheckNumberFormatParams): _zod.ZodFloat32;
1155
+ float64(params?: string | _zod.core.$ZodCheckNumberFormatParams): _zod.ZodFloat64;
1156
+ int32(params?: string | _zod.core.$ZodCheckNumberFormatParams): _zod.ZodInt32;
1157
+ uint32(params?: string | _zod.core.$ZodCheckNumberFormatParams): _zod.ZodUInt32;
1158
+ boolean(params?: string | _zod.core.$ZodBooleanParams): _zod.ZodBoolean;
1159
+ bigint(params?: string | _zod.core.$ZodBigIntParams): _zod.ZodBigInt;
1160
+ int64(params?: string | _zod.core.$ZodBigIntFormatParams): _zod.ZodBigIntFormat;
1161
+ uint64(params?: string | _zod.core.$ZodBigIntFormatParams): _zod.ZodBigIntFormat;
1162
+ symbol(params?: string | _zod.core.$ZodSymbolParams): _zod.ZodSymbol;
1163
+ any(): _zod.ZodAny;
1164
+ unknown(): _zod.ZodUnknown;
1165
+ never(params?: string | _zod.core.$ZodNeverParams): _zod.ZodNever;
1166
+ date(params?: string | _zod.core.$ZodDateParams): _zod.ZodDate;
1167
+ array<T extends _zod.core.SomeType>(element: T, params?: string | _zod.core.$ZodArrayParams): _zod.ZodArray<T>;
1168
+ keyof<T extends _zod.ZodObject>(schema: T): _zod.ZodEnum<_zod.core.util.KeysEnum<T["_zod"]["output"]>>;
1169
+ object<T extends _zod.core.$ZodLooseShape = Partial<Record<never, _zod.core.SomeType>>>(shape?: T, params?: string | _zod.core.$ZodObjectParams): _zod.ZodObject<_zod.core.util.Writeable<T>, _zod.core.$strip>;
1170
+ strictObject<T extends _zod.core.$ZodLooseShape>(shape: T, params?: string | _zod.core.$ZodObjectParams): _zod.ZodObject<T, _zod.core.$strict>;
1171
+ looseObject<T extends _zod.core.$ZodLooseShape>(shape: T, params?: string | _zod.core.$ZodObjectParams): _zod.ZodObject<T, _zod.core.$loose>;
1172
+ union<const T extends readonly _zod.core.SomeType[]>(options: T, params?: string | _zod.core.$ZodUnionParams): _zod.ZodUnion<T>;
1173
+ discriminatedUnion<Types extends readonly [_zod.core.$ZodTypeDiscriminable, ..._zod.core.$ZodTypeDiscriminable[]], Disc extends string>(discriminator: Disc, options: Types, params?: string | _zod.core.$ZodDiscriminatedUnionParams): _zod.ZodDiscriminatedUnion<Types, Disc>;
1174
+ intersection<T extends _zod.core.SomeType, U extends _zod.core.SomeType>(left: T, right: U): _zod.ZodIntersection<T, U>;
1175
+ tuple<T extends readonly [_zod.core.SomeType, ..._zod.core.SomeType[]]>(items: T, params?: string | _zod.core.$ZodTupleParams): _zod.ZodTuple<T, null>;
1176
+ tuple<T extends readonly [_zod.core.SomeType, ..._zod.core.SomeType[]], Rest extends _zod.core.SomeType>(items: T, rest: Rest, params?: string | _zod.core.$ZodTupleParams): _zod.ZodTuple<T, Rest>;
1177
+ tuple(items: [], params?: string | _zod.core.$ZodTupleParams): _zod.ZodTuple<[], null>;
1178
+ record<Key extends _zod.core.$ZodRecordKey, Value extends _zod.core.SomeType>(keyType: Key, valueType: Value, params?: string | _zod.core.$ZodRecordParams): _zod.ZodRecord<Key, Value>;
1179
+ partialRecord<Key extends _zod.core.$ZodRecordKey, Value extends _zod.core.SomeType>(keyType: Key, valueType: Value, params?: string | _zod.core.$ZodRecordParams): _zod.ZodRecord<Key & _zod.core.$partial, Value>;
1180
+ map<Key extends _zod.core.SomeType, Value extends _zod.core.SomeType>(keyType: Key, valueType: Value, params?: string | _zod.core.$ZodMapParams): _zod.ZodMap<Key, Value>;
1181
+ set<Value extends _zod.core.SomeType>(valueType: Value, params?: string | _zod.core.$ZodSetParams): _zod.ZodSet<Value>;
1182
+ nativeEnum<T extends _zod.core.util.EnumLike>(entries: T, params?: string | _zod.core.$ZodEnumParams): _zod.ZodEnum<T>;
1183
+ literal<const T extends ReadonlyArray<_zod.core.util.Literal>>(value: T, params?: string | _zod.core.$ZodLiteralParams): _zod.ZodLiteral<T[number]>;
1184
+ literal<const T extends _zod.core.util.Literal>(value: T, params?: string | _zod.core.$ZodLiteralParams): _zod.ZodLiteral<T>;
1185
+ transform<I = unknown, O = I>(fn: (input: I, ctx: _zod.core.ParsePayload) => O): _zod.ZodTransform<Awaited<O>, I>;
1186
+ optional<T extends _zod.core.SomeType>(innerType: T): _zod.ZodOptional<T>;
1187
+ nullable<T extends _zod.core.SomeType>(innerType: T): _zod.ZodNullable<T>;
1188
+ nullish<T extends _zod.core.SomeType>(innerType: T): _zod.ZodOptional<_zod.ZodNullable<T>>;
1189
+ _default<T extends _zod.core.SomeType>(innerType: T, defaultValue: _zod.core.util.NoUndefined<_zod.core.output<T>> | (() => _zod.core.util.NoUndefined<_zod.core.output<T>>)): _zod.ZodDefault<T>;
1190
+ prefault<T extends _zod.core.SomeType>(innerType: T, defaultValue: _zod.core.input<T> | (() => _zod.core.input<T>)): _zod.ZodPrefault<T>;
1191
+ nonoptional<T extends _zod.core.SomeType>(innerType: T, params?: string | _zod.core.$ZodNonOptionalParams): _zod.ZodNonOptional<T>;
1192
+ success<T extends _zod.core.SomeType>(innerType: T): _zod.ZodSuccess<T>;
1193
+ nan(params?: string | _zod.core.$ZodNaNParams): _zod.ZodNaN;
1194
+ pipe<const A extends _zod.core.SomeType, B extends _zod.core.$ZodType<unknown, _zod.core.output<A>> = _zod.core.$ZodType<unknown, _zod.core.output<A>, _zod.core.$ZodTypeInternals<unknown, _zod.core.output<A>>>>(in_: A, out: B | _zod.core.$ZodType<unknown, _zod.core.output<A>>): _zod.ZodPipe<A, B>;
1195
+ codec<const A extends _zod.core.SomeType, B extends _zod.core.SomeType = _zod.core.$ZodType<unknown, unknown, _zod.core.$ZodTypeInternals<unknown, unknown>>>(in_: A, out: B, params: {
1196
+ decode: (value: _zod.core.output<A>, payload: _zod.core.ParsePayload<_zod.core.output<A>>) => _zod.core.util.MaybeAsync<_zod.core.input<B>>;
1197
+ encode: (value: _zod.core.input<B>, payload: _zod.core.ParsePayload<_zod.core.input<B>>) => _zod.core.util.MaybeAsync<_zod.core.output<A>>;
1198
+ }): _zod.ZodCodec<A, B>;
1199
+ readonly<T extends _zod.core.SomeType>(innerType: T): _zod.ZodReadonly<T>;
1200
+ templateLiteral<const Parts extends _zod.core.$ZodTemplateLiteralPart[]>(parts: Parts, params?: string | _zod.core.$ZodTemplateLiteralParams): _zod.ZodTemplateLiteral<_zod.core.$PartsToTemplateLiteral<Parts>>;
1201
+ lazy<T extends _zod.core.SomeType>(getter: () => T): _zod.ZodLazy<T>;
1202
+ promise<T extends _zod.core.SomeType>(innerType: T): _zod.ZodPromise<T>;
1203
+ _function(): _zod.ZodFunction;
1204
+ _function<const In extends ReadonlyArray<_zod.core.$ZodType>>(params: {
1205
+ input: In;
1206
+ }): _zod.ZodFunction<_zod.ZodTuple<In, null>, _zod.core.$ZodFunctionOut>;
1207
+ _function<const In extends ReadonlyArray<_zod.core.$ZodType>, const Out extends _zod.core.$ZodFunctionOut = _zod.core.$ZodFunctionOut>(params: {
1208
+ input: In;
1209
+ output: Out;
1210
+ }): _zod.ZodFunction<_zod.ZodTuple<In, null>, Out>;
1211
+ _function<const In extends _zod.core.$ZodFunctionIn = _zod.core.$ZodFunctionArgs>(params: {
1212
+ input: In;
1213
+ }): _zod.ZodFunction<In, _zod.core.$ZodFunctionOut>;
1214
+ _function<const Out extends _zod.core.$ZodFunctionOut = _zod.core.$ZodFunctionOut>(params: {
1215
+ output: Out;
1216
+ }): _zod.ZodFunction<_zod.core.$ZodFunctionIn, Out>;
1217
+ _function<In extends _zod.core.$ZodFunctionIn = _zod.core.$ZodFunctionArgs, Out extends _zod.core.$ZodType = _zod.core.$ZodType<unknown, unknown, _zod.core.$ZodTypeInternals<unknown, unknown>>>(params?: {
1218
+ input: In;
1219
+ output: Out;
1220
+ }): _zod.ZodFunction<In, Out>;
1221
+ check<O = unknown>(fn: _zod.core.CheckFn<O>): _zod.core.$ZodCheck<O>;
1222
+ custom<O>(fn?: (data: unknown) => unknown, _params?: string | _zod.core.$ZodCustomParams | undefined): _zod.ZodCustom<O, O>;
1223
+ refine<T>(fn: (arg: NoInfer<T>) => _zod.core.util.MaybeAsync<unknown>, _params?: string | _zod.core.$ZodCustomParams): _zod.core.$ZodCheck<T>;
1224
+ superRefine<T>(fn: (arg: T, payload: _zod.core.$RefinementCtx<T>) => void | Promise<void>): _zod.core.$ZodCheck<T>;
1225
+ json(params?: string | _zod.core.$ZodCustomParams): _zod.ZodJSONSchema;
1226
+ 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>;
1227
+ ZodType: _zod.core.$constructor<_zod.ZodType>;
1228
+ _ZodString: _zod.core.$constructor<_zod._ZodString>;
1229
+ ZodString: _zod.core.$constructor<_zod.ZodString>;
1230
+ ZodStringFormat: _zod.core.$constructor<_zod.ZodStringFormat>;
1231
+ ZodEmail: _zod.core.$constructor<_zod.ZodEmail>;
1232
+ ZodGUID: _zod.core.$constructor<_zod.ZodGUID>;
1233
+ ZodUUID: _zod.core.$constructor<_zod.ZodUUID>;
1234
+ ZodURL: _zod.core.$constructor<_zod.ZodURL>;
1235
+ ZodEmoji: _zod.core.$constructor<_zod.ZodEmoji>;
1236
+ ZodNanoID: _zod.core.$constructor<_zod.ZodNanoID>;
1237
+ ZodCUID: _zod.core.$constructor<_zod.ZodCUID>;
1238
+ ZodCUID2: _zod.core.$constructor<_zod.ZodCUID2>;
1239
+ ZodULID: _zod.core.$constructor<_zod.ZodULID>;
1240
+ ZodXID: _zod.core.$constructor<_zod.ZodXID>;
1241
+ ZodKSUID: _zod.core.$constructor<_zod.ZodKSUID>;
1242
+ ZodIPv4: _zod.core.$constructor<_zod.ZodIPv4>;
1243
+ ZodIPv6: _zod.core.$constructor<_zod.ZodIPv6>;
1244
+ ZodCIDRv4: _zod.core.$constructor<_zod.ZodCIDRv4>;
1245
+ ZodCIDRv6: _zod.core.$constructor<_zod.ZodCIDRv6>;
1246
+ ZodBase64: _zod.core.$constructor<_zod.ZodBase64>;
1247
+ ZodBase64URL: _zod.core.$constructor<_zod.ZodBase64URL>;
1248
+ ZodE164: _zod.core.$constructor<_zod.ZodE164>;
1249
+ ZodJWT: _zod.core.$constructor<_zod.ZodJWT>;
1250
+ ZodCustomStringFormat: _zod.core.$constructor<_zod.ZodCustomStringFormat>;
1251
+ ZodNumber: _zod.core.$constructor<_zod.ZodNumber>;
1252
+ ZodNumberFormat: _zod.core.$constructor<_zod.ZodNumberFormat>;
1253
+ ZodBoolean: _zod.core.$constructor<_zod.ZodBoolean>;
1254
+ ZodBigInt: _zod.core.$constructor<_zod.ZodBigInt>;
1255
+ ZodBigIntFormat: _zod.core.$constructor<_zod.ZodBigIntFormat>;
1256
+ ZodSymbol: _zod.core.$constructor<_zod.ZodSymbol>;
1257
+ ZodUndefined: _zod.core.$constructor<_zod.ZodUndefined>;
1258
+ undefined: typeof _zod.undefined;
1259
+ ZodNull: _zod.core.$constructor<_zod.ZodNull>;
1260
+ null: typeof _zod.null;
1261
+ ZodAny: _zod.core.$constructor<_zod.ZodAny>;
1262
+ ZodUnknown: _zod.core.$constructor<_zod.ZodUnknown>;
1263
+ ZodNever: _zod.core.$constructor<_zod.ZodNever>;
1264
+ ZodVoid: _zod.core.$constructor<_zod.ZodVoid>;
1265
+ void: typeof _zod.void;
1266
+ ZodDate: _zod.core.$constructor<_zod.ZodDate>;
1267
+ ZodArray: _zod.core.$constructor<_zod.ZodArray>;
1268
+ ZodObject: _zod.core.$constructor<_zod.ZodObject>;
1269
+ ZodUnion: _zod.core.$constructor<_zod.ZodUnion>;
1270
+ ZodDiscriminatedUnion: _zod.core.$constructor<_zod.ZodDiscriminatedUnion>;
1271
+ ZodIntersection: _zod.core.$constructor<_zod.ZodIntersection>;
1272
+ ZodTuple: _zod.core.$constructor<_zod.ZodTuple>;
1273
+ ZodRecord: _zod.core.$constructor<_zod.ZodRecord>;
1274
+ ZodMap: _zod.core.$constructor<_zod.ZodMap>;
1275
+ ZodSet: _zod.core.$constructor<_zod.ZodSet>;
1276
+ ZodEnum: _zod.core.$constructor<_zod.ZodEnum>;
1277
+ enum: typeof _zod.enum;
1278
+ ZodLiteral: _zod.core.$constructor<_zod.ZodLiteral>;
1279
+ ZodFile: _zod.core.$constructor<_zod.ZodFile>;
1280
+ ZodTransform: _zod.core.$constructor<_zod.ZodTransform>;
1281
+ ZodOptional: _zod.core.$constructor<_zod.ZodOptional>;
1282
+ ZodNullable: _zod.core.$constructor<_zod.ZodNullable>;
1283
+ ZodDefault: _zod.core.$constructor<_zod.ZodDefault>;
1284
+ ZodPrefault: _zod.core.$constructor<_zod.ZodPrefault>;
1285
+ ZodNonOptional: _zod.core.$constructor<_zod.ZodNonOptional>;
1286
+ ZodSuccess: _zod.core.$constructor<_zod.ZodSuccess>;
1287
+ ZodCatch: _zod.core.$constructor<_zod.ZodCatch>;
1288
+ catch: typeof _zod.catch;
1289
+ ZodNaN: _zod.core.$constructor<_zod.ZodNaN>;
1290
+ ZodPipe: _zod.core.$constructor<_zod.ZodPipe>;
1291
+ ZodCodec: _zod.core.$constructor<_zod.ZodCodec>;
1292
+ ZodReadonly: _zod.core.$constructor<_zod.ZodReadonly>;
1293
+ ZodTemplateLiteral: _zod.core.$constructor<_zod.ZodTemplateLiteral>;
1294
+ ZodLazy: _zod.core.$constructor<_zod.ZodLazy>;
1295
+ ZodPromise: _zod.core.$constructor<_zod.ZodPromise>;
1296
+ ZodFunction: _zod.core.$constructor<_zod.ZodFunction>;
1297
+ function: typeof _zod._function;
1298
+ ZodCustom: _zod.core.$constructor<_zod.ZodCustom>;
1299
+ instanceof: typeof _zod.instanceof;
1300
+ stringbool: (_params?: string | _zod.core.$ZodStringBoolParams) => _zod.ZodCodec<_zod.ZodString, _zod.ZodBoolean>;
1301
+ lt: typeof _zod.core._lt;
1302
+ lte: typeof _zod.core._lte;
1303
+ gt: typeof _zod.core._gt;
1304
+ gte: typeof _zod.core._gte;
1305
+ positive: typeof _zod.core._positive;
1306
+ negative: typeof _zod.core._negative;
1307
+ nonpositive: typeof _zod.core._nonpositive;
1308
+ nonnegative: typeof _zod.core._nonnegative;
1309
+ multipleOf: typeof _zod.core._multipleOf;
1310
+ maxSize: typeof _zod.core._maxSize;
1311
+ minSize: typeof _zod.core._minSize;
1312
+ size: typeof _zod.core._size;
1313
+ maxLength: typeof _zod.core._maxLength;
1314
+ minLength: typeof _zod.core._minLength;
1315
+ length: typeof _zod.core._length;
1316
+ regex: typeof _zod.core._regex;
1317
+ lowercase: typeof _zod.core._lowercase;
1318
+ uppercase: typeof _zod.core._uppercase;
1319
+ includes: typeof _zod.core._includes;
1320
+ startsWith: typeof _zod.core._startsWith;
1321
+ endsWith: typeof _zod.core._endsWith;
1322
+ property: typeof _zod.core._property;
1323
+ mime: typeof _zod.core._mime;
1324
+ overwrite: typeof _zod.core._overwrite;
1325
+ normalize: typeof _zod.core._normalize;
1326
+ trim: typeof _zod.core._trim;
1327
+ toLowerCase: typeof _zod.core._toLowerCase;
1328
+ toUpperCase: typeof _zod.core._toUpperCase;
1329
+ ZodError: _zod.core.$constructor<ZodError>;
1330
+ ZodRealError: _zod.core.$constructor<ZodError>;
1331
+ parse: <T extends _zod.core.$ZodType>(schema: T, value: unknown, _ctx?: _zod.core.ParseContext<_zod.core.$ZodIssue>, _params?: {
1332
+ callee?: _zod.core.util.AnyFunc;
1333
+ Err?: _zod.core.$ZodErrorClass;
1334
+ }) => _zod.core.output<T>;
1335
+ parseAsync: <T extends _zod.core.$ZodType>(schema: T, value: unknown, _ctx?: _zod.core.ParseContext<_zod.core.$ZodIssue>, _params?: {
1336
+ callee?: _zod.core.util.AnyFunc;
1337
+ Err?: _zod.core.$ZodErrorClass;
1338
+ }) => Promise<_zod.core.output<T>>;
1339
+ safeParse: <T extends _zod.core.$ZodType>(schema: T, value: unknown, _ctx?: _zod.core.ParseContext<_zod.core.$ZodIssue>) => _zod.ZodSafeParseResult<_zod.core.output<T>>;
1340
+ safeParseAsync: <T extends _zod.core.$ZodType>(schema: T, value: unknown, _ctx?: _zod.core.ParseContext<_zod.core.$ZodIssue>) => Promise<_zod.ZodSafeParseResult<_zod.core.output<T>>>;
1341
+ encode: <T extends _zod.core.$ZodType>(schema: T, value: _zod.core.output<T>, _ctx?: _zod.core.ParseContext<_zod.core.$ZodIssue>) => _zod.core.input<T>;
1342
+ decode: <T extends _zod.core.$ZodType>(schema: T, value: _zod.core.input<T>, _ctx?: _zod.core.ParseContext<_zod.core.$ZodIssue>) => _zod.core.output<T>;
1343
+ encodeAsync: <T extends _zod.core.$ZodType>(schema: T, value: _zod.core.output<T>, _ctx? /**
1344
+ * Unique identifier for this prompt version.
1345
+ */: _zod.core.ParseContext<_zod.core.$ZodIssue>) => Promise<_zod.core.input<T>>;
1346
+ 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>>;
1347
+ safeEncode: <T extends _zod.core.$ZodType>(schema: T, value: _zod.core.output<T>, _ctx? /**
1348
+ * Variables available in this prompt version.
1349
+ */: _zod.core.ParseContext<_zod.core.$ZodIssue>) => _zod.ZodSafeParseResult<_zod.core.input<T>>;
1350
+ safeDecode: <T extends _zod.core.$ZodType>(schema: T, value: _zod.core.input<T>, _ctx? /**
1351
+ * Configuration settings for this prompt version.
1352
+ */: _zod.core.ParseContext<_zod.core.$ZodIssue>) => _zod.ZodSafeParseResult<_zod.core.output<T>>;
1353
+ 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>>>;
1354
+ 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>>>;
1355
+ setErrorMap(map: _zod.core.$ZodErrorMap): void;
1356
+ getErrorMap(): _zod.core.$ZodErrorMap<_zod.core.$ZodIssue> | undefined;
1357
+ ZodIssueCode: {
1358
+ readonly invalid_type: "invalid_type";
1359
+ readonly too_big: "too_big";
1360
+ readonly too_small: "too_small";
1361
+ readonly invalid_format: "invalid_format";
1362
+ readonly not_multiple_of: "not_multiple_of";
1363
+ readonly unrecognized_keys: "unrecognized_keys";
1364
+ readonly invalid_union: "invalid_union";
1365
+ readonly invalid_key: "invalid_key";
1366
+ readonly invalid_element: "invalid_element";
1367
+ readonly invalid_value: "invalid_value";
1368
+ readonly custom: "custom";
700
1369
  };
1370
+ ZodFirstPartyTypeKind: typeof _zod.ZodFirstPartyTypeKind;
1371
+ };
1372
+ type SchemaBuilder = typeof zod;
1373
+ type SchemaFunction<T> = (schema: SchemaBuilder) => T;
1374
+ type Output<T> = T extends z.ZodType ? z.infer<T> : T;
1375
+ type ZodTypeOrRecord = z.ZodType | Record<string, unknown>;
1376
+ type CanvasExecutionPromiseLike<TParams extends ExecutionParams = SyncExecutionParams, TInput = unknown, TOutput = unknown> = PromiseLike<CanvasExecution<TParams, TInput, TOutput>> & {
1377
+ result: Promise<CanvasExecutionResult<TParams, TOutput>>;
1378
+ };
1379
+ /**
1380
+ * Represents a canvas (prompt template) from the Tela API.
1381
+ *
1382
+ * Canvas instances are retrieved using `tela.canvas.get()` and provide methods
1383
+ * for executing prompts with various modes (sync, async, streaming).
1384
+ *
1385
+ * @category Canvas
1386
+ *
1387
+ * @typeParam TInput - The input schema type (Zod schema or plain object type)
1388
+ * @typeParam TOutput - The output schema type (Zod schema or plain object type)
1389
+ */
1390
+ declare class Canvas<TInput extends ZodTypeOrRecord, TOutput extends ZodTypeOrRecord> {
1391
+ private readonly _id;
1392
+ private readonly _versionId;
1393
+ private readonly _applicationId;
1394
+ private readonly _name;
1395
+ private readonly _input;
1396
+ private readonly _output;
1397
+ private readonly _client;
1398
+ private readonly _variables;
701
1399
  /**
702
- * The original input parameters provided for this chat completion.
703
- */
704
- rawInput: {
705
- versionId?: string;
706
- canvasId?: string;
707
- applicationId?: string;
708
- webhookUrl?: string;
709
- variables?: ChatCompletionVariablesWithFileURL;
710
- messages?: Array<{
711
- role: string;
712
- content: string | {
713
- type: 'text';
714
- text: string;
715
- } | {
716
- type: 'image_url';
717
- imageUrl: {
718
- url: string;
719
- detail?: 'auto' | 'high' | 'low';
720
- };
721
- };
722
- }>;
723
- override?: {
724
- model?: string;
725
- temperature?: number;
726
- type: 'chat' | 'completion';
727
- functions?: Array<{
728
- id: string;
729
- name: string;
730
- description?: string;
731
- parameters?: {
732
- type: 'object';
733
- properties: Record<string, unknown>;
734
- required?: string[];
735
- };
736
- }>;
737
- structuredOutput?: {
738
- enabled: boolean;
739
- schema?: {
740
- properties: Record<string, unknown>;
741
- type: 'object';
742
- title: string;
743
- description: string;
744
- required: string[];
745
- };
746
- };
747
- };
748
- } | null;
1400
+ * Creates a new instance of the Canvas class. Usage of this constructor is not recommended.
1401
+ * Use the `tela.getCanvas` method instead.
1402
+ *
1403
+ * @private
1404
+ */
1405
+ private constructor();
749
1406
  /**
750
- * The raw output from the chat completion process.
1407
+ * Gets a canvas by its ID.
1408
+ *
1409
+ * @param options - The options to use to get the canvas.
1410
+ * @param options.id - The ID of the canvas to get.
1411
+ * @param options.versionId - The version ID of the canvas to get.
1412
+ * @param options.applicationId - The application ID of the canvas to get.
1413
+ * @param options.client - The client to use to make the request.
1414
+ * @param options.input - The input schema of the canvas to get.
1415
+ * @param options.output - The output schema of the canvas to get.
1416
+ * @returns The canvas.
751
1417
  */
752
- rawOutput: Record<string, unknown>;
1418
+ static get<TInput extends ZodTypeOrRecord, TOutput extends ZodTypeOrRecord>(options: CanvasGetOptions<TInput, TOutput> & {
1419
+ client: BaseClient;
1420
+ }): Promise<Canvas<TInput, TOutput>>;
753
1421
  /**
754
- * The date used for compatibility checks.
1422
+ * Gets the unique identifier of this canvas.
1423
+ *
1424
+ * @returns The canvas ID.
755
1425
  */
756
- compatibilityDate: Date;
1426
+ get id(): string;
757
1427
  /**
758
- * The ID of the prompt version used for this chat completion.
1428
+ * Gets the name of this canvas, if provided.
1429
+ *
1430
+ * @returns The canvas name or undefined.
759
1431
  */
760
- promptVersionId: string;
1432
+ get name(): string;
761
1433
  /**
762
- * The ID of the prompt application, if applicable.
1434
+ * Gets the version identifier of this canvas, if specified.
1435
+ * When undefined, the latest promoted version is used.
1436
+ *
1437
+ * @returns The version ID or undefined.
763
1438
  */
764
- promptApplicationId: string | null;
1439
+ get versionId(): string;
1440
+ get applicationId(): string;
765
1441
  /**
766
- * The ID of the workspace where this chat completion was executed.
1442
+ * Gets the variables of this canvas.
1443
+ *
1444
+ * @returns The variables of the canvas.
767
1445
  */
768
- workspaceId: string;
1446
+ get variables(): Array<CanvasVariable>;
769
1447
  /**
770
- * The timestamp when this chat completion was created.
1448
+ * Validates and parses input variables using the canvas input schema.
1449
+ *
1450
+ * @param variables - Raw input variables to validate.
1451
+ * @returns Parsed and validated variables.
1452
+ * @throws {ZodError} If validation fails when a Zod schema is configured.
771
1453
  */
772
- createdAt: string;
1454
+ private parseVariables;
773
1455
  /**
774
- * The timestamp when this chat completion was last updated.
1456
+ * Executes this canvas with the provided input variables.
1457
+ * Creates and starts a canvas execution, handling variable validation and schema parsing.
1458
+ *
1459
+ * Returns a promise-like object that allows flexible usage patterns:
1460
+ * - Await for the execution object: `const exec = await canvas.execute(vars)`
1461
+ * - Direct result access: `const result = await canvas.execute(vars).result`
1462
+ * - Stream iteration: `for await (const chunk of canvas.execute(vars, { stream: true }).result)`
1463
+ *
1464
+ * @param variables - Input variables to pass to the canvas template.
1465
+ * @param params - Optional execution parameters (sync/async/stream configuration).
1466
+ * @returns A promise-like object with a `result` property for direct result access.
1467
+ *
1468
+ * @example
1469
+ * ```typescript
1470
+ * // Direct result access (recommended for simple cases)
1471
+ * const result = await canvas.execute({ query: "Hello" }).result;
1472
+ *
1473
+ * // Get execution object for control (e.g., to abort)
1474
+ * const execution = await canvas.execute({ query: "Hello" });
1475
+ * const result = await execution.result;
1476
+ *
1477
+ * // Asynchronous execution with polling
1478
+ * const result = await canvas.execute(
1479
+ * { query: "Hello" },
1480
+ * { async: true, pollingInterval: 500 }
1481
+ * ).result;
1482
+ *
1483
+ * // Streaming execution
1484
+ * for await (const chunk of canvas.execute(
1485
+ * { query: "Hello" },
1486
+ * { stream: true }
1487
+ * ).result) {
1488
+ * console.log(chunk);
1489
+ * }
1490
+ *
1491
+ * // Execution with tags
1492
+ * const result = await canvas.execute(
1493
+ * { query: "Hello" },
1494
+ * { tags: ["production", "analytics"] }
1495
+ * ).result;
1496
+ * ```
775
1497
  */
776
- updatedAt: string;
1498
+ execute(variables: z.input<TInput>, params?: SyncExecutionParams): CanvasExecutionPromiseLike<SyncExecutionParams, Output<TInput>, Output<TOutput>>;
1499
+ execute(variables: z.input<TInput>, params?: AsyncExecutionParams): CanvasExecutionPromiseLike<AsyncExecutionParams, Output<TInput>, Output<TOutput>>;
1500
+ execute(variables: z.input<TInput>, params?: StreamExecutionParams): CanvasExecutionPromiseLike<StreamExecutionParams, Output<TInput>, Output<TOutput>>;
777
1501
  /**
778
- * The timestamp when this chat completion was deleted, if applicable.
1502
+ * Fetches an existing async execution by its ID.
1503
+ *
1504
+ * This method retrieves the current state of an async execution that was previously
1505
+ * started on this canvas. Only async executions can be fetched, as they are the only
1506
+ * ones with persistent UUIDs on the server.
1507
+ *
1508
+ * @param id - The UUID of the async execution to fetch.
1509
+ * @param options - Optional configuration for polling behavior.
1510
+ * @param options.pollingInterval - Time in milliseconds between polling attempts (default: 1000).
1511
+ * @param options.pollingTimeout - Maximum time in milliseconds to wait for completion (default: 60000).
1512
+ * @throws {InvalidExecutionModeError} If the provided ID is not a valid UUID.
1513
+ * @returns A promise resolving to a CanvasExecution instance with the fetched state.
1514
+ *
1515
+ * @example
1516
+ * ```typescript
1517
+ * // Start an async execution
1518
+ * const execution = await canvas.execute({ query: 'test' }, { async: true })
1519
+ * const executionId = execution.id
1520
+ *
1521
+ * // Later, fetch the execution by ID
1522
+ * const fetched = await canvas.getExecution(executionId)
1523
+ * console.log(fetched.status) // 'running', 'succeeded', or 'failed'
1524
+ *
1525
+ * // Use poll() for event-driven progress tracking
1526
+ * fetched.on('statusChange', (status) => console.log('Status:', status))
1527
+ * fetched.poll()
1528
+ * ```
779
1529
  */
780
- deletedAt: string | null;
1530
+ getExecution(id: string, options?: {
1531
+ pollingInterval?: number;
1532
+ pollingTimeout?: number;
1533
+ }): Promise<CanvasExecution<AsyncExecutionParams, unknown, Output<TOutput>>>;
781
1534
  }
782
1535
 
1536
+ /**
1537
+ * Tela SDK main entry point and client initialization.
1538
+ *
1539
+ * This module provides the main TelaSDK class for initializing the client
1540
+ * and accessing all Tela API resources including canvas management, file
1541
+ * handling, and error classes.
1542
+ *
1543
+ * @module Core
1544
+ */
1545
+
783
1546
  /**
784
1547
  * Configuration options for the TelaSDK.
785
1548
  *
@@ -806,6 +1569,8 @@ interface TelaSDKOptions extends Omit<BaseClientOptions, 'baseURL'> {
806
1569
  *
807
1570
  * Provides methods to access various Tela API resources.
808
1571
  *
1572
+ * @category SDK
1573
+ *
809
1574
  * @example
810
1575
  * ```typescript
811
1576
  * const tela = new TelaSDK({ apiKey: 'your-api-key' });
@@ -823,29 +1588,49 @@ declare class TelaSDK extends BaseClient {
823
1588
  * Creates a new instance of the TelaSDK.
824
1589
  */
825
1590
  constructor({ baseURL, apiKey, jwt, ...rest }: TelaSDKOptions);
1591
+ get authToken(): string;
826
1592
  private validateAuth;
827
1593
  protected getAuthHeaders(): Record<string, string>;
828
1594
  /**
829
- * The ChatCompletions resource for interacting with Tela's chat completion API.
1595
+ * Creates a new `TelaFile` instance from the provided file input.
1596
+ *
1597
+ * @param file - The file input to create a `TelaFile` instance from.
1598
+ * @returns A new `TelaFile` instance.
1599
+ */
1600
+ createFile: typeof TelaFile.create;
1601
+ /**
1602
+ * Retrieves a canvas by its ID, version ID, or application ID.
1603
+ * Validates input and output schemas if provided via schema builder functions.
830
1604
  *
831
- * Use this to generate chat completions based on provided messages.
1605
+ * @param options - Options for retrieving the canvas.
1606
+ * @returns A promise resolving to a Canvas instance.
832
1607
  *
833
1608
  * @example
834
1609
  * ```typescript
835
- * const completion = await tela.completions.create({
836
- * canvasId: "your-canvas-id",
837
- * messages: [{ role: "user", content: "Hello!" }],
1610
+ * // Get canvas by ID with schemas
1611
+ * const canvas = await tela.canvas.get({
1612
+ * id: 'canvas-id',
1613
+ * input: schema => schema.object({
1614
+ * query: schema.string()
1615
+ * }),
1616
+ * output: schema => schema.object({
1617
+ * response: schema.string()
1618
+ * })
838
1619
  * });
839
- * ```
840
- */
841
- completions: ChatCompletions;
842
- /**
843
- * Creates a new `TelaFile` instance from the provided file input.
844
1620
  *
845
- * @param file - The file input to create a `TelaFile` instance from.
846
- * @returns A new `TelaFile` instance.
1621
+ * // Get canvas by application ID
1622
+ * const canvas = await tela.canvas.get({
1623
+ * applicationId: 'app-id'
1624
+ * });
1625
+ *
1626
+ * // Execute the canvas
1627
+ * const execution = await canvas.execute({ query: 'Hello' });
1628
+ * const result = await execution.result;
1629
+ * ```
847
1630
  */
848
- createFile: typeof createTelaFile;
1631
+ canvas: {
1632
+ 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>>;
1633
+ };
849
1634
  static TelaSDK: typeof TelaSDK;
850
1635
  static DEFAULT_TIMEOUT: number;
851
1636
  /** Thrown when an API request fails. */
@@ -891,4 +1676,4 @@ declare class TelaSDK extends BaseClient {
891
1676
  */
892
1677
  declare function createTelaClient(opts: TelaSDKOptions): TelaSDK;
893
1678
 
894
- export { TelaFile, TelaSDK, type TelaSDKOptions, createTelaClient };
1679
+ 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 };