@mastra/client-js 0.1.0-alpha.1 → 0.1.0-alpha.11
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 +30 -93
- 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/src/index.ts
CHANGED
|
@@ -1,194 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
import { type Agent } from './_shims/index';
|
|
4
|
-
import * as Core from './core';
|
|
5
|
-
import * as Errors from './error';
|
|
6
|
-
import * as Uploads from './uploads';
|
|
7
|
-
import * as API from './resources/index';
|
|
8
|
-
import { Logs } from './resources/logs';
|
|
9
|
-
import { SyncExecuteParams, Syncs } from './resources/syncs';
|
|
10
|
-
import { System } from './resources/system';
|
|
11
|
-
import { WorkflowExecuteParams, Workflows } from './resources/workflows';
|
|
12
|
-
import { AgentGenerateParams, AgentStreamParams, Agents } from './resources/agents/agents';
|
|
13
|
-
import { Memory, MemorySaveMessagesParams } from './resources/memory/memory';
|
|
14
|
-
import { ToolExecuteParams, Tools } from './resources/tools/tools';
|
|
15
|
-
|
|
16
|
-
export interface ClientOptions {
|
|
17
|
-
/**
|
|
18
|
-
* Override the default base URL for the API, e.g., "https://api.example.com/v2/"
|
|
19
|
-
*
|
|
20
|
-
* Defaults to process.env['MASTRA_CLIENT_BASE_URL'].
|
|
21
|
-
*/
|
|
22
|
-
baseURL?: string | null | undefined;
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* The maximum amount of time (in milliseconds) that the client should wait for a response
|
|
26
|
-
* from the server before timing out a single request.
|
|
27
|
-
*
|
|
28
|
-
* Note that request timeouts are retried by default, so in a worst-case scenario you may wait
|
|
29
|
-
* much longer than this timeout before the promise succeeds or fails.
|
|
30
|
-
*/
|
|
31
|
-
timeout?: number | undefined;
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* An HTTP agent used to manage HTTP(S) connections.
|
|
35
|
-
*
|
|
36
|
-
* If not provided, an agent will be constructed by default in the Node.js environment,
|
|
37
|
-
* otherwise no agent is used.
|
|
38
|
-
*/
|
|
39
|
-
httpAgent?: Agent | undefined;
|
|
40
|
-
|
|
41
|
-
/**
|
|
42
|
-
* Specify a custom `fetch` function implementation.
|
|
43
|
-
*
|
|
44
|
-
* If not provided, we use `node-fetch` on Node.js and otherwise expect that `fetch` is
|
|
45
|
-
* defined globally.
|
|
46
|
-
*/
|
|
47
|
-
fetch?: Core.Fetch | undefined;
|
|
48
|
-
|
|
49
|
-
/**
|
|
50
|
-
* The maximum number of times that the client will retry a request in case of a
|
|
51
|
-
* temporary failure, like a network error or a 5XX error from the server.
|
|
52
|
-
*
|
|
53
|
-
* @default 2
|
|
54
|
-
*/
|
|
55
|
-
maxRetries?: number | undefined;
|
|
56
|
-
|
|
57
|
-
/**
|
|
58
|
-
* Default headers to include with every request to the API.
|
|
59
|
-
*
|
|
60
|
-
* These can be removed in individual requests by explicitly setting the
|
|
61
|
-
* header to `undefined` or `null` in request options.
|
|
62
|
-
*/
|
|
63
|
-
defaultHeaders?: Core.Headers | undefined;
|
|
64
|
-
|
|
65
|
-
/**
|
|
66
|
-
* Default query parameters to include with every request to the API.
|
|
67
|
-
*
|
|
68
|
-
* These can be removed in individual requests by explicitly setting the
|
|
69
|
-
* param to `undefined` in request options.
|
|
70
|
-
*/
|
|
71
|
-
defaultQuery?: Core.DefaultQuery | undefined;
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
/**
|
|
75
|
-
* API Client for interfacing with the Mastra Client API.
|
|
76
|
-
*/
|
|
77
|
-
export class MastraClient extends Core.APIClient {
|
|
78
|
-
private _options: ClientOptions;
|
|
79
|
-
|
|
80
|
-
/**
|
|
81
|
-
* API Client for interfacing with the Mastra Client API.
|
|
82
|
-
*
|
|
83
|
-
* @param {string} [opts.baseURL=process.env['MASTRA_CLIENT_BASE_URL'] ?? http://localhost:4111] - Override the default base URL for the API.
|
|
84
|
-
* @param {number} [opts.timeout=1 minute] - The maximum amount of time (in milliseconds) the client will wait for a response before timing out.
|
|
85
|
-
* @param {number} [opts.httpAgent] - An HTTP agent used to manage HTTP(s) connections.
|
|
86
|
-
* @param {Core.Fetch} [opts.fetch] - Specify a custom `fetch` function implementation.
|
|
87
|
-
* @param {number} [opts.maxRetries=2] - The maximum number of times the client will retry a request.
|
|
88
|
-
* @param {Core.Headers} opts.defaultHeaders - Default headers to include with every request to the API.
|
|
89
|
-
* @param {Core.DefaultQuery} opts.defaultQuery - Default query parameters to include with every request to the API.
|
|
90
|
-
*/
|
|
91
|
-
constructor({ baseURL = Core.readEnv('MASTRA_CLIENT_BASE_URL'), ...opts }: ClientOptions = {}) {
|
|
92
|
-
const options: ClientOptions = {
|
|
93
|
-
...opts,
|
|
94
|
-
baseURL: baseURL || `http://localhost:4111`,
|
|
95
|
-
};
|
|
96
|
-
|
|
97
|
-
super({
|
|
98
|
-
baseURL: options.baseURL!,
|
|
99
|
-
timeout: options.timeout ?? 60000 /* 1 minute */,
|
|
100
|
-
httpAgent: options.httpAgent,
|
|
101
|
-
maxRetries: options.maxRetries,
|
|
102
|
-
fetch: options.fetch,
|
|
103
|
-
});
|
|
104
|
-
|
|
105
|
-
this._options = options;
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
system: API.System = new API.System(this);
|
|
109
|
-
agents: API.Agents = new API.Agents(this);
|
|
110
|
-
memory: API.Memory = new API.Memory(this);
|
|
111
|
-
workflows: API.Workflows = new API.Workflows(this);
|
|
112
|
-
syncs: API.Syncs = new API.Syncs(this);
|
|
113
|
-
logs: API.Logs = new API.Logs(this);
|
|
114
|
-
tools: API.Tools = new API.Tools(this);
|
|
115
|
-
|
|
116
|
-
protected override defaultQuery(): Core.DefaultQuery | undefined {
|
|
117
|
-
return this._options.defaultQuery;
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
protected override defaultHeaders(opts: Core.FinalRequestOptions): Core.Headers {
|
|
121
|
-
return {
|
|
122
|
-
...super.defaultHeaders(opts),
|
|
123
|
-
...this._options.defaultHeaders,
|
|
124
|
-
};
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
static MastraClient = this;
|
|
128
|
-
static DEFAULT_TIMEOUT = 60000; // 1 minute
|
|
129
|
-
|
|
130
|
-
static MastraClientError = Errors.MastraClientError;
|
|
131
|
-
static APIError = Errors.APIError;
|
|
132
|
-
static APIConnectionError = Errors.APIConnectionError;
|
|
133
|
-
static APIConnectionTimeoutError = Errors.APIConnectionTimeoutError;
|
|
134
|
-
static APIUserAbortError = Errors.APIUserAbortError;
|
|
135
|
-
static NotFoundError = Errors.NotFoundError;
|
|
136
|
-
static ConflictError = Errors.ConflictError;
|
|
137
|
-
static RateLimitError = Errors.RateLimitError;
|
|
138
|
-
static BadRequestError = Errors.BadRequestError;
|
|
139
|
-
static AuthenticationError = Errors.AuthenticationError;
|
|
140
|
-
static InternalServerError = Errors.InternalServerError;
|
|
141
|
-
static PermissionDeniedError = Errors.PermissionDeniedError;
|
|
142
|
-
static UnprocessableEntityError = Errors.UnprocessableEntityError;
|
|
143
|
-
|
|
144
|
-
static toFile = Uploads.toFile;
|
|
145
|
-
static fileFromPath = Uploads.fileFromPath;
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
MastraClient.System = System;
|
|
149
|
-
MastraClient.Agents = Agents;
|
|
150
|
-
MastraClient.Memory = Memory;
|
|
151
|
-
MastraClient.Workflows = Workflows;
|
|
152
|
-
MastraClient.Syncs = Syncs;
|
|
153
|
-
MastraClient.Logs = Logs;
|
|
154
|
-
MastraClient.Tools = Tools;
|
|
155
|
-
export declare namespace MastraClient {
|
|
156
|
-
export type RequestOptions = Core.RequestOptions;
|
|
157
|
-
|
|
158
|
-
export { System as System };
|
|
159
|
-
|
|
160
|
-
export {
|
|
161
|
-
Agents as Agents,
|
|
162
|
-
type AgentGenerateParams as AgentGenerateParams,
|
|
163
|
-
type AgentStreamParams as AgentStreamParams,
|
|
164
|
-
};
|
|
165
|
-
|
|
166
|
-
export { Memory as Memory, type MemorySaveMessagesParams as MemorySaveMessagesParams };
|
|
167
|
-
|
|
168
|
-
export { Workflows as Workflows, type WorkflowExecuteParams as WorkflowExecuteParams };
|
|
169
|
-
|
|
170
|
-
export { Syncs as Syncs, type SyncExecuteParams as SyncExecuteParams };
|
|
171
|
-
|
|
172
|
-
export { Logs as Logs };
|
|
173
|
-
|
|
174
|
-
export { Tools as Tools, type ToolExecuteParams as ToolExecuteParams };
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
export { toFile, fileFromPath } from './uploads';
|
|
178
|
-
export {
|
|
179
|
-
MastraClientError,
|
|
180
|
-
APIError,
|
|
181
|
-
APIConnectionError,
|
|
182
|
-
APIConnectionTimeoutError,
|
|
183
|
-
APIUserAbortError,
|
|
184
|
-
NotFoundError,
|
|
185
|
-
ConflictError,
|
|
186
|
-
RateLimitError,
|
|
187
|
-
BadRequestError,
|
|
188
|
-
AuthenticationError,
|
|
189
|
-
InternalServerError,
|
|
190
|
-
PermissionDeniedError,
|
|
191
|
-
UnprocessableEntityError,
|
|
192
|
-
} from './error';
|
|
193
|
-
|
|
194
|
-
export default MastraClient;
|
|
1
|
+
export * from './client';
|
|
2
|
+
export * from './types';
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
GenerateParams,
|
|
3
|
+
GetAgentResponse,
|
|
4
|
+
GetEvalsByAgentIdResponse,
|
|
5
|
+
GetToolResponse,
|
|
6
|
+
ClientOptions,
|
|
7
|
+
StreamParams,
|
|
8
|
+
} from '../types';
|
|
9
|
+
import type {
|
|
10
|
+
GenerateReturn,
|
|
11
|
+
StreamReturn,
|
|
12
|
+
} from '@mastra/core';
|
|
13
|
+
import type { JSONSchema7 } from 'json-schema';
|
|
14
|
+
import { ZodSchema } from "zod";
|
|
15
|
+
import { zodToJsonSchema } from 'zod-to-json-schema';
|
|
16
|
+
import { BaseResource } from './base';
|
|
17
|
+
|
|
18
|
+
export class AgentTool extends BaseResource {
|
|
19
|
+
constructor(
|
|
20
|
+
options: ClientOptions,
|
|
21
|
+
private agentId: string,
|
|
22
|
+
private toolId: string
|
|
23
|
+
) {
|
|
24
|
+
super(options);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Executes a specific tool for an agent
|
|
29
|
+
* @param params - Parameters required for tool execution
|
|
30
|
+
* @returns Promise containing tool execution results
|
|
31
|
+
*/
|
|
32
|
+
execute(params: Record<string, any>): Promise<Record<string, any>> {
|
|
33
|
+
return this.request(`/api/agents/${this.agentId}/tools/${this.toolId}/execute`, {
|
|
34
|
+
method: 'POST',
|
|
35
|
+
body: params,
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export class Agent extends BaseResource {
|
|
41
|
+
constructor(
|
|
42
|
+
options: ClientOptions,
|
|
43
|
+
private agentId: string
|
|
44
|
+
) {
|
|
45
|
+
super(options);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Retrieves details about the agent
|
|
50
|
+
* @returns Promise containing agent details including model and instructions
|
|
51
|
+
*/
|
|
52
|
+
details(): Promise<GetAgentResponse> {
|
|
53
|
+
return this.request(`/api/agents/${this.agentId}`);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Generates a response from the agent
|
|
58
|
+
* @param params - Generation parameters including prompt
|
|
59
|
+
* @returns Promise containing the generated response
|
|
60
|
+
*/
|
|
61
|
+
generate<T extends JSONSchema7 | ZodSchema | undefined = undefined>(params: GenerateParams<T>): Promise<GenerateReturn<T>> {
|
|
62
|
+
const processedParams = {
|
|
63
|
+
...params,
|
|
64
|
+
output: params.output instanceof ZodSchema ? zodToJsonSchema(params.output) : params.output
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
return this.request(`/api/agents/${this.agentId}/generate`, {
|
|
68
|
+
method: 'POST',
|
|
69
|
+
body: processedParams,
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Streams a response from the agent
|
|
75
|
+
* @param params - Stream parameters including prompt
|
|
76
|
+
* @returns Promise containing the streamed response
|
|
77
|
+
*/
|
|
78
|
+
stream<T extends JSONSchema7 | ZodSchema | undefined = undefined>(params: StreamParams<T>): Promise<Response> {
|
|
79
|
+
const processedParams = {
|
|
80
|
+
...params,
|
|
81
|
+
output: params.output instanceof ZodSchema ? zodToJsonSchema(params.output) : params.output,
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
return this.request(`/api/agents/${this.agentId}/stream`, {
|
|
85
|
+
method: 'POST',
|
|
86
|
+
body: processedParams,
|
|
87
|
+
stream: true
|
|
88
|
+
})
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* Gets details about a specific tool available to the agent
|
|
93
|
+
* @param toolId - ID of the tool to retrieve
|
|
94
|
+
* @returns Promise containing tool details
|
|
95
|
+
*/
|
|
96
|
+
getTool(toolId: string): Promise<GetToolResponse> {
|
|
97
|
+
return this.request(`/api/agents/${this.agentId}/tools/${toolId}`);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* Retrieves evaluation results for the agent
|
|
102
|
+
* @returns Promise containing agent evaluations
|
|
103
|
+
*/
|
|
104
|
+
evals(): Promise<GetEvalsByAgentIdResponse> {
|
|
105
|
+
return this.request(`/api/agents/${this.agentId}/evals`);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* Retrieves live evaluation results for the agent
|
|
110
|
+
* @returns Promise containing live agent evaluations
|
|
111
|
+
*/
|
|
112
|
+
liveEvals(): Promise<GetEvalsByAgentIdResponse> {
|
|
113
|
+
return this.request(`/api/agents/${this.agentId}/evals/live`);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import type { RequestFunction, RequestOptions, ClientOptions } from '../types';
|
|
2
|
+
|
|
3
|
+
export class BaseResource {
|
|
4
|
+
readonly options: ClientOptions
|
|
5
|
+
|
|
6
|
+
constructor(options: ClientOptions) {
|
|
7
|
+
this.options = options;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Makes an HTTP request to the API with retries and exponential backoff
|
|
12
|
+
* @param path - The API endpoint path
|
|
13
|
+
* @param options - Optional request configuration
|
|
14
|
+
* @returns Promise containing the response data
|
|
15
|
+
*/
|
|
16
|
+
public async request<T>(path: string, options: RequestOptions = {}): Promise<T> {
|
|
17
|
+
let lastError: Error | null = null;
|
|
18
|
+
const { baseUrl, retries = 3, backoffMs = 100, maxBackoffMs = 1000, headers = {} } = this.options;
|
|
19
|
+
|
|
20
|
+
let delay = backoffMs;
|
|
21
|
+
|
|
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) : undefined,
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
if (!response.ok) {
|
|
35
|
+
const errorBody = await response.text();
|
|
36
|
+
let errorMessage = `HTTP error! status: ${response.status}`;
|
|
37
|
+
try {
|
|
38
|
+
const errorJson = JSON.parse(errorBody);
|
|
39
|
+
errorMessage += ` - ${JSON.stringify(errorJson)}`;
|
|
40
|
+
} catch {
|
|
41
|
+
if (errorBody) {
|
|
42
|
+
errorMessage += ` - ${errorBody}`;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
throw new Error(errorMessage);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
if (options.stream) {
|
|
49
|
+
return response as unknown as T;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
const data = await response.json();
|
|
53
|
+
return data as T;
|
|
54
|
+
} catch (error) {
|
|
55
|
+
lastError = error as Error;
|
|
56
|
+
|
|
57
|
+
if (attempt === retries) {
|
|
58
|
+
break;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
await new Promise(resolve => setTimeout(resolve, delay));
|
|
62
|
+
delay = Math.min(delay * 2, maxBackoffMs);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
throw lastError || new Error('Request failed');
|
|
67
|
+
}
|
|
68
|
+
}
|
package/src/resources/index.ts
CHANGED
|
@@ -1,9 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
export
|
|
4
|
-
export
|
|
5
|
-
export
|
|
6
|
-
export
|
|
7
|
-
export { System } from './system';
|
|
8
|
-
export { Tools, type ToolExecuteParams } from './tools/tools';
|
|
9
|
-
export { Workflows, type WorkflowExecuteParams } from './workflows';
|
|
1
|
+
export * from './agent';
|
|
2
|
+
export * from './memory-thread';
|
|
3
|
+
export * from './vector';
|
|
4
|
+
export * from './workflow';
|
|
5
|
+
export * from './tool';
|
|
6
|
+
export * from './base';
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import type { StorageThreadType } from '@mastra/core';
|
|
2
|
+
import type {
|
|
3
|
+
CreateMemoryThreadParams,
|
|
4
|
+
GetMemoryThreadMessagesResponse,
|
|
5
|
+
GetMemoryThreadResponse,
|
|
6
|
+
ClientOptions,
|
|
7
|
+
SaveMessageToMemoryParams,
|
|
8
|
+
UpdateMemoryThreadParams,
|
|
9
|
+
} from '../types';
|
|
10
|
+
import { BaseResource } from './base';
|
|
11
|
+
|
|
12
|
+
export class MemoryThread extends BaseResource {
|
|
13
|
+
constructor(
|
|
14
|
+
options: ClientOptions,
|
|
15
|
+
private threadId: string
|
|
16
|
+
) {
|
|
17
|
+
super(options);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Retrieves the memory thread details
|
|
22
|
+
* @returns Promise containing thread details including title and metadata
|
|
23
|
+
*/
|
|
24
|
+
get(): Promise<StorageThreadType> {
|
|
25
|
+
return this.request(`/api/memory/threads/${this.threadId}`);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Updates the memory thread properties
|
|
30
|
+
* @param params - Update parameters including title and metadata
|
|
31
|
+
* @returns Promise containing updated thread details
|
|
32
|
+
*/
|
|
33
|
+
update(params: UpdateMemoryThreadParams): Promise<StorageThreadType> {
|
|
34
|
+
return this.request(`/api/memory/threads/${this.threadId}`, {
|
|
35
|
+
method: 'PATCH',
|
|
36
|
+
body: params,
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Deletes the memory thread
|
|
42
|
+
* @returns Promise containing deletion result
|
|
43
|
+
*/
|
|
44
|
+
delete(): Promise<{ result: string }> {
|
|
45
|
+
return this.request(`/api/memory/threads/${this.threadId}`, {
|
|
46
|
+
method: 'DELETE',
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Retrieves messages associated with the thread
|
|
52
|
+
* @returns Promise containing thread messages and UI messages
|
|
53
|
+
*/
|
|
54
|
+
getMessages(): Promise<GetMemoryThreadMessagesResponse> {
|
|
55
|
+
return this.request(`/api/memory/threads/${this.threadId}/messages`);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { GetToolResponse, ClientOptions } from '../types';
|
|
2
|
+
import { BaseResource } from './base';
|
|
3
|
+
|
|
4
|
+
export class Tool extends BaseResource {
|
|
5
|
+
constructor(
|
|
6
|
+
options: ClientOptions,
|
|
7
|
+
private toolId: string
|
|
8
|
+
) {
|
|
9
|
+
super(options);
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Retrieves details about the tool
|
|
14
|
+
* @returns Promise containing tool details including description and schemas
|
|
15
|
+
*/
|
|
16
|
+
details(): Promise<GetToolResponse> {
|
|
17
|
+
return this.request(`/api/tools/${this.toolId}`);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Executes the tool with the provided parameters
|
|
22
|
+
* @param params - Parameters required for tool execution
|
|
23
|
+
* @returns Promise containing the tool execution results
|
|
24
|
+
*/
|
|
25
|
+
execute(params: Record<string, any>): Promise<Record<string, any>> {
|
|
26
|
+
return this.request(`/api/tools/${this.toolId}/execute`, {
|
|
27
|
+
method: 'POST',
|
|
28
|
+
body: params,
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
CreateIndexParams,
|
|
3
|
+
GetVectorIndexResponse,
|
|
4
|
+
QueryVectorParams,
|
|
5
|
+
QueryVectorResponse,
|
|
6
|
+
ClientOptions,
|
|
7
|
+
UpsertVectorParams,
|
|
8
|
+
} from '../types';
|
|
9
|
+
import { BaseResource } from './base';
|
|
10
|
+
|
|
11
|
+
export class Vector extends BaseResource {
|
|
12
|
+
constructor(
|
|
13
|
+
options: ClientOptions,
|
|
14
|
+
private vectorName: string
|
|
15
|
+
) {
|
|
16
|
+
super(options);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Retrieves details about a specific vector index
|
|
21
|
+
* @param indexName - Name of the index to get details for
|
|
22
|
+
* @returns Promise containing vector index details
|
|
23
|
+
*/
|
|
24
|
+
details(indexName: string): Promise<GetVectorIndexResponse> {
|
|
25
|
+
return this.request(`/api/vector/${this.vectorName}/indexes/${indexName}`);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Deletes a vector index
|
|
30
|
+
* @param indexName - Name of the index to delete
|
|
31
|
+
* @returns Promise indicating deletion success
|
|
32
|
+
*/
|
|
33
|
+
delete(indexName: string): Promise<{ success: boolean }> {
|
|
34
|
+
return this.request(`/api/vector/${this.vectorName}/indexes/${indexName}`, {
|
|
35
|
+
method: 'DELETE'
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Retrieves a list of all available indexes
|
|
41
|
+
* @returns Promise containing array of index names
|
|
42
|
+
*/
|
|
43
|
+
getIndexes(): Promise<{ indexes: string[] }> {
|
|
44
|
+
return this.request(`/api/vector/${this.vectorName}/indexes`);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Creates a new vector index
|
|
49
|
+
* @param params - Parameters for index creation including dimension and metric
|
|
50
|
+
* @returns Promise indicating creation success
|
|
51
|
+
*/
|
|
52
|
+
createIndex(params: CreateIndexParams): Promise<{ success: boolean }> {
|
|
53
|
+
return this.request(`/api/vector/${this.vectorName}/create-index`, {
|
|
54
|
+
method: 'POST',
|
|
55
|
+
body: params
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Upserts vectors into an index
|
|
61
|
+
* @param params - Parameters containing vectors, metadata, and optional IDs
|
|
62
|
+
* @returns Promise containing array of vector IDs
|
|
63
|
+
*/
|
|
64
|
+
upsert(params: UpsertVectorParams): Promise<string[]> {
|
|
65
|
+
return this.request(`/api/vector/${this.vectorName}/upsert`, {
|
|
66
|
+
method: 'POST',
|
|
67
|
+
body: params
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Queries vectors in an index
|
|
73
|
+
* @param params - Query parameters including query vector and search options
|
|
74
|
+
* @returns Promise containing query results
|
|
75
|
+
*/
|
|
76
|
+
query(params: QueryVectorParams): Promise<QueryVectorResponse> {
|
|
77
|
+
return this.request(`/api/vector/${this.vectorName}/query`, {
|
|
78
|
+
method: 'POST',
|
|
79
|
+
body: params
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { GetWorkflowResponse, ClientOptions } from '../types';
|
|
2
|
+
import { BaseResource } from './base';
|
|
3
|
+
|
|
4
|
+
export class Workflow extends BaseResource {
|
|
5
|
+
constructor(
|
|
6
|
+
options: ClientOptions,
|
|
7
|
+
private workflowId: string
|
|
8
|
+
) {
|
|
9
|
+
super(options);
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Retrieves details about the workflow
|
|
14
|
+
* @returns Promise containing workflow details including steps and graphs
|
|
15
|
+
*/
|
|
16
|
+
details(): Promise<GetWorkflowResponse> {
|
|
17
|
+
return this.request(`/api/workflows/${this.workflowId}`);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Executes the workflow with the provided parameters
|
|
22
|
+
* @param params - Parameters required for workflow execution
|
|
23
|
+
* @returns Promise containing the workflow execution results
|
|
24
|
+
*/
|
|
25
|
+
execute(params: Record<string, any>): Promise<Record<string, any>> {
|
|
26
|
+
return this.request(`/api/workflows/${this.workflowId}/execute`, {
|
|
27
|
+
method: 'POST',
|
|
28
|
+
body: params,
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
}
|