@mastra/client-js 0.0.0-cloud-transporter-20250513033346 → 0.0.0-cloudflare-deployer-dont-install-deps-20250714111754
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 +702 -2
- package/LICENSE.md +11 -42
- package/README.md +1 -1
- package/dist/index.cjs +1121 -115
- package/dist/index.d.cts +481 -87
- package/dist/index.d.ts +481 -87
- package/dist/index.js +1122 -116
- package/package.json +20 -14
- package/src/client.ts +280 -22
- package/src/example.ts +59 -29
- package/src/index.test.ts +91 -1
- package/src/resources/agent.ts +629 -25
- package/src/resources/base.ts +3 -1
- package/src/resources/index.ts +3 -2
- package/src/resources/{vnext-workflow.ts → legacy-workflow.ts} +124 -143
- package/src/resources/mcp-tool.ts +48 -0
- package/src/resources/network-memory-thread.ts +63 -0
- package/src/resources/network.ts +2 -3
- package/src/resources/tool.ts +4 -3
- package/src/resources/vNextNetwork.ts +194 -0
- package/src/resources/workflow.ts +241 -96
- package/src/types.ts +181 -23
- package/src/utils/index.ts +11 -0
- package/src/utils/process-client-tools.ts +32 -0
package/src/types.ts
CHANGED
|
@@ -1,18 +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
|
-
BaseLogMessage,
|
|
10
|
-
WorkflowRunResult as CoreWorkflowRunResult,
|
|
11
7
|
WorkflowRuns,
|
|
8
|
+
WorkflowRun,
|
|
9
|
+
LegacyWorkflowRuns,
|
|
12
10
|
} from '@mastra/core';
|
|
11
|
+
import type { AgentGenerateOptions, AgentStreamOptions, ToolsInput } from '@mastra/core/agent';
|
|
12
|
+
import type { BaseLogMessage, LogLevel } from '@mastra/core/logger';
|
|
13
13
|
|
|
14
|
-
import type {
|
|
15
|
-
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';
|
|
16
22
|
import type { JSONSchema7 } from 'json-schema';
|
|
17
23
|
import type { ZodSchema } from 'zod';
|
|
18
24
|
|
|
@@ -28,6 +34,7 @@ export interface ClientOptions {
|
|
|
28
34
|
/** Custom headers to include with requests */
|
|
29
35
|
headers?: Record<string, string>;
|
|
30
36
|
/** Abort signal for request */
|
|
37
|
+
abortSignal?: AbortSignal;
|
|
31
38
|
}
|
|
32
39
|
|
|
33
40
|
export interface RequestOptions {
|
|
@@ -35,9 +42,18 @@ export interface RequestOptions {
|
|
|
35
42
|
headers?: Record<string, string>;
|
|
36
43
|
body?: any;
|
|
37
44
|
stream?: boolean;
|
|
38
|
-
signal?: AbortSignal;
|
|
39
45
|
}
|
|
40
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
|
+
|
|
41
57
|
export interface GetAgentResponse {
|
|
42
58
|
name: string;
|
|
43
59
|
instructions: string;
|
|
@@ -45,15 +61,29 @@ export interface GetAgentResponse {
|
|
|
45
61
|
workflows: Record<string, GetWorkflowResponse>;
|
|
46
62
|
provider: string;
|
|
47
63
|
modelId: string;
|
|
64
|
+
defaultGenerateOptions: WithoutMethods<AgentGenerateOptions>;
|
|
65
|
+
defaultStreamOptions: WithoutMethods<AgentStreamOptions>;
|
|
48
66
|
}
|
|
49
67
|
|
|
50
68
|
export type GenerateParams<T extends JSONSchema7 | ZodSchema | undefined = undefined> = {
|
|
51
69
|
messages: string | string[] | CoreMessage[] | AiMessageType[];
|
|
52
|
-
|
|
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
|
+
>;
|
|
53
77
|
|
|
54
78
|
export type StreamParams<T extends JSONSchema7 | ZodSchema | undefined = undefined> = {
|
|
55
79
|
messages: string | string[] | CoreMessage[] | AiMessageType[];
|
|
56
|
-
|
|
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
|
+
>;
|
|
57
87
|
|
|
58
88
|
export interface GetEvalsByAgentIdResponse extends GetAgentResponse {
|
|
59
89
|
evals: any[];
|
|
@@ -69,7 +99,7 @@ export interface GetToolResponse {
|
|
|
69
99
|
outputSchema: string;
|
|
70
100
|
}
|
|
71
101
|
|
|
72
|
-
export interface
|
|
102
|
+
export interface GetLegacyWorkflowResponse {
|
|
73
103
|
name: string;
|
|
74
104
|
triggerSchema: string;
|
|
75
105
|
steps: Record<string, StepAction<any, any, any, any>>;
|
|
@@ -86,17 +116,24 @@ export interface GetWorkflowRunsParams {
|
|
|
86
116
|
resourceId?: string;
|
|
87
117
|
}
|
|
88
118
|
|
|
119
|
+
export type GetLegacyWorkflowRunsResponse = LegacyWorkflowRuns;
|
|
120
|
+
|
|
89
121
|
export type GetWorkflowRunsResponse = WorkflowRuns;
|
|
90
122
|
|
|
91
|
-
export type
|
|
123
|
+
export type GetWorkflowRunByIdResponse = WorkflowRun;
|
|
124
|
+
|
|
125
|
+
export type GetWorkflowRunExecutionResultResponse = WatchEvent['payload']['workflowState'];
|
|
126
|
+
|
|
127
|
+
export type LegacyWorkflowRunResult = {
|
|
92
128
|
activePaths: Record<string, { status: string; suspendPayload?: any; stepPath: string[] }>;
|
|
93
|
-
results:
|
|
129
|
+
results: CoreLegacyWorkflowRunResult<any, any, any>['results'];
|
|
94
130
|
timestamp: number;
|
|
95
131
|
runId: string;
|
|
96
132
|
};
|
|
97
133
|
|
|
98
|
-
export interface
|
|
134
|
+
export interface GetWorkflowResponse {
|
|
99
135
|
name: string;
|
|
136
|
+
description?: string;
|
|
100
137
|
steps: {
|
|
101
138
|
[key: string]: {
|
|
102
139
|
id: string;
|
|
@@ -107,14 +144,25 @@ export interface GetVNextWorkflowResponse {
|
|
|
107
144
|
suspendSchema: string;
|
|
108
145
|
};
|
|
109
146
|
};
|
|
110
|
-
|
|
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'];
|
|
111
159
|
inputSchema: string;
|
|
112
160
|
outputSchema: string;
|
|
113
161
|
}
|
|
114
162
|
|
|
115
|
-
export type
|
|
163
|
+
export type WorkflowWatchResult = WatchEvent & { runId: string };
|
|
116
164
|
|
|
117
|
-
export type
|
|
165
|
+
export type WorkflowRunResult = WorkflowResult<any, any>;
|
|
118
166
|
export interface UpsertVectorParams {
|
|
119
167
|
indexName: string;
|
|
120
168
|
vectors: number[][];
|
|
@@ -146,20 +194,33 @@ export interface GetVectorIndexResponse {
|
|
|
146
194
|
}
|
|
147
195
|
|
|
148
196
|
export interface SaveMessageToMemoryParams {
|
|
149
|
-
messages:
|
|
197
|
+
messages: MastraMessageV1[];
|
|
150
198
|
agentId: string;
|
|
151
199
|
}
|
|
152
200
|
|
|
153
|
-
export
|
|
201
|
+
export interface SaveNetworkMessageToMemoryParams {
|
|
202
|
+
messages: MastraMessageV1[];
|
|
203
|
+
networkId: string;
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
export type SaveMessageToMemoryResponse = MastraMessageV1[];
|
|
154
207
|
|
|
155
208
|
export interface CreateMemoryThreadParams {
|
|
156
|
-
title
|
|
157
|
-
metadata
|
|
209
|
+
title?: string;
|
|
210
|
+
metadata?: Record<string, any>;
|
|
158
211
|
resourceId: string;
|
|
159
|
-
threadId
|
|
212
|
+
threadId?: string;
|
|
160
213
|
agentId: string;
|
|
161
214
|
}
|
|
162
215
|
|
|
216
|
+
export interface CreateNetworkMemoryThreadParams {
|
|
217
|
+
title?: string;
|
|
218
|
+
metadata?: Record<string, any>;
|
|
219
|
+
resourceId: string;
|
|
220
|
+
threadId?: string;
|
|
221
|
+
networkId: string;
|
|
222
|
+
}
|
|
223
|
+
|
|
163
224
|
export type CreateMemoryThreadResponse = StorageThreadType;
|
|
164
225
|
|
|
165
226
|
export interface GetMemoryThreadParams {
|
|
@@ -167,6 +228,11 @@ export interface GetMemoryThreadParams {
|
|
|
167
228
|
agentId: string;
|
|
168
229
|
}
|
|
169
230
|
|
|
231
|
+
export interface GetNetworkMemoryThreadParams {
|
|
232
|
+
resourceId: string;
|
|
233
|
+
networkId: string;
|
|
234
|
+
}
|
|
235
|
+
|
|
170
236
|
export type GetMemoryThreadResponse = StorageThreadType[];
|
|
171
237
|
|
|
172
238
|
export interface UpdateMemoryThreadParams {
|
|
@@ -189,14 +255,32 @@ export interface GetMemoryThreadMessagesResponse {
|
|
|
189
255
|
|
|
190
256
|
export interface GetLogsParams {
|
|
191
257
|
transportId: string;
|
|
258
|
+
fromDate?: Date;
|
|
259
|
+
toDate?: Date;
|
|
260
|
+
logLevel?: LogLevel;
|
|
261
|
+
filters?: Record<string, string>;
|
|
262
|
+
page?: number;
|
|
263
|
+
perPage?: number;
|
|
192
264
|
}
|
|
193
265
|
|
|
194
266
|
export interface GetLogParams {
|
|
195
267
|
runId: string;
|
|
196
268
|
transportId: string;
|
|
269
|
+
fromDate?: Date;
|
|
270
|
+
toDate?: Date;
|
|
271
|
+
logLevel?: LogLevel;
|
|
272
|
+
filters?: Record<string, string>;
|
|
273
|
+
page?: number;
|
|
274
|
+
perPage?: number;
|
|
197
275
|
}
|
|
198
276
|
|
|
199
|
-
export type GetLogsResponse =
|
|
277
|
+
export type GetLogsResponse = {
|
|
278
|
+
logs: BaseLogMessage[];
|
|
279
|
+
total: number;
|
|
280
|
+
page: number;
|
|
281
|
+
perPage: number;
|
|
282
|
+
hasMore: boolean;
|
|
283
|
+
};
|
|
200
284
|
|
|
201
285
|
export type RequestFunction = (path: string, options?: RequestOptions) => Promise<any>;
|
|
202
286
|
|
|
@@ -255,6 +339,7 @@ export interface GetTelemetryParams {
|
|
|
255
339
|
}
|
|
256
340
|
|
|
257
341
|
export interface GetNetworkResponse {
|
|
342
|
+
id: string;
|
|
258
343
|
name: string;
|
|
259
344
|
instructions: string;
|
|
260
345
|
agents: Array<{
|
|
@@ -268,3 +353,76 @@ export interface GetNetworkResponse {
|
|
|
268
353
|
};
|
|
269
354
|
state?: Record<string, any>;
|
|
270
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
|
+
}
|