@mastra/client-js 0.0.0-add-runtime-context-to-openai-realtime-20250516201052 → 0.0.0-add-save-score-validation-on-stores-20250911031242
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 +1555 -2
- package/LICENSE.md +11 -42
- package/README.md +7 -4
- package/dist/client.d.ts +280 -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 +2411 -450
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +4 -883
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +2413 -452
- 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 +161 -0
- package/dist/resources/agent-builder.d.ts.map +1 -0
- package/dist/resources/agent.d.ts +160 -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 +13 -0
- package/dist/resources/index.d.ts.map +1 -0
- package/dist/resources/legacy-workflow.d.ts +87 -0
- package/dist/resources/legacy-workflow.d.ts.map +1 -0
- package/dist/resources/mcp-tool.d.ts +27 -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/network.d.ts +30 -0
- package/dist/resources/network.d.ts.map +1 -0
- package/dist/resources/observability.d.ts +19 -0
- package/dist/resources/observability.d.ts.map +1 -0
- package/dist/resources/tool.d.ts +23 -0
- package/dist/resources/tool.d.ts.map +1 -0
- package/dist/resources/vNextNetwork.d.ts +42 -0
- package/dist/resources/vNextNetwork.d.ts.map +1 -0
- package/dist/resources/vector.d.ts +48 -0
- package/dist/resources/vector.d.ts.map +1 -0
- package/dist/resources/workflow.d.ts +169 -0
- package/dist/resources/workflow.d.ts.map +1 -0
- package/dist/types.d.ts +469 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/utils/index.d.ts +3 -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 +38 -20
- package/dist/index.d.cts +0 -883
- 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 -335
- package/src/example.ts +0 -64
- 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 -196
- package/src/resources/base.ts +0 -70
- package/src/resources/index.ts +0 -10
- package/src/resources/mcp-tool.ts +0 -48
- package/src/resources/memory-thread.ts +0 -63
- package/src/resources/network.ts +0 -86
- package/src/resources/tool.ts +0 -44
- package/src/resources/vector.ts +0 -83
- package/src/resources/vnext-workflow.ts +0 -261
- package/src/resources/workflow.ts +0 -251
- package/src/types.ts +0 -308
- 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,8 +1,9 @@
|
|
|
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');
|
|
4
|
+
var uuid = require('@lukeed/uuid');
|
|
5
|
+
var runtimeContext = require('@mastra/core/runtime-context');
|
|
6
|
+
var isVercelTool = require('@mastra/core/tools/is-vercel-tool');
|
|
6
7
|
var zod = require('zod');
|
|
7
8
|
var originalZodToJsonSchema = require('zod-to-json-schema');
|
|
8
9
|
|
|
@@ -10,196 +11,111 @@ function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
|
10
11
|
|
|
11
12
|
var originalZodToJsonSchema__default = /*#__PURE__*/_interopDefault(originalZodToJsonSchema);
|
|
12
13
|
|
|
13
|
-
// src/
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
super({
|
|
19
|
-
agentId,
|
|
20
|
-
...rest
|
|
21
|
-
});
|
|
22
|
-
this.agent = agent;
|
|
23
|
-
this.resourceId = resourceId;
|
|
24
|
-
}
|
|
25
|
-
run(input) {
|
|
26
|
-
return new rxjs.Observable((subscriber) => {
|
|
27
|
-
const convertedMessages = convertMessagesToMastraMessages(input.messages);
|
|
28
|
-
subscriber.next({
|
|
29
|
-
type: client.EventType.RUN_STARTED,
|
|
30
|
-
threadId: input.threadId,
|
|
31
|
-
runId: input.runId
|
|
32
|
-
});
|
|
33
|
-
this.agent.stream({
|
|
34
|
-
threadId: input.threadId,
|
|
35
|
-
resourceId: this.resourceId ?? "",
|
|
36
|
-
runId: input.runId,
|
|
37
|
-
messages: convertedMessages,
|
|
38
|
-
clientTools: input.tools.reduce(
|
|
39
|
-
(acc, tool) => {
|
|
40
|
-
acc[tool.name] = {
|
|
41
|
-
id: tool.name,
|
|
42
|
-
description: tool.description,
|
|
43
|
-
inputSchema: tool.parameters
|
|
44
|
-
};
|
|
45
|
-
return acc;
|
|
46
|
-
},
|
|
47
|
-
{}
|
|
48
|
-
)
|
|
49
|
-
}).then((response) => {
|
|
50
|
-
let currentMessageId = void 0;
|
|
51
|
-
let isInTextMessage = false;
|
|
52
|
-
return response.processDataStream({
|
|
53
|
-
onTextPart: (text) => {
|
|
54
|
-
if (currentMessageId === void 0) {
|
|
55
|
-
currentMessageId = generateUUID();
|
|
56
|
-
const message2 = {
|
|
57
|
-
type: client.EventType.TEXT_MESSAGE_START,
|
|
58
|
-
messageId: currentMessageId,
|
|
59
|
-
role: "assistant"
|
|
60
|
-
};
|
|
61
|
-
subscriber.next(message2);
|
|
62
|
-
isInTextMessage = true;
|
|
63
|
-
}
|
|
64
|
-
const message = {
|
|
65
|
-
type: client.EventType.TEXT_MESSAGE_CONTENT,
|
|
66
|
-
messageId: currentMessageId,
|
|
67
|
-
delta: text
|
|
68
|
-
};
|
|
69
|
-
subscriber.next(message);
|
|
70
|
-
},
|
|
71
|
-
onFinishMessagePart: () => {
|
|
72
|
-
if (currentMessageId !== void 0) {
|
|
73
|
-
const message = {
|
|
74
|
-
type: client.EventType.TEXT_MESSAGE_END,
|
|
75
|
-
messageId: currentMessageId
|
|
76
|
-
};
|
|
77
|
-
subscriber.next(message);
|
|
78
|
-
isInTextMessage = false;
|
|
79
|
-
}
|
|
80
|
-
subscriber.next({
|
|
81
|
-
type: client.EventType.RUN_FINISHED,
|
|
82
|
-
threadId: input.threadId,
|
|
83
|
-
runId: input.runId
|
|
84
|
-
});
|
|
85
|
-
subscriber.complete();
|
|
86
|
-
},
|
|
87
|
-
onToolCallPart(streamPart) {
|
|
88
|
-
const parentMessageId = currentMessageId || generateUUID();
|
|
89
|
-
if (isInTextMessage) {
|
|
90
|
-
const message = {
|
|
91
|
-
type: client.EventType.TEXT_MESSAGE_END,
|
|
92
|
-
messageId: parentMessageId
|
|
93
|
-
};
|
|
94
|
-
subscriber.next(message);
|
|
95
|
-
isInTextMessage = false;
|
|
96
|
-
}
|
|
97
|
-
subscriber.next({
|
|
98
|
-
type: client.EventType.TOOL_CALL_START,
|
|
99
|
-
toolCallId: streamPart.toolCallId,
|
|
100
|
-
toolCallName: streamPart.toolName,
|
|
101
|
-
parentMessageId
|
|
102
|
-
});
|
|
103
|
-
subscriber.next({
|
|
104
|
-
type: client.EventType.TOOL_CALL_ARGS,
|
|
105
|
-
toolCallId: streamPart.toolCallId,
|
|
106
|
-
delta: JSON.stringify(streamPart.args),
|
|
107
|
-
parentMessageId
|
|
108
|
-
});
|
|
109
|
-
subscriber.next({
|
|
110
|
-
type: client.EventType.TOOL_CALL_END,
|
|
111
|
-
toolCallId: streamPart.toolCallId,
|
|
112
|
-
parentMessageId
|
|
113
|
-
});
|
|
114
|
-
}
|
|
115
|
-
});
|
|
116
|
-
}).catch((error) => {
|
|
117
|
-
console.error("error", error);
|
|
118
|
-
subscriber.error(error);
|
|
119
|
-
});
|
|
120
|
-
return () => {
|
|
121
|
-
};
|
|
122
|
-
});
|
|
123
|
-
}
|
|
124
|
-
};
|
|
125
|
-
function generateUUID() {
|
|
126
|
-
if (typeof crypto !== "undefined") {
|
|
127
|
-
if (typeof crypto.randomUUID === "function") {
|
|
128
|
-
return crypto.randomUUID();
|
|
129
|
-
}
|
|
130
|
-
if (typeof crypto.getRandomValues === "function") {
|
|
131
|
-
const buffer = new Uint8Array(16);
|
|
132
|
-
crypto.getRandomValues(buffer);
|
|
133
|
-
buffer[6] = buffer[6] & 15 | 64;
|
|
134
|
-
buffer[8] = buffer[8] & 63 | 128;
|
|
135
|
-
let hex = "";
|
|
136
|
-
for (let i = 0; i < 16; i++) {
|
|
137
|
-
hex += buffer[i].toString(16).padStart(2, "0");
|
|
138
|
-
if (i === 3 || i === 5 || i === 7 || i === 9) hex += "-";
|
|
139
|
-
}
|
|
140
|
-
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());
|
|
141
19
|
}
|
|
20
|
+
return runtimeContext$1;
|
|
142
21
|
}
|
|
143
|
-
return
|
|
144
|
-
const r = Math.random() * 16 | 0;
|
|
145
|
-
const v = c === "x" ? r : r & 3 | 8;
|
|
146
|
-
return v.toString(16);
|
|
147
|
-
});
|
|
22
|
+
return void 0;
|
|
148
23
|
}
|
|
149
|
-
function
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
result: JSON.parse(toolCall.function.arguments)
|
|
174
|
-
}))
|
|
175
|
-
});
|
|
176
|
-
}
|
|
177
|
-
} else if (message.role === "user") {
|
|
178
|
-
result.push({
|
|
179
|
-
role: "user",
|
|
180
|
-
content: message.content || ""
|
|
181
|
-
});
|
|
182
|
-
} else if (message.role === "tool") {
|
|
183
|
-
result.push({
|
|
184
|
-
role: "tool",
|
|
185
|
-
content: [
|
|
24
|
+
function isZodType(value) {
|
|
25
|
+
return typeof value === "object" && value !== null && "_def" in value && "parse" in value && typeof value.parse === "function" && "safeParse" in value && typeof value.safeParse === "function";
|
|
26
|
+
}
|
|
27
|
+
function zodToJsonSchema(zodSchema) {
|
|
28
|
+
if (!isZodType(zodSchema)) {
|
|
29
|
+
return zodSchema;
|
|
30
|
+
}
|
|
31
|
+
if ("toJSONSchema" in zod.z) {
|
|
32
|
+
const fn = "toJSONSchema";
|
|
33
|
+
return zod.z[fn].call(zod.z, zodSchema);
|
|
34
|
+
}
|
|
35
|
+
return originalZodToJsonSchema__default.default(zodSchema, { $refStrategy: "relative" });
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// src/utils/process-client-tools.ts
|
|
39
|
+
function processClientTools(clientTools) {
|
|
40
|
+
if (!clientTools) {
|
|
41
|
+
return void 0;
|
|
42
|
+
}
|
|
43
|
+
return Object.fromEntries(
|
|
44
|
+
Object.entries(clientTools).map(([key, value]) => {
|
|
45
|
+
if (isVercelTool.isVercelTool(value)) {
|
|
46
|
+
return [
|
|
47
|
+
key,
|
|
186
48
|
{
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
toolName: "unknown",
|
|
190
|
-
result: message.content
|
|
49
|
+
...value,
|
|
50
|
+
parameters: value.parameters ? zodToJsonSchema(value.parameters) : void 0
|
|
191
51
|
}
|
|
192
|
-
]
|
|
193
|
-
}
|
|
52
|
+
];
|
|
53
|
+
} else {
|
|
54
|
+
return [
|
|
55
|
+
key,
|
|
56
|
+
{
|
|
57
|
+
...value,
|
|
58
|
+
inputSchema: value.inputSchema ? zodToJsonSchema(value.inputSchema) : void 0,
|
|
59
|
+
outputSchema: value.outputSchema ? zodToJsonSchema(value.outputSchema) : void 0
|
|
60
|
+
}
|
|
61
|
+
];
|
|
62
|
+
}
|
|
63
|
+
})
|
|
64
|
+
);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
// src/utils/process-mastra-stream.ts
|
|
68
|
+
async function sharedProcessMastraStream({
|
|
69
|
+
stream,
|
|
70
|
+
onChunk
|
|
71
|
+
}) {
|
|
72
|
+
const reader = stream.getReader();
|
|
73
|
+
const decoder = new TextDecoder();
|
|
74
|
+
let buffer = "";
|
|
75
|
+
try {
|
|
76
|
+
while (true) {
|
|
77
|
+
const { done, value } = await reader.read();
|
|
78
|
+
if (done) break;
|
|
79
|
+
buffer += decoder.decode(value, { stream: true });
|
|
80
|
+
const lines = buffer.split("\n\n");
|
|
81
|
+
buffer = lines.pop() || "";
|
|
82
|
+
for (const line of lines) {
|
|
83
|
+
if (line.startsWith("data: ")) {
|
|
84
|
+
const data = line.slice(6);
|
|
85
|
+
if (data === "[DONE]") {
|
|
86
|
+
console.log("\u{1F3C1} Stream finished");
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
try {
|
|
90
|
+
const json = JSON.parse(data);
|
|
91
|
+
await onChunk(json);
|
|
92
|
+
} catch (error) {
|
|
93
|
+
console.error("\u274C JSON parse error:", error, "Data:", data);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|
|
194
97
|
}
|
|
98
|
+
} finally {
|
|
99
|
+
reader.releaseLock();
|
|
195
100
|
}
|
|
196
|
-
return result;
|
|
197
101
|
}
|
|
198
|
-
function
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
return
|
|
102
|
+
async function processMastraNetworkStream({
|
|
103
|
+
stream,
|
|
104
|
+
onChunk
|
|
105
|
+
}) {
|
|
106
|
+
return sharedProcessMastraStream({
|
|
107
|
+
stream,
|
|
108
|
+
onChunk
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
async function processMastraStream({
|
|
112
|
+
stream,
|
|
113
|
+
onChunk
|
|
114
|
+
}) {
|
|
115
|
+
return sharedProcessMastraStream({
|
|
116
|
+
stream,
|
|
117
|
+
onChunk
|
|
118
|
+
});
|
|
203
119
|
}
|
|
204
120
|
|
|
205
121
|
// src/resources/base.ts
|
|
@@ -216,18 +132,21 @@ var BaseResource = class {
|
|
|
216
132
|
*/
|
|
217
133
|
async request(path, options = {}) {
|
|
218
134
|
let lastError = null;
|
|
219
|
-
const { baseUrl, retries = 3, backoffMs = 100, maxBackoffMs = 1e3, headers = {} } = this.options;
|
|
135
|
+
const { baseUrl, retries = 3, backoffMs = 100, maxBackoffMs = 1e3, headers = {}, credentials } = this.options;
|
|
220
136
|
let delay = backoffMs;
|
|
221
137
|
for (let attempt = 0; attempt <= retries; attempt++) {
|
|
222
138
|
try {
|
|
223
139
|
const response = await fetch(`${baseUrl.replace(/\/$/, "")}${path}`, {
|
|
224
140
|
...options,
|
|
225
141
|
headers: {
|
|
142
|
+
...options.body && !(options.body instanceof FormData) && (options.method === "POST" || options.method === "PUT") ? { "content-type": "application/json" } : {},
|
|
226
143
|
...headers,
|
|
227
144
|
...options.headers
|
|
228
145
|
// TODO: Bring this back once we figure out what we/users need to do to make this work with cross-origin requests
|
|
229
146
|
// 'x-mastra-client-type': 'js',
|
|
230
147
|
},
|
|
148
|
+
signal: this.options.abortSignal,
|
|
149
|
+
credentials: options.credentials ?? credentials,
|
|
231
150
|
body: options.body instanceof FormData ? options.body : options.body ? JSON.stringify(options.body) : void 0
|
|
232
151
|
});
|
|
233
152
|
if (!response.ok) {
|
|
@@ -262,6 +181,63 @@ var BaseResource = class {
|
|
|
262
181
|
};
|
|
263
182
|
|
|
264
183
|
// src/resources/agent.ts
|
|
184
|
+
async function executeToolCallAndRespond({
|
|
185
|
+
response,
|
|
186
|
+
params,
|
|
187
|
+
runId,
|
|
188
|
+
resourceId,
|
|
189
|
+
threadId,
|
|
190
|
+
runtimeContext,
|
|
191
|
+
respondFn
|
|
192
|
+
}) {
|
|
193
|
+
if (response.finishReason === "tool-calls") {
|
|
194
|
+
const toolCalls = response.toolCalls;
|
|
195
|
+
if (!toolCalls || !Array.isArray(toolCalls)) {
|
|
196
|
+
return response;
|
|
197
|
+
}
|
|
198
|
+
for (const toolCall of toolCalls) {
|
|
199
|
+
const clientTool = params.clientTools?.[toolCall.toolName];
|
|
200
|
+
if (clientTool && clientTool.execute) {
|
|
201
|
+
const result = await clientTool.execute(
|
|
202
|
+
{
|
|
203
|
+
context: toolCall?.args,
|
|
204
|
+
runId,
|
|
205
|
+
resourceId,
|
|
206
|
+
threadId,
|
|
207
|
+
runtimeContext,
|
|
208
|
+
tracingContext: { currentSpan: void 0 }
|
|
209
|
+
},
|
|
210
|
+
{
|
|
211
|
+
messages: response.messages,
|
|
212
|
+
toolCallId: toolCall?.toolCallId
|
|
213
|
+
}
|
|
214
|
+
);
|
|
215
|
+
const updatedMessages = [
|
|
216
|
+
{
|
|
217
|
+
role: "user",
|
|
218
|
+
content: params.messages
|
|
219
|
+
},
|
|
220
|
+
...response.response.messages,
|
|
221
|
+
{
|
|
222
|
+
role: "tool",
|
|
223
|
+
content: [
|
|
224
|
+
{
|
|
225
|
+
type: "tool-result",
|
|
226
|
+
toolCallId: toolCall.toolCallId,
|
|
227
|
+
toolName: toolCall.toolName,
|
|
228
|
+
result
|
|
229
|
+
}
|
|
230
|
+
]
|
|
231
|
+
}
|
|
232
|
+
];
|
|
233
|
+
return respondFn({
|
|
234
|
+
...params,
|
|
235
|
+
messages: updatedMessages
|
|
236
|
+
});
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
}
|
|
265
241
|
var AgentVoice = class extends BaseResource {
|
|
266
242
|
constructor(options, agentId) {
|
|
267
243
|
super(options);
|
|
@@ -308,6 +284,13 @@ var AgentVoice = class extends BaseResource {
|
|
|
308
284
|
getSpeakers() {
|
|
309
285
|
return this.request(`/api/agents/${this.agentId}/voice/speakers`);
|
|
310
286
|
}
|
|
287
|
+
/**
|
|
288
|
+
* Get the listener configuration for the agent's voice provider
|
|
289
|
+
* @returns Promise containing a check if the agent has listening capabilities
|
|
290
|
+
*/
|
|
291
|
+
getListener() {
|
|
292
|
+
return this.request(`/api/agents/${this.agentId}/voice/listener`);
|
|
293
|
+
}
|
|
311
294
|
};
|
|
312
295
|
var Agent = class extends BaseResource {
|
|
313
296
|
constructor(options, agentId) {
|
|
@@ -323,152 +306,1060 @@ var Agent = class extends BaseResource {
|
|
|
323
306
|
details() {
|
|
324
307
|
return this.request(`/api/agents/${this.agentId}`);
|
|
325
308
|
}
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
309
|
+
async generate(params) {
|
|
310
|
+
console.warn(
|
|
311
|
+
"Deprecation NOTICE:Generate method will switch to use generateVNext implementation September 16th, 2025. Please use generateLegacy if you don't want to upgrade just yet."
|
|
312
|
+
);
|
|
313
|
+
return this.generateLegacy(params);
|
|
314
|
+
}
|
|
315
|
+
async generateLegacy(params) {
|
|
332
316
|
const processedParams = {
|
|
333
317
|
...params,
|
|
334
318
|
output: params.output ? zodToJsonSchema(params.output) : void 0,
|
|
335
319
|
experimental_output: params.experimental_output ? zodToJsonSchema(params.experimental_output) : void 0,
|
|
336
|
-
runtimeContext:
|
|
320
|
+
runtimeContext: parseClientRuntimeContext(params.runtimeContext),
|
|
321
|
+
clientTools: processClientTools(params.clientTools)
|
|
337
322
|
};
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
323
|
+
const { runId, resourceId, threadId, runtimeContext } = processedParams;
|
|
324
|
+
const response = await this.request(
|
|
325
|
+
`/api/agents/${this.agentId}/generate-legacy`,
|
|
326
|
+
{
|
|
327
|
+
method: "POST",
|
|
328
|
+
body: processedParams
|
|
329
|
+
}
|
|
330
|
+
);
|
|
331
|
+
if (response.finishReason === "tool-calls") {
|
|
332
|
+
const toolCalls = response.toolCalls;
|
|
333
|
+
if (!toolCalls || !Array.isArray(toolCalls)) {
|
|
334
|
+
return response;
|
|
335
|
+
}
|
|
336
|
+
for (const toolCall of toolCalls) {
|
|
337
|
+
const clientTool = params.clientTools?.[toolCall.toolName];
|
|
338
|
+
if (clientTool && clientTool.execute) {
|
|
339
|
+
const result = await clientTool.execute(
|
|
340
|
+
{
|
|
341
|
+
context: toolCall?.args,
|
|
342
|
+
runId,
|
|
343
|
+
resourceId,
|
|
344
|
+
threadId,
|
|
345
|
+
runtimeContext,
|
|
346
|
+
tracingContext: { currentSpan: void 0 }
|
|
347
|
+
},
|
|
348
|
+
{
|
|
349
|
+
messages: response.messages,
|
|
350
|
+
toolCallId: toolCall?.toolCallId
|
|
351
|
+
}
|
|
352
|
+
);
|
|
353
|
+
const updatedMessages = [
|
|
354
|
+
{
|
|
355
|
+
role: "user",
|
|
356
|
+
content: params.messages
|
|
357
|
+
},
|
|
358
|
+
...response.response.messages,
|
|
359
|
+
{
|
|
360
|
+
role: "tool",
|
|
361
|
+
content: [
|
|
362
|
+
{
|
|
363
|
+
type: "tool-result",
|
|
364
|
+
toolCallId: toolCall.toolCallId,
|
|
365
|
+
toolName: toolCall.toolName,
|
|
366
|
+
result
|
|
367
|
+
}
|
|
368
|
+
]
|
|
369
|
+
}
|
|
370
|
+
];
|
|
371
|
+
return this.generate({
|
|
372
|
+
...params,
|
|
373
|
+
messages: updatedMessages
|
|
374
|
+
});
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
return response;
|
|
342
379
|
}
|
|
343
|
-
|
|
344
|
-
* Streams a response from the agent
|
|
345
|
-
* @param params - Stream parameters including prompt
|
|
346
|
-
* @returns Promise containing the enhanced Response object with processDataStream method
|
|
347
|
-
*/
|
|
348
|
-
async stream(params) {
|
|
380
|
+
async generateVNext(params) {
|
|
349
381
|
const processedParams = {
|
|
350
382
|
...params,
|
|
351
383
|
output: params.output ? zodToJsonSchema(params.output) : void 0,
|
|
352
|
-
|
|
353
|
-
|
|
384
|
+
runtimeContext: parseClientRuntimeContext(params.runtimeContext),
|
|
385
|
+
clientTools: processClientTools(params.clientTools),
|
|
386
|
+
structuredOutput: params.structuredOutput ? {
|
|
387
|
+
...params.structuredOutput,
|
|
388
|
+
schema: zodToJsonSchema(params.structuredOutput.schema)
|
|
389
|
+
} : void 0
|
|
354
390
|
};
|
|
355
|
-
const
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
response.
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
391
|
+
const { runId, resourceId, threadId, runtimeContext } = processedParams;
|
|
392
|
+
const response = await this.request(
|
|
393
|
+
`/api/agents/${this.agentId}/generate/vnext`,
|
|
394
|
+
{
|
|
395
|
+
method: "POST",
|
|
396
|
+
body: processedParams
|
|
397
|
+
}
|
|
398
|
+
);
|
|
399
|
+
if (response.finishReason === "tool-calls") {
|
|
400
|
+
return executeToolCallAndRespond({
|
|
401
|
+
response,
|
|
402
|
+
params,
|
|
403
|
+
runId,
|
|
404
|
+
resourceId,
|
|
405
|
+
threadId,
|
|
406
|
+
runtimeContext,
|
|
407
|
+
respondFn: this.generateVNext.bind(this)
|
|
367
408
|
});
|
|
368
|
-
}
|
|
409
|
+
}
|
|
369
410
|
return response;
|
|
370
411
|
}
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
}
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
412
|
+
async processChatResponse({
|
|
413
|
+
stream,
|
|
414
|
+
update,
|
|
415
|
+
onToolCall,
|
|
416
|
+
onFinish,
|
|
417
|
+
getCurrentDate = () => /* @__PURE__ */ new Date(),
|
|
418
|
+
lastMessage
|
|
419
|
+
}) {
|
|
420
|
+
const replaceLastMessage = lastMessage?.role === "assistant";
|
|
421
|
+
let step = replaceLastMessage ? 1 + // find max step in existing tool invocations:
|
|
422
|
+
(lastMessage.toolInvocations?.reduce((max, toolInvocation) => {
|
|
423
|
+
return Math.max(max, toolInvocation.step ?? 0);
|
|
424
|
+
}, 0) ?? 0) : 0;
|
|
425
|
+
const message = replaceLastMessage ? structuredClone(lastMessage) : {
|
|
426
|
+
id: uuid.v4(),
|
|
427
|
+
createdAt: getCurrentDate(),
|
|
428
|
+
role: "assistant",
|
|
429
|
+
content: "",
|
|
430
|
+
parts: []
|
|
389
431
|
};
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
432
|
+
let currentTextPart = void 0;
|
|
433
|
+
let currentReasoningPart = void 0;
|
|
434
|
+
let currentReasoningTextDetail = void 0;
|
|
435
|
+
function updateToolInvocationPart(toolCallId, invocation) {
|
|
436
|
+
const part = message.parts.find(
|
|
437
|
+
(part2) => part2.type === "tool-invocation" && part2.toolInvocation.toolCallId === toolCallId
|
|
438
|
+
);
|
|
439
|
+
if (part != null) {
|
|
440
|
+
part.toolInvocation = invocation;
|
|
441
|
+
} else {
|
|
442
|
+
message.parts.push({
|
|
443
|
+
type: "tool-invocation",
|
|
444
|
+
toolInvocation: invocation
|
|
445
|
+
});
|
|
446
|
+
}
|
|
447
|
+
}
|
|
448
|
+
const data = [];
|
|
449
|
+
let messageAnnotations = replaceLastMessage ? lastMessage?.annotations : void 0;
|
|
450
|
+
const partialToolCalls = {};
|
|
451
|
+
let usage = {
|
|
452
|
+
completionTokens: NaN,
|
|
453
|
+
promptTokens: NaN,
|
|
454
|
+
totalTokens: NaN
|
|
455
|
+
};
|
|
456
|
+
let finishReason = "unknown";
|
|
457
|
+
function execUpdate() {
|
|
458
|
+
const copiedData = [...data];
|
|
459
|
+
if (messageAnnotations?.length) {
|
|
460
|
+
message.annotations = messageAnnotations;
|
|
461
|
+
}
|
|
462
|
+
const copiedMessage = {
|
|
463
|
+
// deep copy the message to ensure that deep changes (msg attachments) are updated
|
|
464
|
+
// with SolidJS. SolidJS uses referential integration of sub-objects to detect changes.
|
|
465
|
+
...structuredClone(message),
|
|
466
|
+
// add a revision id to ensure that the message is updated with SWR. SWR uses a
|
|
467
|
+
// hashing approach by default to detect changes, but it only works for shallow
|
|
468
|
+
// changes. This is why we need to add a revision id to ensure that the message
|
|
469
|
+
// is updated with SWR (without it, the changes get stuck in SWR and are not
|
|
470
|
+
// forwarded to rendering):
|
|
471
|
+
revisionId: uuid.v4()
|
|
472
|
+
};
|
|
473
|
+
update({
|
|
474
|
+
message: copiedMessage,
|
|
475
|
+
data: copiedData,
|
|
476
|
+
replaceLastMessage
|
|
477
|
+
});
|
|
478
|
+
}
|
|
479
|
+
await uiUtils.processDataStream({
|
|
480
|
+
stream,
|
|
481
|
+
onTextPart(value) {
|
|
482
|
+
if (currentTextPart == null) {
|
|
483
|
+
currentTextPart = {
|
|
484
|
+
type: "text",
|
|
485
|
+
text: value
|
|
486
|
+
};
|
|
487
|
+
message.parts.push(currentTextPart);
|
|
488
|
+
} else {
|
|
489
|
+
currentTextPart.text += value;
|
|
490
|
+
}
|
|
491
|
+
message.content += value;
|
|
492
|
+
execUpdate();
|
|
493
|
+
},
|
|
494
|
+
onReasoningPart(value) {
|
|
495
|
+
if (currentReasoningTextDetail == null) {
|
|
496
|
+
currentReasoningTextDetail = { type: "text", text: value };
|
|
497
|
+
if (currentReasoningPart != null) {
|
|
498
|
+
currentReasoningPart.details.push(currentReasoningTextDetail);
|
|
499
|
+
}
|
|
500
|
+
} else {
|
|
501
|
+
currentReasoningTextDetail.text += value;
|
|
502
|
+
}
|
|
503
|
+
if (currentReasoningPart == null) {
|
|
504
|
+
currentReasoningPart = {
|
|
505
|
+
type: "reasoning",
|
|
506
|
+
reasoning: value,
|
|
507
|
+
details: [currentReasoningTextDetail]
|
|
508
|
+
};
|
|
509
|
+
message.parts.push(currentReasoningPart);
|
|
510
|
+
} else {
|
|
511
|
+
currentReasoningPart.reasoning += value;
|
|
512
|
+
}
|
|
513
|
+
message.reasoning = (message.reasoning ?? "") + value;
|
|
514
|
+
execUpdate();
|
|
515
|
+
},
|
|
516
|
+
onReasoningSignaturePart(value) {
|
|
517
|
+
if (currentReasoningTextDetail != null) {
|
|
518
|
+
currentReasoningTextDetail.signature = value.signature;
|
|
519
|
+
}
|
|
520
|
+
},
|
|
521
|
+
onRedactedReasoningPart(value) {
|
|
522
|
+
if (currentReasoningPart == null) {
|
|
523
|
+
currentReasoningPart = {
|
|
524
|
+
type: "reasoning",
|
|
525
|
+
reasoning: "",
|
|
526
|
+
details: []
|
|
527
|
+
};
|
|
528
|
+
message.parts.push(currentReasoningPart);
|
|
529
|
+
}
|
|
530
|
+
currentReasoningPart.details.push({
|
|
531
|
+
type: "redacted",
|
|
532
|
+
data: value.data
|
|
533
|
+
});
|
|
534
|
+
currentReasoningTextDetail = void 0;
|
|
535
|
+
execUpdate();
|
|
536
|
+
},
|
|
537
|
+
onFilePart(value) {
|
|
538
|
+
message.parts.push({
|
|
539
|
+
type: "file",
|
|
540
|
+
mimeType: value.mimeType,
|
|
541
|
+
data: value.data
|
|
542
|
+
});
|
|
543
|
+
execUpdate();
|
|
544
|
+
},
|
|
545
|
+
onSourcePart(value) {
|
|
546
|
+
message.parts.push({
|
|
547
|
+
type: "source",
|
|
548
|
+
source: value
|
|
549
|
+
});
|
|
550
|
+
execUpdate();
|
|
551
|
+
},
|
|
552
|
+
onToolCallStreamingStartPart(value) {
|
|
553
|
+
if (message.toolInvocations == null) {
|
|
554
|
+
message.toolInvocations = [];
|
|
555
|
+
}
|
|
556
|
+
partialToolCalls[value.toolCallId] = {
|
|
557
|
+
text: "",
|
|
558
|
+
step,
|
|
559
|
+
toolName: value.toolName,
|
|
560
|
+
index: message.toolInvocations.length
|
|
561
|
+
};
|
|
562
|
+
const invocation = {
|
|
563
|
+
state: "partial-call",
|
|
564
|
+
step,
|
|
565
|
+
toolCallId: value.toolCallId,
|
|
566
|
+
toolName: value.toolName,
|
|
567
|
+
args: void 0
|
|
568
|
+
};
|
|
569
|
+
message.toolInvocations.push(invocation);
|
|
570
|
+
updateToolInvocationPart(value.toolCallId, invocation);
|
|
571
|
+
execUpdate();
|
|
572
|
+
},
|
|
573
|
+
onToolCallDeltaPart(value) {
|
|
574
|
+
const partialToolCall = partialToolCalls[value.toolCallId];
|
|
575
|
+
partialToolCall.text += value.argsTextDelta;
|
|
576
|
+
const { value: partialArgs } = uiUtils.parsePartialJson(partialToolCall.text);
|
|
577
|
+
const invocation = {
|
|
578
|
+
state: "partial-call",
|
|
579
|
+
step: partialToolCall.step,
|
|
580
|
+
toolCallId: value.toolCallId,
|
|
581
|
+
toolName: partialToolCall.toolName,
|
|
582
|
+
args: partialArgs
|
|
583
|
+
};
|
|
584
|
+
message.toolInvocations[partialToolCall.index] = invocation;
|
|
585
|
+
updateToolInvocationPart(value.toolCallId, invocation);
|
|
586
|
+
execUpdate();
|
|
587
|
+
},
|
|
588
|
+
async onToolCallPart(value) {
|
|
589
|
+
const invocation = {
|
|
590
|
+
state: "call",
|
|
591
|
+
step,
|
|
592
|
+
...value
|
|
593
|
+
};
|
|
594
|
+
if (partialToolCalls[value.toolCallId] != null) {
|
|
595
|
+
message.toolInvocations[partialToolCalls[value.toolCallId].index] = invocation;
|
|
596
|
+
} else {
|
|
597
|
+
if (message.toolInvocations == null) {
|
|
598
|
+
message.toolInvocations = [];
|
|
599
|
+
}
|
|
600
|
+
message.toolInvocations.push(invocation);
|
|
601
|
+
}
|
|
602
|
+
updateToolInvocationPart(value.toolCallId, invocation);
|
|
603
|
+
execUpdate();
|
|
604
|
+
if (onToolCall) {
|
|
605
|
+
const result = await onToolCall({ toolCall: value });
|
|
606
|
+
if (result != null) {
|
|
607
|
+
const invocation2 = {
|
|
608
|
+
state: "result",
|
|
609
|
+
step,
|
|
610
|
+
...value,
|
|
611
|
+
result
|
|
612
|
+
};
|
|
613
|
+
message.toolInvocations[message.toolInvocations.length - 1] = invocation2;
|
|
614
|
+
updateToolInvocationPart(value.toolCallId, invocation2);
|
|
615
|
+
execUpdate();
|
|
616
|
+
}
|
|
617
|
+
}
|
|
618
|
+
},
|
|
619
|
+
onToolResultPart(value) {
|
|
620
|
+
const toolInvocations = message.toolInvocations;
|
|
621
|
+
if (toolInvocations == null) {
|
|
622
|
+
throw new Error("tool_result must be preceded by a tool_call");
|
|
623
|
+
}
|
|
624
|
+
const toolInvocationIndex = toolInvocations.findIndex((invocation2) => invocation2.toolCallId === value.toolCallId);
|
|
625
|
+
if (toolInvocationIndex === -1) {
|
|
626
|
+
throw new Error("tool_result must be preceded by a tool_call with the same toolCallId");
|
|
627
|
+
}
|
|
628
|
+
const invocation = {
|
|
629
|
+
...toolInvocations[toolInvocationIndex],
|
|
630
|
+
state: "result",
|
|
631
|
+
...value
|
|
632
|
+
};
|
|
633
|
+
toolInvocations[toolInvocationIndex] = invocation;
|
|
634
|
+
updateToolInvocationPart(value.toolCallId, invocation);
|
|
635
|
+
execUpdate();
|
|
636
|
+
},
|
|
637
|
+
onDataPart(value) {
|
|
638
|
+
data.push(...value);
|
|
639
|
+
execUpdate();
|
|
640
|
+
},
|
|
641
|
+
onMessageAnnotationsPart(value) {
|
|
642
|
+
if (messageAnnotations == null) {
|
|
643
|
+
messageAnnotations = [...value];
|
|
644
|
+
} else {
|
|
645
|
+
messageAnnotations.push(...value);
|
|
646
|
+
}
|
|
647
|
+
execUpdate();
|
|
648
|
+
},
|
|
649
|
+
onFinishStepPart(value) {
|
|
650
|
+
step += 1;
|
|
651
|
+
currentTextPart = value.isContinued ? currentTextPart : void 0;
|
|
652
|
+
currentReasoningPart = void 0;
|
|
653
|
+
currentReasoningTextDetail = void 0;
|
|
654
|
+
},
|
|
655
|
+
onStartStepPart(value) {
|
|
656
|
+
if (!replaceLastMessage) {
|
|
657
|
+
message.id = value.messageId;
|
|
658
|
+
}
|
|
659
|
+
message.parts.push({ type: "step-start" });
|
|
660
|
+
execUpdate();
|
|
661
|
+
},
|
|
662
|
+
onFinishMessagePart(value) {
|
|
663
|
+
finishReason = value.finishReason;
|
|
664
|
+
if (value.usage != null) {
|
|
665
|
+
usage = value.usage;
|
|
666
|
+
}
|
|
667
|
+
},
|
|
668
|
+
onErrorPart(error) {
|
|
669
|
+
throw new Error(error);
|
|
670
|
+
}
|
|
393
671
|
});
|
|
672
|
+
onFinish?.({ message, finishReason, usage });
|
|
394
673
|
}
|
|
395
674
|
/**
|
|
396
|
-
*
|
|
397
|
-
* @
|
|
398
|
-
|
|
399
|
-
evals() {
|
|
400
|
-
return this.request(`/api/agents/${this.agentId}/evals/ci`);
|
|
401
|
-
}
|
|
402
|
-
/**
|
|
403
|
-
* Retrieves live evaluation results for the agent
|
|
404
|
-
* @returns Promise containing live agent evaluations
|
|
405
|
-
*/
|
|
406
|
-
liveEvals() {
|
|
407
|
-
return this.request(`/api/agents/${this.agentId}/evals/live`);
|
|
408
|
-
}
|
|
409
|
-
};
|
|
410
|
-
var Network = class extends BaseResource {
|
|
411
|
-
constructor(options, networkId) {
|
|
412
|
-
super(options);
|
|
413
|
-
this.networkId = networkId;
|
|
414
|
-
}
|
|
415
|
-
/**
|
|
416
|
-
* Retrieves details about the network
|
|
417
|
-
* @returns Promise containing network details
|
|
418
|
-
*/
|
|
419
|
-
details() {
|
|
420
|
-
return this.request(`/api/networks/${this.networkId}`);
|
|
421
|
-
}
|
|
422
|
-
/**
|
|
423
|
-
* Generates a response from the agent
|
|
424
|
-
* @param params - Generation parameters including prompt
|
|
425
|
-
* @returns Promise containing the generated response
|
|
675
|
+
* Streams a response from the agent
|
|
676
|
+
* @param params - Stream parameters including prompt
|
|
677
|
+
* @returns Promise containing the enhanced Response object with processDataStream method
|
|
426
678
|
*/
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
};
|
|
433
|
-
return this.request(`/api/networks/${this.networkId}/generate`, {
|
|
434
|
-
method: "POST",
|
|
435
|
-
body: processedParams
|
|
436
|
-
});
|
|
679
|
+
async stream(params) {
|
|
680
|
+
console.warn(
|
|
681
|
+
"Deprecation NOTICE:\nStream method will switch to use streamVNext implementation September 16th, 2025. Please use streamLegacy if you don't want to upgrade just yet."
|
|
682
|
+
);
|
|
683
|
+
return this.streamLegacy(params);
|
|
437
684
|
}
|
|
438
685
|
/**
|
|
439
686
|
* Streams a response from the agent
|
|
440
687
|
* @param params - Stream parameters including prompt
|
|
441
688
|
* @returns Promise containing the enhanced Response object with processDataStream method
|
|
442
689
|
*/
|
|
443
|
-
async
|
|
690
|
+
async streamLegacy(params) {
|
|
444
691
|
const processedParams = {
|
|
445
692
|
...params,
|
|
446
|
-
output: zodToJsonSchema(params.output),
|
|
447
|
-
experimental_output: zodToJsonSchema(params.experimental_output)
|
|
693
|
+
output: params.output ? zodToJsonSchema(params.output) : void 0,
|
|
694
|
+
experimental_output: params.experimental_output ? zodToJsonSchema(params.experimental_output) : void 0,
|
|
695
|
+
runtimeContext: parseClientRuntimeContext(params.runtimeContext),
|
|
696
|
+
clientTools: processClientTools(params.clientTools)
|
|
448
697
|
};
|
|
449
|
-
const
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
698
|
+
const { readable, writable } = new TransformStream();
|
|
699
|
+
const response = await this.processStreamResponse(processedParams, writable);
|
|
700
|
+
const streamResponse = new Response(readable, {
|
|
701
|
+
status: response.status,
|
|
702
|
+
statusText: response.statusText,
|
|
703
|
+
headers: response.headers
|
|
453
704
|
});
|
|
454
|
-
|
|
455
|
-
throw new Error("No response body");
|
|
456
|
-
}
|
|
457
|
-
response.processDataStream = async (options = {}) => {
|
|
705
|
+
streamResponse.processDataStream = async (options = {}) => {
|
|
458
706
|
await uiUtils.processDataStream({
|
|
459
|
-
stream:
|
|
707
|
+
stream: streamResponse.body,
|
|
460
708
|
...options
|
|
461
709
|
});
|
|
462
710
|
};
|
|
463
|
-
return
|
|
464
|
-
}
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
711
|
+
return streamResponse;
|
|
712
|
+
}
|
|
713
|
+
async processChatResponse_vNext({
|
|
714
|
+
stream,
|
|
715
|
+
update,
|
|
716
|
+
onToolCall,
|
|
717
|
+
onFinish,
|
|
718
|
+
getCurrentDate = () => /* @__PURE__ */ new Date(),
|
|
719
|
+
lastMessage
|
|
720
|
+
}) {
|
|
721
|
+
const replaceLastMessage = lastMessage?.role === "assistant";
|
|
722
|
+
let step = replaceLastMessage ? 1 + // find max step in existing tool invocations:
|
|
723
|
+
(lastMessage.toolInvocations?.reduce((max, toolInvocation) => {
|
|
724
|
+
return Math.max(max, toolInvocation.step ?? 0);
|
|
725
|
+
}, 0) ?? 0) : 0;
|
|
726
|
+
const message = replaceLastMessage ? structuredClone(lastMessage) : {
|
|
727
|
+
id: uuid.v4(),
|
|
728
|
+
createdAt: getCurrentDate(),
|
|
729
|
+
role: "assistant",
|
|
730
|
+
content: "",
|
|
731
|
+
parts: []
|
|
732
|
+
};
|
|
733
|
+
let currentTextPart = void 0;
|
|
734
|
+
let currentReasoningPart = void 0;
|
|
735
|
+
let currentReasoningTextDetail = void 0;
|
|
736
|
+
function updateToolInvocationPart(toolCallId, invocation) {
|
|
737
|
+
const part = message.parts.find(
|
|
738
|
+
(part2) => part2.type === "tool-invocation" && part2.toolInvocation.toolCallId === toolCallId
|
|
739
|
+
);
|
|
740
|
+
if (part != null) {
|
|
741
|
+
part.toolInvocation = invocation;
|
|
742
|
+
} else {
|
|
743
|
+
message.parts.push({
|
|
744
|
+
type: "tool-invocation",
|
|
745
|
+
toolInvocation: invocation
|
|
746
|
+
});
|
|
747
|
+
}
|
|
748
|
+
}
|
|
749
|
+
const data = [];
|
|
750
|
+
let messageAnnotations = replaceLastMessage ? lastMessage?.annotations : void 0;
|
|
751
|
+
const partialToolCalls = {};
|
|
752
|
+
let usage = {
|
|
753
|
+
completionTokens: NaN,
|
|
754
|
+
promptTokens: NaN,
|
|
755
|
+
totalTokens: NaN
|
|
756
|
+
};
|
|
757
|
+
let finishReason = "unknown";
|
|
758
|
+
function execUpdate() {
|
|
759
|
+
const copiedData = [...data];
|
|
760
|
+
if (messageAnnotations?.length) {
|
|
761
|
+
message.annotations = messageAnnotations;
|
|
762
|
+
}
|
|
763
|
+
const copiedMessage = {
|
|
764
|
+
// deep copy the message to ensure that deep changes (msg attachments) are updated
|
|
765
|
+
// with SolidJS. SolidJS uses referential integration of sub-objects to detect changes.
|
|
766
|
+
...structuredClone(message),
|
|
767
|
+
// add a revision id to ensure that the message is updated with SWR. SWR uses a
|
|
768
|
+
// hashing approach by default to detect changes, but it only works for shallow
|
|
769
|
+
// changes. This is why we need to add a revision id to ensure that the message
|
|
770
|
+
// is updated with SWR (without it, the changes get stuck in SWR and are not
|
|
771
|
+
// forwarded to rendering):
|
|
772
|
+
revisionId: uuid.v4()
|
|
773
|
+
};
|
|
774
|
+
update({
|
|
775
|
+
message: copiedMessage,
|
|
776
|
+
data: copiedData,
|
|
777
|
+
replaceLastMessage
|
|
778
|
+
});
|
|
779
|
+
}
|
|
780
|
+
await processMastraStream({
|
|
781
|
+
stream,
|
|
782
|
+
// TODO: casting as any here because the stream types were all typed as any before in core.
|
|
783
|
+
// but this is completely wrong and this fn is probably broken. Remove ":any" and you'll see a bunch of type errors
|
|
784
|
+
onChunk: async (chunk) => {
|
|
785
|
+
switch (chunk.type) {
|
|
786
|
+
case "step-start": {
|
|
787
|
+
if (!replaceLastMessage) {
|
|
788
|
+
message.id = chunk.payload.messageId;
|
|
789
|
+
}
|
|
790
|
+
message.parts.push({ type: "step-start" });
|
|
791
|
+
execUpdate();
|
|
792
|
+
break;
|
|
793
|
+
}
|
|
794
|
+
case "text-delta": {
|
|
795
|
+
if (currentTextPart == null) {
|
|
796
|
+
currentTextPart = {
|
|
797
|
+
type: "text",
|
|
798
|
+
text: chunk.payload.text
|
|
799
|
+
};
|
|
800
|
+
message.parts.push(currentTextPart);
|
|
801
|
+
} else {
|
|
802
|
+
currentTextPart.text += chunk.payload.text;
|
|
803
|
+
}
|
|
804
|
+
message.content += chunk.payload.text;
|
|
805
|
+
execUpdate();
|
|
806
|
+
break;
|
|
807
|
+
}
|
|
808
|
+
case "reasoning-delta": {
|
|
809
|
+
if (currentReasoningTextDetail == null) {
|
|
810
|
+
currentReasoningTextDetail = { type: "text", text: chunk.payload.text };
|
|
811
|
+
if (currentReasoningPart != null) {
|
|
812
|
+
currentReasoningPart.details.push(currentReasoningTextDetail);
|
|
813
|
+
}
|
|
814
|
+
} else {
|
|
815
|
+
currentReasoningTextDetail.text += chunk.payload.text;
|
|
816
|
+
}
|
|
817
|
+
if (currentReasoningPart == null) {
|
|
818
|
+
currentReasoningPart = {
|
|
819
|
+
type: "reasoning",
|
|
820
|
+
reasoning: chunk.payload.text,
|
|
821
|
+
details: [currentReasoningTextDetail]
|
|
822
|
+
};
|
|
823
|
+
message.parts.push(currentReasoningPart);
|
|
824
|
+
} else {
|
|
825
|
+
currentReasoningPart.reasoning += chunk.payload.text;
|
|
826
|
+
}
|
|
827
|
+
message.reasoning = (message.reasoning ?? "") + chunk.payload.text;
|
|
828
|
+
execUpdate();
|
|
829
|
+
break;
|
|
830
|
+
}
|
|
831
|
+
case "file": {
|
|
832
|
+
message.parts.push({
|
|
833
|
+
type: "file",
|
|
834
|
+
mimeType: chunk.payload.mimeType,
|
|
835
|
+
data: chunk.payload.data
|
|
836
|
+
});
|
|
837
|
+
execUpdate();
|
|
838
|
+
break;
|
|
839
|
+
}
|
|
840
|
+
case "source": {
|
|
841
|
+
message.parts.push({
|
|
842
|
+
type: "source",
|
|
843
|
+
source: chunk.payload.source
|
|
844
|
+
});
|
|
845
|
+
execUpdate();
|
|
846
|
+
break;
|
|
847
|
+
}
|
|
848
|
+
case "tool-call": {
|
|
849
|
+
const invocation = {
|
|
850
|
+
state: "call",
|
|
851
|
+
step,
|
|
852
|
+
...chunk.payload
|
|
853
|
+
};
|
|
854
|
+
if (partialToolCalls[chunk.payload.toolCallId] != null) {
|
|
855
|
+
message.toolInvocations[partialToolCalls[chunk.payload.toolCallId].index] = invocation;
|
|
856
|
+
} else {
|
|
857
|
+
if (message.toolInvocations == null) {
|
|
858
|
+
message.toolInvocations = [];
|
|
859
|
+
}
|
|
860
|
+
message.toolInvocations.push(invocation);
|
|
861
|
+
}
|
|
862
|
+
updateToolInvocationPart(chunk.payload.toolCallId, invocation);
|
|
863
|
+
execUpdate();
|
|
864
|
+
if (onToolCall) {
|
|
865
|
+
const result = await onToolCall({ toolCall: chunk.payload });
|
|
866
|
+
if (result != null) {
|
|
867
|
+
const invocation2 = {
|
|
868
|
+
state: "result",
|
|
869
|
+
step,
|
|
870
|
+
...chunk.payload,
|
|
871
|
+
result
|
|
872
|
+
};
|
|
873
|
+
message.toolInvocations[message.toolInvocations.length - 1] = invocation2;
|
|
874
|
+
updateToolInvocationPart(chunk.payload.toolCallId, invocation2);
|
|
875
|
+
execUpdate();
|
|
876
|
+
}
|
|
877
|
+
}
|
|
878
|
+
}
|
|
879
|
+
case "tool-call-input-streaming-start": {
|
|
880
|
+
if (message.toolInvocations == null) {
|
|
881
|
+
message.toolInvocations = [];
|
|
882
|
+
}
|
|
883
|
+
partialToolCalls[chunk.payload.toolCallId] = {
|
|
884
|
+
text: "",
|
|
885
|
+
step,
|
|
886
|
+
toolName: chunk.payload.toolName,
|
|
887
|
+
index: message.toolInvocations.length
|
|
888
|
+
};
|
|
889
|
+
const invocation = {
|
|
890
|
+
state: "partial-call",
|
|
891
|
+
step,
|
|
892
|
+
toolCallId: chunk.payload.toolCallId,
|
|
893
|
+
toolName: chunk.payload.toolName,
|
|
894
|
+
args: chunk.payload.args
|
|
895
|
+
};
|
|
896
|
+
message.toolInvocations.push(invocation);
|
|
897
|
+
updateToolInvocationPart(chunk.payload.toolCallId, invocation);
|
|
898
|
+
execUpdate();
|
|
899
|
+
break;
|
|
900
|
+
}
|
|
901
|
+
case "tool-call-delta": {
|
|
902
|
+
const partialToolCall = partialToolCalls[chunk.payload.toolCallId];
|
|
903
|
+
partialToolCall.text += chunk.payload.argsTextDelta;
|
|
904
|
+
const { value: partialArgs } = uiUtils.parsePartialJson(partialToolCall.text);
|
|
905
|
+
const invocation = {
|
|
906
|
+
state: "partial-call",
|
|
907
|
+
step: partialToolCall.step,
|
|
908
|
+
toolCallId: chunk.payload.toolCallId,
|
|
909
|
+
toolName: partialToolCall.toolName,
|
|
910
|
+
args: partialArgs
|
|
911
|
+
};
|
|
912
|
+
message.toolInvocations[partialToolCall.index] = invocation;
|
|
913
|
+
updateToolInvocationPart(chunk.payload.toolCallId, invocation);
|
|
914
|
+
execUpdate();
|
|
915
|
+
break;
|
|
916
|
+
}
|
|
917
|
+
case "tool-result": {
|
|
918
|
+
const toolInvocations = message.toolInvocations;
|
|
919
|
+
if (toolInvocations == null) {
|
|
920
|
+
throw new Error("tool_result must be preceded by a tool_call");
|
|
921
|
+
}
|
|
922
|
+
const toolInvocationIndex = toolInvocations.findIndex(
|
|
923
|
+
(invocation2) => invocation2.toolCallId === chunk.payload.toolCallId
|
|
924
|
+
);
|
|
925
|
+
if (toolInvocationIndex === -1) {
|
|
926
|
+
throw new Error("tool_result must be preceded by a tool_call with the same toolCallId");
|
|
927
|
+
}
|
|
928
|
+
const invocation = {
|
|
929
|
+
...toolInvocations[toolInvocationIndex],
|
|
930
|
+
state: "result",
|
|
931
|
+
...chunk.payload
|
|
932
|
+
};
|
|
933
|
+
toolInvocations[toolInvocationIndex] = invocation;
|
|
934
|
+
updateToolInvocationPart(chunk.payload.toolCallId, invocation);
|
|
935
|
+
execUpdate();
|
|
936
|
+
break;
|
|
937
|
+
}
|
|
938
|
+
case "error": {
|
|
939
|
+
throw new Error(chunk.payload.error);
|
|
940
|
+
}
|
|
941
|
+
case "data": {
|
|
942
|
+
data.push(...chunk.payload.data);
|
|
943
|
+
execUpdate();
|
|
944
|
+
break;
|
|
945
|
+
}
|
|
946
|
+
case "step-finish": {
|
|
947
|
+
step += 1;
|
|
948
|
+
currentTextPart = chunk.payload.stepResult.isContinued ? currentTextPart : void 0;
|
|
949
|
+
currentReasoningPart = void 0;
|
|
950
|
+
currentReasoningTextDetail = void 0;
|
|
951
|
+
execUpdate();
|
|
952
|
+
break;
|
|
953
|
+
}
|
|
954
|
+
case "finish": {
|
|
955
|
+
finishReason = chunk.payload.stepResult.reason;
|
|
956
|
+
if (chunk.payload.usage != null) {
|
|
957
|
+
usage = chunk.payload.usage;
|
|
958
|
+
}
|
|
959
|
+
break;
|
|
960
|
+
}
|
|
961
|
+
}
|
|
962
|
+
}
|
|
963
|
+
});
|
|
964
|
+
onFinish?.({ message, finishReason, usage });
|
|
965
|
+
}
|
|
966
|
+
async processStreamResponse_vNext(processedParams, writable) {
|
|
967
|
+
const response = await this.request(`/api/agents/${this.agentId}/stream/vnext`, {
|
|
968
|
+
method: "POST",
|
|
969
|
+
body: processedParams,
|
|
970
|
+
stream: true
|
|
971
|
+
});
|
|
972
|
+
if (!response.body) {
|
|
973
|
+
throw new Error("No response body");
|
|
974
|
+
}
|
|
975
|
+
try {
|
|
976
|
+
let toolCalls = [];
|
|
977
|
+
let messages = [];
|
|
978
|
+
const [streamForWritable, streamForProcessing] = response.body.tee();
|
|
979
|
+
streamForWritable.pipeTo(
|
|
980
|
+
new WritableStream({
|
|
981
|
+
async write(chunk) {
|
|
982
|
+
try {
|
|
983
|
+
const text = new TextDecoder().decode(chunk);
|
|
984
|
+
if (text.includes("[DONE]")) {
|
|
985
|
+
return;
|
|
986
|
+
}
|
|
987
|
+
} catch {
|
|
988
|
+
}
|
|
989
|
+
const writer = writable.getWriter();
|
|
990
|
+
try {
|
|
991
|
+
await writer.write(chunk);
|
|
992
|
+
} finally {
|
|
993
|
+
writer.releaseLock();
|
|
994
|
+
}
|
|
995
|
+
}
|
|
996
|
+
}),
|
|
997
|
+
{
|
|
998
|
+
preventClose: true
|
|
999
|
+
}
|
|
1000
|
+
).catch((error) => {
|
|
1001
|
+
console.error("Error piping to writable stream:", error);
|
|
1002
|
+
});
|
|
1003
|
+
this.processChatResponse_vNext({
|
|
1004
|
+
stream: streamForProcessing,
|
|
1005
|
+
update: ({ message }) => {
|
|
1006
|
+
const existingIndex = messages.findIndex((m) => m.id === message.id);
|
|
1007
|
+
if (existingIndex !== -1) {
|
|
1008
|
+
messages[existingIndex] = message;
|
|
1009
|
+
} else {
|
|
1010
|
+
messages.push(message);
|
|
1011
|
+
}
|
|
1012
|
+
},
|
|
1013
|
+
onFinish: async ({ finishReason, message }) => {
|
|
1014
|
+
if (finishReason === "tool-calls") {
|
|
1015
|
+
const toolCall = [...message?.parts ?? []].reverse().find((part) => part.type === "tool-invocation")?.toolInvocation;
|
|
1016
|
+
if (toolCall) {
|
|
1017
|
+
toolCalls.push(toolCall);
|
|
1018
|
+
}
|
|
1019
|
+
for (const toolCall2 of toolCalls) {
|
|
1020
|
+
const clientTool = processedParams.clientTools?.[toolCall2.toolName];
|
|
1021
|
+
if (clientTool && clientTool.execute) {
|
|
1022
|
+
const result = await clientTool.execute(
|
|
1023
|
+
{
|
|
1024
|
+
context: toolCall2?.args,
|
|
1025
|
+
runId: processedParams.runId,
|
|
1026
|
+
resourceId: processedParams.resourceId,
|
|
1027
|
+
threadId: processedParams.threadId,
|
|
1028
|
+
runtimeContext: processedParams.runtimeContext,
|
|
1029
|
+
// TODO: Pass proper tracing context when client-js supports tracing
|
|
1030
|
+
tracingContext: { currentSpan: void 0 }
|
|
1031
|
+
},
|
|
1032
|
+
{
|
|
1033
|
+
messages: response.messages,
|
|
1034
|
+
toolCallId: toolCall2?.toolCallId
|
|
1035
|
+
}
|
|
1036
|
+
);
|
|
1037
|
+
const lastMessageRaw = messages[messages.length - 1];
|
|
1038
|
+
const lastMessage = lastMessageRaw != null ? JSON.parse(JSON.stringify(lastMessageRaw)) : void 0;
|
|
1039
|
+
const toolInvocationPart = lastMessage?.parts?.find(
|
|
1040
|
+
(part) => part.type === "tool-invocation" && part.toolInvocation?.toolCallId === toolCall2.toolCallId
|
|
1041
|
+
);
|
|
1042
|
+
if (toolInvocationPart) {
|
|
1043
|
+
toolInvocationPart.toolInvocation = {
|
|
1044
|
+
...toolInvocationPart.toolInvocation,
|
|
1045
|
+
state: "result",
|
|
1046
|
+
result
|
|
1047
|
+
};
|
|
1048
|
+
}
|
|
1049
|
+
const toolInvocation = lastMessage?.toolInvocations?.find(
|
|
1050
|
+
(toolInvocation2) => toolInvocation2.toolCallId === toolCall2.toolCallId
|
|
1051
|
+
);
|
|
1052
|
+
if (toolInvocation) {
|
|
1053
|
+
toolInvocation.state = "result";
|
|
1054
|
+
toolInvocation.result = result;
|
|
1055
|
+
}
|
|
1056
|
+
const originalMessages = processedParams.messages;
|
|
1057
|
+
const messageArray = Array.isArray(originalMessages) ? originalMessages : [originalMessages];
|
|
1058
|
+
const updatedMessages = lastMessage != null ? [...messageArray, ...messages.filter((m) => m.id !== lastMessage.id), lastMessage] : [...messageArray, ...messages];
|
|
1059
|
+
this.processStreamResponse_vNext(
|
|
1060
|
+
{
|
|
1061
|
+
...processedParams,
|
|
1062
|
+
messages: updatedMessages
|
|
1063
|
+
},
|
|
1064
|
+
writable
|
|
1065
|
+
).catch((error) => {
|
|
1066
|
+
console.error("Error processing stream response:", error);
|
|
1067
|
+
});
|
|
1068
|
+
}
|
|
1069
|
+
}
|
|
1070
|
+
} else {
|
|
1071
|
+
setTimeout(() => {
|
|
1072
|
+
writable.close();
|
|
1073
|
+
}, 0);
|
|
1074
|
+
}
|
|
1075
|
+
},
|
|
1076
|
+
lastMessage: void 0
|
|
1077
|
+
}).catch((error) => {
|
|
1078
|
+
console.error("Error processing stream response:", error);
|
|
1079
|
+
});
|
|
1080
|
+
} catch (error) {
|
|
1081
|
+
console.error("Error processing stream response:", error);
|
|
1082
|
+
}
|
|
1083
|
+
return response;
|
|
1084
|
+
}
|
|
1085
|
+
async network(params) {
|
|
1086
|
+
const response = await this.request(`/api/agents/${this.agentId}/network`, {
|
|
1087
|
+
method: "POST",
|
|
1088
|
+
body: params,
|
|
1089
|
+
stream: true
|
|
1090
|
+
});
|
|
1091
|
+
if (!response.body) {
|
|
1092
|
+
throw new Error("No response body");
|
|
1093
|
+
}
|
|
1094
|
+
const streamResponse = new Response(response.body, {
|
|
1095
|
+
status: response.status,
|
|
1096
|
+
statusText: response.statusText,
|
|
1097
|
+
headers: response.headers
|
|
1098
|
+
});
|
|
1099
|
+
streamResponse.processDataStream = async ({
|
|
1100
|
+
onChunk
|
|
1101
|
+
}) => {
|
|
1102
|
+
await processMastraNetworkStream({
|
|
1103
|
+
stream: streamResponse.body,
|
|
1104
|
+
onChunk
|
|
1105
|
+
});
|
|
1106
|
+
};
|
|
1107
|
+
return streamResponse;
|
|
1108
|
+
}
|
|
1109
|
+
async streamVNext(params) {
|
|
1110
|
+
const processedParams = {
|
|
1111
|
+
...params,
|
|
1112
|
+
output: params.output ? zodToJsonSchema(params.output) : void 0,
|
|
1113
|
+
runtimeContext: parseClientRuntimeContext(params.runtimeContext),
|
|
1114
|
+
clientTools: processClientTools(params.clientTools),
|
|
1115
|
+
structuredOutput: params.structuredOutput ? {
|
|
1116
|
+
...params.structuredOutput,
|
|
1117
|
+
schema: zodToJsonSchema(params.structuredOutput.schema)
|
|
1118
|
+
} : void 0
|
|
1119
|
+
};
|
|
1120
|
+
const { readable, writable } = new TransformStream();
|
|
1121
|
+
const response = await this.processStreamResponse_vNext(processedParams, writable);
|
|
1122
|
+
const streamResponse = new Response(readable, {
|
|
1123
|
+
status: response.status,
|
|
1124
|
+
statusText: response.statusText,
|
|
1125
|
+
headers: response.headers
|
|
1126
|
+
});
|
|
1127
|
+
streamResponse.processDataStream = async ({
|
|
1128
|
+
onChunk
|
|
1129
|
+
}) => {
|
|
1130
|
+
await processMastraStream({
|
|
1131
|
+
stream: streamResponse.body,
|
|
1132
|
+
onChunk
|
|
1133
|
+
});
|
|
1134
|
+
};
|
|
1135
|
+
return streamResponse;
|
|
1136
|
+
}
|
|
1137
|
+
/**
|
|
1138
|
+
* Processes the stream response and handles tool calls
|
|
1139
|
+
*/
|
|
1140
|
+
async processStreamResponse(processedParams, writable) {
|
|
1141
|
+
const response = await this.request(`/api/agents/${this.agentId}/stream-legacy`, {
|
|
1142
|
+
method: "POST",
|
|
1143
|
+
body: processedParams,
|
|
1144
|
+
stream: true
|
|
1145
|
+
});
|
|
1146
|
+
if (!response.body) {
|
|
1147
|
+
throw new Error("No response body");
|
|
1148
|
+
}
|
|
1149
|
+
try {
|
|
1150
|
+
let toolCalls = [];
|
|
1151
|
+
let messages = [];
|
|
1152
|
+
const [streamForWritable, streamForProcessing] = response.body.tee();
|
|
1153
|
+
streamForWritable.pipeTo(writable, {
|
|
1154
|
+
preventClose: true
|
|
1155
|
+
}).catch((error) => {
|
|
1156
|
+
console.error("Error piping to writable stream:", error);
|
|
1157
|
+
});
|
|
1158
|
+
this.processChatResponse({
|
|
1159
|
+
stream: streamForProcessing,
|
|
1160
|
+
update: ({ message }) => {
|
|
1161
|
+
const existingIndex = messages.findIndex((m) => m.id === message.id);
|
|
1162
|
+
if (existingIndex !== -1) {
|
|
1163
|
+
messages[existingIndex] = message;
|
|
1164
|
+
} else {
|
|
1165
|
+
messages.push(message);
|
|
1166
|
+
}
|
|
1167
|
+
},
|
|
1168
|
+
onFinish: async ({ finishReason, message }) => {
|
|
1169
|
+
if (finishReason === "tool-calls") {
|
|
1170
|
+
const toolCall = [...message?.parts ?? []].reverse().find((part) => part.type === "tool-invocation")?.toolInvocation;
|
|
1171
|
+
if (toolCall) {
|
|
1172
|
+
toolCalls.push(toolCall);
|
|
1173
|
+
}
|
|
1174
|
+
for (const toolCall2 of toolCalls) {
|
|
1175
|
+
const clientTool = processedParams.clientTools?.[toolCall2.toolName];
|
|
1176
|
+
if (clientTool && clientTool.execute) {
|
|
1177
|
+
const result = await clientTool.execute(
|
|
1178
|
+
{
|
|
1179
|
+
context: toolCall2?.args,
|
|
1180
|
+
runId: processedParams.runId,
|
|
1181
|
+
resourceId: processedParams.resourceId,
|
|
1182
|
+
threadId: processedParams.threadId,
|
|
1183
|
+
runtimeContext: processedParams.runtimeContext,
|
|
1184
|
+
// TODO: Pass proper tracing context when client-js supports tracing
|
|
1185
|
+
tracingContext: { currentSpan: void 0 }
|
|
1186
|
+
},
|
|
1187
|
+
{
|
|
1188
|
+
messages: response.messages,
|
|
1189
|
+
toolCallId: toolCall2?.toolCallId
|
|
1190
|
+
}
|
|
1191
|
+
);
|
|
1192
|
+
const lastMessage = JSON.parse(JSON.stringify(messages[messages.length - 1]));
|
|
1193
|
+
const toolInvocationPart = lastMessage?.parts?.find(
|
|
1194
|
+
(part) => part.type === "tool-invocation" && part.toolInvocation?.toolCallId === toolCall2.toolCallId
|
|
1195
|
+
);
|
|
1196
|
+
if (toolInvocationPart) {
|
|
1197
|
+
toolInvocationPart.toolInvocation = {
|
|
1198
|
+
...toolInvocationPart.toolInvocation,
|
|
1199
|
+
state: "result",
|
|
1200
|
+
result
|
|
1201
|
+
};
|
|
1202
|
+
}
|
|
1203
|
+
const toolInvocation = lastMessage?.toolInvocations?.find(
|
|
1204
|
+
(toolInvocation2) => toolInvocation2.toolCallId === toolCall2.toolCallId
|
|
1205
|
+
);
|
|
1206
|
+
if (toolInvocation) {
|
|
1207
|
+
toolInvocation.state = "result";
|
|
1208
|
+
toolInvocation.result = result;
|
|
1209
|
+
}
|
|
1210
|
+
const writer = writable.getWriter();
|
|
1211
|
+
try {
|
|
1212
|
+
await writer.write(
|
|
1213
|
+
new TextEncoder().encode(
|
|
1214
|
+
"a:" + JSON.stringify({
|
|
1215
|
+
toolCallId: toolCall2.toolCallId,
|
|
1216
|
+
result
|
|
1217
|
+
}) + "\n"
|
|
1218
|
+
)
|
|
1219
|
+
);
|
|
1220
|
+
} finally {
|
|
1221
|
+
writer.releaseLock();
|
|
1222
|
+
}
|
|
1223
|
+
const originalMessages = processedParams.messages;
|
|
1224
|
+
const messageArray = Array.isArray(originalMessages) ? originalMessages : [originalMessages];
|
|
1225
|
+
this.processStreamResponse(
|
|
1226
|
+
{
|
|
1227
|
+
...processedParams,
|
|
1228
|
+
messages: [...messageArray, ...messages.filter((m) => m.id !== lastMessage.id), lastMessage]
|
|
1229
|
+
},
|
|
1230
|
+
writable
|
|
1231
|
+
).catch((error) => {
|
|
1232
|
+
console.error("Error processing stream response:", error);
|
|
1233
|
+
});
|
|
1234
|
+
}
|
|
1235
|
+
}
|
|
1236
|
+
} else {
|
|
1237
|
+
setTimeout(() => {
|
|
1238
|
+
writable.close();
|
|
1239
|
+
}, 0);
|
|
1240
|
+
}
|
|
1241
|
+
},
|
|
1242
|
+
lastMessage: void 0
|
|
1243
|
+
}).catch((error) => {
|
|
1244
|
+
console.error("Error processing stream response:", error);
|
|
1245
|
+
});
|
|
1246
|
+
} catch (error) {
|
|
1247
|
+
console.error("Error processing stream response:", error);
|
|
1248
|
+
}
|
|
1249
|
+
return response;
|
|
1250
|
+
}
|
|
1251
|
+
/**
|
|
1252
|
+
* Gets details about a specific tool available to the agent
|
|
1253
|
+
* @param toolId - ID of the tool to retrieve
|
|
1254
|
+
* @returns Promise containing tool details
|
|
1255
|
+
*/
|
|
1256
|
+
getTool(toolId) {
|
|
1257
|
+
return this.request(`/api/agents/${this.agentId}/tools/${toolId}`);
|
|
1258
|
+
}
|
|
1259
|
+
/**
|
|
1260
|
+
* Executes a tool for the agent
|
|
1261
|
+
* @param toolId - ID of the tool to execute
|
|
1262
|
+
* @param params - Parameters required for tool execution
|
|
1263
|
+
* @returns Promise containing the tool execution results
|
|
1264
|
+
*/
|
|
1265
|
+
executeTool(toolId, params) {
|
|
1266
|
+
const body = {
|
|
1267
|
+
data: params.data,
|
|
1268
|
+
runtimeContext: params.runtimeContext ? Object.fromEntries(params.runtimeContext.entries()) : void 0
|
|
1269
|
+
};
|
|
1270
|
+
return this.request(`/api/agents/${this.agentId}/tools/${toolId}/execute`, {
|
|
1271
|
+
method: "POST",
|
|
1272
|
+
body
|
|
1273
|
+
});
|
|
1274
|
+
}
|
|
1275
|
+
/**
|
|
1276
|
+
* Retrieves evaluation results for the agent
|
|
1277
|
+
* @returns Promise containing agent evaluations
|
|
1278
|
+
*/
|
|
1279
|
+
evals() {
|
|
1280
|
+
return this.request(`/api/agents/${this.agentId}/evals/ci`);
|
|
1281
|
+
}
|
|
1282
|
+
/**
|
|
1283
|
+
* Retrieves live evaluation results for the agent
|
|
1284
|
+
* @returns Promise containing live agent evaluations
|
|
1285
|
+
*/
|
|
1286
|
+
liveEvals() {
|
|
1287
|
+
return this.request(`/api/agents/${this.agentId}/evals/live`);
|
|
1288
|
+
}
|
|
1289
|
+
/**
|
|
1290
|
+
* Updates the model for the agent
|
|
1291
|
+
* @param params - Parameters for updating the model
|
|
1292
|
+
* @returns Promise containing the updated model
|
|
1293
|
+
*/
|
|
1294
|
+
updateModel(params) {
|
|
1295
|
+
return this.request(`/api/agents/${this.agentId}/model`, {
|
|
1296
|
+
method: "POST",
|
|
1297
|
+
body: params
|
|
1298
|
+
});
|
|
1299
|
+
}
|
|
1300
|
+
};
|
|
1301
|
+
var Network = class extends BaseResource {
|
|
1302
|
+
constructor(options, networkId) {
|
|
1303
|
+
super(options);
|
|
1304
|
+
this.networkId = networkId;
|
|
1305
|
+
}
|
|
1306
|
+
/**
|
|
1307
|
+
* Retrieves details about the network
|
|
1308
|
+
* @returns Promise containing network details
|
|
1309
|
+
*/
|
|
1310
|
+
details() {
|
|
1311
|
+
return this.request(`/api/networks/${this.networkId}`);
|
|
1312
|
+
}
|
|
1313
|
+
/**
|
|
1314
|
+
* Generates a response from the agent
|
|
1315
|
+
* @param params - Generation parameters including prompt
|
|
1316
|
+
* @returns Promise containing the generated response
|
|
1317
|
+
*/
|
|
1318
|
+
generate(params) {
|
|
1319
|
+
const processedParams = {
|
|
1320
|
+
...params,
|
|
1321
|
+
output: zodToJsonSchema(params.output),
|
|
1322
|
+
experimental_output: zodToJsonSchema(params.experimental_output)
|
|
1323
|
+
};
|
|
1324
|
+
return this.request(`/api/networks/${this.networkId}/generate`, {
|
|
1325
|
+
method: "POST",
|
|
1326
|
+
body: processedParams
|
|
1327
|
+
});
|
|
1328
|
+
}
|
|
1329
|
+
/**
|
|
1330
|
+
* Streams a response from the agent
|
|
1331
|
+
* @param params - Stream parameters including prompt
|
|
1332
|
+
* @returns Promise containing the enhanced Response object with processDataStream method
|
|
1333
|
+
*/
|
|
1334
|
+
async stream(params) {
|
|
1335
|
+
const processedParams = {
|
|
1336
|
+
...params,
|
|
1337
|
+
output: zodToJsonSchema(params.output),
|
|
1338
|
+
experimental_output: zodToJsonSchema(params.experimental_output)
|
|
1339
|
+
};
|
|
1340
|
+
const response = await this.request(`/api/networks/${this.networkId}/stream`, {
|
|
1341
|
+
method: "POST",
|
|
1342
|
+
body: processedParams,
|
|
1343
|
+
stream: true
|
|
1344
|
+
});
|
|
1345
|
+
if (!response.body) {
|
|
1346
|
+
throw new Error("No response body");
|
|
1347
|
+
}
|
|
1348
|
+
response.processDataStream = async (options = {}) => {
|
|
1349
|
+
await uiUtils.processDataStream({
|
|
1350
|
+
stream: response.body,
|
|
1351
|
+
...options
|
|
1352
|
+
});
|
|
1353
|
+
};
|
|
1354
|
+
return response;
|
|
1355
|
+
}
|
|
1356
|
+
};
|
|
1357
|
+
|
|
1358
|
+
// src/resources/memory-thread.ts
|
|
1359
|
+
var MemoryThread = class extends BaseResource {
|
|
1360
|
+
constructor(options, threadId, agentId) {
|
|
1361
|
+
super(options);
|
|
1362
|
+
this.threadId = threadId;
|
|
472
1363
|
this.agentId = agentId;
|
|
473
1364
|
}
|
|
474
1365
|
/**
|
|
@@ -510,6 +1401,36 @@ var MemoryThread = class extends BaseResource {
|
|
|
510
1401
|
});
|
|
511
1402
|
return this.request(`/api/memory/threads/${this.threadId}/messages?${query.toString()}`);
|
|
512
1403
|
}
|
|
1404
|
+
/**
|
|
1405
|
+
* Retrieves paginated messages associated with the thread with advanced filtering and selection options
|
|
1406
|
+
* @param params - Pagination parameters including selectBy criteria, page, perPage, date ranges, and message inclusion options
|
|
1407
|
+
* @returns Promise containing paginated thread messages with pagination metadata (total, page, perPage, hasMore)
|
|
1408
|
+
*/
|
|
1409
|
+
getMessagesPaginated({
|
|
1410
|
+
selectBy,
|
|
1411
|
+
...rest
|
|
1412
|
+
}) {
|
|
1413
|
+
const query = new URLSearchParams({
|
|
1414
|
+
...rest,
|
|
1415
|
+
...selectBy ? { selectBy: JSON.stringify(selectBy) } : {}
|
|
1416
|
+
});
|
|
1417
|
+
return this.request(`/api/memory/threads/${this.threadId}/messages/paginated?${query.toString()}`);
|
|
1418
|
+
}
|
|
1419
|
+
/**
|
|
1420
|
+
* Deletes one or more messages from the thread
|
|
1421
|
+
* @param messageIds - Can be a single message ID (string), array of message IDs,
|
|
1422
|
+
* message object with id property, or array of message objects
|
|
1423
|
+
* @returns Promise containing deletion result
|
|
1424
|
+
*/
|
|
1425
|
+
deleteMessages(messageIds) {
|
|
1426
|
+
const query = new URLSearchParams({
|
|
1427
|
+
agentId: this.agentId
|
|
1428
|
+
});
|
|
1429
|
+
return this.request(`/api/memory/messages/delete?${query.toString()}`, {
|
|
1430
|
+
method: "POST",
|
|
1431
|
+
body: { messageIds }
|
|
1432
|
+
});
|
|
1433
|
+
}
|
|
513
1434
|
};
|
|
514
1435
|
|
|
515
1436
|
// src/resources/vector.ts
|
|
@@ -578,24 +1499,24 @@ var Vector = class extends BaseResource {
|
|
|
578
1499
|
}
|
|
579
1500
|
};
|
|
580
1501
|
|
|
581
|
-
// src/resources/workflow.ts
|
|
1502
|
+
// src/resources/legacy-workflow.ts
|
|
582
1503
|
var RECORD_SEPARATOR = "";
|
|
583
|
-
var
|
|
1504
|
+
var LegacyWorkflow = class extends BaseResource {
|
|
584
1505
|
constructor(options, workflowId) {
|
|
585
1506
|
super(options);
|
|
586
1507
|
this.workflowId = workflowId;
|
|
587
1508
|
}
|
|
588
1509
|
/**
|
|
589
|
-
* Retrieves details about the workflow
|
|
590
|
-
* @returns Promise containing workflow details including steps and graphs
|
|
1510
|
+
* Retrieves details about the legacy workflow
|
|
1511
|
+
* @returns Promise containing legacy workflow details including steps and graphs
|
|
591
1512
|
*/
|
|
592
1513
|
details() {
|
|
593
|
-
return this.request(`/api/workflows/${this.workflowId}`);
|
|
1514
|
+
return this.request(`/api/workflows/legacy/${this.workflowId}`);
|
|
594
1515
|
}
|
|
595
1516
|
/**
|
|
596
|
-
* Retrieves all runs for a workflow
|
|
1517
|
+
* Retrieves all runs for a legacy workflow
|
|
597
1518
|
* @param params - Parameters for filtering runs
|
|
598
|
-
* @returns Promise containing workflow runs array
|
|
1519
|
+
* @returns Promise containing legacy workflow runs array
|
|
599
1520
|
*/
|
|
600
1521
|
runs(params) {
|
|
601
1522
|
const searchParams = new URLSearchParams();
|
|
@@ -615,60 +1536,48 @@ var Workflow = class extends BaseResource {
|
|
|
615
1536
|
searchParams.set("resourceId", params.resourceId);
|
|
616
1537
|
}
|
|
617
1538
|
if (searchParams.size) {
|
|
618
|
-
return this.request(`/api/workflows/${this.workflowId}/runs?${searchParams}`);
|
|
1539
|
+
return this.request(`/api/workflows/legacy/${this.workflowId}/runs?${searchParams}`);
|
|
619
1540
|
} else {
|
|
620
|
-
return this.request(`/api/workflows/${this.workflowId}/runs`);
|
|
1541
|
+
return this.request(`/api/workflows/legacy/${this.workflowId}/runs`);
|
|
621
1542
|
}
|
|
622
1543
|
}
|
|
623
1544
|
/**
|
|
624
|
-
*
|
|
625
|
-
*
|
|
626
|
-
* @param params - Parameters required for workflow execution
|
|
627
|
-
* @returns Promise containing the workflow execution results
|
|
628
|
-
*/
|
|
629
|
-
execute(params) {
|
|
630
|
-
return this.request(`/api/workflows/${this.workflowId}/execute`, {
|
|
631
|
-
method: "POST",
|
|
632
|
-
body: params
|
|
633
|
-
});
|
|
634
|
-
}
|
|
635
|
-
/**
|
|
636
|
-
* Creates a new workflow run
|
|
637
|
-
* @returns Promise containing the generated run ID
|
|
1545
|
+
* Creates a new legacy workflow run
|
|
1546
|
+
* @returns Promise containing the generated run ID
|
|
638
1547
|
*/
|
|
639
1548
|
createRun(params) {
|
|
640
1549
|
const searchParams = new URLSearchParams();
|
|
641
1550
|
if (!!params?.runId) {
|
|
642
1551
|
searchParams.set("runId", params.runId);
|
|
643
1552
|
}
|
|
644
|
-
return this.request(`/api/workflows/${this.workflowId}/
|
|
1553
|
+
return this.request(`/api/workflows/legacy/${this.workflowId}/create-run?${searchParams.toString()}`, {
|
|
645
1554
|
method: "POST"
|
|
646
1555
|
});
|
|
647
1556
|
}
|
|
648
1557
|
/**
|
|
649
|
-
* Starts a workflow run synchronously without waiting for the workflow to complete
|
|
1558
|
+
* Starts a legacy workflow run synchronously without waiting for the workflow to complete
|
|
650
1559
|
* @param params - Object containing the runId and triggerData
|
|
651
1560
|
* @returns Promise containing success message
|
|
652
1561
|
*/
|
|
653
1562
|
start(params) {
|
|
654
|
-
return this.request(`/api/workflows/${this.workflowId}/start?runId=${params.runId}`, {
|
|
1563
|
+
return this.request(`/api/workflows/legacy/${this.workflowId}/start?runId=${params.runId}`, {
|
|
655
1564
|
method: "POST",
|
|
656
1565
|
body: params?.triggerData
|
|
657
1566
|
});
|
|
658
1567
|
}
|
|
659
1568
|
/**
|
|
660
|
-
* Resumes a suspended workflow step synchronously without waiting for the workflow to complete
|
|
1569
|
+
* Resumes a suspended legacy workflow step synchronously without waiting for the workflow to complete
|
|
661
1570
|
* @param stepId - ID of the step to resume
|
|
662
|
-
* @param runId - ID of the workflow run
|
|
663
|
-
* @param context - Context to resume the workflow with
|
|
664
|
-
* @returns Promise containing the workflow resume results
|
|
1571
|
+
* @param runId - ID of the legacy workflow run
|
|
1572
|
+
* @param context - Context to resume the legacy workflow with
|
|
1573
|
+
* @returns Promise containing the legacy workflow resume results
|
|
665
1574
|
*/
|
|
666
1575
|
resume({
|
|
667
1576
|
stepId,
|
|
668
1577
|
runId,
|
|
669
1578
|
context
|
|
670
1579
|
}) {
|
|
671
|
-
return this.request(`/api/workflows/${this.workflowId}/resume?runId=${runId}`, {
|
|
1580
|
+
return this.request(`/api/workflows/legacy/${this.workflowId}/resume?runId=${runId}`, {
|
|
672
1581
|
method: "POST",
|
|
673
1582
|
body: {
|
|
674
1583
|
stepId,
|
|
@@ -686,18 +1595,18 @@ var Workflow = class extends BaseResource {
|
|
|
686
1595
|
if (!!params?.runId) {
|
|
687
1596
|
searchParams.set("runId", params.runId);
|
|
688
1597
|
}
|
|
689
|
-
return this.request(`/api/workflows/${this.workflowId}/start-async?${searchParams.toString()}`, {
|
|
1598
|
+
return this.request(`/api/workflows/legacy/${this.workflowId}/start-async?${searchParams.toString()}`, {
|
|
690
1599
|
method: "POST",
|
|
691
1600
|
body: params?.triggerData
|
|
692
1601
|
});
|
|
693
1602
|
}
|
|
694
1603
|
/**
|
|
695
|
-
* Resumes a suspended workflow step asynchronously and returns a promise that resolves when the workflow is complete
|
|
1604
|
+
* Resumes a suspended legacy workflow step asynchronously and returns a promise that resolves when the workflow is complete
|
|
696
1605
|
* @param params - Object containing the runId, stepId, and context
|
|
697
1606
|
* @returns Promise containing the workflow resume results
|
|
698
1607
|
*/
|
|
699
1608
|
resumeAsync(params) {
|
|
700
|
-
return this.request(`/api/workflows/${this.workflowId}/resume-async?runId=${params.runId}`, {
|
|
1609
|
+
return this.request(`/api/workflows/legacy/${this.workflowId}/resume-async?runId=${params.runId}`, {
|
|
701
1610
|
method: "POST",
|
|
702
1611
|
body: {
|
|
703
1612
|
stepId: params.stepId,
|
|
@@ -751,16 +1660,16 @@ var Workflow = class extends BaseResource {
|
|
|
751
1660
|
}
|
|
752
1661
|
}
|
|
753
1662
|
/**
|
|
754
|
-
* Watches workflow transitions in real-time
|
|
1663
|
+
* Watches legacy workflow transitions in real-time
|
|
755
1664
|
* @param runId - Optional run ID to filter the watch stream
|
|
756
|
-
* @returns AsyncGenerator that yields parsed records from the workflow watch stream
|
|
1665
|
+
* @returns AsyncGenerator that yields parsed records from the legacy workflow watch stream
|
|
757
1666
|
*/
|
|
758
1667
|
async watch({ runId }, onRecord) {
|
|
759
|
-
const response = await this.request(`/api/workflows/${this.workflowId}/watch?runId=${runId}`, {
|
|
1668
|
+
const response = await this.request(`/api/workflows/legacy/${this.workflowId}/watch?runId=${runId}`, {
|
|
760
1669
|
stream: true
|
|
761
1670
|
});
|
|
762
1671
|
if (!response.ok) {
|
|
763
|
-
throw new Error(`Failed to watch workflow: ${response.statusText}`);
|
|
1672
|
+
throw new Error(`Failed to watch legacy workflow: ${response.statusText}`);
|
|
764
1673
|
}
|
|
765
1674
|
if (!response.body) {
|
|
766
1675
|
throw new Error("Response body is null");
|
|
@@ -796,7 +1705,7 @@ var Tool = class extends BaseResource {
|
|
|
796
1705
|
}
|
|
797
1706
|
const body = {
|
|
798
1707
|
data: params.data,
|
|
799
|
-
runtimeContext:
|
|
1708
|
+
runtimeContext: parseClientRuntimeContext(params.runtimeContext)
|
|
800
1709
|
};
|
|
801
1710
|
return this.request(`/api/tools/${this.toolId}/execute?${url.toString()}`, {
|
|
802
1711
|
method: "POST",
|
|
@@ -805,15 +1714,15 @@ var Tool = class extends BaseResource {
|
|
|
805
1714
|
}
|
|
806
1715
|
};
|
|
807
1716
|
|
|
808
|
-
// src/resources/
|
|
1717
|
+
// src/resources/workflow.ts
|
|
809
1718
|
var RECORD_SEPARATOR2 = "";
|
|
810
|
-
var
|
|
1719
|
+
var Workflow = class extends BaseResource {
|
|
811
1720
|
constructor(options, workflowId) {
|
|
812
1721
|
super(options);
|
|
813
1722
|
this.workflowId = workflowId;
|
|
814
1723
|
}
|
|
815
1724
|
/**
|
|
816
|
-
* Creates an async generator that processes a readable stream and yields
|
|
1725
|
+
* Creates an async generator that processes a readable stream and yields workflow records
|
|
817
1726
|
* separated by the Record Separator character (\x1E)
|
|
818
1727
|
*
|
|
819
1728
|
* @param stream - The readable stream to process
|
|
@@ -858,16 +1767,16 @@ var VNextWorkflow = class extends BaseResource {
|
|
|
858
1767
|
}
|
|
859
1768
|
}
|
|
860
1769
|
/**
|
|
861
|
-
* Retrieves details about the
|
|
862
|
-
* @returns Promise containing
|
|
1770
|
+
* Retrieves details about the workflow
|
|
1771
|
+
* @returns Promise containing workflow details including steps and graphs
|
|
863
1772
|
*/
|
|
864
1773
|
details() {
|
|
865
|
-
return this.request(`/api/workflows
|
|
1774
|
+
return this.request(`/api/workflows/${this.workflowId}`);
|
|
866
1775
|
}
|
|
867
1776
|
/**
|
|
868
|
-
* Retrieves all runs for a
|
|
1777
|
+
* Retrieves all runs for a workflow
|
|
869
1778
|
* @param params - Parameters for filtering runs
|
|
870
|
-
* @returns Promise containing
|
|
1779
|
+
* @returns Promise containing workflow runs array
|
|
871
1780
|
*/
|
|
872
1781
|
runs(params) {
|
|
873
1782
|
const searchParams = new URLSearchParams();
|
|
@@ -877,23 +1786,60 @@ var VNextWorkflow = class extends BaseResource {
|
|
|
877
1786
|
if (params?.toDate) {
|
|
878
1787
|
searchParams.set("toDate", params.toDate.toISOString());
|
|
879
1788
|
}
|
|
880
|
-
if (params?.limit) {
|
|
1789
|
+
if (params?.limit !== null && params?.limit !== void 0 && !isNaN(Number(params?.limit))) {
|
|
881
1790
|
searchParams.set("limit", String(params.limit));
|
|
882
1791
|
}
|
|
883
|
-
if (params?.offset) {
|
|
1792
|
+
if (params?.offset !== null && params?.offset !== void 0 && !isNaN(Number(params?.offset))) {
|
|
884
1793
|
searchParams.set("offset", String(params.offset));
|
|
885
1794
|
}
|
|
886
1795
|
if (params?.resourceId) {
|
|
887
1796
|
searchParams.set("resourceId", params.resourceId);
|
|
888
1797
|
}
|
|
889
1798
|
if (searchParams.size) {
|
|
890
|
-
return this.request(`/api/workflows
|
|
1799
|
+
return this.request(`/api/workflows/${this.workflowId}/runs?${searchParams}`);
|
|
891
1800
|
} else {
|
|
892
|
-
return this.request(`/api/workflows
|
|
1801
|
+
return this.request(`/api/workflows/${this.workflowId}/runs`);
|
|
893
1802
|
}
|
|
894
1803
|
}
|
|
895
1804
|
/**
|
|
896
|
-
*
|
|
1805
|
+
* Retrieves a specific workflow run by its ID
|
|
1806
|
+
* @param runId - The ID of the workflow run to retrieve
|
|
1807
|
+
* @returns Promise containing the workflow run details
|
|
1808
|
+
*/
|
|
1809
|
+
runById(runId) {
|
|
1810
|
+
return this.request(`/api/workflows/${this.workflowId}/runs/${runId}`);
|
|
1811
|
+
}
|
|
1812
|
+
/**
|
|
1813
|
+
* Retrieves the execution result for a specific workflow run by its ID
|
|
1814
|
+
* @param runId - The ID of the workflow run to retrieve the execution result for
|
|
1815
|
+
* @returns Promise containing the workflow run execution result
|
|
1816
|
+
*/
|
|
1817
|
+
runExecutionResult(runId) {
|
|
1818
|
+
return this.request(`/api/workflows/${this.workflowId}/runs/${runId}/execution-result`);
|
|
1819
|
+
}
|
|
1820
|
+
/**
|
|
1821
|
+
* Cancels a specific workflow run by its ID
|
|
1822
|
+
* @param runId - The ID of the workflow run to cancel
|
|
1823
|
+
* @returns Promise containing a success message
|
|
1824
|
+
*/
|
|
1825
|
+
cancelRun(runId) {
|
|
1826
|
+
return this.request(`/api/workflows/${this.workflowId}/runs/${runId}/cancel`, {
|
|
1827
|
+
method: "POST"
|
|
1828
|
+
});
|
|
1829
|
+
}
|
|
1830
|
+
/**
|
|
1831
|
+
* Sends an event to a specific workflow run by its ID
|
|
1832
|
+
* @param params - Object containing the runId, event and data
|
|
1833
|
+
* @returns Promise containing a success message
|
|
1834
|
+
*/
|
|
1835
|
+
sendRunEvent(params) {
|
|
1836
|
+
return this.request(`/api/workflows/${this.workflowId}/runs/${params.runId}/send-event`, {
|
|
1837
|
+
method: "POST",
|
|
1838
|
+
body: { event: params.event, data: params.data }
|
|
1839
|
+
});
|
|
1840
|
+
}
|
|
1841
|
+
/**
|
|
1842
|
+
* Creates a new workflow run
|
|
897
1843
|
* @param params - Optional object containing the optional runId
|
|
898
1844
|
* @returns Promise containing the runId of the created run
|
|
899
1845
|
*/
|
|
@@ -902,24 +1848,32 @@ var VNextWorkflow = class extends BaseResource {
|
|
|
902
1848
|
if (!!params?.runId) {
|
|
903
1849
|
searchParams.set("runId", params.runId);
|
|
904
1850
|
}
|
|
905
|
-
return this.request(`/api/workflows
|
|
1851
|
+
return this.request(`/api/workflows/${this.workflowId}/create-run?${searchParams.toString()}`, {
|
|
906
1852
|
method: "POST"
|
|
907
1853
|
});
|
|
908
1854
|
}
|
|
909
1855
|
/**
|
|
910
|
-
*
|
|
1856
|
+
* Creates a new workflow run (alias for createRun)
|
|
1857
|
+
* @param params - Optional object containing the optional runId
|
|
1858
|
+
* @returns Promise containing the runId of the created run
|
|
1859
|
+
*/
|
|
1860
|
+
createRunAsync(params) {
|
|
1861
|
+
return this.createRun(params);
|
|
1862
|
+
}
|
|
1863
|
+
/**
|
|
1864
|
+
* Starts a workflow run synchronously without waiting for the workflow to complete
|
|
911
1865
|
* @param params - Object containing the runId, inputData and runtimeContext
|
|
912
1866
|
* @returns Promise containing success message
|
|
913
1867
|
*/
|
|
914
1868
|
start(params) {
|
|
915
|
-
const runtimeContext =
|
|
916
|
-
return this.request(`/api/workflows
|
|
1869
|
+
const runtimeContext = parseClientRuntimeContext(params.runtimeContext);
|
|
1870
|
+
return this.request(`/api/workflows/${this.workflowId}/start?runId=${params.runId}`, {
|
|
917
1871
|
method: "POST",
|
|
918
1872
|
body: { inputData: params?.inputData, runtimeContext }
|
|
919
1873
|
});
|
|
920
1874
|
}
|
|
921
1875
|
/**
|
|
922
|
-
* Resumes a suspended
|
|
1876
|
+
* Resumes a suspended workflow step synchronously without waiting for the workflow to complete
|
|
923
1877
|
* @param params - Object containing the runId, step, resumeData and runtimeContext
|
|
924
1878
|
* @returns Promise containing success message
|
|
925
1879
|
*/
|
|
@@ -929,8 +1883,8 @@ var VNextWorkflow = class extends BaseResource {
|
|
|
929
1883
|
resumeData,
|
|
930
1884
|
...rest
|
|
931
1885
|
}) {
|
|
932
|
-
const runtimeContext =
|
|
933
|
-
return this.request(`/api/workflows
|
|
1886
|
+
const runtimeContext = parseClientRuntimeContext(rest.runtimeContext);
|
|
1887
|
+
return this.request(`/api/workflows/${this.workflowId}/resume?runId=${runId}`, {
|
|
934
1888
|
method: "POST",
|
|
935
1889
|
stream: true,
|
|
936
1890
|
body: {
|
|
@@ -941,29 +1895,131 @@ var VNextWorkflow = class extends BaseResource {
|
|
|
941
1895
|
});
|
|
942
1896
|
}
|
|
943
1897
|
/**
|
|
944
|
-
* Starts a
|
|
1898
|
+
* Starts a workflow run asynchronously and returns a promise that resolves when the workflow is complete
|
|
945
1899
|
* @param params - Object containing the optional runId, inputData and runtimeContext
|
|
946
|
-
* @returns Promise containing the
|
|
1900
|
+
* @returns Promise containing the workflow execution results
|
|
947
1901
|
*/
|
|
948
1902
|
startAsync(params) {
|
|
949
1903
|
const searchParams = new URLSearchParams();
|
|
950
1904
|
if (!!params?.runId) {
|
|
951
1905
|
searchParams.set("runId", params.runId);
|
|
952
1906
|
}
|
|
953
|
-
const runtimeContext =
|
|
954
|
-
return this.request(`/api/workflows
|
|
1907
|
+
const runtimeContext = parseClientRuntimeContext(params.runtimeContext);
|
|
1908
|
+
return this.request(`/api/workflows/${this.workflowId}/start-async?${searchParams.toString()}`, {
|
|
955
1909
|
method: "POST",
|
|
956
1910
|
body: { inputData: params.inputData, runtimeContext }
|
|
957
1911
|
});
|
|
958
1912
|
}
|
|
959
1913
|
/**
|
|
960
|
-
*
|
|
1914
|
+
* Starts a workflow run and returns a stream
|
|
1915
|
+
* @param params - Object containing the optional runId, inputData and runtimeContext
|
|
1916
|
+
* @returns Promise containing the workflow execution results
|
|
1917
|
+
*/
|
|
1918
|
+
async stream(params) {
|
|
1919
|
+
const searchParams = new URLSearchParams();
|
|
1920
|
+
if (!!params?.runId) {
|
|
1921
|
+
searchParams.set("runId", params.runId);
|
|
1922
|
+
}
|
|
1923
|
+
const runtimeContext = parseClientRuntimeContext(params.runtimeContext);
|
|
1924
|
+
const response = await this.request(
|
|
1925
|
+
`/api/workflows/${this.workflowId}/stream?${searchParams.toString()}`,
|
|
1926
|
+
{
|
|
1927
|
+
method: "POST",
|
|
1928
|
+
body: { inputData: params.inputData, runtimeContext },
|
|
1929
|
+
stream: true
|
|
1930
|
+
}
|
|
1931
|
+
);
|
|
1932
|
+
if (!response.ok) {
|
|
1933
|
+
throw new Error(`Failed to stream vNext workflow: ${response.statusText}`);
|
|
1934
|
+
}
|
|
1935
|
+
if (!response.body) {
|
|
1936
|
+
throw new Error("Response body is null");
|
|
1937
|
+
}
|
|
1938
|
+
let failedChunk = void 0;
|
|
1939
|
+
const transformStream = new TransformStream({
|
|
1940
|
+
start() {
|
|
1941
|
+
},
|
|
1942
|
+
async transform(chunk, controller) {
|
|
1943
|
+
try {
|
|
1944
|
+
const decoded = new TextDecoder().decode(chunk);
|
|
1945
|
+
const chunks = decoded.split(RECORD_SEPARATOR2);
|
|
1946
|
+
for (const chunk2 of chunks) {
|
|
1947
|
+
if (chunk2) {
|
|
1948
|
+
const newChunk = failedChunk ? failedChunk + chunk2 : chunk2;
|
|
1949
|
+
try {
|
|
1950
|
+
const parsedChunk = JSON.parse(newChunk);
|
|
1951
|
+
controller.enqueue(parsedChunk);
|
|
1952
|
+
failedChunk = void 0;
|
|
1953
|
+
} catch {
|
|
1954
|
+
failedChunk = newChunk;
|
|
1955
|
+
}
|
|
1956
|
+
}
|
|
1957
|
+
}
|
|
1958
|
+
} catch {
|
|
1959
|
+
}
|
|
1960
|
+
}
|
|
1961
|
+
});
|
|
1962
|
+
return response.body.pipeThrough(transformStream);
|
|
1963
|
+
}
|
|
1964
|
+
/**
|
|
1965
|
+
* Starts a workflow run and returns a stream
|
|
1966
|
+
* @param params - Object containing the optional runId, inputData and runtimeContext
|
|
1967
|
+
* @returns Promise containing the workflow execution results
|
|
1968
|
+
*/
|
|
1969
|
+
async streamVNext(params) {
|
|
1970
|
+
const searchParams = new URLSearchParams();
|
|
1971
|
+
if (!!params?.runId) {
|
|
1972
|
+
searchParams.set("runId", params.runId);
|
|
1973
|
+
}
|
|
1974
|
+
const runtimeContext = parseClientRuntimeContext(params.runtimeContext);
|
|
1975
|
+
const response = await this.request(
|
|
1976
|
+
`/api/workflows/${this.workflowId}/streamVNext?${searchParams.toString()}`,
|
|
1977
|
+
{
|
|
1978
|
+
method: "POST",
|
|
1979
|
+
body: { inputData: params.inputData, runtimeContext },
|
|
1980
|
+
stream: true
|
|
1981
|
+
}
|
|
1982
|
+
);
|
|
1983
|
+
if (!response.ok) {
|
|
1984
|
+
throw new Error(`Failed to stream vNext workflow: ${response.statusText}`);
|
|
1985
|
+
}
|
|
1986
|
+
if (!response.body) {
|
|
1987
|
+
throw new Error("Response body is null");
|
|
1988
|
+
}
|
|
1989
|
+
let failedChunk = void 0;
|
|
1990
|
+
const transformStream = new TransformStream({
|
|
1991
|
+
start() {
|
|
1992
|
+
},
|
|
1993
|
+
async transform(chunk, controller) {
|
|
1994
|
+
try {
|
|
1995
|
+
const decoded = new TextDecoder().decode(chunk);
|
|
1996
|
+
const chunks = decoded.split(RECORD_SEPARATOR2);
|
|
1997
|
+
for (const chunk2 of chunks) {
|
|
1998
|
+
if (chunk2) {
|
|
1999
|
+
const newChunk = failedChunk ? failedChunk + chunk2 : chunk2;
|
|
2000
|
+
try {
|
|
2001
|
+
const parsedChunk = JSON.parse(newChunk);
|
|
2002
|
+
controller.enqueue(parsedChunk);
|
|
2003
|
+
failedChunk = void 0;
|
|
2004
|
+
} catch {
|
|
2005
|
+
failedChunk = newChunk;
|
|
2006
|
+
}
|
|
2007
|
+
}
|
|
2008
|
+
}
|
|
2009
|
+
} catch {
|
|
2010
|
+
}
|
|
2011
|
+
}
|
|
2012
|
+
});
|
|
2013
|
+
return response.body.pipeThrough(transformStream);
|
|
2014
|
+
}
|
|
2015
|
+
/**
|
|
2016
|
+
* Resumes a suspended workflow step asynchronously and returns a promise that resolves when the workflow is complete
|
|
961
2017
|
* @param params - Object containing the runId, step, resumeData and runtimeContext
|
|
962
|
-
* @returns Promise containing the
|
|
2018
|
+
* @returns Promise containing the workflow resume results
|
|
963
2019
|
*/
|
|
964
2020
|
resumeAsync(params) {
|
|
965
|
-
const runtimeContext =
|
|
966
|
-
return this.request(`/api/workflows
|
|
2021
|
+
const runtimeContext = parseClientRuntimeContext(params.runtimeContext);
|
|
2022
|
+
return this.request(`/api/workflows/${this.workflowId}/resume-async?runId=${params.runId}`, {
|
|
967
2023
|
method: "POST",
|
|
968
2024
|
body: {
|
|
969
2025
|
step: params.step,
|
|
@@ -973,24 +2029,51 @@ var VNextWorkflow = class extends BaseResource {
|
|
|
973
2029
|
});
|
|
974
2030
|
}
|
|
975
2031
|
/**
|
|
976
|
-
* Watches
|
|
2032
|
+
* Watches workflow transitions in real-time
|
|
977
2033
|
* @param runId - Optional run ID to filter the watch stream
|
|
978
|
-
* @returns AsyncGenerator that yields parsed records from the
|
|
2034
|
+
* @returns AsyncGenerator that yields parsed records from the workflow watch stream
|
|
979
2035
|
*/
|
|
980
2036
|
async watch({ runId }, onRecord) {
|
|
981
|
-
const response = await this.request(`/api/workflows
|
|
2037
|
+
const response = await this.request(`/api/workflows/${this.workflowId}/watch?runId=${runId}`, {
|
|
982
2038
|
stream: true
|
|
983
2039
|
});
|
|
984
2040
|
if (!response.ok) {
|
|
985
|
-
throw new Error(`Failed to watch
|
|
2041
|
+
throw new Error(`Failed to watch workflow: ${response.statusText}`);
|
|
986
2042
|
}
|
|
987
2043
|
if (!response.body) {
|
|
988
2044
|
throw new Error("Response body is null");
|
|
989
2045
|
}
|
|
990
2046
|
for await (const record of this.streamProcessor(response.body)) {
|
|
991
|
-
|
|
2047
|
+
if (typeof record === "string") {
|
|
2048
|
+
onRecord(JSON.parse(record));
|
|
2049
|
+
} else {
|
|
2050
|
+
onRecord(record);
|
|
2051
|
+
}
|
|
992
2052
|
}
|
|
993
2053
|
}
|
|
2054
|
+
/**
|
|
2055
|
+
* Creates a new ReadableStream from an iterable or async iterable of objects,
|
|
2056
|
+
* serializing each as JSON and separating them with the record separator (\x1E).
|
|
2057
|
+
*
|
|
2058
|
+
* @param records - An iterable or async iterable of objects to stream
|
|
2059
|
+
* @returns A ReadableStream emitting the records as JSON strings separated by the record separator
|
|
2060
|
+
*/
|
|
2061
|
+
static createRecordStream(records) {
|
|
2062
|
+
const encoder = new TextEncoder();
|
|
2063
|
+
return new ReadableStream({
|
|
2064
|
+
async start(controller) {
|
|
2065
|
+
try {
|
|
2066
|
+
for await (const record of records) {
|
|
2067
|
+
const json = JSON.stringify(record) + RECORD_SEPARATOR2;
|
|
2068
|
+
controller.enqueue(encoder.encode(json));
|
|
2069
|
+
}
|
|
2070
|
+
controller.close();
|
|
2071
|
+
} catch (err) {
|
|
2072
|
+
controller.error(err);
|
|
2073
|
+
}
|
|
2074
|
+
}
|
|
2075
|
+
});
|
|
2076
|
+
}
|
|
994
2077
|
};
|
|
995
2078
|
|
|
996
2079
|
// src/resources/a2a.ts
|
|
@@ -1004,107 +2087,730 @@ var A2A = class extends BaseResource {
|
|
|
1004
2087
|
* @returns Promise containing the agent card information
|
|
1005
2088
|
*/
|
|
1006
2089
|
async getCard() {
|
|
1007
|
-
return this.request(`/.well-known/${this.agentId}/agent.json`);
|
|
2090
|
+
return this.request(`/.well-known/${this.agentId}/agent-card.json`);
|
|
1008
2091
|
}
|
|
1009
2092
|
/**
|
|
1010
|
-
* Send a message to the agent and
|
|
2093
|
+
* Send a message to the agent and gets a message or task response
|
|
1011
2094
|
* @param params - Parameters for the task
|
|
1012
|
-
* @returns Promise containing the
|
|
2095
|
+
* @returns Promise containing the response
|
|
1013
2096
|
*/
|
|
1014
2097
|
async sendMessage(params) {
|
|
1015
2098
|
const response = await this.request(`/a2a/${this.agentId}`, {
|
|
1016
2099
|
method: "POST",
|
|
1017
2100
|
body: {
|
|
1018
|
-
method: "
|
|
2101
|
+
method: "message/send",
|
|
2102
|
+
params
|
|
2103
|
+
}
|
|
2104
|
+
});
|
|
2105
|
+
return response;
|
|
2106
|
+
}
|
|
2107
|
+
/**
|
|
2108
|
+
* Sends a message to an agent to initiate/continue a task and subscribes
|
|
2109
|
+
* the client to real-time updates for that task via Server-Sent Events (SSE).
|
|
2110
|
+
* @param params - Parameters for the task
|
|
2111
|
+
* @returns A stream of Server-Sent Events. Each SSE `data` field contains a `SendStreamingMessageResponse`
|
|
2112
|
+
*/
|
|
2113
|
+
async sendStreamingMessage(params) {
|
|
2114
|
+
const response = await this.request(`/a2a/${this.agentId}`, {
|
|
2115
|
+
method: "POST",
|
|
2116
|
+
body: {
|
|
2117
|
+
method: "message/stream",
|
|
1019
2118
|
params
|
|
1020
2119
|
}
|
|
1021
2120
|
});
|
|
1022
|
-
return
|
|
2121
|
+
return response;
|
|
1023
2122
|
}
|
|
1024
2123
|
/**
|
|
1025
2124
|
* Get the status and result of a task
|
|
1026
2125
|
* @param params - Parameters for querying the task
|
|
1027
2126
|
* @returns Promise containing the task response
|
|
1028
2127
|
*/
|
|
1029
|
-
async getTask(params) {
|
|
1030
|
-
const response = await this.request(`/a2a/${this.agentId}`, {
|
|
2128
|
+
async getTask(params) {
|
|
2129
|
+
const response = await this.request(`/a2a/${this.agentId}`, {
|
|
2130
|
+
method: "POST",
|
|
2131
|
+
body: {
|
|
2132
|
+
method: "tasks/get",
|
|
2133
|
+
params
|
|
2134
|
+
}
|
|
2135
|
+
});
|
|
2136
|
+
return response;
|
|
2137
|
+
}
|
|
2138
|
+
/**
|
|
2139
|
+
* Cancel a running task
|
|
2140
|
+
* @param params - Parameters identifying the task to cancel
|
|
2141
|
+
* @returns Promise containing the task response
|
|
2142
|
+
*/
|
|
2143
|
+
async cancelTask(params) {
|
|
2144
|
+
return this.request(`/a2a/${this.agentId}`, {
|
|
2145
|
+
method: "POST",
|
|
2146
|
+
body: {
|
|
2147
|
+
method: "tasks/cancel",
|
|
2148
|
+
params
|
|
2149
|
+
}
|
|
2150
|
+
});
|
|
2151
|
+
}
|
|
2152
|
+
};
|
|
2153
|
+
|
|
2154
|
+
// src/resources/mcp-tool.ts
|
|
2155
|
+
var MCPTool = class extends BaseResource {
|
|
2156
|
+
serverId;
|
|
2157
|
+
toolId;
|
|
2158
|
+
constructor(options, serverId, toolId) {
|
|
2159
|
+
super(options);
|
|
2160
|
+
this.serverId = serverId;
|
|
2161
|
+
this.toolId = toolId;
|
|
2162
|
+
}
|
|
2163
|
+
/**
|
|
2164
|
+
* Retrieves details about this specific tool from the MCP server.
|
|
2165
|
+
* @returns Promise containing the tool's information (name, description, schema).
|
|
2166
|
+
*/
|
|
2167
|
+
details() {
|
|
2168
|
+
return this.request(`/api/mcp/${this.serverId}/tools/${this.toolId}`);
|
|
2169
|
+
}
|
|
2170
|
+
/**
|
|
2171
|
+
* Executes this specific tool on the MCP server.
|
|
2172
|
+
* @param params - Parameters for tool execution, including data/args and optional runtimeContext.
|
|
2173
|
+
* @returns Promise containing the result of the tool execution.
|
|
2174
|
+
*/
|
|
2175
|
+
execute(params) {
|
|
2176
|
+
const body = {};
|
|
2177
|
+
if (params.data !== void 0) body.data = params.data;
|
|
2178
|
+
if (params.runtimeContext !== void 0) {
|
|
2179
|
+
body.runtimeContext = params.runtimeContext;
|
|
2180
|
+
}
|
|
2181
|
+
return this.request(`/api/mcp/${this.serverId}/tools/${this.toolId}/execute`, {
|
|
2182
|
+
method: "POST",
|
|
2183
|
+
body: Object.keys(body).length > 0 ? body : void 0
|
|
2184
|
+
});
|
|
2185
|
+
}
|
|
2186
|
+
};
|
|
2187
|
+
|
|
2188
|
+
// src/resources/agent-builder.ts
|
|
2189
|
+
var RECORD_SEPARATOR3 = "";
|
|
2190
|
+
var AgentBuilder = class extends BaseResource {
|
|
2191
|
+
constructor(options, actionId) {
|
|
2192
|
+
super(options);
|
|
2193
|
+
this.actionId = actionId;
|
|
2194
|
+
}
|
|
2195
|
+
// Helper function to transform workflow result to action result
|
|
2196
|
+
transformWorkflowResult(result) {
|
|
2197
|
+
if (result.status === "success") {
|
|
2198
|
+
return {
|
|
2199
|
+
success: result.result.success || false,
|
|
2200
|
+
applied: result.result.applied || false,
|
|
2201
|
+
branchName: result.result.branchName,
|
|
2202
|
+
message: result.result.message || "Agent builder action completed",
|
|
2203
|
+
validationResults: result.result.validationResults,
|
|
2204
|
+
error: result.result.error,
|
|
2205
|
+
errors: result.result.errors,
|
|
2206
|
+
stepResults: result.result.stepResults
|
|
2207
|
+
};
|
|
2208
|
+
} else if (result.status === "failed") {
|
|
2209
|
+
return {
|
|
2210
|
+
success: false,
|
|
2211
|
+
applied: false,
|
|
2212
|
+
message: `Agent builder action failed: ${result.error.message}`,
|
|
2213
|
+
error: result.error.message
|
|
2214
|
+
};
|
|
2215
|
+
} else {
|
|
2216
|
+
return {
|
|
2217
|
+
success: false,
|
|
2218
|
+
applied: false,
|
|
2219
|
+
message: "Agent builder action was suspended",
|
|
2220
|
+
error: "Workflow suspended - manual intervention required"
|
|
2221
|
+
};
|
|
2222
|
+
}
|
|
2223
|
+
}
|
|
2224
|
+
/**
|
|
2225
|
+
* Creates a new agent builder action run and returns the runId.
|
|
2226
|
+
* This calls `/api/agent-builder/:actionId/create-run`.
|
|
2227
|
+
*/
|
|
2228
|
+
async createRun(params) {
|
|
2229
|
+
const searchParams = new URLSearchParams();
|
|
2230
|
+
if (!!params?.runId) {
|
|
2231
|
+
searchParams.set("runId", params.runId);
|
|
2232
|
+
}
|
|
2233
|
+
const url = `/api/agent-builder/${this.actionId}/create-run${searchParams.toString() ? `?${searchParams.toString()}` : ""}`;
|
|
2234
|
+
return this.request(url, {
|
|
2235
|
+
method: "POST"
|
|
2236
|
+
});
|
|
2237
|
+
}
|
|
2238
|
+
/**
|
|
2239
|
+
* Creates a new workflow run (alias for createRun)
|
|
2240
|
+
* @param params - Optional object containing the optional runId
|
|
2241
|
+
* @returns Promise containing the runId of the created run
|
|
2242
|
+
*/
|
|
2243
|
+
createRunAsync(params) {
|
|
2244
|
+
return this.createRun(params);
|
|
2245
|
+
}
|
|
2246
|
+
/**
|
|
2247
|
+
* Starts agent builder action asynchronously and waits for completion.
|
|
2248
|
+
* This calls `/api/agent-builder/:actionId/start-async`.
|
|
2249
|
+
*/
|
|
2250
|
+
async startAsync(params, runId) {
|
|
2251
|
+
const searchParams = new URLSearchParams();
|
|
2252
|
+
if (runId) {
|
|
2253
|
+
searchParams.set("runId", runId);
|
|
2254
|
+
}
|
|
2255
|
+
const runtimeContext = parseClientRuntimeContext(params.runtimeContext);
|
|
2256
|
+
const { runtimeContext: _, ...actionParams } = params;
|
|
2257
|
+
const url = `/api/agent-builder/${this.actionId}/start-async${searchParams.toString() ? `?${searchParams.toString()}` : ""}`;
|
|
2258
|
+
const result = await this.request(url, {
|
|
2259
|
+
method: "POST",
|
|
2260
|
+
body: { ...actionParams, runtimeContext }
|
|
2261
|
+
});
|
|
2262
|
+
return this.transformWorkflowResult(result);
|
|
2263
|
+
}
|
|
2264
|
+
/**
|
|
2265
|
+
* Starts an existing agent builder action run.
|
|
2266
|
+
* This calls `/api/agent-builder/:actionId/start`.
|
|
2267
|
+
*/
|
|
2268
|
+
async startActionRun(params, runId) {
|
|
2269
|
+
const searchParams = new URLSearchParams();
|
|
2270
|
+
searchParams.set("runId", runId);
|
|
2271
|
+
const runtimeContext = parseClientRuntimeContext(params.runtimeContext);
|
|
2272
|
+
const { runtimeContext: _, ...actionParams } = params;
|
|
2273
|
+
const url = `/api/agent-builder/${this.actionId}/start?${searchParams.toString()}`;
|
|
2274
|
+
return this.request(url, {
|
|
2275
|
+
method: "POST",
|
|
2276
|
+
body: { ...actionParams, runtimeContext }
|
|
2277
|
+
});
|
|
2278
|
+
}
|
|
2279
|
+
/**
|
|
2280
|
+
* Resumes a suspended agent builder action step.
|
|
2281
|
+
* This calls `/api/agent-builder/:actionId/resume`.
|
|
2282
|
+
*/
|
|
2283
|
+
async resume(params, runId) {
|
|
2284
|
+
const searchParams = new URLSearchParams();
|
|
2285
|
+
searchParams.set("runId", runId);
|
|
2286
|
+
const runtimeContext = parseClientRuntimeContext(params.runtimeContext);
|
|
2287
|
+
const { runtimeContext: _, ...resumeParams } = params;
|
|
2288
|
+
const url = `/api/agent-builder/${this.actionId}/resume?${searchParams.toString()}`;
|
|
2289
|
+
return this.request(url, {
|
|
2290
|
+
method: "POST",
|
|
2291
|
+
body: { ...resumeParams, runtimeContext }
|
|
2292
|
+
});
|
|
2293
|
+
}
|
|
2294
|
+
/**
|
|
2295
|
+
* Resumes a suspended agent builder action step asynchronously.
|
|
2296
|
+
* This calls `/api/agent-builder/:actionId/resume-async`.
|
|
2297
|
+
*/
|
|
2298
|
+
async resumeAsync(params, runId) {
|
|
2299
|
+
const searchParams = new URLSearchParams();
|
|
2300
|
+
searchParams.set("runId", runId);
|
|
2301
|
+
const runtimeContext = parseClientRuntimeContext(params.runtimeContext);
|
|
2302
|
+
const { runtimeContext: _, ...resumeParams } = params;
|
|
2303
|
+
const url = `/api/agent-builder/${this.actionId}/resume-async?${searchParams.toString()}`;
|
|
2304
|
+
const result = await this.request(url, {
|
|
2305
|
+
method: "POST",
|
|
2306
|
+
body: { ...resumeParams, runtimeContext }
|
|
2307
|
+
});
|
|
2308
|
+
return this.transformWorkflowResult(result);
|
|
2309
|
+
}
|
|
2310
|
+
/**
|
|
2311
|
+
* Creates an async generator that processes a readable stream and yields action records
|
|
2312
|
+
* separated by the Record Separator character (\x1E)
|
|
2313
|
+
*
|
|
2314
|
+
* @param stream - The readable stream to process
|
|
2315
|
+
* @returns An async generator that yields parsed records
|
|
2316
|
+
*/
|
|
2317
|
+
async *streamProcessor(stream) {
|
|
2318
|
+
const reader = stream.getReader();
|
|
2319
|
+
let doneReading = false;
|
|
2320
|
+
let buffer = "";
|
|
2321
|
+
try {
|
|
2322
|
+
while (!doneReading) {
|
|
2323
|
+
const { done, value } = await reader.read();
|
|
2324
|
+
doneReading = done;
|
|
2325
|
+
if (done && !value) continue;
|
|
2326
|
+
try {
|
|
2327
|
+
const decoded = value ? new TextDecoder().decode(value) : "";
|
|
2328
|
+
const chunks = (buffer + decoded).split(RECORD_SEPARATOR3);
|
|
2329
|
+
buffer = chunks.pop() || "";
|
|
2330
|
+
for (const chunk of chunks) {
|
|
2331
|
+
if (chunk) {
|
|
2332
|
+
if (typeof chunk === "string") {
|
|
2333
|
+
try {
|
|
2334
|
+
const parsedChunk = JSON.parse(chunk);
|
|
2335
|
+
yield parsedChunk;
|
|
2336
|
+
} catch {
|
|
2337
|
+
}
|
|
2338
|
+
}
|
|
2339
|
+
}
|
|
2340
|
+
}
|
|
2341
|
+
} catch {
|
|
2342
|
+
}
|
|
2343
|
+
}
|
|
2344
|
+
if (buffer) {
|
|
2345
|
+
try {
|
|
2346
|
+
yield JSON.parse(buffer);
|
|
2347
|
+
} catch {
|
|
2348
|
+
}
|
|
2349
|
+
}
|
|
2350
|
+
} finally {
|
|
2351
|
+
reader.cancel().catch(() => {
|
|
2352
|
+
});
|
|
2353
|
+
}
|
|
2354
|
+
}
|
|
2355
|
+
/**
|
|
2356
|
+
* Streams agent builder action progress in real-time.
|
|
2357
|
+
* This calls `/api/agent-builder/:actionId/stream`.
|
|
2358
|
+
*/
|
|
2359
|
+
async stream(params, runId) {
|
|
2360
|
+
const searchParams = new URLSearchParams();
|
|
2361
|
+
if (runId) {
|
|
2362
|
+
searchParams.set("runId", runId);
|
|
2363
|
+
}
|
|
2364
|
+
const runtimeContext = parseClientRuntimeContext(params.runtimeContext);
|
|
2365
|
+
const { runtimeContext: _, ...actionParams } = params;
|
|
2366
|
+
const url = `/api/agent-builder/${this.actionId}/stream${searchParams.toString() ? `?${searchParams.toString()}` : ""}`;
|
|
2367
|
+
const response = await this.request(url, {
|
|
2368
|
+
method: "POST",
|
|
2369
|
+
body: { ...actionParams, runtimeContext },
|
|
2370
|
+
stream: true
|
|
2371
|
+
});
|
|
2372
|
+
if (!response.ok) {
|
|
2373
|
+
throw new Error(`Failed to stream agent builder action: ${response.statusText}`);
|
|
2374
|
+
}
|
|
2375
|
+
if (!response.body) {
|
|
2376
|
+
throw new Error("Response body is null");
|
|
2377
|
+
}
|
|
2378
|
+
let failedChunk = void 0;
|
|
2379
|
+
const transformStream = new TransformStream({
|
|
2380
|
+
start() {
|
|
2381
|
+
},
|
|
2382
|
+
async transform(chunk, controller) {
|
|
2383
|
+
try {
|
|
2384
|
+
const decoded = new TextDecoder().decode(chunk);
|
|
2385
|
+
const chunks = decoded.split(RECORD_SEPARATOR3);
|
|
2386
|
+
for (const chunk2 of chunks) {
|
|
2387
|
+
if (chunk2) {
|
|
2388
|
+
const newChunk = failedChunk ? failedChunk + chunk2 : chunk2;
|
|
2389
|
+
try {
|
|
2390
|
+
const parsedChunk = JSON.parse(newChunk);
|
|
2391
|
+
controller.enqueue(parsedChunk);
|
|
2392
|
+
failedChunk = void 0;
|
|
2393
|
+
} catch {
|
|
2394
|
+
failedChunk = newChunk;
|
|
2395
|
+
}
|
|
2396
|
+
}
|
|
2397
|
+
}
|
|
2398
|
+
} catch {
|
|
2399
|
+
}
|
|
2400
|
+
}
|
|
2401
|
+
});
|
|
2402
|
+
return response.body.pipeThrough(transformStream);
|
|
2403
|
+
}
|
|
2404
|
+
/**
|
|
2405
|
+
* Streams agent builder action progress in real-time using VNext streaming.
|
|
2406
|
+
* This calls `/api/agent-builder/:actionId/streamVNext`.
|
|
2407
|
+
*/
|
|
2408
|
+
async streamVNext(params, runId) {
|
|
2409
|
+
const searchParams = new URLSearchParams();
|
|
2410
|
+
if (runId) {
|
|
2411
|
+
searchParams.set("runId", runId);
|
|
2412
|
+
}
|
|
2413
|
+
const runtimeContext = parseClientRuntimeContext(params.runtimeContext);
|
|
2414
|
+
const { runtimeContext: _, ...actionParams } = params;
|
|
2415
|
+
const url = `/api/agent-builder/${this.actionId}/streamVNext${searchParams.toString() ? `?${searchParams.toString()}` : ""}`;
|
|
2416
|
+
const response = await this.request(url, {
|
|
2417
|
+
method: "POST",
|
|
2418
|
+
body: { ...actionParams, runtimeContext },
|
|
2419
|
+
stream: true
|
|
2420
|
+
});
|
|
2421
|
+
if (!response.ok) {
|
|
2422
|
+
throw new Error(`Failed to stream agent builder action VNext: ${response.statusText}`);
|
|
2423
|
+
}
|
|
2424
|
+
if (!response.body) {
|
|
2425
|
+
throw new Error("Response body is null");
|
|
2426
|
+
}
|
|
2427
|
+
let failedChunk = void 0;
|
|
2428
|
+
const transformStream = new TransformStream({
|
|
2429
|
+
start() {
|
|
2430
|
+
},
|
|
2431
|
+
async transform(chunk, controller) {
|
|
2432
|
+
try {
|
|
2433
|
+
const decoded = new TextDecoder().decode(chunk);
|
|
2434
|
+
const chunks = decoded.split(RECORD_SEPARATOR3);
|
|
2435
|
+
for (const chunk2 of chunks) {
|
|
2436
|
+
if (chunk2) {
|
|
2437
|
+
const newChunk = failedChunk ? failedChunk + chunk2 : chunk2;
|
|
2438
|
+
try {
|
|
2439
|
+
const parsedChunk = JSON.parse(newChunk);
|
|
2440
|
+
controller.enqueue(parsedChunk);
|
|
2441
|
+
failedChunk = void 0;
|
|
2442
|
+
} catch {
|
|
2443
|
+
failedChunk = newChunk;
|
|
2444
|
+
}
|
|
2445
|
+
}
|
|
2446
|
+
}
|
|
2447
|
+
} catch {
|
|
2448
|
+
}
|
|
2449
|
+
}
|
|
2450
|
+
});
|
|
2451
|
+
return response.body.pipeThrough(transformStream);
|
|
2452
|
+
}
|
|
2453
|
+
/**
|
|
2454
|
+
* Watches an existing agent builder action run by runId.
|
|
2455
|
+
* This is used for hot reload recovery - it loads the existing run state
|
|
2456
|
+
* and streams any remaining progress.
|
|
2457
|
+
* This calls `/api/agent-builder/:actionId/watch`.
|
|
2458
|
+
*/
|
|
2459
|
+
async watch({ runId, eventType }, onRecord) {
|
|
2460
|
+
const url = `/api/agent-builder/${this.actionId}/watch?runId=${runId}${eventType ? `&eventType=${eventType}` : ""}`;
|
|
2461
|
+
const response = await this.request(url, {
|
|
2462
|
+
method: "GET",
|
|
2463
|
+
stream: true
|
|
2464
|
+
});
|
|
2465
|
+
if (!response.ok) {
|
|
2466
|
+
throw new Error(`Failed to watch agent builder action: ${response.statusText}`);
|
|
2467
|
+
}
|
|
2468
|
+
if (!response.body) {
|
|
2469
|
+
throw new Error("Response body is null");
|
|
2470
|
+
}
|
|
2471
|
+
for await (const record of this.streamProcessor(response.body)) {
|
|
2472
|
+
if (typeof record === "string") {
|
|
2473
|
+
onRecord(JSON.parse(record));
|
|
2474
|
+
} else {
|
|
2475
|
+
onRecord(record);
|
|
2476
|
+
}
|
|
2477
|
+
}
|
|
2478
|
+
}
|
|
2479
|
+
/**
|
|
2480
|
+
* Gets a specific action run by its ID.
|
|
2481
|
+
* This calls `/api/agent-builder/:actionId/runs/:runId`.
|
|
2482
|
+
*/
|
|
2483
|
+
async runById(runId) {
|
|
2484
|
+
const url = `/api/agent-builder/${this.actionId}/runs/${runId}`;
|
|
2485
|
+
return this.request(url, {
|
|
2486
|
+
method: "GET"
|
|
2487
|
+
});
|
|
2488
|
+
}
|
|
2489
|
+
/**
|
|
2490
|
+
* Gets details about this agent builder action.
|
|
2491
|
+
* This calls `/api/agent-builder/:actionId`.
|
|
2492
|
+
*/
|
|
2493
|
+
async details() {
|
|
2494
|
+
const result = await this.request(`/api/agent-builder/${this.actionId}`);
|
|
2495
|
+
return result;
|
|
2496
|
+
}
|
|
2497
|
+
/**
|
|
2498
|
+
* Gets all runs for this agent builder action.
|
|
2499
|
+
* This calls `/api/agent-builder/:actionId/runs`.
|
|
2500
|
+
*/
|
|
2501
|
+
async runs(params) {
|
|
2502
|
+
const searchParams = new URLSearchParams();
|
|
2503
|
+
if (params?.fromDate) {
|
|
2504
|
+
searchParams.set("fromDate", params.fromDate.toISOString());
|
|
2505
|
+
}
|
|
2506
|
+
if (params?.toDate) {
|
|
2507
|
+
searchParams.set("toDate", params.toDate.toISOString());
|
|
2508
|
+
}
|
|
2509
|
+
if (params?.limit !== void 0) {
|
|
2510
|
+
searchParams.set("limit", String(params.limit));
|
|
2511
|
+
}
|
|
2512
|
+
if (params?.offset !== void 0) {
|
|
2513
|
+
searchParams.set("offset", String(params.offset));
|
|
2514
|
+
}
|
|
2515
|
+
if (params?.resourceId) {
|
|
2516
|
+
searchParams.set("resourceId", params.resourceId);
|
|
2517
|
+
}
|
|
2518
|
+
const url = `/api/agent-builder/${this.actionId}/runs${searchParams.toString() ? `?${searchParams.toString()}` : ""}`;
|
|
2519
|
+
return this.request(url, {
|
|
2520
|
+
method: "GET"
|
|
2521
|
+
});
|
|
2522
|
+
}
|
|
2523
|
+
/**
|
|
2524
|
+
* Gets the execution result of an agent builder action run.
|
|
2525
|
+
* This calls `/api/agent-builder/:actionId/runs/:runId/execution-result`.
|
|
2526
|
+
*/
|
|
2527
|
+
async runExecutionResult(runId) {
|
|
2528
|
+
const url = `/api/agent-builder/${this.actionId}/runs/${runId}/execution-result`;
|
|
2529
|
+
return this.request(url, {
|
|
2530
|
+
method: "GET"
|
|
2531
|
+
});
|
|
2532
|
+
}
|
|
2533
|
+
/**
|
|
2534
|
+
* Cancels an agent builder action run.
|
|
2535
|
+
* This calls `/api/agent-builder/:actionId/runs/:runId/cancel`.
|
|
2536
|
+
*/
|
|
2537
|
+
async cancelRun(runId) {
|
|
2538
|
+
const url = `/api/agent-builder/${this.actionId}/runs/${runId}/cancel`;
|
|
2539
|
+
return this.request(url, {
|
|
2540
|
+
method: "POST"
|
|
2541
|
+
});
|
|
2542
|
+
}
|
|
2543
|
+
/**
|
|
2544
|
+
* Sends an event to an agent builder action run.
|
|
2545
|
+
* This calls `/api/agent-builder/:actionId/runs/:runId/send-event`.
|
|
2546
|
+
*/
|
|
2547
|
+
async sendRunEvent(params) {
|
|
2548
|
+
const url = `/api/agent-builder/${this.actionId}/runs/${params.runId}/send-event`;
|
|
2549
|
+
return this.request(url, {
|
|
2550
|
+
method: "POST",
|
|
2551
|
+
body: { event: params.event, data: params.data }
|
|
2552
|
+
});
|
|
2553
|
+
}
|
|
2554
|
+
};
|
|
2555
|
+
|
|
2556
|
+
// src/resources/observability.ts
|
|
2557
|
+
var Observability = class extends BaseResource {
|
|
2558
|
+
constructor(options) {
|
|
2559
|
+
super(options);
|
|
2560
|
+
}
|
|
2561
|
+
/**
|
|
2562
|
+
* Retrieves a specific AI trace by ID
|
|
2563
|
+
* @param traceId - ID of the trace to retrieve
|
|
2564
|
+
* @returns Promise containing the AI trace with all its spans
|
|
2565
|
+
*/
|
|
2566
|
+
getTrace(traceId) {
|
|
2567
|
+
return this.request(`/api/observability/traces/${traceId}`);
|
|
2568
|
+
}
|
|
2569
|
+
/**
|
|
2570
|
+
* Retrieves paginated list of AI traces with optional filtering
|
|
2571
|
+
* @param params - Parameters for pagination and filtering
|
|
2572
|
+
* @returns Promise containing paginated traces and pagination info
|
|
2573
|
+
*/
|
|
2574
|
+
getTraces(params) {
|
|
2575
|
+
const { pagination, filters } = params;
|
|
2576
|
+
const { page, perPage, dateRange } = pagination || {};
|
|
2577
|
+
const { name, spanType, entityId, entityType } = filters || {};
|
|
2578
|
+
const searchParams = new URLSearchParams();
|
|
2579
|
+
if (page !== void 0) {
|
|
2580
|
+
searchParams.set("page", String(page));
|
|
2581
|
+
}
|
|
2582
|
+
if (perPage !== void 0) {
|
|
2583
|
+
searchParams.set("perPage", String(perPage));
|
|
2584
|
+
}
|
|
2585
|
+
if (name) {
|
|
2586
|
+
searchParams.set("name", name);
|
|
2587
|
+
}
|
|
2588
|
+
if (spanType !== void 0) {
|
|
2589
|
+
searchParams.set("spanType", String(spanType));
|
|
2590
|
+
}
|
|
2591
|
+
if (entityId && entityType) {
|
|
2592
|
+
searchParams.set("entityId", entityId);
|
|
2593
|
+
searchParams.set("entityType", entityType);
|
|
2594
|
+
}
|
|
2595
|
+
if (dateRange) {
|
|
2596
|
+
const dateRangeStr = JSON.stringify({
|
|
2597
|
+
start: dateRange.start instanceof Date ? dateRange.start.toISOString() : dateRange.start,
|
|
2598
|
+
end: dateRange.end instanceof Date ? dateRange.end.toISOString() : dateRange.end
|
|
2599
|
+
});
|
|
2600
|
+
searchParams.set("dateRange", dateRangeStr);
|
|
2601
|
+
}
|
|
2602
|
+
const queryString = searchParams.toString();
|
|
2603
|
+
return this.request(`/api/observability/traces${queryString ? `?${queryString}` : ""}`);
|
|
2604
|
+
}
|
|
2605
|
+
};
|
|
2606
|
+
|
|
2607
|
+
// src/resources/network-memory-thread.ts
|
|
2608
|
+
var NetworkMemoryThread = class extends BaseResource {
|
|
2609
|
+
constructor(options, threadId, networkId) {
|
|
2610
|
+
super(options);
|
|
2611
|
+
this.threadId = threadId;
|
|
2612
|
+
this.networkId = networkId;
|
|
2613
|
+
}
|
|
2614
|
+
/**
|
|
2615
|
+
* Retrieves the memory thread details
|
|
2616
|
+
* @returns Promise containing thread details including title and metadata
|
|
2617
|
+
*/
|
|
2618
|
+
get() {
|
|
2619
|
+
return this.request(`/api/memory/network/threads/${this.threadId}?networkId=${this.networkId}`);
|
|
2620
|
+
}
|
|
2621
|
+
/**
|
|
2622
|
+
* Updates the memory thread properties
|
|
2623
|
+
* @param params - Update parameters including title and metadata
|
|
2624
|
+
* @returns Promise containing updated thread details
|
|
2625
|
+
*/
|
|
2626
|
+
update(params) {
|
|
2627
|
+
return this.request(`/api/memory/network/threads/${this.threadId}?networkId=${this.networkId}`, {
|
|
2628
|
+
method: "PATCH",
|
|
2629
|
+
body: params
|
|
2630
|
+
});
|
|
2631
|
+
}
|
|
2632
|
+
/**
|
|
2633
|
+
* Deletes the memory thread
|
|
2634
|
+
* @returns Promise containing deletion result
|
|
2635
|
+
*/
|
|
2636
|
+
delete() {
|
|
2637
|
+
return this.request(`/api/memory/network/threads/${this.threadId}?networkId=${this.networkId}`, {
|
|
2638
|
+
method: "DELETE"
|
|
2639
|
+
});
|
|
2640
|
+
}
|
|
2641
|
+
/**
|
|
2642
|
+
* Retrieves messages associated with the thread
|
|
2643
|
+
* @param params - Optional parameters including limit for number of messages to retrieve
|
|
2644
|
+
* @returns Promise containing thread messages and UI messages
|
|
2645
|
+
*/
|
|
2646
|
+
getMessages(params) {
|
|
2647
|
+
const query = new URLSearchParams({
|
|
2648
|
+
networkId: this.networkId,
|
|
2649
|
+
...params?.limit ? { limit: params.limit.toString() } : {}
|
|
2650
|
+
});
|
|
2651
|
+
return this.request(`/api/memory/network/threads/${this.threadId}/messages?${query.toString()}`);
|
|
2652
|
+
}
|
|
2653
|
+
/**
|
|
2654
|
+
* Deletes one or more messages from the thread
|
|
2655
|
+
* @param messageIds - Can be a single message ID (string), array of message IDs,
|
|
2656
|
+
* message object with id property, or array of message objects
|
|
2657
|
+
* @returns Promise containing deletion result
|
|
2658
|
+
*/
|
|
2659
|
+
deleteMessages(messageIds) {
|
|
2660
|
+
const query = new URLSearchParams({
|
|
2661
|
+
networkId: this.networkId
|
|
2662
|
+
});
|
|
2663
|
+
return this.request(`/api/memory/network/messages/delete?${query.toString()}`, {
|
|
2664
|
+
method: "POST",
|
|
2665
|
+
body: { messageIds }
|
|
2666
|
+
});
|
|
2667
|
+
}
|
|
2668
|
+
};
|
|
2669
|
+
|
|
2670
|
+
// src/resources/vNextNetwork.ts
|
|
2671
|
+
var RECORD_SEPARATOR4 = "";
|
|
2672
|
+
var VNextNetwork = class extends BaseResource {
|
|
2673
|
+
constructor(options, networkId) {
|
|
2674
|
+
super(options);
|
|
2675
|
+
this.networkId = networkId;
|
|
2676
|
+
}
|
|
2677
|
+
/**
|
|
2678
|
+
* Retrieves details about the network
|
|
2679
|
+
* @returns Promise containing vNext network details
|
|
2680
|
+
*/
|
|
2681
|
+
details() {
|
|
2682
|
+
return this.request(`/api/networks/v-next/${this.networkId}`);
|
|
2683
|
+
}
|
|
2684
|
+
/**
|
|
2685
|
+
* Generates a response from the v-next network
|
|
2686
|
+
* @param params - Generation parameters including message
|
|
2687
|
+
* @returns Promise containing the generated response
|
|
2688
|
+
*/
|
|
2689
|
+
generate(params) {
|
|
2690
|
+
return this.request(`/api/networks/v-next/${this.networkId}/generate`, {
|
|
1031
2691
|
method: "POST",
|
|
1032
2692
|
body: {
|
|
1033
|
-
|
|
1034
|
-
params
|
|
2693
|
+
...params,
|
|
2694
|
+
runtimeContext: parseClientRuntimeContext(params.runtimeContext)
|
|
1035
2695
|
}
|
|
1036
2696
|
});
|
|
1037
|
-
return response.result;
|
|
1038
2697
|
}
|
|
1039
2698
|
/**
|
|
1040
|
-
*
|
|
1041
|
-
* @param params -
|
|
1042
|
-
* @returns Promise containing the
|
|
2699
|
+
* Generates a response from the v-next network using multiple primitives
|
|
2700
|
+
* @param params - Generation parameters including message
|
|
2701
|
+
* @returns Promise containing the generated response
|
|
1043
2702
|
*/
|
|
1044
|
-
|
|
1045
|
-
return this.request(`/
|
|
2703
|
+
loop(params) {
|
|
2704
|
+
return this.request(`/api/networks/v-next/${this.networkId}/loop`, {
|
|
1046
2705
|
method: "POST",
|
|
1047
2706
|
body: {
|
|
1048
|
-
|
|
1049
|
-
params
|
|
2707
|
+
...params,
|
|
2708
|
+
runtimeContext: parseClientRuntimeContext(params.runtimeContext)
|
|
1050
2709
|
}
|
|
1051
2710
|
});
|
|
1052
2711
|
}
|
|
2712
|
+
async *streamProcessor(stream) {
|
|
2713
|
+
const reader = stream.getReader();
|
|
2714
|
+
let doneReading = false;
|
|
2715
|
+
let buffer = "";
|
|
2716
|
+
try {
|
|
2717
|
+
while (!doneReading) {
|
|
2718
|
+
const { done, value } = await reader.read();
|
|
2719
|
+
doneReading = done;
|
|
2720
|
+
if (done && !value) continue;
|
|
2721
|
+
try {
|
|
2722
|
+
const decoded = value ? new TextDecoder().decode(value) : "";
|
|
2723
|
+
const chunks = (buffer + decoded).split(RECORD_SEPARATOR4);
|
|
2724
|
+
buffer = chunks.pop() || "";
|
|
2725
|
+
for (const chunk of chunks) {
|
|
2726
|
+
if (chunk) {
|
|
2727
|
+
if (typeof chunk === "string") {
|
|
2728
|
+
try {
|
|
2729
|
+
const parsedChunk = JSON.parse(chunk);
|
|
2730
|
+
yield parsedChunk;
|
|
2731
|
+
} catch {
|
|
2732
|
+
}
|
|
2733
|
+
}
|
|
2734
|
+
}
|
|
2735
|
+
}
|
|
2736
|
+
} catch {
|
|
2737
|
+
}
|
|
2738
|
+
}
|
|
2739
|
+
if (buffer) {
|
|
2740
|
+
try {
|
|
2741
|
+
yield JSON.parse(buffer);
|
|
2742
|
+
} catch {
|
|
2743
|
+
}
|
|
2744
|
+
}
|
|
2745
|
+
} finally {
|
|
2746
|
+
reader.cancel().catch(() => {
|
|
2747
|
+
});
|
|
2748
|
+
}
|
|
2749
|
+
}
|
|
1053
2750
|
/**
|
|
1054
|
-
*
|
|
1055
|
-
* @param params -
|
|
1056
|
-
* @returns Promise containing the
|
|
2751
|
+
* Streams a response from the v-next network
|
|
2752
|
+
* @param params - Stream parameters including message
|
|
2753
|
+
* @returns Promise containing the results
|
|
1057
2754
|
*/
|
|
1058
|
-
async
|
|
1059
|
-
|
|
2755
|
+
async stream(params, onRecord) {
|
|
2756
|
+
const response = await this.request(`/api/networks/v-next/${this.networkId}/stream`, {
|
|
1060
2757
|
method: "POST",
|
|
1061
2758
|
body: {
|
|
1062
|
-
|
|
1063
|
-
params
|
|
2759
|
+
...params,
|
|
2760
|
+
runtimeContext: parseClientRuntimeContext(params.runtimeContext)
|
|
1064
2761
|
},
|
|
1065
2762
|
stream: true
|
|
1066
2763
|
});
|
|
1067
|
-
|
|
1068
|
-
};
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
* Retrieves details about this specific tool from the MCP server.
|
|
1081
|
-
* @returns Promise containing the tool's information (name, description, schema).
|
|
1082
|
-
*/
|
|
1083
|
-
details() {
|
|
1084
|
-
return this.request(`/api/mcp/${this.serverId}/tools/${this.toolId}`);
|
|
2764
|
+
if (!response.ok) {
|
|
2765
|
+
throw new Error(`Failed to stream vNext network: ${response.statusText}`);
|
|
2766
|
+
}
|
|
2767
|
+
if (!response.body) {
|
|
2768
|
+
throw new Error("Response body is null");
|
|
2769
|
+
}
|
|
2770
|
+
for await (const record of this.streamProcessor(response.body)) {
|
|
2771
|
+
if (typeof record === "string") {
|
|
2772
|
+
onRecord(JSON.parse(record));
|
|
2773
|
+
} else {
|
|
2774
|
+
onRecord(record);
|
|
2775
|
+
}
|
|
2776
|
+
}
|
|
1085
2777
|
}
|
|
1086
2778
|
/**
|
|
1087
|
-
*
|
|
1088
|
-
* @param params -
|
|
1089
|
-
* @returns Promise containing the
|
|
2779
|
+
* Streams a response from the v-next network loop
|
|
2780
|
+
* @param params - Stream parameters including message
|
|
2781
|
+
* @returns Promise containing the results
|
|
1090
2782
|
*/
|
|
1091
|
-
|
|
1092
|
-
const
|
|
1093
|
-
if (params.data !== void 0) body.data = params.data;
|
|
1094
|
-
if (params.runtimeContext !== void 0) {
|
|
1095
|
-
body.runtimeContext = params.runtimeContext;
|
|
1096
|
-
}
|
|
1097
|
-
return this.request(`/api/mcp/${this.serverId}/tools/${this.toolId}/execute`, {
|
|
2783
|
+
async loopStream(params, onRecord) {
|
|
2784
|
+
const response = await this.request(`/api/networks/v-next/${this.networkId}/loop-stream`, {
|
|
1098
2785
|
method: "POST",
|
|
1099
|
-
body:
|
|
2786
|
+
body: {
|
|
2787
|
+
...params,
|
|
2788
|
+
runtimeContext: parseClientRuntimeContext(params.runtimeContext)
|
|
2789
|
+
},
|
|
2790
|
+
stream: true
|
|
1100
2791
|
});
|
|
2792
|
+
if (!response.ok) {
|
|
2793
|
+
throw new Error(`Failed to stream vNext network loop: ${response.statusText}`);
|
|
2794
|
+
}
|
|
2795
|
+
if (!response.body) {
|
|
2796
|
+
throw new Error("Response body is null");
|
|
2797
|
+
}
|
|
2798
|
+
for await (const record of this.streamProcessor(response.body)) {
|
|
2799
|
+
if (typeof record === "string") {
|
|
2800
|
+
onRecord(JSON.parse(record));
|
|
2801
|
+
} else {
|
|
2802
|
+
onRecord(record);
|
|
2803
|
+
}
|
|
2804
|
+
}
|
|
1101
2805
|
}
|
|
1102
2806
|
};
|
|
1103
2807
|
|
|
1104
2808
|
// src/client.ts
|
|
1105
2809
|
var MastraClient = class extends BaseResource {
|
|
2810
|
+
observability;
|
|
1106
2811
|
constructor(options) {
|
|
1107
2812
|
super(options);
|
|
2813
|
+
this.observability = new Observability(options);
|
|
1108
2814
|
}
|
|
1109
2815
|
/**
|
|
1110
2816
|
* Retrieves all available agents
|
|
@@ -1113,21 +2819,6 @@ var MastraClient = class extends BaseResource {
|
|
|
1113
2819
|
getAgents() {
|
|
1114
2820
|
return this.request("/api/agents");
|
|
1115
2821
|
}
|
|
1116
|
-
async getAGUI({ resourceId }) {
|
|
1117
|
-
const agents = await this.getAgents();
|
|
1118
|
-
return Object.entries(agents).reduce(
|
|
1119
|
-
(acc, [agentId]) => {
|
|
1120
|
-
const agent = this.getAgent(agentId);
|
|
1121
|
-
acc[agentId] = new AGUIAdapter({
|
|
1122
|
-
agentId,
|
|
1123
|
-
agent,
|
|
1124
|
-
resourceId
|
|
1125
|
-
});
|
|
1126
|
-
return acc;
|
|
1127
|
-
},
|
|
1128
|
-
{}
|
|
1129
|
-
);
|
|
1130
|
-
}
|
|
1131
2822
|
/**
|
|
1132
2823
|
* Gets an agent instance by ID
|
|
1133
2824
|
* @param agentId - ID of the agent to retrieve
|
|
@@ -1178,6 +2869,48 @@ var MastraClient = class extends BaseResource {
|
|
|
1178
2869
|
getMemoryStatus(agentId) {
|
|
1179
2870
|
return this.request(`/api/memory/status?agentId=${agentId}`);
|
|
1180
2871
|
}
|
|
2872
|
+
/**
|
|
2873
|
+
* Retrieves memory threads for a resource
|
|
2874
|
+
* @param params - Parameters containing the resource ID
|
|
2875
|
+
* @returns Promise containing array of memory threads
|
|
2876
|
+
*/
|
|
2877
|
+
getNetworkMemoryThreads(params) {
|
|
2878
|
+
return this.request(`/api/memory/network/threads?resourceid=${params.resourceId}&networkId=${params.networkId}`);
|
|
2879
|
+
}
|
|
2880
|
+
/**
|
|
2881
|
+
* Creates a new memory thread
|
|
2882
|
+
* @param params - Parameters for creating the memory thread
|
|
2883
|
+
* @returns Promise containing the created memory thread
|
|
2884
|
+
*/
|
|
2885
|
+
createNetworkMemoryThread(params) {
|
|
2886
|
+
return this.request(`/api/memory/network/threads?networkId=${params.networkId}`, { method: "POST", body: params });
|
|
2887
|
+
}
|
|
2888
|
+
/**
|
|
2889
|
+
* Gets a memory thread instance by ID
|
|
2890
|
+
* @param threadId - ID of the memory thread to retrieve
|
|
2891
|
+
* @returns MemoryThread instance
|
|
2892
|
+
*/
|
|
2893
|
+
getNetworkMemoryThread(threadId, networkId) {
|
|
2894
|
+
return new NetworkMemoryThread(this.options, threadId, networkId);
|
|
2895
|
+
}
|
|
2896
|
+
/**
|
|
2897
|
+
* Saves messages to memory
|
|
2898
|
+
* @param params - Parameters containing messages to save
|
|
2899
|
+
* @returns Promise containing the saved messages
|
|
2900
|
+
*/
|
|
2901
|
+
saveNetworkMessageToMemory(params) {
|
|
2902
|
+
return this.request(`/api/memory/network/save-messages?networkId=${params.networkId}`, {
|
|
2903
|
+
method: "POST",
|
|
2904
|
+
body: params
|
|
2905
|
+
});
|
|
2906
|
+
}
|
|
2907
|
+
/**
|
|
2908
|
+
* Gets the status of the memory system
|
|
2909
|
+
* @returns Promise containing memory system status
|
|
2910
|
+
*/
|
|
2911
|
+
getNetworkMemoryStatus(networkId) {
|
|
2912
|
+
return this.request(`/api/memory/network/status?networkId=${networkId}`);
|
|
2913
|
+
}
|
|
1181
2914
|
/**
|
|
1182
2915
|
* Retrieves all available tools
|
|
1183
2916
|
* @returns Promise containing map of tool IDs to tool details
|
|
@@ -1193,6 +2926,21 @@ var MastraClient = class extends BaseResource {
|
|
|
1193
2926
|
getTool(toolId) {
|
|
1194
2927
|
return new Tool(this.options, toolId);
|
|
1195
2928
|
}
|
|
2929
|
+
/**
|
|
2930
|
+
* Retrieves all available legacy workflows
|
|
2931
|
+
* @returns Promise containing map of legacy workflow IDs to legacy workflow details
|
|
2932
|
+
*/
|
|
2933
|
+
getLegacyWorkflows() {
|
|
2934
|
+
return this.request("/api/workflows/legacy");
|
|
2935
|
+
}
|
|
2936
|
+
/**
|
|
2937
|
+
* Gets a legacy workflow instance by ID
|
|
2938
|
+
* @param workflowId - ID of the legacy workflow to retrieve
|
|
2939
|
+
* @returns Legacy Workflow instance
|
|
2940
|
+
*/
|
|
2941
|
+
getLegacyWorkflow(workflowId) {
|
|
2942
|
+
return new LegacyWorkflow(this.options, workflowId);
|
|
2943
|
+
}
|
|
1196
2944
|
/**
|
|
1197
2945
|
* Retrieves all available workflows
|
|
1198
2946
|
* @returns Promise containing map of workflow IDs to workflow details
|
|
@@ -1209,19 +2957,18 @@ var MastraClient = class extends BaseResource {
|
|
|
1209
2957
|
return new Workflow(this.options, workflowId);
|
|
1210
2958
|
}
|
|
1211
2959
|
/**
|
|
1212
|
-
*
|
|
1213
|
-
* @returns Promise containing map of
|
|
2960
|
+
* Gets all available agent builder actions
|
|
2961
|
+
* @returns Promise containing map of action IDs to action details
|
|
1214
2962
|
*/
|
|
1215
|
-
|
|
1216
|
-
return this.request("/api/
|
|
2963
|
+
getAgentBuilderActions() {
|
|
2964
|
+
return this.request("/api/agent-builder/");
|
|
1217
2965
|
}
|
|
1218
2966
|
/**
|
|
1219
|
-
* Gets
|
|
1220
|
-
* @
|
|
1221
|
-
* @returns vNext Workflow instance
|
|
2967
|
+
* Gets an agent builder instance for executing agent-builder workflows
|
|
2968
|
+
* @returns AgentBuilder instance
|
|
1222
2969
|
*/
|
|
1223
|
-
|
|
1224
|
-
return new
|
|
2970
|
+
getAgentBuilderAction(actionId) {
|
|
2971
|
+
return new AgentBuilder(this.options, actionId);
|
|
1225
2972
|
}
|
|
1226
2973
|
/**
|
|
1227
2974
|
* Gets a vector instance by name
|
|
@@ -1237,7 +2984,41 @@ var MastraClient = class extends BaseResource {
|
|
|
1237
2984
|
* @returns Promise containing array of log messages
|
|
1238
2985
|
*/
|
|
1239
2986
|
getLogs(params) {
|
|
1240
|
-
|
|
2987
|
+
const { transportId, fromDate, toDate, logLevel, filters, page, perPage } = params;
|
|
2988
|
+
const _filters = filters ? Object.entries(filters).map(([key, value]) => `${key}:${value}`) : [];
|
|
2989
|
+
const searchParams = new URLSearchParams();
|
|
2990
|
+
if (transportId) {
|
|
2991
|
+
searchParams.set("transportId", transportId);
|
|
2992
|
+
}
|
|
2993
|
+
if (fromDate) {
|
|
2994
|
+
searchParams.set("fromDate", fromDate.toISOString());
|
|
2995
|
+
}
|
|
2996
|
+
if (toDate) {
|
|
2997
|
+
searchParams.set("toDate", toDate.toISOString());
|
|
2998
|
+
}
|
|
2999
|
+
if (logLevel) {
|
|
3000
|
+
searchParams.set("logLevel", logLevel);
|
|
3001
|
+
}
|
|
3002
|
+
if (page) {
|
|
3003
|
+
searchParams.set("page", String(page));
|
|
3004
|
+
}
|
|
3005
|
+
if (perPage) {
|
|
3006
|
+
searchParams.set("perPage", String(perPage));
|
|
3007
|
+
}
|
|
3008
|
+
if (_filters) {
|
|
3009
|
+
if (Array.isArray(_filters)) {
|
|
3010
|
+
for (const filter of _filters) {
|
|
3011
|
+
searchParams.append("filters", filter);
|
|
3012
|
+
}
|
|
3013
|
+
} else {
|
|
3014
|
+
searchParams.set("filters", _filters);
|
|
3015
|
+
}
|
|
3016
|
+
}
|
|
3017
|
+
if (searchParams.size) {
|
|
3018
|
+
return this.request(`/api/logs?${searchParams}`);
|
|
3019
|
+
} else {
|
|
3020
|
+
return this.request(`/api/logs`);
|
|
3021
|
+
}
|
|
1241
3022
|
}
|
|
1242
3023
|
/**
|
|
1243
3024
|
* Gets logs for a specific run
|
|
@@ -1245,7 +3026,44 @@ var MastraClient = class extends BaseResource {
|
|
|
1245
3026
|
* @returns Promise containing array of log messages
|
|
1246
3027
|
*/
|
|
1247
3028
|
getLogForRun(params) {
|
|
1248
|
-
|
|
3029
|
+
const { runId, transportId, fromDate, toDate, logLevel, filters, page, perPage } = params;
|
|
3030
|
+
const _filters = filters ? Object.entries(filters).map(([key, value]) => `${key}:${value}`) : [];
|
|
3031
|
+
const searchParams = new URLSearchParams();
|
|
3032
|
+
if (runId) {
|
|
3033
|
+
searchParams.set("runId", runId);
|
|
3034
|
+
}
|
|
3035
|
+
if (transportId) {
|
|
3036
|
+
searchParams.set("transportId", transportId);
|
|
3037
|
+
}
|
|
3038
|
+
if (fromDate) {
|
|
3039
|
+
searchParams.set("fromDate", fromDate.toISOString());
|
|
3040
|
+
}
|
|
3041
|
+
if (toDate) {
|
|
3042
|
+
searchParams.set("toDate", toDate.toISOString());
|
|
3043
|
+
}
|
|
3044
|
+
if (logLevel) {
|
|
3045
|
+
searchParams.set("logLevel", logLevel);
|
|
3046
|
+
}
|
|
3047
|
+
if (page) {
|
|
3048
|
+
searchParams.set("page", String(page));
|
|
3049
|
+
}
|
|
3050
|
+
if (perPage) {
|
|
3051
|
+
searchParams.set("perPage", String(perPage));
|
|
3052
|
+
}
|
|
3053
|
+
if (_filters) {
|
|
3054
|
+
if (Array.isArray(_filters)) {
|
|
3055
|
+
for (const filter of _filters) {
|
|
3056
|
+
searchParams.append("filters", filter);
|
|
3057
|
+
}
|
|
3058
|
+
} else {
|
|
3059
|
+
searchParams.set("filters", _filters);
|
|
3060
|
+
}
|
|
3061
|
+
}
|
|
3062
|
+
if (searchParams.size) {
|
|
3063
|
+
return this.request(`/api/logs/${runId}?${searchParams}`);
|
|
3064
|
+
} else {
|
|
3065
|
+
return this.request(`/api/logs/${runId}`);
|
|
3066
|
+
}
|
|
1249
3067
|
}
|
|
1250
3068
|
/**
|
|
1251
3069
|
* List of all log transports
|
|
@@ -1303,6 +3121,13 @@ var MastraClient = class extends BaseResource {
|
|
|
1303
3121
|
getNetworks() {
|
|
1304
3122
|
return this.request("/api/networks");
|
|
1305
3123
|
}
|
|
3124
|
+
/**
|
|
3125
|
+
* Retrieves all available vNext networks
|
|
3126
|
+
* @returns Promise containing map of vNext network IDs to vNext network details
|
|
3127
|
+
*/
|
|
3128
|
+
getVNextNetworks() {
|
|
3129
|
+
return this.request("/api/networks/v-next");
|
|
3130
|
+
}
|
|
1306
3131
|
/**
|
|
1307
3132
|
* Gets a network instance by ID
|
|
1308
3133
|
* @param networkId - ID of the network to retrieve
|
|
@@ -1311,6 +3136,14 @@ var MastraClient = class extends BaseResource {
|
|
|
1311
3136
|
getNetwork(networkId) {
|
|
1312
3137
|
return new Network(this.options, networkId);
|
|
1313
3138
|
}
|
|
3139
|
+
/**
|
|
3140
|
+
* Gets a vNext network instance by ID
|
|
3141
|
+
* @param networkId - ID of the vNext network to retrieve
|
|
3142
|
+
* @returns vNext Network instance
|
|
3143
|
+
*/
|
|
3144
|
+
getVNextNetwork(networkId) {
|
|
3145
|
+
return new VNextNetwork(this.options, networkId);
|
|
3146
|
+
}
|
|
1314
3147
|
/**
|
|
1315
3148
|
* Retrieves a list of available MCP servers.
|
|
1316
3149
|
* @param params - Optional parameters for pagination (limit, offset).
|
|
@@ -1367,6 +3200,134 @@ var MastraClient = class extends BaseResource {
|
|
|
1367
3200
|
getA2A(agentId) {
|
|
1368
3201
|
return new A2A(this.options, agentId);
|
|
1369
3202
|
}
|
|
3203
|
+
/**
|
|
3204
|
+
* Retrieves the working memory for a specific thread (optionally resource-scoped).
|
|
3205
|
+
* @param agentId - ID of the agent.
|
|
3206
|
+
* @param threadId - ID of the thread.
|
|
3207
|
+
* @param resourceId - Optional ID of the resource.
|
|
3208
|
+
* @returns Working memory for the specified thread or resource.
|
|
3209
|
+
*/
|
|
3210
|
+
getWorkingMemory({
|
|
3211
|
+
agentId,
|
|
3212
|
+
threadId,
|
|
3213
|
+
resourceId
|
|
3214
|
+
}) {
|
|
3215
|
+
return this.request(`/api/memory/threads/${threadId}/working-memory?agentId=${agentId}&resourceId=${resourceId}`);
|
|
3216
|
+
}
|
|
3217
|
+
/**
|
|
3218
|
+
* Updates the working memory for a specific thread (optionally resource-scoped).
|
|
3219
|
+
* @param agentId - ID of the agent.
|
|
3220
|
+
* @param threadId - ID of the thread.
|
|
3221
|
+
* @param workingMemory - The new working memory content.
|
|
3222
|
+
* @param resourceId - Optional ID of the resource.
|
|
3223
|
+
*/
|
|
3224
|
+
updateWorkingMemory({
|
|
3225
|
+
agentId,
|
|
3226
|
+
threadId,
|
|
3227
|
+
workingMemory,
|
|
3228
|
+
resourceId
|
|
3229
|
+
}) {
|
|
3230
|
+
return this.request(`/api/memory/threads/${threadId}/working-memory?agentId=${agentId}`, {
|
|
3231
|
+
method: "POST",
|
|
3232
|
+
body: {
|
|
3233
|
+
workingMemory,
|
|
3234
|
+
resourceId
|
|
3235
|
+
}
|
|
3236
|
+
});
|
|
3237
|
+
}
|
|
3238
|
+
/**
|
|
3239
|
+
* Retrieves all available scorers
|
|
3240
|
+
* @returns Promise containing list of available scorers
|
|
3241
|
+
*/
|
|
3242
|
+
getScorers() {
|
|
3243
|
+
return this.request("/api/scores/scorers");
|
|
3244
|
+
}
|
|
3245
|
+
/**
|
|
3246
|
+
* Retrieves a scorer by ID
|
|
3247
|
+
* @param scorerId - ID of the scorer to retrieve
|
|
3248
|
+
* @returns Promise containing the scorer
|
|
3249
|
+
*/
|
|
3250
|
+
getScorer(scorerId) {
|
|
3251
|
+
return this.request(`/api/scores/scorers/${scorerId}`);
|
|
3252
|
+
}
|
|
3253
|
+
getScoresByScorerId(params) {
|
|
3254
|
+
const { page, perPage, scorerId, entityId, entityType } = params;
|
|
3255
|
+
const searchParams = new URLSearchParams();
|
|
3256
|
+
if (entityId) {
|
|
3257
|
+
searchParams.set("entityId", entityId);
|
|
3258
|
+
}
|
|
3259
|
+
if (entityType) {
|
|
3260
|
+
searchParams.set("entityType", entityType);
|
|
3261
|
+
}
|
|
3262
|
+
if (page !== void 0) {
|
|
3263
|
+
searchParams.set("page", String(page));
|
|
3264
|
+
}
|
|
3265
|
+
if (perPage !== void 0) {
|
|
3266
|
+
searchParams.set("perPage", String(perPage));
|
|
3267
|
+
}
|
|
3268
|
+
const queryString = searchParams.toString();
|
|
3269
|
+
return this.request(`/api/scores/scorer/${scorerId}${queryString ? `?${queryString}` : ""}`);
|
|
3270
|
+
}
|
|
3271
|
+
/**
|
|
3272
|
+
* Retrieves scores by run ID
|
|
3273
|
+
* @param params - Parameters containing run ID and pagination options
|
|
3274
|
+
* @returns Promise containing scores and pagination info
|
|
3275
|
+
*/
|
|
3276
|
+
getScoresByRunId(params) {
|
|
3277
|
+
const { runId, page, perPage } = params;
|
|
3278
|
+
const searchParams = new URLSearchParams();
|
|
3279
|
+
if (page !== void 0) {
|
|
3280
|
+
searchParams.set("page", String(page));
|
|
3281
|
+
}
|
|
3282
|
+
if (perPage !== void 0) {
|
|
3283
|
+
searchParams.set("perPage", String(perPage));
|
|
3284
|
+
}
|
|
3285
|
+
const queryString = searchParams.toString();
|
|
3286
|
+
return this.request(`/api/scores/run/${runId}${queryString ? `?${queryString}` : ""}`);
|
|
3287
|
+
}
|
|
3288
|
+
/**
|
|
3289
|
+
* Retrieves scores by entity ID and type
|
|
3290
|
+
* @param params - Parameters containing entity ID, type, and pagination options
|
|
3291
|
+
* @returns Promise containing scores and pagination info
|
|
3292
|
+
*/
|
|
3293
|
+
getScoresByEntityId(params) {
|
|
3294
|
+
const { entityId, entityType, page, perPage } = params;
|
|
3295
|
+
const searchParams = new URLSearchParams();
|
|
3296
|
+
if (page !== void 0) {
|
|
3297
|
+
searchParams.set("page", String(page));
|
|
3298
|
+
}
|
|
3299
|
+
if (perPage !== void 0) {
|
|
3300
|
+
searchParams.set("perPage", String(perPage));
|
|
3301
|
+
}
|
|
3302
|
+
const queryString = searchParams.toString();
|
|
3303
|
+
return this.request(`/api/scores/entity/${entityType}/${entityId}${queryString ? `?${queryString}` : ""}`);
|
|
3304
|
+
}
|
|
3305
|
+
/**
|
|
3306
|
+
* Saves a score
|
|
3307
|
+
* @param params - Parameters containing the score data to save
|
|
3308
|
+
* @returns Promise containing the saved score
|
|
3309
|
+
*/
|
|
3310
|
+
saveScore(params) {
|
|
3311
|
+
return this.request("/api/scores", {
|
|
3312
|
+
method: "POST",
|
|
3313
|
+
body: params
|
|
3314
|
+
});
|
|
3315
|
+
}
|
|
3316
|
+
/**
|
|
3317
|
+
* Retrieves model providers with available keys
|
|
3318
|
+
* @returns Promise containing model providers with available keys
|
|
3319
|
+
*/
|
|
3320
|
+
getModelProviders() {
|
|
3321
|
+
return this.request(`/api/model-providers`);
|
|
3322
|
+
}
|
|
3323
|
+
getAITrace(traceId) {
|
|
3324
|
+
return this.observability.getTrace(traceId);
|
|
3325
|
+
}
|
|
3326
|
+
getAITraces(params) {
|
|
3327
|
+
return this.observability.getTraces(params);
|
|
3328
|
+
}
|
|
1370
3329
|
};
|
|
1371
3330
|
|
|
1372
3331
|
exports.MastraClient = MastraClient;
|
|
3332
|
+
//# sourceMappingURL=index.cjs.map
|
|
3333
|
+
//# sourceMappingURL=index.cjs.map
|