@mastra/client-js 0.1.0-alpha.6 → 0.1.0-alpha.8

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/dist/index.d.mts CHANGED
@@ -1,18 +1,24 @@
1
- import { MessageType, OutputType, StorageThreadType, CoreMessage, AiMessageType, StepAction, StepGraph, QueryResult, BaseLogMessage, GenerateReturn, StreamReturn } from '@mastra/core';
1
+ import { MessageType, OutputType, StorageThreadType, CoreMessage, AiMessageType, StepAction, StepGraph, QueryResult, BaseLogMessage, GenerateReturn } from '@mastra/core';
2
2
  import { JSONSchema7 } from 'json-schema';
3
- import { StorageThreadType as StorageThreadType$1 } from '@mastra/core/memory';
3
+ import { ZodSchema } from 'zod';
4
4
 
5
5
  interface ClientOptions {
6
+ /** Base URL for API requests */
6
7
  baseUrl: string;
8
+ /** Number of retry attempts for failed requests */
7
9
  retries?: number;
10
+ /** Initial backoff time in milliseconds between retries */
8
11
  backoffMs?: number;
12
+ /** Maximum backoff time in milliseconds between retries */
9
13
  maxBackoffMs?: number;
14
+ /** Custom headers to include with requests */
10
15
  headers?: Record<string, string>;
11
16
  }
12
17
  interface RequestOptions {
13
18
  method?: string;
14
19
  headers?: Record<string, string>;
15
20
  body?: any;
21
+ stream?: boolean;
16
22
  }
17
23
  interface GetAgentResponse {
18
24
  name: string;
@@ -20,13 +26,13 @@ interface GetAgentResponse {
20
26
  instructions: string;
21
27
  tools: Record<string, GetToolResponse>;
22
28
  }
23
- interface GenerateParams<T extends JSONSchema7 | undefined = undefined> {
29
+ interface GenerateParams<T extends JSONSchema7 | ZodSchema | undefined = undefined> {
24
30
  messages: MessageType[];
25
31
  threadId?: string;
26
32
  resourceid?: string;
27
33
  output?: OutputType | T;
28
34
  }
29
- interface StreamParams<T extends JSONSchema7 | undefined = undefined> {
35
+ interface StreamParams<T extends JSONSchema7 | ZodSchema | undefined = undefined> {
30
36
  messages: MessageType[];
31
37
  threadId?: string;
32
38
  resourceid?: string;
@@ -108,10 +114,21 @@ interface GetLogParams {
108
114
  type GetLogsResponse = BaseLogMessage[];
109
115
  type RequestFunction = (path: string, options?: RequestOptions) => Promise<any>;
110
116
 
111
- declare class Agent {
112
- private request;
117
+ declare class BaseResource {
118
+ readonly options: ClientOptions;
119
+ constructor(options: ClientOptions);
120
+ /**
121
+ * Makes an HTTP request to the API with retries and exponential backoff
122
+ * @param path - The API endpoint path
123
+ * @param options - Optional request configuration
124
+ * @returns Promise containing the response data
125
+ */
126
+ request<T>(path: string, options?: RequestOptions): Promise<T>;
127
+ }
128
+
129
+ declare class Agent extends BaseResource {
113
130
  private agentId;
114
- constructor(request: RequestFunction, agentId: string);
131
+ constructor(options: ClientOptions, agentId: string);
115
132
  /**
116
133
  * Retrieves details about the agent
117
134
  * @returns Promise containing agent details including model and instructions
@@ -122,13 +139,13 @@ declare class Agent {
122
139
  * @param params - Generation parameters including prompt
123
140
  * @returns Promise containing the generated response
124
141
  */
125
- generate<T extends JSONSchema7 | undefined = undefined>(params: GenerateParams<T>): Promise<GenerateReturn<T>>;
142
+ generate<T extends JSONSchema7 | ZodSchema | undefined = undefined>(params: GenerateParams<T>): Promise<GenerateReturn<T>>;
126
143
  /**
127
144
  * Streams a response from the agent
128
145
  * @param params - Stream parameters including prompt
129
146
  * @returns Promise containing the streamed response
130
147
  */
131
- stream<T extends JSONSchema7 | undefined = undefined>(params: StreamParams<T>): Promise<StreamReturn<T>>;
148
+ stream<T extends JSONSchema7 | ZodSchema | undefined = undefined>(params: StreamParams<T>): Promise<Response>;
132
149
  /**
133
150
  * Gets details about a specific tool available to the agent
134
151
  * @param toolId - ID of the tool to retrieve
@@ -147,21 +164,20 @@ declare class Agent {
147
164
  liveEvals(): Promise<GetEvalsByAgentIdResponse>;
148
165
  }
149
166
 
150
- declare class MemoryThread {
151
- private request;
167
+ declare class MemoryThread extends BaseResource {
152
168
  private threadId;
153
- constructor(request: RequestFunction, threadId: string);
169
+ constructor(options: ClientOptions, threadId: string);
154
170
  /**
155
171
  * Retrieves the memory thread details
156
172
  * @returns Promise containing thread details including title and metadata
157
173
  */
158
- get(): Promise<StorageThreadType$1>;
174
+ get(): Promise<StorageThreadType>;
159
175
  /**
160
176
  * Updates the memory thread properties
161
177
  * @param params - Update parameters including title and metadata
162
178
  * @returns Promise containing updated thread details
163
179
  */
164
- update(params: UpdateMemoryThreadParams): Promise<StorageThreadType$1>;
180
+ update(params: UpdateMemoryThreadParams): Promise<StorageThreadType>;
165
181
  /**
166
182
  * Deletes the memory thread
167
183
  * @returns Promise containing deletion result
@@ -176,44 +192,9 @@ declare class MemoryThread {
176
192
  getMessages(): Promise<GetMemoryThreadMessagesResponse>;
177
193
  }
178
194
 
179
- declare class Tool {
180
- private request;
181
- private toolId;
182
- constructor(request: RequestFunction, toolId: string);
183
- /**
184
- * Retrieves details about the tool
185
- * @returns Promise containing tool details including description and schemas
186
- */
187
- details(): Promise<GetToolResponse>;
188
- /**
189
- * Executes the tool with the provided parameters
190
- * @param params - Parameters required for tool execution
191
- * @returns Promise containing the tool execution results
192
- */
193
- execute(params: Record<string, any>): Promise<Record<string, any>>;
194
- }
195
-
196
- declare class Workflow {
197
- private request;
198
- private workflowId;
199
- constructor(request: RequestFunction, workflowId: string);
200
- /**
201
- * Retrieves details about the workflow
202
- * @returns Promise containing workflow details including steps and graphs
203
- */
204
- details(): Promise<GetWorkflowResponse>;
205
- /**
206
- * Executes the workflow with the provided parameters
207
- * @param params - Parameters required for workflow execution
208
- * @returns Promise containing the workflow execution results
209
- */
210
- execute(params: Record<string, any>): Promise<Record<string, any>>;
211
- }
212
-
213
- declare class Vector {
214
- private request;
195
+ declare class Vector extends BaseResource {
215
196
  private vectorName;
216
- constructor(request: RequestFunction, vectorName: string);
197
+ constructor(options: ClientOptions, vectorName: string);
217
198
  /**
218
199
  * Retrieves details about a specific vector index
219
200
  * @param indexName - Name of the index to get details for
@@ -257,21 +238,40 @@ declare class Vector {
257
238
  query(params: QueryVectorParams): Promise<QueryVectorResponse>;
258
239
  }
259
240
 
260
- declare class MastraClient {
261
- readonly baseUrl: string;
262
- private readonly retries;
263
- private readonly backoffMs;
264
- private readonly maxBackoffMs;
265
- private readonly headers;
266
- constructor(options: ClientOptions);
241
+ declare class Workflow extends BaseResource {
242
+ private workflowId;
243
+ constructor(options: ClientOptions, workflowId: string);
244
+ /**
245
+ * Retrieves details about the workflow
246
+ * @returns Promise containing workflow details including steps and graphs
247
+ */
248
+ details(): Promise<GetWorkflowResponse>;
249
+ /**
250
+ * Executes the workflow with the provided parameters
251
+ * @param params - Parameters required for workflow execution
252
+ * @returns Promise containing the workflow execution results
253
+ */
254
+ execute(params: Record<string, any>): Promise<Record<string, any>>;
255
+ }
256
+
257
+ declare class Tool extends BaseResource {
258
+ private toolId;
259
+ constructor(options: ClientOptions, toolId: string);
267
260
  /**
268
- * Makes an HTTP request to the Mastra API
269
- * @param path - API endpoint path
270
- * @param options - Request options including method, headers, and body
271
- * @returns Promise containing the API response
272
- * @throws Error if the request fails after all retries
261
+ * Retrieves details about the tool
262
+ * @returns Promise containing tool details including description and schemas
273
263
  */
274
- request(path: string, options?: RequestOptions): Promise<any>;
264
+ details(): Promise<GetToolResponse>;
265
+ /**
266
+ * Executes the tool with the provided parameters
267
+ * @param params - Parameters required for tool execution
268
+ * @returns Promise containing the tool execution results
269
+ */
270
+ execute(params: Record<string, any>): Promise<Record<string, any>>;
271
+ }
272
+
273
+ declare class MastraClient extends BaseResource {
274
+ constructor(options: ClientOptions);
275
275
  /**
276
276
  * Retrieves all available agents
277
277
  * @returns Promise containing map of agent IDs to agent details
package/dist/index.mjs CHANGED
@@ -1,7 +1,70 @@
1
+ import { ZodSchema } from 'zod';
2
+ import { zodToJsonSchema } from 'zod-to-json-schema';
3
+
1
4
  // src/resources/agent.ts
2
- var Agent = class {
3
- constructor(request, agentId) {
4
- this.request = request;
5
+
6
+ // src/resources/base.ts
7
+ var BaseResource = class {
8
+ options;
9
+ constructor(options) {
10
+ this.options = options;
11
+ }
12
+ /**
13
+ * Makes an HTTP request to the API with retries and exponential backoff
14
+ * @param path - The API endpoint path
15
+ * @param options - Optional request configuration
16
+ * @returns Promise containing the response data
17
+ */
18
+ async request(path, options = {}) {
19
+ let lastError = null;
20
+ const { baseUrl, retries = 3, backoffMs = 100, maxBackoffMs = 1e3, headers = {} } = this.options;
21
+ let delay = backoffMs;
22
+ for (let attempt = 0; attempt <= retries; attempt++) {
23
+ try {
24
+ const response = await fetch(`${baseUrl}${path}`, {
25
+ ...options,
26
+ headers: {
27
+ "Content-Type": "application/json",
28
+ ...headers,
29
+ ...options.headers
30
+ },
31
+ body: options.body ? JSON.stringify(options.body) : void 0
32
+ });
33
+ if (!response.ok) {
34
+ const errorBody = await response.text();
35
+ let errorMessage = `HTTP error! status: ${response.status}`;
36
+ try {
37
+ const errorJson = JSON.parse(errorBody);
38
+ errorMessage += ` - ${JSON.stringify(errorJson)}`;
39
+ } catch {
40
+ if (errorBody) {
41
+ errorMessage += ` - ${errorBody}`;
42
+ }
43
+ }
44
+ throw new Error(errorMessage);
45
+ }
46
+ if (options.stream) {
47
+ return response;
48
+ }
49
+ const data = await response.json();
50
+ return data;
51
+ } catch (error) {
52
+ lastError = error;
53
+ if (attempt === retries) {
54
+ break;
55
+ }
56
+ await new Promise((resolve) => setTimeout(resolve, delay));
57
+ delay = Math.min(delay * 2, maxBackoffMs);
58
+ }
59
+ }
60
+ throw lastError || new Error("Request failed");
61
+ }
62
+ };
63
+
64
+ // src/resources/agent.ts
65
+ var Agent = class extends BaseResource {
66
+ constructor(options, agentId) {
67
+ super(options);
5
68
  this.agentId = agentId;
6
69
  }
7
70
  /**
@@ -17,9 +80,13 @@ var Agent = class {
17
80
  * @returns Promise containing the generated response
18
81
  */
19
82
  generate(params) {
83
+ const processedParams = {
84
+ ...params,
85
+ output: params.output instanceof ZodSchema ? zodToJsonSchema(params.output) : params.output
86
+ };
20
87
  return this.request(`/api/agents/${this.agentId}/generate`, {
21
88
  method: "POST",
22
- body: params
89
+ body: processedParams
23
90
  });
24
91
  }
25
92
  /**
@@ -28,9 +95,14 @@ var Agent = class {
28
95
  * @returns Promise containing the streamed response
29
96
  */
30
97
  stream(params) {
31
- return this.request(`/api/agents/${this.agentId}/generate`, {
98
+ const processedParams = {
99
+ ...params,
100
+ output: params.output instanceof ZodSchema ? zodToJsonSchema(params.output) : params.output
101
+ };
102
+ return this.request(`/api/agents/${this.agentId}/stream`, {
32
103
  method: "POST",
33
- body: { ...params, stream: true }
104
+ body: processedParams,
105
+ stream: true
34
106
  });
35
107
  }
36
108
  /**
@@ -58,9 +130,9 @@ var Agent = class {
58
130
  };
59
131
 
60
132
  // src/resources/memory-thread.ts
61
- var MemoryThread = class {
62
- constructor(request, threadId) {
63
- this.request = request;
133
+ var MemoryThread = class extends BaseResource {
134
+ constructor(options, threadId) {
135
+ super(options);
64
136
  this.threadId = threadId;
65
137
  }
66
138
  /**
@@ -99,62 +171,10 @@ var MemoryThread = class {
99
171
  }
100
172
  };
101
173
 
102
- // src/resources/tool.ts
103
- var Tool = class {
104
- constructor(request, toolId) {
105
- this.request = request;
106
- this.toolId = toolId;
107
- }
108
- /**
109
- * Retrieves details about the tool
110
- * @returns Promise containing tool details including description and schemas
111
- */
112
- details() {
113
- return this.request(`/api/tools/${this.toolId}`);
114
- }
115
- /**
116
- * Executes the tool with the provided parameters
117
- * @param params - Parameters required for tool execution
118
- * @returns Promise containing the tool execution results
119
- */
120
- execute(params) {
121
- return this.request(`/api/tools/${this.toolId}/execute`, {
122
- method: "POST",
123
- body: params
124
- });
125
- }
126
- };
127
-
128
- // src/resources/workflow.ts
129
- var Workflow = class {
130
- constructor(request, workflowId) {
131
- this.request = request;
132
- this.workflowId = workflowId;
133
- }
134
- /**
135
- * Retrieves details about the workflow
136
- * @returns Promise containing workflow details including steps and graphs
137
- */
138
- details() {
139
- return this.request(`/api/workflows/${this.workflowId}`);
140
- }
141
- /**
142
- * Executes the workflow with the provided parameters
143
- * @param params - Parameters required for workflow execution
144
- * @returns Promise containing the workflow execution results
145
- */
146
- execute(params) {
147
- return this.request(`/api/workflows/${this.workflowId}/execute`, {
148
- method: "POST",
149
- body: params
150
- });
151
- }
152
- };
153
-
154
174
  // src/resources/vector.ts
155
- var Vector = class {
156
- constructor(request, vectorName) {
157
- this.request = request;
175
+ var Vector = class extends BaseResource {
176
+ constructor(options, vectorName) {
177
+ super(options);
158
178
  this.vectorName = vectorName;
159
179
  }
160
180
  /**
@@ -217,56 +237,62 @@ var Vector = class {
217
237
  }
218
238
  };
219
239
 
220
- // src/client.ts
221
- var MastraClient = class {
222
- baseUrl;
223
- retries;
224
- backoffMs;
225
- maxBackoffMs;
226
- headers;
227
- constructor(options) {
228
- this.baseUrl = options.baseUrl.replace(/\/$/, "");
229
- this.retries = options.retries ?? 3;
230
- this.backoffMs = options.backoffMs ?? 300;
231
- this.maxBackoffMs = options.maxBackoffMs ?? 5e3;
232
- this.headers = {
233
- "Content-Type": "application/json",
234
- ...options.headers
235
- };
240
+ // src/resources/workflow.ts
241
+ var Workflow = class extends BaseResource {
242
+ constructor(options, workflowId) {
243
+ super(options);
244
+ this.workflowId = workflowId;
236
245
  }
237
246
  /**
238
- * Makes an HTTP request to the Mastra API
239
- * @param path - API endpoint path
240
- * @param options - Request options including method, headers, and body
241
- * @returns Promise containing the API response
242
- * @throws Error if the request fails after all retries
247
+ * Retrieves details about the workflow
248
+ * @returns Promise containing workflow details including steps and graphs
243
249
  */
244
- async request(path, options = {}) {
245
- const url = `${this.baseUrl}${path}`;
246
- let lastError = null;
247
- let currentBackoff = this.backoffMs;
248
- for (let attempt = 0; attempt <= this.retries; attempt++) {
249
- try {
250
- const response = await fetch(url, {
251
- method: options.method ?? "GET",
252
- headers: {
253
- ...this.headers,
254
- ...options.headers
255
- },
256
- body: options.body ? JSON.stringify(options.body) : void 0
257
- });
258
- if (!response.ok) {
259
- throw new Error(`HTTP error! status: ${response.status}`);
260
- }
261
- return await response.json();
262
- } catch (error) {
263
- lastError = error;
264
- if (attempt === this.retries) break;
265
- await new Promise((resolve) => setTimeout(resolve, currentBackoff));
266
- currentBackoff = Math.min(currentBackoff * 2, this.maxBackoffMs);
267
- }
268
- }
269
- throw lastError;
250
+ details() {
251
+ return this.request(`/api/workflows/${this.workflowId}`);
252
+ }
253
+ /**
254
+ * Executes the workflow with the provided parameters
255
+ * @param params - Parameters required for workflow execution
256
+ * @returns Promise containing the workflow execution results
257
+ */
258
+ execute(params) {
259
+ return this.request(`/api/workflows/${this.workflowId}/execute`, {
260
+ method: "POST",
261
+ body: params
262
+ });
263
+ }
264
+ };
265
+
266
+ // src/resources/tool.ts
267
+ var Tool = class extends BaseResource {
268
+ constructor(options, toolId) {
269
+ super(options);
270
+ this.toolId = toolId;
271
+ }
272
+ /**
273
+ * Retrieves details about the tool
274
+ * @returns Promise containing tool details including description and schemas
275
+ */
276
+ details() {
277
+ return this.request(`/api/tools/${this.toolId}`);
278
+ }
279
+ /**
280
+ * Executes the tool with the provided parameters
281
+ * @param params - Parameters required for tool execution
282
+ * @returns Promise containing the tool execution results
283
+ */
284
+ execute(params) {
285
+ return this.request(`/api/tools/${this.toolId}/execute`, {
286
+ method: "POST",
287
+ body: params
288
+ });
289
+ }
290
+ };
291
+
292
+ // src/client.ts
293
+ var MastraClient = class extends BaseResource {
294
+ constructor(options) {
295
+ super(options);
270
296
  }
271
297
  /**
272
298
  * Retrieves all available agents
@@ -281,10 +307,7 @@ var MastraClient = class {
281
307
  * @returns Agent instance
282
308
  */
283
309
  getAgent(agentId) {
284
- return new Agent(
285
- (path, options) => this.request(path, options),
286
- agentId
287
- );
310
+ return new Agent(this.options, agentId);
288
311
  }
289
312
  /**
290
313
  * Retrieves memory threads for a resource
@@ -308,10 +331,7 @@ var MastraClient = class {
308
331
  * @returns MemoryThread instance
309
332
  */
310
333
  getMemoryThread(threadId) {
311
- return new MemoryThread(
312
- (path, options) => this.request(path, options),
313
- threadId
314
- );
334
+ return new MemoryThread(this.options, threadId);
315
335
  }
316
336
  /**
317
337
  * Saves messages to memory
@@ -344,10 +364,7 @@ var MastraClient = class {
344
364
  * @returns Tool instance
345
365
  */
346
366
  getTool(toolId) {
347
- return new Tool(
348
- (path, options) => this.request(path, options),
349
- toolId
350
- );
367
+ return new Tool(this.options, toolId);
351
368
  }
352
369
  /**
353
370
  * Retrieves all available workflows
@@ -362,10 +379,7 @@ var MastraClient = class {
362
379
  * @returns Workflow instance
363
380
  */
364
381
  getWorkflow(workflowId) {
365
- return new Workflow(
366
- (path, options) => this.request(path, options),
367
- workflowId
368
- );
382
+ return new Workflow(this.options, workflowId);
369
383
  }
370
384
  /**
371
385
  * Gets a vector instance by name
@@ -373,10 +387,7 @@ var MastraClient = class {
373
387
  * @returns Vector instance
374
388
  */
375
389
  getVector(vectorName) {
376
- return new Vector(
377
- (path, options) => this.request(path, options),
378
- vectorName
379
- );
390
+ return new Vector(this.options, vectorName);
380
391
  }
381
392
  /**
382
393
  * Retrieves logs
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mastra/client-js",
3
- "version": "0.1.0-alpha.6",
3
+ "version": "0.1.0-alpha.8",
4
4
  "description": "The official TypeScript library for the Mastra Client API",
5
5
  "author": "",
6
6
  "types": "dist/index.d.mts",
package/src/client.ts CHANGED
@@ -1,63 +1,12 @@
1
1
  import type { ClientOptions, CreateMemoryThreadParams, CreateMemoryThreadResponse, GetAgentResponse, GetLogParams, GetLogsParams, GetLogsResponse, GetMemoryThreadParams, GetMemoryThreadResponse, GetToolResponse, GetWorkflowResponse, RequestOptions, SaveMessageToMemoryParams, SaveMessageToMemoryResponse } from './types';
2
- import { Agent, MemoryThread, Tool, Workflow, Vector } from './resources';
2
+ import { Agent, MemoryThread, Tool, Workflow, Vector, BaseResource } from './resources';
3
3
 
4
- export class MastraClient {
5
- readonly baseUrl: string;
6
- private readonly retries: number;
7
- private readonly backoffMs: number;
8
- private readonly maxBackoffMs: number;
9
- private readonly headers: Record<string, string>;
4
+ export class MastraClient extends BaseResource {
10
5
 
11
6
  constructor(options: ClientOptions) {
12
- this.baseUrl = options.baseUrl.replace(/\/$/, '');
13
- this.retries = options.retries ?? 3;
14
- this.backoffMs = options.backoffMs ?? 300;
15
- this.maxBackoffMs = options.maxBackoffMs ?? 5000;
16
- this.headers = {
17
- 'Content-Type': 'application/json',
18
- ...options.headers,
19
- };
7
+ super(options);
20
8
  }
21
9
 
22
- /**
23
- * Makes an HTTP request to the Mastra API
24
- * @param path - API endpoint path
25
- * @param options - Request options including method, headers, and body
26
- * @returns Promise containing the API response
27
- * @throws Error if the request fails after all retries
28
- */
29
- async request(path: string, options: RequestOptions = {}): Promise<any> {
30
- const url = `${this.baseUrl}${path}`;
31
- let lastError: Error | null = null;
32
- let currentBackoff = this.backoffMs;
33
-
34
- for (let attempt = 0; attempt <= this.retries; attempt++) {
35
- try {
36
- const response = await fetch(url, {
37
- method: options.method ?? 'GET',
38
- headers: {
39
- ...this.headers,
40
- ...options.headers,
41
- },
42
- body: options.body ? JSON.stringify(options.body) : undefined,
43
- });
44
-
45
- if (!response.ok) {
46
- throw new Error(`HTTP error! status: ${response.status}`);
47
- }
48
-
49
- return await response.json();
50
- } catch (error) {
51
- lastError = error as Error;
52
- if (attempt === this.retries) break;
53
-
54
- await new Promise(resolve => setTimeout(resolve, currentBackoff));
55
- currentBackoff = Math.min(currentBackoff * 2, this.maxBackoffMs);
56
- }
57
- }
58
-
59
- throw lastError;
60
- }
61
10
 
62
11
  /**
63
12
  * Retrieves all available agents
@@ -73,10 +22,7 @@ export class MastraClient {
73
22
  * @returns Agent instance
74
23
  */
75
24
  public getAgent(agentId: string) {
76
- return new Agent(
77
- (path: string, options?: RequestOptions) => this.request(path, options),
78
- agentId
79
- );
25
+ return new Agent(this.options, agentId);
80
26
  }
81
27
 
82
28
  /**
@@ -103,10 +49,7 @@ export class MastraClient {
103
49
  * @returns MemoryThread instance
104
50
  */
105
51
  public getMemoryThread(threadId: string) {
106
- return new MemoryThread(
107
- (path: string, options?: RequestOptions) => this.request(path, options),
108
- threadId
109
- );
52
+ return new MemoryThread(this.options, threadId);
110
53
  }
111
54
 
112
55
  /**
@@ -143,10 +86,7 @@ export class MastraClient {
143
86
  * @returns Tool instance
144
87
  */
145
88
  public getTool(toolId: string) {
146
- return new Tool(
147
- (path: string, options?: RequestOptions) => this.request(path, options),
148
- toolId
149
- );
89
+ return new Tool(this.options, toolId);
150
90
  }
151
91
 
152
92
  /**
@@ -163,10 +103,7 @@ export class MastraClient {
163
103
  * @returns Workflow instance
164
104
  */
165
105
  public getWorkflow(workflowId: string) {
166
- return new Workflow(
167
- (path: string, options?: RequestOptions) => this.request(path, options),
168
- workflowId
169
- );
106
+ return new Workflow(this.options, workflowId);
170
107
  }
171
108
 
172
109
  /**
@@ -175,10 +112,7 @@ export class MastraClient {
175
112
  * @returns Vector instance
176
113
  */
177
114
  public getVector(vectorName: string) {
178
- return new Vector(
179
- (path: string, options?: RequestOptions) => this.request(path, options),
180
- vectorName
181
- );
115
+ return new Vector(this.options, vectorName);
182
116
  }
183
117
 
184
118
  /**