@mastra/client-js 0.0.0-message-ordering-20250415215612 → 0.0.0-message-list-update-20250715150321

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/src/types.ts CHANGED
@@ -1,16 +1,24 @@
1
1
  import type {
2
- MessageType,
2
+ MastraMessageV1,
3
3
  AiMessageType,
4
4
  CoreMessage,
5
5
  QueryResult,
6
- StepAction,
7
- StepGraph,
8
6
  StorageThreadType,
9
- BaseLogMessage,
10
- WorkflowRunResult as CoreWorkflowRunResult,
7
+ WorkflowRuns,
8
+ WorkflowRun,
9
+ LegacyWorkflowRuns,
11
10
  } from '@mastra/core';
11
+ import type { AgentGenerateOptions, AgentStreamOptions, ToolsInput } from '@mastra/core/agent';
12
+ import type { BaseLogMessage, LogLevel } from '@mastra/core/logger';
12
13
 
13
- import type { AgentGenerateOptions, AgentStreamOptions } from '@mastra/core/agent';
14
+ import type { MCPToolType, ServerInfo } from '@mastra/core/mcp';
15
+ import type { RuntimeContext } from '@mastra/core/runtime-context';
16
+ import type { Workflow, WatchEvent, WorkflowResult } from '@mastra/core/workflows';
17
+ import type {
18
+ StepAction,
19
+ StepGraph,
20
+ LegacyWorkflowRunResult as CoreLegacyWorkflowRunResult,
21
+ } from '@mastra/core/workflows/legacy';
14
22
  import type { JSONSchema7 } from 'json-schema';
15
23
  import type { ZodSchema } from 'zod';
16
24
 
@@ -26,6 +34,7 @@ export interface ClientOptions {
26
34
  /** Custom headers to include with requests */
27
35
  headers?: Record<string, string>;
28
36
  /** Abort signal for request */
37
+ abortSignal?: AbortSignal;
29
38
  }
30
39
 
31
40
  export interface RequestOptions {
@@ -33,27 +42,54 @@ export interface RequestOptions {
33
42
  headers?: Record<string, string>;
34
43
  body?: any;
35
44
  stream?: boolean;
36
- signal?: AbortSignal;
37
45
  }
38
46
 
47
+ type WithoutMethods<T> = {
48
+ [K in keyof T as T[K] extends (...args: any[]) => any
49
+ ? never
50
+ : T[K] extends { (): any }
51
+ ? never
52
+ : T[K] extends undefined | ((...args: any[]) => any)
53
+ ? never
54
+ : K]: T[K];
55
+ };
56
+
39
57
  export interface GetAgentResponse {
40
58
  name: string;
41
59
  instructions: string;
42
60
  tools: Record<string, GetToolResponse>;
61
+ workflows: Record<string, GetWorkflowResponse>;
43
62
  provider: string;
44
63
  modelId: string;
64
+ defaultGenerateOptions: WithoutMethods<AgentGenerateOptions>;
65
+ defaultStreamOptions: WithoutMethods<AgentStreamOptions>;
45
66
  }
46
67
 
47
68
  export type GenerateParams<T extends JSONSchema7 | ZodSchema | undefined = undefined> = {
48
69
  messages: string | string[] | CoreMessage[] | AiMessageType[];
49
- } & Partial<AgentGenerateOptions<T>>;
70
+ output?: T;
71
+ experimental_output?: T;
72
+ runtimeContext?: RuntimeContext | Record<string, any>;
73
+ clientTools?: ToolsInput;
74
+ } & WithoutMethods<
75
+ Omit<AgentGenerateOptions<T>, 'output' | 'experimental_output' | 'runtimeContext' | 'clientTools' | 'abortSignal'>
76
+ >;
50
77
 
51
78
  export type StreamParams<T extends JSONSchema7 | ZodSchema | undefined = undefined> = {
52
79
  messages: string | string[] | CoreMessage[] | AiMessageType[];
53
- } & Omit<AgentStreamOptions<T>, 'onFinish' | 'onStepFinish' | 'telemetry'>;
80
+ output?: T;
81
+ experimental_output?: T;
82
+ runtimeContext?: RuntimeContext | Record<string, any>;
83
+ clientTools?: ToolsInput;
84
+ } & WithoutMethods<
85
+ Omit<AgentStreamOptions<T>, 'output' | 'experimental_output' | 'runtimeContext' | 'clientTools' | 'abortSignal'>
86
+ >;
54
87
 
55
88
  export interface GetEvalsByAgentIdResponse extends GetAgentResponse {
56
89
  evals: any[];
90
+ instructions: string;
91
+ name: string;
92
+ id: string;
57
93
  }
58
94
 
59
95
  export interface GetToolResponse {
@@ -63,7 +99,7 @@ export interface GetToolResponse {
63
99
  outputSchema: string;
64
100
  }
65
101
 
66
- export interface GetWorkflowResponse {
102
+ export interface GetLegacyWorkflowResponse {
67
103
  name: string;
68
104
  triggerSchema: string;
69
105
  steps: Record<string, StepAction<any, any, any, any>>;
@@ -72,12 +108,61 @@ export interface GetWorkflowResponse {
72
108
  workflowId?: string;
73
109
  }
74
110
 
75
- export type WorkflowRunResult = {
111
+ export interface GetWorkflowRunsParams {
112
+ fromDate?: Date;
113
+ toDate?: Date;
114
+ limit?: number;
115
+ offset?: number;
116
+ resourceId?: string;
117
+ }
118
+
119
+ export type GetLegacyWorkflowRunsResponse = LegacyWorkflowRuns;
120
+
121
+ export type GetWorkflowRunsResponse = WorkflowRuns;
122
+
123
+ export type GetWorkflowRunByIdResponse = WorkflowRun;
124
+
125
+ export type GetWorkflowRunExecutionResultResponse = WatchEvent['payload']['workflowState'];
126
+
127
+ export type LegacyWorkflowRunResult = {
76
128
  activePaths: Record<string, { status: string; suspendPayload?: any; stepPath: string[] }>;
77
- results: CoreWorkflowRunResult<any, any, any>['results'];
129
+ results: CoreLegacyWorkflowRunResult<any, any, any>['results'];
78
130
  timestamp: number;
79
131
  runId: string;
80
132
  };
133
+
134
+ export interface GetWorkflowResponse {
135
+ name: string;
136
+ description?: string;
137
+ steps: {
138
+ [key: string]: {
139
+ id: string;
140
+ description: string;
141
+ inputSchema: string;
142
+ outputSchema: string;
143
+ resumeSchema: string;
144
+ suspendSchema: string;
145
+ };
146
+ };
147
+ allSteps: {
148
+ [key: string]: {
149
+ id: string;
150
+ description: string;
151
+ inputSchema: string;
152
+ outputSchema: string;
153
+ resumeSchema: string;
154
+ suspendSchema: string;
155
+ isWorkflow: boolean;
156
+ };
157
+ };
158
+ stepGraph: Workflow['serializedStepGraph'];
159
+ inputSchema: string;
160
+ outputSchema: string;
161
+ }
162
+
163
+ export type WorkflowWatchResult = WatchEvent & { runId: string };
164
+
165
+ export type WorkflowRunResult = WorkflowResult<any, any>;
81
166
  export interface UpsertVectorParams {
82
167
  indexName: string;
83
168
  vectors: number[][];
@@ -109,20 +194,33 @@ export interface GetVectorIndexResponse {
109
194
  }
110
195
 
111
196
  export interface SaveMessageToMemoryParams {
112
- messages: MessageType[];
197
+ messages: MastraMessageV1[];
113
198
  agentId: string;
114
199
  }
115
200
 
116
- export type SaveMessageToMemoryResponse = MessageType[];
201
+ export interface SaveNetworkMessageToMemoryParams {
202
+ messages: MastraMessageV1[];
203
+ networkId: string;
204
+ }
205
+
206
+ export type SaveMessageToMemoryResponse = MastraMessageV1[];
117
207
 
118
208
  export interface CreateMemoryThreadParams {
119
- title: string;
120
- metadata: Record<string, any>;
121
- resourceid: string;
122
- threadId: string;
209
+ title?: string;
210
+ metadata?: Record<string, any>;
211
+ resourceId: string;
212
+ threadId?: string;
123
213
  agentId: string;
124
214
  }
125
215
 
216
+ export interface CreateNetworkMemoryThreadParams {
217
+ title?: string;
218
+ metadata?: Record<string, any>;
219
+ resourceId: string;
220
+ threadId?: string;
221
+ networkId: string;
222
+ }
223
+
126
224
  export type CreateMemoryThreadResponse = StorageThreadType;
127
225
 
128
226
  export interface GetMemoryThreadParams {
@@ -130,12 +228,24 @@ export interface GetMemoryThreadParams {
130
228
  agentId: string;
131
229
  }
132
230
 
231
+ export interface GetNetworkMemoryThreadParams {
232
+ resourceId: string;
233
+ networkId: string;
234
+ }
235
+
133
236
  export type GetMemoryThreadResponse = StorageThreadType[];
134
237
 
135
238
  export interface UpdateMemoryThreadParams {
136
239
  title: string;
137
240
  metadata: Record<string, any>;
138
- resourceid: string;
241
+ resourceId: string;
242
+ }
243
+
244
+ export interface GetMemoryThreadMessagesParams {
245
+ /**
246
+ * Limit the number of messages to retrieve (default: 40)
247
+ */
248
+ limit?: number;
139
249
  }
140
250
 
141
251
  export interface GetMemoryThreadMessagesResponse {
@@ -145,14 +255,32 @@ export interface GetMemoryThreadMessagesResponse {
145
255
 
146
256
  export interface GetLogsParams {
147
257
  transportId: string;
258
+ fromDate?: Date;
259
+ toDate?: Date;
260
+ logLevel?: LogLevel;
261
+ filters?: Record<string, string>;
262
+ page?: number;
263
+ perPage?: number;
148
264
  }
149
265
 
150
266
  export interface GetLogParams {
151
267
  runId: string;
152
268
  transportId: string;
269
+ fromDate?: Date;
270
+ toDate?: Date;
271
+ logLevel?: LogLevel;
272
+ filters?: Record<string, string>;
273
+ page?: number;
274
+ perPage?: number;
153
275
  }
154
276
 
155
- export type GetLogsResponse = BaseLogMessage[];
277
+ export type GetLogsResponse = {
278
+ logs: BaseLogMessage[];
279
+ total: number;
280
+ page: number;
281
+ perPage: number;
282
+ hasMore: boolean;
283
+ };
156
284
 
157
285
  export type RequestFunction = (path: string, options?: RequestOptions) => Promise<any>;
158
286
 
@@ -206,9 +334,12 @@ export interface GetTelemetryParams {
206
334
  page?: number;
207
335
  perPage?: number;
208
336
  attribute?: Record<string, string>;
337
+ fromDate?: Date;
338
+ toDate?: Date;
209
339
  }
210
340
 
211
341
  export interface GetNetworkResponse {
342
+ id: string;
212
343
  name: string;
213
344
  instructions: string;
214
345
  agents: Array<{
@@ -222,3 +353,76 @@ export interface GetNetworkResponse {
222
353
  };
223
354
  state?: Record<string, any>;
224
355
  }
356
+
357
+ export interface GetVNextNetworkResponse {
358
+ id: string;
359
+ name: string;
360
+ instructions: string;
361
+ agents: Array<{
362
+ name: string;
363
+ provider: string;
364
+ modelId: string;
365
+ }>;
366
+ routingModel: {
367
+ provider: string;
368
+ modelId: string;
369
+ };
370
+ workflows: Array<{
371
+ name: string;
372
+ description: string;
373
+ inputSchema: string | undefined;
374
+ outputSchema: string | undefined;
375
+ }>;
376
+ tools: Array<{
377
+ id: string;
378
+ description: string;
379
+ }>;
380
+ }
381
+
382
+ export interface GenerateVNextNetworkResponse {
383
+ task: string;
384
+ result: string;
385
+ resourceId: string;
386
+ resourceType: 'none' | 'tool' | 'agent' | 'workflow';
387
+ }
388
+
389
+ export interface GenerateOrStreamVNextNetworkParams {
390
+ message: string;
391
+ threadId?: string;
392
+ resourceId?: string;
393
+ runtimeContext?: RuntimeContext | Record<string, any>;
394
+ }
395
+
396
+ export interface LoopStreamVNextNetworkParams {
397
+ message: string;
398
+ threadId?: string;
399
+ resourceId?: string;
400
+ maxIterations?: number;
401
+ runtimeContext?: RuntimeContext | Record<string, any>;
402
+ }
403
+
404
+ export interface LoopVNextNetworkResponse {
405
+ status: 'success';
406
+ result: {
407
+ text: string;
408
+ };
409
+ steps: WorkflowResult<any, any>['steps'];
410
+ }
411
+
412
+ export interface McpServerListResponse {
413
+ servers: ServerInfo[];
414
+ next: string | null;
415
+ total_count: number;
416
+ }
417
+
418
+ export interface McpToolInfo {
419
+ id: string;
420
+ name: string;
421
+ description?: string;
422
+ inputSchema: string;
423
+ toolType?: MCPToolType;
424
+ }
425
+
426
+ export interface McpServerToolListResponse {
427
+ tools: McpToolInfo[];
428
+ }
@@ -0,0 +1,11 @@
1
+ import { RuntimeContext } from '@mastra/core/runtime-context';
2
+
3
+ export function parseClientRuntimeContext(runtimeContext?: RuntimeContext | Record<string, any>) {
4
+ if (runtimeContext) {
5
+ if (runtimeContext instanceof RuntimeContext) {
6
+ return Object.fromEntries(runtimeContext.entries());
7
+ }
8
+ return runtimeContext;
9
+ }
10
+ return undefined;
11
+ }
@@ -0,0 +1,32 @@
1
+ import { isVercelTool } from '@mastra/core/tools';
2
+ import { zodToJsonSchema } from './zod-to-json-schema';
3
+ import type { ToolsInput } from '@mastra/core/agent';
4
+
5
+ export function processClientTools(clientTools: ToolsInput | undefined): ToolsInput | undefined {
6
+ if (!clientTools) {
7
+ return undefined;
8
+ }
9
+
10
+ return Object.fromEntries(
11
+ Object.entries(clientTools).map(([key, value]) => {
12
+ if (isVercelTool(value)) {
13
+ return [
14
+ key,
15
+ {
16
+ ...value,
17
+ parameters: value.parameters ? zodToJsonSchema(value.parameters) : undefined,
18
+ },
19
+ ];
20
+ } else {
21
+ return [
22
+ key,
23
+ {
24
+ ...value,
25
+ inputSchema: value.inputSchema ? zodToJsonSchema(value.inputSchema) : undefined,
26
+ outputSchema: value.outputSchema ? zodToJsonSchema(value.outputSchema) : undefined,
27
+ },
28
+ ];
29
+ }
30
+ }),
31
+ );
32
+ }
@@ -0,0 +1,10 @@
1
+ import { ZodSchema } from 'zod';
2
+ import originalZodToJsonSchema from 'zod-to-json-schema';
3
+
4
+ export function zodToJsonSchema<T extends ZodSchema | any>(zodSchema: T) {
5
+ if (!(zodSchema instanceof ZodSchema)) {
6
+ return zodSchema;
7
+ }
8
+
9
+ return originalZodToJsonSchema(zodSchema, { $refStrategy: 'none' });
10
+ }