@meistrari/tela-sdk-js 2.1.0 → 2.2.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 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.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;
@@ -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);
@@ -1911,7 +1938,7 @@ class CanvasExecution extends Emittery__default {
1911
1938
  }).then((response) => {
1912
1939
  this._id = response.id;
1913
1940
  this._rawResultValue = response;
1914
- return response.choices?.[0]?.message?.content;
1941
+ return getResultFromPollingResponse(response);
1915
1942
  }).then((content) => {
1916
1943
  const validatedContent = this._skipResultValidation || !(this._outputSchema instanceof z__default.ZodType) ? content : this._outputSchema.parse(content);
1917
1944
  this.status = "succeeded";
@@ -2017,10 +2044,10 @@ class CanvasExecution extends Emittery__default {
2017
2044
  };
2018
2045
  }
2019
2046
  this._rawResultValue = response;
2020
- this.emit("success", response.outputContent.content);
2047
+ this.emit("success", getResultFromPollingResponse(response));
2021
2048
  return {
2022
2049
  done: response.status === "succeeded",
2023
- value: response.outputContent.content
2050
+ value: getResultFromPollingResponse(response)
2024
2051
  };
2025
2052
  }).then((value) => {
2026
2053
  if (this._skipResultValidation || !(this._outputSchema instanceof z__default.ZodType)) {
@@ -2211,7 +2238,7 @@ class Canvas {
2211
2238
  *
2212
2239
  * @private
2213
2240
  */
2214
- constructor({ id, applicationId, name, versionId, input, output, client, variables }) {
2241
+ constructor({ id, applicationId, name, versionId, input, output, client, variables, isWorkflow }) {
2215
2242
  __publicField$1(this, "_id");
2216
2243
  __publicField$1(this, "_versionId");
2217
2244
  __publicField$1(this, "_applicationId");
@@ -2220,6 +2247,7 @@ class Canvas {
2220
2247
  __publicField$1(this, "_output");
2221
2248
  __publicField$1(this, "_client");
2222
2249
  __publicField$1(this, "_variables");
2250
+ __publicField$1(this, "_isWorkflow");
2223
2251
  this._id = id;
2224
2252
  this._applicationId = applicationId;
2225
2253
  this._name = name;
@@ -2228,6 +2256,7 @@ class Canvas {
2228
2256
  this._output = output && output(zod);
2229
2257
  this._client = client;
2230
2258
  this._variables = variables;
2259
+ this._isWorkflow = isWorkflow;
2231
2260
  }
2232
2261
  /**
2233
2262
  * Gets a canvas by its ID.
@@ -2256,7 +2285,8 @@ class Canvas {
2256
2285
  input,
2257
2286
  output,
2258
2287
  client,
2259
- variables: promptVersion.variables
2288
+ variables: promptVersion.variables,
2289
+ isWorkflow: promptVersion.isWorkflow
2260
2290
  });
2261
2291
  }
2262
2292
  /**
@@ -2307,6 +2337,14 @@ class Canvas {
2307
2337
  get variables() {
2308
2338
  return this._variables;
2309
2339
  }
2340
+ /**
2341
+ * Gets whether this canvas is a workflow.
2342
+ *
2343
+ * @returns True if the canvas is a workflow.
2344
+ */
2345
+ get isWorkflow() {
2346
+ return this._isWorkflow;
2347
+ }
2310
2348
  /**
2311
2349
  * Validates and parses input variables using the canvas input schema.
2312
2350
  *
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.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;
@@ -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);
@@ -1891,7 +1918,7 @@ class CanvasExecution extends Emittery {
1891
1918
  }).then((response) => {
1892
1919
  this._id = response.id;
1893
1920
  this._rawResultValue = response;
1894
- return response.choices?.[0]?.message?.content;
1921
+ return getResultFromPollingResponse(response);
1895
1922
  }).then((content) => {
1896
1923
  const validatedContent = this._skipResultValidation || !(this._outputSchema instanceof z__default.ZodType) ? content : this._outputSchema.parse(content);
1897
1924
  this.status = "succeeded";
@@ -1997,10 +2024,10 @@ class CanvasExecution extends Emittery {
1997
2024
  };
1998
2025
  }
1999
2026
  this._rawResultValue = response;
2000
- this.emit("success", response.outputContent.content);
2027
+ this.emit("success", getResultFromPollingResponse(response));
2001
2028
  return {
2002
2029
  done: response.status === "succeeded",
2003
- value: response.outputContent.content
2030
+ value: getResultFromPollingResponse(response)
2004
2031
  };
2005
2032
  }).then((value) => {
2006
2033
  if (this._skipResultValidation || !(this._outputSchema instanceof z__default.ZodType)) {
@@ -2191,7 +2218,7 @@ class Canvas {
2191
2218
  *
2192
2219
  * @private
2193
2220
  */
2194
- constructor({ id, applicationId, name, versionId, input, output, client, variables }) {
2221
+ constructor({ id, applicationId, name, versionId, input, output, client, variables, isWorkflow }) {
2195
2222
  __publicField$1(this, "_id");
2196
2223
  __publicField$1(this, "_versionId");
2197
2224
  __publicField$1(this, "_applicationId");
@@ -2200,6 +2227,7 @@ class Canvas {
2200
2227
  __publicField$1(this, "_output");
2201
2228
  __publicField$1(this, "_client");
2202
2229
  __publicField$1(this, "_variables");
2230
+ __publicField$1(this, "_isWorkflow");
2203
2231
  this._id = id;
2204
2232
  this._applicationId = applicationId;
2205
2233
  this._name = name;
@@ -2208,6 +2236,7 @@ class Canvas {
2208
2236
  this._output = output && output(zod);
2209
2237
  this._client = client;
2210
2238
  this._variables = variables;
2239
+ this._isWorkflow = isWorkflow;
2211
2240
  }
2212
2241
  /**
2213
2242
  * Gets a canvas by its ID.
@@ -2236,7 +2265,8 @@ class Canvas {
2236
2265
  input,
2237
2266
  output,
2238
2267
  client,
2239
- variables: promptVersion.variables
2268
+ variables: promptVersion.variables,
2269
+ isWorkflow: promptVersion.isWorkflow
2240
2270
  });
2241
2271
  }
2242
2272
  /**
@@ -2287,6 +2317,14 @@ class Canvas {
2287
2317
  get variables() {
2288
2318
  return this._variables;
2289
2319
  }
2320
+ /**
2321
+ * Gets whether this canvas is a workflow.
2322
+ *
2323
+ * @returns True if the canvas is a workflow.
2324
+ */
2325
+ get isWorkflow() {
2326
+ return this._isWorkflow;
2327
+ }
2290
2328
  /**
2291
2329
  * Validates and parses input variables using the canvas input schema.
2292
2330
  *
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.0",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/meistrari/tela-sdk-js.git"