@mastra/s3 0.0.0
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/LICENSE.md +15 -0
- package/README.md +72 -0
- package/dist/filesystem/index.d.ts +141 -0
- package/dist/filesystem/index.d.ts.map +1 -0
- package/dist/index.cjs +586 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +584 -0
- package/dist/index.js.map +1 -0
- package/package.json +70 -0
package/LICENSE.md
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# Apache License 2.0
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Kepler Software, Inc.
|
|
4
|
+
|
|
5
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
you may not use this file except in compliance with the License.
|
|
7
|
+
You may obtain a copy of the License at
|
|
8
|
+
|
|
9
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
|
|
11
|
+
Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
See the License for the specific language governing permissions and
|
|
15
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
# @mastra/s3
|
|
2
|
+
|
|
3
|
+
S3-compatible filesystem provider for Mastra workspaces. Works with AWS S3, Cloudflare R2, MinIO, DigitalOcean Spaces, and other S3-compatible storage services.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @mastra/s3
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
```typescript
|
|
14
|
+
import { Agent } from '@mastra/core/agent';
|
|
15
|
+
import { Workspace } from '@mastra/core/workspace';
|
|
16
|
+
import { S3Filesystem } from '@mastra/s3';
|
|
17
|
+
|
|
18
|
+
const workspace = new Workspace({
|
|
19
|
+
filesystem: new S3Filesystem({
|
|
20
|
+
bucket: 'my-bucket',
|
|
21
|
+
region: 'us-east-1',
|
|
22
|
+
accessKeyId: process.env.AWS_ACCESS_KEY_ID,
|
|
23
|
+
secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY,
|
|
24
|
+
}),
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
const agent = new Agent({
|
|
28
|
+
name: 'my-agent',
|
|
29
|
+
model: 'anthropic/claude-opus-4-5',
|
|
30
|
+
workspace,
|
|
31
|
+
});
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
### Cloudflare R2
|
|
35
|
+
|
|
36
|
+
```typescript
|
|
37
|
+
const workspace = new Workspace({
|
|
38
|
+
filesystem: new S3Filesystem({
|
|
39
|
+
bucket: 'my-r2-bucket',
|
|
40
|
+
region: 'auto',
|
|
41
|
+
endpoint: `https://${process.env.R2_ACCOUNT_ID}.r2.cloudflarestorage.com`,
|
|
42
|
+
accessKeyId: process.env.R2_ACCESS_KEY_ID,
|
|
43
|
+
secretAccessKey: process.env.R2_SECRET_ACCESS_KEY,
|
|
44
|
+
}),
|
|
45
|
+
});
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
### With E2B Sandbox
|
|
49
|
+
|
|
50
|
+
When used with `@mastra/e2b`, S3 filesystems can be mounted into E2B sandboxes via s3fs-fuse:
|
|
51
|
+
|
|
52
|
+
```typescript
|
|
53
|
+
import { Workspace } from '@mastra/core/workspace';
|
|
54
|
+
import { S3Filesystem } from '@mastra/s3';
|
|
55
|
+
import { E2BSandbox } from '@mastra/e2b';
|
|
56
|
+
|
|
57
|
+
const workspace = new Workspace({
|
|
58
|
+
mounts: {
|
|
59
|
+
'/my-bucket': new S3Filesystem({
|
|
60
|
+
bucket: 'my-bucket',
|
|
61
|
+
region: 'us-east-1',
|
|
62
|
+
accessKeyId: process.env.AWS_ACCESS_KEY_ID,
|
|
63
|
+
secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY,
|
|
64
|
+
}),
|
|
65
|
+
},
|
|
66
|
+
sandbox: new E2BSandbox(),
|
|
67
|
+
});
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
## Documentation
|
|
71
|
+
|
|
72
|
+
For more information, see the [Mastra Workspaces documentation](https://mastra.ai/docs/workspace/overview).
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
import type { FileContent, FileStat, FileEntry, ReadOptions, WriteOptions, ListOptions, RemoveOptions, CopyOptions, FilesystemMountConfig, FilesystemIcon, FilesystemInfo, ProviderStatus } from '@mastra/core/workspace';
|
|
2
|
+
import { MastraFilesystem } from '@mastra/core/workspace';
|
|
3
|
+
/**
|
|
4
|
+
* S3 mount configuration.
|
|
5
|
+
* Returned by S3Filesystem.getMountConfig() for FUSE mounting in sandboxes.
|
|
6
|
+
*/
|
|
7
|
+
export interface S3MountConfig extends FilesystemMountConfig {
|
|
8
|
+
type: 's3';
|
|
9
|
+
/** S3 bucket name */
|
|
10
|
+
bucket: string;
|
|
11
|
+
/** AWS region (use 'auto' for R2) */
|
|
12
|
+
region?: string;
|
|
13
|
+
/** Optional endpoint for S3-compatible storage (MinIO, R2, etc.) */
|
|
14
|
+
endpoint?: string;
|
|
15
|
+
/** AWS access key ID */
|
|
16
|
+
accessKeyId?: string;
|
|
17
|
+
/** AWS secret access key */
|
|
18
|
+
secretAccessKey?: string;
|
|
19
|
+
/** Mount as read-only */
|
|
20
|
+
readOnly?: boolean;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* S3 filesystem provider configuration.
|
|
24
|
+
*/
|
|
25
|
+
export interface S3FilesystemOptions {
|
|
26
|
+
/** Unique identifier for this filesystem instance */
|
|
27
|
+
id?: string;
|
|
28
|
+
/** S3 bucket name */
|
|
29
|
+
bucket: string;
|
|
30
|
+
/** Human-friendly display name for the UI */
|
|
31
|
+
displayName?: string;
|
|
32
|
+
/** Icon identifier for the UI (defaults to 's3') */
|
|
33
|
+
icon?: FilesystemIcon;
|
|
34
|
+
/** Description shown in tooltips */
|
|
35
|
+
description?: string;
|
|
36
|
+
/** AWS region (use 'auto' for R2) */
|
|
37
|
+
region: string;
|
|
38
|
+
/**
|
|
39
|
+
* AWS access key ID.
|
|
40
|
+
* Optional - omit for public buckets (read-only access).
|
|
41
|
+
*/
|
|
42
|
+
accessKeyId?: string;
|
|
43
|
+
/**
|
|
44
|
+
* AWS secret access key.
|
|
45
|
+
* Optional - omit for public buckets (read-only access).
|
|
46
|
+
*/
|
|
47
|
+
secretAccessKey?: string;
|
|
48
|
+
/**
|
|
49
|
+
* Custom endpoint URL for S3-compatible storage.
|
|
50
|
+
* Examples:
|
|
51
|
+
* - Cloudflare R2: 'https://{accountId}.r2.cloudflarestorage.com'
|
|
52
|
+
* - MinIO: 'http://localhost:9000'
|
|
53
|
+
* - DigitalOcean Spaces: 'https://{region}.digitaloceanspaces.com'
|
|
54
|
+
*/
|
|
55
|
+
endpoint?: string;
|
|
56
|
+
/** Force path-style URLs (required for some S3-compatible services) */
|
|
57
|
+
forcePathStyle?: boolean;
|
|
58
|
+
/** Optional prefix for all keys (acts like a subdirectory) */
|
|
59
|
+
prefix?: string;
|
|
60
|
+
/** Mount as read-only (blocks write operations, mounts read-only in sandboxes) */
|
|
61
|
+
readOnly?: boolean;
|
|
62
|
+
}
|
|
63
|
+
export declare class S3Filesystem extends MastraFilesystem {
|
|
64
|
+
readonly id: string;
|
|
65
|
+
readonly name = "S3Filesystem";
|
|
66
|
+
readonly provider = "s3";
|
|
67
|
+
readonly readOnly?: boolean;
|
|
68
|
+
status: ProviderStatus;
|
|
69
|
+
readonly displayName?: string;
|
|
70
|
+
readonly icon: FilesystemIcon;
|
|
71
|
+
readonly description?: string;
|
|
72
|
+
private readonly bucket;
|
|
73
|
+
private readonly region;
|
|
74
|
+
private readonly accessKeyId?;
|
|
75
|
+
private readonly secretAccessKey?;
|
|
76
|
+
private readonly endpoint?;
|
|
77
|
+
private readonly forcePathStyle;
|
|
78
|
+
private readonly prefix;
|
|
79
|
+
private _client;
|
|
80
|
+
constructor(options: S3FilesystemOptions);
|
|
81
|
+
/**
|
|
82
|
+
* Get mount configuration for E2B sandbox.
|
|
83
|
+
* Returns S3-compatible config that works with s3fs-fuse.
|
|
84
|
+
*/
|
|
85
|
+
getMountConfig(): S3MountConfig;
|
|
86
|
+
/**
|
|
87
|
+
* Get filesystem info for status reporting.
|
|
88
|
+
*/
|
|
89
|
+
getInfo(): FilesystemInfo;
|
|
90
|
+
/**
|
|
91
|
+
* Handle an error, checking for access denied and updating status accordingly.
|
|
92
|
+
* Returns the error for re-throwing.
|
|
93
|
+
*/
|
|
94
|
+
private handleError;
|
|
95
|
+
/**
|
|
96
|
+
* Get instructions describing this S3 filesystem.
|
|
97
|
+
* Used by agents to understand storage semantics.
|
|
98
|
+
*/
|
|
99
|
+
getInstructions(): string;
|
|
100
|
+
/**
|
|
101
|
+
* Detect the appropriate icon based on the S3 endpoint.
|
|
102
|
+
*/
|
|
103
|
+
private detectIconFromEndpoint;
|
|
104
|
+
/**
|
|
105
|
+
* Get a user-friendly display name based on the icon/provider.
|
|
106
|
+
*/
|
|
107
|
+
private getDefaultDisplayName;
|
|
108
|
+
private getClient;
|
|
109
|
+
/**
|
|
110
|
+
* Ensure the filesystem is initialized and return the S3 client.
|
|
111
|
+
* Uses base class ensureReady() for status management, then returns client.
|
|
112
|
+
*/
|
|
113
|
+
private getReadyClient;
|
|
114
|
+
private toKey;
|
|
115
|
+
readFile(path: string, options?: ReadOptions): Promise<string | Buffer>;
|
|
116
|
+
writeFile(path: string, content: FileContent, _options?: WriteOptions): Promise<void>;
|
|
117
|
+
appendFile(path: string, content: FileContent): Promise<void>;
|
|
118
|
+
deleteFile(path: string, options?: RemoveOptions): Promise<void>;
|
|
119
|
+
copyFile(src: string, dest: string, _options?: CopyOptions): Promise<void>;
|
|
120
|
+
moveFile(src: string, dest: string, options?: CopyOptions): Promise<void>;
|
|
121
|
+
mkdir(_path: string, _options?: {
|
|
122
|
+
recursive?: boolean;
|
|
123
|
+
}): Promise<void>;
|
|
124
|
+
rmdir(path: string, options?: RemoveOptions): Promise<void>;
|
|
125
|
+
readdir(path: string, options?: ListOptions): Promise<FileEntry[]>;
|
|
126
|
+
exists(path: string): Promise<boolean>;
|
|
127
|
+
stat(path: string): Promise<FileStat>;
|
|
128
|
+
isFile(path: string): Promise<boolean>;
|
|
129
|
+
isDirectory(path: string): Promise<boolean>;
|
|
130
|
+
/**
|
|
131
|
+
* Initialize the S3 client.
|
|
132
|
+
* Status management is handled by the base class.
|
|
133
|
+
*/
|
|
134
|
+
init(): Promise<void>;
|
|
135
|
+
/**
|
|
136
|
+
* Clean up the S3 client.
|
|
137
|
+
* Status management is handled by the base class.
|
|
138
|
+
*/
|
|
139
|
+
destroy(): Promise<void>;
|
|
140
|
+
}
|
|
141
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/filesystem/index.ts"],"names":[],"mappings":"AAYA,OAAO,KAAK,EACV,WAAW,EACX,QAAQ,EACR,SAAS,EACT,WAAW,EACX,YAAY,EACZ,WAAW,EACX,aAAa,EACb,WAAW,EACX,qBAAqB,EACrB,cAAc,EACd,cAAc,EACd,cAAc,EACf,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAE,gBAAgB,EAAqB,MAAM,wBAAwB,CAAC;AAE7E;;;GAGG;AACH,MAAM,WAAW,aAAc,SAAQ,qBAAqB;IAC1D,IAAI,EAAE,IAAI,CAAC;IACX,qBAAqB;IACrB,MAAM,EAAE,MAAM,CAAC;IACf,qCAAqC;IACrC,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,oEAAoE;IACpE,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,wBAAwB;IACxB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,4BAA4B;IA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