@mastra/client-js 0.12.3 → 0.12.4-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.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  export * from './client.js';
2
2
  export * from './types.js';
3
+ export * from './tools.js';
3
4
  export type { UIMessageWithMetadata } from '@mastra/core/agent';
4
5
  //# sourceMappingURL=index.d.ts.map
@@ -1 +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"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,cAAc,SAAS,CAAC;AACxB,cAAc,SAAS,CAAC;AACxB,YAAY,EAAE,qBAAqB,EAAE,MAAM,oBAAoB,CAAC"}
package/dist/index.js CHANGED
@@ -21,6 +21,14 @@ function base64RuntimeContext(runtimeContext) {
21
21
  }
22
22
  return void 0;
23
23
  }
24
+ function runtimeContextQueryString(runtimeContext) {
25
+ const runtimeContextParam = base64RuntimeContext(parseClientRuntimeContext(runtimeContext));
26
+ if (!runtimeContextParam) return "";
27
+ const searchParams = new URLSearchParams();
28
+ searchParams.set("runtimeContext", runtimeContextParam);
29
+ const queryString = searchParams.toString();
30
+ return queryString ? `?${queryString}` : "";
31
+ }
24
32
  function isZodType(value) {
25
33
  return typeof value === "object" && value !== null && "_def" in value && "parse" in value && typeof value.parse === "function" && "safeParse" in value && typeof value.safeParse === "function";
26
34
  }
@@ -280,30 +288,20 @@ var AgentVoice = class extends BaseResource {
280
288
  /**
281
289
  * Get available speakers for the agent's voice provider
282
290
  * @param runtimeContext - Optional runtime context to pass as query parameter
291
+ * @param runtimeContext - Optional runtime context to pass as query parameter
283
292
  * @returns Promise containing list of available speakers
284
293
  */
285
294
  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}` : ""}`);
295
+ return this.request(`/api/agents/${this.agentId}/voice/speakers${runtimeContextQueryString(runtimeContext)}`);
293
296
  }
294
297
  /**
295
298
  * Get the listener configuration for the agent's voice provider
296
299
  * @param runtimeContext - Optional runtime context to pass as query parameter
300
+ * @param runtimeContext - Optional runtime context to pass as query parameter
297
301
  * @returns Promise containing a check if the agent has listening capabilities
298
302
  */
299
303
  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}` : ""}`);
304
+ return this.request(`/api/agents/${this.agentId}/voice/listener${runtimeContextQueryString(runtimeContext)}`);
307
305
  }
308
306
  };
309
307
  var Agent = class extends BaseResource {
@@ -315,17 +313,11 @@ var Agent = class extends BaseResource {
315
313
  voice;
316
314
  /**
317
315
  * Retrieves details about the agent
318
- * @param runtimeContext - Runtime context to use for the agent
316
+ * @param runtimeContext - Optional runtime context to pass as query parameter
319
317
  * @returns Promise containing agent details including model and instructions
320
318
  */
321
319
  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}` : ""}`);
320
+ return this.request(`/api/agents/${this.agentId}${runtimeContextQueryString(runtimeContext)}`);
329
321
  }
330
322
  async generate(params) {
331
323
  console.warn(
@@ -398,7 +390,16 @@ var Agent = class extends BaseResource {
398
390
  }
399
391
  return response;
400
392
  }
401
- async generateVNext(params) {
393
+ async generateVNext(messagesOrParams, options) {
394
+ let params;
395
+ if (typeof messagesOrParams === "object" && "messages" in messagesOrParams) {
396
+ params = messagesOrParams;
397
+ } else {
398
+ params = {
399
+ messages: messagesOrParams,
400
+ ...options
401
+ };
402
+ }
402
403
  const processedParams = {
403
404
  ...params,
404
405
  output: params.output ? zodToJsonSchema(params.output) : void 0,
@@ -1127,7 +1128,16 @@ var Agent = class extends BaseResource {
1127
1128
  };
1128
1129
  return streamResponse;
1129
1130
  }
1130
- async streamVNext(params) {
1131
+ async streamVNext(messagesOrParams, options) {
1132
+ let params;
1133
+ if (typeof messagesOrParams === "object" && "messages" in messagesOrParams) {
1134
+ params = messagesOrParams;
1135
+ } else {
1136
+ params = {
1137
+ messages: messagesOrParams,
1138
+ ...options
1139
+ };
1140
+ }
1131
1141
  const processedParams = {
1132
1142
  ...params,
1133
1143
  output: params.output ? zodToJsonSchema(params.output) : void 0,
@@ -1276,13 +1286,7 @@ var Agent = class extends BaseResource {
1276
1286
  * @returns Promise containing tool details
1277
1287
  */
1278
1288
  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}` : ""}`);
1289
+ return this.request(`/api/agents/${this.agentId}/tools/${toolId}${runtimeContextQueryString(runtimeContext)}`);
1286
1290
  }
1287
1291
  /**
1288
1292
  * Executes a tool for the agent
@@ -1306,13 +1310,7 @@ var Agent = class extends BaseResource {
1306
1310
  * @returns Promise containing agent evaluations
1307
1311
  */
1308
1312
  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}` : ""}`);
1313
+ return this.request(`/api/agents/${this.agentId}/evals/ci${runtimeContextQueryString(runtimeContext)}`);
1316
1314
  }
1317
1315
  /**
1318
1316
  * Retrieves live evaluation results for the agent
@@ -1320,13 +1318,7 @@ var Agent = class extends BaseResource {
1320
1318
  * @returns Promise containing live agent evaluations
1321
1319
  */
1322
1320
  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}` : ""}`);
1321
+ return this.request(`/api/agents/${this.agentId}/evals/live${runtimeContextQueryString(runtimeContext)}`);
1330
1322
  }
1331
1323
  /**
1332
1324
  * Updates the model for the agent
@@ -1347,10 +1339,11 @@ var Network = class extends BaseResource {
1347
1339
  }
1348
1340
  /**
1349
1341
  * Retrieves details about the network
1342
+ * @param runtimeContext - Optional runtime context to pass as query parameter
1350
1343
  * @returns Promise containing network details
1351
1344
  */
1352
- details() {
1353
- return this.request(`/api/networks/${this.networkId}`);
1345
+ details(runtimeContext) {
1346
+ return this.request(`/api/networks/${this.networkId}${runtimeContextQueryString(runtimeContext)}`);
1354
1347
  }
1355
1348
  /**
1356
1349
  * Generates a response from the agent
@@ -1484,10 +1477,13 @@ var Vector = class extends BaseResource {
1484
1477
  /**
1485
1478
  * Retrieves details about a specific vector index
1486
1479
  * @param indexName - Name of the index to get details for
1480
+ * @param runtimeContext - Optional runtime context to pass as query parameter
1487
1481
  * @returns Promise containing vector index details
1488
1482
  */
1489
- details(indexName) {
1490
- return this.request(`/api/vector/${this.vectorName}/indexes/${indexName}`);
1483
+ details(indexName, runtimeContext) {
1484
+ return this.request(
1485
+ `/api/vector/${this.vectorName}/indexes/${indexName}${runtimeContextQueryString(runtimeContext)}`
1486
+ );
1491
1487
  }
1492
1488
  /**
1493
1489
  * Deletes a vector index
@@ -1501,10 +1497,11 @@ var Vector = class extends BaseResource {
1501
1497
  }
1502
1498
  /**
1503
1499
  * Retrieves a list of all available indexes
1500
+ * @param runtimeContext - Optional runtime context to pass as query parameter
1504
1501
  * @returns Promise containing array of index names
1505
1502
  */
1506
- getIndexes() {
1507
- return this.request(`/api/vector/${this.vectorName}/indexes`);
1503
+ getIndexes(runtimeContext) {
1504
+ return this.request(`/api/vector/${this.vectorName}/indexes${runtimeContextQueryString(runtimeContext)}`);
1508
1505
  }
1509
1506
  /**
1510
1507
  * Creates a new vector index
@@ -1550,17 +1547,20 @@ var LegacyWorkflow = class extends BaseResource {
1550
1547
  }
1551
1548
  /**
1552
1549
  * Retrieves details about the legacy workflow
1550
+ * @param runtimeContext - Optional runtime context to pass as query parameter
1553
1551
  * @returns Promise containing legacy workflow details including steps and graphs
1554
1552
  */
1555
- details() {
1556
- return this.request(`/api/workflows/legacy/${this.workflowId}`);
1553
+ details(runtimeContext) {
1554
+ return this.request(`/api/workflows/legacy/${this.workflowId}${runtimeContextQueryString(runtimeContext)}`);
1557
1555
  }
1558
1556
  /**
1559
1557
  * Retrieves all runs for a legacy workflow
1560
1558
  * @param params - Parameters for filtering runs
1559
+ * @param runtimeContext - Optional runtime context to pass as query parameter
1561
1560
  * @returns Promise containing legacy workflow runs array
1562
1561
  */
1563
- runs(params) {
1562
+ runs(params, runtimeContext) {
1563
+ const runtimeContextParam = base64RuntimeContext(parseClientRuntimeContext(runtimeContext));
1564
1564
  const searchParams = new URLSearchParams();
1565
1565
  if (params?.fromDate) {
1566
1566
  searchParams.set("fromDate", params.fromDate.toISOString());
@@ -1577,6 +1577,9 @@ var LegacyWorkflow = class extends BaseResource {
1577
1577
  if (params?.resourceId) {
1578
1578
  searchParams.set("resourceId", params.resourceId);
1579
1579
  }
1580
+ if (runtimeContextParam) {
1581
+ searchParams.set("runtimeContext", runtimeContextParam);
1582
+ }
1580
1583
  if (searchParams.size) {
1581
1584
  return this.request(`/api/workflows/legacy/${this.workflowId}/runs?${searchParams}`);
1582
1585
  } else {
@@ -1730,10 +1733,11 @@ var Tool = class extends BaseResource {
1730
1733
  }
1731
1734
  /**
1732
1735
  * Retrieves details about the tool
1736
+ * @param runtimeContext - Optional runtime context to pass as query parameter
1733
1737
  * @returns Promise containing tool details including description and schemas
1734
1738
  */
1735
- details() {
1736
- return this.request(`/api/tools/${this.toolId}`);
1739
+ details(runtimeContext) {
1740
+ return this.request(`/api/tools/${this.toolId}${runtimeContextQueryString(runtimeContext)}`);
1737
1741
  }
1738
1742
  /**
1739
1743
  * Executes the tool with the provided parameters
@@ -1810,17 +1814,20 @@ var Workflow = class extends BaseResource {
1810
1814
  }
1811
1815
  /**
1812
1816
  * Retrieves details about the workflow
1817
+ * @param runtimeContext - Optional runtime context to pass as query parameter
1813
1818
  * @returns Promise containing workflow details including steps and graphs
1814
1819
  */
1815
- details() {
1816
- return this.request(`/api/workflows/${this.workflowId}`);
1820
+ details(runtimeContext) {
1821
+ return this.request(`/api/workflows/${this.workflowId}${runtimeContextQueryString(runtimeContext)}`);
1817
1822
  }
1818
1823
  /**
1819
1824
  * Retrieves all runs for a workflow
1820
1825
  * @param params - Parameters for filtering runs
1826
+ * @param runtimeContext - Optional runtime context to pass as query parameter
1821
1827
  * @returns Promise containing workflow runs array
1822
1828
  */
1823
- runs(params) {
1829
+ runs(params, runtimeContext) {
1830
+ const runtimeContextParam = base64RuntimeContext(parseClientRuntimeContext(runtimeContext));
1824
1831
  const searchParams = new URLSearchParams();
1825
1832
  if (params?.fromDate) {
1826
1833
  searchParams.set("fromDate", params.fromDate.toISOString());
@@ -1837,6 +1844,9 @@ var Workflow = class extends BaseResource {
1837
1844
  if (params?.resourceId) {
1838
1845
  searchParams.set("resourceId", params.resourceId);
1839
1846
  }
1847
+ if (runtimeContextParam) {
1848
+ searchParams.set("runtimeContext", runtimeContextParam);
1849
+ }
1840
1850
  if (searchParams.size) {
1841
1851
  return this.request(`/api/workflows/${this.workflowId}/runs?${searchParams}`);
1842
1852
  } else {
@@ -1846,18 +1856,22 @@ var Workflow = class extends BaseResource {
1846
1856
  /**
1847
1857
  * Retrieves a specific workflow run by its ID
1848
1858
  * @param runId - The ID of the workflow run to retrieve
1859
+ * @param runtimeContext - Optional runtime context to pass as query parameter
1849
1860
  * @returns Promise containing the workflow run details
1850
1861
  */
1851
- runById(runId) {
1852
- return this.request(`/api/workflows/${this.workflowId}/runs/${runId}`);
1862
+ runById(runId, runtimeContext) {
1863
+ return this.request(`/api/workflows/${this.workflowId}/runs/${runId}${runtimeContextQueryString(runtimeContext)}`);
1853
1864
  }
1854
1865
  /**
1855
1866
  * Retrieves the execution result for a specific workflow run by its ID
1856
1867
  * @param runId - The ID of the workflow run to retrieve the execution result for
1868
+ * @param runtimeContext - Optional runtime context to pass as query parameter
1857
1869
  * @returns Promise containing the workflow run execution result
1858
1870
  */
1859
- runExecutionResult(runId) {
1860
- return this.request(`/api/workflows/${this.workflowId}/runs/${runId}/execution-result`);
1871
+ runExecutionResult(runId, runtimeContext) {
1872
+ return this.request(
1873
+ `/api/workflows/${this.workflowId}/runs/${runId}/execution-result${runtimeContextQueryString(runtimeContext)}`
1874
+ );
1861
1875
  }
1862
1876
  /**
1863
1877
  * Cancels a specific workflow run by its ID
@@ -1885,14 +1899,40 @@ var Workflow = class extends BaseResource {
1885
1899
  * @param params - Optional object containing the optional runId
1886
1900
  * @returns Promise containing the runId of the created run
1887
1901
  */
1888
- createRun(params) {
1902
+ /** @deprecated Use createRunAsync instead */
1903
+ async createRun(params) {
1889
1904
  const searchParams = new URLSearchParams();
1890
1905
  if (!!params?.runId) {
1891
1906
  searchParams.set("runId", params.runId);
1892
1907
  }
1893
- return this.request(`/api/workflows/${this.workflowId}/create-run?${searchParams.toString()}`, {
1894
- method: "POST"
1895
- });
1908
+ const res = await this.request(
1909
+ `/api/workflows/${this.workflowId}/create-run?${searchParams.toString()}`,
1910
+ {
1911
+ method: "POST"
1912
+ }
1913
+ );
1914
+ const runId = res.runId;
1915
+ return {
1916
+ runId,
1917
+ start: async (p) => {
1918
+ return this.start({ runId, inputData: p.inputData, runtimeContext: p.runtimeContext });
1919
+ },
1920
+ startAsync: async (p) => {
1921
+ return this.startAsync({ runId, inputData: p.inputData, runtimeContext: p.runtimeContext });
1922
+ },
1923
+ watch: async (onRecord) => {
1924
+ return this.watch({ runId }, onRecord);
1925
+ },
1926
+ stream: async (p) => {
1927
+ return this.stream({ runId, inputData: p.inputData, runtimeContext: p.runtimeContext });
1928
+ },
1929
+ resume: async (p) => {
1930
+ return this.resume({ runId, step: p.step, resumeData: p.resumeData, runtimeContext: p.runtimeContext });
1931
+ },
1932
+ resumeAsync: async (p) => {
1933
+ return this.resumeAsync({ runId, step: p.step, resumeData: p.resumeData, runtimeContext: p.runtimeContext });
1934
+ }
1935
+ };
1896
1936
  }
1897
1937
  /**
1898
1938
  * Creates a new workflow run (alias for createRun)
@@ -1928,7 +1968,6 @@ var Workflow = class extends BaseResource {
1928
1968
  const runtimeContext = parseClientRuntimeContext(rest.runtimeContext);
1929
1969
  return this.request(`/api/workflows/${this.workflowId}/resume?runId=${runId}`, {
1930
1970
  method: "POST",
1931
- stream: true,
1932
1971
  body: {
1933
1972
  step,
1934
1973
  resumeData,
@@ -2204,10 +2243,11 @@ var MCPTool = class extends BaseResource {
2204
2243
  }
2205
2244
  /**
2206
2245
  * Retrieves details about this specific tool from the MCP server.
2246
+ * @param runtimeContext - Optional runtime context to pass as query parameter
2207
2247
  * @returns Promise containing the tool's information (name, description, schema).
2208
2248
  */
2209
- details() {
2210
- return this.request(`/api/mcp/${this.serverId}/tools/${this.toolId}`);
2249
+ details(runtimeContext) {
2250
+ return this.request(`/api/mcp/${this.serverId}/tools/${this.toolId}${runtimeContextQueryString(runtimeContext)}`);
2211
2251
  }
2212
2252
  /**
2213
2253
  * Executes this specific tool on the MCP server.
@@ -2718,10 +2758,11 @@ var VNextNetwork = class extends BaseResource {
2718
2758
  }
2719
2759
  /**
2720
2760
  * Retrieves details about the network
2761
+ * @param runtimeContext - Optional runtime context to pass as query parameter
2721
2762
  * @returns Promise containing vNext network details
2722
2763
  */
2723
- details() {
2724
- return this.request(`/api/networks/v-next/${this.networkId}`);
2764
+ details(runtimeContext) {
2765
+ return this.request(`/api/networks/v-next/${this.networkId}${runtimeContextQueryString(runtimeContext)}`);
2725
2766
  }
2726
2767
  /**
2727
2768
  * Generates a response from the v-next network
@@ -2856,7 +2897,7 @@ var MastraClient = class extends BaseResource {
2856
2897
  }
2857
2898
  /**
2858
2899
  * Retrieves all available agents
2859
- * @param runtimeContext - Runtime context to use for the agents
2900
+ * @param runtimeContext - Optional runtime context to pass as query parameter
2860
2901
  * @returns Promise containing map of agent IDs to agent details
2861
2902
  */
2862
2903
  getAgents(runtimeContext) {
@@ -2962,10 +3003,17 @@ var MastraClient = class extends BaseResource {
2962
3003
  }
2963
3004
  /**
2964
3005
  * Retrieves all available tools
3006
+ * @param runtimeContext - Optional runtime context to pass as query parameter
2965
3007
  * @returns Promise containing map of tool IDs to tool details
2966
3008
  */
2967
- getTools() {
2968
- return this.request("/api/tools");
3009
+ getTools(runtimeContext) {
3010
+ const runtimeContextParam = base64RuntimeContext(parseClientRuntimeContext(runtimeContext));
3011
+ const searchParams = new URLSearchParams();
3012
+ if (runtimeContextParam) {
3013
+ searchParams.set("runtimeContext", runtimeContextParam);
3014
+ }
3015
+ const queryString = searchParams.toString();
3016
+ return this.request(`/api/tools${queryString ? `?${queryString}` : ""}`);
2969
3017
  }
2970
3018
  /**
2971
3019
  * Gets a tool instance by ID
@@ -2992,10 +3040,17 @@ var MastraClient = class extends BaseResource {
2992
3040
  }
2993
3041
  /**
2994
3042
  * Retrieves all available workflows
3043
+ * @param runtimeContext - Optional runtime context to pass as query parameter
2995
3044
  * @returns Promise containing map of workflow IDs to workflow details
2996
3045
  */
2997
- getWorkflows() {
2998
- return this.request("/api/workflows");
3046
+ getWorkflows(runtimeContext) {
3047
+ const runtimeContextParam = base64RuntimeContext(parseClientRuntimeContext(runtimeContext));
3048
+ const searchParams = new URLSearchParams();
3049
+ if (runtimeContextParam) {
3050
+ searchParams.set("runtimeContext", runtimeContextParam);
3051
+ }
3052
+ const queryString = searchParams.toString();
3053
+ return this.request(`/api/workflows${queryString ? `?${queryString}` : ""}`);
2999
3054
  }
3000
3055
  /**
3001
3056
  * Gets a workflow instance by ID
@@ -3377,6 +3432,25 @@ var MastraClient = class extends BaseResource {
3377
3432
  }
3378
3433
  };
3379
3434
 
3380
- export { MastraClient };
3435
+ // src/tools.ts
3436
+ var ClientTool = class {
3437
+ id;
3438
+ description;
3439
+ inputSchema;
3440
+ outputSchema;
3441
+ execute;
3442
+ constructor(opts) {
3443
+ this.id = opts.id;
3444
+ this.description = opts.description;
3445
+ this.inputSchema = opts.inputSchema;
3446
+ this.outputSchema = opts.outputSchema;
3447
+ this.execute = opts.execute;
3448
+ }
3449
+ };
3450
+ function createTool(opts) {
3451
+ return new ClientTool(opts);
3452
+ }
3453
+
3454
+ export { ClientTool, MastraClient, createTool };
3381
3455
  //# sourceMappingURL=index.js.map
3382
3456
  //# sourceMappingURL=index.js.map