@mastra/client-js 0.1.0-alpha.1 → 0.1.0-alpha.10
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/.eslintrc.js +10 -0
- package/.prettierignore +3 -0
- package/.prettierrc.json +26 -0
- package/LICENSE +44 -201
- package/README.md +90 -271
- package/dist/index.d.mts +359 -0
- package/dist/index.mjs +410 -0
- package/package.json +32 -95
- package/src/client.ts +135 -0
- package/src/example.ts +47 -0
- package/src/index.test.ts +585 -0
- package/src/index.ts +2 -194
- package/src/resources/agent.ts +115 -0
- package/src/resources/base.ts +68 -0
- package/src/resources/index.ts +6 -9
- package/src/resources/memory-thread.ts +57 -0
- package/src/resources/tool.ts +31 -0
- package/src/resources/vector.ts +82 -0
- package/src/resources/workflow.ts +31 -0
- package/src/types.ts +142 -0
- package/tsconfig.json +29 -0
- package/vitest.config.js +8 -0
- package/CHANGELOG.md +0 -21
- package/_shims/MultipartBody.d.ts +0 -9
- package/_shims/MultipartBody.d.ts.map +0 -1
- package/_shims/MultipartBody.js +0 -16
- package/_shims/MultipartBody.js.map +0 -1
- package/_shims/MultipartBody.mjs +0 -12
- package/_shims/MultipartBody.mjs.map +0 -1
- package/_shims/README.md +0 -46
- package/_shims/auto/runtime-bun.d.ts +0 -5
- package/_shims/auto/runtime-bun.d.ts.map +0 -1
- package/_shims/auto/runtime-bun.js +0 -21
- package/_shims/auto/runtime-bun.js.map +0 -1
- package/_shims/auto/runtime-bun.mjs +0 -2
- package/_shims/auto/runtime-bun.mjs.map +0 -1
- package/_shims/auto/runtime-node.d.ts +0 -5
- package/_shims/auto/runtime-node.d.ts.map +0 -1
- package/_shims/auto/runtime-node.js +0 -21
- package/_shims/auto/runtime-node.js.map +0 -1
- package/_shims/auto/runtime-node.mjs +0 -2
- package/_shims/auto/runtime-node.mjs.map +0 -1
- package/_shims/auto/runtime.d.ts +0 -5
- package/_shims/auto/runtime.d.ts.map +0 -1
- package/_shims/auto/runtime.js +0 -21
- package/_shims/auto/runtime.js.map +0 -1
- package/_shims/auto/runtime.mjs +0 -2
- package/_shims/auto/runtime.mjs.map +0 -1
- package/_shims/auto/types-node.d.ts +0 -5
- package/_shims/auto/types-node.d.ts.map +0 -1
- package/_shims/auto/types-node.js +0 -21
- package/_shims/auto/types-node.js.map +0 -1
- package/_shims/auto/types-node.mjs +0 -2
- package/_shims/auto/types-node.mjs.map +0 -1
- package/_shims/auto/types.d.ts +0 -101
- package/_shims/auto/types.js +0 -3
- package/_shims/auto/types.mjs +0 -3
- package/_shims/bun-runtime.d.ts +0 -6
- package/_shims/bun-runtime.d.ts.map +0 -1
- package/_shims/bun-runtime.js +0 -14
- package/_shims/bun-runtime.js.map +0 -1
- package/_shims/bun-runtime.mjs +0 -10
- package/_shims/bun-runtime.mjs.map +0 -1
- package/_shims/index.d.ts +0 -81
- package/_shims/index.js +0 -13
- package/_shims/index.mjs +0 -7
- package/_shims/manual-types.d.ts +0 -12
- package/_shims/manual-types.js +0 -3
- package/_shims/manual-types.mjs +0 -3
- package/_shims/node-runtime.d.ts +0 -3
- package/_shims/node-runtime.d.ts.map +0 -1
- package/_shims/node-runtime.js +0 -89
- package/_shims/node-runtime.js.map +0 -1
- package/_shims/node-runtime.mjs +0 -56
- package/_shims/node-runtime.mjs.map +0 -1
- package/_shims/node-types.d.ts +0 -42
- package/_shims/node-types.js +0 -3
- package/_shims/node-types.mjs +0 -3
- package/_shims/registry.d.ts +0 -37
- package/_shims/registry.d.ts.map +0 -1
- package/_shims/registry.js +0 -41
- package/_shims/registry.js.map +0 -1
- package/_shims/registry.mjs +0 -37
- package/_shims/registry.mjs.map +0 -1
- package/_shims/web-runtime.d.ts +0 -5
- package/_shims/web-runtime.d.ts.map +0 -1
- package/_shims/web-runtime.js +0 -78
- package/_shims/web-runtime.js.map +0 -1
- package/_shims/web-runtime.mjs +0 -71
- package/_shims/web-runtime.mjs.map +0 -1
- package/_shims/web-types.d.ts +0 -83
- package/_shims/web-types.js +0 -3
- package/_shims/web-types.mjs +0 -3
- package/core.d.ts +0 -241
- package/core.d.ts.map +0 -1
- package/core.js +0 -908
- package/core.js.map +0 -1
- package/core.mjs +0 -876
- package/core.mjs.map +0 -1
- package/error.d.ts +0 -47
- package/error.d.ts.map +0 -1
- package/error.js +0 -113
- package/error.js.map +0 -1
- package/error.mjs +0 -97
- package/error.mjs.map +0 -1
- package/index.d.mts +0 -121
- package/index.d.ts +0 -121
- package/index.d.ts.map +0 -1
- package/index.js +0 -131
- package/index.js.map +0 -1
- package/index.mjs +0 -88
- package/index.mjs.map +0 -1
- package/resource.d.ts +0 -6
- package/resource.d.ts.map +0 -1
- package/resource.js +0 -11
- package/resource.js.map +0 -1
- package/resource.mjs +0 -7
- package/resource.mjs.map +0 -1
- package/resources/agents/agents.d.ts +0 -40
- package/resources/agents/agents.d.ts.map +0 -1
- package/resources/agents/agents.js +0 -74
- package/resources/agents/agents.js.map +0 -1
- package/resources/agents/agents.mjs +0 -47
- package/resources/agents/agents.mjs.map +0 -1
- package/resources/agents/index.d.ts +0 -3
- package/resources/agents/index.d.ts.map +0 -1
- package/resources/agents/index.js +0 -9
- package/resources/agents/index.js.map +0 -1
- package/resources/agents/index.mjs +0 -4
- package/resources/agents/index.mjs.map +0 -1
- package/resources/agents/tools.d.ts +0 -17
- package/resources/agents/tools.d.ts.map +0 -1
- package/resources/agents/tools.js +0 -19
- package/resources/agents/tools.js.map +0 -1
- package/resources/agents/tools.mjs +0 -15
- package/resources/agents/tools.mjs.map +0 -1
- package/resources/index.d.ts +0 -8
- package/resources/index.d.ts.map +0 -1
- package/resources/index.js +0 -19
- package/resources/index.js.map +0 -1
- package/resources/index.mjs +0 -9
- package/resources/index.mjs.map +0 -1
- package/resources/logs.d.ts +0 -13
- package/resources/logs.d.ts.map +0 -1
- package/resources/logs.js +0 -24
- package/resources/logs.js.map +0 -1
- package/resources/logs.mjs +0 -20
- package/resources/logs.mjs.map +0 -1
- package/resources/memory/index.d.ts +0 -4
- package/resources/memory/index.d.ts.map +0 -1
- package/resources/memory/index.js +0 -11
- package/resources/memory/index.js.map +0 -1
- package/resources/memory/index.mjs +0 -5
- package/resources/memory/index.mjs.map +0 -1
- package/resources/memory/memory.d.ts +0 -23
- package/resources/memory/memory.d.ts.map +0 -1
- package/resources/memory/memory.js +0 -53
- package/resources/memory/memory.js.map +0 -1
- package/resources/memory/memory.mjs +0 -26
- package/resources/memory/memory.mjs.map +0 -1
- package/resources/memory/status.d.ts +0 -9
- package/resources/memory/status.d.ts.map +0 -1
- package/resources/memory/status.js +0 -18
- package/resources/memory/status.js.map +0 -1
- package/resources/memory/status.mjs +0 -14
- package/resources/memory/status.mjs.map +0 -1
- package/resources/memory/threads/index.d.ts +0 -3
- package/resources/memory/threads/index.d.ts.map +0 -1
- package/resources/memory/threads/index.js +0 -9
- package/resources/memory/threads/index.js.map +0 -1
- package/resources/memory/threads/index.mjs +0 -4
- package/resources/memory/threads/index.mjs.map +0 -1
- package/resources/memory/threads/messages.d.ts +0 -9
- package/resources/memory/threads/messages.d.ts.map +0 -1
- package/resources/memory/threads/messages.js +0 -18
- package/resources/memory/threads/messages.js.map +0 -1
- package/resources/memory/threads/messages.mjs +0 -14
- package/resources/memory/threads/messages.mjs.map +0 -1
- package/resources/memory/threads/threads.d.ts +0 -45
- package/resources/memory/threads/threads.d.ts.map +0 -1
- package/resources/memory/threads/threads.js +0 -104
- package/resources/memory/threads/threads.js.map +0 -1
- package/resources/memory/threads/threads.mjs +0 -77
- package/resources/memory/threads/threads.mjs.map +0 -1
- package/resources/syncs.d.ts +0 -15
- package/resources/syncs.d.ts.map +0 -1
- package/resources/syncs.js +0 -19
- package/resources/syncs.js.map +0 -1
- package/resources/syncs.mjs +0 -15
- package/resources/syncs.mjs.map +0 -1
- package/resources/system.d.ts +0 -9
- package/resources/system.d.ts.map +0 -1
- package/resources/system.js +0 -15
- package/resources/system.js.map +0 -1
- package/resources/system.mjs +0 -11
- package/resources/system.mjs.map +0 -1
- package/resources/tools/index.d.ts +0 -3
- package/resources/tools/index.d.ts.map +0 -1
- package/resources/tools/index.js +0 -9
- package/resources/tools/index.js.map +0 -1
- package/resources/tools/index.mjs +0 -4
- package/resources/tools/index.mjs.map +0 -1
- package/resources/tools/result.d.ts +0 -9
- package/resources/tools/result.d.ts.map +0 -1
- package/resources/tools/result.js +0 -18
- package/resources/tools/result.js.map +0 -1
- package/resources/tools/result.mjs +0 -14
- package/resources/tools/result.mjs.map +0 -1
- package/resources/tools/tools.d.ts +0 -29
- package/resources/tools/tools.d.ts.map +0 -1
- package/resources/tools/tools.js +0 -64
- package/resources/tools/tools.js.map +0 -1
- package/resources/tools/tools.mjs +0 -37
- package/resources/tools/tools.mjs.map +0 -1
- package/resources/workflows.d.ts +0 -23
- package/resources/workflows.d.ts.map +0 -1
- package/resources/workflows.js +0 -37
- package/resources/workflows.js.map +0 -1
- package/resources/workflows.mjs +0 -33
- package/resources/workflows.mjs.map +0 -1
- package/shims/node.d.ts +0 -30
- package/shims/node.d.ts.map +0 -1
- package/shims/node.js +0 -31
- package/shims/node.js.map +0 -1
- package/shims/node.mjs +0 -5
- package/shims/node.mjs.map +0 -1
- package/shims/web.d.ts +0 -26
- package/shims/web.d.ts.map +0 -1
- package/shims/web.js +0 -31
- package/shims/web.js.map +0 -1
- package/shims/web.mjs +0 -5
- package/shims/web.mjs.map +0 -1
- package/src/_shims/MultipartBody.ts +0 -9
- package/src/_shims/README.md +0 -46
- package/src/_shims/auto/runtime-bun.ts +0 -4
- package/src/_shims/auto/runtime-node.ts +0 -4
- package/src/_shims/auto/runtime.ts +0 -4
- package/src/_shims/auto/types-node.ts +0 -4
- package/src/_shims/auto/types.d.ts +0 -101
- package/src/_shims/auto/types.js +0 -3
- package/src/_shims/auto/types.mjs +0 -3
- package/src/_shims/bun-runtime.ts +0 -14
- package/src/_shims/index.d.ts +0 -81
- package/src/_shims/index.js +0 -13
- package/src/_shims/index.mjs +0 -7
- package/src/_shims/manual-types.d.ts +0 -12
- package/src/_shims/manual-types.js +0 -3
- package/src/_shims/manual-types.mjs +0 -3
- package/src/_shims/node-runtime.ts +0 -81
- package/src/_shims/node-types.d.ts +0 -42
- package/src/_shims/node-types.js +0 -3
- package/src/_shims/node-types.mjs +0 -3
- package/src/_shims/registry.ts +0 -67
- package/src/_shims/web-runtime.ts +0 -103
- package/src/_shims/web-types.d.ts +0 -83
- package/src/_shims/web-types.js +0 -3
- package/src/_shims/web-types.mjs +0 -3
- package/src/core.ts +0 -1201
- package/src/error.ts +0 -130
- package/src/lib/.keep +0 -4
- package/src/resource.ts +0 -11
- package/src/resources/agents/agents.ts +0 -77
- package/src/resources/agents/index.ts +0 -4
- package/src/resources/agents/tools.ts +0 -34
- package/src/resources/logs.ts +0 -23
- package/src/resources/memory/index.ts +0 -5
- package/src/resources/memory/memory.ts +0 -43
- package/src/resources/memory/status.ts +0 -16
- package/src/resources/memory/threads/index.ts +0 -4
- package/src/resources/memory/threads/messages.ts +0 -16
- package/src/resources/memory/threads/threads.ts +0 -105
- package/src/resources/syncs.ts +0 -25
- package/src/resources/system.ts +0 -13
- package/src/resources/tools/index.ts +0 -4
- package/src/resources/tools/result.ts +0 -16
- package/src/resources/tools/tools.ts +0 -54
- package/src/resources/workflows.ts +0 -49
- package/src/shims/node.ts +0 -50
- package/src/shims/web.ts +0 -50
- package/src/tsconfig.json +0 -11
- package/src/uploads.ts +0 -255
- package/src/version.ts +0 -1
- package/uploads.d.ts +0 -75
- package/uploads.d.ts.map +0 -1
- package/uploads.js +0 -171
- package/uploads.js.map +0 -1
- package/uploads.mjs +0 -158
- package/uploads.mjs.map +0 -1
- package/version.d.ts +0 -2
- package/version.d.ts.map +0 -1
- package/version.js +0 -5
- package/version.js.map +0 -1
- package/version.mjs +0 -2
- package/version.mjs.map +0 -1
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,410 @@
|
|
|
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`);
|
|
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) {
|
|
135
|
+
super(options);
|
|
136
|
+
this.threadId = threadId;
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* Retrieves the memory thread details
|
|
140
|
+
* @returns Promise containing thread details including title and metadata
|
|
141
|
+
*/
|
|
142
|
+
get() {
|
|
143
|
+
return this.request(`/api/memory/threads/${this.threadId}`);
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* Updates the memory thread properties
|
|
147
|
+
* @param params - Update parameters including title and metadata
|
|
148
|
+
* @returns Promise containing updated thread details
|
|
149
|
+
*/
|
|
150
|
+
update(params) {
|
|
151
|
+
return this.request(`/api/memory/threads/${this.threadId}`, {
|
|
152
|
+
method: "PATCH",
|
|
153
|
+
body: params
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* Deletes the memory thread
|
|
158
|
+
* @returns Promise containing deletion result
|
|
159
|
+
*/
|
|
160
|
+
delete() {
|
|
161
|
+
return this.request(`/api/memory/threads/${this.threadId}`, {
|
|
162
|
+
method: "DELETE"
|
|
163
|
+
});
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* Retrieves messages associated with the thread
|
|
167
|
+
* @returns Promise containing thread messages and UI messages
|
|
168
|
+
*/
|
|
169
|
+
getMessages() {
|
|
170
|
+
return this.request(`/api/memory/threads/${this.threadId}/messages`);
|
|
171
|
+
}
|
|
172
|
+
};
|
|
173
|
+
|
|
174
|
+
// src/resources/vector.ts
|
|
175
|
+
var Vector = class extends BaseResource {
|
|
176
|
+
constructor(options, vectorName) {
|
|
177
|
+
super(options);
|
|
178
|
+
this.vectorName = vectorName;
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* Retrieves details about a specific vector index
|
|
182
|
+
* @param indexName - Name of the index to get details for
|
|
183
|
+
* @returns Promise containing vector index details
|
|
184
|
+
*/
|
|
185
|
+
details(indexName) {
|
|
186
|
+
return this.request(`/api/vector/${this.vectorName}/indexes/${indexName}`);
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* Deletes a vector index
|
|
190
|
+
* @param indexName - Name of the index to delete
|
|
191
|
+
* @returns Promise indicating deletion success
|
|
192
|
+
*/
|
|
193
|
+
delete(indexName) {
|
|
194
|
+
return this.request(`/api/vector/${this.vectorName}/indexes/${indexName}`, {
|
|
195
|
+
method: "DELETE"
|
|
196
|
+
});
|
|
197
|
+
}
|
|
198
|
+
/**
|
|
199
|
+
* Retrieves a list of all available indexes
|
|
200
|
+
* @returns Promise containing array of index names
|
|
201
|
+
*/
|
|
202
|
+
getIndexes() {
|
|
203
|
+
return this.request(`/api/vector/${this.vectorName}/indexes`);
|
|
204
|
+
}
|
|
205
|
+
/**
|
|
206
|
+
* Creates a new vector index
|
|
207
|
+
* @param params - Parameters for index creation including dimension and metric
|
|
208
|
+
* @returns Promise indicating creation success
|
|
209
|
+
*/
|
|
210
|
+
createIndex(params) {
|
|
211
|
+
return this.request(`/api/vector/${this.vectorName}/create-index`, {
|
|
212
|
+
method: "POST",
|
|
213
|
+
body: params
|
|
214
|
+
});
|
|
215
|
+
}
|
|
216
|
+
/**
|
|
217
|
+
* Upserts vectors into an index
|
|
218
|
+
* @param params - Parameters containing vectors, metadata, and optional IDs
|
|
219
|
+
* @returns Promise containing array of vector IDs
|
|
220
|
+
*/
|
|
221
|
+
upsert(params) {
|
|
222
|
+
return this.request(`/api/vector/${this.vectorName}/upsert`, {
|
|
223
|
+
method: "POST",
|
|
224
|
+
body: params
|
|
225
|
+
});
|
|
226
|
+
}
|
|
227
|
+
/**
|
|
228
|
+
* Queries vectors in an index
|
|
229
|
+
* @param params - Query parameters including query vector and search options
|
|
230
|
+
* @returns Promise containing query results
|
|
231
|
+
*/
|
|
232
|
+
query(params) {
|
|
233
|
+
return this.request(`/api/vector/${this.vectorName}/query`, {
|
|
234
|
+
method: "POST",
|
|
235
|
+
body: params
|
|
236
|
+
});
|
|
237
|
+
}
|
|
238
|
+
};
|
|
239
|
+
|
|
240
|
+
// src/resources/workflow.ts
|
|
241
|
+
var Workflow = class extends BaseResource {
|
|
242
|
+
constructor(options, workflowId) {
|
|
243
|
+
super(options);
|
|
244
|
+
this.workflowId = workflowId;
|
|
245
|
+
}
|
|
246
|
+
/**
|
|
247
|
+
* Retrieves details about the workflow
|
|
248
|
+
* @returns Promise containing workflow details including steps and graphs
|
|
249
|
+
*/
|
|
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);
|
|
296
|
+
}
|
|
297
|
+
/**
|
|
298
|
+
* Retrieves all available agents
|
|
299
|
+
* @returns Promise containing map of agent IDs to agent details
|
|
300
|
+
*/
|
|
301
|
+
getAgents() {
|
|
302
|
+
return this.request("/api/agents");
|
|
303
|
+
}
|
|
304
|
+
/**
|
|
305
|
+
* Gets an agent instance by ID
|
|
306
|
+
* @param agentId - ID of the agent to retrieve
|
|
307
|
+
* @returns Agent instance
|
|
308
|
+
*/
|
|
309
|
+
getAgent(agentId) {
|
|
310
|
+
return new Agent(this.options, agentId);
|
|
311
|
+
}
|
|
312
|
+
/**
|
|
313
|
+
* Retrieves memory threads for a resource
|
|
314
|
+
* @param params - Parameters containing the resource ID
|
|
315
|
+
* @returns Promise containing array of memory threads
|
|
316
|
+
*/
|
|
317
|
+
getMemoryThreads(params) {
|
|
318
|
+
return this.request(`/api/memory/threads?resourceid=${params.resourceId}`);
|
|
319
|
+
}
|
|
320
|
+
/**
|
|
321
|
+
* Creates a new memory thread
|
|
322
|
+
* @param params - Parameters for creating the memory thread
|
|
323
|
+
* @returns Promise containing the created memory thread
|
|
324
|
+
*/
|
|
325
|
+
createMemoryThread(params) {
|
|
326
|
+
return this.request("/api/memory/threads", { method: "POST", body: params });
|
|
327
|
+
}
|
|
328
|
+
/**
|
|
329
|
+
* Gets a memory thread instance by ID
|
|
330
|
+
* @param threadId - ID of the memory thread to retrieve
|
|
331
|
+
* @returns MemoryThread instance
|
|
332
|
+
*/
|
|
333
|
+
getMemoryThread(threadId) {
|
|
334
|
+
return new MemoryThread(this.options, threadId);
|
|
335
|
+
}
|
|
336
|
+
/**
|
|
337
|
+
* Saves messages to memory
|
|
338
|
+
* @param params - Parameters containing messages to save
|
|
339
|
+
* @returns Promise containing the saved messages
|
|
340
|
+
*/
|
|
341
|
+
saveMessageToMemory(params) {
|
|
342
|
+
return this.request("/api/memory/save-messages", {
|
|
343
|
+
method: "POST",
|
|
344
|
+
body: params
|
|
345
|
+
});
|
|
346
|
+
}
|
|
347
|
+
/**
|
|
348
|
+
* Gets the status of the memory system
|
|
349
|
+
* @returns Promise containing memory system status
|
|
350
|
+
*/
|
|
351
|
+
getMemoryStatus() {
|
|
352
|
+
return this.request("/api/memory/status");
|
|
353
|
+
}
|
|
354
|
+
/**
|
|
355
|
+
* Retrieves all available tools
|
|
356
|
+
* @returns Promise containing map of tool IDs to tool details
|
|
357
|
+
*/
|
|
358
|
+
getTools() {
|
|
359
|
+
return this.request("/api/tools");
|
|
360
|
+
}
|
|
361
|
+
/**
|
|
362
|
+
* Gets a tool instance by ID
|
|
363
|
+
* @param toolId - ID of the tool to retrieve
|
|
364
|
+
* @returns Tool instance
|
|
365
|
+
*/
|
|
366
|
+
getTool(toolId) {
|
|
367
|
+
return new Tool(this.options, toolId);
|
|
368
|
+
}
|
|
369
|
+
/**
|
|
370
|
+
* Retrieves all available workflows
|
|
371
|
+
* @returns Promise containing map of workflow IDs to workflow details
|
|
372
|
+
*/
|
|
373
|
+
getWorkflows() {
|
|
374
|
+
return this.request("/api/workflows");
|
|
375
|
+
}
|
|
376
|
+
/**
|
|
377
|
+
* Gets a workflow instance by ID
|
|
378
|
+
* @param workflowId - ID of the workflow to retrieve
|
|
379
|
+
* @returns Workflow instance
|
|
380
|
+
*/
|
|
381
|
+
getWorkflow(workflowId) {
|
|
382
|
+
return new Workflow(this.options, workflowId);
|
|
383
|
+
}
|
|
384
|
+
/**
|
|
385
|
+
* Gets a vector instance by name
|
|
386
|
+
* @param vectorName - Name of the vector to retrieve
|
|
387
|
+
* @returns Vector instance
|
|
388
|
+
*/
|
|
389
|
+
getVector(vectorName) {
|
|
390
|
+
return new Vector(this.options, vectorName);
|
|
391
|
+
}
|
|
392
|
+
/**
|
|
393
|
+
* Retrieves logs
|
|
394
|
+
* @param params - Parameters for filtering logs
|
|
395
|
+
* @returns Promise containing array of log messages
|
|
396
|
+
*/
|
|
397
|
+
getLogs(params) {
|
|
398
|
+
return this.request(`/api/logs?transportId=${params.transportId}`);
|
|
399
|
+
}
|
|
400
|
+
/**
|
|
401
|
+
* Gets logs for a specific run
|
|
402
|
+
* @param params - Parameters containing run ID to retrieve
|
|
403
|
+
* @returns Promise containing array of log messages
|
|
404
|
+
*/
|
|
405
|
+
getLogForRun(params) {
|
|
406
|
+
return this.request(`/api/logs/${params.runId}?transportId=${params.transportId}`);
|
|
407
|
+
}
|
|
408
|
+
};
|
|
409
|
+
|
|
410
|
+
export { MastraClient };
|
package/package.json
CHANGED
|
@@ -1,103 +1,40 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mastra/client-js",
|
|
3
|
-
"version": "0.1.0-alpha.
|
|
3
|
+
"version": "0.1.0-alpha.10",
|
|
4
4
|
"description": "The official TypeScript library for the Mastra Client API",
|
|
5
|
-
"author": "
|
|
6
|
-
"types": "
|
|
7
|
-
"main": "
|
|
8
|
-
"
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
"scripts": {
|
|
17
|
-
"test": "./scripts/test",
|
|
18
|
-
"build": "./scripts/build",
|
|
19
|
-
"format": "prettier --write --cache --cache-strategy metadata . !dist",
|
|
20
|
-
"tsn": "ts-node -r tsconfig-paths/register",
|
|
21
|
-
"lint": "./scripts/lint",
|
|
22
|
-
"fix": "./scripts/format"
|
|
5
|
+
"author": "",
|
|
6
|
+
"types": "dist/index.d.mts",
|
|
7
|
+
"main": "dist/index.mjs",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"import": {
|
|
11
|
+
"types": "./dist/index.d.mts",
|
|
12
|
+
"default": "./dist/index.mjs"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"./package.json": "./package.json"
|
|
23
16
|
},
|
|
17
|
+
"repository": "github:mastra-ai/client-js",
|
|
18
|
+
"license": "ISC",
|
|
24
19
|
"dependencies": {
|
|
25
|
-
"@
|
|
26
|
-
"
|
|
27
|
-
"
|
|
28
|
-
"
|
|
29
|
-
"form-data-encoder": "1.7.2",
|
|
30
|
-
"formdata-node": "^4.3.2",
|
|
31
|
-
"node-fetch": "^2.6.7"
|
|
20
|
+
"@mastra/core": "^0.2.0-alpha.83",
|
|
21
|
+
"json-schema": "^0.4.0",
|
|
22
|
+
"zod": "^3.24.1",
|
|
23
|
+
"zod-to-json-schema": "^3.24.1"
|
|
32
24
|
},
|
|
33
|
-
"
|
|
34
|
-
"
|
|
35
|
-
"
|
|
36
|
-
"
|
|
37
|
-
"
|
|
38
|
-
"
|
|
39
|
-
"
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
"@mastra/client-js": ".",
|
|
43
|
-
"@mastra/client-js/*": "./src/*"
|
|
25
|
+
"devDependencies": {
|
|
26
|
+
"@babel/preset-env": "^7.26.0",
|
|
27
|
+
"@babel/preset-typescript": "^7.26.0",
|
|
28
|
+
"@tsconfig/recommended": "^1.0.7",
|
|
29
|
+
"@types/json-schema": "^7.0.15",
|
|
30
|
+
"@types/node": "^22.9.0",
|
|
31
|
+
"tsup": "^8.0.1",
|
|
32
|
+
"typescript": "^5.7.3",
|
|
33
|
+
"vitest": "^3.0.4"
|
|
44
34
|
},
|
|
45
|
-
"
|
|
46
|
-
"
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
"require": "./_shims/auto/*.js",
|
|
50
|
-
"default": "./_shims/auto/*.mjs"
|
|
51
|
-
},
|
|
52
|
-
"bun": {
|
|
53
|
-
"types": "./_shims/auto/*.d.ts",
|
|
54
|
-
"require": "./_shims/auto/*-bun.js",
|
|
55
|
-
"default": "./_shims/auto/*-bun.mjs"
|
|
56
|
-
},
|
|
57
|
-
"browser": {
|
|
58
|
-
"types": "./_shims/auto/*.d.ts",
|
|
59
|
-
"require": "./_shims/auto/*.js",
|
|
60
|
-
"default": "./_shims/auto/*.mjs"
|
|
61
|
-
},
|
|
62
|
-
"worker": {
|
|
63
|
-
"types": "./_shims/auto/*.d.ts",
|
|
64
|
-
"require": "./_shims/auto/*.js",
|
|
65
|
-
"default": "./_shims/auto/*.mjs"
|
|
66
|
-
},
|
|
67
|
-
"workerd": {
|
|
68
|
-
"types": "./_shims/auto/*.d.ts",
|
|
69
|
-
"require": "./_shims/auto/*.js",
|
|
70
|
-
"default": "./_shims/auto/*.mjs"
|
|
71
|
-
},
|
|
72
|
-
"node": {
|
|
73
|
-
"types": "./_shims/auto/*-node.d.ts",
|
|
74
|
-
"require": "./_shims/auto/*-node.js",
|
|
75
|
-
"default": "./_shims/auto/*-node.mjs"
|
|
76
|
-
},
|
|
77
|
-
"types": "./_shims/auto/*.d.ts",
|
|
78
|
-
"require": "./_shims/auto/*.js",
|
|
79
|
-
"default": "./_shims/auto/*.mjs"
|
|
80
|
-
},
|
|
81
|
-
".": {
|
|
82
|
-
"require": {
|
|
83
|
-
"types": "./index.d.ts",
|
|
84
|
-
"default": "./index.js"
|
|
85
|
-
},
|
|
86
|
-
"types": "./index.d.mts",
|
|
87
|
-
"default": "./index.mjs"
|
|
88
|
-
},
|
|
89
|
-
"./*.mjs": {
|
|
90
|
-
"types": "./*.d.ts",
|
|
91
|
-
"default": "./*.mjs"
|
|
92
|
-
},
|
|
93
|
-
"./*.js": {
|
|
94
|
-
"types": "./*.d.ts",
|
|
95
|
-
"default": "./*.js"
|
|
96
|
-
},
|
|
97
|
-
"./*": {
|
|
98
|
-
"types": "./*.d.ts",
|
|
99
|
-
"require": "./*.js",
|
|
100
|
-
"default": "./*.mjs"
|
|
101
|
-
}
|
|
35
|
+
"scripts": {
|
|
36
|
+
"build": "tsup-node src/index.ts --format esm --dts --clean --treeshake",
|
|
37
|
+
"dev": "tsup-node src/index.ts --format esm --dts --clean --treeshake --watch",
|
|
38
|
+
"test": "vitest run"
|
|
102
39
|
}
|
|
103
|
-
}
|
|
40
|
+
}
|
package/src/client.ts
ADDED
|
@@ -0,0 +1,135 @@
|
|
|
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, BaseResource } from './resources';
|
|
3
|
+
|
|
4
|
+
export class MastraClient extends BaseResource {
|
|
5
|
+
|
|
6
|
+
constructor(options: ClientOptions) {
|
|
7
|
+
super(options);
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Retrieves all available agents
|
|
13
|
+
* @returns Promise containing map of agent IDs to agent details
|
|
14
|
+
*/
|
|
15
|
+
public getAgents(): Promise<Record<string, GetAgentResponse>> {
|
|
16
|
+
return this.request('/api/agents');
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Gets an agent instance by ID
|
|
21
|
+
* @param agentId - ID of the agent to retrieve
|
|
22
|
+
* @returns Agent instance
|
|
23
|
+
*/
|
|
24
|
+
public getAgent(agentId: string) {
|
|
25
|
+
return new Agent(this.options, agentId);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Retrieves memory threads for a resource
|
|
30
|
+
* @param params - Parameters containing the resource ID
|
|
31
|
+
* @returns Promise containing array of memory threads
|
|
32
|
+
*/
|
|
33
|
+
public getMemoryThreads(params: GetMemoryThreadParams): Promise<GetMemoryThreadResponse> {
|
|
34
|
+
return this.request(`/api/memory/threads?resourceid=${params.resourceId}`);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Creates a new memory thread
|
|
39
|
+
* @param params - Parameters for creating the memory thread
|
|
40
|
+
* @returns Promise containing the created memory thread
|
|
41
|
+
*/
|
|
42
|
+
public createMemoryThread(params: CreateMemoryThreadParams): Promise<CreateMemoryThreadResponse> {
|
|
43
|
+
return this.request('/api/memory/threads', { method: 'POST', body: params });
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Gets a memory thread instance by ID
|
|
48
|
+
* @param threadId - ID of the memory thread to retrieve
|
|
49
|
+
* @returns MemoryThread instance
|
|
50
|
+
*/
|
|
51
|
+
public getMemoryThread(threadId: string) {
|
|
52
|
+
return new MemoryThread(this.options, threadId);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Saves messages to memory
|
|
57
|
+
* @param params - Parameters containing messages to save
|
|
58
|
+
* @returns Promise containing the saved messages
|
|
59
|
+
*/
|
|
60
|
+
public saveMessageToMemory(params: SaveMessageToMemoryParams): Promise<SaveMessageToMemoryResponse> {
|
|
61
|
+
return this.request('/api/memory/save-messages', {
|
|
62
|
+
method: 'POST',
|
|
63
|
+
body: params,
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Gets the status of the memory system
|
|
69
|
+
* @returns Promise containing memory system status
|
|
70
|
+
*/
|
|
71
|
+
public getMemoryStatus(): Promise<{ result: boolean }> {
|
|
72
|
+
return this.request('/api/memory/status');
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Retrieves all available tools
|
|
77
|
+
* @returns Promise containing map of tool IDs to tool details
|
|
78
|
+
*/
|
|
79
|
+
public getTools(): Promise<Record<string, GetToolResponse>> {
|
|
80
|
+
return this.request('/api/tools');
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Gets a tool instance by ID
|
|
85
|
+
* @param toolId - ID of the tool to retrieve
|
|
86
|
+
* @returns Tool instance
|
|
87
|
+
*/
|
|
88
|
+
public getTool(toolId: string) {
|
|
89
|
+
return new Tool(this.options, toolId);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Retrieves all available workflows
|
|
94
|
+
* @returns Promise containing map of workflow IDs to workflow details
|
|
95
|
+
*/
|
|
96
|
+
public getWorkflows(): Promise<Record<string, GetWorkflowResponse>> {
|
|
97
|
+
return this.request('/api/workflows');
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* Gets a workflow instance by ID
|
|
102
|
+
* @param workflowId - ID of the workflow to retrieve
|
|
103
|
+
* @returns Workflow instance
|
|
104
|
+
*/
|
|
105
|
+
public getWorkflow(workflowId: string) {
|
|
106
|
+
return new Workflow(this.options, workflowId);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* Gets a vector instance by name
|
|
111
|
+
* @param vectorName - Name of the vector to retrieve
|
|
112
|
+
* @returns Vector instance
|
|
113
|
+
*/
|
|
114
|
+
public getVector(vectorName: string) {
|
|
115
|
+
return new Vector(this.options, vectorName);
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* Retrieves logs
|
|
120
|
+
* @param params - Parameters for filtering logs
|
|
121
|
+
* @returns Promise containing array of log messages
|
|
122
|
+
*/
|
|
123
|
+
public getLogs(params: GetLogsParams): Promise<GetLogsResponse> {
|
|
124
|
+
return this.request(`/api/logs?transportId=${params.transportId}`);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* Gets logs for a specific run
|
|
129
|
+
* @param params - Parameters containing run ID to retrieve
|
|
130
|
+
* @returns Promise containing array of log messages
|
|
131
|
+
*/
|
|
132
|
+
public getLogForRun(params: GetLogParams): Promise<GetLogsResponse> {
|
|
133
|
+
return this.request(`/api/logs/${params.runId}?transportId=${params.transportId}`);
|
|
134
|
+
}
|
|
135
|
+
}
|