@mastra/client-js 1.0.0-beta.0 → 1.0.0-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +16 -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,21 @@
|
|
|
1
1
|
# @mastra/client-js
|
|
2
2
|
|
|
3
|
+
## 1.0.0-beta.2
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Updated dependencies [[`465ac05`](https://github.com/mastra-ai/mastra/commit/465ac0526a91d175542091c675181f1a96c98c46)]:
|
|
8
|
+
- @mastra/core@1.0.0-beta.2
|
|
9
|
+
|
|
10
|
+
## 1.0.0-beta.1
|
|
11
|
+
|
|
12
|
+
### Patch Changes
|
|
13
|
+
|
|
14
|
+
- Fix clientTools execution in client js ([#9880](https://github.com/mastra-ai/mastra/pull/9880))
|
|
15
|
+
|
|
16
|
+
- Updated dependencies [[`910db9e`](https://github.com/mastra-ai/mastra/commit/910db9e0312888495eb5617b567f247d03303814), [`e7266a2`](https://github.com/mastra-ai/mastra/commit/e7266a278db02035c97a5e9cd9d1669a6b7a535d)]:
|
|
17
|
+
- @mastra/core@1.0.0-beta.1
|
|
18
|
+
|
|
3
19
|
## 1.0.0-beta.0
|
|
4
20
|
|
|
5
21
|
### Major 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;
|
|
@@ -214,14 +213,14 @@ async function executeToolCallAndRespond({
|
|
|
214
213
|
return response;
|
|
215
214
|
}
|
|
216
215
|
for (const toolCall of toolCalls) {
|
|
217
|
-
const clientTool = params.clientTools?.[toolCall.toolName];
|
|
216
|
+
const clientTool = params.clientTools?.[toolCall.payload.toolName];
|
|
218
217
|
if (clientTool && clientTool.execute) {
|
|
219
|
-
const result = await clientTool.execute(toolCall?.args, {
|
|
218
|
+
const result = await clientTool.execute(toolCall?.payload.args, {
|
|
220
219
|
requestContext,
|
|
221
220
|
tracingContext: { currentSpan: void 0 },
|
|
222
221
|
agent: {
|
|
223
222
|
messages: response.messages,
|
|
224
|
-
toolCallId: toolCall?.toolCallId,
|
|
223
|
+
toolCallId: toolCall?.payload.toolCallId,
|
|
225
224
|
suspend: async () => {
|
|
226
225
|
},
|
|
227
226
|
threadId,
|
|
@@ -235,8 +234,8 @@ async function executeToolCallAndRespond({
|
|
|
235
234
|
content: [
|
|
236
235
|
{
|
|
237
236
|
type: "tool-result",
|
|
238
|
-
toolCallId: toolCall.toolCallId,
|
|
239
|
-
toolName: toolCall.toolName,
|
|
237
|
+
toolCallId: toolCall.payload.toolCallId,
|
|
238
|
+
toolName: toolCall.payload.toolName,
|
|
240
239
|
result
|
|
241
240
|
}
|
|
242
241
|
]
|
|
@@ -249,6 +248,7 @@ async function executeToolCallAndRespond({
|
|
|
249
248
|
}
|
|
250
249
|
}
|
|
251
250
|
}
|
|
251
|
+
return response;
|
|
252
252
|
}
|
|
253
253
|
var AgentVoice = class extends BaseResource {
|
|
254
254
|
constructor(options, agentId) {
|
|
@@ -981,7 +981,7 @@ var Agent = class extends BaseResource {
|
|
|
981
981
|
});
|
|
982
982
|
onFinish?.({ message, finishReason, usage });
|
|
983
983
|
}
|
|
984
|
-
async processStreamResponse(processedParams,
|
|
984
|
+
async processStreamResponse(processedParams, controller, route = "stream") {
|
|
985
985
|
const response = await this.request(`/api/agents/${this.agentId}/${route}`, {
|
|
986
986
|
method: "POST",
|
|
987
987
|
body: processedParams,
|
|
@@ -993,29 +993,30 @@ var Agent = class extends BaseResource {
|
|
|
993
993
|
try {
|
|
994
994
|
let toolCalls = [];
|
|
995
995
|
let messages = [];
|
|
996
|
-
const [
|
|
997
|
-
|
|
996
|
+
const [streamForController, streamForProcessing] = response.body.tee();
|
|
997
|
+
const pipePromise = streamForController.pipeTo(
|
|
998
998
|
new WritableStream({
|
|
999
999
|
async write(chunk) {
|
|
1000
|
-
let writer;
|
|
1001
1000
|
try {
|
|
1002
|
-
writer = writable.getWriter();
|
|
1003
1001
|
const text = new TextDecoder().decode(chunk);
|
|
1004
1002
|
const lines = text.split("\n\n");
|
|
1005
|
-
const readableLines = lines.filter((line) => line !== "[DONE]").join("\n\n");
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1003
|
+
const readableLines = lines.filter((line) => line.trim() !== "[DONE]" && line.trim() !== "data: [DONE]").join("\n\n");
|
|
1004
|
+
if (readableLines) {
|
|
1005
|
+
const encoded = new TextEncoder().encode(readableLines);
|
|
1006
|
+
controller.enqueue(encoded);
|
|
1007
|
+
}
|
|
1008
|
+
} catch (error) {
|
|
1009
|
+
console.error("Error enqueueing to controller:", error);
|
|
1010
|
+
controller.enqueue(chunk);
|
|
1011
1011
|
}
|
|
1012
1012
|
}
|
|
1013
|
-
})
|
|
1014
|
-
{
|
|
1015
|
-
preventClose: true
|
|
1016
|
-
}
|
|
1013
|
+
})
|
|
1017
1014
|
).catch((error) => {
|
|
1018
|
-
console.error("Error piping to
|
|
1015
|
+
console.error("Error piping to controller:", error);
|
|
1016
|
+
try {
|
|
1017
|
+
controller.close();
|
|
1018
|
+
} catch {
|
|
1019
|
+
}
|
|
1019
1020
|
});
|
|
1020
1021
|
this.processChatResponse_vNext({
|
|
1021
1022
|
stream: streamForProcessing,
|
|
@@ -1071,31 +1072,36 @@ var Agent = class extends BaseResource {
|
|
|
1071
1072
|
toolInvocation.result = result;
|
|
1072
1073
|
}
|
|
1073
1074
|
const updatedMessages = lastMessage != null ? [...messages.filter((m) => m.id !== lastMessage.id), lastMessage] : [...messages];
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
})
|
|
1075
|
+
try {
|
|
1076
|
+
await this.processStreamResponse(
|
|
1077
|
+
{
|
|
1078
|
+
...processedParams,
|
|
1079
|
+
messages: updatedMessages
|
|
1080
|
+
},
|
|
1081
|
+
controller
|
|
1082
|
+
);
|
|
1083
|
+
} catch (error) {
|
|
1084
|
+
console.error("Error processing recursive stream response:", error);
|
|
1085
|
+
}
|
|
1083
1086
|
}
|
|
1084
1087
|
}
|
|
1085
1088
|
if (!shouldExecuteClientTool) {
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
}, 0);
|
|
1089
|
+
await pipePromise;
|
|
1090
|
+
controller.close();
|
|
1089
1091
|
}
|
|
1090
1092
|
} else {
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
}, 0);
|
|
1093
|
+
await pipePromise;
|
|
1094
|
+
controller.close();
|
|
1094
1095
|
}
|
|
1095
1096
|
},
|
|
1096
1097
|
lastMessage: void 0
|
|
1097
|
-
}).catch((error) => {
|
|
1098
|
+
}).catch(async (error) => {
|
|
1098
1099
|
console.error("Error processing stream response:", error);
|
|
1100
|
+
try {
|
|
1101
|
+
await pipePromise;
|
|
1102
|
+
controller.close();
|
|
1103
|
+
} catch {
|
|
1104
|
+
}
|
|
1099
1105
|
});
|
|
1100
1106
|
} catch (error) {
|
|
1101
1107
|
console.error("Error processing stream response:", error);
|
|
@@ -1145,8 +1151,13 @@ var Agent = class extends BaseResource {
|
|
|
1145
1151
|
schema: zodToJsonSchema(params.structuredOutput.schema)
|
|
1146
1152
|
} : void 0
|
|
1147
1153
|
};
|
|
1148
|
-
|
|
1149
|
-
const
|
|
1154
|
+
let readableController;
|
|
1155
|
+
const readable = new ReadableStream({
|
|
1156
|
+
start(controller) {
|
|
1157
|
+
readableController = controller;
|
|
1158
|
+
}
|
|
1159
|
+
});
|
|
1160
|
+
const response = await this.processStreamResponse(processedParams, readableController);
|
|
1150
1161
|
const streamResponse = new Response(readable, {
|
|
1151
1162
|
status: response.status,
|
|
1152
1163
|
statusText: response.statusText,
|
|
@@ -1163,8 +1174,13 @@ var Agent = class extends BaseResource {
|
|
|
1163
1174
|
return streamResponse;
|
|
1164
1175
|
}
|
|
1165
1176
|
async approveToolCall(params) {
|
|
1166
|
-
|
|
1167
|
-
const
|
|
1177
|
+
let readableController;
|
|
1178
|
+
const readable = new ReadableStream({
|
|
1179
|
+
start(controller) {
|
|
1180
|
+
readableController = controller;
|
|
1181
|
+
}
|
|
1182
|
+
});
|
|
1183
|
+
const response = await this.processStreamResponse(params, readableController, "approve-tool-call");
|
|
1168
1184
|
const streamResponse = new Response(readable, {
|
|
1169
1185
|
status: response.status,
|
|
1170
1186
|
statusText: response.statusText,
|
|
@@ -1181,8 +1197,13 @@ var Agent = class extends BaseResource {
|
|
|
1181
1197
|
return streamResponse;
|
|
1182
1198
|
}
|
|
1183
1199
|
async declineToolCall(params) {
|
|
1184
|
-
|
|
1185
|
-
const
|
|
1200
|
+
let readableController;
|
|
1201
|
+
const readable = new ReadableStream({
|
|
1202
|
+
start(controller) {
|
|
1203
|
+
readableController = controller;
|
|
1204
|
+
}
|
|
1205
|
+
});
|
|
1206
|
+
const response = await this.processStreamResponse(params, readableController, "decline-tool-call");
|
|
1186
1207
|
const streamResponse = new Response(readable, {
|
|
1187
1208
|
status: response.status,
|
|
1188
1209
|
statusText: response.statusText,
|