@mastra/client-js 1.60.0-alpha.2 → 1.60.0-alpha.4
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/dist/docs/SKILL.md +1 -1
- package/dist/docs/assets/SOURCE_MAP.json +6 -6
- package/dist/index.cjs +37 -26
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +37 -26
- package/dist/index.js.map +1 -1
- package/dist/resources/agent.d.ts.map +1 -1
- package/dist/route-types.generated.d.ts +6 -0
- package/dist/route-types.generated.d.ts.map +1 -1
- package/dist/types.d.ts +2 -2
- package/dist/types.d.ts.map +1 -1
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -1315,11 +1315,13 @@ async function executeClientToolWithObservability({ clientTool, args, toolName,
|
|
|
1315
1315
|
}
|
|
1316
1316
|
};
|
|
1317
1317
|
}
|
|
1318
|
-
async function executeToolCallAndRespond({ response, params, agentId, resourceId, threadId, requestContext, respondFn }) {
|
|
1318
|
+
async function executeToolCallAndRespond({ response, params, agentId, resourceId, threadId, requestContext, respondFn, abortSignal }) {
|
|
1319
1319
|
if (response.finishReason === "tool-calls") {
|
|
1320
1320
|
const toolCalls = response.toolCalls;
|
|
1321
1321
|
if (!toolCalls || !Array.isArray(toolCalls)) return response;
|
|
1322
|
+
const toolResults = [];
|
|
1322
1323
|
for (const toolCall of toolCalls) {
|
|
1324
|
+
if (abortSignal?.aborted) throw abortSignal.reason ?? new DOMException("This operation was aborted", "AbortError");
|
|
1323
1325
|
const clientTool = params.clientTools?.[toolCall.payload.toolName];
|
|
1324
1326
|
if (clientTool && clientTool.execute) {
|
|
1325
1327
|
const { result, observability } = await executeClientToolWithObservability({
|
|
@@ -1349,19 +1351,22 @@ async function executeToolCallAndRespond({ response, params, agentId, resourceId
|
|
|
1349
1351
|
...modelOutput != null ? { providerOptions: { mastra: { modelOutput } } } : {}
|
|
1350
1352
|
};
|
|
1351
1353
|
if (observability) toolResultContent.__mastraObservability = observability;
|
|
1352
|
-
|
|
1353
|
-
role: "tool",
|
|
1354
|
-
content: [toolResultContent]
|
|
1355
|
-
}];
|
|
1356
|
-
const updatedMessages = threadId ? newMessages : [...Array.isArray(params.messages) ? params.messages : [], ...newMessages];
|
|
1357
|
-
const respondOptions = {
|
|
1358
|
-
...params,
|
|
1359
|
-
clientTools: params.clientToolsResolver?.() ?? params.clientTools
|
|
1360
|
-
};
|
|
1361
|
-
delete respondOptions.messages;
|
|
1362
|
-
return respondFn(updatedMessages, respondOptions);
|
|
1354
|
+
toolResults.push(toolResultContent);
|
|
1363
1355
|
}
|
|
1364
1356
|
}
|
|
1357
|
+
if (toolResults.length > 0) {
|
|
1358
|
+
const newMessages = [...response.response.messages || [], {
|
|
1359
|
+
role: "tool",
|
|
1360
|
+
content: toolResults
|
|
1361
|
+
}];
|
|
1362
|
+
const updatedMessages = threadId ? newMessages : [...Array.isArray(params.messages) ? params.messages : [], ...newMessages];
|
|
1363
|
+
const respondOptions = {
|
|
1364
|
+
...params,
|
|
1365
|
+
clientTools: params.clientToolsResolver?.() ?? params.clientTools
|
|
1366
|
+
};
|
|
1367
|
+
delete respondOptions.messages;
|
|
1368
|
+
return respondFn(updatedMessages, respondOptions);
|
|
1369
|
+
}
|
|
1365
1370
|
}
|
|
1366
1371
|
return response;
|
|
1367
1372
|
}
|
|
@@ -2058,7 +2063,9 @@ var Agent = class extends BaseResource {
|
|
|
2058
2063
|
if (abortSignal?.aborted) throw abortSignal.reason ?? new DOMException("This operation was aborted", "AbortError");
|
|
2059
2064
|
const toolCalls = response.toolCalls;
|
|
2060
2065
|
if (!toolCalls || !Array.isArray(toolCalls)) return response;
|
|
2066
|
+
const toolResults = [];
|
|
2061
2067
|
for (const toolCall of toolCalls) {
|
|
2068
|
+
if (abortSignal?.aborted) throw abortSignal.reason ?? new DOMException("This operation was aborted", "AbortError");
|
|
2062
2069
|
const clientTool = processedParams.clientTools?.[toolCall.toolName];
|
|
2063
2070
|
if (clientTool && clientTool.execute) {
|
|
2064
2071
|
const { result, observability } = await executeClientToolWithObservability({
|
|
@@ -2079,22 +2086,25 @@ var Agent = class extends BaseResource {
|
|
|
2079
2086
|
}
|
|
2080
2087
|
}
|
|
2081
2088
|
});
|
|
2082
|
-
|
|
2083
|
-
|
|
2084
|
-
|
|
2085
|
-
|
|
2086
|
-
|
|
2087
|
-
|
|
2088
|
-
result,
|
|
2089
|
-
...observability ? { __mastraObservability: observability } : {}
|
|
2090
|
-
}]
|
|
2091
|
-
}];
|
|
2092
|
-
return this.generateLegacy({
|
|
2093
|
-
...params,
|
|
2094
|
-
messages: updatedMessages
|
|
2089
|
+
toolResults.push({
|
|
2090
|
+
type: "tool-result",
|
|
2091
|
+
toolCallId: toolCall.toolCallId,
|
|
2092
|
+
toolName: toolCall.toolName,
|
|
2093
|
+
result,
|
|
2094
|
+
...observability ? { __mastraObservability: observability } : {}
|
|
2095
2095
|
});
|
|
2096
2096
|
}
|
|
2097
2097
|
}
|
|
2098
|
+
if (toolResults.length > 0) {
|
|
2099
|
+
const updatedMessages = [...response.response.messages, {
|
|
2100
|
+
role: "tool",
|
|
2101
|
+
content: toolResults
|
|
2102
|
+
}];
|
|
2103
|
+
return this.generateLegacy({
|
|
2104
|
+
...params,
|
|
2105
|
+
messages: updatedMessages
|
|
2106
|
+
});
|
|
2107
|
+
}
|
|
2098
2108
|
}
|
|
2099
2109
|
return response;
|
|
2100
2110
|
}
|
|
@@ -2136,7 +2146,8 @@ var Agent = class extends BaseResource {
|
|
|
2136
2146
|
resourceId,
|
|
2137
2147
|
threadId,
|
|
2138
2148
|
requestContext,
|
|
2139
|
-
respondFn: this.generate.bind(this)
|
|
2149
|
+
respondFn: this.generate.bind(this),
|
|
2150
|
+
abortSignal
|
|
2140
2151
|
});
|
|
2141
2152
|
}
|
|
2142
2153
|
return response;
|