@mastra/client-js 0.11.3-alpha.3 → 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 +16 -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 +8 -4
  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/src/types.ts DELETED
@@ -1,534 +0,0 @@
1
- import type {
2
- AgentExecutionOptions,
3
- AgentGenerateOptions,
4
- AgentStreamOptions,
5
- ToolsInput,
6
- UIMessageWithMetadata,
7
- } from '@mastra/core/agent';
8
- import type { MessageListInput } from '@mastra/core/agent/message-list';
9
- import type { CoreMessage } from '@mastra/core/llm';
10
- import type { BaseLogMessage, LogLevel } from '@mastra/core/logger';
11
- import type { MCPToolType, ServerInfo } from '@mastra/core/mcp';
12
- import type { AiMessageType, MastraMessageV1, MastraMessageV2, StorageThreadType } from '@mastra/core/memory';
13
- import type { RuntimeContext } from '@mastra/core/runtime-context';
14
- import type { MastraScorerEntry, ScoreRowData } from '@mastra/core/scores';
15
- import type {
16
- AITraceRecord,
17
- AISpanRecord,
18
- LegacyWorkflowRuns,
19
- StorageGetMessagesArg,
20
- PaginationInfo,
21
- WorkflowRun,
22
- WorkflowRuns,
23
- } from '@mastra/core/storage';
24
- import type { OutputSchema } from '@mastra/core/stream';
25
- import type { QueryResult } from '@mastra/core/vector';
26
- import type { Workflow, WatchEvent, WorkflowResult } from '@mastra/core/workflows';
27
- import type {
28
- StepAction,
29
- StepGraph,
30
- LegacyWorkflowRunResult as CoreLegacyWorkflowRunResult,
31
- } from '@mastra/core/workflows/legacy';
32
- import type { JSONSchema7 } from 'json-schema';
33
- import type { ZodSchema } from 'zod';
34
-
35
- export interface ClientOptions {
36
- /** Base URL for API requests */
37
- baseUrl: string;
38
- /** Number of retry attempts for failed requests */
39
- retries?: number;
40
- /** Initial backoff time in milliseconds between retries */
41
- backoffMs?: number;
42
- /** Maximum backoff time in milliseconds between retries */
43
- maxBackoffMs?: number;
44
- /** Custom headers to include with requests */
45
- headers?: Record<string, string>;
46
- /** Abort signal for request */
47
- abortSignal?: AbortSignal;
48
- /** Credentials mode for requests. See https://developer.mozilla.org/en-US/docs/Web/API/Request/credentials for more info. */
49
- credentials?: 'omit' | 'same-origin' | 'include';
50
- }
51
-
52
- export interface RequestOptions {
53
- method?: string;
54
- headers?: Record<string, string>;
55
- body?: any;
56
- stream?: boolean;
57
- /** Credentials mode for requests. See https://developer.mozilla.org/en-US/docs/Web/API/Request/credentials for more info. */
58
- credentials?: 'omit' | 'same-origin' | 'include';
59
- }
60
-
61
- type WithoutMethods<T> = {
62
- [K in keyof T as T[K] extends (...args: any[]) => any
63
- ? never
64
- : T[K] extends { (): any }
65
- ? never
66
- : T[K] extends undefined | ((...args: any[]) => any)
67
- ? never
68
- : K]: T[K];
69
- };
70
-
71
- export interface GetAgentResponse {
72
- name: string;
73
- instructions: string;
74
- tools: Record<string, GetToolResponse>;
75
- workflows: Record<string, GetWorkflowResponse>;
76
- provider: string;
77
- modelId: string;
78
- modelVersion: string;
79
- defaultGenerateOptions: WithoutMethods<AgentGenerateOptions>;
80
- defaultStreamOptions: WithoutMethods<AgentStreamOptions>;
81
- }
82
-
83
- export type GenerateParams<T extends JSONSchema7 | ZodSchema | undefined = undefined> = {
84
- messages: string | string[] | CoreMessage[] | AiMessageType[] | UIMessageWithMetadata[];
85
- output?: T;
86
- experimental_output?: T;
87
- runtimeContext?: RuntimeContext | Record<string, any>;
88
- clientTools?: ToolsInput;
89
- } & WithoutMethods<
90
- Omit<AgentGenerateOptions<T>, 'output' | 'experimental_output' | 'runtimeContext' | 'clientTools' | 'abortSignal'>
91
- >;
92
-
93
- export type StreamParams<T extends JSONSchema7 | ZodSchema | undefined = undefined> = {
94
- messages: string | string[] | CoreMessage[] | AiMessageType[] | UIMessageWithMetadata[];
95
- output?: T;
96
- experimental_output?: T;
97
- runtimeContext?: RuntimeContext | Record<string, any>;
98
- clientTools?: ToolsInput;
99
- } & WithoutMethods<
100
- Omit<AgentStreamOptions<T>, 'output' | 'experimental_output' | 'runtimeContext' | 'clientTools' | 'abortSignal'>
101
- >;
102
-
103
- export type StreamVNextParams<OUTPUT extends OutputSchema | undefined = undefined> = {
104
- messages: MessageListInput;
105
- output?: OUTPUT;
106
- runtimeContext?: RuntimeContext | Record<string, any>;
107
- clientTools?: ToolsInput;
108
- } & WithoutMethods<Omit<AgentExecutionOptions<OUTPUT>, 'output' | 'runtimeContext' | 'clientTools' | 'options'>>;
109
-
110
- export type UpdateModelParams = {
111
- modelId: string;
112
- provider: 'openai' | 'anthropic' | 'groq' | 'xai' | 'google';
113
- };
114
-
115
- export interface GetEvalsByAgentIdResponse extends GetAgentResponse {
116
- evals: any[];
117
- instructions: string;
118
- name: string;
119
- id: string;
120
- }
121
-
122
- export interface GetToolResponse {
123
- id: string;
124
- description: string;
125
- inputSchema: string;
126
- outputSchema: string;
127
- }
128
-
129
- export interface GetLegacyWorkflowResponse {
130
- name: string;
131
- triggerSchema: string;
132
- steps: Record<string, StepAction<any, any, any, any>>;
133
- stepGraph: StepGraph;
134
- stepSubscriberGraph: Record<string, StepGraph>;
135
- workflowId?: string;
136
- }
137
-
138
- export interface GetWorkflowRunsParams {
139
- fromDate?: Date;
140
- toDate?: Date;
141
- limit?: number;
142
- offset?: number;
143
- resourceId?: string;
144
- }
145
-
146
- export type GetLegacyWorkflowRunsResponse = LegacyWorkflowRuns;
147
-
148
- export type GetWorkflowRunsResponse = WorkflowRuns;
149
-
150
- export type GetWorkflowRunByIdResponse = WorkflowRun;
151
-
152
- export type GetWorkflowRunExecutionResultResponse = WatchEvent['payload']['workflowState'];
153
-
154
- export type LegacyWorkflowRunResult = {
155
- activePaths: Record<string, { status: string; suspendPayload?: any; stepPath: string[] }>;
156
- results: CoreLegacyWorkflowRunResult<any, any, any>['results'];
157
- timestamp: number;
158
- runId: string;
159
- };
160
-
161
- export interface GetWorkflowResponse {
162
- name: string;
163
- description?: string;
164
- steps: {
165
- [key: string]: {
166
- id: string;
167
- description: string;
168
- inputSchema: string;
169
- outputSchema: string;
170
- resumeSchema: string;
171
- suspendSchema: string;
172
- };
173
- };
174
- allSteps: {
175
- [key: string]: {
176
- id: string;
177
- description: string;
178
- inputSchema: string;
179
- outputSchema: string;
180
- resumeSchema: string;
181
- suspendSchema: string;
182
- isWorkflow: boolean;
183
- };
184
- };
185
- stepGraph: Workflow['serializedStepGraph'];
186
- inputSchema: string;
187
- outputSchema: string;
188
- }
189
-
190
- export type WorkflowWatchResult = WatchEvent & { runId: string };
191
-
192
- export type WorkflowRunResult = WorkflowResult<any, any>;
193
- export interface UpsertVectorParams {
194
- indexName: string;
195
- vectors: number[][];
196
- metadata?: Record<string, any>[];
197
- ids?: string[];
198
- }
199
- export interface CreateIndexParams {
200
- indexName: string;
201
- dimension: number;
202
- metric?: 'cosine' | 'euclidean' | 'dotproduct';
203
- }
204
-
205
- export interface QueryVectorParams {
206
- indexName: string;
207
- queryVector: number[];
208
- topK?: number;
209
- filter?: Record<string, any>;
210
- includeVector?: boolean;
211
- }
212
-
213
- export interface QueryVectorResponse {
214
- results: QueryResult[];
215
- }
216
-
217
- export interface GetVectorIndexResponse {
218
- dimension: number;
219
- metric: 'cosine' | 'euclidean' | 'dotproduct';
220
- count: number;
221
- }
222
-
223
- export interface SaveMessageToMemoryParams {
224
- messages: (MastraMessageV1 | MastraMessageV2)[];
225
- agentId: string;
226
- }
227
-
228
- export interface SaveNetworkMessageToMemoryParams {
229
- messages: (MastraMessageV1 | MastraMessageV2)[];
230
- networkId: string;
231
- }
232
-
233
- export type SaveMessageToMemoryResponse = (MastraMessageV1 | MastraMessageV2)[];
234
-
235
- export interface CreateMemoryThreadParams {
236
- title?: string;
237
- metadata?: Record<string, any>;
238
- resourceId: string;
239
- threadId?: string;
240
- agentId: string;
241
- }
242
-
243
- export interface CreateNetworkMemoryThreadParams {
244
- title?: string;
245
- metadata?: Record<string, any>;
246
- resourceId: string;
247
- threadId?: string;
248
- networkId: string;
249
- }
250
-
251
- export type CreateMemoryThreadResponse = StorageThreadType;
252
-
253
- export interface GetMemoryThreadParams {
254
- resourceId: string;
255
- agentId: string;
256
- }
257
-
258
- export interface GetNetworkMemoryThreadParams {
259
- resourceId: string;
260
- networkId: string;
261
- }
262
-
263
- export type GetMemoryThreadResponse = StorageThreadType[];
264
-
265
- export interface UpdateMemoryThreadParams {
266
- title: string;
267
- metadata: Record<string, any>;
268
- resourceId: string;
269
- }
270
-
271
- export interface GetMemoryThreadMessagesParams {
272
- /**
273
- * Limit the number of messages to retrieve (default: 40)
274
- */
275
- limit?: number;
276
- }
277
-
278
- export type GetMemoryThreadMessagesPaginatedParams = Omit<StorageGetMessagesArg, 'threadConfig' | 'threadId'>;
279
-
280
- export interface GetMemoryThreadMessagesResponse {
281
- messages: CoreMessage[];
282
- uiMessages: AiMessageType[];
283
- }
284
-
285
- export type GetMemoryThreadMessagesPaginatedResponse = PaginationInfo & {
286
- messages: MastraMessageV1[] | MastraMessageV2[];
287
- };
288
-
289
- export interface GetLogsParams {
290
- transportId: string;
291
- fromDate?: Date;
292
- toDate?: Date;
293
- logLevel?: LogLevel;
294
- filters?: Record<string, string>;
295
- page?: number;
296
- perPage?: number;
297
- }
298
-
299
- export interface GetLogParams {
300
- runId: string;
301
- transportId: string;
302
- fromDate?: Date;
303
- toDate?: Date;
304
- logLevel?: LogLevel;
305
- filters?: Record<string, string>;
306
- page?: number;
307
- perPage?: number;
308
- }
309
-
310
- export type GetLogsResponse = {
311
- logs: BaseLogMessage[];
312
- total: number;
313
- page: number;
314
- perPage: number;
315
- hasMore: boolean;
316
- };
317
-
318
- export type RequestFunction = (path: string, options?: RequestOptions) => Promise<any>;
319
-
320
- type SpanStatus = {
321
- code: number;
322
- };
323
-
324
- type SpanOther = {
325
- droppedAttributesCount: number;
326
- droppedEventsCount: number;
327
- droppedLinksCount: number;
328
- };
329
-
330
- type SpanEventAttributes = {
331
- key: string;
332
- value: { [key: string]: string | number | boolean | null };
333
- };
334
-
335
- type SpanEvent = {
336
- attributes: SpanEventAttributes[];
337
- name: string;
338
- timeUnixNano: string;
339
- droppedAttributesCount: number;
340
- };
341
-
342
- type Span = {
343
- id: string;
344
- parentSpanId: string | null;
345
- traceId: string;
346
- name: string;
347
- scope: string;
348
- kind: number;
349
- status: SpanStatus;
350
- events: SpanEvent[];
351
- links: any[];
352
- attributes: Record<string, string | number | boolean | null>;
353
- startTime: number;
354
- endTime: number;
355
- duration: number;
356
- other: SpanOther;
357
- createdAt: string;
358
- };
359
-
360
- export interface GetTelemetryResponse {
361
- traces: Span[];
362
- }
363
-
364
- export interface GetTelemetryParams {
365
- name?: string;
366
- scope?: string;
367
- page?: number;
368
- perPage?: number;
369
- attribute?: Record<string, string>;
370
- fromDate?: Date;
371
- toDate?: Date;
372
- }
373
-
374
- export interface GetNetworkResponse {
375
- id: string;
376
- name: string;
377
- instructions: string;
378
- agents: Array<{
379
- name: string;
380
- provider: string;
381
- modelId: string;
382
- }>;
383
- routingModel: {
384
- provider: string;
385
- modelId: string;
386
- };
387
- state?: Record<string, any>;
388
- }
389
-
390
- export interface GetVNextNetworkResponse {
391
- id: string;
392
- name: string;
393
- instructions: string;
394
- agents: Array<{
395
- name: string;
396
- provider: string;
397
- modelId: string;
398
- }>;
399
- routingModel: {
400
- provider: string;
401
- modelId: string;
402
- };
403
- workflows: Array<{
404
- name: string;
405
- description: string;
406
- inputSchema: string | undefined;
407
- outputSchema: string | undefined;
408
- }>;
409
- tools: Array<{
410
- id: string;
411
- description: string;
412
- }>;
413
- }
414
-
415
- export interface GenerateVNextNetworkResponse {
416
- task: string;
417
- result: string;
418
- resourceId: string;
419
- resourceType: 'none' | 'tool' | 'agent' | 'workflow';
420
- }
421
-
422
- export interface GenerateOrStreamVNextNetworkParams {
423
- message: string;
424
- threadId?: string;
425
- resourceId?: string;
426
- runtimeContext?: RuntimeContext | Record<string, any>;
427
- }
428
-
429
- export interface LoopStreamVNextNetworkParams {
430
- message: string;
431
- threadId?: string;
432
- resourceId?: string;
433
- maxIterations?: number;
434
- runtimeContext?: RuntimeContext | Record<string, any>;
435
- }
436
-
437
- export interface LoopVNextNetworkResponse {
438
- status: 'success';
439
- result: {
440
- task: string;
441
- resourceId: string;
442
- resourceType: 'agent' | 'workflow' | 'none' | 'tool';
443
- result: string;
444
- iteration: number;
445
- isOneOff: boolean;
446
- prompt: string;
447
- threadId?: string | undefined;
448
- threadResourceId?: string | undefined;
449
- isComplete?: boolean | undefined;
450
- completionReason?: string | undefined;
451
- };
452
- steps: WorkflowResult<any, any>['steps'];
453
- }
454
-
455
- export interface McpServerListResponse {
456
- servers: ServerInfo[];
457
- next: string | null;
458
- total_count: number;
459
- }
460
-
461
- export interface McpToolInfo {
462
- id: string;
463
- name: string;
464
- description?: string;
465
- inputSchema: string;
466
- toolType?: MCPToolType;
467
- }
468
-
469
- export interface McpServerToolListResponse {
470
- tools: McpToolInfo[];
471
- }
472
-
473
- export type ClientScoreRowData = Omit<ScoreRowData, 'createdAt' | 'updatedAt'> & {
474
- createdAt: string;
475
- updatedAt: string;
476
- };
477
-
478
- // Scores-related types
479
- export interface GetScoresByRunIdParams {
480
- runId: string;
481
- page?: number;
482
- perPage?: number;
483
- }
484
-
485
- export interface GetScoresByScorerIdParams {
486
- scorerId: string;
487
- entityId?: string;
488
- entityType?: string;
489
- page?: number;
490
- perPage?: number;
491
- }
492
-
493
- export interface GetScoresByEntityIdParams {
494
- entityId: string;
495
- entityType: string;
496
- page?: number;
497
- perPage?: number;
498
- }
499
-
500
- export interface SaveScoreParams {
501
- score: Omit<ScoreRowData, 'id' | 'createdAt' | 'updatedAt'>;
502
- }
503
-
504
- export interface GetScoresResponse {
505
- pagination: {
506
- total: number;
507
- page: number;
508
- perPage: number;
509
- hasMore: boolean;
510
- };
511
- scores: ClientScoreRowData[];
512
- }
513
-
514
- export interface SaveScoreResponse {
515
- score: ClientScoreRowData;
516
- }
517
-
518
- export type GetScorerResponse = MastraScorerEntry & {
519
- agentIds: string[];
520
- workflowIds: string[];
521
- };
522
-
523
- export interface GetScorersResponse {
524
- scorers: Array<GetScorerResponse>;
525
- }
526
-
527
- export interface GetAITraceResponse {
528
- trace: AITraceRecord;
529
- }
530
-
531
- export interface GetAITracesResponse {
532
- spans: AISpanRecord[];
533
- pagination: PaginationInfo;
534
- }
@@ -1,11 +0,0 @@
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
- }
@@ -1,32 +0,0 @@
1
- import type { ToolsInput } from '@mastra/core/agent';
2
- import { isVercelTool } from '@mastra/core/tools/is-vercel-tool';
3
- import { zodToJsonSchema } from './zod-to-json-schema';
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
- }