@mastra/client-js 0.0.0-separate-trace-data-from-component-20250501141108 → 0.0.0-support-d1-client-20250701191943
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/.turbo/turbo-build.log +19 -0
- package/CHANGELOG.md +695 -2
- package/README.md +1 -1
- package/dist/index.cjs +1406 -119
- package/dist/index.d.cts +521 -84
- package/dist/index.d.ts +521 -84
- package/dist/index.js +1405 -122
- package/package.json +22 -15
- package/src/adapters/agui.test.ts +180 -0
- package/src/adapters/agui.ts +239 -0
- package/src/client.ts +271 -23
- package/src/example.ts +33 -31
- package/src/index.test.ts +121 -1
- package/src/resources/a2a.ts +88 -0
- package/src/resources/agent.ts +603 -44
- package/src/resources/base.ts +2 -1
- package/src/resources/index.ts +4 -2
- package/src/resources/{vnext-workflow.ts → legacy-workflow.ts} +140 -132
- package/src/resources/mcp-tool.ts +48 -0
- package/src/resources/memory-thread.ts +13 -3
- package/src/resources/network-memory-thread.ts +63 -0
- package/src/resources/network.ts +6 -13
- package/src/resources/tool.ts +9 -2
- package/src/resources/vNextNetwork.ts +177 -0
- package/src/resources/workflow.ts +256 -95
- package/src/types.ts +192 -22
- package/src/utils/index.ts +11 -0
- package/src/utils/process-client-tools.ts +32 -0
- package/src/utils/zod-to-json-schema.ts +10 -0
package/src/resources/base.ts
CHANGED
|
@@ -21,9 +21,10 @@ export class BaseResource {
|
|
|
21
21
|
|
|
22
22
|
for (let attempt = 0; attempt <= retries; attempt++) {
|
|
23
23
|
try {
|
|
24
|
-
const response = await fetch(`${baseUrl}${path}`, {
|
|
24
|
+
const response = await fetch(`${baseUrl.replace(/\/$/, '')}${path}`, {
|
|
25
25
|
...options,
|
|
26
26
|
headers: {
|
|
27
|
+
...(options.method === 'POST' || options.method === 'PUT' ? { 'content-type': 'application/json' } : {}),
|
|
27
28
|
...headers,
|
|
28
29
|
...options.headers,
|
|
29
30
|
// TODO: Bring this back once we figure out what we/users need to do to make this work with cross-origin requests
|
package/src/resources/index.ts
CHANGED
|
@@ -2,7 +2,9 @@ export * from './agent';
|
|
|
2
2
|
export * from './network';
|
|
3
3
|
export * from './memory-thread';
|
|
4
4
|
export * from './vector';
|
|
5
|
-
export * from './workflow';
|
|
5
|
+
export * from './legacy-workflow';
|
|
6
6
|
export * from './tool';
|
|
7
7
|
export * from './base';
|
|
8
|
-
export * from './
|
|
8
|
+
export * from './workflow';
|
|
9
|
+
export * from './a2a';
|
|
10
|
+
export * from './mcp-tool';
|
|
@@ -1,17 +1,16 @@
|
|
|
1
|
-
import type { RuntimeContext } from '@mastra/core/runtime-context';
|
|
2
1
|
import type {
|
|
3
2
|
ClientOptions,
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
3
|
+
LegacyWorkflowRunResult,
|
|
4
|
+
GetLegacyWorkflowRunsResponse,
|
|
5
|
+
GetWorkflowRunsParams,
|
|
6
|
+
GetLegacyWorkflowResponse,
|
|
8
7
|
} from '../types';
|
|
9
8
|
|
|
10
9
|
import { BaseResource } from './base';
|
|
11
10
|
|
|
12
11
|
const RECORD_SEPARATOR = '\x1E';
|
|
13
12
|
|
|
14
|
-
export class
|
|
13
|
+
export class LegacyWorkflow extends BaseResource {
|
|
15
14
|
constructor(
|
|
16
15
|
options: ClientOptions,
|
|
17
16
|
private workflowId: string,
|
|
@@ -20,13 +19,141 @@ export class VNextWorkflow extends BaseResource {
|
|
|
20
19
|
}
|
|
21
20
|
|
|
22
21
|
/**
|
|
23
|
-
*
|
|
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
|
|
24
151
|
* separated by the Record Separator character (\x1E)
|
|
25
152
|
*
|
|
26
153
|
* @param stream - The readable stream to process
|
|
27
154
|
* @returns An async generator that yields parsed records
|
|
28
155
|
*/
|
|
29
|
-
private async *streamProcessor(stream: ReadableStream): AsyncGenerator<
|
|
156
|
+
private async *streamProcessor(stream: ReadableStream): AsyncGenerator<LegacyWorkflowRunResult, void, unknown> {
|
|
30
157
|
const reader = stream.getReader();
|
|
31
158
|
|
|
32
159
|
// Track if we've finished reading from the stream
|
|
@@ -91,136 +218,17 @@ export class VNextWorkflow extends BaseResource {
|
|
|
91
218
|
}
|
|
92
219
|
|
|
93
220
|
/**
|
|
94
|
-
*
|
|
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
|
|
221
|
+
* Watches legacy workflow transitions in real-time
|
|
214
222
|
* @param runId - Optional run ID to filter the watch stream
|
|
215
|
-
* @returns AsyncGenerator that yields parsed records from the
|
|
223
|
+
* @returns AsyncGenerator that yields parsed records from the legacy workflow watch stream
|
|
216
224
|
*/
|
|
217
|
-
async watch({ runId }: { runId?: string }, onRecord: (record:
|
|
218
|
-
const response: Response = await this.request(`/api/workflows/
|
|
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}`, {
|
|
219
227
|
stream: true,
|
|
220
228
|
});
|
|
221
229
|
|
|
222
230
|
if (!response.ok) {
|
|
223
|
-
throw new Error(`Failed to watch
|
|
231
|
+
throw new Error(`Failed to watch legacy workflow: ${response.statusText}`);
|
|
224
232
|
}
|
|
225
233
|
|
|
226
234
|
if (!response.body) {
|
|
@@ -0,0 +1,48 @@
|
|
|
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
|
+
}
|
|
@@ -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
|
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import type { StorageThreadType } from '@mastra/core';
|
|
2
|
+
|
|
3
|
+
import type {
|
|
4
|
+
GetMemoryThreadMessagesResponse,
|
|
5
|
+
ClientOptions,
|
|
6
|
+
UpdateMemoryThreadParams,
|
|
7
|
+
GetMemoryThreadMessagesParams,
|
|
8
|
+
} from '../types';
|
|
9
|
+
|
|
10
|
+
import { BaseResource } from './base';
|
|
11
|
+
|
|
12
|
+
export class NetworkMemoryThread extends BaseResource {
|
|
13
|
+
constructor(
|
|
14
|
+
options: ClientOptions,
|
|
15
|
+
private threadId: string,
|
|
16
|
+
private networkId: string,
|
|
17
|
+
) {
|
|
18
|
+
super(options);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Retrieves the memory thread details
|
|
23
|
+
* @returns Promise containing thread details including title and metadata
|
|
24
|
+
*/
|
|
25
|
+
get(): Promise<StorageThreadType> {
|
|
26
|
+
return this.request(`/api/memory/network/threads/${this.threadId}?networkId=${this.networkId}`);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Updates the memory thread properties
|
|
31
|
+
* @param params - Update parameters including title and metadata
|
|
32
|
+
* @returns Promise containing updated thread details
|
|
33
|
+
*/
|
|
34
|
+
update(params: UpdateMemoryThreadParams): Promise<StorageThreadType> {
|
|
35
|
+
return this.request(`/api/memory/network/threads/${this.threadId}?networkId=${this.networkId}`, {
|
|
36
|
+
method: 'PATCH',
|
|
37
|
+
body: params,
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Deletes the memory thread
|
|
43
|
+
* @returns Promise containing deletion result
|
|
44
|
+
*/
|
|
45
|
+
delete(): Promise<{ result: string }> {
|
|
46
|
+
return this.request(`/api/memory/network/threads/${this.threadId}?networkId=${this.networkId}`, {
|
|
47
|
+
method: 'DELETE',
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Retrieves messages associated with the thread
|
|
53
|
+
* @param params - Optional parameters including limit for number of messages to retrieve
|
|
54
|
+
* @returns Promise containing thread messages and UI messages
|
|
55
|
+
*/
|
|
56
|
+
getMessages(params?: GetMemoryThreadMessagesParams): Promise<GetMemoryThreadMessagesResponse> {
|
|
57
|
+
const query = new URLSearchParams({
|
|
58
|
+
networkId: this.networkId,
|
|
59
|
+
...(params?.limit ? { limit: params.limit.toString() } : {}),
|
|
60
|
+
});
|
|
61
|
+
return this.request(`/api/memory/network/threads/${this.threadId}/messages?${query.toString()}`);
|
|
62
|
+
}
|
|
63
|
+
}
|
package/src/resources/network.ts
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import { processDataStream } from '@ai-sdk/ui-utils';
|
|
2
2
|
import type { GenerateReturn } from '@mastra/core';
|
|
3
3
|
import type { JSONSchema7 } from 'json-schema';
|
|
4
|
-
import { ZodSchema } from 'zod';
|
|
5
|
-
import { zodToJsonSchema } from 'zod-to-json-schema';
|
|
6
|
-
|
|
4
|
+
import type { ZodSchema } from 'zod';
|
|
7
5
|
import type { GenerateParams, ClientOptions, StreamParams, GetNetworkResponse } from '../types';
|
|
6
|
+
import { zodToJsonSchema } from '../utils/zod-to-json-schema';
|
|
8
7
|
|
|
9
8
|
import { BaseResource } from './base';
|
|
10
9
|
|
|
@@ -34,11 +33,8 @@ export class Network extends BaseResource {
|
|
|
34
33
|
): Promise<GenerateReturn<T>> {
|
|
35
34
|
const processedParams = {
|
|
36
35
|
...params,
|
|
37
|
-
output:
|
|
38
|
-
experimental_output:
|
|
39
|
-
params.experimental_output instanceof ZodSchema
|
|
40
|
-
? zodToJsonSchema(params.experimental_output)
|
|
41
|
-
: params.experimental_output,
|
|
36
|
+
output: zodToJsonSchema(params.output),
|
|
37
|
+
experimental_output: zodToJsonSchema(params.experimental_output),
|
|
42
38
|
};
|
|
43
39
|
|
|
44
40
|
return this.request(`/api/networks/${this.networkId}/generate`, {
|
|
@@ -61,11 +57,8 @@ export class Network extends BaseResource {
|
|
|
61
57
|
> {
|
|
62
58
|
const processedParams = {
|
|
63
59
|
...params,
|
|
64
|
-
output:
|
|
65
|
-
experimental_output:
|
|
66
|
-
params.experimental_output instanceof ZodSchema
|
|
67
|
-
? zodToJsonSchema(params.experimental_output)
|
|
68
|
-
: params.experimental_output,
|
|
60
|
+
output: zodToJsonSchema(params.output),
|
|
61
|
+
experimental_output: zodToJsonSchema(params.experimental_output),
|
|
69
62
|
};
|
|
70
63
|
|
|
71
64
|
const response: Response & {
|
package/src/resources/tool.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
|
+
import type { RuntimeContext } from '@mastra/core/runtime-context';
|
|
1
2
|
import type { GetToolResponse, ClientOptions } from '../types';
|
|
2
3
|
|
|
3
4
|
import { BaseResource } from './base';
|
|
5
|
+
import { parseClientRuntimeContext } from '../utils';
|
|
4
6
|
|
|
5
7
|
export class Tool extends BaseResource {
|
|
6
8
|
constructor(
|
|
@@ -23,16 +25,21 @@ export class Tool extends BaseResource {
|
|
|
23
25
|
* @param params - Parameters required for tool execution
|
|
24
26
|
* @returns Promise containing the tool execution results
|
|
25
27
|
*/
|
|
26
|
-
execute(params: { data: any; runId?: string }): Promise<any> {
|
|
28
|
+
execute(params: { data: any; runId?: string; runtimeContext?: RuntimeContext | Record<string, any> }): Promise<any> {
|
|
27
29
|
const url = new URLSearchParams();
|
|
28
30
|
|
|
29
31
|
if (params.runId) {
|
|
30
32
|
url.set('runId', params.runId);
|
|
31
33
|
}
|
|
32
34
|
|
|
35
|
+
const body = {
|
|
36
|
+
data: params.data,
|
|
37
|
+
runtimeContext: parseClientRuntimeContext(params.runtimeContext),
|
|
38
|
+
};
|
|
39
|
+
|
|
33
40
|
return this.request(`/api/tools/${this.toolId}/execute?${url.toString()}`, {
|
|
34
41
|
method: 'POST',
|
|
35
|
-
body
|
|
42
|
+
body,
|
|
36
43
|
});
|
|
37
44
|
}
|
|
38
45
|
}
|