@mastra/client-js 0.0.0-support-d1-client-20250701191943 → 0.0.0-taofeeq-fix-tool-call-showing-after-message-20250806162745
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/.turbo/turbo-build.log +9 -10
- package/CHANGELOG.md +538 -2
- package/LICENSE.md +11 -42
- package/README.md +1 -0
- package/dist/adapters/agui.d.ts +23 -0
- package/dist/adapters/agui.d.ts.map +1 -0
- package/dist/client.d.ts +265 -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 +306 -79
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +4 -1152
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +305 -78
- package/dist/index.js.map +1 -0
- package/dist/resources/a2a.d.ts +44 -0
- package/dist/resources/a2a.d.ts.map +1 -0
- package/dist/resources/agent.d.ts +112 -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 +11 -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/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 +154 -0
- package/dist/resources/workflow.d.ts.map +1 -0
- package/dist/types.d.ts +422 -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/zod-to-json-schema.d.ts +105 -0
- package/dist/utils/zod-to-json-schema.d.ts.map +1 -0
- package/integration-tests/agui-adapter.test.ts +122 -0
- package/integration-tests/package.json +18 -0
- package/integration-tests/src/mastra/index.ts +35 -0
- package/integration-tests/vitest.config.ts +9 -0
- package/package.json +15 -9
- package/src/adapters/agui.test.ts +145 -3
- package/src/adapters/agui.ts +29 -11
- package/src/client.ts +145 -2
- package/src/example.ts +45 -17
- package/src/index.test.ts +402 -6
- package/src/index.ts +1 -0
- package/src/resources/agent.ts +46 -24
- package/src/resources/base.ts +6 -1
- package/src/resources/memory-thread.test.ts +285 -0
- package/src/resources/memory-thread.ts +36 -0
- package/src/resources/network-memory-thread.test.ts +269 -0
- package/src/resources/network-memory-thread.ts +18 -0
- package/src/resources/network.ts +4 -3
- package/src/resources/vNextNetwork.ts +22 -5
- package/src/resources/workflow.ts +31 -5
- package/src/types.ts +90 -10
- package/src/utils/process-client-tools.ts +1 -1
- package/src/v2-messages.test.ts +180 -0
- package/tsconfig.build.json +9 -0
- package/tsconfig.json +1 -1
- package/tsup.config.ts +17 -0
- package/dist/index.d.cts +0 -1152
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,cAAc,SAAS,CAAC;AACxB,YAAY,EAAE,qBAAqB,EAAE,MAAM,oBAAoB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -3,7 +3,8 @@ import { Observable } from 'rxjs';
|
|
|
3
3
|
import { processDataStream, parsePartialJson } from '@ai-sdk/ui-utils';
|
|
4
4
|
import { ZodSchema } from 'zod';
|
|
5
5
|
import originalZodToJsonSchema from 'zod-to-json-schema';
|
|
6
|
-
import { isVercelTool } from '@mastra/core/tools';
|
|
6
|
+
import { isVercelTool } from '@mastra/core/tools/is-vercel-tool';
|
|
7
|
+
import { v4 } from '@lukeed/uuid';
|
|
7
8
|
import { RuntimeContext } from '@mastra/core/runtime-context';
|
|
8
9
|
|
|
9
10
|
// src/adapters/agui.ts
|
|
@@ -144,6 +145,12 @@ function generateUUID() {
|
|
|
144
145
|
}
|
|
145
146
|
function convertMessagesToMastraMessages(messages) {
|
|
146
147
|
const result = [];
|
|
148
|
+
const toolCallsWithResults = /* @__PURE__ */ new Set();
|
|
149
|
+
for (const message of messages) {
|
|
150
|
+
if (message.role === "tool" && message.toolCallId) {
|
|
151
|
+
toolCallsWithResults.add(message.toolCallId);
|
|
152
|
+
}
|
|
153
|
+
}
|
|
147
154
|
for (const message of messages) {
|
|
148
155
|
if (message.role === "assistant") {
|
|
149
156
|
const parts = message.content ? [{ type: "text", text: message.content }] : [];
|
|
@@ -160,15 +167,22 @@ function convertMessagesToMastraMessages(messages) {
|
|
|
160
167
|
content: parts
|
|
161
168
|
});
|
|
162
169
|
if (message.toolCalls?.length) {
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
170
|
+
for (const toolCall of message.toolCalls) {
|
|
171
|
+
if (!toolCallsWithResults.has(toolCall.id)) {
|
|
172
|
+
result.push({
|
|
173
|
+
role: "tool",
|
|
174
|
+
content: [
|
|
175
|
+
{
|
|
176
|
+
type: "tool-result",
|
|
177
|
+
toolCallId: toolCall.id,
|
|
178
|
+
toolName: toolCall.function.name,
|
|
179
|
+
result: JSON.parse(toolCall.function.arguments)
|
|
180
|
+
// This is still wrong but matches test expectations
|
|
181
|
+
}
|
|
182
|
+
]
|
|
183
|
+
});
|
|
184
|
+
}
|
|
185
|
+
}
|
|
172
186
|
}
|
|
173
187
|
} else if (message.role === "user") {
|
|
174
188
|
result.push({
|
|
@@ -181,8 +195,9 @@ function convertMessagesToMastraMessages(messages) {
|
|
|
181
195
|
content: [
|
|
182
196
|
{
|
|
183
197
|
type: "tool-result",
|
|
184
|
-
toolCallId: message.toolCallId,
|
|
198
|
+
toolCallId: message.toolCallId || "unknown",
|
|
185
199
|
toolName: "unknown",
|
|
200
|
+
// toolName is not available in tool messages from CopilotKit
|
|
186
201
|
result: message.content
|
|
187
202
|
}
|
|
188
203
|
]
|
|
@@ -246,12 +261,13 @@ var BaseResource = class {
|
|
|
246
261
|
const response = await fetch(`${baseUrl.replace(/\/$/, "")}${path}`, {
|
|
247
262
|
...options,
|
|
248
263
|
headers: {
|
|
249
|
-
...options.method === "POST" || options.method === "PUT" ? { "content-type": "application/json" } : {},
|
|
264
|
+
...options.body && !(options.body instanceof FormData) && (options.method === "POST" || options.method === "PUT") ? { "content-type": "application/json" } : {},
|
|
250
265
|
...headers,
|
|
251
266
|
...options.headers
|
|
252
267
|
// TODO: Bring this back once we figure out what we/users need to do to make this work with cross-origin requests
|
|
253
268
|
// 'x-mastra-client-type': 'js',
|
|
254
269
|
},
|
|
270
|
+
signal: this.options.abortSignal,
|
|
255
271
|
body: options.body instanceof FormData ? options.body : options.body ? JSON.stringify(options.body) : void 0
|
|
256
272
|
});
|
|
257
273
|
if (!response.ok) {
|
|
@@ -370,12 +386,19 @@ var Agent = class extends BaseResource {
|
|
|
370
386
|
clientTools: processClientTools(params.clientTools)
|
|
371
387
|
};
|
|
372
388
|
const { runId, resourceId, threadId, runtimeContext } = processedParams;
|
|
373
|
-
const response = await this.request(
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
389
|
+
const response = await this.request(
|
|
390
|
+
`/api/agents/${this.agentId}/generate`,
|
|
391
|
+
{
|
|
392
|
+
method: "POST",
|
|
393
|
+
body: processedParams
|
|
394
|
+
}
|
|
395
|
+
);
|
|
377
396
|
if (response.finishReason === "tool-calls") {
|
|
378
|
-
|
|
397
|
+
const toolCalls = response.toolCalls;
|
|
398
|
+
if (!toolCalls || !Array.isArray(toolCalls)) {
|
|
399
|
+
return response;
|
|
400
|
+
}
|
|
401
|
+
for (const toolCall of toolCalls) {
|
|
379
402
|
const clientTool = params.clientTools?.[toolCall.toolName];
|
|
380
403
|
if (clientTool && clientTool.execute) {
|
|
381
404
|
const result = await clientTool.execute(
|
|
@@ -426,7 +449,7 @@ var Agent = class extends BaseResource {
|
|
|
426
449
|
return Math.max(max, toolInvocation.step ?? 0);
|
|
427
450
|
}, 0) ?? 0) : 0;
|
|
428
451
|
const message = replaceLastMessage ? structuredClone(lastMessage) : {
|
|
429
|
-
id:
|
|
452
|
+
id: v4(),
|
|
430
453
|
createdAt: getCurrentDate(),
|
|
431
454
|
role: "assistant",
|
|
432
455
|
content: "",
|
|
@@ -471,7 +494,7 @@ var Agent = class extends BaseResource {
|
|
|
471
494
|
// changes. This is why we need to add a revision id to ensure that the message
|
|
472
495
|
// is updated with SWR (without it, the changes get stuck in SWR and are not
|
|
473
496
|
// forwarded to rendering):
|
|
474
|
-
revisionId:
|
|
497
|
+
revisionId: v4()
|
|
475
498
|
};
|
|
476
499
|
update({
|
|
477
500
|
message: copiedMessage,
|
|
@@ -726,7 +749,12 @@ var Agent = class extends BaseResource {
|
|
|
726
749
|
this.processChatResponse({
|
|
727
750
|
stream: streamForProcessing,
|
|
728
751
|
update: ({ message }) => {
|
|
729
|
-
messages.
|
|
752
|
+
const existingIndex = messages.findIndex((m) => m.id === message.id);
|
|
753
|
+
if (existingIndex !== -1) {
|
|
754
|
+
messages[existingIndex] = message;
|
|
755
|
+
} else {
|
|
756
|
+
messages.push(message);
|
|
757
|
+
}
|
|
730
758
|
},
|
|
731
759
|
onFinish: async ({ finishReason, message }) => {
|
|
732
760
|
if (finishReason === "tool-calls") {
|
|
@@ -786,10 +814,12 @@ var Agent = class extends BaseResource {
|
|
|
786
814
|
this.processStreamResponse(
|
|
787
815
|
{
|
|
788
816
|
...processedParams,
|
|
789
|
-
messages: [...messageArray, ...messages, lastMessage]
|
|
817
|
+
messages: [...messageArray, ...messages.filter((m) => m.id !== lastMessage.id), lastMessage]
|
|
790
818
|
},
|
|
791
819
|
writable
|
|
792
|
-
)
|
|
820
|
+
).catch((error) => {
|
|
821
|
+
console.error("Error processing stream response:", error);
|
|
822
|
+
});
|
|
793
823
|
}
|
|
794
824
|
}
|
|
795
825
|
} else {
|
|
@@ -799,6 +829,8 @@ var Agent = class extends BaseResource {
|
|
|
799
829
|
}
|
|
800
830
|
},
|
|
801
831
|
lastMessage: void 0
|
|
832
|
+
}).catch((error) => {
|
|
833
|
+
console.error("Error processing stream response:", error);
|
|
802
834
|
});
|
|
803
835
|
} catch (error) {
|
|
804
836
|
console.error("Error processing stream response:", error);
|
|
@@ -947,6 +979,36 @@ var MemoryThread = class extends BaseResource {
|
|
|
947
979
|
});
|
|
948
980
|
return this.request(`/api/memory/threads/${this.threadId}/messages?${query.toString()}`);
|
|
949
981
|
}
|
|
982
|
+
/**
|
|
983
|
+
* Retrieves paginated messages associated with the thread with advanced filtering and selection options
|
|
984
|
+
* @param params - Pagination parameters including selectBy criteria, page, perPage, date ranges, and message inclusion options
|
|
985
|
+
* @returns Promise containing paginated thread messages with pagination metadata (total, page, perPage, hasMore)
|
|
986
|
+
*/
|
|
987
|
+
getMessagesPaginated({
|
|
988
|
+
selectBy,
|
|
989
|
+
...rest
|
|
990
|
+
}) {
|
|
991
|
+
const query = new URLSearchParams({
|
|
992
|
+
...rest,
|
|
993
|
+
...selectBy ? { selectBy: JSON.stringify(selectBy) } : {}
|
|
994
|
+
});
|
|
995
|
+
return this.request(`/api/memory/threads/${this.threadId}/messages/paginated?${query.toString()}`);
|
|
996
|
+
}
|
|
997
|
+
/**
|
|
998
|
+
* Deletes one or more messages from the thread
|
|
999
|
+
* @param messageIds - Can be a single message ID (string), array of message IDs,
|
|
1000
|
+
* message object with id property, or array of message objects
|
|
1001
|
+
* @returns Promise containing deletion result
|
|
1002
|
+
*/
|
|
1003
|
+
deleteMessages(messageIds) {
|
|
1004
|
+
const query = new URLSearchParams({
|
|
1005
|
+
agentId: this.agentId
|
|
1006
|
+
});
|
|
1007
|
+
return this.request(`/api/memory/messages/delete?${query.toString()}`, {
|
|
1008
|
+
method: "POST",
|
|
1009
|
+
body: { messageIds }
|
|
1010
|
+
});
|
|
1011
|
+
}
|
|
950
1012
|
};
|
|
951
1013
|
|
|
952
1014
|
// src/resources/vector.ts
|
|
@@ -1302,10 +1364,10 @@ var Workflow = class extends BaseResource {
|
|
|
1302
1364
|
if (params?.toDate) {
|
|
1303
1365
|
searchParams.set("toDate", params.toDate.toISOString());
|
|
1304
1366
|
}
|
|
1305
|
-
if (params?.limit) {
|
|
1367
|
+
if (params?.limit !== null && params?.limit !== void 0 && !isNaN(Number(params?.limit))) {
|
|
1306
1368
|
searchParams.set("limit", String(params.limit));
|
|
1307
1369
|
}
|
|
1308
|
-
if (params?.offset) {
|
|
1370
|
+
if (params?.offset !== null && params?.offset !== void 0 && !isNaN(Number(params?.offset))) {
|
|
1309
1371
|
searchParams.set("offset", String(params.offset));
|
|
1310
1372
|
}
|
|
1311
1373
|
if (params?.resourceId) {
|
|
@@ -1343,6 +1405,17 @@ var Workflow = class extends BaseResource {
|
|
|
1343
1405
|
method: "POST"
|
|
1344
1406
|
});
|
|
1345
1407
|
}
|
|
1408
|
+
/**
|
|
1409
|
+
* Sends an event to a specific workflow run by its ID
|
|
1410
|
+
* @param params - Object containing the runId, event and data
|
|
1411
|
+
* @returns Promise containing a success message
|
|
1412
|
+
*/
|
|
1413
|
+
sendRunEvent(params) {
|
|
1414
|
+
return this.request(`/api/workflows/${this.workflowId}/runs/${params.runId}/send-event`, {
|
|
1415
|
+
method: "POST",
|
|
1416
|
+
body: { event: params.event, data: params.data }
|
|
1417
|
+
});
|
|
1418
|
+
}
|
|
1346
1419
|
/**
|
|
1347
1420
|
* Creates a new workflow run
|
|
1348
1421
|
* @param params - Optional object containing the optional runId
|
|
@@ -1357,6 +1430,14 @@ var Workflow = class extends BaseResource {
|
|
|
1357
1430
|
method: "POST"
|
|
1358
1431
|
});
|
|
1359
1432
|
}
|
|
1433
|
+
/**
|
|
1434
|
+
* Creates a new workflow run (alias for createRun)
|
|
1435
|
+
* @param params - Optional object containing the optional runId
|
|
1436
|
+
* @returns Promise containing the runId of the created run
|
|
1437
|
+
*/
|
|
1438
|
+
createRunAsync(params) {
|
|
1439
|
+
return this.createRun(params);
|
|
1440
|
+
}
|
|
1360
1441
|
/**
|
|
1361
1442
|
* Starts a workflow run synchronously without waiting for the workflow to complete
|
|
1362
1443
|
* @param params - Object containing the runId, inputData and runtimeContext
|
|
@@ -1432,6 +1513,7 @@ var Workflow = class extends BaseResource {
|
|
|
1432
1513
|
if (!response.body) {
|
|
1433
1514
|
throw new Error("Response body is null");
|
|
1434
1515
|
}
|
|
1516
|
+
let failedChunk = void 0;
|
|
1435
1517
|
const transformStream = new TransformStream({
|
|
1436
1518
|
start() {
|
|
1437
1519
|
},
|
|
@@ -1441,10 +1523,13 @@ var Workflow = class extends BaseResource {
|
|
|
1441
1523
|
const chunks = decoded.split(RECORD_SEPARATOR2);
|
|
1442
1524
|
for (const chunk2 of chunks) {
|
|
1443
1525
|
if (chunk2) {
|
|
1526
|
+
const newChunk = failedChunk ? failedChunk + chunk2 : chunk2;
|
|
1444
1527
|
try {
|
|
1445
|
-
const parsedChunk = JSON.parse(
|
|
1528
|
+
const parsedChunk = JSON.parse(newChunk);
|
|
1446
1529
|
controller.enqueue(parsedChunk);
|
|
1447
|
-
|
|
1530
|
+
failedChunk = void 0;
|
|
1531
|
+
} catch (error) {
|
|
1532
|
+
failedChunk = newChunk;
|
|
1448
1533
|
}
|
|
1449
1534
|
}
|
|
1450
1535
|
}
|
|
@@ -1626,6 +1711,69 @@ var MCPTool = class extends BaseResource {
|
|
|
1626
1711
|
}
|
|
1627
1712
|
};
|
|
1628
1713
|
|
|
1714
|
+
// src/resources/network-memory-thread.ts
|
|
1715
|
+
var NetworkMemoryThread = class extends BaseResource {
|
|
1716
|
+
constructor(options, threadId, networkId) {
|
|
1717
|
+
super(options);
|
|
1718
|
+
this.threadId = threadId;
|
|
1719
|
+
this.networkId = networkId;
|
|
1720
|
+
}
|
|
1721
|
+
/**
|
|
1722
|
+
* Retrieves the memory thread details
|
|
1723
|
+
* @returns Promise containing thread details including title and metadata
|
|
1724
|
+
*/
|
|
1725
|
+
get() {
|
|
1726
|
+
return this.request(`/api/memory/network/threads/${this.threadId}?networkId=${this.networkId}`);
|
|
1727
|
+
}
|
|
1728
|
+
/**
|
|
1729
|
+
* Updates the memory thread properties
|
|
1730
|
+
* @param params - Update parameters including title and metadata
|
|
1731
|
+
* @returns Promise containing updated thread details
|
|
1732
|
+
*/
|
|
1733
|
+
update(params) {
|
|
1734
|
+
return this.request(`/api/memory/network/threads/${this.threadId}?networkId=${this.networkId}`, {
|
|
1735
|
+
method: "PATCH",
|
|
1736
|
+
body: params
|
|
1737
|
+
});
|
|
1738
|
+
}
|
|
1739
|
+
/**
|
|
1740
|
+
* Deletes the memory thread
|
|
1741
|
+
* @returns Promise containing deletion result
|
|
1742
|
+
*/
|
|
1743
|
+
delete() {
|
|
1744
|
+
return this.request(`/api/memory/network/threads/${this.threadId}?networkId=${this.networkId}`, {
|
|
1745
|
+
method: "DELETE"
|
|
1746
|
+
});
|
|
1747
|
+
}
|
|
1748
|
+
/**
|
|
1749
|
+
* Retrieves messages associated with the thread
|
|
1750
|
+
* @param params - Optional parameters including limit for number of messages to retrieve
|
|
1751
|
+
* @returns Promise containing thread messages and UI messages
|
|
1752
|
+
*/
|
|
1753
|
+
getMessages(params) {
|
|
1754
|
+
const query = new URLSearchParams({
|
|
1755
|
+
networkId: this.networkId,
|
|
1756
|
+
...params?.limit ? { limit: params.limit.toString() } : {}
|
|
1757
|
+
});
|
|
1758
|
+
return this.request(`/api/memory/network/threads/${this.threadId}/messages?${query.toString()}`);
|
|
1759
|
+
}
|
|
1760
|
+
/**
|
|
1761
|
+
* Deletes one or more messages from the thread
|
|
1762
|
+
* @param messageIds - Can be a single message ID (string), array of message IDs,
|
|
1763
|
+
* message object with id property, or array of message objects
|
|
1764
|
+
* @returns Promise containing deletion result
|
|
1765
|
+
*/
|
|
1766
|
+
deleteMessages(messageIds) {
|
|
1767
|
+
const query = new URLSearchParams({
|
|
1768
|
+
networkId: this.networkId
|
|
1769
|
+
});
|
|
1770
|
+
return this.request(`/api/memory/network/messages/delete?${query.toString()}`, {
|
|
1771
|
+
method: "POST",
|
|
1772
|
+
body: { messageIds }
|
|
1773
|
+
});
|
|
1774
|
+
}
|
|
1775
|
+
};
|
|
1776
|
+
|
|
1629
1777
|
// src/resources/vNextNetwork.ts
|
|
1630
1778
|
var RECORD_SEPARATOR3 = "";
|
|
1631
1779
|
var VNextNetwork = class extends BaseResource {
|
|
@@ -1648,7 +1796,10 @@ var VNextNetwork = class extends BaseResource {
|
|
|
1648
1796
|
generate(params) {
|
|
1649
1797
|
return this.request(`/api/networks/v-next/${this.networkId}/generate`, {
|
|
1650
1798
|
method: "POST",
|
|
1651
|
-
body:
|
|
1799
|
+
body: {
|
|
1800
|
+
...params,
|
|
1801
|
+
runtimeContext: parseClientRuntimeContext(params.runtimeContext)
|
|
1802
|
+
}
|
|
1652
1803
|
});
|
|
1653
1804
|
}
|
|
1654
1805
|
/**
|
|
@@ -1659,7 +1810,10 @@ var VNextNetwork = class extends BaseResource {
|
|
|
1659
1810
|
loop(params) {
|
|
1660
1811
|
return this.request(`/api/networks/v-next/${this.networkId}/loop`, {
|
|
1661
1812
|
method: "POST",
|
|
1662
|
-
body:
|
|
1813
|
+
body: {
|
|
1814
|
+
...params,
|
|
1815
|
+
runtimeContext: parseClientRuntimeContext(params.runtimeContext)
|
|
1816
|
+
}
|
|
1663
1817
|
});
|
|
1664
1818
|
}
|
|
1665
1819
|
async *streamProcessor(stream) {
|
|
@@ -1708,7 +1862,10 @@ var VNextNetwork = class extends BaseResource {
|
|
|
1708
1862
|
async stream(params, onRecord) {
|
|
1709
1863
|
const response = await this.request(`/api/networks/v-next/${this.networkId}/stream`, {
|
|
1710
1864
|
method: "POST",
|
|
1711
|
-
body:
|
|
1865
|
+
body: {
|
|
1866
|
+
...params,
|
|
1867
|
+
runtimeContext: parseClientRuntimeContext(params.runtimeContext)
|
|
1868
|
+
},
|
|
1712
1869
|
stream: true
|
|
1713
1870
|
});
|
|
1714
1871
|
if (!response.ok) {
|
|
@@ -1733,7 +1890,10 @@ var VNextNetwork = class extends BaseResource {
|
|
|
1733
1890
|
async loopStream(params, onRecord) {
|
|
1734
1891
|
const response = await this.request(`/api/networks/v-next/${this.networkId}/loop-stream`, {
|
|
1735
1892
|
method: "POST",
|
|
1736
|
-
body:
|
|
1893
|
+
body: {
|
|
1894
|
+
...params,
|
|
1895
|
+
runtimeContext: parseClientRuntimeContext(params.runtimeContext)
|
|
1896
|
+
},
|
|
1737
1897
|
stream: true
|
|
1738
1898
|
});
|
|
1739
1899
|
if (!response.ok) {
|
|
@@ -1752,54 +1912,6 @@ var VNextNetwork = class extends BaseResource {
|
|
|
1752
1912
|
}
|
|
1753
1913
|
};
|
|
1754
1914
|
|
|
1755
|
-
// src/resources/network-memory-thread.ts
|
|
1756
|
-
var NetworkMemoryThread = class extends BaseResource {
|
|
1757
|
-
constructor(options, threadId, networkId) {
|
|
1758
|
-
super(options);
|
|
1759
|
-
this.threadId = threadId;
|
|
1760
|
-
this.networkId = networkId;
|
|
1761
|
-
}
|
|
1762
|
-
/**
|
|
1763
|
-
* Retrieves the memory thread details
|
|
1764
|
-
* @returns Promise containing thread details including title and metadata
|
|
1765
|
-
*/
|
|
1766
|
-
get() {
|
|
1767
|
-
return this.request(`/api/memory/network/threads/${this.threadId}?networkId=${this.networkId}`);
|
|
1768
|
-
}
|
|
1769
|
-
/**
|
|
1770
|
-
* Updates the memory thread properties
|
|
1771
|
-
* @param params - Update parameters including title and metadata
|
|
1772
|
-
* @returns Promise containing updated thread details
|
|
1773
|
-
*/
|
|
1774
|
-
update(params) {
|
|
1775
|
-
return this.request(`/api/memory/network/threads/${this.threadId}?networkId=${this.networkId}`, {
|
|
1776
|
-
method: "PATCH",
|
|
1777
|
-
body: params
|
|
1778
|
-
});
|
|
1779
|
-
}
|
|
1780
|
-
/**
|
|
1781
|
-
* Deletes the memory thread
|
|
1782
|
-
* @returns Promise containing deletion result
|
|
1783
|
-
*/
|
|
1784
|
-
delete() {
|
|
1785
|
-
return this.request(`/api/memory/network/threads/${this.threadId}?networkId=${this.networkId}`, {
|
|
1786
|
-
method: "DELETE"
|
|
1787
|
-
});
|
|
1788
|
-
}
|
|
1789
|
-
/**
|
|
1790
|
-
* Retrieves messages associated with the thread
|
|
1791
|
-
* @param params - Optional parameters including limit for number of messages to retrieve
|
|
1792
|
-
* @returns Promise containing thread messages and UI messages
|
|
1793
|
-
*/
|
|
1794
|
-
getMessages(params) {
|
|
1795
|
-
const query = new URLSearchParams({
|
|
1796
|
-
networkId: this.networkId,
|
|
1797
|
-
...params?.limit ? { limit: params.limit.toString() } : {}
|
|
1798
|
-
});
|
|
1799
|
-
return this.request(`/api/memory/network/threads/${this.threadId}/messages?${query.toString()}`);
|
|
1800
|
-
}
|
|
1801
|
-
};
|
|
1802
|
-
|
|
1803
1915
|
// src/client.ts
|
|
1804
1916
|
var MastraClient = class extends BaseResource {
|
|
1805
1917
|
constructor(options) {
|
|
@@ -2194,6 +2306,121 @@ var MastraClient = class extends BaseResource {
|
|
|
2194
2306
|
getA2A(agentId) {
|
|
2195
2307
|
return new A2A(this.options, agentId);
|
|
2196
2308
|
}
|
|
2309
|
+
/**
|
|
2310
|
+
* Retrieves the working memory for a specific thread (optionally resource-scoped).
|
|
2311
|
+
* @param agentId - ID of the agent.
|
|
2312
|
+
* @param threadId - ID of the thread.
|
|
2313
|
+
* @param resourceId - Optional ID of the resource.
|
|
2314
|
+
* @returns Working memory for the specified thread or resource.
|
|
2315
|
+
*/
|
|
2316
|
+
getWorkingMemory({
|
|
2317
|
+
agentId,
|
|
2318
|
+
threadId,
|
|
2319
|
+
resourceId
|
|
2320
|
+
}) {
|
|
2321
|
+
return this.request(`/api/memory/threads/${threadId}/working-memory?agentId=${agentId}&resourceId=${resourceId}`);
|
|
2322
|
+
}
|
|
2323
|
+
/**
|
|
2324
|
+
* Updates the working memory for a specific thread (optionally resource-scoped).
|
|
2325
|
+
* @param agentId - ID of the agent.
|
|
2326
|
+
* @param threadId - ID of the thread.
|
|
2327
|
+
* @param workingMemory - The new working memory content.
|
|
2328
|
+
* @param resourceId - Optional ID of the resource.
|
|
2329
|
+
*/
|
|
2330
|
+
updateWorkingMemory({
|
|
2331
|
+
agentId,
|
|
2332
|
+
threadId,
|
|
2333
|
+
workingMemory,
|
|
2334
|
+
resourceId
|
|
2335
|
+
}) {
|
|
2336
|
+
return this.request(`/api/memory/threads/${threadId}/working-memory?agentId=${agentId}`, {
|
|
2337
|
+
method: "POST",
|
|
2338
|
+
body: {
|
|
2339
|
+
workingMemory,
|
|
2340
|
+
resourceId
|
|
2341
|
+
}
|
|
2342
|
+
});
|
|
2343
|
+
}
|
|
2344
|
+
/**
|
|
2345
|
+
* Retrieves all available scorers
|
|
2346
|
+
* @returns Promise containing list of available scorers
|
|
2347
|
+
*/
|
|
2348
|
+
getScorers() {
|
|
2349
|
+
return this.request("/api/scores/scorers");
|
|
2350
|
+
}
|
|
2351
|
+
/**
|
|
2352
|
+
* Retrieves a scorer by ID
|
|
2353
|
+
* @param scorerId - ID of the scorer to retrieve
|
|
2354
|
+
* @returns Promise containing the scorer
|
|
2355
|
+
*/
|
|
2356
|
+
getScorer(scorerId) {
|
|
2357
|
+
return this.request(`/api/scores/scorers/${scorerId}`);
|
|
2358
|
+
}
|
|
2359
|
+
getScoresByScorerId(params) {
|
|
2360
|
+
const { page, perPage, scorerId, entityId, entityType } = params;
|
|
2361
|
+
const searchParams = new URLSearchParams();
|
|
2362
|
+
if (entityId) {
|
|
2363
|
+
searchParams.set("entityId", entityId);
|
|
2364
|
+
}
|
|
2365
|
+
if (entityType) {
|
|
2366
|
+
searchParams.set("entityType", entityType);
|
|
2367
|
+
}
|
|
2368
|
+
if (page !== void 0) {
|
|
2369
|
+
searchParams.set("page", String(page));
|
|
2370
|
+
}
|
|
2371
|
+
if (perPage !== void 0) {
|
|
2372
|
+
searchParams.set("perPage", String(perPage));
|
|
2373
|
+
}
|
|
2374
|
+
const queryString = searchParams.toString();
|
|
2375
|
+
return this.request(`/api/scores/scorer/${scorerId}${queryString ? `?${queryString}` : ""}`);
|
|
2376
|
+
}
|
|
2377
|
+
/**
|
|
2378
|
+
* Retrieves scores by run ID
|
|
2379
|
+
* @param params - Parameters containing run ID and pagination options
|
|
2380
|
+
* @returns Promise containing scores and pagination info
|
|
2381
|
+
*/
|
|
2382
|
+
getScoresByRunId(params) {
|
|
2383
|
+
const { runId, page, perPage } = params;
|
|
2384
|
+
const searchParams = new URLSearchParams();
|
|
2385
|
+
if (page !== void 0) {
|
|
2386
|
+
searchParams.set("page", String(page));
|
|
2387
|
+
}
|
|
2388
|
+
if (perPage !== void 0) {
|
|
2389
|
+
searchParams.set("perPage", String(perPage));
|
|
2390
|
+
}
|
|
2391
|
+
const queryString = searchParams.toString();
|
|
2392
|
+
return this.request(`/api/scores/run/${runId}${queryString ? `?${queryString}` : ""}`);
|
|
2393
|
+
}
|
|
2394
|
+
/**
|
|
2395
|
+
* Retrieves scores by entity ID and type
|
|
2396
|
+
* @param params - Parameters containing entity ID, type, and pagination options
|
|
2397
|
+
* @returns Promise containing scores and pagination info
|
|
2398
|
+
*/
|
|
2399
|
+
getScoresByEntityId(params) {
|
|
2400
|
+
const { entityId, entityType, page, perPage } = params;
|
|
2401
|
+
const searchParams = new URLSearchParams();
|
|
2402
|
+
if (page !== void 0) {
|
|
2403
|
+
searchParams.set("page", String(page));
|
|
2404
|
+
}
|
|
2405
|
+
if (perPage !== void 0) {
|
|
2406
|
+
searchParams.set("perPage", String(perPage));
|
|
2407
|
+
}
|
|
2408
|
+
const queryString = searchParams.toString();
|
|
2409
|
+
return this.request(`/api/scores/entity/${entityType}/${entityId}${queryString ? `?${queryString}` : ""}`);
|
|
2410
|
+
}
|
|
2411
|
+
/**
|
|
2412
|
+
* Saves a score
|
|
2413
|
+
* @param params - Parameters containing the score data to save
|
|
2414
|
+
* @returns Promise containing the saved score
|
|
2415
|
+
*/
|
|
2416
|
+
saveScore(params) {
|
|
2417
|
+
return this.request("/api/scores", {
|
|
2418
|
+
method: "POST",
|
|
2419
|
+
body: params
|
|
2420
|
+
});
|
|
2421
|
+
}
|
|
2197
2422
|
};
|
|
2198
2423
|
|
|
2199
2424
|
export { MastraClient };
|
|
2425
|
+
//# sourceMappingURL=index.js.map
|
|
2426
|
+
//# sourceMappingURL=index.js.map
|