@mastra/client-js 0.0.0-vnext-inngest-20250508131921 → 0.0.0-vnext-20251104230439

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 (68) hide show
  1. package/CHANGELOG.md +2389 -2
  2. package/LICENSE.md +11 -42
  3. package/README.md +12 -15
  4. package/dist/client.d.ts +254 -0
  5. package/dist/client.d.ts.map +1 -0
  6. package/dist/example.d.ts +2 -0
  7. package/dist/example.d.ts.map +1 -0
  8. package/dist/index.cjs +2594 -548
  9. package/dist/index.cjs.map +1 -0
  10. package/dist/index.d.ts +5 -730
  11. package/dist/index.d.ts.map +1 -0
  12. package/dist/index.js +2593 -553
  13. package/dist/index.js.map +1 -0
  14. package/dist/resources/a2a.d.ts +41 -0
  15. package/dist/resources/a2a.d.ts.map +1 -0
  16. package/dist/resources/agent-builder.d.ts +186 -0
  17. package/dist/resources/agent-builder.d.ts.map +1 -0
  18. package/dist/resources/agent.d.ts +181 -0
  19. package/dist/resources/agent.d.ts.map +1 -0
  20. package/dist/resources/base.d.ts +13 -0
  21. package/dist/resources/base.d.ts.map +1 -0
  22. package/dist/resources/index.d.ts +11 -0
  23. package/dist/resources/index.d.ts.map +1 -0
  24. package/dist/resources/mcp-tool.d.ts +28 -0
  25. package/dist/resources/mcp-tool.d.ts.map +1 -0
  26. package/dist/resources/memory-thread.d.ts +61 -0
  27. package/dist/resources/memory-thread.d.ts.map +1 -0
  28. package/dist/resources/observability.d.ts +35 -0
  29. package/dist/resources/observability.d.ts.map +1 -0
  30. package/dist/resources/tool.d.ts +24 -0
  31. package/dist/resources/tool.d.ts.map +1 -0
  32. package/dist/resources/vector.d.ts +51 -0
  33. package/dist/resources/vector.d.ts.map +1 -0
  34. package/dist/resources/workflow.d.ts +216 -0
  35. package/dist/resources/workflow.d.ts.map +1 -0
  36. package/dist/tools.d.ts +22 -0
  37. package/dist/tools.d.ts.map +1 -0
  38. package/dist/types.d.ts +457 -0
  39. package/dist/types.d.ts.map +1 -0
  40. package/dist/utils/index.d.ts +11 -0
  41. package/dist/utils/index.d.ts.map +1 -0
  42. package/dist/utils/process-client-tools.d.ts +3 -0
  43. package/dist/utils/process-client-tools.d.ts.map +1 -0
  44. package/dist/utils/process-mastra-stream.d.ts +11 -0
  45. package/dist/utils/process-mastra-stream.d.ts.map +1 -0
  46. package/dist/utils/zod-to-json-schema.d.ts +3 -0
  47. package/dist/utils/zod-to-json-schema.d.ts.map +1 -0
  48. package/package.json +38 -20
  49. package/dist/index.d.cts +0 -730
  50. package/eslint.config.js +0 -6
  51. package/src/adapters/agui.test.ts +0 -167
  52. package/src/adapters/agui.ts +0 -219
  53. package/src/client.ts +0 -259
  54. package/src/example.ts +0 -65
  55. package/src/index.test.ts +0 -710
  56. package/src/index.ts +0 -2
  57. package/src/resources/agent.ts +0 -206
  58. package/src/resources/base.ts +0 -70
  59. package/src/resources/index.ts +0 -8
  60. package/src/resources/memory-thread.ts +0 -53
  61. package/src/resources/network.ts +0 -92
  62. package/src/resources/tool.ts +0 -38
  63. package/src/resources/vector.ts +0 -83
  64. package/src/resources/vnext-workflow.ts +0 -257
  65. package/src/resources/workflow.ts +0 -251
  66. package/src/types.ts +0 -262
  67. package/tsconfig.json +0 -5
  68. package/vitest.config.js +0 -8
@@ -1,206 +0,0 @@
1
- import { processDataStream } from '@ai-sdk/ui-utils';
2
- import type { GenerateReturn } from '@mastra/core';
3
- import type { JSONSchema7 } from 'json-schema';
4
- import { ZodSchema } from 'zod';
5
- import { zodToJsonSchema } from 'zod-to-json-schema';
6
-
7
- import type {
8
- GenerateParams,
9
- GetAgentResponse,
10
- GetEvalsByAgentIdResponse,
11
- GetToolResponse,
12
- ClientOptions,
13
- StreamParams,
14
- } from '../types';
15
-
16
- import { BaseResource } from './base';
17
-
18
- export class AgentTool extends BaseResource {
19
- constructor(
20
- options: ClientOptions,
21
- private agentId: string,
22
- private toolId: string,
23
- ) {
24
- super(options);
25
- }
26
-
27
- /**
28
- * Executes a specific tool for an agent
29
- * @param params - Parameters required for tool execution
30
- * @returns Promise containing tool execution results
31
- */
32
- execute(params: { data: any }): Promise<any> {
33
- return this.request(`/api/agents/${this.agentId}/tools/${this.toolId}/execute`, {
34
- method: 'POST',
35
- body: params,
36
- });
37
- }
38
- }
39
-
40
- export class AgentVoice extends BaseResource {
41
- constructor(
42
- options: ClientOptions,
43
- private agentId: string,
44
- ) {
45
- super(options);
46
- this.agentId = agentId;
47
- }
48
-
49
- /**
50
- * Convert text to speech using the agent's voice provider
51
- * @param text - Text to convert to speech
52
- * @param options - Optional provider-specific options for speech generation
53
- * @returns Promise containing the audio data
54
- */
55
- async speak(text: string, options?: { speaker?: string; [key: string]: any }): Promise<Response> {
56
- return this.request<Response>(`/api/agents/${this.agentId}/voice/speak`, {
57
- method: 'POST',
58
- headers: {
59
- 'Content-Type': 'application/json',
60
- },
61
- body: { input: text, options },
62
- stream: true,
63
- });
64
- }
65
-
66
- /**
67
- * Convert speech to text using the agent's voice provider
68
- * @param audio - Audio data to transcribe
69
- * @param options - Optional provider-specific options
70
- * @returns Promise containing the transcribed text
71
- */
72
- listen(audio: Blob, options?: Record<string, any>): Promise<Response> {
73
- const formData = new FormData();
74
- formData.append('audio', audio);
75
-
76
- if (options) {
77
- formData.append('options', JSON.stringify(options));
78
- }
79
-
80
- return this.request(`/api/agents/${this.agentId}/voice/listen`, {
81
- method: 'POST',
82
- body: formData,
83
- });
84
- }
85
-
86
- /**
87
- * Get available speakers for the agent's voice provider
88
- * @returns Promise containing list of available speakers
89
- */
90
- getSpeakers(): Promise<Array<{ voiceId: string; [key: string]: any }>> {
91
- return this.request(`/api/agents/${this.agentId}/voice/speakers`);
92
- }
93
- }
94
-
95
- export class Agent extends BaseResource {
96
- public readonly voice: AgentVoice;
97
-
98
- constructor(
99
- options: ClientOptions,
100
- private agentId: string,
101
- ) {
102
- super(options);
103
- this.voice = new AgentVoice(options, this.agentId);
104
- }
105
-
106
- /**
107
- * Retrieves details about the agent
108
- * @returns Promise containing agent details including model and instructions
109
- */
110
- details(): Promise<GetAgentResponse> {
111
- return this.request(`/api/agents/${this.agentId}`);
112
- }
113
-
114
- /**
115
- * Generates a response from the agent
116
- * @param params - Generation parameters including prompt
117
- * @returns Promise containing the generated response
118
- */
119
- generate<T extends JSONSchema7 | ZodSchema | undefined = undefined>(
120
- params: GenerateParams<T>,
121
- ): Promise<GenerateReturn<T>> {
122
- const processedParams = {
123
- ...params,
124
- output: params.output instanceof ZodSchema ? zodToJsonSchema(params.output) : params.output,
125
- experimental_output:
126
- params.experimental_output instanceof ZodSchema
127
- ? zodToJsonSchema(params.experimental_output)
128
- : params.experimental_output,
129
- runtimeContext: params.runtimeContext ? Object.fromEntries(params.runtimeContext.entries()) : undefined,
130
- };
131
-
132
- return this.request(`/api/agents/${this.agentId}/generate`, {
133
- method: 'POST',
134
- body: processedParams,
135
- });
136
- }
137
-
138
- /**
139
- * Streams a response from the agent
140
- * @param params - Stream parameters including prompt
141
- * @returns Promise containing the enhanced Response object with processDataStream method
142
- */
143
- async stream<T extends JSONSchema7 | ZodSchema | undefined = undefined>(
144
- params: StreamParams<T>,
145
- ): Promise<
146
- Response & {
147
- processDataStream: (options?: Omit<Parameters<typeof processDataStream>[0], 'stream'>) => Promise<void>;
148
- }
149
- > {
150
- const processedParams = {
151
- ...params,
152
- output: params.output instanceof ZodSchema ? zodToJsonSchema(params.output) : params.output,
153
- experimental_output:
154
- params.experimental_output instanceof ZodSchema
155
- ? zodToJsonSchema(params.experimental_output)
156
- : params.experimental_output,
157
- runtimeContext: params.runtimeContext ? Object.fromEntries(params.runtimeContext.entries()) : undefined,
158
- };
159
-
160
- const response: Response & {
161
- processDataStream: (options?: Omit<Parameters<typeof processDataStream>[0], 'stream'>) => Promise<void>;
162
- } = await this.request(`/api/agents/${this.agentId}/stream`, {
163
- method: 'POST',
164
- body: processedParams,
165
- stream: true,
166
- });
167
-
168
- if (!response.body) {
169
- throw new Error('No response body');
170
- }
171
-
172
- response.processDataStream = async (options = {}) => {
173
- await processDataStream({
174
- stream: response.body as ReadableStream<Uint8Array>,
175
- ...options,
176
- });
177
- };
178
-
179
- return response;
180
- }
181
-
182
- /**
183
- * Gets details about a specific tool available to the agent
184
- * @param toolId - ID of the tool to retrieve
185
- * @returns Promise containing tool details
186
- */
187
- getTool(toolId: string): Promise<GetToolResponse> {
188
- return this.request(`/api/agents/${this.agentId}/tools/${toolId}`);
189
- }
190
-
191
- /**
192
- * Retrieves evaluation results for the agent
193
- * @returns Promise containing agent evaluations
194
- */
195
- evals(): Promise<GetEvalsByAgentIdResponse> {
196
- return this.request(`/api/agents/${this.agentId}/evals/ci`);
197
- }
198
-
199
- /**
200
- * Retrieves live evaluation results for the agent
201
- * @returns Promise containing live agent evaluations
202
- */
203
- liveEvals(): Promise<GetEvalsByAgentIdResponse> {
204
- return this.request(`/api/agents/${this.agentId}/evals/live`);
205
- }
206
- }
@@ -1,70 +0,0 @@
1
- import type { RequestOptions, ClientOptions } from '../types';
2
-
3
- export class BaseResource {
4
- readonly options: ClientOptions;
5
-
6
- constructor(options: ClientOptions) {
7
- this.options = options;
8
- }
9
-
10
- /**
11
- * Makes an HTTP request to the API with retries and exponential backoff
12
- * @param path - The API endpoint path
13
- * @param options - Optional request configuration
14
- * @returns Promise containing the response data
15
- */
16
- public async request<T>(path: string, options: RequestOptions = {}): Promise<T> {
17
- let lastError: Error | null = null;
18
- const { baseUrl, retries = 3, backoffMs = 100, maxBackoffMs = 1000, headers = {} } = this.options;
19
-
20
- let delay = backoffMs;
21
-
22
- for (let attempt = 0; attempt <= retries; attempt++) {
23
- try {
24
- const response = await fetch(`${baseUrl}${path}`, {
25
- ...options,
26
- headers: {
27
- ...headers,
28
- ...options.headers,
29
- // TODO: Bring this back once we figure out what we/users need to do to make this work with cross-origin requests
30
- // 'x-mastra-client-type': 'js',
31
- },
32
- body:
33
- options.body instanceof FormData ? options.body : options.body ? JSON.stringify(options.body) : undefined,
34
- });
35
-
36
- if (!response.ok) {
37
- const errorBody = await response.text();
38
- let errorMessage = `HTTP error! status: ${response.status}`;
39
- try {
40
- const errorJson = JSON.parse(errorBody);
41
- errorMessage += ` - ${JSON.stringify(errorJson)}`;
42
- } catch {
43
- if (errorBody) {
44
- errorMessage += ` - ${errorBody}`;
45
- }
46
- }
47
- throw new Error(errorMessage);
48
- }
49
-
50
- if (options.stream) {
51
- return response as unknown as T;
52
- }
53
-
54
- const data = await response.json();
55
- return data as T;
56
- } catch (error) {
57
- lastError = error as Error;
58
-
59
- if (attempt === retries) {
60
- break;
61
- }
62
-
63
- await new Promise(resolve => setTimeout(resolve, delay));
64
- delay = Math.min(delay * 2, maxBackoffMs);
65
- }
66
- }
67
-
68
- throw lastError || new Error('Request failed');
69
- }
70
- }
@@ -1,8 +0,0 @@
1
- export * from './agent';
2
- export * from './network';
3
- export * from './memory-thread';
4
- export * from './vector';
5
- export * from './workflow';
6
- export * from './tool';
7
- export * from './base';
8
- export * from './vnext-workflow';
@@ -1,53 +0,0 @@
1
- import type { StorageThreadType } from '@mastra/core';
2
-
3
- import type { GetMemoryThreadMessagesResponse, ClientOptions, UpdateMemoryThreadParams } from '../types';
4
-
5
- import { BaseResource } from './base';
6
-
7
- export class MemoryThread extends BaseResource {
8
- constructor(
9
- options: ClientOptions,
10
- private threadId: string,
11
- private agentId: string,
12
- ) {
13
- super(options);
14
- }
15
-
16
- /**
17
- * Retrieves the memory thread details
18
- * @returns Promise containing thread details including title and metadata
19
- */
20
- get(): Promise<StorageThreadType> {
21
- return this.request(`/api/memory/threads/${this.threadId}?agentId=${this.agentId}`);
22
- }
23
-
24
- /**
25
- * Updates the memory thread properties
26
- * @param params - Update parameters including title and metadata
27
- * @returns Promise containing updated thread details
28
- */
29
- update(params: UpdateMemoryThreadParams): Promise<StorageThreadType> {
30
- return this.request(`/api/memory/threads/${this.threadId}?agentId=${this.agentId}`, {
31
- method: 'PATCH',
32
- body: params,
33
- });
34
- }
35
-
36
- /**
37
- * Deletes the memory thread
38
- * @returns Promise containing deletion result
39
- */
40
- delete(): Promise<{ result: string }> {
41
- return this.request(`/api/memory/threads/${this.threadId}?agentId=${this.agentId}`, {
42
- method: 'DELETE',
43
- });
44
- }
45
-
46
- /**
47
- * Retrieves messages associated with the thread
48
- * @returns Promise containing thread messages and UI messages
49
- */
50
- getMessages(): Promise<GetMemoryThreadMessagesResponse> {
51
- return this.request(`/api/memory/threads/${this.threadId}/messages?agentId=${this.agentId}`);
52
- }
53
- }
@@ -1,92 +0,0 @@
1
- import { processDataStream } from '@ai-sdk/ui-utils';
2
- import type { GenerateReturn } from '@mastra/core';
3
- import type { JSONSchema7 } from 'json-schema';
4
- import { ZodSchema } from 'zod';
5
- import { zodToJsonSchema } from 'zod-to-json-schema';
6
-
7
- import type { GenerateParams, ClientOptions, StreamParams, GetNetworkResponse } from '../types';
8
-
9
- import { BaseResource } from './base';
10
-
11
- export class Network extends BaseResource {
12
- constructor(
13
- options: ClientOptions,
14
- private networkId: string,
15
- ) {
16
- super(options);
17
- }
18
-
19
- /**
20
- * Retrieves details about the network
21
- * @returns Promise containing network details
22
- */
23
- details(): Promise<GetNetworkResponse> {
24
- return this.request(`/api/networks/${this.networkId}`);
25
- }
26
-
27
- /**
28
- * Generates a response from the agent
29
- * @param params - Generation parameters including prompt
30
- * @returns Promise containing the generated response
31
- */
32
- generate<T extends JSONSchema7 | ZodSchema | undefined = undefined>(
33
- params: GenerateParams<T>,
34
- ): Promise<GenerateReturn<T>> {
35
- const processedParams = {
36
- ...params,
37
- output: params.output instanceof ZodSchema ? zodToJsonSchema(params.output) : params.output,
38
- experimental_output:
39
- params.experimental_output instanceof ZodSchema
40
- ? zodToJsonSchema(params.experimental_output)
41
- : params.experimental_output,
42
- };
43
-
44
- return this.request(`/api/networks/${this.networkId}/generate`, {
45
- method: 'POST',
46
- body: processedParams,
47
- });
48
- }
49
-
50
- /**
51
- * Streams a response from the agent
52
- * @param params - Stream parameters including prompt
53
- * @returns Promise containing the enhanced Response object with processDataStream method
54
- */
55
- async stream<T extends JSONSchema7 | ZodSchema | undefined = undefined>(
56
- params: StreamParams<T>,
57
- ): Promise<
58
- Response & {
59
- processDataStream: (options?: Omit<Parameters<typeof processDataStream>[0], 'stream'>) => Promise<void>;
60
- }
61
- > {
62
- const processedParams = {
63
- ...params,
64
- output: params.output instanceof ZodSchema ? zodToJsonSchema(params.output) : params.output,
65
- experimental_output:
66
- params.experimental_output instanceof ZodSchema
67
- ? zodToJsonSchema(params.experimental_output)
68
- : params.experimental_output,
69
- };
70
-
71
- const response: Response & {
72
- processDataStream: (options?: Omit<Parameters<typeof processDataStream>[0], 'stream'>) => Promise<void>;
73
- } = await this.request(`/api/networks/${this.networkId}/stream`, {
74
- method: 'POST',
75
- body: processedParams,
76
- stream: true,
77
- });
78
-
79
- if (!response.body) {
80
- throw new Error('No response body');
81
- }
82
-
83
- response.processDataStream = async (options = {}) => {
84
- await processDataStream({
85
- stream: response.body as ReadableStream<Uint8Array>,
86
- ...options,
87
- });
88
- };
89
-
90
- return response;
91
- }
92
- }
@@ -1,38 +0,0 @@
1
- import type { GetToolResponse, ClientOptions } from '../types';
2
-
3
- import { BaseResource } from './base';
4
-
5
- export class Tool extends BaseResource {
6
- constructor(
7
- options: ClientOptions,
8
- private toolId: string,
9
- ) {
10
- super(options);
11
- }
12
-
13
- /**
14
- * Retrieves details about the tool
15
- * @returns Promise containing tool details including description and schemas
16
- */
17
- details(): Promise<GetToolResponse> {
18
- return this.request(`/api/tools/${this.toolId}`);
19
- }
20
-
21
- /**
22
- * Executes the tool with the provided parameters
23
- * @param params - Parameters required for tool execution
24
- * @returns Promise containing the tool execution results
25
- */
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()}`, {
34
- method: 'POST',
35
- body: params.data,
36
- });
37
- }
38
- }
@@ -1,83 +0,0 @@
1
- import type {
2
- CreateIndexParams,
3
- GetVectorIndexResponse,
4
- QueryVectorParams,
5
- QueryVectorResponse,
6
- ClientOptions,
7
- UpsertVectorParams,
8
- } from '../types';
9
-
10
- import { BaseResource } from './base';
11
-
12
- export class Vector extends BaseResource {
13
- constructor(
14
- options: ClientOptions,
15
- private vectorName: string,
16
- ) {
17
- super(options);
18
- }
19
-
20
- /**
21
- * Retrieves details about a specific vector index
22
- * @param indexName - Name of the index to get details for
23
- * @returns Promise containing vector index details
24
- */
25
- details(indexName: string): Promise<GetVectorIndexResponse> {
26
- return this.request(`/api/vector/${this.vectorName}/indexes/${indexName}`);
27
- }
28
-
29
- /**
30
- * Deletes a vector index
31
- * @param indexName - Name of the index to delete
32
- * @returns Promise indicating deletion success
33
- */
34
- delete(indexName: string): Promise<{ success: boolean }> {
35
- return this.request(`/api/vector/${this.vectorName}/indexes/${indexName}`, {
36
- method: 'DELETE',
37
- });
38
- }
39
-
40
- /**
41
- * Retrieves a list of all available indexes
42
- * @returns Promise containing array of index names
43
- */
44
- getIndexes(): Promise<{ indexes: string[] }> {
45
- return this.request(`/api/vector/${this.vectorName}/indexes`);
46
- }
47
-
48
- /**
49
- * Creates a new vector index
50
- * @param params - Parameters for index creation including dimension and metric
51
- * @returns Promise indicating creation success
52
- */
53
- createIndex(params: CreateIndexParams): Promise<{ success: boolean }> {
54
- return this.request(`/api/vector/${this.vectorName}/create-index`, {
55
- method: 'POST',
56
- body: params,
57
- });
58
- }
59
-
60
- /**
61
- * Upserts vectors into an index
62
- * @param params - Parameters containing vectors, metadata, and optional IDs
63
- * @returns Promise containing array of vector IDs
64
- */
65
- upsert(params: UpsertVectorParams): Promise<string[]> {
66
- return this.request(`/api/vector/${this.vectorName}/upsert`, {
67
- method: 'POST',
68
- body: params,
69
- });
70
- }
71
-
72
- /**
73
- * Queries vectors in an index
74
- * @param params - Query parameters including query vector and search options
75
- * @returns Promise containing query results
76
- */
77
- query(params: QueryVectorParams): Promise<QueryVectorResponse> {
78
- return this.request(`/api/vector/${this.vectorName}/query`, {
79
- method: 'POST',
80
- body: params,
81
- });
82
- }
83
- }