@mastra/client-js 0.1.0-alpha.5 → 0.1.0-alpha.6
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/package.json +4 -2
- package/src/resources/agent.ts +17 -4
- package/src/types.ts +3 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mastra/client-js",
|
|
3
|
-
"version": "0.1.0-alpha.
|
|
3
|
+
"version": "0.1.0-alpha.6",
|
|
4
4
|
"description": "The official TypeScript library for the Mastra Client API",
|
|
5
5
|
"author": "",
|
|
6
6
|
"types": "dist/index.d.mts",
|
|
@@ -18,7 +18,9 @@
|
|
|
18
18
|
"license": "ISC",
|
|
19
19
|
"dependencies": {
|
|
20
20
|
"@mastra/core": "^0.2.0-alpha.83",
|
|
21
|
-
"json-schema": "^0.4.0"
|
|
21
|
+
"json-schema": "^0.4.0",
|
|
22
|
+
"zod": "^3.24.1",
|
|
23
|
+
"zod-to-json-schema": "^3.24.1"
|
|
22
24
|
},
|
|
23
25
|
"devDependencies": {
|
|
24
26
|
"@babel/preset-env": "^7.26.0",
|
package/src/resources/agent.ts
CHANGED
|
@@ -11,6 +11,8 @@ import type {
|
|
|
11
11
|
StreamReturn,
|
|
12
12
|
} from '@mastra/core';
|
|
13
13
|
import type { JSONSchema7 } from 'json-schema';
|
|
14
|
+
import { ZodSchema } from "zod";
|
|
15
|
+
import { zodToJsonSchema } from 'zod-to-json-schema';
|
|
14
16
|
|
|
15
17
|
export class AgentTool {
|
|
16
18
|
constructor(
|
|
@@ -51,10 +53,15 @@ export class Agent {
|
|
|
51
53
|
* @param params - Generation parameters including prompt
|
|
52
54
|
* @returns Promise containing the generated response
|
|
53
55
|
*/
|
|
54
|
-
generate<T extends JSONSchema7 | undefined = undefined>(params: GenerateParams<T>): Promise<GenerateReturn<T>> {
|
|
56
|
+
generate<T extends JSONSchema7 | ZodSchema | undefined = undefined>(params: GenerateParams<T>): Promise<GenerateReturn<T>> {
|
|
57
|
+
const processedParams = {
|
|
58
|
+
...params,
|
|
59
|
+
output: params.output instanceof ZodSchema ? zodToJsonSchema(params.output) : params.output
|
|
60
|
+
};
|
|
61
|
+
|
|
55
62
|
return this.request(`/api/agents/${this.agentId}/generate`, {
|
|
56
63
|
method: 'POST',
|
|
57
|
-
body:
|
|
64
|
+
body: processedParams,
|
|
58
65
|
});
|
|
59
66
|
}
|
|
60
67
|
|
|
@@ -63,10 +70,16 @@ export class Agent {
|
|
|
63
70
|
* @param params - Stream parameters including prompt
|
|
64
71
|
* @returns Promise containing the streamed response
|
|
65
72
|
*/
|
|
66
|
-
stream<T extends JSONSchema7 | undefined = undefined>(params: StreamParams<T>): Promise<StreamReturn<T>> {
|
|
73
|
+
stream<T extends JSONSchema7 | ZodSchema | undefined = undefined>(params: StreamParams<T>): Promise<StreamReturn<T>> {
|
|
74
|
+
const processedParams = {
|
|
75
|
+
...params,
|
|
76
|
+
output: params.output instanceof ZodSchema ? zodToJsonSchema(params.output) : params.output,
|
|
77
|
+
stream: true
|
|
78
|
+
};
|
|
79
|
+
|
|
67
80
|
return this.request(`/api/agents/${this.agentId}/generate`, {
|
|
68
81
|
method: 'POST',
|
|
69
|
-
body:
|
|
82
|
+
body: processedParams,
|
|
70
83
|
});
|
|
71
84
|
}
|
|
72
85
|
|
package/src/types.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { MessageType, AiMessageType, CoreMessage, QueryResult, StepAction, StepGraph, StorageThreadType, BaseLogMessage, OutputType } from "@mastra/core";
|
|
2
2
|
import type { JSONSchema7 } from 'json-schema';
|
|
3
|
+
import { ZodSchema } from "zod";
|
|
3
4
|
|
|
4
5
|
export interface ClientOptions {
|
|
5
6
|
baseUrl: string;
|
|
@@ -22,14 +23,14 @@ export interface GetAgentResponse {
|
|
|
22
23
|
tools: Record<string, GetToolResponse>;
|
|
23
24
|
}
|
|
24
25
|
|
|
25
|
-
export interface GenerateParams<T extends JSONSchema7 | undefined = undefined> {
|
|
26
|
+
export interface GenerateParams<T extends JSONSchema7 | ZodSchema | undefined = undefined> {
|
|
26
27
|
messages: MessageType[];
|
|
27
28
|
threadId?: string;
|
|
28
29
|
resourceid?: string;
|
|
29
30
|
output?: OutputType | T
|
|
30
31
|
}
|
|
31
32
|
|
|
32
|
-
export interface StreamParams<T extends JSONSchema7 | undefined = undefined> {
|
|
33
|
+
export interface StreamParams<T extends JSONSchema7 | ZodSchema | undefined = undefined> {
|
|
33
34
|
messages: MessageType[];
|
|
34
35
|
threadId?: string;
|
|
35
36
|
resourceid?: string;
|