@mastra/client-js 0.0.0-message-list-update-20250715150321 → 0.0.0-monorepo-binary-20251013210052
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/CHANGELOG.md +1284 -3
- package/README.md +6 -7
- package/dist/client.d.ts +278 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/example.d.ts +2 -0
- package/dist/example.d.ts.map +1 -0
- package/dist/index.cjs +2187 -1178
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +5 -1194
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +2187 -1180
- package/dist/index.js.map +1 -0
- package/dist/resources/a2a.d.ts +41 -0
- package/dist/resources/a2a.d.ts.map +1 -0
- package/dist/resources/agent-builder.d.ts +160 -0
- package/dist/resources/agent-builder.d.ts.map +1 -0
- package/dist/resources/agent.d.ts +184 -0
- package/dist/resources/agent.d.ts.map +1 -0
- package/dist/resources/base.d.ts +13 -0
- package/dist/resources/base.d.ts.map +1 -0
- package/dist/resources/index.d.ts +11 -0
- package/dist/resources/index.d.ts.map +1 -0
- package/dist/resources/mcp-tool.d.ts +28 -0
- package/dist/resources/mcp-tool.d.ts.map +1 -0
- package/dist/resources/memory-thread.d.ts +53 -0
- package/dist/resources/memory-thread.d.ts.map +1 -0
- package/dist/resources/network-memory-thread.d.ts +47 -0
- package/dist/resources/network-memory-thread.d.ts.map +1 -0
- package/dist/resources/observability.d.ts +35 -0
- package/dist/resources/observability.d.ts.map +1 -0
- package/dist/resources/tool.d.ts +24 -0
- package/dist/resources/tool.d.ts.map +1 -0
- package/dist/resources/vector.d.ts +51 -0
- package/dist/resources/vector.d.ts.map +1 -0
- package/dist/resources/workflow.d.ts +269 -0
- package/dist/resources/workflow.d.ts.map +1 -0
- package/dist/tools.d.ts +22 -0
- package/dist/tools.d.ts.map +1 -0
- package/dist/types.d.ts +479 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/utils/index.d.ts +5 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/process-client-tools.d.ts +3 -0
- package/dist/utils/process-client-tools.d.ts.map +1 -0
- package/dist/utils/process-mastra-stream.d.ts +11 -0
- package/dist/utils/process-mastra-stream.d.ts.map +1 -0
- package/dist/utils/zod-to-json-schema.d.ts +3 -0
- package/dist/utils/zod-to-json-schema.d.ts.map +1 -0
- package/package.json +25 -14
- package/.turbo/turbo-build.log +0 -19
- package/dist/index.d.cts +0 -1194
- package/eslint.config.js +0 -6
- package/src/adapters/agui.test.ts +0 -180
- package/src/adapters/agui.ts +0 -239
- package/src/client.ts +0 -526
- package/src/example.ts +0 -95
- package/src/index.test.ts +0 -830
- package/src/index.ts +0 -2
- package/src/resources/a2a.ts +0 -88
- package/src/resources/agent.ts +0 -800
- package/src/resources/base.ts +0 -72
- package/src/resources/index.ts +0 -10
- package/src/resources/legacy-workflow.ts +0 -242
- package/src/resources/mcp-tool.ts +0 -48
- package/src/resources/memory-thread.ts +0 -63
- package/src/resources/network-memory-thread.ts +0 -63
- package/src/resources/network.ts +0 -85
- package/src/resources/tool.ts +0 -45
- package/src/resources/vNextNetwork.ts +0 -194
- package/src/resources/vector.ts +0 -83
- package/src/resources/workflow.ts +0 -396
- package/src/types.ts +0 -428
- package/src/utils/index.ts +0 -11
- package/src/utils/process-client-tools.ts +0 -32
- package/src/utils/zod-to-json-schema.ts +0 -10
- package/tsconfig.json +0 -5
- package/vitest.config.js +0 -8
package/dist/index.cjs
CHANGED
|
@@ -1,216 +1,62 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var client = require('@ag-ui/client');
|
|
4
|
-
var rxjs = require('rxjs');
|
|
5
3
|
var uiUtils = require('@ai-sdk/ui-utils');
|
|
6
|
-
var zod = require('zod');
|
|
7
|
-
var originalZodToJsonSchema = require('zod-to-json-schema');
|
|
8
|
-
var tools = require('@mastra/core/tools');
|
|
9
4
|
var uuid = require('@lukeed/uuid');
|
|
10
5
|
var runtimeContext = require('@mastra/core/runtime-context');
|
|
6
|
+
var isVercelTool = require('@mastra/core/tools/is-vercel-tool');
|
|
7
|
+
var zod = require('zod');
|
|
8
|
+
var originalZodToJsonSchema = require('zod-to-json-schema');
|
|
11
9
|
|
|
12
10
|
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
13
11
|
|
|
14
12
|
var originalZodToJsonSchema__default = /*#__PURE__*/_interopDefault(originalZodToJsonSchema);
|
|
15
13
|
|
|
16
|
-
// src/
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
super({
|
|
22
|
-
agentId,
|
|
23
|
-
...rest
|
|
24
|
-
});
|
|
25
|
-
this.agent = agent;
|
|
26
|
-
this.resourceId = resourceId;
|
|
27
|
-
}
|
|
28
|
-
run(input) {
|
|
29
|
-
return new rxjs.Observable((subscriber) => {
|
|
30
|
-
const convertedMessages = convertMessagesToMastraMessages(input.messages);
|
|
31
|
-
subscriber.next({
|
|
32
|
-
type: client.EventType.RUN_STARTED,
|
|
33
|
-
threadId: input.threadId,
|
|
34
|
-
runId: input.runId
|
|
35
|
-
});
|
|
36
|
-
this.agent.stream({
|
|
37
|
-
threadId: input.threadId,
|
|
38
|
-
resourceId: this.resourceId ?? "",
|
|
39
|
-
runId: input.runId,
|
|
40
|
-
messages: convertedMessages,
|
|
41
|
-
clientTools: input.tools.reduce(
|
|
42
|
-
(acc, tool) => {
|
|
43
|
-
acc[tool.name] = {
|
|
44
|
-
id: tool.name,
|
|
45
|
-
description: tool.description,
|
|
46
|
-
inputSchema: tool.parameters
|
|
47
|
-
};
|
|
48
|
-
return acc;
|
|
49
|
-
},
|
|
50
|
-
{}
|
|
51
|
-
)
|
|
52
|
-
}).then((response) => {
|
|
53
|
-
let currentMessageId = void 0;
|
|
54
|
-
let isInTextMessage = false;
|
|
55
|
-
return response.processDataStream({
|
|
56
|
-
onTextPart: (text) => {
|
|
57
|
-
if (currentMessageId === void 0) {
|
|
58
|
-
currentMessageId = generateUUID();
|
|
59
|
-
const message2 = {
|
|
60
|
-
type: client.EventType.TEXT_MESSAGE_START,
|
|
61
|
-
messageId: currentMessageId,
|
|
62
|
-
role: "assistant"
|
|
63
|
-
};
|
|
64
|
-
subscriber.next(message2);
|
|
65
|
-
isInTextMessage = true;
|
|
66
|
-
}
|
|
67
|
-
const message = {
|
|
68
|
-
type: client.EventType.TEXT_MESSAGE_CONTENT,
|
|
69
|
-
messageId: currentMessageId,
|
|
70
|
-
delta: text
|
|
71
|
-
};
|
|
72
|
-
subscriber.next(message);
|
|
73
|
-
},
|
|
74
|
-
onFinishMessagePart: () => {
|
|
75
|
-
if (currentMessageId !== void 0) {
|
|
76
|
-
const message = {
|
|
77
|
-
type: client.EventType.TEXT_MESSAGE_END,
|
|
78
|
-
messageId: currentMessageId
|
|
79
|
-
};
|
|
80
|
-
subscriber.next(message);
|
|
81
|
-
isInTextMessage = false;
|
|
82
|
-
}
|
|
83
|
-
subscriber.next({
|
|
84
|
-
type: client.EventType.RUN_FINISHED,
|
|
85
|
-
threadId: input.threadId,
|
|
86
|
-
runId: input.runId
|
|
87
|
-
});
|
|
88
|
-
subscriber.complete();
|
|
89
|
-
},
|
|
90
|
-
onToolCallPart(streamPart) {
|
|
91
|
-
const parentMessageId = currentMessageId || generateUUID();
|
|
92
|
-
if (isInTextMessage) {
|
|
93
|
-
const message = {
|
|
94
|
-
type: client.EventType.TEXT_MESSAGE_END,
|
|
95
|
-
messageId: parentMessageId
|
|
96
|
-
};
|
|
97
|
-
subscriber.next(message);
|
|
98
|
-
isInTextMessage = false;
|
|
99
|
-
}
|
|
100
|
-
subscriber.next({
|
|
101
|
-
type: client.EventType.TOOL_CALL_START,
|
|
102
|
-
toolCallId: streamPart.toolCallId,
|
|
103
|
-
toolCallName: streamPart.toolName,
|
|
104
|
-
parentMessageId
|
|
105
|
-
});
|
|
106
|
-
subscriber.next({
|
|
107
|
-
type: client.EventType.TOOL_CALL_ARGS,
|
|
108
|
-
toolCallId: streamPart.toolCallId,
|
|
109
|
-
delta: JSON.stringify(streamPart.args),
|
|
110
|
-
parentMessageId
|
|
111
|
-
});
|
|
112
|
-
subscriber.next({
|
|
113
|
-
type: client.EventType.TOOL_CALL_END,
|
|
114
|
-
toolCallId: streamPart.toolCallId,
|
|
115
|
-
parentMessageId
|
|
116
|
-
});
|
|
117
|
-
}
|
|
118
|
-
});
|
|
119
|
-
}).catch((error) => {
|
|
120
|
-
console.error("error", error);
|
|
121
|
-
subscriber.error(error);
|
|
122
|
-
});
|
|
123
|
-
return () => {
|
|
124
|
-
};
|
|
125
|
-
});
|
|
126
|
-
}
|
|
127
|
-
};
|
|
128
|
-
function generateUUID() {
|
|
129
|
-
if (typeof crypto !== "undefined") {
|
|
130
|
-
if (typeof crypto.randomUUID === "function") {
|
|
131
|
-
return crypto.randomUUID();
|
|
132
|
-
}
|
|
133
|
-
if (typeof crypto.getRandomValues === "function") {
|
|
134
|
-
const buffer = new Uint8Array(16);
|
|
135
|
-
crypto.getRandomValues(buffer);
|
|
136
|
-
buffer[6] = buffer[6] & 15 | 64;
|
|
137
|
-
buffer[8] = buffer[8] & 63 | 128;
|
|
138
|
-
let hex = "";
|
|
139
|
-
for (let i = 0; i < 16; i++) {
|
|
140
|
-
hex += buffer[i].toString(16).padStart(2, "0");
|
|
141
|
-
if (i === 3 || i === 5 || i === 7 || i === 9) hex += "-";
|
|
142
|
-
}
|
|
143
|
-
return hex;
|
|
14
|
+
// src/resources/agent.ts
|
|
15
|
+
function parseClientRuntimeContext(runtimeContext$1) {
|
|
16
|
+
if (runtimeContext$1) {
|
|
17
|
+
if (runtimeContext$1 instanceof runtimeContext.RuntimeContext) {
|
|
18
|
+
return Object.fromEntries(runtimeContext$1.entries());
|
|
144
19
|
}
|
|
20
|
+
return runtimeContext$1;
|
|
145
21
|
}
|
|
146
|
-
return
|
|
147
|
-
const r = Math.random() * 16 | 0;
|
|
148
|
-
const v = c === "x" ? r : r & 3 | 8;
|
|
149
|
-
return v.toString(16);
|
|
150
|
-
});
|
|
22
|
+
return void 0;
|
|
151
23
|
}
|
|
152
|
-
function
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
if (message.role === "assistant") {
|
|
156
|
-
const parts = message.content ? [{ type: "text", text: message.content }] : [];
|
|
157
|
-
for (const toolCall of message.toolCalls ?? []) {
|
|
158
|
-
parts.push({
|
|
159
|
-
type: "tool-call",
|
|
160
|
-
toolCallId: toolCall.id,
|
|
161
|
-
toolName: toolCall.function.name,
|
|
162
|
-
args: JSON.parse(toolCall.function.arguments)
|
|
163
|
-
});
|
|
164
|
-
}
|
|
165
|
-
result.push({
|
|
166
|
-
role: "assistant",
|
|
167
|
-
content: parts
|
|
168
|
-
});
|
|
169
|
-
if (message.toolCalls?.length) {
|
|
170
|
-
result.push({
|
|
171
|
-
role: "tool",
|
|
172
|
-
content: message.toolCalls.map((toolCall) => ({
|
|
173
|
-
type: "tool-result",
|
|
174
|
-
toolCallId: toolCall.id,
|
|
175
|
-
toolName: toolCall.function.name,
|
|
176
|
-
result: JSON.parse(toolCall.function.arguments)
|
|
177
|
-
}))
|
|
178
|
-
});
|
|
179
|
-
}
|
|
180
|
-
} else if (message.role === "user") {
|
|
181
|
-
result.push({
|
|
182
|
-
role: "user",
|
|
183
|
-
content: message.content || ""
|
|
184
|
-
});
|
|
185
|
-
} else if (message.role === "tool") {
|
|
186
|
-
result.push({
|
|
187
|
-
role: "tool",
|
|
188
|
-
content: [
|
|
189
|
-
{
|
|
190
|
-
type: "tool-result",
|
|
191
|
-
toolCallId: message.toolCallId,
|
|
192
|
-
toolName: "unknown",
|
|
193
|
-
result: message.content
|
|
194
|
-
}
|
|
195
|
-
]
|
|
196
|
-
});
|
|
197
|
-
}
|
|
24
|
+
function base64RuntimeContext(runtimeContext) {
|
|
25
|
+
if (runtimeContext) {
|
|
26
|
+
return btoa(JSON.stringify(runtimeContext));
|
|
198
27
|
}
|
|
199
|
-
return
|
|
28
|
+
return void 0;
|
|
29
|
+
}
|
|
30
|
+
function runtimeContextQueryString(runtimeContext) {
|
|
31
|
+
const runtimeContextParam = base64RuntimeContext(parseClientRuntimeContext(runtimeContext));
|
|
32
|
+
if (!runtimeContextParam) return "";
|
|
33
|
+
const searchParams = new URLSearchParams();
|
|
34
|
+
searchParams.set("runtimeContext", runtimeContextParam);
|
|
35
|
+
const queryString = searchParams.toString();
|
|
36
|
+
return queryString ? `?${queryString}` : "";
|
|
37
|
+
}
|
|
38
|
+
function isZodType(value) {
|
|
39
|
+
return typeof value === "object" && value !== null && "_def" in value && "parse" in value && typeof value.parse === "function" && "safeParse" in value && typeof value.safeParse === "function";
|
|
200
40
|
}
|
|
201
41
|
function zodToJsonSchema(zodSchema) {
|
|
202
|
-
if (!(zodSchema
|
|
42
|
+
if (!isZodType(zodSchema)) {
|
|
203
43
|
return zodSchema;
|
|
204
44
|
}
|
|
205
|
-
|
|
45
|
+
if ("toJSONSchema" in zod.z) {
|
|
46
|
+
const fn = "toJSONSchema";
|
|
47
|
+
return zod.z[fn].call(zod.z, zodSchema);
|
|
48
|
+
}
|
|
49
|
+
return originalZodToJsonSchema__default.default(zodSchema, { $refStrategy: "relative" });
|
|
206
50
|
}
|
|
51
|
+
|
|
52
|
+
// src/utils/process-client-tools.ts
|
|
207
53
|
function processClientTools(clientTools) {
|
|
208
54
|
if (!clientTools) {
|
|
209
55
|
return void 0;
|
|
210
56
|
}
|
|
211
57
|
return Object.fromEntries(
|
|
212
58
|
Object.entries(clientTools).map(([key, value]) => {
|
|
213
|
-
if (
|
|
59
|
+
if (isVercelTool.isVercelTool(value)) {
|
|
214
60
|
return [
|
|
215
61
|
key,
|
|
216
62
|
{
|
|
@@ -232,6 +78,60 @@ function processClientTools(clientTools) {
|
|
|
232
78
|
);
|
|
233
79
|
}
|
|
234
80
|
|
|
81
|
+
// src/utils/process-mastra-stream.ts
|
|
82
|
+
async function sharedProcessMastraStream({
|
|
83
|
+
stream,
|
|
84
|
+
onChunk
|
|
85
|
+
}) {
|
|
86
|
+
const reader = stream.getReader();
|
|
87
|
+
const decoder = new TextDecoder();
|
|
88
|
+
let buffer = "";
|
|
89
|
+
try {
|
|
90
|
+
while (true) {
|
|
91
|
+
const { done, value } = await reader.read();
|
|
92
|
+
if (done) break;
|
|
93
|
+
buffer += decoder.decode(value, { stream: true });
|
|
94
|
+
const lines = buffer.split("\n\n");
|
|
95
|
+
buffer = lines.pop() || "";
|
|
96
|
+
for (const line of lines) {
|
|
97
|
+
if (line.startsWith("data: ")) {
|
|
98
|
+
const data = line.slice(6);
|
|
99
|
+
if (data === "[DONE]") {
|
|
100
|
+
console.info("\u{1F3C1} Stream finished");
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
try {
|
|
104
|
+
const json = JSON.parse(data);
|
|
105
|
+
await onChunk(json);
|
|
106
|
+
} catch (error) {
|
|
107
|
+
console.error("\u274C JSON parse error:", error, "Data:", data);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
} finally {
|
|
113
|
+
reader.releaseLock();
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
async function processMastraNetworkStream({
|
|
117
|
+
stream,
|
|
118
|
+
onChunk
|
|
119
|
+
}) {
|
|
120
|
+
return sharedProcessMastraStream({
|
|
121
|
+
stream,
|
|
122
|
+
onChunk
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
async function processMastraStream({
|
|
126
|
+
stream,
|
|
127
|
+
onChunk
|
|
128
|
+
}) {
|
|
129
|
+
return sharedProcessMastraStream({
|
|
130
|
+
stream,
|
|
131
|
+
onChunk
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
|
|
235
135
|
// src/resources/base.ts
|
|
236
136
|
var BaseResource = class {
|
|
237
137
|
options;
|
|
@@ -246,20 +146,21 @@ var BaseResource = class {
|
|
|
246
146
|
*/
|
|
247
147
|
async request(path, options = {}) {
|
|
248
148
|
let lastError = null;
|
|
249
|
-
const { baseUrl, retries = 3, backoffMs = 100, maxBackoffMs = 1e3, headers = {} } = this.options;
|
|
149
|
+
const { baseUrl, retries = 3, backoffMs = 100, maxBackoffMs = 1e3, headers = {}, credentials } = this.options;
|
|
250
150
|
let delay = backoffMs;
|
|
251
151
|
for (let attempt = 0; attempt <= retries; attempt++) {
|
|
252
152
|
try {
|
|
253
153
|
const response = await fetch(`${baseUrl.replace(/\/$/, "")}${path}`, {
|
|
254
154
|
...options,
|
|
255
155
|
headers: {
|
|
256
|
-
...options.method === "POST" || options.method === "PUT" ? { "content-type": "application/json" } : {},
|
|
156
|
+
...options.body && !(options.body instanceof FormData) && (options.method === "POST" || options.method === "PUT") ? { "content-type": "application/json" } : {},
|
|
257
157
|
...headers,
|
|
258
158
|
...options.headers
|
|
259
159
|
// TODO: Bring this back once we figure out what we/users need to do to make this work with cross-origin requests
|
|
260
160
|
// 'x-mastra-client-type': 'js',
|
|
261
161
|
},
|
|
262
162
|
signal: this.options.abortSignal,
|
|
163
|
+
credentials: options.credentials ?? credentials,
|
|
263
164
|
body: options.body instanceof FormData ? options.body : options.body ? JSON.stringify(options.body) : void 0
|
|
264
165
|
});
|
|
265
166
|
if (!response.ok) {
|
|
@@ -292,14 +193,62 @@ var BaseResource = class {
|
|
|
292
193
|
throw lastError || new Error("Request failed");
|
|
293
194
|
}
|
|
294
195
|
};
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
196
|
+
|
|
197
|
+
// src/resources/agent.ts
|
|
198
|
+
async function executeToolCallAndRespond({
|
|
199
|
+
response,
|
|
200
|
+
params,
|
|
201
|
+
runId,
|
|
202
|
+
resourceId,
|
|
203
|
+
threadId,
|
|
204
|
+
runtimeContext,
|
|
205
|
+
respondFn
|
|
206
|
+
}) {
|
|
207
|
+
if (response.finishReason === "tool-calls") {
|
|
208
|
+
const toolCalls = response.toolCalls;
|
|
209
|
+
if (!toolCalls || !Array.isArray(toolCalls)) {
|
|
210
|
+
return response;
|
|
211
|
+
}
|
|
212
|
+
for (const toolCall of toolCalls) {
|
|
213
|
+
const clientTool = params.clientTools?.[toolCall.toolName];
|
|
214
|
+
if (clientTool && clientTool.execute) {
|
|
215
|
+
const result = await clientTool.execute(
|
|
216
|
+
{
|
|
217
|
+
context: toolCall?.args,
|
|
218
|
+
runId,
|
|
219
|
+
resourceId,
|
|
220
|
+
threadId,
|
|
221
|
+
runtimeContext,
|
|
222
|
+
tracingContext: { currentSpan: void 0 },
|
|
223
|
+
suspend: async () => {
|
|
224
|
+
}
|
|
225
|
+
},
|
|
226
|
+
{
|
|
227
|
+
messages: response.messages,
|
|
228
|
+
toolCallId: toolCall?.toolCallId
|
|
229
|
+
}
|
|
230
|
+
);
|
|
231
|
+
const updatedMessages = [
|
|
232
|
+
...response.response.messages || [],
|
|
233
|
+
{
|
|
234
|
+
role: "tool",
|
|
235
|
+
content: [
|
|
236
|
+
{
|
|
237
|
+
type: "tool-result",
|
|
238
|
+
toolCallId: toolCall.toolCallId,
|
|
239
|
+
toolName: toolCall.toolName,
|
|
240
|
+
result
|
|
241
|
+
}
|
|
242
|
+
]
|
|
243
|
+
}
|
|
244
|
+
];
|
|
245
|
+
return respondFn({
|
|
246
|
+
...params,
|
|
247
|
+
messages: updatedMessages
|
|
248
|
+
});
|
|
249
|
+
}
|
|
299
250
|
}
|
|
300
|
-
return runtimeContext$1;
|
|
301
251
|
}
|
|
302
|
-
return void 0;
|
|
303
252
|
}
|
|
304
253
|
var AgentVoice = class extends BaseResource {
|
|
305
254
|
constructor(options, agentId) {
|
|
@@ -342,17 +291,21 @@ var AgentVoice = class extends BaseResource {
|
|
|
342
291
|
}
|
|
343
292
|
/**
|
|
344
293
|
* Get available speakers for the agent's voice provider
|
|
294
|
+
* @param runtimeContext - Optional runtime context to pass as query parameter
|
|
295
|
+
* @param runtimeContext - Optional runtime context to pass as query parameter
|
|
345
296
|
* @returns Promise containing list of available speakers
|
|
346
297
|
*/
|
|
347
|
-
getSpeakers() {
|
|
348
|
-
return this.request(`/api/agents/${this.agentId}/voice/speakers`);
|
|
298
|
+
getSpeakers(runtimeContext) {
|
|
299
|
+
return this.request(`/api/agents/${this.agentId}/voice/speakers${runtimeContextQueryString(runtimeContext)}`);
|
|
349
300
|
}
|
|
350
301
|
/**
|
|
351
302
|
* Get the listener configuration for the agent's voice provider
|
|
303
|
+
* @param runtimeContext - Optional runtime context to pass as query parameter
|
|
304
|
+
* @param runtimeContext - Optional runtime context to pass as query parameter
|
|
352
305
|
* @returns Promise containing a check if the agent has listening capabilities
|
|
353
306
|
*/
|
|
354
|
-
getListener() {
|
|
355
|
-
return this.request(`/api/agents/${this.agentId}/voice/listener`);
|
|
307
|
+
getListener(runtimeContext) {
|
|
308
|
+
return this.request(`/api/agents/${this.agentId}/voice/listener${runtimeContextQueryString(runtimeContext)}`);
|
|
356
309
|
}
|
|
357
310
|
};
|
|
358
311
|
var Agent = class extends BaseResource {
|
|
@@ -364,12 +317,13 @@ var Agent = class extends BaseResource {
|
|
|
364
317
|
voice;
|
|
365
318
|
/**
|
|
366
319
|
* Retrieves details about the agent
|
|
320
|
+
* @param runtimeContext - Optional runtime context to pass as query parameter
|
|
367
321
|
* @returns Promise containing agent details including model and instructions
|
|
368
322
|
*/
|
|
369
|
-
details() {
|
|
370
|
-
return this.request(`/api/agents/${this.agentId}`);
|
|
323
|
+
details(runtimeContext) {
|
|
324
|
+
return this.request(`/api/agents/${this.agentId}${runtimeContextQueryString(runtimeContext)}`);
|
|
371
325
|
}
|
|
372
|
-
async
|
|
326
|
+
async generateLegacy(params) {
|
|
373
327
|
const processedParams = {
|
|
374
328
|
...params,
|
|
375
329
|
output: params.output ? zodToJsonSchema(params.output) : void 0,
|
|
@@ -378,10 +332,13 @@ var Agent = class extends BaseResource {
|
|
|
378
332
|
clientTools: processClientTools(params.clientTools)
|
|
379
333
|
};
|
|
380
334
|
const { runId, resourceId, threadId, runtimeContext } = processedParams;
|
|
381
|
-
const response = await this.request(
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
335
|
+
const response = await this.request(
|
|
336
|
+
`/api/agents/${this.agentId}/generate-legacy`,
|
|
337
|
+
{
|
|
338
|
+
method: "POST",
|
|
339
|
+
body: processedParams
|
|
340
|
+
}
|
|
341
|
+
);
|
|
385
342
|
if (response.finishReason === "tool-calls") {
|
|
386
343
|
const toolCalls = response.toolCalls;
|
|
387
344
|
if (!toolCalls || !Array.isArray(toolCalls)) {
|
|
@@ -391,17 +348,22 @@ var Agent = class extends BaseResource {
|
|
|
391
348
|
const clientTool = params.clientTools?.[toolCall.toolName];
|
|
392
349
|
if (clientTool && clientTool.execute) {
|
|
393
350
|
const result = await clientTool.execute(
|
|
394
|
-
{
|
|
351
|
+
{
|
|
352
|
+
context: toolCall?.args,
|
|
353
|
+
runId,
|
|
354
|
+
resourceId,
|
|
355
|
+
threadId,
|
|
356
|
+
runtimeContext,
|
|
357
|
+
tracingContext: { currentSpan: void 0 },
|
|
358
|
+
suspend: async () => {
|
|
359
|
+
}
|
|
360
|
+
},
|
|
395
361
|
{
|
|
396
362
|
messages: response.messages,
|
|
397
363
|
toolCallId: toolCall?.toolCallId
|
|
398
364
|
}
|
|
399
365
|
);
|
|
400
366
|
const updatedMessages = [
|
|
401
|
-
{
|
|
402
|
-
role: "user",
|
|
403
|
-
content: params.messages
|
|
404
|
-
},
|
|
405
367
|
...response.response.messages,
|
|
406
368
|
{
|
|
407
369
|
role: "tool",
|
|
@@ -424,14 +386,54 @@ var Agent = class extends BaseResource {
|
|
|
424
386
|
}
|
|
425
387
|
return response;
|
|
426
388
|
}
|
|
389
|
+
async generate(messagesOrParams, options) {
|
|
390
|
+
let params;
|
|
391
|
+
if (typeof messagesOrParams === "object" && "messages" in messagesOrParams) {
|
|
392
|
+
params = messagesOrParams;
|
|
393
|
+
} else {
|
|
394
|
+
params = {
|
|
395
|
+
messages: messagesOrParams,
|
|
396
|
+
...options
|
|
397
|
+
};
|
|
398
|
+
}
|
|
399
|
+
const processedParams = {
|
|
400
|
+
...params,
|
|
401
|
+
output: params.output ? zodToJsonSchema(params.output) : void 0,
|
|
402
|
+
runtimeContext: parseClientRuntimeContext(params.runtimeContext),
|
|
403
|
+
clientTools: processClientTools(params.clientTools),
|
|
404
|
+
structuredOutput: params.structuredOutput ? {
|
|
405
|
+
...params.structuredOutput,
|
|
406
|
+
schema: zodToJsonSchema(params.structuredOutput.schema)
|
|
407
|
+
} : void 0
|
|
408
|
+
};
|
|
409
|
+
const { runId, resourceId, threadId, runtimeContext } = processedParams;
|
|
410
|
+
const response = await this.request(
|
|
411
|
+
`/api/agents/${this.agentId}/generate`,
|
|
412
|
+
{
|
|
413
|
+
method: "POST",
|
|
414
|
+
body: processedParams
|
|
415
|
+
}
|
|
416
|
+
);
|
|
417
|
+
if (response.finishReason === "tool-calls") {
|
|
418
|
+
return executeToolCallAndRespond({
|
|
419
|
+
response,
|
|
420
|
+
params,
|
|
421
|
+
runId,
|
|
422
|
+
resourceId,
|
|
423
|
+
threadId,
|
|
424
|
+
runtimeContext,
|
|
425
|
+
respondFn: this.generate.bind(this)
|
|
426
|
+
});
|
|
427
|
+
}
|
|
428
|
+
return response;
|
|
429
|
+
}
|
|
427
430
|
async processChatResponse({
|
|
428
431
|
stream,
|
|
429
432
|
update,
|
|
430
433
|
onToolCall,
|
|
431
434
|
onFinish,
|
|
432
435
|
getCurrentDate = () => /* @__PURE__ */ new Date(),
|
|
433
|
-
lastMessage
|
|
434
|
-
streamProtocol
|
|
436
|
+
lastMessage
|
|
435
437
|
}) {
|
|
436
438
|
const replaceLastMessage = lastMessage?.role === "assistant";
|
|
437
439
|
let step = replaceLastMessage ? 1 + // find max step in existing tool invocations:
|
|
@@ -492,264 +494,566 @@ var Agent = class extends BaseResource {
|
|
|
492
494
|
replaceLastMessage
|
|
493
495
|
});
|
|
494
496
|
}
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
497
|
+
await uiUtils.processDataStream({
|
|
498
|
+
stream,
|
|
499
|
+
onTextPart(value) {
|
|
500
|
+
if (currentTextPart == null) {
|
|
501
|
+
currentTextPart = {
|
|
502
|
+
type: "text",
|
|
503
|
+
text: value
|
|
504
|
+
};
|
|
505
|
+
message.parts.push(currentTextPart);
|
|
506
|
+
} else {
|
|
507
|
+
currentTextPart.text += value;
|
|
501
508
|
}
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
if (
|
|
509
|
-
|
|
510
|
-
type: "text",
|
|
511
|
-
text: value
|
|
512
|
-
};
|
|
513
|
-
message.parts.push(currentTextPart);
|
|
514
|
-
} else {
|
|
515
|
-
currentTextPart.text += value;
|
|
516
|
-
}
|
|
517
|
-
message.content += value;
|
|
518
|
-
execUpdate();
|
|
519
|
-
},
|
|
520
|
-
onReasoningPart(value) {
|
|
521
|
-
if (currentReasoningTextDetail == null) {
|
|
522
|
-
currentReasoningTextDetail = { type: "text", text: value };
|
|
523
|
-
if (currentReasoningPart != null) {
|
|
524
|
-
currentReasoningPart.details.push(currentReasoningTextDetail);
|
|
525
|
-
}
|
|
526
|
-
} else {
|
|
527
|
-
currentReasoningTextDetail.text += value;
|
|
528
|
-
}
|
|
529
|
-
if (currentReasoningPart == null) {
|
|
530
|
-
currentReasoningPart = {
|
|
531
|
-
type: "reasoning",
|
|
532
|
-
reasoning: value,
|
|
533
|
-
details: [currentReasoningTextDetail]
|
|
534
|
-
};
|
|
535
|
-
message.parts.push(currentReasoningPart);
|
|
536
|
-
} else {
|
|
537
|
-
currentReasoningPart.reasoning += value;
|
|
538
|
-
}
|
|
539
|
-
message.reasoning = (message.reasoning ?? "") + value;
|
|
540
|
-
execUpdate();
|
|
541
|
-
},
|
|
542
|
-
onReasoningSignaturePart(value) {
|
|
543
|
-
if (currentReasoningTextDetail != null) {
|
|
544
|
-
currentReasoningTextDetail.signature = value.signature;
|
|
545
|
-
}
|
|
546
|
-
},
|
|
547
|
-
onRedactedReasoningPart(value) {
|
|
548
|
-
if (currentReasoningPart == null) {
|
|
549
|
-
currentReasoningPart = {
|
|
550
|
-
type: "reasoning",
|
|
551
|
-
reasoning: "",
|
|
552
|
-
details: []
|
|
553
|
-
};
|
|
554
|
-
message.parts.push(currentReasoningPart);
|
|
509
|
+
message.content += value;
|
|
510
|
+
execUpdate();
|
|
511
|
+
},
|
|
512
|
+
onReasoningPart(value) {
|
|
513
|
+
if (currentReasoningTextDetail == null) {
|
|
514
|
+
currentReasoningTextDetail = { type: "text", text: value };
|
|
515
|
+
if (currentReasoningPart != null) {
|
|
516
|
+
currentReasoningPart.details.push(currentReasoningTextDetail);
|
|
555
517
|
}
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
518
|
+
} else {
|
|
519
|
+
currentReasoningTextDetail.text += value;
|
|
520
|
+
}
|
|
521
|
+
if (currentReasoningPart == null) {
|
|
522
|
+
currentReasoningPart = {
|
|
523
|
+
type: "reasoning",
|
|
524
|
+
reasoning: value,
|
|
525
|
+
details: [currentReasoningTextDetail]
|
|
526
|
+
};
|
|
527
|
+
message.parts.push(currentReasoningPart);
|
|
528
|
+
} else {
|
|
529
|
+
currentReasoningPart.reasoning += value;
|
|
530
|
+
}
|
|
531
|
+
message.reasoning = (message.reasoning ?? "") + value;
|
|
532
|
+
execUpdate();
|
|
533
|
+
},
|
|
534
|
+
onReasoningSignaturePart(value) {
|
|
535
|
+
if (currentReasoningTextDetail != null) {
|
|
536
|
+
currentReasoningTextDetail.signature = value.signature;
|
|
537
|
+
}
|
|
538
|
+
},
|
|
539
|
+
onRedactedReasoningPart(value) {
|
|
540
|
+
if (currentReasoningPart == null) {
|
|
541
|
+
currentReasoningPart = {
|
|
542
|
+
type: "reasoning",
|
|
543
|
+
reasoning: "",
|
|
544
|
+
details: []
|
|
545
|
+
};
|
|
546
|
+
message.parts.push(currentReasoningPart);
|
|
547
|
+
}
|
|
548
|
+
currentReasoningPart.details.push({
|
|
549
|
+
type: "redacted",
|
|
550
|
+
data: value.data
|
|
551
|
+
});
|
|
552
|
+
currentReasoningTextDetail = void 0;
|
|
553
|
+
execUpdate();
|
|
554
|
+
},
|
|
555
|
+
onFilePart(value) {
|
|
556
|
+
message.parts.push({
|
|
557
|
+
type: "file",
|
|
558
|
+
mimeType: value.mimeType,
|
|
559
|
+
data: value.data
|
|
560
|
+
});
|
|
561
|
+
execUpdate();
|
|
562
|
+
},
|
|
563
|
+
onSourcePart(value) {
|
|
564
|
+
message.parts.push({
|
|
565
|
+
type: "source",
|
|
566
|
+
source: value
|
|
567
|
+
});
|
|
568
|
+
execUpdate();
|
|
569
|
+
},
|
|
570
|
+
onToolCallStreamingStartPart(value) {
|
|
571
|
+
if (message.toolInvocations == null) {
|
|
572
|
+
message.toolInvocations = [];
|
|
573
|
+
}
|
|
574
|
+
partialToolCalls[value.toolCallId] = {
|
|
575
|
+
text: "",
|
|
576
|
+
step,
|
|
577
|
+
toolName: value.toolName,
|
|
578
|
+
index: message.toolInvocations.length
|
|
579
|
+
};
|
|
580
|
+
const invocation = {
|
|
581
|
+
state: "partial-call",
|
|
582
|
+
step,
|
|
583
|
+
toolCallId: value.toolCallId,
|
|
584
|
+
toolName: value.toolName,
|
|
585
|
+
args: void 0
|
|
586
|
+
};
|
|
587
|
+
message.toolInvocations.push(invocation);
|
|
588
|
+
updateToolInvocationPart(value.toolCallId, invocation);
|
|
589
|
+
execUpdate();
|
|
590
|
+
},
|
|
591
|
+
onToolCallDeltaPart(value) {
|
|
592
|
+
const partialToolCall = partialToolCalls[value.toolCallId];
|
|
593
|
+
partialToolCall.text += value.argsTextDelta;
|
|
594
|
+
const { value: partialArgs } = uiUtils.parsePartialJson(partialToolCall.text);
|
|
595
|
+
const invocation = {
|
|
596
|
+
state: "partial-call",
|
|
597
|
+
step: partialToolCall.step,
|
|
598
|
+
toolCallId: value.toolCallId,
|
|
599
|
+
toolName: partialToolCall.toolName,
|
|
600
|
+
args: partialArgs
|
|
601
|
+
};
|
|
602
|
+
message.toolInvocations[partialToolCall.index] = invocation;
|
|
603
|
+
updateToolInvocationPart(value.toolCallId, invocation);
|
|
604
|
+
execUpdate();
|
|
605
|
+
},
|
|
606
|
+
async onToolCallPart(value) {
|
|
607
|
+
const invocation = {
|
|
608
|
+
state: "call",
|
|
609
|
+
step,
|
|
610
|
+
...value
|
|
611
|
+
};
|
|
612
|
+
if (partialToolCalls[value.toolCallId] != null) {
|
|
613
|
+
message.toolInvocations[partialToolCalls[value.toolCallId].index] = invocation;
|
|
614
|
+
} else {
|
|
579
615
|
if (message.toolInvocations == null) {
|
|
580
616
|
message.toolInvocations = [];
|
|
581
617
|
}
|
|
582
|
-
partialToolCalls[value.toolCallId] = {
|
|
583
|
-
text: "",
|
|
584
|
-
step,
|
|
585
|
-
toolName: value.toolName,
|
|
586
|
-
index: message.toolInvocations.length
|
|
587
|
-
};
|
|
588
|
-
const invocation = {
|
|
589
|
-
state: "partial-call",
|
|
590
|
-
step,
|
|
591
|
-
toolCallId: value.toolCallId,
|
|
592
|
-
toolName: value.toolName,
|
|
593
|
-
args: void 0
|
|
594
|
-
};
|
|
595
618
|
message.toolInvocations.push(invocation);
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
const
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
updateToolInvocationPart(value.toolCallId, invocation);
|
|
612
|
-
execUpdate();
|
|
613
|
-
},
|
|
614
|
-
async onToolCallPart(value) {
|
|
615
|
-
const invocation = {
|
|
616
|
-
state: "call",
|
|
617
|
-
step,
|
|
618
|
-
...value
|
|
619
|
-
};
|
|
620
|
-
if (partialToolCalls[value.toolCallId] != null) {
|
|
621
|
-
message.toolInvocations[partialToolCalls[value.toolCallId].index] = invocation;
|
|
622
|
-
} else {
|
|
623
|
-
if (message.toolInvocations == null) {
|
|
624
|
-
message.toolInvocations = [];
|
|
625
|
-
}
|
|
626
|
-
message.toolInvocations.push(invocation);
|
|
627
|
-
}
|
|
628
|
-
updateToolInvocationPart(value.toolCallId, invocation);
|
|
629
|
-
execUpdate();
|
|
630
|
-
if (onToolCall) {
|
|
631
|
-
const result = await onToolCall({ toolCall: value });
|
|
632
|
-
if (result != null) {
|
|
633
|
-
const invocation2 = {
|
|
634
|
-
state: "result",
|
|
635
|
-
step,
|
|
636
|
-
...value,
|
|
637
|
-
result
|
|
638
|
-
};
|
|
639
|
-
message.toolInvocations[message.toolInvocations.length - 1] = invocation2;
|
|
640
|
-
updateToolInvocationPart(value.toolCallId, invocation2);
|
|
641
|
-
execUpdate();
|
|
642
|
-
}
|
|
643
|
-
}
|
|
644
|
-
},
|
|
645
|
-
onToolResultPart(value) {
|
|
646
|
-
const toolInvocations = message.toolInvocations;
|
|
647
|
-
if (toolInvocations == null) {
|
|
648
|
-
throw new Error("tool_result must be preceded by a tool_call");
|
|
649
|
-
}
|
|
650
|
-
const toolInvocationIndex = toolInvocations.findIndex(
|
|
651
|
-
(invocation2) => invocation2.toolCallId === value.toolCallId
|
|
652
|
-
);
|
|
653
|
-
if (toolInvocationIndex === -1) {
|
|
654
|
-
throw new Error("tool_result must be preceded by a tool_call with the same toolCallId");
|
|
655
|
-
}
|
|
656
|
-
const invocation = {
|
|
657
|
-
...toolInvocations[toolInvocationIndex],
|
|
658
|
-
state: "result",
|
|
659
|
-
...value
|
|
660
|
-
};
|
|
661
|
-
toolInvocations[toolInvocationIndex] = invocation;
|
|
662
|
-
updateToolInvocationPart(value.toolCallId, invocation);
|
|
663
|
-
execUpdate();
|
|
664
|
-
},
|
|
665
|
-
onDataPart(value) {
|
|
666
|
-
data.push(...value);
|
|
667
|
-
execUpdate();
|
|
668
|
-
},
|
|
669
|
-
onMessageAnnotationsPart(value) {
|
|
670
|
-
if (messageAnnotations == null) {
|
|
671
|
-
messageAnnotations = [...value];
|
|
672
|
-
} else {
|
|
673
|
-
messageAnnotations.push(...value);
|
|
674
|
-
}
|
|
675
|
-
execUpdate();
|
|
676
|
-
},
|
|
677
|
-
onFinishStepPart(value) {
|
|
678
|
-
step += 1;
|
|
679
|
-
currentTextPart = value.isContinued ? currentTextPart : void 0;
|
|
680
|
-
currentReasoningPart = void 0;
|
|
681
|
-
currentReasoningTextDetail = void 0;
|
|
682
|
-
},
|
|
683
|
-
onStartStepPart(value) {
|
|
684
|
-
if (!replaceLastMessage) {
|
|
685
|
-
message.id = value.messageId;
|
|
686
|
-
}
|
|
687
|
-
message.parts.push({ type: "step-start" });
|
|
688
|
-
execUpdate();
|
|
689
|
-
},
|
|
690
|
-
onFinishMessagePart(value) {
|
|
691
|
-
finishReason = value.finishReason;
|
|
692
|
-
if (value.usage != null) {
|
|
693
|
-
usage = value.usage;
|
|
619
|
+
}
|
|
620
|
+
updateToolInvocationPart(value.toolCallId, invocation);
|
|
621
|
+
execUpdate();
|
|
622
|
+
if (onToolCall) {
|
|
623
|
+
const result = await onToolCall({ toolCall: value });
|
|
624
|
+
if (result != null) {
|
|
625
|
+
const invocation2 = {
|
|
626
|
+
state: "result",
|
|
627
|
+
step,
|
|
628
|
+
...value,
|
|
629
|
+
result
|
|
630
|
+
};
|
|
631
|
+
message.toolInvocations[message.toolInvocations.length - 1] = invocation2;
|
|
632
|
+
updateToolInvocationPart(value.toolCallId, invocation2);
|
|
633
|
+
execUpdate();
|
|
694
634
|
}
|
|
695
|
-
},
|
|
696
|
-
onErrorPart(error) {
|
|
697
|
-
throw new Error(error);
|
|
698
635
|
}
|
|
699
|
-
}
|
|
700
|
-
|
|
701
|
-
|
|
636
|
+
},
|
|
637
|
+
onToolResultPart(value) {
|
|
638
|
+
const toolInvocations = message.toolInvocations;
|
|
639
|
+
if (toolInvocations == null) {
|
|
640
|
+
throw new Error("tool_result must be preceded by a tool_call");
|
|
641
|
+
}
|
|
642
|
+
const toolInvocationIndex = toolInvocations.findIndex((invocation2) => invocation2.toolCallId === value.toolCallId);
|
|
643
|
+
if (toolInvocationIndex === -1) {
|
|
644
|
+
throw new Error("tool_result must be preceded by a tool_call with the same toolCallId");
|
|
645
|
+
}
|
|
646
|
+
const invocation = {
|
|
647
|
+
...toolInvocations[toolInvocationIndex],
|
|
648
|
+
state: "result",
|
|
649
|
+
...value
|
|
650
|
+
};
|
|
651
|
+
toolInvocations[toolInvocationIndex] = invocation;
|
|
652
|
+
updateToolInvocationPart(value.toolCallId, invocation);
|
|
653
|
+
execUpdate();
|
|
654
|
+
},
|
|
655
|
+
onDataPart(value) {
|
|
656
|
+
data.push(...value);
|
|
657
|
+
execUpdate();
|
|
658
|
+
},
|
|
659
|
+
onMessageAnnotationsPart(value) {
|
|
660
|
+
if (messageAnnotations == null) {
|
|
661
|
+
messageAnnotations = [...value];
|
|
662
|
+
} else {
|
|
663
|
+
messageAnnotations.push(...value);
|
|
664
|
+
}
|
|
665
|
+
execUpdate();
|
|
666
|
+
},
|
|
667
|
+
onFinishStepPart(value) {
|
|
668
|
+
step += 1;
|
|
669
|
+
currentTextPart = value.isContinued ? currentTextPart : void 0;
|
|
670
|
+
currentReasoningPart = void 0;
|
|
671
|
+
currentReasoningTextDetail = void 0;
|
|
672
|
+
},
|
|
673
|
+
onStartStepPart(value) {
|
|
674
|
+
if (!replaceLastMessage) {
|
|
675
|
+
message.id = value.messageId;
|
|
676
|
+
}
|
|
677
|
+
message.parts.push({ type: "step-start" });
|
|
678
|
+
execUpdate();
|
|
679
|
+
},
|
|
680
|
+
onFinishMessagePart(value) {
|
|
681
|
+
finishReason = value.finishReason;
|
|
682
|
+
if (value.usage != null) {
|
|
683
|
+
usage = value.usage;
|
|
684
|
+
}
|
|
685
|
+
},
|
|
686
|
+
onErrorPart(error) {
|
|
687
|
+
throw new Error(error);
|
|
688
|
+
}
|
|
689
|
+
});
|
|
690
|
+
onFinish?.({ message, finishReason, usage });
|
|
702
691
|
}
|
|
703
692
|
/**
|
|
704
|
-
*
|
|
693
|
+
* Streams a response from the agent
|
|
694
|
+
* @param params - Stream parameters including prompt
|
|
695
|
+
* @returns Promise containing the enhanced Response object with processDataStream method
|
|
705
696
|
*/
|
|
706
|
-
async
|
|
707
|
-
const
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
697
|
+
async streamLegacy(params) {
|
|
698
|
+
const processedParams = {
|
|
699
|
+
...params,
|
|
700
|
+
output: params.output ? zodToJsonSchema(params.output) : void 0,
|
|
701
|
+
experimental_output: params.experimental_output ? zodToJsonSchema(params.experimental_output) : void 0,
|
|
702
|
+
runtimeContext: parseClientRuntimeContext(params.runtimeContext),
|
|
703
|
+
clientTools: processClientTools(params.clientTools)
|
|
704
|
+
};
|
|
705
|
+
const { readable, writable } = new TransformStream();
|
|
706
|
+
const response = await this.processStreamResponseLegacy(processedParams, writable);
|
|
707
|
+
const streamResponse = new Response(readable, {
|
|
708
|
+
status: response.status,
|
|
709
|
+
statusText: response.statusText,
|
|
710
|
+
headers: response.headers
|
|
711
711
|
});
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
const streamProtocol = processedParams.output ? "text" : "data";
|
|
717
|
-
let toolCalls = [];
|
|
718
|
-
let messages = [];
|
|
719
|
-
const [streamForWritable, streamForProcessing] = response.body.tee();
|
|
720
|
-
streamForWritable.pipeTo(writable, {
|
|
721
|
-
preventClose: true
|
|
722
|
-
}).catch((error) => {
|
|
723
|
-
console.error("Error piping to writable stream:", error);
|
|
712
|
+
streamResponse.processDataStream = async (options = {}) => {
|
|
713
|
+
await uiUtils.processDataStream({
|
|
714
|
+
stream: streamResponse.body,
|
|
715
|
+
...options
|
|
724
716
|
});
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
717
|
+
};
|
|
718
|
+
return streamResponse;
|
|
719
|
+
}
|
|
720
|
+
async processChatResponse_vNext({
|
|
721
|
+
stream,
|
|
722
|
+
update,
|
|
723
|
+
onToolCall,
|
|
724
|
+
onFinish,
|
|
725
|
+
getCurrentDate = () => /* @__PURE__ */ new Date(),
|
|
726
|
+
lastMessage
|
|
727
|
+
}) {
|
|
728
|
+
const replaceLastMessage = lastMessage?.role === "assistant";
|
|
729
|
+
let step = replaceLastMessage ? 1 + // find max step in existing tool invocations:
|
|
730
|
+
(lastMessage.toolInvocations?.reduce((max, toolInvocation) => {
|
|
731
|
+
return Math.max(max, toolInvocation.step ?? 0);
|
|
732
|
+
}, 0) ?? 0) : 0;
|
|
733
|
+
const message = replaceLastMessage ? structuredClone(lastMessage) : {
|
|
734
|
+
id: uuid.v4(),
|
|
735
|
+
createdAt: getCurrentDate(),
|
|
736
|
+
role: "assistant",
|
|
737
|
+
content: "",
|
|
738
|
+
parts: []
|
|
739
|
+
};
|
|
740
|
+
let currentTextPart = void 0;
|
|
741
|
+
let currentReasoningPart = void 0;
|
|
742
|
+
let currentReasoningTextDetail = void 0;
|
|
743
|
+
function updateToolInvocationPart(toolCallId, invocation) {
|
|
744
|
+
const part = message.parts.find(
|
|
745
|
+
(part2) => part2.type === "tool-invocation" && part2.toolInvocation.toolCallId === toolCallId
|
|
746
|
+
);
|
|
747
|
+
if (part != null) {
|
|
748
|
+
part.toolInvocation = invocation;
|
|
749
|
+
} else {
|
|
750
|
+
message.parts.push({
|
|
751
|
+
type: "tool-invocation",
|
|
752
|
+
toolInvocation: invocation
|
|
753
|
+
});
|
|
754
|
+
}
|
|
755
|
+
}
|
|
756
|
+
const data = [];
|
|
757
|
+
let messageAnnotations = replaceLastMessage ? lastMessage?.annotations : void 0;
|
|
758
|
+
const partialToolCalls = {};
|
|
759
|
+
let usage = {
|
|
760
|
+
completionTokens: NaN,
|
|
761
|
+
promptTokens: NaN,
|
|
762
|
+
totalTokens: NaN
|
|
763
|
+
};
|
|
764
|
+
let finishReason = "unknown";
|
|
765
|
+
function execUpdate() {
|
|
766
|
+
const copiedData = [...data];
|
|
767
|
+
if (messageAnnotations?.length) {
|
|
768
|
+
message.annotations = messageAnnotations;
|
|
769
|
+
}
|
|
770
|
+
const copiedMessage = {
|
|
771
|
+
// deep copy the message to ensure that deep changes (msg attachments) are updated
|
|
772
|
+
// with SolidJS. SolidJS uses referential integration of sub-objects to detect changes.
|
|
773
|
+
...structuredClone(message),
|
|
774
|
+
// add a revision id to ensure that the message is updated with SWR. SWR uses a
|
|
775
|
+
// hashing approach by default to detect changes, but it only works for shallow
|
|
776
|
+
// changes. This is why we need to add a revision id to ensure that the message
|
|
777
|
+
// is updated with SWR (without it, the changes get stuck in SWR and are not
|
|
778
|
+
// forwarded to rendering):
|
|
779
|
+
revisionId: uuid.v4()
|
|
780
|
+
};
|
|
781
|
+
update({
|
|
782
|
+
message: copiedMessage,
|
|
783
|
+
data: copiedData,
|
|
784
|
+
replaceLastMessage
|
|
785
|
+
});
|
|
786
|
+
}
|
|
787
|
+
await processMastraStream({
|
|
788
|
+
stream,
|
|
789
|
+
// TODO: casting as any here because the stream types were all typed as any before in core.
|
|
790
|
+
// but this is completely wrong and this fn is probably broken. Remove ":any" and you'll see a bunch of type errors
|
|
791
|
+
onChunk: async (chunk) => {
|
|
792
|
+
switch (chunk.type) {
|
|
793
|
+
case "tripwire": {
|
|
794
|
+
message.parts.push({
|
|
795
|
+
type: "text",
|
|
796
|
+
text: chunk.payload.tripwireReason
|
|
797
|
+
});
|
|
798
|
+
execUpdate();
|
|
799
|
+
break;
|
|
800
|
+
}
|
|
801
|
+
case "step-start": {
|
|
802
|
+
if (!replaceLastMessage) {
|
|
803
|
+
message.id = chunk.payload.messageId;
|
|
804
|
+
}
|
|
805
|
+
message.parts.push({ type: "step-start" });
|
|
806
|
+
execUpdate();
|
|
807
|
+
break;
|
|
808
|
+
}
|
|
809
|
+
case "text-delta": {
|
|
810
|
+
if (currentTextPart == null) {
|
|
811
|
+
currentTextPart = {
|
|
812
|
+
type: "text",
|
|
813
|
+
text: chunk.payload.text
|
|
814
|
+
};
|
|
815
|
+
message.parts.push(currentTextPart);
|
|
816
|
+
} else {
|
|
817
|
+
currentTextPart.text += chunk.payload.text;
|
|
818
|
+
}
|
|
819
|
+
message.content += chunk.payload.text;
|
|
820
|
+
execUpdate();
|
|
821
|
+
break;
|
|
822
|
+
}
|
|
823
|
+
case "reasoning-delta": {
|
|
824
|
+
if (currentReasoningTextDetail == null) {
|
|
825
|
+
currentReasoningTextDetail = { type: "text", text: chunk.payload.text };
|
|
826
|
+
if (currentReasoningPart != null) {
|
|
827
|
+
currentReasoningPart.details.push(currentReasoningTextDetail);
|
|
828
|
+
}
|
|
829
|
+
} else {
|
|
830
|
+
currentReasoningTextDetail.text += chunk.payload.text;
|
|
831
|
+
}
|
|
832
|
+
if (currentReasoningPart == null) {
|
|
833
|
+
currentReasoningPart = {
|
|
834
|
+
type: "reasoning",
|
|
835
|
+
reasoning: chunk.payload.text,
|
|
836
|
+
details: [currentReasoningTextDetail]
|
|
837
|
+
};
|
|
838
|
+
message.parts.push(currentReasoningPart);
|
|
839
|
+
} else {
|
|
840
|
+
currentReasoningPart.reasoning += chunk.payload.text;
|
|
841
|
+
}
|
|
842
|
+
message.reasoning = (message.reasoning ?? "") + chunk.payload.text;
|
|
843
|
+
execUpdate();
|
|
844
|
+
break;
|
|
845
|
+
}
|
|
846
|
+
case "file": {
|
|
847
|
+
message.parts.push({
|
|
848
|
+
type: "file",
|
|
849
|
+
mimeType: chunk.payload.mimeType,
|
|
850
|
+
data: chunk.payload.data
|
|
851
|
+
});
|
|
852
|
+
execUpdate();
|
|
853
|
+
break;
|
|
854
|
+
}
|
|
855
|
+
case "source": {
|
|
856
|
+
message.parts.push({
|
|
857
|
+
type: "source",
|
|
858
|
+
source: chunk.payload.source
|
|
859
|
+
});
|
|
860
|
+
execUpdate();
|
|
861
|
+
break;
|
|
862
|
+
}
|
|
863
|
+
case "tool-call": {
|
|
864
|
+
const invocation = {
|
|
865
|
+
state: "call",
|
|
866
|
+
step,
|
|
867
|
+
...chunk.payload
|
|
868
|
+
};
|
|
869
|
+
if (partialToolCalls[chunk.payload.toolCallId] != null) {
|
|
870
|
+
message.toolInvocations[partialToolCalls[chunk.payload.toolCallId].index] = invocation;
|
|
871
|
+
} else {
|
|
872
|
+
if (message.toolInvocations == null) {
|
|
873
|
+
message.toolInvocations = [];
|
|
874
|
+
}
|
|
875
|
+
message.toolInvocations.push(invocation);
|
|
876
|
+
}
|
|
877
|
+
updateToolInvocationPart(chunk.payload.toolCallId, invocation);
|
|
878
|
+
execUpdate();
|
|
879
|
+
if (onToolCall) {
|
|
880
|
+
const result = await onToolCall({ toolCall: chunk.payload });
|
|
881
|
+
if (result != null) {
|
|
882
|
+
const invocation2 = {
|
|
883
|
+
state: "result",
|
|
884
|
+
step,
|
|
885
|
+
...chunk.payload,
|
|
886
|
+
result
|
|
887
|
+
};
|
|
888
|
+
message.toolInvocations[message.toolInvocations.length - 1] = invocation2;
|
|
889
|
+
updateToolInvocationPart(chunk.payload.toolCallId, invocation2);
|
|
890
|
+
execUpdate();
|
|
891
|
+
}
|
|
892
|
+
}
|
|
893
|
+
}
|
|
894
|
+
case "tool-call-input-streaming-start": {
|
|
895
|
+
if (message.toolInvocations == null) {
|
|
896
|
+
message.toolInvocations = [];
|
|
897
|
+
}
|
|
898
|
+
partialToolCalls[chunk.payload.toolCallId] = {
|
|
899
|
+
text: "",
|
|
900
|
+
step,
|
|
901
|
+
toolName: chunk.payload.toolName,
|
|
902
|
+
index: message.toolInvocations.length
|
|
903
|
+
};
|
|
904
|
+
const invocation = {
|
|
905
|
+
state: "partial-call",
|
|
906
|
+
step,
|
|
907
|
+
toolCallId: chunk.payload.toolCallId,
|
|
908
|
+
toolName: chunk.payload.toolName,
|
|
909
|
+
args: chunk.payload.args
|
|
910
|
+
};
|
|
911
|
+
message.toolInvocations.push(invocation);
|
|
912
|
+
updateToolInvocationPart(chunk.payload.toolCallId, invocation);
|
|
913
|
+
execUpdate();
|
|
914
|
+
break;
|
|
915
|
+
}
|
|
916
|
+
case "tool-call-delta": {
|
|
917
|
+
const partialToolCall = partialToolCalls[chunk.payload.toolCallId];
|
|
918
|
+
partialToolCall.text += chunk.payload.argsTextDelta;
|
|
919
|
+
const { value: partialArgs } = uiUtils.parsePartialJson(partialToolCall.text);
|
|
920
|
+
const invocation = {
|
|
921
|
+
state: "partial-call",
|
|
922
|
+
step: partialToolCall.step,
|
|
923
|
+
toolCallId: chunk.payload.toolCallId,
|
|
924
|
+
toolName: partialToolCall.toolName,
|
|
925
|
+
args: partialArgs
|
|
926
|
+
};
|
|
927
|
+
message.toolInvocations[partialToolCall.index] = invocation;
|
|
928
|
+
updateToolInvocationPart(chunk.payload.toolCallId, invocation);
|
|
929
|
+
execUpdate();
|
|
930
|
+
break;
|
|
931
|
+
}
|
|
932
|
+
case "tool-result": {
|
|
933
|
+
const toolInvocations = message.toolInvocations;
|
|
934
|
+
if (toolInvocations == null) {
|
|
935
|
+
throw new Error("tool_result must be preceded by a tool_call");
|
|
936
|
+
}
|
|
937
|
+
const toolInvocationIndex = toolInvocations.findIndex(
|
|
938
|
+
(invocation2) => invocation2.toolCallId === chunk.payload.toolCallId
|
|
939
|
+
);
|
|
940
|
+
if (toolInvocationIndex === -1) {
|
|
941
|
+
throw new Error("tool_result must be preceded by a tool_call with the same toolCallId");
|
|
942
|
+
}
|
|
943
|
+
const invocation = {
|
|
944
|
+
...toolInvocations[toolInvocationIndex],
|
|
945
|
+
state: "result",
|
|
946
|
+
...chunk.payload
|
|
947
|
+
};
|
|
948
|
+
toolInvocations[toolInvocationIndex] = invocation;
|
|
949
|
+
updateToolInvocationPart(chunk.payload.toolCallId, invocation);
|
|
950
|
+
execUpdate();
|
|
951
|
+
break;
|
|
952
|
+
}
|
|
953
|
+
case "error": {
|
|
954
|
+
throw new Error(chunk.payload.error);
|
|
955
|
+
}
|
|
956
|
+
case "data": {
|
|
957
|
+
data.push(...chunk.payload.data);
|
|
958
|
+
execUpdate();
|
|
959
|
+
break;
|
|
960
|
+
}
|
|
961
|
+
case "step-finish": {
|
|
962
|
+
step += 1;
|
|
963
|
+
currentTextPart = chunk.payload.stepResult.isContinued ? currentTextPart : void 0;
|
|
964
|
+
currentReasoningPart = void 0;
|
|
965
|
+
currentReasoningTextDetail = void 0;
|
|
966
|
+
execUpdate();
|
|
967
|
+
break;
|
|
968
|
+
}
|
|
969
|
+
case "finish": {
|
|
970
|
+
finishReason = chunk.payload.stepResult.reason;
|
|
971
|
+
if (chunk.payload.usage != null) {
|
|
972
|
+
usage = chunk.payload.usage;
|
|
973
|
+
}
|
|
974
|
+
break;
|
|
975
|
+
}
|
|
976
|
+
}
|
|
977
|
+
}
|
|
978
|
+
});
|
|
979
|
+
onFinish?.({ message, finishReason, usage });
|
|
980
|
+
}
|
|
981
|
+
async processStreamResponse(processedParams, writable) {
|
|
982
|
+
const response = await this.request(`/api/agents/${this.agentId}/stream`, {
|
|
983
|
+
method: "POST",
|
|
984
|
+
body: processedParams,
|
|
985
|
+
stream: true
|
|
986
|
+
});
|
|
987
|
+
if (!response.body) {
|
|
988
|
+
throw new Error("No response body");
|
|
989
|
+
}
|
|
990
|
+
try {
|
|
991
|
+
let toolCalls = [];
|
|
992
|
+
let messages = [];
|
|
993
|
+
const [streamForWritable, streamForProcessing] = response.body.tee();
|
|
994
|
+
streamForWritable.pipeTo(
|
|
995
|
+
new WritableStream({
|
|
996
|
+
async write(chunk) {
|
|
997
|
+
let writer;
|
|
998
|
+
try {
|
|
999
|
+
writer = writable.getWriter();
|
|
1000
|
+
const text = new TextDecoder().decode(chunk);
|
|
1001
|
+
const lines = text.split("\n\n");
|
|
1002
|
+
const readableLines = lines.filter((line) => line !== "[DONE]").join("\n\n");
|
|
1003
|
+
await writer.write(new TextEncoder().encode(readableLines));
|
|
1004
|
+
} catch {
|
|
1005
|
+
await writer?.write(chunk);
|
|
1006
|
+
} finally {
|
|
1007
|
+
writer?.releaseLock();
|
|
1008
|
+
}
|
|
1009
|
+
}
|
|
1010
|
+
}),
|
|
1011
|
+
{
|
|
1012
|
+
preventClose: true
|
|
1013
|
+
}
|
|
1014
|
+
).catch((error) => {
|
|
1015
|
+
console.error("Error piping to writable stream:", error);
|
|
1016
|
+
});
|
|
1017
|
+
this.processChatResponse_vNext({
|
|
1018
|
+
stream: streamForProcessing,
|
|
1019
|
+
update: ({ message }) => {
|
|
1020
|
+
const existingIndex = messages.findIndex((m) => m.id === message.id);
|
|
1021
|
+
if (existingIndex !== -1) {
|
|
1022
|
+
messages[existingIndex] = message;
|
|
1023
|
+
} else {
|
|
1024
|
+
messages.push(message);
|
|
1025
|
+
}
|
|
1026
|
+
},
|
|
1027
|
+
onFinish: async ({ finishReason, message }) => {
|
|
1028
|
+
if (finishReason === "tool-calls") {
|
|
1029
|
+
const toolCall = [...message?.parts ?? []].reverse().find((part) => part.type === "tool-invocation")?.toolInvocation;
|
|
1030
|
+
if (toolCall) {
|
|
1031
|
+
toolCalls.push(toolCall);
|
|
1032
|
+
}
|
|
1033
|
+
let shouldExecuteClientTool = false;
|
|
736
1034
|
for (const toolCall2 of toolCalls) {
|
|
737
1035
|
const clientTool = processedParams.clientTools?.[toolCall2.toolName];
|
|
738
1036
|
if (clientTool && clientTool.execute) {
|
|
1037
|
+
shouldExecuteClientTool = true;
|
|
739
1038
|
const result = await clientTool.execute(
|
|
740
1039
|
{
|
|
741
1040
|
context: toolCall2?.args,
|
|
742
1041
|
runId: processedParams.runId,
|
|
743
1042
|
resourceId: processedParams.resourceId,
|
|
744
1043
|
threadId: processedParams.threadId,
|
|
745
|
-
runtimeContext: processedParams.runtimeContext
|
|
1044
|
+
runtimeContext: processedParams.runtimeContext,
|
|
1045
|
+
// TODO: Pass proper tracing context when client-js supports tracing
|
|
1046
|
+
tracingContext: { currentSpan: void 0 },
|
|
1047
|
+
suspend: async () => {
|
|
1048
|
+
}
|
|
746
1049
|
},
|
|
747
1050
|
{
|
|
748
1051
|
messages: response.messages,
|
|
749
1052
|
toolCallId: toolCall2?.toolCallId
|
|
750
1053
|
}
|
|
751
1054
|
);
|
|
752
|
-
const
|
|
1055
|
+
const lastMessageRaw = messages[messages.length - 1];
|
|
1056
|
+
const lastMessage = lastMessageRaw != null ? JSON.parse(JSON.stringify(lastMessageRaw)) : void 0;
|
|
753
1057
|
const toolInvocationPart = lastMessage?.parts?.find(
|
|
754
1058
|
(part) => part.type === "tool-invocation" && part.toolInvocation?.toolCallId === toolCall2.toolCallId
|
|
755
1059
|
);
|
|
@@ -767,58 +1071,81 @@ var Agent = class extends BaseResource {
|
|
|
767
1071
|
toolInvocation.state = "result";
|
|
768
1072
|
toolInvocation.result = result;
|
|
769
1073
|
}
|
|
770
|
-
const
|
|
771
|
-
try {
|
|
772
|
-
await writer.write(
|
|
773
|
-
new TextEncoder().encode(
|
|
774
|
-
"a:" + JSON.stringify({
|
|
775
|
-
toolCallId: toolCall2.toolCallId,
|
|
776
|
-
result
|
|
777
|
-
}) + "\n"
|
|
778
|
-
)
|
|
779
|
-
);
|
|
780
|
-
} finally {
|
|
781
|
-
writer.releaseLock();
|
|
782
|
-
}
|
|
783
|
-
const originalMessages = processedParams.messages;
|
|
784
|
-
const messageArray = Array.isArray(originalMessages) ? originalMessages : [originalMessages];
|
|
1074
|
+
const updatedMessages = lastMessage != null ? [...messages.filter((m) => m.id !== lastMessage.id), lastMessage] : [...messages];
|
|
785
1075
|
this.processStreamResponse(
|
|
786
1076
|
{
|
|
787
1077
|
...processedParams,
|
|
788
|
-
messages:
|
|
1078
|
+
messages: updatedMessages
|
|
789
1079
|
},
|
|
790
1080
|
writable
|
|
791
|
-
)
|
|
1081
|
+
).catch((error) => {
|
|
1082
|
+
console.error("Error processing stream response:", error);
|
|
1083
|
+
});
|
|
792
1084
|
}
|
|
793
1085
|
}
|
|
1086
|
+
if (!shouldExecuteClientTool) {
|
|
1087
|
+
setTimeout(() => {
|
|
1088
|
+
writable.close();
|
|
1089
|
+
}, 0);
|
|
1090
|
+
}
|
|
794
1091
|
} else {
|
|
795
1092
|
setTimeout(() => {
|
|
796
|
-
|
|
797
|
-
writable.close();
|
|
798
|
-
}
|
|
1093
|
+
writable.close();
|
|
799
1094
|
}, 0);
|
|
800
1095
|
}
|
|
801
1096
|
},
|
|
802
|
-
lastMessage: void 0
|
|
803
|
-
|
|
1097
|
+
lastMessage: void 0
|
|
1098
|
+
}).catch((error) => {
|
|
1099
|
+
console.error("Error processing stream response:", error);
|
|
804
1100
|
});
|
|
805
1101
|
} catch (error) {
|
|
806
1102
|
console.error("Error processing stream response:", error);
|
|
807
1103
|
}
|
|
808
1104
|
return response;
|
|
809
1105
|
}
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
1106
|
+
async network(params) {
|
|
1107
|
+
const response = await this.request(`/api/agents/${this.agentId}/network`, {
|
|
1108
|
+
method: "POST",
|
|
1109
|
+
body: params,
|
|
1110
|
+
stream: true
|
|
1111
|
+
});
|
|
1112
|
+
if (!response.body) {
|
|
1113
|
+
throw new Error("No response body");
|
|
1114
|
+
}
|
|
1115
|
+
const streamResponse = new Response(response.body, {
|
|
1116
|
+
status: response.status,
|
|
1117
|
+
statusText: response.statusText,
|
|
1118
|
+
headers: response.headers
|
|
1119
|
+
});
|
|
1120
|
+
streamResponse.processDataStream = async ({
|
|
1121
|
+
onChunk
|
|
1122
|
+
}) => {
|
|
1123
|
+
await processMastraNetworkStream({
|
|
1124
|
+
stream: streamResponse.body,
|
|
1125
|
+
onChunk
|
|
1126
|
+
});
|
|
1127
|
+
};
|
|
1128
|
+
return streamResponse;
|
|
1129
|
+
}
|
|
1130
|
+
async stream(messagesOrParams, options) {
|
|
1131
|
+
let params;
|
|
1132
|
+
if (typeof messagesOrParams === "object" && "messages" in messagesOrParams) {
|
|
1133
|
+
params = messagesOrParams;
|
|
1134
|
+
} else {
|
|
1135
|
+
params = {
|
|
1136
|
+
messages: messagesOrParams,
|
|
1137
|
+
...options
|
|
1138
|
+
};
|
|
1139
|
+
}
|
|
816
1140
|
const processedParams = {
|
|
817
1141
|
...params,
|
|
818
1142
|
output: params.output ? zodToJsonSchema(params.output) : void 0,
|
|
819
|
-
experimental_output: params.experimental_output ? zodToJsonSchema(params.experimental_output) : void 0,
|
|
820
1143
|
runtimeContext: parseClientRuntimeContext(params.runtimeContext),
|
|
821
|
-
clientTools: processClientTools(params.clientTools)
|
|
1144
|
+
clientTools: processClientTools(params.clientTools),
|
|
1145
|
+
structuredOutput: params.structuredOutput ? {
|
|
1146
|
+
...params.structuredOutput,
|
|
1147
|
+
schema: zodToJsonSchema(params.structuredOutput.schema)
|
|
1148
|
+
} : void 0
|
|
822
1149
|
};
|
|
823
1150
|
const { readable, writable } = new TransformStream();
|
|
824
1151
|
const response = await this.processStreamResponse(processedParams, writable);
|
|
@@ -827,100 +1154,21 @@ var Agent = class extends BaseResource {
|
|
|
827
1154
|
statusText: response.statusText,
|
|
828
1155
|
headers: response.headers
|
|
829
1156
|
});
|
|
830
|
-
streamResponse.processDataStream = async (
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
});
|
|
835
|
-
};
|
|
836
|
-
streamResponse.processTextStream = async (options) => {
|
|
837
|
-
await uiUtils.processTextStream({
|
|
1157
|
+
streamResponse.processDataStream = async ({
|
|
1158
|
+
onChunk
|
|
1159
|
+
}) => {
|
|
1160
|
+
await processMastraStream({
|
|
838
1161
|
stream: streamResponse.body,
|
|
839
|
-
|
|
840
|
-
})
|
|
1162
|
+
onChunk
|
|
841
1163
|
});
|
|
842
1164
|
};
|
|
843
1165
|
return streamResponse;
|
|
844
1166
|
}
|
|
845
1167
|
/**
|
|
846
|
-
*
|
|
847
|
-
* @param toolId - ID of the tool to retrieve
|
|
848
|
-
* @returns Promise containing tool details
|
|
849
|
-
*/
|
|
850
|
-
getTool(toolId) {
|
|
851
|
-
return this.request(`/api/agents/${this.agentId}/tools/${toolId}`);
|
|
852
|
-
}
|
|
853
|
-
/**
|
|
854
|
-
* Executes a tool for the agent
|
|
855
|
-
* @param toolId - ID of the tool to execute
|
|
856
|
-
* @param params - Parameters required for tool execution
|
|
857
|
-
* @returns Promise containing the tool execution results
|
|
858
|
-
*/
|
|
859
|
-
executeTool(toolId, params) {
|
|
860
|
-
const body = {
|
|
861
|
-
data: params.data,
|
|
862
|
-
runtimeContext: params.runtimeContext ? Object.fromEntries(params.runtimeContext.entries()) : void 0
|
|
863
|
-
};
|
|
864
|
-
return this.request(`/api/agents/${this.agentId}/tools/${toolId}/execute`, {
|
|
865
|
-
method: "POST",
|
|
866
|
-
body
|
|
867
|
-
});
|
|
868
|
-
}
|
|
869
|
-
/**
|
|
870
|
-
* Retrieves evaluation results for the agent
|
|
871
|
-
* @returns Promise containing agent evaluations
|
|
872
|
-
*/
|
|
873
|
-
evals() {
|
|
874
|
-
return this.request(`/api/agents/${this.agentId}/evals/ci`);
|
|
875
|
-
}
|
|
876
|
-
/**
|
|
877
|
-
* Retrieves live evaluation results for the agent
|
|
878
|
-
* @returns Promise containing live agent evaluations
|
|
879
|
-
*/
|
|
880
|
-
liveEvals() {
|
|
881
|
-
return this.request(`/api/agents/${this.agentId}/evals/live`);
|
|
882
|
-
}
|
|
883
|
-
};
|
|
884
|
-
var Network = class extends BaseResource {
|
|
885
|
-
constructor(options, networkId) {
|
|
886
|
-
super(options);
|
|
887
|
-
this.networkId = networkId;
|
|
888
|
-
}
|
|
889
|
-
/**
|
|
890
|
-
* Retrieves details about the network
|
|
891
|
-
* @returns Promise containing network details
|
|
892
|
-
*/
|
|
893
|
-
details() {
|
|
894
|
-
return this.request(`/api/networks/${this.networkId}`);
|
|
895
|
-
}
|
|
896
|
-
/**
|
|
897
|
-
* Generates a response from the agent
|
|
898
|
-
* @param params - Generation parameters including prompt
|
|
899
|
-
* @returns Promise containing the generated response
|
|
900
|
-
*/
|
|
901
|
-
generate(params) {
|
|
902
|
-
const processedParams = {
|
|
903
|
-
...params,
|
|
904
|
-
output: zodToJsonSchema(params.output),
|
|
905
|
-
experimental_output: zodToJsonSchema(params.experimental_output)
|
|
906
|
-
};
|
|
907
|
-
return this.request(`/api/networks/${this.networkId}/generate`, {
|
|
908
|
-
method: "POST",
|
|
909
|
-
body: processedParams
|
|
910
|
-
});
|
|
911
|
-
}
|
|
912
|
-
/**
|
|
913
|
-
* Streams a response from the agent
|
|
914
|
-
* @param params - Stream parameters including prompt
|
|
915
|
-
* @returns Promise containing the enhanced Response object with processDataStream method
|
|
1168
|
+
* Processes the stream response and handles tool calls
|
|
916
1169
|
*/
|
|
917
|
-
async
|
|
918
|
-
const
|
|
919
|
-
...params,
|
|
920
|
-
output: zodToJsonSchema(params.output),
|
|
921
|
-
experimental_output: zodToJsonSchema(params.experimental_output)
|
|
922
|
-
};
|
|
923
|
-
const response = await this.request(`/api/networks/${this.networkId}/stream`, {
|
|
1170
|
+
async processStreamResponseLegacy(processedParams, writable) {
|
|
1171
|
+
const response = await this.request(`/api/agents/${this.agentId}/stream-legacy`, {
|
|
924
1172
|
method: "POST",
|
|
925
1173
|
body: processedParams,
|
|
926
1174
|
stream: true
|
|
@@ -928,14 +1176,188 @@ var Network = class extends BaseResource {
|
|
|
928
1176
|
if (!response.body) {
|
|
929
1177
|
throw new Error("No response body");
|
|
930
1178
|
}
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
1179
|
+
try {
|
|
1180
|
+
let toolCalls = [];
|
|
1181
|
+
let messages = [];
|
|
1182
|
+
const [streamForWritable, streamForProcessing] = response.body.tee();
|
|
1183
|
+
streamForWritable.pipeTo(writable, {
|
|
1184
|
+
preventClose: true
|
|
1185
|
+
}).catch((error) => {
|
|
1186
|
+
console.error("Error piping to writable stream:", error);
|
|
1187
|
+
});
|
|
1188
|
+
this.processChatResponse({
|
|
1189
|
+
stream: streamForProcessing,
|
|
1190
|
+
update: ({ message }) => {
|
|
1191
|
+
const existingIndex = messages.findIndex((m) => m.id === message.id);
|
|
1192
|
+
if (existingIndex !== -1) {
|
|
1193
|
+
messages[existingIndex] = message;
|
|
1194
|
+
} else {
|
|
1195
|
+
messages.push(message);
|
|
1196
|
+
}
|
|
1197
|
+
},
|
|
1198
|
+
onFinish: async ({ finishReason, message }) => {
|
|
1199
|
+
if (finishReason === "tool-calls") {
|
|
1200
|
+
const toolCall = [...message?.parts ?? []].reverse().find((part) => part.type === "tool-invocation")?.toolInvocation;
|
|
1201
|
+
if (toolCall) {
|
|
1202
|
+
toolCalls.push(toolCall);
|
|
1203
|
+
}
|
|
1204
|
+
for (const toolCall2 of toolCalls) {
|
|
1205
|
+
const clientTool = processedParams.clientTools?.[toolCall2.toolName];
|
|
1206
|
+
if (clientTool && clientTool.execute) {
|
|
1207
|
+
const result = await clientTool.execute(
|
|
1208
|
+
{
|
|
1209
|
+
context: toolCall2?.args,
|
|
1210
|
+
runId: processedParams.runId,
|
|
1211
|
+
resourceId: processedParams.resourceId,
|
|
1212
|
+
threadId: processedParams.threadId,
|
|
1213
|
+
runtimeContext: processedParams.runtimeContext,
|
|
1214
|
+
// TODO: Pass proper tracing context when client-js supports tracing
|
|
1215
|
+
tracingContext: { currentSpan: void 0 },
|
|
1216
|
+
suspend: async () => {
|
|
1217
|
+
}
|
|
1218
|
+
},
|
|
1219
|
+
{
|
|
1220
|
+
messages: response.messages,
|
|
1221
|
+
toolCallId: toolCall2?.toolCallId
|
|
1222
|
+
}
|
|
1223
|
+
);
|
|
1224
|
+
const lastMessage = JSON.parse(JSON.stringify(messages[messages.length - 1]));
|
|
1225
|
+
const toolInvocationPart = lastMessage?.parts?.find(
|
|
1226
|
+
(part) => part.type === "tool-invocation" && part.toolInvocation?.toolCallId === toolCall2.toolCallId
|
|
1227
|
+
);
|
|
1228
|
+
if (toolInvocationPart) {
|
|
1229
|
+
toolInvocationPart.toolInvocation = {
|
|
1230
|
+
...toolInvocationPart.toolInvocation,
|
|
1231
|
+
state: "result",
|
|
1232
|
+
result
|
|
1233
|
+
};
|
|
1234
|
+
}
|
|
1235
|
+
const toolInvocation = lastMessage?.toolInvocations?.find(
|
|
1236
|
+
(toolInvocation2) => toolInvocation2.toolCallId === toolCall2.toolCallId
|
|
1237
|
+
);
|
|
1238
|
+
if (toolInvocation) {
|
|
1239
|
+
toolInvocation.state = "result";
|
|
1240
|
+
toolInvocation.result = result;
|
|
1241
|
+
}
|
|
1242
|
+
const writer = writable.getWriter();
|
|
1243
|
+
try {
|
|
1244
|
+
await writer.write(
|
|
1245
|
+
new TextEncoder().encode(
|
|
1246
|
+
"a:" + JSON.stringify({
|
|
1247
|
+
toolCallId: toolCall2.toolCallId,
|
|
1248
|
+
result
|
|
1249
|
+
}) + "\n"
|
|
1250
|
+
)
|
|
1251
|
+
);
|
|
1252
|
+
} finally {
|
|
1253
|
+
writer.releaseLock();
|
|
1254
|
+
}
|
|
1255
|
+
this.processStreamResponseLegacy(
|
|
1256
|
+
{
|
|
1257
|
+
...processedParams,
|
|
1258
|
+
messages: [...messages.filter((m) => m.id !== lastMessage.id), lastMessage]
|
|
1259
|
+
},
|
|
1260
|
+
writable
|
|
1261
|
+
).catch((error) => {
|
|
1262
|
+
console.error("Error processing stream response:", error);
|
|
1263
|
+
});
|
|
1264
|
+
}
|
|
1265
|
+
}
|
|
1266
|
+
} else {
|
|
1267
|
+
setTimeout(() => {
|
|
1268
|
+
writable.close();
|
|
1269
|
+
}, 0);
|
|
1270
|
+
}
|
|
1271
|
+
},
|
|
1272
|
+
lastMessage: void 0
|
|
1273
|
+
}).catch((error) => {
|
|
1274
|
+
console.error("Error processing stream response:", error);
|
|
1275
|
+
});
|
|
1276
|
+
} catch (error) {
|
|
1277
|
+
console.error("Error processing stream response:", error);
|
|
1278
|
+
}
|
|
1279
|
+
return response;
|
|
1280
|
+
}
|
|
1281
|
+
/**
|
|
1282
|
+
* Gets details about a specific tool available to the agent
|
|
1283
|
+
* @param toolId - ID of the tool to retrieve
|
|
1284
|
+
* @param runtimeContext - Optional runtime context to pass as query parameter
|
|
1285
|
+
* @returns Promise containing tool details
|
|
1286
|
+
*/
|
|
1287
|
+
getTool(toolId, runtimeContext) {
|
|
1288
|
+
return this.request(`/api/agents/${this.agentId}/tools/${toolId}${runtimeContextQueryString(runtimeContext)}`);
|
|
1289
|
+
}
|
|
1290
|
+
/**
|
|
1291
|
+
* Executes a tool for the agent
|
|
1292
|
+
* @param toolId - ID of the tool to execute
|
|
1293
|
+
* @param params - Parameters required for tool execution
|
|
1294
|
+
* @returns Promise containing the tool execution results
|
|
1295
|
+
*/
|
|
1296
|
+
executeTool(toolId, params) {
|
|
1297
|
+
const body = {
|
|
1298
|
+
data: params.data,
|
|
1299
|
+
runtimeContext: parseClientRuntimeContext(params.runtimeContext)
|
|
1300
|
+
};
|
|
1301
|
+
return this.request(`/api/agents/${this.agentId}/tools/${toolId}/execute`, {
|
|
1302
|
+
method: "POST",
|
|
1303
|
+
body
|
|
1304
|
+
});
|
|
1305
|
+
}
|
|
1306
|
+
/**
|
|
1307
|
+
* Retrieves evaluation results for the agent
|
|
1308
|
+
* @param runtimeContext - Optional runtime context to pass as query parameter
|
|
1309
|
+
* @returns Promise containing agent evaluations
|
|
1310
|
+
*/
|
|
1311
|
+
evals(runtimeContext) {
|
|
1312
|
+
return this.request(`/api/agents/${this.agentId}/evals/ci${runtimeContextQueryString(runtimeContext)}`);
|
|
1313
|
+
}
|
|
1314
|
+
/**
|
|
1315
|
+
* Retrieves live evaluation results for the agent
|
|
1316
|
+
* @param runtimeContext - Optional runtime context to pass as query parameter
|
|
1317
|
+
* @returns Promise containing live agent evaluations
|
|
1318
|
+
*/
|
|
1319
|
+
liveEvals(runtimeContext) {
|
|
1320
|
+
return this.request(`/api/agents/${this.agentId}/evals/live${runtimeContextQueryString(runtimeContext)}`);
|
|
1321
|
+
}
|
|
1322
|
+
/**
|
|
1323
|
+
* Updates the model for the agent
|
|
1324
|
+
* @param params - Parameters for updating the model
|
|
1325
|
+
* @returns Promise containing the updated model
|
|
1326
|
+
*/
|
|
1327
|
+
updateModel(params) {
|
|
1328
|
+
return this.request(`/api/agents/${this.agentId}/model`, {
|
|
1329
|
+
method: "POST",
|
|
1330
|
+
body: params
|
|
1331
|
+
});
|
|
1332
|
+
}
|
|
1333
|
+
/**
|
|
1334
|
+
* Updates the model for the agent in the model list
|
|
1335
|
+
* @param params - Parameters for updating the model
|
|
1336
|
+
* @returns Promise containing the updated model
|
|
1337
|
+
*/
|
|
1338
|
+
updateModelInModelList({ modelConfigId, ...params }) {
|
|
1339
|
+
return this.request(`/api/agents/${this.agentId}/models/${modelConfigId}`, {
|
|
1340
|
+
method: "POST",
|
|
1341
|
+
body: params
|
|
1342
|
+
});
|
|
1343
|
+
}
|
|
1344
|
+
/**
|
|
1345
|
+
* Reorders the models for the agent
|
|
1346
|
+
* @param params - Parameters for reordering the model list
|
|
1347
|
+
* @returns Promise containing the updated model list
|
|
1348
|
+
*/
|
|
1349
|
+
reorderModelList(params) {
|
|
1350
|
+
return this.request(`/api/agents/${this.agentId}/models/reorder`, {
|
|
1351
|
+
method: "POST",
|
|
1352
|
+
body: params
|
|
1353
|
+
});
|
|
1354
|
+
}
|
|
1355
|
+
async generateVNext(_messagesOrParams, _options) {
|
|
1356
|
+
throw new Error("generateVNext has been renamed to generate. Please use generate instead.");
|
|
1357
|
+
}
|
|
1358
|
+
async streamVNext(_messagesOrParams, _options) {
|
|
1359
|
+
throw new Error("streamVNext has been renamed to stream. Please use stream instead.");
|
|
1360
|
+
}
|
|
939
1361
|
};
|
|
940
1362
|
|
|
941
1363
|
// src/resources/memory-thread.ts
|
|
@@ -984,6 +1406,36 @@ var MemoryThread = class extends BaseResource {
|
|
|
984
1406
|
});
|
|
985
1407
|
return this.request(`/api/memory/threads/${this.threadId}/messages?${query.toString()}`);
|
|
986
1408
|
}
|
|
1409
|
+
/**
|
|
1410
|
+
* Retrieves paginated messages associated with the thread with advanced filtering and selection options
|
|
1411
|
+
* @param params - Pagination parameters including selectBy criteria, page, perPage, date ranges, and message inclusion options
|
|
1412
|
+
* @returns Promise containing paginated thread messages with pagination metadata (total, page, perPage, hasMore)
|
|
1413
|
+
*/
|
|
1414
|
+
getMessagesPaginated({
|
|
1415
|
+
selectBy,
|
|
1416
|
+
...rest
|
|
1417
|
+
}) {
|
|
1418
|
+
const query = new URLSearchParams({
|
|
1419
|
+
...rest,
|
|
1420
|
+
...selectBy ? { selectBy: JSON.stringify(selectBy) } : {}
|
|
1421
|
+
});
|
|
1422
|
+
return this.request(`/api/memory/threads/${this.threadId}/messages/paginated?${query.toString()}`);
|
|
1423
|
+
}
|
|
1424
|
+
/**
|
|
1425
|
+
* Deletes one or more messages from the thread
|
|
1426
|
+
* @param messageIds - Can be a single message ID (string), array of message IDs,
|
|
1427
|
+
* message object with id property, or array of message objects
|
|
1428
|
+
* @returns Promise containing deletion result
|
|
1429
|
+
*/
|
|
1430
|
+
deleteMessages(messageIds) {
|
|
1431
|
+
const query = new URLSearchParams({
|
|
1432
|
+
agentId: this.agentId
|
|
1433
|
+
});
|
|
1434
|
+
return this.request(`/api/memory/messages/delete?${query.toString()}`, {
|
|
1435
|
+
method: "POST",
|
|
1436
|
+
body: { messageIds }
|
|
1437
|
+
});
|
|
1438
|
+
}
|
|
987
1439
|
};
|
|
988
1440
|
|
|
989
1441
|
// src/resources/vector.ts
|
|
@@ -995,10 +1447,13 @@ var Vector = class extends BaseResource {
|
|
|
995
1447
|
/**
|
|
996
1448
|
* Retrieves details about a specific vector index
|
|
997
1449
|
* @param indexName - Name of the index to get details for
|
|
1450
|
+
* @param runtimeContext - Optional runtime context to pass as query parameter
|
|
998
1451
|
* @returns Promise containing vector index details
|
|
999
1452
|
*/
|
|
1000
|
-
details(indexName) {
|
|
1001
|
-
return this.request(
|
|
1453
|
+
details(indexName, runtimeContext) {
|
|
1454
|
+
return this.request(
|
|
1455
|
+
`/api/vector/${this.vectorName}/indexes/${indexName}${runtimeContextQueryString(runtimeContext)}`
|
|
1456
|
+
);
|
|
1002
1457
|
}
|
|
1003
1458
|
/**
|
|
1004
1459
|
* Deletes a vector index
|
|
@@ -1012,10 +1467,11 @@ var Vector = class extends BaseResource {
|
|
|
1012
1467
|
}
|
|
1013
1468
|
/**
|
|
1014
1469
|
* Retrieves a list of all available indexes
|
|
1470
|
+
* @param runtimeContext - Optional runtime context to pass as query parameter
|
|
1015
1471
|
* @returns Promise containing array of index names
|
|
1016
1472
|
*/
|
|
1017
|
-
getIndexes() {
|
|
1018
|
-
return this.request(`/api/vector/${this.vectorName}/indexes`);
|
|
1473
|
+
getIndexes(runtimeContext) {
|
|
1474
|
+
return this.request(`/api/vector/${this.vectorName}/indexes${runtimeContextQueryString(runtimeContext)}`);
|
|
1019
1475
|
}
|
|
1020
1476
|
/**
|
|
1021
1477
|
* Creates a new vector index
|
|
@@ -1052,123 +1508,50 @@ var Vector = class extends BaseResource {
|
|
|
1052
1508
|
}
|
|
1053
1509
|
};
|
|
1054
1510
|
|
|
1055
|
-
// src/resources/
|
|
1056
|
-
var
|
|
1057
|
-
|
|
1058
|
-
constructor(options, workflowId) {
|
|
1511
|
+
// src/resources/tool.ts
|
|
1512
|
+
var Tool = class extends BaseResource {
|
|
1513
|
+
constructor(options, toolId) {
|
|
1059
1514
|
super(options);
|
|
1060
|
-
this.
|
|
1061
|
-
}
|
|
1062
|
-
/**
|
|
1063
|
-
* Retrieves details about the legacy workflow
|
|
1064
|
-
* @returns Promise containing legacy workflow details including steps and graphs
|
|
1065
|
-
*/
|
|
1066
|
-
details() {
|
|
1067
|
-
return this.request(`/api/workflows/legacy/${this.workflowId}`);
|
|
1068
|
-
}
|
|
1069
|
-
/**
|
|
1070
|
-
* Retrieves all runs for a legacy workflow
|
|
1071
|
-
* @param params - Parameters for filtering runs
|
|
1072
|
-
* @returns Promise containing legacy workflow runs array
|
|
1073
|
-
*/
|
|
1074
|
-
runs(params) {
|
|
1075
|
-
const searchParams = new URLSearchParams();
|
|
1076
|
-
if (params?.fromDate) {
|
|
1077
|
-
searchParams.set("fromDate", params.fromDate.toISOString());
|
|
1078
|
-
}
|
|
1079
|
-
if (params?.toDate) {
|
|
1080
|
-
searchParams.set("toDate", params.toDate.toISOString());
|
|
1081
|
-
}
|
|
1082
|
-
if (params?.limit) {
|
|
1083
|
-
searchParams.set("limit", String(params.limit));
|
|
1084
|
-
}
|
|
1085
|
-
if (params?.offset) {
|
|
1086
|
-
searchParams.set("offset", String(params.offset));
|
|
1087
|
-
}
|
|
1088
|
-
if (params?.resourceId) {
|
|
1089
|
-
searchParams.set("resourceId", params.resourceId);
|
|
1090
|
-
}
|
|
1091
|
-
if (searchParams.size) {
|
|
1092
|
-
return this.request(`/api/workflows/legacy/${this.workflowId}/runs?${searchParams}`);
|
|
1093
|
-
} else {
|
|
1094
|
-
return this.request(`/api/workflows/legacy/${this.workflowId}/runs`);
|
|
1095
|
-
}
|
|
1096
|
-
}
|
|
1097
|
-
/**
|
|
1098
|
-
* Creates a new legacy workflow run
|
|
1099
|
-
* @returns Promise containing the generated run ID
|
|
1100
|
-
*/
|
|
1101
|
-
createRun(params) {
|
|
1102
|
-
const searchParams = new URLSearchParams();
|
|
1103
|
-
if (!!params?.runId) {
|
|
1104
|
-
searchParams.set("runId", params.runId);
|
|
1105
|
-
}
|
|
1106
|
-
return this.request(`/api/workflows/legacy/${this.workflowId}/create-run?${searchParams.toString()}`, {
|
|
1107
|
-
method: "POST"
|
|
1108
|
-
});
|
|
1109
|
-
}
|
|
1110
|
-
/**
|
|
1111
|
-
* Starts a legacy workflow run synchronously without waiting for the workflow to complete
|
|
1112
|
-
* @param params - Object containing the runId and triggerData
|
|
1113
|
-
* @returns Promise containing success message
|
|
1114
|
-
*/
|
|
1115
|
-
start(params) {
|
|
1116
|
-
return this.request(`/api/workflows/legacy/${this.workflowId}/start?runId=${params.runId}`, {
|
|
1117
|
-
method: "POST",
|
|
1118
|
-
body: params?.triggerData
|
|
1119
|
-
});
|
|
1515
|
+
this.toolId = toolId;
|
|
1120
1516
|
}
|
|
1121
1517
|
/**
|
|
1122
|
-
*
|
|
1123
|
-
* @param
|
|
1124
|
-
* @
|
|
1125
|
-
* @param context - Context to resume the legacy workflow with
|
|
1126
|
-
* @returns Promise containing the legacy workflow resume results
|
|
1518
|
+
* Retrieves details about the tool
|
|
1519
|
+
* @param runtimeContext - Optional runtime context to pass as query parameter
|
|
1520
|
+
* @returns Promise containing tool details including description and schemas
|
|
1127
1521
|
*/
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
runId,
|
|
1131
|
-
context
|
|
1132
|
-
}) {
|
|
1133
|
-
return this.request(`/api/workflows/legacy/${this.workflowId}/resume?runId=${runId}`, {
|
|
1134
|
-
method: "POST",
|
|
1135
|
-
body: {
|
|
1136
|
-
stepId,
|
|
1137
|
-
context
|
|
1138
|
-
}
|
|
1139
|
-
});
|
|
1522
|
+
details(runtimeContext) {
|
|
1523
|
+
return this.request(`/api/tools/${this.toolId}${runtimeContextQueryString(runtimeContext)}`);
|
|
1140
1524
|
}
|
|
1141
1525
|
/**
|
|
1142
|
-
*
|
|
1143
|
-
* @param params -
|
|
1144
|
-
* @returns Promise containing the
|
|
1526
|
+
* Executes the tool with the provided parameters
|
|
1527
|
+
* @param params - Parameters required for tool execution
|
|
1528
|
+
* @returns Promise containing the tool execution results
|
|
1145
1529
|
*/
|
|
1146
|
-
|
|
1147
|
-
const
|
|
1148
|
-
if (
|
|
1149
|
-
|
|
1530
|
+
execute(params) {
|
|
1531
|
+
const url = new URLSearchParams();
|
|
1532
|
+
if (params.runId) {
|
|
1533
|
+
url.set("runId", params.runId);
|
|
1150
1534
|
}
|
|
1151
|
-
|
|
1535
|
+
const body = {
|
|
1536
|
+
data: params.data,
|
|
1537
|
+
runtimeContext: parseClientRuntimeContext(params.runtimeContext)
|
|
1538
|
+
};
|
|
1539
|
+
return this.request(`/api/tools/${this.toolId}/execute?${url.toString()}`, {
|
|
1152
1540
|
method: "POST",
|
|
1153
|
-
body
|
|
1541
|
+
body
|
|
1154
1542
|
});
|
|
1155
1543
|
}
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
body: {
|
|
1165
|
-
stepId: params.stepId,
|
|
1166
|
-
context: params.context
|
|
1167
|
-
}
|
|
1168
|
-
});
|
|
1544
|
+
};
|
|
1545
|
+
|
|
1546
|
+
// src/resources/workflow.ts
|
|
1547
|
+
var RECORD_SEPARATOR = "";
|
|
1548
|
+
var Workflow = class extends BaseResource {
|
|
1549
|
+
constructor(options, workflowId) {
|
|
1550
|
+
super(options);
|
|
1551
|
+
this.workflowId = workflowId;
|
|
1169
1552
|
}
|
|
1170
1553
|
/**
|
|
1171
|
-
* Creates an async generator that processes a readable stream and yields records
|
|
1554
|
+
* Creates an async generator that processes a readable stream and yields workflow records
|
|
1172
1555
|
* separated by the Record Separator character (\x1E)
|
|
1173
1556
|
*
|
|
1174
1557
|
* @param stream - The readable stream to process
|
|
@@ -1213,69 +1596,771 @@ var LegacyWorkflow = class extends BaseResource {
|
|
|
1213
1596
|
}
|
|
1214
1597
|
}
|
|
1215
1598
|
/**
|
|
1216
|
-
*
|
|
1217
|
-
* @param
|
|
1218
|
-
* @returns
|
|
1599
|
+
* Retrieves details about the workflow
|
|
1600
|
+
* @param runtimeContext - Optional runtime context to pass as query parameter
|
|
1601
|
+
* @returns Promise containing workflow details including steps and graphs
|
|
1219
1602
|
*/
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1603
|
+
details(runtimeContext) {
|
|
1604
|
+
return this.request(`/api/workflows/${this.workflowId}${runtimeContextQueryString(runtimeContext)}`);
|
|
1605
|
+
}
|
|
1606
|
+
/**
|
|
1607
|
+
* Retrieves all runs for a workflow
|
|
1608
|
+
* @param params - Parameters for filtering runs
|
|
1609
|
+
* @param runtimeContext - Optional runtime context to pass as query parameter
|
|
1610
|
+
* @returns Promise containing workflow runs array
|
|
1611
|
+
*/
|
|
1612
|
+
runs(params, runtimeContext) {
|
|
1613
|
+
const runtimeContextParam = base64RuntimeContext(parseClientRuntimeContext(runtimeContext));
|
|
1614
|
+
const searchParams = new URLSearchParams();
|
|
1615
|
+
if (params?.fromDate) {
|
|
1616
|
+
searchParams.set("fromDate", params.fromDate.toISOString());
|
|
1617
|
+
}
|
|
1618
|
+
if (params?.toDate) {
|
|
1619
|
+
searchParams.set("toDate", params.toDate.toISOString());
|
|
1620
|
+
}
|
|
1621
|
+
if (params?.limit !== null && params?.limit !== void 0 && !isNaN(Number(params?.limit))) {
|
|
1622
|
+
searchParams.set("limit", String(params.limit));
|
|
1623
|
+
}
|
|
1624
|
+
if (params?.offset !== null && params?.offset !== void 0 && !isNaN(Number(params?.offset))) {
|
|
1625
|
+
searchParams.set("offset", String(params.offset));
|
|
1626
|
+
}
|
|
1627
|
+
if (params?.resourceId) {
|
|
1628
|
+
searchParams.set("resourceId", params.resourceId);
|
|
1629
|
+
}
|
|
1630
|
+
if (runtimeContextParam) {
|
|
1631
|
+
searchParams.set("runtimeContext", runtimeContextParam);
|
|
1632
|
+
}
|
|
1633
|
+
if (searchParams.size) {
|
|
1634
|
+
return this.request(`/api/workflows/${this.workflowId}/runs?${searchParams}`);
|
|
1635
|
+
} else {
|
|
1636
|
+
return this.request(`/api/workflows/${this.workflowId}/runs`);
|
|
1637
|
+
}
|
|
1638
|
+
}
|
|
1639
|
+
/**
|
|
1640
|
+
* Retrieves a specific workflow run by its ID
|
|
1641
|
+
* @param runId - The ID of the workflow run to retrieve
|
|
1642
|
+
* @param runtimeContext - Optional runtime context to pass as query parameter
|
|
1643
|
+
* @returns Promise containing the workflow run details
|
|
1644
|
+
*/
|
|
1645
|
+
runById(runId, runtimeContext) {
|
|
1646
|
+
return this.request(`/api/workflows/${this.workflowId}/runs/${runId}${runtimeContextQueryString(runtimeContext)}`);
|
|
1647
|
+
}
|
|
1648
|
+
/**
|
|
1649
|
+
* Retrieves the execution result for a specific workflow run by its ID
|
|
1650
|
+
* @param runId - The ID of the workflow run to retrieve the execution result for
|
|
1651
|
+
* @param runtimeContext - Optional runtime context to pass as query parameter
|
|
1652
|
+
* @returns Promise containing the workflow run execution result
|
|
1653
|
+
*/
|
|
1654
|
+
runExecutionResult(runId, runtimeContext) {
|
|
1655
|
+
return this.request(
|
|
1656
|
+
`/api/workflows/${this.workflowId}/runs/${runId}/execution-result${runtimeContextQueryString(runtimeContext)}`
|
|
1657
|
+
);
|
|
1658
|
+
}
|
|
1659
|
+
/**
|
|
1660
|
+
* Cancels a specific workflow run by its ID
|
|
1661
|
+
* @param runId - The ID of the workflow run to cancel
|
|
1662
|
+
* @returns Promise containing a success message
|
|
1663
|
+
*/
|
|
1664
|
+
cancelRun(runId) {
|
|
1665
|
+
return this.request(`/api/workflows/${this.workflowId}/runs/${runId}/cancel`, {
|
|
1666
|
+
method: "POST"
|
|
1667
|
+
});
|
|
1668
|
+
}
|
|
1669
|
+
/**
|
|
1670
|
+
* Sends an event to a specific workflow run by its ID
|
|
1671
|
+
* @param params - Object containing the runId, event and data
|
|
1672
|
+
* @returns Promise containing a success message
|
|
1673
|
+
*/
|
|
1674
|
+
sendRunEvent(params) {
|
|
1675
|
+
return this.request(`/api/workflows/${this.workflowId}/runs/${params.runId}/send-event`, {
|
|
1676
|
+
method: "POST",
|
|
1677
|
+
body: { event: params.event, data: params.data }
|
|
1678
|
+
});
|
|
1679
|
+
}
|
|
1680
|
+
/**
|
|
1681
|
+
* @deprecated Use createRunAsync() instead.
|
|
1682
|
+
* @throws {Error} Always throws an error directing users to use createRunAsync()
|
|
1683
|
+
*/
|
|
1684
|
+
async createRun(_params) {
|
|
1685
|
+
throw new Error(
|
|
1686
|
+
"createRun() has been deprecated. Please use createRunAsync() instead.\n\nMigration guide:\n Before: const run = workflow.createRun();\n After: const run = await workflow.createRunAsync();\n\nNote: createRunAsync() is an async method, so make sure your calling function is async."
|
|
1687
|
+
);
|
|
1688
|
+
}
|
|
1689
|
+
/**
|
|
1690
|
+
* Creates a new workflow run
|
|
1691
|
+
* @param params - Optional object containing the optional runId
|
|
1692
|
+
* @returns Promise containing the runId of the created run with methods to control execution
|
|
1693
|
+
*/
|
|
1694
|
+
async createRunAsync(params) {
|
|
1695
|
+
const searchParams = new URLSearchParams();
|
|
1696
|
+
if (!!params?.runId) {
|
|
1697
|
+
searchParams.set("runId", params.runId);
|
|
1698
|
+
}
|
|
1699
|
+
const res = await this.request(
|
|
1700
|
+
`/api/workflows/${this.workflowId}/create-run?${searchParams.toString()}`,
|
|
1701
|
+
{
|
|
1702
|
+
method: "POST"
|
|
1703
|
+
}
|
|
1704
|
+
);
|
|
1705
|
+
const runId = res.runId;
|
|
1706
|
+
return {
|
|
1707
|
+
runId,
|
|
1708
|
+
start: async (p) => {
|
|
1709
|
+
return this.start({
|
|
1710
|
+
runId,
|
|
1711
|
+
inputData: p.inputData,
|
|
1712
|
+
runtimeContext: p.runtimeContext,
|
|
1713
|
+
tracingOptions: p.tracingOptions
|
|
1714
|
+
});
|
|
1715
|
+
},
|
|
1716
|
+
startAsync: async (p) => {
|
|
1717
|
+
return this.startAsync({
|
|
1718
|
+
runId,
|
|
1719
|
+
inputData: p.inputData,
|
|
1720
|
+
runtimeContext: p.runtimeContext,
|
|
1721
|
+
tracingOptions: p.tracingOptions
|
|
1722
|
+
});
|
|
1723
|
+
},
|
|
1724
|
+
watch: async (onRecord) => {
|
|
1725
|
+
return this.watch({ runId }, onRecord);
|
|
1726
|
+
},
|
|
1727
|
+
stream: async (p) => {
|
|
1728
|
+
return this.stream({ runId, inputData: p.inputData, runtimeContext: p.runtimeContext });
|
|
1729
|
+
},
|
|
1730
|
+
resume: async (p) => {
|
|
1731
|
+
return this.resume({
|
|
1732
|
+
runId,
|
|
1733
|
+
step: p.step,
|
|
1734
|
+
resumeData: p.resumeData,
|
|
1735
|
+
runtimeContext: p.runtimeContext,
|
|
1736
|
+
tracingOptions: p.tracingOptions
|
|
1737
|
+
});
|
|
1738
|
+
},
|
|
1739
|
+
resumeAsync: async (p) => {
|
|
1740
|
+
return this.resumeAsync({
|
|
1741
|
+
runId,
|
|
1742
|
+
step: p.step,
|
|
1743
|
+
resumeData: p.resumeData,
|
|
1744
|
+
runtimeContext: p.runtimeContext,
|
|
1745
|
+
tracingOptions: p.tracingOptions
|
|
1746
|
+
});
|
|
1747
|
+
},
|
|
1748
|
+
resumeStreamVNext: async (p) => {
|
|
1749
|
+
return this.resumeStreamVNext({
|
|
1750
|
+
runId,
|
|
1751
|
+
step: p.step,
|
|
1752
|
+
resumeData: p.resumeData,
|
|
1753
|
+
runtimeContext: p.runtimeContext
|
|
1754
|
+
});
|
|
1755
|
+
}
|
|
1756
|
+
};
|
|
1757
|
+
}
|
|
1758
|
+
/**
|
|
1759
|
+
* Starts a workflow run synchronously without waiting for the workflow to complete
|
|
1760
|
+
* @param params - Object containing the runId, inputData and runtimeContext
|
|
1761
|
+
* @returns Promise containing success message
|
|
1762
|
+
*/
|
|
1763
|
+
start(params) {
|
|
1764
|
+
const runtimeContext = parseClientRuntimeContext(params.runtimeContext);
|
|
1765
|
+
return this.request(`/api/workflows/${this.workflowId}/start?runId=${params.runId}`, {
|
|
1766
|
+
method: "POST",
|
|
1767
|
+
body: { inputData: params?.inputData, runtimeContext, tracingOptions: params.tracingOptions }
|
|
1768
|
+
});
|
|
1769
|
+
}
|
|
1770
|
+
/**
|
|
1771
|
+
* Resumes a suspended workflow step synchronously without waiting for the workflow to complete
|
|
1772
|
+
* @param params - Object containing the runId, step, resumeData and runtimeContext
|
|
1773
|
+
* @returns Promise containing success message
|
|
1774
|
+
*/
|
|
1775
|
+
resume({
|
|
1776
|
+
step,
|
|
1777
|
+
runId,
|
|
1778
|
+
resumeData,
|
|
1779
|
+
tracingOptions,
|
|
1780
|
+
...rest
|
|
1781
|
+
}) {
|
|
1782
|
+
const runtimeContext = parseClientRuntimeContext(rest.runtimeContext);
|
|
1783
|
+
return this.request(`/api/workflows/${this.workflowId}/resume?runId=${runId}`, {
|
|
1784
|
+
method: "POST",
|
|
1785
|
+
body: {
|
|
1786
|
+
step,
|
|
1787
|
+
resumeData,
|
|
1788
|
+
runtimeContext,
|
|
1789
|
+
tracingOptions
|
|
1790
|
+
}
|
|
1791
|
+
});
|
|
1792
|
+
}
|
|
1793
|
+
/**
|
|
1794
|
+
* Starts a workflow run asynchronously and returns a promise that resolves when the workflow is complete
|
|
1795
|
+
* @param params - Object containing the optional runId, inputData and runtimeContext
|
|
1796
|
+
* @returns Promise containing the workflow execution results
|
|
1797
|
+
*/
|
|
1798
|
+
startAsync(params) {
|
|
1799
|
+
const searchParams = new URLSearchParams();
|
|
1800
|
+
if (!!params?.runId) {
|
|
1801
|
+
searchParams.set("runId", params.runId);
|
|
1802
|
+
}
|
|
1803
|
+
const runtimeContext = parseClientRuntimeContext(params.runtimeContext);
|
|
1804
|
+
return this.request(`/api/workflows/${this.workflowId}/start-async?${searchParams.toString()}`, {
|
|
1805
|
+
method: "POST",
|
|
1806
|
+
body: { inputData: params.inputData, runtimeContext, tracingOptions: params.tracingOptions }
|
|
1807
|
+
});
|
|
1808
|
+
}
|
|
1809
|
+
/**
|
|
1810
|
+
* Starts a workflow run and returns a stream
|
|
1811
|
+
* @param params - Object containing the optional runId, inputData and runtimeContext
|
|
1812
|
+
* @returns Promise containing the workflow execution results
|
|
1813
|
+
*/
|
|
1814
|
+
async stream(params) {
|
|
1815
|
+
const searchParams = new URLSearchParams();
|
|
1816
|
+
if (!!params?.runId) {
|
|
1817
|
+
searchParams.set("runId", params.runId);
|
|
1818
|
+
}
|
|
1819
|
+
const runtimeContext = parseClientRuntimeContext(params.runtimeContext);
|
|
1820
|
+
const response = await this.request(
|
|
1821
|
+
`/api/workflows/${this.workflowId}/stream?${searchParams.toString()}`,
|
|
1822
|
+
{
|
|
1823
|
+
method: "POST",
|
|
1824
|
+
body: { inputData: params.inputData, runtimeContext, tracingOptions: params.tracingOptions },
|
|
1825
|
+
stream: true
|
|
1826
|
+
}
|
|
1827
|
+
);
|
|
1828
|
+
if (!response.ok) {
|
|
1829
|
+
throw new Error(`Failed to stream workflow: ${response.statusText}`);
|
|
1830
|
+
}
|
|
1831
|
+
if (!response.body) {
|
|
1832
|
+
throw new Error("Response body is null");
|
|
1833
|
+
}
|
|
1834
|
+
let failedChunk = void 0;
|
|
1835
|
+
const transformStream = new TransformStream({
|
|
1836
|
+
start() {
|
|
1837
|
+
},
|
|
1838
|
+
async transform(chunk, controller) {
|
|
1839
|
+
try {
|
|
1840
|
+
const decoded = new TextDecoder().decode(chunk);
|
|
1841
|
+
const chunks = decoded.split(RECORD_SEPARATOR);
|
|
1842
|
+
for (const chunk2 of chunks) {
|
|
1843
|
+
if (chunk2) {
|
|
1844
|
+
const newChunk = failedChunk ? failedChunk + chunk2 : chunk2;
|
|
1845
|
+
try {
|
|
1846
|
+
const parsedChunk = JSON.parse(newChunk);
|
|
1847
|
+
controller.enqueue(parsedChunk);
|
|
1848
|
+
failedChunk = void 0;
|
|
1849
|
+
} catch {
|
|
1850
|
+
failedChunk = newChunk;
|
|
1851
|
+
}
|
|
1852
|
+
}
|
|
1853
|
+
}
|
|
1854
|
+
} catch {
|
|
1855
|
+
}
|
|
1856
|
+
}
|
|
1857
|
+
});
|
|
1858
|
+
return response.body.pipeThrough(transformStream);
|
|
1859
|
+
}
|
|
1860
|
+
/**
|
|
1861
|
+
* Observes workflow stream for a workflow run
|
|
1862
|
+
* @param params - Object containing the runId
|
|
1863
|
+
* @returns Promise containing the workflow execution results
|
|
1864
|
+
*/
|
|
1865
|
+
async observeStream(params) {
|
|
1866
|
+
const searchParams = new URLSearchParams();
|
|
1867
|
+
searchParams.set("runId", params.runId);
|
|
1868
|
+
const response = await this.request(
|
|
1869
|
+
`/api/workflows/${this.workflowId}/observe-stream?${searchParams.toString()}`,
|
|
1870
|
+
{
|
|
1871
|
+
method: "POST",
|
|
1872
|
+
stream: true
|
|
1873
|
+
}
|
|
1874
|
+
);
|
|
1875
|
+
if (!response.ok) {
|
|
1876
|
+
throw new Error(`Failed to observe workflow stream: ${response.statusText}`);
|
|
1877
|
+
}
|
|
1878
|
+
if (!response.body) {
|
|
1879
|
+
throw new Error("Response body is null");
|
|
1880
|
+
}
|
|
1881
|
+
let failedChunk = void 0;
|
|
1882
|
+
const transformStream = new TransformStream({
|
|
1883
|
+
start() {
|
|
1884
|
+
},
|
|
1885
|
+
async transform(chunk, controller) {
|
|
1886
|
+
try {
|
|
1887
|
+
const decoded = new TextDecoder().decode(chunk);
|
|
1888
|
+
const chunks = decoded.split(RECORD_SEPARATOR);
|
|
1889
|
+
for (const chunk2 of chunks) {
|
|
1890
|
+
if (chunk2) {
|
|
1891
|
+
const newChunk = failedChunk ? failedChunk + chunk2 : chunk2;
|
|
1892
|
+
try {
|
|
1893
|
+
const parsedChunk = JSON.parse(newChunk);
|
|
1894
|
+
controller.enqueue(parsedChunk);
|
|
1895
|
+
failedChunk = void 0;
|
|
1896
|
+
} catch {
|
|
1897
|
+
failedChunk = newChunk;
|
|
1898
|
+
}
|
|
1899
|
+
}
|
|
1900
|
+
}
|
|
1901
|
+
} catch {
|
|
1902
|
+
}
|
|
1903
|
+
}
|
|
1904
|
+
});
|
|
1905
|
+
return response.body.pipeThrough(transformStream);
|
|
1906
|
+
}
|
|
1907
|
+
/**
|
|
1908
|
+
* Starts a workflow run and returns a stream
|
|
1909
|
+
* @param params - Object containing the optional runId, inputData and runtimeContext
|
|
1910
|
+
* @returns Promise containing the workflow execution results
|
|
1911
|
+
*/
|
|
1912
|
+
async streamVNext(params) {
|
|
1913
|
+
const searchParams = new URLSearchParams();
|
|
1914
|
+
if (!!params?.runId) {
|
|
1915
|
+
searchParams.set("runId", params.runId);
|
|
1916
|
+
}
|
|
1917
|
+
const runtimeContext = parseClientRuntimeContext(params.runtimeContext);
|
|
1918
|
+
const response = await this.request(
|
|
1919
|
+
`/api/workflows/${this.workflowId}/streamVNext?${searchParams.toString()}`,
|
|
1920
|
+
{
|
|
1921
|
+
method: "POST",
|
|
1922
|
+
body: {
|
|
1923
|
+
inputData: params.inputData,
|
|
1924
|
+
runtimeContext,
|
|
1925
|
+
closeOnSuspend: params.closeOnSuspend,
|
|
1926
|
+
tracingOptions: params.tracingOptions
|
|
1927
|
+
},
|
|
1928
|
+
stream: true
|
|
1929
|
+
}
|
|
1930
|
+
);
|
|
1931
|
+
if (!response.ok) {
|
|
1932
|
+
throw new Error(`Failed to stream vNext workflow: ${response.statusText}`);
|
|
1933
|
+
}
|
|
1934
|
+
if (!response.body) {
|
|
1935
|
+
throw new Error("Response body is null");
|
|
1936
|
+
}
|
|
1937
|
+
let failedChunk = void 0;
|
|
1938
|
+
const transformStream = new TransformStream({
|
|
1939
|
+
start() {
|
|
1940
|
+
},
|
|
1941
|
+
async transform(chunk, controller) {
|
|
1942
|
+
try {
|
|
1943
|
+
const decoded = new TextDecoder().decode(chunk);
|
|
1944
|
+
const chunks = decoded.split(RECORD_SEPARATOR);
|
|
1945
|
+
for (const chunk2 of chunks) {
|
|
1946
|
+
if (chunk2) {
|
|
1947
|
+
const newChunk = failedChunk ? failedChunk + chunk2 : chunk2;
|
|
1948
|
+
try {
|
|
1949
|
+
const parsedChunk = JSON.parse(newChunk);
|
|
1950
|
+
controller.enqueue(parsedChunk);
|
|
1951
|
+
failedChunk = void 0;
|
|
1952
|
+
} catch {
|
|
1953
|
+
failedChunk = newChunk;
|
|
1954
|
+
}
|
|
1955
|
+
}
|
|
1956
|
+
}
|
|
1957
|
+
} catch {
|
|
1958
|
+
}
|
|
1959
|
+
}
|
|
1960
|
+
});
|
|
1961
|
+
return response.body.pipeThrough(transformStream);
|
|
1962
|
+
}
|
|
1963
|
+
/**
|
|
1964
|
+
* Observes workflow vNext stream for a workflow run
|
|
1965
|
+
* @param params - Object containing the runId
|
|
1966
|
+
* @returns Promise containing the workflow execution results
|
|
1967
|
+
*/
|
|
1968
|
+
async observeStreamVNext(params) {
|
|
1969
|
+
const searchParams = new URLSearchParams();
|
|
1970
|
+
searchParams.set("runId", params.runId);
|
|
1971
|
+
const response = await this.request(
|
|
1972
|
+
`/api/workflows/${this.workflowId}/observe-streamVNext?${searchParams.toString()}`,
|
|
1973
|
+
{
|
|
1974
|
+
method: "POST",
|
|
1975
|
+
stream: true
|
|
1976
|
+
}
|
|
1977
|
+
);
|
|
1978
|
+
if (!response.ok) {
|
|
1979
|
+
throw new Error(`Failed to observe stream vNext workflow: ${response.statusText}`);
|
|
1980
|
+
}
|
|
1981
|
+
if (!response.body) {
|
|
1982
|
+
throw new Error("Response body is null");
|
|
1983
|
+
}
|
|
1984
|
+
let failedChunk = void 0;
|
|
1985
|
+
const transformStream = new TransformStream({
|
|
1986
|
+
start() {
|
|
1987
|
+
},
|
|
1988
|
+
async transform(chunk, controller) {
|
|
1989
|
+
try {
|
|
1990
|
+
const decoded = new TextDecoder().decode(chunk);
|
|
1991
|
+
const chunks = decoded.split(RECORD_SEPARATOR);
|
|
1992
|
+
for (const chunk2 of chunks) {
|
|
1993
|
+
if (chunk2) {
|
|
1994
|
+
const newChunk = failedChunk ? failedChunk + chunk2 : chunk2;
|
|
1995
|
+
try {
|
|
1996
|
+
const parsedChunk = JSON.parse(newChunk);
|
|
1997
|
+
controller.enqueue(parsedChunk);
|
|
1998
|
+
failedChunk = void 0;
|
|
1999
|
+
} catch {
|
|
2000
|
+
failedChunk = newChunk;
|
|
2001
|
+
}
|
|
2002
|
+
}
|
|
2003
|
+
}
|
|
2004
|
+
} catch {
|
|
2005
|
+
}
|
|
2006
|
+
}
|
|
2007
|
+
});
|
|
2008
|
+
return response.body.pipeThrough(transformStream);
|
|
2009
|
+
}
|
|
2010
|
+
/**
|
|
2011
|
+
* Resumes a suspended workflow step asynchronously and returns a promise that resolves when the workflow is complete
|
|
2012
|
+
* @param params - Object containing the runId, step, resumeData and runtimeContext
|
|
2013
|
+
* @returns Promise containing the workflow resume results
|
|
2014
|
+
*/
|
|
2015
|
+
resumeAsync(params) {
|
|
2016
|
+
const runtimeContext = parseClientRuntimeContext(params.runtimeContext);
|
|
2017
|
+
return this.request(`/api/workflows/${this.workflowId}/resume-async?runId=${params.runId}`, {
|
|
2018
|
+
method: "POST",
|
|
2019
|
+
body: {
|
|
2020
|
+
step: params.step,
|
|
2021
|
+
resumeData: params.resumeData,
|
|
2022
|
+
runtimeContext,
|
|
2023
|
+
tracingOptions: params.tracingOptions
|
|
2024
|
+
}
|
|
2025
|
+
});
|
|
2026
|
+
}
|
|
2027
|
+
/**
|
|
2028
|
+
* Resumes a suspended workflow step that uses streamVNext asynchronously and returns a promise that resolves when the workflow is complete
|
|
2029
|
+
* @param params - Object containing the runId, step, resumeData and runtimeContext
|
|
2030
|
+
* @returns Promise containing the workflow resume results
|
|
2031
|
+
*/
|
|
2032
|
+
async resumeStreamVNext(params) {
|
|
2033
|
+
const searchParams = new URLSearchParams();
|
|
2034
|
+
searchParams.set("runId", params.runId);
|
|
2035
|
+
const runtimeContext = parseClientRuntimeContext(params.runtimeContext);
|
|
2036
|
+
const response = await this.request(
|
|
2037
|
+
`/api/workflows/${this.workflowId}/resume-stream?${searchParams.toString()}`,
|
|
2038
|
+
{
|
|
2039
|
+
method: "POST",
|
|
2040
|
+
body: {
|
|
2041
|
+
step: params.step,
|
|
2042
|
+
resumeData: params.resumeData,
|
|
2043
|
+
runtimeContext,
|
|
2044
|
+
tracingOptions: params.tracingOptions
|
|
2045
|
+
},
|
|
2046
|
+
stream: true
|
|
2047
|
+
}
|
|
2048
|
+
);
|
|
2049
|
+
if (!response.ok) {
|
|
2050
|
+
throw new Error(`Failed to stream vNext workflow: ${response.statusText}`);
|
|
2051
|
+
}
|
|
2052
|
+
if (!response.body) {
|
|
2053
|
+
throw new Error("Response body is null");
|
|
2054
|
+
}
|
|
2055
|
+
let failedChunk = void 0;
|
|
2056
|
+
const transformStream = new TransformStream({
|
|
2057
|
+
start() {
|
|
2058
|
+
},
|
|
2059
|
+
async transform(chunk, controller) {
|
|
2060
|
+
try {
|
|
2061
|
+
const decoded = new TextDecoder().decode(chunk);
|
|
2062
|
+
const chunks = decoded.split(RECORD_SEPARATOR);
|
|
2063
|
+
for (const chunk2 of chunks) {
|
|
2064
|
+
if (chunk2) {
|
|
2065
|
+
const newChunk = failedChunk ? failedChunk + chunk2 : chunk2;
|
|
2066
|
+
try {
|
|
2067
|
+
const parsedChunk = JSON.parse(newChunk);
|
|
2068
|
+
controller.enqueue(parsedChunk);
|
|
2069
|
+
failedChunk = void 0;
|
|
2070
|
+
} catch {
|
|
2071
|
+
failedChunk = newChunk;
|
|
2072
|
+
}
|
|
2073
|
+
}
|
|
2074
|
+
}
|
|
2075
|
+
} catch {
|
|
2076
|
+
}
|
|
2077
|
+
}
|
|
2078
|
+
});
|
|
2079
|
+
return response.body.pipeThrough(transformStream);
|
|
2080
|
+
}
|
|
2081
|
+
/**
|
|
2082
|
+
* Watches workflow transitions in real-time
|
|
2083
|
+
* @param runId - Optional run ID to filter the watch stream
|
|
2084
|
+
* @returns AsyncGenerator that yields parsed records from the workflow watch stream
|
|
2085
|
+
*/
|
|
2086
|
+
async watch({ runId }, onRecord) {
|
|
2087
|
+
const response = await this.request(`/api/workflows/${this.workflowId}/watch?runId=${runId}`, {
|
|
2088
|
+
stream: true
|
|
2089
|
+
});
|
|
2090
|
+
if (!response.ok) {
|
|
2091
|
+
throw new Error(`Failed to watch workflow: ${response.statusText}`);
|
|
2092
|
+
}
|
|
2093
|
+
if (!response.body) {
|
|
2094
|
+
throw new Error("Response body is null");
|
|
2095
|
+
}
|
|
2096
|
+
for await (const record of this.streamProcessor(response.body)) {
|
|
2097
|
+
if (typeof record === "string") {
|
|
2098
|
+
onRecord(JSON.parse(record));
|
|
2099
|
+
} else {
|
|
2100
|
+
onRecord(record);
|
|
2101
|
+
}
|
|
1232
2102
|
}
|
|
1233
2103
|
}
|
|
2104
|
+
/**
|
|
2105
|
+
* Creates a new ReadableStream from an iterable or async iterable of objects,
|
|
2106
|
+
* serializing each as JSON and separating them with the record separator (\x1E).
|
|
2107
|
+
*
|
|
2108
|
+
* @param records - An iterable or async iterable of objects to stream
|
|
2109
|
+
* @returns A ReadableStream emitting the records as JSON strings separated by the record separator
|
|
2110
|
+
*/
|
|
2111
|
+
static createRecordStream(records) {
|
|
2112
|
+
const encoder = new TextEncoder();
|
|
2113
|
+
return new ReadableStream({
|
|
2114
|
+
async start(controller) {
|
|
2115
|
+
try {
|
|
2116
|
+
for await (const record of records) {
|
|
2117
|
+
const json = JSON.stringify(record) + RECORD_SEPARATOR;
|
|
2118
|
+
controller.enqueue(encoder.encode(json));
|
|
2119
|
+
}
|
|
2120
|
+
controller.close();
|
|
2121
|
+
} catch (err) {
|
|
2122
|
+
controller.error(err);
|
|
2123
|
+
}
|
|
2124
|
+
}
|
|
2125
|
+
});
|
|
2126
|
+
}
|
|
1234
2127
|
};
|
|
1235
2128
|
|
|
1236
|
-
// src/resources/
|
|
1237
|
-
var
|
|
1238
|
-
constructor(options,
|
|
2129
|
+
// src/resources/a2a.ts
|
|
2130
|
+
var A2A = class extends BaseResource {
|
|
2131
|
+
constructor(options, agentId) {
|
|
2132
|
+
super(options);
|
|
2133
|
+
this.agentId = agentId;
|
|
2134
|
+
}
|
|
2135
|
+
/**
|
|
2136
|
+
* Get the agent card with metadata about the agent
|
|
2137
|
+
* @returns Promise containing the agent card information
|
|
2138
|
+
*/
|
|
2139
|
+
async getCard() {
|
|
2140
|
+
return this.request(`/.well-known/${this.agentId}/agent-card.json`);
|
|
2141
|
+
}
|
|
2142
|
+
/**
|
|
2143
|
+
* Send a message to the agent and gets a message or task response
|
|
2144
|
+
* @param params - Parameters for the task
|
|
2145
|
+
* @returns Promise containing the response
|
|
2146
|
+
*/
|
|
2147
|
+
async sendMessage(params) {
|
|
2148
|
+
const response = await this.request(`/a2a/${this.agentId}`, {
|
|
2149
|
+
method: "POST",
|
|
2150
|
+
body: {
|
|
2151
|
+
method: "message/send",
|
|
2152
|
+
params
|
|
2153
|
+
}
|
|
2154
|
+
});
|
|
2155
|
+
return response;
|
|
2156
|
+
}
|
|
2157
|
+
/**
|
|
2158
|
+
* Sends a message to an agent to initiate/continue a task and subscribes
|
|
2159
|
+
* the client to real-time updates for that task via Server-Sent Events (SSE).
|
|
2160
|
+
* @param params - Parameters for the task
|
|
2161
|
+
* @returns A stream of Server-Sent Events. Each SSE `data` field contains a `SendStreamingMessageResponse`
|
|
2162
|
+
*/
|
|
2163
|
+
async sendStreamingMessage(params) {
|
|
2164
|
+
const response = await this.request(`/a2a/${this.agentId}`, {
|
|
2165
|
+
method: "POST",
|
|
2166
|
+
body: {
|
|
2167
|
+
method: "message/stream",
|
|
2168
|
+
params
|
|
2169
|
+
}
|
|
2170
|
+
});
|
|
2171
|
+
return response;
|
|
2172
|
+
}
|
|
2173
|
+
/**
|
|
2174
|
+
* Get the status and result of a task
|
|
2175
|
+
* @param params - Parameters for querying the task
|
|
2176
|
+
* @returns Promise containing the task response
|
|
2177
|
+
*/
|
|
2178
|
+
async getTask(params) {
|
|
2179
|
+
const response = await this.request(`/a2a/${this.agentId}`, {
|
|
2180
|
+
method: "POST",
|
|
2181
|
+
body: {
|
|
2182
|
+
method: "tasks/get",
|
|
2183
|
+
params
|
|
2184
|
+
}
|
|
2185
|
+
});
|
|
2186
|
+
return response;
|
|
2187
|
+
}
|
|
2188
|
+
/**
|
|
2189
|
+
* Cancel a running task
|
|
2190
|
+
* @param params - Parameters identifying the task to cancel
|
|
2191
|
+
* @returns Promise containing the task response
|
|
2192
|
+
*/
|
|
2193
|
+
async cancelTask(params) {
|
|
2194
|
+
return this.request(`/a2a/${this.agentId}`, {
|
|
2195
|
+
method: "POST",
|
|
2196
|
+
body: {
|
|
2197
|
+
method: "tasks/cancel",
|
|
2198
|
+
params
|
|
2199
|
+
}
|
|
2200
|
+
});
|
|
2201
|
+
}
|
|
2202
|
+
};
|
|
2203
|
+
|
|
2204
|
+
// src/resources/mcp-tool.ts
|
|
2205
|
+
var MCPTool = class extends BaseResource {
|
|
2206
|
+
serverId;
|
|
2207
|
+
toolId;
|
|
2208
|
+
constructor(options, serverId, toolId) {
|
|
1239
2209
|
super(options);
|
|
2210
|
+
this.serverId = serverId;
|
|
1240
2211
|
this.toolId = toolId;
|
|
1241
2212
|
}
|
|
1242
2213
|
/**
|
|
1243
|
-
* Retrieves details about the
|
|
1244
|
-
* @
|
|
2214
|
+
* Retrieves details about this specific tool from the MCP server.
|
|
2215
|
+
* @param runtimeContext - Optional runtime context to pass as query parameter
|
|
2216
|
+
* @returns Promise containing the tool's information (name, description, schema).
|
|
1245
2217
|
*/
|
|
1246
|
-
details() {
|
|
1247
|
-
return this.request(`/api/tools/${this.toolId}`);
|
|
2218
|
+
details(runtimeContext) {
|
|
2219
|
+
return this.request(`/api/mcp/${this.serverId}/tools/${this.toolId}${runtimeContextQueryString(runtimeContext)}`);
|
|
1248
2220
|
}
|
|
1249
2221
|
/**
|
|
1250
|
-
* Executes
|
|
1251
|
-
* @param params - Parameters
|
|
1252
|
-
* @returns Promise containing the tool execution
|
|
2222
|
+
* Executes this specific tool on the MCP server.
|
|
2223
|
+
* @param params - Parameters for tool execution, including data/args and optional runtimeContext.
|
|
2224
|
+
* @returns Promise containing the result of the tool execution.
|
|
1253
2225
|
*/
|
|
1254
2226
|
execute(params) {
|
|
1255
|
-
const
|
|
1256
|
-
if (params.
|
|
1257
|
-
|
|
2227
|
+
const body = {};
|
|
2228
|
+
if (params.data !== void 0) body.data = params.data;
|
|
2229
|
+
if (params.runtimeContext !== void 0) {
|
|
2230
|
+
body.runtimeContext = params.runtimeContext;
|
|
1258
2231
|
}
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
};
|
|
1263
|
-
|
|
2232
|
+
return this.request(`/api/mcp/${this.serverId}/tools/${this.toolId}/execute`, {
|
|
2233
|
+
method: "POST",
|
|
2234
|
+
body: Object.keys(body).length > 0 ? body : void 0
|
|
2235
|
+
});
|
|
2236
|
+
}
|
|
2237
|
+
};
|
|
2238
|
+
|
|
2239
|
+
// src/resources/agent-builder.ts
|
|
2240
|
+
var RECORD_SEPARATOR2 = "";
|
|
2241
|
+
var AgentBuilder = class extends BaseResource {
|
|
2242
|
+
constructor(options, actionId) {
|
|
2243
|
+
super(options);
|
|
2244
|
+
this.actionId = actionId;
|
|
2245
|
+
}
|
|
2246
|
+
// Helper function to transform workflow result to action result
|
|
2247
|
+
transformWorkflowResult(result) {
|
|
2248
|
+
if (result.status === "success") {
|
|
2249
|
+
return {
|
|
2250
|
+
success: result.result.success || false,
|
|
2251
|
+
applied: result.result.applied || false,
|
|
2252
|
+
branchName: result.result.branchName,
|
|
2253
|
+
message: result.result.message || "Agent builder action completed",
|
|
2254
|
+
validationResults: result.result.validationResults,
|
|
2255
|
+
error: result.result.error,
|
|
2256
|
+
errors: result.result.errors,
|
|
2257
|
+
stepResults: result.result.stepResults
|
|
2258
|
+
};
|
|
2259
|
+
} else if (result.status === "failed") {
|
|
2260
|
+
return {
|
|
2261
|
+
success: false,
|
|
2262
|
+
applied: false,
|
|
2263
|
+
message: `Agent builder action failed: ${result.error.message}`,
|
|
2264
|
+
error: result.error.message
|
|
2265
|
+
};
|
|
2266
|
+
} else {
|
|
2267
|
+
return {
|
|
2268
|
+
success: false,
|
|
2269
|
+
applied: false,
|
|
2270
|
+
message: "Agent builder action was suspended",
|
|
2271
|
+
error: "Workflow suspended - manual intervention required"
|
|
2272
|
+
};
|
|
2273
|
+
}
|
|
2274
|
+
}
|
|
2275
|
+
/**
|
|
2276
|
+
* @deprecated Use createRunAsync() instead.
|
|
2277
|
+
* @throws {Error} Always throws an error directing users to use createRunAsync()
|
|
2278
|
+
*/
|
|
2279
|
+
async createRun(_params) {
|
|
2280
|
+
throw new Error(
|
|
2281
|
+
"createRun() has been deprecated. Please use createRunAsync() instead.\n\nMigration guide:\n Before: const run = agentBuilder.createRun();\n After: const run = await agentBuilder.createRunAsync();\n\nNote: createRunAsync() is an async method, so make sure your calling function is async."
|
|
2282
|
+
);
|
|
2283
|
+
}
|
|
2284
|
+
/**
|
|
2285
|
+
* Creates a new agent builder action run and returns the runId.
|
|
2286
|
+
* This calls `/api/agent-builder/:actionId/create-run`.
|
|
2287
|
+
*/
|
|
2288
|
+
async createRunAsync(params) {
|
|
2289
|
+
const searchParams = new URLSearchParams();
|
|
2290
|
+
if (!!params?.runId) {
|
|
2291
|
+
searchParams.set("runId", params.runId);
|
|
2292
|
+
}
|
|
2293
|
+
const url = `/api/agent-builder/${this.actionId}/create-run${searchParams.toString() ? `?${searchParams.toString()}` : ""}`;
|
|
2294
|
+
return this.request(url, {
|
|
2295
|
+
method: "POST"
|
|
2296
|
+
});
|
|
2297
|
+
}
|
|
2298
|
+
/**
|
|
2299
|
+
* Starts agent builder action asynchronously and waits for completion.
|
|
2300
|
+
* This calls `/api/agent-builder/:actionId/start-async`.
|
|
2301
|
+
*/
|
|
2302
|
+
async startAsync(params, runId) {
|
|
2303
|
+
const searchParams = new URLSearchParams();
|
|
2304
|
+
if (runId) {
|
|
2305
|
+
searchParams.set("runId", runId);
|
|
2306
|
+
}
|
|
2307
|
+
const runtimeContext = parseClientRuntimeContext(params.runtimeContext);
|
|
2308
|
+
const { runtimeContext: _, ...actionParams } = params;
|
|
2309
|
+
const url = `/api/agent-builder/${this.actionId}/start-async${searchParams.toString() ? `?${searchParams.toString()}` : ""}`;
|
|
2310
|
+
const result = await this.request(url, {
|
|
2311
|
+
method: "POST",
|
|
2312
|
+
body: { ...actionParams, runtimeContext }
|
|
2313
|
+
});
|
|
2314
|
+
return this.transformWorkflowResult(result);
|
|
2315
|
+
}
|
|
2316
|
+
/**
|
|
2317
|
+
* Starts an existing agent builder action run.
|
|
2318
|
+
* This calls `/api/agent-builder/:actionId/start`.
|
|
2319
|
+
*/
|
|
2320
|
+
async startActionRun(params, runId) {
|
|
2321
|
+
const searchParams = new URLSearchParams();
|
|
2322
|
+
searchParams.set("runId", runId);
|
|
2323
|
+
const runtimeContext = parseClientRuntimeContext(params.runtimeContext);
|
|
2324
|
+
const { runtimeContext: _, ...actionParams } = params;
|
|
2325
|
+
const url = `/api/agent-builder/${this.actionId}/start?${searchParams.toString()}`;
|
|
2326
|
+
return this.request(url, {
|
|
2327
|
+
method: "POST",
|
|
2328
|
+
body: { ...actionParams, runtimeContext }
|
|
2329
|
+
});
|
|
2330
|
+
}
|
|
2331
|
+
/**
|
|
2332
|
+
* Resumes a suspended agent builder action step.
|
|
2333
|
+
* This calls `/api/agent-builder/:actionId/resume`.
|
|
2334
|
+
*/
|
|
2335
|
+
async resume(params, runId) {
|
|
2336
|
+
const searchParams = new URLSearchParams();
|
|
2337
|
+
searchParams.set("runId", runId);
|
|
2338
|
+
const runtimeContext = parseClientRuntimeContext(params.runtimeContext);
|
|
2339
|
+
const { runtimeContext: _, ...resumeParams } = params;
|
|
2340
|
+
const url = `/api/agent-builder/${this.actionId}/resume?${searchParams.toString()}`;
|
|
2341
|
+
return this.request(url, {
|
|
1264
2342
|
method: "POST",
|
|
1265
|
-
body
|
|
2343
|
+
body: { ...resumeParams, runtimeContext }
|
|
1266
2344
|
});
|
|
1267
2345
|
}
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
|
|
2346
|
+
/**
|
|
2347
|
+
* Resumes a suspended agent builder action step asynchronously.
|
|
2348
|
+
* This calls `/api/agent-builder/:actionId/resume-async`.
|
|
2349
|
+
*/
|
|
2350
|
+
async resumeAsync(params, runId) {
|
|
2351
|
+
const searchParams = new URLSearchParams();
|
|
2352
|
+
searchParams.set("runId", runId);
|
|
2353
|
+
const runtimeContext = parseClientRuntimeContext(params.runtimeContext);
|
|
2354
|
+
const { runtimeContext: _, ...resumeParams } = params;
|
|
2355
|
+
const url = `/api/agent-builder/${this.actionId}/resume-async?${searchParams.toString()}`;
|
|
2356
|
+
const result = await this.request(url, {
|
|
2357
|
+
method: "POST",
|
|
2358
|
+
body: { ...resumeParams, runtimeContext }
|
|
2359
|
+
});
|
|
2360
|
+
return this.transformWorkflowResult(result);
|
|
1276
2361
|
}
|
|
1277
2362
|
/**
|
|
1278
|
-
* Creates an async generator that processes a readable stream and yields
|
|
2363
|
+
* Creates an async generator that processes a readable stream and yields action records
|
|
1279
2364
|
* separated by the Record Separator character (\x1E)
|
|
1280
2365
|
*
|
|
1281
2366
|
* @param stream - The readable stream to process
|
|
@@ -1320,166 +2405,78 @@ var Workflow = class extends BaseResource {
|
|
|
1320
2405
|
}
|
|
1321
2406
|
}
|
|
1322
2407
|
/**
|
|
1323
|
-
*
|
|
1324
|
-
*
|
|
1325
|
-
*/
|
|
1326
|
-
details() {
|
|
1327
|
-
return this.request(`/api/workflows/${this.workflowId}`);
|
|
1328
|
-
}
|
|
1329
|
-
/**
|
|
1330
|
-
* Retrieves all runs for a workflow
|
|
1331
|
-
* @param params - Parameters for filtering runs
|
|
1332
|
-
* @returns Promise containing workflow runs array
|
|
1333
|
-
*/
|
|
1334
|
-
runs(params) {
|
|
1335
|
-
const searchParams = new URLSearchParams();
|
|
1336
|
-
if (params?.fromDate) {
|
|
1337
|
-
searchParams.set("fromDate", params.fromDate.toISOString());
|
|
1338
|
-
}
|
|
1339
|
-
if (params?.toDate) {
|
|
1340
|
-
searchParams.set("toDate", params.toDate.toISOString());
|
|
1341
|
-
}
|
|
1342
|
-
if (params?.limit !== null && params?.limit !== void 0 && !isNaN(Number(params?.limit))) {
|
|
1343
|
-
searchParams.set("limit", String(params.limit));
|
|
1344
|
-
}
|
|
1345
|
-
if (params?.offset !== null && params?.offset !== void 0 && !isNaN(Number(params?.offset))) {
|
|
1346
|
-
searchParams.set("offset", String(params.offset));
|
|
1347
|
-
}
|
|
1348
|
-
if (params?.resourceId) {
|
|
1349
|
-
searchParams.set("resourceId", params.resourceId);
|
|
1350
|
-
}
|
|
1351
|
-
if (searchParams.size) {
|
|
1352
|
-
return this.request(`/api/workflows/${this.workflowId}/runs?${searchParams}`);
|
|
1353
|
-
} else {
|
|
1354
|
-
return this.request(`/api/workflows/${this.workflowId}/runs`);
|
|
1355
|
-
}
|
|
1356
|
-
}
|
|
1357
|
-
/**
|
|
1358
|
-
* Retrieves a specific workflow run by its ID
|
|
1359
|
-
* @param runId - The ID of the workflow run to retrieve
|
|
1360
|
-
* @returns Promise containing the workflow run details
|
|
1361
|
-
*/
|
|
1362
|
-
runById(runId) {
|
|
1363
|
-
return this.request(`/api/workflows/${this.workflowId}/runs/${runId}`);
|
|
1364
|
-
}
|
|
1365
|
-
/**
|
|
1366
|
-
* Retrieves the execution result for a specific workflow run by its ID
|
|
1367
|
-
* @param runId - The ID of the workflow run to retrieve the execution result for
|
|
1368
|
-
* @returns Promise containing the workflow run execution result
|
|
1369
|
-
*/
|
|
1370
|
-
runExecutionResult(runId) {
|
|
1371
|
-
return this.request(`/api/workflows/${this.workflowId}/runs/${runId}/execution-result`);
|
|
1372
|
-
}
|
|
1373
|
-
/**
|
|
1374
|
-
* Cancels a specific workflow run by its ID
|
|
1375
|
-
* @param runId - The ID of the workflow run to cancel
|
|
1376
|
-
* @returns Promise containing a success message
|
|
1377
|
-
*/
|
|
1378
|
-
cancelRun(runId) {
|
|
1379
|
-
return this.request(`/api/workflows/${this.workflowId}/runs/${runId}/cancel`, {
|
|
1380
|
-
method: "POST"
|
|
1381
|
-
});
|
|
1382
|
-
}
|
|
1383
|
-
/**
|
|
1384
|
-
* Sends an event to a specific workflow run by its ID
|
|
1385
|
-
* @param params - Object containing the runId, event and data
|
|
1386
|
-
* @returns Promise containing a success message
|
|
1387
|
-
*/
|
|
1388
|
-
sendRunEvent(params) {
|
|
1389
|
-
return this.request(`/api/workflows/${this.workflowId}/runs/${params.runId}/send-event`, {
|
|
1390
|
-
method: "POST",
|
|
1391
|
-
body: { event: params.event, data: params.data }
|
|
1392
|
-
});
|
|
1393
|
-
}
|
|
1394
|
-
/**
|
|
1395
|
-
* Creates a new workflow run
|
|
1396
|
-
* @param params - Optional object containing the optional runId
|
|
1397
|
-
* @returns Promise containing the runId of the created run
|
|
2408
|
+
* Streams agent builder action progress in real-time.
|
|
2409
|
+
* This calls `/api/agent-builder/:actionId/stream`.
|
|
1398
2410
|
*/
|
|
1399
|
-
|
|
2411
|
+
async stream(params, runId) {
|
|
1400
2412
|
const searchParams = new URLSearchParams();
|
|
1401
|
-
if (
|
|
1402
|
-
searchParams.set("runId",
|
|
2413
|
+
if (runId) {
|
|
2414
|
+
searchParams.set("runId", runId);
|
|
1403
2415
|
}
|
|
1404
|
-
return this.request(`/api/workflows/${this.workflowId}/create-run?${searchParams.toString()}`, {
|
|
1405
|
-
method: "POST"
|
|
1406
|
-
});
|
|
1407
|
-
}
|
|
1408
|
-
/**
|
|
1409
|
-
* Starts a workflow run synchronously without waiting for the workflow to complete
|
|
1410
|
-
* @param params - Object containing the runId, inputData and runtimeContext
|
|
1411
|
-
* @returns Promise containing success message
|
|
1412
|
-
*/
|
|
1413
|
-
start(params) {
|
|
1414
2416
|
const runtimeContext = parseClientRuntimeContext(params.runtimeContext);
|
|
1415
|
-
|
|
2417
|
+
const { runtimeContext: _, ...actionParams } = params;
|
|
2418
|
+
const url = `/api/agent-builder/${this.actionId}/stream${searchParams.toString() ? `?${searchParams.toString()}` : ""}`;
|
|
2419
|
+
const response = await this.request(url, {
|
|
1416
2420
|
method: "POST",
|
|
1417
|
-
body: {
|
|
2421
|
+
body: { ...actionParams, runtimeContext },
|
|
2422
|
+
stream: true
|
|
1418
2423
|
});
|
|
1419
|
-
|
|
1420
|
-
|
|
1421
|
-
|
|
1422
|
-
|
|
1423
|
-
|
|
1424
|
-
|
|
1425
|
-
|
|
1426
|
-
|
|
1427
|
-
|
|
1428
|
-
|
|
1429
|
-
|
|
1430
|
-
|
|
1431
|
-
|
|
1432
|
-
|
|
1433
|
-
|
|
1434
|
-
|
|
1435
|
-
|
|
1436
|
-
|
|
1437
|
-
|
|
1438
|
-
|
|
2424
|
+
if (!response.ok) {
|
|
2425
|
+
throw new Error(`Failed to stream agent builder action: ${response.statusText}`);
|
|
2426
|
+
}
|
|
2427
|
+
if (!response.body) {
|
|
2428
|
+
throw new Error("Response body is null");
|
|
2429
|
+
}
|
|
2430
|
+
let failedChunk = void 0;
|
|
2431
|
+
const transformStream = new TransformStream({
|
|
2432
|
+
start() {
|
|
2433
|
+
},
|
|
2434
|
+
async transform(chunk, controller) {
|
|
2435
|
+
try {
|
|
2436
|
+
const decoded = new TextDecoder().decode(chunk);
|
|
2437
|
+
const chunks = decoded.split(RECORD_SEPARATOR2);
|
|
2438
|
+
for (const chunk2 of chunks) {
|
|
2439
|
+
if (chunk2) {
|
|
2440
|
+
const newChunk = failedChunk ? failedChunk + chunk2 : chunk2;
|
|
2441
|
+
try {
|
|
2442
|
+
const parsedChunk = JSON.parse(newChunk);
|
|
2443
|
+
controller.enqueue(parsedChunk);
|
|
2444
|
+
failedChunk = void 0;
|
|
2445
|
+
} catch {
|
|
2446
|
+
failedChunk = newChunk;
|
|
2447
|
+
}
|
|
2448
|
+
}
|
|
2449
|
+
}
|
|
2450
|
+
} catch {
|
|
2451
|
+
}
|
|
1439
2452
|
}
|
|
1440
2453
|
});
|
|
2454
|
+
return response.body.pipeThrough(transformStream);
|
|
1441
2455
|
}
|
|
1442
2456
|
/**
|
|
1443
|
-
*
|
|
1444
|
-
*
|
|
1445
|
-
* @returns Promise containing the workflow execution results
|
|
2457
|
+
* Streams agent builder action progress in real-time using VNext streaming.
|
|
2458
|
+
* This calls `/api/agent-builder/:actionId/streamVNext`.
|
|
1446
2459
|
*/
|
|
1447
|
-
|
|
2460
|
+
async streamVNext(params, runId) {
|
|
1448
2461
|
const searchParams = new URLSearchParams();
|
|
1449
|
-
if (
|
|
1450
|
-
searchParams.set("runId",
|
|
2462
|
+
if (runId) {
|
|
2463
|
+
searchParams.set("runId", runId);
|
|
1451
2464
|
}
|
|
1452
2465
|
const runtimeContext = parseClientRuntimeContext(params.runtimeContext);
|
|
1453
|
-
|
|
2466
|
+
const { runtimeContext: _, ...actionParams } = params;
|
|
2467
|
+
const url = `/api/agent-builder/${this.actionId}/streamVNext${searchParams.toString() ? `?${searchParams.toString()}` : ""}`;
|
|
2468
|
+
const response = await this.request(url, {
|
|
1454
2469
|
method: "POST",
|
|
1455
|
-
body: {
|
|
2470
|
+
body: { ...actionParams, runtimeContext },
|
|
2471
|
+
stream: true
|
|
1456
2472
|
});
|
|
1457
|
-
}
|
|
1458
|
-
/**
|
|
1459
|
-
* Starts a workflow run and returns a stream
|
|
1460
|
-
* @param params - Object containing the optional runId, inputData and runtimeContext
|
|
1461
|
-
* @returns Promise containing the workflow execution results
|
|
1462
|
-
*/
|
|
1463
|
-
async stream(params) {
|
|
1464
|
-
const searchParams = new URLSearchParams();
|
|
1465
|
-
if (!!params?.runId) {
|
|
1466
|
-
searchParams.set("runId", params.runId);
|
|
1467
|
-
}
|
|
1468
|
-
const runtimeContext = parseClientRuntimeContext(params.runtimeContext);
|
|
1469
|
-
const response = await this.request(
|
|
1470
|
-
`/api/workflows/${this.workflowId}/stream?${searchParams.toString()}`,
|
|
1471
|
-
{
|
|
1472
|
-
method: "POST",
|
|
1473
|
-
body: { inputData: params.inputData, runtimeContext },
|
|
1474
|
-
stream: true
|
|
1475
|
-
}
|
|
1476
|
-
);
|
|
1477
2473
|
if (!response.ok) {
|
|
1478
|
-
throw new Error(`Failed to stream
|
|
2474
|
+
throw new Error(`Failed to stream agent builder action VNext: ${response.statusText}`);
|
|
1479
2475
|
}
|
|
1480
2476
|
if (!response.body) {
|
|
1481
2477
|
throw new Error("Response body is null");
|
|
1482
2478
|
}
|
|
2479
|
+
let failedChunk = void 0;
|
|
1483
2480
|
const transformStream = new TransformStream({
|
|
1484
2481
|
start() {
|
|
1485
2482
|
},
|
|
@@ -1489,10 +2486,13 @@ var Workflow = class extends BaseResource {
|
|
|
1489
2486
|
const chunks = decoded.split(RECORD_SEPARATOR2);
|
|
1490
2487
|
for (const chunk2 of chunks) {
|
|
1491
2488
|
if (chunk2) {
|
|
2489
|
+
const newChunk = failedChunk ? failedChunk + chunk2 : chunk2;
|
|
1492
2490
|
try {
|
|
1493
|
-
const parsedChunk = JSON.parse(
|
|
2491
|
+
const parsedChunk = JSON.parse(newChunk);
|
|
1494
2492
|
controller.enqueue(parsedChunk);
|
|
2493
|
+
failedChunk = void 0;
|
|
1495
2494
|
} catch {
|
|
2495
|
+
failedChunk = newChunk;
|
|
1496
2496
|
}
|
|
1497
2497
|
}
|
|
1498
2498
|
}
|
|
@@ -1503,32 +2503,19 @@ var Workflow = class extends BaseResource {
|
|
|
1503
2503
|
return response.body.pipeThrough(transformStream);
|
|
1504
2504
|
}
|
|
1505
2505
|
/**
|
|
1506
|
-
*
|
|
1507
|
-
*
|
|
1508
|
-
*
|
|
1509
|
-
|
|
1510
|
-
resumeAsync(params) {
|
|
1511
|
-
const runtimeContext = parseClientRuntimeContext(params.runtimeContext);
|
|
1512
|
-
return this.request(`/api/workflows/${this.workflowId}/resume-async?runId=${params.runId}`, {
|
|
1513
|
-
method: "POST",
|
|
1514
|
-
body: {
|
|
1515
|
-
step: params.step,
|
|
1516
|
-
resumeData: params.resumeData,
|
|
1517
|
-
runtimeContext
|
|
1518
|
-
}
|
|
1519
|
-
});
|
|
1520
|
-
}
|
|
1521
|
-
/**
|
|
1522
|
-
* Watches workflow transitions in real-time
|
|
1523
|
-
* @param runId - Optional run ID to filter the watch stream
|
|
1524
|
-
* @returns AsyncGenerator that yields parsed records from the workflow watch stream
|
|
2506
|
+
* Watches an existing agent builder action run by runId.
|
|
2507
|
+
* This is used for hot reload recovery - it loads the existing run state
|
|
2508
|
+
* and streams any remaining progress.
|
|
2509
|
+
* This calls `/api/agent-builder/:actionId/watch`.
|
|
1525
2510
|
*/
|
|
1526
|
-
async watch({ runId }, onRecord) {
|
|
1527
|
-
const
|
|
2511
|
+
async watch({ runId, eventType }, onRecord) {
|
|
2512
|
+
const url = `/api/agent-builder/${this.actionId}/watch?runId=${runId}${eventType ? `&eventType=${eventType}` : ""}`;
|
|
2513
|
+
const response = await this.request(url, {
|
|
2514
|
+
method: "GET",
|
|
1528
2515
|
stream: true
|
|
1529
2516
|
});
|
|
1530
2517
|
if (!response.ok) {
|
|
1531
|
-
throw new Error(`Failed to watch
|
|
2518
|
+
throw new Error(`Failed to watch agent builder action: ${response.statusText}`);
|
|
1532
2519
|
}
|
|
1533
2520
|
if (!response.body) {
|
|
1534
2521
|
throw new Error("Response body is null");
|
|
@@ -1542,134 +2529,154 @@ var Workflow = class extends BaseResource {
|
|
|
1542
2529
|
}
|
|
1543
2530
|
}
|
|
1544
2531
|
/**
|
|
1545
|
-
*
|
|
1546
|
-
*
|
|
1547
|
-
*
|
|
1548
|
-
* @param records - An iterable or async iterable of objects to stream
|
|
1549
|
-
* @returns A ReadableStream emitting the records as JSON strings separated by the record separator
|
|
2532
|
+
* Gets a specific action run by its ID.
|
|
2533
|
+
* This calls `/api/agent-builder/:actionId/runs/:runId`.
|
|
1550
2534
|
*/
|
|
1551
|
-
|
|
1552
|
-
const
|
|
1553
|
-
return
|
|
1554
|
-
|
|
1555
|
-
try {
|
|
1556
|
-
for await (const record of records) {
|
|
1557
|
-
const json = JSON.stringify(record) + RECORD_SEPARATOR2;
|
|
1558
|
-
controller.enqueue(encoder.encode(json));
|
|
1559
|
-
}
|
|
1560
|
-
controller.close();
|
|
1561
|
-
} catch (err) {
|
|
1562
|
-
controller.error(err);
|
|
1563
|
-
}
|
|
1564
|
-
}
|
|
2535
|
+
async runById(runId) {
|
|
2536
|
+
const url = `/api/agent-builder/${this.actionId}/runs/${runId}`;
|
|
2537
|
+
return this.request(url, {
|
|
2538
|
+
method: "GET"
|
|
1565
2539
|
});
|
|
1566
2540
|
}
|
|
1567
|
-
};
|
|
1568
|
-
|
|
1569
|
-
// src/resources/a2a.ts
|
|
1570
|
-
var A2A = class extends BaseResource {
|
|
1571
|
-
constructor(options, agentId) {
|
|
1572
|
-
super(options);
|
|
1573
|
-
this.agentId = agentId;
|
|
1574
|
-
}
|
|
1575
2541
|
/**
|
|
1576
|
-
*
|
|
1577
|
-
*
|
|
2542
|
+
* Gets details about this agent builder action.
|
|
2543
|
+
* This calls `/api/agent-builder/:actionId`.
|
|
1578
2544
|
*/
|
|
1579
|
-
async
|
|
1580
|
-
|
|
2545
|
+
async details() {
|
|
2546
|
+
const result = await this.request(`/api/agent-builder/${this.actionId}`);
|
|
2547
|
+
return result;
|
|
1581
2548
|
}
|
|
1582
2549
|
/**
|
|
1583
|
-
*
|
|
1584
|
-
*
|
|
1585
|
-
* @returns Promise containing the task response
|
|
2550
|
+
* Gets all runs for this agent builder action.
|
|
2551
|
+
* This calls `/api/agent-builder/:actionId/runs`.
|
|
1586
2552
|
*/
|
|
1587
|
-
async
|
|
1588
|
-
const
|
|
1589
|
-
|
|
1590
|
-
|
|
1591
|
-
|
|
1592
|
-
|
|
1593
|
-
|
|
2553
|
+
async runs(params) {
|
|
2554
|
+
const searchParams = new URLSearchParams();
|
|
2555
|
+
if (params?.fromDate) {
|
|
2556
|
+
searchParams.set("fromDate", params.fromDate.toISOString());
|
|
2557
|
+
}
|
|
2558
|
+
if (params?.toDate) {
|
|
2559
|
+
searchParams.set("toDate", params.toDate.toISOString());
|
|
2560
|
+
}
|
|
2561
|
+
if (params?.limit !== void 0) {
|
|
2562
|
+
searchParams.set("limit", String(params.limit));
|
|
2563
|
+
}
|
|
2564
|
+
if (params?.offset !== void 0) {
|
|
2565
|
+
searchParams.set("offset", String(params.offset));
|
|
2566
|
+
}
|
|
2567
|
+
if (params?.resourceId) {
|
|
2568
|
+
searchParams.set("resourceId", params.resourceId);
|
|
2569
|
+
}
|
|
2570
|
+
const url = `/api/agent-builder/${this.actionId}/runs${searchParams.toString() ? `?${searchParams.toString()}` : ""}`;
|
|
2571
|
+
return this.request(url, {
|
|
2572
|
+
method: "GET"
|
|
1594
2573
|
});
|
|
1595
|
-
|
|
1596
|
-
|
|
1597
|
-
|
|
1598
|
-
*
|
|
1599
|
-
|
|
1600
|
-
|
|
1601
|
-
|
|
1602
|
-
|
|
1603
|
-
|
|
1604
|
-
method: "POST",
|
|
1605
|
-
body: {
|
|
1606
|
-
method: "tasks/get",
|
|
1607
|
-
params
|
|
1608
|
-
}
|
|
2574
|
+
}
|
|
2575
|
+
/**
|
|
2576
|
+
* Gets the execution result of an agent builder action run.
|
|
2577
|
+
* This calls `/api/agent-builder/:actionId/runs/:runId/execution-result`.
|
|
2578
|
+
*/
|
|
2579
|
+
async runExecutionResult(runId) {
|
|
2580
|
+
const url = `/api/agent-builder/${this.actionId}/runs/${runId}/execution-result`;
|
|
2581
|
+
return this.request(url, {
|
|
2582
|
+
method: "GET"
|
|
1609
2583
|
});
|
|
1610
|
-
return response.result;
|
|
1611
2584
|
}
|
|
1612
2585
|
/**
|
|
1613
|
-
*
|
|
1614
|
-
*
|
|
1615
|
-
* @returns Promise containing the task response
|
|
2586
|
+
* Cancels an agent builder action run.
|
|
2587
|
+
* This calls `/api/agent-builder/:actionId/runs/:runId/cancel`.
|
|
1616
2588
|
*/
|
|
1617
|
-
async
|
|
1618
|
-
|
|
1619
|
-
|
|
1620
|
-
|
|
1621
|
-
method: "tasks/cancel",
|
|
1622
|
-
params
|
|
1623
|
-
}
|
|
2589
|
+
async cancelRun(runId) {
|
|
2590
|
+
const url = `/api/agent-builder/${this.actionId}/runs/${runId}/cancel`;
|
|
2591
|
+
return this.request(url, {
|
|
2592
|
+
method: "POST"
|
|
1624
2593
|
});
|
|
1625
2594
|
}
|
|
1626
2595
|
/**
|
|
1627
|
-
*
|
|
1628
|
-
*
|
|
1629
|
-
* @returns Promise containing the task response
|
|
2596
|
+
* Sends an event to an agent builder action run.
|
|
2597
|
+
* This calls `/api/agent-builder/:actionId/runs/:runId/send-event`.
|
|
1630
2598
|
*/
|
|
1631
|
-
async
|
|
1632
|
-
|
|
2599
|
+
async sendRunEvent(params) {
|
|
2600
|
+
const url = `/api/agent-builder/${this.actionId}/runs/${params.runId}/send-event`;
|
|
2601
|
+
return this.request(url, {
|
|
1633
2602
|
method: "POST",
|
|
1634
|
-
body: {
|
|
1635
|
-
method: "tasks/sendSubscribe",
|
|
1636
|
-
params
|
|
1637
|
-
},
|
|
1638
|
-
stream: true
|
|
2603
|
+
body: { event: params.event, data: params.data }
|
|
1639
2604
|
});
|
|
1640
2605
|
}
|
|
1641
2606
|
};
|
|
1642
2607
|
|
|
1643
|
-
// src/resources/
|
|
1644
|
-
var
|
|
1645
|
-
|
|
1646
|
-
toolId;
|
|
1647
|
-
constructor(options, serverId, toolId) {
|
|
2608
|
+
// src/resources/observability.ts
|
|
2609
|
+
var Observability = class extends BaseResource {
|
|
2610
|
+
constructor(options) {
|
|
1648
2611
|
super(options);
|
|
1649
|
-
this.serverId = serverId;
|
|
1650
|
-
this.toolId = toolId;
|
|
1651
2612
|
}
|
|
1652
2613
|
/**
|
|
1653
|
-
* Retrieves
|
|
1654
|
-
* @
|
|
2614
|
+
* Retrieves a specific AI trace by ID
|
|
2615
|
+
* @param traceId - ID of the trace to retrieve
|
|
2616
|
+
* @returns Promise containing the AI trace with all its spans
|
|
1655
2617
|
*/
|
|
1656
|
-
|
|
1657
|
-
return this.request(`/api/
|
|
2618
|
+
getTrace(traceId) {
|
|
2619
|
+
return this.request(`/api/observability/traces/${traceId}`);
|
|
1658
2620
|
}
|
|
1659
2621
|
/**
|
|
1660
|
-
*
|
|
1661
|
-
* @param params - Parameters for
|
|
1662
|
-
* @returns Promise containing
|
|
2622
|
+
* Retrieves paginated list of AI traces with optional filtering
|
|
2623
|
+
* @param params - Parameters for pagination and filtering
|
|
2624
|
+
* @returns Promise containing paginated traces and pagination info
|
|
1663
2625
|
*/
|
|
1664
|
-
|
|
1665
|
-
const
|
|
1666
|
-
|
|
1667
|
-
|
|
1668
|
-
|
|
2626
|
+
getTraces(params) {
|
|
2627
|
+
const { pagination, filters } = params;
|
|
2628
|
+
const { page, perPage, dateRange } = pagination || {};
|
|
2629
|
+
const { name, spanType, entityId, entityType } = filters || {};
|
|
2630
|
+
const searchParams = new URLSearchParams();
|
|
2631
|
+
if (page !== void 0) {
|
|
2632
|
+
searchParams.set("page", String(page));
|
|
1669
2633
|
}
|
|
1670
|
-
|
|
2634
|
+
if (perPage !== void 0) {
|
|
2635
|
+
searchParams.set("perPage", String(perPage));
|
|
2636
|
+
}
|
|
2637
|
+
if (name) {
|
|
2638
|
+
searchParams.set("name", name);
|
|
2639
|
+
}
|
|
2640
|
+
if (spanType !== void 0) {
|
|
2641
|
+
searchParams.set("spanType", String(spanType));
|
|
2642
|
+
}
|
|
2643
|
+
if (entityId && entityType) {
|
|
2644
|
+
searchParams.set("entityId", entityId);
|
|
2645
|
+
searchParams.set("entityType", entityType);
|
|
2646
|
+
}
|
|
2647
|
+
if (dateRange) {
|
|
2648
|
+
const dateRangeStr = JSON.stringify({
|
|
2649
|
+
start: dateRange.start instanceof Date ? dateRange.start.toISOString() : dateRange.start,
|
|
2650
|
+
end: dateRange.end instanceof Date ? dateRange.end.toISOString() : dateRange.end
|
|
2651
|
+
});
|
|
2652
|
+
searchParams.set("dateRange", dateRangeStr);
|
|
2653
|
+
}
|
|
2654
|
+
const queryString = searchParams.toString();
|
|
2655
|
+
return this.request(`/api/observability/traces${queryString ? `?${queryString}` : ""}`);
|
|
2656
|
+
}
|
|
2657
|
+
/**
|
|
2658
|
+
* Retrieves scores by trace ID and span ID
|
|
2659
|
+
* @param params - Parameters containing trace ID, span ID, and pagination options
|
|
2660
|
+
* @returns Promise containing scores and pagination info
|
|
2661
|
+
*/
|
|
2662
|
+
getScoresBySpan(params) {
|
|
2663
|
+
const { traceId, spanId, page, perPage } = params;
|
|
2664
|
+
const searchParams = new URLSearchParams();
|
|
2665
|
+
if (page !== void 0) {
|
|
2666
|
+
searchParams.set("page", String(page));
|
|
2667
|
+
}
|
|
2668
|
+
if (perPage !== void 0) {
|
|
2669
|
+
searchParams.set("perPage", String(perPage));
|
|
2670
|
+
}
|
|
2671
|
+
const queryString = searchParams.toString();
|
|
2672
|
+
return this.request(
|
|
2673
|
+
`/api/observability/traces/${encodeURIComponent(traceId)}/${encodeURIComponent(spanId)}/scores${queryString ? `?${queryString}` : ""}`
|
|
2674
|
+
);
|
|
2675
|
+
}
|
|
2676
|
+
score(params) {
|
|
2677
|
+
return this.request(`/api/observability/traces/score`, {
|
|
1671
2678
|
method: "POST",
|
|
1672
|
-
body:
|
|
2679
|
+
body: { ...params }
|
|
1673
2680
|
});
|
|
1674
2681
|
}
|
|
1675
2682
|
};
|
|
@@ -1720,172 +2727,43 @@ var NetworkMemoryThread = class extends BaseResource {
|
|
|
1720
2727
|
});
|
|
1721
2728
|
return this.request(`/api/memory/network/threads/${this.threadId}/messages?${query.toString()}`);
|
|
1722
2729
|
}
|
|
1723
|
-
};
|
|
1724
|
-
|
|
1725
|
-
// src/resources/vNextNetwork.ts
|
|
1726
|
-
var RECORD_SEPARATOR3 = "";
|
|
1727
|
-
var VNextNetwork = class extends BaseResource {
|
|
1728
|
-
constructor(options, networkId) {
|
|
1729
|
-
super(options);
|
|
1730
|
-
this.networkId = networkId;
|
|
1731
|
-
}
|
|
1732
|
-
/**
|
|
1733
|
-
* Retrieves details about the network
|
|
1734
|
-
* @returns Promise containing vNext network details
|
|
1735
|
-
*/
|
|
1736
|
-
details() {
|
|
1737
|
-
return this.request(`/api/networks/v-next/${this.networkId}`);
|
|
1738
|
-
}
|
|
1739
|
-
/**
|
|
1740
|
-
* Generates a response from the v-next network
|
|
1741
|
-
* @param params - Generation parameters including message
|
|
1742
|
-
* @returns Promise containing the generated response
|
|
1743
|
-
*/
|
|
1744
|
-
generate(params) {
|
|
1745
|
-
return this.request(`/api/networks/v-next/${this.networkId}/generate`, {
|
|
1746
|
-
method: "POST",
|
|
1747
|
-
body: {
|
|
1748
|
-
...params,
|
|
1749
|
-
runtimeContext: parseClientRuntimeContext(params.runtimeContext)
|
|
1750
|
-
}
|
|
1751
|
-
});
|
|
1752
|
-
}
|
|
1753
|
-
/**
|
|
1754
|
-
* Generates a response from the v-next network using multiple primitives
|
|
1755
|
-
* @param params - Generation parameters including message
|
|
1756
|
-
* @returns Promise containing the generated response
|
|
1757
|
-
*/
|
|
1758
|
-
loop(params) {
|
|
1759
|
-
return this.request(`/api/networks/v-next/${this.networkId}/loop`, {
|
|
1760
|
-
method: "POST",
|
|
1761
|
-
body: {
|
|
1762
|
-
...params,
|
|
1763
|
-
runtimeContext: parseClientRuntimeContext(params.runtimeContext)
|
|
1764
|
-
}
|
|
1765
|
-
});
|
|
1766
|
-
}
|
|
1767
|
-
async *streamProcessor(stream) {
|
|
1768
|
-
const reader = stream.getReader();
|
|
1769
|
-
let doneReading = false;
|
|
1770
|
-
let buffer = "";
|
|
1771
|
-
try {
|
|
1772
|
-
while (!doneReading) {
|
|
1773
|
-
const { done, value } = await reader.read();
|
|
1774
|
-
doneReading = done;
|
|
1775
|
-
if (done && !value) continue;
|
|
1776
|
-
try {
|
|
1777
|
-
const decoded = value ? new TextDecoder().decode(value) : "";
|
|
1778
|
-
const chunks = (buffer + decoded).split(RECORD_SEPARATOR3);
|
|
1779
|
-
buffer = chunks.pop() || "";
|
|
1780
|
-
for (const chunk of chunks) {
|
|
1781
|
-
if (chunk) {
|
|
1782
|
-
if (typeof chunk === "string") {
|
|
1783
|
-
try {
|
|
1784
|
-
const parsedChunk = JSON.parse(chunk);
|
|
1785
|
-
yield parsedChunk;
|
|
1786
|
-
} catch {
|
|
1787
|
-
}
|
|
1788
|
-
}
|
|
1789
|
-
}
|
|
1790
|
-
}
|
|
1791
|
-
} catch {
|
|
1792
|
-
}
|
|
1793
|
-
}
|
|
1794
|
-
if (buffer) {
|
|
1795
|
-
try {
|
|
1796
|
-
yield JSON.parse(buffer);
|
|
1797
|
-
} catch {
|
|
1798
|
-
}
|
|
1799
|
-
}
|
|
1800
|
-
} finally {
|
|
1801
|
-
reader.cancel().catch(() => {
|
|
1802
|
-
});
|
|
1803
|
-
}
|
|
1804
|
-
}
|
|
1805
2730
|
/**
|
|
1806
|
-
*
|
|
1807
|
-
* @param
|
|
1808
|
-
*
|
|
2731
|
+
* Deletes one or more messages from the thread
|
|
2732
|
+
* @param messageIds - Can be a single message ID (string), array of message IDs,
|
|
2733
|
+
* message object with id property, or array of message objects
|
|
2734
|
+
* @returns Promise containing deletion result
|
|
1809
2735
|
*/
|
|
1810
|
-
|
|
1811
|
-
const
|
|
1812
|
-
|
|
1813
|
-
body: {
|
|
1814
|
-
...params,
|
|
1815
|
-
runtimeContext: parseClientRuntimeContext(params.runtimeContext)
|
|
1816
|
-
},
|
|
1817
|
-
stream: true
|
|
2736
|
+
deleteMessages(messageIds) {
|
|
2737
|
+
const query = new URLSearchParams({
|
|
2738
|
+
networkId: this.networkId
|
|
1818
2739
|
});
|
|
1819
|
-
|
|
1820
|
-
throw new Error(`Failed to stream vNext network: ${response.statusText}`);
|
|
1821
|
-
}
|
|
1822
|
-
if (!response.body) {
|
|
1823
|
-
throw new Error("Response body is null");
|
|
1824
|
-
}
|
|
1825
|
-
for await (const record of this.streamProcessor(response.body)) {
|
|
1826
|
-
if (typeof record === "string") {
|
|
1827
|
-
onRecord(JSON.parse(record));
|
|
1828
|
-
} else {
|
|
1829
|
-
onRecord(record);
|
|
1830
|
-
}
|
|
1831
|
-
}
|
|
1832
|
-
}
|
|
1833
|
-
/**
|
|
1834
|
-
* Streams a response from the v-next network loop
|
|
1835
|
-
* @param params - Stream parameters including message
|
|
1836
|
-
* @returns Promise containing the results
|
|
1837
|
-
*/
|
|
1838
|
-
async loopStream(params, onRecord) {
|
|
1839
|
-
const response = await this.request(`/api/networks/v-next/${this.networkId}/loop-stream`, {
|
|
2740
|
+
return this.request(`/api/memory/network/messages/delete?${query.toString()}`, {
|
|
1840
2741
|
method: "POST",
|
|
1841
|
-
body: {
|
|
1842
|
-
...params,
|
|
1843
|
-
runtimeContext: parseClientRuntimeContext(params.runtimeContext)
|
|
1844
|
-
},
|
|
1845
|
-
stream: true
|
|
2742
|
+
body: { messageIds }
|
|
1846
2743
|
});
|
|
1847
|
-
if (!response.ok) {
|
|
1848
|
-
throw new Error(`Failed to stream vNext network loop: ${response.statusText}`);
|
|
1849
|
-
}
|
|
1850
|
-
if (!response.body) {
|
|
1851
|
-
throw new Error("Response body is null");
|
|
1852
|
-
}
|
|
1853
|
-
for await (const record of this.streamProcessor(response.body)) {
|
|
1854
|
-
if (typeof record === "string") {
|
|
1855
|
-
onRecord(JSON.parse(record));
|
|
1856
|
-
} else {
|
|
1857
|
-
onRecord(record);
|
|
1858
|
-
}
|
|
1859
|
-
}
|
|
1860
2744
|
}
|
|
1861
2745
|
};
|
|
1862
2746
|
|
|
1863
2747
|
// src/client.ts
|
|
1864
2748
|
var MastraClient = class extends BaseResource {
|
|
2749
|
+
observability;
|
|
1865
2750
|
constructor(options) {
|
|
1866
2751
|
super(options);
|
|
2752
|
+
this.observability = new Observability(options);
|
|
1867
2753
|
}
|
|
1868
2754
|
/**
|
|
1869
2755
|
* Retrieves all available agents
|
|
2756
|
+
* @param runtimeContext - Optional runtime context to pass as query parameter
|
|
1870
2757
|
* @returns Promise containing map of agent IDs to agent details
|
|
1871
2758
|
*/
|
|
1872
|
-
getAgents() {
|
|
1873
|
-
|
|
1874
|
-
|
|
1875
|
-
|
|
1876
|
-
|
|
1877
|
-
|
|
1878
|
-
|
|
1879
|
-
|
|
1880
|
-
acc[agentId] = new AGUIAdapter({
|
|
1881
|
-
agentId,
|
|
1882
|
-
agent,
|
|
1883
|
-
resourceId
|
|
1884
|
-
});
|
|
1885
|
-
return acc;
|
|
1886
|
-
},
|
|
1887
|
-
{}
|
|
1888
|
-
);
|
|
2759
|
+
getAgents(runtimeContext) {
|
|
2760
|
+
const runtimeContextParam = base64RuntimeContext(parseClientRuntimeContext(runtimeContext));
|
|
2761
|
+
const searchParams = new URLSearchParams();
|
|
2762
|
+
if (runtimeContextParam) {
|
|
2763
|
+
searchParams.set("runtimeContext", runtimeContextParam);
|
|
2764
|
+
}
|
|
2765
|
+
const queryString = searchParams.toString();
|
|
2766
|
+
return this.request(`/api/agents${queryString ? `?${queryString}` : ""}`);
|
|
1889
2767
|
}
|
|
1890
2768
|
/**
|
|
1891
2769
|
* Gets an agent instance by ID
|
|
@@ -1903,6 +2781,14 @@ var MastraClient = class extends BaseResource {
|
|
|
1903
2781
|
getMemoryThreads(params) {
|
|
1904
2782
|
return this.request(`/api/memory/threads?resourceid=${params.resourceId}&agentId=${params.agentId}`);
|
|
1905
2783
|
}
|
|
2784
|
+
/**
|
|
2785
|
+
* Retrieves memory config for a resource
|
|
2786
|
+
* @param params - Parameters containing the resource ID
|
|
2787
|
+
* @returns Promise containing array of memory threads
|
|
2788
|
+
*/
|
|
2789
|
+
getMemoryConfig(params) {
|
|
2790
|
+
return this.request(`/api/memory/config?agentId=${params.agentId}`);
|
|
2791
|
+
}
|
|
1906
2792
|
/**
|
|
1907
2793
|
* Creates a new memory thread
|
|
1908
2794
|
* @param params - Parameters for creating the memory thread
|
|
@@ -1919,6 +2805,24 @@ var MastraClient = class extends BaseResource {
|
|
|
1919
2805
|
getMemoryThread(threadId, agentId) {
|
|
1920
2806
|
return new MemoryThread(this.options, threadId, agentId);
|
|
1921
2807
|
}
|
|
2808
|
+
getThreadMessages(threadId, opts = {}) {
|
|
2809
|
+
let url = "";
|
|
2810
|
+
if (opts.agentId) {
|
|
2811
|
+
url = `/api/memory/threads/${threadId}/messages?agentId=${opts.agentId}`;
|
|
2812
|
+
} else if (opts.networkId) {
|
|
2813
|
+
url = `/api/memory/network/threads/${threadId}/messages?networkId=${opts.networkId}`;
|
|
2814
|
+
}
|
|
2815
|
+
return this.request(url);
|
|
2816
|
+
}
|
|
2817
|
+
deleteThread(threadId, opts = {}) {
|
|
2818
|
+
let url = "";
|
|
2819
|
+
if (opts.agentId) {
|
|
2820
|
+
url = `/api/memory/threads/${threadId}?agentId=${opts.agentId}`;
|
|
2821
|
+
} else if (opts.networkId) {
|
|
2822
|
+
url = `/api/memory/network/threads/${threadId}?networkId=${opts.networkId}`;
|
|
2823
|
+
}
|
|
2824
|
+
return this.request(url, { method: "DELETE" });
|
|
2825
|
+
}
|
|
1922
2826
|
/**
|
|
1923
2827
|
* Saves messages to memory
|
|
1924
2828
|
* @param params - Parameters containing messages to save
|
|
@@ -1981,10 +2885,17 @@ var MastraClient = class extends BaseResource {
|
|
|
1981
2885
|
}
|
|
1982
2886
|
/**
|
|
1983
2887
|
* Retrieves all available tools
|
|
2888
|
+
* @param runtimeContext - Optional runtime context to pass as query parameter
|
|
1984
2889
|
* @returns Promise containing map of tool IDs to tool details
|
|
1985
2890
|
*/
|
|
1986
|
-
getTools() {
|
|
1987
|
-
|
|
2891
|
+
getTools(runtimeContext) {
|
|
2892
|
+
const runtimeContextParam = base64RuntimeContext(parseClientRuntimeContext(runtimeContext));
|
|
2893
|
+
const searchParams = new URLSearchParams();
|
|
2894
|
+
if (runtimeContextParam) {
|
|
2895
|
+
searchParams.set("runtimeContext", runtimeContextParam);
|
|
2896
|
+
}
|
|
2897
|
+
const queryString = searchParams.toString();
|
|
2898
|
+
return this.request(`/api/tools${queryString ? `?${queryString}` : ""}`);
|
|
1988
2899
|
}
|
|
1989
2900
|
/**
|
|
1990
2901
|
* Gets a tool instance by ID
|
|
@@ -1992,29 +2903,21 @@ var MastraClient = class extends BaseResource {
|
|
|
1992
2903
|
* @returns Tool instance
|
|
1993
2904
|
*/
|
|
1994
2905
|
getTool(toolId) {
|
|
1995
|
-
return new
|
|
1996
|
-
}
|
|
1997
|
-
/**
|
|
1998
|
-
* Retrieves all available legacy workflows
|
|
1999
|
-
* @returns Promise containing map of legacy workflow IDs to legacy workflow details
|
|
2000
|
-
*/
|
|
2001
|
-
getLegacyWorkflows() {
|
|
2002
|
-
return this.request("/api/workflows/legacy");
|
|
2003
|
-
}
|
|
2004
|
-
/**
|
|
2005
|
-
* Gets a legacy workflow instance by ID
|
|
2006
|
-
* @param workflowId - ID of the legacy workflow to retrieve
|
|
2007
|
-
* @returns Legacy Workflow instance
|
|
2008
|
-
*/
|
|
2009
|
-
getLegacyWorkflow(workflowId) {
|
|
2010
|
-
return new LegacyWorkflow(this.options, workflowId);
|
|
2906
|
+
return new Tool(this.options, toolId);
|
|
2011
2907
|
}
|
|
2012
2908
|
/**
|
|
2013
2909
|
* Retrieves all available workflows
|
|
2910
|
+
* @param runtimeContext - Optional runtime context to pass as query parameter
|
|
2014
2911
|
* @returns Promise containing map of workflow IDs to workflow details
|
|
2015
2912
|
*/
|
|
2016
|
-
getWorkflows() {
|
|
2017
|
-
|
|
2913
|
+
getWorkflows(runtimeContext) {
|
|
2914
|
+
const runtimeContextParam = base64RuntimeContext(parseClientRuntimeContext(runtimeContext));
|
|
2915
|
+
const searchParams = new URLSearchParams();
|
|
2916
|
+
if (runtimeContextParam) {
|
|
2917
|
+
searchParams.set("runtimeContext", runtimeContextParam);
|
|
2918
|
+
}
|
|
2919
|
+
const queryString = searchParams.toString();
|
|
2920
|
+
return this.request(`/api/workflows${queryString ? `?${queryString}` : ""}`);
|
|
2018
2921
|
}
|
|
2019
2922
|
/**
|
|
2020
2923
|
* Gets a workflow instance by ID
|
|
@@ -2024,6 +2927,20 @@ var MastraClient = class extends BaseResource {
|
|
|
2024
2927
|
getWorkflow(workflowId) {
|
|
2025
2928
|
return new Workflow(this.options, workflowId);
|
|
2026
2929
|
}
|
|
2930
|
+
/**
|
|
2931
|
+
* Gets all available agent builder actions
|
|
2932
|
+
* @returns Promise containing map of action IDs to action details
|
|
2933
|
+
*/
|
|
2934
|
+
getAgentBuilderActions() {
|
|
2935
|
+
return this.request("/api/agent-builder/");
|
|
2936
|
+
}
|
|
2937
|
+
/**
|
|
2938
|
+
* Gets an agent builder instance for executing agent-builder workflows
|
|
2939
|
+
* @returns AgentBuilder instance
|
|
2940
|
+
*/
|
|
2941
|
+
getAgentBuilderAction(actionId) {
|
|
2942
|
+
return new AgentBuilder(this.options, actionId);
|
|
2943
|
+
}
|
|
2027
2944
|
/**
|
|
2028
2945
|
* Gets a vector instance by name
|
|
2029
2946
|
* @param vectorName - Name of the vector to retrieve
|
|
@@ -2168,36 +3085,6 @@ var MastraClient = class extends BaseResource {
|
|
|
2168
3085
|
return this.request(`/api/telemetry`);
|
|
2169
3086
|
}
|
|
2170
3087
|
}
|
|
2171
|
-
/**
|
|
2172
|
-
* Retrieves all available networks
|
|
2173
|
-
* @returns Promise containing map of network IDs to network details
|
|
2174
|
-
*/
|
|
2175
|
-
getNetworks() {
|
|
2176
|
-
return this.request("/api/networks");
|
|
2177
|
-
}
|
|
2178
|
-
/**
|
|
2179
|
-
* Retrieves all available vNext networks
|
|
2180
|
-
* @returns Promise containing map of vNext network IDs to vNext network details
|
|
2181
|
-
*/
|
|
2182
|
-
getVNextNetworks() {
|
|
2183
|
-
return this.request("/api/networks/v-next");
|
|
2184
|
-
}
|
|
2185
|
-
/**
|
|
2186
|
-
* Gets a network instance by ID
|
|
2187
|
-
* @param networkId - ID of the network to retrieve
|
|
2188
|
-
* @returns Network instance
|
|
2189
|
-
*/
|
|
2190
|
-
getNetwork(networkId) {
|
|
2191
|
-
return new Network(this.options, networkId);
|
|
2192
|
-
}
|
|
2193
|
-
/**
|
|
2194
|
-
* Gets a vNext network instance by ID
|
|
2195
|
-
* @param networkId - ID of the vNext network to retrieve
|
|
2196
|
-
* @returns vNext Network instance
|
|
2197
|
-
*/
|
|
2198
|
-
getVNextNetwork(networkId) {
|
|
2199
|
-
return new VNextNetwork(this.options, networkId);
|
|
2200
|
-
}
|
|
2201
3088
|
/**
|
|
2202
3089
|
* Retrieves a list of available MCP servers.
|
|
2203
3090
|
* @param params - Optional parameters for pagination (limit, offset).
|
|
@@ -2289,6 +3176,128 @@ var MastraClient = class extends BaseResource {
|
|
|
2289
3176
|
}
|
|
2290
3177
|
});
|
|
2291
3178
|
}
|
|
3179
|
+
/**
|
|
3180
|
+
* Retrieves all available scorers
|
|
3181
|
+
* @returns Promise containing list of available scorers
|
|
3182
|
+
*/
|
|
3183
|
+
getScorers() {
|
|
3184
|
+
return this.request("/api/scores/scorers");
|
|
3185
|
+
}
|
|
3186
|
+
/**
|
|
3187
|
+
* Retrieves a scorer by ID
|
|
3188
|
+
* @param scorerId - ID of the scorer to retrieve
|
|
3189
|
+
* @returns Promise containing the scorer
|
|
3190
|
+
*/
|
|
3191
|
+
getScorer(scorerId) {
|
|
3192
|
+
return this.request(`/api/scores/scorers/${encodeURIComponent(scorerId)}`);
|
|
3193
|
+
}
|
|
3194
|
+
getScoresByScorerId(params) {
|
|
3195
|
+
const { page, perPage, scorerId, entityId, entityType } = params;
|
|
3196
|
+
const searchParams = new URLSearchParams();
|
|
3197
|
+
if (entityId) {
|
|
3198
|
+
searchParams.set("entityId", entityId);
|
|
3199
|
+
}
|
|
3200
|
+
if (entityType) {
|
|
3201
|
+
searchParams.set("entityType", entityType);
|
|
3202
|
+
}
|
|
3203
|
+
if (page !== void 0) {
|
|
3204
|
+
searchParams.set("page", String(page));
|
|
3205
|
+
}
|
|
3206
|
+
if (perPage !== void 0) {
|
|
3207
|
+
searchParams.set("perPage", String(perPage));
|
|
3208
|
+
}
|
|
3209
|
+
const queryString = searchParams.toString();
|
|
3210
|
+
return this.request(`/api/scores/scorer/${encodeURIComponent(scorerId)}${queryString ? `?${queryString}` : ""}`);
|
|
3211
|
+
}
|
|
3212
|
+
/**
|
|
3213
|
+
* Retrieves scores by run ID
|
|
3214
|
+
* @param params - Parameters containing run ID and pagination options
|
|
3215
|
+
* @returns Promise containing scores and pagination info
|
|
3216
|
+
*/
|
|
3217
|
+
getScoresByRunId(params) {
|
|
3218
|
+
const { runId, page, perPage } = params;
|
|
3219
|
+
const searchParams = new URLSearchParams();
|
|
3220
|
+
if (page !== void 0) {
|
|
3221
|
+
searchParams.set("page", String(page));
|
|
3222
|
+
}
|
|
3223
|
+
if (perPage !== void 0) {
|
|
3224
|
+
searchParams.set("perPage", String(perPage));
|
|
3225
|
+
}
|
|
3226
|
+
const queryString = searchParams.toString();
|
|
3227
|
+
return this.request(`/api/scores/run/${encodeURIComponent(runId)}${queryString ? `?${queryString}` : ""}`);
|
|
3228
|
+
}
|
|
3229
|
+
/**
|
|
3230
|
+
* Retrieves scores by entity ID and type
|
|
3231
|
+
* @param params - Parameters containing entity ID, type, and pagination options
|
|
3232
|
+
* @returns Promise containing scores and pagination info
|
|
3233
|
+
*/
|
|
3234
|
+
getScoresByEntityId(params) {
|
|
3235
|
+
const { entityId, entityType, page, perPage } = params;
|
|
3236
|
+
const searchParams = new URLSearchParams();
|
|
3237
|
+
if (page !== void 0) {
|
|
3238
|
+
searchParams.set("page", String(page));
|
|
3239
|
+
}
|
|
3240
|
+
if (perPage !== void 0) {
|
|
3241
|
+
searchParams.set("perPage", String(perPage));
|
|
3242
|
+
}
|
|
3243
|
+
const queryString = searchParams.toString();
|
|
3244
|
+
return this.request(
|
|
3245
|
+
`/api/scores/entity/${encodeURIComponent(entityType)}/${encodeURIComponent(entityId)}${queryString ? `?${queryString}` : ""}`
|
|
3246
|
+
);
|
|
3247
|
+
}
|
|
3248
|
+
/**
|
|
3249
|
+
* Saves a score
|
|
3250
|
+
* @param params - Parameters containing the score data to save
|
|
3251
|
+
* @returns Promise containing the saved score
|
|
3252
|
+
*/
|
|
3253
|
+
saveScore(params) {
|
|
3254
|
+
return this.request("/api/scores", {
|
|
3255
|
+
method: "POST",
|
|
3256
|
+
body: params
|
|
3257
|
+
});
|
|
3258
|
+
}
|
|
3259
|
+
/**
|
|
3260
|
+
* Retrieves model providers with available keys
|
|
3261
|
+
* @returns Promise containing model providers with available keys
|
|
3262
|
+
*/
|
|
3263
|
+
getModelProviders() {
|
|
3264
|
+
return this.request(`/api/model-providers`);
|
|
3265
|
+
}
|
|
3266
|
+
getAITrace(traceId) {
|
|
3267
|
+
return this.observability.getTrace(traceId);
|
|
3268
|
+
}
|
|
3269
|
+
getAITraces(params) {
|
|
3270
|
+
return this.observability.getTraces(params);
|
|
3271
|
+
}
|
|
3272
|
+
getScoresBySpan(params) {
|
|
3273
|
+
return this.observability.getScoresBySpan(params);
|
|
3274
|
+
}
|
|
3275
|
+
score(params) {
|
|
3276
|
+
return this.observability.score(params);
|
|
3277
|
+
}
|
|
2292
3278
|
};
|
|
2293
3279
|
|
|
3280
|
+
// src/tools.ts
|
|
3281
|
+
var ClientTool = class {
|
|
3282
|
+
id;
|
|
3283
|
+
description;
|
|
3284
|
+
inputSchema;
|
|
3285
|
+
outputSchema;
|
|
3286
|
+
execute;
|
|
3287
|
+
constructor(opts) {
|
|
3288
|
+
this.id = opts.id;
|
|
3289
|
+
this.description = opts.description;
|
|
3290
|
+
this.inputSchema = opts.inputSchema;
|
|
3291
|
+
this.outputSchema = opts.outputSchema;
|
|
3292
|
+
this.execute = opts.execute;
|
|
3293
|
+
}
|
|
3294
|
+
};
|
|
3295
|
+
function createTool(opts) {
|
|
3296
|
+
return new ClientTool(opts);
|
|
3297
|
+
}
|
|
3298
|
+
|
|
3299
|
+
exports.ClientTool = ClientTool;
|
|
2294
3300
|
exports.MastraClient = MastraClient;
|
|
3301
|
+
exports.createTool = createTool;
|
|
3302
|
+
//# sourceMappingURL=index.cjs.map
|
|
3303
|
+
//# sourceMappingURL=index.cjs.map
|