@mastra/client-js 0.11.3-alpha.2 → 0.11.3-alpha.4

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.
Files changed (55) hide show
  1. package/CHANGELOG.md +23 -0
  2. package/dist/client.d.ts +12 -2
  3. package/dist/client.d.ts.map +1 -1
  4. package/dist/index.cjs +398 -4
  5. package/dist/index.cjs.map +1 -1
  6. package/dist/index.js +398 -4
  7. package/dist/index.js.map +1 -1
  8. package/dist/resources/agent-builder.d.ts +148 -0
  9. package/dist/resources/agent-builder.d.ts.map +1 -0
  10. package/dist/resources/agent.d.ts +25 -0
  11. package/dist/resources/agent.d.ts.map +1 -1
  12. package/dist/resources/index.d.ts +1 -0
  13. package/dist/resources/index.d.ts.map +1 -1
  14. package/dist/types.d.ts +33 -0
  15. package/dist/types.d.ts.map +1 -1
  16. package/package.json +10 -6
  17. package/.turbo/turbo-build.log +0 -18
  18. package/eslint.config.js +0 -11
  19. package/integration-tests/agui-adapter.test.ts +0 -122
  20. package/integration-tests/package.json +0 -18
  21. package/integration-tests/src/mastra/index.ts +0 -35
  22. package/integration-tests/vitest.config.ts +0 -9
  23. package/src/adapters/agui.test.ts +0 -293
  24. package/src/adapters/agui.ts +0 -257
  25. package/src/client.ts +0 -644
  26. package/src/example.ts +0 -95
  27. package/src/index.test.ts +0 -1253
  28. package/src/index.ts +0 -3
  29. package/src/resources/a2a.ts +0 -98
  30. package/src/resources/agent.ts +0 -1460
  31. package/src/resources/base.ts +0 -77
  32. package/src/resources/index.ts +0 -11
  33. package/src/resources/legacy-workflow.ts +0 -242
  34. package/src/resources/mcp-tool.ts +0 -48
  35. package/src/resources/memory-thread.test.ts +0 -285
  36. package/src/resources/memory-thread.ts +0 -99
  37. package/src/resources/network-memory-thread.test.ts +0 -269
  38. package/src/resources/network-memory-thread.ts +0 -81
  39. package/src/resources/network.ts +0 -86
  40. package/src/resources/observability.ts +0 -53
  41. package/src/resources/tool.ts +0 -45
  42. package/src/resources/vNextNetwork.ts +0 -194
  43. package/src/resources/vector.ts +0 -83
  44. package/src/resources/workflow.ts +0 -410
  45. package/src/types.ts +0 -534
  46. package/src/utils/index.ts +0 -11
  47. package/src/utils/process-client-tools.ts +0 -32
  48. package/src/utils/process-mastra-stream.test.ts +0 -353
  49. package/src/utils/process-mastra-stream.ts +0 -49
  50. package/src/utils/zod-to-json-schema.ts +0 -30
  51. package/src/v2-messages.test.ts +0 -180
  52. package/tsconfig.build.json +0 -9
  53. package/tsconfig.json +0 -5
  54. package/tsup.config.ts +0 -17
  55. package/vitest.config.js +0 -8
package/dist/index.js CHANGED
@@ -483,6 +483,12 @@ var Agent = class extends BaseResource {
483
483
  return this.request(`/api/agents/${this.agentId}`);
484
484
  }
485
485
  async generate(params) {
486
+ console.warn(
487
+ "Deprecation NOTICE:Generate method will switch to use generateVNext implementation September 16th. Please use generateLegacy if you don't want to upgrade just yet."
488
+ );
489
+ return this.generateLegacy(params);
490
+ }
491
+ async generateLegacy(params) {
486
492
  const processedParams = {
487
493
  ...params,
488
494
  output: params.output ? zodToJsonSchema(params.output) : void 0,
@@ -492,7 +498,7 @@ var Agent = class extends BaseResource {
492
498
  };
493
499
  const { runId, resourceId, threadId, runtimeContext } = processedParams;
494
500
  const response = await this.request(
495
- `/api/agents/${this.agentId}/generate`,
501
+ `/api/agents/${this.agentId}/generate-legacy`,
496
502
  {
497
503
  method: "POST",
498
504
  body: processedParams
@@ -843,6 +849,17 @@ var Agent = class extends BaseResource {
843
849
  * @returns Promise containing the enhanced Response object with processDataStream method
844
850
  */
845
851
  async stream(params) {
852
+ console.warn(
853
+ "Deprecation NOTICE:\nStream method will switch to use streamVNext implementation September 16th. Please use streamLegacy if you don't want to upgrade just yet."
854
+ );
855
+ return this.streamLegacy(params);
856
+ }
857
+ /**
858
+ * Streams a response from the agent
859
+ * @param params - Stream parameters including prompt
860
+ * @returns Promise containing the enhanced Response object with processDataStream method
861
+ */
862
+ async streamLegacy(params) {
846
863
  const processedParams = {
847
864
  ...params,
848
865
  output: params.output ? zodToJsonSchema(params.output) : void 0,
@@ -1257,7 +1274,7 @@ var Agent = class extends BaseResource {
1257
1274
  * Processes the stream response and handles tool calls
1258
1275
  */
1259
1276
  async processStreamResponse(processedParams, writable) {
1260
- const response = await this.request(`/api/agents/${this.agentId}/stream`, {
1277
+ const response = await this.request(`/api/agents/${this.agentId}/stream-legacy`, {
1261
1278
  method: "POST",
1262
1279
  body: processedParams,
1263
1280
  stream: true
@@ -2253,6 +2270,369 @@ var MCPTool = class extends BaseResource {
2253
2270
  }
2254
2271
  };
2255
2272
 
2273
+ // src/resources/agent-builder.ts
2274
+ var RECORD_SEPARATOR3 = "";
2275
+ var AgentBuilder = class extends BaseResource {
2276
+ constructor(options, actionId) {
2277
+ super(options);
2278
+ this.actionId = actionId;
2279
+ }
2280
+ // Helper function to transform workflow result to action result
2281
+ transformWorkflowResult(result) {
2282
+ if (result.status === "success") {
2283
+ return {
2284
+ success: result.result.success || false,
2285
+ applied: result.result.applied || false,
2286
+ branchName: result.result.branchName,
2287
+ message: result.result.message || "Agent builder action completed",
2288
+ validationResults: result.result.validationResults,
2289
+ error: result.result.error,
2290
+ errors: result.result.errors,
2291
+ stepResults: result.result.stepResults
2292
+ };
2293
+ } else if (result.status === "failed") {
2294
+ return {
2295
+ success: false,
2296
+ applied: false,
2297
+ message: `Agent builder action failed: ${result.error.message}`,
2298
+ error: result.error.message
2299
+ };
2300
+ } else {
2301
+ return {
2302
+ success: false,
2303
+ applied: false,
2304
+ message: "Agent builder action was suspended",
2305
+ error: "Workflow suspended - manual intervention required"
2306
+ };
2307
+ }
2308
+ }
2309
+ /**
2310
+ * Creates a new agent builder action run and returns the runId.
2311
+ * This calls `/api/agent-builder/:actionId/create-run`.
2312
+ */
2313
+ async createRun(params, runId) {
2314
+ const searchParams = new URLSearchParams();
2315
+ if (runId) {
2316
+ searchParams.set("runId", runId);
2317
+ }
2318
+ const runtimeContext = parseClientRuntimeContext(params.runtimeContext);
2319
+ const { runtimeContext: _, ...actionParams } = params;
2320
+ const url = `/api/agent-builder/${this.actionId}/create-run${searchParams.toString() ? `?${searchParams.toString()}` : ""}`;
2321
+ return this.request(url, {
2322
+ method: "POST",
2323
+ body: { ...actionParams, runtimeContext }
2324
+ });
2325
+ }
2326
+ /**
2327
+ * Starts agent builder action asynchronously and waits for completion.
2328
+ * This calls `/api/agent-builder/:actionId/start-async`.
2329
+ */
2330
+ async startAsync(params, runId) {
2331
+ const searchParams = new URLSearchParams();
2332
+ if (runId) {
2333
+ searchParams.set("runId", runId);
2334
+ }
2335
+ const runtimeContext = parseClientRuntimeContext(params.runtimeContext);
2336
+ const { runtimeContext: _, ...actionParams } = params;
2337
+ const url = `/api/agent-builder/${this.actionId}/start-async${searchParams.toString() ? `?${searchParams.toString()}` : ""}`;
2338
+ const result = await this.request(url, {
2339
+ method: "POST",
2340
+ body: { ...actionParams, runtimeContext }
2341
+ });
2342
+ return this.transformWorkflowResult(result);
2343
+ }
2344
+ /**
2345
+ * Starts an existing agent builder action run.
2346
+ * This calls `/api/agent-builder/:actionId/start`.
2347
+ */
2348
+ async startActionRun(params, runId) {
2349
+ const searchParams = new URLSearchParams();
2350
+ searchParams.set("runId", runId);
2351
+ const runtimeContext = parseClientRuntimeContext(params.runtimeContext);
2352
+ const { runtimeContext: _, ...actionParams } = params;
2353
+ const url = `/api/agent-builder/${this.actionId}/start?${searchParams.toString()}`;
2354
+ return this.request(url, {
2355
+ method: "POST",
2356
+ body: { ...actionParams, runtimeContext }
2357
+ });
2358
+ }
2359
+ /**
2360
+ * Resumes a suspended agent builder action step.
2361
+ * This calls `/api/agent-builder/:actionId/resume`.
2362
+ */
2363
+ async resume(params, runId) {
2364
+ const searchParams = new URLSearchParams();
2365
+ searchParams.set("runId", runId);
2366
+ const runtimeContext = parseClientRuntimeContext(params.runtimeContext);
2367
+ const { runtimeContext: _, ...resumeParams } = params;
2368
+ const url = `/api/agent-builder/${this.actionId}/resume?${searchParams.toString()}`;
2369
+ return this.request(url, {
2370
+ method: "POST",
2371
+ body: { ...resumeParams, runtimeContext }
2372
+ });
2373
+ }
2374
+ /**
2375
+ * Resumes a suspended agent builder action step asynchronously.
2376
+ * This calls `/api/agent-builder/:actionId/resume-async`.
2377
+ */
2378
+ async resumeAsync(params, runId) {
2379
+ const searchParams = new URLSearchParams();
2380
+ searchParams.set("runId", runId);
2381
+ const runtimeContext = parseClientRuntimeContext(params.runtimeContext);
2382
+ const { runtimeContext: _, ...resumeParams } = params;
2383
+ const url = `/api/agent-builder/${this.actionId}/resume-async?${searchParams.toString()}`;
2384
+ const result = await this.request(url, {
2385
+ method: "POST",
2386
+ body: { ...resumeParams, runtimeContext }
2387
+ });
2388
+ return this.transformWorkflowResult(result);
2389
+ }
2390
+ /**
2391
+ * Creates an async generator that processes a readable stream and yields action records
2392
+ * separated by the Record Separator character (\x1E)
2393
+ *
2394
+ * @param stream - The readable stream to process
2395
+ * @returns An async generator that yields parsed records
2396
+ */
2397
+ async *streamProcessor(stream) {
2398
+ const reader = stream.getReader();
2399
+ let doneReading = false;
2400
+ let buffer = "";
2401
+ try {
2402
+ while (!doneReading) {
2403
+ const { done, value } = await reader.read();
2404
+ doneReading = done;
2405
+ if (done && !value) continue;
2406
+ try {
2407
+ const decoded = value ? new TextDecoder().decode(value) : "";
2408
+ const chunks = (buffer + decoded).split(RECORD_SEPARATOR3);
2409
+ buffer = chunks.pop() || "";
2410
+ for (const chunk of chunks) {
2411
+ if (chunk) {
2412
+ if (typeof chunk === "string") {
2413
+ try {
2414
+ const parsedChunk = JSON.parse(chunk);
2415
+ yield parsedChunk;
2416
+ } catch {
2417
+ }
2418
+ }
2419
+ }
2420
+ }
2421
+ } catch {
2422
+ }
2423
+ }
2424
+ if (buffer) {
2425
+ try {
2426
+ yield JSON.parse(buffer);
2427
+ } catch {
2428
+ }
2429
+ }
2430
+ } finally {
2431
+ reader.cancel().catch(() => {
2432
+ });
2433
+ }
2434
+ }
2435
+ /**
2436
+ * Streams agent builder action progress in real-time.
2437
+ * This calls `/api/agent-builder/:actionId/stream`.
2438
+ */
2439
+ async stream(params, runId) {
2440
+ const searchParams = new URLSearchParams();
2441
+ if (runId) {
2442
+ searchParams.set("runId", runId);
2443
+ }
2444
+ const runtimeContext = parseClientRuntimeContext(params.runtimeContext);
2445
+ const { runtimeContext: _, ...actionParams } = params;
2446
+ const url = `/api/agent-builder/${this.actionId}/stream${searchParams.toString() ? `?${searchParams.toString()}` : ""}`;
2447
+ const response = await this.request(url, {
2448
+ method: "POST",
2449
+ body: { ...actionParams, runtimeContext },
2450
+ stream: true
2451
+ });
2452
+ if (!response.ok) {
2453
+ throw new Error(`Failed to stream agent builder action: ${response.statusText}`);
2454
+ }
2455
+ if (!response.body) {
2456
+ throw new Error("Response body is null");
2457
+ }
2458
+ let failedChunk = void 0;
2459
+ const transformStream = new TransformStream({
2460
+ start() {
2461
+ },
2462
+ async transform(chunk, controller) {
2463
+ try {
2464
+ const decoded = new TextDecoder().decode(chunk);
2465
+ const chunks = decoded.split(RECORD_SEPARATOR3);
2466
+ for (const chunk2 of chunks) {
2467
+ if (chunk2) {
2468
+ const newChunk = failedChunk ? failedChunk + chunk2 : chunk2;
2469
+ try {
2470
+ const parsedChunk = JSON.parse(newChunk);
2471
+ controller.enqueue(parsedChunk);
2472
+ failedChunk = void 0;
2473
+ } catch {
2474
+ failedChunk = newChunk;
2475
+ }
2476
+ }
2477
+ }
2478
+ } catch {
2479
+ }
2480
+ }
2481
+ });
2482
+ return response.body.pipeThrough(transformStream);
2483
+ }
2484
+ /**
2485
+ * Streams agent builder action progress in real-time using VNext streaming.
2486
+ * This calls `/api/agent-builder/:actionId/streamVNext`.
2487
+ */
2488
+ async streamVNext(params, runId) {
2489
+ const searchParams = new URLSearchParams();
2490
+ if (runId) {
2491
+ searchParams.set("runId", runId);
2492
+ }
2493
+ const runtimeContext = parseClientRuntimeContext(params.runtimeContext);
2494
+ const { runtimeContext: _, ...actionParams } = params;
2495
+ const url = `/api/agent-builder/${this.actionId}/streamVNext${searchParams.toString() ? `?${searchParams.toString()}` : ""}`;
2496
+ const response = await this.request(url, {
2497
+ method: "POST",
2498
+ body: { ...actionParams, runtimeContext },
2499
+ stream: true
2500
+ });
2501
+ if (!response.ok) {
2502
+ throw new Error(`Failed to stream agent builder action VNext: ${response.statusText}`);
2503
+ }
2504
+ if (!response.body) {
2505
+ throw new Error("Response body is null");
2506
+ }
2507
+ let failedChunk = void 0;
2508
+ const transformStream = new TransformStream({
2509
+ start() {
2510
+ },
2511
+ async transform(chunk, controller) {
2512
+ try {
2513
+ const decoded = new TextDecoder().decode(chunk);
2514
+ const chunks = decoded.split(RECORD_SEPARATOR3);
2515
+ for (const chunk2 of chunks) {
2516
+ if (chunk2) {
2517
+ const newChunk = failedChunk ? failedChunk + chunk2 : chunk2;
2518
+ try {
2519
+ const parsedChunk = JSON.parse(newChunk);
2520
+ controller.enqueue(parsedChunk);
2521
+ failedChunk = void 0;
2522
+ } catch {
2523
+ failedChunk = newChunk;
2524
+ }
2525
+ }
2526
+ }
2527
+ } catch {
2528
+ }
2529
+ }
2530
+ });
2531
+ return response.body.pipeThrough(transformStream);
2532
+ }
2533
+ /**
2534
+ * Watches an existing agent builder action run by runId.
2535
+ * This is used for hot reload recovery - it loads the existing run state
2536
+ * and streams any remaining progress.
2537
+ * This calls `/api/agent-builder/:actionId/watch`.
2538
+ */
2539
+ async watch({ runId }, onRecord) {
2540
+ const url = `/api/agent-builder/${this.actionId}/watch?runId=${runId}`;
2541
+ const response = await this.request(url, {
2542
+ method: "GET",
2543
+ stream: true
2544
+ });
2545
+ if (!response.ok) {
2546
+ throw new Error(`Failed to watch agent builder action: ${response.statusText}`);
2547
+ }
2548
+ if (!response.body) {
2549
+ throw new Error("Response body is null");
2550
+ }
2551
+ for await (const record of this.streamProcessor(response.body)) {
2552
+ if (typeof record === "string") {
2553
+ onRecord(JSON.parse(record));
2554
+ } else {
2555
+ onRecord(record);
2556
+ }
2557
+ }
2558
+ }
2559
+ /**
2560
+ * Gets a specific action run by its ID.
2561
+ * This calls `/api/agent-builder/:actionId/runs/:runId`.
2562
+ */
2563
+ async runById(runId) {
2564
+ const url = `/api/agent-builder/${this.actionId}/runs/${runId}`;
2565
+ return this.request(url, {
2566
+ method: "GET"
2567
+ });
2568
+ }
2569
+ /**
2570
+ * Gets details about this agent builder action.
2571
+ * This calls `/api/agent-builder/:actionId`.
2572
+ */
2573
+ async details() {
2574
+ const result = await this.request(`/api/agent-builder/${this.actionId}`);
2575
+ return result;
2576
+ }
2577
+ /**
2578
+ * Gets all runs for this agent builder action.
2579
+ * This calls `/api/agent-builder/:actionId/runs`.
2580
+ */
2581
+ async runs(params) {
2582
+ const searchParams = new URLSearchParams();
2583
+ if (params?.fromDate) {
2584
+ searchParams.set("fromDate", params.fromDate.toISOString());
2585
+ }
2586
+ if (params?.toDate) {
2587
+ searchParams.set("toDate", params.toDate.toISOString());
2588
+ }
2589
+ if (params?.limit !== void 0) {
2590
+ searchParams.set("limit", String(params.limit));
2591
+ }
2592
+ if (params?.offset !== void 0) {
2593
+ searchParams.set("offset", String(params.offset));
2594
+ }
2595
+ if (params?.resourceId) {
2596
+ searchParams.set("resourceId", params.resourceId);
2597
+ }
2598
+ const url = `/api/agent-builder/${this.actionId}/runs${searchParams.toString() ? `?${searchParams.toString()}` : ""}`;
2599
+ return this.request(url, {
2600
+ method: "GET"
2601
+ });
2602
+ }
2603
+ /**
2604
+ * Gets the execution result of an agent builder action run.
2605
+ * This calls `/api/agent-builder/:actionId/runs/:runId/execution-result`.
2606
+ */
2607
+ async runExecutionResult(runId) {
2608
+ const url = `/api/agent-builder/${this.actionId}/runs/${runId}/execution-result`;
2609
+ return this.request(url, {
2610
+ method: "GET"
2611
+ });
2612
+ }
2613
+ /**
2614
+ * Cancels an agent builder action run.
2615
+ * This calls `/api/agent-builder/:actionId/runs/:runId/cancel`.
2616
+ */
2617
+ async cancelRun(runId) {
2618
+ const url = `/api/agent-builder/${this.actionId}/runs/${runId}/cancel`;
2619
+ return this.request(url, {
2620
+ method: "POST"
2621
+ });
2622
+ }
2623
+ /**
2624
+ * Sends an event to an agent builder action run.
2625
+ * This calls `/api/agent-builder/:actionId/runs/:runId/send-event`.
2626
+ */
2627
+ async sendRunEvent(params) {
2628
+ const url = `/api/agent-builder/${this.actionId}/runs/${params.runId}/send-event`;
2629
+ return this.request(url, {
2630
+ method: "POST",
2631
+ body: { event: params.event, data: params.data }
2632
+ });
2633
+ }
2634
+ };
2635
+
2256
2636
  // src/resources/observability.ts
2257
2637
  var Observability = class extends BaseResource {
2258
2638
  constructor(options) {
@@ -2364,7 +2744,7 @@ var NetworkMemoryThread = class extends BaseResource {
2364
2744
  };
2365
2745
 
2366
2746
  // src/resources/vNextNetwork.ts
2367
- var RECORD_SEPARATOR3 = "";
2747
+ var RECORD_SEPARATOR4 = "";
2368
2748
  var VNextNetwork = class extends BaseResource {
2369
2749
  constructor(options, networkId) {
2370
2750
  super(options);
@@ -2416,7 +2796,7 @@ var VNextNetwork = class extends BaseResource {
2416
2796
  if (done && !value) continue;
2417
2797
  try {
2418
2798
  const decoded = value ? new TextDecoder().decode(value) : "";
2419
- const chunks = (buffer + decoded).split(RECORD_SEPARATOR3);
2799
+ const chunks = (buffer + decoded).split(RECORD_SEPARATOR4);
2420
2800
  buffer = chunks.pop() || "";
2421
2801
  for (const chunk of chunks) {
2422
2802
  if (chunk) {
@@ -2667,6 +3047,20 @@ var MastraClient = class extends BaseResource {
2667
3047
  getWorkflow(workflowId) {
2668
3048
  return new Workflow(this.options, workflowId);
2669
3049
  }
3050
+ /**
3051
+ * Gets all available agent builder actions
3052
+ * @returns Promise containing map of action IDs to action details
3053
+ */
3054
+ getAgentBuilderActions() {
3055
+ return this.request("/api/agent-builder/");
3056
+ }
3057
+ /**
3058
+ * Gets an agent builder instance for executing agent-builder workflows
3059
+ * @returns AgentBuilder instance
3060
+ */
3061
+ getAgentBuilderAction(actionId) {
3062
+ return new AgentBuilder(this.options, actionId);
3063
+ }
2670
3064
  /**
2671
3065
  * Gets a vector instance by name
2672
3066
  * @param vectorName - Name of the vector to retrieve