@mastra/client-js 0.0.0-agui-20250501191909 → 0.0.0-cloud-transporter-20250513033346
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/CHANGELOG.md +160 -2
- package/dist/index.cjs +218 -28
- package/dist/index.d.cts +97 -29
- package/dist/index.d.ts +97 -29
- package/dist/index.js +214 -28
- package/package.json +6 -6
- package/src/adapters/agui.test.ts +19 -6
- package/src/adapters/agui.ts +31 -11
- package/src/client.ts +20 -4
- package/src/index.test.ts +30 -0
- package/src/resources/a2a.ts +88 -0
- package/src/resources/agent.ts +26 -34
- package/src/resources/index.ts +1 -0
- package/src/resources/memory-thread.ts +13 -3
- package/src/resources/network.ts +5 -11
- package/src/resources/tool.ts +8 -2
- package/src/resources/vnext-workflow.ts +34 -7
- package/src/resources/workflow.ts +31 -3
- package/src/types.ts +20 -2
- package/src/utils/zod-to-json-schema.ts +10 -0
package/src/index.test.ts
CHANGED
|
@@ -236,6 +236,7 @@ describe('MastraClient Resources', () => {
|
|
|
236
236
|
model: 'gpt-4',
|
|
237
237
|
instructions: 'Test instructions',
|
|
238
238
|
tools: {},
|
|
239
|
+
workflows: {},
|
|
239
240
|
};
|
|
240
241
|
mockFetchResponse(mockResponse);
|
|
241
242
|
|
|
@@ -552,6 +553,35 @@ describe('MastraClient Resources', () => {
|
|
|
552
553
|
}),
|
|
553
554
|
);
|
|
554
555
|
});
|
|
556
|
+
|
|
557
|
+
it('should get thread messages with limit', async () => {
|
|
558
|
+
const mockResponse = {
|
|
559
|
+
messages: [
|
|
560
|
+
{
|
|
561
|
+
id: '1',
|
|
562
|
+
content: 'test',
|
|
563
|
+
threadId,
|
|
564
|
+
role: 'user',
|
|
565
|
+
type: 'text',
|
|
566
|
+
resourceId: 'test-resource',
|
|
567
|
+
createdAt: new Date(),
|
|
568
|
+
},
|
|
569
|
+
],
|
|
570
|
+
uiMessages: [],
|
|
571
|
+
};
|
|
572
|
+
mockFetchResponse(mockResponse);
|
|
573
|
+
|
|
574
|
+
const limit = 5;
|
|
575
|
+
const result = await memoryThread.getMessages({ limit });
|
|
576
|
+
|
|
577
|
+
expect(result).toEqual(mockResponse);
|
|
578
|
+
expect(global.fetch).toHaveBeenCalledWith(
|
|
579
|
+
`${clientOptions.baseUrl}/api/memory/threads/${threadId}/messages?agentId=${agentId}&limit=${limit}`,
|
|
580
|
+
expect.objectContaining({
|
|
581
|
+
headers: expect.objectContaining(clientOptions.headers),
|
|
582
|
+
}),
|
|
583
|
+
);
|
|
584
|
+
});
|
|
555
585
|
});
|
|
556
586
|
|
|
557
587
|
describe('Tool Resource', () => {
|
|
@@ -0,0 +1,88 @@
|
|
|
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
|
+
}
|
package/src/resources/agent.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { processDataStream } from '@ai-sdk/ui-utils';
|
|
|
2
2
|
import type { GenerateReturn } from '@mastra/core';
|
|
3
3
|
import type { JSONSchema7 } from 'json-schema';
|
|
4
4
|
import { ZodSchema } from 'zod';
|
|
5
|
-
import { zodToJsonSchema } from 'zod-to-json-schema';
|
|
5
|
+
import { zodToJsonSchema } from '../utils/zod-to-json-schema';
|
|
6
6
|
|
|
7
7
|
import type {
|
|
8
8
|
GenerateParams,
|
|
@@ -14,28 +14,7 @@ import type {
|
|
|
14
14
|
} from '../types';
|
|
15
15
|
|
|
16
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
|
-
}
|
|
17
|
+
import type { RuntimeContext } from '@mastra/core/di';
|
|
39
18
|
|
|
40
19
|
export class AgentVoice extends BaseResource {
|
|
41
20
|
constructor(
|
|
@@ -69,7 +48,7 @@ export class AgentVoice extends BaseResource {
|
|
|
69
48
|
* @param options - Optional provider-specific options
|
|
70
49
|
* @returns Promise containing the transcribed text
|
|
71
50
|
*/
|
|
72
|
-
listen(audio: Blob, options?: Record<string, any>): Promise<
|
|
51
|
+
listen(audio: Blob, options?: Record<string, any>): Promise<{ text: string }> {
|
|
73
52
|
const formData = new FormData();
|
|
74
53
|
formData.append('audio', audio);
|
|
75
54
|
|
|
@@ -121,11 +100,9 @@ export class Agent extends BaseResource {
|
|
|
121
100
|
): Promise<GenerateReturn<T>> {
|
|
122
101
|
const processedParams = {
|
|
123
102
|
...params,
|
|
124
|
-
output:
|
|
125
|
-
experimental_output:
|
|
126
|
-
|
|
127
|
-
? zodToJsonSchema(params.experimental_output)
|
|
128
|
-
: params.experimental_output,
|
|
103
|
+
output: zodToJsonSchema(params.output),
|
|
104
|
+
experimental_output: zodToJsonSchema(params.experimental_output),
|
|
105
|
+
runtimeContext: params.runtimeContext ? Object.fromEntries(params.runtimeContext.entries()) : undefined,
|
|
129
106
|
};
|
|
130
107
|
|
|
131
108
|
return this.request(`/api/agents/${this.agentId}/generate`, {
|
|
@@ -148,11 +125,9 @@ export class Agent extends BaseResource {
|
|
|
148
125
|
> {
|
|
149
126
|
const processedParams = {
|
|
150
127
|
...params,
|
|
151
|
-
output:
|
|
152
|
-
experimental_output:
|
|
153
|
-
|
|
154
|
-
? zodToJsonSchema(params.experimental_output)
|
|
155
|
-
: params.experimental_output,
|
|
128
|
+
output: zodToJsonSchema(params.output),
|
|
129
|
+
experimental_output: zodToJsonSchema(params.experimental_output),
|
|
130
|
+
runtimeContext: params.runtimeContext ? Object.fromEntries(params.runtimeContext.entries()) : undefined,
|
|
156
131
|
};
|
|
157
132
|
|
|
158
133
|
const response: Response & {
|
|
@@ -186,6 +161,23 @@ export class Agent extends BaseResource {
|
|
|
186
161
|
return this.request(`/api/agents/${this.agentId}/tools/${toolId}`);
|
|
187
162
|
}
|
|
188
163
|
|
|
164
|
+
/**
|
|
165
|
+
* Executes a tool for the agent
|
|
166
|
+
* @param toolId - ID of the tool to execute
|
|
167
|
+
* @param params - Parameters required for tool execution
|
|
168
|
+
* @returns Promise containing the tool execution results
|
|
169
|
+
*/
|
|
170
|
+
executeTool(toolId: string, params: { data: any; runtimeContext?: RuntimeContext }): Promise<any> {
|
|
171
|
+
const body = {
|
|
172
|
+
data: params.data,
|
|
173
|
+
runtimeContext: params.runtimeContext ? Object.fromEntries(params.runtimeContext.entries()) : undefined,
|
|
174
|
+
};
|
|
175
|
+
return this.request(`/api/agents/${this.agentId}/tools/${toolId}/execute`, {
|
|
176
|
+
method: 'POST',
|
|
177
|
+
body,
|
|
178
|
+
});
|
|
179
|
+
}
|
|
180
|
+
|
|
189
181
|
/**
|
|
190
182
|
* Retrieves evaluation results for the agent
|
|
191
183
|
* @returns Promise containing agent evaluations
|
package/src/resources/index.ts
CHANGED
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
import type { StorageThreadType } from '@mastra/core';
|
|
2
2
|
|
|
3
|
-
import type {
|
|
3
|
+
import type {
|
|
4
|
+
GetMemoryThreadMessagesResponse,
|
|
5
|
+
ClientOptions,
|
|
6
|
+
UpdateMemoryThreadParams,
|
|
7
|
+
GetMemoryThreadMessagesParams,
|
|
8
|
+
} from '../types';
|
|
4
9
|
|
|
5
10
|
import { BaseResource } from './base';
|
|
6
11
|
|
|
@@ -45,9 +50,14 @@ export class MemoryThread extends BaseResource {
|
|
|
45
50
|
|
|
46
51
|
/**
|
|
47
52
|
* Retrieves messages associated with the thread
|
|
53
|
+
* @param params - Optional parameters including limit for number of messages to retrieve
|
|
48
54
|
* @returns Promise containing thread messages and UI messages
|
|
49
55
|
*/
|
|
50
|
-
getMessages(): Promise<GetMemoryThreadMessagesResponse> {
|
|
51
|
-
|
|
56
|
+
getMessages(params?: GetMemoryThreadMessagesParams): Promise<GetMemoryThreadMessagesResponse> {
|
|
57
|
+
const query = new URLSearchParams({
|
|
58
|
+
agentId: this.agentId,
|
|
59
|
+
...(params?.limit ? { limit: params.limit.toString() } : {}),
|
|
60
|
+
});
|
|
61
|
+
return this.request(`/api/memory/threads/${this.threadId}/messages?${query.toString()}`);
|
|
52
62
|
}
|
|
53
63
|
}
|
package/src/resources/network.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { processDataStream } from '@ai-sdk/ui-utils';
|
|
|
2
2
|
import type { GenerateReturn } from '@mastra/core';
|
|
3
3
|
import type { JSONSchema7 } from 'json-schema';
|
|
4
4
|
import { ZodSchema } from 'zod';
|
|
5
|
-
import { zodToJsonSchema } from 'zod-to-json-schema';
|
|
5
|
+
import { zodToJsonSchema } from '../utils/zod-to-json-schema';
|
|
6
6
|
|
|
7
7
|
import type { GenerateParams, ClientOptions, StreamParams, GetNetworkResponse } from '../types';
|
|
8
8
|
|
|
@@ -34,11 +34,8 @@ export class Network extends BaseResource {
|
|
|
34
34
|
): Promise<GenerateReturn<T>> {
|
|
35
35
|
const processedParams = {
|
|
36
36
|
...params,
|
|
37
|
-
output:
|
|
38
|
-
experimental_output:
|
|
39
|
-
params.experimental_output instanceof ZodSchema
|
|
40
|
-
? zodToJsonSchema(params.experimental_output)
|
|
41
|
-
: params.experimental_output,
|
|
37
|
+
output: zodToJsonSchema(params.output),
|
|
38
|
+
experimental_output: zodToJsonSchema(params.experimental_output),
|
|
42
39
|
};
|
|
43
40
|
|
|
44
41
|
return this.request(`/api/networks/${this.networkId}/generate`, {
|
|
@@ -61,11 +58,8 @@ export class Network extends BaseResource {
|
|
|
61
58
|
> {
|
|
62
59
|
const processedParams = {
|
|
63
60
|
...params,
|
|
64
|
-
output:
|
|
65
|
-
experimental_output:
|
|
66
|
-
params.experimental_output instanceof ZodSchema
|
|
67
|
-
? zodToJsonSchema(params.experimental_output)
|
|
68
|
-
: params.experimental_output,
|
|
61
|
+
output: zodToJsonSchema(params.output),
|
|
62
|
+
experimental_output: zodToJsonSchema(params.experimental_output),
|
|
69
63
|
};
|
|
70
64
|
|
|
71
65
|
const response: Response & {
|
package/src/resources/tool.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { RuntimeContext } from '@mastra/core/di';
|
|
1
2
|
import type { GetToolResponse, ClientOptions } from '../types';
|
|
2
3
|
|
|
3
4
|
import { BaseResource } from './base';
|
|
@@ -23,16 +24,21 @@ export class Tool extends BaseResource {
|
|
|
23
24
|
* @param params - Parameters required for tool execution
|
|
24
25
|
* @returns Promise containing the tool execution results
|
|
25
26
|
*/
|
|
26
|
-
execute(params: { data: any; runId?: string }): Promise<any> {
|
|
27
|
+
execute(params: { data: any; runId?: string; runtimeContext?: RuntimeContext }): Promise<any> {
|
|
27
28
|
const url = new URLSearchParams();
|
|
28
29
|
|
|
29
30
|
if (params.runId) {
|
|
30
31
|
url.set('runId', params.runId);
|
|
31
32
|
}
|
|
32
33
|
|
|
34
|
+
const body = {
|
|
35
|
+
data: params.data,
|
|
36
|
+
runtimeContext: params.runtimeContext ? Object.fromEntries(params.runtimeContext.entries()) : undefined,
|
|
37
|
+
};
|
|
38
|
+
|
|
33
39
|
return this.request(`/api/tools/${this.toolId}/execute?${url.toString()}`, {
|
|
34
40
|
method: 'POST',
|
|
35
|
-
body
|
|
41
|
+
body,
|
|
36
42
|
});
|
|
37
43
|
}
|
|
38
44
|
}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { RuntimeContext } from '@mastra/core/runtime-context';
|
|
2
2
|
import type {
|
|
3
3
|
ClientOptions,
|
|
4
4
|
GetVNextWorkflowResponse,
|
|
5
|
+
GetWorkflowRunsParams,
|
|
5
6
|
GetWorkflowRunsResponse,
|
|
6
7
|
VNextWorkflowRunResult,
|
|
7
8
|
VNextWorkflowWatchResult,
|
|
@@ -100,10 +101,32 @@ export class VNextWorkflow extends BaseResource {
|
|
|
100
101
|
|
|
101
102
|
/**
|
|
102
103
|
* Retrieves all runs for a vNext workflow
|
|
104
|
+
* @param params - Parameters for filtering runs
|
|
103
105
|
* @returns Promise containing vNext workflow runs array
|
|
104
106
|
*/
|
|
105
|
-
runs(): Promise<GetWorkflowRunsResponse> {
|
|
106
|
-
|
|
107
|
+
runs(params?: GetWorkflowRunsParams): Promise<GetWorkflowRunsResponse> {
|
|
108
|
+
const searchParams = new URLSearchParams();
|
|
109
|
+
if (params?.fromDate) {
|
|
110
|
+
searchParams.set('fromDate', params.fromDate.toISOString());
|
|
111
|
+
}
|
|
112
|
+
if (params?.toDate) {
|
|
113
|
+
searchParams.set('toDate', params.toDate.toISOString());
|
|
114
|
+
}
|
|
115
|
+
if (params?.limit) {
|
|
116
|
+
searchParams.set('limit', String(params.limit));
|
|
117
|
+
}
|
|
118
|
+
if (params?.offset) {
|
|
119
|
+
searchParams.set('offset', String(params.offset));
|
|
120
|
+
}
|
|
121
|
+
if (params?.resourceId) {
|
|
122
|
+
searchParams.set('resourceId', params.resourceId);
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
if (searchParams.size) {
|
|
126
|
+
return this.request(`/api/workflows/v-next/${this.workflowId}/runs?${searchParams}`);
|
|
127
|
+
} else {
|
|
128
|
+
return this.request(`/api/workflows/v-next/${this.workflowId}/runs`);
|
|
129
|
+
}
|
|
107
130
|
}
|
|
108
131
|
|
|
109
132
|
/**
|
|
@@ -133,9 +156,10 @@ export class VNextWorkflow extends BaseResource {
|
|
|
133
156
|
inputData: Record<string, any>;
|
|
134
157
|
runtimeContext?: RuntimeContext;
|
|
135
158
|
}): Promise<{ message: string }> {
|
|
159
|
+
const runtimeContext = params.runtimeContext ? Object.fromEntries(params.runtimeContext.entries()) : undefined;
|
|
136
160
|
return this.request(`/api/workflows/v-next/${this.workflowId}/start?runId=${params.runId}`, {
|
|
137
161
|
method: 'POST',
|
|
138
|
-
body: { inputData: params?.inputData, runtimeContext
|
|
162
|
+
body: { inputData: params?.inputData, runtimeContext },
|
|
139
163
|
});
|
|
140
164
|
}
|
|
141
165
|
|
|
@@ -148,13 +172,14 @@ export class VNextWorkflow extends BaseResource {
|
|
|
148
172
|
step,
|
|
149
173
|
runId,
|
|
150
174
|
resumeData,
|
|
151
|
-
|
|
175
|
+
...rest
|
|
152
176
|
}: {
|
|
153
177
|
step: string | string[];
|
|
154
178
|
runId: string;
|
|
155
179
|
resumeData?: Record<string, any>;
|
|
156
180
|
runtimeContext?: RuntimeContext;
|
|
157
181
|
}): Promise<{ message: string }> {
|
|
182
|
+
const runtimeContext = rest.runtimeContext ? Object.fromEntries(rest.runtimeContext.entries()) : undefined;
|
|
158
183
|
return this.request(`/api/workflows/v-next/${this.workflowId}/resume?runId=${runId}`, {
|
|
159
184
|
method: 'POST',
|
|
160
185
|
stream: true,
|
|
@@ -182,9 +207,10 @@ export class VNextWorkflow extends BaseResource {
|
|
|
182
207
|
searchParams.set('runId', params.runId);
|
|
183
208
|
}
|
|
184
209
|
|
|
210
|
+
const runtimeContext = params.runtimeContext ? Object.fromEntries(params.runtimeContext.entries()) : undefined;
|
|
185
211
|
return this.request(`/api/workflows/v-next/${this.workflowId}/start-async?${searchParams.toString()}`, {
|
|
186
212
|
method: 'POST',
|
|
187
|
-
body: { inputData: params.inputData, runtimeContext
|
|
213
|
+
body: { inputData: params.inputData, runtimeContext },
|
|
188
214
|
});
|
|
189
215
|
}
|
|
190
216
|
|
|
@@ -199,12 +225,13 @@ export class VNextWorkflow extends BaseResource {
|
|
|
199
225
|
resumeData?: Record<string, any>;
|
|
200
226
|
runtimeContext?: RuntimeContext;
|
|
201
227
|
}): Promise<VNextWorkflowRunResult> {
|
|
228
|
+
const runtimeContext = params.runtimeContext ? Object.fromEntries(params.runtimeContext.entries()) : undefined;
|
|
202
229
|
return this.request(`/api/workflows/v-next/${this.workflowId}/resume-async?runId=${params.runId}`, {
|
|
203
230
|
method: 'POST',
|
|
204
231
|
body: {
|
|
205
232
|
step: params.step,
|
|
206
233
|
resumeData: params.resumeData,
|
|
207
|
-
runtimeContext
|
|
234
|
+
runtimeContext,
|
|
208
235
|
},
|
|
209
236
|
});
|
|
210
237
|
}
|
|
@@ -1,4 +1,10 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type {
|
|
2
|
+
GetWorkflowResponse,
|
|
3
|
+
ClientOptions,
|
|
4
|
+
WorkflowRunResult,
|
|
5
|
+
GetWorkflowRunsResponse,
|
|
6
|
+
GetWorkflowRunsParams,
|
|
7
|
+
} from '../types';
|
|
2
8
|
|
|
3
9
|
import { BaseResource } from './base';
|
|
4
10
|
|
|
@@ -22,10 +28,32 @@ export class Workflow extends BaseResource {
|
|
|
22
28
|
|
|
23
29
|
/**
|
|
24
30
|
* Retrieves all runs for a workflow
|
|
31
|
+
* @param params - Parameters for filtering runs
|
|
25
32
|
* @returns Promise containing workflow runs array
|
|
26
33
|
*/
|
|
27
|
-
runs(): Promise<GetWorkflowRunsResponse> {
|
|
28
|
-
|
|
34
|
+
runs(params?: GetWorkflowRunsParams): Promise<GetWorkflowRunsResponse> {
|
|
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/${this.workflowId}/runs?${searchParams}`);
|
|
54
|
+
} else {
|
|
55
|
+
return this.request(`/api/workflows/${this.workflowId}/runs`);
|
|
56
|
+
}
|
|
29
57
|
}
|
|
30
58
|
|
|
31
59
|
/**
|
package/src/types.ts
CHANGED
|
@@ -42,17 +42,18 @@ export interface GetAgentResponse {
|
|
|
42
42
|
name: string;
|
|
43
43
|
instructions: string;
|
|
44
44
|
tools: Record<string, GetToolResponse>;
|
|
45
|
+
workflows: Record<string, GetWorkflowResponse>;
|
|
45
46
|
provider: string;
|
|
46
47
|
modelId: string;
|
|
47
48
|
}
|
|
48
49
|
|
|
49
50
|
export type GenerateParams<T extends JSONSchema7 | ZodSchema | undefined = undefined> = {
|
|
50
51
|
messages: string | string[] | CoreMessage[] | AiMessageType[];
|
|
51
|
-
} & Partial<AgentGenerateOptions<T>>;
|
|
52
|
+
} & Partial<Omit<AgentGenerateOptions<T>, 'experimental_generateMessageId'>>;
|
|
52
53
|
|
|
53
54
|
export type StreamParams<T extends JSONSchema7 | ZodSchema | undefined = undefined> = {
|
|
54
55
|
messages: string | string[] | CoreMessage[] | AiMessageType[];
|
|
55
|
-
} & Omit<AgentStreamOptions<T>, 'onFinish' | 'onStepFinish' | 'telemetry'>;
|
|
56
|
+
} & Omit<AgentStreamOptions<T>, 'onFinish' | 'onStepFinish' | 'telemetry' | 'experimental_generateMessageId'>;
|
|
56
57
|
|
|
57
58
|
export interface GetEvalsByAgentIdResponse extends GetAgentResponse {
|
|
58
59
|
evals: any[];
|
|
@@ -77,6 +78,14 @@ export interface GetWorkflowResponse {
|
|
|
77
78
|
workflowId?: string;
|
|
78
79
|
}
|
|
79
80
|
|
|
81
|
+
export interface GetWorkflowRunsParams {
|
|
82
|
+
fromDate?: Date;
|
|
83
|
+
toDate?: Date;
|
|
84
|
+
limit?: number;
|
|
85
|
+
offset?: number;
|
|
86
|
+
resourceId?: string;
|
|
87
|
+
}
|
|
88
|
+
|
|
80
89
|
export type GetWorkflowRunsResponse = WorkflowRuns;
|
|
81
90
|
|
|
82
91
|
export type WorkflowRunResult = {
|
|
@@ -166,6 +175,13 @@ export interface UpdateMemoryThreadParams {
|
|
|
166
175
|
resourceId: string;
|
|
167
176
|
}
|
|
168
177
|
|
|
178
|
+
export interface GetMemoryThreadMessagesParams {
|
|
179
|
+
/**
|
|
180
|
+
* Limit the number of messages to retrieve (default: 40)
|
|
181
|
+
*/
|
|
182
|
+
limit?: number;
|
|
183
|
+
}
|
|
184
|
+
|
|
169
185
|
export interface GetMemoryThreadMessagesResponse {
|
|
170
186
|
messages: CoreMessage[];
|
|
171
187
|
uiMessages: AiMessageType[];
|
|
@@ -234,6 +250,8 @@ export interface GetTelemetryParams {
|
|
|
234
250
|
page?: number;
|
|
235
251
|
perPage?: number;
|
|
236
252
|
attribute?: Record<string, string>;
|
|
253
|
+
fromDate?: Date;
|
|
254
|
+
toDate?: Date;
|
|
237
255
|
}
|
|
238
256
|
|
|
239
257
|
export interface GetNetworkResponse {
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { ZodSchema } from 'zod';
|
|
2
|
+
import originalZodToJsonSchema from 'zod-to-json-schema';
|
|
3
|
+
|
|
4
|
+
export function zodToJsonSchema<T extends ZodSchema | any>(zodSchema: T) {
|
|
5
|
+
if (!(zodSchema instanceof ZodSchema)) {
|
|
6
|
+
return zodSchema;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
return originalZodToJsonSchema(zodSchema, { $refStrategy: 'none' });
|
|
10
|
+
}
|