@mastra/client-js 0.0.0-inject-middleware-20250528222017 → 0.0.0-issue-7498-20250905233741

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 (78) hide show
  1. package/CHANGELOG.md +1370 -2
  2. package/LICENSE.md +11 -42
  3. package/README.md +7 -4
  4. package/dist/client.d.ts +280 -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 +2062 -286
  9. package/dist/index.cjs.map +1 -0
  10. package/dist/index.d.ts +4 -900
  11. package/dist/index.d.ts.map +1 -0
  12. package/dist/index.js +2064 -288
  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 +161 -0
  17. package/dist/resources/agent-builder.d.ts.map +1 -0
  18. package/dist/resources/agent.d.ts +155 -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 +13 -0
  23. package/dist/resources/index.d.ts.map +1 -0
  24. package/dist/resources/legacy-workflow.d.ts +87 -0
  25. package/dist/resources/legacy-workflow.d.ts.map +1 -0
  26. package/dist/resources/mcp-tool.d.ts +27 -0
  27. package/dist/resources/mcp-tool.d.ts.map +1 -0
  28. package/dist/resources/memory-thread.d.ts +53 -0
  29. package/dist/resources/memory-thread.d.ts.map +1 -0
  30. package/dist/resources/network-memory-thread.d.ts +47 -0
  31. package/dist/resources/network-memory-thread.d.ts.map +1 -0
  32. package/dist/resources/network.d.ts +30 -0
  33. package/dist/resources/network.d.ts.map +1 -0
  34. package/dist/resources/observability.d.ts +19 -0
  35. package/dist/resources/observability.d.ts.map +1 -0
  36. package/dist/resources/tool.d.ts +23 -0
  37. package/dist/resources/tool.d.ts.map +1 -0
  38. package/dist/resources/vNextNetwork.d.ts +42 -0
  39. package/dist/resources/vNextNetwork.d.ts.map +1 -0
  40. package/dist/resources/vector.d.ts +48 -0
  41. package/dist/resources/vector.d.ts.map +1 -0
  42. package/dist/resources/workflow.d.ts +154 -0
  43. package/dist/resources/workflow.d.ts.map +1 -0
  44. package/dist/types.d.ts +461 -0
  45. package/dist/types.d.ts.map +1 -0
  46. package/dist/utils/index.d.ts +3 -0
  47. package/dist/utils/index.d.ts.map +1 -0
  48. package/dist/utils/process-client-tools.d.ts +3 -0
  49. package/dist/utils/process-client-tools.d.ts.map +1 -0
  50. package/dist/utils/process-mastra-stream.d.ts +7 -0
  51. package/dist/utils/process-mastra-stream.d.ts.map +1 -0
  52. package/dist/utils/zod-to-json-schema.d.ts +3 -0
  53. package/dist/utils/zod-to-json-schema.d.ts.map +1 -0
  54. package/package.json +38 -21
  55. package/dist/index.d.cts +0 -900
  56. package/eslint.config.js +0 -6
  57. package/src/adapters/agui.test.ts +0 -180
  58. package/src/adapters/agui.ts +0 -239
  59. package/src/client.ts +0 -334
  60. package/src/example.ts +0 -64
  61. package/src/index.test.ts +0 -830
  62. package/src/index.ts +0 -2
  63. package/src/resources/a2a.ts +0 -88
  64. package/src/resources/agent.ts +0 -197
  65. package/src/resources/base.ts +0 -70
  66. package/src/resources/index.ts +0 -10
  67. package/src/resources/legacy-workflow.ts +0 -242
  68. package/src/resources/mcp-tool.ts +0 -48
  69. package/src/resources/memory-thread.ts +0 -63
  70. package/src/resources/network.ts +0 -86
  71. package/src/resources/tool.ts +0 -45
  72. package/src/resources/vector.ts +0 -83
  73. package/src/resources/workflow.ts +0 -353
  74. package/src/types.ts +0 -314
  75. package/src/utils/index.ts +0 -11
  76. package/src/utils/zod-to-json-schema.ts +0 -10
  77. package/tsconfig.json +0 -5
  78. package/vitest.config.js +0 -8
package/src/index.ts DELETED
@@ -1,2 +0,0 @@
1
- export * from './client';
2
- export * from './types';
@@ -1,88 +0,0 @@
1
- import type { TaskSendParams, TaskQueryParams, TaskIdParams, Task, AgentCard, JSONRPCResponse } from '@mastra/core/a2a';
2
- import type { ClientOptions } from '../types';
3
- import { BaseResource } from './base';
4
-
5
- /**
6
- * Class for interacting with an agent via the A2A protocol
7
- */
8
- export class A2A extends BaseResource {
9
- constructor(
10
- options: ClientOptions,
11
- private agentId: string,
12
- ) {
13
- super(options);
14
- }
15
-
16
- /**
17
- * Get the agent card with metadata about the agent
18
- * @returns Promise containing the agent card information
19
- */
20
- async getCard(): Promise<AgentCard> {
21
- return this.request(`/.well-known/${this.agentId}/agent.json`);
22
- }
23
-
24
- /**
25
- * Send a message to the agent and get a response
26
- * @param params - Parameters for the task
27
- * @returns Promise containing the task response
28
- */
29
- async sendMessage(params: TaskSendParams): Promise<{ task: Task }> {
30
- const response = await this.request<JSONRPCResponse<Task>>(`/a2a/${this.agentId}`, {
31
- method: 'POST',
32
- body: {
33
- method: 'tasks/send',
34
- params,
35
- },
36
- });
37
-
38
- return { task: response.result! };
39
- }
40
-
41
- /**
42
- * Get the status and result of a task
43
- * @param params - Parameters for querying the task
44
- * @returns Promise containing the task response
45
- */
46
- async getTask(params: TaskQueryParams): Promise<Task> {
47
- const response = await this.request<JSONRPCResponse<Task>>(`/a2a/${this.agentId}`, {
48
- method: 'POST',
49
- body: {
50
- method: 'tasks/get',
51
- params,
52
- },
53
- });
54
-
55
- return response.result!;
56
- }
57
-
58
- /**
59
- * Cancel a running task
60
- * @param params - Parameters identifying the task to cancel
61
- * @returns Promise containing the task response
62
- */
63
- async cancelTask(params: TaskIdParams): Promise<{ task: Task }> {
64
- return this.request(`/a2a/${this.agentId}`, {
65
- method: 'POST',
66
- body: {
67
- method: 'tasks/cancel',
68
- params,
69
- },
70
- });
71
- }
72
-
73
- /**
74
- * Send a message and subscribe to streaming updates (not fully implemented)
75
- * @param params - Parameters for the task
76
- * @returns Promise containing the task response
77
- */
78
- async sendAndSubscribe(params: TaskSendParams): Promise<Response> {
79
- return this.request(`/a2a/${this.agentId}`, {
80
- method: 'POST',
81
- body: {
82
- method: 'tasks/sendSubscribe',
83
- params,
84
- },
85
- stream: true,
86
- });
87
- }
88
- }
@@ -1,197 +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 '../utils/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
- import type { RuntimeContext } from '@mastra/core/runtime-context';
18
- import { parseClientRuntimeContext } from '../utils';
19
-
20
- export class AgentVoice extends BaseResource {
21
- constructor(
22
- options: ClientOptions,
23
- private agentId: string,
24
- ) {
25
- super(options);
26
- this.agentId = agentId;
27
- }
28
-
29
- /**
30
- * Convert text to speech using the agent's voice provider
31
- * @param text - Text to convert to speech
32
- * @param options - Optional provider-specific options for speech generation
33
- * @returns Promise containing the audio data
34
- */
35
- async speak(text: string, options?: { speaker?: string; [key: string]: any }): Promise<Response> {
36
- return this.request<Response>(`/api/agents/${this.agentId}/voice/speak`, {
37
- method: 'POST',
38
- headers: {
39
- 'Content-Type': 'application/json',
40
- },
41
- body: { input: text, options },
42
- stream: true,
43
- });
44
- }
45
-
46
- /**
47
- * Convert speech to text using the agent's voice provider
48
- * @param audio - Audio data to transcribe
49
- * @param options - Optional provider-specific options
50
- * @returns Promise containing the transcribed text
51
- */
52
- listen(audio: Blob, options?: Record<string, any>): Promise<{ text: string }> {
53
- const formData = new FormData();
54
- formData.append('audio', audio);
55
-
56
- if (options) {
57
- formData.append('options', JSON.stringify(options));
58
- }
59
-
60
- return this.request(`/api/agents/${this.agentId}/voice/listen`, {
61
- method: 'POST',
62
- body: formData,
63
- });
64
- }
65
-
66
- /**
67
- * Get available speakers for the agent's voice provider
68
- * @returns Promise containing list of available speakers
69
- */
70
- getSpeakers(): Promise<Array<{ voiceId: string; [key: string]: any }>> {
71
- return this.request(`/api/agents/${this.agentId}/voice/speakers`);
72
- }
73
- }
74
-
75
- export class Agent extends BaseResource {
76
- public readonly voice: AgentVoice;
77
-
78
- constructor(
79
- options: ClientOptions,
80
- private agentId: string,
81
- ) {
82
- super(options);
83
- this.voice = new AgentVoice(options, this.agentId);
84
- }
85
-
86
- /**
87
- * Retrieves details about the agent
88
- * @returns Promise containing agent details including model and instructions
89
- */
90
- details(): Promise<GetAgentResponse> {
91
- return this.request(`/api/agents/${this.agentId}`);
92
- }
93
-
94
- /**
95
- * Generates a response from the agent
96
- * @param params - Generation parameters including prompt
97
- * @returns Promise containing the generated response
98
- */
99
- generate<T extends JSONSchema7 | ZodSchema | undefined = undefined>(
100
- params: GenerateParams<T>,
101
- ): Promise<GenerateReturn<T>> {
102
- const processedParams = {
103
- ...params,
104
- output: params.output ? zodToJsonSchema(params.output) : undefined,
105
- experimental_output: params.experimental_output ? zodToJsonSchema(params.experimental_output) : undefined,
106
- runtimeContext: parseClientRuntimeContext(params.runtimeContext),
107
- };
108
-
109
- return this.request(`/api/agents/${this.agentId}/generate`, {
110
- method: 'POST',
111
- body: processedParams,
112
- });
113
- }
114
-
115
- /**
116
- * Streams a response from the agent
117
- * @param params - Stream parameters including prompt
118
- * @returns Promise containing the enhanced Response object with processDataStream method
119
- */
120
- async stream<T extends JSONSchema7 | ZodSchema | undefined = undefined>(
121
- params: StreamParams<T>,
122
- ): Promise<
123
- Response & {
124
- processDataStream: (options?: Omit<Parameters<typeof processDataStream>[0], 'stream'>) => Promise<void>;
125
- }
126
- > {
127
- const processedParams = {
128
- ...params,
129
- output: params.output ? zodToJsonSchema(params.output) : undefined,
130
- experimental_output: params.experimental_output ? zodToJsonSchema(params.experimental_output) : undefined,
131
- runtimeContext: parseClientRuntimeContext(params.runtimeContext),
132
- };
133
-
134
- const response: Response & {
135
- processDataStream: (options?: Omit<Parameters<typeof processDataStream>[0], 'stream'>) => Promise<void>;
136
- } = await this.request(`/api/agents/${this.agentId}/stream`, {
137
- method: 'POST',
138
- body: processedParams,
139
- stream: true,
140
- });
141
-
142
- if (!response.body) {
143
- throw new Error('No response body');
144
- }
145
-
146
- response.processDataStream = async (options = {}) => {
147
- await processDataStream({
148
- stream: response.body as ReadableStream<Uint8Array>,
149
- ...options,
150
- });
151
- };
152
-
153
- return response;
154
- }
155
-
156
- /**
157
- * Gets details about a specific tool available to the agent
158
- * @param toolId - ID of the tool to retrieve
159
- * @returns Promise containing tool details
160
- */
161
- getTool(toolId: string): Promise<GetToolResponse> {
162
- return this.request(`/api/agents/${this.agentId}/tools/${toolId}`);
163
- }
164
-
165
- /**
166
- * Executes a tool for the agent
167
- * @param toolId - ID of the tool to execute
168
- * @param params - Parameters required for tool execution
169
- * @returns Promise containing the tool execution results
170
- */
171
- executeTool(toolId: string, params: { data: any; runtimeContext?: RuntimeContext }): Promise<any> {
172
- const body = {
173
- data: params.data,
174
- runtimeContext: params.runtimeContext ? Object.fromEntries(params.runtimeContext.entries()) : undefined,
175
- };
176
- return this.request(`/api/agents/${this.agentId}/tools/${toolId}/execute`, {
177
- method: 'POST',
178
- body,
179
- });
180
- }
181
-
182
- /**
183
- * Retrieves evaluation results for the agent
184
- * @returns Promise containing agent evaluations
185
- */
186
- evals(): Promise<GetEvalsByAgentIdResponse> {
187
- return this.request(`/api/agents/${this.agentId}/evals/ci`);
188
- }
189
-
190
- /**
191
- * Retrieves live evaluation results for the agent
192
- * @returns Promise containing live agent evaluations
193
- */
194
- liveEvals(): Promise<GetEvalsByAgentIdResponse> {
195
- return this.request(`/api/agents/${this.agentId}/evals/live`);
196
- }
197
- }
@@ -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.replace(/\/$/, '')}${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,10 +0,0 @@
1
- export * from './agent';
2
- export * from './network';
3
- export * from './memory-thread';
4
- export * from './vector';
5
- export * from './legacy-workflow';
6
- export * from './tool';
7
- export * from './base';
8
- export * from './workflow';
9
- export * from './a2a';
10
- export * from './mcp-tool';
@@ -1,242 +0,0 @@
1
- import type {
2
- ClientOptions,
3
- LegacyWorkflowRunResult,
4
- GetLegacyWorkflowRunsResponse,
5
- GetWorkflowRunsParams,
6
- GetLegacyWorkflowResponse,
7
- } from '../types';
8
-
9
- import { BaseResource } from './base';
10
-
11
- const RECORD_SEPARATOR = '\x1E';
12
-
13
- export class LegacyWorkflow extends BaseResource {
14
- constructor(
15
- options: ClientOptions,
16
- private workflowId: string,
17
- ) {
18
- super(options);
19
- }
20
-
21
- /**
22
- * Retrieves details about the legacy workflow
23
- * @returns Promise containing legacy workflow details including steps and graphs
24
- */
25
- details(): Promise<GetLegacyWorkflowResponse> {
26
- return this.request(`/api/workflows/legacy/${this.workflowId}`);
27
- }
28
-
29
- /**
30
- * Retrieves all runs for a legacy workflow
31
- * @param params - Parameters for filtering runs
32
- * @returns Promise containing legacy workflow runs array
33
- */
34
- runs(params?: GetWorkflowRunsParams): Promise<GetLegacyWorkflowRunsResponse> {
35
- const searchParams = new URLSearchParams();
36
- if (params?.fromDate) {
37
- searchParams.set('fromDate', params.fromDate.toISOString());
38
- }
39
- if (params?.toDate) {
40
- searchParams.set('toDate', params.toDate.toISOString());
41
- }
42
- if (params?.limit) {
43
- searchParams.set('limit', String(params.limit));
44
- }
45
- if (params?.offset) {
46
- searchParams.set('offset', String(params.offset));
47
- }
48
- if (params?.resourceId) {
49
- searchParams.set('resourceId', params.resourceId);
50
- }
51
-
52
- if (searchParams.size) {
53
- return this.request(`/api/workflows/legacy/${this.workflowId}/runs?${searchParams}`);
54
- } else {
55
- return this.request(`/api/workflows/legacy/${this.workflowId}/runs`);
56
- }
57
- }
58
-
59
- /**
60
- * Creates a new legacy workflow run
61
- * @returns Promise containing the generated run ID
62
- */
63
- createRun(params?: { runId?: string }): Promise<{ runId: string }> {
64
- const searchParams = new URLSearchParams();
65
-
66
- if (!!params?.runId) {
67
- searchParams.set('runId', params.runId);
68
- }
69
-
70
- return this.request(`/api/workflows/legacy/${this.workflowId}/create-run?${searchParams.toString()}`, {
71
- method: 'POST',
72
- });
73
- }
74
-
75
- /**
76
- * Starts a legacy workflow run synchronously without waiting for the workflow to complete
77
- * @param params - Object containing the runId and triggerData
78
- * @returns Promise containing success message
79
- */
80
- start(params: { runId: string; triggerData: Record<string, any> }): Promise<{ message: string }> {
81
- return this.request(`/api/workflows/legacy/${this.workflowId}/start?runId=${params.runId}`, {
82
- method: 'POST',
83
- body: params?.triggerData,
84
- });
85
- }
86
-
87
- /**
88
- * Resumes a suspended legacy workflow step synchronously without waiting for the workflow to complete
89
- * @param stepId - ID of the step to resume
90
- * @param runId - ID of the legacy workflow run
91
- * @param context - Context to resume the legacy workflow with
92
- * @returns Promise containing the legacy workflow resume results
93
- */
94
- resume({
95
- stepId,
96
- runId,
97
- context,
98
- }: {
99
- stepId: string;
100
- runId: string;
101
- context: Record<string, any>;
102
- }): Promise<{ message: string }> {
103
- return this.request(`/api/workflows/legacy/${this.workflowId}/resume?runId=${runId}`, {
104
- method: 'POST',
105
- body: {
106
- stepId,
107
- context,
108
- },
109
- });
110
- }
111
-
112
- /**
113
- * Starts a workflow run asynchronously and returns a promise that resolves when the workflow is complete
114
- * @param params - Object containing the optional runId and triggerData
115
- * @returns Promise containing the workflow execution results
116
- */
117
- startAsync(params: { runId?: string; triggerData: Record<string, any> }): Promise<LegacyWorkflowRunResult> {
118
- const searchParams = new URLSearchParams();
119
-
120
- if (!!params?.runId) {
121
- searchParams.set('runId', params.runId);
122
- }
123
-
124
- return this.request(`/api/workflows/legacy/${this.workflowId}/start-async?${searchParams.toString()}`, {
125
- method: 'POST',
126
- body: params?.triggerData,
127
- });
128
- }
129
-
130
- /**
131
- * Resumes a suspended legacy workflow step asynchronously and returns a promise that resolves when the workflow is complete
132
- * @param params - Object containing the runId, stepId, and context
133
- * @returns Promise containing the workflow resume results
134
- */
135
- resumeAsync(params: {
136
- runId: string;
137
- stepId: string;
138
- context: Record<string, any>;
139
- }): Promise<LegacyWorkflowRunResult> {
140
- return this.request(`/api/workflows/legacy/${this.workflowId}/resume-async?runId=${params.runId}`, {
141
- method: 'POST',
142
- body: {
143
- stepId: params.stepId,
144
- context: params.context,
145
- },
146
- });
147
- }
148
-
149
- /**
150
- * Creates an async generator that processes a readable stream and yields records
151
- * separated by the Record Separator character (\x1E)
152
- *
153
- * @param stream - The readable stream to process
154
- * @returns An async generator that yields parsed records
155
- */
156
- private async *streamProcessor(stream: ReadableStream): AsyncGenerator<LegacyWorkflowRunResult, void, unknown> {
157
- const reader = stream.getReader();
158
-
159
- // Track if we've finished reading from the stream
160
- let doneReading = false;
161
- // Buffer to accumulate partial chunks
162
- let buffer = '';
163
-
164
- try {
165
- while (!doneReading) {
166
- // Read the next chunk from the stream
167
- const { done, value } = await reader.read();
168
- doneReading = done;
169
-
170
- // Skip processing if we're done and there's no value
171
- if (done && !value) continue;
172
-
173
- try {
174
- // Decode binary data to text
175
- const decoded = value ? new TextDecoder().decode(value) : '';
176
-
177
- // Split the combined buffer and new data by record separator
178
- const chunks = (buffer + decoded).split(RECORD_SEPARATOR);
179
-
180
- // The last chunk might be incomplete, so save it for the next iteration
181
- buffer = chunks.pop() || '';
182
-
183
- // Process complete chunks
184
- for (const chunk of chunks) {
185
- if (chunk) {
186
- // Only process non-empty chunks
187
- if (typeof chunk === 'string') {
188
- try {
189
- const parsedChunk = JSON.parse(chunk);
190
- yield parsedChunk;
191
- } catch {
192
- // Silently ignore parsing errors to maintain stream processing
193
- // This allows the stream to continue even if one record is malformed
194
- }
195
- }
196
- }
197
- }
198
- } catch {
199
- // Silently ignore parsing errors to maintain stream processing
200
- // This allows the stream to continue even if one record is malformed
201
- }
202
- }
203
-
204
- // Process any remaining data in the buffer after stream is done
205
- if (buffer) {
206
- try {
207
- yield JSON.parse(buffer);
208
- } catch {
209
- // Ignore parsing error for final chunk
210
- }
211
- }
212
- } finally {
213
- // Always ensure we clean up the reader
214
- reader.cancel().catch(() => {
215
- // Ignore cancel errors
216
- });
217
- }
218
- }
219
-
220
- /**
221
- * Watches legacy workflow transitions in real-time
222
- * @param runId - Optional run ID to filter the watch stream
223
- * @returns AsyncGenerator that yields parsed records from the legacy workflow watch stream
224
- */
225
- async watch({ runId }: { runId?: string }, onRecord: (record: LegacyWorkflowRunResult) => void) {
226
- const response: Response = await this.request(`/api/workflows/legacy/${this.workflowId}/watch?runId=${runId}`, {
227
- stream: true,
228
- });
229
-
230
- if (!response.ok) {
231
- throw new Error(`Failed to watch legacy workflow: ${response.statusText}`);
232
- }
233
-
234
- if (!response.body) {
235
- throw new Error('Response body is null');
236
- }
237
-
238
- for await (const record of this.streamProcessor(response.body)) {
239
- onRecord(record);
240
- }
241
- }
242
- }
@@ -1,48 +0,0 @@
1
- import type { RuntimeContext } from '@mastra/core/runtime-context';
2
- import type { ClientOptions, McpToolInfo } from '../types';
3
- import { BaseResource } from './base';
4
-
5
- /**
6
- * Represents a specific tool available on a specific MCP server.
7
- * Provides methods to get details and execute the tool.
8
- */
9
- export class MCPTool extends BaseResource {
10
- private serverId: string;
11
- private toolId: string;
12
-
13
- constructor(options: ClientOptions, serverId: string, toolId: string) {
14
- super(options);
15
- this.serverId = serverId;
16
- this.toolId = toolId;
17
- }
18
-
19
- /**
20
- * Retrieves details about this specific tool from the MCP server.
21
- * @returns Promise containing the tool's information (name, description, schema).
22
- */
23
- details(): Promise<McpToolInfo> {
24
- return this.request(`/api/mcp/${this.serverId}/tools/${this.toolId}`);
25
- }
26
-
27
- /**
28
- * Executes this specific tool on the MCP server.
29
- * @param params - Parameters for tool execution, including data/args and optional runtimeContext.
30
- * @returns Promise containing the result of the tool execution.
31
- */
32
- execute(params: { data?: any; runtimeContext?: RuntimeContext }): Promise<any> {
33
- const body: any = {};
34
- if (params.data !== undefined) body.data = params.data;
35
- // If none of data, args the body might be empty or just contain runtimeContext.
36
- // The handler will look for these, so an empty args object might be appropriate if that's the intent.
37
- // else body.data = {}; // Or let it be empty if no specific input fields are used
38
-
39
- if (params.runtimeContext !== undefined) {
40
- body.runtimeContext = params.runtimeContext;
41
- }
42
-
43
- return this.request(`/api/mcp/${this.serverId}/tools/${this.toolId}/execute`, {
44
- method: 'POST',
45
- body: Object.keys(body).length > 0 ? body : undefined,
46
- });
47
- }
48
- }