@mastra/client-js 0.0.0-storage-20250225005900 → 0.0.0-taofeeqInngest-20250603090617

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.mjs DELETED
@@ -1,487 +0,0 @@
1
- import { ZodSchema } from 'zod';
2
- import { zodToJsonSchema } from 'zod-to-json-schema';
3
-
4
- // src/resources/agent.ts
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);
68
- this.agentId = agentId;
69
- }
70
- /**
71
- * Retrieves details about the agent
72
- * @returns Promise containing agent details including model and instructions
73
- */
74
- details() {
75
- return this.request(`/api/agents/${this.agentId}`);
76
- }
77
- /**
78
- * Generates a response from the agent
79
- * @param params - Generation parameters including prompt
80
- * @returns Promise containing the generated response
81
- */
82
- generate(params) {
83
- const processedParams = {
84
- ...params,
85
- output: params.output instanceof ZodSchema ? zodToJsonSchema(params.output) : params.output
86
- };
87
- return this.request(`/api/agents/${this.agentId}/generate`, {
88
- method: "POST",
89
- body: processedParams
90
- });
91
- }
92
- /**
93
- * Streams a response from the agent
94
- * @param params - Stream parameters including prompt
95
- * @returns Promise containing the streamed response
96
- */
97
- stream(params) {
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`, {
103
- method: "POST",
104
- body: processedParams,
105
- stream: true
106
- });
107
- }
108
- /**
109
- * Gets details about a specific tool available to the agent
110
- * @param toolId - ID of the tool to retrieve
111
- * @returns Promise containing tool details
112
- */
113
- getTool(toolId) {
114
- return this.request(`/api/agents/${this.agentId}/tools/${toolId}`);
115
- }
116
- /**
117
- * Retrieves evaluation results for the agent
118
- * @returns Promise containing agent evaluations
119
- */
120
- evals() {
121
- return this.request(`/api/agents/${this.agentId}/evals/ci`);
122
- }
123
- /**
124
- * Retrieves live evaluation results for the agent
125
- * @returns Promise containing live agent evaluations
126
- */
127
- liveEvals() {
128
- return this.request(`/api/agents/${this.agentId}/evals/live`);
129
- }
130
- };
131
-
132
- // src/resources/memory-thread.ts
133
- var MemoryThread = class extends BaseResource {
134
- constructor(options, threadId, agentId) {
135
- super(options);
136
- this.threadId = threadId;
137
- this.agentId = agentId;
138
- }
139
- /**
140
- * Retrieves the memory thread details
141
- * @returns Promise containing thread details including title and metadata
142
- */
143
- get() {
144
- return this.request(`/api/memory/threads/${this.threadId}?agentId=${this.agentId}`);
145
- }
146
- /**
147
- * Updates the memory thread properties
148
- * @param params - Update parameters including title and metadata
149
- * @returns Promise containing updated thread details
150
- */
151
- update(params) {
152
- return this.request(`/api/memory/threads/${this.threadId}?agentId=${this.agentId}`, {
153
- method: "PATCH",
154
- body: params
155
- });
156
- }
157
- /**
158
- * Deletes the memory thread
159
- * @returns Promise containing deletion result
160
- */
161
- delete() {
162
- return this.request(`/api/memory/threads/${this.threadId}?agentId=${this.agentId}`, {
163
- method: "DELETE"
164
- });
165
- }
166
- /**
167
- * Retrieves messages associated with the thread
168
- * @returns Promise containing thread messages and UI messages
169
- */
170
- getMessages() {
171
- return this.request(`/api/memory/threads/${this.threadId}/messages?agentId=${this.agentId}`);
172
- }
173
- };
174
-
175
- // src/resources/vector.ts
176
- var Vector = class extends BaseResource {
177
- constructor(options, vectorName) {
178
- super(options);
179
- this.vectorName = vectorName;
180
- }
181
- /**
182
- * Retrieves details about a specific vector index
183
- * @param indexName - Name of the index to get details for
184
- * @returns Promise containing vector index details
185
- */
186
- details(indexName) {
187
- return this.request(`/api/vector/${this.vectorName}/indexes/${indexName}`);
188
- }
189
- /**
190
- * Deletes a vector index
191
- * @param indexName - Name of the index to delete
192
- * @returns Promise indicating deletion success
193
- */
194
- delete(indexName) {
195
- return this.request(`/api/vector/${this.vectorName}/indexes/${indexName}`, {
196
- method: "DELETE"
197
- });
198
- }
199
- /**
200
- * Retrieves a list of all available indexes
201
- * @returns Promise containing array of index names
202
- */
203
- getIndexes() {
204
- return this.request(`/api/vector/${this.vectorName}/indexes`);
205
- }
206
- /**
207
- * Creates a new vector index
208
- * @param params - Parameters for index creation including dimension and metric
209
- * @returns Promise indicating creation success
210
- */
211
- createIndex(params) {
212
- return this.request(`/api/vector/${this.vectorName}/create-index`, {
213
- method: "POST",
214
- body: params
215
- });
216
- }
217
- /**
218
- * Upserts vectors into an index
219
- * @param params - Parameters containing vectors, metadata, and optional IDs
220
- * @returns Promise containing array of vector IDs
221
- */
222
- upsert(params) {
223
- return this.request(`/api/vector/${this.vectorName}/upsert`, {
224
- method: "POST",
225
- body: params
226
- });
227
- }
228
- /**
229
- * Queries vectors in an index
230
- * @param params - Query parameters including query vector and search options
231
- * @returns Promise containing query results
232
- */
233
- query(params) {
234
- return this.request(`/api/vector/${this.vectorName}/query`, {
235
- method: "POST",
236
- body: params
237
- });
238
- }
239
- };
240
-
241
- // src/resources/workflow.ts
242
- var Workflow = class extends BaseResource {
243
- constructor(options, workflowId) {
244
- super(options);
245
- this.workflowId = workflowId;
246
- }
247
- /**
248
- * Retrieves details about the workflow
249
- * @returns Promise containing workflow details including steps and graphs
250
- */
251
- details() {
252
- return this.request(`/api/workflows/${this.workflowId}`);
253
- }
254
- /**
255
- * Executes the workflow with the provided parameters
256
- * @param params - Parameters required for workflow execution
257
- * @returns Promise containing the workflow execution results
258
- */
259
- execute(params) {
260
- return this.request(`/api/workflows/${this.workflowId}/execute`, {
261
- method: "POST",
262
- body: params
263
- });
264
- }
265
- /**
266
- * Resumes a suspended workflow step
267
- * @param stepId - ID of the step to resume
268
- * @param runId - ID of the workflow run
269
- * @param context - Context to resume the workflow with
270
- * @returns Promise containing the workflow resume results
271
- */
272
- resume({
273
- stepId,
274
- runId,
275
- context
276
- }) {
277
- return this.request(`/api/workflows/${this.workflowId}/resume`, {
278
- method: "POST",
279
- body: {
280
- stepId,
281
- runId,
282
- context
283
- }
284
- });
285
- }
286
- /**
287
- * Watches workflow transitions in real-time
288
- * @returns Promise containing the workflow watch stream
289
- */
290
- watch() {
291
- return this.request(`/api/workflows/${this.workflowId}/watch`, {
292
- stream: true
293
- });
294
- }
295
- };
296
-
297
- // src/resources/tool.ts
298
- var Tool = class extends BaseResource {
299
- constructor(options, toolId) {
300
- super(options);
301
- this.toolId = toolId;
302
- }
303
- /**
304
- * Retrieves details about the tool
305
- * @returns Promise containing tool details including description and schemas
306
- */
307
- details() {
308
- return this.request(`/api/tools/${this.toolId}`);
309
- }
310
- /**
311
- * Executes the tool with the provided parameters
312
- * @param params - Parameters required for tool execution
313
- * @returns Promise containing the tool execution results
314
- */
315
- execute(params) {
316
- return this.request(`/api/tools/${this.toolId}/execute`, {
317
- method: "POST",
318
- body: params
319
- });
320
- }
321
- };
322
-
323
- // src/client.ts
324
- var MastraClient = class extends BaseResource {
325
- constructor(options) {
326
- super(options);
327
- }
328
- /**
329
- * Retrieves all available agents
330
- * @returns Promise containing map of agent IDs to agent details
331
- */
332
- getAgents() {
333
- return this.request("/api/agents");
334
- }
335
- /**
336
- * Gets an agent instance by ID
337
- * @param agentId - ID of the agent to retrieve
338
- * @returns Agent instance
339
- */
340
- getAgent(agentId) {
341
- return new Agent(this.options, agentId);
342
- }
343
- /**
344
- * Retrieves memory threads for a resource
345
- * @param params - Parameters containing the resource ID
346
- * @returns Promise containing array of memory threads
347
- */
348
- getMemoryThreads(params) {
349
- return this.request(`/api/memory/threads?resourceid=${params.resourceId}&agentId=${params.agentId}`);
350
- }
351
- /**
352
- * Creates a new memory thread
353
- * @param params - Parameters for creating the memory thread
354
- * @returns Promise containing the created memory thread
355
- */
356
- createMemoryThread(params) {
357
- return this.request(`/api/memory/threads?agentId=${params.agentId}`, { method: "POST", body: params });
358
- }
359
- /**
360
- * Gets a memory thread instance by ID
361
- * @param threadId - ID of the memory thread to retrieve
362
- * @returns MemoryThread instance
363
- */
364
- getMemoryThread(threadId, agentId) {
365
- return new MemoryThread(this.options, threadId, agentId);
366
- }
367
- /**
368
- * Saves messages to memory
369
- * @param params - Parameters containing messages to save
370
- * @returns Promise containing the saved messages
371
- */
372
- saveMessageToMemory(params) {
373
- return this.request(`/api/memory/save-messages?agentId=${params.agentId}`, {
374
- method: "POST",
375
- body: params
376
- });
377
- }
378
- /**
379
- * Gets the status of the memory system
380
- * @returns Promise containing memory system status
381
- */
382
- getMemoryStatus(agentId) {
383
- return this.request(`/api/memory/status?agentId=${agentId}`);
384
- }
385
- /**
386
- * Retrieves all available tools
387
- * @returns Promise containing map of tool IDs to tool details
388
- */
389
- getTools() {
390
- return this.request("/api/tools");
391
- }
392
- /**
393
- * Gets a tool instance by ID
394
- * @param toolId - ID of the tool to retrieve
395
- * @returns Tool instance
396
- */
397
- getTool(toolId) {
398
- return new Tool(this.options, toolId);
399
- }
400
- /**
401
- * Retrieves all available workflows
402
- * @returns Promise containing map of workflow IDs to workflow details
403
- */
404
- getWorkflows() {
405
- return this.request("/api/workflows");
406
- }
407
- /**
408
- * Gets a workflow instance by ID
409
- * @param workflowId - ID of the workflow to retrieve
410
- * @returns Workflow instance
411
- */
412
- getWorkflow(workflowId) {
413
- return new Workflow(this.options, workflowId);
414
- }
415
- /**
416
- * Gets a vector instance by name
417
- * @param vectorName - Name of the vector to retrieve
418
- * @returns Vector instance
419
- */
420
- getVector(vectorName) {
421
- return new Vector(this.options, vectorName);
422
- }
423
- /**
424
- * Retrieves logs
425
- * @param params - Parameters for filtering logs
426
- * @returns Promise containing array of log messages
427
- */
428
- getLogs(params) {
429
- return this.request(`/api/logs?transportId=${params.transportId}`);
430
- }
431
- /**
432
- * Gets logs for a specific run
433
- * @param params - Parameters containing run ID to retrieve
434
- * @returns Promise containing array of log messages
435
- */
436
- getLogForRun(params) {
437
- return this.request(`/api/logs/${params.runId}?transportId=${params.transportId}`);
438
- }
439
- /**
440
- * List of all log transports
441
- * @returns Promise containing list of log transports
442
- */
443
- getLogTransports() {
444
- return this.request("/api/logs/transports");
445
- }
446
- /**
447
- * List of all traces (paged)
448
- * @param params - Parameters for filtering traces
449
- * @returns Promise containing telemetry data
450
- */
451
- getTelemetry(params) {
452
- const { name, scope, page, perPage, attribute } = params || {};
453
- const _attribute = attribute ? Object.entries(attribute).map(([key, value]) => `${key}:${value}`) : [];
454
- ({
455
- ..._attribute?.length ? { attribute: _attribute } : {}
456
- });
457
- const searchParams = new URLSearchParams();
458
- if (name) {
459
- searchParams.set("name", name);
460
- }
461
- if (scope) {
462
- searchParams.set("scope", scope);
463
- }
464
- if (page) {
465
- searchParams.set("page", String(page));
466
- }
467
- if (perPage) {
468
- searchParams.set("perPage", String(perPage));
469
- }
470
- if (_attribute) {
471
- if (Array.isArray(_attribute)) {
472
- for (const attr of _attribute) {
473
- searchParams.append("attribute", attr);
474
- }
475
- } else {
476
- searchParams.set("attribute", _attribute);
477
- }
478
- }
479
- if (searchParams.size) {
480
- return this.request(`/api/telemetry?${searchParams}`);
481
- } else {
482
- return this.request(`/api/telemetry`);
483
- }
484
- }
485
- };
486
-
487
- export { MastraClient };