@mastra/client-js 0.0.0-tool-call-parts-20250630193309 → 0.0.0-transpile-packages-20250730132657
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 +318 -3
- package/LICENSE.md +11 -42
- package/README.md +1 -0
- package/dist/index.cjs +261 -66
- package/dist/index.d.cts +211 -45
- package/dist/index.d.ts +211 -45
- package/dist/index.js +260 -65
- package/package.json +6 -5
- package/src/client.ts +145 -2
- package/src/example.ts +45 -17
- package/src/index.test.ts +294 -6
- package/src/resources/agent.ts +51 -21
- package/src/resources/base.ts +6 -1
- package/src/resources/memory-thread.ts +18 -0
- package/src/resources/network.ts +4 -3
- package/src/resources/vNextNetwork.ts +22 -5
- package/src/resources/workflow.ts +42 -5
- package/src/types.ts +95 -4
- package/src/utils/process-client-tools.ts +1 -1
- package/.turbo/turbo-build.log +0 -19
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,
|
|
@@ -768,6 +777,19 @@ var Agent = class extends BaseResource {
|
|
|
768
777
|
toolInvocation.state = "result";
|
|
769
778
|
toolInvocation.result = result;
|
|
770
779
|
}
|
|
780
|
+
const writer = writable.getWriter();
|
|
781
|
+
try {
|
|
782
|
+
await writer.write(
|
|
783
|
+
new TextEncoder().encode(
|
|
784
|
+
"a:" + JSON.stringify({
|
|
785
|
+
toolCallId: toolCall2.toolCallId,
|
|
786
|
+
result
|
|
787
|
+
}) + "\n"
|
|
788
|
+
)
|
|
789
|
+
);
|
|
790
|
+
} finally {
|
|
791
|
+
writer.releaseLock();
|
|
792
|
+
}
|
|
771
793
|
const originalMessages = processedParams.messages;
|
|
772
794
|
const messageArray = Array.isArray(originalMessages) ? originalMessages : [originalMessages];
|
|
773
795
|
this.processStreamResponse(
|
|
@@ -934,6 +956,21 @@ var MemoryThread = class extends BaseResource {
|
|
|
934
956
|
});
|
|
935
957
|
return this.request(`/api/memory/threads/${this.threadId}/messages?${query.toString()}`);
|
|
936
958
|
}
|
|
959
|
+
/**
|
|
960
|
+
* Retrieves paginated messages associated with the thread with advanced filtering and selection options
|
|
961
|
+
* @param params - Pagination parameters including selectBy criteria, page, perPage, date ranges, and message inclusion options
|
|
962
|
+
* @returns Promise containing paginated thread messages with pagination metadata (total, page, perPage, hasMore)
|
|
963
|
+
*/
|
|
964
|
+
getMessagesPaginated({
|
|
965
|
+
selectBy,
|
|
966
|
+
...rest
|
|
967
|
+
}) {
|
|
968
|
+
const query = new URLSearchParams({
|
|
969
|
+
...rest,
|
|
970
|
+
...selectBy ? { selectBy: JSON.stringify(selectBy) } : {}
|
|
971
|
+
});
|
|
972
|
+
return this.request(`/api/memory/threads/${this.threadId}/messages/paginated?${query.toString()}`);
|
|
973
|
+
}
|
|
937
974
|
};
|
|
938
975
|
|
|
939
976
|
// src/resources/vector.ts
|
|
@@ -1289,10 +1326,10 @@ var Workflow = class extends BaseResource {
|
|
|
1289
1326
|
if (params?.toDate) {
|
|
1290
1327
|
searchParams.set("toDate", params.toDate.toISOString());
|
|
1291
1328
|
}
|
|
1292
|
-
if (params?.limit) {
|
|
1329
|
+
if (params?.limit !== null && params?.limit !== void 0 && !isNaN(Number(params?.limit))) {
|
|
1293
1330
|
searchParams.set("limit", String(params.limit));
|
|
1294
1331
|
}
|
|
1295
|
-
if (params?.offset) {
|
|
1332
|
+
if (params?.offset !== null && params?.offset !== void 0 && !isNaN(Number(params?.offset))) {
|
|
1296
1333
|
searchParams.set("offset", String(params.offset));
|
|
1297
1334
|
}
|
|
1298
1335
|
if (params?.resourceId) {
|
|
@@ -1320,6 +1357,27 @@ var Workflow = class extends BaseResource {
|
|
|
1320
1357
|
runExecutionResult(runId) {
|
|
1321
1358
|
return this.request(`/api/workflows/${this.workflowId}/runs/${runId}/execution-result`);
|
|
1322
1359
|
}
|
|
1360
|
+
/**
|
|
1361
|
+
* Cancels a specific workflow run by its ID
|
|
1362
|
+
* @param runId - The ID of the workflow run to cancel
|
|
1363
|
+
* @returns Promise containing a success message
|
|
1364
|
+
*/
|
|
1365
|
+
cancelRun(runId) {
|
|
1366
|
+
return this.request(`/api/workflows/${this.workflowId}/runs/${runId}/cancel`, {
|
|
1367
|
+
method: "POST"
|
|
1368
|
+
});
|
|
1369
|
+
}
|
|
1370
|
+
/**
|
|
1371
|
+
* Sends an event to a specific workflow run by its ID
|
|
1372
|
+
* @param params - Object containing the runId, event and data
|
|
1373
|
+
* @returns Promise containing a success message
|
|
1374
|
+
*/
|
|
1375
|
+
sendRunEvent(params) {
|
|
1376
|
+
return this.request(`/api/workflows/${this.workflowId}/runs/${params.runId}/send-event`, {
|
|
1377
|
+
method: "POST",
|
|
1378
|
+
body: { event: params.event, data: params.data }
|
|
1379
|
+
});
|
|
1380
|
+
}
|
|
1323
1381
|
/**
|
|
1324
1382
|
* Creates a new workflow run
|
|
1325
1383
|
* @param params - Optional object containing the optional runId
|
|
@@ -1334,6 +1392,14 @@ var Workflow = class extends BaseResource {
|
|
|
1334
1392
|
method: "POST"
|
|
1335
1393
|
});
|
|
1336
1394
|
}
|
|
1395
|
+
/**
|
|
1396
|
+
* Creates a new workflow run (alias for createRun)
|
|
1397
|
+
* @param params - Optional object containing the optional runId
|
|
1398
|
+
* @returns Promise containing the runId of the created run
|
|
1399
|
+
*/
|
|
1400
|
+
createRunAsync(params) {
|
|
1401
|
+
return this.createRun(params);
|
|
1402
|
+
}
|
|
1337
1403
|
/**
|
|
1338
1404
|
* Starts a workflow run synchronously without waiting for the workflow to complete
|
|
1339
1405
|
* @param params - Object containing the runId, inputData and runtimeContext
|
|
@@ -1409,6 +1475,7 @@ var Workflow = class extends BaseResource {
|
|
|
1409
1475
|
if (!response.body) {
|
|
1410
1476
|
throw new Error("Response body is null");
|
|
1411
1477
|
}
|
|
1478
|
+
let failedChunk = void 0;
|
|
1412
1479
|
const transformStream = new TransformStream({
|
|
1413
1480
|
start() {
|
|
1414
1481
|
},
|
|
@@ -1418,10 +1485,13 @@ var Workflow = class extends BaseResource {
|
|
|
1418
1485
|
const chunks = decoded.split(RECORD_SEPARATOR2);
|
|
1419
1486
|
for (const chunk2 of chunks) {
|
|
1420
1487
|
if (chunk2) {
|
|
1488
|
+
const newChunk = failedChunk ? failedChunk + chunk2 : chunk2;
|
|
1421
1489
|
try {
|
|
1422
|
-
const parsedChunk = JSON.parse(
|
|
1490
|
+
const parsedChunk = JSON.parse(newChunk);
|
|
1423
1491
|
controller.enqueue(parsedChunk);
|
|
1424
|
-
|
|
1492
|
+
failedChunk = void 0;
|
|
1493
|
+
} catch (error) {
|
|
1494
|
+
failedChunk = newChunk;
|
|
1425
1495
|
}
|
|
1426
1496
|
}
|
|
1427
1497
|
}
|
|
@@ -1603,6 +1673,54 @@ var MCPTool = class extends BaseResource {
|
|
|
1603
1673
|
}
|
|
1604
1674
|
};
|
|
1605
1675
|
|
|
1676
|
+
// src/resources/network-memory-thread.ts
|
|
1677
|
+
var NetworkMemoryThread = class extends BaseResource {
|
|
1678
|
+
constructor(options, threadId, networkId) {
|
|
1679
|
+
super(options);
|
|
1680
|
+
this.threadId = threadId;
|
|
1681
|
+
this.networkId = networkId;
|
|
1682
|
+
}
|
|
1683
|
+
/**
|
|
1684
|
+
* Retrieves the memory thread details
|
|
1685
|
+
* @returns Promise containing thread details including title and metadata
|
|
1686
|
+
*/
|
|
1687
|
+
get() {
|
|
1688
|
+
return this.request(`/api/memory/network/threads/${this.threadId}?networkId=${this.networkId}`);
|
|
1689
|
+
}
|
|
1690
|
+
/**
|
|
1691
|
+
* Updates the memory thread properties
|
|
1692
|
+
* @param params - Update parameters including title and metadata
|
|
1693
|
+
* @returns Promise containing updated thread details
|
|
1694
|
+
*/
|
|
1695
|
+
update(params) {
|
|
1696
|
+
return this.request(`/api/memory/network/threads/${this.threadId}?networkId=${this.networkId}`, {
|
|
1697
|
+
method: "PATCH",
|
|
1698
|
+
body: params
|
|
1699
|
+
});
|
|
1700
|
+
}
|
|
1701
|
+
/**
|
|
1702
|
+
* Deletes the memory thread
|
|
1703
|
+
* @returns Promise containing deletion result
|
|
1704
|
+
*/
|
|
1705
|
+
delete() {
|
|
1706
|
+
return this.request(`/api/memory/network/threads/${this.threadId}?networkId=${this.networkId}`, {
|
|
1707
|
+
method: "DELETE"
|
|
1708
|
+
});
|
|
1709
|
+
}
|
|
1710
|
+
/**
|
|
1711
|
+
* Retrieves messages associated with the thread
|
|
1712
|
+
* @param params - Optional parameters including limit for number of messages to retrieve
|
|
1713
|
+
* @returns Promise containing thread messages and UI messages
|
|
1714
|
+
*/
|
|
1715
|
+
getMessages(params) {
|
|
1716
|
+
const query = new URLSearchParams({
|
|
1717
|
+
networkId: this.networkId,
|
|
1718
|
+
...params?.limit ? { limit: params.limit.toString() } : {}
|
|
1719
|
+
});
|
|
1720
|
+
return this.request(`/api/memory/network/threads/${this.threadId}/messages?${query.toString()}`);
|
|
1721
|
+
}
|
|
1722
|
+
};
|
|
1723
|
+
|
|
1606
1724
|
// src/resources/vNextNetwork.ts
|
|
1607
1725
|
var RECORD_SEPARATOR3 = "";
|
|
1608
1726
|
var VNextNetwork = class extends BaseResource {
|
|
@@ -1625,7 +1743,10 @@ var VNextNetwork = class extends BaseResource {
|
|
|
1625
1743
|
generate(params) {
|
|
1626
1744
|
return this.request(`/api/networks/v-next/${this.networkId}/generate`, {
|
|
1627
1745
|
method: "POST",
|
|
1628
|
-
body:
|
|
1746
|
+
body: {
|
|
1747
|
+
...params,
|
|
1748
|
+
runtimeContext: parseClientRuntimeContext(params.runtimeContext)
|
|
1749
|
+
}
|
|
1629
1750
|
});
|
|
1630
1751
|
}
|
|
1631
1752
|
/**
|
|
@@ -1636,7 +1757,10 @@ var VNextNetwork = class extends BaseResource {
|
|
|
1636
1757
|
loop(params) {
|
|
1637
1758
|
return this.request(`/api/networks/v-next/${this.networkId}/loop`, {
|
|
1638
1759
|
method: "POST",
|
|
1639
|
-
body:
|
|
1760
|
+
body: {
|
|
1761
|
+
...params,
|
|
1762
|
+
runtimeContext: parseClientRuntimeContext(params.runtimeContext)
|
|
1763
|
+
}
|
|
1640
1764
|
});
|
|
1641
1765
|
}
|
|
1642
1766
|
async *streamProcessor(stream) {
|
|
@@ -1685,7 +1809,10 @@ var VNextNetwork = class extends BaseResource {
|
|
|
1685
1809
|
async stream(params, onRecord) {
|
|
1686
1810
|
const response = await this.request(`/api/networks/v-next/${this.networkId}/stream`, {
|
|
1687
1811
|
method: "POST",
|
|
1688
|
-
body:
|
|
1812
|
+
body: {
|
|
1813
|
+
...params,
|
|
1814
|
+
runtimeContext: parseClientRuntimeContext(params.runtimeContext)
|
|
1815
|
+
},
|
|
1689
1816
|
stream: true
|
|
1690
1817
|
});
|
|
1691
1818
|
if (!response.ok) {
|
|
@@ -1710,7 +1837,10 @@ var VNextNetwork = class extends BaseResource {
|
|
|
1710
1837
|
async loopStream(params, onRecord) {
|
|
1711
1838
|
const response = await this.request(`/api/networks/v-next/${this.networkId}/loop-stream`, {
|
|
1712
1839
|
method: "POST",
|
|
1713
|
-
body:
|
|
1840
|
+
body: {
|
|
1841
|
+
...params,
|
|
1842
|
+
runtimeContext: parseClientRuntimeContext(params.runtimeContext)
|
|
1843
|
+
},
|
|
1714
1844
|
stream: true
|
|
1715
1845
|
});
|
|
1716
1846
|
if (!response.ok) {
|
|
@@ -1729,54 +1859,6 @@ var VNextNetwork = class extends BaseResource {
|
|
|
1729
1859
|
}
|
|
1730
1860
|
};
|
|
1731
1861
|
|
|
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
1862
|
// src/client.ts
|
|
1781
1863
|
var MastraClient = class extends BaseResource {
|
|
1782
1864
|
constructor(options) {
|
|
@@ -2171,6 +2253,119 @@ var MastraClient = class extends BaseResource {
|
|
|
2171
2253
|
getA2A(agentId) {
|
|
2172
2254
|
return new A2A(this.options, agentId);
|
|
2173
2255
|
}
|
|
2256
|
+
/**
|
|
2257
|
+
* Retrieves the working memory for a specific thread (optionally resource-scoped).
|
|
2258
|
+
* @param agentId - ID of the agent.
|
|
2259
|
+
* @param threadId - ID of the thread.
|
|
2260
|
+
* @param resourceId - Optional ID of the resource.
|
|
2261
|
+
* @returns Working memory for the specified thread or resource.
|
|
2262
|
+
*/
|
|
2263
|
+
getWorkingMemory({
|
|
2264
|
+
agentId,
|
|
2265
|
+
threadId,
|
|
2266
|
+
resourceId
|
|
2267
|
+
}) {
|
|
2268
|
+
return this.request(`/api/memory/threads/${threadId}/working-memory?agentId=${agentId}&resourceId=${resourceId}`);
|
|
2269
|
+
}
|
|
2270
|
+
/**
|
|
2271
|
+
* Updates the working memory for a specific thread (optionally resource-scoped).
|
|
2272
|
+
* @param agentId - ID of the agent.
|
|
2273
|
+
* @param threadId - ID of the thread.
|
|
2274
|
+
* @param workingMemory - The new working memory content.
|
|
2275
|
+
* @param resourceId - Optional ID of the resource.
|
|
2276
|
+
*/
|
|
2277
|
+
updateWorkingMemory({
|
|
2278
|
+
agentId,
|
|
2279
|
+
threadId,
|
|
2280
|
+
workingMemory,
|
|
2281
|
+
resourceId
|
|
2282
|
+
}) {
|
|
2283
|
+
return this.request(`/api/memory/threads/${threadId}/working-memory?agentId=${agentId}`, {
|
|
2284
|
+
method: "POST",
|
|
2285
|
+
body: {
|
|
2286
|
+
workingMemory,
|
|
2287
|
+
resourceId
|
|
2288
|
+
}
|
|
2289
|
+
});
|
|
2290
|
+
}
|
|
2291
|
+
/**
|
|
2292
|
+
* Retrieves all available scorers
|
|
2293
|
+
* @returns Promise containing list of available scorers
|
|
2294
|
+
*/
|
|
2295
|
+
getScorers() {
|
|
2296
|
+
return this.request("/api/scores/scorers");
|
|
2297
|
+
}
|
|
2298
|
+
/**
|
|
2299
|
+
* Retrieves a scorer by ID
|
|
2300
|
+
* @param scorerId - ID of the scorer to retrieve
|
|
2301
|
+
* @returns Promise containing the scorer
|
|
2302
|
+
*/
|
|
2303
|
+
getScorer(scorerId) {
|
|
2304
|
+
return this.request(`/api/scores/scorers/${scorerId}`);
|
|
2305
|
+
}
|
|
2306
|
+
getScoresByScorerId(params) {
|
|
2307
|
+
const { page, perPage, scorerId, entityId, entityType } = params;
|
|
2308
|
+
const searchParams = new URLSearchParams();
|
|
2309
|
+
if (entityId) {
|
|
2310
|
+
searchParams.set("entityId", entityId);
|
|
2311
|
+
}
|
|
2312
|
+
if (entityType) {
|
|
2313
|
+
searchParams.set("entityType", entityType);
|
|
2314
|
+
}
|
|
2315
|
+
if (page !== void 0) {
|
|
2316
|
+
searchParams.set("page", String(page));
|
|
2317
|
+
}
|
|
2318
|
+
if (perPage !== void 0) {
|
|
2319
|
+
searchParams.set("perPage", String(perPage));
|
|
2320
|
+
}
|
|
2321
|
+
const queryString = searchParams.toString();
|
|
2322
|
+
return this.request(`/api/scores/scorer/${scorerId}${queryString ? `?${queryString}` : ""}`);
|
|
2323
|
+
}
|
|
2324
|
+
/**
|
|
2325
|
+
* Retrieves scores by run ID
|
|
2326
|
+
* @param params - Parameters containing run ID and pagination options
|
|
2327
|
+
* @returns Promise containing scores and pagination info
|
|
2328
|
+
*/
|
|
2329
|
+
getScoresByRunId(params) {
|
|
2330
|
+
const { runId, page, perPage } = params;
|
|
2331
|
+
const searchParams = new URLSearchParams();
|
|
2332
|
+
if (page !== void 0) {
|
|
2333
|
+
searchParams.set("page", String(page));
|
|
2334
|
+
}
|
|
2335
|
+
if (perPage !== void 0) {
|
|
2336
|
+
searchParams.set("perPage", String(perPage));
|
|
2337
|
+
}
|
|
2338
|
+
const queryString = searchParams.toString();
|
|
2339
|
+
return this.request(`/api/scores/run/${runId}${queryString ? `?${queryString}` : ""}`);
|
|
2340
|
+
}
|
|
2341
|
+
/**
|
|
2342
|
+
* Retrieves scores by entity ID and type
|
|
2343
|
+
* @param params - Parameters containing entity ID, type, and pagination options
|
|
2344
|
+
* @returns Promise containing scores and pagination info
|
|
2345
|
+
*/
|
|
2346
|
+
getScoresByEntityId(params) {
|
|
2347
|
+
const { entityId, entityType, page, perPage } = params;
|
|
2348
|
+
const searchParams = new URLSearchParams();
|
|
2349
|
+
if (page !== void 0) {
|
|
2350
|
+
searchParams.set("page", String(page));
|
|
2351
|
+
}
|
|
2352
|
+
if (perPage !== void 0) {
|
|
2353
|
+
searchParams.set("perPage", String(perPage));
|
|
2354
|
+
}
|
|
2355
|
+
const queryString = searchParams.toString();
|
|
2356
|
+
return this.request(`/api/scores/entity/${entityType}/${entityId}${queryString ? `?${queryString}` : ""}`);
|
|
2357
|
+
}
|
|
2358
|
+
/**
|
|
2359
|
+
* Saves a score
|
|
2360
|
+
* @param params - Parameters containing the score data to save
|
|
2361
|
+
* @returns Promise containing the saved score
|
|
2362
|
+
*/
|
|
2363
|
+
saveScore(params) {
|
|
2364
|
+
return this.request("/api/scores", {
|
|
2365
|
+
method: "POST",
|
|
2366
|
+
body: params
|
|
2367
|
+
});
|
|
2368
|
+
}
|
|
2174
2369
|
};
|
|
2175
2370
|
|
|
2176
2371
|
export { MastraClient };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mastra/client-js",
|
|
3
|
-
"version": "0.0.0-
|
|
3
|
+
"version": "0.0.0-transpile-packages-20250730132657",
|
|
4
4
|
"description": "The official TypeScript library for the Mastra Client API",
|
|
5
5
|
"author": "",
|
|
6
6
|
"type": "module",
|
|
@@ -25,15 +25,16 @@
|
|
|
25
25
|
"directory": "client-sdks/client-js"
|
|
26
26
|
},
|
|
27
27
|
"homepage": "https://github.com/mastra-ai/mastra/tree/main/client-sdks/client-js#readme",
|
|
28
|
-
"license": "
|
|
28
|
+
"license": "Apache-2.0",
|
|
29
29
|
"dependencies": {
|
|
30
30
|
"@ag-ui/client": "^0.0.27",
|
|
31
31
|
"@ai-sdk/ui-utils": "^1.2.11",
|
|
32
|
+
"@lukeed/uuid": "^2.0.1",
|
|
32
33
|
"json-schema": "^0.4.0",
|
|
33
34
|
"rxjs": "7.8.1",
|
|
34
35
|
"zod": "^3.25.67",
|
|
35
36
|
"zod-to-json-schema": "^3.24.5",
|
|
36
|
-
"@mastra/core": "0.0.0-
|
|
37
|
+
"@mastra/core": "0.0.0-transpile-packages-20250730132657"
|
|
37
38
|
},
|
|
38
39
|
"peerDependencies": {
|
|
39
40
|
"zod": "^3.0.0"
|
|
@@ -46,8 +47,8 @@
|
|
|
46
47
|
"@types/node": "^20.19.0",
|
|
47
48
|
"tsup": "^8.5.0",
|
|
48
49
|
"typescript": "^5.8.3",
|
|
49
|
-
"vitest": "^3.2.
|
|
50
|
-
"@internal/lint": "0.0.0-
|
|
50
|
+
"vitest": "^3.2.4",
|
|
51
|
+
"@internal/lint": "0.0.0-transpile-packages-20250730132657"
|
|
51
52
|
},
|
|
52
53
|
"scripts": {
|
|
53
54
|
"build": "tsup src/index.ts --format esm,cjs --dts --clean --treeshake=smallest --splitting",
|
package/src/client.ts
CHANGED
|
@@ -13,6 +13,8 @@ import {
|
|
|
13
13
|
MCPTool,
|
|
14
14
|
LegacyWorkflow,
|
|
15
15
|
} from './resources';
|
|
16
|
+
import { NetworkMemoryThread } from './resources/network-memory-thread';
|
|
17
|
+
import { VNextNetwork } from './resources/vNextNetwork';
|
|
16
18
|
import type {
|
|
17
19
|
ClientOptions,
|
|
18
20
|
CreateMemoryThreadParams,
|
|
@@ -37,9 +39,14 @@ import type {
|
|
|
37
39
|
GetNetworkMemoryThreadParams,
|
|
38
40
|
CreateNetworkMemoryThreadParams,
|
|
39
41
|
SaveNetworkMessageToMemoryParams,
|
|
42
|
+
GetScorerResponse,
|
|
43
|
+
GetScoresByScorerIdParams,
|
|
44
|
+
GetScoresResponse,
|
|
45
|
+
GetScoresByRunIdParams,
|
|
46
|
+
GetScoresByEntityIdParams,
|
|
47
|
+
SaveScoreParams,
|
|
48
|
+
SaveScoreResponse,
|
|
40
49
|
} from './types';
|
|
41
|
-
import { VNextNetwork } from './resources/vNextNetwork';
|
|
42
|
-
import { NetworkMemoryThread } from './resources/network-memory-thread';
|
|
43
50
|
|
|
44
51
|
export class MastraClient extends BaseResource {
|
|
45
52
|
constructor(options: ClientOptions) {
|
|
@@ -477,4 +484,140 @@ export class MastraClient extends BaseResource {
|
|
|
477
484
|
public getA2A(agentId: string) {
|
|
478
485
|
return new A2A(this.options, agentId);
|
|
479
486
|
}
|
|
487
|
+
|
|
488
|
+
/**
|
|
489
|
+
* Retrieves the working memory for a specific thread (optionally resource-scoped).
|
|
490
|
+
* @param agentId - ID of the agent.
|
|
491
|
+
* @param threadId - ID of the thread.
|
|
492
|
+
* @param resourceId - Optional ID of the resource.
|
|
493
|
+
* @returns Working memory for the specified thread or resource.
|
|
494
|
+
*/
|
|
495
|
+
public getWorkingMemory({
|
|
496
|
+
agentId,
|
|
497
|
+
threadId,
|
|
498
|
+
resourceId,
|
|
499
|
+
}: {
|
|
500
|
+
agentId: string;
|
|
501
|
+
threadId: string;
|
|
502
|
+
resourceId?: string;
|
|
503
|
+
}) {
|
|
504
|
+
return this.request(`/api/memory/threads/${threadId}/working-memory?agentId=${agentId}&resourceId=${resourceId}`);
|
|
505
|
+
}
|
|
506
|
+
|
|
507
|
+
/**
|
|
508
|
+
* Updates the working memory for a specific thread (optionally resource-scoped).
|
|
509
|
+
* @param agentId - ID of the agent.
|
|
510
|
+
* @param threadId - ID of the thread.
|
|
511
|
+
* @param workingMemory - The new working memory content.
|
|
512
|
+
* @param resourceId - Optional ID of the resource.
|
|
513
|
+
*/
|
|
514
|
+
public updateWorkingMemory({
|
|
515
|
+
agentId,
|
|
516
|
+
threadId,
|
|
517
|
+
workingMemory,
|
|
518
|
+
resourceId,
|
|
519
|
+
}: {
|
|
520
|
+
agentId: string;
|
|
521
|
+
threadId: string;
|
|
522
|
+
workingMemory: string;
|
|
523
|
+
resourceId?: string;
|
|
524
|
+
}) {
|
|
525
|
+
return this.request(`/api/memory/threads/${threadId}/working-memory?agentId=${agentId}`, {
|
|
526
|
+
method: 'POST',
|
|
527
|
+
body: {
|
|
528
|
+
workingMemory,
|
|
529
|
+
resourceId,
|
|
530
|
+
},
|
|
531
|
+
});
|
|
532
|
+
}
|
|
533
|
+
|
|
534
|
+
/**
|
|
535
|
+
* Retrieves all available scorers
|
|
536
|
+
* @returns Promise containing list of available scorers
|
|
537
|
+
*/
|
|
538
|
+
public getScorers(): Promise<Record<string, GetScorerResponse>> {
|
|
539
|
+
return this.request('/api/scores/scorers');
|
|
540
|
+
}
|
|
541
|
+
|
|
542
|
+
/**
|
|
543
|
+
* Retrieves a scorer by ID
|
|
544
|
+
* @param scorerId - ID of the scorer to retrieve
|
|
545
|
+
* @returns Promise containing the scorer
|
|
546
|
+
*/
|
|
547
|
+
public getScorer(scorerId: string): Promise<GetScorerResponse> {
|
|
548
|
+
return this.request(`/api/scores/scorers/${scorerId}`);
|
|
549
|
+
}
|
|
550
|
+
|
|
551
|
+
public getScoresByScorerId(params: GetScoresByScorerIdParams): Promise<GetScoresResponse> {
|
|
552
|
+
const { page, perPage, scorerId, entityId, entityType } = params;
|
|
553
|
+
const searchParams = new URLSearchParams();
|
|
554
|
+
|
|
555
|
+
if (entityId) {
|
|
556
|
+
searchParams.set('entityId', entityId);
|
|
557
|
+
}
|
|
558
|
+
if (entityType) {
|
|
559
|
+
searchParams.set('entityType', entityType);
|
|
560
|
+
}
|
|
561
|
+
|
|
562
|
+
if (page !== undefined) {
|
|
563
|
+
searchParams.set('page', String(page));
|
|
564
|
+
}
|
|
565
|
+
if (perPage !== undefined) {
|
|
566
|
+
searchParams.set('perPage', String(perPage));
|
|
567
|
+
}
|
|
568
|
+
const queryString = searchParams.toString();
|
|
569
|
+
return this.request(`/api/scores/scorer/${scorerId}${queryString ? `?${queryString}` : ''}`);
|
|
570
|
+
}
|
|
571
|
+
|
|
572
|
+
/**
|
|
573
|
+
* Retrieves scores by run ID
|
|
574
|
+
* @param params - Parameters containing run ID and pagination options
|
|
575
|
+
* @returns Promise containing scores and pagination info
|
|
576
|
+
*/
|
|
577
|
+
public getScoresByRunId(params: GetScoresByRunIdParams): Promise<GetScoresResponse> {
|
|
578
|
+
const { runId, page, perPage } = params;
|
|
579
|
+
const searchParams = new URLSearchParams();
|
|
580
|
+
|
|
581
|
+
if (page !== undefined) {
|
|
582
|
+
searchParams.set('page', String(page));
|
|
583
|
+
}
|
|
584
|
+
if (perPage !== undefined) {
|
|
585
|
+
searchParams.set('perPage', String(perPage));
|
|
586
|
+
}
|
|
587
|
+
|
|
588
|
+
const queryString = searchParams.toString();
|
|
589
|
+
return this.request(`/api/scores/run/${runId}${queryString ? `?${queryString}` : ''}`);
|
|
590
|
+
}
|
|
591
|
+
|
|
592
|
+
/**
|
|
593
|
+
* Retrieves scores by entity ID and type
|
|
594
|
+
* @param params - Parameters containing entity ID, type, and pagination options
|
|
595
|
+
* @returns Promise containing scores and pagination info
|
|
596
|
+
*/
|
|
597
|
+
public getScoresByEntityId(params: GetScoresByEntityIdParams): Promise<GetScoresResponse> {
|
|
598
|
+
const { entityId, entityType, page, perPage } = params;
|
|
599
|
+
const searchParams = new URLSearchParams();
|
|
600
|
+
|
|
601
|
+
if (page !== undefined) {
|
|
602
|
+
searchParams.set('page', String(page));
|
|
603
|
+
}
|
|
604
|
+
if (perPage !== undefined) {
|
|
605
|
+
searchParams.set('perPage', String(perPage));
|
|
606
|
+
}
|
|
607
|
+
|
|
608
|
+
const queryString = searchParams.toString();
|
|
609
|
+
return this.request(`/api/scores/entity/${entityType}/${entityId}${queryString ? `?${queryString}` : ''}`);
|
|
610
|
+
}
|
|
611
|
+
|
|
612
|
+
/**
|
|
613
|
+
* Saves a score
|
|
614
|
+
* @param params - Parameters containing the score data to save
|
|
615
|
+
* @returns Promise containing the saved score
|
|
616
|
+
*/
|
|
617
|
+
public saveScore(params: SaveScoreParams): Promise<SaveScoreResponse> {
|
|
618
|
+
return this.request('/api/scores', {
|
|
619
|
+
method: 'POST',
|
|
620
|
+
body: params,
|
|
621
|
+
});
|
|
622
|
+
}
|
|
480
623
|
}
|