@mastra/client-js 0.0.0-vnextWorkflows-20250422142014 → 0.0.0-workflow-deno-20250616130925
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/.turbo/turbo-build.log +19 -0
- package/CHANGELOG.md +662 -2
- package/dist/index.cjs +889 -55
- package/dist/index.d.cts +408 -41
- package/dist/index.d.ts +408 -41
- package/dist/index.js +885 -55
- package/package.json +23 -13
- package/src/adapters/agui.test.ts +180 -0
- package/src/adapters/agui.ts +239 -0
- package/src/client.ts +200 -13
- package/src/example.ts +30 -31
- package/src/index.test.ts +125 -5
- package/src/resources/a2a.ts +88 -0
- package/src/resources/agent.ts +49 -37
- package/src/resources/base.ts +2 -2
- package/src/resources/index.ts +4 -1
- package/src/resources/legacy-workflow.ts +242 -0
- package/src/resources/mcp-tool.ts +48 -0
- package/src/resources/memory-thread.ts +8 -5
- package/src/resources/network.ts +6 -12
- package/src/resources/tool.ts +16 -3
- package/src/resources/workflow.ts +254 -96
- package/src/types.ts +134 -19
- package/src/utils/index.ts +11 -0
- package/src/utils/process-client-tools.ts +31 -0
- package/src/utils/zod-to-json-schema.ts +10 -0
package/src/types.ts
CHANGED
|
@@ -1,16 +1,24 @@
|
|
|
1
1
|
import type {
|
|
2
|
-
|
|
2
|
+
MastraMessageV1,
|
|
3
3
|
AiMessageType,
|
|
4
4
|
CoreMessage,
|
|
5
5
|
QueryResult,
|
|
6
|
-
StepAction,
|
|
7
|
-
StepGraph,
|
|
8
6
|
StorageThreadType,
|
|
9
|
-
|
|
10
|
-
|
|
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 {
|
|
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
|
|
|
@@ -36,24 +44,48 @@ export interface RequestOptions {
|
|
|
36
44
|
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
|
-
|
|
70
|
+
output?: T;
|
|
71
|
+
experimental_output?: T;
|
|
72
|
+
runtimeContext?: RuntimeContext | Record<string, any>;
|
|
73
|
+
clientTools?: ToolsInput;
|
|
74
|
+
} & WithoutMethods<Omit<AgentGenerateOptions<T>, 'output' | 'experimental_output' | 'runtimeContext' | 'clientTools'>>;
|
|
50
75
|
|
|
51
76
|
export type StreamParams<T extends JSONSchema7 | ZodSchema | undefined = undefined> = {
|
|
52
77
|
messages: string | string[] | CoreMessage[] | AiMessageType[];
|
|
53
|
-
|
|
78
|
+
output?: T;
|
|
79
|
+
experimental_output?: T;
|
|
80
|
+
runtimeContext?: RuntimeContext | Record<string, any>;
|
|
81
|
+
clientTools?: ToolsInput;
|
|
82
|
+
} & WithoutMethods<Omit<AgentStreamOptions<T>, 'output' | 'experimental_output' | 'runtimeContext' | 'clientTools'>>;
|
|
54
83
|
|
|
55
84
|
export interface GetEvalsByAgentIdResponse extends GetAgentResponse {
|
|
56
85
|
evals: any[];
|
|
86
|
+
instructions: string;
|
|
87
|
+
name: string;
|
|
88
|
+
id: string;
|
|
57
89
|
}
|
|
58
90
|
|
|
59
91
|
export interface GetToolResponse {
|
|
@@ -63,7 +95,7 @@ export interface GetToolResponse {
|
|
|
63
95
|
outputSchema: string;
|
|
64
96
|
}
|
|
65
97
|
|
|
66
|
-
export interface
|
|
98
|
+
export interface GetLegacyWorkflowResponse {
|
|
67
99
|
name: string;
|
|
68
100
|
triggerSchema: string;
|
|
69
101
|
steps: Record<string, StepAction<any, any, any, any>>;
|
|
@@ -72,12 +104,50 @@ export interface GetWorkflowResponse {
|
|
|
72
104
|
workflowId?: string;
|
|
73
105
|
}
|
|
74
106
|
|
|
75
|
-
export
|
|
107
|
+
export interface GetWorkflowRunsParams {
|
|
108
|
+
fromDate?: Date;
|
|
109
|
+
toDate?: Date;
|
|
110
|
+
limit?: number;
|
|
111
|
+
offset?: number;
|
|
112
|
+
resourceId?: string;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
export type GetLegacyWorkflowRunsResponse = LegacyWorkflowRuns;
|
|
116
|
+
|
|
117
|
+
export type GetWorkflowRunsResponse = WorkflowRuns;
|
|
118
|
+
|
|
119
|
+
export type GetWorkflowRunByIdResponse = WorkflowRun;
|
|
120
|
+
|
|
121
|
+
export type GetWorkflowRunExecutionResultResponse = WatchEvent['payload']['workflowState'];
|
|
122
|
+
|
|
123
|
+
export type LegacyWorkflowRunResult = {
|
|
76
124
|
activePaths: Record<string, { status: string; suspendPayload?: any; stepPath: string[] }>;
|
|
77
|
-
results:
|
|
125
|
+
results: CoreLegacyWorkflowRunResult<any, any, any>['results'];
|
|
78
126
|
timestamp: number;
|
|
79
127
|
runId: string;
|
|
80
128
|
};
|
|
129
|
+
|
|
130
|
+
export interface GetWorkflowResponse {
|
|
131
|
+
name: string;
|
|
132
|
+
description?: string;
|
|
133
|
+
steps: {
|
|
134
|
+
[key: string]: {
|
|
135
|
+
id: string;
|
|
136
|
+
description: string;
|
|
137
|
+
inputSchema: string;
|
|
138
|
+
outputSchema: string;
|
|
139
|
+
resumeSchema: string;
|
|
140
|
+
suspendSchema: string;
|
|
141
|
+
};
|
|
142
|
+
};
|
|
143
|
+
stepGraph: Workflow['serializedStepGraph'];
|
|
144
|
+
inputSchema: string;
|
|
145
|
+
outputSchema: string;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
export type WorkflowWatchResult = WatchEvent & { runId: string };
|
|
149
|
+
|
|
150
|
+
export type WorkflowRunResult = WorkflowResult<any, any>;
|
|
81
151
|
export interface UpsertVectorParams {
|
|
82
152
|
indexName: string;
|
|
83
153
|
vectors: number[][];
|
|
@@ -109,17 +179,17 @@ export interface GetVectorIndexResponse {
|
|
|
109
179
|
}
|
|
110
180
|
|
|
111
181
|
export interface SaveMessageToMemoryParams {
|
|
112
|
-
messages:
|
|
182
|
+
messages: MastraMessageV1[];
|
|
113
183
|
agentId: string;
|
|
114
184
|
}
|
|
115
185
|
|
|
116
|
-
export type SaveMessageToMemoryResponse =
|
|
186
|
+
export type SaveMessageToMemoryResponse = MastraMessageV1[];
|
|
117
187
|
|
|
118
188
|
export interface CreateMemoryThreadParams {
|
|
119
|
-
title
|
|
120
|
-
metadata
|
|
121
|
-
|
|
122
|
-
threadId
|
|
189
|
+
title?: string;
|
|
190
|
+
metadata?: Record<string, any>;
|
|
191
|
+
resourceId: string;
|
|
192
|
+
threadId?: string;
|
|
123
193
|
agentId: string;
|
|
124
194
|
}
|
|
125
195
|
|
|
@@ -135,7 +205,14 @@ export type GetMemoryThreadResponse = StorageThreadType[];
|
|
|
135
205
|
export interface UpdateMemoryThreadParams {
|
|
136
206
|
title: string;
|
|
137
207
|
metadata: Record<string, any>;
|
|
138
|
-
|
|
208
|
+
resourceId: string;
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
export interface GetMemoryThreadMessagesParams {
|
|
212
|
+
/**
|
|
213
|
+
* Limit the number of messages to retrieve (default: 40)
|
|
214
|
+
*/
|
|
215
|
+
limit?: number;
|
|
139
216
|
}
|
|
140
217
|
|
|
141
218
|
export interface GetMemoryThreadMessagesResponse {
|
|
@@ -145,14 +222,32 @@ export interface GetMemoryThreadMessagesResponse {
|
|
|
145
222
|
|
|
146
223
|
export interface GetLogsParams {
|
|
147
224
|
transportId: string;
|
|
225
|
+
fromDate?: Date;
|
|
226
|
+
toDate?: Date;
|
|
227
|
+
logLevel?: LogLevel;
|
|
228
|
+
filters?: Record<string, string>;
|
|
229
|
+
page?: number;
|
|
230
|
+
perPage?: number;
|
|
148
231
|
}
|
|
149
232
|
|
|
150
233
|
export interface GetLogParams {
|
|
151
234
|
runId: string;
|
|
152
235
|
transportId: string;
|
|
236
|
+
fromDate?: Date;
|
|
237
|
+
toDate?: Date;
|
|
238
|
+
logLevel?: LogLevel;
|
|
239
|
+
filters?: Record<string, string>;
|
|
240
|
+
page?: number;
|
|
241
|
+
perPage?: number;
|
|
153
242
|
}
|
|
154
243
|
|
|
155
|
-
export type GetLogsResponse =
|
|
244
|
+
export type GetLogsResponse = {
|
|
245
|
+
logs: BaseLogMessage[];
|
|
246
|
+
total: number;
|
|
247
|
+
page: number;
|
|
248
|
+
perPage: number;
|
|
249
|
+
hasMore: boolean;
|
|
250
|
+
};
|
|
156
251
|
|
|
157
252
|
export type RequestFunction = (path: string, options?: RequestOptions) => Promise<any>;
|
|
158
253
|
|
|
@@ -206,6 +301,8 @@ export interface GetTelemetryParams {
|
|
|
206
301
|
page?: number;
|
|
207
302
|
perPage?: number;
|
|
208
303
|
attribute?: Record<string, string>;
|
|
304
|
+
fromDate?: Date;
|
|
305
|
+
toDate?: Date;
|
|
209
306
|
}
|
|
210
307
|
|
|
211
308
|
export interface GetNetworkResponse {
|
|
@@ -222,3 +319,21 @@ export interface GetNetworkResponse {
|
|
|
222
319
|
};
|
|
223
320
|
state?: Record<string, any>;
|
|
224
321
|
}
|
|
322
|
+
|
|
323
|
+
export interface McpServerListResponse {
|
|
324
|
+
servers: ServerInfo[];
|
|
325
|
+
next: string | null;
|
|
326
|
+
total_count: number;
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
export interface McpToolInfo {
|
|
330
|
+
id: string;
|
|
331
|
+
name: string;
|
|
332
|
+
description?: string;
|
|
333
|
+
inputSchema: string;
|
|
334
|
+
toolType?: MCPToolType;
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
export interface McpServerToolListResponse {
|
|
338
|
+
tools: McpToolInfo[];
|
|
339
|
+
}
|
|
@@ -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,31 @@
|
|
|
1
|
+
import { isVercelTool } from '@mastra/core/tools';
|
|
2
|
+
import { zodToJsonSchema } from './zod-to-json-schema';
|
|
3
|
+
|
|
4
|
+
export function processClientTools(clientTools: Record<string, any> | undefined): Record<string, any> | undefined {
|
|
5
|
+
if (!clientTools) {
|
|
6
|
+
return undefined;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
return Object.fromEntries(
|
|
10
|
+
Object.entries(clientTools).map(([key, value]) => {
|
|
11
|
+
if (isVercelTool(value)) {
|
|
12
|
+
return [
|
|
13
|
+
key,
|
|
14
|
+
{
|
|
15
|
+
...value,
|
|
16
|
+
parameters: value.parameters ? zodToJsonSchema(value.parameters) : undefined,
|
|
17
|
+
},
|
|
18
|
+
];
|
|
19
|
+
} else {
|
|
20
|
+
return [
|
|
21
|
+
key,
|
|
22
|
+
{
|
|
23
|
+
...value,
|
|
24
|
+
inputSchema: value.inputSchema ? zodToJsonSchema(value.inputSchema) : undefined,
|
|
25
|
+
outputSchema: value.outputSchema ? zodToJsonSchema(value.outputSchema) : undefined,
|
|
26
|
+
},
|
|
27
|
+
];
|
|
28
|
+
}
|
|
29
|
+
}),
|
|
30
|
+
) as Record<string, any>;
|
|
31
|
+
}
|
|
@@ -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
|
+
}
|