@strands-agents/sdk 1.8.0 → 1.10.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/dist/src/agent/agent.d.ts +31 -1
- package/dist/src/agent/agent.d.ts.map +1 -1
- package/dist/src/agent/agent.js +92 -4
- package/dist/src/agent/agent.js.map +1 -1
- package/dist/src/conversation-manager/sliding-window-conversation-manager.d.ts.map +1 -1
- package/dist/src/conversation-manager/sliding-window-conversation-manager.js +2 -0
- package/dist/src/conversation-manager/sliding-window-conversation-manager.js.map +1 -1
- package/dist/src/errors.d.ts +22 -0
- package/dist/src/errors.d.ts.map +1 -1
- package/dist/src/errors.js +28 -0
- package/dist/src/errors.js.map +1 -1
- package/dist/src/experimental/checkpoint.d.ts +118 -0
- package/dist/src/experimental/checkpoint.d.ts.map +1 -0
- package/dist/src/experimental/checkpoint.js +108 -0
- package/dist/src/experimental/checkpoint.js.map +1 -0
- package/dist/src/experimental/index.d.ts +10 -0
- package/dist/src/experimental/index.d.ts.map +1 -0
- package/dist/src/experimental/index.js +9 -0
- package/dist/src/experimental/index.js.map +1 -0
- package/dist/src/index.d.ts +2 -1
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +1 -1
- package/dist/src/index.js.map +1 -1
- package/dist/src/injection/message-injection.d.ts.map +1 -1
- package/dist/src/injection/message-injection.js +2 -0
- package/dist/src/injection/message-injection.js.map +1 -1
- package/dist/src/models/bedrock.d.ts.map +1 -1
- package/dist/src/models/bedrock.js +23 -1
- package/dist/src/models/bedrock.js.map +1 -1
- package/dist/src/models/openai/mantle.d.ts +6 -2
- package/dist/src/models/openai/mantle.d.ts.map +1 -1
- package/dist/src/models/openai/mantle.js +17 -3
- package/dist/src/models/openai/mantle.js.map +1 -1
- package/dist/src/models/openai/model.d.ts.map +1 -1
- package/dist/src/models/openai/model.js +4 -3
- package/dist/src/models/openai/model.js.map +1 -1
- package/dist/src/multiagent/graph.d.ts.map +1 -1
- package/dist/src/multiagent/graph.js +1 -1
- package/dist/src/multiagent/graph.js.map +1 -1
- package/dist/src/multiagent/multiagent.d.ts +2 -1
- package/dist/src/multiagent/multiagent.d.ts.map +1 -1
- package/dist/src/multiagent/multiagent.js.map +1 -1
- package/dist/src/{multiagent/queue.d.ts → queue.d.ts} +12 -27
- package/dist/src/queue.d.ts.map +1 -0
- package/dist/src/{multiagent/queue.js → queue.js} +4 -2
- package/dist/src/queue.js.map +1 -0
- package/dist/src/session/file-storage.d.ts +3 -0
- package/dist/src/session/file-storage.d.ts.map +1 -1
- package/dist/src/session/file-storage.js +3 -0
- package/dist/src/session/file-storage.js.map +1 -1
- package/dist/src/session/s3-storage.d.ts +3 -0
- package/dist/src/session/s3-storage.d.ts.map +1 -1
- package/dist/src/session/s3-storage.js +3 -0
- package/dist/src/session/s3-storage.js.map +1 -1
- package/dist/src/session/session-manager.d.ts +11 -2
- package/dist/src/session/session-manager.d.ts.map +1 -1
- package/dist/src/session/session-manager.js +19 -8
- package/dist/src/session/session-manager.js.map +1 -1
- package/dist/src/session/snapshot-storage-adapter.d.ts +93 -0
- package/dist/src/session/snapshot-storage-adapter.d.ts.map +1 -0
- package/dist/src/session/snapshot-storage-adapter.js +157 -0
- package/dist/src/session/snapshot-storage-adapter.js.map +1 -0
- package/dist/src/session/storage.d.ts +3 -6
- package/dist/src/session/storage.d.ts.map +1 -1
- package/dist/src/storage/in-memory-storage.d.ts +64 -0
- package/dist/src/storage/in-memory-storage.d.ts.map +1 -0
- package/dist/src/storage/in-memory-storage.js +85 -0
- package/dist/src/storage/in-memory-storage.js.map +1 -0
- package/dist/src/storage/index.d.ts +20 -0
- package/dist/src/storage/index.d.ts.map +1 -0
- package/dist/src/storage/index.js +18 -0
- package/dist/src/storage/index.js.map +1 -0
- package/dist/src/storage/local-file-storage.d.ts +81 -0
- package/dist/src/storage/local-file-storage.d.ts.map +1 -0
- package/dist/src/storage/local-file-storage.js +244 -0
- package/dist/src/storage/local-file-storage.js.map +1 -0
- package/dist/src/storage/s3-storage.d.ts +73 -0
- package/dist/src/storage/s3-storage.d.ts.map +1 -0
- package/dist/src/storage/s3-storage.js +146 -0
- package/dist/src/storage/s3-storage.js.map +1 -0
- package/dist/src/storage/storage.d.ts +102 -0
- package/dist/src/storage/storage.d.ts.map +1 -0
- package/dist/src/storage/storage.js +68 -0
- package/dist/src/storage/storage.js.map +1 -0
- package/dist/src/telemetry/tracer.d.ts +18 -0
- package/dist/src/telemetry/tracer.d.ts.map +1 -1
- package/dist/src/telemetry/tracer.js +31 -11
- package/dist/src/telemetry/tracer.js.map +1 -1
- package/dist/src/tsconfig.tsbuildinfo +1 -1
- package/dist/src/types/agent.d.ts +19 -1
- package/dist/src/types/agent.d.ts.map +1 -1
- package/dist/src/types/agent.js +12 -0
- package/dist/src/types/agent.js.map +1 -1
- package/dist/src/types/messages.d.ts +22 -1
- package/dist/src/types/messages.d.ts.map +1 -1
- package/dist/src/types/messages.js +22 -0
- package/dist/src/types/messages.js.map +1 -1
- package/dist/src/vended-memory-stores/test-memory-store/index.d.ts +2 -0
- package/dist/src/vended-memory-stores/test-memory-store/index.d.ts.map +1 -0
- package/dist/src/vended-memory-stores/test-memory-store/index.js +2 -0
- package/dist/src/vended-memory-stores/test-memory-store/index.js.map +1 -0
- package/dist/src/vended-memory-stores/{local → test-memory-store}/store.d.ts +10 -10
- package/dist/src/vended-memory-stores/test-memory-store/store.d.ts.map +1 -0
- package/dist/src/vended-memory-stores/{local → test-memory-store}/store.js +15 -15
- package/dist/src/vended-memory-stores/test-memory-store/store.js.map +1 -0
- package/dist/src/vended-plugins/context-offloader/plugin.d.ts +37 -5
- package/dist/src/vended-plugins/context-offloader/plugin.d.ts.map +1 -1
- package/dist/src/vended-plugins/context-offloader/plugin.js +116 -17
- package/dist/src/vended-plugins/context-offloader/plugin.js.map +1 -1
- package/dist/src/vended-plugins/context-offloader/storage.d.ts +23 -9
- package/dist/src/vended-plugins/context-offloader/storage.d.ts.map +1 -1
- package/dist/src/vended-plugins/context-offloader/storage.js +17 -6
- package/dist/src/vended-plugins/context-offloader/storage.js.map +1 -1
- package/dist/src/vended-tools/notebook/notebook.d.ts +1 -1
- package/package.json +31 -24
- package/dist/src/conversation-manager/index.d.ts +0 -10
- package/dist/src/conversation-manager/index.d.ts.map +0 -1
- package/dist/src/conversation-manager/index.js +0 -10
- package/dist/src/conversation-manager/index.js.map +0 -1
- package/dist/src/multiagent/queue.d.ts.map +0 -1
- package/dist/src/multiagent/queue.js.map +0 -1
- package/dist/src/vended-memory-stores/local/index.d.ts +0 -2
- package/dist/src/vended-memory-stores/local/index.d.ts.map +0 -1
- package/dist/src/vended-memory-stores/local/index.js +0 -2
- package/dist/src/vended-memory-stores/local/index.js.map +0 -1
- package/dist/src/vended-memory-stores/local/store.d.ts.map +0 -1
- package/dist/src/vended-memory-stores/local/store.js.map +0 -1
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import type { Storage } from './storage.js';
|
|
2
|
+
/**
|
|
3
|
+
* In-memory {@link Storage} backend backed by a `Map`.
|
|
4
|
+
*
|
|
5
|
+
* Useful for testing and for serverless environments where disk access is unavailable.
|
|
6
|
+
* Content does not survive process restarts — for persistence use {@link LocalFileStorage}
|
|
7
|
+
* or {@link S3Storage}.
|
|
8
|
+
*
|
|
9
|
+
* This is a plain unbounded store with no eviction. Consumers that need eviction
|
|
10
|
+
* (e.g. the ContextOffloader plugin) manage it themselves.
|
|
11
|
+
*
|
|
12
|
+
* Keys are normalized identically to {@link LocalFileStorage}: slash runs are collapsed,
|
|
13
|
+
* leading/trailing slashes are stripped, and `..` segments are rejected.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```typescript
|
|
17
|
+
* const storage = new InMemoryStorage()
|
|
18
|
+
* await storage.write('memory/notes.json', new TextEncoder().encode('[]'))
|
|
19
|
+
* const bytes = await storage.read('memory/notes.json')
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
22
|
+
export declare class InMemoryStorage implements Storage {
|
|
23
|
+
private readonly _store;
|
|
24
|
+
/**
|
|
25
|
+
* Stores `data` under `key`, overwriting any existing value.
|
|
26
|
+
* Bytes are copied on write to prevent aliasing with the caller's buffer.
|
|
27
|
+
*
|
|
28
|
+
* @param key - Opaque, `/`-separated key identifying the value
|
|
29
|
+
* @param data - Raw bytes to persist
|
|
30
|
+
* @throws {@link StorageError} if the key is empty or contains `..` segments
|
|
31
|
+
*/
|
|
32
|
+
write(key: string, data: Uint8Array): Promise<void>;
|
|
33
|
+
/**
|
|
34
|
+
* Retrieves the bytes previously stored under `key`.
|
|
35
|
+
* Returns a copy to prevent aliasing with the internal buffer.
|
|
36
|
+
*
|
|
37
|
+
* @param key - The key to read
|
|
38
|
+
* @returns The stored bytes, or `null` if no value exists for `key`
|
|
39
|
+
* @throws {@link StorageError} if the key is empty or contains `..` segments
|
|
40
|
+
*/
|
|
41
|
+
read(key: string): Promise<Uint8Array | null>;
|
|
42
|
+
/**
|
|
43
|
+
* Deletes the value stored under `key`. A no-op if the key does not exist.
|
|
44
|
+
*
|
|
45
|
+
* @param key - The key to delete
|
|
46
|
+
* @throws {@link StorageError} if the key is empty or contains `..` segments
|
|
47
|
+
*/
|
|
48
|
+
delete(key: string): Promise<void>;
|
|
49
|
+
/**
|
|
50
|
+
* Lists the keys whose names begin with `prefix`, sorted lexicographically.
|
|
51
|
+
*
|
|
52
|
+
* @param prefix - Key prefix to match. An empty string matches all keys.
|
|
53
|
+
* @returns The matching keys, sorted ascending
|
|
54
|
+
* @throws {@link StorageError} if the prefix contains `..` segments
|
|
55
|
+
*/
|
|
56
|
+
list(prefix: string): Promise<string[]>;
|
|
57
|
+
/** Returns a prefixed view of this storage without mutating the original. */
|
|
58
|
+
namespace(prefix: string): Storage;
|
|
59
|
+
/**
|
|
60
|
+
* Removes all stored entries. Useful for resetting state between tests.
|
|
61
|
+
*/
|
|
62
|
+
clear(): void;
|
|
63
|
+
}
|
|
64
|
+
//# sourceMappingURL=in-memory-storage.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"in-memory-storage.d.ts","sourceRoot":"","sources":["../../../src/storage/in-memory-storage.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AAI3C;;;;;;;;;;;;;;;;;;;GAmBG;AACH,qBAAa,eAAgB,YAAW,OAAO;IAC7C,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAgC;IAEvD;;;;;;;OAOG;IACG,KAAK,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,UAAU,GAAG,OAAO,CAAC,IAAI,CAAC;IAIzD;;;;;;;OAOG;IACG,IAAI,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,GAAG,IAAI,CAAC;IAMnD;;;;;OAKG;IACG,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAIxC;;;;;;OAMG;IACG,IAAI,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC;IAS7C,6EAA6E;IAC7E,SAAS,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO;IAIlC;;OAEG;IACH,KAAK,IAAI,IAAI;CAGd"}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { namespace, normalizeKey, normalizePrefix } from './storage.js';
|
|
2
|
+
/**
|
|
3
|
+
* In-memory {@link Storage} backend backed by a `Map`.
|
|
4
|
+
*
|
|
5
|
+
* Useful for testing and for serverless environments where disk access is unavailable.
|
|
6
|
+
* Content does not survive process restarts — for persistence use {@link LocalFileStorage}
|
|
7
|
+
* or {@link S3Storage}.
|
|
8
|
+
*
|
|
9
|
+
* This is a plain unbounded store with no eviction. Consumers that need eviction
|
|
10
|
+
* (e.g. the ContextOffloader plugin) manage it themselves.
|
|
11
|
+
*
|
|
12
|
+
* Keys are normalized identically to {@link LocalFileStorage}: slash runs are collapsed,
|
|
13
|
+
* leading/trailing slashes are stripped, and `..` segments are rejected.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```typescript
|
|
17
|
+
* const storage = new InMemoryStorage()
|
|
18
|
+
* await storage.write('memory/notes.json', new TextEncoder().encode('[]'))
|
|
19
|
+
* const bytes = await storage.read('memory/notes.json')
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
22
|
+
export class InMemoryStorage {
|
|
23
|
+
_store = new Map();
|
|
24
|
+
/**
|
|
25
|
+
* Stores `data` under `key`, overwriting any existing value.
|
|
26
|
+
* Bytes are copied on write to prevent aliasing with the caller's buffer.
|
|
27
|
+
*
|
|
28
|
+
* @param key - Opaque, `/`-separated key identifying the value
|
|
29
|
+
* @param data - Raw bytes to persist
|
|
30
|
+
* @throws {@link StorageError} if the key is empty or contains `..` segments
|
|
31
|
+
*/
|
|
32
|
+
async write(key, data) {
|
|
33
|
+
this._store.set(normalizeKey(key), data.slice());
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Retrieves the bytes previously stored under `key`.
|
|
37
|
+
* Returns a copy to prevent aliasing with the internal buffer.
|
|
38
|
+
*
|
|
39
|
+
* @param key - The key to read
|
|
40
|
+
* @returns The stored bytes, or `null` if no value exists for `key`
|
|
41
|
+
* @throws {@link StorageError} if the key is empty or contains `..` segments
|
|
42
|
+
*/
|
|
43
|
+
async read(key) {
|
|
44
|
+
const value = this._store.get(normalizeKey(key));
|
|
45
|
+
if (value === undefined)
|
|
46
|
+
return null;
|
|
47
|
+
return value.slice();
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Deletes the value stored under `key`. A no-op if the key does not exist.
|
|
51
|
+
*
|
|
52
|
+
* @param key - The key to delete
|
|
53
|
+
* @throws {@link StorageError} if the key is empty or contains `..` segments
|
|
54
|
+
*/
|
|
55
|
+
async delete(key) {
|
|
56
|
+
this._store.delete(normalizeKey(key));
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Lists the keys whose names begin with `prefix`, sorted lexicographically.
|
|
60
|
+
*
|
|
61
|
+
* @param prefix - Key prefix to match. An empty string matches all keys.
|
|
62
|
+
* @returns The matching keys, sorted ascending
|
|
63
|
+
* @throws {@link StorageError} if the prefix contains `..` segments
|
|
64
|
+
*/
|
|
65
|
+
async list(prefix) {
|
|
66
|
+
const normalized = normalizePrefix(prefix);
|
|
67
|
+
const keys = [];
|
|
68
|
+
for (const key of this._store.keys()) {
|
|
69
|
+
if (key.startsWith(normalized))
|
|
70
|
+
keys.push(key);
|
|
71
|
+
}
|
|
72
|
+
return keys.sort();
|
|
73
|
+
}
|
|
74
|
+
/** Returns a prefixed view of this storage without mutating the original. */
|
|
75
|
+
namespace(prefix) {
|
|
76
|
+
return namespace(this, prefix);
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Removes all stored entries. Useful for resetting state between tests.
|
|
80
|
+
*/
|
|
81
|
+
clear() {
|
|
82
|
+
this._store.clear();
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
//# sourceMappingURL=in-memory-storage.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"in-memory-storage.js","sourceRoot":"","sources":["../../../src/storage/in-memory-storage.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,SAAS,EAAE,YAAY,EAAE,eAAe,EAAE,MAAM,cAAc,CAAA;AAEvE;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAM,OAAO,eAAe;IACT,MAAM,GAAG,IAAI,GAAG,EAAsB,CAAA;IAEvD;;;;;;;OAOG;IACH,KAAK,CAAC,KAAK,CAAC,GAAW,EAAE,IAAgB;QACvC,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,YAAY,CAAC,GAAG,CAAC,EAAE,IAAI,CAAC,KAAK,EAAE,CAAC,CAAA;IAClD,CAAC;IAED;;;;;;;OAOG;IACH,KAAK,CAAC,IAAI,CAAC,GAAW;QACpB,MAAM,KAAK,GAAG,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,YAAY,CAAC,GAAG,CAAC,CAAC,CAAA;QAChD,IAAI,KAAK,KAAK,SAAS;YAAE,OAAO,IAAI,CAAA;QACpC,OAAO,KAAK,CAAC,KAAK,EAAE,CAAA;IACtB,CAAC;IAED;;;;;OAKG;IACH,KAAK,CAAC,MAAM,CAAC,GAAW;QACtB,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,YAAY,CAAC,GAAG,CAAC,CAAC,CAAA;IACvC,CAAC;IAED;;;;;;OAMG;IACH,KAAK,CAAC,IAAI,CAAC,MAAc;QACvB,MAAM,UAAU,GAAG,eAAe,CAAC,MAAM,CAAC,CAAA;QAC1C,MAAM,IAAI,GAAa,EAAE,CAAA;QACzB,KAAK,MAAM,GAAG,IAAI,IAAI,CAAC,MAAM,CAAC,IAAI,EAAE,EAAE,CAAC;YACrC,IAAI,GAAG,CAAC,UAAU,CAAC,UAAU,CAAC;gBAAE,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA;QAChD,CAAC;QACD,OAAO,IAAI,CAAC,IAAI,EAAE,CAAA;IACpB,CAAC;IAED,6EAA6E;IAC7E,SAAS,CAAC,MAAc;QACtB,OAAO,SAAS,CAAC,IAAI,EAAE,MAAM,CAAC,CAAA;IAChC,CAAC;IAED;;OAEG;IACH,KAAK;QACH,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,CAAA;IACrB,CAAC;CACF"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Unified storage module.
|
|
3
|
+
*
|
|
4
|
+
* Provides the {@link Storage} interface and shipped implementations for persisting
|
|
5
|
+
* raw bytes under string keys. All SDK subsystems that need persistence — sessions,
|
|
6
|
+
* memory, context offloading, transcripts — consume this interface.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```typescript
|
|
10
|
+
* import { LocalFileStorage, InMemoryStorage } from '@strands-agents/sdk/storage'
|
|
11
|
+
* ```
|
|
12
|
+
*
|
|
13
|
+
* @packageDocumentation
|
|
14
|
+
*/
|
|
15
|
+
export type { Storage } from './storage.js';
|
|
16
|
+
export { InMemoryStorage } from './in-memory-storage.js';
|
|
17
|
+
export { LocalFileStorage } from './local-file-storage.js';
|
|
18
|
+
export { S3Storage } from './s3-storage.js';
|
|
19
|
+
export type { S3StorageConfig } from './s3-storage.js';
|
|
20
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/storage/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,YAAY,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AAC3C,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAA;AACxD,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAA;AAC1D,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAA;AAC3C,YAAY,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAA"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Unified storage module.
|
|
3
|
+
*
|
|
4
|
+
* Provides the {@link Storage} interface and shipped implementations for persisting
|
|
5
|
+
* raw bytes under string keys. All SDK subsystems that need persistence — sessions,
|
|
6
|
+
* memory, context offloading, transcripts — consume this interface.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```typescript
|
|
10
|
+
* import { LocalFileStorage, InMemoryStorage } from '@strands-agents/sdk/storage'
|
|
11
|
+
* ```
|
|
12
|
+
*
|
|
13
|
+
* @packageDocumentation
|
|
14
|
+
*/
|
|
15
|
+
export { InMemoryStorage } from './in-memory-storage.js';
|
|
16
|
+
export { LocalFileStorage } from './local-file-storage.js';
|
|
17
|
+
export { S3Storage } from './s3-storage.js';
|
|
18
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/storage/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAGH,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAA;AACxD,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAA;AAC1D,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAA"}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import type { Sandbox } from '../sandbox/base.js';
|
|
2
|
+
import type { Storage } from './storage.js';
|
|
3
|
+
/**
|
|
4
|
+
* Local-filesystem {@link Storage} backend.
|
|
5
|
+
*
|
|
6
|
+
* Persists each key as a file under a base directory, mapping the key's `/` segments
|
|
7
|
+
* onto directory segments. On the host filesystem, writes are atomic (write to a
|
|
8
|
+
* scratch sibling, then rename) so a crash mid-write never leaves a partially written
|
|
9
|
+
* file. When bound to a {@link Sandbox} via {@link forSandbox}, all I/O is routed
|
|
10
|
+
* through that sandbox instead of the host's `node:fs` (atomicity depends on the
|
|
11
|
+
* sandbox implementation).
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```typescript
|
|
15
|
+
* import { LocalFileStorage } from '@strands-agents/sdk/storage'
|
|
16
|
+
*
|
|
17
|
+
* const storage = new LocalFileStorage('./.strands/')
|
|
18
|
+
* await storage.write('sessions/abc/snapshot.json', bytes)
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
export declare class LocalFileStorage implements Storage {
|
|
22
|
+
private readonly _baseDir;
|
|
23
|
+
private readonly _sandbox;
|
|
24
|
+
/**
|
|
25
|
+
* @param baseDir - Root directory under which keys are stored. Defaults to `./.strands/`.
|
|
26
|
+
* @param sandbox - Optional sandbox to route I/O through. Usually set via {@link forSandbox}.
|
|
27
|
+
*/
|
|
28
|
+
constructor(baseDir?: string, sandbox?: Sandbox);
|
|
29
|
+
/**
|
|
30
|
+
* Returns a storage instance whose I/O is routed through `sandbox`.
|
|
31
|
+
*
|
|
32
|
+
* Instances already bound to a sandbox return themselves unchanged.
|
|
33
|
+
*
|
|
34
|
+
* @param sandbox - Sandbox to route the returned instance's I/O through
|
|
35
|
+
* @returns A new `LocalFileStorage` with the same base directory, routed through `sandbox`
|
|
36
|
+
*/
|
|
37
|
+
forSandbox(sandbox: Sandbox): LocalFileStorage;
|
|
38
|
+
/**
|
|
39
|
+
* Stores `data` under `key`, overwriting any existing value.
|
|
40
|
+
*
|
|
41
|
+
* @param key - Opaque, `/`-separated key identifying the value
|
|
42
|
+
* @param data - Raw bytes to persist
|
|
43
|
+
* @throws {@link StorageError} if the key is invalid or the write fails
|
|
44
|
+
*/
|
|
45
|
+
write(key: string, data: Uint8Array): Promise<void>;
|
|
46
|
+
/**
|
|
47
|
+
* Retrieves the bytes previously stored under `key`.
|
|
48
|
+
*
|
|
49
|
+
* @param key - The key to read
|
|
50
|
+
* @returns The stored bytes, or `null` if no value exists for `key`
|
|
51
|
+
* @throws {@link StorageError} if the key is invalid or the read fails
|
|
52
|
+
*/
|
|
53
|
+
read(key: string): Promise<Uint8Array | null>;
|
|
54
|
+
/**
|
|
55
|
+
* Deletes the value stored under `key`. A no-op if the key does not exist.
|
|
56
|
+
*
|
|
57
|
+
* @param key - The key to delete
|
|
58
|
+
* @throws {@link StorageError} if the key is invalid or the delete fails
|
|
59
|
+
*/
|
|
60
|
+
delete(key: string): Promise<void>;
|
|
61
|
+
/**
|
|
62
|
+
* Lists the keys whose names begin with `prefix`, sorted lexicographically.
|
|
63
|
+
*
|
|
64
|
+
* @param prefix - Key prefix to match. An empty string matches all keys.
|
|
65
|
+
* @returns The matching keys, sorted ascending
|
|
66
|
+
* @throws {@link StorageError} if the prefix is invalid or the listing fails
|
|
67
|
+
*/
|
|
68
|
+
list(prefix: string): Promise<string[]>;
|
|
69
|
+
private _pathFor;
|
|
70
|
+
private _listKeysHost;
|
|
71
|
+
private _listKeysSandbox;
|
|
72
|
+
/**
|
|
73
|
+
* Returns a prefixed view of this storage without mutating the original.
|
|
74
|
+
* The returned view preserves `forSandbox` for single-level namespacing;
|
|
75
|
+
* nested `.namespace()` calls on the view do not carry sandbox routing.
|
|
76
|
+
*/
|
|
77
|
+
namespace(prefix: string): Storage & {
|
|
78
|
+
forSandbox(sandbox: Sandbox): Storage;
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
//# sourceMappingURL=local-file-storage.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"local-file-storage.d.ts","sourceRoot":"","sources":["../../../src/storage/local-file-storage.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAA;AACjD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AAgB3C;;;;;;;;;;;;;;;;;GAiBG;AACH,qBAAa,gBAAiB,YAAW,OAAO;IAC9C,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAQ;IACjC,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAqB;IAE9C;;;OAGG;gBACS,OAAO,GAAE,MAAsB,EAAE,OAAO,CAAC,EAAE,OAAO;IAK9D;;;;;;;OAOG;IACH,UAAU,CAAC,OAAO,EAAE,OAAO,GAAG,gBAAgB;IAK9C;;;;;;OAMG;IACG,KAAK,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,UAAU,GAAG,OAAO,CAAC,IAAI,CAAC;IA6BzD;;;;;;OAMG;IACG,IAAI,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,GAAG,IAAI,CAAC;IAqBnD;;;;;OAKG;IACG,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAqBxC;;;;;;OAMG;IACG,IAAI,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC;IAa7C,OAAO,CAAC,QAAQ;YAKF,aAAa;YA2Bb,gBAAgB;IA2B9B;;;;OAIG;IACH,SAAS,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,GAAG;QAAE,UAAU,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAAA;KAAE;CAO/E"}
|
|
@@ -0,0 +1,244 @@
|
|
|
1
|
+
import { StorageError } from '../errors.js';
|
|
2
|
+
import { namespace, normalizeKey, normalizePrefix } from './storage.js';
|
|
3
|
+
/**
|
|
4
|
+
* Returns true if the error represents a missing or non-directory path (ENOENT or ENOTDIR).
|
|
5
|
+
*
|
|
6
|
+
* @param error - The caught error to inspect
|
|
7
|
+
* @returns Whether the error is a filesystem not-found error
|
|
8
|
+
*/
|
|
9
|
+
function isNotFoundError(error) {
|
|
10
|
+
if (error === null || typeof error !== 'object' || !('code' in error))
|
|
11
|
+
return false;
|
|
12
|
+
return error.code === 'ENOENT' || error.code === 'ENOTDIR';
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Local-filesystem {@link Storage} backend.
|
|
16
|
+
*
|
|
17
|
+
* Persists each key as a file under a base directory, mapping the key's `/` segments
|
|
18
|
+
* onto directory segments. On the host filesystem, writes are atomic (write to a
|
|
19
|
+
* scratch sibling, then rename) so a crash mid-write never leaves a partially written
|
|
20
|
+
* file. When bound to a {@link Sandbox} via {@link forSandbox}, all I/O is routed
|
|
21
|
+
* through that sandbox instead of the host's `node:fs` (atomicity depends on the
|
|
22
|
+
* sandbox implementation).
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* ```typescript
|
|
26
|
+
* import { LocalFileStorage } from '@strands-agents/sdk/storage'
|
|
27
|
+
*
|
|
28
|
+
* const storage = new LocalFileStorage('./.strands/')
|
|
29
|
+
* await storage.write('sessions/abc/snapshot.json', bytes)
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
32
|
+
export class LocalFileStorage {
|
|
33
|
+
_baseDir;
|
|
34
|
+
_sandbox;
|
|
35
|
+
/**
|
|
36
|
+
* @param baseDir - Root directory under which keys are stored. Defaults to `./.strands/`.
|
|
37
|
+
* @param sandbox - Optional sandbox to route I/O through. Usually set via {@link forSandbox}.
|
|
38
|
+
*/
|
|
39
|
+
constructor(baseDir = './.strands/', sandbox) {
|
|
40
|
+
this._baseDir = baseDir;
|
|
41
|
+
this._sandbox = sandbox;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Returns a storage instance whose I/O is routed through `sandbox`.
|
|
45
|
+
*
|
|
46
|
+
* Instances already bound to a sandbox return themselves unchanged.
|
|
47
|
+
*
|
|
48
|
+
* @param sandbox - Sandbox to route the returned instance's I/O through
|
|
49
|
+
* @returns A new `LocalFileStorage` with the same base directory, routed through `sandbox`
|
|
50
|
+
*/
|
|
51
|
+
forSandbox(sandbox) {
|
|
52
|
+
if (this._sandbox)
|
|
53
|
+
return this;
|
|
54
|
+
return new LocalFileStorage(this._baseDir, sandbox);
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Stores `data` under `key`, overwriting any existing value.
|
|
58
|
+
*
|
|
59
|
+
* @param key - Opaque, `/`-separated key identifying the value
|
|
60
|
+
* @param data - Raw bytes to persist
|
|
61
|
+
* @throws {@link StorageError} if the key is invalid or the write fails
|
|
62
|
+
*/
|
|
63
|
+
async write(key, data) {
|
|
64
|
+
const normalized = normalizeKey(key);
|
|
65
|
+
const path = this._pathFor(normalized);
|
|
66
|
+
if (this._sandbox) {
|
|
67
|
+
try {
|
|
68
|
+
await this._sandbox.writeFile(path, data);
|
|
69
|
+
}
|
|
70
|
+
catch (error) {
|
|
71
|
+
throw new StorageError(`Failed to write '${normalized}' to sandbox storage`, { cause: error });
|
|
72
|
+
}
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
let tmpPath;
|
|
76
|
+
try {
|
|
77
|
+
const { mkdir, writeFile, rename } = await import('node:fs/promises');
|
|
78
|
+
const { dirname } = await import('node:path');
|
|
79
|
+
await mkdir(dirname(path), { recursive: true });
|
|
80
|
+
const { randomUUID } = await import('node:crypto');
|
|
81
|
+
tmpPath = `${path}.__strands_tmp_${randomUUID()}`;
|
|
82
|
+
await writeFile(tmpPath, data);
|
|
83
|
+
await rename(tmpPath, path);
|
|
84
|
+
}
|
|
85
|
+
catch (error) {
|
|
86
|
+
if (tmpPath) {
|
|
87
|
+
const { rm } = await import('node:fs/promises');
|
|
88
|
+
await rm(tmpPath, { force: true }).catch(() => { });
|
|
89
|
+
}
|
|
90
|
+
throw new StorageError(`Failed to write '${normalized}' to local storage`, { cause: error });
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Retrieves the bytes previously stored under `key`.
|
|
95
|
+
*
|
|
96
|
+
* @param key - The key to read
|
|
97
|
+
* @returns The stored bytes, or `null` if no value exists for `key`
|
|
98
|
+
* @throws {@link StorageError} if the key is invalid or the read fails
|
|
99
|
+
*/
|
|
100
|
+
async read(key) {
|
|
101
|
+
const normalized = normalizeKey(key);
|
|
102
|
+
const path = this._pathFor(normalized);
|
|
103
|
+
if (this._sandbox) {
|
|
104
|
+
try {
|
|
105
|
+
return await this._sandbox.readFile(path);
|
|
106
|
+
}
|
|
107
|
+
catch (error) {
|
|
108
|
+
if (isNotFoundError(error))
|
|
109
|
+
return null;
|
|
110
|
+
throw new StorageError(`Failed to read '${normalized}' from sandbox storage`, { cause: error });
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
try {
|
|
114
|
+
const { readFile } = await import('node:fs/promises');
|
|
115
|
+
const content = await readFile(path);
|
|
116
|
+
return new Uint8Array(content);
|
|
117
|
+
}
|
|
118
|
+
catch (error) {
|
|
119
|
+
if (isNotFoundError(error))
|
|
120
|
+
return null;
|
|
121
|
+
throw new StorageError(`Failed to read '${normalized}' from local storage`, { cause: error });
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Deletes the value stored under `key`. A no-op if the key does not exist.
|
|
126
|
+
*
|
|
127
|
+
* @param key - The key to delete
|
|
128
|
+
* @throws {@link StorageError} if the key is invalid or the delete fails
|
|
129
|
+
*/
|
|
130
|
+
async delete(key) {
|
|
131
|
+
const normalized = normalizeKey(key);
|
|
132
|
+
const path = this._pathFor(normalized);
|
|
133
|
+
if (this._sandbox) {
|
|
134
|
+
try {
|
|
135
|
+
await this._sandbox.removeFile(path);
|
|
136
|
+
}
|
|
137
|
+
catch (error) {
|
|
138
|
+
if (!isNotFoundError(error)) {
|
|
139
|
+
throw new StorageError(`Failed to delete '${normalized}' from sandbox storage`, { cause: error });
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
return;
|
|
143
|
+
}
|
|
144
|
+
try {
|
|
145
|
+
const { rm } = await import('node:fs/promises');
|
|
146
|
+
await rm(path, { force: true });
|
|
147
|
+
}
|
|
148
|
+
catch (error) {
|
|
149
|
+
throw new StorageError(`Failed to delete '${normalized}' from local storage`, { cause: error });
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* Lists the keys whose names begin with `prefix`, sorted lexicographically.
|
|
154
|
+
*
|
|
155
|
+
* @param prefix - Key prefix to match. An empty string matches all keys.
|
|
156
|
+
* @returns The matching keys, sorted ascending
|
|
157
|
+
* @throws {@link StorageError} if the prefix is invalid or the listing fails
|
|
158
|
+
*/
|
|
159
|
+
async list(prefix) {
|
|
160
|
+
const normalized = normalizePrefix(prefix);
|
|
161
|
+
const base = this._baseDir.replace(/\/$/, '');
|
|
162
|
+
// Narrow the walk to the deepest directory the prefix fully specifies
|
|
163
|
+
const lastSlash = normalized.lastIndexOf('/');
|
|
164
|
+
const dirPortion = lastSlash >= 0 ? normalized.slice(0, lastSlash) : '';
|
|
165
|
+
const startDir = dirPortion ? `${base}/${dirPortion}` : base;
|
|
166
|
+
const keys = this._sandbox
|
|
167
|
+
? await this._listKeysSandbox(startDir, dirPortion)
|
|
168
|
+
: await this._listKeysHost(startDir, dirPortion);
|
|
169
|
+
return keys.filter((key) => key.startsWith(normalized)).sort();
|
|
170
|
+
}
|
|
171
|
+
_pathFor(key) {
|
|
172
|
+
const base = this._baseDir.replace(/\/$/, '');
|
|
173
|
+
return `${base}/${key}`;
|
|
174
|
+
}
|
|
175
|
+
async _listKeysHost(dir, keyPrefix) {
|
|
176
|
+
const { readdir } = await import('node:fs/promises');
|
|
177
|
+
const walk = async (walkDir, walkPrefix) => {
|
|
178
|
+
let entries;
|
|
179
|
+
try {
|
|
180
|
+
entries = await readdir(walkDir, { withFileTypes: true });
|
|
181
|
+
}
|
|
182
|
+
catch (error) {
|
|
183
|
+
if (isNotFoundError(error))
|
|
184
|
+
return [];
|
|
185
|
+
throw new StorageError(`Failed to list local storage under '${walkPrefix}'`, { cause: error });
|
|
186
|
+
}
|
|
187
|
+
const found = [];
|
|
188
|
+
for (const entry of entries) {
|
|
189
|
+
if (!entry.isDirectory() && entry.name.includes('.__strands_tmp'))
|
|
190
|
+
continue;
|
|
191
|
+
const childKey = walkPrefix ? `${walkPrefix}/${entry.name}` : entry.name;
|
|
192
|
+
if (entry.isDirectory()) {
|
|
193
|
+
found.push(...(await walk(`${walkDir}/${entry.name}`, childKey)));
|
|
194
|
+
}
|
|
195
|
+
else {
|
|
196
|
+
found.push(childKey);
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
return found;
|
|
200
|
+
};
|
|
201
|
+
return walk(dir, keyPrefix);
|
|
202
|
+
}
|
|
203
|
+
async _listKeysSandbox(dir, keyPrefix) {
|
|
204
|
+
const sandbox = this._sandbox;
|
|
205
|
+
const walk = async (walkDir, walkPrefix) => {
|
|
206
|
+
let entries;
|
|
207
|
+
try {
|
|
208
|
+
entries = await sandbox.listFiles(walkDir);
|
|
209
|
+
}
|
|
210
|
+
catch (error) {
|
|
211
|
+
if (isNotFoundError(error))
|
|
212
|
+
return [];
|
|
213
|
+
throw new StorageError(`Failed to list sandbox storage under '${walkPrefix}'`, { cause: error });
|
|
214
|
+
}
|
|
215
|
+
const found = [];
|
|
216
|
+
for (const entry of entries) {
|
|
217
|
+
if (!entry.isDir && entry.name.includes('.__strands_tmp'))
|
|
218
|
+
continue;
|
|
219
|
+
const childKey = walkPrefix ? `${walkPrefix}/${entry.name}` : entry.name;
|
|
220
|
+
if (entry.isDir) {
|
|
221
|
+
found.push(...(await walk(`${walkDir}/${entry.name}`, childKey)));
|
|
222
|
+
}
|
|
223
|
+
else {
|
|
224
|
+
found.push(childKey);
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
return found;
|
|
228
|
+
};
|
|
229
|
+
return walk(dir, keyPrefix);
|
|
230
|
+
}
|
|
231
|
+
/**
|
|
232
|
+
* Returns a prefixed view of this storage without mutating the original.
|
|
233
|
+
* The returned view preserves `forSandbox` for single-level namespacing;
|
|
234
|
+
* nested `.namespace()` calls on the view do not carry sandbox routing.
|
|
235
|
+
*/
|
|
236
|
+
namespace(prefix) {
|
|
237
|
+
const view = namespace(this, prefix);
|
|
238
|
+
return {
|
|
239
|
+
...view,
|
|
240
|
+
forSandbox: (sandbox) => namespace(this.forSandbox(sandbox), prefix),
|
|
241
|
+
};
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
//# sourceMappingURL=local-file-storage.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"local-file-storage.js","sourceRoot":"","sources":["../../../src/storage/local-file-storage.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAA;AAC3C,OAAO,EAAE,SAAS,EAAE,YAAY,EAAE,eAAe,EAAE,MAAM,cAAc,CAAA;AAEvE;;;;;GAKG;AACH,SAAS,eAAe,CAAC,KAAc;IACrC,IAAI,KAAK,KAAK,IAAI,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,CAAC,CAAC,MAAM,IAAI,KAAK,CAAC;QAAE,OAAO,KAAK,CAAA;IACnF,OAAO,KAAK,CAAC,IAAI,KAAK,QAAQ,IAAI,KAAK,CAAC,IAAI,KAAK,SAAS,CAAA;AAC5D,CAAC;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,OAAO,gBAAgB;IACV,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EAAE,CAAC,OAAgB,EAAW,EAAE,CAAC,SAAS,CAAC,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC;SACvF,CAAA;IACH,CAAC;CACF"}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import type { Storage } from './storage.js';
|
|
2
|
+
/** Configuration for {@link S3Storage}. */
|
|
3
|
+
export interface S3StorageConfig {
|
|
4
|
+
/** Optional key prefix prepended to every key (a leading namespace within the bucket). */
|
|
5
|
+
prefix?: string;
|
|
6
|
+
/** AWS region override. When omitted, the SDK's standard resolution chain applies. Cannot be combined with `s3Client`. */
|
|
7
|
+
region?: string;
|
|
8
|
+
/** Pre-configured S3 client. Cannot be combined with `region`. */
|
|
9
|
+
s3Client?: import('@aws-sdk/client-s3').S3Client;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Amazon S3 {@link Storage} backend.
|
|
13
|
+
*
|
|
14
|
+
* Stores each key as an S3 object under an optional prefix. The AWS SDK is loaded
|
|
15
|
+
* lazily on first use and declared as an optional peer dependency, so consumers that
|
|
16
|
+
* never construct an `S3Storage` are not required to install `@aws-sdk/client-s3`.
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```typescript
|
|
20
|
+
* import { S3Storage } from '@strands-agents/sdk/storage'
|
|
21
|
+
*
|
|
22
|
+
* const storage = new S3Storage('my-bucket', { prefix: 'agents/' })
|
|
23
|
+
* await storage.write('sessions/abc/snapshot.json', bytes)
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
26
|
+
export declare class S3Storage implements Storage {
|
|
27
|
+
private readonly _bucket;
|
|
28
|
+
private readonly _prefix;
|
|
29
|
+
private readonly _region;
|
|
30
|
+
private _client;
|
|
31
|
+
/**
|
|
32
|
+
* @param bucket - Target S3 bucket name
|
|
33
|
+
* @param config - Optional prefix, region, or pre-configured client
|
|
34
|
+
* @throws {@link StorageError} if both `region` and `s3Client` are provided
|
|
35
|
+
*/
|
|
36
|
+
constructor(bucket: string, config?: S3StorageConfig);
|
|
37
|
+
/**
|
|
38
|
+
* Stores `data` under `key`, overwriting any existing value.
|
|
39
|
+
*
|
|
40
|
+
* @param key - Opaque, `/`-separated key identifying the value
|
|
41
|
+
* @param data - Raw bytes to persist
|
|
42
|
+
* @throws {@link StorageError} if the key is invalid or the upload fails
|
|
43
|
+
*/
|
|
44
|
+
write(key: string, data: Uint8Array): Promise<void>;
|
|
45
|
+
/**
|
|
46
|
+
* Retrieves the bytes previously stored under `key`.
|
|
47
|
+
*
|
|
48
|
+
* @param key - The key to read
|
|
49
|
+
* @returns The stored bytes, or `null` if no value exists for `key`
|
|
50
|
+
* @throws {@link StorageError} if the key is invalid or the download fails
|
|
51
|
+
*/
|
|
52
|
+
read(key: string): Promise<Uint8Array | null>;
|
|
53
|
+
/**
|
|
54
|
+
* Deletes the value stored under `key`. A no-op if the key does not exist.
|
|
55
|
+
*
|
|
56
|
+
* @param key - The key to delete
|
|
57
|
+
* @throws {@link StorageError} if the key is invalid or the delete request fails
|
|
58
|
+
*/
|
|
59
|
+
delete(key: string): Promise<void>;
|
|
60
|
+
/**
|
|
61
|
+
* Lists the keys whose names begin with `prefix`, sorted lexicographically.
|
|
62
|
+
*
|
|
63
|
+
* @param prefix - Key prefix to match. An empty string matches all keys.
|
|
64
|
+
* @returns The matching keys, sorted ascending
|
|
65
|
+
* @throws {@link StorageError} if the prefix is invalid or the list request fails
|
|
66
|
+
*/
|
|
67
|
+
list(prefix: string): Promise<string[]>;
|
|
68
|
+
private _getClient;
|
|
69
|
+
/** Returns a prefixed view of this storage without mutating the original. */
|
|
70
|
+
namespace(prefix: string): Storage;
|
|
71
|
+
private _objectKey;
|
|
72
|
+
}
|
|
73
|
+
//# sourceMappingURL=s3-storage.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"s3-storage.d.ts","sourceRoot":"","sources":["../../../src/storage/s3-storage.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,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