@mastra/client-js 0.1.0-alpha.3 → 0.1.0-alpha.4

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/README.md CHANGED
@@ -25,7 +25,7 @@ async function main() {
25
25
 
26
26
  // Generate a response
27
27
  const response = await agent.generate({
28
- prompt: "What's the weather like today?"
28
+ messages: [{ role: 'user', content: "What's the weather like today?" }],
29
29
  });
30
30
 
31
31
  console.log(response);
package/dist/index.d.mts CHANGED
@@ -1,4 +1,5 @@
1
- import { StorageThreadType, CoreMessage, AiMessageType, MessageType, StepAction, StepGraph, QueryResult, BaseLogMessage, GenerateReturn, StreamReturn } from '@mastra/core';
1
+ import { MessageType, OutputType, StorageThreadType, CoreMessage, AiMessageType, StepAction, StepGraph, QueryResult, BaseLogMessage, GenerateReturn, StreamReturn } from '@mastra/core';
2
+ import { JSONSchema7 } from 'json-schema';
2
3
  import { StorageThreadType as StorageThreadType$1 } from '@mastra/core/memory';
3
4
 
4
5
  interface ClientOptions {
@@ -19,6 +20,18 @@ interface GetAgentResponse {
19
20
  instructions: string;
20
21
  tools: Record<string, GetToolResponse>;
21
22
  }
23
+ interface GenerateParams<T extends JSONSchema7 | undefined = undefined> {
24
+ messages: MessageType[];
25
+ threadId?: string;
26
+ resourceid?: string;
27
+ output?: OutputType | T;
28
+ }
29
+ interface StreamParams<T extends JSONSchema7 | undefined = undefined> {
30
+ messages: MessageType[];
31
+ threadId?: string;
32
+ resourceid?: string;
33
+ output?: OutputType | T;
34
+ }
22
35
  interface GetEvalsByAgentIdResponse extends GetAgentResponse {
23
36
  evals: any[];
24
37
  }
@@ -109,13 +122,13 @@ declare class Agent {
109
122
  * @param params - Generation parameters including prompt
110
123
  * @returns Promise containing the generated response
111
124
  */
112
- generate<T>(params: any): Promise<GenerateReturn<T>>;
125
+ generate<T extends JSONSchema7 | undefined = undefined>(params: GenerateParams<T>): Promise<GenerateReturn<T>>;
113
126
  /**
114
127
  * Streams a response from the agent
115
128
  * @param params - Stream parameters including prompt
116
129
  * @returns Promise containing the streamed response
117
130
  */
118
- stream<T>(params: any): Promise<StreamReturn<T>>;
131
+ stream<T extends JSONSchema7 | undefined = undefined>(params: StreamParams<T>): Promise<StreamReturn<T>>;
119
132
  /**
120
133
  * Gets details about a specific tool available to the agent
121
134
  * @param toolId - ID of the tool to retrieve
@@ -343,4 +356,4 @@ declare class MastraClient {
343
356
  getLogForRun(params: GetLogParams): Promise<GetLogsResponse>;
344
357
  }
345
358
 
346
- export { type ClientOptions, type CreateIndexParams, type CreateMemoryThreadParams, type CreateMemoryThreadResponse, type GetAgentResponse, type GetEvalsByAgentIdResponse, type GetLogParams, type GetLogsParams, type GetLogsResponse, type GetMemoryThreadMessagesResponse, type GetMemoryThreadParams, type GetMemoryThreadResponse, type GetToolResponse, type GetVectorIndexResponse, type GetWorkflowResponse, MastraClient, type QueryVectorParams, type QueryVectorResponse, type RequestFunction, type RequestOptions, type SaveMessageToMemoryParams, type SaveMessageToMemoryResponse, type UpdateMemoryThreadParams, type UpsertVectorParams };
359
+ export { type ClientOptions, type CreateIndexParams, type CreateMemoryThreadParams, type CreateMemoryThreadResponse, type GenerateParams, type GetAgentResponse, type GetEvalsByAgentIdResponse, type GetLogParams, type GetLogsParams, type GetLogsResponse, type GetMemoryThreadMessagesResponse, type GetMemoryThreadParams, type GetMemoryThreadResponse, type GetToolResponse, type GetVectorIndexResponse, type GetWorkflowResponse, MastraClient, type QueryVectorParams, type QueryVectorResponse, type RequestFunction, type RequestOptions, type SaveMessageToMemoryParams, type SaveMessageToMemoryResponse, type StreamParams, type UpdateMemoryThreadParams, type UpsertVectorParams };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mastra/client-js",
3
- "version": "0.1.0-alpha.3",
3
+ "version": "0.1.0-alpha.4",
4
4
  "description": "The official TypeScript library for the Mastra Client API",
5
5
  "author": "",
6
6
  "types": "dist/index.d.ts",
@@ -17,12 +17,14 @@
17
17
  "repository": "github:mastra-ai/client-js",
18
18
  "license": "ISC",
19
19
  "dependencies": {
20
- "@mastra/core": "^0.2.0-alpha.83"
20
+ "@mastra/core": "^0.2.0-alpha.83",
21
+ "json-schema": "^0.4.0"
21
22
  },
22
23
  "devDependencies": {
23
24
  "@babel/preset-env": "^7.26.0",
24
25
  "@babel/preset-typescript": "^7.26.0",
25
26
  "@tsconfig/recommended": "^1.0.7",
27
+ "@types/json-schema": "^7.0.15",
26
28
  "@types/node": "^22.9.0",
27
29
  "tsup": "^8.0.1",
28
30
  "typescript": "^5.7.3",
package/src/index.test.ts CHANGED
@@ -198,13 +198,23 @@ describe('MastraClient Resources', () => {
198
198
  };
199
199
  mockFetchResponse(mockResponse);
200
200
 
201
- const result = await agent.generate({ prompt: 'Test prompt' });
201
+ const result = await agent.generate({
202
+ messages: [],
203
+ threadId: 'test-thread',
204
+ resourceid: 'test-resource',
205
+ output: {}
206
+ });
202
207
  expect(result).toEqual(mockResponse);
203
208
  expect(global.fetch).toHaveBeenCalledWith(
204
209
  `${client.baseUrl}/api/agents/test-agent/generate`,
205
210
  expect.objectContaining({
206
211
  method: 'POST',
207
- body: JSON.stringify({ prompt: 'Test prompt' })
212
+ body: JSON.stringify({
213
+ messages: [],
214
+ threadId: 'test-thread',
215
+ resourceid: 'test-resource',
216
+ output: {}
217
+ })
208
218
  })
209
219
  );
210
220
  });
@@ -215,13 +225,24 @@ describe('MastraClient Resources', () => {
215
225
  chunks: ['chunk1', 'chunk2']
216
226
  };
217
227
  mockFetchResponse(mockResponse);
218
- const result = await agent.stream({ prompt: 'Test prompt' });
228
+ const result = await agent.stream({
229
+ messages: [],
230
+ threadId: 'test-thread',
231
+ resourceid: 'test-resource',
232
+ output: undefined
233
+ });
219
234
  expect(result).toEqual(mockResponse);
220
235
  expect(global.fetch).toHaveBeenCalledWith(
221
236
  `${client.baseUrl}/api/agents/test-agent/generate`,
222
237
  expect.objectContaining({
223
238
  method: 'POST',
224
- body: JSON.stringify({ prompt: 'Test prompt', stream: true })
239
+ body: JSON.stringify({
240
+ messages: [],
241
+ threadId: 'test-thread',
242
+ resourceid: 'test-resource',
243
+ output: undefined,
244
+ stream: true
245
+ })
225
246
  })
226
247
  );
227
248
  });
@@ -1,13 +1,16 @@
1
1
  import type {
2
+ GenerateParams,
2
3
  GetAgentResponse,
3
4
  GetEvalsByAgentIdResponse,
4
5
  GetToolResponse,
5
6
  RequestFunction,
7
+ StreamParams,
6
8
  } from '../types';
7
9
  import type {
8
10
  GenerateReturn,
9
11
  StreamReturn,
10
12
  } from '@mastra/core';
13
+ import type { JSONSchema7 } from 'json-schema';
11
14
 
12
15
  export class AgentTool {
13
16
  constructor(
@@ -48,7 +51,7 @@ export class Agent {
48
51
  * @param params - Generation parameters including prompt
49
52
  * @returns Promise containing the generated response
50
53
  */
51
- generate<T>(params: any): Promise<GenerateReturn<T>> {
54
+ generate<T extends JSONSchema7 | undefined = undefined>(params: GenerateParams<T>): Promise<GenerateReturn<T>> {
52
55
  return this.request(`/api/agents/${this.agentId}/generate`, {
53
56
  method: 'POST',
54
57
  body: params,
@@ -60,7 +63,7 @@ export class Agent {
60
63
  * @param params - Stream parameters including prompt
61
64
  * @returns Promise containing the streamed response
62
65
  */
63
- stream<T>(params: any): Promise<StreamReturn<T>> {
66
+ stream<T extends JSONSchema7 | undefined = undefined>(params: StreamParams<T>): Promise<StreamReturn<T>> {
64
67
  return this.request(`/api/agents/${this.agentId}/generate`, {
65
68
  method: 'POST',
66
69
  body: { ...params, stream: true },
package/src/types.ts CHANGED
@@ -1,5 +1,5 @@
1
- import type { MessageType, AiMessageType, CoreMessage, QueryResult, StepAction, StepGraph, StorageThreadType, BaseLogMessage } from "@mastra/core";
2
-
1
+ import type { MessageType, AiMessageType, CoreMessage, QueryResult, StepAction, StepGraph, StorageThreadType, BaseLogMessage, OutputType } from "@mastra/core";
2
+ import type { JSONSchema7 } from 'json-schema';
3
3
 
4
4
  export interface ClientOptions {
5
5
  baseUrl: string;
@@ -22,6 +22,20 @@ export interface GetAgentResponse {
22
22
  tools: Record<string, GetToolResponse>;
23
23
  }
24
24
 
25
+ export interface GenerateParams<T extends JSONSchema7 | undefined = undefined> {
26
+ messages: MessageType[];
27
+ threadId?: string;
28
+ resourceid?: string;
29
+ output?: OutputType | T
30
+ }
31
+
32
+ export interface StreamParams<T extends JSONSchema7 | undefined = undefined> {
33
+ messages: MessageType[];
34
+ threadId?: string;
35
+ resourceid?: string;
36
+ output?: OutputType | T
37
+ }
38
+
25
39
  export interface GetEvalsByAgentIdResponse extends GetAgentResponse {
26
40
  evals: any[];
27
41
  }