@mastra/client-js 0.12.2 → 0.12.3-alpha.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -15,6 +15,12 @@ function parseClientRuntimeContext(runtimeContext) {
15
15
  }
16
16
  return void 0;
17
17
  }
18
+ function base64RuntimeContext(runtimeContext) {
19
+ if (runtimeContext) {
20
+ return btoa(JSON.stringify(runtimeContext));
21
+ }
22
+ return void 0;
23
+ }
18
24
  function isZodType(value) {
19
25
  return typeof value === "object" && value !== null && "_def" in value && "parse" in value && typeof value.parse === "function" && "safeParse" in value && typeof value.safeParse === "function";
20
26
  }
@@ -26,7 +32,7 @@ function zodToJsonSchema(zodSchema) {
26
32
  const fn = "toJSONSchema";
27
33
  return z[fn].call(z, zodSchema);
28
34
  }
29
- return originalZodToJsonSchema(zodSchema, { $refStrategy: "none" });
35
+ return originalZodToJsonSchema(zodSchema, { $refStrategy: "relative" });
30
36
  }
31
37
 
32
38
  // src/utils/process-client-tools.ts
@@ -59,7 +65,7 @@ function processClientTools(clientTools) {
59
65
  }
60
66
 
61
67
  // src/utils/process-mastra-stream.ts
62
- async function processMastraStream({
68
+ async function sharedProcessMastraStream({
63
69
  stream,
64
70
  onChunk
65
71
  }) {
@@ -93,6 +99,24 @@ async function processMastraStream({
93
99
  reader.releaseLock();
94
100
  }
95
101
  }
102
+ async function processMastraNetworkStream({
103
+ stream,
104
+ onChunk
105
+ }) {
106
+ return sharedProcessMastraStream({
107
+ stream,
108
+ onChunk
109
+ });
110
+ }
111
+ async function processMastraStream({
112
+ stream,
113
+ onChunk
114
+ }) {
115
+ return sharedProcessMastraStream({
116
+ stream,
117
+ onChunk
118
+ });
119
+ }
96
120
 
97
121
  // src/resources/base.ts
98
122
  var BaseResource = class {
@@ -255,17 +279,31 @@ var AgentVoice = class extends BaseResource {
255
279
  }
256
280
  /**
257
281
  * Get available speakers for the agent's voice provider
282
+ * @param runtimeContext - Optional runtime context to pass as query parameter
258
283
  * @returns Promise containing list of available speakers
259
284
  */
260
- getSpeakers() {
261
- return this.request(`/api/agents/${this.agentId}/voice/speakers`);
285
+ getSpeakers(runtimeContext) {
286
+ const runtimeContextParam = base64RuntimeContext(parseClientRuntimeContext(runtimeContext));
287
+ const searchParams = new URLSearchParams();
288
+ if (runtimeContextParam) {
289
+ searchParams.set("runtimeContext", runtimeContextParam);
290
+ }
291
+ const queryString = searchParams.toString();
292
+ return this.request(`/api/agents/${this.agentId}/voice/speakers${queryString ? `?${queryString}` : ""}`);
262
293
  }
263
294
  /**
264
295
  * Get the listener configuration for the agent's voice provider
296
+ * @param runtimeContext - Optional runtime context to pass as query parameter
265
297
  * @returns Promise containing a check if the agent has listening capabilities
266
298
  */
267
- getListener() {
268
- return this.request(`/api/agents/${this.agentId}/voice/listener`);
299
+ getListener(runtimeContext) {
300
+ const runtimeContextParam = base64RuntimeContext(parseClientRuntimeContext(runtimeContext));
301
+ const searchParams = new URLSearchParams();
302
+ if (runtimeContextParam) {
303
+ searchParams.set("runtimeContext", runtimeContextParam);
304
+ }
305
+ const queryString = searchParams.toString();
306
+ return this.request(`/api/agents/${this.agentId}/voice/listener${queryString ? `?${queryString}` : ""}`);
269
307
  }
270
308
  };
271
309
  var Agent = class extends BaseResource {
@@ -277,14 +315,21 @@ var Agent = class extends BaseResource {
277
315
  voice;
278
316
  /**
279
317
  * Retrieves details about the agent
318
+ * @param runtimeContext - Runtime context to use for the agent
280
319
  * @returns Promise containing agent details including model and instructions
281
320
  */
282
- details() {
283
- return this.request(`/api/agents/${this.agentId}`);
321
+ details(runtimeContext) {
322
+ const runtimeContextParam = base64RuntimeContext(parseClientRuntimeContext(runtimeContext));
323
+ const searchParams = new URLSearchParams();
324
+ if (runtimeContextParam) {
325
+ searchParams.set("runtimeContext", runtimeContextParam);
326
+ }
327
+ const queryString = searchParams.toString();
328
+ return this.request(`/api/agents/${this.agentId}${queryString ? `?${queryString}` : ""}`);
284
329
  }
285
330
  async generate(params) {
286
331
  console.warn(
287
- "Deprecation NOTICE:Generate method will switch to use generateVNext implementation September 16th. Please use generateLegacy if you don't want to upgrade just yet."
332
+ "Deprecation NOTICE:Generate method will switch to use generateVNext implementation September 23rd, 2025. Please use generateLegacy if you don't want to upgrade just yet."
288
333
  );
289
334
  return this.generateLegacy(params);
290
335
  }
@@ -654,7 +699,7 @@ var Agent = class extends BaseResource {
654
699
  */
655
700
  async stream(params) {
656
701
  console.warn(
657
- "Deprecation NOTICE:\nStream method will switch to use streamVNext implementation September 16th. Please use streamLegacy if you don't want to upgrade just yet."
702
+ "Deprecation NOTICE:\nStream method will switch to use streamVNext implementation September 23rd, 2025. Please use streamLegacy if you don't want to upgrade just yet."
658
703
  );
659
704
  return this.streamLegacy(params);
660
705
  }
@@ -1058,6 +1103,30 @@ var Agent = class extends BaseResource {
1058
1103
  }
1059
1104
  return response;
1060
1105
  }
1106
+ async network(params) {
1107
+ const response = await this.request(`/api/agents/${this.agentId}/network`, {
1108
+ method: "POST",
1109
+ body: params,
1110
+ stream: true
1111
+ });
1112
+ if (!response.body) {
1113
+ throw new Error("No response body");
1114
+ }
1115
+ const streamResponse = new Response(response.body, {
1116
+ status: response.status,
1117
+ statusText: response.statusText,
1118
+ headers: response.headers
1119
+ });
1120
+ streamResponse.processDataStream = async ({
1121
+ onChunk
1122
+ }) => {
1123
+ await processMastraNetworkStream({
1124
+ stream: streamResponse.body,
1125
+ onChunk
1126
+ });
1127
+ };
1128
+ return streamResponse;
1129
+ }
1061
1130
  async streamVNext(params) {
1062
1131
  const processedParams = {
1063
1132
  ...params,
@@ -1203,10 +1272,17 @@ var Agent = class extends BaseResource {
1203
1272
  /**
1204
1273
  * Gets details about a specific tool available to the agent
1205
1274
  * @param toolId - ID of the tool to retrieve
1275
+ * @param runtimeContext - Optional runtime context to pass as query parameter
1206
1276
  * @returns Promise containing tool details
1207
1277
  */
1208
- getTool(toolId) {
1209
- return this.request(`/api/agents/${this.agentId}/tools/${toolId}`);
1278
+ getTool(toolId, runtimeContext) {
1279
+ const runtimeContextParam = base64RuntimeContext(parseClientRuntimeContext(runtimeContext));
1280
+ const searchParams = new URLSearchParams();
1281
+ if (runtimeContextParam) {
1282
+ searchParams.set("runtimeContext", runtimeContextParam);
1283
+ }
1284
+ const queryString = searchParams.toString();
1285
+ return this.request(`/api/agents/${this.agentId}/tools/${toolId}${queryString ? `?${queryString}` : ""}`);
1210
1286
  }
1211
1287
  /**
1212
1288
  * Executes a tool for the agent
@@ -1217,7 +1293,7 @@ var Agent = class extends BaseResource {
1217
1293
  executeTool(toolId, params) {
1218
1294
  const body = {
1219
1295
  data: params.data,
1220
- runtimeContext: params.runtimeContext ? Object.fromEntries(params.runtimeContext.entries()) : void 0
1296
+ runtimeContext: parseClientRuntimeContext(params.runtimeContext)
1221
1297
  };
1222
1298
  return this.request(`/api/agents/${this.agentId}/tools/${toolId}/execute`, {
1223
1299
  method: "POST",
@@ -1226,17 +1302,31 @@ var Agent = class extends BaseResource {
1226
1302
  }
1227
1303
  /**
1228
1304
  * Retrieves evaluation results for the agent
1305
+ * @param runtimeContext - Optional runtime context to pass as query parameter
1229
1306
  * @returns Promise containing agent evaluations
1230
1307
  */
1231
- evals() {
1232
- return this.request(`/api/agents/${this.agentId}/evals/ci`);
1308
+ evals(runtimeContext) {
1309
+ const runtimeContextParam = base64RuntimeContext(parseClientRuntimeContext(runtimeContext));
1310
+ const searchParams = new URLSearchParams();
1311
+ if (runtimeContextParam) {
1312
+ searchParams.set("runtimeContext", runtimeContextParam);
1313
+ }
1314
+ const queryString = searchParams.toString();
1315
+ return this.request(`/api/agents/${this.agentId}/evals/ci${queryString ? `?${queryString}` : ""}`);
1233
1316
  }
1234
1317
  /**
1235
1318
  * Retrieves live evaluation results for the agent
1319
+ * @param runtimeContext - Optional runtime context to pass as query parameter
1236
1320
  * @returns Promise containing live agent evaluations
1237
1321
  */
1238
- liveEvals() {
1239
- return this.request(`/api/agents/${this.agentId}/evals/live`);
1322
+ liveEvals(runtimeContext) {
1323
+ const runtimeContextParam = base64RuntimeContext(parseClientRuntimeContext(runtimeContext));
1324
+ const searchParams = new URLSearchParams();
1325
+ if (runtimeContextParam) {
1326
+ searchParams.set("runtimeContext", runtimeContextParam);
1327
+ }
1328
+ const queryString = searchParams.toString();
1329
+ return this.request(`/api/agents/${this.agentId}/evals/live${queryString ? `?${queryString}` : ""}`);
1240
1330
  }
1241
1331
  /**
1242
1332
  * Updates the model for the agent
@@ -2766,10 +2856,17 @@ var MastraClient = class extends BaseResource {
2766
2856
  }
2767
2857
  /**
2768
2858
  * Retrieves all available agents
2859
+ * @param runtimeContext - Runtime context to use for the agents
2769
2860
  * @returns Promise containing map of agent IDs to agent details
2770
2861
  */
2771
- getAgents() {
2772
- return this.request("/api/agents");
2862
+ getAgents(runtimeContext) {
2863
+ const runtimeContextParam = base64RuntimeContext(parseClientRuntimeContext(runtimeContext));
2864
+ const searchParams = new URLSearchParams();
2865
+ if (runtimeContextParam) {
2866
+ searchParams.set("runtimeContext", runtimeContextParam);
2867
+ }
2868
+ const queryString = searchParams.toString();
2869
+ return this.request(`/api/agents${queryString ? `?${queryString}` : ""}`);
2773
2870
  }
2774
2871
  /**
2775
2872
  * Gets an agent instance by ID