@mastra/client-js 0.10.6-alpha.0 → 0.10.6-alpha.2
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 -8
- package/CHANGELOG.md +26 -0
- package/dist/index.cjs +209 -2
- package/dist/index.d.cts +161 -4
- package/dist/index.d.ts +161 -4
- package/dist/index.js +209 -2
- package/package.json +4 -4
- package/src/client.ts +71 -1
- package/src/resources/base.ts +1 -0
- package/src/resources/network-memory-thread.ts +63 -0
- package/src/resources/network.ts +2 -3
- package/src/resources/vNextNetwork.ts +147 -0
- package/src/resources/workflow.ts +2 -2
- package/src/types.ts +61 -0
package/dist/index.d.ts
CHANGED
|
@@ -152,6 +152,10 @@ interface SaveMessageToMemoryParams {
|
|
|
152
152
|
messages: MastraMessageV1[];
|
|
153
153
|
agentId: string;
|
|
154
154
|
}
|
|
155
|
+
interface SaveNetworkMessageToMemoryParams {
|
|
156
|
+
messages: MastraMessageV1[];
|
|
157
|
+
networkId: string;
|
|
158
|
+
}
|
|
155
159
|
type SaveMessageToMemoryResponse = MastraMessageV1[];
|
|
156
160
|
interface CreateMemoryThreadParams {
|
|
157
161
|
title?: string;
|
|
@@ -160,11 +164,22 @@ interface CreateMemoryThreadParams {
|
|
|
160
164
|
threadId?: string;
|
|
161
165
|
agentId: string;
|
|
162
166
|
}
|
|
167
|
+
interface CreateNetworkMemoryThreadParams {
|
|
168
|
+
title?: string;
|
|
169
|
+
metadata?: Record<string, any>;
|
|
170
|
+
resourceId: string;
|
|
171
|
+
threadId?: string;
|
|
172
|
+
networkId: string;
|
|
173
|
+
}
|
|
163
174
|
type CreateMemoryThreadResponse = StorageThreadType;
|
|
164
175
|
interface GetMemoryThreadParams {
|
|
165
176
|
resourceId: string;
|
|
166
177
|
agentId: string;
|
|
167
178
|
}
|
|
179
|
+
interface GetNetworkMemoryThreadParams {
|
|
180
|
+
resourceId: string;
|
|
181
|
+
networkId: string;
|
|
182
|
+
}
|
|
168
183
|
type GetMemoryThreadResponse = StorageThreadType[];
|
|
169
184
|
interface UpdateMemoryThreadParams {
|
|
170
185
|
title: string;
|
|
@@ -258,6 +273,7 @@ interface GetTelemetryParams {
|
|
|
258
273
|
toDate?: Date;
|
|
259
274
|
}
|
|
260
275
|
interface GetNetworkResponse {
|
|
276
|
+
id: string;
|
|
261
277
|
name: string;
|
|
262
278
|
instructions: string;
|
|
263
279
|
agents: Array<{
|
|
@@ -271,6 +287,44 @@ interface GetNetworkResponse {
|
|
|
271
287
|
};
|
|
272
288
|
state?: Record<string, any>;
|
|
273
289
|
}
|
|
290
|
+
interface GetVNextNetworkResponse {
|
|
291
|
+
id: string;
|
|
292
|
+
name: string;
|
|
293
|
+
instructions: string;
|
|
294
|
+
agents: Array<{
|
|
295
|
+
name: string;
|
|
296
|
+
provider: string;
|
|
297
|
+
modelId: string;
|
|
298
|
+
}>;
|
|
299
|
+
routingModel: {
|
|
300
|
+
provider: string;
|
|
301
|
+
modelId: string;
|
|
302
|
+
};
|
|
303
|
+
workflows: Array<{
|
|
304
|
+
name: string;
|
|
305
|
+
description: string;
|
|
306
|
+
inputSchema: string | undefined;
|
|
307
|
+
outputSchema: string | undefined;
|
|
308
|
+
}>;
|
|
309
|
+
}
|
|
310
|
+
interface GenerateVNextNetworkResponse {
|
|
311
|
+
task: string;
|
|
312
|
+
result: string;
|
|
313
|
+
resourceId: string;
|
|
314
|
+
resourceType: 'none' | 'tool' | 'agent' | 'workflow';
|
|
315
|
+
}
|
|
316
|
+
interface GenerateOrStreamVNextNetworkParams {
|
|
317
|
+
message: string;
|
|
318
|
+
threadId?: string;
|
|
319
|
+
resourceId?: string;
|
|
320
|
+
}
|
|
321
|
+
interface LoopVNextNetworkResponse {
|
|
322
|
+
status: 'success';
|
|
323
|
+
result: {
|
|
324
|
+
text: string;
|
|
325
|
+
};
|
|
326
|
+
steps: WorkflowResult<any, any>['steps'];
|
|
327
|
+
}
|
|
274
328
|
interface McpServerListResponse {
|
|
275
329
|
servers: ServerInfo[];
|
|
276
330
|
next: string | null;
|
|
@@ -684,9 +738,9 @@ declare class Workflow extends BaseResource {
|
|
|
684
738
|
runtimeContext?: RuntimeContext | Record<string, any>;
|
|
685
739
|
}): Promise<WorkflowRunResult>;
|
|
686
740
|
/**
|
|
687
|
-
* Starts a
|
|
741
|
+
* Starts a workflow run and returns a stream
|
|
688
742
|
* @param params - Object containing the optional runId, inputData and runtimeContext
|
|
689
|
-
* @returns Promise containing the
|
|
743
|
+
* @returns Promise containing the workflow execution results
|
|
690
744
|
*/
|
|
691
745
|
stream(params: {
|
|
692
746
|
runId?: string;
|
|
@@ -787,6 +841,67 @@ declare class MCPTool extends BaseResource {
|
|
|
787
841
|
}): Promise<any>;
|
|
788
842
|
}
|
|
789
843
|
|
|
844
|
+
declare class VNextNetwork extends BaseResource {
|
|
845
|
+
private networkId;
|
|
846
|
+
constructor(options: ClientOptions, networkId: string);
|
|
847
|
+
/**
|
|
848
|
+
* Retrieves details about the network
|
|
849
|
+
* @returns Promise containing vNext network details
|
|
850
|
+
*/
|
|
851
|
+
details(): Promise<GetVNextNetworkResponse>;
|
|
852
|
+
/**
|
|
853
|
+
* Generates a response from the v-next network
|
|
854
|
+
* @param params - Generation parameters including message
|
|
855
|
+
* @returns Promise containing the generated response
|
|
856
|
+
*/
|
|
857
|
+
generate(params: GenerateOrStreamVNextNetworkParams): Promise<GenerateVNextNetworkResponse>;
|
|
858
|
+
/**
|
|
859
|
+
* Generates a response from the v-next network using multiple primitives
|
|
860
|
+
* @param params - Generation parameters including message
|
|
861
|
+
* @returns Promise containing the generated response
|
|
862
|
+
*/
|
|
863
|
+
loop(params: {
|
|
864
|
+
message: string;
|
|
865
|
+
}): Promise<LoopVNextNetworkResponse>;
|
|
866
|
+
private streamProcessor;
|
|
867
|
+
/**
|
|
868
|
+
* Streams a response from the v-next network
|
|
869
|
+
* @param params - Stream parameters including message
|
|
870
|
+
* @returns Promise containing the results
|
|
871
|
+
*/
|
|
872
|
+
stream(params: GenerateOrStreamVNextNetworkParams, onRecord: (record: WatchEvent) => void): Promise<void>;
|
|
873
|
+
}
|
|
874
|
+
|
|
875
|
+
declare class NetworkMemoryThread extends BaseResource {
|
|
876
|
+
private threadId;
|
|
877
|
+
private networkId;
|
|
878
|
+
constructor(options: ClientOptions, threadId: string, networkId: string);
|
|
879
|
+
/**
|
|
880
|
+
* Retrieves the memory thread details
|
|
881
|
+
* @returns Promise containing thread details including title and metadata
|
|
882
|
+
*/
|
|
883
|
+
get(): Promise<StorageThreadType>;
|
|
884
|
+
/**
|
|
885
|
+
* Updates the memory thread properties
|
|
886
|
+
* @param params - Update parameters including title and metadata
|
|
887
|
+
* @returns Promise containing updated thread details
|
|
888
|
+
*/
|
|
889
|
+
update(params: UpdateMemoryThreadParams): Promise<StorageThreadType>;
|
|
890
|
+
/**
|
|
891
|
+
* Deletes the memory thread
|
|
892
|
+
* @returns Promise containing deletion result
|
|
893
|
+
*/
|
|
894
|
+
delete(): Promise<{
|
|
895
|
+
result: string;
|
|
896
|
+
}>;
|
|
897
|
+
/**
|
|
898
|
+
* Retrieves messages associated with the thread
|
|
899
|
+
* @param params - Optional parameters including limit for number of messages to retrieve
|
|
900
|
+
* @returns Promise containing thread messages and UI messages
|
|
901
|
+
*/
|
|
902
|
+
getMessages(params?: GetMemoryThreadMessagesParams): Promise<GetMemoryThreadMessagesResponse>;
|
|
903
|
+
}
|
|
904
|
+
|
|
790
905
|
declare class MastraClient extends BaseResource {
|
|
791
906
|
constructor(options: ClientOptions);
|
|
792
907
|
/**
|
|
@@ -834,6 +949,37 @@ declare class MastraClient extends BaseResource {
|
|
|
834
949
|
getMemoryStatus(agentId: string): Promise<{
|
|
835
950
|
result: boolean;
|
|
836
951
|
}>;
|
|
952
|
+
/**
|
|
953
|
+
* Retrieves memory threads for a resource
|
|
954
|
+
* @param params - Parameters containing the resource ID
|
|
955
|
+
* @returns Promise containing array of memory threads
|
|
956
|
+
*/
|
|
957
|
+
getNetworkMemoryThreads(params: GetNetworkMemoryThreadParams): Promise<GetMemoryThreadResponse>;
|
|
958
|
+
/**
|
|
959
|
+
* Creates a new memory thread
|
|
960
|
+
* @param params - Parameters for creating the memory thread
|
|
961
|
+
* @returns Promise containing the created memory thread
|
|
962
|
+
*/
|
|
963
|
+
createNetworkMemoryThread(params: CreateNetworkMemoryThreadParams): Promise<CreateMemoryThreadResponse>;
|
|
964
|
+
/**
|
|
965
|
+
* Gets a memory thread instance by ID
|
|
966
|
+
* @param threadId - ID of the memory thread to retrieve
|
|
967
|
+
* @returns MemoryThread instance
|
|
968
|
+
*/
|
|
969
|
+
getNetworkMemoryThread(threadId: string, networkId: string): NetworkMemoryThread;
|
|
970
|
+
/**
|
|
971
|
+
* Saves messages to memory
|
|
972
|
+
* @param params - Parameters containing messages to save
|
|
973
|
+
* @returns Promise containing the saved messages
|
|
974
|
+
*/
|
|
975
|
+
saveNetworkMessageToMemory(params: SaveNetworkMessageToMemoryParams): Promise<SaveMessageToMemoryResponse>;
|
|
976
|
+
/**
|
|
977
|
+
* Gets the status of the memory system
|
|
978
|
+
* @returns Promise containing memory system status
|
|
979
|
+
*/
|
|
980
|
+
getNetworkMemoryStatus(networkId: string): Promise<{
|
|
981
|
+
result: boolean;
|
|
982
|
+
}>;
|
|
837
983
|
/**
|
|
838
984
|
* Retrieves all available tools
|
|
839
985
|
* @returns Promise containing map of tool IDs to tool details
|
|
@@ -902,13 +1048,24 @@ declare class MastraClient extends BaseResource {
|
|
|
902
1048
|
* Retrieves all available networks
|
|
903
1049
|
* @returns Promise containing map of network IDs to network details
|
|
904
1050
|
*/
|
|
905
|
-
getNetworks(): Promise<
|
|
1051
|
+
getNetworks(): Promise<Array<GetNetworkResponse>>;
|
|
1052
|
+
/**
|
|
1053
|
+
* Retrieves all available vNext networks
|
|
1054
|
+
* @returns Promise containing map of vNext network IDs to vNext network details
|
|
1055
|
+
*/
|
|
1056
|
+
getVNextNetworks(): Promise<Array<GetVNextNetworkResponse>>;
|
|
906
1057
|
/**
|
|
907
1058
|
* Gets a network instance by ID
|
|
908
1059
|
* @param networkId - ID of the network to retrieve
|
|
909
1060
|
* @returns Network instance
|
|
910
1061
|
*/
|
|
911
1062
|
getNetwork(networkId: string): Network;
|
|
1063
|
+
/**
|
|
1064
|
+
* Gets a vNext network instance by ID
|
|
1065
|
+
* @param networkId - ID of the vNext network to retrieve
|
|
1066
|
+
* @returns vNext Network instance
|
|
1067
|
+
*/
|
|
1068
|
+
getVNextNetwork(networkId: string): VNextNetwork;
|
|
912
1069
|
/**
|
|
913
1070
|
* Retrieves a list of available MCP servers.
|
|
914
1071
|
* @param params - Optional parameters for pagination (limit, offset).
|
|
@@ -949,4 +1106,4 @@ declare class MastraClient extends BaseResource {
|
|
|
949
1106
|
getA2A(agentId: string): A2A;
|
|
950
1107
|
}
|
|
951
1108
|
|
|
952
|
-
export { type ClientOptions, type CreateIndexParams, type CreateMemoryThreadParams, type CreateMemoryThreadResponse, type GenerateParams, type GetAgentResponse, type GetEvalsByAgentIdResponse, type GetLegacyWorkflowResponse, type GetLegacyWorkflowRunsResponse, type GetLogParams, type GetLogsParams, type GetLogsResponse, type GetMemoryThreadMessagesParams, type GetMemoryThreadMessagesResponse, type GetMemoryThreadParams, type GetMemoryThreadResponse, type GetNetworkResponse, type GetTelemetryParams, type GetTelemetryResponse, type GetToolResponse, type GetVectorIndexResponse, type GetWorkflowResponse, type GetWorkflowRunByIdResponse, type GetWorkflowRunExecutionResultResponse, type GetWorkflowRunsParams, type GetWorkflowRunsResponse, type LegacyWorkflowRunResult, MastraClient, type McpServerListResponse, type McpServerToolListResponse, type McpToolInfo, type QueryVectorParams, type QueryVectorResponse, type RequestFunction, type RequestOptions, type SaveMessageToMemoryParams, type SaveMessageToMemoryResponse, type StreamParams, type UpdateMemoryThreadParams, type UpsertVectorParams, type WorkflowRunResult, type WorkflowWatchResult };
|
|
1109
|
+
export { type ClientOptions, type CreateIndexParams, type CreateMemoryThreadParams, type CreateMemoryThreadResponse, type CreateNetworkMemoryThreadParams, type GenerateOrStreamVNextNetworkParams, type GenerateParams, type GenerateVNextNetworkResponse, type GetAgentResponse, type GetEvalsByAgentIdResponse, type GetLegacyWorkflowResponse, type GetLegacyWorkflowRunsResponse, type GetLogParams, type GetLogsParams, type GetLogsResponse, type GetMemoryThreadMessagesParams, type GetMemoryThreadMessagesResponse, type GetMemoryThreadParams, type GetMemoryThreadResponse, type GetNetworkMemoryThreadParams, type GetNetworkResponse, type GetTelemetryParams, type GetTelemetryResponse, type GetToolResponse, type GetVNextNetworkResponse, type GetVectorIndexResponse, type GetWorkflowResponse, type GetWorkflowRunByIdResponse, type GetWorkflowRunExecutionResultResponse, type GetWorkflowRunsParams, type GetWorkflowRunsResponse, type LegacyWorkflowRunResult, type LoopVNextNetworkResponse, MastraClient, type McpServerListResponse, type McpServerToolListResponse, type McpToolInfo, type QueryVectorParams, type QueryVectorResponse, type RequestFunction, type RequestOptions, type SaveMessageToMemoryParams, type SaveMessageToMemoryResponse, type SaveNetworkMessageToMemoryParams, type StreamParams, type UpdateMemoryThreadParams, type UpsertVectorParams, type WorkflowRunResult, type WorkflowWatchResult };
|
package/dist/index.js
CHANGED
|
@@ -246,6 +246,7 @@ var BaseResource = class {
|
|
|
246
246
|
const response = await fetch(`${baseUrl.replace(/\/$/, "")}${path}`, {
|
|
247
247
|
...options,
|
|
248
248
|
headers: {
|
|
249
|
+
...options.method === "POST" || options.method === "PUT" ? { "content-type": "application/json" } : {},
|
|
249
250
|
...headers,
|
|
250
251
|
...options.headers
|
|
251
252
|
// TODO: Bring this back once we figure out what we/users need to do to make this work with cross-origin requests
|
|
@@ -997,9 +998,9 @@ var Workflow = class extends BaseResource {
|
|
|
997
998
|
});
|
|
998
999
|
}
|
|
999
1000
|
/**
|
|
1000
|
-
* Starts a
|
|
1001
|
+
* Starts a workflow run and returns a stream
|
|
1001
1002
|
* @param params - Object containing the optional runId, inputData and runtimeContext
|
|
1002
|
-
* @returns Promise containing the
|
|
1003
|
+
* @returns Promise containing the workflow execution results
|
|
1003
1004
|
*/
|
|
1004
1005
|
async stream(params) {
|
|
1005
1006
|
const searchParams = new URLSearchParams();
|
|
@@ -1215,6 +1216,155 @@ var MCPTool = class extends BaseResource {
|
|
|
1215
1216
|
}
|
|
1216
1217
|
};
|
|
1217
1218
|
|
|
1219
|
+
// src/resources/vNextNetwork.ts
|
|
1220
|
+
var RECORD_SEPARATOR3 = "";
|
|
1221
|
+
var VNextNetwork = class extends BaseResource {
|
|
1222
|
+
constructor(options, networkId) {
|
|
1223
|
+
super(options);
|
|
1224
|
+
this.networkId = networkId;
|
|
1225
|
+
}
|
|
1226
|
+
/**
|
|
1227
|
+
* Retrieves details about the network
|
|
1228
|
+
* @returns Promise containing vNext network details
|
|
1229
|
+
*/
|
|
1230
|
+
details() {
|
|
1231
|
+
return this.request(`/api/networks/v-next/${this.networkId}`);
|
|
1232
|
+
}
|
|
1233
|
+
/**
|
|
1234
|
+
* Generates a response from the v-next network
|
|
1235
|
+
* @param params - Generation parameters including message
|
|
1236
|
+
* @returns Promise containing the generated response
|
|
1237
|
+
*/
|
|
1238
|
+
generate(params) {
|
|
1239
|
+
return this.request(`/api/networks/v-next/${this.networkId}/generate`, {
|
|
1240
|
+
method: "POST",
|
|
1241
|
+
body: params
|
|
1242
|
+
});
|
|
1243
|
+
}
|
|
1244
|
+
/**
|
|
1245
|
+
* Generates a response from the v-next network using multiple primitives
|
|
1246
|
+
* @param params - Generation parameters including message
|
|
1247
|
+
* @returns Promise containing the generated response
|
|
1248
|
+
*/
|
|
1249
|
+
loop(params) {
|
|
1250
|
+
return this.request(`/api/networks/v-next/${this.networkId}/loop`, {
|
|
1251
|
+
method: "POST",
|
|
1252
|
+
body: params
|
|
1253
|
+
});
|
|
1254
|
+
}
|
|
1255
|
+
async *streamProcessor(stream) {
|
|
1256
|
+
const reader = stream.getReader();
|
|
1257
|
+
let doneReading = false;
|
|
1258
|
+
let buffer = "";
|
|
1259
|
+
try {
|
|
1260
|
+
while (!doneReading) {
|
|
1261
|
+
const { done, value } = await reader.read();
|
|
1262
|
+
doneReading = done;
|
|
1263
|
+
if (done && !value) continue;
|
|
1264
|
+
try {
|
|
1265
|
+
const decoded = value ? new TextDecoder().decode(value) : "";
|
|
1266
|
+
const chunks = (buffer + decoded).split(RECORD_SEPARATOR3);
|
|
1267
|
+
buffer = chunks.pop() || "";
|
|
1268
|
+
for (const chunk of chunks) {
|
|
1269
|
+
if (chunk) {
|
|
1270
|
+
if (typeof chunk === "string") {
|
|
1271
|
+
try {
|
|
1272
|
+
const parsedChunk = JSON.parse(chunk);
|
|
1273
|
+
yield parsedChunk;
|
|
1274
|
+
} catch {
|
|
1275
|
+
}
|
|
1276
|
+
}
|
|
1277
|
+
}
|
|
1278
|
+
}
|
|
1279
|
+
} catch {
|
|
1280
|
+
}
|
|
1281
|
+
}
|
|
1282
|
+
if (buffer) {
|
|
1283
|
+
try {
|
|
1284
|
+
yield JSON.parse(buffer);
|
|
1285
|
+
} catch {
|
|
1286
|
+
}
|
|
1287
|
+
}
|
|
1288
|
+
} finally {
|
|
1289
|
+
reader.cancel().catch(() => {
|
|
1290
|
+
});
|
|
1291
|
+
}
|
|
1292
|
+
}
|
|
1293
|
+
/**
|
|
1294
|
+
* Streams a response from the v-next network
|
|
1295
|
+
* @param params - Stream parameters including message
|
|
1296
|
+
* @returns Promise containing the results
|
|
1297
|
+
*/
|
|
1298
|
+
async stream(params, onRecord) {
|
|
1299
|
+
const response = await this.request(`/api/networks/v-next/${this.networkId}/stream`, {
|
|
1300
|
+
method: "POST",
|
|
1301
|
+
body: params,
|
|
1302
|
+
stream: true
|
|
1303
|
+
});
|
|
1304
|
+
if (!response.ok) {
|
|
1305
|
+
throw new Error(`Failed to stream vNext network: ${response.statusText}`);
|
|
1306
|
+
}
|
|
1307
|
+
if (!response.body) {
|
|
1308
|
+
throw new Error("Response body is null");
|
|
1309
|
+
}
|
|
1310
|
+
for await (const record of this.streamProcessor(response.body)) {
|
|
1311
|
+
if (typeof record === "string") {
|
|
1312
|
+
onRecord(JSON.parse(record));
|
|
1313
|
+
} else {
|
|
1314
|
+
onRecord(record);
|
|
1315
|
+
}
|
|
1316
|
+
}
|
|
1317
|
+
}
|
|
1318
|
+
};
|
|
1319
|
+
|
|
1320
|
+
// src/resources/network-memory-thread.ts
|
|
1321
|
+
var NetworkMemoryThread = class extends BaseResource {
|
|
1322
|
+
constructor(options, threadId, networkId) {
|
|
1323
|
+
super(options);
|
|
1324
|
+
this.threadId = threadId;
|
|
1325
|
+
this.networkId = networkId;
|
|
1326
|
+
}
|
|
1327
|
+
/**
|
|
1328
|
+
* Retrieves the memory thread details
|
|
1329
|
+
* @returns Promise containing thread details including title and metadata
|
|
1330
|
+
*/
|
|
1331
|
+
get() {
|
|
1332
|
+
return this.request(`/api/memory/network/threads/${this.threadId}?networkId=${this.networkId}`);
|
|
1333
|
+
}
|
|
1334
|
+
/**
|
|
1335
|
+
* Updates the memory thread properties
|
|
1336
|
+
* @param params - Update parameters including title and metadata
|
|
1337
|
+
* @returns Promise containing updated thread details
|
|
1338
|
+
*/
|
|
1339
|
+
update(params) {
|
|
1340
|
+
return this.request(`/api/memory/network/threads/${this.threadId}?networkId=${this.networkId}`, {
|
|
1341
|
+
method: "PATCH",
|
|
1342
|
+
body: params
|
|
1343
|
+
});
|
|
1344
|
+
}
|
|
1345
|
+
/**
|
|
1346
|
+
* Deletes the memory thread
|
|
1347
|
+
* @returns Promise containing deletion result
|
|
1348
|
+
*/
|
|
1349
|
+
delete() {
|
|
1350
|
+
return this.request(`/api/memory/network/threads/${this.threadId}?networkId=${this.networkId}`, {
|
|
1351
|
+
method: "DELETE"
|
|
1352
|
+
});
|
|
1353
|
+
}
|
|
1354
|
+
/**
|
|
1355
|
+
* Retrieves messages associated with the thread
|
|
1356
|
+
* @param params - Optional parameters including limit for number of messages to retrieve
|
|
1357
|
+
* @returns Promise containing thread messages and UI messages
|
|
1358
|
+
*/
|
|
1359
|
+
getMessages(params) {
|
|
1360
|
+
const query = new URLSearchParams({
|
|
1361
|
+
networkId: this.networkId,
|
|
1362
|
+
...params?.limit ? { limit: params.limit.toString() } : {}
|
|
1363
|
+
});
|
|
1364
|
+
return this.request(`/api/memory/network/threads/${this.threadId}/messages?${query.toString()}`);
|
|
1365
|
+
}
|
|
1366
|
+
};
|
|
1367
|
+
|
|
1218
1368
|
// src/client.ts
|
|
1219
1369
|
var MastraClient = class extends BaseResource {
|
|
1220
1370
|
constructor(options) {
|
|
@@ -1292,6 +1442,48 @@ var MastraClient = class extends BaseResource {
|
|
|
1292
1442
|
getMemoryStatus(agentId) {
|
|
1293
1443
|
return this.request(`/api/memory/status?agentId=${agentId}`);
|
|
1294
1444
|
}
|
|
1445
|
+
/**
|
|
1446
|
+
* Retrieves memory threads for a resource
|
|
1447
|
+
* @param params - Parameters containing the resource ID
|
|
1448
|
+
* @returns Promise containing array of memory threads
|
|
1449
|
+
*/
|
|
1450
|
+
getNetworkMemoryThreads(params) {
|
|
1451
|
+
return this.request(`/api/memory/network/threads?resourceid=${params.resourceId}&networkId=${params.networkId}`);
|
|
1452
|
+
}
|
|
1453
|
+
/**
|
|
1454
|
+
* Creates a new memory thread
|
|
1455
|
+
* @param params - Parameters for creating the memory thread
|
|
1456
|
+
* @returns Promise containing the created memory thread
|
|
1457
|
+
*/
|
|
1458
|
+
createNetworkMemoryThread(params) {
|
|
1459
|
+
return this.request(`/api/memory/network/threads?networkId=${params.networkId}`, { method: "POST", body: params });
|
|
1460
|
+
}
|
|
1461
|
+
/**
|
|
1462
|
+
* Gets a memory thread instance by ID
|
|
1463
|
+
* @param threadId - ID of the memory thread to retrieve
|
|
1464
|
+
* @returns MemoryThread instance
|
|
1465
|
+
*/
|
|
1466
|
+
getNetworkMemoryThread(threadId, networkId) {
|
|
1467
|
+
return new NetworkMemoryThread(this.options, threadId, networkId);
|
|
1468
|
+
}
|
|
1469
|
+
/**
|
|
1470
|
+
* Saves messages to memory
|
|
1471
|
+
* @param params - Parameters containing messages to save
|
|
1472
|
+
* @returns Promise containing the saved messages
|
|
1473
|
+
*/
|
|
1474
|
+
saveNetworkMessageToMemory(params) {
|
|
1475
|
+
return this.request(`/api/memory/network/save-messages?networkId=${params.networkId}`, {
|
|
1476
|
+
method: "POST",
|
|
1477
|
+
body: params
|
|
1478
|
+
});
|
|
1479
|
+
}
|
|
1480
|
+
/**
|
|
1481
|
+
* Gets the status of the memory system
|
|
1482
|
+
* @returns Promise containing memory system status
|
|
1483
|
+
*/
|
|
1484
|
+
getNetworkMemoryStatus(networkId) {
|
|
1485
|
+
return this.request(`/api/memory/network/status?networkId=${networkId}`);
|
|
1486
|
+
}
|
|
1295
1487
|
/**
|
|
1296
1488
|
* Retrieves all available tools
|
|
1297
1489
|
* @returns Promise containing map of tool IDs to tool details
|
|
@@ -1488,6 +1680,13 @@ var MastraClient = class extends BaseResource {
|
|
|
1488
1680
|
getNetworks() {
|
|
1489
1681
|
return this.request("/api/networks");
|
|
1490
1682
|
}
|
|
1683
|
+
/**
|
|
1684
|
+
* Retrieves all available vNext networks
|
|
1685
|
+
* @returns Promise containing map of vNext network IDs to vNext network details
|
|
1686
|
+
*/
|
|
1687
|
+
getVNextNetworks() {
|
|
1688
|
+
return this.request("/api/networks/v-next");
|
|
1689
|
+
}
|
|
1491
1690
|
/**
|
|
1492
1691
|
* Gets a network instance by ID
|
|
1493
1692
|
* @param networkId - ID of the network to retrieve
|
|
@@ -1496,6 +1695,14 @@ var MastraClient = class extends BaseResource {
|
|
|
1496
1695
|
getNetwork(networkId) {
|
|
1497
1696
|
return new Network(this.options, networkId);
|
|
1498
1697
|
}
|
|
1698
|
+
/**
|
|
1699
|
+
* Gets a vNext network instance by ID
|
|
1700
|
+
* @param networkId - ID of the vNext network to retrieve
|
|
1701
|
+
* @returns vNext Network instance
|
|
1702
|
+
*/
|
|
1703
|
+
getVNextNetwork(networkId) {
|
|
1704
|
+
return new VNextNetwork(this.options, networkId);
|
|
1705
|
+
}
|
|
1499
1706
|
/**
|
|
1500
1707
|
* Retrieves a list of available MCP servers.
|
|
1501
1708
|
* @param params - Optional parameters for pagination (limit, offset).
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mastra/client-js",
|
|
3
|
-
"version": "0.10.6-alpha.
|
|
3
|
+
"version": "0.10.6-alpha.2",
|
|
4
4
|
"description": "The official TypeScript library for the Mastra Client API",
|
|
5
5
|
"author": "",
|
|
6
6
|
"type": "module",
|
|
@@ -31,9 +31,9 @@
|
|
|
31
31
|
"@ai-sdk/ui-utils": "^1.2.11",
|
|
32
32
|
"json-schema": "^0.4.0",
|
|
33
33
|
"rxjs": "7.8.1",
|
|
34
|
-
"zod": "^3.25.
|
|
34
|
+
"zod": "^3.25.67",
|
|
35
35
|
"zod-to-json-schema": "^3.24.5",
|
|
36
|
-
"@mastra/core": "0.10.7-alpha.
|
|
36
|
+
"@mastra/core": "0.10.7-alpha.2"
|
|
37
37
|
},
|
|
38
38
|
"peerDependencies": {
|
|
39
39
|
"zod": "^3.0.0"
|
|
@@ -41,7 +41,7 @@
|
|
|
41
41
|
"devDependencies": {
|
|
42
42
|
"@babel/preset-env": "^7.27.2",
|
|
43
43
|
"@babel/preset-typescript": "^7.27.1",
|
|
44
|
-
"@tsconfig/recommended": "^1.0.
|
|
44
|
+
"@tsconfig/recommended": "^1.0.9",
|
|
45
45
|
"@types/json-schema": "^7.0.15",
|
|
46
46
|
"@types/node": "^20.19.0",
|
|
47
47
|
"tsup": "^8.5.0",
|
package/src/client.ts
CHANGED
|
@@ -33,7 +33,13 @@ import type {
|
|
|
33
33
|
McpServerListResponse,
|
|
34
34
|
McpServerToolListResponse,
|
|
35
35
|
GetLegacyWorkflowResponse,
|
|
36
|
+
GetVNextNetworkResponse,
|
|
37
|
+
GetNetworkMemoryThreadParams,
|
|
38
|
+
CreateNetworkMemoryThreadParams,
|
|
39
|
+
SaveNetworkMessageToMemoryParams,
|
|
36
40
|
} from './types';
|
|
41
|
+
import { VNextNetwork } from './resources/vNextNetwork';
|
|
42
|
+
import { NetworkMemoryThread } from './resources/network-memory-thread';
|
|
37
43
|
|
|
38
44
|
export class MastraClient extends BaseResource {
|
|
39
45
|
constructor(options: ClientOptions) {
|
|
@@ -123,6 +129,53 @@ export class MastraClient extends BaseResource {
|
|
|
123
129
|
return this.request(`/api/memory/status?agentId=${agentId}`);
|
|
124
130
|
}
|
|
125
131
|
|
|
132
|
+
/**
|
|
133
|
+
* Retrieves memory threads for a resource
|
|
134
|
+
* @param params - Parameters containing the resource ID
|
|
135
|
+
* @returns Promise containing array of memory threads
|
|
136
|
+
*/
|
|
137
|
+
public getNetworkMemoryThreads(params: GetNetworkMemoryThreadParams): Promise<GetMemoryThreadResponse> {
|
|
138
|
+
return this.request(`/api/memory/network/threads?resourceid=${params.resourceId}&networkId=${params.networkId}`);
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* Creates a new memory thread
|
|
143
|
+
* @param params - Parameters for creating the memory thread
|
|
144
|
+
* @returns Promise containing the created memory thread
|
|
145
|
+
*/
|
|
146
|
+
public createNetworkMemoryThread(params: CreateNetworkMemoryThreadParams): Promise<CreateMemoryThreadResponse> {
|
|
147
|
+
return this.request(`/api/memory/network/threads?networkId=${params.networkId}`, { method: 'POST', body: params });
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* Gets a memory thread instance by ID
|
|
152
|
+
* @param threadId - ID of the memory thread to retrieve
|
|
153
|
+
* @returns MemoryThread instance
|
|
154
|
+
*/
|
|
155
|
+
public getNetworkMemoryThread(threadId: string, networkId: string) {
|
|
156
|
+
return new NetworkMemoryThread(this.options, threadId, networkId);
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* Saves messages to memory
|
|
161
|
+
* @param params - Parameters containing messages to save
|
|
162
|
+
* @returns Promise containing the saved messages
|
|
163
|
+
*/
|
|
164
|
+
public saveNetworkMessageToMemory(params: SaveNetworkMessageToMemoryParams): Promise<SaveMessageToMemoryResponse> {
|
|
165
|
+
return this.request(`/api/memory/network/save-messages?networkId=${params.networkId}`, {
|
|
166
|
+
method: 'POST',
|
|
167
|
+
body: params,
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
/**
|
|
172
|
+
* Gets the status of the memory system
|
|
173
|
+
* @returns Promise containing memory system status
|
|
174
|
+
*/
|
|
175
|
+
public getNetworkMemoryStatus(networkId: string): Promise<{ result: boolean }> {
|
|
176
|
+
return this.request(`/api/memory/network/status?networkId=${networkId}`);
|
|
177
|
+
}
|
|
178
|
+
|
|
126
179
|
/**
|
|
127
180
|
* Retrieves all available tools
|
|
128
181
|
* @returns Promise containing map of tool IDs to tool details
|
|
@@ -334,10 +387,18 @@ export class MastraClient extends BaseResource {
|
|
|
334
387
|
* Retrieves all available networks
|
|
335
388
|
* @returns Promise containing map of network IDs to network details
|
|
336
389
|
*/
|
|
337
|
-
public getNetworks(): Promise<
|
|
390
|
+
public getNetworks(): Promise<Array<GetNetworkResponse>> {
|
|
338
391
|
return this.request('/api/networks');
|
|
339
392
|
}
|
|
340
393
|
|
|
394
|
+
/**
|
|
395
|
+
* Retrieves all available vNext networks
|
|
396
|
+
* @returns Promise containing map of vNext network IDs to vNext network details
|
|
397
|
+
*/
|
|
398
|
+
public getVNextNetworks(): Promise<Array<GetVNextNetworkResponse>> {
|
|
399
|
+
return this.request('/api/networks/v-next');
|
|
400
|
+
}
|
|
401
|
+
|
|
341
402
|
/**
|
|
342
403
|
* Gets a network instance by ID
|
|
343
404
|
* @param networkId - ID of the network to retrieve
|
|
@@ -347,6 +408,15 @@ export class MastraClient extends BaseResource {
|
|
|
347
408
|
return new Network(this.options, networkId);
|
|
348
409
|
}
|
|
349
410
|
|
|
411
|
+
/**
|
|
412
|
+
* Gets a vNext network instance by ID
|
|
413
|
+
* @param networkId - ID of the vNext network to retrieve
|
|
414
|
+
* @returns vNext Network instance
|
|
415
|
+
*/
|
|
416
|
+
public getVNextNetwork(networkId: string) {
|
|
417
|
+
return new VNextNetwork(this.options, networkId);
|
|
418
|
+
}
|
|
419
|
+
|
|
350
420
|
/**
|
|
351
421
|
* Retrieves a list of available MCP servers.
|
|
352
422
|
* @param params - Optional parameters for pagination (limit, offset).
|
package/src/resources/base.ts
CHANGED
|
@@ -24,6 +24,7 @@ export class BaseResource {
|
|
|
24
24
|
const response = await fetch(`${baseUrl.replace(/\/$/, '')}${path}`, {
|
|
25
25
|
...options,
|
|
26
26
|
headers: {
|
|
27
|
+
...(options.method === 'POST' || options.method === 'PUT' ? { 'content-type': 'application/json' } : {}),
|
|
27
28
|
...headers,
|
|
28
29
|
...options.headers,
|
|
29
30
|
// TODO: Bring this back once we figure out what we/users need to do to make this work with cross-origin requests
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import type { StorageThreadType } from '@mastra/core';
|
|
2
|
+
|
|
3
|
+
import type {
|
|
4
|
+
GetMemoryThreadMessagesResponse,
|
|
5
|
+
ClientOptions,
|
|
6
|
+
UpdateMemoryThreadParams,
|
|
7
|
+
GetMemoryThreadMessagesParams,
|
|
8
|
+
} from '../types';
|
|
9
|
+
|
|
10
|
+
import { BaseResource } from './base';
|
|
11
|
+
|
|
12
|
+
export class NetworkMemoryThread extends BaseResource {
|
|
13
|
+
constructor(
|
|
14
|
+
options: ClientOptions,
|
|
15
|
+
private threadId: string,
|
|
16
|
+
private networkId: string,
|
|
17
|
+
) {
|
|
18
|
+
super(options);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Retrieves the memory thread details
|
|
23
|
+
* @returns Promise containing thread details including title and metadata
|
|
24
|
+
*/
|
|
25
|
+
get(): Promise<StorageThreadType> {
|
|
26
|
+
return this.request(`/api/memory/network/threads/${this.threadId}?networkId=${this.networkId}`);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Updates the memory thread properties
|
|
31
|
+
* @param params - Update parameters including title and metadata
|
|
32
|
+
* @returns Promise containing updated thread details
|
|
33
|
+
*/
|
|
34
|
+
update(params: UpdateMemoryThreadParams): Promise<StorageThreadType> {
|
|
35
|
+
return this.request(`/api/memory/network/threads/${this.threadId}?networkId=${this.networkId}`, {
|
|
36
|
+
method: 'PATCH',
|
|
37
|
+
body: params,
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Deletes the memory thread
|
|
43
|
+
* @returns Promise containing deletion result
|
|
44
|
+
*/
|
|
45
|
+
delete(): Promise<{ result: string }> {
|
|
46
|
+
return this.request(`/api/memory/network/threads/${this.threadId}?networkId=${this.networkId}`, {
|
|
47
|
+
method: 'DELETE',
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Retrieves messages associated with the thread
|
|
53
|
+
* @param params - Optional parameters including limit for number of messages to retrieve
|
|
54
|
+
* @returns Promise containing thread messages and UI messages
|
|
55
|
+
*/
|
|
56
|
+
getMessages(params?: GetMemoryThreadMessagesParams): Promise<GetMemoryThreadMessagesResponse> {
|
|
57
|
+
const query = new URLSearchParams({
|
|
58
|
+
networkId: this.networkId,
|
|
59
|
+
...(params?.limit ? { limit: params.limit.toString() } : {}),
|
|
60
|
+
});
|
|
61
|
+
return this.request(`/api/memory/network/threads/${this.threadId}/messages?${query.toString()}`);
|
|
62
|
+
}
|
|
63
|
+
}
|