@meistrari/tela-sdk-js 2.0.0 → 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/README.md +771 -1
- package/dist/index.cjs +314 -32
- package/dist/index.d.cts +641 -29
- package/dist/index.d.mts +641 -29
- package/dist/index.d.ts +641 -29
- package/dist/index.mjs +318 -37
- package/package.json +36 -35
package/dist/index.mjs
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import * as changeCase from 'change-case';
|
|
2
2
|
import { minimatch } from 'minimatch';
|
|
3
|
-
import
|
|
3
|
+
import * as z from 'zod';
|
|
4
|
+
import z__default, { z as z$1, ZodError } from 'zod';
|
|
5
|
+
import Emittery from 'emittery';
|
|
4
6
|
|
|
5
|
-
const version = "2.
|
|
7
|
+
const version = "2.1.0";
|
|
6
8
|
|
|
7
9
|
var __defProp$7 = Object.defineProperty;
|
|
8
10
|
var __defNormalProp$7 = (obj, key, value) => key in obj ? __defProp$7(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
@@ -1023,17 +1025,9 @@ var __publicField$4 = (obj, key, value) => {
|
|
|
1023
1025
|
return value;
|
|
1024
1026
|
};
|
|
1025
1027
|
function TelaFileSchema() {
|
|
1026
|
-
return
|
|
1028
|
+
return z__default.custom((value) => value instanceof TelaFile, { message: "Value must be an instance of TelaFile" }).meta({ isTelaFile: true });
|
|
1027
1029
|
}
|
|
1028
1030
|
class TelaFile {
|
|
1029
|
-
/**
|
|
1030
|
-
* Creates an instance of `TelaFile`.
|
|
1031
|
-
*
|
|
1032
|
-
* @param file - The source of the file. Can be a URL string, Uint8Array, ReadableStream, ReadStream, Blob, or File.
|
|
1033
|
-
* @param options - Optional configuration options such as byte range.
|
|
1034
|
-
* @throws {InvalidFileURL} If the provided URL is not valid.
|
|
1035
|
-
* @throws {EmptyFileError} If the provided file is empty.
|
|
1036
|
-
*/
|
|
1037
1031
|
constructor(file, options = {}) {
|
|
1038
1032
|
__publicField$4(this, "_file");
|
|
1039
1033
|
__publicField$4(this, "_options");
|
|
@@ -1411,7 +1405,7 @@ class Poller {
|
|
|
1411
1405
|
const resultPromise = async () => {
|
|
1412
1406
|
try {
|
|
1413
1407
|
while (!this._abortSignal.aborted) {
|
|
1414
|
-
const result = await
|
|
1408
|
+
const result = await callback(this._abortSignal);
|
|
1415
1409
|
if (result.done) {
|
|
1416
1410
|
return result.value;
|
|
1417
1411
|
}
|
|
@@ -1473,7 +1467,11 @@ function isTelaFile(obj) {
|
|
|
1473
1467
|
function isTelaFileArray(obj) {
|
|
1474
1468
|
return Array.isArray(obj) && obj.length > 0 && obj.every(isTelaFile);
|
|
1475
1469
|
}
|
|
1476
|
-
|
|
1470
|
+
function isUUID(str) {
|
|
1471
|
+
const uuidRegex = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
1472
|
+
return uuidRegex.test(str);
|
|
1473
|
+
}
|
|
1474
|
+
class CanvasExecution extends Emittery {
|
|
1477
1475
|
/**
|
|
1478
1476
|
* Creates a new canvas execution instance.
|
|
1479
1477
|
*
|
|
@@ -1483,16 +1481,18 @@ class CanvasExecution {
|
|
|
1483
1481
|
* @param client - HTTP client instance for making API requests.
|
|
1484
1482
|
*/
|
|
1485
1483
|
constructor(variables, params = { async: false }, outputSchema, client) {
|
|
1484
|
+
super();
|
|
1486
1485
|
__publicField$2(this, "_id");
|
|
1486
|
+
__publicField$2(this, "_status");
|
|
1487
1487
|
__publicField$2(this, "_variables");
|
|
1488
1488
|
__publicField$2(this, "_params");
|
|
1489
1489
|
__publicField$2(this, "_client");
|
|
1490
1490
|
__publicField$2(this, "_outputSchema");
|
|
1491
1491
|
__publicField$2(this, "_skipResultValidation");
|
|
1492
1492
|
__publicField$2(this, "_abortController");
|
|
1493
|
-
__publicField$2(this, "_startPropmise");
|
|
1494
1493
|
__publicField$2(this, "_resultPromise");
|
|
1495
1494
|
__publicField$2(this, "_stream");
|
|
1495
|
+
__publicField$2(this, "_rawResultValue");
|
|
1496
1496
|
this._variables = variables;
|
|
1497
1497
|
this._params = params;
|
|
1498
1498
|
this._outputSchema = outputSchema;
|
|
@@ -1500,18 +1500,138 @@ class CanvasExecution {
|
|
|
1500
1500
|
this._client = client;
|
|
1501
1501
|
this._abortController = new AbortController();
|
|
1502
1502
|
}
|
|
1503
|
+
/**
|
|
1504
|
+
* Fetches an existing asynchronous execution by its ID.
|
|
1505
|
+
*
|
|
1506
|
+
* This method retrieves the current state of an async execution and creates a new
|
|
1507
|
+
* CanvasExecution instance with the fetched data. Only async executions can be
|
|
1508
|
+
* fetched, as they are the only ones with persistent UUIDs on the server.
|
|
1509
|
+
*
|
|
1510
|
+
* @param id - The UUID of the async execution to fetch.
|
|
1511
|
+
* @param outputSchema - Zod schema or object schema for validating/parsing output.
|
|
1512
|
+
* @param client - HTTP client instance for making API requests.
|
|
1513
|
+
* @param options - Optional configuration for polling behavior.
|
|
1514
|
+
* @param options.pollingInterval - Time in milliseconds between polling attempts (default: 1000).
|
|
1515
|
+
* @param options.pollingTimeout - Maximum time in milliseconds to wait for completion (default: 60000).
|
|
1516
|
+
* @throws {InvalidExecutionModeError} If the provided ID is not a valid UUID.
|
|
1517
|
+
* @returns A promise resolving to a CanvasExecution instance with the fetched state.
|
|
1518
|
+
*
|
|
1519
|
+
* @example
|
|
1520
|
+
* ```typescript
|
|
1521
|
+
* const execution = await CanvasExecution.fetch(
|
|
1522
|
+
* 'execution-uuid',
|
|
1523
|
+
* z.object({ result: z.string() }),
|
|
1524
|
+
* client,
|
|
1525
|
+
* { pollingInterval: 2000, pollingTimeout: 120000 }
|
|
1526
|
+
* )
|
|
1527
|
+
* console.log(execution.status) // 'running' or 'succeeded' or 'failed'
|
|
1528
|
+
* ```
|
|
1529
|
+
*/
|
|
1530
|
+
static async fetch(id, outputSchema, client, options) {
|
|
1531
|
+
if (!isUUID(id)) {
|
|
1532
|
+
throw new InvalidExecutionModeError(
|
|
1533
|
+
"Only async executions can be fetched by ID. The provided ID is not a valid UUID."
|
|
1534
|
+
);
|
|
1535
|
+
}
|
|
1536
|
+
const response = await client.get(
|
|
1537
|
+
`/v2/chat/completions/${id}`
|
|
1538
|
+
);
|
|
1539
|
+
const params = {
|
|
1540
|
+
async: true,
|
|
1541
|
+
pollingInterval: options?.pollingInterval,
|
|
1542
|
+
pollingTimeout: options?.pollingTimeout
|
|
1543
|
+
};
|
|
1544
|
+
const execution = new CanvasExecution(
|
|
1545
|
+
{},
|
|
1546
|
+
// No variables needed for fetched execution
|
|
1547
|
+
params,
|
|
1548
|
+
outputSchema,
|
|
1549
|
+
client
|
|
1550
|
+
);
|
|
1551
|
+
execution._id = response.id;
|
|
1552
|
+
execution.status = response.status;
|
|
1553
|
+
if (response.status === "succeeded") {
|
|
1554
|
+
execution._rawResultValue = response;
|
|
1555
|
+
const content = response.outputContent.content;
|
|
1556
|
+
try {
|
|
1557
|
+
const validatedContent = execution._skipResultValidation || !(outputSchema instanceof z__default.ZodType) ? content : outputSchema.parse(content);
|
|
1558
|
+
execution._resultPromise = Promise.resolve(validatedContent);
|
|
1559
|
+
} catch (error) {
|
|
1560
|
+
execution._resultPromise = Promise.reject(error);
|
|
1561
|
+
execution._resultPromise.catch(() => {
|
|
1562
|
+
});
|
|
1563
|
+
}
|
|
1564
|
+
} else if (response.status === "failed") {
|
|
1565
|
+
execution._rawResultValue = response;
|
|
1566
|
+
const error = new ExecutionFailedError(response.rawOutput);
|
|
1567
|
+
execution._resultPromise = Promise.reject(error);
|
|
1568
|
+
execution._resultPromise.catch(() => {
|
|
1569
|
+
});
|
|
1570
|
+
}
|
|
1571
|
+
return execution;
|
|
1572
|
+
}
|
|
1503
1573
|
/**
|
|
1504
1574
|
* Gets the unique execution ID assigned by the server.
|
|
1505
1575
|
*
|
|
1506
|
-
*
|
|
1576
|
+
* Note: Streaming executions do not have an ID as they don't create a tracked execution on the server.
|
|
1577
|
+
*
|
|
1578
|
+
* @throws {ExecutionNotStartedError} If the execution has not been started yet.
|
|
1579
|
+
* @throws {InvalidExecutionModeError} If called on a streaming execution (streams don't have IDs).
|
|
1507
1580
|
* @returns The execution ID.
|
|
1508
1581
|
*/
|
|
1509
1582
|
get id() {
|
|
1583
|
+
if (this.isStream) {
|
|
1584
|
+
throw new InvalidExecutionModeError("Streaming executions do not have an execution ID");
|
|
1585
|
+
}
|
|
1510
1586
|
if (!this._id) {
|
|
1511
1587
|
throw new ExecutionNotStartedError();
|
|
1512
1588
|
}
|
|
1513
1589
|
return this._id;
|
|
1514
1590
|
}
|
|
1591
|
+
/**
|
|
1592
|
+
* Gets the latest known status of the execution.
|
|
1593
|
+
*
|
|
1594
|
+
* Status values and transitions:
|
|
1595
|
+
* - **Sync**: `succeeded` (after validation) or `failed` (on any error)
|
|
1596
|
+
* - **Async**: `created` → `running` → `succeeded` or `failed`
|
|
1597
|
+
* - **Stream**: `streaming` (once started)
|
|
1598
|
+
*
|
|
1599
|
+
* **Important:** Status is set to `succeeded` only after successful validation.
|
|
1600
|
+
* If validation fails, status will be `failed` even if the API request succeeded.
|
|
1601
|
+
*
|
|
1602
|
+
* Use the `statusChange` event to track status transitions in real-time.
|
|
1603
|
+
*
|
|
1604
|
+
* @throws {ExecutionNotStartedError} If the execution has not been started yet.
|
|
1605
|
+
* @returns The current status of the execution.
|
|
1606
|
+
*
|
|
1607
|
+
* @example
|
|
1608
|
+
* ```typescript
|
|
1609
|
+
* const execution = await canvas.execute({ query: 'test' }, { async: true })
|
|
1610
|
+
* console.log(execution.status) // 'created'
|
|
1611
|
+
*
|
|
1612
|
+
* await execution.result
|
|
1613
|
+
* console.log(execution.status) // 'succeeded' or 'failed'
|
|
1614
|
+
* ```
|
|
1615
|
+
*/
|
|
1616
|
+
get status() {
|
|
1617
|
+
if (!this._status) {
|
|
1618
|
+
throw new ExecutionNotStartedError();
|
|
1619
|
+
}
|
|
1620
|
+
return this._status;
|
|
1621
|
+
}
|
|
1622
|
+
/**
|
|
1623
|
+
* Sets the status of the execution.
|
|
1624
|
+
*
|
|
1625
|
+
* @param status - The new status of the execution.
|
|
1626
|
+
* @private
|
|
1627
|
+
*/
|
|
1628
|
+
set status(status) {
|
|
1629
|
+
const changed = this._status !== status;
|
|
1630
|
+
this._status = status;
|
|
1631
|
+
if (changed) {
|
|
1632
|
+
this.emit("statusChange", status);
|
|
1633
|
+
}
|
|
1634
|
+
}
|
|
1515
1635
|
/**
|
|
1516
1636
|
* Gets the input variables provided to this execution.
|
|
1517
1637
|
*
|
|
@@ -1552,6 +1672,31 @@ class CanvasExecution {
|
|
|
1552
1672
|
get isStream() {
|
|
1553
1673
|
return Boolean(this._params.stream);
|
|
1554
1674
|
}
|
|
1675
|
+
/**
|
|
1676
|
+
* Gets the raw API response without any processing or validation.
|
|
1677
|
+
* Automatically starts execution and waits for completion (including polling for async executions).
|
|
1678
|
+
*
|
|
1679
|
+
* For sync executions, returns the complete API response.
|
|
1680
|
+
* For async executions, returns the polling response with status and output.
|
|
1681
|
+
*
|
|
1682
|
+
* @throws {InvalidExecutionModeError} If called on a streaming execution.
|
|
1683
|
+
* @returns A promise resolving to the raw API result.
|
|
1684
|
+
*/
|
|
1685
|
+
get rawResult() {
|
|
1686
|
+
if (this.isStream) {
|
|
1687
|
+
throw new InvalidExecutionModeError("rawResult is not available for streaming executions");
|
|
1688
|
+
}
|
|
1689
|
+
if (this.isSync) {
|
|
1690
|
+
if (!this._resultPromise) {
|
|
1691
|
+
throw new ExecutionNotStartedError();
|
|
1692
|
+
}
|
|
1693
|
+
return this._resultPromise.then(() => this._rawResultValue);
|
|
1694
|
+
}
|
|
1695
|
+
if (!this._resultPromise) {
|
|
1696
|
+
this._resultPromise = this.startPolling();
|
|
1697
|
+
}
|
|
1698
|
+
return this._resultPromise.then(() => this._rawResultValue);
|
|
1699
|
+
}
|
|
1555
1700
|
/**
|
|
1556
1701
|
* Type guard to check if params indicate async execution.
|
|
1557
1702
|
*
|
|
@@ -1610,25 +1755,95 @@ class CanvasExecution {
|
|
|
1610
1755
|
cancel() {
|
|
1611
1756
|
this._abortController.abort();
|
|
1612
1757
|
}
|
|
1758
|
+
/**
|
|
1759
|
+
* Starts polling for the execution result without waiting for the promise to resolve.
|
|
1760
|
+
* This allows users to track execution progress via events rather than awaiting a promise.
|
|
1761
|
+
*
|
|
1762
|
+
* The following events will be emitted during polling:
|
|
1763
|
+
* - `statusChange`: Emitted when the execution status changes (e.g., 'created' → 'running' → 'succeeded')
|
|
1764
|
+
* - `poll`: Emitted on each polling attempt with the server response
|
|
1765
|
+
* - `success`: Emitted when the execution completes successfully with the final result
|
|
1766
|
+
* - `error`: Emitted if the execution fails
|
|
1767
|
+
*
|
|
1768
|
+
* **Important:** Events are only emitted while polling is active. You must either call `poll()` or
|
|
1769
|
+
* await `execution.result` to start polling. Simply setting up event listeners without starting
|
|
1770
|
+
* polling will not trigger any events.
|
|
1771
|
+
*
|
|
1772
|
+
* **Note:** If the execution has already completed (succeeded or failed) when fetched, the `success`
|
|
1773
|
+
* and `error` events will not fire since no polling is needed. Check the `status` property and
|
|
1774
|
+
* access the `result` directly for already-completed executions.
|
|
1775
|
+
*
|
|
1776
|
+
* @throws {InvalidExecutionModeError} If called on a non-async execution (sync or stream).
|
|
1777
|
+
* @throws {ExecutionNotStartedError} If the execution has not been started yet (no ID assigned).
|
|
1778
|
+
*
|
|
1779
|
+
* @example
|
|
1780
|
+
* ```typescript
|
|
1781
|
+
* const execution = await canvas.getExecution('execution-id')
|
|
1782
|
+
*
|
|
1783
|
+
* // Check if already completed
|
|
1784
|
+
* if (execution.status === 'succeeded' || execution.status === 'failed') {
|
|
1785
|
+
* // Access result directly - events won't fire
|
|
1786
|
+
* const result = await execution.result
|
|
1787
|
+
* console.log('Already completed:', result)
|
|
1788
|
+
* } else {
|
|
1789
|
+
* // Still running - set up events and start polling
|
|
1790
|
+
* execution.on('statusChange', (status) => {
|
|
1791
|
+
* console.log('Status:', status)
|
|
1792
|
+
* })
|
|
1793
|
+
*
|
|
1794
|
+
* execution.on('success', (result) => {
|
|
1795
|
+
* console.log('Completed:', result)
|
|
1796
|
+
* })
|
|
1797
|
+
*
|
|
1798
|
+
* execution.on('error', (error) => {
|
|
1799
|
+
* console.error('Failed:', error)
|
|
1800
|
+
* })
|
|
1801
|
+
*
|
|
1802
|
+
* // Start polling without waiting
|
|
1803
|
+
* execution.poll()
|
|
1804
|
+
* }
|
|
1805
|
+
* ```
|
|
1806
|
+
*/
|
|
1807
|
+
poll() {
|
|
1808
|
+
if (!this.isAsync) {
|
|
1809
|
+
throw new InvalidExecutionModeError("Polling is only supported for async executions");
|
|
1810
|
+
}
|
|
1811
|
+
if (!this._id) {
|
|
1812
|
+
throw new ExecutionNotStartedError();
|
|
1813
|
+
}
|
|
1814
|
+
if (this._resultPromise) {
|
|
1815
|
+
return;
|
|
1816
|
+
}
|
|
1817
|
+
this._resultPromise = this.startPolling();
|
|
1818
|
+
this._resultPromise.catch(() => {
|
|
1819
|
+
});
|
|
1820
|
+
}
|
|
1613
1821
|
/**
|
|
1614
1822
|
* Builds the base request body shared across all execution types.
|
|
1615
|
-
* Includes messages, overrides, and structured output configuration.
|
|
1823
|
+
* Includes messages, overrides, tags, label, and structured output configuration.
|
|
1616
1824
|
*
|
|
1617
1825
|
* @returns The base request body object.
|
|
1618
1826
|
*/
|
|
1619
1827
|
get baseBody() {
|
|
1828
|
+
if (this._params.label && !this._params.applicationId) {
|
|
1829
|
+
console.warn(
|
|
1830
|
+
'[Tela SDK - WARNING] The "label" field is only applicable when using applicationId. It will be ignored since no applicationId is provided.'
|
|
1831
|
+
);
|
|
1832
|
+
}
|
|
1620
1833
|
const body = {
|
|
1621
1834
|
canvasId: this._params.canvasId,
|
|
1622
1835
|
applicationId: this._params.applicationId,
|
|
1623
1836
|
versionId: this._params.versionId,
|
|
1624
|
-
messages: this._params.messages
|
|
1837
|
+
messages: this._params.messages,
|
|
1838
|
+
tags: this._params.tags,
|
|
1839
|
+
label: this._params.label
|
|
1625
1840
|
};
|
|
1626
|
-
if (this._params.override && this._outputSchema instanceof
|
|
1841
|
+
if (this._params.override && this._outputSchema instanceof z__default.ZodType) {
|
|
1627
1842
|
return {
|
|
1628
1843
|
...body,
|
|
1629
1844
|
override: {
|
|
1630
1845
|
...this._params.override,
|
|
1631
|
-
structured_output:
|
|
1846
|
+
structured_output: z__default.toJSONSchema(this._outputSchema)
|
|
1632
1847
|
}
|
|
1633
1848
|
};
|
|
1634
1849
|
}
|
|
@@ -1675,12 +1890,20 @@ class CanvasExecution {
|
|
|
1675
1890
|
signal: this._abortController.signal
|
|
1676
1891
|
}).then((response) => {
|
|
1677
1892
|
this._id = response.id;
|
|
1893
|
+
this._rawResultValue = response;
|
|
1678
1894
|
return response.choices?.[0]?.message?.content;
|
|
1679
1895
|
}).then((content) => {
|
|
1680
|
-
|
|
1681
|
-
|
|
1896
|
+
const validatedContent = this._skipResultValidation || !(this._outputSchema instanceof z__default.ZodType) ? content : this._outputSchema.parse(content);
|
|
1897
|
+
this.status = "succeeded";
|
|
1898
|
+
this.emit("success", validatedContent);
|
|
1899
|
+
return validatedContent;
|
|
1900
|
+
}).catch((error) => {
|
|
1901
|
+
this.status = "failed";
|
|
1902
|
+
if (this.listenerCount("error") > 0) {
|
|
1903
|
+
this.emit("error", error);
|
|
1904
|
+
return;
|
|
1682
1905
|
}
|
|
1683
|
-
|
|
1906
|
+
throw error;
|
|
1684
1907
|
});
|
|
1685
1908
|
return this._resultPromise;
|
|
1686
1909
|
}
|
|
@@ -1704,6 +1927,13 @@ class CanvasExecution {
|
|
|
1704
1927
|
signal: this._abortController.signal
|
|
1705
1928
|
}).then((response) => {
|
|
1706
1929
|
this._id = response.id;
|
|
1930
|
+
this.status = response.status;
|
|
1931
|
+
this.emit("poll", {
|
|
1932
|
+
id: response.id,
|
|
1933
|
+
status: response.status,
|
|
1934
|
+
outputContent: response.output_content,
|
|
1935
|
+
rawOutput: response.raw_output
|
|
1936
|
+
});
|
|
1707
1937
|
return response;
|
|
1708
1938
|
});
|
|
1709
1939
|
}
|
|
@@ -1724,6 +1954,7 @@ class CanvasExecution {
|
|
|
1724
1954
|
stream: true,
|
|
1725
1955
|
signal: this._abortController.signal
|
|
1726
1956
|
});
|
|
1957
|
+
this.status = "streaming";
|
|
1727
1958
|
return this._stream;
|
|
1728
1959
|
}
|
|
1729
1960
|
/**
|
|
@@ -1752,8 +1983,12 @@ class CanvasExecution {
|
|
|
1752
1983
|
signal
|
|
1753
1984
|
}
|
|
1754
1985
|
);
|
|
1986
|
+
this.status = response.status;
|
|
1987
|
+
this.emit("poll", response);
|
|
1755
1988
|
if (response.status === "failed") {
|
|
1756
|
-
|
|
1989
|
+
const error = new ExecutionFailedError(response.rawOutput);
|
|
1990
|
+
this.emit("error", error);
|
|
1991
|
+
throw error;
|
|
1757
1992
|
}
|
|
1758
1993
|
if (response.status !== "succeeded") {
|
|
1759
1994
|
return {
|
|
@@ -1761,15 +1996,28 @@ class CanvasExecution {
|
|
|
1761
1996
|
value: void 0
|
|
1762
1997
|
};
|
|
1763
1998
|
}
|
|
1999
|
+
this._rawResultValue = response;
|
|
2000
|
+
this.emit("success", response.outputContent.content);
|
|
1764
2001
|
return {
|
|
1765
2002
|
done: response.status === "succeeded",
|
|
1766
2003
|
value: response.outputContent.content
|
|
1767
2004
|
};
|
|
1768
2005
|
}).then((value) => {
|
|
1769
|
-
if (this._skipResultValidation || !(this._outputSchema instanceof
|
|
2006
|
+
if (this._skipResultValidation || !(this._outputSchema instanceof z__default.ZodType)) {
|
|
1770
2007
|
return value;
|
|
1771
2008
|
}
|
|
1772
2009
|
return this._outputSchema.parse(value);
|
|
2010
|
+
}).catch((error) => {
|
|
2011
|
+
if (this._status !== "failed") {
|
|
2012
|
+
this.status = "failed";
|
|
2013
|
+
}
|
|
2014
|
+
if (this.listenerCount("error") > 0) {
|
|
2015
|
+
if (!(error instanceof ExecutionFailedError)) {
|
|
2016
|
+
this.emit("error", error);
|
|
2017
|
+
}
|
|
2018
|
+
return;
|
|
2019
|
+
}
|
|
2020
|
+
throw error;
|
|
1773
2021
|
});
|
|
1774
2022
|
}
|
|
1775
2023
|
/**
|
|
@@ -1862,14 +2110,8 @@ var __publicField$1 = (obj, key, value) => {
|
|
|
1862
2110
|
return value;
|
|
1863
2111
|
};
|
|
1864
2112
|
const zod = {
|
|
1865
|
-
|
|
1866
|
-
|
|
1867
|
-
boolean,
|
|
1868
|
-
object,
|
|
1869
|
-
array,
|
|
1870
|
-
file: TelaFileSchema,
|
|
1871
|
-
any,
|
|
1872
|
-
unknown
|
|
2113
|
+
...z,
|
|
2114
|
+
file: TelaFileSchema
|
|
1873
2115
|
};
|
|
1874
2116
|
function fetchById(id, client) {
|
|
1875
2117
|
return client.get(`/prompt/${id}/promoted-version`);
|
|
@@ -2083,6 +2325,43 @@ class Canvas {
|
|
|
2083
2325
|
}
|
|
2084
2326
|
};
|
|
2085
2327
|
}
|
|
2328
|
+
/**
|
|
2329
|
+
* Fetches an existing async execution by its ID.
|
|
2330
|
+
*
|
|
2331
|
+
* This method retrieves the current state of an async execution that was previously
|
|
2332
|
+
* started on this canvas. Only async executions can be fetched, as they are the only
|
|
2333
|
+
* ones with persistent UUIDs on the server.
|
|
2334
|
+
*
|
|
2335
|
+
* @param id - The UUID of the async execution to fetch.
|
|
2336
|
+
* @param options - Optional configuration for polling behavior.
|
|
2337
|
+
* @param options.pollingInterval - Time in milliseconds between polling attempts (default: 1000).
|
|
2338
|
+
* @param options.pollingTimeout - Maximum time in milliseconds to wait for completion (default: 60000).
|
|
2339
|
+
* @throws {InvalidExecutionModeError} If the provided ID is not a valid UUID.
|
|
2340
|
+
* @returns A promise resolving to a CanvasExecution instance with the fetched state.
|
|
2341
|
+
*
|
|
2342
|
+
* @example
|
|
2343
|
+
* ```typescript
|
|
2344
|
+
* // Start an async execution
|
|
2345
|
+
* const execution = await canvas.execute({ query: 'test' }, { async: true })
|
|
2346
|
+
* const executionId = execution.id
|
|
2347
|
+
*
|
|
2348
|
+
* // Later, fetch the execution by ID
|
|
2349
|
+
* const fetched = await canvas.getExecution(executionId)
|
|
2350
|
+
* console.log(fetched.status) // 'running', 'succeeded', or 'failed'
|
|
2351
|
+
*
|
|
2352
|
+
* // Use poll() for event-driven progress tracking
|
|
2353
|
+
* fetched.on('statusChange', (status) => console.log('Status:', status))
|
|
2354
|
+
* fetched.poll()
|
|
2355
|
+
* ```
|
|
2356
|
+
*/
|
|
2357
|
+
async getExecution(id, options) {
|
|
2358
|
+
return CanvasExecution.fetch(
|
|
2359
|
+
id,
|
|
2360
|
+
this._output,
|
|
2361
|
+
this._client,
|
|
2362
|
+
options
|
|
2363
|
+
);
|
|
2364
|
+
}
|
|
2086
2365
|
}
|
|
2087
2366
|
|
|
2088
2367
|
var __defProp = Object.defineProperty;
|
|
@@ -2110,20 +2389,22 @@ const _TelaSDK = class _TelaSDK extends BaseClient {
|
|
|
2110
2389
|
__publicField(this, "createFile", TelaFile.create.bind(this));
|
|
2111
2390
|
/**
|
|
2112
2391
|
* Retrieves a canvas by its ID, version ID, or application ID.
|
|
2113
|
-
* Validates input and output schemas if
|
|
2392
|
+
* Validates input and output schemas if provided via schema builder functions.
|
|
2114
2393
|
*
|
|
2115
2394
|
* @param options - Options for retrieving the canvas.
|
|
2116
2395
|
* @returns A promise resolving to a Canvas instance.
|
|
2117
2396
|
*
|
|
2118
2397
|
* @example
|
|
2119
2398
|
* ```typescript
|
|
2120
|
-
* import { z } from 'zod';
|
|
2121
|
-
*
|
|
2122
2399
|
* // Get canvas by ID with schemas
|
|
2123
2400
|
* const canvas = await tela.canvas.get({
|
|
2124
2401
|
* id: 'canvas-id',
|
|
2125
|
-
* input:
|
|
2126
|
-
*
|
|
2402
|
+
* input: schema => schema.object({
|
|
2403
|
+
* query: schema.string()
|
|
2404
|
+
* }),
|
|
2405
|
+
* output: schema => schema.object({
|
|
2406
|
+
* response: schema.string()
|
|
2407
|
+
* })
|
|
2127
2408
|
* });
|
|
2128
2409
|
*
|
|
2129
2410
|
* // Get canvas by application ID
|
package/package.json
CHANGED
|
@@ -1,14 +1,38 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@meistrari/tela-sdk-js",
|
|
3
|
-
"version": "2.
|
|
4
|
-
"type": "module",
|
|
3
|
+
"version": "2.1.0",
|
|
5
4
|
"repository": {
|
|
6
5
|
"type": "git",
|
|
7
6
|
"url": "https://github.com/meistrari/tela-sdk-js.git"
|
|
8
7
|
},
|
|
9
|
-
"types": "dist/index.d.ts",
|
|
10
8
|
"main": "dist/index.mjs",
|
|
11
9
|
"module": "dist/index.mjs",
|
|
10
|
+
"dependencies": {
|
|
11
|
+
"change-case": "5.4.4",
|
|
12
|
+
"emittery": "^1.2.0",
|
|
13
|
+
"minimatch": "10.0.1",
|
|
14
|
+
"zod": "4.1.12"
|
|
15
|
+
},
|
|
16
|
+
"devDependencies": {
|
|
17
|
+
"@antfu/eslint-config": "3.0.0",
|
|
18
|
+
"@types/bun": "1.2.23",
|
|
19
|
+
"@types/node": "22.5.5",
|
|
20
|
+
"@typhonjs-typedoc/typedoc-theme-dmt": "0.4.0",
|
|
21
|
+
"@vitest/browser": "3.0.8",
|
|
22
|
+
"husky": "9.1.6",
|
|
23
|
+
"lint-staged": "15.2.10",
|
|
24
|
+
"playwright": "1.51.0",
|
|
25
|
+
"typedoc": "0.28.14",
|
|
26
|
+
"typedoc-plugin-merge-modules": "7.0.0",
|
|
27
|
+
"typedoc-unhoax-theme": "0.5.3",
|
|
28
|
+
"typescript": "5.6.3",
|
|
29
|
+
"unbuild": "2.0.0",
|
|
30
|
+
"unenv": "2.0.0-rc.14",
|
|
31
|
+
"vitest": "3.0.8"
|
|
32
|
+
},
|
|
33
|
+
"peerDependencies": {
|
|
34
|
+
"typescript": "5.6.3"
|
|
35
|
+
},
|
|
12
36
|
"exports": {
|
|
13
37
|
".": {
|
|
14
38
|
"types": "./dist/index.d.ts",
|
|
@@ -16,11 +40,16 @@
|
|
|
16
40
|
"require": "./dist/index.cjs"
|
|
17
41
|
}
|
|
18
42
|
},
|
|
43
|
+
"engines": {
|
|
44
|
+
"node": "^20.15.1"
|
|
45
|
+
},
|
|
19
46
|
"files": [
|
|
20
47
|
"dist"
|
|
21
48
|
],
|
|
22
|
-
"
|
|
23
|
-
"
|
|
49
|
+
"lint-staged": {
|
|
50
|
+
"*.{js,ts}": [
|
|
51
|
+
"eslint --fix"
|
|
52
|
+
]
|
|
24
53
|
},
|
|
25
54
|
"scripts": {
|
|
26
55
|
"prepublishOnly": "bun run build",
|
|
@@ -39,34 +68,6 @@
|
|
|
39
68
|
"docs": "typedoc",
|
|
40
69
|
"docs:serve": "bunx http-server docs"
|
|
41
70
|
},
|
|
42
|
-
"
|
|
43
|
-
|
|
44
|
-
"change-case": "5.4.4",
|
|
45
|
-
"minimatch": "10.0.1",
|
|
46
|
-
"zod": "4.1.12"
|
|
47
|
-
},
|
|
48
|
-
"devDependencies": {
|
|
49
|
-
"@antfu/eslint-config": "3.0.0",
|
|
50
|
-
"@types/bun": "1.2.23",
|
|
51
|
-
"@types/node": "22.5.5",
|
|
52
|
-
"@typhonjs-typedoc/typedoc-theme-dmt": "0.4.0",
|
|
53
|
-
"@vitest/browser": "3.0.8",
|
|
54
|
-
"husky": "9.1.6",
|
|
55
|
-
"lint-staged": "15.2.10",
|
|
56
|
-
"playwright": "1.51.0",
|
|
57
|
-
"typedoc": "0.28.14",
|
|
58
|
-
"typedoc-plugin-merge-modules": "7.0.0",
|
|
59
|
-
"typedoc-unhoax-theme": "0.5.3",
|
|
60
|
-
"unbuild": "2.0.0",
|
|
61
|
-
"unenv": "2.0.0-rc.14",
|
|
62
|
-
"vitest": "3.0.8"
|
|
63
|
-
},
|
|
64
|
-
"peerDependencies": {
|
|
65
|
-
"typescript": "5.8.2"
|
|
66
|
-
},
|
|
67
|
-
"lint-staged": {
|
|
68
|
-
"*.{js,ts}": [
|
|
69
|
-
"eslint --fix"
|
|
70
|
-
]
|
|
71
|
-
}
|
|
71
|
+
"type": "module",
|
|
72
|
+
"types": "dist/index.d.ts"
|
|
72
73
|
}
|