@mastra/client-js 0.16.9 → 0.16.10
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 +18 -0
- package/dist/index.cjs +65 -44
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +65 -44
- package/dist/index.js.map +1 -1
- package/dist/resources/agent.d.ts +1 -1
- package/dist/resources/agent.d.ts.map +1 -1
- package/dist/utils/process-mastra-stream.d.ts.map +1 -1
- package/package.json +4 -4
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,23 @@
|
|
|
1
1
|
# @mastra/client-js
|
|
2
2
|
|
|
3
|
+
## 0.16.10
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Fix clientTools execution in client js ([#10051](https://github.com/mastra-ai/mastra/pull/10051))
|
|
8
|
+
|
|
9
|
+
- Updated dependencies [[`0a0aa87`](https://github.com/mastra-ai/mastra/commit/0a0aa87910dd9234ae11e8146fbf54d71f0b1516), [`56bbbd0`](https://github.com/mastra-ai/mastra/commit/56bbbd0eb4510455ff03d6bf2827fdbd307938be), [`d576fd8`](https://github.com/mastra-ai/mastra/commit/d576fd8f2a3c61bcf2f7d5d2bdfb496d442c46c2), [`5e48406`](https://github.com/mastra-ai/mastra/commit/5e48406766fa94e2b7c56b70fb7d6068cf7f3989), [`7fcce62`](https://github.com/mastra-ai/mastra/commit/7fcce62880c3525fbf752d59c0ac2c478cffe024), [`16a324f`](https://github.com/mastra-ai/mastra/commit/16a324f8c30a07d0d899bc2e4e7998c6b40a4cb6), [`26aee16`](https://github.com/mastra-ai/mastra/commit/26aee160149e7acb84a533bf45631aaed6dd7077), [`b063a81`](https://github.com/mastra-ai/mastra/commit/b063a8144176915a766ea15888e1e8a06a020776), [`5ff9462`](https://github.com/mastra-ai/mastra/commit/5ff9462691c80a6841b014bcc68f6a85c3fd3fbf)]:
|
|
10
|
+
- @mastra/core@0.24.1
|
|
11
|
+
|
|
12
|
+
## 0.16.10-alpha.0
|
|
13
|
+
|
|
14
|
+
### Patch Changes
|
|
15
|
+
|
|
16
|
+
- Fix clientTools execution in client js ([#10051](https://github.com/mastra-ai/mastra/pull/10051))
|
|
17
|
+
|
|
18
|
+
- Updated dependencies [[`0a0aa87`](https://github.com/mastra-ai/mastra/commit/0a0aa87910dd9234ae11e8146fbf54d71f0b1516), [`56bbbd0`](https://github.com/mastra-ai/mastra/commit/56bbbd0eb4510455ff03d6bf2827fdbd307938be), [`d576fd8`](https://github.com/mastra-ai/mastra/commit/d576fd8f2a3c61bcf2f7d5d2bdfb496d442c46c2), [`5e48406`](https://github.com/mastra-ai/mastra/commit/5e48406766fa94e2b7c56b70fb7d6068cf7f3989), [`7fcce62`](https://github.com/mastra-ai/mastra/commit/7fcce62880c3525fbf752d59c0ac2c478cffe024), [`16a324f`](https://github.com/mastra-ai/mastra/commit/16a324f8c30a07d0d899bc2e4e7998c6b40a4cb6), [`26aee16`](https://github.com/mastra-ai/mastra/commit/26aee160149e7acb84a533bf45631aaed6dd7077), [`b063a81`](https://github.com/mastra-ai/mastra/commit/b063a8144176915a766ea15888e1e8a06a020776), [`5ff9462`](https://github.com/mastra-ai/mastra/commit/5ff9462691c80a6841b014bcc68f6a85c3fd3fbf)]:
|
|
19
|
+
- @mastra/core@0.24.1-alpha.0
|
|
20
|
+
|
|
3
21
|
## 0.16.9
|
|
4
22
|
|
|
5
23
|
### Patch Changes
|
package/dist/index.cjs
CHANGED
|
@@ -98,7 +98,6 @@ async function sharedProcessMastraStream({
|
|
|
98
98
|
if (line.startsWith("data: ")) {
|
|
99
99
|
const data = line.slice(6);
|
|
100
100
|
if (data === "[DONE]") {
|
|
101
|
-
console.info("\u{1F3C1} Stream finished");
|
|
102
101
|
return;
|
|
103
102
|
}
|
|
104
103
|
let json;
|
|
@@ -215,11 +214,11 @@ async function executeToolCallAndRespond({
|
|
|
215
214
|
return response;
|
|
216
215
|
}
|
|
217
216
|
for (const toolCall of toolCalls) {
|
|
218
|
-
const clientTool = params.clientTools?.[toolCall.toolName];
|
|
217
|
+
const clientTool = params.clientTools?.[toolCall.payload.toolName];
|
|
219
218
|
if (clientTool && clientTool.execute) {
|
|
220
219
|
const result = await clientTool.execute(
|
|
221
220
|
{
|
|
222
|
-
context: toolCall?.args,
|
|
221
|
+
context: toolCall?.payload.args,
|
|
223
222
|
runId,
|
|
224
223
|
resourceId,
|
|
225
224
|
threadId,
|
|
@@ -230,7 +229,7 @@ async function executeToolCallAndRespond({
|
|
|
230
229
|
},
|
|
231
230
|
{
|
|
232
231
|
messages: response.messages,
|
|
233
|
-
toolCallId: toolCall?.toolCallId
|
|
232
|
+
toolCallId: toolCall?.payload.toolCallId
|
|
234
233
|
}
|
|
235
234
|
);
|
|
236
235
|
const updatedMessages = [
|
|
@@ -240,8 +239,8 @@ async function executeToolCallAndRespond({
|
|
|
240
239
|
content: [
|
|
241
240
|
{
|
|
242
241
|
type: "tool-result",
|
|
243
|
-
toolCallId: toolCall.toolCallId,
|
|
244
|
-
toolName: toolCall.toolName,
|
|
242
|
+
toolCallId: toolCall.payload.toolCallId,
|
|
243
|
+
toolName: toolCall.payload.toolName,
|
|
245
244
|
result
|
|
246
245
|
}
|
|
247
246
|
]
|
|
@@ -254,6 +253,7 @@ async function executeToolCallAndRespond({
|
|
|
254
253
|
}
|
|
255
254
|
}
|
|
256
255
|
}
|
|
256
|
+
return response;
|
|
257
257
|
}
|
|
258
258
|
var AgentVoice = class extends BaseResource {
|
|
259
259
|
constructor(options, agentId) {
|
|
@@ -986,7 +986,7 @@ var Agent = class extends BaseResource {
|
|
|
986
986
|
});
|
|
987
987
|
onFinish?.({ message, finishReason, usage });
|
|
988
988
|
}
|
|
989
|
-
async processStreamResponse(processedParams,
|
|
989
|
+
async processStreamResponse(processedParams, controller, route = "stream") {
|
|
990
990
|
const response = await this.request(`/api/agents/${this.agentId}/${route}`, {
|
|
991
991
|
method: "POST",
|
|
992
992
|
body: processedParams,
|
|
@@ -998,29 +998,30 @@ var Agent = class extends BaseResource {
|
|
|
998
998
|
try {
|
|
999
999
|
let toolCalls = [];
|
|
1000
1000
|
let messages = [];
|
|
1001
|
-
const [
|
|
1002
|
-
|
|
1001
|
+
const [streamForController, streamForProcessing] = response.body.tee();
|
|
1002
|
+
const pipePromise = streamForController.pipeTo(
|
|
1003
1003
|
new WritableStream({
|
|
1004
1004
|
async write(chunk) {
|
|
1005
|
-
let writer;
|
|
1006
1005
|
try {
|
|
1007
|
-
writer = writable.getWriter();
|
|
1008
1006
|
const text = new TextDecoder().decode(chunk);
|
|
1009
1007
|
const lines = text.split("\n\n");
|
|
1010
|
-
const readableLines = lines.filter((line) => line !== "[DONE]").join("\n\n");
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1008
|
+
const readableLines = lines.filter((line) => line.trim() !== "[DONE]" && line.trim() !== "data: [DONE]").join("\n\n");
|
|
1009
|
+
if (readableLines) {
|
|
1010
|
+
const encoded = new TextEncoder().encode(readableLines);
|
|
1011
|
+
controller.enqueue(encoded);
|
|
1012
|
+
}
|
|
1013
|
+
} catch (error) {
|
|
1014
|
+
console.error("Error enqueueing to controller:", error);
|
|
1015
|
+
controller.enqueue(chunk);
|
|
1016
1016
|
}
|
|
1017
1017
|
}
|
|
1018
|
-
})
|
|
1019
|
-
{
|
|
1020
|
-
preventClose: true
|
|
1021
|
-
}
|
|
1018
|
+
})
|
|
1022
1019
|
).catch((error) => {
|
|
1023
|
-
console.error("Error piping to
|
|
1020
|
+
console.error("Error piping to controller:", error);
|
|
1021
|
+
try {
|
|
1022
|
+
controller.close();
|
|
1023
|
+
} catch {
|
|
1024
|
+
}
|
|
1024
1025
|
});
|
|
1025
1026
|
this.processChatResponse_vNext({
|
|
1026
1027
|
stream: streamForProcessing,
|
|
@@ -1080,31 +1081,36 @@ var Agent = class extends BaseResource {
|
|
|
1080
1081
|
toolInvocation.result = result;
|
|
1081
1082
|
}
|
|
1082
1083
|
const updatedMessages = lastMessage != null ? [...messages.filter((m) => m.id !== lastMessage.id), lastMessage] : [...messages];
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
})
|
|
1084
|
+
try {
|
|
1085
|
+
await this.processStreamResponse(
|
|
1086
|
+
{
|
|
1087
|
+
...processedParams,
|
|
1088
|
+
messages: updatedMessages
|
|
1089
|
+
},
|
|
1090
|
+
controller
|
|
1091
|
+
);
|
|
1092
|
+
} catch (error) {
|
|
1093
|
+
console.error("Error processing recursive stream response:", error);
|
|
1094
|
+
}
|
|
1092
1095
|
}
|
|
1093
1096
|
}
|
|
1094
1097
|
if (!shouldExecuteClientTool) {
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
}, 0);
|
|
1098
|
+
await pipePromise;
|
|
1099
|
+
controller.close();
|
|
1098
1100
|
}
|
|
1099
1101
|
} else {
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
}, 0);
|
|
1102
|
+
await pipePromise;
|
|
1103
|
+
controller.close();
|
|
1103
1104
|
}
|
|
1104
1105
|
},
|
|
1105
1106
|
lastMessage: void 0
|
|
1106
|
-
}).catch((error) => {
|
|
1107
|
+
}).catch(async (error) => {
|
|
1107
1108
|
console.error("Error processing stream response:", error);
|
|
1109
|
+
try {
|
|
1110
|
+
await pipePromise;
|
|
1111
|
+
controller.close();
|
|
1112
|
+
} catch {
|
|
1113
|
+
}
|
|
1108
1114
|
});
|
|
1109
1115
|
} catch (error) {
|
|
1110
1116
|
console.error("Error processing stream response:", error);
|
|
@@ -1155,8 +1161,13 @@ var Agent = class extends BaseResource {
|
|
|
1155
1161
|
schema: zodToJsonSchema(params.structuredOutput.schema)
|
|
1156
1162
|
} : void 0
|
|
1157
1163
|
};
|
|
1158
|
-
|
|
1159
|
-
const
|
|
1164
|
+
let readableController;
|
|
1165
|
+
const readable = new ReadableStream({
|
|
1166
|
+
start(controller) {
|
|
1167
|
+
readableController = controller;
|
|
1168
|
+
}
|
|
1169
|
+
});
|
|
1170
|
+
const response = await this.processStreamResponse(processedParams, readableController);
|
|
1160
1171
|
const streamResponse = new Response(readable, {
|
|
1161
1172
|
status: response.status,
|
|
1162
1173
|
statusText: response.statusText,
|
|
@@ -1173,8 +1184,13 @@ var Agent = class extends BaseResource {
|
|
|
1173
1184
|
return streamResponse;
|
|
1174
1185
|
}
|
|
1175
1186
|
async approveToolCall(params) {
|
|
1176
|
-
|
|
1177
|
-
const
|
|
1187
|
+
let readableController;
|
|
1188
|
+
const readable = new ReadableStream({
|
|
1189
|
+
start(controller) {
|
|
1190
|
+
readableController = controller;
|
|
1191
|
+
}
|
|
1192
|
+
});
|
|
1193
|
+
const response = await this.processStreamResponse(params, readableController, "approve-tool-call");
|
|
1178
1194
|
const streamResponse = new Response(readable, {
|
|
1179
1195
|
status: response.status,
|
|
1180
1196
|
statusText: response.statusText,
|
|
@@ -1191,8 +1207,13 @@ var Agent = class extends BaseResource {
|
|
|
1191
1207
|
return streamResponse;
|
|
1192
1208
|
}
|
|
1193
1209
|
async declineToolCall(params) {
|
|
1194
|
-
|
|
1195
|
-
const
|
|
1210
|
+
let readableController;
|
|
1211
|
+
const readable = new ReadableStream({
|
|
1212
|
+
start(controller) {
|
|
1213
|
+
readableController = controller;
|
|
1214
|
+
}
|
|
1215
|
+
});
|
|
1216
|
+
const response = await this.processStreamResponse(params, readableController, "decline-tool-call");
|
|
1196
1217
|
const streamResponse = new Response(readable, {
|
|
1197
1218
|
status: response.status,
|
|
1198
1219
|
statusText: response.statusText,
|