@meistrari/tela-sdk-js 2.11.0 → 2.13.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/README.md +92 -0
- package/dist/index.cjs +719 -146
- package/dist/index.d.cts +540 -1
- package/dist/index.d.mts +540 -1
- package/dist/index.d.ts +540 -1
- package/dist/index.mjs +716 -147
- package/package.json +2 -1
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.
|
|
27
|
+
const version = "2.13.0";
|
|
27
28
|
|
|
28
|
-
var __defProp$
|
|
29
|
-
var __defNormalProp$
|
|
30
|
-
var __publicField$
|
|
31
|
-
__defNormalProp$
|
|
29
|
+
var __defProp$c = Object.defineProperty;
|
|
30
|
+
var __defNormalProp$c = (obj, key, value) => key in obj ? __defProp$c(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
31
|
+
var __publicField$c = (obj, key, value) => {
|
|
32
|
+
__defNormalProp$c(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$
|
|
62
|
+
__publicField$c(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$
|
|
79
|
+
__publicField$c(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$
|
|
86
|
+
__publicField$c(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$
|
|
93
|
+
__publicField$c(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$c(this, "sessionId");
|
|
102
|
+
/** The server-provided error message, when available. */
|
|
103
|
+
__publicField$c(this, "error");
|
|
104
|
+
/** The full raw payload that triggered the failure. */
|
|
105
|
+
__publicField$c(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$
|
|
101
|
-
__publicField$
|
|
115
|
+
__publicField$c(this, "statusCode");
|
|
116
|
+
__publicField$c(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$
|
|
158
|
+
__publicField$c(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$
|
|
167
|
+
__publicField$c(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$
|
|
177
|
+
__publicField$c(this, "statusCode");
|
|
163
178
|
}
|
|
164
179
|
}
|
|
165
180
|
class BadRequestError extends APIError {
|
|
166
181
|
constructor() {
|
|
167
182
|
super(...arguments);
|
|
168
|
-
__publicField$
|
|
183
|
+
__publicField$c(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$
|
|
190
|
+
__publicField$c(this, "statusCode", 401);
|
|
176
191
|
}
|
|
177
192
|
}
|
|
178
193
|
class AuthorizationError extends APIError {
|
|
179
194
|
constructor() {
|
|
180
195
|
super(...arguments);
|
|
181
|
-
__publicField$
|
|
196
|
+
__publicField$c(this, "statusCode", 403);
|
|
182
197
|
}
|
|
183
198
|
}
|
|
184
199
|
class NotFoundError extends APIError {
|
|
185
200
|
constructor() {
|
|
186
201
|
super(...arguments);
|
|
187
|
-
__publicField$
|
|
202
|
+
__publicField$c(this, "statusCode", 404);
|
|
188
203
|
}
|
|
189
204
|
}
|
|
190
205
|
class ConflictError extends APIError {
|
|
191
206
|
constructor() {
|
|
192
207
|
super(...arguments);
|
|
193
|
-
__publicField$
|
|
208
|
+
__publicField$c(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$
|
|
215
|
+
__publicField$c(this, "statusCode", 422);
|
|
201
216
|
}
|
|
202
217
|
}
|
|
203
218
|
class RateLimitError extends APIError {
|
|
204
219
|
constructor() {
|
|
205
220
|
super(...arguments);
|
|
206
|
-
__publicField$
|
|
221
|
+
__publicField$c(this, "statusCode", 429);
|
|
207
222
|
}
|
|
208
223
|
}
|
|
209
224
|
class InternalServerError extends APIError {
|
|
210
225
|
constructor() {
|
|
211
226
|
super(...arguments);
|
|
212
|
-
__publicField$
|
|
227
|
+
__publicField$c(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$
|
|
499
|
-
var __defNormalProp$
|
|
500
|
-
var __publicField$
|
|
501
|
-
__defNormalProp$
|
|
513
|
+
var __defProp$b = Object.defineProperty;
|
|
514
|
+
var __defNormalProp$b = (obj, key, value) => key in obj ? __defProp$b(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
515
|
+
var __publicField$b = (obj, key, value) => {
|
|
516
|
+
__defNormalProp$b(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$
|
|
766
|
-
__publicField$
|
|
767
|
-
__publicField$
|
|
780
|
+
__publicField$b(this, "data");
|
|
781
|
+
__publicField$b(this, "event");
|
|
782
|
+
__publicField$b(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$
|
|
809
|
-
__publicField$
|
|
810
|
-
__publicField$
|
|
823
|
+
__publicField$b(this, "buffer");
|
|
824
|
+
__publicField$b(this, "trailingCR");
|
|
825
|
+
__publicField$b(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$
|
|
886
|
-
__publicField$
|
|
900
|
+
__publicField$b(_LineDecoder, "NEWLINE_CHARS", /* @__PURE__ */ new Set(["\n", "\r"]));
|
|
901
|
+
__publicField$b(_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$
|
|
924
|
-
var __defNormalProp$
|
|
925
|
-
var __publicField$
|
|
926
|
-
__defNormalProp$
|
|
938
|
+
var __defProp$a = Object.defineProperty;
|
|
939
|
+
var __defNormalProp$a = (obj, key, value) => key in obj ? __defProp$a(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
940
|
+
var __publicField$a = (obj, key, value) => {
|
|
941
|
+
__defNormalProp$a(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$
|
|
1003
|
-
__publicField$
|
|
1004
|
-
__publicField$
|
|
1005
|
-
__publicField$
|
|
1017
|
+
__publicField$a(this, "baseURL");
|
|
1018
|
+
__publicField$a(this, "maxRetries");
|
|
1019
|
+
__publicField$a(this, "timeout");
|
|
1020
|
+
__publicField$a(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$
|
|
1291
|
-
var __defNormalProp$
|
|
1292
|
-
var __publicField$
|
|
1293
|
-
__defNormalProp$
|
|
1335
|
+
var __defProp$9 = Object.defineProperty;
|
|
1336
|
+
var __defNormalProp$9 = (obj, key, value) => key in obj ? __defProp$9(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
1337
|
+
var __publicField$9 = (obj, key, value) => {
|
|
1338
|
+
__defNormalProp$9(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$
|
|
1302
|
-
__publicField$
|
|
1303
|
-
__publicField$
|
|
1304
|
-
__publicField$
|
|
1305
|
-
__publicField$
|
|
1346
|
+
__publicField$9(this, "_file");
|
|
1347
|
+
__publicField$9(this, "_options");
|
|
1348
|
+
__publicField$9(this, "_size", null);
|
|
1349
|
+
__publicField$9(this, "_mimeType");
|
|
1350
|
+
__publicField$9(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$
|
|
1785
|
-
var __defNormalProp$
|
|
1786
|
-
var __publicField$
|
|
1787
|
-
__defNormalProp$
|
|
1829
|
+
var __defProp$8 = Object.defineProperty;
|
|
1830
|
+
var __defNormalProp$8 = (obj, key, value) => key in obj ? __defProp$8(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
1831
|
+
var __publicField$8 = (obj, key, value) => {
|
|
1832
|
+
__defNormalProp$8(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$
|
|
1804
|
-
__publicField$
|
|
1805
|
-
__publicField$
|
|
1806
|
-
__publicField$
|
|
1848
|
+
__publicField$8(this, "_interval");
|
|
1849
|
+
__publicField$8(this, "_timeout");
|
|
1850
|
+
__publicField$8(this, "_abortSignal");
|
|
1851
|
+
__publicField$8(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$
|
|
1868
|
-
var __defNormalProp$
|
|
1869
|
-
var __publicField$
|
|
1870
|
-
__defNormalProp$
|
|
1912
|
+
var __defProp$7 = Object.defineProperty;
|
|
1913
|
+
var __defNormalProp$7 = (obj, key, value) => key in obj ? __defProp$7(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
1914
|
+
var __publicField$7 = (obj, key, value) => {
|
|
1915
|
+
__defNormalProp$7(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$
|
|
1927
|
-
__publicField$
|
|
1928
|
-
__publicField$
|
|
1929
|
-
__publicField$
|
|
1930
|
-
__publicField$
|
|
1931
|
-
__publicField$
|
|
1932
|
-
__publicField$
|
|
1933
|
-
__publicField$
|
|
1934
|
-
__publicField$
|
|
1935
|
-
__publicField$
|
|
1936
|
-
__publicField$
|
|
1937
|
-
__publicField$
|
|
1938
|
-
__publicField$
|
|
1939
|
-
__publicField$
|
|
1940
|
-
__publicField$
|
|
1971
|
+
__publicField$7(this, "_id");
|
|
1972
|
+
__publicField$7(this, "_status");
|
|
1973
|
+
__publicField$7(this, "_variables");
|
|
1974
|
+
__publicField$7(this, "_params");
|
|
1975
|
+
__publicField$7(this, "_client");
|
|
1976
|
+
__publicField$7(this, "_outputSchema");
|
|
1977
|
+
__publicField$7(this, "_skipResultValidation");
|
|
1978
|
+
__publicField$7(this, "_abortController");
|
|
1979
|
+
__publicField$7(this, "_isTask");
|
|
1980
|
+
__publicField$7(this, "_headers");
|
|
1981
|
+
__publicField$7(this, "_resultPromise");
|
|
1982
|
+
__publicField$7(this, "_stream");
|
|
1983
|
+
__publicField$7(this, "_rawResultValue");
|
|
1984
|
+
__publicField$7(this, "_requestId");
|
|
1985
|
+
__publicField$7(this, "_task");
|
|
1941
1986
|
this._variables = variables;
|
|
1942
1987
|
this._params = params;
|
|
1943
1988
|
this._outputSchema = outputSchema;
|
|
@@ -2568,12 +2613,46 @@ class CanvasExecution extends Emittery__default {
|
|
|
2568
2613
|
}
|
|
2569
2614
|
}
|
|
2570
2615
|
|
|
2571
|
-
var __defProp$
|
|
2572
|
-
var __defNormalProp$
|
|
2573
|
-
var __publicField$
|
|
2574
|
-
__defNormalProp$
|
|
2616
|
+
var __defProp$6 = Object.defineProperty;
|
|
2617
|
+
var __defNormalProp$6 = (obj, key, value) => key in obj ? __defProp$6(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
2618
|
+
var __publicField$6 = (obj, key, value) => {
|
|
2619
|
+
__defNormalProp$6(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
2575
2620
|
return value;
|
|
2576
2621
|
};
|
|
2622
|
+
function resolveBatchQueue(queue) {
|
|
2623
|
+
if (!queue) {
|
|
2624
|
+
return void 0;
|
|
2625
|
+
}
|
|
2626
|
+
const type = queue.type === void 0 ? "customer" : queue.type;
|
|
2627
|
+
if (type !== "internal" && type !== "customer") {
|
|
2628
|
+
throw new Error('Batch queue type must be either "internal" or "customer"');
|
|
2629
|
+
}
|
|
2630
|
+
if (typeof queue.application !== "string" || queue.application.trim().length === 0) {
|
|
2631
|
+
throw new Error("Batch queue application is required when queue is provided");
|
|
2632
|
+
}
|
|
2633
|
+
return {
|
|
2634
|
+
type,
|
|
2635
|
+
application: queue.application.trim()
|
|
2636
|
+
};
|
|
2637
|
+
}
|
|
2638
|
+
function createBatchRequestHeaders(params) {
|
|
2639
|
+
const headers = new Headers();
|
|
2640
|
+
let hasHeaders = false;
|
|
2641
|
+
const queue = resolveBatchQueue(params.queue);
|
|
2642
|
+
if (queue) {
|
|
2643
|
+
headers.set("x-batch-source", queue.type);
|
|
2644
|
+
headers.set("x-batch-source-application", queue.application);
|
|
2645
|
+
hasHeaders = true;
|
|
2646
|
+
}
|
|
2647
|
+
if (params.webhook?.headers) {
|
|
2648
|
+
for (const [key, value] of Object.entries(params.webhook.headers)) {
|
|
2649
|
+
const headerKey = key.toLowerCase().startsWith("x-tela-forward-") ? key : `x-tela-forward-${key}`;
|
|
2650
|
+
headers.set(headerKey, value);
|
|
2651
|
+
hasHeaders = true;
|
|
2652
|
+
}
|
|
2653
|
+
}
|
|
2654
|
+
return hasHeaders ? headers : void 0;
|
|
2655
|
+
}
|
|
2577
2656
|
const BatchResultItem = z__default.looseObject({
|
|
2578
2657
|
reference_id: z__default.string(),
|
|
2579
2658
|
status: z__default.string(),
|
|
@@ -2689,8 +2768,8 @@ class BatchExecutionResult {
|
|
|
2689
2768
|
* @internal
|
|
2690
2769
|
*/
|
|
2691
2770
|
constructor(client, response) {
|
|
2692
|
-
__publicField$
|
|
2693
|
-
__publicField$
|
|
2771
|
+
__publicField$6(this, "_client");
|
|
2772
|
+
__publicField$6(this, "_response");
|
|
2694
2773
|
this._client = client;
|
|
2695
2774
|
this._response = response;
|
|
2696
2775
|
}
|
|
@@ -2966,13 +3045,13 @@ class BatchExecution extends Emittery__default {
|
|
|
2966
3045
|
*/
|
|
2967
3046
|
constructor(id, client, params = {}, creationResponse) {
|
|
2968
3047
|
super();
|
|
2969
|
-
__publicField$
|
|
2970
|
-
__publicField$
|
|
2971
|
-
__publicField$
|
|
2972
|
-
__publicField$
|
|
2973
|
-
__publicField$
|
|
2974
|
-
__publicField$
|
|
2975
|
-
__publicField$
|
|
3048
|
+
__publicField$6(this, "_client");
|
|
3049
|
+
__publicField$6(this, "_id");
|
|
3050
|
+
__publicField$6(this, "_params");
|
|
3051
|
+
__publicField$6(this, "_abortController");
|
|
3052
|
+
__publicField$6(this, "_creationResponse");
|
|
3053
|
+
__publicField$6(this, "_status", "created");
|
|
3054
|
+
__publicField$6(this, "_resultPromise");
|
|
2976
3055
|
this._id = id;
|
|
2977
3056
|
this._client = client;
|
|
2978
3057
|
this._params = params;
|
|
@@ -3185,10 +3264,10 @@ class Batch {
|
|
|
3185
3264
|
* @internal
|
|
3186
3265
|
*/
|
|
3187
3266
|
constructor(client, canvasIdentifier, params = {}) {
|
|
3188
|
-
__publicField$
|
|
3189
|
-
__publicField$
|
|
3190
|
-
__publicField$
|
|
3191
|
-
__publicField$
|
|
3267
|
+
__publicField$6(this, "_client");
|
|
3268
|
+
__publicField$6(this, "_canvasIdentifier");
|
|
3269
|
+
__publicField$6(this, "_items", []);
|
|
3270
|
+
__publicField$6(this, "_params");
|
|
3192
3271
|
this._client = client;
|
|
3193
3272
|
this._canvasIdentifier = canvasIdentifier;
|
|
3194
3273
|
this._params = params;
|
|
@@ -3304,6 +3383,7 @@ class Batch {
|
|
|
3304
3383
|
const client = this._client;
|
|
3305
3384
|
const params = this._params;
|
|
3306
3385
|
async function execute() {
|
|
3386
|
+
const headers = createBatchRequestHeaders(params);
|
|
3307
3387
|
const { fileUrl } = await uploadFile(file, client);
|
|
3308
3388
|
const webhookUrl = params.webhook?.url ?? params.webhookUrl;
|
|
3309
3389
|
const body = {
|
|
@@ -3311,40 +3391,31 @@ class Batch {
|
|
|
3311
3391
|
inputFile: fileUrl,
|
|
3312
3392
|
webhookUrl
|
|
3313
3393
|
};
|
|
3314
|
-
const forwardHeaders = {};
|
|
3315
|
-
if (params.webhook?.headers) {
|
|
3316
|
-
for (const [key, value] of Object.entries(params.webhook.headers)) {
|
|
3317
|
-
const headerKey = key.toLowerCase().startsWith("x-tela-forward-") ? key : `x-tela-forward-${key}`;
|
|
3318
|
-
forwardHeaders[headerKey] = value;
|
|
3319
|
-
}
|
|
3320
|
-
}
|
|
3321
|
-
let headers;
|
|
3322
|
-
if (Object.keys(forwardHeaders).length > 0) {
|
|
3323
|
-
headers = new Headers();
|
|
3324
|
-
for (const [key, value] of Object.entries(forwardHeaders)) {
|
|
3325
|
-
headers.set(key, value);
|
|
3326
|
-
}
|
|
3327
|
-
}
|
|
3328
3394
|
return client.post("/_services/batch/batches", {
|
|
3329
3395
|
body,
|
|
3330
3396
|
...headers && { headers }
|
|
3331
3397
|
}).then((response) => new BatchExecution(response.id, client, params, response));
|
|
3332
3398
|
}
|
|
3399
|
+
let executionPromise;
|
|
3400
|
+
function getExecution() {
|
|
3401
|
+
executionPromise ?? (executionPromise = execute());
|
|
3402
|
+
return executionPromise;
|
|
3403
|
+
}
|
|
3333
3404
|
return {
|
|
3334
3405
|
then(onfulfilled, onrejected) {
|
|
3335
|
-
return
|
|
3406
|
+
return getExecution().then((execution) => onfulfilled?.(execution) ?? execution).catch(onrejected);
|
|
3336
3407
|
},
|
|
3337
3408
|
get result() {
|
|
3338
|
-
return
|
|
3409
|
+
return getExecution().then((execution) => execution.result);
|
|
3339
3410
|
}
|
|
3340
3411
|
};
|
|
3341
3412
|
}
|
|
3342
3413
|
}
|
|
3343
3414
|
|
|
3344
|
-
var __defProp$
|
|
3345
|
-
var __defNormalProp$
|
|
3346
|
-
var __publicField$
|
|
3347
|
-
__defNormalProp$
|
|
3415
|
+
var __defProp$5 = Object.defineProperty;
|
|
3416
|
+
var __defNormalProp$5 = (obj, key, value) => key in obj ? __defProp$5(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
3417
|
+
var __publicField$5 = (obj, key, value) => {
|
|
3418
|
+
__defNormalProp$5(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
3348
3419
|
return value;
|
|
3349
3420
|
};
|
|
3350
3421
|
function fetchById(id, client) {
|
|
@@ -3376,15 +3447,15 @@ class Canvas {
|
|
|
3376
3447
|
* @private
|
|
3377
3448
|
*/
|
|
3378
3449
|
constructor({ id, applicationId, name, versionId, input, output, client, variables, isWorkflow }) {
|
|
3379
|
-
__publicField$
|
|
3380
|
-
__publicField$
|
|
3381
|
-
__publicField$
|
|
3382
|
-
__publicField$
|
|
3383
|
-
__publicField$
|
|
3384
|
-
__publicField$
|
|
3385
|
-
__publicField$
|
|
3386
|
-
__publicField$
|
|
3387
|
-
__publicField$
|
|
3450
|
+
__publicField$5(this, "_id");
|
|
3451
|
+
__publicField$5(this, "_versionId");
|
|
3452
|
+
__publicField$5(this, "_applicationId");
|
|
3453
|
+
__publicField$5(this, "_name");
|
|
3454
|
+
__publicField$5(this, "_input");
|
|
3455
|
+
__publicField$5(this, "_output");
|
|
3456
|
+
__publicField$5(this, "_client");
|
|
3457
|
+
__publicField$5(this, "_variables");
|
|
3458
|
+
__publicField$5(this, "_isWorkflow");
|
|
3388
3459
|
this._id = id;
|
|
3389
3460
|
this._applicationId = applicationId;
|
|
3390
3461
|
this._name = name;
|
|
@@ -3641,24 +3712,24 @@ z.z.object({
|
|
|
3641
3712
|
requestId: z.z.string()
|
|
3642
3713
|
});
|
|
3643
3714
|
|
|
3644
|
-
var __defProp$
|
|
3645
|
-
var __defNormalProp$
|
|
3646
|
-
var __publicField$
|
|
3647
|
-
__defNormalProp$
|
|
3715
|
+
var __defProp$4 = Object.defineProperty;
|
|
3716
|
+
var __defNormalProp$4 = (obj, key, value) => key in obj ? __defProp$4(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
3717
|
+
var __publicField$4 = (obj, key, value) => {
|
|
3718
|
+
__defNormalProp$4(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
3648
3719
|
return value;
|
|
3649
3720
|
};
|
|
3650
3721
|
class Task extends Emittery__default {
|
|
3651
3722
|
constructor(client, variables, task, requestId, outputSchema, skipResultValidation = false) {
|
|
3652
3723
|
super();
|
|
3653
|
-
__publicField$
|
|
3654
|
-
__publicField$
|
|
3655
|
-
__publicField$
|
|
3656
|
-
__publicField$
|
|
3657
|
-
__publicField$
|
|
3658
|
-
__publicField$
|
|
3659
|
-
__publicField$
|
|
3660
|
-
__publicField$
|
|
3661
|
-
__publicField$
|
|
3724
|
+
__publicField$4(this, "_variables");
|
|
3725
|
+
__publicField$4(this, "_task");
|
|
3726
|
+
__publicField$4(this, "_abortController", new AbortController());
|
|
3727
|
+
__publicField$4(this, "_client");
|
|
3728
|
+
__publicField$4(this, "_outputSchema");
|
|
3729
|
+
__publicField$4(this, "_skipResultValidation");
|
|
3730
|
+
__publicField$4(this, "_resultPromise");
|
|
3731
|
+
__publicField$4(this, "_status");
|
|
3732
|
+
__publicField$4(this, "_requestId");
|
|
3662
3733
|
this._variables = variables;
|
|
3663
3734
|
this._task = task;
|
|
3664
3735
|
this._client = client;
|
|
@@ -3906,10 +3977,10 @@ class Task extends Emittery__default {
|
|
|
3906
3977
|
}
|
|
3907
3978
|
}
|
|
3908
3979
|
|
|
3909
|
-
var __defProp$
|
|
3910
|
-
var __defNormalProp$
|
|
3911
|
-
var __publicField$
|
|
3912
|
-
__defNormalProp$
|
|
3980
|
+
var __defProp$3 = Object.defineProperty;
|
|
3981
|
+
var __defNormalProp$3 = (obj, key, value) => key in obj ? __defProp$3(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
3982
|
+
var __publicField$3 = (obj, key, value) => {
|
|
3983
|
+
__defNormalProp$3(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
3913
3984
|
return value;
|
|
3914
3985
|
};
|
|
3915
3986
|
const DateRange = z__default.object({
|
|
@@ -3955,11 +4026,11 @@ class Workstation {
|
|
|
3955
4026
|
* @internal
|
|
3956
4027
|
*/
|
|
3957
4028
|
constructor({ client, applicationId, promptVersion, input, output }) {
|
|
3958
|
-
__publicField$
|
|
3959
|
-
__publicField$
|
|
3960
|
-
__publicField$
|
|
3961
|
-
__publicField$
|
|
3962
|
-
__publicField$
|
|
4029
|
+
__publicField$3(this, "_id");
|
|
4030
|
+
__publicField$3(this, "_promptVersion");
|
|
4031
|
+
__publicField$3(this, "_client");
|
|
4032
|
+
__publicField$3(this, "_input");
|
|
4033
|
+
__publicField$3(this, "_output");
|
|
3963
4034
|
this._id = applicationId;
|
|
3964
4035
|
this._promptVersion = promptVersion;
|
|
3965
4036
|
this._client = client;
|
|
@@ -4650,6 +4721,490 @@ class Vault {
|
|
|
4650
4721
|
}
|
|
4651
4722
|
}
|
|
4652
4723
|
|
|
4724
|
+
var __defProp$2 = Object.defineProperty;
|
|
4725
|
+
var __defNormalProp$2 = (obj, key, value) => key in obj ? __defProp$2(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
4726
|
+
var __publicField$2 = (obj, key, value) => {
|
|
4727
|
+
__defNormalProp$2(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
4728
|
+
return value;
|
|
4729
|
+
};
|
|
4730
|
+
const AGENT_NO_TRANSFORM$1 = { transformCase: false };
|
|
4731
|
+
const DEFAULT_MESSAGE = "Execute";
|
|
4732
|
+
const RECONNECT_DELAY_MS = 2e3;
|
|
4733
|
+
const MAX_STREAM_RECONNECT_ERRORS = 5;
|
|
4734
|
+
class AgentExecution extends Emittery__default {
|
|
4735
|
+
constructor(context) {
|
|
4736
|
+
super();
|
|
4737
|
+
__publicField$2(this, "_sessionId");
|
|
4738
|
+
__publicField$2(this, "_status");
|
|
4739
|
+
__publicField$2(this, "_cursor");
|
|
4740
|
+
__publicField$2(this, "_resultPromise");
|
|
4741
|
+
__publicField$2(this, "_stream");
|
|
4742
|
+
__publicField$2(this, "_abortController");
|
|
4743
|
+
__publicField$2(this, "_client");
|
|
4744
|
+
__publicField$2(this, "_agentId");
|
|
4745
|
+
__publicField$2(this, "_mode");
|
|
4746
|
+
__publicField$2(this, "_reconnectDelayMs");
|
|
4747
|
+
this._client = context.client;
|
|
4748
|
+
this._agentId = context.agentId;
|
|
4749
|
+
this._mode = context.mode ?? "run";
|
|
4750
|
+
this._sessionId = context.sessionId;
|
|
4751
|
+
this._reconnectDelayMs = context.reconnectDelayMs ?? RECONNECT_DELAY_MS;
|
|
4752
|
+
this._abortController = new AbortController();
|
|
4753
|
+
}
|
|
4754
|
+
/**
|
|
4755
|
+
* Builds a resumable execution bound to an existing session id.
|
|
4756
|
+
*
|
|
4757
|
+
* Used by `tela.agents.getSession()`. The returned execution can `.stream`,
|
|
4758
|
+
* `.result`, `.cancel`, or `.recover` — but not `.continue` (a new turn
|
|
4759
|
+
* needs the agent id).
|
|
4760
|
+
*/
|
|
4761
|
+
static fromSession(sessionId, client) {
|
|
4762
|
+
return new AgentExecution({ client, sessionId });
|
|
4763
|
+
}
|
|
4764
|
+
/**
|
|
4765
|
+
* The session id assigned by the server.
|
|
4766
|
+
*
|
|
4767
|
+
* @throws {ExecutionNotStartedError} If the execution has not started yet.
|
|
4768
|
+
*/
|
|
4769
|
+
get sessionId() {
|
|
4770
|
+
if (!this._sessionId)
|
|
4771
|
+
throw new ExecutionNotStartedError();
|
|
4772
|
+
return this._sessionId;
|
|
4773
|
+
}
|
|
4774
|
+
/**
|
|
4775
|
+
* The latest known session status.
|
|
4776
|
+
*
|
|
4777
|
+
* @throws {ExecutionNotStartedError} If no status has been observed yet.
|
|
4778
|
+
*/
|
|
4779
|
+
get status() {
|
|
4780
|
+
if (!this._status)
|
|
4781
|
+
throw new ExecutionNotStartedError();
|
|
4782
|
+
return this._status;
|
|
4783
|
+
}
|
|
4784
|
+
set status(status) {
|
|
4785
|
+
const changed = this._status !== status;
|
|
4786
|
+
this._status = status;
|
|
4787
|
+
if (changed)
|
|
4788
|
+
this.emit("status", status).catch(() => {
|
|
4789
|
+
});
|
|
4790
|
+
}
|
|
4791
|
+
/**
|
|
4792
|
+
* Starts (or continues) the session by POSTing to `/agent/:id/run`
|
|
4793
|
+
* (or `/agent/:id/test` in draft mode). Resets any in-flight stream/result
|
|
4794
|
+
* so the next read re-opens.
|
|
4795
|
+
*
|
|
4796
|
+
* @throws {AgentExecutionFailedError} If the server rejects the execution.
|
|
4797
|
+
*/
|
|
4798
|
+
async start(params) {
|
|
4799
|
+
if (!this._agentId)
|
|
4800
|
+
throw new InvalidExecutionModeError("agents: this execution is bound to an existing session \u2014 use recover() to resume it (a new turn requires the agent id).");
|
|
4801
|
+
this._abortController = new AbortController();
|
|
4802
|
+
const message = resolveMessage(params);
|
|
4803
|
+
const inputSchema = await this.resolveInputs(params.inputs);
|
|
4804
|
+
const attachments = await this.resolveAttachments(params.attachments);
|
|
4805
|
+
const body = {
|
|
4806
|
+
message,
|
|
4807
|
+
sessionId: this._sessionId,
|
|
4808
|
+
inputSchema,
|
|
4809
|
+
attachments,
|
|
4810
|
+
environmentVariables: params.environmentVariables
|
|
4811
|
+
};
|
|
4812
|
+
if (this._mode === "test") {
|
|
4813
|
+
body.ref = params.ref;
|
|
4814
|
+
body.isMultiturn = params.isMultiturn;
|
|
4815
|
+
}
|
|
4816
|
+
const envelope = await this._client.post(`/agent/${this._agentId}/${this._mode}`, {
|
|
4817
|
+
...AGENT_NO_TRANSFORM$1,
|
|
4818
|
+
body,
|
|
4819
|
+
signal: this._abortController.signal,
|
|
4820
|
+
headers: params.headers ? new Headers(params.headers) : void 0
|
|
4821
|
+
});
|
|
4822
|
+
const response = envelope.data;
|
|
4823
|
+
if (!response?.success || !response.sessionId)
|
|
4824
|
+
throw new AgentExecutionFailedError({ sessionId: response?.sessionId, error: response?.error });
|
|
4825
|
+
this._sessionId = response.sessionId;
|
|
4826
|
+
this._stream = void 0;
|
|
4827
|
+
this._resultPromise = void 0;
|
|
4828
|
+
this.status = "pending";
|
|
4829
|
+
return this;
|
|
4830
|
+
}
|
|
4831
|
+
/**
|
|
4832
|
+
* Continues this session with another turn (same `sessionId`).
|
|
4833
|
+
*
|
|
4834
|
+
* @returns A promise-like handle for the new turn (`.result` / `.stream`).
|
|
4835
|
+
*/
|
|
4836
|
+
continue(params) {
|
|
4837
|
+
return toExecutionPromise(this, params);
|
|
4838
|
+
}
|
|
4839
|
+
/**
|
|
4840
|
+
* Recovers a failed/terminal session (`POST /agent/sessions/:id/recover`),
|
|
4841
|
+
* then re-opens the stream from the current cursor.
|
|
4842
|
+
*
|
|
4843
|
+
* @throws {ExecutionNotStartedError} If there is no session to recover.
|
|
4844
|
+
* @throws {AgentExecutionFailedError} If recovery is rejected.
|
|
4845
|
+
*/
|
|
4846
|
+
async recover() {
|
|
4847
|
+
if (!this._sessionId)
|
|
4848
|
+
throw new ExecutionNotStartedError();
|
|
4849
|
+
this._abortController = new AbortController();
|
|
4850
|
+
const envelope = await this._client.post(`/agent/sessions/${this._sessionId}/recover`, {
|
|
4851
|
+
...AGENT_NO_TRANSFORM$1,
|
|
4852
|
+
signal: this._abortController.signal
|
|
4853
|
+
});
|
|
4854
|
+
const response = envelope.data;
|
|
4855
|
+
if (!response?.success || !response.sessionId)
|
|
4856
|
+
throw new AgentExecutionFailedError({ sessionId: response?.sessionId ?? this._sessionId, error: response?.error });
|
|
4857
|
+
this._sessionId = response.sessionId;
|
|
4858
|
+
this._stream = void 0;
|
|
4859
|
+
this._resultPromise = void 0;
|
|
4860
|
+
this.status = "pending";
|
|
4861
|
+
return this;
|
|
4862
|
+
}
|
|
4863
|
+
/**
|
|
4864
|
+
* A live, typed stream of session events. Memoized: repeated access returns
|
|
4865
|
+
* the same generator. Updates `status` and the resume cursor as it goes.
|
|
4866
|
+
*
|
|
4867
|
+
* @throws {ExecutionNotStartedError} If the session has no id yet.
|
|
4868
|
+
*/
|
|
4869
|
+
get stream() {
|
|
4870
|
+
if (!this._stream)
|
|
4871
|
+
this._stream = this.openStream();
|
|
4872
|
+
return this._stream;
|
|
4873
|
+
}
|
|
4874
|
+
async *openStream() {
|
|
4875
|
+
if (!this._sessionId)
|
|
4876
|
+
throw new ExecutionNotStartedError();
|
|
4877
|
+
let consecutiveErrors = 0;
|
|
4878
|
+
try {
|
|
4879
|
+
while (!this._abortController.signal.aborted) {
|
|
4880
|
+
try {
|
|
4881
|
+
const { response } = await this._client.requestRaw("GET", `/agent/sessions/${this._sessionId}`, {
|
|
4882
|
+
...AGENT_NO_TRANSFORM$1,
|
|
4883
|
+
query: this._cursor !== void 0 ? { cursor: this._cursor } : void 0,
|
|
4884
|
+
signal: this._abortController.signal,
|
|
4885
|
+
headers: new Headers({ Accept: "text/event-stream" })
|
|
4886
|
+
});
|
|
4887
|
+
if (!response.body)
|
|
4888
|
+
throw new Error("agent session stream response has no body");
|
|
4889
|
+
for await (const event of agentSdk.parseSessionStream(response.body)) {
|
|
4890
|
+
consecutiveErrors = 0;
|
|
4891
|
+
if ("status" in event)
|
|
4892
|
+
this.status = event.status;
|
|
4893
|
+
if ("nextCursor" in event && event.nextCursor != null)
|
|
4894
|
+
this._cursor = event.nextCursor;
|
|
4895
|
+
if (event.kind === "steps")
|
|
4896
|
+
this.emit("step", event.steps).catch(() => {
|
|
4897
|
+
});
|
|
4898
|
+
if (event.kind === "result")
|
|
4899
|
+
this.emit("result", event.result).catch(() => {
|
|
4900
|
+
});
|
|
4901
|
+
yield event;
|
|
4902
|
+
switch (event.kind) {
|
|
4903
|
+
case "error":
|
|
4904
|
+
throw this.fail(event.sessionId, event.error);
|
|
4905
|
+
case "result":
|
|
4906
|
+
return;
|
|
4907
|
+
case "status":
|
|
4908
|
+
case "steps":
|
|
4909
|
+
case "timeline-finalize":
|
|
4910
|
+
if (event.status === "failed")
|
|
4911
|
+
throw this.fail(event.sessionId, "error" in event ? event.error : void 0);
|
|
4912
|
+
if (event.status === "cancelled")
|
|
4913
|
+
return;
|
|
4914
|
+
break;
|
|
4915
|
+
}
|
|
4916
|
+
}
|
|
4917
|
+
} catch (error) {
|
|
4918
|
+
if (error instanceof AgentExecutionFailedError)
|
|
4919
|
+
throw error;
|
|
4920
|
+
if (this._abortController.signal.aborted)
|
|
4921
|
+
return;
|
|
4922
|
+
if (++consecutiveErrors > MAX_STREAM_RECONNECT_ERRORS)
|
|
4923
|
+
throw error;
|
|
4924
|
+
}
|
|
4925
|
+
if (this._abortController.signal.aborted)
|
|
4926
|
+
return;
|
|
4927
|
+
await delay(this._reconnectDelayMs, this._abortController.signal);
|
|
4928
|
+
}
|
|
4929
|
+
} finally {
|
|
4930
|
+
this._abortController.abort();
|
|
4931
|
+
}
|
|
4932
|
+
}
|
|
4933
|
+
fail(sessionId, error) {
|
|
4934
|
+
const failure = new AgentExecutionFailedError({ sessionId, error });
|
|
4935
|
+
this.status = "failed";
|
|
4936
|
+
this.emit("error", failure).catch(() => {
|
|
4937
|
+
});
|
|
4938
|
+
return failure;
|
|
4939
|
+
}
|
|
4940
|
+
/**
|
|
4941
|
+
* Resolves with the session's result payload, lazily consuming the stream.
|
|
4942
|
+
*
|
|
4943
|
+
* Memoized: repeated access returns the same promise. Resolves on the first
|
|
4944
|
+
* `result` event — for `completed` *or* `waiting_messages`. Inspect
|
|
4945
|
+
* `.status` to tell them apart, and `.continue()` from a paused turn.
|
|
4946
|
+
*
|
|
4947
|
+
* @throws {AgentExecutionFailedError} If the session fails or the stream
|
|
4948
|
+
* ends without producing a result.
|
|
4949
|
+
*/
|
|
4950
|
+
get result() {
|
|
4951
|
+
if (this._resultPromise)
|
|
4952
|
+
return this._resultPromise;
|
|
4953
|
+
this._resultPromise = (async () => {
|
|
4954
|
+
let lastResult;
|
|
4955
|
+
for await (const event of this.stream) {
|
|
4956
|
+
if (event.kind === "result")
|
|
4957
|
+
lastResult = event.result;
|
|
4958
|
+
}
|
|
4959
|
+
if (lastResult !== void 0)
|
|
4960
|
+
return lastResult;
|
|
4961
|
+
throw new AgentExecutionFailedError({
|
|
4962
|
+
sessionId: this._sessionId,
|
|
4963
|
+
error: "session stream ended without a result"
|
|
4964
|
+
});
|
|
4965
|
+
})();
|
|
4966
|
+
this._resultPromise.catch(() => {
|
|
4967
|
+
});
|
|
4968
|
+
return this._resultPromise;
|
|
4969
|
+
}
|
|
4970
|
+
/**
|
|
4971
|
+
* Cancels the session: aborts the open stream immediately, then requests a
|
|
4972
|
+
* server-side cancel (`POST /agent/sessions/:id/cancel`).
|
|
4973
|
+
*/
|
|
4974
|
+
async cancel() {
|
|
4975
|
+
this._abortController.abort();
|
|
4976
|
+
if (this._sessionId) {
|
|
4977
|
+
await this._client.post(`/agent/sessions/${this._sessionId}/cancel`, { ...AGENT_NO_TRANSFORM$1 }).catch(() => {
|
|
4978
|
+
});
|
|
4979
|
+
}
|
|
4980
|
+
}
|
|
4981
|
+
/**
|
|
4982
|
+
* Resolves the agent's input values into {@link AgentInputItem}s, uploading
|
|
4983
|
+
* any `TelaFile`s to the vault and passing strings through as text.
|
|
4984
|
+
*/
|
|
4985
|
+
async resolveInputs(inputs) {
|
|
4986
|
+
if (!inputs)
|
|
4987
|
+
return void 0;
|
|
4988
|
+
const entries = Object.entries(inputs);
|
|
4989
|
+
if (entries.length === 0)
|
|
4990
|
+
return void 0;
|
|
4991
|
+
return Promise.all(
|
|
4992
|
+
entries.map(async ([name, value]) => {
|
|
4993
|
+
if (isTelaFile(value)) {
|
|
4994
|
+
const { fileUrl } = await uploadFile(value, this._client);
|
|
4995
|
+
return { type: "file", name, vaultRef: fileUrl, filename: value.name ?? name };
|
|
4996
|
+
}
|
|
4997
|
+
return { type: "text", name, content: value };
|
|
4998
|
+
})
|
|
4999
|
+
);
|
|
5000
|
+
}
|
|
5001
|
+
/**
|
|
5002
|
+
* Resolves attachments to {@link AgentAttachment}s, uploading any `TelaFile`s.
|
|
5003
|
+
*/
|
|
5004
|
+
async resolveAttachments(attachments) {
|
|
5005
|
+
if (!attachments || attachments.length === 0)
|
|
5006
|
+
return void 0;
|
|
5007
|
+
return Promise.all(
|
|
5008
|
+
attachments.map(async (attachment) => {
|
|
5009
|
+
if (isTelaFile(attachment)) {
|
|
5010
|
+
const { fileUrl } = await uploadFile(attachment, this._client);
|
|
5011
|
+
return { vaultRef: fileUrl, filename: attachment.name ?? "file" };
|
|
5012
|
+
}
|
|
5013
|
+
return attachment;
|
|
5014
|
+
})
|
|
5015
|
+
);
|
|
5016
|
+
}
|
|
5017
|
+
}
|
|
5018
|
+
function resolveMessage(params) {
|
|
5019
|
+
if (params.prompt !== void 0 && params.message !== void 0)
|
|
5020
|
+
throw new InvalidExecutionModeError("agents.execute: provide either `prompt` or `message`, not both");
|
|
5021
|
+
return params.prompt ?? params.message ?? DEFAULT_MESSAGE;
|
|
5022
|
+
}
|
|
5023
|
+
function delay(ms, signal) {
|
|
5024
|
+
return new Promise((resolve) => {
|
|
5025
|
+
if (signal.aborted) {
|
|
5026
|
+
resolve();
|
|
5027
|
+
return;
|
|
5028
|
+
}
|
|
5029
|
+
const timeout = setTimeout(resolve, ms);
|
|
5030
|
+
signal.addEventListener("abort", () => {
|
|
5031
|
+
clearTimeout(timeout);
|
|
5032
|
+
resolve();
|
|
5033
|
+
}, { once: true });
|
|
5034
|
+
});
|
|
5035
|
+
}
|
|
5036
|
+
function toExecutionPromise(execution, params) {
|
|
5037
|
+
let started;
|
|
5038
|
+
let stream;
|
|
5039
|
+
const ensureStarted = () => started ?? (started = execution.start(params));
|
|
5040
|
+
async function* deferredStream() {
|
|
5041
|
+
await ensureStarted();
|
|
5042
|
+
yield* execution.stream;
|
|
5043
|
+
}
|
|
5044
|
+
return {
|
|
5045
|
+
then(onfulfilled, onrejected) {
|
|
5046
|
+
return ensureStarted().then(() => onfulfilled?.(execution) ?? execution).catch(onrejected);
|
|
5047
|
+
},
|
|
5048
|
+
get result() {
|
|
5049
|
+
return ensureStarted().then(() => execution.result);
|
|
5050
|
+
},
|
|
5051
|
+
get stream() {
|
|
5052
|
+
return stream ?? (stream = deferredStream());
|
|
5053
|
+
}
|
|
5054
|
+
};
|
|
5055
|
+
}
|
|
5056
|
+
|
|
5057
|
+
var __defProp$1 = Object.defineProperty;
|
|
5058
|
+
var __defNormalProp$1 = (obj, key, value) => key in obj ? __defProp$1(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
5059
|
+
var __publicField$1 = (obj, key, value) => {
|
|
5060
|
+
__defNormalProp$1(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
5061
|
+
return value;
|
|
5062
|
+
};
|
|
5063
|
+
class Agent {
|
|
5064
|
+
constructor(client, record) {
|
|
5065
|
+
__publicField$1(this, "_client");
|
|
5066
|
+
__publicField$1(this, "_record");
|
|
5067
|
+
this._client = client;
|
|
5068
|
+
this._record = record;
|
|
5069
|
+
}
|
|
5070
|
+
/** The agent id. */
|
|
5071
|
+
get id() {
|
|
5072
|
+
return this._record.id;
|
|
5073
|
+
}
|
|
5074
|
+
/** The agent's display title. */
|
|
5075
|
+
get title() {
|
|
5076
|
+
return this._record.title;
|
|
5077
|
+
}
|
|
5078
|
+
/** The organization that owns the agent's repository. */
|
|
5079
|
+
get organizationName() {
|
|
5080
|
+
return this._record.organizationName;
|
|
5081
|
+
}
|
|
5082
|
+
/** The agent's repository name. */
|
|
5083
|
+
get repository() {
|
|
5084
|
+
return this._record.repository;
|
|
5085
|
+
}
|
|
5086
|
+
/** The agent's declared input variables. */
|
|
5087
|
+
get inputSchema() {
|
|
5088
|
+
return this._record.inputSchema;
|
|
5089
|
+
}
|
|
5090
|
+
/** The published commit id, or `null` if the agent has never been published. */
|
|
5091
|
+
get publishedId() {
|
|
5092
|
+
return this._record.publishedId;
|
|
5093
|
+
}
|
|
5094
|
+
/** Whether the agent supports multi-turn sessions. */
|
|
5095
|
+
get isMultiturn() {
|
|
5096
|
+
return this._record.isMultiturn ?? false;
|
|
5097
|
+
}
|
|
5098
|
+
/** The full agent record as returned by the API. */
|
|
5099
|
+
get record() {
|
|
5100
|
+
return this._record;
|
|
5101
|
+
}
|
|
5102
|
+
/**
|
|
5103
|
+
* Executes the agent. By default this runs the **published** version
|
|
5104
|
+
* (`POST /agent/:id/run`); pass `{ draft: true }` to run the current draft
|
|
5105
|
+
* (`POST /agent/:id/test`).
|
|
5106
|
+
*
|
|
5107
|
+
* Returns a promise-like handle: `await` it for the {@link AgentExecution},
|
|
5108
|
+
* read `.result` for the final payload, or iterate `.stream` for live events.
|
|
5109
|
+
*
|
|
5110
|
+
* @param params - Execution parameters (notably `prompt`, `inputs`, `draft`).
|
|
5111
|
+
*/
|
|
5112
|
+
execute(params = {}) {
|
|
5113
|
+
const execution = new AgentExecution({
|
|
5114
|
+
client: this._client,
|
|
5115
|
+
agentId: this._record.id,
|
|
5116
|
+
mode: params.draft ? "test" : "run"
|
|
5117
|
+
});
|
|
5118
|
+
return toExecutionPromise(execution, params);
|
|
5119
|
+
}
|
|
5120
|
+
}
|
|
5121
|
+
|
|
5122
|
+
const AGENT_NO_TRANSFORM = { transformCase: false };
|
|
5123
|
+
class Agents {
|
|
5124
|
+
constructor(client) {
|
|
5125
|
+
this.client = client;
|
|
5126
|
+
}
|
|
5127
|
+
/**
|
|
5128
|
+
* Lists the agents available in the workspace (optionally filtered by project).
|
|
5129
|
+
*/
|
|
5130
|
+
async list(query = {}) {
|
|
5131
|
+
const response = await this.client.get("/agent", {
|
|
5132
|
+
...AGENT_NO_TRANSFORM,
|
|
5133
|
+
query
|
|
5134
|
+
});
|
|
5135
|
+
return response.data;
|
|
5136
|
+
}
|
|
5137
|
+
/**
|
|
5138
|
+
* Fetches an agent by id and returns a handle for running it.
|
|
5139
|
+
*/
|
|
5140
|
+
async get(agentId) {
|
|
5141
|
+
const response = await this.client.get(`/agent/${agentId}`, {
|
|
5142
|
+
...AGENT_NO_TRANSFORM
|
|
5143
|
+
});
|
|
5144
|
+
return new Agent(this.client, response.data);
|
|
5145
|
+
}
|
|
5146
|
+
/**
|
|
5147
|
+
* Executes an agent by id without first fetching its record.
|
|
5148
|
+
*
|
|
5149
|
+
* Convenience shortcut equivalent to `(await get(id)).execute(params)` but
|
|
5150
|
+
* skipping the metadata fetch. Defaults to the published version; pass
|
|
5151
|
+
* `{ draft: true }` to run the draft.
|
|
5152
|
+
*/
|
|
5153
|
+
execute(agentId, params = {}) {
|
|
5154
|
+
const execution = new AgentExecution({
|
|
5155
|
+
client: this.client,
|
|
5156
|
+
agentId,
|
|
5157
|
+
mode: params.draft ? "test" : "run"
|
|
5158
|
+
});
|
|
5159
|
+
return toExecutionPromise(execution, params);
|
|
5160
|
+
}
|
|
5161
|
+
/**
|
|
5162
|
+
* Returns a resumable execution bound to an existing session id. Use it to
|
|
5163
|
+
* monitor (`.stream` / `.result`), `.cancel()`, or `.recover()` a session
|
|
5164
|
+
* that was started elsewhere.
|
|
5165
|
+
*/
|
|
5166
|
+
async getSession(sessionId) {
|
|
5167
|
+
return AgentExecution.fromSession(sessionId, this.client);
|
|
5168
|
+
}
|
|
5169
|
+
/**
|
|
5170
|
+
* Fetches the session timeline summary (`GET /agent/sessions/:id/timeline`):
|
|
5171
|
+
* duration, token/cost metrics, prompt, and spans.
|
|
5172
|
+
*/
|
|
5173
|
+
async getTimeline(sessionId) {
|
|
5174
|
+
const response = await this.client.get(`/agent/sessions/${sessionId}/timeline`, {
|
|
5175
|
+
...AGENT_NO_TRANSFORM
|
|
5176
|
+
});
|
|
5177
|
+
return response.data;
|
|
5178
|
+
}
|
|
5179
|
+
/**
|
|
5180
|
+
* Cancels a running session (`POST /agent/sessions/:id/cancel`).
|
|
5181
|
+
*/
|
|
5182
|
+
async cancel(sessionId) {
|
|
5183
|
+
const response = await this.client.post(`/agent/sessions/${sessionId}/cancel`, {
|
|
5184
|
+
...AGENT_NO_TRANSFORM
|
|
5185
|
+
});
|
|
5186
|
+
return response?.data ?? {};
|
|
5187
|
+
}
|
|
5188
|
+
/**
|
|
5189
|
+
* Recovers a failed/terminal session and returns a resumable execution for
|
|
5190
|
+
* the new turn.
|
|
5191
|
+
*/
|
|
5192
|
+
async recover(sessionId) {
|
|
5193
|
+
const execution = AgentExecution.fromSession(sessionId, this.client);
|
|
5194
|
+
await execution.recover();
|
|
5195
|
+
return execution;
|
|
5196
|
+
}
|
|
5197
|
+
/**
|
|
5198
|
+
* Ends a session (`DELETE /agent/sessions/:id`), marking it finished.
|
|
5199
|
+
*/
|
|
5200
|
+
async endSession(sessionId) {
|
|
5201
|
+
const response = await this.client.delete(`/agent/sessions/${sessionId}`, {
|
|
5202
|
+
...AGENT_NO_TRANSFORM
|
|
5203
|
+
});
|
|
5204
|
+
return response?.data ?? {};
|
|
5205
|
+
}
|
|
5206
|
+
}
|
|
5207
|
+
|
|
4653
5208
|
var __defProp = Object.defineProperty;
|
|
4654
5209
|
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
4655
5210
|
var __publicField = (obj, key, value) => {
|
|
@@ -4736,6 +5291,17 @@ const _TelaSDK = class _TelaSDK extends BaseClient {
|
|
|
4736
5291
|
* ```
|
|
4737
5292
|
*/
|
|
4738
5293
|
__publicField(this, "vault", new Vault(this));
|
|
5294
|
+
/**
|
|
5295
|
+
* Agents API resource for running agent sessions by `agentId` — execute,
|
|
5296
|
+
* stream events, multi-turn, cancel — and reading session state.
|
|
5297
|
+
*
|
|
5298
|
+
* @example
|
|
5299
|
+
* ```typescript
|
|
5300
|
+
* const agent = await tela.agents.get('agent-id')
|
|
5301
|
+
* const result = await agent.execute({ prompt: 'Hello' }).result
|
|
5302
|
+
* ```
|
|
5303
|
+
*/
|
|
5304
|
+
__publicField(this, "agents");
|
|
4739
5305
|
__publicField(this, "workstation", {
|
|
4740
5306
|
get: async (options) => {
|
|
4741
5307
|
return Workstation.get({
|
|
@@ -4751,6 +5317,7 @@ const _TelaSDK = class _TelaSDK extends BaseClient {
|
|
|
4751
5317
|
this.apiKey = apiKey;
|
|
4752
5318
|
this.jwt = jwt;
|
|
4753
5319
|
this.dataToken = dataToken;
|
|
5320
|
+
this.agents = new Agents(this);
|
|
4754
5321
|
this.validateAuth();
|
|
4755
5322
|
}
|
|
4756
5323
|
get authToken() {
|
|
@@ -4827,12 +5394,18 @@ __publicField(_TelaSDK, "ConflictApiKeyAndJWTError", ConflictApiKeyAndJWTError);
|
|
|
4827
5394
|
__publicField(_TelaSDK, "ExecutionFailedError", ExecutionFailedError);
|
|
4828
5395
|
/** Thrown when a workstation task fails on the server. */
|
|
4829
5396
|
__publicField(_TelaSDK, "TaskFailedError", TaskFailedError);
|
|
5397
|
+
/** Thrown when an agent session fails on the server. */
|
|
5398
|
+
__publicField(_TelaSDK, "AgentExecutionFailedError", AgentExecutionFailedError);
|
|
4830
5399
|
let TelaSDK = _TelaSDK;
|
|
4831
5400
|
function createTelaClient(opts) {
|
|
4832
5401
|
return new TelaSDK(opts);
|
|
4833
5402
|
}
|
|
4834
5403
|
|
|
4835
5404
|
exports.APIError = APIError;
|
|
5405
|
+
exports.Agent = Agent;
|
|
5406
|
+
exports.AgentExecution = AgentExecution;
|
|
5407
|
+
exports.AgentExecutionFailedError = AgentExecutionFailedError;
|
|
5408
|
+
exports.Agents = Agents;
|
|
4836
5409
|
exports.AuthenticationError = AuthenticationError;
|
|
4837
5410
|
exports.AuthorizationError = AuthorizationError;
|
|
4838
5411
|
exports.BadRequestError = BadRequestError;
|