@mastra/client-js 0.1.0-alpha.1
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/CHANGELOG.md +21 -0
- package/LICENSE +201 -0
- package/README.md +291 -0
- package/_shims/MultipartBody.d.ts +9 -0
- package/_shims/MultipartBody.d.ts.map +1 -0
- package/_shims/MultipartBody.js +16 -0
- package/_shims/MultipartBody.js.map +1 -0
- package/_shims/MultipartBody.mjs +12 -0
- package/_shims/MultipartBody.mjs.map +1 -0
- package/_shims/README.md +46 -0
- package/_shims/auto/runtime-bun.d.ts +5 -0
- package/_shims/auto/runtime-bun.d.ts.map +1 -0
- package/_shims/auto/runtime-bun.js +21 -0
- package/_shims/auto/runtime-bun.js.map +1 -0
- package/_shims/auto/runtime-bun.mjs +2 -0
- package/_shims/auto/runtime-bun.mjs.map +1 -0
- package/_shims/auto/runtime-node.d.ts +5 -0
- package/_shims/auto/runtime-node.d.ts.map +1 -0
- package/_shims/auto/runtime-node.js +21 -0
- package/_shims/auto/runtime-node.js.map +1 -0
- package/_shims/auto/runtime-node.mjs +2 -0
- package/_shims/auto/runtime-node.mjs.map +1 -0
- package/_shims/auto/runtime.d.ts +5 -0
- package/_shims/auto/runtime.d.ts.map +1 -0
- package/_shims/auto/runtime.js +21 -0
- package/_shims/auto/runtime.js.map +1 -0
- package/_shims/auto/runtime.mjs +2 -0
- package/_shims/auto/runtime.mjs.map +1 -0
- package/_shims/auto/types-node.d.ts +5 -0
- package/_shims/auto/types-node.d.ts.map +1 -0
- package/_shims/auto/types-node.js +21 -0
- package/_shims/auto/types-node.js.map +1 -0
- package/_shims/auto/types-node.mjs +2 -0
- package/_shims/auto/types-node.mjs.map +1 -0
- package/_shims/auto/types.d.ts +101 -0
- package/_shims/auto/types.js +3 -0
- package/_shims/auto/types.mjs +3 -0
- package/_shims/bun-runtime.d.ts +6 -0
- package/_shims/bun-runtime.d.ts.map +1 -0
- package/_shims/bun-runtime.js +14 -0
- package/_shims/bun-runtime.js.map +1 -0
- package/_shims/bun-runtime.mjs +10 -0
- package/_shims/bun-runtime.mjs.map +1 -0
- package/_shims/index.d.ts +81 -0
- package/_shims/index.js +13 -0
- package/_shims/index.mjs +7 -0
- package/_shims/manual-types.d.ts +12 -0
- package/_shims/manual-types.js +3 -0
- package/_shims/manual-types.mjs +3 -0
- package/_shims/node-runtime.d.ts +3 -0
- package/_shims/node-runtime.d.ts.map +1 -0
- package/_shims/node-runtime.js +89 -0
- package/_shims/node-runtime.js.map +1 -0
- package/_shims/node-runtime.mjs +56 -0
- package/_shims/node-runtime.mjs.map +1 -0
- package/_shims/node-types.d.ts +42 -0
- package/_shims/node-types.js +3 -0
- package/_shims/node-types.mjs +3 -0
- package/_shims/registry.d.ts +37 -0
- package/_shims/registry.d.ts.map +1 -0
- package/_shims/registry.js +41 -0
- package/_shims/registry.js.map +1 -0
- package/_shims/registry.mjs +37 -0
- package/_shims/registry.mjs.map +1 -0
- package/_shims/web-runtime.d.ts +5 -0
- package/_shims/web-runtime.d.ts.map +1 -0
- package/_shims/web-runtime.js +78 -0
- package/_shims/web-runtime.js.map +1 -0
- package/_shims/web-runtime.mjs +71 -0
- package/_shims/web-runtime.mjs.map +1 -0
- package/_shims/web-types.d.ts +83 -0
- package/_shims/web-types.js +3 -0
- package/_shims/web-types.mjs +3 -0
- package/core.d.ts +241 -0
- package/core.d.ts.map +1 -0
- package/core.js +908 -0
- package/core.js.map +1 -0
- package/core.mjs +876 -0
- package/core.mjs.map +1 -0
- package/error.d.ts +47 -0
- package/error.d.ts.map +1 -0
- package/error.js +113 -0
- package/error.js.map +1 -0
- package/error.mjs +97 -0
- package/error.mjs.map +1 -0
- package/index.d.mts +121 -0
- package/index.d.ts +121 -0
- package/index.d.ts.map +1 -0
- package/index.js +131 -0
- package/index.js.map +1 -0
- package/index.mjs +88 -0
- package/index.mjs.map +1 -0
- package/package.json +103 -0
- package/resource.d.ts +6 -0
- package/resource.d.ts.map +1 -0
- package/resource.js +11 -0
- package/resource.js.map +1 -0
- package/resource.mjs +7 -0
- package/resource.mjs.map +1 -0
- package/resources/agents/agents.d.ts +40 -0
- package/resources/agents/agents.d.ts.map +1 -0
- package/resources/agents/agents.js +74 -0
- package/resources/agents/agents.js.map +1 -0
- package/resources/agents/agents.mjs +47 -0
- package/resources/agents/agents.mjs.map +1 -0
- package/resources/agents/index.d.ts +3 -0
- package/resources/agents/index.d.ts.map +1 -0
- package/resources/agents/index.js +9 -0
- package/resources/agents/index.js.map +1 -0
- package/resources/agents/index.mjs +4 -0
- package/resources/agents/index.mjs.map +1 -0
- package/resources/agents/tools.d.ts +17 -0
- package/resources/agents/tools.d.ts.map +1 -0
- package/resources/agents/tools.js +19 -0
- package/resources/agents/tools.js.map +1 -0
- package/resources/agents/tools.mjs +15 -0
- package/resources/agents/tools.mjs.map +1 -0
- package/resources/index.d.ts +8 -0
- package/resources/index.d.ts.map +1 -0
- package/resources/index.js +19 -0
- package/resources/index.js.map +1 -0
- package/resources/index.mjs +9 -0
- package/resources/index.mjs.map +1 -0
- package/resources/logs.d.ts +13 -0
- package/resources/logs.d.ts.map +1 -0
- package/resources/logs.js +24 -0
- package/resources/logs.js.map +1 -0
- package/resources/logs.mjs +20 -0
- package/resources/logs.mjs.map +1 -0
- package/resources/memory/index.d.ts +4 -0
- package/resources/memory/index.d.ts.map +1 -0
- package/resources/memory/index.js +11 -0
- package/resources/memory/index.js.map +1 -0
- package/resources/memory/index.mjs +5 -0
- package/resources/memory/index.mjs.map +1 -0
- package/resources/memory/memory.d.ts +23 -0
- package/resources/memory/memory.d.ts.map +1 -0
- package/resources/memory/memory.js +53 -0
- package/resources/memory/memory.js.map +1 -0
- package/resources/memory/memory.mjs +26 -0
- package/resources/memory/memory.mjs.map +1 -0
- package/resources/memory/status.d.ts +9 -0
- package/resources/memory/status.d.ts.map +1 -0
- package/resources/memory/status.js +18 -0
- package/resources/memory/status.js.map +1 -0
- package/resources/memory/status.mjs +14 -0
- package/resources/memory/status.mjs.map +1 -0
- package/resources/memory/threads/index.d.ts +3 -0
- package/resources/memory/threads/index.d.ts.map +1 -0
- package/resources/memory/threads/index.js +9 -0
- package/resources/memory/threads/index.js.map +1 -0
- package/resources/memory/threads/index.mjs +4 -0
- package/resources/memory/threads/index.mjs.map +1 -0
- package/resources/memory/threads/messages.d.ts +9 -0
- package/resources/memory/threads/messages.d.ts.map +1 -0
- package/resources/memory/threads/messages.js +18 -0
- package/resources/memory/threads/messages.js.map +1 -0
- package/resources/memory/threads/messages.mjs +14 -0
- package/resources/memory/threads/messages.mjs.map +1 -0
- package/resources/memory/threads/threads.d.ts +45 -0
- package/resources/memory/threads/threads.d.ts.map +1 -0
- package/resources/memory/threads/threads.js +104 -0
- package/resources/memory/threads/threads.js.map +1 -0
- package/resources/memory/threads/threads.mjs +77 -0
- package/resources/memory/threads/threads.mjs.map +1 -0
- package/resources/syncs.d.ts +15 -0
- package/resources/syncs.d.ts.map +1 -0
- package/resources/syncs.js +19 -0
- package/resources/syncs.js.map +1 -0
- package/resources/syncs.mjs +15 -0
- package/resources/syncs.mjs.map +1 -0
- package/resources/system.d.ts +9 -0
- package/resources/system.d.ts.map +1 -0
- package/resources/system.js +15 -0
- package/resources/system.js.map +1 -0
- package/resources/system.mjs +11 -0
- package/resources/system.mjs.map +1 -0
- package/resources/tools/index.d.ts +3 -0
- package/resources/tools/index.d.ts.map +1 -0
- package/resources/tools/index.js +9 -0
- package/resources/tools/index.js.map +1 -0
- package/resources/tools/index.mjs +4 -0
- package/resources/tools/index.mjs.map +1 -0
- package/resources/tools/result.d.ts +9 -0
- package/resources/tools/result.d.ts.map +1 -0
- package/resources/tools/result.js +18 -0
- package/resources/tools/result.js.map +1 -0
- package/resources/tools/result.mjs +14 -0
- package/resources/tools/result.mjs.map +1 -0
- package/resources/tools/tools.d.ts +29 -0
- package/resources/tools/tools.d.ts.map +1 -0
- package/resources/tools/tools.js +64 -0
- package/resources/tools/tools.js.map +1 -0
- package/resources/tools/tools.mjs +37 -0
- package/resources/tools/tools.mjs.map +1 -0
- package/resources/workflows.d.ts +23 -0
- package/resources/workflows.d.ts.map +1 -0
- package/resources/workflows.js +37 -0
- package/resources/workflows.js.map +1 -0
- package/resources/workflows.mjs +33 -0
- package/resources/workflows.mjs.map +1 -0
- package/shims/node.d.ts +30 -0
- package/shims/node.d.ts.map +1 -0
- package/shims/node.js +31 -0
- package/shims/node.js.map +1 -0
- package/shims/node.mjs +5 -0
- package/shims/node.mjs.map +1 -0
- package/shims/web.d.ts +26 -0
- package/shims/web.d.ts.map +1 -0
- package/shims/web.js +31 -0
- package/shims/web.js.map +1 -0
- package/shims/web.mjs +5 -0
- package/shims/web.mjs.map +1 -0
- package/src/_shims/MultipartBody.ts +9 -0
- package/src/_shims/README.md +46 -0
- package/src/_shims/auto/runtime-bun.ts +4 -0
- package/src/_shims/auto/runtime-node.ts +4 -0
- package/src/_shims/auto/runtime.ts +4 -0
- package/src/_shims/auto/types-node.ts +4 -0
- package/src/_shims/auto/types.d.ts +101 -0
- package/src/_shims/auto/types.js +3 -0
- package/src/_shims/auto/types.mjs +3 -0
- package/src/_shims/bun-runtime.ts +14 -0
- package/src/_shims/index.d.ts +81 -0
- package/src/_shims/index.js +13 -0
- package/src/_shims/index.mjs +7 -0
- package/src/_shims/manual-types.d.ts +12 -0
- package/src/_shims/manual-types.js +3 -0
- package/src/_shims/manual-types.mjs +3 -0
- package/src/_shims/node-runtime.ts +81 -0
- package/src/_shims/node-types.d.ts +42 -0
- package/src/_shims/node-types.js +3 -0
- package/src/_shims/node-types.mjs +3 -0
- package/src/_shims/registry.ts +67 -0
- package/src/_shims/web-runtime.ts +103 -0
- package/src/_shims/web-types.d.ts +83 -0
- package/src/_shims/web-types.js +3 -0
- package/src/_shims/web-types.mjs +3 -0
- package/src/core.ts +1201 -0
- package/src/error.ts +130 -0
- package/src/index.ts +194 -0
- package/src/lib/.keep +4 -0
- package/src/resource.ts +11 -0
- package/src/resources/agents/agents.ts +77 -0
- package/src/resources/agents/index.ts +4 -0
- package/src/resources/agents/tools.ts +34 -0
- package/src/resources/index.ts +9 -0
- package/src/resources/logs.ts +23 -0
- package/src/resources/memory/index.ts +5 -0
- package/src/resources/memory/memory.ts +43 -0
- package/src/resources/memory/status.ts +16 -0
- package/src/resources/memory/threads/index.ts +4 -0
- package/src/resources/memory/threads/messages.ts +16 -0
- package/src/resources/memory/threads/threads.ts +105 -0
- package/src/resources/syncs.ts +25 -0
- package/src/resources/system.ts +13 -0
- package/src/resources/tools/index.ts +4 -0
- package/src/resources/tools/result.ts +16 -0
- package/src/resources/tools/tools.ts +54 -0
- package/src/resources/workflows.ts +49 -0
- package/src/shims/node.ts +50 -0
- package/src/shims/web.ts +50 -0
- package/src/tsconfig.json +11 -0
- package/src/uploads.ts +255 -0
- package/src/version.ts +1 -0
- package/uploads.d.ts +75 -0
- package/uploads.d.ts.map +1 -0
- package/uploads.js +171 -0
- package/uploads.js.map +1 -0
- package/uploads.mjs +158 -0
- package/uploads.mjs.map +1 -0
- package/version.d.ts +2 -0
- package/version.d.ts.map +1 -0
- package/version.js +5 -0
- package/version.js.map +1 -0
- package/version.mjs +2 -0
- package/version.mjs.map +1 -0
package/src/error.ts
ADDED
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
|
2
|
+
|
|
3
|
+
import { castToError, Headers } from './core';
|
|
4
|
+
|
|
5
|
+
export class MastraClientError extends Error {}
|
|
6
|
+
|
|
7
|
+
export class APIError<
|
|
8
|
+
TStatus extends number | undefined = number | undefined,
|
|
9
|
+
THeaders extends Headers | undefined = Headers | undefined,
|
|
10
|
+
TError extends Object | undefined = Object | undefined,
|
|
11
|
+
> extends MastraClientError {
|
|
12
|
+
/** HTTP status for the response that caused the error */
|
|
13
|
+
readonly status: TStatus;
|
|
14
|
+
/** HTTP headers for the response that caused the error */
|
|
15
|
+
readonly headers: THeaders;
|
|
16
|
+
/** JSON body of the response that caused the error */
|
|
17
|
+
readonly error: TError;
|
|
18
|
+
|
|
19
|
+
constructor(status: TStatus, error: TError, message: string | undefined, headers: THeaders) {
|
|
20
|
+
super(`${APIError.makeMessage(status, error, message)}`);
|
|
21
|
+
this.status = status;
|
|
22
|
+
this.headers = headers;
|
|
23
|
+
this.error = error;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
private static makeMessage(status: number | undefined, error: any, message: string | undefined) {
|
|
27
|
+
const msg =
|
|
28
|
+
error?.message ?
|
|
29
|
+
typeof error.message === 'string' ?
|
|
30
|
+
error.message
|
|
31
|
+
: JSON.stringify(error.message)
|
|
32
|
+
: error ? JSON.stringify(error)
|
|
33
|
+
: message;
|
|
34
|
+
|
|
35
|
+
if (status && msg) {
|
|
36
|
+
return `${status} ${msg}`;
|
|
37
|
+
}
|
|
38
|
+
if (status) {
|
|
39
|
+
return `${status} status code (no body)`;
|
|
40
|
+
}
|
|
41
|
+
if (msg) {
|
|
42
|
+
return msg;
|
|
43
|
+
}
|
|
44
|
+
return '(no status code or body)';
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
static generate(
|
|
48
|
+
status: number | undefined,
|
|
49
|
+
errorResponse: Object | undefined,
|
|
50
|
+
message: string | undefined,
|
|
51
|
+
headers: Headers | undefined,
|
|
52
|
+
): APIError {
|
|
53
|
+
if (!status || !headers) {
|
|
54
|
+
return new APIConnectionError({ message, cause: castToError(errorResponse) });
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
const error = errorResponse as Record<string, any>;
|
|
58
|
+
|
|
59
|
+
if (status === 400) {
|
|
60
|
+
return new BadRequestError(status, error, message, headers);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
if (status === 401) {
|
|
64
|
+
return new AuthenticationError(status, error, message, headers);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
if (status === 403) {
|
|
68
|
+
return new PermissionDeniedError(status, error, message, headers);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
if (status === 404) {
|
|
72
|
+
return new NotFoundError(status, error, message, headers);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
if (status === 409) {
|
|
76
|
+
return new ConflictError(status, error, message, headers);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
if (status === 422) {
|
|
80
|
+
return new UnprocessableEntityError(status, error, message, headers);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
if (status === 429) {
|
|
84
|
+
return new RateLimitError(status, error, message, headers);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
if (status >= 500) {
|
|
88
|
+
return new InternalServerError(status, error, message, headers);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
return new APIError(status, error, message, headers);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
export class APIUserAbortError extends APIError<undefined, undefined, undefined> {
|
|
96
|
+
constructor({ message }: { message?: string } = {}) {
|
|
97
|
+
super(undefined, undefined, message || 'Request was aborted.', undefined);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
export class APIConnectionError extends APIError<undefined, undefined, undefined> {
|
|
102
|
+
constructor({ message, cause }: { message?: string | undefined; cause?: Error | undefined }) {
|
|
103
|
+
super(undefined, undefined, message || 'Connection error.', undefined);
|
|
104
|
+
// in some environments the 'cause' property is already declared
|
|
105
|
+
// @ts-ignore
|
|
106
|
+
if (cause) this.cause = cause;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
export class APIConnectionTimeoutError extends APIConnectionError {
|
|
111
|
+
constructor({ message }: { message?: string } = {}) {
|
|
112
|
+
super({ message: message ?? 'Request timed out.' });
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
export class BadRequestError extends APIError<400, Headers> {}
|
|
117
|
+
|
|
118
|
+
export class AuthenticationError extends APIError<401, Headers> {}
|
|
119
|
+
|
|
120
|
+
export class PermissionDeniedError extends APIError<403, Headers> {}
|
|
121
|
+
|
|
122
|
+
export class NotFoundError extends APIError<404, Headers> {}
|
|
123
|
+
|
|
124
|
+
export class ConflictError extends APIError<409, Headers> {}
|
|
125
|
+
|
|
126
|
+
export class UnprocessableEntityError extends APIError<422, Headers> {}
|
|
127
|
+
|
|
128
|
+
export class RateLimitError extends APIError<429, Headers> {}
|
|
129
|
+
|
|
130
|
+
export class InternalServerError extends APIError<number, Headers> {}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
|
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;
|
package/src/lib/.keep
ADDED
package/src/resource.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
|
2
|
+
|
|
3
|
+
import type { MastraClient } from './index';
|
|
4
|
+
|
|
5
|
+
export class APIResource {
|
|
6
|
+
protected _client: MastraClient;
|
|
7
|
+
|
|
8
|
+
constructor(client: MastraClient) {
|
|
9
|
+
this._client = client;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
|
2
|
+
|
|
3
|
+
import { APIResource } from '../../resource';
|
|
4
|
+
import * as Core from '../../core';
|
|
5
|
+
import * as ToolsAPI from './tools';
|
|
6
|
+
import { ToolExecuteParams, Tools } from './tools';
|
|
7
|
+
|
|
8
|
+
export class Agents extends APIResource {
|
|
9
|
+
tools: ToolsAPI.Tools = new ToolsAPI.Tools(this._client);
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Get agent by ID
|
|
13
|
+
*/
|
|
14
|
+
retrieve(agentId: string, options?: Core.RequestOptions): Core.APIPromise<void> {
|
|
15
|
+
return this._client.get(`/api/agents/${agentId}`, {
|
|
16
|
+
...options,
|
|
17
|
+
headers: { Accept: '*/*', ...options?.headers },
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Get all available agents
|
|
23
|
+
*/
|
|
24
|
+
list(options?: Core.RequestOptions): Core.APIPromise<void> {
|
|
25
|
+
return this._client.get('/api/agents', { ...options, headers: { Accept: '*/*', ...options?.headers } });
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Generate a response from an agent
|
|
30
|
+
*/
|
|
31
|
+
generate(agentId: string, body: AgentGenerateParams, options?: Core.RequestOptions): Core.APIPromise<void> {
|
|
32
|
+
return this._client.post(`/api/agents/${agentId}/generate`, {
|
|
33
|
+
body,
|
|
34
|
+
...options,
|
|
35
|
+
headers: { Accept: '*/*', ...options?.headers },
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Stream a response from an agent
|
|
41
|
+
*/
|
|
42
|
+
stream(agentId: string, body: AgentStreamParams, options?: Core.RequestOptions): Core.APIPromise<void> {
|
|
43
|
+
return this._client.post(`/api/agents/${agentId}/stream`, {
|
|
44
|
+
body,
|
|
45
|
+
...options,
|
|
46
|
+
headers: { Accept: '*/*', ...options?.headers },
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export interface AgentGenerateParams {
|
|
52
|
+
messages: Array<unknown>;
|
|
53
|
+
|
|
54
|
+
output?: unknown;
|
|
55
|
+
|
|
56
|
+
resourceid?: string;
|
|
57
|
+
|
|
58
|
+
threadId?: string;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export interface AgentStreamParams {
|
|
62
|
+
messages: Array<unknown>;
|
|
63
|
+
|
|
64
|
+
output?: unknown;
|
|
65
|
+
|
|
66
|
+
resourceid?: string;
|
|
67
|
+
|
|
68
|
+
threadId?: string;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
Agents.Tools = Tools;
|
|
72
|
+
|
|
73
|
+
export declare namespace Agents {
|
|
74
|
+
export { type AgentGenerateParams as AgentGenerateParams, type AgentStreamParams as AgentStreamParams };
|
|
75
|
+
|
|
76
|
+
export { Tools as Tools, type ToolExecuteParams as ToolExecuteParams };
|
|
77
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
|
2
|
+
|
|
3
|
+
import { APIResource } from '../../resource';
|
|
4
|
+
import * as Core from '../../core';
|
|
5
|
+
|
|
6
|
+
export class Tools extends APIResource {
|
|
7
|
+
/**
|
|
8
|
+
* Execute a tool through an agent
|
|
9
|
+
*/
|
|
10
|
+
execute(
|
|
11
|
+
agentId: string,
|
|
12
|
+
toolId: string,
|
|
13
|
+
body: ToolExecuteParams,
|
|
14
|
+
options?: Core.RequestOptions,
|
|
15
|
+
): Core.APIPromise<void> {
|
|
16
|
+
return this._client.post(`/api/agents/${agentId}/tools/${toolId}/execute`, {
|
|
17
|
+
body,
|
|
18
|
+
...options,
|
|
19
|
+
headers: { Accept: '*/*', ...options?.headers },
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export interface ToolExecuteParams {
|
|
25
|
+
args: unknown;
|
|
26
|
+
|
|
27
|
+
resourceid?: string;
|
|
28
|
+
|
|
29
|
+
threadId?: string;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export declare namespace Tools {
|
|
33
|
+
export { type ToolExecuteParams as ToolExecuteParams };
|
|
34
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
|
2
|
+
|
|
3
|
+
export { Agents, type AgentGenerateParams, type AgentStreamParams } from './agents/agents';
|
|
4
|
+
export { Logs } from './logs';
|
|
5
|
+
export { Memory, type MemorySaveMessagesParams } from './memory/memory';
|
|
6
|
+
export { Syncs, type SyncExecuteParams } from './syncs';
|
|
7
|
+
export { System } from './system';
|
|
8
|
+
export { Tools, type ToolExecuteParams } from './tools/tools';
|
|
9
|
+
export { Workflows, type WorkflowExecuteParams } from './workflows';
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
|
2
|
+
|
|
3
|
+
import { APIResource } from '../resource';
|
|
4
|
+
import * as Core from '../core';
|
|
5
|
+
|
|
6
|
+
export class Logs extends APIResource {
|
|
7
|
+
/**
|
|
8
|
+
* Get logs by run ID
|
|
9
|
+
*/
|
|
10
|
+
retrieve(runId: string, options?: Core.RequestOptions): Core.APIPromise<void> {
|
|
11
|
+
return this._client.get(`/api/logs/${runId}`, {
|
|
12
|
+
...options,
|
|
13
|
+
headers: { Accept: '*/*', ...options?.headers },
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Get all logs
|
|
19
|
+
*/
|
|
20
|
+
list(options?: Core.RequestOptions): Core.APIPromise<void> {
|
|
21
|
+
return this._client.get('/api/logs', { ...options, headers: { Accept: '*/*', ...options?.headers } });
|
|
22
|
+
}
|
|
23
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
|
2
|
+
|
|
3
|
+
export { Memory, type MemorySaveMessagesParams } from './memory';
|
|
4
|
+
export { Status } from './status';
|
|
5
|
+
export { Threads, type ThreadUpdateParams, type ThreadToolResultParams } from './threads/index';
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
|
2
|
+
|
|
3
|
+
import { APIResource } from '../../resource';
|
|
4
|
+
import * as Core from '../../core';
|
|
5
|
+
import * as StatusAPI from './status';
|
|
6
|
+
import { Status } from './status';
|
|
7
|
+
import * as ThreadsAPI from './threads/threads';
|
|
8
|
+
import { ThreadToolResultParams, ThreadUpdateParams, Threads } from './threads/threads';
|
|
9
|
+
|
|
10
|
+
export class Memory extends APIResource {
|
|
11
|
+
status: StatusAPI.Status = new StatusAPI.Status(this._client);
|
|
12
|
+
threads: ThreadsAPI.Threads = new ThreadsAPI.Threads(this._client);
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Save messages
|
|
16
|
+
*/
|
|
17
|
+
saveMessages(body: MemorySaveMessagesParams, options?: Core.RequestOptions): Core.APIPromise<void> {
|
|
18
|
+
return this._client.post('/api/memory/save-messages', {
|
|
19
|
+
body,
|
|
20
|
+
...options,
|
|
21
|
+
headers: { Accept: '*/*', ...options?.headers },
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export interface MemorySaveMessagesParams {
|
|
27
|
+
messages: Array<unknown>;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
Memory.Status = Status;
|
|
31
|
+
Memory.Threads = Threads;
|
|
32
|
+
|
|
33
|
+
export declare namespace Memory {
|
|
34
|
+
export { type MemorySaveMessagesParams as MemorySaveMessagesParams };
|
|
35
|
+
|
|
36
|
+
export { Status as Status };
|
|
37
|
+
|
|
38
|
+
export {
|
|
39
|
+
Threads as Threads,
|
|
40
|
+
type ThreadUpdateParams as ThreadUpdateParams,
|
|
41
|
+
type ThreadToolResultParams as ThreadToolResultParams,
|
|
42
|
+
};
|
|
43
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
|
2
|
+
|
|
3
|
+
import { APIResource } from '../../resource';
|
|
4
|
+
import * as Core from '../../core';
|
|
5
|
+
|
|
6
|
+
export class Status extends APIResource {
|
|
7
|
+
/**
|
|
8
|
+
* Get memory status
|
|
9
|
+
*/
|
|
10
|
+
retrieve(options?: Core.RequestOptions): Core.APIPromise<void> {
|
|
11
|
+
return this._client.get('/api/memory/status', {
|
|
12
|
+
...options,
|
|
13
|
+
headers: { Accept: '*/*', ...options?.headers },
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
|
2
|
+
|
|
3
|
+
import { APIResource } from '../../../resource';
|
|
4
|
+
import * as Core from '../../../core';
|
|
5
|
+
|
|
6
|
+
export class Messages extends APIResource {
|
|
7
|
+
/**
|
|
8
|
+
* Get messages for a thread
|
|
9
|
+
*/
|
|
10
|
+
list(threadId: string, options?: Core.RequestOptions): Core.APIPromise<void> {
|
|
11
|
+
return this._client.get(`/api/memory/threads/${threadId}/messages`, {
|
|
12
|
+
...options,
|
|
13
|
+
headers: { Accept: '*/*', ...options?.headers },
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
}
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
|
2
|
+
|
|
3
|
+
import { APIResource } from '../../../resource';
|
|
4
|
+
import * as Core from '../../../core';
|
|
5
|
+
import * as MessagesAPI from './messages';
|
|
6
|
+
import { Messages } from './messages';
|
|
7
|
+
|
|
8
|
+
export class Threads extends APIResource {
|
|
9
|
+
messages: MessagesAPI.Messages = new MessagesAPI.Messages(this._client);
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Create a new thread
|
|
13
|
+
*/
|
|
14
|
+
create(options?: Core.RequestOptions): Core.APIPromise<void> {
|
|
15
|
+
return this._client.post('/api/memory/threads', {
|
|
16
|
+
...options,
|
|
17
|
+
headers: { Accept: '*/*', ...options?.headers },
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Get thread by ID
|
|
23
|
+
*/
|
|
24
|
+
retrieve(threadId: string, options?: Core.RequestOptions): Core.APIPromise<void> {
|
|
25
|
+
return this._client.get(`/api/memory/threads/${threadId}`, {
|
|
26
|
+
...options,
|
|
27
|
+
headers: { Accept: '*/*', ...options?.headers },
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Update a thread
|
|
33
|
+
*/
|
|
34
|
+
update(threadId: string, body: ThreadUpdateParams, options?: Core.RequestOptions): Core.APIPromise<void> {
|
|
35
|
+
return this._client.patch(`/api/memory/threads/${threadId}`, {
|
|
36
|
+
body,
|
|
37
|
+
...options,
|
|
38
|
+
headers: { Accept: '*/*', ...options?.headers },
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Get all threads
|
|
44
|
+
*/
|
|
45
|
+
list(options?: Core.RequestOptions): Core.APIPromise<void> {
|
|
46
|
+
return this._client.get('/api/memory/threads', {
|
|
47
|
+
...options,
|
|
48
|
+
headers: { Accept: '*/*', ...options?.headers },
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Delete a thread
|
|
54
|
+
*/
|
|
55
|
+
delete(threadId: string, options?: Core.RequestOptions): Core.APIPromise<void> {
|
|
56
|
+
return this._client.delete(`/api/memory/threads/${threadId}`, {
|
|
57
|
+
...options,
|
|
58
|
+
headers: { Accept: '*/*', ...options?.headers },
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Get context window for a thread
|
|
64
|
+
*/
|
|
65
|
+
contextWindow(threadId: string, options?: Core.RequestOptions): Core.APIPromise<void> {
|
|
66
|
+
return this._client.get(`/api/memory/threads/${threadId}/context-window`, {
|
|
67
|
+
...options,
|
|
68
|
+
headers: { Accept: '*/*', ...options?.headers },
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Get tool execution result for a thread
|
|
74
|
+
*/
|
|
75
|
+
toolResult(
|
|
76
|
+
threadId: string,
|
|
77
|
+
body: ThreadToolResultParams,
|
|
78
|
+
options?: Core.RequestOptions,
|
|
79
|
+
): Core.APIPromise<void> {
|
|
80
|
+
return this._client.post(`/api/memory/threads/${threadId}/tool-result`, {
|
|
81
|
+
body,
|
|
82
|
+
...options,
|
|
83
|
+
headers: { Accept: '*/*', ...options?.headers },
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
export type ThreadUpdateParams = unknown;
|
|
89
|
+
|
|
90
|
+
export interface ThreadToolResultParams {
|
|
91
|
+
resultId: string;
|
|
92
|
+
|
|
93
|
+
toolId: string;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
Threads.Messages = Messages;
|
|
97
|
+
|
|
98
|
+
export declare namespace Threads {
|
|
99
|
+
export {
|
|
100
|
+
type ThreadUpdateParams as ThreadUpdateParams,
|
|
101
|
+
type ThreadToolResultParams as ThreadToolResultParams,
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
export { Messages as Messages };
|
|
105
|
+
}
|