@meistrari/tela-sdk-js 2.1.0 → 2.2.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 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.1.0";
27
+ const version = "2.2.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;
@@ -1491,6 +1491,33 @@ function isUUID(str) {
1491
1491
  const uuidRegex = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
1492
1492
  return uuidRegex.test(str);
1493
1493
  }
1494
+ function isSyncWorkflowResult(obj) {
1495
+ return "output" in obj;
1496
+ }
1497
+ function isAsyncWorkflowResult(obj) {
1498
+ return "outputContent" in obj && "output" in obj.outputContent;
1499
+ }
1500
+ function isSyncCanvasResult(obj) {
1501
+ return "choices" in obj;
1502
+ }
1503
+ function isAsyncCanvasResult(obj) {
1504
+ return "outputContent" in obj && "content" in obj.outputContent;
1505
+ }
1506
+ function getResultFromPollingResponse(response) {
1507
+ if (isSyncWorkflowResult(response)) {
1508
+ return response.output.output;
1509
+ }
1510
+ if (isAsyncWorkflowResult(response)) {
1511
+ return response.outputContent.output.output;
1512
+ }
1513
+ if (isSyncCanvasResult(response)) {
1514
+ return response.choices?.[0]?.message?.content;
1515
+ }
1516
+ if (isAsyncCanvasResult(response)) {
1517
+ return response.outputContent.content;
1518
+ }
1519
+ throw new Error("Invalid response type");
1520
+ }
1494
1521
  class CanvasExecution extends Emittery__default {
1495
1522
  /**
1496
1523
  * Creates a new canvas execution instance.
@@ -1572,7 +1599,7 @@ class CanvasExecution extends Emittery__default {
1572
1599
  execution.status = response.status;
1573
1600
  if (response.status === "succeeded") {
1574
1601
  execution._rawResultValue = response;
1575
- const content = response.outputContent.content;
1602
+ const content = getResultFromPollingResponse(response);
1576
1603
  try {
1577
1604
  const validatedContent = execution._skipResultValidation || !(outputSchema instanceof z__default.ZodType) ? content : outputSchema.parse(content);
1578
1605
  execution._resultPromise = Promise.resolve(validatedContent);
@@ -1856,7 +1883,8 @@ class CanvasExecution extends Emittery__default {
1856
1883
  versionId: this._params.versionId,
1857
1884
  messages: this._params.messages,
1858
1885
  tags: this._params.tags,
1859
- label: this._params.label
1886
+ label: this._params.label,
1887
+ webhook_url: this._params.webhookUrl
1860
1888
  };
1861
1889
  if (this._params.override && this._outputSchema instanceof z__default.ZodType) {
1862
1890
  return {
@@ -1911,7 +1939,7 @@ class CanvasExecution extends Emittery__default {
1911
1939
  }).then((response) => {
1912
1940
  this._id = response.id;
1913
1941
  this._rawResultValue = response;
1914
- return response.choices?.[0]?.message?.content;
1942
+ return getResultFromPollingResponse(response);
1915
1943
  }).then((content) => {
1916
1944
  const validatedContent = this._skipResultValidation || !(this._outputSchema instanceof z__default.ZodType) ? content : this._outputSchema.parse(content);
1917
1945
  this.status = "succeeded";
@@ -2017,10 +2045,10 @@ class CanvasExecution extends Emittery__default {
2017
2045
  };
2018
2046
  }
2019
2047
  this._rawResultValue = response;
2020
- this.emit("success", response.outputContent.content);
2048
+ this.emit("success", getResultFromPollingResponse(response));
2021
2049
  return {
2022
2050
  done: response.status === "succeeded",
2023
- value: response.outputContent.content
2051
+ value: getResultFromPollingResponse(response)
2024
2052
  };
2025
2053
  }).then((value) => {
2026
2054
  if (this._skipResultValidation || !(this._outputSchema instanceof z__default.ZodType)) {
@@ -2211,7 +2239,7 @@ class Canvas {
2211
2239
  *
2212
2240
  * @private
2213
2241
  */
2214
- constructor({ id, applicationId, name, versionId, input, output, client, variables }) {
2242
+ constructor({ id, applicationId, name, versionId, input, output, client, variables, isWorkflow }) {
2215
2243
  __publicField$1(this, "_id");
2216
2244
  __publicField$1(this, "_versionId");
2217
2245
  __publicField$1(this, "_applicationId");
@@ -2220,6 +2248,7 @@ class Canvas {
2220
2248
  __publicField$1(this, "_output");
2221
2249
  __publicField$1(this, "_client");
2222
2250
  __publicField$1(this, "_variables");
2251
+ __publicField$1(this, "_isWorkflow");
2223
2252
  this._id = id;
2224
2253
  this._applicationId = applicationId;
2225
2254
  this._name = name;
@@ -2228,6 +2257,7 @@ class Canvas {
2228
2257
  this._output = output && output(zod);
2229
2258
  this._client = client;
2230
2259
  this._variables = variables;
2260
+ this._isWorkflow = isWorkflow;
2231
2261
  }
2232
2262
  /**
2233
2263
  * Gets a canvas by its ID.
@@ -2256,7 +2286,8 @@ class Canvas {
2256
2286
  input,
2257
2287
  output,
2258
2288
  client,
2259
- variables: promptVersion.variables
2289
+ variables: promptVersion.variables,
2290
+ isWorkflow: promptVersion.isWorkflow
2260
2291
  });
2261
2292
  }
2262
2293
  /**
@@ -2307,6 +2338,14 @@ class Canvas {
2307
2338
  get variables() {
2308
2339
  return this._variables;
2309
2340
  }
2341
+ /**
2342
+ * Gets whether this canvas is a workflow.
2343
+ *
2344
+ * @returns True if the canvas is a workflow.
2345
+ */
2346
+ get isWorkflow() {
2347
+ return this._isWorkflow;
2348
+ }
2310
2349
  /**
2311
2350
  * Validates and parses input variables using the canvas input schema.
2312
2351
  *
package/dist/index.d.cts CHANGED
@@ -1075,8 +1075,12 @@ interface CanvasOptions<TInput, TOutput> {
1075
1075
  * Variables of the canvas.
1076
1076
  */
1077
1077
  variables: Array<CanvasVariable>;
1078
+ /**
1079
+ * Whether the canvas is a workflow.
1080
+ */
1081
+ isWorkflow: boolean;
1078
1082
  }
1079
- type CanvasGetOptions<TInput extends ZodTypeOrRecord, TOutput extends ZodTypeOrRecord> = Omit<CanvasOptions<TInput, TOutput>, 'client' | 'variables'> & {
1083
+ type CanvasGetOptions<TInput extends ZodTypeOrRecord, TOutput extends ZodTypeOrRecord> = Omit<CanvasOptions<TInput, TOutput>, 'client' | 'variables' | 'isWorkflow'> & {
1080
1084
  /**
1081
1085
  * Whether to skip schema validation warnings during canvas retrieval.
1082
1086
  * When true, no warnings will be logged for schema mismatches.
@@ -1396,6 +1400,7 @@ declare class Canvas<TInput extends ZodTypeOrRecord, TOutput extends ZodTypeOrRe
1396
1400
  private readonly _output;
1397
1401
  private readonly _client;
1398
1402
  private readonly _variables;
1403
+ private readonly _isWorkflow;
1399
1404
  /**
1400
1405
  * Creates a new instance of the Canvas class. Usage of this constructor is not recommended.
1401
1406
  * Use the `tela.getCanvas` method instead.
@@ -1444,6 +1449,12 @@ declare class Canvas<TInput extends ZodTypeOrRecord, TOutput extends ZodTypeOrRe
1444
1449
  * @returns The variables of the canvas.
1445
1450
  */
1446
1451
  get variables(): Array<CanvasVariable>;
1452
+ /**
1453
+ * Gets whether this canvas is a workflow.
1454
+ *
1455
+ * @returns True if the canvas is a workflow.
1456
+ */
1457
+ get isWorkflow(): boolean;
1447
1458
  /**
1448
1459
  * Validates and parses input variables using the canvas input schema.
1449
1460
  *
package/dist/index.d.mts CHANGED
@@ -1075,8 +1075,12 @@ interface CanvasOptions<TInput, TOutput> {
1075
1075
  * Variables of the canvas.
1076
1076
  */
1077
1077
  variables: Array<CanvasVariable>;
1078
+ /**
1079
+ * Whether the canvas is a workflow.
1080
+ */
1081
+ isWorkflow: boolean;
1078
1082
  }
1079
- type CanvasGetOptions<TInput extends ZodTypeOrRecord, TOutput extends ZodTypeOrRecord> = Omit<CanvasOptions<TInput, TOutput>, 'client' | 'variables'> & {
1083
+ type CanvasGetOptions<TInput extends ZodTypeOrRecord, TOutput extends ZodTypeOrRecord> = Omit<CanvasOptions<TInput, TOutput>, 'client' | 'variables' | 'isWorkflow'> & {
1080
1084
  /**
1081
1085
  * Whether to skip schema validation warnings during canvas retrieval.
1082
1086
  * When true, no warnings will be logged for schema mismatches.
@@ -1396,6 +1400,7 @@ declare class Canvas<TInput extends ZodTypeOrRecord, TOutput extends ZodTypeOrRe
1396
1400
  private readonly _output;
1397
1401
  private readonly _client;
1398
1402
  private readonly _variables;
1403
+ private readonly _isWorkflow;
1399
1404
  /**
1400
1405
  * Creates a new instance of the Canvas class. Usage of this constructor is not recommended.
1401
1406
  * Use the `tela.getCanvas` method instead.
@@ -1444,6 +1449,12 @@ declare class Canvas<TInput extends ZodTypeOrRecord, TOutput extends ZodTypeOrRe
1444
1449
  * @returns The variables of the canvas.
1445
1450
  */
1446
1451
  get variables(): Array<CanvasVariable>;
1452
+ /**
1453
+ * Gets whether this canvas is a workflow.
1454
+ *
1455
+ * @returns True if the canvas is a workflow.
1456
+ */
1457
+ get isWorkflow(): boolean;
1447
1458
  /**
1448
1459
  * Validates and parses input variables using the canvas input schema.
1449
1460
  *
package/dist/index.d.ts CHANGED
@@ -1075,8 +1075,12 @@ interface CanvasOptions<TInput, TOutput> {
1075
1075
  * Variables of the canvas.
1076
1076
  */
1077
1077
  variables: Array<CanvasVariable>;
1078
+ /**
1079
+ * Whether the canvas is a workflow.
1080
+ */
1081
+ isWorkflow: boolean;
1078
1082
  }
1079
- type CanvasGetOptions<TInput extends ZodTypeOrRecord, TOutput extends ZodTypeOrRecord> = Omit<CanvasOptions<TInput, TOutput>, 'client' | 'variables'> & {
1083
+ type CanvasGetOptions<TInput extends ZodTypeOrRecord, TOutput extends ZodTypeOrRecord> = Omit<CanvasOptions<TInput, TOutput>, 'client' | 'variables' | 'isWorkflow'> & {
1080
1084
  /**
1081
1085
  * Whether to skip schema validation warnings during canvas retrieval.
1082
1086
  * When true, no warnings will be logged for schema mismatches.
@@ -1396,6 +1400,7 @@ declare class Canvas<TInput extends ZodTypeOrRecord, TOutput extends ZodTypeOrRe
1396
1400
  private readonly _output;
1397
1401
  private readonly _client;
1398
1402
  private readonly _variables;
1403
+ private readonly _isWorkflow;
1399
1404
  /**
1400
1405
  * Creates a new instance of the Canvas class. Usage of this constructor is not recommended.
1401
1406
  * Use the `tela.getCanvas` method instead.
@@ -1444,6 +1449,12 @@ declare class Canvas<TInput extends ZodTypeOrRecord, TOutput extends ZodTypeOrRe
1444
1449
  * @returns The variables of the canvas.
1445
1450
  */
1446
1451
  get variables(): Array<CanvasVariable>;
1452
+ /**
1453
+ * Gets whether this canvas is a workflow.
1454
+ *
1455
+ * @returns True if the canvas is a workflow.
1456
+ */
1457
+ get isWorkflow(): boolean;
1447
1458
  /**
1448
1459
  * Validates and parses input variables using the canvas input schema.
1449
1460
  *
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.1.0";
7
+ const version = "2.2.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;
@@ -1471,6 +1471,33 @@ function isUUID(str) {
1471
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
1472
  return uuidRegex.test(str);
1473
1473
  }
1474
+ function isSyncWorkflowResult(obj) {
1475
+ return "output" in obj;
1476
+ }
1477
+ function isAsyncWorkflowResult(obj) {
1478
+ return "outputContent" in obj && "output" in obj.outputContent;
1479
+ }
1480
+ function isSyncCanvasResult(obj) {
1481
+ return "choices" in obj;
1482
+ }
1483
+ function isAsyncCanvasResult(obj) {
1484
+ return "outputContent" in obj && "content" in obj.outputContent;
1485
+ }
1486
+ function getResultFromPollingResponse(response) {
1487
+ if (isSyncWorkflowResult(response)) {
1488
+ return response.output.output;
1489
+ }
1490
+ if (isAsyncWorkflowResult(response)) {
1491
+ return response.outputContent.output.output;
1492
+ }
1493
+ if (isSyncCanvasResult(response)) {
1494
+ return response.choices?.[0]?.message?.content;
1495
+ }
1496
+ if (isAsyncCanvasResult(response)) {
1497
+ return response.outputContent.content;
1498
+ }
1499
+ throw new Error("Invalid response type");
1500
+ }
1474
1501
  class CanvasExecution extends Emittery {
1475
1502
  /**
1476
1503
  * Creates a new canvas execution instance.
@@ -1552,7 +1579,7 @@ class CanvasExecution extends Emittery {
1552
1579
  execution.status = response.status;
1553
1580
  if (response.status === "succeeded") {
1554
1581
  execution._rawResultValue = response;
1555
- const content = response.outputContent.content;
1582
+ const content = getResultFromPollingResponse(response);
1556
1583
  try {
1557
1584
  const validatedContent = execution._skipResultValidation || !(outputSchema instanceof z__default.ZodType) ? content : outputSchema.parse(content);
1558
1585
  execution._resultPromise = Promise.resolve(validatedContent);
@@ -1836,7 +1863,8 @@ class CanvasExecution extends Emittery {
1836
1863
  versionId: this._params.versionId,
1837
1864
  messages: this._params.messages,
1838
1865
  tags: this._params.tags,
1839
- label: this._params.label
1866
+ label: this._params.label,
1867
+ webhook_url: this._params.webhookUrl
1840
1868
  };
1841
1869
  if (this._params.override && this._outputSchema instanceof z__default.ZodType) {
1842
1870
  return {
@@ -1891,7 +1919,7 @@ class CanvasExecution extends Emittery {
1891
1919
  }).then((response) => {
1892
1920
  this._id = response.id;
1893
1921
  this._rawResultValue = response;
1894
- return response.choices?.[0]?.message?.content;
1922
+ return getResultFromPollingResponse(response);
1895
1923
  }).then((content) => {
1896
1924
  const validatedContent = this._skipResultValidation || !(this._outputSchema instanceof z__default.ZodType) ? content : this._outputSchema.parse(content);
1897
1925
  this.status = "succeeded";
@@ -1997,10 +2025,10 @@ class CanvasExecution extends Emittery {
1997
2025
  };
1998
2026
  }
1999
2027
  this._rawResultValue = response;
2000
- this.emit("success", response.outputContent.content);
2028
+ this.emit("success", getResultFromPollingResponse(response));
2001
2029
  return {
2002
2030
  done: response.status === "succeeded",
2003
- value: response.outputContent.content
2031
+ value: getResultFromPollingResponse(response)
2004
2032
  };
2005
2033
  }).then((value) => {
2006
2034
  if (this._skipResultValidation || !(this._outputSchema instanceof z__default.ZodType)) {
@@ -2191,7 +2219,7 @@ class Canvas {
2191
2219
  *
2192
2220
  * @private
2193
2221
  */
2194
- constructor({ id, applicationId, name, versionId, input, output, client, variables }) {
2222
+ constructor({ id, applicationId, name, versionId, input, output, client, variables, isWorkflow }) {
2195
2223
  __publicField$1(this, "_id");
2196
2224
  __publicField$1(this, "_versionId");
2197
2225
  __publicField$1(this, "_applicationId");
@@ -2200,6 +2228,7 @@ class Canvas {
2200
2228
  __publicField$1(this, "_output");
2201
2229
  __publicField$1(this, "_client");
2202
2230
  __publicField$1(this, "_variables");
2231
+ __publicField$1(this, "_isWorkflow");
2203
2232
  this._id = id;
2204
2233
  this._applicationId = applicationId;
2205
2234
  this._name = name;
@@ -2208,6 +2237,7 @@ class Canvas {
2208
2237
  this._output = output && output(zod);
2209
2238
  this._client = client;
2210
2239
  this._variables = variables;
2240
+ this._isWorkflow = isWorkflow;
2211
2241
  }
2212
2242
  /**
2213
2243
  * Gets a canvas by its ID.
@@ -2236,7 +2266,8 @@ class Canvas {
2236
2266
  input,
2237
2267
  output,
2238
2268
  client,
2239
- variables: promptVersion.variables
2269
+ variables: promptVersion.variables,
2270
+ isWorkflow: promptVersion.isWorkflow
2240
2271
  });
2241
2272
  }
2242
2273
  /**
@@ -2287,6 +2318,14 @@ class Canvas {
2287
2318
  get variables() {
2288
2319
  return this._variables;
2289
2320
  }
2321
+ /**
2322
+ * Gets whether this canvas is a workflow.
2323
+ *
2324
+ * @returns True if the canvas is a workflow.
2325
+ */
2326
+ get isWorkflow() {
2327
+ return this._isWorkflow;
2328
+ }
2290
2329
  /**
2291
2330
  * Validates and parses input variables using the canvas input schema.
2292
2331
  *
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@meistrari/tela-sdk-js",
3
- "version": "2.1.0",
3
+ "version": "2.2.1",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/meistrari/tela-sdk-js.git"
@@ -70,4 +70,4 @@
70
70
  },
71
71
  "type": "module",
72
72
  "types": "dist/index.d.ts"
73
- }
73
+ }