@mastra/client-js 0.0.0-afterToolExecute-20250414225911 → 0.0.0-agui-20250501182100

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.
@@ -0,0 +1,219 @@
1
+ // Cross-platform UUID generation function
2
+ import { AbstractAgent, EventType } from '@ag-ui/client';
3
+ import type {
4
+ BaseEvent,
5
+ RunAgentInput,
6
+ AgentConfig,
7
+ RunStartedEvent,
8
+ RunFinishedEvent,
9
+ TextMessageStartEvent,
10
+ TextMessageContentEvent,
11
+ TextMessageEndEvent,
12
+ Message,
13
+ ToolCallStartEvent,
14
+ ToolCallArgsEvent,
15
+ ToolCallEndEvent,
16
+ } from '@ag-ui/client';
17
+ import type { CoreMessage } from '@mastra/core';
18
+ import { Observable } from 'rxjs';
19
+ import type { Agent } from '../resources/agent';
20
+
21
+ interface MastraAgentConfig extends AgentConfig {
22
+ agent: Agent;
23
+ agentId: string;
24
+ resourceId?: string;
25
+ }
26
+
27
+ export class AGUIAdapter extends AbstractAgent {
28
+ agent: Agent;
29
+ resourceId?: string;
30
+ constructor({ agent, agentId, resourceId, ...rest }: MastraAgentConfig) {
31
+ super({
32
+ agentId,
33
+ ...rest,
34
+ });
35
+ this.agent = agent;
36
+ this.resourceId = resourceId;
37
+ }
38
+
39
+ protected run(input: RunAgentInput): Observable<BaseEvent> {
40
+ return new Observable<BaseEvent>(subscriber => {
41
+ const convertedMessages = convertMessagesToMastraMessages(input.messages);
42
+
43
+ subscriber.next({
44
+ type: EventType.RUN_STARTED,
45
+ threadId: input.threadId,
46
+ runId: input.runId,
47
+ } as RunStartedEvent);
48
+
49
+ this.agent
50
+ .stream({
51
+ threadId: input.threadId,
52
+ resourceId: this.resourceId ?? '',
53
+ runId: input.runId,
54
+ messages: convertedMessages,
55
+ clientTools: input.tools.reduce(
56
+ (acc, tool) => {
57
+ acc[tool.name as string] = {
58
+ id: tool.name,
59
+ description: tool.description,
60
+ inputSchema: tool.parameters,
61
+ };
62
+ return acc;
63
+ },
64
+ {} as Record<string, any>,
65
+ ),
66
+ })
67
+ .then(response => {
68
+ let currentMessageId: string | undefined = undefined;
69
+ return response.processDataStream({
70
+ onTextPart: text => {
71
+ if (currentMessageId === undefined) {
72
+ currentMessageId = generateUUID();
73
+
74
+ const message: TextMessageStartEvent = {
75
+ type: EventType.TEXT_MESSAGE_START,
76
+ messageId: currentMessageId,
77
+ role: 'assistant',
78
+ };
79
+ subscriber.next(message);
80
+ }
81
+
82
+ const message: TextMessageContentEvent = {
83
+ type: EventType.TEXT_MESSAGE_CONTENT,
84
+ messageId: currentMessageId,
85
+ delta: text,
86
+ };
87
+ subscriber.next(message);
88
+ },
89
+ onFinishMessagePart: message => {
90
+ console.log('onFinishMessagePart', message);
91
+ if (currentMessageId !== undefined) {
92
+ const message: TextMessageEndEvent = {
93
+ type: EventType.TEXT_MESSAGE_END,
94
+ messageId: currentMessageId,
95
+ };
96
+ subscriber.next(message);
97
+ }
98
+ // Emit run finished event
99
+ subscriber.next({
100
+ type: EventType.RUN_FINISHED,
101
+ threadId: input.threadId,
102
+ runId: input.runId,
103
+ } as RunFinishedEvent);
104
+
105
+ // Complete the observable
106
+ subscriber.complete();
107
+ },
108
+ onToolCallPart(streamPart) {
109
+ const parentMessageId = currentMessageId || generateUUID();
110
+ subscriber.next({
111
+ type: EventType.TOOL_CALL_START,
112
+ toolCallId: streamPart.toolCallId,
113
+ toolCallName: streamPart.toolName,
114
+ parentMessageId,
115
+ } as ToolCallStartEvent);
116
+
117
+ subscriber.next({
118
+ type: EventType.TOOL_CALL_ARGS,
119
+ toolCallId: streamPart.toolCallId,
120
+ delta: JSON.stringify(streamPart.args),
121
+ parentMessageId,
122
+ } as ToolCallArgsEvent);
123
+
124
+ subscriber.next({
125
+ type: EventType.TOOL_CALL_END,
126
+ toolCallId: streamPart.toolCallId,
127
+ parentMessageId,
128
+ } as ToolCallEndEvent);
129
+ },
130
+ });
131
+ })
132
+ .catch(error => {
133
+ console.log('error', error);
134
+ // Handle error
135
+ subscriber.error(error);
136
+ });
137
+
138
+ return () => {};
139
+ });
140
+ }
141
+ }
142
+
143
+ /**
144
+ * Generates a UUID v4 that works in both browser and Node.js environments
145
+ */
146
+ export function generateUUID(): string {
147
+ // Use crypto.randomUUID() if available (Node.js environment or modern browsers)
148
+ if (typeof crypto !== 'undefined') {
149
+ // Browser crypto API or Node.js crypto global
150
+ if (typeof crypto.randomUUID === 'function') {
151
+ return crypto.randomUUID();
152
+ }
153
+ // Fallback for older browsers
154
+ if (typeof crypto.getRandomValues === 'function') {
155
+ const buffer = new Uint8Array(16);
156
+ crypto.getRandomValues(buffer);
157
+ // Set version (4) and variant (8, 9, A, or B)
158
+ buffer[6] = (buffer[6]! & 0x0f) | 0x40; // version 4
159
+ buffer[8] = (buffer[8]! & 0x3f) | 0x80; // variant
160
+
161
+ // Convert to hex string in UUID format
162
+ let hex = '';
163
+ for (let i = 0; i < 16; i++) {
164
+ hex += buffer[i]!.toString(16).padStart(2, '0');
165
+ // Add hyphens at standard positions
166
+ if (i === 3 || i === 5 || i === 7 || i === 9) hex += '-';
167
+ }
168
+ return hex;
169
+ }
170
+ }
171
+
172
+ // Last resort fallback (less secure but works everywhere)
173
+ return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, c => {
174
+ const r = (Math.random() * 16) | 0;
175
+ const v = c === 'x' ? r : (r & 0x3) | 0x8;
176
+ return v.toString(16);
177
+ });
178
+ }
179
+
180
+ export function convertMessagesToMastraMessages(messages: Message[]): CoreMessage[] {
181
+ const result: CoreMessage[] = [];
182
+
183
+ for (const message of messages) {
184
+ if (message.role === 'assistant') {
185
+ const parts: any[] = message.content ? [{ type: 'text', text: message.content }] : [];
186
+ for (const toolCall of message.toolCalls ?? []) {
187
+ parts.push({
188
+ type: 'tool-call',
189
+ toolCallId: toolCall.id,
190
+ toolName: toolCall.function.name,
191
+ args: JSON.parse(toolCall.function.arguments),
192
+ });
193
+ }
194
+ result.push({
195
+ role: 'assistant',
196
+ content: parts,
197
+ });
198
+ } else if (message.role === 'user') {
199
+ result.push({
200
+ role: 'user',
201
+ content: message.content || '',
202
+ });
203
+ } else if (message.role === 'tool') {
204
+ result.push({
205
+ role: 'tool',
206
+ content: [
207
+ {
208
+ type: 'tool-result',
209
+ toolCallId: message.toolCallId,
210
+ toolName: 'unknown',
211
+ result: message.content,
212
+ },
213
+ ],
214
+ });
215
+ }
216
+ }
217
+
218
+ return result;
219
+ }
package/src/client.ts CHANGED
@@ -1,4 +1,5 @@
1
- import { Agent, MemoryThread, Tool, Workflow, Vector, BaseResource, Network } from './resources';
1
+ import { AGUIAdapter } from './adapters/agui';
2
+ import { Agent, MemoryThread, Tool, Workflow, Vector, BaseResource, Network, VNextWorkflow } from './resources';
2
3
  import type {
3
4
  ClientOptions,
4
5
  CreateMemoryThreadParams,
@@ -13,6 +14,7 @@ import type {
13
14
  GetTelemetryParams,
14
15
  GetTelemetryResponse,
15
16
  GetToolResponse,
17
+ GetVNextWorkflowResponse,
16
18
  GetWorkflowResponse,
17
19
  SaveMessageToMemoryParams,
18
20
  SaveMessageToMemoryResponse,
@@ -31,6 +33,23 @@ export class MastraClient extends BaseResource {
31
33
  return this.request('/api/agents');
32
34
  }
33
35
 
36
+ public async getAGUI(): Promise<Record<string, AGUIAdapter>> {
37
+ const agents = (await this.request('/api/agents/gui')) as Record<string, GetAgentResponse>;
38
+
39
+ return Object.entries(agents).reduce(
40
+ (acc, [agentId]) => {
41
+ const agent = this.getAgent(agentId);
42
+ acc[agentId] = new AGUIAdapter({
43
+ agentId,
44
+ agent,
45
+ });
46
+
47
+ return acc;
48
+ },
49
+ {} as Record<string, AGUIAdapter>,
50
+ );
51
+ }
52
+
34
53
  /**
35
54
  * Gets an agent instance by ID
36
55
  * @param agentId - ID of the agent to retrieve
@@ -121,6 +140,23 @@ export class MastraClient extends BaseResource {
121
140
  return new Workflow(this.options, workflowId);
122
141
  }
123
142
 
143
+ /**
144
+ * Retrieves all available vNext workflows
145
+ * @returns Promise containing map of vNext workflow IDs to vNext workflow details
146
+ */
147
+ public getVNextWorkflows(): Promise<Record<string, GetVNextWorkflowResponse>> {
148
+ return this.request('/api/workflows/v-next');
149
+ }
150
+
151
+ /**
152
+ * Gets a vNext workflow instance by ID
153
+ * @param workflowId - ID of the vNext workflow to retrieve
154
+ * @returns vNext Workflow instance
155
+ */
156
+ public getVNextWorkflow(workflowId: string) {
157
+ return new VNextWorkflow(this.options, workflowId);
158
+ }
159
+
124
160
  /**
125
161
  * Gets a vector instance by name
126
162
  * @param vectorName - Name of the vector to retrieve
@@ -165,14 +201,6 @@ export class MastraClient extends BaseResource {
165
201
  const { name, scope, page, perPage, attribute } = params || {};
166
202
  const _attribute = attribute ? Object.entries(attribute).map(([key, value]) => `${key}:${value}`) : [];
167
203
 
168
- const queryObj = {
169
- ...(name ? { name } : {}),
170
- ...(scope ? { scope } : {}),
171
- ...(page ? { page: String(page) } : {}),
172
- ...(perPage ? { perPage: String(perPage) } : {}),
173
- ...(_attribute?.length ? { attribute: _attribute } : {}),
174
- } as const;
175
-
176
204
  const searchParams = new URLSearchParams();
177
205
  if (name) {
178
206
  searchParams.set('name', name);
package/src/index.test.ts CHANGED
@@ -1,4 +1,3 @@
1
- import type { MessageType } from '@mastra/core';
2
1
  import { describe, expect, beforeEach, it, vi } from 'vitest';
3
2
 
4
3
  import { MastraClient } from './client';
@@ -489,7 +488,7 @@ describe('MastraClient Resources', () => {
489
488
  const result = await memoryThread.update({
490
489
  title: 'Updated Thread',
491
490
  metadata: { updated: true },
492
- resourceid: 'test-resource',
491
+ resourceId: 'test-resource',
493
492
  });
494
493
  expect(result).toEqual(mockResponse);
495
494
  expect(global.fetch).toHaveBeenCalledWith(
@@ -536,6 +535,7 @@ describe('MastraClient Resources', () => {
536
535
  content: 'test',
537
536
  role: 'user' as const,
538
537
  threadId: 'test-thread',
538
+ resourceId: 'test-resource',
539
539
  createdAt: new Date('2025-03-26T10:40:55.116Z'),
540
540
  },
541
541
  ];
@@ -584,10 +584,10 @@ describe('MastraClient Resources', () => {
584
584
  it('should execute tool', async () => {
585
585
  const mockResponse = { data: 'test' };
586
586
  mockFetchResponse(mockResponse);
587
- const result = await tool.execute({ data: '' });
587
+ const result = await tool.execute({ data: '', runId: 'test-run-id' });
588
588
  expect(result).toEqual(mockResponse);
589
589
  expect(global.fetch).toHaveBeenCalledWith(
590
- `${clientOptions.baseUrl}/api/tools/test-tool/execute`,
590
+ `${clientOptions.baseUrl}/api/tools/test-tool/execute?runId=test-run-id`,
591
591
  expect.objectContaining({
592
592
  method: 'POST',
593
593
  headers: expect.objectContaining({
@@ -29,7 +29,6 @@ export class AgentTool extends BaseResource {
29
29
  * @param params - Parameters required for tool execution
30
30
  * @returns Promise containing tool execution results
31
31
  */
32
- /** @deprecated use CreateRun/startRun */
33
32
  execute(params: { data: any }): Promise<any> {
34
33
  return this.request(`/api/agents/${this.agentId}/tools/${this.toolId}/execute`, {
35
34
  method: 'POST',
@@ -1,4 +1,4 @@
1
- import type { RequestFunction, RequestOptions, ClientOptions } from '../types';
1
+ import type { RequestOptions, ClientOptions } from '../types';
2
2
 
3
3
  export class BaseResource {
4
4
  readonly options: ClientOptions;
@@ -5,3 +5,4 @@ export * from './vector';
5
5
  export * from './workflow';
6
6
  export * from './tool';
7
7
  export * from './base';
8
+ export * from './vnext-workflow';
@@ -1,13 +1,6 @@
1
1
  import type { StorageThreadType } from '@mastra/core';
2
2
 
3
- import type {
4
- CreateMemoryThreadParams,
5
- GetMemoryThreadMessagesResponse,
6
- GetMemoryThreadResponse,
7
- ClientOptions,
8
- SaveMessageToMemoryParams,
9
- UpdateMemoryThreadParams,
10
- } from '../types';
3
+ import type { GetMemoryThreadMessagesResponse, ClientOptions, UpdateMemoryThreadParams } from '../types';
11
4
 
12
5
  import { BaseResource } from './base';
13
6
 
@@ -1,3 +1,4 @@
1
+ import { processDataStream } from '@ai-sdk/ui-utils';
1
2
  import type { GenerateReturn } from '@mastra/core';
2
3
  import type { JSONSchema7 } from 'json-schema';
3
4
  import { ZodSchema } from 'zod';
@@ -6,7 +7,6 @@ import { zodToJsonSchema } from 'zod-to-json-schema';
6
7
  import type { GenerateParams, ClientOptions, StreamParams, GetNetworkResponse } from '../types';
7
8
 
8
9
  import { BaseResource } from './base';
9
- import { processDataStream } from '@ai-sdk/ui-utils';
10
10
 
11
11
  export class Network extends BaseResource {
12
12
  constructor(
@@ -23,10 +23,16 @@ export class Tool extends BaseResource {
23
23
  * @param params - Parameters required for tool execution
24
24
  * @returns Promise containing the tool execution results
25
25
  */
26
- execute(params: { data: any }): Promise<any> {
27
- return this.request(`/api/tools/${this.toolId}/execute`, {
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()}`, {
28
34
  method: 'POST',
29
- body: params,
35
+ body: params.data,
30
36
  });
31
37
  }
32
38
  }
@@ -0,0 +1,234 @@
1
+ import type { RuntimeContext } from '@mastra/core/runtime-context';
2
+ import type {
3
+ ClientOptions,
4
+ GetVNextWorkflowResponse,
5
+ GetWorkflowRunsResponse,
6
+ VNextWorkflowRunResult,
7
+ VNextWorkflowWatchResult,
8
+ } from '../types';
9
+
10
+ import { BaseResource } from './base';
11
+
12
+ const RECORD_SEPARATOR = '\x1E';
13
+
14
+ export class VNextWorkflow extends BaseResource {
15
+ constructor(
16
+ options: ClientOptions,
17
+ private workflowId: string,
18
+ ) {
19
+ super(options);
20
+ }
21
+
22
+ /**
23
+ * Creates an async generator that processes a readable stream and yields vNext workflow records
24
+ * separated by the Record Separator character (\x1E)
25
+ *
26
+ * @param stream - The readable stream to process
27
+ * @returns An async generator that yields parsed records
28
+ */
29
+ private async *streamProcessor(stream: ReadableStream): AsyncGenerator<VNextWorkflowWatchResult, void, unknown> {
30
+ const reader = stream.getReader();
31
+
32
+ // Track if we've finished reading from the stream
33
+ let doneReading = false;
34
+ // Buffer to accumulate partial chunks
35
+ let buffer = '';
36
+
37
+ try {
38
+ while (!doneReading) {
39
+ // Read the next chunk from the stream
40
+ const { done, value } = await reader.read();
41
+ doneReading = done;
42
+
43
+ // Skip processing if we're done and there's no value
44
+ if (done && !value) continue;
45
+
46
+ try {
47
+ // Decode binary data to text
48
+ const decoded = value ? new TextDecoder().decode(value) : '';
49
+
50
+ // Split the combined buffer and new data by record separator
51
+ const chunks = (buffer + decoded).split(RECORD_SEPARATOR);
52
+
53
+ // The last chunk might be incomplete, so save it for the next iteration
54
+ buffer = chunks.pop() || '';
55
+
56
+ // Process complete chunks
57
+ for (const chunk of chunks) {
58
+ if (chunk) {
59
+ // Only process non-empty chunks
60
+ if (typeof chunk === 'string') {
61
+ try {
62
+ const parsedChunk = JSON.parse(chunk);
63
+ yield parsedChunk;
64
+ } catch {
65
+ // Silently ignore parsing errors to maintain stream processing
66
+ // This allows the stream to continue even if one record is malformed
67
+ }
68
+ }
69
+ }
70
+ }
71
+ } catch {
72
+ // Silently ignore parsing errors to maintain stream processing
73
+ // This allows the stream to continue even if one record is malformed
74
+ }
75
+ }
76
+
77
+ // Process any remaining data in the buffer after stream is done
78
+ if (buffer) {
79
+ try {
80
+ yield JSON.parse(buffer);
81
+ } catch {
82
+ // Ignore parsing error for final chunk
83
+ }
84
+ }
85
+ } finally {
86
+ // Always ensure we clean up the reader
87
+ reader.cancel().catch(() => {
88
+ // Ignore cancel errors
89
+ });
90
+ }
91
+ }
92
+
93
+ /**
94
+ * Retrieves details about the vNext workflow
95
+ * @returns Promise containing vNext workflow details including steps and graphs
96
+ */
97
+ details(): Promise<GetVNextWorkflowResponse> {
98
+ return this.request(`/api/workflows/v-next/${this.workflowId}`);
99
+ }
100
+
101
+ /**
102
+ * Retrieves all runs for a vNext workflow
103
+ * @returns Promise containing vNext workflow runs array
104
+ */
105
+ runs(): Promise<GetWorkflowRunsResponse> {
106
+ return this.request(`/api/workflows/v-next/${this.workflowId}/runs`);
107
+ }
108
+
109
+ /**
110
+ * Creates a new vNext workflow run
111
+ * @param params - Optional object containing the optional runId
112
+ * @returns Promise containing the runId of the created run
113
+ */
114
+ createRun(params?: { runId?: string }): Promise<{ runId: string }> {
115
+ const searchParams = new URLSearchParams();
116
+
117
+ if (!!params?.runId) {
118
+ searchParams.set('runId', params.runId);
119
+ }
120
+
121
+ return this.request(`/api/workflows/v-next/${this.workflowId}/create-run?${searchParams.toString()}`, {
122
+ method: 'POST',
123
+ });
124
+ }
125
+
126
+ /**
127
+ * Starts a vNext workflow run synchronously without waiting for the workflow to complete
128
+ * @param params - Object containing the runId, inputData and runtimeContext
129
+ * @returns Promise containing success message
130
+ */
131
+ start(params: {
132
+ runId: string;
133
+ inputData: Record<string, any>;
134
+ runtimeContext?: RuntimeContext;
135
+ }): Promise<{ message: string }> {
136
+ return this.request(`/api/workflows/v-next/${this.workflowId}/start?runId=${params.runId}`, {
137
+ method: 'POST',
138
+ body: { inputData: params?.inputData, runtimeContext: params.runtimeContext },
139
+ });
140
+ }
141
+
142
+ /**
143
+ * Resumes a suspended vNext workflow step synchronously without waiting for the vNext workflow to complete
144
+ * @param params - Object containing the runId, step, resumeData and runtimeContext
145
+ * @returns Promise containing success message
146
+ */
147
+ resume({
148
+ step,
149
+ runId,
150
+ resumeData,
151
+ runtimeContext,
152
+ }: {
153
+ step: string | string[];
154
+ runId: string;
155
+ resumeData?: Record<string, any>;
156
+ runtimeContext?: RuntimeContext;
157
+ }): Promise<{ message: string }> {
158
+ return this.request(`/api/workflows/v-next/${this.workflowId}/resume?runId=${runId}`, {
159
+ method: 'POST',
160
+ stream: true,
161
+ body: {
162
+ step,
163
+ resumeData,
164
+ runtimeContext,
165
+ },
166
+ });
167
+ }
168
+
169
+ /**
170
+ * Starts a vNext workflow run asynchronously and returns a promise that resolves when the vNext workflow is complete
171
+ * @param params - Object containing the optional runId, inputData and runtimeContext
172
+ * @returns Promise containing the vNext workflow execution results
173
+ */
174
+ startAsync(params: {
175
+ runId?: string;
176
+ inputData: Record<string, any>;
177
+ runtimeContext?: RuntimeContext;
178
+ }): Promise<VNextWorkflowRunResult> {
179
+ const searchParams = new URLSearchParams();
180
+
181
+ if (!!params?.runId) {
182
+ searchParams.set('runId', params.runId);
183
+ }
184
+
185
+ return this.request(`/api/workflows/v-next/${this.workflowId}/start-async?${searchParams.toString()}`, {
186
+ method: 'POST',
187
+ body: { inputData: params.inputData, runtimeContext: params.runtimeContext },
188
+ });
189
+ }
190
+
191
+ /**
192
+ * Resumes a suspended vNext workflow step asynchronously and returns a promise that resolves when the vNext workflow is complete
193
+ * @param params - Object containing the runId, step, resumeData and runtimeContext
194
+ * @returns Promise containing the vNext workflow resume results
195
+ */
196
+ resumeAsync(params: {
197
+ runId: string;
198
+ step: string | string[];
199
+ resumeData?: Record<string, any>;
200
+ runtimeContext?: RuntimeContext;
201
+ }): Promise<VNextWorkflowRunResult> {
202
+ return this.request(`/api/workflows/v-next/${this.workflowId}/resume-async?runId=${params.runId}`, {
203
+ method: 'POST',
204
+ body: {
205
+ step: params.step,
206
+ resumeData: params.resumeData,
207
+ runtimeContext: params.runtimeContext,
208
+ },
209
+ });
210
+ }
211
+
212
+ /**
213
+ * Watches vNext workflow transitions in real-time
214
+ * @param runId - Optional run ID to filter the watch stream
215
+ * @returns AsyncGenerator that yields parsed records from the vNext workflow watch stream
216
+ */
217
+ async watch({ runId }: { runId?: string }, onRecord: (record: VNextWorkflowWatchResult) => void) {
218
+ const response: Response = await this.request(`/api/workflows/v-next/${this.workflowId}/watch?runId=${runId}`, {
219
+ stream: true,
220
+ });
221
+
222
+ if (!response.ok) {
223
+ throw new Error(`Failed to watch vNext workflow: ${response.statusText}`);
224
+ }
225
+
226
+ if (!response.body) {
227
+ throw new Error('Response body is null');
228
+ }
229
+
230
+ for await (const record of this.streamProcessor(response.body)) {
231
+ onRecord(record);
232
+ }
233
+ }
234
+ }
@@ -1,4 +1,4 @@
1
- import type { GetWorkflowResponse, ClientOptions, WorkflowRunResult } from '../types';
1
+ import type { GetWorkflowResponse, ClientOptions, WorkflowRunResult, GetWorkflowRunsResponse } from '../types';
2
2
 
3
3
  import { BaseResource } from './base';
4
4
 
@@ -20,6 +20,14 @@ export class Workflow extends BaseResource {
20
20
  return this.request(`/api/workflows/${this.workflowId}`);
21
21
  }
22
22
 
23
+ /**
24
+ * Retrieves all runs for a workflow
25
+ * @returns Promise containing workflow runs array
26
+ */
27
+ runs(): Promise<GetWorkflowRunsResponse> {
28
+ return this.request(`/api/workflows/${this.workflowId}/runs`);
29
+ }
30
+
23
31
  /**
24
32
  * @deprecated Use `startAsync` instead
25
33
  * Executes the workflow with the provided parameters
@@ -168,7 +176,7 @@ export class Workflow extends BaseResource {
168
176
  }
169
177
  }
170
178
  }
171
- } catch (error) {
179
+ } catch {
172
180
  // Silently ignore parsing errors to maintain stream processing
173
181
  // This allows the stream to continue even if one record is malformed
174
182
  }