@meistrari/tela-sdk-js 2.3.2 → 2.4.1
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 +27 -11
- 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 +27 -11
- 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.1";
|
|
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;
|
|
@@ -824,7 +824,8 @@ class BaseClient {
|
|
|
824
824
|
return headers;
|
|
825
825
|
}
|
|
826
826
|
getUserAgent() {
|
|
827
|
-
|
|
827
|
+
const serviceName = typeof process !== "undefined" && process?.env?.SERVICE_NAME ? `@${process.env.SERVICE_NAME}` : "";
|
|
828
|
+
return `tela-sdk-node:${version}${serviceName}`;
|
|
828
829
|
}
|
|
829
830
|
get(path, opts) {
|
|
830
831
|
return this.methodRequest("GET", path, opts);
|
|
@@ -864,6 +865,7 @@ class BaseClient {
|
|
|
864
865
|
remainingRetries = options.maxRetries ?? this.maxRetries;
|
|
865
866
|
}
|
|
866
867
|
const { req, url, timeout } = this.buildRequest(options);
|
|
868
|
+
debug("request", `[${options.method}] ${options.path} ${JSON.stringify(options.body)}`);
|
|
867
869
|
if (options.signal?.aborted) {
|
|
868
870
|
throw new UserAbortError();
|
|
869
871
|
}
|
|
@@ -1535,13 +1537,13 @@ function isSyncWorkflowResult(obj) {
|
|
|
1535
1537
|
return "output" in obj;
|
|
1536
1538
|
}
|
|
1537
1539
|
function isAsyncWorkflowResult(obj) {
|
|
1538
|
-
return "outputContent" in obj && "output" in obj.outputContent;
|
|
1540
|
+
return "outputContent" in obj && obj.outputContent && typeof obj.outputContent === "object" && "output" in obj.outputContent;
|
|
1539
1541
|
}
|
|
1540
1542
|
function isSyncCanvasResult(obj) {
|
|
1541
1543
|
return "choices" in obj;
|
|
1542
1544
|
}
|
|
1543
1545
|
function isAsyncCanvasResult(obj) {
|
|
1544
|
-
return "outputContent" in obj && "content" in obj.outputContent;
|
|
1546
|
+
return "outputContent" in obj && obj.outputContent && typeof obj.outputContent === "object" && "content" in obj.outputContent;
|
|
1545
1547
|
}
|
|
1546
1548
|
function getResultFromPollingResponse(response) {
|
|
1547
1549
|
if (isSyncWorkflowResult(response)) {
|
|
@@ -1847,7 +1849,13 @@ class CanvasExecution extends Emittery__default {
|
|
|
1847
1849
|
*
|
|
1848
1850
|
* @returns A promise or async generator depending on execution mode.
|
|
1849
1851
|
*/
|
|
1850
|
-
start() {
|
|
1852
|
+
async start() {
|
|
1853
|
+
if (this._params.applicationId && !this._params.async) {
|
|
1854
|
+
console.warn("[Tela SDK - WARNING] ApplicationId was provided, but async mode was not enabled. This will create a task, and tasks are always async. ");
|
|
1855
|
+
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.");
|
|
1856
|
+
console.warn("[Tela SDK - WARNING] To disable these warnings, you can enable async mode explicitly.");
|
|
1857
|
+
this._params.async = true;
|
|
1858
|
+
}
|
|
1851
1859
|
if (this._resultPromise || this._stream) {
|
|
1852
1860
|
return this._resultPromise ?? this._stream;
|
|
1853
1861
|
}
|
|
@@ -1866,15 +1874,19 @@ class CanvasExecution extends Emittery__default {
|
|
|
1866
1874
|
* @returns The execution result as a promise or async generator.
|
|
1867
1875
|
*/
|
|
1868
1876
|
get result() {
|
|
1877
|
+
if (this._params.applicationId && !this._params.canvasId) {
|
|
1878
|
+
const message = "Tasks are not fully supported yet. You can create them, but cannot obtain the results or poll for their status.";
|
|
1879
|
+
return Promise.reject(new InvalidExecutionModeError(message));
|
|
1880
|
+
}
|
|
1869
1881
|
if (this.isSync) {
|
|
1870
1882
|
if (!this._resultPromise) {
|
|
1871
|
-
|
|
1883
|
+
return Promise.reject(new ExecutionNotStartedError());
|
|
1872
1884
|
}
|
|
1873
1885
|
return this._resultPromise;
|
|
1874
1886
|
}
|
|
1875
1887
|
if (this.isStream) {
|
|
1876
1888
|
if (!this._stream) {
|
|
1877
|
-
|
|
1889
|
+
return Promise.reject(new ExecutionNotStartedError());
|
|
1878
1890
|
}
|
|
1879
1891
|
return this._stream;
|
|
1880
1892
|
}
|
|
@@ -1940,6 +1952,9 @@ class CanvasExecution extends Emittery__default {
|
|
|
1940
1952
|
* ```
|
|
1941
1953
|
*/
|
|
1942
1954
|
poll() {
|
|
1955
|
+
if (this._params.applicationId && !this._params.canvasId) {
|
|
1956
|
+
throw new InvalidExecutionModeError("Tasks are not fully supported yet. You can create them, but cannot obtain the results or poll for their status.");
|
|
1957
|
+
}
|
|
1943
1958
|
if (!this.isAsync) {
|
|
1944
1959
|
throw new InvalidExecutionModeError("Polling is only supported for async executions");
|
|
1945
1960
|
}
|
|
@@ -2122,6 +2137,7 @@ class CanvasExecution extends Emittery__default {
|
|
|
2122
2137
|
this.emit("poll", response);
|
|
2123
2138
|
if (response.status === "failed") {
|
|
2124
2139
|
const error = new ExecutionFailedError(response.rawOutput);
|
|
2140
|
+
this.cancel();
|
|
2125
2141
|
this.emit("error", error);
|
|
2126
2142
|
throw error;
|
|
2127
2143
|
}
|
|
@@ -2368,8 +2384,9 @@ class Canvas {
|
|
|
2368
2384
|
}
|
|
2369
2385
|
return new Canvas({
|
|
2370
2386
|
id: promptVersion.promptId,
|
|
2371
|
-
name: promptVersion.title,
|
|
2372
2387
|
versionId: promptVersion.id,
|
|
2388
|
+
applicationId: applicationId ?? void 0,
|
|
2389
|
+
name: promptVersion.title,
|
|
2373
2390
|
input,
|
|
2374
2391
|
output,
|
|
2375
2392
|
client,
|
|
@@ -2455,11 +2472,10 @@ class Canvas {
|
|
|
2455
2472
|
}
|
|
2456
2473
|
execute(variables, params) {
|
|
2457
2474
|
const parsedInput = this.parseVariables(variables);
|
|
2475
|
+
const idObject = this._applicationId ? { applicationId: this._applicationId } : { versionId: this._versionId, canvasId: this._id };
|
|
2458
2476
|
const fullParams = {
|
|
2459
2477
|
...params ?? { async: false },
|
|
2460
|
-
|
|
2461
|
-
canvasId: this._id,
|
|
2462
|
-
applicationId: this._applicationId
|
|
2478
|
+
...idObject
|
|
2463
2479
|
};
|
|
2464
2480
|
const execution = new CanvasExecution(parsedInput, fullParams, this._output, this._client);
|
|
2465
2481
|
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.1";
|
|
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;
|
|
@@ -804,7 +804,8 @@ class BaseClient {
|
|
|
804
804
|
return headers;
|
|
805
805
|
}
|
|
806
806
|
getUserAgent() {
|
|
807
|
-
|
|
807
|
+
const serviceName = typeof process !== "undefined" && process?.env?.SERVICE_NAME ? `@${process.env.SERVICE_NAME}` : "";
|
|
808
|
+
return `tela-sdk-node:${version}${serviceName}`;
|
|
808
809
|
}
|
|
809
810
|
get(path, opts) {
|
|
810
811
|
return this.methodRequest("GET", path, opts);
|
|
@@ -844,6 +845,7 @@ class BaseClient {
|
|
|
844
845
|
remainingRetries = options.maxRetries ?? this.maxRetries;
|
|
845
846
|
}
|
|
846
847
|
const { req, url, timeout } = this.buildRequest(options);
|
|
848
|
+
debug("request", `[${options.method}] ${options.path} ${JSON.stringify(options.body)}`);
|
|
847
849
|
if (options.signal?.aborted) {
|
|
848
850
|
throw new UserAbortError();
|
|
849
851
|
}
|
|
@@ -1515,13 +1517,13 @@ function isSyncWorkflowResult(obj) {
|
|
|
1515
1517
|
return "output" in obj;
|
|
1516
1518
|
}
|
|
1517
1519
|
function isAsyncWorkflowResult(obj) {
|
|
1518
|
-
return "outputContent" in obj && "output" in obj.outputContent;
|
|
1520
|
+
return "outputContent" in obj && obj.outputContent && typeof obj.outputContent === "object" && "output" in obj.outputContent;
|
|
1519
1521
|
}
|
|
1520
1522
|
function isSyncCanvasResult(obj) {
|
|
1521
1523
|
return "choices" in obj;
|
|
1522
1524
|
}
|
|
1523
1525
|
function isAsyncCanvasResult(obj) {
|
|
1524
|
-
return "outputContent" in obj && "content" in obj.outputContent;
|
|
1526
|
+
return "outputContent" in obj && obj.outputContent && typeof obj.outputContent === "object" && "content" in obj.outputContent;
|
|
1525
1527
|
}
|
|
1526
1528
|
function getResultFromPollingResponse(response) {
|
|
1527
1529
|
if (isSyncWorkflowResult(response)) {
|
|
@@ -1827,7 +1829,13 @@ class CanvasExecution extends Emittery {
|
|
|
1827
1829
|
*
|
|
1828
1830
|
* @returns A promise or async generator depending on execution mode.
|
|
1829
1831
|
*/
|
|
1830
|
-
start() {
|
|
1832
|
+
async start() {
|
|
1833
|
+
if (this._params.applicationId && !this._params.async) {
|
|
1834
|
+
console.warn("[Tela SDK - WARNING] ApplicationId was provided, but async mode was not enabled. This will create a task, and tasks are always async. ");
|
|
1835
|
+
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.");
|
|
1836
|
+
console.warn("[Tela SDK - WARNING] To disable these warnings, you can enable async mode explicitly.");
|
|
1837
|
+
this._params.async = true;
|
|
1838
|
+
}
|
|
1831
1839
|
if (this._resultPromise || this._stream) {
|
|
1832
1840
|
return this._resultPromise ?? this._stream;
|
|
1833
1841
|
}
|
|
@@ -1846,15 +1854,19 @@ class CanvasExecution extends Emittery {
|
|
|
1846
1854
|
* @returns The execution result as a promise or async generator.
|
|
1847
1855
|
*/
|
|
1848
1856
|
get result() {
|
|
1857
|
+
if (this._params.applicationId && !this._params.canvasId) {
|
|
1858
|
+
const message = "Tasks are not fully supported yet. You can create them, but cannot obtain the results or poll for their status.";
|
|
1859
|
+
return Promise.reject(new InvalidExecutionModeError(message));
|
|
1860
|
+
}
|
|
1849
1861
|
if (this.isSync) {
|
|
1850
1862
|
if (!this._resultPromise) {
|
|
1851
|
-
|
|
1863
|
+
return Promise.reject(new ExecutionNotStartedError());
|
|
1852
1864
|
}
|
|
1853
1865
|
return this._resultPromise;
|
|
1854
1866
|
}
|
|
1855
1867
|
if (this.isStream) {
|
|
1856
1868
|
if (!this._stream) {
|
|
1857
|
-
|
|
1869
|
+
return Promise.reject(new ExecutionNotStartedError());
|
|
1858
1870
|
}
|
|
1859
1871
|
return this._stream;
|
|
1860
1872
|
}
|
|
@@ -1920,6 +1932,9 @@ class CanvasExecution extends Emittery {
|
|
|
1920
1932
|
* ```
|
|
1921
1933
|
*/
|
|
1922
1934
|
poll() {
|
|
1935
|
+
if (this._params.applicationId && !this._params.canvasId) {
|
|
1936
|
+
throw new InvalidExecutionModeError("Tasks are not fully supported yet. You can create them, but cannot obtain the results or poll for their status.");
|
|
1937
|
+
}
|
|
1923
1938
|
if (!this.isAsync) {
|
|
1924
1939
|
throw new InvalidExecutionModeError("Polling is only supported for async executions");
|
|
1925
1940
|
}
|
|
@@ -2102,6 +2117,7 @@ class CanvasExecution extends Emittery {
|
|
|
2102
2117
|
this.emit("poll", response);
|
|
2103
2118
|
if (response.status === "failed") {
|
|
2104
2119
|
const error = new ExecutionFailedError(response.rawOutput);
|
|
2120
|
+
this.cancel();
|
|
2105
2121
|
this.emit("error", error);
|
|
2106
2122
|
throw error;
|
|
2107
2123
|
}
|
|
@@ -2348,8 +2364,9 @@ class Canvas {
|
|
|
2348
2364
|
}
|
|
2349
2365
|
return new Canvas({
|
|
2350
2366
|
id: promptVersion.promptId,
|
|
2351
|
-
name: promptVersion.title,
|
|
2352
2367
|
versionId: promptVersion.id,
|
|
2368
|
+
applicationId: applicationId ?? void 0,
|
|
2369
|
+
name: promptVersion.title,
|
|
2353
2370
|
input,
|
|
2354
2371
|
output,
|
|
2355
2372
|
client,
|
|
@@ -2435,11 +2452,10 @@ class Canvas {
|
|
|
2435
2452
|
}
|
|
2436
2453
|
execute(variables, params) {
|
|
2437
2454
|
const parsedInput = this.parseVariables(variables);
|
|
2455
|
+
const idObject = this._applicationId ? { applicationId: this._applicationId } : { versionId: this._versionId, canvasId: this._id };
|
|
2438
2456
|
const fullParams = {
|
|
2439
2457
|
...params ?? { async: false },
|
|
2440
|
-
|
|
2441
|
-
canvasId: this._id,
|
|
2442
|
-
applicationId: this._applicationId
|
|
2458
|
+
...idObject
|
|
2443
2459
|
};
|
|
2444
2460
|
const execution = new CanvasExecution(parsedInput, fullParams, this._output, this._client);
|
|
2445
2461
|
return {
|