@mastra/client-js 0.0.0-default-storage-virtual-file-20250410035748 → 0.0.0-expose-more-playground-ui-20250502050852

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mastra/client-js",
3
- "version": "0.0.0-default-storage-virtual-file-20250410035748",
3
+ "version": "0.0.0-expose-more-playground-ui-20250502050852",
4
4
  "description": "The official TypeScript library for the Mastra Client API",
5
5
  "author": "",
6
6
  "type": "module",
@@ -20,13 +20,16 @@
20
20
  "./package.json": "./package.json"
21
21
  },
22
22
  "repository": "github:mastra-ai/client-js",
23
- "license": "ISC",
23
+ "license": "Elastic-2.0",
24
24
  "dependencies": {
25
25
  "@ai-sdk/ui-utils": "^1.1.19",
26
26
  "json-schema": "^0.4.0",
27
27
  "zod": "^3.24.2",
28
28
  "zod-to-json-schema": "^3.24.3",
29
- "@mastra/core": "0.0.0-default-storage-virtual-file-20250410035748"
29
+ "@mastra/core": "0.0.0-expose-more-playground-ui-20250502050852"
30
+ },
31
+ "peerDependencies": {
32
+ "zod": "^3.24.2"
30
33
  },
31
34
  "devDependencies": {
32
35
  "@babel/preset-env": "^7.26.9",
@@ -36,8 +39,8 @@
36
39
  "@types/node": "^20.17.27",
37
40
  "tsup": "^8.4.0",
38
41
  "typescript": "^5.8.2",
39
- "vitest": "^3.0.9",
40
- "@internal/lint": "0.0.1"
42
+ "vitest": "^3.1.2",
43
+ "@internal/lint": "0.0.2"
41
44
  },
42
45
  "scripts": {
43
46
  "build": "tsup src/index.ts --format esm,cjs --dts --clean --treeshake=smallest --splitting",
package/src/client.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { Agent, MemoryThread, Tool, Workflow, Vector, BaseResource, Network } from './resources';
1
+ import { Agent, MemoryThread, Tool, Workflow, Vector, BaseResource, Network, VNextWorkflow } from './resources';
2
2
  import type {
3
3
  ClientOptions,
4
4
  CreateMemoryThreadParams,
@@ -13,8 +13,8 @@ import type {
13
13
  GetTelemetryParams,
14
14
  GetTelemetryResponse,
15
15
  GetToolResponse,
16
+ GetVNextWorkflowResponse,
16
17
  GetWorkflowResponse,
17
- RequestOptions,
18
18
  SaveMessageToMemoryParams,
19
19
  SaveMessageToMemoryResponse,
20
20
  } from './types';
@@ -122,6 +122,23 @@ export class MastraClient extends BaseResource {
122
122
  return new Workflow(this.options, workflowId);
123
123
  }
124
124
 
125
+ /**
126
+ * Retrieves all available vNext workflows
127
+ * @returns Promise containing map of vNext workflow IDs to vNext workflow details
128
+ */
129
+ public getVNextWorkflows(): Promise<Record<string, GetVNextWorkflowResponse>> {
130
+ return this.request('/api/workflows/v-next');
131
+ }
132
+
133
+ /**
134
+ * Gets a vNext workflow instance by ID
135
+ * @param workflowId - ID of the vNext workflow to retrieve
136
+ * @returns vNext Workflow instance
137
+ */
138
+ public getVNextWorkflow(workflowId: string) {
139
+ return new VNextWorkflow(this.options, workflowId);
140
+ }
141
+
125
142
  /**
126
143
  * Gets a vector instance by name
127
144
  * @param vectorName - Name of the vector to retrieve
@@ -166,14 +183,6 @@ export class MastraClient extends BaseResource {
166
183
  const { name, scope, page, perPage, attribute } = params || {};
167
184
  const _attribute = attribute ? Object.entries(attribute).map(([key, value]) => `${key}:${value}`) : [];
168
185
 
169
- const queryObj = {
170
- ...(name ? { name } : {}),
171
- ...(scope ? { scope } : {}),
172
- ...(page ? { page: String(page) } : {}),
173
- ...(perPage ? { perPage: String(perPage) } : {}),
174
- ...(_attribute?.length ? { attribute: _attribute } : {}),
175
- } as const;
176
-
177
186
  const searchParams = new URLSearchParams();
178
187
  if (name) {
179
188
  searchParams.set('name', name);
package/src/index.test.ts CHANGED
@@ -1,4 +1,3 @@
1
- import type { MessageType } from '@mastra/core';
2
1
  import { describe, expect, beforeEach, it, vi } from 'vitest';
3
2
 
4
3
  import { MastraClient } from './client';
@@ -489,7 +488,7 @@ describe('MastraClient Resources', () => {
489
488
  const result = await memoryThread.update({
490
489
  title: 'Updated Thread',
491
490
  metadata: { updated: true },
492
- resourceid: 'test-resource',
491
+ resourceId: 'test-resource',
493
492
  });
494
493
  expect(result).toEqual(mockResponse);
495
494
  expect(global.fetch).toHaveBeenCalledWith(
@@ -536,6 +535,7 @@ describe('MastraClient Resources', () => {
536
535
  content: 'test',
537
536
  role: 'user' as const,
538
537
  threadId: 'test-thread',
538
+ resourceId: 'test-resource',
539
539
  createdAt: new Date('2025-03-26T10:40:55.116Z'),
540
540
  },
541
541
  ];
@@ -584,10 +584,10 @@ describe('MastraClient Resources', () => {
584
584
  it('should execute tool', async () => {
585
585
  const mockResponse = { data: 'test' };
586
586
  mockFetchResponse(mockResponse);
587
- const result = await tool.execute({ data: '' });
587
+ const result = await tool.execute({ data: '', runId: 'test-run-id' });
588
588
  expect(result).toEqual(mockResponse);
589
589
  expect(global.fetch).toHaveBeenCalledWith(
590
- `${clientOptions.baseUrl}/api/tools/test-tool/execute`,
590
+ `${clientOptions.baseUrl}/api/tools/test-tool/execute?runId=test-run-id`,
591
591
  expect.objectContaining({
592
592
  method: 'POST',
593
593
  headers: expect.objectContaining({
@@ -1,8 +1,8 @@
1
+ import { processDataStream } from '@ai-sdk/ui-utils';
1
2
  import type { GenerateReturn } from '@mastra/core';
2
3
  import type { JSONSchema7 } from 'json-schema';
3
4
  import { ZodSchema } from 'zod';
4
5
  import { zodToJsonSchema } from 'zod-to-json-schema';
5
- import { processDataStream } from '@ai-sdk/ui-utils';
6
6
 
7
7
  import type {
8
8
  GenerateParams,
@@ -29,7 +29,6 @@ export class AgentTool extends BaseResource {
29
29
  * @param params - Parameters required for tool execution
30
30
  * @returns Promise containing tool execution results
31
31
  */
32
- /** @deprecated use CreateRun/startRun */
33
32
  execute(params: { data: any }): Promise<any> {
34
33
  return this.request(`/api/agents/${this.agentId}/tools/${this.toolId}/execute`, {
35
34
  method: 'POST',
@@ -1,4 +1,4 @@
1
- import type { RequestFunction, RequestOptions, ClientOptions } from '../types';
1
+ import type { RequestOptions, ClientOptions } from '../types';
2
2
 
3
3
  export class BaseResource {
4
4
  readonly options: ClientOptions;
@@ -5,3 +5,4 @@ export * from './vector';
5
5
  export * from './workflow';
6
6
  export * from './tool';
7
7
  export * from './base';
8
+ export * from './vnext-workflow';
@@ -1,13 +1,6 @@
1
1
  import type { StorageThreadType } from '@mastra/core';
2
2
 
3
- import type {
4
- CreateMemoryThreadParams,
5
- GetMemoryThreadMessagesResponse,
6
- GetMemoryThreadResponse,
7
- ClientOptions,
8
- SaveMessageToMemoryParams,
9
- UpdateMemoryThreadParams,
10
- } from '../types';
3
+ import type { GetMemoryThreadMessagesResponse, ClientOptions, UpdateMemoryThreadParams } from '../types';
11
4
 
12
5
  import { BaseResource } from './base';
13
6
 
@@ -1,3 +1,4 @@
1
+ import { processDataStream } from '@ai-sdk/ui-utils';
1
2
  import type { GenerateReturn } from '@mastra/core';
2
3
  import type { JSONSchema7 } from 'json-schema';
3
4
  import { ZodSchema } from 'zod';
@@ -6,7 +7,6 @@ import { zodToJsonSchema } from 'zod-to-json-schema';
6
7
  import type { GenerateParams, ClientOptions, StreamParams, GetNetworkResponse } from '../types';
7
8
 
8
9
  import { BaseResource } from './base';
9
- import { processDataStream } from '@ai-sdk/ui-utils';
10
10
 
11
11
  export class Network extends BaseResource {
12
12
  constructor(
@@ -23,10 +23,16 @@ export class Tool extends BaseResource {
23
23
  * @param params - Parameters required for tool execution
24
24
  * @returns Promise containing the tool execution results
25
25
  */
26
- execute(params: { data: any }): Promise<any> {
27
- return this.request(`/api/tools/${this.toolId}/execute`, {
26
+ execute(params: { data: any; runId?: string }): Promise<any> {
27
+ const url = new URLSearchParams();
28
+
29
+ if (params.runId) {
30
+ url.set('runId', params.runId);
31
+ }
32
+
33
+ return this.request(`/api/tools/${this.toolId}/execute?${url.toString()}`, {
28
34
  method: 'POST',
29
- body: params,
35
+ body: params.data,
30
36
  });
31
37
  }
32
38
  }
@@ -0,0 +1,234 @@
1
+ import type { RuntimeContext } from '@mastra/core/runtime-context';
2
+ import type {
3
+ ClientOptions,
4
+ GetVNextWorkflowResponse,
5
+ GetWorkflowRunsResponse,
6
+ VNextWorkflowRunResult,
7
+ VNextWorkflowWatchResult,
8
+ } from '../types';
9
+
10
+ import { BaseResource } from './base';
11
+
12
+ const RECORD_SEPARATOR = '\x1E';
13
+
14
+ export class VNextWorkflow extends BaseResource {
15
+ constructor(
16
+ options: ClientOptions,
17
+ private workflowId: string,
18
+ ) {
19
+ super(options);
20
+ }
21
+
22
+ /**
23
+ * Creates an async generator that processes a readable stream and yields vNext workflow records
24
+ * separated by the Record Separator character (\x1E)
25
+ *
26
+ * @param stream - The readable stream to process
27
+ * @returns An async generator that yields parsed records
28
+ */
29
+ private async *streamProcessor(stream: ReadableStream): AsyncGenerator<VNextWorkflowWatchResult, void, unknown> {
30
+ const reader = stream.getReader();
31
+
32
+ // Track if we've finished reading from the stream
33
+ let doneReading = false;
34
+ // Buffer to accumulate partial chunks
35
+ let buffer = '';
36
+
37
+ try {
38
+ while (!doneReading) {
39
+ // Read the next chunk from the stream
40
+ const { done, value } = await reader.read();
41
+ doneReading = done;
42
+
43
+ // Skip processing if we're done and there's no value
44
+ if (done && !value) continue;
45
+
46
+ try {
47
+ // Decode binary data to text
48
+ const decoded = value ? new TextDecoder().decode(value) : '';
49
+
50
+ // Split the combined buffer and new data by record separator
51
+ const chunks = (buffer + decoded).split(RECORD_SEPARATOR);
52
+
53
+ // The last chunk might be incomplete, so save it for the next iteration
54
+ buffer = chunks.pop() || '';
55
+
56
+ // Process complete chunks
57
+ for (const chunk of chunks) {
58
+ if (chunk) {
59
+ // Only process non-empty chunks
60
+ if (typeof chunk === 'string') {
61
+ try {
62
+ const parsedChunk = JSON.parse(chunk);
63
+ yield parsedChunk;
64
+ } catch {
65
+ // Silently ignore parsing errors to maintain stream processing
66
+ // This allows the stream to continue even if one record is malformed
67
+ }
68
+ }
69
+ }
70
+ }
71
+ } catch {
72
+ // Silently ignore parsing errors to maintain stream processing
73
+ // This allows the stream to continue even if one record is malformed
74
+ }
75
+ }
76
+
77
+ // Process any remaining data in the buffer after stream is done
78
+ if (buffer) {
79
+ try {
80
+ yield JSON.parse(buffer);
81
+ } catch {
82
+ // Ignore parsing error for final chunk
83
+ }
84
+ }
85
+ } finally {
86
+ // Always ensure we clean up the reader
87
+ reader.cancel().catch(() => {
88
+ // Ignore cancel errors
89
+ });
90
+ }
91
+ }
92
+
93
+ /**
94
+ * Retrieves details about the vNext workflow
95
+ * @returns Promise containing vNext workflow details including steps and graphs
96
+ */
97
+ details(): Promise<GetVNextWorkflowResponse> {
98
+ return this.request(`/api/workflows/v-next/${this.workflowId}`);
99
+ }
100
+
101
+ /**
102
+ * Retrieves all runs for a vNext workflow
103
+ * @returns Promise containing vNext workflow runs array
104
+ */
105
+ runs(): Promise<GetWorkflowRunsResponse> {
106
+ return this.request(`/api/workflows/v-next/${this.workflowId}/runs`);
107
+ }
108
+
109
+ /**
110
+ * Creates a new vNext workflow run
111
+ * @param params - Optional object containing the optional runId
112
+ * @returns Promise containing the runId of the created run
113
+ */
114
+ createRun(params?: { runId?: string }): Promise<{ runId: string }> {
115
+ const searchParams = new URLSearchParams();
116
+
117
+ if (!!params?.runId) {
118
+ searchParams.set('runId', params.runId);
119
+ }
120
+
121
+ return this.request(`/api/workflows/v-next/${this.workflowId}/create-run?${searchParams.toString()}`, {
122
+ method: 'POST',
123
+ });
124
+ }
125
+
126
+ /**
127
+ * Starts a vNext workflow run synchronously without waiting for the workflow to complete
128
+ * @param params - Object containing the runId, inputData and runtimeContext
129
+ * @returns Promise containing success message
130
+ */
131
+ start(params: {
132
+ runId: string;
133
+ inputData: Record<string, any>;
134
+ runtimeContext?: RuntimeContext;
135
+ }): Promise<{ message: string }> {
136
+ return this.request(`/api/workflows/v-next/${this.workflowId}/start?runId=${params.runId}`, {
137
+ method: 'POST',
138
+ body: { inputData: params?.inputData, runtimeContext: params.runtimeContext },
139
+ });
140
+ }
141
+
142
+ /**
143
+ * Resumes a suspended vNext workflow step synchronously without waiting for the vNext workflow to complete
144
+ * @param params - Object containing the runId, step, resumeData and runtimeContext
145
+ * @returns Promise containing success message
146
+ */
147
+ resume({
148
+ step,
149
+ runId,
150
+ resumeData,
151
+ runtimeContext,
152
+ }: {
153
+ step: string | string[];
154
+ runId: string;
155
+ resumeData?: Record<string, any>;
156
+ runtimeContext?: RuntimeContext;
157
+ }): Promise<{ message: string }> {
158
+ return this.request(`/api/workflows/v-next/${this.workflowId}/resume?runId=${runId}`, {
159
+ method: 'POST',
160
+ stream: true,
161
+ body: {
162
+ step,
163
+ resumeData,
164
+ runtimeContext,
165
+ },
166
+ });
167
+ }
168
+
169
+ /**
170
+ * Starts a vNext workflow run asynchronously and returns a promise that resolves when the vNext workflow is complete
171
+ * @param params - Object containing the optional runId, inputData and runtimeContext
172
+ * @returns Promise containing the vNext workflow execution results
173
+ */
174
+ startAsync(params: {
175
+ runId?: string;
176
+ inputData: Record<string, any>;
177
+ runtimeContext?: RuntimeContext;
178
+ }): Promise<VNextWorkflowRunResult> {
179
+ const searchParams = new URLSearchParams();
180
+
181
+ if (!!params?.runId) {
182
+ searchParams.set('runId', params.runId);
183
+ }
184
+
185
+ return this.request(`/api/workflows/v-next/${this.workflowId}/start-async?${searchParams.toString()}`, {
186
+ method: 'POST',
187
+ body: { inputData: params.inputData, runtimeContext: params.runtimeContext },
188
+ });
189
+ }
190
+
191
+ /**
192
+ * Resumes a suspended vNext workflow step asynchronously and returns a promise that resolves when the vNext workflow is complete
193
+ * @param params - Object containing the runId, step, resumeData and runtimeContext
194
+ * @returns Promise containing the vNext workflow resume results
195
+ */
196
+ resumeAsync(params: {
197
+ runId: string;
198
+ step: string | string[];
199
+ resumeData?: Record<string, any>;
200
+ runtimeContext?: RuntimeContext;
201
+ }): Promise<VNextWorkflowRunResult> {
202
+ return this.request(`/api/workflows/v-next/${this.workflowId}/resume-async?runId=${params.runId}`, {
203
+ method: 'POST',
204
+ body: {
205
+ step: params.step,
206
+ resumeData: params.resumeData,
207
+ runtimeContext: params.runtimeContext,
208
+ },
209
+ });
210
+ }
211
+
212
+ /**
213
+ * Watches vNext workflow transitions in real-time
214
+ * @param runId - Optional run ID to filter the watch stream
215
+ * @returns AsyncGenerator that yields parsed records from the vNext workflow watch stream
216
+ */
217
+ async watch({ runId }: { runId?: string }, onRecord: (record: VNextWorkflowWatchResult) => void) {
218
+ const response: Response = await this.request(`/api/workflows/v-next/${this.workflowId}/watch?runId=${runId}`, {
219
+ stream: true,
220
+ });
221
+
222
+ if (!response.ok) {
223
+ throw new Error(`Failed to watch vNext workflow: ${response.statusText}`);
224
+ }
225
+
226
+ if (!response.body) {
227
+ throw new Error('Response body is null');
228
+ }
229
+
230
+ for await (const record of this.streamProcessor(response.body)) {
231
+ onRecord(record);
232
+ }
233
+ }
234
+ }
@@ -1,4 +1,4 @@
1
- import type { GetWorkflowResponse, ClientOptions, WorkflowRunResult } from '../types';
1
+ import type { GetWorkflowResponse, ClientOptions, WorkflowRunResult, GetWorkflowRunsResponse } from '../types';
2
2
 
3
3
  import { BaseResource } from './base';
4
4
 
@@ -20,6 +20,14 @@ export class Workflow extends BaseResource {
20
20
  return this.request(`/api/workflows/${this.workflowId}`);
21
21
  }
22
22
 
23
+ /**
24
+ * Retrieves all runs for a workflow
25
+ * @returns Promise containing workflow runs array
26
+ */
27
+ runs(): Promise<GetWorkflowRunsResponse> {
28
+ return this.request(`/api/workflows/${this.workflowId}/runs`);
29
+ }
30
+
23
31
  /**
24
32
  * @deprecated Use `startAsync` instead
25
33
  * Executes the workflow with the provided parameters
@@ -168,7 +176,7 @@ export class Workflow extends BaseResource {
168
176
  }
169
177
  }
170
178
  }
171
- } catch (error) {
179
+ } catch {
172
180
  // Silently ignore parsing errors to maintain stream processing
173
181
  // This allows the stream to continue even if one record is malformed
174
182
  }
package/src/types.ts CHANGED
@@ -8,9 +8,11 @@ import type {
8
8
  StorageThreadType,
9
9
  BaseLogMessage,
10
10
  WorkflowRunResult as CoreWorkflowRunResult,
11
+ WorkflowRuns,
11
12
  } from '@mastra/core';
12
13
 
13
14
  import type { AgentGenerateOptions, AgentStreamOptions } from '@mastra/core/agent';
15
+ import type { NewWorkflow, WatchEvent, WorkflowResult as VNextWorkflowResult } from '@mastra/core/workflows/vNext';
14
16
  import type { JSONSchema7 } from 'json-schema';
15
17
  import type { ZodSchema } from 'zod';
16
18
 
@@ -54,6 +56,9 @@ export type StreamParams<T extends JSONSchema7 | ZodSchema | undefined = undefin
54
56
 
55
57
  export interface GetEvalsByAgentIdResponse extends GetAgentResponse {
56
58
  evals: any[];
59
+ instructions: string;
60
+ name: string;
61
+ id: string;
57
62
  }
58
63
 
59
64
  export interface GetToolResponse {
@@ -72,12 +77,35 @@ export interface GetWorkflowResponse {
72
77
  workflowId?: string;
73
78
  }
74
79
 
80
+ export type GetWorkflowRunsResponse = WorkflowRuns;
81
+
75
82
  export type WorkflowRunResult = {
76
83
  activePaths: Record<string, { status: string; suspendPayload?: any; stepPath: string[] }>;
77
84
  results: CoreWorkflowRunResult<any, any, any>['results'];
78
85
  timestamp: number;
79
86
  runId: string;
80
87
  };
88
+
89
+ export interface GetVNextWorkflowResponse {
90
+ name: string;
91
+ steps: {
92
+ [key: string]: {
93
+ id: string;
94
+ description: string;
95
+ inputSchema: string;
96
+ outputSchema: string;
97
+ resumeSchema: string;
98
+ suspendSchema: string;
99
+ };
100
+ };
101
+ stepGraph: NewWorkflow['serializedStepGraph'];
102
+ inputSchema: string;
103
+ outputSchema: string;
104
+ }
105
+
106
+ export type VNextWorkflowWatchResult = WatchEvent & { runId: string };
107
+
108
+ export type VNextWorkflowRunResult = VNextWorkflowResult<any, any>;
81
109
  export interface UpsertVectorParams {
82
110
  indexName: string;
83
111
  vectors: number[][];
@@ -118,7 +146,7 @@ export type SaveMessageToMemoryResponse = MessageType[];
118
146
  export interface CreateMemoryThreadParams {
119
147
  title: string;
120
148
  metadata: Record<string, any>;
121
- resourceid: string;
149
+ resourceId: string;
122
150
  threadId: string;
123
151
  agentId: string;
124
152
  }
@@ -135,7 +163,7 @@ export type GetMemoryThreadResponse = StorageThreadType[];
135
163
  export interface UpdateMemoryThreadParams {
136
164
  title: string;
137
165
  metadata: Record<string, any>;
138
- resourceid: string;
166
+ resourceId: string;
139
167
  }
140
168
 
141
169
  export interface GetMemoryThreadMessagesResponse {
@@ -197,7 +225,7 @@ type Span = {
197
225
  };
198
226
 
199
227
  export interface GetTelemetryResponse {
200
- traces: { traces: Span[] };
228
+ traces: Span[];
201
229
  }
202
230
 
203
231
  export interface GetTelemetryParams {