@mastra/client-js 0.10.2-alpha.2 → 0.10.3-alpha.0
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 +9 -9
- package/CHANGELOG.md +55 -0
- package/dist/index.cjs +105 -9
- package/dist/index.d.cts +37 -6
- package/dist/index.d.ts +37 -6
- package/dist/index.js +105 -9
- package/package.json +7 -8
- package/src/client.ts +78 -2
- package/src/resources/agent.ts +13 -1
- package/src/types.ts +25 -5
- package/src/utils/process-client-tools.ts +31 -0
package/.turbo/turbo-build.log
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
|
|
2
|
-
> @mastra/client-js@0.10.
|
|
2
|
+
> @mastra/client-js@0.10.3-alpha.0 build /home/runner/work/mastra/mastra/client-sdks/client-js
|
|
3
3
|
> tsup src/index.ts --format esm,cjs --dts --clean --treeshake=smallest --splitting
|
|
4
4
|
|
|
5
5
|
[34mCLI[39m Building entry: src/index.ts
|
|
6
6
|
[34mCLI[39m Using tsconfig: tsconfig.json
|
|
7
|
-
[34mCLI[39m tsup v8.
|
|
7
|
+
[34mCLI[39m tsup v8.5.0
|
|
8
8
|
[34mCLI[39m Target: es2022
|
|
9
9
|
[34mCLI[39m Cleaning output folder
|
|
10
10
|
[34mESM[39m Build start
|
|
11
11
|
[34mCJS[39m Build start
|
|
12
|
-
[32mESM[39m [1mdist/index.js [22m[
|
|
13
|
-
[32mESM[39m ⚡️ Build success in
|
|
14
|
-
[32mCJS[39m [1mdist/index.cjs [22m[
|
|
15
|
-
[32mCJS[39m ⚡️ Build success in
|
|
12
|
+
[32mESM[39m [1mdist/index.js [22m[32m46.36 KB[39m
|
|
13
|
+
[32mESM[39m ⚡️ Build success in 2170ms
|
|
14
|
+
[32mCJS[39m [1mdist/index.cjs [22m[32m46.65 KB[39m
|
|
15
|
+
[32mCJS[39m ⚡️ Build success in 2178ms
|
|
16
16
|
[34mDTS[39m Build start
|
|
17
|
-
[32mDTS[39m ⚡️ Build success in
|
|
18
|
-
[32mDTS[39m [1mdist/index.d.ts [22m[
|
|
19
|
-
[32mDTS[39m [1mdist/index.d.cts [22m[
|
|
17
|
+
[32mDTS[39m ⚡️ Build success in 16147ms
|
|
18
|
+
[32mDTS[39m [1mdist/index.d.ts [22m[32m32.85 KB[39m
|
|
19
|
+
[32mDTS[39m [1mdist/index.d.cts [22m[32m32.85 KB[39m
|
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,60 @@
|
|
|
1
1
|
# @mastra/client-js
|
|
2
2
|
|
|
3
|
+
## 0.10.3-alpha.0
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- f1f1f1b: Add basic filtering capabilities to logs
|
|
8
|
+
- b2810ab: Move @mastra/core to deps
|
|
9
|
+
- 82090c1: Add pagination to logs
|
|
10
|
+
- 67d21b5: Added overloading to the generate method of the Agent class to enhance type definition using ZodSchema.
|
|
11
|
+
- Updated dependencies [d1ed912]
|
|
12
|
+
- Updated dependencies [f1f1f1b]
|
|
13
|
+
- Updated dependencies [f9816ae]
|
|
14
|
+
- Updated dependencies [82090c1]
|
|
15
|
+
- Updated dependencies [1b443fd]
|
|
16
|
+
- Updated dependencies [ce97900]
|
|
17
|
+
- Updated dependencies [14a2566]
|
|
18
|
+
- @mastra/core@0.10.4-alpha.0
|
|
19
|
+
|
|
20
|
+
## 0.10.2
|
|
21
|
+
|
|
22
|
+
### Patch Changes
|
|
23
|
+
|
|
24
|
+
- 592a2db: Added different icons for agents and workflows in mcp tools list
|
|
25
|
+
- 37643b8: Fix tool access
|
|
26
|
+
- c5bf1ce: Add backwards compat code for new MessageList in storage
|
|
27
|
+
- b72c768: [Bug fix] Serialize parameters in clientTools
|
|
28
|
+
- f0d559f: Fix peerdeps for alpha channel
|
|
29
|
+
- Updated dependencies [ee77e78]
|
|
30
|
+
- Updated dependencies [592a2db]
|
|
31
|
+
- Updated dependencies [e5dc18d]
|
|
32
|
+
- Updated dependencies [ab5adbe]
|
|
33
|
+
- Updated dependencies [1e8bb40]
|
|
34
|
+
- Updated dependencies [1b5fc55]
|
|
35
|
+
- Updated dependencies [195c428]
|
|
36
|
+
- Updated dependencies [f73e11b]
|
|
37
|
+
- Updated dependencies [37643b8]
|
|
38
|
+
- Updated dependencies [99fd6cf]
|
|
39
|
+
- Updated dependencies [c5bf1ce]
|
|
40
|
+
- Updated dependencies [add596e]
|
|
41
|
+
- Updated dependencies [8dc94d8]
|
|
42
|
+
- Updated dependencies [ecebbeb]
|
|
43
|
+
- Updated dependencies [79d5145]
|
|
44
|
+
- Updated dependencies [12b7002]
|
|
45
|
+
- Updated dependencies [2901125]
|
|
46
|
+
- @mastra/core@0.10.2
|
|
47
|
+
|
|
48
|
+
## 0.10.2-alpha.3
|
|
49
|
+
|
|
50
|
+
### Patch Changes
|
|
51
|
+
|
|
52
|
+
- 37643b8: Fix tool access
|
|
53
|
+
- b72c768: [Bug fix] Serialize parameters in clientTools
|
|
54
|
+
- Updated dependencies [37643b8]
|
|
55
|
+
- Updated dependencies [79d5145]
|
|
56
|
+
- @mastra/core@0.10.2-alpha.8
|
|
57
|
+
|
|
3
58
|
## 0.10.2-alpha.2
|
|
4
59
|
|
|
5
60
|
### Patch Changes
|
package/dist/index.cjs
CHANGED
|
@@ -5,6 +5,7 @@ var rxjs = require('rxjs');
|
|
|
5
5
|
var uiUtils = require('@ai-sdk/ui-utils');
|
|
6
6
|
var zod = require('zod');
|
|
7
7
|
var originalZodToJsonSchema = require('zod-to-json-schema');
|
|
8
|
+
var tools = require('@mastra/core/tools');
|
|
8
9
|
var runtimeContext = require('@mastra/core/runtime-context');
|
|
9
10
|
|
|
10
11
|
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
@@ -202,6 +203,33 @@ function zodToJsonSchema(zodSchema) {
|
|
|
202
203
|
}
|
|
203
204
|
return originalZodToJsonSchema__default.default(zodSchema, { $refStrategy: "none" });
|
|
204
205
|
}
|
|
206
|
+
function processClientTools(clientTools) {
|
|
207
|
+
if (!clientTools) {
|
|
208
|
+
return void 0;
|
|
209
|
+
}
|
|
210
|
+
return Object.fromEntries(
|
|
211
|
+
Object.entries(clientTools).map(([key, value]) => {
|
|
212
|
+
if (tools.isVercelTool(value)) {
|
|
213
|
+
return [
|
|
214
|
+
key,
|
|
215
|
+
{
|
|
216
|
+
...value,
|
|
217
|
+
parameters: value.parameters ? zodToJsonSchema(value.parameters) : void 0
|
|
218
|
+
}
|
|
219
|
+
];
|
|
220
|
+
} else {
|
|
221
|
+
return [
|
|
222
|
+
key,
|
|
223
|
+
{
|
|
224
|
+
...value,
|
|
225
|
+
inputSchema: value.inputSchema ? zodToJsonSchema(value.inputSchema) : void 0,
|
|
226
|
+
outputSchema: value.outputSchema ? zodToJsonSchema(value.outputSchema) : void 0
|
|
227
|
+
}
|
|
228
|
+
];
|
|
229
|
+
}
|
|
230
|
+
})
|
|
231
|
+
);
|
|
232
|
+
}
|
|
205
233
|
|
|
206
234
|
// src/resources/base.ts
|
|
207
235
|
var BaseResource = class {
|
|
@@ -340,17 +368,13 @@ var Agent = class extends BaseResource {
|
|
|
340
368
|
details() {
|
|
341
369
|
return this.request(`/api/agents/${this.agentId}`);
|
|
342
370
|
}
|
|
343
|
-
/**
|
|
344
|
-
* Generates a response from the agent
|
|
345
|
-
* @param params - Generation parameters including prompt
|
|
346
|
-
* @returns Promise containing the generated response
|
|
347
|
-
*/
|
|
348
371
|
generate(params) {
|
|
349
372
|
const processedParams = {
|
|
350
373
|
...params,
|
|
351
374
|
output: params.output ? zodToJsonSchema(params.output) : void 0,
|
|
352
375
|
experimental_output: params.experimental_output ? zodToJsonSchema(params.experimental_output) : void 0,
|
|
353
|
-
runtimeContext: parseClientRuntimeContext(params.runtimeContext)
|
|
376
|
+
runtimeContext: parseClientRuntimeContext(params.runtimeContext),
|
|
377
|
+
clientTools: processClientTools(params.clientTools)
|
|
354
378
|
};
|
|
355
379
|
return this.request(`/api/agents/${this.agentId}/generate`, {
|
|
356
380
|
method: "POST",
|
|
@@ -367,7 +391,8 @@ var Agent = class extends BaseResource {
|
|
|
367
391
|
...params,
|
|
368
392
|
output: params.output ? zodToJsonSchema(params.output) : void 0,
|
|
369
393
|
experimental_output: params.experimental_output ? zodToJsonSchema(params.experimental_output) : void 0,
|
|
370
|
-
runtimeContext: parseClientRuntimeContext(params.runtimeContext)
|
|
394
|
+
runtimeContext: parseClientRuntimeContext(params.runtimeContext),
|
|
395
|
+
clientTools: processClientTools(params.clientTools)
|
|
371
396
|
};
|
|
372
397
|
const response = await this.request(`/api/agents/${this.agentId}/stream`, {
|
|
373
398
|
method: "POST",
|
|
@@ -1316,7 +1341,41 @@ var MastraClient = class extends BaseResource {
|
|
|
1316
1341
|
* @returns Promise containing array of log messages
|
|
1317
1342
|
*/
|
|
1318
1343
|
getLogs(params) {
|
|
1319
|
-
|
|
1344
|
+
const { transportId, fromDate, toDate, logLevel, filters, page, perPage } = params;
|
|
1345
|
+
const _filters = filters ? Object.entries(filters).map(([key, value]) => `${key}:${value}`) : [];
|
|
1346
|
+
const searchParams = new URLSearchParams();
|
|
1347
|
+
if (transportId) {
|
|
1348
|
+
searchParams.set("transportId", transportId);
|
|
1349
|
+
}
|
|
1350
|
+
if (fromDate) {
|
|
1351
|
+
searchParams.set("fromDate", fromDate.toISOString());
|
|
1352
|
+
}
|
|
1353
|
+
if (toDate) {
|
|
1354
|
+
searchParams.set("toDate", toDate.toISOString());
|
|
1355
|
+
}
|
|
1356
|
+
if (logLevel) {
|
|
1357
|
+
searchParams.set("logLevel", logLevel);
|
|
1358
|
+
}
|
|
1359
|
+
if (page) {
|
|
1360
|
+
searchParams.set("page", String(page));
|
|
1361
|
+
}
|
|
1362
|
+
if (perPage) {
|
|
1363
|
+
searchParams.set("perPage", String(perPage));
|
|
1364
|
+
}
|
|
1365
|
+
if (_filters) {
|
|
1366
|
+
if (Array.isArray(_filters)) {
|
|
1367
|
+
for (const filter of _filters) {
|
|
1368
|
+
searchParams.append("filters", filter);
|
|
1369
|
+
}
|
|
1370
|
+
} else {
|
|
1371
|
+
searchParams.set("filters", _filters);
|
|
1372
|
+
}
|
|
1373
|
+
}
|
|
1374
|
+
if (searchParams.size) {
|
|
1375
|
+
return this.request(`/api/logs?${searchParams}`);
|
|
1376
|
+
} else {
|
|
1377
|
+
return this.request(`/api/logs`);
|
|
1378
|
+
}
|
|
1320
1379
|
}
|
|
1321
1380
|
/**
|
|
1322
1381
|
* Gets logs for a specific run
|
|
@@ -1324,7 +1383,44 @@ var MastraClient = class extends BaseResource {
|
|
|
1324
1383
|
* @returns Promise containing array of log messages
|
|
1325
1384
|
*/
|
|
1326
1385
|
getLogForRun(params) {
|
|
1327
|
-
|
|
1386
|
+
const { runId, transportId, fromDate, toDate, logLevel, filters, page, perPage } = params;
|
|
1387
|
+
const _filters = filters ? Object.entries(filters).map(([key, value]) => `${key}:${value}`) : [];
|
|
1388
|
+
const searchParams = new URLSearchParams();
|
|
1389
|
+
if (runId) {
|
|
1390
|
+
searchParams.set("runId", runId);
|
|
1391
|
+
}
|
|
1392
|
+
if (transportId) {
|
|
1393
|
+
searchParams.set("transportId", transportId);
|
|
1394
|
+
}
|
|
1395
|
+
if (fromDate) {
|
|
1396
|
+
searchParams.set("fromDate", fromDate.toISOString());
|
|
1397
|
+
}
|
|
1398
|
+
if (toDate) {
|
|
1399
|
+
searchParams.set("toDate", toDate.toISOString());
|
|
1400
|
+
}
|
|
1401
|
+
if (logLevel) {
|
|
1402
|
+
searchParams.set("logLevel", logLevel);
|
|
1403
|
+
}
|
|
1404
|
+
if (page) {
|
|
1405
|
+
searchParams.set("page", String(page));
|
|
1406
|
+
}
|
|
1407
|
+
if (perPage) {
|
|
1408
|
+
searchParams.set("perPage", String(perPage));
|
|
1409
|
+
}
|
|
1410
|
+
if (_filters) {
|
|
1411
|
+
if (Array.isArray(_filters)) {
|
|
1412
|
+
for (const filter of _filters) {
|
|
1413
|
+
searchParams.append("filters", filter);
|
|
1414
|
+
}
|
|
1415
|
+
} else {
|
|
1416
|
+
searchParams.set("filters", _filters);
|
|
1417
|
+
}
|
|
1418
|
+
}
|
|
1419
|
+
if (searchParams.size) {
|
|
1420
|
+
return this.request(`/api/logs/${runId}?${searchParams}`);
|
|
1421
|
+
} else {
|
|
1422
|
+
return this.request(`/api/logs/${runId}`);
|
|
1423
|
+
}
|
|
1328
1424
|
}
|
|
1329
1425
|
/**
|
|
1330
1426
|
* List of all log transports
|
package/dist/index.d.cts
CHANGED
|
@@ -4,8 +4,8 @@ import { processDataStream } from '@ai-sdk/ui-utils';
|
|
|
4
4
|
import { CoreMessage, AiMessageType, StorageThreadType, MastraMessageV1, LegacyWorkflowRuns, WorkflowRuns, QueryResult, GenerateReturn } from '@mastra/core';
|
|
5
5
|
import { JSONSchema7 } from 'json-schema';
|
|
6
6
|
import { ZodSchema } from 'zod';
|
|
7
|
-
import { AgentGenerateOptions, AgentStreamOptions } from '@mastra/core/agent';
|
|
8
|
-
import { BaseLogMessage } from '@mastra/core/logger';
|
|
7
|
+
import { AgentGenerateOptions, AgentStreamOptions, ToolsInput } from '@mastra/core/agent';
|
|
8
|
+
import { LogLevel, BaseLogMessage } from '@mastra/core/logger';
|
|
9
9
|
import { RuntimeContext } from '@mastra/core/runtime-context';
|
|
10
10
|
import { Workflow as Workflow$1, WorkflowResult, WatchEvent } from '@mastra/core/workflows';
|
|
11
11
|
import { StepAction, StepGraph, LegacyWorkflowRunResult as LegacyWorkflowRunResult$1 } from '@mastra/core/workflows/legacy';
|
|
@@ -51,13 +51,15 @@ type GenerateParams<T extends JSONSchema7 | ZodSchema | undefined = undefined> =
|
|
|
51
51
|
output?: T;
|
|
52
52
|
experimental_output?: T;
|
|
53
53
|
runtimeContext?: RuntimeContext | Record<string, any>;
|
|
54
|
-
|
|
54
|
+
clientTools?: ToolsInput;
|
|
55
|
+
} & WithoutMethods<Omit<AgentGenerateOptions<T>, 'output' | 'experimental_output' | 'runtimeContext' | 'clientTools'>>;
|
|
55
56
|
type StreamParams<T extends JSONSchema7 | ZodSchema | undefined = undefined> = {
|
|
56
57
|
messages: string | string[] | CoreMessage[] | AiMessageType[];
|
|
57
58
|
output?: T;
|
|
58
59
|
experimental_output?: T;
|
|
59
60
|
runtimeContext?: RuntimeContext | Record<string, any>;
|
|
60
|
-
|
|
61
|
+
clientTools?: ToolsInput;
|
|
62
|
+
} & WithoutMethods<Omit<AgentStreamOptions<T>, 'output' | 'experimental_output' | 'runtimeContext' | 'clientTools'>>;
|
|
61
63
|
interface GetEvalsByAgentIdResponse extends GetAgentResponse {
|
|
62
64
|
evals: any[];
|
|
63
65
|
instructions: string;
|
|
@@ -179,12 +181,30 @@ interface GetMemoryThreadMessagesResponse {
|
|
|
179
181
|
}
|
|
180
182
|
interface GetLogsParams {
|
|
181
183
|
transportId: string;
|
|
184
|
+
fromDate?: Date;
|
|
185
|
+
toDate?: Date;
|
|
186
|
+
logLevel?: LogLevel;
|
|
187
|
+
filters?: Record<string, string>;
|
|
188
|
+
page?: number;
|
|
189
|
+
perPage?: number;
|
|
182
190
|
}
|
|
183
191
|
interface GetLogParams {
|
|
184
192
|
runId: string;
|
|
185
193
|
transportId: string;
|
|
194
|
+
fromDate?: Date;
|
|
195
|
+
toDate?: Date;
|
|
196
|
+
logLevel?: LogLevel;
|
|
197
|
+
filters?: Record<string, string>;
|
|
198
|
+
page?: number;
|
|
199
|
+
perPage?: number;
|
|
186
200
|
}
|
|
187
|
-
type GetLogsResponse =
|
|
201
|
+
type GetLogsResponse = {
|
|
202
|
+
logs: BaseLogMessage[];
|
|
203
|
+
total: number;
|
|
204
|
+
page: number;
|
|
205
|
+
perPage: number;
|
|
206
|
+
hasMore: boolean;
|
|
207
|
+
};
|
|
188
208
|
type RequestFunction = (path: string, options?: RequestOptions) => Promise<any>;
|
|
189
209
|
type SpanStatus = {
|
|
190
210
|
code: number;
|
|
@@ -329,7 +349,18 @@ declare class Agent extends BaseResource {
|
|
|
329
349
|
* @param params - Generation parameters including prompt
|
|
330
350
|
* @returns Promise containing the generated response
|
|
331
351
|
*/
|
|
332
|
-
generate<T extends JSONSchema7 | ZodSchema | undefined = undefined>(params: GenerateParams<T>
|
|
352
|
+
generate<T extends JSONSchema7 | ZodSchema | undefined = undefined>(params: GenerateParams<T> & {
|
|
353
|
+
output?: never;
|
|
354
|
+
experimental_output?: never;
|
|
355
|
+
}): Promise<GenerateReturn<T>>;
|
|
356
|
+
generate<T extends JSONSchema7 | ZodSchema | undefined = undefined>(params: GenerateParams<T> & {
|
|
357
|
+
output: T;
|
|
358
|
+
experimental_output?: never;
|
|
359
|
+
}): Promise<GenerateReturn<T>>;
|
|
360
|
+
generate<T extends JSONSchema7 | ZodSchema | undefined = undefined>(params: GenerateParams<T> & {
|
|
361
|
+
output?: never;
|
|
362
|
+
experimental_output: T;
|
|
363
|
+
}): Promise<GenerateReturn<T>>;
|
|
333
364
|
/**
|
|
334
365
|
* Streams a response from the agent
|
|
335
366
|
* @param params - Stream parameters including prompt
|
package/dist/index.d.ts
CHANGED
|
@@ -4,8 +4,8 @@ import { processDataStream } from '@ai-sdk/ui-utils';
|
|
|
4
4
|
import { CoreMessage, AiMessageType, StorageThreadType, MastraMessageV1, LegacyWorkflowRuns, WorkflowRuns, QueryResult, GenerateReturn } from '@mastra/core';
|
|
5
5
|
import { JSONSchema7 } from 'json-schema';
|
|
6
6
|
import { ZodSchema } from 'zod';
|
|
7
|
-
import { AgentGenerateOptions, AgentStreamOptions } from '@mastra/core/agent';
|
|
8
|
-
import { BaseLogMessage } from '@mastra/core/logger';
|
|
7
|
+
import { AgentGenerateOptions, AgentStreamOptions, ToolsInput } from '@mastra/core/agent';
|
|
8
|
+
import { LogLevel, BaseLogMessage } from '@mastra/core/logger';
|
|
9
9
|
import { RuntimeContext } from '@mastra/core/runtime-context';
|
|
10
10
|
import { Workflow as Workflow$1, WorkflowResult, WatchEvent } from '@mastra/core/workflows';
|
|
11
11
|
import { StepAction, StepGraph, LegacyWorkflowRunResult as LegacyWorkflowRunResult$1 } from '@mastra/core/workflows/legacy';
|
|
@@ -51,13 +51,15 @@ type GenerateParams<T extends JSONSchema7 | ZodSchema | undefined = undefined> =
|
|
|
51
51
|
output?: T;
|
|
52
52
|
experimental_output?: T;
|
|
53
53
|
runtimeContext?: RuntimeContext | Record<string, any>;
|
|
54
|
-
|
|
54
|
+
clientTools?: ToolsInput;
|
|
55
|
+
} & WithoutMethods<Omit<AgentGenerateOptions<T>, 'output' | 'experimental_output' | 'runtimeContext' | 'clientTools'>>;
|
|
55
56
|
type StreamParams<T extends JSONSchema7 | ZodSchema | undefined = undefined> = {
|
|
56
57
|
messages: string | string[] | CoreMessage[] | AiMessageType[];
|
|
57
58
|
output?: T;
|
|
58
59
|
experimental_output?: T;
|
|
59
60
|
runtimeContext?: RuntimeContext | Record<string, any>;
|
|
60
|
-
|
|
61
|
+
clientTools?: ToolsInput;
|
|
62
|
+
} & WithoutMethods<Omit<AgentStreamOptions<T>, 'output' | 'experimental_output' | 'runtimeContext' | 'clientTools'>>;
|
|
61
63
|
interface GetEvalsByAgentIdResponse extends GetAgentResponse {
|
|
62
64
|
evals: any[];
|
|
63
65
|
instructions: string;
|
|
@@ -179,12 +181,30 @@ interface GetMemoryThreadMessagesResponse {
|
|
|
179
181
|
}
|
|
180
182
|
interface GetLogsParams {
|
|
181
183
|
transportId: string;
|
|
184
|
+
fromDate?: Date;
|
|
185
|
+
toDate?: Date;
|
|
186
|
+
logLevel?: LogLevel;
|
|
187
|
+
filters?: Record<string, string>;
|
|
188
|
+
page?: number;
|
|
189
|
+
perPage?: number;
|
|
182
190
|
}
|
|
183
191
|
interface GetLogParams {
|
|
184
192
|
runId: string;
|
|
185
193
|
transportId: string;
|
|
194
|
+
fromDate?: Date;
|
|
195
|
+
toDate?: Date;
|
|
196
|
+
logLevel?: LogLevel;
|
|
197
|
+
filters?: Record<string, string>;
|
|
198
|
+
page?: number;
|
|
199
|
+
perPage?: number;
|
|
186
200
|
}
|
|
187
|
-
type GetLogsResponse =
|
|
201
|
+
type GetLogsResponse = {
|
|
202
|
+
logs: BaseLogMessage[];
|
|
203
|
+
total: number;
|
|
204
|
+
page: number;
|
|
205
|
+
perPage: number;
|
|
206
|
+
hasMore: boolean;
|
|
207
|
+
};
|
|
188
208
|
type RequestFunction = (path: string, options?: RequestOptions) => Promise<any>;
|
|
189
209
|
type SpanStatus = {
|
|
190
210
|
code: number;
|
|
@@ -329,7 +349,18 @@ declare class Agent extends BaseResource {
|
|
|
329
349
|
* @param params - Generation parameters including prompt
|
|
330
350
|
* @returns Promise containing the generated response
|
|
331
351
|
*/
|
|
332
|
-
generate<T extends JSONSchema7 | ZodSchema | undefined = undefined>(params: GenerateParams<T>
|
|
352
|
+
generate<T extends JSONSchema7 | ZodSchema | undefined = undefined>(params: GenerateParams<T> & {
|
|
353
|
+
output?: never;
|
|
354
|
+
experimental_output?: never;
|
|
355
|
+
}): Promise<GenerateReturn<T>>;
|
|
356
|
+
generate<T extends JSONSchema7 | ZodSchema | undefined = undefined>(params: GenerateParams<T> & {
|
|
357
|
+
output: T;
|
|
358
|
+
experimental_output?: never;
|
|
359
|
+
}): Promise<GenerateReturn<T>>;
|
|
360
|
+
generate<T extends JSONSchema7 | ZodSchema | undefined = undefined>(params: GenerateParams<T> & {
|
|
361
|
+
output?: never;
|
|
362
|
+
experimental_output: T;
|
|
363
|
+
}): Promise<GenerateReturn<T>>;
|
|
333
364
|
/**
|
|
334
365
|
* Streams a response from the agent
|
|
335
366
|
* @param params - Stream parameters including prompt
|
package/dist/index.js
CHANGED
|
@@ -3,6 +3,7 @@ import { Observable } from 'rxjs';
|
|
|
3
3
|
import { processDataStream } from '@ai-sdk/ui-utils';
|
|
4
4
|
import { ZodSchema } from 'zod';
|
|
5
5
|
import originalZodToJsonSchema from 'zod-to-json-schema';
|
|
6
|
+
import { isVercelTool } from '@mastra/core/tools';
|
|
6
7
|
import { RuntimeContext } from '@mastra/core/runtime-context';
|
|
7
8
|
|
|
8
9
|
// src/adapters/agui.ts
|
|
@@ -196,6 +197,33 @@ function zodToJsonSchema(zodSchema) {
|
|
|
196
197
|
}
|
|
197
198
|
return originalZodToJsonSchema(zodSchema, { $refStrategy: "none" });
|
|
198
199
|
}
|
|
200
|
+
function processClientTools(clientTools) {
|
|
201
|
+
if (!clientTools) {
|
|
202
|
+
return void 0;
|
|
203
|
+
}
|
|
204
|
+
return Object.fromEntries(
|
|
205
|
+
Object.entries(clientTools).map(([key, value]) => {
|
|
206
|
+
if (isVercelTool(value)) {
|
|
207
|
+
return [
|
|
208
|
+
key,
|
|
209
|
+
{
|
|
210
|
+
...value,
|
|
211
|
+
parameters: value.parameters ? zodToJsonSchema(value.parameters) : void 0
|
|
212
|
+
}
|
|
213
|
+
];
|
|
214
|
+
} else {
|
|
215
|
+
return [
|
|
216
|
+
key,
|
|
217
|
+
{
|
|
218
|
+
...value,
|
|
219
|
+
inputSchema: value.inputSchema ? zodToJsonSchema(value.inputSchema) : void 0,
|
|
220
|
+
outputSchema: value.outputSchema ? zodToJsonSchema(value.outputSchema) : void 0
|
|
221
|
+
}
|
|
222
|
+
];
|
|
223
|
+
}
|
|
224
|
+
})
|
|
225
|
+
);
|
|
226
|
+
}
|
|
199
227
|
|
|
200
228
|
// src/resources/base.ts
|
|
201
229
|
var BaseResource = class {
|
|
@@ -334,17 +362,13 @@ var Agent = class extends BaseResource {
|
|
|
334
362
|
details() {
|
|
335
363
|
return this.request(`/api/agents/${this.agentId}`);
|
|
336
364
|
}
|
|
337
|
-
/**
|
|
338
|
-
* Generates a response from the agent
|
|
339
|
-
* @param params - Generation parameters including prompt
|
|
340
|
-
* @returns Promise containing the generated response
|
|
341
|
-
*/
|
|
342
365
|
generate(params) {
|
|
343
366
|
const processedParams = {
|
|
344
367
|
...params,
|
|
345
368
|
output: params.output ? zodToJsonSchema(params.output) : void 0,
|
|
346
369
|
experimental_output: params.experimental_output ? zodToJsonSchema(params.experimental_output) : void 0,
|
|
347
|
-
runtimeContext: parseClientRuntimeContext(params.runtimeContext)
|
|
370
|
+
runtimeContext: parseClientRuntimeContext(params.runtimeContext),
|
|
371
|
+
clientTools: processClientTools(params.clientTools)
|
|
348
372
|
};
|
|
349
373
|
return this.request(`/api/agents/${this.agentId}/generate`, {
|
|
350
374
|
method: "POST",
|
|
@@ -361,7 +385,8 @@ var Agent = class extends BaseResource {
|
|
|
361
385
|
...params,
|
|
362
386
|
output: params.output ? zodToJsonSchema(params.output) : void 0,
|
|
363
387
|
experimental_output: params.experimental_output ? zodToJsonSchema(params.experimental_output) : void 0,
|
|
364
|
-
runtimeContext: parseClientRuntimeContext(params.runtimeContext)
|
|
388
|
+
runtimeContext: parseClientRuntimeContext(params.runtimeContext),
|
|
389
|
+
clientTools: processClientTools(params.clientTools)
|
|
365
390
|
};
|
|
366
391
|
const response = await this.request(`/api/agents/${this.agentId}/stream`, {
|
|
367
392
|
method: "POST",
|
|
@@ -1310,7 +1335,41 @@ var MastraClient = class extends BaseResource {
|
|
|
1310
1335
|
* @returns Promise containing array of log messages
|
|
1311
1336
|
*/
|
|
1312
1337
|
getLogs(params) {
|
|
1313
|
-
|
|
1338
|
+
const { transportId, fromDate, toDate, logLevel, filters, page, perPage } = params;
|
|
1339
|
+
const _filters = filters ? Object.entries(filters).map(([key, value]) => `${key}:${value}`) : [];
|
|
1340
|
+
const searchParams = new URLSearchParams();
|
|
1341
|
+
if (transportId) {
|
|
1342
|
+
searchParams.set("transportId", transportId);
|
|
1343
|
+
}
|
|
1344
|
+
if (fromDate) {
|
|
1345
|
+
searchParams.set("fromDate", fromDate.toISOString());
|
|
1346
|
+
}
|
|
1347
|
+
if (toDate) {
|
|
1348
|
+
searchParams.set("toDate", toDate.toISOString());
|
|
1349
|
+
}
|
|
1350
|
+
if (logLevel) {
|
|
1351
|
+
searchParams.set("logLevel", logLevel);
|
|
1352
|
+
}
|
|
1353
|
+
if (page) {
|
|
1354
|
+
searchParams.set("page", String(page));
|
|
1355
|
+
}
|
|
1356
|
+
if (perPage) {
|
|
1357
|
+
searchParams.set("perPage", String(perPage));
|
|
1358
|
+
}
|
|
1359
|
+
if (_filters) {
|
|
1360
|
+
if (Array.isArray(_filters)) {
|
|
1361
|
+
for (const filter of _filters) {
|
|
1362
|
+
searchParams.append("filters", filter);
|
|
1363
|
+
}
|
|
1364
|
+
} else {
|
|
1365
|
+
searchParams.set("filters", _filters);
|
|
1366
|
+
}
|
|
1367
|
+
}
|
|
1368
|
+
if (searchParams.size) {
|
|
1369
|
+
return this.request(`/api/logs?${searchParams}`);
|
|
1370
|
+
} else {
|
|
1371
|
+
return this.request(`/api/logs`);
|
|
1372
|
+
}
|
|
1314
1373
|
}
|
|
1315
1374
|
/**
|
|
1316
1375
|
* Gets logs for a specific run
|
|
@@ -1318,7 +1377,44 @@ var MastraClient = class extends BaseResource {
|
|
|
1318
1377
|
* @returns Promise containing array of log messages
|
|
1319
1378
|
*/
|
|
1320
1379
|
getLogForRun(params) {
|
|
1321
|
-
|
|
1380
|
+
const { runId, transportId, fromDate, toDate, logLevel, filters, page, perPage } = params;
|
|
1381
|
+
const _filters = filters ? Object.entries(filters).map(([key, value]) => `${key}:${value}`) : [];
|
|
1382
|
+
const searchParams = new URLSearchParams();
|
|
1383
|
+
if (runId) {
|
|
1384
|
+
searchParams.set("runId", runId);
|
|
1385
|
+
}
|
|
1386
|
+
if (transportId) {
|
|
1387
|
+
searchParams.set("transportId", transportId);
|
|
1388
|
+
}
|
|
1389
|
+
if (fromDate) {
|
|
1390
|
+
searchParams.set("fromDate", fromDate.toISOString());
|
|
1391
|
+
}
|
|
1392
|
+
if (toDate) {
|
|
1393
|
+
searchParams.set("toDate", toDate.toISOString());
|
|
1394
|
+
}
|
|
1395
|
+
if (logLevel) {
|
|
1396
|
+
searchParams.set("logLevel", logLevel);
|
|
1397
|
+
}
|
|
1398
|
+
if (page) {
|
|
1399
|
+
searchParams.set("page", String(page));
|
|
1400
|
+
}
|
|
1401
|
+
if (perPage) {
|
|
1402
|
+
searchParams.set("perPage", String(perPage));
|
|
1403
|
+
}
|
|
1404
|
+
if (_filters) {
|
|
1405
|
+
if (Array.isArray(_filters)) {
|
|
1406
|
+
for (const filter of _filters) {
|
|
1407
|
+
searchParams.append("filters", filter);
|
|
1408
|
+
}
|
|
1409
|
+
} else {
|
|
1410
|
+
searchParams.set("filters", _filters);
|
|
1411
|
+
}
|
|
1412
|
+
}
|
|
1413
|
+
if (searchParams.size) {
|
|
1414
|
+
return this.request(`/api/logs/${runId}?${searchParams}`);
|
|
1415
|
+
} else {
|
|
1416
|
+
return this.request(`/api/logs/${runId}`);
|
|
1417
|
+
}
|
|
1322
1418
|
}
|
|
1323
1419
|
/**
|
|
1324
1420
|
* List of all log transports
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mastra/client-js",
|
|
3
|
-
"version": "0.10.
|
|
3
|
+
"version": "0.10.3-alpha.0",
|
|
4
4
|
"description": "The official TypeScript library for the Mastra Client API",
|
|
5
5
|
"author": "",
|
|
6
6
|
"type": "module",
|
|
@@ -27,23 +27,22 @@
|
|
|
27
27
|
"json-schema": "^0.4.0",
|
|
28
28
|
"rxjs": "7.8.1",
|
|
29
29
|
"zod": "^3.24.3",
|
|
30
|
-
"zod-to-json-schema": "^3.24.5"
|
|
30
|
+
"zod-to-json-schema": "^3.24.5",
|
|
31
|
+
"@mastra/core": "0.10.4-alpha.0"
|
|
31
32
|
},
|
|
32
33
|
"peerDependencies": {
|
|
33
|
-
"zod": "^3.0.0"
|
|
34
|
-
"@mastra/core": "^0.10.0-alpha.0"
|
|
34
|
+
"zod": "^3.0.0"
|
|
35
35
|
},
|
|
36
36
|
"devDependencies": {
|
|
37
37
|
"@babel/preset-env": "^7.26.9",
|
|
38
38
|
"@babel/preset-typescript": "^7.27.0",
|
|
39
39
|
"@tsconfig/recommended": "^1.0.8",
|
|
40
40
|
"@types/json-schema": "^7.0.15",
|
|
41
|
-
"@types/node": "^20.17.
|
|
42
|
-
"tsup": "^8.
|
|
41
|
+
"@types/node": "^20.17.57",
|
|
42
|
+
"tsup": "^8.5.0",
|
|
43
43
|
"typescript": "^5.8.2",
|
|
44
44
|
"vitest": "^3.1.2",
|
|
45
|
-
"@internal/lint": "0.0.
|
|
46
|
-
"@mastra/core": "0.10.2-alpha.4"
|
|
45
|
+
"@internal/lint": "0.0.10"
|
|
47
46
|
},
|
|
48
47
|
"scripts": {
|
|
49
48
|
"build": "tsup src/index.ts --format esm,cjs --dts --clean --treeshake=smallest --splitting",
|
package/src/client.ts
CHANGED
|
@@ -189,7 +189,43 @@ export class MastraClient extends BaseResource {
|
|
|
189
189
|
* @returns Promise containing array of log messages
|
|
190
190
|
*/
|
|
191
191
|
public getLogs(params: GetLogsParams): Promise<GetLogsResponse> {
|
|
192
|
-
|
|
192
|
+
const { transportId, fromDate, toDate, logLevel, filters, page, perPage } = params;
|
|
193
|
+
const _filters = filters ? Object.entries(filters).map(([key, value]) => `${key}:${value}`) : [];
|
|
194
|
+
|
|
195
|
+
const searchParams = new URLSearchParams();
|
|
196
|
+
if (transportId) {
|
|
197
|
+
searchParams.set('transportId', transportId);
|
|
198
|
+
}
|
|
199
|
+
if (fromDate) {
|
|
200
|
+
searchParams.set('fromDate', fromDate.toISOString());
|
|
201
|
+
}
|
|
202
|
+
if (toDate) {
|
|
203
|
+
searchParams.set('toDate', toDate.toISOString());
|
|
204
|
+
}
|
|
205
|
+
if (logLevel) {
|
|
206
|
+
searchParams.set('logLevel', logLevel);
|
|
207
|
+
}
|
|
208
|
+
if (page) {
|
|
209
|
+
searchParams.set('page', String(page));
|
|
210
|
+
}
|
|
211
|
+
if (perPage) {
|
|
212
|
+
searchParams.set('perPage', String(perPage));
|
|
213
|
+
}
|
|
214
|
+
if (_filters) {
|
|
215
|
+
if (Array.isArray(_filters)) {
|
|
216
|
+
for (const filter of _filters) {
|
|
217
|
+
searchParams.append('filters', filter);
|
|
218
|
+
}
|
|
219
|
+
} else {
|
|
220
|
+
searchParams.set('filters', _filters);
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
if (searchParams.size) {
|
|
225
|
+
return this.request(`/api/logs?${searchParams}`);
|
|
226
|
+
} else {
|
|
227
|
+
return this.request(`/api/logs`);
|
|
228
|
+
}
|
|
193
229
|
}
|
|
194
230
|
|
|
195
231
|
/**
|
|
@@ -198,7 +234,47 @@ export class MastraClient extends BaseResource {
|
|
|
198
234
|
* @returns Promise containing array of log messages
|
|
199
235
|
*/
|
|
200
236
|
public getLogForRun(params: GetLogParams): Promise<GetLogsResponse> {
|
|
201
|
-
|
|
237
|
+
const { runId, transportId, fromDate, toDate, logLevel, filters, page, perPage } = params;
|
|
238
|
+
|
|
239
|
+
const _filters = filters ? Object.entries(filters).map(([key, value]) => `${key}:${value}`) : [];
|
|
240
|
+
const searchParams = new URLSearchParams();
|
|
241
|
+
if (runId) {
|
|
242
|
+
searchParams.set('runId', runId);
|
|
243
|
+
}
|
|
244
|
+
if (transportId) {
|
|
245
|
+
searchParams.set('transportId', transportId);
|
|
246
|
+
}
|
|
247
|
+
if (fromDate) {
|
|
248
|
+
searchParams.set('fromDate', fromDate.toISOString());
|
|
249
|
+
}
|
|
250
|
+
if (toDate) {
|
|
251
|
+
searchParams.set('toDate', toDate.toISOString());
|
|
252
|
+
}
|
|
253
|
+
if (logLevel) {
|
|
254
|
+
searchParams.set('logLevel', logLevel);
|
|
255
|
+
}
|
|
256
|
+
if (page) {
|
|
257
|
+
searchParams.set('page', String(page));
|
|
258
|
+
}
|
|
259
|
+
if (perPage) {
|
|
260
|
+
searchParams.set('perPage', String(perPage));
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
if (_filters) {
|
|
264
|
+
if (Array.isArray(_filters)) {
|
|
265
|
+
for (const filter of _filters) {
|
|
266
|
+
searchParams.append('filters', filter);
|
|
267
|
+
}
|
|
268
|
+
} else {
|
|
269
|
+
searchParams.set('filters', _filters);
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
if (searchParams.size) {
|
|
274
|
+
return this.request(`/api/logs/${runId}?${searchParams}`);
|
|
275
|
+
} else {
|
|
276
|
+
return this.request(`/api/logs/${runId}`);
|
|
277
|
+
}
|
|
202
278
|
}
|
|
203
279
|
|
|
204
280
|
/**
|
package/src/resources/agent.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { processDataStream } from '@ai-sdk/ui-utils';
|
|
2
|
-
import type
|
|
2
|
+
import { type GenerateReturn } from '@mastra/core';
|
|
3
3
|
import type { JSONSchema7 } from 'json-schema';
|
|
4
4
|
import { ZodSchema } from 'zod';
|
|
5
5
|
import { zodToJsonSchema } from '../utils/zod-to-json-schema';
|
|
6
|
+
import { processClientTools } from '../utils/process-client-tools';
|
|
6
7
|
|
|
7
8
|
import type {
|
|
8
9
|
GenerateParams,
|
|
@@ -104,6 +105,15 @@ export class Agent extends BaseResource {
|
|
|
104
105
|
* @param params - Generation parameters including prompt
|
|
105
106
|
* @returns Promise containing the generated response
|
|
106
107
|
*/
|
|
108
|
+
generate<T extends JSONSchema7 | ZodSchema | undefined = undefined>(
|
|
109
|
+
params: GenerateParams<T> & { output?: never; experimental_output?: never },
|
|
110
|
+
): Promise<GenerateReturn<T>>;
|
|
111
|
+
generate<T extends JSONSchema7 | ZodSchema | undefined = undefined>(
|
|
112
|
+
params: GenerateParams<T> & { output: T; experimental_output?: never },
|
|
113
|
+
): Promise<GenerateReturn<T>>;
|
|
114
|
+
generate<T extends JSONSchema7 | ZodSchema | undefined = undefined>(
|
|
115
|
+
params: GenerateParams<T> & { output?: never; experimental_output: T },
|
|
116
|
+
): Promise<GenerateReturn<T>>;
|
|
107
117
|
generate<T extends JSONSchema7 | ZodSchema | undefined = undefined>(
|
|
108
118
|
params: GenerateParams<T>,
|
|
109
119
|
): Promise<GenerateReturn<T>> {
|
|
@@ -112,6 +122,7 @@ export class Agent extends BaseResource {
|
|
|
112
122
|
output: params.output ? zodToJsonSchema(params.output) : undefined,
|
|
113
123
|
experimental_output: params.experimental_output ? zodToJsonSchema(params.experimental_output) : undefined,
|
|
114
124
|
runtimeContext: parseClientRuntimeContext(params.runtimeContext),
|
|
125
|
+
clientTools: processClientTools(params.clientTools),
|
|
115
126
|
};
|
|
116
127
|
|
|
117
128
|
return this.request(`/api/agents/${this.agentId}/generate`, {
|
|
@@ -137,6 +148,7 @@ export class Agent extends BaseResource {
|
|
|
137
148
|
output: params.output ? zodToJsonSchema(params.output) : undefined,
|
|
138
149
|
experimental_output: params.experimental_output ? zodToJsonSchema(params.experimental_output) : undefined,
|
|
139
150
|
runtimeContext: parseClientRuntimeContext(params.runtimeContext),
|
|
151
|
+
clientTools: processClientTools(params.clientTools),
|
|
140
152
|
};
|
|
141
153
|
|
|
142
154
|
const response: Response & {
|
package/src/types.ts
CHANGED
|
@@ -7,8 +7,8 @@ import type {
|
|
|
7
7
|
WorkflowRuns,
|
|
8
8
|
LegacyWorkflowRuns,
|
|
9
9
|
} from '@mastra/core';
|
|
10
|
-
import type { AgentGenerateOptions, AgentStreamOptions } from '@mastra/core/agent';
|
|
11
|
-
import type { BaseLogMessage } from '@mastra/core/logger';
|
|
10
|
+
import type { AgentGenerateOptions, AgentStreamOptions, ToolsInput } from '@mastra/core/agent';
|
|
11
|
+
import type { BaseLogMessage, LogLevel } from '@mastra/core/logger';
|
|
12
12
|
|
|
13
13
|
import type { MCPToolType, ServerInfo } from '@mastra/core/mcp';
|
|
14
14
|
import type { RuntimeContext } from '@mastra/core/runtime-context';
|
|
@@ -69,14 +69,16 @@ export type GenerateParams<T extends JSONSchema7 | ZodSchema | undefined = undef
|
|
|
69
69
|
output?: T;
|
|
70
70
|
experimental_output?: T;
|
|
71
71
|
runtimeContext?: RuntimeContext | Record<string, any>;
|
|
72
|
-
|
|
72
|
+
clientTools?: ToolsInput;
|
|
73
|
+
} & WithoutMethods<Omit<AgentGenerateOptions<T>, 'output' | 'experimental_output' | 'runtimeContext' | 'clientTools'>>;
|
|
73
74
|
|
|
74
75
|
export type StreamParams<T extends JSONSchema7 | ZodSchema | undefined = undefined> = {
|
|
75
76
|
messages: string | string[] | CoreMessage[] | AiMessageType[];
|
|
76
77
|
output?: T;
|
|
77
78
|
experimental_output?: T;
|
|
78
79
|
runtimeContext?: RuntimeContext | Record<string, any>;
|
|
79
|
-
|
|
80
|
+
clientTools?: ToolsInput;
|
|
81
|
+
} & WithoutMethods<Omit<AgentStreamOptions<T>, 'output' | 'experimental_output' | 'runtimeContext' | 'clientTools'>>;
|
|
80
82
|
|
|
81
83
|
export interface GetEvalsByAgentIdResponse extends GetAgentResponse {
|
|
82
84
|
evals: any[];
|
|
@@ -215,14 +217,32 @@ export interface GetMemoryThreadMessagesResponse {
|
|
|
215
217
|
|
|
216
218
|
export interface GetLogsParams {
|
|
217
219
|
transportId: string;
|
|
220
|
+
fromDate?: Date;
|
|
221
|
+
toDate?: Date;
|
|
222
|
+
logLevel?: LogLevel;
|
|
223
|
+
filters?: Record<string, string>;
|
|
224
|
+
page?: number;
|
|
225
|
+
perPage?: number;
|
|
218
226
|
}
|
|
219
227
|
|
|
220
228
|
export interface GetLogParams {
|
|
221
229
|
runId: string;
|
|
222
230
|
transportId: string;
|
|
231
|
+
fromDate?: Date;
|
|
232
|
+
toDate?: Date;
|
|
233
|
+
logLevel?: LogLevel;
|
|
234
|
+
filters?: Record<string, string>;
|
|
235
|
+
page?: number;
|
|
236
|
+
perPage?: number;
|
|
223
237
|
}
|
|
224
238
|
|
|
225
|
-
export type GetLogsResponse =
|
|
239
|
+
export type GetLogsResponse = {
|
|
240
|
+
logs: BaseLogMessage[];
|
|
241
|
+
total: number;
|
|
242
|
+
page: number;
|
|
243
|
+
perPage: number;
|
|
244
|
+
hasMore: boolean;
|
|
245
|
+
};
|
|
226
246
|
|
|
227
247
|
export type RequestFunction = (path: string, options?: RequestOptions) => Promise<any>;
|
|
228
248
|
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { isVercelTool } from '@mastra/core/tools';
|
|
2
|
+
import { zodToJsonSchema } from './zod-to-json-schema';
|
|
3
|
+
|
|
4
|
+
export function processClientTools(clientTools: Record<string, any> | undefined): Record<string, any> | undefined {
|
|
5
|
+
if (!clientTools) {
|
|
6
|
+
return undefined;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
return Object.fromEntries(
|
|
10
|
+
Object.entries(clientTools).map(([key, value]) => {
|
|
11
|
+
if (isVercelTool(value)) {
|
|
12
|
+
return [
|
|
13
|
+
key,
|
|
14
|
+
{
|
|
15
|
+
...value,
|
|
16
|
+
parameters: value.parameters ? zodToJsonSchema(value.parameters) : undefined,
|
|
17
|
+
},
|
|
18
|
+
];
|
|
19
|
+
} else {
|
|
20
|
+
return [
|
|
21
|
+
key,
|
|
22
|
+
{
|
|
23
|
+
...value,
|
|
24
|
+
inputSchema: value.inputSchema ? zodToJsonSchema(value.inputSchema) : undefined,
|
|
25
|
+
outputSchema: value.outputSchema ? zodToJsonSchema(value.outputSchema) : undefined,
|
|
26
|
+
},
|
|
27
|
+
];
|
|
28
|
+
}
|
|
29
|
+
}),
|
|
30
|
+
) as Record<string, any>;
|
|
31
|
+
}
|