@mastra/client-js 1.3.0 → 1.4.0

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
@@ -1124,7 +1124,8 @@ function parseClientRequestContext(requestContext) {
1124
1124
  }
1125
1125
  function base64RequestContext(requestContext) {
1126
1126
  if (requestContext) {
1127
- return btoa(JSON.stringify(requestContext));
1127
+ const bytes = new TextEncoder().encode(JSON.stringify(requestContext));
1128
+ return btoa(Array.from(bytes, (byte) => String.fromCharCode(byte)).join(""));
1128
1129
  }
1129
1130
  return void 0;
1130
1131
  }
@@ -1282,7 +1283,7 @@ var BaseResource = class {
1282
1283
  const response = await fetchFn(`${baseUrl.replace(/\/$/, "")}${fullPath}`, {
1283
1284
  ...options,
1284
1285
  headers: {
1285
- ...options.body && !(options.body instanceof FormData) && (options.method === "POST" || options.method === "PUT" || options.method === "PATCH") ? { "content-type": "application/json" } : {},
1286
+ ...options.body && !(options.body instanceof FormData) && (options.method === "POST" || options.method === "PUT" || options.method === "PATCH" || options.method === "DELETE") ? { "content-type": "application/json" } : {},
1286
1287
  ...headers,
1287
1288
  ...options.headers
1288
1289
  // TODO: Bring this back once we figure out what we/users need to do to make this work with cross-origin requests
@@ -2245,12 +2246,18 @@ var Agent = class extends BaseResource {
2245
2246
  return response;
2246
2247
  }
2247
2248
  async network(messages, params) {
2249
+ const processedParams = {
2250
+ ...params,
2251
+ messages,
2252
+ requestContext: parseClientRequestContext(params.requestContext),
2253
+ structuredOutput: params.structuredOutput ? {
2254
+ ...params.structuredOutput,
2255
+ schema: zodToJsonSchema2(params.structuredOutput.schema)
2256
+ } : void 0
2257
+ };
2248
2258
  const response = await this.request(`/agents/${this.agentId}/network`, {
2249
2259
  method: "POST",
2250
- body: {
2251
- messages,
2252
- ...params
2253
- },
2260
+ body: processedParams,
2254
2261
  stream: true
2255
2262
  });
2256
2263
  if (!response.body) {
@@ -3312,6 +3319,17 @@ var Workflow = class extends BaseResource {
3312
3319
  method: "DELETE"
3313
3320
  });
3314
3321
  }
3322
+ /**
3323
+ * Retrieves the input/output schema for the workflow
3324
+ * @returns Promise containing parsed inputSchema and outputSchema, or null if not defined
3325
+ */
3326
+ async getSchema() {
3327
+ const details = await this.details();
3328
+ return {
3329
+ inputSchema: details.inputSchema ? JSON.parse(details.inputSchema) : null,
3330
+ outputSchema: details.outputSchema ? JSON.parse(details.outputSchema) : null
3331
+ };
3332
+ }
3315
3333
  /**
3316
3334
  * Creates a new workflow run
3317
3335
  * @param params - Optional object containing the optional runId
@@ -4070,6 +4088,52 @@ var StoredAgent = class extends BaseResource {
4070
4088
  }
4071
4089
  };
4072
4090
 
4091
+ // src/resources/stored-mcp-client.ts
4092
+ var StoredMCPClient = class extends BaseResource {
4093
+ constructor(options, storedMCPClientId) {
4094
+ super(options);
4095
+ this.storedMCPClientId = storedMCPClientId;
4096
+ }
4097
+ /**
4098
+ * Retrieves details about the stored MCP client
4099
+ * @param requestContext - Optional request context to pass as query parameter
4100
+ * @returns Promise containing stored MCP client details
4101
+ */
4102
+ details(requestContext) {
4103
+ return this.request(
4104
+ `/stored/mcp-clients/${encodeURIComponent(this.storedMCPClientId)}${requestContextQueryString(requestContext)}`
4105
+ );
4106
+ }
4107
+ /**
4108
+ * Updates the stored MCP client with the provided fields
4109
+ * @param params - Fields to update
4110
+ * @param requestContext - Optional request context to pass as query parameter
4111
+ * @returns Promise containing the updated stored MCP client
4112
+ */
4113
+ update(params, requestContext) {
4114
+ return this.request(
4115
+ `/stored/mcp-clients/${encodeURIComponent(this.storedMCPClientId)}${requestContextQueryString(requestContext)}`,
4116
+ {
4117
+ method: "PATCH",
4118
+ body: params
4119
+ }
4120
+ );
4121
+ }
4122
+ /**
4123
+ * Deletes the stored MCP client
4124
+ * @param requestContext - Optional request context to pass as query parameter
4125
+ * @returns Promise containing deletion confirmation
4126
+ */
4127
+ delete(requestContext) {
4128
+ return this.request(
4129
+ `/stored/mcp-clients/${encodeURIComponent(this.storedMCPClientId)}${requestContextQueryString(requestContext)}`,
4130
+ {
4131
+ method: "DELETE"
4132
+ }
4133
+ );
4134
+ }
4135
+ };
4136
+
4073
4137
  // src/resources/stored-scorer.ts
4074
4138
  var StoredScorer = class extends BaseResource {
4075
4139
  constructor(options, storedScorerId) {
@@ -4116,6 +4180,55 @@ var StoredScorer = class extends BaseResource {
4116
4180
  }
4117
4181
  };
4118
4182
 
4183
+ // src/resources/tool-provider.ts
4184
+ var ToolProvider = class extends BaseResource {
4185
+ constructor(options, providerId) {
4186
+ super(options);
4187
+ this.providerId = providerId;
4188
+ }
4189
+ /**
4190
+ * Lists available toolkits from this provider
4191
+ * @returns Promise containing list of toolkits
4192
+ */
4193
+ listToolkits() {
4194
+ return this.request(`/tool-providers/${encodeURIComponent(this.providerId)}/toolkits`);
4195
+ }
4196
+ /**
4197
+ * Lists available tools from this provider, with optional filtering
4198
+ * @param params - Optional filtering and pagination parameters
4199
+ * @returns Promise containing list of tools
4200
+ */
4201
+ listTools(params) {
4202
+ const searchParams = new URLSearchParams();
4203
+ if (params?.toolkit) {
4204
+ searchParams.set("toolkit", params.toolkit);
4205
+ }
4206
+ if (params?.search) {
4207
+ searchParams.set("search", params.search);
4208
+ }
4209
+ if (params?.page !== void 0) {
4210
+ searchParams.set("page", String(params.page));
4211
+ }
4212
+ if (params?.perPage !== void 0) {
4213
+ searchParams.set("perPage", String(params.perPage));
4214
+ }
4215
+ const queryString = searchParams.toString();
4216
+ return this.request(
4217
+ `/tool-providers/${encodeURIComponent(this.providerId)}/tools${queryString ? `?${queryString}` : ""}`
4218
+ );
4219
+ }
4220
+ /**
4221
+ * Gets the input schema for a specific tool
4222
+ * @param toolSlug - The slug of the tool
4223
+ * @returns Promise containing the tool's JSON schema
4224
+ */
4225
+ getToolSchema(toolSlug) {
4226
+ return this.request(
4227
+ `/tool-providers/${encodeURIComponent(this.providerId)}/tools/${encodeURIComponent(toolSlug)}/schema`
4228
+ );
4229
+ }
4230
+ };
4231
+
4119
4232
  // src/resources/workspace.ts
4120
4233
  var WorkspaceSkillResource = class extends BaseResource {
4121
4234
  constructor(options, workspaceId, skillName) {
@@ -5048,6 +5161,76 @@ var MastraClient = class extends BaseResource {
5048
5161
  return new StoredScorer(this.options, storedScorerId);
5049
5162
  }
5050
5163
  // ============================================================================
5164
+ // Stored MCP Clients
5165
+ // ============================================================================
5166
+ /**
5167
+ * Lists all stored MCP clients with optional pagination
5168
+ * @param params - Optional pagination and ordering parameters
5169
+ * @returns Promise containing paginated list of stored MCP clients
5170
+ */
5171
+ listStoredMCPClients(params) {
5172
+ const searchParams = new URLSearchParams();
5173
+ if (params?.page !== void 0) {
5174
+ searchParams.set("page", String(params.page));
5175
+ }
5176
+ if (params?.perPage !== void 0) {
5177
+ searchParams.set("perPage", String(params.perPage));
5178
+ }
5179
+ if (params?.orderBy) {
5180
+ if (params.orderBy.field) {
5181
+ searchParams.set("orderBy[field]", params.orderBy.field);
5182
+ }
5183
+ if (params.orderBy.direction) {
5184
+ searchParams.set("orderBy[direction]", params.orderBy.direction);
5185
+ }
5186
+ }
5187
+ if (params?.authorId) {
5188
+ searchParams.set("authorId", params.authorId);
5189
+ }
5190
+ if (params?.metadata) {
5191
+ searchParams.set("metadata", JSON.stringify(params.metadata));
5192
+ }
5193
+ const queryString = searchParams.toString();
5194
+ return this.request(`/stored/mcp-clients${queryString ? `?${queryString}` : ""}`);
5195
+ }
5196
+ /**
5197
+ * Creates a new stored MCP client
5198
+ * @param params - MCP client configuration
5199
+ * @returns Promise containing the created stored MCP client
5200
+ */
5201
+ createStoredMCPClient(params) {
5202
+ return this.request("/stored/mcp-clients", {
5203
+ method: "POST",
5204
+ body: params
5205
+ });
5206
+ }
5207
+ /**
5208
+ * Gets a stored MCP client instance by ID for further operations (details, update, delete)
5209
+ * @param storedMCPClientId - ID of the stored MCP client
5210
+ * @returns StoredMCPClient instance
5211
+ */
5212
+ getStoredMCPClient(storedMCPClientId) {
5213
+ return new StoredMCPClient(this.options, storedMCPClientId);
5214
+ }
5215
+ // ============================================================================
5216
+ // Tool Providers
5217
+ // ============================================================================
5218
+ /**
5219
+ * Lists all registered tool providers
5220
+ * @returns Promise containing list of tool provider info
5221
+ */
5222
+ listToolProviders() {
5223
+ return this.request("/tool-providers");
5224
+ }
5225
+ /**
5226
+ * Gets a tool provider instance by ID for further operations (listToolkits, listTools, getToolSchema)
5227
+ * @param providerId - ID of the tool provider
5228
+ * @returns ToolProvider instance
5229
+ */
5230
+ getToolProvider(providerId) {
5231
+ return new ToolProvider(this.options, providerId);
5232
+ }
5233
+ // ============================================================================
5051
5234
  // System
5052
5235
  // ============================================================================
5053
5236
  /**
@@ -5092,6 +5275,201 @@ var MastraClient = class extends BaseResource {
5092
5275
  listEmbedders() {
5093
5276
  return this.request("/embedders");
5094
5277
  }
5278
+ // ============================================================================
5279
+ // Datasets
5280
+ // ============================================================================
5281
+ /**
5282
+ * Lists all datasets with optional pagination
5283
+ */
5284
+ listDatasets(pagination) {
5285
+ const searchParams = new URLSearchParams();
5286
+ if (pagination?.page !== void 0) searchParams.set("page", String(pagination.page));
5287
+ if (pagination?.perPage !== void 0) searchParams.set("perPage", String(pagination.perPage));
5288
+ const qs = searchParams.toString();
5289
+ return this.request(`/datasets${qs ? `?${qs}` : ""}`);
5290
+ }
5291
+ /**
5292
+ * Gets a single dataset by ID
5293
+ */
5294
+ getDataset(datasetId) {
5295
+ return this.request(`/datasets/${encodeURIComponent(datasetId)}`);
5296
+ }
5297
+ /**
5298
+ * Creates a new dataset
5299
+ */
5300
+ createDataset(params) {
5301
+ return this.request("/datasets", { method: "POST", body: params });
5302
+ }
5303
+ /**
5304
+ * Updates a dataset
5305
+ */
5306
+ updateDataset(params) {
5307
+ const { datasetId, ...body } = params;
5308
+ return this.request(`/datasets/${encodeURIComponent(datasetId)}`, {
5309
+ method: "PATCH",
5310
+ body
5311
+ });
5312
+ }
5313
+ /**
5314
+ * Deletes a dataset
5315
+ */
5316
+ deleteDataset(datasetId) {
5317
+ return this.request(`/datasets/${encodeURIComponent(datasetId)}`, {
5318
+ method: "DELETE"
5319
+ });
5320
+ }
5321
+ // ============================================================================
5322
+ // Dataset Items
5323
+ // ============================================================================
5324
+ /**
5325
+ * Lists items in a dataset with optional pagination, search, and version filter
5326
+ */
5327
+ listDatasetItems(datasetId, params) {
5328
+ const searchParams = new URLSearchParams();
5329
+ if (params?.page !== void 0) searchParams.set("page", String(params.page));
5330
+ if (params?.perPage !== void 0) searchParams.set("perPage", String(params.perPage));
5331
+ if (params?.search) searchParams.set("search", params.search);
5332
+ if (params?.version != null) {
5333
+ searchParams.set("version", String(params.version));
5334
+ }
5335
+ const qs = searchParams.toString();
5336
+ return this.request(`/datasets/${encodeURIComponent(datasetId)}/items${qs ? `?${qs}` : ""}`);
5337
+ }
5338
+ /**
5339
+ * Gets a single dataset item by ID
5340
+ */
5341
+ getDatasetItem(datasetId, itemId) {
5342
+ return this.request(`/datasets/${encodeURIComponent(datasetId)}/items/${encodeURIComponent(itemId)}`);
5343
+ }
5344
+ /**
5345
+ * Adds an item to a dataset
5346
+ */
5347
+ addDatasetItem(params) {
5348
+ const { datasetId, ...body } = params;
5349
+ return this.request(`/datasets/${encodeURIComponent(datasetId)}/items`, {
5350
+ method: "POST",
5351
+ body
5352
+ });
5353
+ }
5354
+ /**
5355
+ * Updates a dataset item
5356
+ */
5357
+ updateDatasetItem(params) {
5358
+ const { datasetId, itemId, ...body } = params;
5359
+ return this.request(`/datasets/${encodeURIComponent(datasetId)}/items/${encodeURIComponent(itemId)}`, {
5360
+ method: "PATCH",
5361
+ body
5362
+ });
5363
+ }
5364
+ /**
5365
+ * Deletes a dataset item
5366
+ */
5367
+ deleteDatasetItem(datasetId, itemId) {
5368
+ return this.request(`/datasets/${encodeURIComponent(datasetId)}/items/${encodeURIComponent(itemId)}`, {
5369
+ method: "DELETE"
5370
+ });
5371
+ }
5372
+ /**
5373
+ * Batch inserts items to a dataset
5374
+ */
5375
+ batchInsertDatasetItems(params) {
5376
+ const { datasetId, ...body } = params;
5377
+ return this.request(`/datasets/${encodeURIComponent(datasetId)}/items/batch`, {
5378
+ method: "POST",
5379
+ body
5380
+ });
5381
+ }
5382
+ /**
5383
+ * Batch deletes items from a dataset
5384
+ */
5385
+ batchDeleteDatasetItems(params) {
5386
+ const { datasetId, ...body } = params;
5387
+ return this.request(`/datasets/${encodeURIComponent(datasetId)}/items/batch`, {
5388
+ method: "DELETE",
5389
+ body
5390
+ });
5391
+ }
5392
+ // ============================================================================
5393
+ // Dataset Item Versions
5394
+ // ============================================================================
5395
+ /**
5396
+ * Lists versions for a dataset item
5397
+ */
5398
+ getItemHistory(datasetId, itemId) {
5399
+ return this.request(`/datasets/${encodeURIComponent(datasetId)}/items/${encodeURIComponent(itemId)}/history`);
5400
+ }
5401
+ /**
5402
+ * Gets a specific version of a dataset item
5403
+ */
5404
+ getDatasetItemVersion(datasetId, itemId, datasetVersion) {
5405
+ return this.request(
5406
+ `/datasets/${encodeURIComponent(datasetId)}/items/${encodeURIComponent(itemId)}/versions/${datasetVersion}`
5407
+ );
5408
+ }
5409
+ // ============================================================================
5410
+ // Dataset Versions
5411
+ // ============================================================================
5412
+ /**
5413
+ * Lists versions for a dataset
5414
+ */
5415
+ listDatasetVersions(datasetId, pagination) {
5416
+ const searchParams = new URLSearchParams();
5417
+ if (pagination?.page !== void 0) searchParams.set("page", String(pagination.page));
5418
+ if (pagination?.perPage !== void 0) searchParams.set("perPage", String(pagination.perPage));
5419
+ const qs = searchParams.toString();
5420
+ return this.request(`/datasets/${encodeURIComponent(datasetId)}/versions${qs ? `?${qs}` : ""}`);
5421
+ }
5422
+ // ============================================================================
5423
+ // Dataset Experiments
5424
+ // ============================================================================
5425
+ /**
5426
+ * Lists experiments for a dataset
5427
+ */
5428
+ listDatasetExperiments(datasetId, pagination) {
5429
+ const searchParams = new URLSearchParams();
5430
+ if (pagination?.page !== void 0) searchParams.set("page", String(pagination.page));
5431
+ if (pagination?.perPage !== void 0) searchParams.set("perPage", String(pagination.perPage));
5432
+ const qs = searchParams.toString();
5433
+ return this.request(`/datasets/${encodeURIComponent(datasetId)}/experiments${qs ? `?${qs}` : ""}`);
5434
+ }
5435
+ /**
5436
+ * Gets a single dataset experiment by ID
5437
+ */
5438
+ getDatasetExperiment(datasetId, experimentId) {
5439
+ return this.request(`/datasets/${encodeURIComponent(datasetId)}/experiments/${encodeURIComponent(experimentId)}`);
5440
+ }
5441
+ /**
5442
+ * Lists results for a dataset experiment
5443
+ */
5444
+ listDatasetExperimentResults(datasetId, experimentId, pagination) {
5445
+ const searchParams = new URLSearchParams();
5446
+ if (pagination?.page !== void 0) searchParams.set("page", String(pagination.page));
5447
+ if (pagination?.perPage !== void 0) searchParams.set("perPage", String(pagination.perPage));
5448
+ const qs = searchParams.toString();
5449
+ return this.request(
5450
+ `/datasets/${encodeURIComponent(datasetId)}/experiments/${encodeURIComponent(experimentId)}/results${qs ? `?${qs}` : ""}`
5451
+ );
5452
+ }
5453
+ /**
5454
+ * Triggers a new dataset experiment
5455
+ */
5456
+ triggerDatasetExperiment(params) {
5457
+ const { datasetId, ...body } = params;
5458
+ return this.request(`/datasets/${encodeURIComponent(datasetId)}/experiments`, {
5459
+ method: "POST",
5460
+ body
5461
+ });
5462
+ }
5463
+ /**
5464
+ * Compares two dataset experiments for regression detection
5465
+ */
5466
+ compareExperiments(params) {
5467
+ const { datasetId, ...body } = params;
5468
+ return this.request(`/datasets/${encodeURIComponent(datasetId)}/compare`, {
5469
+ method: "POST",
5470
+ body
5471
+ });
5472
+ }
5095
5473
  };
5096
5474
 
5097
5475
  // src/tools.ts