@meistrari/tela-sdk-js 2.13.0 → 2.13.2
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 +65 -42
- package/dist/index.cjs +275 -583
- package/dist/index.d.cts +221 -360
- package/dist/index.d.mts +221 -360
- package/dist/index.d.ts +221 -360
- package/dist/index.mjs +276 -583
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -24,12 +24,12 @@ const changeCase__namespace = /*#__PURE__*/_interopNamespaceCompat(changeCase);
|
|
|
24
24
|
const z__default = /*#__PURE__*/_interopDefaultCompat(z);
|
|
25
25
|
const Emittery__default = /*#__PURE__*/_interopDefaultCompat(Emittery);
|
|
26
26
|
|
|
27
|
-
const version = "2.13.
|
|
27
|
+
const version = "2.13.2";
|
|
28
28
|
|
|
29
|
-
var __defProp$
|
|
30
|
-
var __defNormalProp$
|
|
31
|
-
var __publicField$
|
|
32
|
-
__defNormalProp$
|
|
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);
|
|
33
33
|
return value;
|
|
34
34
|
};
|
|
35
35
|
class TelaError extends Error {
|
|
@@ -59,7 +59,7 @@ class InvalidFileURL extends TelaError {
|
|
|
59
59
|
class FileUploadError extends TelaError {
|
|
60
60
|
constructor(message, statusCode) {
|
|
61
61
|
super(`Failed to upload file: ${message} (Status code: ${statusCode})`);
|
|
62
|
-
__publicField$
|
|
62
|
+
__publicField$b(this, "statusCode");
|
|
63
63
|
this.statusCode = statusCode;
|
|
64
64
|
}
|
|
65
65
|
}
|
|
@@ -76,21 +76,21 @@ class InvalidExecutionModeError extends TelaError {
|
|
|
76
76
|
class ExecutionFailedError extends TelaError {
|
|
77
77
|
constructor(rawOutput) {
|
|
78
78
|
super(`Execution failed: ${JSON.stringify(rawOutput)}`);
|
|
79
|
-
__publicField$
|
|
79
|
+
__publicField$b(this, "rawOutput");
|
|
80
80
|
this.rawOutput = rawOutput;
|
|
81
81
|
}
|
|
82
82
|
}
|
|
83
83
|
class TaskFailedError extends TelaError {
|
|
84
84
|
constructor(rawTask, message, cause) {
|
|
85
85
|
super(`Task failed: ${JSON.stringify(rawTask)}`, { cause });
|
|
86
|
-
__publicField$
|
|
86
|
+
__publicField$b(this, "rawTask");
|
|
87
87
|
this.rawTask = rawTask;
|
|
88
88
|
}
|
|
89
89
|
}
|
|
90
90
|
class BatchExecutionFailedError extends TelaError {
|
|
91
91
|
constructor(rawResponse) {
|
|
92
92
|
super(`Batch execution failed: ${JSON.stringify(rawResponse)}`);
|
|
93
|
-
__publicField$
|
|
93
|
+
__publicField$b(this, "rawResponse");
|
|
94
94
|
this.rawResponse = rawResponse;
|
|
95
95
|
}
|
|
96
96
|
}
|
|
@@ -98,11 +98,11 @@ class AgentExecutionFailedError extends TelaError {
|
|
|
98
98
|
constructor(payload) {
|
|
99
99
|
super(`Agent execution failed${payload.sessionId ? ` (session ${payload.sessionId})` : ""}: ${payload.error ?? "unknown error"}`);
|
|
100
100
|
/** The session id, when known. */
|
|
101
|
-
__publicField$
|
|
101
|
+
__publicField$b(this, "sessionId");
|
|
102
102
|
/** The server-provided error message, when available. */
|
|
103
|
-
__publicField$
|
|
103
|
+
__publicField$b(this, "error");
|
|
104
104
|
/** The full raw payload that triggered the failure. */
|
|
105
|
-
__publicField$
|
|
105
|
+
__publicField$b(this, "raw");
|
|
106
106
|
this.sessionId = payload.sessionId;
|
|
107
107
|
this.error = payload.error;
|
|
108
108
|
this.raw = payload;
|
|
@@ -112,8 +112,8 @@ class APIError extends TelaError {
|
|
|
112
112
|
constructor(statusCode, error, _message) {
|
|
113
113
|
const message = error?.message ? typeof error.message === "string" ? error.message : JSON.stringify(error.message) : error ? JSON.stringify(error) : _message;
|
|
114
114
|
super(message);
|
|
115
|
-
__publicField$
|
|
116
|
-
__publicField$
|
|
115
|
+
__publicField$b(this, "statusCode");
|
|
116
|
+
__publicField$b(this, "error");
|
|
117
117
|
this.statusCode = statusCode;
|
|
118
118
|
this.error = error;
|
|
119
119
|
}
|
|
@@ -155,7 +155,7 @@ class APIError extends TelaError {
|
|
|
155
155
|
class UserAbortError extends APIError {
|
|
156
156
|
constructor({ message } = {}) {
|
|
157
157
|
super(void 0, void 0, message || "User aborted.");
|
|
158
|
-
__publicField$
|
|
158
|
+
__publicField$b(this, "statusCode");
|
|
159
159
|
}
|
|
160
160
|
}
|
|
161
161
|
class ConnectionError extends APIError {
|
|
@@ -164,7 +164,7 @@ class ConnectionError extends APIError {
|
|
|
164
164
|
cause
|
|
165
165
|
}) {
|
|
166
166
|
super(void 0, void 0, message || "Connection error.");
|
|
167
|
-
__publicField$
|
|
167
|
+
__publicField$b(this, "statusCode");
|
|
168
168
|
if (cause)
|
|
169
169
|
this.cause = cause;
|
|
170
170
|
}
|
|
@@ -174,57 +174,57 @@ class ConnectionTimeout extends APIError {
|
|
|
174
174
|
message
|
|
175
175
|
} = {}) {
|
|
176
176
|
super(void 0, void 0, message || "Request timed out.");
|
|
177
|
-
__publicField$
|
|
177
|
+
__publicField$b(this, "statusCode");
|
|
178
178
|
}
|
|
179
179
|
}
|
|
180
180
|
class BadRequestError extends APIError {
|
|
181
181
|
constructor() {
|
|
182
182
|
super(...arguments);
|
|
183
|
-
__publicField$
|
|
183
|
+
__publicField$b(this, "statusCode", 400);
|
|
184
184
|
}
|
|
185
185
|
// todo: handle validation errors from zod/typebox
|
|
186
186
|
}
|
|
187
187
|
class AuthenticationError extends APIError {
|
|
188
188
|
constructor() {
|
|
189
189
|
super(...arguments);
|
|
190
|
-
__publicField$
|
|
190
|
+
__publicField$b(this, "statusCode", 401);
|
|
191
191
|
}
|
|
192
192
|
}
|
|
193
193
|
class AuthorizationError extends APIError {
|
|
194
194
|
constructor() {
|
|
195
195
|
super(...arguments);
|
|
196
|
-
__publicField$
|
|
196
|
+
__publicField$b(this, "statusCode", 403);
|
|
197
197
|
}
|
|
198
198
|
}
|
|
199
199
|
class NotFoundError extends APIError {
|
|
200
200
|
constructor() {
|
|
201
201
|
super(...arguments);
|
|
202
|
-
__publicField$
|
|
202
|
+
__publicField$b(this, "statusCode", 404);
|
|
203
203
|
}
|
|
204
204
|
}
|
|
205
205
|
class ConflictError extends APIError {
|
|
206
206
|
constructor() {
|
|
207
207
|
super(...arguments);
|
|
208
|
-
__publicField$
|
|
208
|
+
__publicField$b(this, "statusCode", 409);
|
|
209
209
|
}
|
|
210
210
|
}
|
|
211
211
|
class UnprocessableEntityError extends APIError {
|
|
212
212
|
constructor() {
|
|
213
213
|
super(...arguments);
|
|
214
214
|
// todo: check if tela returns 400 or 422 for zod errors
|
|
215
|
-
__publicField$
|
|
215
|
+
__publicField$b(this, "statusCode", 422);
|
|
216
216
|
}
|
|
217
217
|
}
|
|
218
218
|
class RateLimitError extends APIError {
|
|
219
219
|
constructor() {
|
|
220
220
|
super(...arguments);
|
|
221
|
-
__publicField$
|
|
221
|
+
__publicField$b(this, "statusCode", 429);
|
|
222
222
|
}
|
|
223
223
|
}
|
|
224
224
|
class InternalServerError extends APIError {
|
|
225
225
|
constructor() {
|
|
226
226
|
super(...arguments);
|
|
227
|
-
__publicField$
|
|
227
|
+
__publicField$b(this, "statusCode", 500);
|
|
228
228
|
}
|
|
229
229
|
}
|
|
230
230
|
function toError(err) {
|
|
@@ -510,10 +510,10 @@ function transformDurationToMs(durationStr) {
|
|
|
510
510
|
return Number.parseInt(amount) * multiplier;
|
|
511
511
|
}
|
|
512
512
|
|
|
513
|
-
var __defProp$
|
|
514
|
-
var __defNormalProp$
|
|
515
|
-
var __publicField$
|
|
516
|
-
__defNormalProp$
|
|
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);
|
|
517
517
|
return value;
|
|
518
518
|
};
|
|
519
519
|
class Stream {
|
|
@@ -777,9 +777,9 @@ function findDoubleNewlineIndex(buffer) {
|
|
|
777
777
|
}
|
|
778
778
|
class SSEDecoder {
|
|
779
779
|
constructor() {
|
|
780
|
-
__publicField$
|
|
781
|
-
__publicField$
|
|
782
|
-
__publicField$
|
|
780
|
+
__publicField$a(this, "data");
|
|
781
|
+
__publicField$a(this, "event");
|
|
782
|
+
__publicField$a(this, "chunks");
|
|
783
783
|
this.event = null;
|
|
784
784
|
this.data = [];
|
|
785
785
|
this.chunks = [];
|
|
@@ -820,9 +820,9 @@ class SSEDecoder {
|
|
|
820
820
|
const _LineDecoder = class _LineDecoder {
|
|
821
821
|
// TextDecoder found in browsers; not typed to avoid pulling in either "dom" or "node" types.
|
|
822
822
|
constructor() {
|
|
823
|
-
__publicField$
|
|
824
|
-
__publicField$
|
|
825
|
-
__publicField$
|
|
823
|
+
__publicField$a(this, "buffer");
|
|
824
|
+
__publicField$a(this, "trailingCR");
|
|
825
|
+
__publicField$a(this, "textDecoder");
|
|
826
826
|
this.buffer = [];
|
|
827
827
|
this.trailingCR = false;
|
|
828
828
|
}
|
|
@@ -897,8 +897,8 @@ const _LineDecoder = class _LineDecoder {
|
|
|
897
897
|
}
|
|
898
898
|
};
|
|
899
899
|
// prettier-ignore
|
|
900
|
-
__publicField$
|
|
901
|
-
__publicField$
|
|
900
|
+
__publicField$a(_LineDecoder, "NEWLINE_CHARS", /* @__PURE__ */ new Set(["\n", "\r"]));
|
|
901
|
+
__publicField$a(_LineDecoder, "NEWLINE_REGEXP", /\r\n|[\n\r]/g);
|
|
902
902
|
let LineDecoder = _LineDecoder;
|
|
903
903
|
function partition(str, delimiter) {
|
|
904
904
|
const index = str.indexOf(delimiter);
|
|
@@ -935,10 +935,10 @@ function readableStreamAsyncIterable(stream) {
|
|
|
935
935
|
};
|
|
936
936
|
}
|
|
937
937
|
|
|
938
|
-
var __defProp$
|
|
939
|
-
var __defNormalProp$
|
|
940
|
-
var __publicField$
|
|
941
|
-
__defNormalProp$
|
|
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);
|
|
942
942
|
return value;
|
|
943
943
|
};
|
|
944
944
|
function getRequestIdFromResponse(response) {
|
|
@@ -1014,10 +1014,10 @@ function transformObjectCase(obj, transformCase) {
|
|
|
1014
1014
|
}
|
|
1015
1015
|
class BaseClient {
|
|
1016
1016
|
constructor({ baseURL, maxRetries = 5, timeout = 0 }) {
|
|
1017
|
-
__publicField$
|
|
1018
|
-
__publicField$
|
|
1019
|
-
__publicField$
|
|
1020
|
-
__publicField$
|
|
1017
|
+
__publicField$9(this, "baseURL");
|
|
1018
|
+
__publicField$9(this, "maxRetries");
|
|
1019
|
+
__publicField$9(this, "timeout");
|
|
1020
|
+
__publicField$9(this, "fetch");
|
|
1021
1021
|
this.baseURL = baseURL;
|
|
1022
1022
|
this.maxRetries = validateMaxRetries(maxRetries);
|
|
1023
1023
|
this.timeout = validateTimeout(timeout);
|
|
@@ -1332,10 +1332,10 @@ async function getStreamSize(stream) {
|
|
|
1332
1332
|
return size;
|
|
1333
1333
|
}
|
|
1334
1334
|
|
|
1335
|
-
var __defProp$
|
|
1336
|
-
var __defNormalProp$
|
|
1337
|
-
var __publicField$
|
|
1338
|
-
__defNormalProp$
|
|
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);
|
|
1339
1339
|
return value;
|
|
1340
1340
|
};
|
|
1341
1341
|
function TelaFileSchema() {
|
|
@@ -1343,11 +1343,11 @@ function TelaFileSchema() {
|
|
|
1343
1343
|
}
|
|
1344
1344
|
class TelaFile {
|
|
1345
1345
|
constructor(file, options = {}) {
|
|
1346
|
-
__publicField$
|
|
1347
|
-
__publicField$
|
|
1348
|
-
__publicField$
|
|
1349
|
-
__publicField$
|
|
1350
|
-
__publicField$
|
|
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");
|
|
1351
1351
|
this._file = file;
|
|
1352
1352
|
if (file instanceof File || file instanceof Blob) {
|
|
1353
1353
|
this._size = file.size;
|
|
@@ -1826,10 +1826,10 @@ async function streamFile(vaultReference, client) {
|
|
|
1826
1826
|
});
|
|
1827
1827
|
}
|
|
1828
1828
|
|
|
1829
|
-
var __defProp$
|
|
1830
|
-
var __defNormalProp$
|
|
1831
|
-
var __publicField$
|
|
1832
|
-
__defNormalProp$
|
|
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);
|
|
1833
1833
|
return value;
|
|
1834
1834
|
};
|
|
1835
1835
|
function timeout(ms, signal) {
|
|
@@ -1845,10 +1845,10 @@ function timeout(ms, signal) {
|
|
|
1845
1845
|
}
|
|
1846
1846
|
class Poller {
|
|
1847
1847
|
constructor({ interval, timeout: timeout2, abortSignal }) {
|
|
1848
|
-
__publicField$
|
|
1849
|
-
__publicField$
|
|
1850
|
-
__publicField$
|
|
1851
|
-
__publicField$
|
|
1848
|
+
__publicField$7(this, "_interval");
|
|
1849
|
+
__publicField$7(this, "_timeout");
|
|
1850
|
+
__publicField$7(this, "_abortSignal");
|
|
1851
|
+
__publicField$7(this, "_internalAbortController");
|
|
1852
1852
|
if (interval <= 0) {
|
|
1853
1853
|
throw new TelaError("Interval must be greater than 0");
|
|
1854
1854
|
}
|
|
@@ -1909,10 +1909,10 @@ class Poller {
|
|
|
1909
1909
|
}
|
|
1910
1910
|
}
|
|
1911
1911
|
|
|
1912
|
-
var __defProp$
|
|
1913
|
-
var __defNormalProp$
|
|
1914
|
-
var __publicField$
|
|
1915
|
-
__defNormalProp$
|
|
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);
|
|
1916
1916
|
return value;
|
|
1917
1917
|
};
|
|
1918
1918
|
function isUUID(str) {
|
|
@@ -1968,21 +1968,21 @@ class CanvasExecution extends Emittery__default {
|
|
|
1968
1968
|
*/
|
|
1969
1969
|
constructor(variables, params = { async: false }, outputSchema, client, isTask = false) {
|
|
1970
1970
|
super();
|
|
1971
|
-
__publicField$
|
|
1972
|
-
__publicField$
|
|
1973
|
-
__publicField$
|
|
1974
|
-
__publicField$
|
|
1975
|
-
__publicField$
|
|
1976
|
-
__publicField$
|
|
1977
|
-
__publicField$
|
|
1978
|
-
__publicField$
|
|
1979
|
-
__publicField$
|
|
1980
|
-
__publicField$
|
|
1981
|
-
__publicField$
|
|
1982
|
-
__publicField$
|
|
1983
|
-
__publicField$
|
|
1984
|
-
__publicField$
|
|
1985
|
-
__publicField$
|
|
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");
|
|
1986
1986
|
this._variables = variables;
|
|
1987
1987
|
this._params = params;
|
|
1988
1988
|
this._outputSchema = outputSchema;
|
|
@@ -2613,10 +2613,10 @@ class CanvasExecution extends Emittery__default {
|
|
|
2613
2613
|
}
|
|
2614
2614
|
}
|
|
2615
2615
|
|
|
2616
|
-
var __defProp$
|
|
2617
|
-
var __defNormalProp$
|
|
2618
|
-
var __publicField$
|
|
2619
|
-
__defNormalProp$
|
|
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);
|
|
2620
2620
|
return value;
|
|
2621
2621
|
};
|
|
2622
2622
|
function resolveBatchQueue(queue) {
|
|
@@ -2768,8 +2768,8 @@ class BatchExecutionResult {
|
|
|
2768
2768
|
* @internal
|
|
2769
2769
|
*/
|
|
2770
2770
|
constructor(client, response) {
|
|
2771
|
-
__publicField$
|
|
2772
|
-
__publicField$
|
|
2771
|
+
__publicField$5(this, "_client");
|
|
2772
|
+
__publicField$5(this, "_response");
|
|
2773
2773
|
this._client = client;
|
|
2774
2774
|
this._response = response;
|
|
2775
2775
|
}
|
|
@@ -3045,13 +3045,13 @@ class BatchExecution extends Emittery__default {
|
|
|
3045
3045
|
*/
|
|
3046
3046
|
constructor(id, client, params = {}, creationResponse) {
|
|
3047
3047
|
super();
|
|
3048
|
-
__publicField$
|
|
3049
|
-
__publicField$
|
|
3050
|
-
__publicField$
|
|
3051
|
-
__publicField$
|
|
3052
|
-
__publicField$
|
|
3053
|
-
__publicField$
|
|
3054
|
-
__publicField$
|
|
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");
|
|
3055
3055
|
this._id = id;
|
|
3056
3056
|
this._client = client;
|
|
3057
3057
|
this._params = params;
|
|
@@ -3264,10 +3264,10 @@ class Batch {
|
|
|
3264
3264
|
* @internal
|
|
3265
3265
|
*/
|
|
3266
3266
|
constructor(client, canvasIdentifier, params = {}) {
|
|
3267
|
-
__publicField$
|
|
3268
|
-
__publicField$
|
|
3269
|
-
__publicField$
|
|
3270
|
-
__publicField$
|
|
3267
|
+
__publicField$5(this, "_client");
|
|
3268
|
+
__publicField$5(this, "_canvasIdentifier");
|
|
3269
|
+
__publicField$5(this, "_items", []);
|
|
3270
|
+
__publicField$5(this, "_params");
|
|
3271
3271
|
this._client = client;
|
|
3272
3272
|
this._canvasIdentifier = canvasIdentifier;
|
|
3273
3273
|
this._params = params;
|
|
@@ -3412,10 +3412,10 @@ class Batch {
|
|
|
3412
3412
|
}
|
|
3413
3413
|
}
|
|
3414
3414
|
|
|
3415
|
-
var __defProp$
|
|
3416
|
-
var __defNormalProp$
|
|
3417
|
-
var __publicField$
|
|
3418
|
-
__defNormalProp$
|
|
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);
|
|
3419
3419
|
return value;
|
|
3420
3420
|
};
|
|
3421
3421
|
function fetchById(id, client) {
|
|
@@ -3447,15 +3447,15 @@ class Canvas {
|
|
|
3447
3447
|
* @private
|
|
3448
3448
|
*/
|
|
3449
3449
|
constructor({ id, applicationId, name, versionId, input, output, client, variables, isWorkflow }) {
|
|
3450
|
-
__publicField$
|
|
3451
|
-
__publicField$
|
|
3452
|
-
__publicField$
|
|
3453
|
-
__publicField$
|
|
3454
|
-
__publicField$
|
|
3455
|
-
__publicField$
|
|
3456
|
-
__publicField$
|
|
3457
|
-
__publicField$
|
|
3458
|
-
__publicField$
|
|
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");
|
|
3459
3459
|
this._id = id;
|
|
3460
3460
|
this._applicationId = applicationId;
|
|
3461
3461
|
this._name = name;
|
|
@@ -3712,24 +3712,24 @@ z.z.object({
|
|
|
3712
3712
|
requestId: z.z.string()
|
|
3713
3713
|
});
|
|
3714
3714
|
|
|
3715
|
-
var __defProp$
|
|
3716
|
-
var __defNormalProp$
|
|
3717
|
-
var __publicField$
|
|
3718
|
-
__defNormalProp$
|
|
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);
|
|
3719
3719
|
return value;
|
|
3720
3720
|
};
|
|
3721
3721
|
class Task extends Emittery__default {
|
|
3722
3722
|
constructor(client, variables, task, requestId, outputSchema, skipResultValidation = false) {
|
|
3723
3723
|
super();
|
|
3724
|
-
__publicField$
|
|
3725
|
-
__publicField$
|
|
3726
|
-
__publicField$
|
|
3727
|
-
__publicField$
|
|
3728
|
-
__publicField$
|
|
3729
|
-
__publicField$
|
|
3730
|
-
__publicField$
|
|
3731
|
-
__publicField$
|
|
3732
|
-
__publicField$
|
|
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");
|
|
3733
3733
|
this._variables = variables;
|
|
3734
3734
|
this._task = task;
|
|
3735
3735
|
this._client = client;
|
|
@@ -3977,10 +3977,10 @@ class Task extends Emittery__default {
|
|
|
3977
3977
|
}
|
|
3978
3978
|
}
|
|
3979
3979
|
|
|
3980
|
-
var __defProp$
|
|
3981
|
-
var __defNormalProp$
|
|
3982
|
-
var __publicField$
|
|
3983
|
-
__defNormalProp$
|
|
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);
|
|
3984
3984
|
return value;
|
|
3985
3985
|
};
|
|
3986
3986
|
const DateRange = z__default.object({
|
|
@@ -4026,11 +4026,11 @@ class Workstation {
|
|
|
4026
4026
|
* @internal
|
|
4027
4027
|
*/
|
|
4028
4028
|
constructor({ client, applicationId, promptVersion, input, output }) {
|
|
4029
|
-
__publicField$
|
|
4030
|
-
__publicField$
|
|
4031
|
-
__publicField$
|
|
4032
|
-
__publicField$
|
|
4033
|
-
__publicField$
|
|
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");
|
|
4034
4034
|
this._id = applicationId;
|
|
4035
4035
|
this._promptVersion = promptVersion;
|
|
4036
4036
|
this._client = client;
|
|
@@ -4721,490 +4721,173 @@ class Vault {
|
|
|
4721
4721
|
}
|
|
4722
4722
|
}
|
|
4723
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
4724
|
var __defProp$1 = Object.defineProperty;
|
|
5058
4725
|
var __defNormalProp$1 = (obj, key, value) => key in obj ? __defProp$1(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
5059
4726
|
var __publicField$1 = (obj, key, value) => {
|
|
5060
4727
|
__defNormalProp$1(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
5061
4728
|
return value;
|
|
5062
4729
|
};
|
|
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
4730
|
const AGENT_NO_TRANSFORM = { transformCase: false };
|
|
5123
4731
|
class Agents {
|
|
5124
|
-
constructor(
|
|
5125
|
-
|
|
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;
|
|
5126
4769
|
}
|
|
5127
4770
|
/**
|
|
5128
|
-
* Lists the agents available in the workspace (optionally filtered by
|
|
4771
|
+
* Lists the agents available in the workspace (optionally filtered by
|
|
4772
|
+
* project) via the Tela gateway (`GET /agent`).
|
|
5129
4773
|
*/
|
|
5130
4774
|
async list(query = {}) {
|
|
5131
|
-
const response = await this.
|
|
4775
|
+
const response = await this.gateway.get("/agent", {
|
|
5132
4776
|
...AGENT_NO_TRANSFORM,
|
|
5133
4777
|
query
|
|
5134
4778
|
});
|
|
5135
4779
|
return response.data;
|
|
5136
4780
|
}
|
|
5137
4781
|
/**
|
|
5138
|
-
* Fetches an agent by id
|
|
4782
|
+
* Fetches an agent record by id via the Tela gateway (`GET /agent/:id`).
|
|
5139
4783
|
*/
|
|
5140
4784
|
async get(agentId) {
|
|
5141
|
-
const response = await this.
|
|
4785
|
+
const response = await this.gateway.get(`/agent/${agentId}`, {
|
|
5142
4786
|
...AGENT_NO_TRANSFORM
|
|
5143
4787
|
});
|
|
5144
|
-
return
|
|
4788
|
+
return response.data;
|
|
5145
4789
|
}
|
|
5146
4790
|
/**
|
|
5147
|
-
*
|
|
4791
|
+
* Starts (or continues) an agent session via the Tela gateway
|
|
4792
|
+
* (`POST /agent/:id/run`).
|
|
5148
4793
|
*
|
|
5149
|
-
*
|
|
5150
|
-
*
|
|
5151
|
-
*
|
|
5152
|
-
|
|
5153
|
-
|
|
5154
|
-
|
|
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.
|
|
4794
|
+
* - **New session**: pass `agentId` (+ `message`).
|
|
4795
|
+
* - **Continue**: pass `agentId` and the existing `sessionId`.
|
|
4796
|
+
*
|
|
4797
|
+
* The per-variable `inputs` map is flattened into the wire `inputSchema`
|
|
4798
|
+
* array (each entry tagged with its variable name); any `TelaFile` inputs are
|
|
4799
|
+
* uploaded to the vault first. Returns the `sessionId` to stream/inspect.
|
|
5165
4800
|
*/
|
|
5166
|
-
async
|
|
5167
|
-
|
|
4801
|
+
async run(params) {
|
|
4802
|
+
const { agentId, message, sessionId, environmentVariables, inputs, webhooks } = params;
|
|
4803
|
+
const inputSchema = inputs ? await this.buildInputSchema(inputs) : void 0;
|
|
4804
|
+
const response = await this.gateway.post(
|
|
4805
|
+
`/agent/${agentId}/run`,
|
|
4806
|
+
{
|
|
4807
|
+
...AGENT_NO_TRANSFORM,
|
|
4808
|
+
body: { message, sessionId, inputSchema, environmentVariables, webhooks }
|
|
4809
|
+
}
|
|
4810
|
+
);
|
|
4811
|
+
return response.data;
|
|
5168
4812
|
}
|
|
5169
4813
|
/**
|
|
5170
|
-
*
|
|
5171
|
-
*
|
|
4814
|
+
* Updates an agent's model, delegating to the agent-sdk client
|
|
4815
|
+
* (`PUT /v4/agents/:repository/model`). The `agentId` is resolved to the
|
|
4816
|
+
* underlying repository first.
|
|
5172
4817
|
*/
|
|
5173
|
-
async
|
|
5174
|
-
const
|
|
5175
|
-
|
|
4818
|
+
async updateAgentModel(params) {
|
|
4819
|
+
const { repository } = await this.resolveAgent(params.agentId);
|
|
4820
|
+
return this.client.updateAgentModel({
|
|
4821
|
+
repository,
|
|
4822
|
+
model: params.model,
|
|
4823
|
+
commitMessage: params.commitMessage
|
|
5176
4824
|
});
|
|
5177
|
-
return response.data;
|
|
5178
4825
|
}
|
|
5179
4826
|
/**
|
|
5180
|
-
*
|
|
4827
|
+
* Resolves an `agentId` to its `organizationName`/`repository`, memoizing the
|
|
4828
|
+
* lookup. Backed by the Tela gateway `GET /agent/:id`.
|
|
5181
4829
|
*/
|
|
5182
|
-
async
|
|
5183
|
-
const
|
|
5184
|
-
|
|
5185
|
-
|
|
5186
|
-
|
|
4830
|
+
async resolveAgent(agentId) {
|
|
4831
|
+
const cached = this.resolved.get(agentId);
|
|
4832
|
+
if (cached)
|
|
4833
|
+
return cached;
|
|
4834
|
+
const { organizationName, repository } = await this.get(agentId);
|
|
4835
|
+
const resolution = { organizationName, repository };
|
|
4836
|
+
this.resolved.set(agentId, resolution);
|
|
4837
|
+
return resolution;
|
|
5187
4838
|
}
|
|
5188
4839
|
/**
|
|
5189
|
-
*
|
|
5190
|
-
*
|
|
4840
|
+
* Flattens the per-variable {@link AgentRunInputs} map into the wire
|
|
4841
|
+
* `inputSchema` array, tagging each entry with its variable name and
|
|
4842
|
+
* uploading any {@link TelaFile} entries to the vault.
|
|
5191
4843
|
*/
|
|
5192
|
-
async
|
|
5193
|
-
const
|
|
5194
|
-
|
|
5195
|
-
|
|
4844
|
+
async buildInputSchema(inputs) {
|
|
4845
|
+
const pairs = Object.entries(inputs).flatMap(([name, value]) => {
|
|
4846
|
+
const entries = Array.isArray(value) ? value : [value];
|
|
4847
|
+
return entries.map((entry) => ({ name, entry }));
|
|
4848
|
+
});
|
|
4849
|
+
return Promise.all(pairs.map(({ name, entry }) => this.resolveEntry(name, entry)));
|
|
5196
4850
|
}
|
|
5197
4851
|
/**
|
|
5198
|
-
*
|
|
4852
|
+
* Resolves a single {@link AgentRunInputEntry} into a wire
|
|
4853
|
+
* {@link AgentRunInputItem}, uploading {@link TelaFile}s to the vault.
|
|
5199
4854
|
*/
|
|
5200
|
-
async
|
|
5201
|
-
|
|
5202
|
-
|
|
5203
|
-
|
|
5204
|
-
|
|
4855
|
+
async resolveEntry(name, entry) {
|
|
4856
|
+
if (isTelaFile(entry)) {
|
|
4857
|
+
const { fileUrl } = await uploadFile(entry, this.gateway);
|
|
4858
|
+
return { type: "file", name, vaultRef: fileUrl, filename: entry.name ?? "file" };
|
|
4859
|
+
}
|
|
4860
|
+
if ("type" in entry && entry.type === "text")
|
|
4861
|
+
return { type: "text", name, content: entry.content };
|
|
4862
|
+
if ("file" in entry) {
|
|
4863
|
+
const { fileUrl } = await uploadFile(entry.file, this.gateway);
|
|
4864
|
+
return {
|
|
4865
|
+
type: "file",
|
|
4866
|
+
name,
|
|
4867
|
+
vaultRef: fileUrl,
|
|
4868
|
+
filename: entry.filename ?? entry.file.name ?? "file",
|
|
4869
|
+
...entry.metadata ? { metadata: entry.metadata } : {}
|
|
4870
|
+
};
|
|
4871
|
+
}
|
|
4872
|
+
return {
|
|
4873
|
+
type: "file",
|
|
4874
|
+
name,
|
|
4875
|
+
vaultRef: entry.vaultRef,
|
|
4876
|
+
filename: entry.filename,
|
|
4877
|
+
...entry.metadata ? { metadata: entry.metadata } : {}
|
|
4878
|
+
};
|
|
5205
4879
|
}
|
|
5206
4880
|
}
|
|
5207
4881
|
|
|
4882
|
+
function createAuthStrategy(credentials) {
|
|
4883
|
+
if (credentials.dataToken)
|
|
4884
|
+
return new agentSdk.DataTokenAuthStrategy(credentials.dataToken);
|
|
4885
|
+
const bearer = credentials.apiKey ?? credentials.jwt;
|
|
4886
|
+
if (!bearer)
|
|
4887
|
+
throw new MissingAuthError();
|
|
4888
|
+
return new agentSdk.APIKeyAuthStrategy(bearer);
|
|
4889
|
+
}
|
|
4890
|
+
|
|
5208
4891
|
var __defProp = Object.defineProperty;
|
|
5209
4892
|
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
5210
4893
|
var __publicField = (obj, key, value) => {
|
|
@@ -5216,7 +4899,7 @@ const _TelaSDK = class _TelaSDK extends BaseClient {
|
|
|
5216
4899
|
/**
|
|
5217
4900
|
* Creates a new instance of the TelaSDK.
|
|
5218
4901
|
*/
|
|
5219
|
-
constructor({ baseURL = baseUrl, apiKey, jwt, dataToken, ...rest }) {
|
|
4902
|
+
constructor({ baseURL = baseUrl, apiKey, jwt, dataToken, agentBaseURL, vaultURL, ...rest }) {
|
|
5220
4903
|
super({ baseURL, ...rest });
|
|
5221
4904
|
__publicField(this, "opts");
|
|
5222
4905
|
__publicField(this, "apiKey");
|
|
@@ -5292,13 +4975,18 @@ const _TelaSDK = class _TelaSDK extends BaseClient {
|
|
|
5292
4975
|
*/
|
|
5293
4976
|
__publicField(this, "vault", new Vault(this));
|
|
5294
4977
|
/**
|
|
5295
|
-
* Agents API resource
|
|
5296
|
-
* stream events,
|
|
4978
|
+
* Agents API resource. Run an agent by `agentId` via the Tela gateway
|
|
4979
|
+
* (`POST /agent/:id/run`), then stream events, fetch the timeline, or cancel
|
|
4980
|
+
* by `sessionId` (delegated to `@meistrari/agent-sdk`).
|
|
5297
4981
|
*
|
|
5298
4982
|
* @example
|
|
5299
4983
|
* ```typescript
|
|
5300
|
-
* const
|
|
5301
|
-
*
|
|
4984
|
+
* const { sessionId } = await tela.agents.run({
|
|
4985
|
+
* agentId: 'agent-id',
|
|
4986
|
+
* message: 'Hello',
|
|
4987
|
+
* })
|
|
4988
|
+
* for await (const event of await tela.agents.streamSession(sessionId))
|
|
4989
|
+
* console.log(event.kind)
|
|
5302
4990
|
* ```
|
|
5303
4991
|
*/
|
|
5304
4992
|
__publicField(this, "agents");
|
|
@@ -5317,8 +5005,12 @@ const _TelaSDK = class _TelaSDK extends BaseClient {
|
|
|
5317
5005
|
this.apiKey = apiKey;
|
|
5318
5006
|
this.jwt = jwt;
|
|
5319
5007
|
this.dataToken = dataToken;
|
|
5320
|
-
this.agents = new Agents(this);
|
|
5321
5008
|
this.validateAuth();
|
|
5009
|
+
this.agents = new Agents(this, {
|
|
5010
|
+
agentBaseURL: agentBaseURL ?? baseURL,
|
|
5011
|
+
vaultURL: vaultURL ?? `${baseURL}/_services/vault`,
|
|
5012
|
+
authStrategy: createAuthStrategy({ apiKey, jwt, dataToken })
|
|
5013
|
+
});
|
|
5322
5014
|
}
|
|
5323
5015
|
get authToken() {
|
|
5324
5016
|
return this.apiKey || this.jwt || this.dataToken;
|
|
@@ -5401,9 +5093,9 @@ function createTelaClient(opts) {
|
|
|
5401
5093
|
return new TelaSDK(opts);
|
|
5402
5094
|
}
|
|
5403
5095
|
|
|
5096
|
+
exports.parseSessionStream = agentSdk.parseSessionStream;
|
|
5097
|
+
exports.verifyWebhookSignature = agentSdk.verifyWebhookSignature;
|
|
5404
5098
|
exports.APIError = APIError;
|
|
5405
|
-
exports.Agent = Agent;
|
|
5406
|
-
exports.AgentExecution = AgentExecution;
|
|
5407
5099
|
exports.AgentExecutionFailedError = AgentExecutionFailedError;
|
|
5408
5100
|
exports.Agents = Agents;
|
|
5409
5101
|
exports.AuthenticationError = AuthenticationError;
|