@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.mjs
CHANGED
|
@@ -2,14 +2,15 @@ import * as changeCase from 'change-case';
|
|
|
2
2
|
import { Minimatch } from 'minimatch';
|
|
3
3
|
import z, { z as z$1, ZodError } from 'zod';
|
|
4
4
|
import Emittery from 'emittery';
|
|
5
|
-
import {
|
|
5
|
+
import { agentClient, DataTokenAuthStrategy, APIKeyAuthStrategy } from '@meistrari/agent-sdk';
|
|
6
|
+
export { parseSessionStream, verifyWebhookSignature } from '@meistrari/agent-sdk';
|
|
6
7
|
|
|
7
|
-
const version = "2.13.
|
|
8
|
+
const version = "2.13.2";
|
|
8
9
|
|
|
9
|
-
var __defProp$
|
|
10
|
-
var __defNormalProp$
|
|
11
|
-
var __publicField$
|
|
12
|
-
__defNormalProp$
|
|
10
|
+
var __defProp$b = Object.defineProperty;
|
|
11
|
+
var __defNormalProp$b = (obj, key, value) => key in obj ? __defProp$b(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
12
|
+
var __publicField$b = (obj, key, value) => {
|
|
13
|
+
__defNormalProp$b(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
13
14
|
return value;
|
|
14
15
|
};
|
|
15
16
|
class TelaError extends Error {
|
|
@@ -39,7 +40,7 @@ class InvalidFileURL extends TelaError {
|
|
|
39
40
|
class FileUploadError extends TelaError {
|
|
40
41
|
constructor(message, statusCode) {
|
|
41
42
|
super(`Failed to upload file: ${message} (Status code: ${statusCode})`);
|
|
42
|
-
__publicField$
|
|
43
|
+
__publicField$b(this, "statusCode");
|
|
43
44
|
this.statusCode = statusCode;
|
|
44
45
|
}
|
|
45
46
|
}
|
|
@@ -56,21 +57,21 @@ class InvalidExecutionModeError extends TelaError {
|
|
|
56
57
|
class ExecutionFailedError extends TelaError {
|
|
57
58
|
constructor(rawOutput) {
|
|
58
59
|
super(`Execution failed: ${JSON.stringify(rawOutput)}`);
|
|
59
|
-
__publicField$
|
|
60
|
+
__publicField$b(this, "rawOutput");
|
|
60
61
|
this.rawOutput = rawOutput;
|
|
61
62
|
}
|
|
62
63
|
}
|
|
63
64
|
class TaskFailedError extends TelaError {
|
|
64
65
|
constructor(rawTask, message, cause) {
|
|
65
66
|
super(`Task failed: ${JSON.stringify(rawTask)}`, { cause });
|
|
66
|
-
__publicField$
|
|
67
|
+
__publicField$b(this, "rawTask");
|
|
67
68
|
this.rawTask = rawTask;
|
|
68
69
|
}
|
|
69
70
|
}
|
|
70
71
|
class BatchExecutionFailedError extends TelaError {
|
|
71
72
|
constructor(rawResponse) {
|
|
72
73
|
super(`Batch execution failed: ${JSON.stringify(rawResponse)}`);
|
|
73
|
-
__publicField$
|
|
74
|
+
__publicField$b(this, "rawResponse");
|
|
74
75
|
this.rawResponse = rawResponse;
|
|
75
76
|
}
|
|
76
77
|
}
|
|
@@ -78,11 +79,11 @@ class AgentExecutionFailedError extends TelaError {
|
|
|
78
79
|
constructor(payload) {
|
|
79
80
|
super(`Agent execution failed${payload.sessionId ? ` (session ${payload.sessionId})` : ""}: ${payload.error ?? "unknown error"}`);
|
|
80
81
|
/** The session id, when known. */
|
|
81
|
-
__publicField$
|
|
82
|
+
__publicField$b(this, "sessionId");
|
|
82
83
|
/** The server-provided error message, when available. */
|
|
83
|
-
__publicField$
|
|
84
|
+
__publicField$b(this, "error");
|
|
84
85
|
/** The full raw payload that triggered the failure. */
|
|
85
|
-
__publicField$
|
|
86
|
+
__publicField$b(this, "raw");
|
|
86
87
|
this.sessionId = payload.sessionId;
|
|
87
88
|
this.error = payload.error;
|
|
88
89
|
this.raw = payload;
|
|
@@ -92,8 +93,8 @@ class APIError extends TelaError {
|
|
|
92
93
|
constructor(statusCode, error, _message) {
|
|
93
94
|
const message = error?.message ? typeof error.message === "string" ? error.message : JSON.stringify(error.message) : error ? JSON.stringify(error) : _message;
|
|
94
95
|
super(message);
|
|
95
|
-
__publicField$
|
|
96
|
-
__publicField$
|
|
96
|
+
__publicField$b(this, "statusCode");
|
|
97
|
+
__publicField$b(this, "error");
|
|
97
98
|
this.statusCode = statusCode;
|
|
98
99
|
this.error = error;
|
|
99
100
|
}
|
|
@@ -135,7 +136,7 @@ class APIError extends TelaError {
|
|
|
135
136
|
class UserAbortError extends APIError {
|
|
136
137
|
constructor({ message } = {}) {
|
|
137
138
|
super(void 0, void 0, message || "User aborted.");
|
|
138
|
-
__publicField$
|
|
139
|
+
__publicField$b(this, "statusCode");
|
|
139
140
|
}
|
|
140
141
|
}
|
|
141
142
|
class ConnectionError extends APIError {
|
|
@@ -144,7 +145,7 @@ class ConnectionError extends APIError {
|
|
|
144
145
|
cause
|
|
145
146
|
}) {
|
|
146
147
|
super(void 0, void 0, message || "Connection error.");
|
|
147
|
-
__publicField$
|
|
148
|
+
__publicField$b(this, "statusCode");
|
|
148
149
|
if (cause)
|
|
149
150
|
this.cause = cause;
|
|
150
151
|
}
|
|
@@ -154,57 +155,57 @@ class ConnectionTimeout extends APIError {
|
|
|
154
155
|
message
|
|
155
156
|
} = {}) {
|
|
156
157
|
super(void 0, void 0, message || "Request timed out.");
|
|
157
|
-
__publicField$
|
|
158
|
+
__publicField$b(this, "statusCode");
|
|
158
159
|
}
|
|
159
160
|
}
|
|
160
161
|
class BadRequestError extends APIError {
|
|
161
162
|
constructor() {
|
|
162
163
|
super(...arguments);
|
|
163
|
-
__publicField$
|
|
164
|
+
__publicField$b(this, "statusCode", 400);
|
|
164
165
|
}
|
|
165
166
|
// todo: handle validation errors from zod/typebox
|
|
166
167
|
}
|
|
167
168
|
class AuthenticationError extends APIError {
|
|
168
169
|
constructor() {
|
|
169
170
|
super(...arguments);
|
|
170
|
-
__publicField$
|
|
171
|
+
__publicField$b(this, "statusCode", 401);
|
|
171
172
|
}
|
|
172
173
|
}
|
|
173
174
|
class AuthorizationError extends APIError {
|
|
174
175
|
constructor() {
|
|
175
176
|
super(...arguments);
|
|
176
|
-
__publicField$
|
|
177
|
+
__publicField$b(this, "statusCode", 403);
|
|
177
178
|
}
|
|
178
179
|
}
|
|
179
180
|
class NotFoundError extends APIError {
|
|
180
181
|
constructor() {
|
|
181
182
|
super(...arguments);
|
|
182
|
-
__publicField$
|
|
183
|
+
__publicField$b(this, "statusCode", 404);
|
|
183
184
|
}
|
|
184
185
|
}
|
|
185
186
|
class ConflictError extends APIError {
|
|
186
187
|
constructor() {
|
|
187
188
|
super(...arguments);
|
|
188
|
-
__publicField$
|
|
189
|
+
__publicField$b(this, "statusCode", 409);
|
|
189
190
|
}
|
|
190
191
|
}
|
|
191
192
|
class UnprocessableEntityError extends APIError {
|
|
192
193
|
constructor() {
|
|
193
194
|
super(...arguments);
|
|
194
195
|
// todo: check if tela returns 400 or 422 for zod errors
|
|
195
|
-
__publicField$
|
|
196
|
+
__publicField$b(this, "statusCode", 422);
|
|
196
197
|
}
|
|
197
198
|
}
|
|
198
199
|
class RateLimitError extends APIError {
|
|
199
200
|
constructor() {
|
|
200
201
|
super(...arguments);
|
|
201
|
-
__publicField$
|
|
202
|
+
__publicField$b(this, "statusCode", 429);
|
|
202
203
|
}
|
|
203
204
|
}
|
|
204
205
|
class InternalServerError extends APIError {
|
|
205
206
|
constructor() {
|
|
206
207
|
super(...arguments);
|
|
207
|
-
__publicField$
|
|
208
|
+
__publicField$b(this, "statusCode", 500);
|
|
208
209
|
}
|
|
209
210
|
}
|
|
210
211
|
function toError(err) {
|
|
@@ -490,10 +491,10 @@ function transformDurationToMs(durationStr) {
|
|
|
490
491
|
return Number.parseInt(amount) * multiplier;
|
|
491
492
|
}
|
|
492
493
|
|
|
493
|
-
var __defProp$
|
|
494
|
-
var __defNormalProp$
|
|
495
|
-
var __publicField$
|
|
496
|
-
__defNormalProp$
|
|
494
|
+
var __defProp$a = Object.defineProperty;
|
|
495
|
+
var __defNormalProp$a = (obj, key, value) => key in obj ? __defProp$a(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
496
|
+
var __publicField$a = (obj, key, value) => {
|
|
497
|
+
__defNormalProp$a(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
497
498
|
return value;
|
|
498
499
|
};
|
|
499
500
|
class Stream {
|
|
@@ -757,9 +758,9 @@ function findDoubleNewlineIndex(buffer) {
|
|
|
757
758
|
}
|
|
758
759
|
class SSEDecoder {
|
|
759
760
|
constructor() {
|
|
760
|
-
__publicField$
|
|
761
|
-
__publicField$
|
|
762
|
-
__publicField$
|
|
761
|
+
__publicField$a(this, "data");
|
|
762
|
+
__publicField$a(this, "event");
|
|
763
|
+
__publicField$a(this, "chunks");
|
|
763
764
|
this.event = null;
|
|
764
765
|
this.data = [];
|
|
765
766
|
this.chunks = [];
|
|
@@ -800,9 +801,9 @@ class SSEDecoder {
|
|
|
800
801
|
const _LineDecoder = class _LineDecoder {
|
|
801
802
|
// TextDecoder found in browsers; not typed to avoid pulling in either "dom" or "node" types.
|
|
802
803
|
constructor() {
|
|
803
|
-
__publicField$
|
|
804
|
-
__publicField$
|
|
805
|
-
__publicField$
|
|
804
|
+
__publicField$a(this, "buffer");
|
|
805
|
+
__publicField$a(this, "trailingCR");
|
|
806
|
+
__publicField$a(this, "textDecoder");
|
|
806
807
|
this.buffer = [];
|
|
807
808
|
this.trailingCR = false;
|
|
808
809
|
}
|
|
@@ -877,8 +878,8 @@ const _LineDecoder = class _LineDecoder {
|
|
|
877
878
|
}
|
|
878
879
|
};
|
|
879
880
|
// prettier-ignore
|
|
880
|
-
__publicField$
|
|
881
|
-
__publicField$
|
|
881
|
+
__publicField$a(_LineDecoder, "NEWLINE_CHARS", /* @__PURE__ */ new Set(["\n", "\r"]));
|
|
882
|
+
__publicField$a(_LineDecoder, "NEWLINE_REGEXP", /\r\n|[\n\r]/g);
|
|
882
883
|
let LineDecoder = _LineDecoder;
|
|
883
884
|
function partition(str, delimiter) {
|
|
884
885
|
const index = str.indexOf(delimiter);
|
|
@@ -915,10 +916,10 @@ function readableStreamAsyncIterable(stream) {
|
|
|
915
916
|
};
|
|
916
917
|
}
|
|
917
918
|
|
|
918
|
-
var __defProp$
|
|
919
|
-
var __defNormalProp$
|
|
920
|
-
var __publicField$
|
|
921
|
-
__defNormalProp$
|
|
919
|
+
var __defProp$9 = Object.defineProperty;
|
|
920
|
+
var __defNormalProp$9 = (obj, key, value) => key in obj ? __defProp$9(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
921
|
+
var __publicField$9 = (obj, key, value) => {
|
|
922
|
+
__defNormalProp$9(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
922
923
|
return value;
|
|
923
924
|
};
|
|
924
925
|
function getRequestIdFromResponse(response) {
|
|
@@ -994,10 +995,10 @@ function transformObjectCase(obj, transformCase) {
|
|
|
994
995
|
}
|
|
995
996
|
class BaseClient {
|
|
996
997
|
constructor({ baseURL, maxRetries = 5, timeout = 0 }) {
|
|
997
|
-
__publicField$
|
|
998
|
-
__publicField$
|
|
999
|
-
__publicField$
|
|
1000
|
-
__publicField$
|
|
998
|
+
__publicField$9(this, "baseURL");
|
|
999
|
+
__publicField$9(this, "maxRetries");
|
|
1000
|
+
__publicField$9(this, "timeout");
|
|
1001
|
+
__publicField$9(this, "fetch");
|
|
1001
1002
|
this.baseURL = baseURL;
|
|
1002
1003
|
this.maxRetries = validateMaxRetries(maxRetries);
|
|
1003
1004
|
this.timeout = validateTimeout(timeout);
|
|
@@ -1312,10 +1313,10 @@ async function getStreamSize(stream) {
|
|
|
1312
1313
|
return size;
|
|
1313
1314
|
}
|
|
1314
1315
|
|
|
1315
|
-
var __defProp$
|
|
1316
|
-
var __defNormalProp$
|
|
1317
|
-
var __publicField$
|
|
1318
|
-
__defNormalProp$
|
|
1316
|
+
var __defProp$8 = Object.defineProperty;
|
|
1317
|
+
var __defNormalProp$8 = (obj, key, value) => key in obj ? __defProp$8(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
1318
|
+
var __publicField$8 = (obj, key, value) => {
|
|
1319
|
+
__defNormalProp$8(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
1319
1320
|
return value;
|
|
1320
1321
|
};
|
|
1321
1322
|
function TelaFileSchema() {
|
|
@@ -1323,11 +1324,11 @@ function TelaFileSchema() {
|
|
|
1323
1324
|
}
|
|
1324
1325
|
class TelaFile {
|
|
1325
1326
|
constructor(file, options = {}) {
|
|
1326
|
-
__publicField$
|
|
1327
|
-
__publicField$
|
|
1328
|
-
__publicField$
|
|
1329
|
-
__publicField$
|
|
1330
|
-
__publicField$
|
|
1327
|
+
__publicField$8(this, "_file");
|
|
1328
|
+
__publicField$8(this, "_options");
|
|
1329
|
+
__publicField$8(this, "_size", null);
|
|
1330
|
+
__publicField$8(this, "_mimeType");
|
|
1331
|
+
__publicField$8(this, "_name");
|
|
1331
1332
|
this._file = file;
|
|
1332
1333
|
if (file instanceof File || file instanceof Blob) {
|
|
1333
1334
|
this._size = file.size;
|
|
@@ -1806,10 +1807,10 @@ async function streamFile(vaultReference, client) {
|
|
|
1806
1807
|
});
|
|
1807
1808
|
}
|
|
1808
1809
|
|
|
1809
|
-
var __defProp$
|
|
1810
|
-
var __defNormalProp$
|
|
1811
|
-
var __publicField$
|
|
1812
|
-
__defNormalProp$
|
|
1810
|
+
var __defProp$7 = Object.defineProperty;
|
|
1811
|
+
var __defNormalProp$7 = (obj, key, value) => key in obj ? __defProp$7(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
1812
|
+
var __publicField$7 = (obj, key, value) => {
|
|
1813
|
+
__defNormalProp$7(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
1813
1814
|
return value;
|
|
1814
1815
|
};
|
|
1815
1816
|
function timeout(ms, signal) {
|
|
@@ -1825,10 +1826,10 @@ function timeout(ms, signal) {
|
|
|
1825
1826
|
}
|
|
1826
1827
|
class Poller {
|
|
1827
1828
|
constructor({ interval, timeout: timeout2, abortSignal }) {
|
|
1828
|
-
__publicField$
|
|
1829
|
-
__publicField$
|
|
1830
|
-
__publicField$
|
|
1831
|
-
__publicField$
|
|
1829
|
+
__publicField$7(this, "_interval");
|
|
1830
|
+
__publicField$7(this, "_timeout");
|
|
1831
|
+
__publicField$7(this, "_abortSignal");
|
|
1832
|
+
__publicField$7(this, "_internalAbortController");
|
|
1832
1833
|
if (interval <= 0) {
|
|
1833
1834
|
throw new TelaError("Interval must be greater than 0");
|
|
1834
1835
|
}
|
|
@@ -1889,10 +1890,10 @@ class Poller {
|
|
|
1889
1890
|
}
|
|
1890
1891
|
}
|
|
1891
1892
|
|
|
1892
|
-
var __defProp$
|
|
1893
|
-
var __defNormalProp$
|
|
1894
|
-
var __publicField$
|
|
1895
|
-
__defNormalProp$
|
|
1893
|
+
var __defProp$6 = Object.defineProperty;
|
|
1894
|
+
var __defNormalProp$6 = (obj, key, value) => key in obj ? __defProp$6(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
1895
|
+
var __publicField$6 = (obj, key, value) => {
|
|
1896
|
+
__defNormalProp$6(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
1896
1897
|
return value;
|
|
1897
1898
|
};
|
|
1898
1899
|
function isUUID(str) {
|
|
@@ -1948,21 +1949,21 @@ class CanvasExecution extends Emittery {
|
|
|
1948
1949
|
*/
|
|
1949
1950
|
constructor(variables, params = { async: false }, outputSchema, client, isTask = false) {
|
|
1950
1951
|
super();
|
|
1951
|
-
__publicField$
|
|
1952
|
-
__publicField$
|
|
1953
|
-
__publicField$
|
|
1954
|
-
__publicField$
|
|
1955
|
-
__publicField$
|
|
1956
|
-
__publicField$
|
|
1957
|
-
__publicField$
|
|
1958
|
-
__publicField$
|
|
1959
|
-
__publicField$
|
|
1960
|
-
__publicField$
|
|
1961
|
-
__publicField$
|
|
1962
|
-
__publicField$
|
|
1963
|
-
__publicField$
|
|
1964
|
-
__publicField$
|
|
1965
|
-
__publicField$
|
|
1952
|
+
__publicField$6(this, "_id");
|
|
1953
|
+
__publicField$6(this, "_status");
|
|
1954
|
+
__publicField$6(this, "_variables");
|
|
1955
|
+
__publicField$6(this, "_params");
|
|
1956
|
+
__publicField$6(this, "_client");
|
|
1957
|
+
__publicField$6(this, "_outputSchema");
|
|
1958
|
+
__publicField$6(this, "_skipResultValidation");
|
|
1959
|
+
__publicField$6(this, "_abortController");
|
|
1960
|
+
__publicField$6(this, "_isTask");
|
|
1961
|
+
__publicField$6(this, "_headers");
|
|
1962
|
+
__publicField$6(this, "_resultPromise");
|
|
1963
|
+
__publicField$6(this, "_stream");
|
|
1964
|
+
__publicField$6(this, "_rawResultValue");
|
|
1965
|
+
__publicField$6(this, "_requestId");
|
|
1966
|
+
__publicField$6(this, "_task");
|
|
1966
1967
|
this._variables = variables;
|
|
1967
1968
|
this._params = params;
|
|
1968
1969
|
this._outputSchema = outputSchema;
|
|
@@ -2593,10 +2594,10 @@ class CanvasExecution extends Emittery {
|
|
|
2593
2594
|
}
|
|
2594
2595
|
}
|
|
2595
2596
|
|
|
2596
|
-
var __defProp$
|
|
2597
|
-
var __defNormalProp$
|
|
2598
|
-
var __publicField$
|
|
2599
|
-
__defNormalProp$
|
|
2597
|
+
var __defProp$5 = Object.defineProperty;
|
|
2598
|
+
var __defNormalProp$5 = (obj, key, value) => key in obj ? __defProp$5(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
2599
|
+
var __publicField$5 = (obj, key, value) => {
|
|
2600
|
+
__defNormalProp$5(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
2600
2601
|
return value;
|
|
2601
2602
|
};
|
|
2602
2603
|
function resolveBatchQueue(queue) {
|
|
@@ -2748,8 +2749,8 @@ class BatchExecutionResult {
|
|
|
2748
2749
|
* @internal
|
|
2749
2750
|
*/
|
|
2750
2751
|
constructor(client, response) {
|
|
2751
|
-
__publicField$
|
|
2752
|
-
__publicField$
|
|
2752
|
+
__publicField$5(this, "_client");
|
|
2753
|
+
__publicField$5(this, "_response");
|
|
2753
2754
|
this._client = client;
|
|
2754
2755
|
this._response = response;
|
|
2755
2756
|
}
|
|
@@ -3025,13 +3026,13 @@ class BatchExecution extends Emittery {
|
|
|
3025
3026
|
*/
|
|
3026
3027
|
constructor(id, client, params = {}, creationResponse) {
|
|
3027
3028
|
super();
|
|
3028
|
-
__publicField$
|
|
3029
|
-
__publicField$
|
|
3030
|
-
__publicField$
|
|
3031
|
-
__publicField$
|
|
3032
|
-
__publicField$
|
|
3033
|
-
__publicField$
|
|
3034
|
-
__publicField$
|
|
3029
|
+
__publicField$5(this, "_client");
|
|
3030
|
+
__publicField$5(this, "_id");
|
|
3031
|
+
__publicField$5(this, "_params");
|
|
3032
|
+
__publicField$5(this, "_abortController");
|
|
3033
|
+
__publicField$5(this, "_creationResponse");
|
|
3034
|
+
__publicField$5(this, "_status", "created");
|
|
3035
|
+
__publicField$5(this, "_resultPromise");
|
|
3035
3036
|
this._id = id;
|
|
3036
3037
|
this._client = client;
|
|
3037
3038
|
this._params = params;
|
|
@@ -3244,10 +3245,10 @@ class Batch {
|
|
|
3244
3245
|
* @internal
|
|
3245
3246
|
*/
|
|
3246
3247
|
constructor(client, canvasIdentifier, params = {}) {
|
|
3247
|
-
__publicField$
|
|
3248
|
-
__publicField$
|
|
3249
|
-
__publicField$
|
|
3250
|
-
__publicField$
|
|
3248
|
+
__publicField$5(this, "_client");
|
|
3249
|
+
__publicField$5(this, "_canvasIdentifier");
|
|
3250
|
+
__publicField$5(this, "_items", []);
|
|
3251
|
+
__publicField$5(this, "_params");
|
|
3251
3252
|
this._client = client;
|
|
3252
3253
|
this._canvasIdentifier = canvasIdentifier;
|
|
3253
3254
|
this._params = params;
|
|
@@ -3392,10 +3393,10 @@ class Batch {
|
|
|
3392
3393
|
}
|
|
3393
3394
|
}
|
|
3394
3395
|
|
|
3395
|
-
var __defProp$
|
|
3396
|
-
var __defNormalProp$
|
|
3397
|
-
var __publicField$
|
|
3398
|
-
__defNormalProp$
|
|
3396
|
+
var __defProp$4 = Object.defineProperty;
|
|
3397
|
+
var __defNormalProp$4 = (obj, key, value) => key in obj ? __defProp$4(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
3398
|
+
var __publicField$4 = (obj, key, value) => {
|
|
3399
|
+
__defNormalProp$4(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
3399
3400
|
return value;
|
|
3400
3401
|
};
|
|
3401
3402
|
function fetchById(id, client) {
|
|
@@ -3427,15 +3428,15 @@ class Canvas {
|
|
|
3427
3428
|
* @private
|
|
3428
3429
|
*/
|
|
3429
3430
|
constructor({ id, applicationId, name, versionId, input, output, client, variables, isWorkflow }) {
|
|
3430
|
-
__publicField$
|
|
3431
|
-
__publicField$
|
|
3432
|
-
__publicField$
|
|
3433
|
-
__publicField$
|
|
3434
|
-
__publicField$
|
|
3435
|
-
__publicField$
|
|
3436
|
-
__publicField$
|
|
3437
|
-
__publicField$
|
|
3438
|
-
__publicField$
|
|
3431
|
+
__publicField$4(this, "_id");
|
|
3432
|
+
__publicField$4(this, "_versionId");
|
|
3433
|
+
__publicField$4(this, "_applicationId");
|
|
3434
|
+
__publicField$4(this, "_name");
|
|
3435
|
+
__publicField$4(this, "_input");
|
|
3436
|
+
__publicField$4(this, "_output");
|
|
3437
|
+
__publicField$4(this, "_client");
|
|
3438
|
+
__publicField$4(this, "_variables");
|
|
3439
|
+
__publicField$4(this, "_isWorkflow");
|
|
3439
3440
|
this._id = id;
|
|
3440
3441
|
this._applicationId = applicationId;
|
|
3441
3442
|
this._name = name;
|
|
@@ -3692,24 +3693,24 @@ z$1.object({
|
|
|
3692
3693
|
requestId: z$1.string()
|
|
3693
3694
|
});
|
|
3694
3695
|
|
|
3695
|
-
var __defProp$
|
|
3696
|
-
var __defNormalProp$
|
|
3697
|
-
var __publicField$
|
|
3698
|
-
__defNormalProp$
|
|
3696
|
+
var __defProp$3 = Object.defineProperty;
|
|
3697
|
+
var __defNormalProp$3 = (obj, key, value) => key in obj ? __defProp$3(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
3698
|
+
var __publicField$3 = (obj, key, value) => {
|
|
3699
|
+
__defNormalProp$3(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
3699
3700
|
return value;
|
|
3700
3701
|
};
|
|
3701
3702
|
class Task extends Emittery {
|
|
3702
3703
|
constructor(client, variables, task, requestId, outputSchema, skipResultValidation = false) {
|
|
3703
3704
|
super();
|
|
3704
|
-
__publicField$
|
|
3705
|
-
__publicField$
|
|
3706
|
-
__publicField$
|
|
3707
|
-
__publicField$
|
|
3708
|
-
__publicField$
|
|
3709
|
-
__publicField$
|
|
3710
|
-
__publicField$
|
|
3711
|
-
__publicField$
|
|
3712
|
-
__publicField$
|
|
3705
|
+
__publicField$3(this, "_variables");
|
|
3706
|
+
__publicField$3(this, "_task");
|
|
3707
|
+
__publicField$3(this, "_abortController", new AbortController());
|
|
3708
|
+
__publicField$3(this, "_client");
|
|
3709
|
+
__publicField$3(this, "_outputSchema");
|
|
3710
|
+
__publicField$3(this, "_skipResultValidation");
|
|
3711
|
+
__publicField$3(this, "_resultPromise");
|
|
3712
|
+
__publicField$3(this, "_status");
|
|
3713
|
+
__publicField$3(this, "_requestId");
|
|
3713
3714
|
this._variables = variables;
|
|
3714
3715
|
this._task = task;
|
|
3715
3716
|
this._client = client;
|
|
@@ -3957,10 +3958,10 @@ class Task extends Emittery {
|
|
|
3957
3958
|
}
|
|
3958
3959
|
}
|
|
3959
3960
|
|
|
3960
|
-
var __defProp$
|
|
3961
|
-
var __defNormalProp$
|
|
3962
|
-
var __publicField$
|
|
3963
|
-
__defNormalProp$
|
|
3961
|
+
var __defProp$2 = Object.defineProperty;
|
|
3962
|
+
var __defNormalProp$2 = (obj, key, value) => key in obj ? __defProp$2(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
3963
|
+
var __publicField$2 = (obj, key, value) => {
|
|
3964
|
+
__defNormalProp$2(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
3964
3965
|
return value;
|
|
3965
3966
|
};
|
|
3966
3967
|
const DateRange = z.object({
|
|
@@ -4006,11 +4007,11 @@ class Workstation {
|
|
|
4006
4007
|
* @internal
|
|
4007
4008
|
*/
|
|
4008
4009
|
constructor({ client, applicationId, promptVersion, input, output }) {
|
|
4009
|
-
__publicField$
|
|
4010
|
-
__publicField$
|
|
4011
|
-
__publicField$
|
|
4012
|
-
__publicField$
|
|
4013
|
-
__publicField$
|
|
4010
|
+
__publicField$2(this, "_id");
|
|
4011
|
+
__publicField$2(this, "_promptVersion");
|
|
4012
|
+
__publicField$2(this, "_client");
|
|
4013
|
+
__publicField$2(this, "_input");
|
|
4014
|
+
__publicField$2(this, "_output");
|
|
4014
4015
|
this._id = applicationId;
|
|
4015
4016
|
this._promptVersion = promptVersion;
|
|
4016
4017
|
this._client = client;
|
|
@@ -4701,490 +4702,173 @@ class Vault {
|
|
|
4701
4702
|
}
|
|
4702
4703
|
}
|
|
4703
4704
|
|
|
4704
|
-
var __defProp$2 = Object.defineProperty;
|
|
4705
|
-
var __defNormalProp$2 = (obj, key, value) => key in obj ? __defProp$2(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
4706
|
-
var __publicField$2 = (obj, key, value) => {
|
|
4707
|
-
__defNormalProp$2(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
4708
|
-
return value;
|
|
4709
|
-
};
|
|
4710
|
-
const AGENT_NO_TRANSFORM$1 = { transformCase: false };
|
|
4711
|
-
const DEFAULT_MESSAGE = "Execute";
|
|
4712
|
-
const RECONNECT_DELAY_MS = 2e3;
|
|
4713
|
-
const MAX_STREAM_RECONNECT_ERRORS = 5;
|
|
4714
|
-
class AgentExecution extends Emittery {
|
|
4715
|
-
constructor(context) {
|
|
4716
|
-
super();
|
|
4717
|
-
__publicField$2(this, "_sessionId");
|
|
4718
|
-
__publicField$2(this, "_status");
|
|
4719
|
-
__publicField$2(this, "_cursor");
|
|
4720
|
-
__publicField$2(this, "_resultPromise");
|
|
4721
|
-
__publicField$2(this, "_stream");
|
|
4722
|
-
__publicField$2(this, "_abortController");
|
|
4723
|
-
__publicField$2(this, "_client");
|
|
4724
|
-
__publicField$2(this, "_agentId");
|
|
4725
|
-
__publicField$2(this, "_mode");
|
|
4726
|
-
__publicField$2(this, "_reconnectDelayMs");
|
|
4727
|
-
this._client = context.client;
|
|
4728
|
-
this._agentId = context.agentId;
|
|
4729
|
-
this._mode = context.mode ?? "run";
|
|
4730
|
-
this._sessionId = context.sessionId;
|
|
4731
|
-
this._reconnectDelayMs = context.reconnectDelayMs ?? RECONNECT_DELAY_MS;
|
|
4732
|
-
this._abortController = new AbortController();
|
|
4733
|
-
}
|
|
4734
|
-
/**
|
|
4735
|
-
* Builds a resumable execution bound to an existing session id.
|
|
4736
|
-
*
|
|
4737
|
-
* Used by `tela.agents.getSession()`. The returned execution can `.stream`,
|
|
4738
|
-
* `.result`, `.cancel`, or `.recover` — but not `.continue` (a new turn
|
|
4739
|
-
* needs the agent id).
|
|
4740
|
-
*/
|
|
4741
|
-
static fromSession(sessionId, client) {
|
|
4742
|
-
return new AgentExecution({ client, sessionId });
|
|
4743
|
-
}
|
|
4744
|
-
/**
|
|
4745
|
-
* The session id assigned by the server.
|
|
4746
|
-
*
|
|
4747
|
-
* @throws {ExecutionNotStartedError} If the execution has not started yet.
|
|
4748
|
-
*/
|
|
4749
|
-
get sessionId() {
|
|
4750
|
-
if (!this._sessionId)
|
|
4751
|
-
throw new ExecutionNotStartedError();
|
|
4752
|
-
return this._sessionId;
|
|
4753
|
-
}
|
|
4754
|
-
/**
|
|
4755
|
-
* The latest known session status.
|
|
4756
|
-
*
|
|
4757
|
-
* @throws {ExecutionNotStartedError} If no status has been observed yet.
|
|
4758
|
-
*/
|
|
4759
|
-
get status() {
|
|
4760
|
-
if (!this._status)
|
|
4761
|
-
throw new ExecutionNotStartedError();
|
|
4762
|
-
return this._status;
|
|
4763
|
-
}
|
|
4764
|
-
set status(status) {
|
|
4765
|
-
const changed = this._status !== status;
|
|
4766
|
-
this._status = status;
|
|
4767
|
-
if (changed)
|
|
4768
|
-
this.emit("status", status).catch(() => {
|
|
4769
|
-
});
|
|
4770
|
-
}
|
|
4771
|
-
/**
|
|
4772
|
-
* Starts (or continues) the session by POSTing to `/agent/:id/run`
|
|
4773
|
-
* (or `/agent/:id/test` in draft mode). Resets any in-flight stream/result
|
|
4774
|
-
* so the next read re-opens.
|
|
4775
|
-
*
|
|
4776
|
-
* @throws {AgentExecutionFailedError} If the server rejects the execution.
|
|
4777
|
-
*/
|
|
4778
|
-
async start(params) {
|
|
4779
|
-
if (!this._agentId)
|
|
4780
|
-
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).");
|
|
4781
|
-
this._abortController = new AbortController();
|
|
4782
|
-
const message = resolveMessage(params);
|
|
4783
|
-
const inputSchema = await this.resolveInputs(params.inputs);
|
|
4784
|
-
const attachments = await this.resolveAttachments(params.attachments);
|
|
4785
|
-
const body = {
|
|
4786
|
-
message,
|
|
4787
|
-
sessionId: this._sessionId,
|
|
4788
|
-
inputSchema,
|
|
4789
|
-
attachments,
|
|
4790
|
-
environmentVariables: params.environmentVariables
|
|
4791
|
-
};
|
|
4792
|
-
if (this._mode === "test") {
|
|
4793
|
-
body.ref = params.ref;
|
|
4794
|
-
body.isMultiturn = params.isMultiturn;
|
|
4795
|
-
}
|
|
4796
|
-
const envelope = await this._client.post(`/agent/${this._agentId}/${this._mode}`, {
|
|
4797
|
-
...AGENT_NO_TRANSFORM$1,
|
|
4798
|
-
body,
|
|
4799
|
-
signal: this._abortController.signal,
|
|
4800
|
-
headers: params.headers ? new Headers(params.headers) : void 0
|
|
4801
|
-
});
|
|
4802
|
-
const response = envelope.data;
|
|
4803
|
-
if (!response?.success || !response.sessionId)
|
|
4804
|
-
throw new AgentExecutionFailedError({ sessionId: response?.sessionId, error: response?.error });
|
|
4805
|
-
this._sessionId = response.sessionId;
|
|
4806
|
-
this._stream = void 0;
|
|
4807
|
-
this._resultPromise = void 0;
|
|
4808
|
-
this.status = "pending";
|
|
4809
|
-
return this;
|
|
4810
|
-
}
|
|
4811
|
-
/**
|
|
4812
|
-
* Continues this session with another turn (same `sessionId`).
|
|
4813
|
-
*
|
|
4814
|
-
* @returns A promise-like handle for the new turn (`.result` / `.stream`).
|
|
4815
|
-
*/
|
|
4816
|
-
continue(params) {
|
|
4817
|
-
return toExecutionPromise(this, params);
|
|
4818
|
-
}
|
|
4819
|
-
/**
|
|
4820
|
-
* Recovers a failed/terminal session (`POST /agent/sessions/:id/recover`),
|
|
4821
|
-
* then re-opens the stream from the current cursor.
|
|
4822
|
-
*
|
|
4823
|
-
* @throws {ExecutionNotStartedError} If there is no session to recover.
|
|
4824
|
-
* @throws {AgentExecutionFailedError} If recovery is rejected.
|
|
4825
|
-
*/
|
|
4826
|
-
async recover() {
|
|
4827
|
-
if (!this._sessionId)
|
|
4828
|
-
throw new ExecutionNotStartedError();
|
|
4829
|
-
this._abortController = new AbortController();
|
|
4830
|
-
const envelope = await this._client.post(`/agent/sessions/${this._sessionId}/recover`, {
|
|
4831
|
-
...AGENT_NO_TRANSFORM$1,
|
|
4832
|
-
signal: this._abortController.signal
|
|
4833
|
-
});
|
|
4834
|
-
const response = envelope.data;
|
|
4835
|
-
if (!response?.success || !response.sessionId)
|
|
4836
|
-
throw new AgentExecutionFailedError({ sessionId: response?.sessionId ?? this._sessionId, error: response?.error });
|
|
4837
|
-
this._sessionId = response.sessionId;
|
|
4838
|
-
this._stream = void 0;
|
|
4839
|
-
this._resultPromise = void 0;
|
|
4840
|
-
this.status = "pending";
|
|
4841
|
-
return this;
|
|
4842
|
-
}
|
|
4843
|
-
/**
|
|
4844
|
-
* A live, typed stream of session events. Memoized: repeated access returns
|
|
4845
|
-
* the same generator. Updates `status` and the resume cursor as it goes.
|
|
4846
|
-
*
|
|
4847
|
-
* @throws {ExecutionNotStartedError} If the session has no id yet.
|
|
4848
|
-
*/
|
|
4849
|
-
get stream() {
|
|
4850
|
-
if (!this._stream)
|
|
4851
|
-
this._stream = this.openStream();
|
|
4852
|
-
return this._stream;
|
|
4853
|
-
}
|
|
4854
|
-
async *openStream() {
|
|
4855
|
-
if (!this._sessionId)
|
|
4856
|
-
throw new ExecutionNotStartedError();
|
|
4857
|
-
let consecutiveErrors = 0;
|
|
4858
|
-
try {
|
|
4859
|
-
while (!this._abortController.signal.aborted) {
|
|
4860
|
-
try {
|
|
4861
|
-
const { response } = await this._client.requestRaw("GET", `/agent/sessions/${this._sessionId}`, {
|
|
4862
|
-
...AGENT_NO_TRANSFORM$1,
|
|
4863
|
-
query: this._cursor !== void 0 ? { cursor: this._cursor } : void 0,
|
|
4864
|
-
signal: this._abortController.signal,
|
|
4865
|
-
headers: new Headers({ Accept: "text/event-stream" })
|
|
4866
|
-
});
|
|
4867
|
-
if (!response.body)
|
|
4868
|
-
throw new Error("agent session stream response has no body");
|
|
4869
|
-
for await (const event of parseSessionStream(response.body)) {
|
|
4870
|
-
consecutiveErrors = 0;
|
|
4871
|
-
if ("status" in event)
|
|
4872
|
-
this.status = event.status;
|
|
4873
|
-
if ("nextCursor" in event && event.nextCursor != null)
|
|
4874
|
-
this._cursor = event.nextCursor;
|
|
4875
|
-
if (event.kind === "steps")
|
|
4876
|
-
this.emit("step", event.steps).catch(() => {
|
|
4877
|
-
});
|
|
4878
|
-
if (event.kind === "result")
|
|
4879
|
-
this.emit("result", event.result).catch(() => {
|
|
4880
|
-
});
|
|
4881
|
-
yield event;
|
|
4882
|
-
switch (event.kind) {
|
|
4883
|
-
case "error":
|
|
4884
|
-
throw this.fail(event.sessionId, event.error);
|
|
4885
|
-
case "result":
|
|
4886
|
-
return;
|
|
4887
|
-
case "status":
|
|
4888
|
-
case "steps":
|
|
4889
|
-
case "timeline-finalize":
|
|
4890
|
-
if (event.status === "failed")
|
|
4891
|
-
throw this.fail(event.sessionId, "error" in event ? event.error : void 0);
|
|
4892
|
-
if (event.status === "cancelled")
|
|
4893
|
-
return;
|
|
4894
|
-
break;
|
|
4895
|
-
}
|
|
4896
|
-
}
|
|
4897
|
-
} catch (error) {
|
|
4898
|
-
if (error instanceof AgentExecutionFailedError)
|
|
4899
|
-
throw error;
|
|
4900
|
-
if (this._abortController.signal.aborted)
|
|
4901
|
-
return;
|
|
4902
|
-
if (++consecutiveErrors > MAX_STREAM_RECONNECT_ERRORS)
|
|
4903
|
-
throw error;
|
|
4904
|
-
}
|
|
4905
|
-
if (this._abortController.signal.aborted)
|
|
4906
|
-
return;
|
|
4907
|
-
await delay(this._reconnectDelayMs, this._abortController.signal);
|
|
4908
|
-
}
|
|
4909
|
-
} finally {
|
|
4910
|
-
this._abortController.abort();
|
|
4911
|
-
}
|
|
4912
|
-
}
|
|
4913
|
-
fail(sessionId, error) {
|
|
4914
|
-
const failure = new AgentExecutionFailedError({ sessionId, error });
|
|
4915
|
-
this.status = "failed";
|
|
4916
|
-
this.emit("error", failure).catch(() => {
|
|
4917
|
-
});
|
|
4918
|
-
return failure;
|
|
4919
|
-
}
|
|
4920
|
-
/**
|
|
4921
|
-
* Resolves with the session's result payload, lazily consuming the stream.
|
|
4922
|
-
*
|
|
4923
|
-
* Memoized: repeated access returns the same promise. Resolves on the first
|
|
4924
|
-
* `result` event — for `completed` *or* `waiting_messages`. Inspect
|
|
4925
|
-
* `.status` to tell them apart, and `.continue()` from a paused turn.
|
|
4926
|
-
*
|
|
4927
|
-
* @throws {AgentExecutionFailedError} If the session fails or the stream
|
|
4928
|
-
* ends without producing a result.
|
|
4929
|
-
*/
|
|
4930
|
-
get result() {
|
|
4931
|
-
if (this._resultPromise)
|
|
4932
|
-
return this._resultPromise;
|
|
4933
|
-
this._resultPromise = (async () => {
|
|
4934
|
-
let lastResult;
|
|
4935
|
-
for await (const event of this.stream) {
|
|
4936
|
-
if (event.kind === "result")
|
|
4937
|
-
lastResult = event.result;
|
|
4938
|
-
}
|
|
4939
|
-
if (lastResult !== void 0)
|
|
4940
|
-
return lastResult;
|
|
4941
|
-
throw new AgentExecutionFailedError({
|
|
4942
|
-
sessionId: this._sessionId,
|
|
4943
|
-
error: "session stream ended without a result"
|
|
4944
|
-
});
|
|
4945
|
-
})();
|
|
4946
|
-
this._resultPromise.catch(() => {
|
|
4947
|
-
});
|
|
4948
|
-
return this._resultPromise;
|
|
4949
|
-
}
|
|
4950
|
-
/**
|
|
4951
|
-
* Cancels the session: aborts the open stream immediately, then requests a
|
|
4952
|
-
* server-side cancel (`POST /agent/sessions/:id/cancel`).
|
|
4953
|
-
*/
|
|
4954
|
-
async cancel() {
|
|
4955
|
-
this._abortController.abort();
|
|
4956
|
-
if (this._sessionId) {
|
|
4957
|
-
await this._client.post(`/agent/sessions/${this._sessionId}/cancel`, { ...AGENT_NO_TRANSFORM$1 }).catch(() => {
|
|
4958
|
-
});
|
|
4959
|
-
}
|
|
4960
|
-
}
|
|
4961
|
-
/**
|
|
4962
|
-
* Resolves the agent's input values into {@link AgentInputItem}s, uploading
|
|
4963
|
-
* any `TelaFile`s to the vault and passing strings through as text.
|
|
4964
|
-
*/
|
|
4965
|
-
async resolveInputs(inputs) {
|
|
4966
|
-
if (!inputs)
|
|
4967
|
-
return void 0;
|
|
4968
|
-
const entries = Object.entries(inputs);
|
|
4969
|
-
if (entries.length === 0)
|
|
4970
|
-
return void 0;
|
|
4971
|
-
return Promise.all(
|
|
4972
|
-
entries.map(async ([name, value]) => {
|
|
4973
|
-
if (isTelaFile(value)) {
|
|
4974
|
-
const { fileUrl } = await uploadFile(value, this._client);
|
|
4975
|
-
return { type: "file", name, vaultRef: fileUrl, filename: value.name ?? name };
|
|
4976
|
-
}
|
|
4977
|
-
return { type: "text", name, content: value };
|
|
4978
|
-
})
|
|
4979
|
-
);
|
|
4980
|
-
}
|
|
4981
|
-
/**
|
|
4982
|
-
* Resolves attachments to {@link AgentAttachment}s, uploading any `TelaFile`s.
|
|
4983
|
-
*/
|
|
4984
|
-
async resolveAttachments(attachments) {
|
|
4985
|
-
if (!attachments || attachments.length === 0)
|
|
4986
|
-
return void 0;
|
|
4987
|
-
return Promise.all(
|
|
4988
|
-
attachments.map(async (attachment) => {
|
|
4989
|
-
if (isTelaFile(attachment)) {
|
|
4990
|
-
const { fileUrl } = await uploadFile(attachment, this._client);
|
|
4991
|
-
return { vaultRef: fileUrl, filename: attachment.name ?? "file" };
|
|
4992
|
-
}
|
|
4993
|
-
return attachment;
|
|
4994
|
-
})
|
|
4995
|
-
);
|
|
4996
|
-
}
|
|
4997
|
-
}
|
|
4998
|
-
function resolveMessage(params) {
|
|
4999
|
-
if (params.prompt !== void 0 && params.message !== void 0)
|
|
5000
|
-
throw new InvalidExecutionModeError("agents.execute: provide either `prompt` or `message`, not both");
|
|
5001
|
-
return params.prompt ?? params.message ?? DEFAULT_MESSAGE;
|
|
5002
|
-
}
|
|
5003
|
-
function delay(ms, signal) {
|
|
5004
|
-
return new Promise((resolve) => {
|
|
5005
|
-
if (signal.aborted) {
|
|
5006
|
-
resolve();
|
|
5007
|
-
return;
|
|
5008
|
-
}
|
|
5009
|
-
const timeout = setTimeout(resolve, ms);
|
|
5010
|
-
signal.addEventListener("abort", () => {
|
|
5011
|
-
clearTimeout(timeout);
|
|
5012
|
-
resolve();
|
|
5013
|
-
}, { once: true });
|
|
5014
|
-
});
|
|
5015
|
-
}
|
|
5016
|
-
function toExecutionPromise(execution, params) {
|
|
5017
|
-
let started;
|
|
5018
|
-
let stream;
|
|
5019
|
-
const ensureStarted = () => started ?? (started = execution.start(params));
|
|
5020
|
-
async function* deferredStream() {
|
|
5021
|
-
await ensureStarted();
|
|
5022
|
-
yield* execution.stream;
|
|
5023
|
-
}
|
|
5024
|
-
return {
|
|
5025
|
-
then(onfulfilled, onrejected) {
|
|
5026
|
-
return ensureStarted().then(() => onfulfilled?.(execution) ?? execution).catch(onrejected);
|
|
5027
|
-
},
|
|
5028
|
-
get result() {
|
|
5029
|
-
return ensureStarted().then(() => execution.result);
|
|
5030
|
-
},
|
|
5031
|
-
get stream() {
|
|
5032
|
-
return stream ?? (stream = deferredStream());
|
|
5033
|
-
}
|
|
5034
|
-
};
|
|
5035
|
-
}
|
|
5036
|
-
|
|
5037
4705
|
var __defProp$1 = Object.defineProperty;
|
|
5038
4706
|
var __defNormalProp$1 = (obj, key, value) => key in obj ? __defProp$1(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
5039
4707
|
var __publicField$1 = (obj, key, value) => {
|
|
5040
4708
|
__defNormalProp$1(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
5041
4709
|
return value;
|
|
5042
4710
|
};
|
|
5043
|
-
class Agent {
|
|
5044
|
-
constructor(client, record) {
|
|
5045
|
-
__publicField$1(this, "_client");
|
|
5046
|
-
__publicField$1(this, "_record");
|
|
5047
|
-
this._client = client;
|
|
5048
|
-
this._record = record;
|
|
5049
|
-
}
|
|
5050
|
-
/** The agent id. */
|
|
5051
|
-
get id() {
|
|
5052
|
-
return this._record.id;
|
|
5053
|
-
}
|
|
5054
|
-
/** The agent's display title. */
|
|
5055
|
-
get title() {
|
|
5056
|
-
return this._record.title;
|
|
5057
|
-
}
|
|
5058
|
-
/** The organization that owns the agent's repository. */
|
|
5059
|
-
get organizationName() {
|
|
5060
|
-
return this._record.organizationName;
|
|
5061
|
-
}
|
|
5062
|
-
/** The agent's repository name. */
|
|
5063
|
-
get repository() {
|
|
5064
|
-
return this._record.repository;
|
|
5065
|
-
}
|
|
5066
|
-
/** The agent's declared input variables. */
|
|
5067
|
-
get inputSchema() {
|
|
5068
|
-
return this._record.inputSchema;
|
|
5069
|
-
}
|
|
5070
|
-
/** The published commit id, or `null` if the agent has never been published. */
|
|
5071
|
-
get publishedId() {
|
|
5072
|
-
return this._record.publishedId;
|
|
5073
|
-
}
|
|
5074
|
-
/** Whether the agent supports multi-turn sessions. */
|
|
5075
|
-
get isMultiturn() {
|
|
5076
|
-
return this._record.isMultiturn ?? false;
|
|
5077
|
-
}
|
|
5078
|
-
/** The full agent record as returned by the API. */
|
|
5079
|
-
get record() {
|
|
5080
|
-
return this._record;
|
|
5081
|
-
}
|
|
5082
|
-
/**
|
|
5083
|
-
* Executes the agent. By default this runs the **published** version
|
|
5084
|
-
* (`POST /agent/:id/run`); pass `{ draft: true }` to run the current draft
|
|
5085
|
-
* (`POST /agent/:id/test`).
|
|
5086
|
-
*
|
|
5087
|
-
* Returns a promise-like handle: `await` it for the {@link AgentExecution},
|
|
5088
|
-
* read `.result` for the final payload, or iterate `.stream` for live events.
|
|
5089
|
-
*
|
|
5090
|
-
* @param params - Execution parameters (notably `prompt`, `inputs`, `draft`).
|
|
5091
|
-
*/
|
|
5092
|
-
execute(params = {}) {
|
|
5093
|
-
const execution = new AgentExecution({
|
|
5094
|
-
client: this._client,
|
|
5095
|
-
agentId: this._record.id,
|
|
5096
|
-
mode: params.draft ? "test" : "run"
|
|
5097
|
-
});
|
|
5098
|
-
return toExecutionPromise(execution, params);
|
|
5099
|
-
}
|
|
5100
|
-
}
|
|
5101
|
-
|
|
5102
4711
|
const AGENT_NO_TRANSFORM = { transformCase: false };
|
|
5103
4712
|
class Agents {
|
|
5104
|
-
constructor(
|
|
5105
|
-
|
|
4713
|
+
constructor(gateway, config) {
|
|
4714
|
+
/** The delegated agent-sdk client (the `/v4/*` execution backend). */
|
|
4715
|
+
__publicField$1(this, "client");
|
|
4716
|
+
/** The Tela gateway client (`/agent` discovery + vault upload). */
|
|
4717
|
+
__publicField$1(this, "gateway");
|
|
4718
|
+
/** Memoized `agentId` → `{ organizationName, repository }` resolutions. */
|
|
4719
|
+
__publicField$1(this, "resolved", /* @__PURE__ */ new Map());
|
|
4720
|
+
/**
|
|
4721
|
+
* Streams a session's events. Pass-through to the agent-sdk client
|
|
4722
|
+
* (`GET /v4/sessions/:id`).
|
|
4723
|
+
*/
|
|
4724
|
+
__publicField$1(this, "streamSession");
|
|
4725
|
+
/**
|
|
4726
|
+
* Fetches the session timeline summary. Pass-through to the agent-sdk client
|
|
4727
|
+
* (`GET /v4/sessions/:id/timeline`).
|
|
4728
|
+
*/
|
|
4729
|
+
__publicField$1(this, "fetchTimeline");
|
|
4730
|
+
/**
|
|
4731
|
+
* Cancels a running session. Pass-through to the agent-sdk client
|
|
4732
|
+
* (`POST /v4/sessions/:id/cancel`).
|
|
4733
|
+
*/
|
|
4734
|
+
__publicField$1(this, "cancelSession");
|
|
4735
|
+
/**
|
|
4736
|
+
* Resolves a `vault://` reference to bytes/stream/json. Pass-through to the
|
|
4737
|
+
* agent-sdk client.
|
|
4738
|
+
*/
|
|
4739
|
+
__publicField$1(this, "resolveReference");
|
|
4740
|
+
this.gateway = gateway;
|
|
4741
|
+
this.client = "client" in config ? config.client : agentClient({
|
|
4742
|
+
baseUrl: config.agentBaseURL,
|
|
4743
|
+
authStrategy: config.authStrategy,
|
|
4744
|
+
vaultUrl: config.vaultURL
|
|
4745
|
+
});
|
|
4746
|
+
this.streamSession = this.client.streamSession;
|
|
4747
|
+
this.fetchTimeline = this.client.fetchTimeline;
|
|
4748
|
+
this.cancelSession = this.client.cancelSession;
|
|
4749
|
+
this.resolveReference = this.client.resolveReference;
|
|
5106
4750
|
}
|
|
5107
4751
|
/**
|
|
5108
|
-
* Lists the agents available in the workspace (optionally filtered by
|
|
4752
|
+
* Lists the agents available in the workspace (optionally filtered by
|
|
4753
|
+
* project) via the Tela gateway (`GET /agent`).
|
|
5109
4754
|
*/
|
|
5110
4755
|
async list(query = {}) {
|
|
5111
|
-
const response = await this.
|
|
4756
|
+
const response = await this.gateway.get("/agent", {
|
|
5112
4757
|
...AGENT_NO_TRANSFORM,
|
|
5113
4758
|
query
|
|
5114
4759
|
});
|
|
5115
4760
|
return response.data;
|
|
5116
4761
|
}
|
|
5117
4762
|
/**
|
|
5118
|
-
* Fetches an agent by id
|
|
4763
|
+
* Fetches an agent record by id via the Tela gateway (`GET /agent/:id`).
|
|
5119
4764
|
*/
|
|
5120
4765
|
async get(agentId) {
|
|
5121
|
-
const response = await this.
|
|
4766
|
+
const response = await this.gateway.get(`/agent/${agentId}`, {
|
|
5122
4767
|
...AGENT_NO_TRANSFORM
|
|
5123
4768
|
});
|
|
5124
|
-
return
|
|
4769
|
+
return response.data;
|
|
5125
4770
|
}
|
|
5126
4771
|
/**
|
|
5127
|
-
*
|
|
4772
|
+
* Starts (or continues) an agent session via the Tela gateway
|
|
4773
|
+
* (`POST /agent/:id/run`).
|
|
5128
4774
|
*
|
|
5129
|
-
*
|
|
5130
|
-
*
|
|
5131
|
-
*
|
|
5132
|
-
|
|
5133
|
-
|
|
5134
|
-
|
|
5135
|
-
client: this.client,
|
|
5136
|
-
agentId,
|
|
5137
|
-
mode: params.draft ? "test" : "run"
|
|
5138
|
-
});
|
|
5139
|
-
return toExecutionPromise(execution, params);
|
|
5140
|
-
}
|
|
5141
|
-
/**
|
|
5142
|
-
* Returns a resumable execution bound to an existing session id. Use it to
|
|
5143
|
-
* monitor (`.stream` / `.result`), `.cancel()`, or `.recover()` a session
|
|
5144
|
-
* that was started elsewhere.
|
|
4775
|
+
* - **New session**: pass `agentId` (+ `message`).
|
|
4776
|
+
* - **Continue**: pass `agentId` and the existing `sessionId`.
|
|
4777
|
+
*
|
|
4778
|
+
* The per-variable `inputs` map is flattened into the wire `inputSchema`
|
|
4779
|
+
* array (each entry tagged with its variable name); any `TelaFile` inputs are
|
|
4780
|
+
* uploaded to the vault first. Returns the `sessionId` to stream/inspect.
|
|
5145
4781
|
*/
|
|
5146
|
-
async
|
|
5147
|
-
|
|
4782
|
+
async run(params) {
|
|
4783
|
+
const { agentId, message, sessionId, environmentVariables, inputs, webhooks } = params;
|
|
4784
|
+
const inputSchema = inputs ? await this.buildInputSchema(inputs) : void 0;
|
|
4785
|
+
const response = await this.gateway.post(
|
|
4786
|
+
`/agent/${agentId}/run`,
|
|
4787
|
+
{
|
|
4788
|
+
...AGENT_NO_TRANSFORM,
|
|
4789
|
+
body: { message, sessionId, inputSchema, environmentVariables, webhooks }
|
|
4790
|
+
}
|
|
4791
|
+
);
|
|
4792
|
+
return response.data;
|
|
5148
4793
|
}
|
|
5149
4794
|
/**
|
|
5150
|
-
*
|
|
5151
|
-
*
|
|
4795
|
+
* Updates an agent's model, delegating to the agent-sdk client
|
|
4796
|
+
* (`PUT /v4/agents/:repository/model`). The `agentId` is resolved to the
|
|
4797
|
+
* underlying repository first.
|
|
5152
4798
|
*/
|
|
5153
|
-
async
|
|
5154
|
-
const
|
|
5155
|
-
|
|
4799
|
+
async updateAgentModel(params) {
|
|
4800
|
+
const { repository } = await this.resolveAgent(params.agentId);
|
|
4801
|
+
return this.client.updateAgentModel({
|
|
4802
|
+
repository,
|
|
4803
|
+
model: params.model,
|
|
4804
|
+
commitMessage: params.commitMessage
|
|
5156
4805
|
});
|
|
5157
|
-
return response.data;
|
|
5158
4806
|
}
|
|
5159
4807
|
/**
|
|
5160
|
-
*
|
|
4808
|
+
* Resolves an `agentId` to its `organizationName`/`repository`, memoizing the
|
|
4809
|
+
* lookup. Backed by the Tela gateway `GET /agent/:id`.
|
|
5161
4810
|
*/
|
|
5162
|
-
async
|
|
5163
|
-
const
|
|
5164
|
-
|
|
5165
|
-
|
|
5166
|
-
|
|
4811
|
+
async resolveAgent(agentId) {
|
|
4812
|
+
const cached = this.resolved.get(agentId);
|
|
4813
|
+
if (cached)
|
|
4814
|
+
return cached;
|
|
4815
|
+
const { organizationName, repository } = await this.get(agentId);
|
|
4816
|
+
const resolution = { organizationName, repository };
|
|
4817
|
+
this.resolved.set(agentId, resolution);
|
|
4818
|
+
return resolution;
|
|
5167
4819
|
}
|
|
5168
4820
|
/**
|
|
5169
|
-
*
|
|
5170
|
-
*
|
|
4821
|
+
* Flattens the per-variable {@link AgentRunInputs} map into the wire
|
|
4822
|
+
* `inputSchema` array, tagging each entry with its variable name and
|
|
4823
|
+
* uploading any {@link TelaFile} entries to the vault.
|
|
5171
4824
|
*/
|
|
5172
|
-
async
|
|
5173
|
-
const
|
|
5174
|
-
|
|
5175
|
-
|
|
4825
|
+
async buildInputSchema(inputs) {
|
|
4826
|
+
const pairs = Object.entries(inputs).flatMap(([name, value]) => {
|
|
4827
|
+
const entries = Array.isArray(value) ? value : [value];
|
|
4828
|
+
return entries.map((entry) => ({ name, entry }));
|
|
4829
|
+
});
|
|
4830
|
+
return Promise.all(pairs.map(({ name, entry }) => this.resolveEntry(name, entry)));
|
|
5176
4831
|
}
|
|
5177
4832
|
/**
|
|
5178
|
-
*
|
|
4833
|
+
* Resolves a single {@link AgentRunInputEntry} into a wire
|
|
4834
|
+
* {@link AgentRunInputItem}, uploading {@link TelaFile}s to the vault.
|
|
5179
4835
|
*/
|
|
5180
|
-
async
|
|
5181
|
-
|
|
5182
|
-
|
|
5183
|
-
|
|
5184
|
-
|
|
4836
|
+
async resolveEntry(name, entry) {
|
|
4837
|
+
if (isTelaFile(entry)) {
|
|
4838
|
+
const { fileUrl } = await uploadFile(entry, this.gateway);
|
|
4839
|
+
return { type: "file", name, vaultRef: fileUrl, filename: entry.name ?? "file" };
|
|
4840
|
+
}
|
|
4841
|
+
if ("type" in entry && entry.type === "text")
|
|
4842
|
+
return { type: "text", name, content: entry.content };
|
|
4843
|
+
if ("file" in entry) {
|
|
4844
|
+
const { fileUrl } = await uploadFile(entry.file, this.gateway);
|
|
4845
|
+
return {
|
|
4846
|
+
type: "file",
|
|
4847
|
+
name,
|
|
4848
|
+
vaultRef: fileUrl,
|
|
4849
|
+
filename: entry.filename ?? entry.file.name ?? "file",
|
|
4850
|
+
...entry.metadata ? { metadata: entry.metadata } : {}
|
|
4851
|
+
};
|
|
4852
|
+
}
|
|
4853
|
+
return {
|
|
4854
|
+
type: "file",
|
|
4855
|
+
name,
|
|
4856
|
+
vaultRef: entry.vaultRef,
|
|
4857
|
+
filename: entry.filename,
|
|
4858
|
+
...entry.metadata ? { metadata: entry.metadata } : {}
|
|
4859
|
+
};
|
|
5185
4860
|
}
|
|
5186
4861
|
}
|
|
5187
4862
|
|
|
4863
|
+
function createAuthStrategy(credentials) {
|
|
4864
|
+
if (credentials.dataToken)
|
|
4865
|
+
return new DataTokenAuthStrategy(credentials.dataToken);
|
|
4866
|
+
const bearer = credentials.apiKey ?? credentials.jwt;
|
|
4867
|
+
if (!bearer)
|
|
4868
|
+
throw new MissingAuthError();
|
|
4869
|
+
return new APIKeyAuthStrategy(bearer);
|
|
4870
|
+
}
|
|
4871
|
+
|
|
5188
4872
|
var __defProp = Object.defineProperty;
|
|
5189
4873
|
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
5190
4874
|
var __publicField = (obj, key, value) => {
|
|
@@ -5196,7 +4880,7 @@ const _TelaSDK = class _TelaSDK extends BaseClient {
|
|
|
5196
4880
|
/**
|
|
5197
4881
|
* Creates a new instance of the TelaSDK.
|
|
5198
4882
|
*/
|
|
5199
|
-
constructor({ baseURL = baseUrl, apiKey, jwt, dataToken, ...rest }) {
|
|
4883
|
+
constructor({ baseURL = baseUrl, apiKey, jwt, dataToken, agentBaseURL, vaultURL, ...rest }) {
|
|
5200
4884
|
super({ baseURL, ...rest });
|
|
5201
4885
|
__publicField(this, "opts");
|
|
5202
4886
|
__publicField(this, "apiKey");
|
|
@@ -5272,13 +4956,18 @@ const _TelaSDK = class _TelaSDK extends BaseClient {
|
|
|
5272
4956
|
*/
|
|
5273
4957
|
__publicField(this, "vault", new Vault(this));
|
|
5274
4958
|
/**
|
|
5275
|
-
* Agents API resource
|
|
5276
|
-
* stream events,
|
|
4959
|
+
* Agents API resource. Run an agent by `agentId` via the Tela gateway
|
|
4960
|
+
* (`POST /agent/:id/run`), then stream events, fetch the timeline, or cancel
|
|
4961
|
+
* by `sessionId` (delegated to `@meistrari/agent-sdk`).
|
|
5277
4962
|
*
|
|
5278
4963
|
* @example
|
|
5279
4964
|
* ```typescript
|
|
5280
|
-
* const
|
|
5281
|
-
*
|
|
4965
|
+
* const { sessionId } = await tela.agents.run({
|
|
4966
|
+
* agentId: 'agent-id',
|
|
4967
|
+
* message: 'Hello',
|
|
4968
|
+
* })
|
|
4969
|
+
* for await (const event of await tela.agents.streamSession(sessionId))
|
|
4970
|
+
* console.log(event.kind)
|
|
5282
4971
|
* ```
|
|
5283
4972
|
*/
|
|
5284
4973
|
__publicField(this, "agents");
|
|
@@ -5297,8 +4986,12 @@ const _TelaSDK = class _TelaSDK extends BaseClient {
|
|
|
5297
4986
|
this.apiKey = apiKey;
|
|
5298
4987
|
this.jwt = jwt;
|
|
5299
4988
|
this.dataToken = dataToken;
|
|
5300
|
-
this.agents = new Agents(this);
|
|
5301
4989
|
this.validateAuth();
|
|
4990
|
+
this.agents = new Agents(this, {
|
|
4991
|
+
agentBaseURL: agentBaseURL ?? baseURL,
|
|
4992
|
+
vaultURL: vaultURL ?? `${baseURL}/_services/vault`,
|
|
4993
|
+
authStrategy: createAuthStrategy({ apiKey, jwt, dataToken })
|
|
4994
|
+
});
|
|
5302
4995
|
}
|
|
5303
4996
|
get authToken() {
|
|
5304
4997
|
return this.apiKey || this.jwt || this.dataToken;
|
|
@@ -5381,4 +5074,4 @@ function createTelaClient(opts) {
|
|
|
5381
5074
|
return new TelaSDK(opts);
|
|
5382
5075
|
}
|
|
5383
5076
|
|
|
5384
|
-
export { APIError,
|
|
5077
|
+
export { APIError, AgentExecutionFailedError, Agents, AuthenticationError, AuthorizationError, BadRequestError, BaseClient, BatchExecutionFailedError, ConflictApiKeyAndJWTError, ConflictAuthMethodsError, ConflictError, ConnectionError, ConnectionTimeout, EmptyFileError, ExecutionFailedError, ExecutionNotStartedError, FileUploadError, InternalServerError, InvalidExecutionModeError, InvalidFileURL, MissingApiKeyOrJWTError, MissingAuthError, NotFoundError, RateLimitError, TaskFailedError, Tasks, TelaError, TelaFile, TelaFileSchema, TelaSDK, UnprocessableEntityError, UserAbortError, Vault, createTelaClient, extractTaskOutput, isTelaFile, isTelaFileArray, normalizeTaskStatus, toError };
|