@mastra/client-js 0.0.0-custom-instrumentation-20250626084921 → 0.0.0-declaration-maps-20250729202623
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 +8 -10
- package/CHANGELOG.md +452 -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 +305 -69
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +4 -1126
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +304 -68
- 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/package.json +8 -7
- 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 +64 -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 +43 -6
- package/src/types.ts +105 -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/dist/index.d.cts +0 -1126
|
@@ -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
|
|
@@ -246,12 +247,13 @@ var BaseResource = class {
|
|
|
246
247
|
const response = await fetch(`${baseUrl.replace(/\/$/, "")}${path}`, {
|
|
247
248
|
...options,
|
|
248
249
|
headers: {
|
|
249
|
-
...options.method === "POST" || options.method === "PUT" ? { "content-type": "application/json" } : {},
|
|
250
|
+
...options.body && !(options.body instanceof FormData) && (options.method === "POST" || options.method === "PUT") ? { "content-type": "application/json" } : {},
|
|
250
251
|
...headers,
|
|
251
252
|
...options.headers
|
|
252
253
|
// TODO: Bring this back once we figure out what we/users need to do to make this work with cross-origin requests
|
|
253
254
|
// 'x-mastra-client-type': 'js',
|
|
254
255
|
},
|
|
256
|
+
signal: this.options.abortSignal,
|
|
255
257
|
body: options.body instanceof FormData ? options.body : options.body ? JSON.stringify(options.body) : void 0
|
|
256
258
|
});
|
|
257
259
|
if (!response.ok) {
|
|
@@ -370,12 +372,19 @@ var Agent = class extends BaseResource {
|
|
|
370
372
|
clientTools: processClientTools(params.clientTools)
|
|
371
373
|
};
|
|
372
374
|
const { runId, resourceId, threadId, runtimeContext } = processedParams;
|
|
373
|
-
const response = await this.request(
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
375
|
+
const response = await this.request(
|
|
376
|
+
`/api/agents/${this.agentId}/generate`,
|
|
377
|
+
{
|
|
378
|
+
method: "POST",
|
|
379
|
+
body: processedParams
|
|
380
|
+
}
|
|
381
|
+
);
|
|
377
382
|
if (response.finishReason === "tool-calls") {
|
|
378
|
-
|
|
383
|
+
const toolCalls = response.toolCalls;
|
|
384
|
+
if (!toolCalls || !Array.isArray(toolCalls)) {
|
|
385
|
+
return response;
|
|
386
|
+
}
|
|
387
|
+
for (const toolCall of toolCalls) {
|
|
379
388
|
const clientTool = params.clientTools?.[toolCall.toolName];
|
|
380
389
|
if (clientTool && clientTool.execute) {
|
|
381
390
|
const result = await clientTool.execute(
|
|
@@ -426,7 +435,7 @@ var Agent = class extends BaseResource {
|
|
|
426
435
|
return Math.max(max, toolInvocation.step ?? 0);
|
|
427
436
|
}, 0) ?? 0) : 0;
|
|
428
437
|
const message = replaceLastMessage ? structuredClone(lastMessage) : {
|
|
429
|
-
id:
|
|
438
|
+
id: v4(),
|
|
430
439
|
createdAt: getCurrentDate(),
|
|
431
440
|
role: "assistant",
|
|
432
441
|
content: "",
|
|
@@ -471,7 +480,7 @@ var Agent = class extends BaseResource {
|
|
|
471
480
|
// changes. This is why we need to add a revision id to ensure that the message
|
|
472
481
|
// is updated with SWR (without it, the changes get stuck in SWR and are not
|
|
473
482
|
// forwarded to rendering):
|
|
474
|
-
revisionId:
|
|
483
|
+
revisionId: v4()
|
|
475
484
|
};
|
|
476
485
|
update({
|
|
477
486
|
message: copiedMessage,
|
|
@@ -726,7 +735,12 @@ var Agent = class extends BaseResource {
|
|
|
726
735
|
this.processChatResponse({
|
|
727
736
|
stream: streamForProcessing,
|
|
728
737
|
update: ({ message }) => {
|
|
729
|
-
messages.
|
|
738
|
+
const existingIndex = messages.findIndex((m) => m.id === message.id);
|
|
739
|
+
if (existingIndex !== -1) {
|
|
740
|
+
messages[existingIndex] = message;
|
|
741
|
+
} else {
|
|
742
|
+
messages.push(message);
|
|
743
|
+
}
|
|
730
744
|
},
|
|
731
745
|
onFinish: async ({ finishReason, message }) => {
|
|
732
746
|
if (finishReason === "tool-calls") {
|
|
@@ -768,15 +782,30 @@ var Agent = class extends BaseResource {
|
|
|
768
782
|
toolInvocation.state = "result";
|
|
769
783
|
toolInvocation.result = result;
|
|
770
784
|
}
|
|
785
|
+
const writer = writable.getWriter();
|
|
786
|
+
try {
|
|
787
|
+
await writer.write(
|
|
788
|
+
new TextEncoder().encode(
|
|
789
|
+
"a:" + JSON.stringify({
|
|
790
|
+
toolCallId: toolCall2.toolCallId,
|
|
791
|
+
result
|
|
792
|
+
}) + "\n"
|
|
793
|
+
)
|
|
794
|
+
);
|
|
795
|
+
} finally {
|
|
796
|
+
writer.releaseLock();
|
|
797
|
+
}
|
|
771
798
|
const originalMessages = processedParams.messages;
|
|
772
799
|
const messageArray = Array.isArray(originalMessages) ? originalMessages : [originalMessages];
|
|
773
800
|
this.processStreamResponse(
|
|
774
801
|
{
|
|
775
802
|
...processedParams,
|
|
776
|
-
messages: [...messageArray, ...messages, lastMessage]
|
|
803
|
+
messages: [...messageArray, ...messages.filter((m) => m.id !== lastMessage.id), lastMessage]
|
|
777
804
|
},
|
|
778
805
|
writable
|
|
779
|
-
)
|
|
806
|
+
).catch((error) => {
|
|
807
|
+
console.error("Error processing stream response:", error);
|
|
808
|
+
});
|
|
780
809
|
}
|
|
781
810
|
}
|
|
782
811
|
} else {
|
|
@@ -786,6 +815,8 @@ var Agent = class extends BaseResource {
|
|
|
786
815
|
}
|
|
787
816
|
},
|
|
788
817
|
lastMessage: void 0
|
|
818
|
+
}).catch((error) => {
|
|
819
|
+
console.error("Error processing stream response:", error);
|
|
789
820
|
});
|
|
790
821
|
} catch (error) {
|
|
791
822
|
console.error("Error processing stream response:", error);
|
|
@@ -934,6 +965,36 @@ var MemoryThread = class extends BaseResource {
|
|
|
934
965
|
});
|
|
935
966
|
return this.request(`/api/memory/threads/${this.threadId}/messages?${query.toString()}`);
|
|
936
967
|
}
|
|
968
|
+
/**
|
|
969
|
+
* Retrieves paginated messages associated with the thread with advanced filtering and selection options
|
|
970
|
+
* @param params - Pagination parameters including selectBy criteria, page, perPage, date ranges, and message inclusion options
|
|
971
|
+
* @returns Promise containing paginated thread messages with pagination metadata (total, page, perPage, hasMore)
|
|
972
|
+
*/
|
|
973
|
+
getMessagesPaginated({
|
|
974
|
+
selectBy,
|
|
975
|
+
...rest
|
|
976
|
+
}) {
|
|
977
|
+
const query = new URLSearchParams({
|
|
978
|
+
...rest,
|
|
979
|
+
...selectBy ? { selectBy: JSON.stringify(selectBy) } : {}
|
|
980
|
+
});
|
|
981
|
+
return this.request(`/api/memory/threads/${this.threadId}/messages/paginated?${query.toString()}`);
|
|
982
|
+
}
|
|
983
|
+
/**
|
|
984
|
+
* Deletes one or more messages from the thread
|
|
985
|
+
* @param messageIds - Can be a single message ID (string), array of message IDs,
|
|
986
|
+
* message object with id property, or array of message objects
|
|
987
|
+
* @returns Promise containing deletion result
|
|
988
|
+
*/
|
|
989
|
+
deleteMessages(messageIds) {
|
|
990
|
+
const query = new URLSearchParams({
|
|
991
|
+
agentId: this.agentId
|
|
992
|
+
});
|
|
993
|
+
return this.request(`/api/memory/messages/delete?${query.toString()}`, {
|
|
994
|
+
method: "POST",
|
|
995
|
+
body: { messageIds }
|
|
996
|
+
});
|
|
997
|
+
}
|
|
937
998
|
};
|
|
938
999
|
|
|
939
1000
|
// src/resources/vector.ts
|
|
@@ -1289,10 +1350,10 @@ var Workflow = class extends BaseResource {
|
|
|
1289
1350
|
if (params?.toDate) {
|
|
1290
1351
|
searchParams.set("toDate", params.toDate.toISOString());
|
|
1291
1352
|
}
|
|
1292
|
-
if (params?.limit) {
|
|
1353
|
+
if (params?.limit !== null && params?.limit !== void 0 && !isNaN(Number(params?.limit))) {
|
|
1293
1354
|
searchParams.set("limit", String(params.limit));
|
|
1294
1355
|
}
|
|
1295
|
-
if (params?.offset) {
|
|
1356
|
+
if (params?.offset !== null && params?.offset !== void 0 && !isNaN(Number(params?.offset))) {
|
|
1296
1357
|
searchParams.set("offset", String(params.offset));
|
|
1297
1358
|
}
|
|
1298
1359
|
if (params?.resourceId) {
|
|
@@ -1320,6 +1381,27 @@ var Workflow = class extends BaseResource {
|
|
|
1320
1381
|
runExecutionResult(runId) {
|
|
1321
1382
|
return this.request(`/api/workflows/${this.workflowId}/runs/${runId}/execution-result`);
|
|
1322
1383
|
}
|
|
1384
|
+
/**
|
|
1385
|
+
* Cancels a specific workflow run by its ID
|
|
1386
|
+
* @param runId - The ID of the workflow run to cancel
|
|
1387
|
+
* @returns Promise containing a success message
|
|
1388
|
+
*/
|
|
1389
|
+
cancelRun(runId) {
|
|
1390
|
+
return this.request(`/api/workflows/${this.workflowId}/runs/${runId}/cancel`, {
|
|
1391
|
+
method: "POST"
|
|
1392
|
+
});
|
|
1393
|
+
}
|
|
1394
|
+
/**
|
|
1395
|
+
* Sends an event to a specific workflow run by its ID
|
|
1396
|
+
* @param params - Object containing the runId, event and data
|
|
1397
|
+
* @returns Promise containing a success message
|
|
1398
|
+
*/
|
|
1399
|
+
sendRunEvent(params) {
|
|
1400
|
+
return this.request(`/api/workflows/${this.workflowId}/runs/${params.runId}/send-event`, {
|
|
1401
|
+
method: "POST",
|
|
1402
|
+
body: { event: params.event, data: params.data }
|
|
1403
|
+
});
|
|
1404
|
+
}
|
|
1323
1405
|
/**
|
|
1324
1406
|
* Creates a new workflow run
|
|
1325
1407
|
* @param params - Optional object containing the optional runId
|
|
@@ -1334,6 +1416,14 @@ var Workflow = class extends BaseResource {
|
|
|
1334
1416
|
method: "POST"
|
|
1335
1417
|
});
|
|
1336
1418
|
}
|
|
1419
|
+
/**
|
|
1420
|
+
* Creates a new workflow run (alias for createRun)
|
|
1421
|
+
* @param params - Optional object containing the optional runId
|
|
1422
|
+
* @returns Promise containing the runId of the created run
|
|
1423
|
+
*/
|
|
1424
|
+
createRunAsync(params) {
|
|
1425
|
+
return this.createRun(params);
|
|
1426
|
+
}
|
|
1337
1427
|
/**
|
|
1338
1428
|
* Starts a workflow run synchronously without waiting for the workflow to complete
|
|
1339
1429
|
* @param params - Object containing the runId, inputData and runtimeContext
|
|
@@ -1409,6 +1499,7 @@ var Workflow = class extends BaseResource {
|
|
|
1409
1499
|
if (!response.body) {
|
|
1410
1500
|
throw new Error("Response body is null");
|
|
1411
1501
|
}
|
|
1502
|
+
let failedChunk = void 0;
|
|
1412
1503
|
const transformStream = new TransformStream({
|
|
1413
1504
|
start() {
|
|
1414
1505
|
},
|
|
@@ -1418,10 +1509,13 @@ var Workflow = class extends BaseResource {
|
|
|
1418
1509
|
const chunks = decoded.split(RECORD_SEPARATOR2);
|
|
1419
1510
|
for (const chunk2 of chunks) {
|
|
1420
1511
|
if (chunk2) {
|
|
1512
|
+
const newChunk = failedChunk ? failedChunk + chunk2 : chunk2;
|
|
1421
1513
|
try {
|
|
1422
|
-
const parsedChunk = JSON.parse(
|
|
1514
|
+
const parsedChunk = JSON.parse(newChunk);
|
|
1423
1515
|
controller.enqueue(parsedChunk);
|
|
1424
|
-
|
|
1516
|
+
failedChunk = void 0;
|
|
1517
|
+
} catch (error) {
|
|
1518
|
+
failedChunk = newChunk;
|
|
1425
1519
|
}
|
|
1426
1520
|
}
|
|
1427
1521
|
}
|
|
@@ -1603,6 +1697,69 @@ var MCPTool = class extends BaseResource {
|
|
|
1603
1697
|
}
|
|
1604
1698
|
};
|
|
1605
1699
|
|
|
1700
|
+
// src/resources/network-memory-thread.ts
|
|
1701
|
+
var NetworkMemoryThread = class extends BaseResource {
|
|
1702
|
+
constructor(options, threadId, networkId) {
|
|
1703
|
+
super(options);
|
|
1704
|
+
this.threadId = threadId;
|
|
1705
|
+
this.networkId = networkId;
|
|
1706
|
+
}
|
|
1707
|
+
/**
|
|
1708
|
+
* Retrieves the memory thread details
|
|
1709
|
+
* @returns Promise containing thread details including title and metadata
|
|
1710
|
+
*/
|
|
1711
|
+
get() {
|
|
1712
|
+
return this.request(`/api/memory/network/threads/${this.threadId}?networkId=${this.networkId}`);
|
|
1713
|
+
}
|
|
1714
|
+
/**
|
|
1715
|
+
* Updates the memory thread properties
|
|
1716
|
+
* @param params - Update parameters including title and metadata
|
|
1717
|
+
* @returns Promise containing updated thread details
|
|
1718
|
+
*/
|
|
1719
|
+
update(params) {
|
|
1720
|
+
return this.request(`/api/memory/network/threads/${this.threadId}?networkId=${this.networkId}`, {
|
|
1721
|
+
method: "PATCH",
|
|
1722
|
+
body: params
|
|
1723
|
+
});
|
|
1724
|
+
}
|
|
1725
|
+
/**
|
|
1726
|
+
* Deletes the memory thread
|
|
1727
|
+
* @returns Promise containing deletion result
|
|
1728
|
+
*/
|
|
1729
|
+
delete() {
|
|
1730
|
+
return this.request(`/api/memory/network/threads/${this.threadId}?networkId=${this.networkId}`, {
|
|
1731
|
+
method: "DELETE"
|
|
1732
|
+
});
|
|
1733
|
+
}
|
|
1734
|
+
/**
|
|
1735
|
+
* Retrieves messages associated with the thread
|
|
1736
|
+
* @param params - Optional parameters including limit for number of messages to retrieve
|
|
1737
|
+
* @returns Promise containing thread messages and UI messages
|
|
1738
|
+
*/
|
|
1739
|
+
getMessages(params) {
|
|
1740
|
+
const query = new URLSearchParams({
|
|
1741
|
+
networkId: this.networkId,
|
|
1742
|
+
...params?.limit ? { limit: params.limit.toString() } : {}
|
|
1743
|
+
});
|
|
1744
|
+
return this.request(`/api/memory/network/threads/${this.threadId}/messages?${query.toString()}`);
|
|
1745
|
+
}
|
|
1746
|
+
/**
|
|
1747
|
+
* Deletes one or more messages from the thread
|
|
1748
|
+
* @param messageIds - Can be a single message ID (string), array of message IDs,
|
|
1749
|
+
* message object with id property, or array of message objects
|
|
1750
|
+
* @returns Promise containing deletion result
|
|
1751
|
+
*/
|
|
1752
|
+
deleteMessages(messageIds) {
|
|
1753
|
+
const query = new URLSearchParams({
|
|
1754
|
+
networkId: this.networkId
|
|
1755
|
+
});
|
|
1756
|
+
return this.request(`/api/memory/network/messages/delete?${query.toString()}`, {
|
|
1757
|
+
method: "POST",
|
|
1758
|
+
body: { messageIds }
|
|
1759
|
+
});
|
|
1760
|
+
}
|
|
1761
|
+
};
|
|
1762
|
+
|
|
1606
1763
|
// src/resources/vNextNetwork.ts
|
|
1607
1764
|
var RECORD_SEPARATOR3 = "";
|
|
1608
1765
|
var VNextNetwork = class extends BaseResource {
|
|
@@ -1625,7 +1782,10 @@ var VNextNetwork = class extends BaseResource {
|
|
|
1625
1782
|
generate(params) {
|
|
1626
1783
|
return this.request(`/api/networks/v-next/${this.networkId}/generate`, {
|
|
1627
1784
|
method: "POST",
|
|
1628
|
-
body:
|
|
1785
|
+
body: {
|
|
1786
|
+
...params,
|
|
1787
|
+
runtimeContext: parseClientRuntimeContext(params.runtimeContext)
|
|
1788
|
+
}
|
|
1629
1789
|
});
|
|
1630
1790
|
}
|
|
1631
1791
|
/**
|
|
@@ -1636,7 +1796,10 @@ var VNextNetwork = class extends BaseResource {
|
|
|
1636
1796
|
loop(params) {
|
|
1637
1797
|
return this.request(`/api/networks/v-next/${this.networkId}/loop`, {
|
|
1638
1798
|
method: "POST",
|
|
1639
|
-
body:
|
|
1799
|
+
body: {
|
|
1800
|
+
...params,
|
|
1801
|
+
runtimeContext: parseClientRuntimeContext(params.runtimeContext)
|
|
1802
|
+
}
|
|
1640
1803
|
});
|
|
1641
1804
|
}
|
|
1642
1805
|
async *streamProcessor(stream) {
|
|
@@ -1685,7 +1848,10 @@ var VNextNetwork = class extends BaseResource {
|
|
|
1685
1848
|
async stream(params, onRecord) {
|
|
1686
1849
|
const response = await this.request(`/api/networks/v-next/${this.networkId}/stream`, {
|
|
1687
1850
|
method: "POST",
|
|
1688
|
-
body:
|
|
1851
|
+
body: {
|
|
1852
|
+
...params,
|
|
1853
|
+
runtimeContext: parseClientRuntimeContext(params.runtimeContext)
|
|
1854
|
+
},
|
|
1689
1855
|
stream: true
|
|
1690
1856
|
});
|
|
1691
1857
|
if (!response.ok) {
|
|
@@ -1710,7 +1876,10 @@ var VNextNetwork = class extends BaseResource {
|
|
|
1710
1876
|
async loopStream(params, onRecord) {
|
|
1711
1877
|
const response = await this.request(`/api/networks/v-next/${this.networkId}/loop-stream`, {
|
|
1712
1878
|
method: "POST",
|
|
1713
|
-
body:
|
|
1879
|
+
body: {
|
|
1880
|
+
...params,
|
|
1881
|
+
runtimeContext: parseClientRuntimeContext(params.runtimeContext)
|
|
1882
|
+
},
|
|
1714
1883
|
stream: true
|
|
1715
1884
|
});
|
|
1716
1885
|
if (!response.ok) {
|
|
@@ -1729,54 +1898,6 @@ var VNextNetwork = class extends BaseResource {
|
|
|
1729
1898
|
}
|
|
1730
1899
|
};
|
|
1731
1900
|
|
|
1732
|
-
// src/resources/network-memory-thread.ts
|
|
1733
|
-
var NetworkMemoryThread = class extends BaseResource {
|
|
1734
|
-
constructor(options, threadId, networkId) {
|
|
1735
|
-
super(options);
|
|
1736
|
-
this.threadId = threadId;
|
|
1737
|
-
this.networkId = networkId;
|
|
1738
|
-
}
|
|
1739
|
-
/**
|
|
1740
|
-
* Retrieves the memory thread details
|
|
1741
|
-
* @returns Promise containing thread details including title and metadata
|
|
1742
|
-
*/
|
|
1743
|
-
get() {
|
|
1744
|
-
return this.request(`/api/memory/network/threads/${this.threadId}?networkId=${this.networkId}`);
|
|
1745
|
-
}
|
|
1746
|
-
/**
|
|
1747
|
-
* Updates the memory thread properties
|
|
1748
|
-
* @param params - Update parameters including title and metadata
|
|
1749
|
-
* @returns Promise containing updated thread details
|
|
1750
|
-
*/
|
|
1751
|
-
update(params) {
|
|
1752
|
-
return this.request(`/api/memory/network/threads/${this.threadId}?networkId=${this.networkId}`, {
|
|
1753
|
-
method: "PATCH",
|
|
1754
|
-
body: params
|
|
1755
|
-
});
|
|
1756
|
-
}
|
|
1757
|
-
/**
|
|
1758
|
-
* Deletes the memory thread
|
|
1759
|
-
* @returns Promise containing deletion result
|
|
1760
|
-
*/
|
|
1761
|
-
delete() {
|
|
1762
|
-
return this.request(`/api/memory/network/threads/${this.threadId}?networkId=${this.networkId}`, {
|
|
1763
|
-
method: "DELETE"
|
|
1764
|
-
});
|
|
1765
|
-
}
|
|
1766
|
-
/**
|
|
1767
|
-
* Retrieves messages associated with the thread
|
|
1768
|
-
* @param params - Optional parameters including limit for number of messages to retrieve
|
|
1769
|
-
* @returns Promise containing thread messages and UI messages
|
|
1770
|
-
*/
|
|
1771
|
-
getMessages(params) {
|
|
1772
|
-
const query = new URLSearchParams({
|
|
1773
|
-
networkId: this.networkId,
|
|
1774
|
-
...params?.limit ? { limit: params.limit.toString() } : {}
|
|
1775
|
-
});
|
|
1776
|
-
return this.request(`/api/memory/network/threads/${this.threadId}/messages?${query.toString()}`);
|
|
1777
|
-
}
|
|
1778
|
-
};
|
|
1779
|
-
|
|
1780
1901
|
// src/client.ts
|
|
1781
1902
|
var MastraClient = class extends BaseResource {
|
|
1782
1903
|
constructor(options) {
|
|
@@ -2171,6 +2292,121 @@ var MastraClient = class extends BaseResource {
|
|
|
2171
2292
|
getA2A(agentId) {
|
|
2172
2293
|
return new A2A(this.options, agentId);
|
|
2173
2294
|
}
|
|
2295
|
+
/**
|
|
2296
|
+
* Retrieves the working memory for a specific thread (optionally resource-scoped).
|
|
2297
|
+
* @param agentId - ID of the agent.
|
|
2298
|
+
* @param threadId - ID of the thread.
|
|
2299
|
+
* @param resourceId - Optional ID of the resource.
|
|
2300
|
+
* @returns Working memory for the specified thread or resource.
|
|
2301
|
+
*/
|
|
2302
|
+
getWorkingMemory({
|
|
2303
|
+
agentId,
|
|
2304
|
+
threadId,
|
|
2305
|
+
resourceId
|
|
2306
|
+
}) {
|
|
2307
|
+
return this.request(`/api/memory/threads/${threadId}/working-memory?agentId=${agentId}&resourceId=${resourceId}`);
|
|
2308
|
+
}
|
|
2309
|
+
/**
|
|
2310
|
+
* Updates 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 workingMemory - The new working memory content.
|
|
2314
|
+
* @param resourceId - Optional ID of the resource.
|
|
2315
|
+
*/
|
|
2316
|
+
updateWorkingMemory({
|
|
2317
|
+
agentId,
|
|
2318
|
+
threadId,
|
|
2319
|
+
workingMemory,
|
|
2320
|
+
resourceId
|
|
2321
|
+
}) {
|
|
2322
|
+
return this.request(`/api/memory/threads/${threadId}/working-memory?agentId=${agentId}`, {
|
|
2323
|
+
method: "POST",
|
|
2324
|
+
body: {
|
|
2325
|
+
workingMemory,
|
|
2326
|
+
resourceId
|
|
2327
|
+
}
|
|
2328
|
+
});
|
|
2329
|
+
}
|
|
2330
|
+
/**
|
|
2331
|
+
* Retrieves all available scorers
|
|
2332
|
+
* @returns Promise containing list of available scorers
|
|
2333
|
+
*/
|
|
2334
|
+
getScorers() {
|
|
2335
|
+
return this.request("/api/scores/scorers");
|
|
2336
|
+
}
|
|
2337
|
+
/**
|
|
2338
|
+
* Retrieves a scorer by ID
|
|
2339
|
+
* @param scorerId - ID of the scorer to retrieve
|
|
2340
|
+
* @returns Promise containing the scorer
|
|
2341
|
+
*/
|
|
2342
|
+
getScorer(scorerId) {
|
|
2343
|
+
return this.request(`/api/scores/scorers/${scorerId}`);
|
|
2344
|
+
}
|
|
2345
|
+
getScoresByScorerId(params) {
|
|
2346
|
+
const { page, perPage, scorerId, entityId, entityType } = params;
|
|
2347
|
+
const searchParams = new URLSearchParams();
|
|
2348
|
+
if (entityId) {
|
|
2349
|
+
searchParams.set("entityId", entityId);
|
|
2350
|
+
}
|
|
2351
|
+
if (entityType) {
|
|
2352
|
+
searchParams.set("entityType", entityType);
|
|
2353
|
+
}
|
|
2354
|
+
if (page !== void 0) {
|
|
2355
|
+
searchParams.set("page", String(page));
|
|
2356
|
+
}
|
|
2357
|
+
if (perPage !== void 0) {
|
|
2358
|
+
searchParams.set("perPage", String(perPage));
|
|
2359
|
+
}
|
|
2360
|
+
const queryString = searchParams.toString();
|
|
2361
|
+
return this.request(`/api/scores/scorer/${scorerId}${queryString ? `?${queryString}` : ""}`);
|
|
2362
|
+
}
|
|
2363
|
+
/**
|
|
2364
|
+
* Retrieves scores by run ID
|
|
2365
|
+
* @param params - Parameters containing run ID and pagination options
|
|
2366
|
+
* @returns Promise containing scores and pagination info
|
|
2367
|
+
*/
|
|
2368
|
+
getScoresByRunId(params) {
|
|
2369
|
+
const { runId, page, perPage } = params;
|
|
2370
|
+
const searchParams = new URLSearchParams();
|
|
2371
|
+
if (page !== void 0) {
|
|
2372
|
+
searchParams.set("page", String(page));
|
|
2373
|
+
}
|
|
2374
|
+
if (perPage !== void 0) {
|
|
2375
|
+
searchParams.set("perPage", String(perPage));
|
|
2376
|
+
}
|
|
2377
|
+
const queryString = searchParams.toString();
|
|
2378
|
+
return this.request(`/api/scores/run/${runId}${queryString ? `?${queryString}` : ""}`);
|
|
2379
|
+
}
|
|
2380
|
+
/**
|
|
2381
|
+
* Retrieves scores by entity ID and type
|
|
2382
|
+
* @param params - Parameters containing entity ID, type, and pagination options
|
|
2383
|
+
* @returns Promise containing scores and pagination info
|
|
2384
|
+
*/
|
|
2385
|
+
getScoresByEntityId(params) {
|
|
2386
|
+
const { entityId, entityType, page, perPage } = params;
|
|
2387
|
+
const searchParams = new URLSearchParams();
|
|
2388
|
+
if (page !== void 0) {
|
|
2389
|
+
searchParams.set("page", String(page));
|
|
2390
|
+
}
|
|
2391
|
+
if (perPage !== void 0) {
|
|
2392
|
+
searchParams.set("perPage", String(perPage));
|
|
2393
|
+
}
|
|
2394
|
+
const queryString = searchParams.toString();
|
|
2395
|
+
return this.request(`/api/scores/entity/${entityType}/${entityId}${queryString ? `?${queryString}` : ""}`);
|
|
2396
|
+
}
|
|
2397
|
+
/**
|
|
2398
|
+
* Saves a score
|
|
2399
|
+
* @param params - Parameters containing the score data to save
|
|
2400
|
+
* @returns Promise containing the saved score
|
|
2401
|
+
*/
|
|
2402
|
+
saveScore(params) {
|
|
2403
|
+
return this.request("/api/scores", {
|
|
2404
|
+
method: "POST",
|
|
2405
|
+
body: params
|
|
2406
|
+
});
|
|
2407
|
+
}
|
|
2174
2408
|
};
|
|
2175
2409
|
|
|
2176
2410
|
export { MastraClient };
|
|
2411
|
+
//# sourceMappingURL=index.js.map
|
|
2412
|
+
//# sourceMappingURL=index.js.map
|