@strands-agents/sdk 0.2.2 → 0.4.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/README.md +43 -0
- package/dist/src/__fixtures__/mock-hook-provider.d.ts +3 -7
- package/dist/src/__fixtures__/mock-hook-provider.d.ts.map +1 -1
- package/dist/src/__fixtures__/mock-hook-provider.js +3 -9
- package/dist/src/__fixtures__/mock-hook-provider.js.map +1 -1
- package/dist/src/__fixtures__/mock-message-model.d.ts +8 -2
- package/dist/src/__fixtures__/mock-message-model.d.ts.map +1 -1
- package/dist/src/__fixtures__/mock-message-model.js +1 -0
- package/dist/src/__fixtures__/mock-message-model.js.map +1 -1
- package/dist/src/__fixtures__/mock-storage-provider.d.ts +37 -0
- package/dist/src/__fixtures__/mock-storage-provider.d.ts.map +1 -0
- package/dist/src/__fixtures__/mock-storage-provider.js +105 -0
- package/dist/src/__fixtures__/mock-storage-provider.js.map +1 -0
- package/dist/src/__fixtures__/slim-types.d.ts +50 -0
- package/dist/src/__fixtures__/slim-types.d.ts.map +1 -0
- package/dist/src/__fixtures__/slim-types.js +6 -0
- package/dist/src/__fixtures__/slim-types.js.map +1 -0
- package/dist/src/__fixtures__/tool-helpers.d.ts +8 -3
- package/dist/src/__fixtures__/tool-helpers.d.ts.map +1 -1
- package/dist/src/__fixtures__/tool-helpers.js +1 -1
- package/dist/src/__fixtures__/tool-helpers.js.map +1 -1
- package/dist/src/agent/__tests__/agent.hook.test.js +18 -18
- package/dist/src/agent/__tests__/agent.hook.test.js.map +1 -1
- package/dist/src/agent/__tests__/agent.test.js +124 -8
- package/dist/src/agent/__tests__/agent.test.js.map +1 -1
- package/dist/src/agent/__tests__/printer.test.js +5 -9
- package/dist/src/agent/__tests__/printer.test.js.map +1 -1
- package/dist/src/agent/__tests__/snapshot.test.d.ts +2 -0
- package/dist/src/agent/__tests__/snapshot.test.d.ts.map +1 -0
- package/dist/src/agent/__tests__/snapshot.test.js +249 -0
- package/dist/src/agent/__tests__/snapshot.test.js.map +1 -0
- package/dist/src/agent/__tests__/state.test.js +19 -0
- package/dist/src/agent/__tests__/state.test.js.map +1 -1
- package/dist/src/agent/agent.d.ts +19 -4
- package/dist/src/agent/agent.d.ts.map +1 -1
- package/dist/src/agent/agent.js +104 -34
- package/dist/src/agent/agent.js.map +1 -1
- package/dist/src/agent/printer.d.ts +4 -0
- package/dist/src/agent/printer.d.ts.map +1 -1
- package/dist/src/agent/printer.js +18 -6
- package/dist/src/agent/printer.js.map +1 -1
- package/dist/src/agent/snapshot.d.ts +132 -0
- package/dist/src/agent/snapshot.d.ts.map +1 -0
- package/dist/src/agent/snapshot.js +151 -0
- package/dist/src/agent/snapshot.js.map +1 -0
- package/dist/src/agent/state.d.ts +14 -1
- package/dist/src/agent/state.d.ts.map +1 -1
- package/dist/src/agent/state.js +21 -0
- package/dist/src/agent/state.js.map +1 -1
- package/dist/src/errors.d.ts +15 -0
- package/dist/src/errors.d.ts.map +1 -1
- package/dist/src/errors.js +18 -0
- package/dist/src/errors.js.map +1 -1
- package/dist/src/hooks/__tests__/events.test.js +102 -21
- package/dist/src/hooks/__tests__/events.test.js.map +1 -1
- package/dist/src/hooks/events.d.ts +156 -22
- package/dist/src/hooks/events.d.ts.map +1 -1
- package/dist/src/hooks/events.js +158 -18
- package/dist/src/hooks/events.js.map +1 -1
- package/dist/src/hooks/index.d.ts +12 -4
- package/dist/src/hooks/index.d.ts.map +1 -1
- package/dist/src/hooks/index.js +11 -3
- package/dist/src/hooks/index.js.map +1 -1
- package/dist/src/hooks/registry.d.ts +5 -5
- package/dist/src/hooks/registry.d.ts.map +1 -1
- package/dist/src/hooks/registry.js.map +1 -1
- package/dist/src/hooks/types.d.ts +5 -5
- package/dist/src/hooks/types.d.ts.map +1 -1
- package/dist/src/index.d.ts +4 -2
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +4 -3
- package/dist/src/index.js.map +1 -1
- package/dist/src/models/__tests__/anthropic.test.js +31 -42
- package/dist/src/models/__tests__/anthropic.test.js.map +1 -1
- package/dist/src/models/__tests__/bedrock.test.js +70 -107
- package/dist/src/models/__tests__/bedrock.test.js.map +1 -1
- package/dist/src/models/__tests__/gemini.test.js +438 -141
- package/dist/src/models/__tests__/gemini.test.js.map +1 -1
- package/dist/src/models/__tests__/model.test.js +14 -13
- package/dist/src/models/__tests__/model.test.js.map +1 -1
- package/dist/src/models/__tests__/openai.test.js +73 -83
- package/dist/src/models/__tests__/openai.test.js.map +1 -1
- package/dist/src/models/gemini/adapters.d.ts +2 -1
- package/dist/src/models/gemini/adapters.d.ts.map +1 -1
- package/dist/src/models/gemini/adapters.js +97 -10
- package/dist/src/models/gemini/adapters.js.map +1 -1
- package/dist/src/models/gemini/model.d.ts.map +1 -1
- package/dist/src/models/gemini/model.js +37 -1
- package/dist/src/models/gemini/model.js.map +1 -1
- package/dist/src/models/gemini/types.d.ts +9 -1
- package/dist/src/models/gemini/types.d.ts.map +1 -1
- package/dist/src/models/model.d.ts.map +1 -1
- package/dist/src/models/model.js +4 -0
- package/dist/src/models/model.js.map +1 -1
- package/dist/src/models/streaming.d.ts +13 -0
- package/dist/src/models/streaming.d.ts.map +1 -1
- package/dist/src/models/streaming.js +17 -0
- package/dist/src/models/streaming.js.map +1 -1
- package/dist/src/multiagent/__tests__/nodes.test.d.ts +2 -0
- package/dist/src/multiagent/__tests__/nodes.test.d.ts.map +1 -0
- package/dist/src/multiagent/__tests__/nodes.test.js +98 -0
- package/dist/src/multiagent/__tests__/nodes.test.js.map +1 -0
- package/dist/src/multiagent/events.d.ts +24 -0
- package/dist/src/multiagent/events.d.ts.map +1 -0
- package/dist/src/multiagent/events.js +19 -0
- package/dist/src/multiagent/events.js.map +1 -0
- package/dist/src/multiagent/index.d.ts +11 -0
- package/dist/src/multiagent/index.d.ts.map +1 -0
- package/dist/src/multiagent/index.js +7 -0
- package/dist/src/multiagent/index.js.map +1 -0
- package/dist/src/multiagent/nodes.d.ts +75 -0
- package/dist/src/multiagent/nodes.d.ts.map +1 -0
- package/dist/src/multiagent/nodes.js +101 -0
- package/dist/src/multiagent/nodes.js.map +1 -0
- package/dist/src/multiagent/state.d.ts +55 -0
- package/dist/src/multiagent/state.d.ts.map +1 -0
- package/dist/src/multiagent/state.js +43 -0
- package/dist/src/multiagent/state.js.map +1 -0
- package/dist/src/multiagent/types.d.ts +5 -0
- package/dist/src/multiagent/types.d.ts.map +1 -0
- package/dist/src/multiagent/types.js +2 -0
- package/dist/src/multiagent/types.js.map +1 -0
- package/dist/src/registry/tool-registry.d.ts +2 -1
- package/dist/src/registry/tool-registry.d.ts.map +1 -1
- package/dist/src/registry/tool-registry.js +4 -2
- package/dist/src/registry/tool-registry.js.map +1 -1
- package/dist/src/session/__tests__/file-storage.test.node.d.ts +2 -0
- package/dist/src/session/__tests__/file-storage.test.node.d.ts.map +1 -0
- package/dist/src/session/__tests__/file-storage.test.node.js +218 -0
- package/dist/src/session/__tests__/file-storage.test.node.js.map +1 -0
- package/dist/src/session/__tests__/s3-storage.test.node.d.ts +2 -0
- package/dist/src/session/__tests__/s3-storage.test.node.d.ts.map +1 -0
- package/dist/src/session/__tests__/s3-storage.test.node.js +375 -0
- package/dist/src/session/__tests__/s3-storage.test.node.js.map +1 -0
- package/dist/src/session/__tests__/validation.test.d.ts +2 -0
- package/dist/src/session/__tests__/validation.test.d.ts.map +1 -0
- package/dist/src/session/__tests__/validation.test.js +20 -0
- package/dist/src/session/__tests__/validation.test.js.map +1 -0
- package/dist/src/session/file-storage.d.ts +79 -0
- package/dist/src/session/file-storage.d.ts.map +1 -0
- package/dist/src/session/file-storage.js +144 -0
- package/dist/src/session/file-storage.js.map +1 -0
- package/dist/src/session/index.d.ts +19 -0
- package/dist/src/session/index.d.ts.map +1 -0
- package/dist/src/session/index.js +18 -0
- package/dist/src/session/index.js.map +1 -0
- package/dist/src/session/s3-storage.d.ts +93 -0
- package/dist/src/session/s3-storage.d.ts.map +1 -0
- package/dist/src/session/s3-storage.js +150 -0
- package/dist/src/session/s3-storage.js.map +1 -0
- package/dist/src/session/storage.d.ts +91 -0
- package/dist/src/session/storage.d.ts.map +1 -0
- package/dist/src/session/storage.js +2 -0
- package/dist/src/session/storage.js.map +1 -0
- package/dist/src/session/types.d.ts +49 -0
- package/dist/src/session/types.d.ts.map +1 -0
- package/dist/src/session/types.js +2 -0
- package/dist/src/session/types.js.map +1 -0
- package/dist/src/session/validation.d.ts +10 -0
- package/dist/src/session/validation.d.ts.map +1 -0
- package/dist/src/session/validation.js +16 -0
- package/dist/src/session/validation.js.map +1 -0
- package/dist/src/structured-output/__tests__/context.test.d.ts +2 -0
- package/dist/src/structured-output/__tests__/context.test.d.ts.map +1 -0
- package/dist/src/structured-output/__tests__/context.test.js +201 -0
- package/dist/src/structured-output/__tests__/context.test.js.map +1 -0
- package/dist/src/structured-output/__tests__/exceptions.test.d.ts +2 -0
- package/dist/src/structured-output/__tests__/exceptions.test.d.ts.map +1 -0
- package/dist/src/structured-output/__tests__/exceptions.test.js +103 -0
- package/dist/src/structured-output/__tests__/exceptions.test.js.map +1 -0
- package/dist/src/structured-output/__tests__/tool.test.d.ts +2 -0
- package/dist/src/structured-output/__tests__/tool.test.d.ts.map +1 -0
- package/dist/src/structured-output/__tests__/tool.test.js +256 -0
- package/dist/src/structured-output/__tests__/tool.test.js.map +1 -0
- package/dist/src/structured-output/__tests__/utils.test.d.ts +2 -0
- package/dist/src/structured-output/__tests__/utils.test.d.ts.map +1 -0
- package/dist/src/structured-output/__tests__/utils.test.js +183 -0
- package/dist/src/structured-output/__tests__/utils.test.js.map +1 -0
- package/dist/src/structured-output/context.d.ts +91 -0
- package/dist/src/structured-output/context.d.ts.map +1 -0
- package/dist/src/structured-output/context.js +112 -0
- package/dist/src/structured-output/context.js.map +1 -0
- package/dist/src/structured-output/exceptions.d.ts +18 -0
- package/dist/src/structured-output/exceptions.d.ts.map +1 -0
- package/dist/src/structured-output/exceptions.js +28 -0
- package/dist/src/structured-output/exceptions.js.map +1 -0
- package/dist/src/structured-output/tool.d.ts +33 -0
- package/dist/src/structured-output/tool.d.ts.map +1 -0
- package/dist/src/structured-output/tool.js +73 -0
- package/dist/src/structured-output/tool.js.map +1 -0
- package/dist/src/structured-output/utils.d.ts +23 -0
- package/dist/src/structured-output/utils.d.ts.map +1 -0
- package/dist/src/structured-output/utils.js +104 -0
- package/dist/src/structured-output/utils.js.map +1 -0
- package/dist/src/tools/zod-tool.d.ts.map +1 -1
- package/dist/src/tools/zod-tool.js +2 -5
- package/dist/src/tools/zod-tool.js.map +1 -1
- package/dist/src/tsconfig.tsbuildinfo +1 -1
- package/dist/src/types/__tests__/media.test.js +216 -1
- package/dist/src/types/__tests__/media.test.js.map +1 -1
- package/dist/src/types/__tests__/messages.test.js +193 -4
- package/dist/src/types/__tests__/messages.test.js.map +1 -1
- package/dist/src/types/agent.d.ts +13 -7
- package/dist/src/types/agent.d.ts.map +1 -1
- package/dist/src/types/agent.js +8 -1
- package/dist/src/types/agent.js.map +1 -1
- package/dist/src/types/json.d.ts +61 -0
- package/dist/src/types/json.d.ts.map +1 -1
- package/dist/src/types/json.js +24 -0
- package/dist/src/types/json.js.map +1 -1
- package/dist/src/types/media.d.ts +84 -4
- package/dist/src/types/media.d.ts.map +1 -1
- package/dist/src/types/media.js +194 -0
- package/dist/src/types/media.js.map +1 -1
- package/dist/src/types/messages.d.ts +158 -9
- package/dist/src/types/messages.d.ts.map +1 -1
- package/dist/src/types/messages.js +242 -7
- package/dist/src/types/messages.js.map +1 -1
- package/dist/src/types/serializable.d.ts +31 -0
- package/dist/src/types/serializable.d.ts.map +1 -0
- package/dist/src/types/serializable.js +19 -0
- package/dist/src/types/serializable.js.map +1 -0
- package/dist/src/utils/zod.d.ts +11 -0
- package/dist/src/utils/zod.d.ts.map +1 -0
- package/dist/src/utils/zod.js +14 -0
- package/dist/src/utils/zod.js.map +1 -0
- package/dist/src/vended-tools/bash/__tests__/bash.test.node.d.ts +2 -0
- package/dist/src/vended-tools/bash/__tests__/bash.test.node.d.ts.map +1 -0
- package/dist/src/vended-tools/bash/__tests__/{bash.test.js → bash.test.node.js} +3 -4
- package/dist/src/vended-tools/bash/__tests__/bash.test.node.js.map +1 -0
- package/dist/src/vended-tools/file_editor/__tests__/file-editor.test.node.d.ts +2 -0
- package/dist/src/vended-tools/file_editor/__tests__/file-editor.test.node.d.ts.map +1 -0
- package/dist/src/vended-tools/file_editor/__tests__/{file-editor.test.js → file-editor.test.node.js} +1 -1
- package/dist/src/vended-tools/file_editor/__tests__/file-editor.test.node.js.map +1 -0
- package/package.json +7 -2
- package/dist/src/vended-tools/bash/__tests__/bash.test.d.ts +0 -2
- package/dist/src/vended-tools/bash/__tests__/bash.test.d.ts.map +0 -1
- package/dist/src/vended-tools/bash/__tests__/bash.test.js.map +0 -1
- package/dist/src/vended-tools/file_editor/__tests__/file-editor.test.d.ts +0 -2
- package/dist/src/vended-tools/file_editor/__tests__/file-editor.test.d.ts.map +0 -1
- package/dist/src/vended-tools/file_editor/__tests__/file-editor.test.js.map +0 -1
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
import { promises as fs } from 'fs';
|
|
2
|
+
import { join, dirname } from 'path';
|
|
3
|
+
import { SessionError } from '../errors.js';
|
|
4
|
+
import { validateIdentifier } from './validation.js';
|
|
5
|
+
const MANIFEST = 'manifest.json';
|
|
6
|
+
const SNAPSHOT_LATEST = 'snapshot_latest.json';
|
|
7
|
+
const IMMUTABLE_HISTORY = 'immutable_history';
|
|
8
|
+
const SNAPSHOT_REGEX = /snapshot_(\d+)\.json$/;
|
|
9
|
+
const SCHEMA_VERSION = '1.0';
|
|
10
|
+
const DEFAULT_SNAPSHOT_ID = '1';
|
|
11
|
+
/**
|
|
12
|
+
* File-based implementation of SnapshotStorage for persisting session snapshots
|
|
13
|
+
*/
|
|
14
|
+
export class FileStorage {
|
|
15
|
+
/** Base directory path */
|
|
16
|
+
_baseDir;
|
|
17
|
+
/**
|
|
18
|
+
* Creates new FileStorage instance
|
|
19
|
+
* @param baseDir - Base directory path for storing snapshots
|
|
20
|
+
*/
|
|
21
|
+
constructor(baseDir) {
|
|
22
|
+
this._baseDir = baseDir;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Generates file path for session scope snapshots
|
|
26
|
+
*/
|
|
27
|
+
_getPath(location, filename) {
|
|
28
|
+
validateIdentifier(location.sessionId);
|
|
29
|
+
validateIdentifier(location.scopeId);
|
|
30
|
+
return join(this._baseDir, location.sessionId, 'scopes', location.scope, location.scopeId, 'snapshots', filename);
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Saves snapshot to file, optionally marking as latest
|
|
34
|
+
*/
|
|
35
|
+
async saveSnapshot(params) {
|
|
36
|
+
await this._writeJSON(this._getHistorySnapshotPath(params.location, params.snapshotId), params.snapshot);
|
|
37
|
+
if (params.isLatest) {
|
|
38
|
+
await this._writeJSON(this._getLatestSnapshotPath(params.location), params.snapshot);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Loads snapshot by ID or latest if null
|
|
43
|
+
*/
|
|
44
|
+
async loadSnapshot(params) {
|
|
45
|
+
const path = params.snapshotId === undefined
|
|
46
|
+
? this._getLatestSnapshotPath(params.location)
|
|
47
|
+
: this._getHistorySnapshotPath(params.location, params.snapshotId);
|
|
48
|
+
return this._readJSON(path);
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Checks if an error is a file not found error (ENOENT)
|
|
52
|
+
*/
|
|
53
|
+
_isFileNotFoundError(error) {
|
|
54
|
+
return error !== null && typeof error === 'object' && 'code' in error && error.code === 'ENOENT';
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Lists all snapshot IDs for a session scope.
|
|
58
|
+
*
|
|
59
|
+
* TODO: Add pagination support for long-running agents with many snapshots.
|
|
60
|
+
* Future signature could be:
|
|
61
|
+
* ```typescript
|
|
62
|
+
* listSnapshots(params: {
|
|
63
|
+
* sessionId: string
|
|
64
|
+
* scope: Scope
|
|
65
|
+
* limit?: number // Max results to return (e.g., 100)
|
|
66
|
+
* startAfter?: string // Snapshot ID to start after (for cursor-based pagination)
|
|
67
|
+
* }): Promise<{ snapshotIds: string[]; nextToken?: string }>
|
|
68
|
+
* ```
|
|
69
|
+
*/
|
|
70
|
+
async listSnapshotIds(params) {
|
|
71
|
+
const dirPath = this._getPath(params.location, IMMUTABLE_HISTORY);
|
|
72
|
+
try {
|
|
73
|
+
const files = await fs.readdir(dirPath);
|
|
74
|
+
return files
|
|
75
|
+
.map((file) => file.match(SNAPSHOT_REGEX)?.[1])
|
|
76
|
+
.filter((id) => id !== undefined)
|
|
77
|
+
.sort((a, b) => parseInt(a) - parseInt(b));
|
|
78
|
+
}
|
|
79
|
+
catch (error) {
|
|
80
|
+
if (this._isFileNotFoundError(error)) {
|
|
81
|
+
return [];
|
|
82
|
+
}
|
|
83
|
+
throw new SessionError(`Failed to list snapshots for session ${params.location.sessionId}`, { cause: error });
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Loads manifest or returns default if not found
|
|
88
|
+
*/
|
|
89
|
+
async loadManifest(params) {
|
|
90
|
+
const path = this._getPath(params.location, MANIFEST);
|
|
91
|
+
const manifest = await this._readJSON(path);
|
|
92
|
+
return (manifest ?? {
|
|
93
|
+
schemaVersion: SCHEMA_VERSION,
|
|
94
|
+
nextSnapshotId: DEFAULT_SNAPSHOT_ID,
|
|
95
|
+
updatedAt: new Date().toISOString(),
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Saves manifest to file
|
|
100
|
+
*/
|
|
101
|
+
async saveManifest(params) {
|
|
102
|
+
const path = this._getPath(params.location, MANIFEST);
|
|
103
|
+
await this._writeJSON(path, params.manifest);
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Writes JSON data to file atomically
|
|
107
|
+
*/
|
|
108
|
+
async _writeJSON(path, data) {
|
|
109
|
+
try {
|
|
110
|
+
await fs.mkdir(dirname(path), { recursive: true });
|
|
111
|
+
const tmpPath = `${path}.tmp`;
|
|
112
|
+
await fs.writeFile(tmpPath, JSON.stringify(data, null, 2), 'utf8');
|
|
113
|
+
await fs.rename(tmpPath, path);
|
|
114
|
+
}
|
|
115
|
+
catch (error) {
|
|
116
|
+
throw new SessionError(`Failed to write file ${path}`, { cause: error });
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Reads and parses JSON from file
|
|
121
|
+
*/
|
|
122
|
+
async _readJSON(path) {
|
|
123
|
+
try {
|
|
124
|
+
const content = await fs.readFile(path, 'utf8');
|
|
125
|
+
return JSON.parse(content);
|
|
126
|
+
}
|
|
127
|
+
catch (error) {
|
|
128
|
+
if (this._isFileNotFoundError(error)) {
|
|
129
|
+
return null;
|
|
130
|
+
}
|
|
131
|
+
if (error instanceof SyntaxError) {
|
|
132
|
+
throw new SessionError(`Invalid JSON in file ${path}`, { cause: error });
|
|
133
|
+
}
|
|
134
|
+
throw new SessionError(`File system error reading ${path}`, { cause: error });
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
_getLatestSnapshotPath(location) {
|
|
138
|
+
return this._getPath(location, SNAPSHOT_LATEST);
|
|
139
|
+
}
|
|
140
|
+
_getHistorySnapshotPath(location, snapshotId) {
|
|
141
|
+
return this._getPath(location, `${IMMUTABLE_HISTORY}/snapshot_${String(snapshotId).padStart(5, '0')}.json`);
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
//# sourceMappingURL=file-storage.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"file-storage.js","sourceRoot":"","sources":["../../../src/session/file-storage.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,IAAI,EAAE,EAAE,MAAM,IAAI,CAAA;AACnC,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,MAAM,CAAA;AAIpC,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CA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,IAAI,EAAE,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC,CAAA;QAC1E,CAAC;IACH,CAAC;IAED;;OAEG;IACK,KAAK,CAAC,SAAS,CAAI,IAAY;QACrC,IAAI,CAAC;YACH,MAAM,OAAO,GAAG,MAAM,EAAE,CAAC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC,CAAA;YAC/C,OAAO,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CAAA;QAC5B,CAAC;QAAC,OAAO,KAAc,EAAE,CAAC;YACxB,IAAI,IAAI,CAAC,oBAAoB,CAAC,KAAK,CAAC,EAAE,CAAC;gBACrC,OAAO,IAAI,CAAA;YACb,CAAC;YACD,IAAI,KAAK,YAAY,WAAW,EAAE,CAAC;gBACjC,MAAM,IAAI,YAAY,CAAC,wBAAwB,IAAI,EAAE,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC,CAAA;YAC1E,CAAC;YACD,MAAM,IAAI,YAAY,CAAC,6BAA6B,IAAI,EAAE,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC,CAAA;QAC/E,CAAC;IACH,CAAC;IAEO,sBAAsB,CAAC,QAA0B;QACvD,OAAO,IAAI,CAAC,QAAQ,CAAC,QAAQ,EAAE,eAAe,CAAC,CAAA;IACjD,CAAC;IAEO,uBAAuB,CAAC,QAA0B,EAAE,UAAkB;QAC5E,OAAO,IAAI,CAAC,QAAQ,CAAC,QAAQ,EAAE,GAAG,iBAAiB,aAAa,MAAM,CAAC,UAAU,CAAC,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,OAAO,CAAC,CAAA;IAC7G,CAAC;CACF"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Session management module for conversation persistence and restoration.
|
|
3
|
+
*
|
|
4
|
+
* Provides snapshot-based session management with pluggable storage backends.
|
|
5
|
+
* Supports conversation history, state persistence, and branching.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```typescript
|
|
9
|
+
* import { FileStorage, SnapshotStorage } from '@strands/agents/session'
|
|
10
|
+
*
|
|
11
|
+
* const storage = new FileStorage('./sessions')
|
|
12
|
+
* await storage.saveSnapshot({ sessionId, scope, isLatest: true, snapshot })
|
|
13
|
+
* ```
|
|
14
|
+
*/
|
|
15
|
+
export type { Scope, Snapshot, SnapshotManifest, SnapshotTriggerCallback } from './types.js';
|
|
16
|
+
export type { SessionStorage, SnapshotStorage, SnapshotLocation } from './storage.js';
|
|
17
|
+
export { FileStorage } from './file-storage.js';
|
|
18
|
+
export { S3Storage, type S3StorageConfig } from './s3-storage.js';
|
|
19
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/session/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAIH,YAAY,EAAE,KAAK,EAAE,QAAQ,EAAE,gBAAgB,EAAE,uBAAuB,EAAE,MAAM,YAAY,CAAA;AAG5F,YAAY,EAAE,cAAc,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAA;AAGrF,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAA;AAC/C,OAAO,EAAE,SAAS,EAAE,KAAK,eAAe,EAAE,MAAM,iBAAiB,CAAA"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Session management module for conversation persistence and restoration.
|
|
3
|
+
*
|
|
4
|
+
* Provides snapshot-based session management with pluggable storage backends.
|
|
5
|
+
* Supports conversation history, state persistence, and branching.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```typescript
|
|
9
|
+
* import { FileStorage, SnapshotStorage } from '@strands/agents/session'
|
|
10
|
+
*
|
|
11
|
+
* const storage = new FileStorage('./sessions')
|
|
12
|
+
* await storage.saveSnapshot({ sessionId, scope, isLatest: true, snapshot })
|
|
13
|
+
* ```
|
|
14
|
+
*/
|
|
15
|
+
// Storage implementations
|
|
16
|
+
export { FileStorage } from './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/session/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AASH,0BAA0B;AAC1B,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAA;AAC/C,OAAO,EAAE,SAAS,EAAwB,MAAM,iBAAiB,CAAA"}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { S3Client } from '@aws-sdk/client-s3';
|
|
2
|
+
import type { SnapshotStorage, SnapshotLocation } from './storage.js';
|
|
3
|
+
import type { Snapshot, SnapshotManifest } from './types.js';
|
|
4
|
+
/**
|
|
5
|
+
* Configuration options for S3Storage
|
|
6
|
+
*/
|
|
7
|
+
export type S3StorageConfig = {
|
|
8
|
+
/** S3 bucket name */
|
|
9
|
+
bucket: string;
|
|
10
|
+
/** Optional key prefix for all objects */
|
|
11
|
+
prefix?: string;
|
|
12
|
+
/** AWS region (default: us-east-1). Cannot be used with s3Client */
|
|
13
|
+
region?: string;
|
|
14
|
+
/** Pre-configured S3 client. Cannot be used with region */
|
|
15
|
+
s3Client?: S3Client;
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* S3-based implementation of SnapshotStorage for persisting session snapshots
|
|
19
|
+
*/
|
|
20
|
+
export declare class S3Storage implements SnapshotStorage {
|
|
21
|
+
/** S3 client instance */
|
|
22
|
+
private readonly _s3;
|
|
23
|
+
/** S3 bucket name */
|
|
24
|
+
private readonly _bucket;
|
|
25
|
+
/** Key prefix for all objects */
|
|
26
|
+
private readonly _prefix;
|
|
27
|
+
/**
|
|
28
|
+
* Creates new S3Storage instance
|
|
29
|
+
* @param config - Configuration options
|
|
30
|
+
*/
|
|
31
|
+
constructor(config: S3StorageConfig);
|
|
32
|
+
/**
|
|
33
|
+
* Generates S3 key path for session scope snapshots
|
|
34
|
+
*/
|
|
35
|
+
private _getKey;
|
|
36
|
+
/**
|
|
37
|
+
* Saves snapshot to S3, optionally marking as latest
|
|
38
|
+
*/
|
|
39
|
+
saveSnapshot(params: {
|
|
40
|
+
location: SnapshotLocation;
|
|
41
|
+
snapshotId: string;
|
|
42
|
+
isLatest: boolean;
|
|
43
|
+
snapshot: Snapshot;
|
|
44
|
+
}): Promise<void>;
|
|
45
|
+
/**
|
|
46
|
+
* Loads snapshot by ID or latest if undefined
|
|
47
|
+
*/
|
|
48
|
+
loadSnapshot(params: {
|
|
49
|
+
location: SnapshotLocation;
|
|
50
|
+
snapshotId?: string;
|
|
51
|
+
}): Promise<Snapshot | null>;
|
|
52
|
+
/**
|
|
53
|
+
* Lists all snapshot IDs for a session scope.
|
|
54
|
+
*
|
|
55
|
+
* TODO: Add pagination support for long-running agents with many snapshots.
|
|
56
|
+
* Future signature could be:
|
|
57
|
+
* ```typescript
|
|
58
|
+
* listSnapshots(params: {
|
|
59
|
+
* sessionId: string
|
|
60
|
+
* scope: Scope
|
|
61
|
+
* limit?: number // Max results to return (e.g., 100)
|
|
62
|
+
* startAfter?: string // Snapshot ID to start after (for cursor-based pagination)
|
|
63
|
+
* }): Promise<{ snapshotIds: string[]; nextToken?: string }>
|
|
64
|
+
* ```
|
|
65
|
+
*/
|
|
66
|
+
listSnapshotIds(params: {
|
|
67
|
+
location: SnapshotLocation;
|
|
68
|
+
}): Promise<string[]>;
|
|
69
|
+
/**
|
|
70
|
+
* Loads manifest or returns default if not found
|
|
71
|
+
*/
|
|
72
|
+
loadManifest(params: {
|
|
73
|
+
location: SnapshotLocation;
|
|
74
|
+
}): Promise<SnapshotManifest>;
|
|
75
|
+
/**
|
|
76
|
+
* Saves manifest to S3
|
|
77
|
+
*/
|
|
78
|
+
saveManifest(params: {
|
|
79
|
+
location: SnapshotLocation;
|
|
80
|
+
manifest: SnapshotManifest;
|
|
81
|
+
}): Promise<void>;
|
|
82
|
+
/**
|
|
83
|
+
* Writes JSON data to S3
|
|
84
|
+
*/
|
|
85
|
+
private _writeJSON;
|
|
86
|
+
/**
|
|
87
|
+
* Reads and parses JSON from S3
|
|
88
|
+
*/
|
|
89
|
+
private _readJSON;
|
|
90
|
+
private _getLatestSnapshotKey;
|
|
91
|
+
private _getHistorySnapshotKey;
|
|
92
|
+
}
|
|
93
|
+
//# sourceMappingURL=s3-storage.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"s3-storage.d.ts","sourceRoot":"","sources":["../../../src/session/s3-storage.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAA4D,MAAM,oBAAoB,CAAA;AAEvG,OAAO,KAAK,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAA;AACrE,OAAO,KAAK,EAAE,QAAQ,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAA;AAW5D;;GAEG;AACH,MAAM,MAAM,eAAe,GAAG;IAC5B,qBAAqB;IACrB,MAAM,EAAE,MAAM,CAAA;IACd,0CAA0C;IAC1C,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,oEAAoE;IACpE,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,2DAA2D;IAC3D,QAAQ,CAAC,EAAE,QAAQ,CAAA;CACpB,CAAA;AAED;;GAEG;AACH,qBAAa,SAAU,YAAW,eAAe;IAC/C,yBAAyB;IACzB,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAU;IAC9B,qBAAqB;IACrB,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAQ;IAChC,iCAAiC;IACjC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAQ;IAEhC;;;OAGG;gBACS,MAAM,EAAE,eAAe;IAUnC;;OAEG;IACH,OAAO,CAAC,OAAO;IAOf;;OAEG;IACG,YAAY,CAAC,MAAM,EAAE;QACzB,QAAQ,EAAE,gBAAgB,CAAA;QAC1B,UAAU,EAAE,MAAM,CAAA;QAClB,QAAQ,EAAE,OAAO,CAAA;QACjB,QAAQ,EAAE,QAAQ,CAAA;KACnB,GAAG,OAAO,CAAC,IAAI,CAAC;IAOjB;;OAEG;IACG,YAAY,CAAC,MAAM,EAAE;QAAE,QAAQ,EAAE,gBAAgB,CAAC;QAAC,UAAU,CAAC,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,QAAQ,GAAG,IAAI,CAAC;IAQzG;;;;;;;;;;;;;OAaG;IACG,eAAe,CAAC,MAAM,EAAE;QAAE,QAAQ,EAAE,gBAAgB,CAAA;KAAE,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC;IAgBhF;;OAEG;IACG,YAAY,CAAC,MAAM,EAAE;QAAE,QAAQ,EAAE,gBAAgB,CAAA;KAAE,GAAG,OAAO,CAAC,gBAAgB,CAAC;IAarF;;OAEG;IACG,YAAY,CAAC,MAAM,EAAE;QAAE,QAAQ,EAAE,gBAAgB,CAAC;QAAC,QAAQ,EAAE,gBAAgB,CAAA;KAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IAKrG;;OAEG;YACW,UAAU;IAexB;;OAEG;YACW,SAAS;IAiBvB,OAAO,CAAC,qBAAqB;IAI7B,OAAO,CAAC,sBAAsB;CAG/B"}
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
import { S3Client, PutObjectCommand, GetObjectCommand, ListObjectsV2Command } from '@aws-sdk/client-s3';
|
|
2
|
+
import { SessionError } from '../errors.js';
|
|
3
|
+
import { validateIdentifier } from './validation.js';
|
|
4
|
+
const MANIFEST = 'manifest.json';
|
|
5
|
+
const SNAPSHOT_LATEST = 'snapshot_latest.json';
|
|
6
|
+
const IMMUTABLE_HISTORY = 'immutable_history/';
|
|
7
|
+
const SNAPSHOT_REGEX = /snapshot_(\d+)\.json$/;
|
|
8
|
+
const SCHEMA_VERSION = '1.0';
|
|
9
|
+
const DEFAULT_SNAPSHOT_ID = '1';
|
|
10
|
+
/**
|
|
11
|
+
* S3-based implementation of SnapshotStorage for persisting session snapshots
|
|
12
|
+
*/
|
|
13
|
+
export class S3Storage {
|
|
14
|
+
/** S3 client instance */
|
|
15
|
+
_s3;
|
|
16
|
+
/** S3 bucket name */
|
|
17
|
+
_bucket;
|
|
18
|
+
/** Key prefix for all objects */
|
|
19
|
+
_prefix;
|
|
20
|
+
/**
|
|
21
|
+
* Creates new S3Storage instance
|
|
22
|
+
* @param config - Configuration options
|
|
23
|
+
*/
|
|
24
|
+
constructor(config) {
|
|
25
|
+
if (config.s3Client && config.region) {
|
|
26
|
+
throw new SessionError('Cannot specify both s3Client and region. Configure region in the S3Client instead.');
|
|
27
|
+
}
|
|
28
|
+
this._bucket = config.bucket;
|
|
29
|
+
this._prefix = config.prefix ?? '';
|
|
30
|
+
this._s3 = config.s3Client ?? new S3Client({ region: config.region ?? 'us-east-1' });
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Generates S3 key path for session scope snapshots
|
|
34
|
+
*/
|
|
35
|
+
_getKey(location, path) {
|
|
36
|
+
validateIdentifier(location.sessionId);
|
|
37
|
+
validateIdentifier(location.scopeId);
|
|
38
|
+
const base = this._prefix ? `${this._prefix}/` : '';
|
|
39
|
+
return `${base}${location.sessionId}/scopes/${location.scope}/${location.scopeId}/snapshots/${path}`;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Saves snapshot to S3, optionally marking as latest
|
|
43
|
+
*/
|
|
44
|
+
async saveSnapshot(params) {
|
|
45
|
+
await this._writeJSON(this._getHistorySnapshotKey(params.location, params.snapshotId), params.snapshot);
|
|
46
|
+
if (params.isLatest) {
|
|
47
|
+
await this._writeJSON(this._getLatestSnapshotKey(params.location), params.snapshot);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Loads snapshot by ID or latest if undefined
|
|
52
|
+
*/
|
|
53
|
+
async loadSnapshot(params) {
|
|
54
|
+
const key = params.snapshotId === undefined
|
|
55
|
+
? this._getLatestSnapshotKey(params.location)
|
|
56
|
+
: this._getHistorySnapshotKey(params.location, params.snapshotId);
|
|
57
|
+
return this._readJSON(key);
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Lists all snapshot IDs for a session scope.
|
|
61
|
+
*
|
|
62
|
+
* TODO: Add pagination support for long-running agents with many snapshots.
|
|
63
|
+
* Future signature could be:
|
|
64
|
+
* ```typescript
|
|
65
|
+
* listSnapshots(params: {
|
|
66
|
+
* sessionId: string
|
|
67
|
+
* scope: Scope
|
|
68
|
+
* limit?: number // Max results to return (e.g., 100)
|
|
69
|
+
* startAfter?: string // Snapshot ID to start after (for cursor-based pagination)
|
|
70
|
+
* }): Promise<{ snapshotIds: string[]; nextToken?: string }>
|
|
71
|
+
* ```
|
|
72
|
+
*/
|
|
73
|
+
async listSnapshotIds(params) {
|
|
74
|
+
const prefix = this._getKey(params.location, IMMUTABLE_HISTORY);
|
|
75
|
+
try {
|
|
76
|
+
const response = await this._s3.send(new ListObjectsV2Command({ Bucket: this._bucket, Prefix: prefix }));
|
|
77
|
+
return (response.Contents ?? [])
|
|
78
|
+
.map((obj) => obj.Key?.match(SNAPSHOT_REGEX)?.[1])
|
|
79
|
+
.filter((id) => id !== undefined)
|
|
80
|
+
.map((id) => String(parseInt(id)))
|
|
81
|
+
.sort((a, b) => parseInt(a) - parseInt(b));
|
|
82
|
+
}
|
|
83
|
+
catch (error) {
|
|
84
|
+
throw new SessionError(`Failed to list snapshots for session ${params.location.sessionId}`, { cause: error });
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Loads manifest or returns default if not found
|
|
89
|
+
*/
|
|
90
|
+
async loadManifest(params) {
|
|
91
|
+
const key = this._getKey(params.location, MANIFEST);
|
|
92
|
+
const manifest = await this._readJSON(key);
|
|
93
|
+
return (manifest ?? {
|
|
94
|
+
schemaVersion: SCHEMA_VERSION,
|
|
95
|
+
nextSnapshotId: DEFAULT_SNAPSHOT_ID,
|
|
96
|
+
updatedAt: new Date().toISOString(),
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Saves manifest to S3
|
|
101
|
+
*/
|
|
102
|
+
async saveManifest(params) {
|
|
103
|
+
const key = this._getKey(params.location, MANIFEST);
|
|
104
|
+
await this._writeJSON(key, params.manifest);
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Writes JSON data to S3
|
|
108
|
+
*/
|
|
109
|
+
async _writeJSON(key, data) {
|
|
110
|
+
try {
|
|
111
|
+
await this._s3.send(new PutObjectCommand({
|
|
112
|
+
Bucket: this._bucket,
|
|
113
|
+
Key: key,
|
|
114
|
+
Body: JSON.stringify(data, null, 2),
|
|
115
|
+
ContentType: 'application/json',
|
|
116
|
+
}));
|
|
117
|
+
}
|
|
118
|
+
catch (error) {
|
|
119
|
+
throw new SessionError(`Failed to write S3 object ${key}`, { cause: error });
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Reads and parses JSON from S3
|
|
124
|
+
*/
|
|
125
|
+
async _readJSON(key) {
|
|
126
|
+
try {
|
|
127
|
+
const response = await this._s3.send(new GetObjectCommand({ Bucket: this._bucket, Key: key }));
|
|
128
|
+
const body = await response.Body?.transformToString();
|
|
129
|
+
if (!body)
|
|
130
|
+
return null;
|
|
131
|
+
return JSON.parse(body);
|
|
132
|
+
}
|
|
133
|
+
catch (error) {
|
|
134
|
+
if (error && typeof error === 'object' && 'name' in error && error.name === 'NoSuchKey') {
|
|
135
|
+
return null;
|
|
136
|
+
}
|
|
137
|
+
if (error instanceof SyntaxError) {
|
|
138
|
+
throw new SessionError(`Invalid JSON in S3 object ${key}`, { cause: error });
|
|
139
|
+
}
|
|
140
|
+
throw new SessionError(`S3 error reading ${key}`, { cause: error });
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
_getLatestSnapshotKey(location) {
|
|
144
|
+
return this._getKey(location, SNAPSHOT_LATEST);
|
|
145
|
+
}
|
|
146
|
+
_getHistorySnapshotKey(location, snapshotId) {
|
|
147
|
+
return this._getKey(location, `${IMMUTABLE_HISTORY}snapshot_${String(snapshotId).padStart(5, '0')}.json`);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
//# sourceMappingURL=s3-storage.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"s3-storage.js","sourceRoot":"","sources":["../../../src/session/s3-storage.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,oBAAoB,EAAE,MAAM,oBAAoB,CAAA;AAIvG,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAA;AAC3C,OAAO,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAA;AAEpD,MAAM,QAAQ,GAAG,eAAe,CAAA;AAChC,MAAM,eAAe,GAAG,sBAAsB,CAAA;AAC9C,MAAM,iBAAiB,GAAG,oBAAoB,CAAA;AAC9C,MAAM,cAAc,GAAG,uBAAuB,CAAA;AAC9C,MAAM,cAAc,GAAG,KAAK,CAAA;AAC5B,MAAM,mBAAmB,GAAG,GAAG,CAAA;AAgB/B;;GAEG;AACH,MAAM,OAAO,SAAS;IACpB,yBAAyB;IACR,GAAG,CAAU;IAC9B,qBAAqB;IACJ,OAAO,CAAQ;IAChC,iCAAiC;IAChB,OAAO,CAAQ;IAEhC;;;OAGG;IACH,YAAY,MAAuB;QACjC,IAAI,MAAM,CAAC,QAAQ,IAAI,MAAM,CAAC,MAAM,EAAE,CAAC;YACrC,MAAM,IAAI,YAAY,CAAC,oFAAoF,CAAC,CAAA;QAC9G,CAAC;QAED,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC,MAAM,CAAA;QAC5B,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC,MAAM,IAAI,EAAE,CAAA;QAClC,IAAI,CAAC,GAAG,GAAG,MAAM,CAAC,QAAQ,IAAI,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CAAC,IAAI;gBAAE,OAAO,IAAI,CAAA;YACtB,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAA;QACzB,CAAC;QAAC,OAAO,KAAc,EAAE,CAAC;YACxB,IAAI,KAAK,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,MAAM,IAAI,KAAK,IAAI,KAAK,CAAC,IAAI,KAAK,WAAW,EAAE,CAAC;gBACxF,OAAO,IAAI,CAAA;YACb,CAAC;YACD,IAAI,KAAK,YAAY,WAAW,EAAE,CAAC;gBACjC,MAAM,IAAI,YAAY,CAAC,6BAA6B,GAAG,EAAE,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC,CAAA;YAC9E,CAAC;YACD,MAAM,IAAI,YAAY,CAAC,oBAAoB,GAAG,EAAE,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC,CAAA;QACrE,CAAC;IACH,CAAC;IAEO,qBAAqB,CAAC,QAA0B;QACtD,OAAO,IAAI,CAAC,OAAO,CAAC,QAAQ,EAAE,eAAe,CAAC,CAAA;IAChD,CAAC;IAEO,sBAAsB,CAAC,QAA0B,EAAE,UAAkB;QAC3E,OAAO,IAAI,CAAC,OAAO,CAAC,QAAQ,EAAE,GAAG,iBAAiB,YAAY,MAAM,CAAC,UAAU,CAAC,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,OAAO,CAAC,CAAA;IAC3G,CAAC;CACF"}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import type { Scope, Snapshot, SnapshotManifest } from './types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Identifies the location of a snapshot within the storage hierarchy.
|
|
4
|
+
*/
|
|
5
|
+
export type SnapshotLocation = {
|
|
6
|
+
/** Session identifier */
|
|
7
|
+
sessionId: string;
|
|
8
|
+
/** Scope of the snapshot (agent or multi-agent) */
|
|
9
|
+
scope: Scope;
|
|
10
|
+
/** Scope-specific identifier (agentId or multiAgentId) */
|
|
11
|
+
scopeId: string;
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* SessionStorage configuration for pluggable storage backends.
|
|
15
|
+
* Allows users to configure snapshot and transcript storage independently.
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```typescript
|
|
19
|
+
* const storage: SessionStorage = {
|
|
20
|
+
* snapshot: new S3Storage({ bucket: 'my-bucket' })
|
|
21
|
+
* }
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
export type SessionStorage = {
|
|
25
|
+
snapshot: SnapshotStorage;
|
|
26
|
+
};
|
|
27
|
+
/**
|
|
28
|
+
* Interface for snapshot persistence.
|
|
29
|
+
* Implementations provide storage backends (S3, filesystem, etc.).
|
|
30
|
+
*
|
|
31
|
+
* File layout convention:
|
|
32
|
+
* ```
|
|
33
|
+
* sessions/<session_id>/
|
|
34
|
+
* scopes/
|
|
35
|
+
* agent/<scope_id>/
|
|
36
|
+
* snapshots/
|
|
37
|
+
* snapshot_latest.json
|
|
38
|
+
* manifest.json
|
|
39
|
+
* immutable_history/
|
|
40
|
+
* snapshot_00001.json
|
|
41
|
+
* snapshot_00002.json
|
|
42
|
+
* ```
|
|
43
|
+
*/
|
|
44
|
+
export interface SnapshotStorage {
|
|
45
|
+
/**
|
|
46
|
+
* Persists a snapshot to storage.
|
|
47
|
+
*/
|
|
48
|
+
saveSnapshot(params: {
|
|
49
|
+
location: SnapshotLocation;
|
|
50
|
+
snapshotId: string;
|
|
51
|
+
isLatest: boolean;
|
|
52
|
+
snapshot: Snapshot;
|
|
53
|
+
}): Promise<void>;
|
|
54
|
+
/**
|
|
55
|
+
* Loads a snapshot from storage.
|
|
56
|
+
*/
|
|
57
|
+
loadSnapshot(params: {
|
|
58
|
+
location: SnapshotLocation;
|
|
59
|
+
snapshotId?: string;
|
|
60
|
+
}): Promise<Snapshot | null>;
|
|
61
|
+
/**
|
|
62
|
+
* Lists all available snapshot IDs for a session scope.
|
|
63
|
+
*
|
|
64
|
+
* TODO: Add pagination support for long-running agents with many snapshots.
|
|
65
|
+
* Future signature could be:
|
|
66
|
+
* ```typescript
|
|
67
|
+
* listSnapshots(params: {
|
|
68
|
+
* location: SnapshotLocation
|
|
69
|
+
* limit?: number // Max results to return (e.g., 100)
|
|
70
|
+
* startAfter?: string // Snapshot ID to start after (for cursor-based pagination)
|
|
71
|
+
* }): Promise<{ snapshotIds: string[]; nextToken?: string }>
|
|
72
|
+
* ```
|
|
73
|
+
*/
|
|
74
|
+
listSnapshotIds(params: {
|
|
75
|
+
location: SnapshotLocation;
|
|
76
|
+
}): Promise<string[]>;
|
|
77
|
+
/**
|
|
78
|
+
* Loads the snapshot manifest.
|
|
79
|
+
*/
|
|
80
|
+
loadManifest(params: {
|
|
81
|
+
location: SnapshotLocation;
|
|
82
|
+
}): Promise<SnapshotManifest>;
|
|
83
|
+
/**
|
|
84
|
+
* Saves the snapshot manifest.
|
|
85
|
+
*/
|
|
86
|
+
saveManifest(params: {
|
|
87
|
+
location: SnapshotLocation;
|
|
88
|
+
manifest: SnapshotManifest;
|
|
89
|
+
}): Promise<void>;
|
|
90
|
+
}
|
|
91
|
+
//# sourceMappingURL=storage.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"storage.d.ts","sourceRoot":"","sources":["../../../src/session/storage.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,QAAQ,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAA;AAEnE;;GAEG;AACH,MAAM,MAAM,gBAAgB,GAAG;IAC7B,yBAAyB;IACzB,SAAS,EAAE,MAAM,CAAA;IACjB,mDAAmD;IACnD,KAAK,EAAE,KAAK,CAAA;IACZ,0DAA0D;IAC1D,OAAO,EAAE,MAAM,CAAA;CAChB,CAAA;AAED;;;;;;;;;;GAUG;AACH,MAAM,MAAM,cAAc,GAAG;IAC3B,QAAQ,EAAE,eAAe,CAAA;CAE1B,CAAA;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,WAAW,eAAe;IAC9B;;OAEG;IACH,YAAY,CAAC,MAAM,EAAE;QACnB,QAAQ,EAAE,gBAAgB,CAAA;QAC1B,UAAU,EAAE,MAAM,CAAA;QAClB,QAAQ,EAAE,OAAO,CAAA;QACjB,QAAQ,EAAE,QAAQ,CAAA;KACnB,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;IAEjB;;OAEG;IACH,YAAY,CAAC,MAAM,EAAE;QAAE,QAAQ,EAAE,gBAAgB,CAAC;QAAC,UAAU,CAAC,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,QAAQ,GAAG,IAAI,CAAC,CAAA;IAEnG;;;;;;;;;;;;OAYG;IACH,eAAe,CAAC,MAAM,EAAE;QAAE,QAAQ,EAAE,gBAAgB,CAAA;KAAE,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC,CAAA;IAE1E;;OAEG;IACH,YAAY,CAAC,MAAM,EAAE;QAAE,QAAQ,EAAE,gBAAgB,CAAA;KAAE,GAAG,OAAO,CAAC,gBAAgB,CAAC,CAAA;IAE/E;;OAEG;IACH,YAAY,CAAC,MAAM,EAAE;QAAE,QAAQ,EAAE,gBAAgB,CAAC;QAAC,QAAQ,EAAE,gBAAgB,CAAA;KAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;CAChG"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"storage.js","sourceRoot":"","sources":["../../../src/session/storage.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import type { AgentData } from '../types/agent.js';
|
|
2
|
+
export type { Snapshot, Scope } from '../agent/snapshot.js';
|
|
3
|
+
/**
|
|
4
|
+
* Manifest tracks snapshot metadata and ID allocation.
|
|
5
|
+
* Stored alongside snapshots to manage versioning.
|
|
6
|
+
*/
|
|
7
|
+
export interface SnapshotManifest {
|
|
8
|
+
/** Schema version for forward/backward compatibility */
|
|
9
|
+
schemaVersion: string;
|
|
10
|
+
/** Next available snapshot ID for allocation */
|
|
11
|
+
nextSnapshotId: string;
|
|
12
|
+
/** ISO 8601 timestamp of last manifest update */
|
|
13
|
+
updatedAt: string;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Parameters passed to SnapshotTriggerCallback to determine when to create snapshots.
|
|
17
|
+
*/
|
|
18
|
+
export interface SnapshotTriggerParams {
|
|
19
|
+
/** Number of agent invocations (turns) since session started */
|
|
20
|
+
turnCount: number;
|
|
21
|
+
/** Timestamp (ms) of last immutable snapshot creation, undefined if no snapshot yet */
|
|
22
|
+
lastSnapshotAt?: number;
|
|
23
|
+
/** Current agent data including messages and state */
|
|
24
|
+
agentData: AgentData;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Callback function to determine when to create immutable snapshots.
|
|
28
|
+
* Called after each agent invocation to decide if a snapshot should be saved.
|
|
29
|
+
*
|
|
30
|
+
* @param params - Snapshot trigger parameters
|
|
31
|
+
* @returns true to create a snapshot, false to skip
|
|
32
|
+
*
|
|
33
|
+
* @example
|
|
34
|
+
* ```ts
|
|
35
|
+
* // Snapshot every 5 turns
|
|
36
|
+
* const trigger: SnapshotTriggerCallback = ({ turnCount }) => turnCount % 5 === 0
|
|
37
|
+
*
|
|
38
|
+
* // Snapshot every 60 seconds
|
|
39
|
+
* const trigger: SnapshotTriggerCallback = ({ lastSnapshotAt }) => {
|
|
40
|
+
* if (!lastSnapshotAt) return false
|
|
41
|
+
* return Date.now() - lastSnapshotAt > 60000
|
|
42
|
+
* }
|
|
43
|
+
*
|
|
44
|
+
* // Snapshot when conversation exceeds 10 messages
|
|
45
|
+
* const trigger: SnapshotTriggerCallback = ({ agentData }) => agentData.messages.length > 10
|
|
46
|
+
* ```
|
|
47
|
+
*/
|
|
48
|
+
export type SnapshotTriggerCallback = (params: SnapshotTriggerParams) => boolean;
|
|
49
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/session/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAA;AAGlD,YAAY,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,sBAAsB,CAAA;AAE3D;;;GAGG;AACH,MAAM,WAAW,gBAAgB;IAC/B,wDAAwD;IACxD,aAAa,EAAE,MAAM,CAAA;IACrB,gDAAgD;IAChD,cAAc,EAAE,MAAM,CAAA;IACtB,iDAAiD;IACjD,SAAS,EAAE,MAAM,CAAA;CAClB;AAED;;GAEG;AACH,MAAM,WAAW,qBAAqB;IACpC,gEAAgE;IAChE,SAAS,EAAE,MAAM,CAAA;IACjB,uFAAuF;IACvF,cAAc,CAAC,EAAE,MAAM,CAAA;IACvB,sDAAsD;IACtD,SAAS,EAAE,SAAS,CAAA;CACrB;AAED;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,MAAM,MAAM,uBAAuB,GAAG,CAAC,MAAM,EAAE,qBAAqB,KAAK,OAAO,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/session/types.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Validates that an identifier contains only allowed characters.
|
|
3
|
+
* Allowed characters: lowercase letters (a-z), numbers (0-9), hyphens (-), and underscores (_)
|
|
4
|
+
*
|
|
5
|
+
* @param id - The identifier to validate
|
|
6
|
+
* @returns The validated identifier
|
|
7
|
+
* @throws Error if identifier contains invalid characters
|
|
8
|
+
*/
|
|
9
|
+
export declare function validateIdentifier(id: string): string;
|
|
10
|
+
//# sourceMappingURL=validation.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validation.d.ts","sourceRoot":"","sources":["../../../src/session/validation.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,wBAAgB,kBAAkB,CAAC,EAAE,EAAE,MAAM,GAAG,MAAM,CAMrD"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Validates that an identifier contains only allowed characters.
|
|
3
|
+
* Allowed characters: lowercase letters (a-z), numbers (0-9), hyphens (-), and underscores (_)
|
|
4
|
+
*
|
|
5
|
+
* @param id - The identifier to validate
|
|
6
|
+
* @returns The validated identifier
|
|
7
|
+
* @throws Error if identifier contains invalid characters
|
|
8
|
+
*/
|
|
9
|
+
export function validateIdentifier(id) {
|
|
10
|
+
const validPattern = /^[a-z0-9_-]+$/;
|
|
11
|
+
if (!validPattern.test(id)) {
|
|
12
|
+
throw new Error(`Identifier '${id}' can only contain lowercase letters, numbers, hyphens, and underscores`);
|
|
13
|
+
}
|
|
14
|
+
return id;
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=validation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validation.js","sourceRoot":"","sources":["../../../src/session/validation.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,MAAM,UAAU,kBAAkB,CAAC,EAAU;IAC3C,MAAM,YAAY,GAAG,eAAe,CAAA;IACpC,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE,CAAC;QAC3B,MAAM,IAAI,KAAK,CAAC,eAAe,EAAE,yEAAyE,CAAC,CAAA;IAC7G,CAAC;IACD,OAAO,EAAE,CAAA;AACX,CAAC"}
|