@mastra/client-js 0.0.0-fix-model-router-machine-cache-20251021232825 → 0.0.0-fix-memory-search-fetch-20251027160505
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 +57 -3
- package/dist/client.d.ts +8 -7
- package/dist/client.d.ts.map +1 -1
- package/dist/index.cjs +75 -49
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +75 -49
- package/dist/index.js.map +1 -1
- package/dist/resources/agent.d.ts +21 -1
- package/dist/resources/agent.d.ts.map +1 -1
- package/dist/types.d.ts +31 -51
- package/dist/types.d.ts.map +1 -1
- package/dist/utils/process-mastra-stream.d.ts.map +1 -1
- package/package.json +5 -4
package/dist/index.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { processDataStream, parsePartialJson } from '@ai-sdk/ui-utils';
|
|
2
2
|
import { v4 } from '@lukeed/uuid';
|
|
3
|
+
import { getErrorFromUnknown } from '@mastra/core/error';
|
|
3
4
|
import { RuntimeContext } from '@mastra/core/runtime-context';
|
|
4
5
|
import { isVercelTool } from '@mastra/core/tools/is-vercel-tool';
|
|
5
6
|
import { z } from 'zod';
|
|
@@ -94,11 +95,15 @@ async function sharedProcessMastraStream({
|
|
|
94
95
|
console.info("\u{1F3C1} Stream finished");
|
|
95
96
|
return;
|
|
96
97
|
}
|
|
98
|
+
let json;
|
|
97
99
|
try {
|
|
98
|
-
|
|
99
|
-
await onChunk(json);
|
|
100
|
+
json = JSON.parse(data);
|
|
100
101
|
} catch (error) {
|
|
101
102
|
console.error("\u274C JSON parse error:", error, "Data:", data);
|
|
103
|
+
continue;
|
|
104
|
+
}
|
|
105
|
+
if (json) {
|
|
106
|
+
await onChunk(json);
|
|
102
107
|
}
|
|
103
108
|
}
|
|
104
109
|
}
|
|
@@ -317,6 +322,12 @@ var Agent = class extends BaseResource {
|
|
|
317
322
|
details(runtimeContext) {
|
|
318
323
|
return this.request(`/api/agents/${this.agentId}${runtimeContextQueryString(runtimeContext)}`);
|
|
319
324
|
}
|
|
325
|
+
enhanceInstructions(instructions, comment) {
|
|
326
|
+
return this.request(`/api/agents/${this.agentId}/instructions/enhance`, {
|
|
327
|
+
method: "POST",
|
|
328
|
+
body: { instructions, comment }
|
|
329
|
+
});
|
|
330
|
+
}
|
|
320
331
|
async generateLegacy(params) {
|
|
321
332
|
const processedParams = {
|
|
322
333
|
...params,
|
|
@@ -392,7 +403,6 @@ var Agent = class extends BaseResource {
|
|
|
392
403
|
}
|
|
393
404
|
const processedParams = {
|
|
394
405
|
...params,
|
|
395
|
-
output: params.output ? zodToJsonSchema(params.output) : void 0,
|
|
396
406
|
runtimeContext: parseClientRuntimeContext(params.runtimeContext),
|
|
397
407
|
clientTools: processClientTools(params.clientTools),
|
|
398
408
|
structuredOutput: params.structuredOutput ? {
|
|
@@ -945,7 +955,10 @@ var Agent = class extends BaseResource {
|
|
|
945
955
|
break;
|
|
946
956
|
}
|
|
947
957
|
case "error": {
|
|
948
|
-
throw
|
|
958
|
+
throw getErrorFromUnknown(chunk.payload.error, {
|
|
959
|
+
fallbackMessage: "Unknown error in stream",
|
|
960
|
+
supportSerialization: false
|
|
961
|
+
});
|
|
949
962
|
}
|
|
950
963
|
case "data": {
|
|
951
964
|
data.push(...chunk.payload.data);
|
|
@@ -972,8 +985,8 @@ var Agent = class extends BaseResource {
|
|
|
972
985
|
});
|
|
973
986
|
onFinish?.({ message, finishReason, usage });
|
|
974
987
|
}
|
|
975
|
-
async processStreamResponse(processedParams, writable) {
|
|
976
|
-
const response = await this.request(`/api/agents/${this.agentId}
|
|
988
|
+
async processStreamResponse(processedParams, writable, route = "stream") {
|
|
989
|
+
const response = await this.request(`/api/agents/${this.agentId}/${route}`, {
|
|
977
990
|
method: "POST",
|
|
978
991
|
body: processedParams,
|
|
979
992
|
stream: true
|
|
@@ -1133,7 +1146,6 @@ var Agent = class extends BaseResource {
|
|
|
1133
1146
|
}
|
|
1134
1147
|
const processedParams = {
|
|
1135
1148
|
...params,
|
|
1136
|
-
output: params.output ? zodToJsonSchema(params.output) : void 0,
|
|
1137
1149
|
runtimeContext: parseClientRuntimeContext(params.runtimeContext),
|
|
1138
1150
|
clientTools: processClientTools(params.clientTools),
|
|
1139
1151
|
structuredOutput: params.structuredOutput ? {
|
|
@@ -1158,6 +1170,42 @@ var Agent = class extends BaseResource {
|
|
|
1158
1170
|
};
|
|
1159
1171
|
return streamResponse;
|
|
1160
1172
|
}
|
|
1173
|
+
async approveToolCall(params) {
|
|
1174
|
+
const { readable, writable } = new TransformStream();
|
|
1175
|
+
const response = await this.processStreamResponse(params, writable, "approve-tool-call");
|
|
1176
|
+
const streamResponse = new Response(readable, {
|
|
1177
|
+
status: response.status,
|
|
1178
|
+
statusText: response.statusText,
|
|
1179
|
+
headers: response.headers
|
|
1180
|
+
});
|
|
1181
|
+
streamResponse.processDataStream = async ({
|
|
1182
|
+
onChunk
|
|
1183
|
+
}) => {
|
|
1184
|
+
await processMastraStream({
|
|
1185
|
+
stream: streamResponse.body,
|
|
1186
|
+
onChunk
|
|
1187
|
+
});
|
|
1188
|
+
};
|
|
1189
|
+
return streamResponse;
|
|
1190
|
+
}
|
|
1191
|
+
async declineToolCall(params) {
|
|
1192
|
+
const { readable, writable } = new TransformStream();
|
|
1193
|
+
const response = await this.processStreamResponse(params, writable, "decline-tool-call");
|
|
1194
|
+
const streamResponse = new Response(readable, {
|
|
1195
|
+
status: response.status,
|
|
1196
|
+
statusText: response.statusText,
|
|
1197
|
+
headers: response.headers
|
|
1198
|
+
});
|
|
1199
|
+
streamResponse.processDataStream = async ({
|
|
1200
|
+
onChunk
|
|
1201
|
+
}) => {
|
|
1202
|
+
await processMastraStream({
|
|
1203
|
+
stream: streamResponse.body,
|
|
1204
|
+
onChunk
|
|
1205
|
+
});
|
|
1206
|
+
};
|
|
1207
|
+
return streamResponse;
|
|
1208
|
+
}
|
|
1161
1209
|
/**
|
|
1162
1210
|
* Processes the stream response and handles tool calls
|
|
1163
1211
|
*/
|
|
@@ -3037,48 +3085,6 @@ var MastraClient = class extends BaseResource {
|
|
|
3037
3085
|
getLogTransports() {
|
|
3038
3086
|
return this.request("/api/logs/transports");
|
|
3039
3087
|
}
|
|
3040
|
-
/**
|
|
3041
|
-
* List of all traces (paged)
|
|
3042
|
-
* @param params - Parameters for filtering traces
|
|
3043
|
-
* @returns Promise containing telemetry data
|
|
3044
|
-
*/
|
|
3045
|
-
getTelemetry(params) {
|
|
3046
|
-
const { name, scope, page, perPage, attribute, fromDate, toDate } = params || {};
|
|
3047
|
-
const _attribute = attribute ? Object.entries(attribute).map(([key, value]) => `${key}:${value}`) : [];
|
|
3048
|
-
const searchParams = new URLSearchParams();
|
|
3049
|
-
if (name) {
|
|
3050
|
-
searchParams.set("name", name);
|
|
3051
|
-
}
|
|
3052
|
-
if (scope) {
|
|
3053
|
-
searchParams.set("scope", scope);
|
|
3054
|
-
}
|
|
3055
|
-
if (page) {
|
|
3056
|
-
searchParams.set("page", String(page));
|
|
3057
|
-
}
|
|
3058
|
-
if (perPage) {
|
|
3059
|
-
searchParams.set("perPage", String(perPage));
|
|
3060
|
-
}
|
|
3061
|
-
if (_attribute) {
|
|
3062
|
-
if (Array.isArray(_attribute)) {
|
|
3063
|
-
for (const attr of _attribute) {
|
|
3064
|
-
searchParams.append("attribute", attr);
|
|
3065
|
-
}
|
|
3066
|
-
} else {
|
|
3067
|
-
searchParams.set("attribute", _attribute);
|
|
3068
|
-
}
|
|
3069
|
-
}
|
|
3070
|
-
if (fromDate) {
|
|
3071
|
-
searchParams.set("fromDate", fromDate.toISOString());
|
|
3072
|
-
}
|
|
3073
|
-
if (toDate) {
|
|
3074
|
-
searchParams.set("toDate", toDate.toISOString());
|
|
3075
|
-
}
|
|
3076
|
-
if (searchParams.size) {
|
|
3077
|
-
return this.request(`/api/telemetry?${searchParams}`);
|
|
3078
|
-
} else {
|
|
3079
|
-
return this.request(`/api/telemetry`);
|
|
3080
|
-
}
|
|
3081
|
-
}
|
|
3082
3088
|
/**
|
|
3083
3089
|
* Retrieves a list of available MCP servers.
|
|
3084
3090
|
* @param params - Optional parameters for pagination (limit, offset).
|
|
@@ -3149,6 +3155,26 @@ var MastraClient = class extends BaseResource {
|
|
|
3149
3155
|
}) {
|
|
3150
3156
|
return this.request(`/api/memory/threads/${threadId}/working-memory?agentId=${agentId}&resourceId=${resourceId}`);
|
|
3151
3157
|
}
|
|
3158
|
+
searchMemory({
|
|
3159
|
+
agentId,
|
|
3160
|
+
resourceId,
|
|
3161
|
+
threadId,
|
|
3162
|
+
searchQuery,
|
|
3163
|
+
memoryConfig
|
|
3164
|
+
}) {
|
|
3165
|
+
const params = new URLSearchParams({
|
|
3166
|
+
searchQuery,
|
|
3167
|
+
resourceId,
|
|
3168
|
+
agentId
|
|
3169
|
+
});
|
|
3170
|
+
if (threadId) {
|
|
3171
|
+
params.append("threadId", threadId);
|
|
3172
|
+
}
|
|
3173
|
+
if (memoryConfig) {
|
|
3174
|
+
params.append("memoryConfig", JSON.stringify(memoryConfig));
|
|
3175
|
+
}
|
|
3176
|
+
return this.request(`/api/memory/search?${params}`);
|
|
3177
|
+
}
|
|
3152
3178
|
/**
|
|
3153
3179
|
* Updates the working memory for a specific thread (optionally resource-scoped).
|
|
3154
3180
|
* @param agentId - ID of the agent.
|