@meistrari/tela-sdk-js 2.12.0 → 2.13.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
@@ -4,6 +4,7 @@ const changeCase = require('change-case');
4
4
  const minimatch = require('minimatch');
5
5
  const z = require('zod');
6
6
  const Emittery = require('emittery');
7
+ const agentSdk = require('@meistrari/agent-sdk');
7
8
 
8
9
  function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e.default : e; }
9
10
 
@@ -23,12 +24,12 @@ const changeCase__namespace = /*#__PURE__*/_interopNamespaceCompat(changeCase);
23
24
  const z__default = /*#__PURE__*/_interopDefaultCompat(z);
24
25
  const Emittery__default = /*#__PURE__*/_interopDefaultCompat(Emittery);
25
26
 
26
- const version = "2.12.0";
27
+ const version = "2.13.1";
27
28
 
28
- var __defProp$a = Object.defineProperty;
29
- var __defNormalProp$a = (obj, key, value) => key in obj ? __defProp$a(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
30
- var __publicField$a = (obj, key, value) => {
31
- __defNormalProp$a(obj, typeof key !== "symbol" ? key + "" : key, value);
29
+ var __defProp$b = Object.defineProperty;
30
+ var __defNormalProp$b = (obj, key, value) => key in obj ? __defProp$b(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
31
+ var __publicField$b = (obj, key, value) => {
32
+ __defNormalProp$b(obj, typeof key !== "symbol" ? key + "" : key, value);
32
33
  return value;
33
34
  };
34
35
  class TelaError extends Error {
@@ -58,7 +59,7 @@ class InvalidFileURL extends TelaError {
58
59
  class FileUploadError extends TelaError {
59
60
  constructor(message, statusCode) {
60
61
  super(`Failed to upload file: ${message} (Status code: ${statusCode})`);
61
- __publicField$a(this, "statusCode");
62
+ __publicField$b(this, "statusCode");
62
63
  this.statusCode = statusCode;
63
64
  }
64
65
  }
@@ -75,30 +76,44 @@ class InvalidExecutionModeError extends TelaError {
75
76
  class ExecutionFailedError extends TelaError {
76
77
  constructor(rawOutput) {
77
78
  super(`Execution failed: ${JSON.stringify(rawOutput)}`);
78
- __publicField$a(this, "rawOutput");
79
+ __publicField$b(this, "rawOutput");
79
80
  this.rawOutput = rawOutput;
80
81
  }
81
82
  }
82
83
  class TaskFailedError extends TelaError {
83
84
  constructor(rawTask, message, cause) {
84
85
  super(`Task failed: ${JSON.stringify(rawTask)}`, { cause });
85
- __publicField$a(this, "rawTask");
86
+ __publicField$b(this, "rawTask");
86
87
  this.rawTask = rawTask;
87
88
  }
88
89
  }
89
90
  class BatchExecutionFailedError extends TelaError {
90
91
  constructor(rawResponse) {
91
92
  super(`Batch execution failed: ${JSON.stringify(rawResponse)}`);
92
- __publicField$a(this, "rawResponse");
93
+ __publicField$b(this, "rawResponse");
93
94
  this.rawResponse = rawResponse;
94
95
  }
95
96
  }
97
+ class AgentExecutionFailedError extends TelaError {
98
+ constructor(payload) {
99
+ super(`Agent execution failed${payload.sessionId ? ` (session ${payload.sessionId})` : ""}: ${payload.error ?? "unknown error"}`);
100
+ /** The session id, when known. */
101
+ __publicField$b(this, "sessionId");
102
+ /** The server-provided error message, when available. */
103
+ __publicField$b(this, "error");
104
+ /** The full raw payload that triggered the failure. */
105
+ __publicField$b(this, "raw");
106
+ this.sessionId = payload.sessionId;
107
+ this.error = payload.error;
108
+ this.raw = payload;
109
+ }
110
+ }
96
111
  class APIError extends TelaError {
97
112
  constructor(statusCode, error, _message) {
98
113
  const message = error?.message ? typeof error.message === "string" ? error.message : JSON.stringify(error.message) : error ? JSON.stringify(error) : _message;
99
114
  super(message);
100
- __publicField$a(this, "statusCode");
101
- __publicField$a(this, "error");
115
+ __publicField$b(this, "statusCode");
116
+ __publicField$b(this, "error");
102
117
  this.statusCode = statusCode;
103
118
  this.error = error;
104
119
  }
@@ -140,7 +155,7 @@ class APIError extends TelaError {
140
155
  class UserAbortError extends APIError {
141
156
  constructor({ message } = {}) {
142
157
  super(void 0, void 0, message || "User aborted.");
143
- __publicField$a(this, "statusCode");
158
+ __publicField$b(this, "statusCode");
144
159
  }
145
160
  }
146
161
  class ConnectionError extends APIError {
@@ -149,7 +164,7 @@ class ConnectionError extends APIError {
149
164
  cause
150
165
  }) {
151
166
  super(void 0, void 0, message || "Connection error.");
152
- __publicField$a(this, "statusCode");
167
+ __publicField$b(this, "statusCode");
153
168
  if (cause)
154
169
  this.cause = cause;
155
170
  }
@@ -159,57 +174,57 @@ class ConnectionTimeout extends APIError {
159
174
  message
160
175
  } = {}) {
161
176
  super(void 0, void 0, message || "Request timed out.");
162
- __publicField$a(this, "statusCode");
177
+ __publicField$b(this, "statusCode");
163
178
  }
164
179
  }
165
180
  class BadRequestError extends APIError {
166
181
  constructor() {
167
182
  super(...arguments);
168
- __publicField$a(this, "statusCode", 400);
183
+ __publicField$b(this, "statusCode", 400);
169
184
  }
170
185
  // todo: handle validation errors from zod/typebox
171
186
  }
172
187
  class AuthenticationError extends APIError {
173
188
  constructor() {
174
189
  super(...arguments);
175
- __publicField$a(this, "statusCode", 401);
190
+ __publicField$b(this, "statusCode", 401);
176
191
  }
177
192
  }
178
193
  class AuthorizationError extends APIError {
179
194
  constructor() {
180
195
  super(...arguments);
181
- __publicField$a(this, "statusCode", 403);
196
+ __publicField$b(this, "statusCode", 403);
182
197
  }
183
198
  }
184
199
  class NotFoundError extends APIError {
185
200
  constructor() {
186
201
  super(...arguments);
187
- __publicField$a(this, "statusCode", 404);
202
+ __publicField$b(this, "statusCode", 404);
188
203
  }
189
204
  }
190
205
  class ConflictError extends APIError {
191
206
  constructor() {
192
207
  super(...arguments);
193
- __publicField$a(this, "statusCode", 409);
208
+ __publicField$b(this, "statusCode", 409);
194
209
  }
195
210
  }
196
211
  class UnprocessableEntityError extends APIError {
197
212
  constructor() {
198
213
  super(...arguments);
199
214
  // todo: check if tela returns 400 or 422 for zod errors
200
- __publicField$a(this, "statusCode", 422);
215
+ __publicField$b(this, "statusCode", 422);
201
216
  }
202
217
  }
203
218
  class RateLimitError extends APIError {
204
219
  constructor() {
205
220
  super(...arguments);
206
- __publicField$a(this, "statusCode", 429);
221
+ __publicField$b(this, "statusCode", 429);
207
222
  }
208
223
  }
209
224
  class InternalServerError extends APIError {
210
225
  constructor() {
211
226
  super(...arguments);
212
- __publicField$a(this, "statusCode", 500);
227
+ __publicField$b(this, "statusCode", 500);
213
228
  }
214
229
  }
215
230
  function toError(err) {
@@ -495,10 +510,10 @@ function transformDurationToMs(durationStr) {
495
510
  return Number.parseInt(amount) * multiplier;
496
511
  }
497
512
 
498
- var __defProp$9 = Object.defineProperty;
499
- var __defNormalProp$9 = (obj, key, value) => key in obj ? __defProp$9(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
500
- var __publicField$9 = (obj, key, value) => {
501
- __defNormalProp$9(obj, typeof key !== "symbol" ? key + "" : key, value);
513
+ var __defProp$a = Object.defineProperty;
514
+ var __defNormalProp$a = (obj, key, value) => key in obj ? __defProp$a(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
515
+ var __publicField$a = (obj, key, value) => {
516
+ __defNormalProp$a(obj, typeof key !== "symbol" ? key + "" : key, value);
502
517
  return value;
503
518
  };
504
519
  class Stream {
@@ -762,9 +777,9 @@ function findDoubleNewlineIndex(buffer) {
762
777
  }
763
778
  class SSEDecoder {
764
779
  constructor() {
765
- __publicField$9(this, "data");
766
- __publicField$9(this, "event");
767
- __publicField$9(this, "chunks");
780
+ __publicField$a(this, "data");
781
+ __publicField$a(this, "event");
782
+ __publicField$a(this, "chunks");
768
783
  this.event = null;
769
784
  this.data = [];
770
785
  this.chunks = [];
@@ -805,9 +820,9 @@ class SSEDecoder {
805
820
  const _LineDecoder = class _LineDecoder {
806
821
  // TextDecoder found in browsers; not typed to avoid pulling in either "dom" or "node" types.
807
822
  constructor() {
808
- __publicField$9(this, "buffer");
809
- __publicField$9(this, "trailingCR");
810
- __publicField$9(this, "textDecoder");
823
+ __publicField$a(this, "buffer");
824
+ __publicField$a(this, "trailingCR");
825
+ __publicField$a(this, "textDecoder");
811
826
  this.buffer = [];
812
827
  this.trailingCR = false;
813
828
  }
@@ -882,8 +897,8 @@ const _LineDecoder = class _LineDecoder {
882
897
  }
883
898
  };
884
899
  // prettier-ignore
885
- __publicField$9(_LineDecoder, "NEWLINE_CHARS", /* @__PURE__ */ new Set(["\n", "\r"]));
886
- __publicField$9(_LineDecoder, "NEWLINE_REGEXP", /\r\n|[\n\r]/g);
900
+ __publicField$a(_LineDecoder, "NEWLINE_CHARS", /* @__PURE__ */ new Set(["\n", "\r"]));
901
+ __publicField$a(_LineDecoder, "NEWLINE_REGEXP", /\r\n|[\n\r]/g);
887
902
  let LineDecoder = _LineDecoder;
888
903
  function partition(str, delimiter) {
889
904
  const index = str.indexOf(delimiter);
@@ -920,10 +935,10 @@ function readableStreamAsyncIterable(stream) {
920
935
  };
921
936
  }
922
937
 
923
- var __defProp$8 = Object.defineProperty;
924
- var __defNormalProp$8 = (obj, key, value) => key in obj ? __defProp$8(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
925
- var __publicField$8 = (obj, key, value) => {
926
- __defNormalProp$8(obj, typeof key !== "symbol" ? key + "" : key, value);
938
+ var __defProp$9 = Object.defineProperty;
939
+ var __defNormalProp$9 = (obj, key, value) => key in obj ? __defProp$9(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
940
+ var __publicField$9 = (obj, key, value) => {
941
+ __defNormalProp$9(obj, typeof key !== "symbol" ? key + "" : key, value);
927
942
  return value;
928
943
  };
929
944
  function getRequestIdFromResponse(response) {
@@ -999,10 +1014,10 @@ function transformObjectCase(obj, transformCase) {
999
1014
  }
1000
1015
  class BaseClient {
1001
1016
  constructor({ baseURL, maxRetries = 5, timeout = 0 }) {
1002
- __publicField$8(this, "baseURL");
1003
- __publicField$8(this, "maxRetries");
1004
- __publicField$8(this, "timeout");
1005
- __publicField$8(this, "fetch");
1017
+ __publicField$9(this, "baseURL");
1018
+ __publicField$9(this, "maxRetries");
1019
+ __publicField$9(this, "timeout");
1020
+ __publicField$9(this, "fetch");
1006
1021
  this.baseURL = baseURL;
1007
1022
  this.maxRetries = validateMaxRetries(maxRetries);
1008
1023
  this.timeout = validateTimeout(timeout);
@@ -1040,6 +1055,36 @@ class BaseClient {
1040
1055
  delete(path, opts) {
1041
1056
  return this.methodRequest("DELETE", path, opts);
1042
1057
  }
1058
+ /**
1059
+ * Performs a request and returns the raw {@link Response} together with its
1060
+ * {@link AbortController}, bypassing JSON parsing and case transformation.
1061
+ *
1062
+ * Intended for consumers that parse the response body themselves — e.g.
1063
+ * custom Server-Sent Events streams whose framing differs from the chat
1064
+ * completion stream handled by {@link Stream.fromSSEResponse}. Reuses the
1065
+ * client's retry, auth, timeout, and `baseURL` handling.
1066
+ *
1067
+ * @param method - The HTTP method to use.
1068
+ * @param path - Request path (relative to `baseURL`/`opts.baseURL`, or absolute).
1069
+ * @param opts - Request options (notably `baseURL`, `query`, and `signal`).
1070
+ * @returns The live `Response` and the `AbortController` controlling it.
1071
+ */
1072
+ async requestRaw(method, path, opts) {
1073
+ const { headers: customHeaders, ...restOpts } = opts ?? {};
1074
+ const headers = this.createHeaders();
1075
+ if (customHeaders) {
1076
+ for (const [key, value] of customHeaders.entries()) {
1077
+ headers.set(key, value);
1078
+ }
1079
+ }
1080
+ const { response, controller } = await this.request({
1081
+ method,
1082
+ path,
1083
+ headers,
1084
+ ...restOpts
1085
+ });
1086
+ return { response, controller };
1087
+ }
1043
1088
  async methodRequest(method, path, opts) {
1044
1089
  const { transformCase = true, headers: customHeaders, ...restOpts } = opts ?? {};
1045
1090
  const headers = this.createHeaders();
@@ -1287,10 +1332,10 @@ async function getStreamSize(stream) {
1287
1332
  return size;
1288
1333
  }
1289
1334
 
1290
- var __defProp$7 = Object.defineProperty;
1291
- var __defNormalProp$7 = (obj, key, value) => key in obj ? __defProp$7(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
1292
- var __publicField$7 = (obj, key, value) => {
1293
- __defNormalProp$7(obj, typeof key !== "symbol" ? key + "" : key, value);
1335
+ var __defProp$8 = Object.defineProperty;
1336
+ var __defNormalProp$8 = (obj, key, value) => key in obj ? __defProp$8(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
1337
+ var __publicField$8 = (obj, key, value) => {
1338
+ __defNormalProp$8(obj, typeof key !== "symbol" ? key + "" : key, value);
1294
1339
  return value;
1295
1340
  };
1296
1341
  function TelaFileSchema() {
@@ -1298,11 +1343,11 @@ function TelaFileSchema() {
1298
1343
  }
1299
1344
  class TelaFile {
1300
1345
  constructor(file, options = {}) {
1301
- __publicField$7(this, "_file");
1302
- __publicField$7(this, "_options");
1303
- __publicField$7(this, "_size", null);
1304
- __publicField$7(this, "_mimeType");
1305
- __publicField$7(this, "_name");
1346
+ __publicField$8(this, "_file");
1347
+ __publicField$8(this, "_options");
1348
+ __publicField$8(this, "_size", null);
1349
+ __publicField$8(this, "_mimeType");
1350
+ __publicField$8(this, "_name");
1306
1351
  this._file = file;
1307
1352
  if (file instanceof File || file instanceof Blob) {
1308
1353
  this._size = file.size;
@@ -1781,10 +1826,10 @@ async function streamFile(vaultReference, client) {
1781
1826
  });
1782
1827
  }
1783
1828
 
1784
- var __defProp$6 = Object.defineProperty;
1785
- var __defNormalProp$6 = (obj, key, value) => key in obj ? __defProp$6(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
1786
- var __publicField$6 = (obj, key, value) => {
1787
- __defNormalProp$6(obj, typeof key !== "symbol" ? key + "" : key, value);
1829
+ var __defProp$7 = Object.defineProperty;
1830
+ var __defNormalProp$7 = (obj, key, value) => key in obj ? __defProp$7(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
1831
+ var __publicField$7 = (obj, key, value) => {
1832
+ __defNormalProp$7(obj, typeof key !== "symbol" ? key + "" : key, value);
1788
1833
  return value;
1789
1834
  };
1790
1835
  function timeout(ms, signal) {
@@ -1800,10 +1845,10 @@ function timeout(ms, signal) {
1800
1845
  }
1801
1846
  class Poller {
1802
1847
  constructor({ interval, timeout: timeout2, abortSignal }) {
1803
- __publicField$6(this, "_interval");
1804
- __publicField$6(this, "_timeout");
1805
- __publicField$6(this, "_abortSignal");
1806
- __publicField$6(this, "_internalAbortController");
1848
+ __publicField$7(this, "_interval");
1849
+ __publicField$7(this, "_timeout");
1850
+ __publicField$7(this, "_abortSignal");
1851
+ __publicField$7(this, "_internalAbortController");
1807
1852
  if (interval <= 0) {
1808
1853
  throw new TelaError("Interval must be greater than 0");
1809
1854
  }
@@ -1864,10 +1909,10 @@ class Poller {
1864
1909
  }
1865
1910
  }
1866
1911
 
1867
- var __defProp$5 = Object.defineProperty;
1868
- var __defNormalProp$5 = (obj, key, value) => key in obj ? __defProp$5(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
1869
- var __publicField$5 = (obj, key, value) => {
1870
- __defNormalProp$5(obj, typeof key !== "symbol" ? key + "" : key, value);
1912
+ var __defProp$6 = Object.defineProperty;
1913
+ var __defNormalProp$6 = (obj, key, value) => key in obj ? __defProp$6(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
1914
+ var __publicField$6 = (obj, key, value) => {
1915
+ __defNormalProp$6(obj, typeof key !== "symbol" ? key + "" : key, value);
1871
1916
  return value;
1872
1917
  };
1873
1918
  function isUUID(str) {
@@ -1923,21 +1968,21 @@ class CanvasExecution extends Emittery__default {
1923
1968
  */
1924
1969
  constructor(variables, params = { async: false }, outputSchema, client, isTask = false) {
1925
1970
  super();
1926
- __publicField$5(this, "_id");
1927
- __publicField$5(this, "_status");
1928
- __publicField$5(this, "_variables");
1929
- __publicField$5(this, "_params");
1930
- __publicField$5(this, "_client");
1931
- __publicField$5(this, "_outputSchema");
1932
- __publicField$5(this, "_skipResultValidation");
1933
- __publicField$5(this, "_abortController");
1934
- __publicField$5(this, "_isTask");
1935
- __publicField$5(this, "_headers");
1936
- __publicField$5(this, "_resultPromise");
1937
- __publicField$5(this, "_stream");
1938
- __publicField$5(this, "_rawResultValue");
1939
- __publicField$5(this, "_requestId");
1940
- __publicField$5(this, "_task");
1971
+ __publicField$6(this, "_id");
1972
+ __publicField$6(this, "_status");
1973
+ __publicField$6(this, "_variables");
1974
+ __publicField$6(this, "_params");
1975
+ __publicField$6(this, "_client");
1976
+ __publicField$6(this, "_outputSchema");
1977
+ __publicField$6(this, "_skipResultValidation");
1978
+ __publicField$6(this, "_abortController");
1979
+ __publicField$6(this, "_isTask");
1980
+ __publicField$6(this, "_headers");
1981
+ __publicField$6(this, "_resultPromise");
1982
+ __publicField$6(this, "_stream");
1983
+ __publicField$6(this, "_rawResultValue");
1984
+ __publicField$6(this, "_requestId");
1985
+ __publicField$6(this, "_task");
1941
1986
  this._variables = variables;
1942
1987
  this._params = params;
1943
1988
  this._outputSchema = outputSchema;
@@ -2568,10 +2613,10 @@ class CanvasExecution extends Emittery__default {
2568
2613
  }
2569
2614
  }
2570
2615
 
2571
- var __defProp$4 = Object.defineProperty;
2572
- var __defNormalProp$4 = (obj, key, value) => key in obj ? __defProp$4(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
2573
- var __publicField$4 = (obj, key, value) => {
2574
- __defNormalProp$4(obj, typeof key !== "symbol" ? key + "" : key, value);
2616
+ var __defProp$5 = Object.defineProperty;
2617
+ var __defNormalProp$5 = (obj, key, value) => key in obj ? __defProp$5(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
2618
+ var __publicField$5 = (obj, key, value) => {
2619
+ __defNormalProp$5(obj, typeof key !== "symbol" ? key + "" : key, value);
2575
2620
  return value;
2576
2621
  };
2577
2622
  function resolveBatchQueue(queue) {
@@ -2723,8 +2768,8 @@ class BatchExecutionResult {
2723
2768
  * @internal
2724
2769
  */
2725
2770
  constructor(client, response) {
2726
- __publicField$4(this, "_client");
2727
- __publicField$4(this, "_response");
2771
+ __publicField$5(this, "_client");
2772
+ __publicField$5(this, "_response");
2728
2773
  this._client = client;
2729
2774
  this._response = response;
2730
2775
  }
@@ -3000,13 +3045,13 @@ class BatchExecution extends Emittery__default {
3000
3045
  */
3001
3046
  constructor(id, client, params = {}, creationResponse) {
3002
3047
  super();
3003
- __publicField$4(this, "_client");
3004
- __publicField$4(this, "_id");
3005
- __publicField$4(this, "_params");
3006
- __publicField$4(this, "_abortController");
3007
- __publicField$4(this, "_creationResponse");
3008
- __publicField$4(this, "_status", "created");
3009
- __publicField$4(this, "_resultPromise");
3048
+ __publicField$5(this, "_client");
3049
+ __publicField$5(this, "_id");
3050
+ __publicField$5(this, "_params");
3051
+ __publicField$5(this, "_abortController");
3052
+ __publicField$5(this, "_creationResponse");
3053
+ __publicField$5(this, "_status", "created");
3054
+ __publicField$5(this, "_resultPromise");
3010
3055
  this._id = id;
3011
3056
  this._client = client;
3012
3057
  this._params = params;
@@ -3219,10 +3264,10 @@ class Batch {
3219
3264
  * @internal
3220
3265
  */
3221
3266
  constructor(client, canvasIdentifier, params = {}) {
3222
- __publicField$4(this, "_client");
3223
- __publicField$4(this, "_canvasIdentifier");
3224
- __publicField$4(this, "_items", []);
3225
- __publicField$4(this, "_params");
3267
+ __publicField$5(this, "_client");
3268
+ __publicField$5(this, "_canvasIdentifier");
3269
+ __publicField$5(this, "_items", []);
3270
+ __publicField$5(this, "_params");
3226
3271
  this._client = client;
3227
3272
  this._canvasIdentifier = canvasIdentifier;
3228
3273
  this._params = params;
@@ -3367,10 +3412,10 @@ class Batch {
3367
3412
  }
3368
3413
  }
3369
3414
 
3370
- var __defProp$3 = Object.defineProperty;
3371
- var __defNormalProp$3 = (obj, key, value) => key in obj ? __defProp$3(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
3372
- var __publicField$3 = (obj, key, value) => {
3373
- __defNormalProp$3(obj, typeof key !== "symbol" ? key + "" : key, value);
3415
+ var __defProp$4 = Object.defineProperty;
3416
+ var __defNormalProp$4 = (obj, key, value) => key in obj ? __defProp$4(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
3417
+ var __publicField$4 = (obj, key, value) => {
3418
+ __defNormalProp$4(obj, typeof key !== "symbol" ? key + "" : key, value);
3374
3419
  return value;
3375
3420
  };
3376
3421
  function fetchById(id, client) {
@@ -3402,15 +3447,15 @@ class Canvas {
3402
3447
  * @private
3403
3448
  */
3404
3449
  constructor({ id, applicationId, name, versionId, input, output, client, variables, isWorkflow }) {
3405
- __publicField$3(this, "_id");
3406
- __publicField$3(this, "_versionId");
3407
- __publicField$3(this, "_applicationId");
3408
- __publicField$3(this, "_name");
3409
- __publicField$3(this, "_input");
3410
- __publicField$3(this, "_output");
3411
- __publicField$3(this, "_client");
3412
- __publicField$3(this, "_variables");
3413
- __publicField$3(this, "_isWorkflow");
3450
+ __publicField$4(this, "_id");
3451
+ __publicField$4(this, "_versionId");
3452
+ __publicField$4(this, "_applicationId");
3453
+ __publicField$4(this, "_name");
3454
+ __publicField$4(this, "_input");
3455
+ __publicField$4(this, "_output");
3456
+ __publicField$4(this, "_client");
3457
+ __publicField$4(this, "_variables");
3458
+ __publicField$4(this, "_isWorkflow");
3414
3459
  this._id = id;
3415
3460
  this._applicationId = applicationId;
3416
3461
  this._name = name;
@@ -3667,24 +3712,24 @@ z.z.object({
3667
3712
  requestId: z.z.string()
3668
3713
  });
3669
3714
 
3670
- var __defProp$2 = Object.defineProperty;
3671
- var __defNormalProp$2 = (obj, key, value) => key in obj ? __defProp$2(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
3672
- var __publicField$2 = (obj, key, value) => {
3673
- __defNormalProp$2(obj, typeof key !== "symbol" ? key + "" : key, value);
3715
+ var __defProp$3 = Object.defineProperty;
3716
+ var __defNormalProp$3 = (obj, key, value) => key in obj ? __defProp$3(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
3717
+ var __publicField$3 = (obj, key, value) => {
3718
+ __defNormalProp$3(obj, typeof key !== "symbol" ? key + "" : key, value);
3674
3719
  return value;
3675
3720
  };
3676
3721
  class Task extends Emittery__default {
3677
3722
  constructor(client, variables, task, requestId, outputSchema, skipResultValidation = false) {
3678
3723
  super();
3679
- __publicField$2(this, "_variables");
3680
- __publicField$2(this, "_task");
3681
- __publicField$2(this, "_abortController", new AbortController());
3682
- __publicField$2(this, "_client");
3683
- __publicField$2(this, "_outputSchema");
3684
- __publicField$2(this, "_skipResultValidation");
3685
- __publicField$2(this, "_resultPromise");
3686
- __publicField$2(this, "_status");
3687
- __publicField$2(this, "_requestId");
3724
+ __publicField$3(this, "_variables");
3725
+ __publicField$3(this, "_task");
3726
+ __publicField$3(this, "_abortController", new AbortController());
3727
+ __publicField$3(this, "_client");
3728
+ __publicField$3(this, "_outputSchema");
3729
+ __publicField$3(this, "_skipResultValidation");
3730
+ __publicField$3(this, "_resultPromise");
3731
+ __publicField$3(this, "_status");
3732
+ __publicField$3(this, "_requestId");
3688
3733
  this._variables = variables;
3689
3734
  this._task = task;
3690
3735
  this._client = client;
@@ -3932,10 +3977,10 @@ class Task extends Emittery__default {
3932
3977
  }
3933
3978
  }
3934
3979
 
3935
- var __defProp$1 = Object.defineProperty;
3936
- var __defNormalProp$1 = (obj, key, value) => key in obj ? __defProp$1(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
3937
- var __publicField$1 = (obj, key, value) => {
3938
- __defNormalProp$1(obj, typeof key !== "symbol" ? key + "" : key, value);
3980
+ var __defProp$2 = Object.defineProperty;
3981
+ var __defNormalProp$2 = (obj, key, value) => key in obj ? __defProp$2(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
3982
+ var __publicField$2 = (obj, key, value) => {
3983
+ __defNormalProp$2(obj, typeof key !== "symbol" ? key + "" : key, value);
3939
3984
  return value;
3940
3985
  };
3941
3986
  const DateRange = z__default.object({
@@ -3981,11 +4026,11 @@ class Workstation {
3981
4026
  * @internal
3982
4027
  */
3983
4028
  constructor({ client, applicationId, promptVersion, input, output }) {
3984
- __publicField$1(this, "_id");
3985
- __publicField$1(this, "_promptVersion");
3986
- __publicField$1(this, "_client");
3987
- __publicField$1(this, "_input");
3988
- __publicField$1(this, "_output");
4029
+ __publicField$2(this, "_id");
4030
+ __publicField$2(this, "_promptVersion");
4031
+ __publicField$2(this, "_client");
4032
+ __publicField$2(this, "_input");
4033
+ __publicField$2(this, "_output");
3989
4034
  this._id = applicationId;
3990
4035
  this._promptVersion = promptVersion;
3991
4036
  this._client = client;
@@ -4676,6 +4721,154 @@ class Vault {
4676
4721
  }
4677
4722
  }
4678
4723
 
4724
+ var __defProp$1 = Object.defineProperty;
4725
+ var __defNormalProp$1 = (obj, key, value) => key in obj ? __defProp$1(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
4726
+ var __publicField$1 = (obj, key, value) => {
4727
+ __defNormalProp$1(obj, typeof key !== "symbol" ? key + "" : key, value);
4728
+ return value;
4729
+ };
4730
+ const AGENT_NO_TRANSFORM = { transformCase: false };
4731
+ class Agents {
4732
+ constructor(gateway, config) {
4733
+ /** The delegated agent-sdk client (the `/v4/*` execution backend). */
4734
+ __publicField$1(this, "client");
4735
+ /** The Tela gateway client (`/agent` discovery + vault upload). */
4736
+ __publicField$1(this, "gateway");
4737
+ /** Memoized `agentId` → `{ organizationName, repository }` resolutions. */
4738
+ __publicField$1(this, "resolved", /* @__PURE__ */ new Map());
4739
+ /**
4740
+ * Streams a session's events. Pass-through to the agent-sdk client
4741
+ * (`GET /v4/sessions/:id`).
4742
+ */
4743
+ __publicField$1(this, "streamSession");
4744
+ /**
4745
+ * Fetches the session timeline summary. Pass-through to the agent-sdk client
4746
+ * (`GET /v4/sessions/:id/timeline`).
4747
+ */
4748
+ __publicField$1(this, "fetchTimeline");
4749
+ /**
4750
+ * Cancels a running session. Pass-through to the agent-sdk client
4751
+ * (`POST /v4/sessions/:id/cancel`).
4752
+ */
4753
+ __publicField$1(this, "cancelSession");
4754
+ /**
4755
+ * Resolves a `vault://` reference to bytes/stream/json. Pass-through to the
4756
+ * agent-sdk client.
4757
+ */
4758
+ __publicField$1(this, "resolveReference");
4759
+ this.gateway = gateway;
4760
+ this.client = "client" in config ? config.client : agentSdk.agentClient({
4761
+ baseUrl: config.agentBaseURL,
4762
+ authStrategy: config.authStrategy,
4763
+ vaultUrl: config.vaultURL
4764
+ });
4765
+ this.streamSession = this.client.streamSession;
4766
+ this.fetchTimeline = this.client.fetchTimeline;
4767
+ this.cancelSession = this.client.cancelSession;
4768
+ this.resolveReference = this.client.resolveReference;
4769
+ }
4770
+ /**
4771
+ * Lists the agents available in the workspace (optionally filtered by
4772
+ * project) via the Tela gateway (`GET /agent`).
4773
+ */
4774
+ async list(query = {}) {
4775
+ const response = await this.gateway.get("/agent", {
4776
+ ...AGENT_NO_TRANSFORM,
4777
+ query
4778
+ });
4779
+ return response.data;
4780
+ }
4781
+ /**
4782
+ * Fetches an agent record by id via the Tela gateway (`GET /agent/:id`).
4783
+ */
4784
+ async get(agentId) {
4785
+ const response = await this.gateway.get(`/agent/${agentId}`, {
4786
+ ...AGENT_NO_TRANSFORM
4787
+ });
4788
+ return response.data;
4789
+ }
4790
+ /**
4791
+ * Starts (or continues/recovers) an agent session, delegating to the
4792
+ * agent-sdk client (`POST /v4/agents/execute`).
4793
+ *
4794
+ * - **New session**: pass `agentId` (+ `message`). It is resolved to the
4795
+ * underlying `organizationName`/`repository`.
4796
+ * - **Continue / recover**: pass `sessionId` (omit `agentId`); `recover: true`
4797
+ * resumes without a new message.
4798
+ *
4799
+ * After the request shape is validated, `TelaFile` inputs are uploaded to
4800
+ * the vault; `webhooks` pass through to register lifecycle callbacks.
4801
+ *
4802
+ * @throws {Error} If neither `agentId` nor `sessionId` is provided, or if
4803
+ * both are provided.
4804
+ */
4805
+ async executeAgent(params) {
4806
+ const { agentId, inputs, ...rest } = params;
4807
+ const hasSessionId = rest.sessionId !== void 0;
4808
+ if (hasSessionId) {
4809
+ if (agentId)
4810
+ throw new Error("agents.executeAgent: pass either `agentId` to start a new session or `sessionId` to continue/recover an existing session, not both.");
4811
+ const resolvedInputs2 = inputs ? await this.uploadInputs(inputs) : void 0;
4812
+ return this.client.executeAgent({ ...rest, inputs: resolvedInputs2 });
4813
+ }
4814
+ if (!agentId)
4815
+ throw new Error("agents.executeAgent: `agentId` is required to start a new session (omit it only when continuing an existing `sessionId`).");
4816
+ const resolvedInputs = inputs ? await this.uploadInputs(inputs) : void 0;
4817
+ const { organizationName, repository } = await this.resolveAgent(agentId);
4818
+ return this.client.executeAgent({ ...rest, inputs: resolvedInputs, organizationName, repository });
4819
+ }
4820
+ /**
4821
+ * Updates an agent's model, delegating to the agent-sdk client
4822
+ * (`PUT /v4/agents/:repository/model`). The `agentId` is resolved to the
4823
+ * underlying repository first.
4824
+ */
4825
+ async updateAgentModel(params) {
4826
+ const { repository } = await this.resolveAgent(params.agentId);
4827
+ return this.client.updateAgentModel({
4828
+ repository,
4829
+ model: params.model,
4830
+ commitMessage: params.commitMessage
4831
+ });
4832
+ }
4833
+ /**
4834
+ * Resolves an `agentId` to its `organizationName`/`repository`, memoizing the
4835
+ * lookup. Backed by the Tela gateway `GET /agent/:id`.
4836
+ */
4837
+ async resolveAgent(agentId) {
4838
+ const cached = this.resolved.get(agentId);
4839
+ if (cached)
4840
+ return cached;
4841
+ const { organizationName, repository } = await this.get(agentId);
4842
+ const resolution = { organizationName, repository };
4843
+ this.resolved.set(agentId, resolution);
4844
+ return resolution;
4845
+ }
4846
+ /**
4847
+ * Uploads any {@link TelaFile} inputs to the vault, turning the input list
4848
+ * into agent-sdk {@link AgentInput}s (`vault://` references pass through).
4849
+ */
4850
+ async uploadInputs(inputs) {
4851
+ return Promise.all(
4852
+ inputs.map(async (input) => {
4853
+ if (isTelaFile(input)) {
4854
+ const { fileUrl } = await uploadFile(input, this.gateway);
4855
+ return { vaultRef: fileUrl, filename: input.name ?? "file" };
4856
+ }
4857
+ return input;
4858
+ })
4859
+ );
4860
+ }
4861
+ }
4862
+
4863
+ function createAuthStrategy(credentials) {
4864
+ if (credentials.dataToken)
4865
+ return new agentSdk.DataTokenAuthStrategy(credentials.dataToken);
4866
+ const bearer = credentials.apiKey ?? credentials.jwt;
4867
+ if (!bearer)
4868
+ throw new MissingAuthError();
4869
+ return new agentSdk.APIKeyAuthStrategy(bearer);
4870
+ }
4871
+
4679
4872
  var __defProp = Object.defineProperty;
4680
4873
  var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
4681
4874
  var __publicField = (obj, key, value) => {
@@ -4687,7 +4880,7 @@ const _TelaSDK = class _TelaSDK extends BaseClient {
4687
4880
  /**
4688
4881
  * Creates a new instance of the TelaSDK.
4689
4882
  */
4690
- constructor({ baseURL = baseUrl, apiKey, jwt, dataToken, ...rest }) {
4883
+ constructor({ baseURL = baseUrl, apiKey, jwt, dataToken, agentBaseURL, vaultURL, ...rest }) {
4691
4884
  super({ baseURL, ...rest });
4692
4885
  __publicField(this, "opts");
4693
4886
  __publicField(this, "apiKey");
@@ -4762,6 +4955,22 @@ const _TelaSDK = class _TelaSDK extends BaseClient {
4762
4955
  * ```
4763
4956
  */
4764
4957
  __publicField(this, "vault", new Vault(this));
4958
+ /**
4959
+ * Agents API resource — a thin pass-through wrapper around
4960
+ * `@meistrari/agent-sdk`. Execute by `agentId`, then stream events, fetch the
4961
+ * timeline, or cancel by `sessionId`.
4962
+ *
4963
+ * @example
4964
+ * ```typescript
4965
+ * const { sessionId } = await tela.agents.executeAgent({
4966
+ * agentId: 'agent-id',
4967
+ * message: 'Hello',
4968
+ * })
4969
+ * for await (const event of await tela.agents.streamSession(sessionId))
4970
+ * console.log(event.kind)
4971
+ * ```
4972
+ */
4973
+ __publicField(this, "agents");
4765
4974
  __publicField(this, "workstation", {
4766
4975
  get: async (options) => {
4767
4976
  return Workstation.get({
@@ -4778,6 +4987,11 @@ const _TelaSDK = class _TelaSDK extends BaseClient {
4778
4987
  this.jwt = jwt;
4779
4988
  this.dataToken = dataToken;
4780
4989
  this.validateAuth();
4990
+ this.agents = new Agents(this, {
4991
+ agentBaseURL: agentBaseURL ?? baseURL,
4992
+ vaultURL: vaultURL ?? `${baseURL}/_services/vault`,
4993
+ authStrategy: createAuthStrategy({ apiKey, jwt, dataToken })
4994
+ });
4781
4995
  }
4782
4996
  get authToken() {
4783
4997
  return this.apiKey || this.jwt || this.dataToken;
@@ -4853,12 +5067,18 @@ __publicField(_TelaSDK, "ConflictApiKeyAndJWTError", ConflictApiKeyAndJWTError);
4853
5067
  __publicField(_TelaSDK, "ExecutionFailedError", ExecutionFailedError);
4854
5068
  /** Thrown when a workstation task fails on the server. */
4855
5069
  __publicField(_TelaSDK, "TaskFailedError", TaskFailedError);
5070
+ /** Thrown when an agent session fails on the server. */
5071
+ __publicField(_TelaSDK, "AgentExecutionFailedError", AgentExecutionFailedError);
4856
5072
  let TelaSDK = _TelaSDK;
4857
5073
  function createTelaClient(opts) {
4858
5074
  return new TelaSDK(opts);
4859
5075
  }
4860
5076
 
5077
+ exports.parseSessionStream = agentSdk.parseSessionStream;
5078
+ exports.verifyWebhookSignature = agentSdk.verifyWebhookSignature;
4861
5079
  exports.APIError = APIError;
5080
+ exports.AgentExecutionFailedError = AgentExecutionFailedError;
5081
+ exports.Agents = Agents;
4862
5082
  exports.AuthenticationError = AuthenticationError;
4863
5083
  exports.AuthorizationError = AuthorizationError;
4864
5084
  exports.BadRequestError = BadRequestError;