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

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,12 +1,17 @@
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 {
@@ -20,13 +25,13 @@ interface GetAgentResponse {
20
25
  instructions: string;
21
26
  tools: Record<string, GetToolResponse>;
22
27
  }
23
- interface GenerateParams<T extends JSONSchema7 | undefined = undefined> {
28
+ interface GenerateParams<T extends JSONSchema7 | ZodSchema | undefined = undefined> {
24
29
  messages: MessageType[];
25
30
  threadId?: string;
26
31
  resourceid?: string;
27
32
  output?: OutputType | T;
28
33
  }
29
- interface StreamParams<T extends JSONSchema7 | undefined = undefined> {
34
+ interface StreamParams<T extends JSONSchema7 | ZodSchema | undefined = undefined> {
30
35
  messages: MessageType[];
31
36
  threadId?: string;
32
37
  resourceid?: string;
@@ -108,10 +113,21 @@ interface GetLogParams {
108
113
  type GetLogsResponse = BaseLogMessage[];
109
114
  type RequestFunction = (path: string, options?: RequestOptions) => Promise<any>;
110
115
 
111
- declare class Agent {
112
- private request;
116
+ declare class BaseResource {
117
+ readonly options: ClientOptions;
118
+ constructor(options: ClientOptions);
119
+ /**
120
+ * Makes an HTTP request to the API with retries and exponential backoff
121
+ * @param path - The API endpoint path
122
+ * @param options - Optional request configuration
123
+ * @returns Promise containing the response data
124
+ */
125
+ request<T>(path: string, options?: RequestOptions): Promise<T>;
126
+ }
127
+
128
+ declare class Agent extends BaseResource {
113
129
  private agentId;
114
- constructor(request: RequestFunction, agentId: string);
130
+ constructor(options: ClientOptions, agentId: string);
115
131
  /**
116
132
  * Retrieves details about the agent
117
133
  * @returns Promise containing agent details including model and instructions
@@ -122,13 +138,13 @@ declare class Agent {
122
138
  * @param params - Generation parameters including prompt
123
139
  * @returns Promise containing the generated response
124
140
  */
125
- generate<T extends JSONSchema7 | undefined = undefined>(params: GenerateParams<T>): Promise<GenerateReturn<T>>;
141
+ generate<T extends JSONSchema7 | ZodSchema | undefined = undefined>(params: GenerateParams<T>): Promise<GenerateReturn<T>>;
126
142
  /**
127
143
  * Streams a response from the agent
128
144
  * @param params - Stream parameters including prompt
129
145
  * @returns Promise containing the streamed response
130
146
  */
131
- stream<T extends JSONSchema7 | undefined = undefined>(params: StreamParams<T>): Promise<StreamReturn<T>>;
147
+ stream<T extends JSONSchema7 | ZodSchema | undefined = undefined>(params: StreamParams<T>): T extends undefined ? Promise<ReadableStream<Uint8Array>> : Promise<Response>;
132
148
  /**
133
149
  * Gets details about a specific tool available to the agent
134
150
  * @param toolId - ID of the tool to retrieve
@@ -147,21 +163,20 @@ declare class Agent {
147
163
  liveEvals(): Promise<GetEvalsByAgentIdResponse>;
148
164
  }
149
165
 
150
- declare class MemoryThread {
151
- private request;
166
+ declare class MemoryThread extends BaseResource {
152
167
  private threadId;
153
- constructor(request: RequestFunction, threadId: string);
168
+ constructor(options: ClientOptions, threadId: string);
154
169
  /**
155
170
  * Retrieves the memory thread details
156
171
  * @returns Promise containing thread details including title and metadata
157
172
  */
158
- get(): Promise<StorageThreadType$1>;
173
+ get(): Promise<StorageThreadType>;
159
174
  /**
160
175
  * Updates the memory thread properties
161
176
  * @param params - Update parameters including title and metadata
162
177
  * @returns Promise containing updated thread details
163
178
  */
164
- update(params: UpdateMemoryThreadParams): Promise<StorageThreadType$1>;
179
+ update(params: UpdateMemoryThreadParams): Promise<StorageThreadType>;
165
180
  /**
166
181
  * Deletes the memory thread
167
182
  * @returns Promise containing deletion result
@@ -176,44 +191,9 @@ declare class MemoryThread {
176
191
  getMessages(): Promise<GetMemoryThreadMessagesResponse>;
177
192
  }
178
193
 
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;
194
+ declare class Vector extends BaseResource {
215
195
  private vectorName;
216
- constructor(request: RequestFunction, vectorName: string);
196
+ constructor(options: ClientOptions, vectorName: string);
217
197
  /**
218
198
  * Retrieves details about a specific vector index
219
199
  * @param indexName - Name of the index to get details for
@@ -257,21 +237,40 @@ declare class Vector {
257
237
  query(params: QueryVectorParams): Promise<QueryVectorResponse>;
258
238
  }
259
239
 
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);
240
+ declare class Workflow extends BaseResource {
241
+ private workflowId;
242
+ constructor(options: ClientOptions, workflowId: string);
243
+ /**
244
+ * Retrieves details about the workflow
245
+ * @returns Promise containing workflow details including steps and graphs
246
+ */
247
+ details(): Promise<GetWorkflowResponse>;
248
+ /**
249
+ * Executes the workflow with the provided parameters
250
+ * @param params - Parameters required for workflow execution
251
+ * @returns Promise containing the workflow execution results
252
+ */
253
+ execute(params: Record<string, any>): Promise<Record<string, any>>;
254
+ }
255
+
256
+ declare class Tool extends BaseResource {
257
+ private toolId;
258
+ constructor(options: ClientOptions, toolId: string);
267
259
  /**
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
260
+ * Retrieves details about the tool
261
+ * @returns Promise containing tool details including description and schemas
273
262
  */
274
- request(path: string, options?: RequestOptions): Promise<any>;
263
+ details(): Promise<GetToolResponse>;
264
+ /**
265
+ * Executes the tool with the provided parameters
266
+ * @param params - Parameters required for tool execution
267
+ * @returns Promise containing the tool execution results
268
+ */
269
+ execute(params: Record<string, any>): Promise<Record<string, any>>;
270
+ }
271
+
272
+ declare class MastraClient extends BaseResource {
273
+ constructor(options: ClientOptions);
275
274
  /**
276
275
  * Retrieves all available agents
277
276
  * @returns Promise containing map of agent IDs to agent details
package/dist/index.mjs CHANGED
@@ -1,7 +1,73 @@
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 (response.headers.get("Content-Type")?.includes("text/event-stream")) {
47
+ return response.body;
48
+ }
49
+ if (response.headers.get("Content-Type")?.includes("text/x-unknown")) {
50
+ return response;
51
+ }
52
+ const data = await response.json();
53
+ return data;
54
+ } catch (error) {
55
+ lastError = error;
56
+ if (attempt === retries) {
57
+ break;
58
+ }
59
+ await new Promise((resolve) => setTimeout(resolve, delay));
60
+ delay = Math.min(delay * 2, maxBackoffMs);
61
+ }
62
+ }
63
+ throw lastError || new Error("Request failed");
64
+ }
65
+ };
66
+
67
+ // src/resources/agent.ts
68
+ var Agent = class extends BaseResource {
69
+ constructor(options, agentId) {
70
+ super(options);
5
71
  this.agentId = agentId;
6
72
  }
7
73
  /**
@@ -17,9 +83,13 @@ var Agent = class {
17
83
  * @returns Promise containing the generated response
18
84
  */
19
85
  generate(params) {
86
+ const processedParams = {
87
+ ...params,
88
+ output: params.output instanceof ZodSchema ? zodToJsonSchema(params.output) : params.output
89
+ };
20
90
  return this.request(`/api/agents/${this.agentId}/generate`, {
21
91
  method: "POST",
22
- body: params
92
+ body: processedParams
23
93
  });
24
94
  }
25
95
  /**
@@ -28,9 +98,14 @@ var Agent = class {
28
98
  * @returns Promise containing the streamed response
29
99
  */
30
100
  stream(params) {
31
- return this.request(`/api/agents/${this.agentId}/generate`, {
101
+ const processedParams = {
102
+ ...params,
103
+ output: params.output instanceof ZodSchema ? zodToJsonSchema(params.output) : params.output,
104
+ stream: true
105
+ };
106
+ return this.request(`/api/agents/${this.agentId}/stream`, {
32
107
  method: "POST",
33
- body: { ...params, stream: true }
108
+ body: processedParams
34
109
  });
35
110
  }
36
111
  /**
@@ -58,9 +133,9 @@ var Agent = class {
58
133
  };
59
134
 
60
135
  // src/resources/memory-thread.ts
61
- var MemoryThread = class {
62
- constructor(request, threadId) {
63
- this.request = request;
136
+ var MemoryThread = class extends BaseResource {
137
+ constructor(options, threadId) {
138
+ super(options);
64
139
  this.threadId = threadId;
65
140
  }
66
141
  /**
@@ -99,62 +174,10 @@ var MemoryThread = class {
99
174
  }
100
175
  };
101
176
 
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
177
  // src/resources/vector.ts
155
- var Vector = class {
156
- constructor(request, vectorName) {
157
- this.request = request;
178
+ var Vector = class extends BaseResource {
179
+ constructor(options, vectorName) {
180
+ super(options);
158
181
  this.vectorName = vectorName;
159
182
  }
160
183
  /**
@@ -217,56 +240,62 @@ var Vector = class {
217
240
  }
218
241
  };
219
242
 
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
- };
243
+ // src/resources/workflow.ts
244
+ var Workflow = class extends BaseResource {
245
+ constructor(options, workflowId) {
246
+ super(options);
247
+ this.workflowId = workflowId;
236
248
  }
237
249
  /**
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
250
+ * Retrieves details about the workflow
251
+ * @returns Promise containing workflow details including steps and graphs
243
252
  */
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;
253
+ details() {
254
+ return this.request(`/api/workflows/${this.workflowId}`);
255
+ }
256
+ /**
257
+ * Executes the workflow with the provided parameters
258
+ * @param params - Parameters required for workflow execution
259
+ * @returns Promise containing the workflow execution results
260
+ */
261
+ execute(params) {
262
+ return this.request(`/api/workflows/${this.workflowId}/execute`, {
263
+ method: "POST",
264
+ body: params
265
+ });
266
+ }
267
+ };
268
+
269
+ // src/resources/tool.ts
270
+ var Tool = class extends BaseResource {
271
+ constructor(options, toolId) {
272
+ super(options);
273
+ this.toolId = toolId;
274
+ }
275
+ /**
276
+ * Retrieves details about the tool
277
+ * @returns Promise containing tool details including description and schemas
278
+ */
279
+ details() {
280
+ return this.request(`/api/tools/${this.toolId}`);
281
+ }
282
+ /**
283
+ * Executes the tool with the provided parameters
284
+ * @param params - Parameters required for tool execution
285
+ * @returns Promise containing the tool execution results
286
+ */
287
+ execute(params) {
288
+ return this.request(`/api/tools/${this.toolId}/execute`, {
289
+ method: "POST",
290
+ body: params
291
+ });
292
+ }
293
+ };
294
+
295
+ // src/client.ts
296
+ var MastraClient = class extends BaseResource {
297
+ constructor(options) {
298
+ super(options);
270
299
  }
271
300
  /**
272
301
  * Retrieves all available agents
@@ -281,10 +310,7 @@ var MastraClient = class {
281
310
  * @returns Agent instance
282
311
  */
283
312
  getAgent(agentId) {
284
- return new Agent(
285
- (path, options) => this.request(path, options),
286
- agentId
287
- );
313
+ return new Agent(this.options, agentId);
288
314
  }
289
315
  /**
290
316
  * Retrieves memory threads for a resource
@@ -308,10 +334,7 @@ var MastraClient = class {
308
334
  * @returns MemoryThread instance
309
335
  */
310
336
  getMemoryThread(threadId) {
311
- return new MemoryThread(
312
- (path, options) => this.request(path, options),
313
- threadId
314
- );
337
+ return new MemoryThread(this.options, threadId);
315
338
  }
316
339
  /**
317
340
  * Saves messages to memory
@@ -344,10 +367,7 @@ var MastraClient = class {
344
367
  * @returns Tool instance
345
368
  */
346
369
  getTool(toolId) {
347
- return new Tool(
348
- (path, options) => this.request(path, options),
349
- toolId
350
- );
370
+ return new Tool(this.options, toolId);
351
371
  }
352
372
  /**
353
373
  * Retrieves all available workflows
@@ -362,10 +382,7 @@ var MastraClient = class {
362
382
  * @returns Workflow instance
363
383
  */
364
384
  getWorkflow(workflowId) {
365
- return new Workflow(
366
- (path, options) => this.request(path, options),
367
- workflowId
368
- );
385
+ return new Workflow(this.options, workflowId);
369
386
  }
370
387
  /**
371
388
  * Gets a vector instance by name
@@ -373,10 +390,7 @@ var MastraClient = class {
373
390
  * @returns Vector instance
374
391
  */
375
392
  getVector(vectorName) {
376
- return new Vector(
377
- (path, options) => this.request(path, options),
378
- vectorName
379
- );
393
+ return new Vector(this.options, vectorName);
380
394
  }
381
395
  /**
382
396
  * 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.7",
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
  /**