@meistrari/tela-sdk-js 2.3.2 → 2.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +25 -10
- package/dist/index.d.cts +1 -1
- package/dist/index.d.mts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.mjs +25 -10
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -24,7 +24,7 @@ const z__default = /*#__PURE__*/_interopDefaultCompat(z);
|
|
|
24
24
|
const z__namespace = /*#__PURE__*/_interopNamespaceCompat(z);
|
|
25
25
|
const Emittery__default = /*#__PURE__*/_interopDefaultCompat(Emittery);
|
|
26
26
|
|
|
27
|
-
const version = "2.
|
|
27
|
+
const version = "2.4.0";
|
|
28
28
|
|
|
29
29
|
var __defProp$7 = Object.defineProperty;
|
|
30
30
|
var __defNormalProp$7 = (obj, key, value) => key in obj ? __defProp$7(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
@@ -864,6 +864,7 @@ class BaseClient {
|
|
|
864
864
|
remainingRetries = options.maxRetries ?? this.maxRetries;
|
|
865
865
|
}
|
|
866
866
|
const { req, url, timeout } = this.buildRequest(options);
|
|
867
|
+
debug("request", `[${options.method}] ${options.path} ${JSON.stringify(options.body)}`);
|
|
867
868
|
if (options.signal?.aborted) {
|
|
868
869
|
throw new UserAbortError();
|
|
869
870
|
}
|
|
@@ -1535,13 +1536,13 @@ function isSyncWorkflowResult(obj) {
|
|
|
1535
1536
|
return "output" in obj;
|
|
1536
1537
|
}
|
|
1537
1538
|
function isAsyncWorkflowResult(obj) {
|
|
1538
|
-
return "outputContent" in obj && "output" in obj.outputContent;
|
|
1539
|
+
return "outputContent" in obj && obj.outputContent && typeof obj.outputContent === "object" && "output" in obj.outputContent;
|
|
1539
1540
|
}
|
|
1540
1541
|
function isSyncCanvasResult(obj) {
|
|
1541
1542
|
return "choices" in obj;
|
|
1542
1543
|
}
|
|
1543
1544
|
function isAsyncCanvasResult(obj) {
|
|
1544
|
-
return "outputContent" in obj && "content" in obj.outputContent;
|
|
1545
|
+
return "outputContent" in obj && obj.outputContent && typeof obj.outputContent === "object" && "content" in obj.outputContent;
|
|
1545
1546
|
}
|
|
1546
1547
|
function getResultFromPollingResponse(response) {
|
|
1547
1548
|
if (isSyncWorkflowResult(response)) {
|
|
@@ -1847,7 +1848,13 @@ class CanvasExecution extends Emittery__default {
|
|
|
1847
1848
|
*
|
|
1848
1849
|
* @returns A promise or async generator depending on execution mode.
|
|
1849
1850
|
*/
|
|
1850
|
-
start() {
|
|
1851
|
+
async start() {
|
|
1852
|
+
if (this._params.applicationId && !this._params.async) {
|
|
1853
|
+
console.warn("[Tela SDK - WARNING] ApplicationId was provided, but async mode was not enabled. This will create a task, and tasks are always async. ");
|
|
1854
|
+
console.warn("[Tela SDK - WARNING] Tasks are not fully supported yet. You can create them, but cannot obtain the results or poll for their status.");
|
|
1855
|
+
console.warn("[Tela SDK - WARNING] To disable these warnings, you can enable async mode explicitly.");
|
|
1856
|
+
this._params.async = true;
|
|
1857
|
+
}
|
|
1851
1858
|
if (this._resultPromise || this._stream) {
|
|
1852
1859
|
return this._resultPromise ?? this._stream;
|
|
1853
1860
|
}
|
|
@@ -1866,15 +1873,19 @@ class CanvasExecution extends Emittery__default {
|
|
|
1866
1873
|
* @returns The execution result as a promise or async generator.
|
|
1867
1874
|
*/
|
|
1868
1875
|
get result() {
|
|
1876
|
+
if (this._params.applicationId && !this._params.canvasId) {
|
|
1877
|
+
const message = "Tasks are not fully supported yet. You can create them, but cannot obtain the results or poll for their status.";
|
|
1878
|
+
return Promise.reject(new InvalidExecutionModeError(message));
|
|
1879
|
+
}
|
|
1869
1880
|
if (this.isSync) {
|
|
1870
1881
|
if (!this._resultPromise) {
|
|
1871
|
-
|
|
1882
|
+
return Promise.reject(new ExecutionNotStartedError());
|
|
1872
1883
|
}
|
|
1873
1884
|
return this._resultPromise;
|
|
1874
1885
|
}
|
|
1875
1886
|
if (this.isStream) {
|
|
1876
1887
|
if (!this._stream) {
|
|
1877
|
-
|
|
1888
|
+
return Promise.reject(new ExecutionNotStartedError());
|
|
1878
1889
|
}
|
|
1879
1890
|
return this._stream;
|
|
1880
1891
|
}
|
|
@@ -1940,6 +1951,9 @@ class CanvasExecution extends Emittery__default {
|
|
|
1940
1951
|
* ```
|
|
1941
1952
|
*/
|
|
1942
1953
|
poll() {
|
|
1954
|
+
if (this._params.applicationId && !this._params.canvasId) {
|
|
1955
|
+
throw new InvalidExecutionModeError("Tasks are not fully supported yet. You can create them, but cannot obtain the results or poll for their status.");
|
|
1956
|
+
}
|
|
1943
1957
|
if (!this.isAsync) {
|
|
1944
1958
|
throw new InvalidExecutionModeError("Polling is only supported for async executions");
|
|
1945
1959
|
}
|
|
@@ -2122,6 +2136,7 @@ class CanvasExecution extends Emittery__default {
|
|
|
2122
2136
|
this.emit("poll", response);
|
|
2123
2137
|
if (response.status === "failed") {
|
|
2124
2138
|
const error = new ExecutionFailedError(response.rawOutput);
|
|
2139
|
+
this.cancel();
|
|
2125
2140
|
this.emit("error", error);
|
|
2126
2141
|
throw error;
|
|
2127
2142
|
}
|
|
@@ -2368,8 +2383,9 @@ class Canvas {
|
|
|
2368
2383
|
}
|
|
2369
2384
|
return new Canvas({
|
|
2370
2385
|
id: promptVersion.promptId,
|
|
2371
|
-
name: promptVersion.title,
|
|
2372
2386
|
versionId: promptVersion.id,
|
|
2387
|
+
applicationId: applicationId ?? void 0,
|
|
2388
|
+
name: promptVersion.title,
|
|
2373
2389
|
input,
|
|
2374
2390
|
output,
|
|
2375
2391
|
client,
|
|
@@ -2455,11 +2471,10 @@ class Canvas {
|
|
|
2455
2471
|
}
|
|
2456
2472
|
execute(variables, params) {
|
|
2457
2473
|
const parsedInput = this.parseVariables(variables);
|
|
2474
|
+
const idObject = this._applicationId ? { applicationId: this._applicationId } : { versionId: this._versionId, canvasId: this._id };
|
|
2458
2475
|
const fullParams = {
|
|
2459
2476
|
...params ?? { async: false },
|
|
2460
|
-
|
|
2461
|
-
canvasId: this._id,
|
|
2462
|
-
applicationId: this._applicationId
|
|
2477
|
+
...idObject
|
|
2463
2478
|
};
|
|
2464
2479
|
const execution = new CanvasExecution(parsedInput, fullParams, this._output, this._client);
|
|
2465
2480
|
return {
|
package/dist/index.d.cts
CHANGED
|
@@ -933,7 +933,7 @@ declare class CanvasExecution<TParams extends ExecutionParams = SyncExecutionPar
|
|
|
933
933
|
*
|
|
934
934
|
* @returns A promise or async generator depending on execution mode.
|
|
935
935
|
*/
|
|
936
|
-
start(): Promise<CanvasExecutionResult<TParams, TOutput
|
|
936
|
+
start(): Promise<CanvasExecutionResult<TParams, TOutput> | AsyncGenerator<Partial<TOutput>, any, any> | WithRequestId<AsyncCompletionCreateResult>>;
|
|
937
937
|
/**
|
|
938
938
|
* Gets the execution result. For async executions, automatically starts polling.
|
|
939
939
|
* For sync executions, returns the result promise. For streams, returns the generator.
|
package/dist/index.d.mts
CHANGED
|
@@ -933,7 +933,7 @@ declare class CanvasExecution<TParams extends ExecutionParams = SyncExecutionPar
|
|
|
933
933
|
*
|
|
934
934
|
* @returns A promise or async generator depending on execution mode.
|
|
935
935
|
*/
|
|
936
|
-
start(): Promise<CanvasExecutionResult<TParams, TOutput
|
|
936
|
+
start(): Promise<CanvasExecutionResult<TParams, TOutput> | AsyncGenerator<Partial<TOutput>, any, any> | WithRequestId<AsyncCompletionCreateResult>>;
|
|
937
937
|
/**
|
|
938
938
|
* Gets the execution result. For async executions, automatically starts polling.
|
|
939
939
|
* For sync executions, returns the result promise. For streams, returns the generator.
|
package/dist/index.d.ts
CHANGED
|
@@ -933,7 +933,7 @@ declare class CanvasExecution<TParams extends ExecutionParams = SyncExecutionPar
|
|
|
933
933
|
*
|
|
934
934
|
* @returns A promise or async generator depending on execution mode.
|
|
935
935
|
*/
|
|
936
|
-
start(): Promise<CanvasExecutionResult<TParams, TOutput
|
|
936
|
+
start(): Promise<CanvasExecutionResult<TParams, TOutput> | AsyncGenerator<Partial<TOutput>, any, any> | WithRequestId<AsyncCompletionCreateResult>>;
|
|
937
937
|
/**
|
|
938
938
|
* Gets the execution result. For async executions, automatically starts polling.
|
|
939
939
|
* For sync executions, returns the result promise. For streams, returns the generator.
|
package/dist/index.mjs
CHANGED
|
@@ -4,7 +4,7 @@ import * as z from 'zod';
|
|
|
4
4
|
import z__default, { z as z$1, ZodError } from 'zod';
|
|
5
5
|
import Emittery from 'emittery';
|
|
6
6
|
|
|
7
|
-
const version = "2.
|
|
7
|
+
const version = "2.4.0";
|
|
8
8
|
|
|
9
9
|
var __defProp$7 = Object.defineProperty;
|
|
10
10
|
var __defNormalProp$7 = (obj, key, value) => key in obj ? __defProp$7(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
@@ -844,6 +844,7 @@ class BaseClient {
|
|
|
844
844
|
remainingRetries = options.maxRetries ?? this.maxRetries;
|
|
845
845
|
}
|
|
846
846
|
const { req, url, timeout } = this.buildRequest(options);
|
|
847
|
+
debug("request", `[${options.method}] ${options.path} ${JSON.stringify(options.body)}`);
|
|
847
848
|
if (options.signal?.aborted) {
|
|
848
849
|
throw new UserAbortError();
|
|
849
850
|
}
|
|
@@ -1515,13 +1516,13 @@ function isSyncWorkflowResult(obj) {
|
|
|
1515
1516
|
return "output" in obj;
|
|
1516
1517
|
}
|
|
1517
1518
|
function isAsyncWorkflowResult(obj) {
|
|
1518
|
-
return "outputContent" in obj && "output" in obj.outputContent;
|
|
1519
|
+
return "outputContent" in obj && obj.outputContent && typeof obj.outputContent === "object" && "output" in obj.outputContent;
|
|
1519
1520
|
}
|
|
1520
1521
|
function isSyncCanvasResult(obj) {
|
|
1521
1522
|
return "choices" in obj;
|
|
1522
1523
|
}
|
|
1523
1524
|
function isAsyncCanvasResult(obj) {
|
|
1524
|
-
return "outputContent" in obj && "content" in obj.outputContent;
|
|
1525
|
+
return "outputContent" in obj && obj.outputContent && typeof obj.outputContent === "object" && "content" in obj.outputContent;
|
|
1525
1526
|
}
|
|
1526
1527
|
function getResultFromPollingResponse(response) {
|
|
1527
1528
|
if (isSyncWorkflowResult(response)) {
|
|
@@ -1827,7 +1828,13 @@ class CanvasExecution extends Emittery {
|
|
|
1827
1828
|
*
|
|
1828
1829
|
* @returns A promise or async generator depending on execution mode.
|
|
1829
1830
|
*/
|
|
1830
|
-
start() {
|
|
1831
|
+
async start() {
|
|
1832
|
+
if (this._params.applicationId && !this._params.async) {
|
|
1833
|
+
console.warn("[Tela SDK - WARNING] ApplicationId was provided, but async mode was not enabled. This will create a task, and tasks are always async. ");
|
|
1834
|
+
console.warn("[Tela SDK - WARNING] Tasks are not fully supported yet. You can create them, but cannot obtain the results or poll for their status.");
|
|
1835
|
+
console.warn("[Tela SDK - WARNING] To disable these warnings, you can enable async mode explicitly.");
|
|
1836
|
+
this._params.async = true;
|
|
1837
|
+
}
|
|
1831
1838
|
if (this._resultPromise || this._stream) {
|
|
1832
1839
|
return this._resultPromise ?? this._stream;
|
|
1833
1840
|
}
|
|
@@ -1846,15 +1853,19 @@ class CanvasExecution extends Emittery {
|
|
|
1846
1853
|
* @returns The execution result as a promise or async generator.
|
|
1847
1854
|
*/
|
|
1848
1855
|
get result() {
|
|
1856
|
+
if (this._params.applicationId && !this._params.canvasId) {
|
|
1857
|
+
const message = "Tasks are not fully supported yet. You can create them, but cannot obtain the results or poll for their status.";
|
|
1858
|
+
return Promise.reject(new InvalidExecutionModeError(message));
|
|
1859
|
+
}
|
|
1849
1860
|
if (this.isSync) {
|
|
1850
1861
|
if (!this._resultPromise) {
|
|
1851
|
-
|
|
1862
|
+
return Promise.reject(new ExecutionNotStartedError());
|
|
1852
1863
|
}
|
|
1853
1864
|
return this._resultPromise;
|
|
1854
1865
|
}
|
|
1855
1866
|
if (this.isStream) {
|
|
1856
1867
|
if (!this._stream) {
|
|
1857
|
-
|
|
1868
|
+
return Promise.reject(new ExecutionNotStartedError());
|
|
1858
1869
|
}
|
|
1859
1870
|
return this._stream;
|
|
1860
1871
|
}
|
|
@@ -1920,6 +1931,9 @@ class CanvasExecution extends Emittery {
|
|
|
1920
1931
|
* ```
|
|
1921
1932
|
*/
|
|
1922
1933
|
poll() {
|
|
1934
|
+
if (this._params.applicationId && !this._params.canvasId) {
|
|
1935
|
+
throw new InvalidExecutionModeError("Tasks are not fully supported yet. You can create them, but cannot obtain the results or poll for their status.");
|
|
1936
|
+
}
|
|
1923
1937
|
if (!this.isAsync) {
|
|
1924
1938
|
throw new InvalidExecutionModeError("Polling is only supported for async executions");
|
|
1925
1939
|
}
|
|
@@ -2102,6 +2116,7 @@ class CanvasExecution extends Emittery {
|
|
|
2102
2116
|
this.emit("poll", response);
|
|
2103
2117
|
if (response.status === "failed") {
|
|
2104
2118
|
const error = new ExecutionFailedError(response.rawOutput);
|
|
2119
|
+
this.cancel();
|
|
2105
2120
|
this.emit("error", error);
|
|
2106
2121
|
throw error;
|
|
2107
2122
|
}
|
|
@@ -2348,8 +2363,9 @@ class Canvas {
|
|
|
2348
2363
|
}
|
|
2349
2364
|
return new Canvas({
|
|
2350
2365
|
id: promptVersion.promptId,
|
|
2351
|
-
name: promptVersion.title,
|
|
2352
2366
|
versionId: promptVersion.id,
|
|
2367
|
+
applicationId: applicationId ?? void 0,
|
|
2368
|
+
name: promptVersion.title,
|
|
2353
2369
|
input,
|
|
2354
2370
|
output,
|
|
2355
2371
|
client,
|
|
@@ -2435,11 +2451,10 @@ class Canvas {
|
|
|
2435
2451
|
}
|
|
2436
2452
|
execute(variables, params) {
|
|
2437
2453
|
const parsedInput = this.parseVariables(variables);
|
|
2454
|
+
const idObject = this._applicationId ? { applicationId: this._applicationId } : { versionId: this._versionId, canvasId: this._id };
|
|
2438
2455
|
const fullParams = {
|
|
2439
2456
|
...params ?? { async: false },
|
|
2440
|
-
|
|
2441
|
-
canvasId: this._id,
|
|
2442
|
-
applicationId: this._applicationId
|
|
2457
|
+
...idObject
|
|
2443
2458
|
};
|
|
2444
2459
|
const execution = new CanvasExecution(parsedInput, fullParams, this._output, this._client);
|
|
2445
2460
|
return {
|