byterover-cli 2.0.0 → 2.1.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 +6 -81
- package/dist/agent/core/domain/llm/index.d.ts +1 -1
- package/dist/agent/core/domain/llm/index.js +1 -1
- package/dist/agent/core/domain/llm/registry.d.ts +8 -0
- package/dist/agent/core/domain/llm/registry.js +34 -0
- package/dist/agent/core/domain/sandbox/types.d.ts +2 -0
- package/dist/agent/core/domain/tools/constants.d.ts +3 -0
- package/dist/agent/core/domain/tools/constants.js +3 -0
- package/dist/agent/core/interfaces/cipher-services.d.ts +2 -4
- package/dist/agent/core/interfaces/i-cipher-agent.d.ts +9 -1
- package/dist/agent/core/interfaces/i-sandbox-service.d.ts +8 -0
- package/dist/agent/core/interfaces/i-tool-provider.d.ts +10 -0
- package/dist/agent/core/interfaces/i-tool-scheduler.d.ts +9 -0
- package/dist/agent/infra/agent/agent-schemas.d.ts +0 -9
- package/dist/agent/infra/agent/agent-schemas.js +0 -3
- package/dist/agent/infra/agent/cipher-agent.d.ts +25 -1
- package/dist/agent/infra/agent/cipher-agent.js +138 -11
- package/dist/agent/infra/agent/provider-update-config.d.ts +0 -2
- package/dist/agent/infra/agent/service-initializer.d.ts +2 -6
- package/dist/agent/infra/agent/service-initializer.js +45 -38
- package/dist/agent/infra/blob/blob-storage-factory.d.ts +2 -2
- package/dist/agent/infra/blob/blob-storage-factory.js +4 -4
- package/dist/agent/infra/blob/file-blob-storage.d.ts +96 -0
- package/dist/agent/infra/blob/file-blob-storage.js +454 -0
- package/dist/agent/infra/blob/index.d.ts +2 -3
- package/dist/agent/infra/blob/index.js +4 -6
- package/dist/agent/infra/llm/agent-llm-service.d.ts +3 -0
- package/dist/agent/infra/llm/agent-llm-service.js +34 -52
- package/dist/agent/infra/llm/context/compression/compression-helpers.d.ts +35 -0
- package/dist/agent/infra/llm/context/compression/compression-helpers.js +124 -0
- package/dist/agent/infra/llm/context/compression/escalated-compression.d.ts +62 -0
- package/dist/agent/infra/llm/context/compression/escalated-compression.js +144 -0
- package/dist/agent/infra/llm/context/compression/index.d.ts +3 -0
- package/dist/agent/infra/llm/context/compression/index.js +3 -0
- package/dist/agent/infra/llm/context/compression/reactive-overflow.d.ts +0 -27
- package/dist/agent/infra/llm/context/compression/reactive-overflow.js +5 -122
- package/dist/agent/infra/llm/context/context-manager.d.ts +20 -1
- package/dist/agent/infra/llm/context/context-manager.js +37 -7
- package/dist/agent/infra/llm/providers/index.js +0 -2
- package/dist/agent/infra/llm/providers/types.d.ts +1 -5
- package/dist/agent/infra/map/agentic-map-service.d.ts +97 -0
- package/dist/agent/infra/map/agentic-map-service.js +309 -0
- package/dist/agent/infra/map/context-tree-store.d.ts +94 -0
- package/dist/agent/infra/map/context-tree-store.js +278 -0
- package/dist/agent/infra/map/index.d.ts +4 -0
- package/dist/agent/infra/map/index.js +4 -0
- package/dist/agent/infra/map/llm-map-memory.d.ts +59 -0
- package/dist/agent/infra/map/llm-map-memory.js +187 -0
- package/dist/agent/infra/map/llm-map-service.d.ts +36 -0
- package/dist/agent/infra/map/llm-map-service.js +118 -0
- package/dist/agent/infra/map/map-shared.d.ts +140 -0
- package/dist/agent/infra/map/map-shared.js +325 -0
- package/dist/agent/infra/map/worker-pool.d.ts +45 -0
- package/dist/agent/infra/map/worker-pool.js +73 -0
- package/dist/agent/infra/sandbox/curation-helpers.d.ts +62 -0
- package/dist/agent/infra/sandbox/curation-helpers.js +219 -0
- package/dist/agent/infra/sandbox/sandbox-service.d.ts +12 -0
- package/dist/agent/infra/sandbox/sandbox-service.js +39 -7
- package/dist/agent/infra/sandbox/tools-sdk.d.ts +48 -1
- package/dist/agent/infra/sandbox/tools-sdk.js +52 -1
- package/dist/agent/infra/session/session-manager.d.ts +8 -1
- package/dist/agent/infra/session/session-manager.js +24 -4
- package/dist/agent/infra/storage/file-key-storage.d.ts +142 -0
- package/dist/agent/infra/storage/file-key-storage.js +572 -0
- package/dist/agent/infra/storage/granular-history-storage.d.ts +1 -1
- package/dist/agent/infra/storage/granular-history-storage.js +1 -1
- package/dist/agent/infra/system-prompt/contributors/context-tree-structure-contributor.d.ts +4 -0
- package/dist/agent/infra/system-prompt/contributors/context-tree-structure-contributor.js +42 -14
- package/dist/agent/infra/system-prompt/contributors/map-selection-contributor.d.ts +16 -0
- package/dist/agent/infra/system-prompt/contributors/map-selection-contributor.js +47 -0
- package/dist/agent/infra/tools/core-tool-scheduler.js +3 -1
- package/dist/agent/infra/tools/implementations/agentic-map-tool.d.ts +35 -0
- package/dist/agent/infra/tools/implementations/agentic-map-tool.js +156 -0
- package/dist/agent/infra/tools/implementations/code-exec-tool.js +1 -0
- package/dist/agent/infra/tools/implementations/curate-tool.d.ts +9 -9
- package/dist/agent/infra/tools/implementations/expand-knowledge-tool.d.ts +18 -0
- package/dist/agent/infra/tools/implementations/expand-knowledge-tool.js +43 -0
- package/dist/agent/infra/tools/implementations/llm-map-tool.d.ts +24 -0
- package/dist/agent/infra/tools/implementations/llm-map-tool.js +87 -0
- package/dist/agent/infra/tools/implementations/memory-symbol-tree.d.ts +28 -1
- package/dist/agent/infra/tools/implementations/memory-symbol-tree.js +27 -3
- package/dist/agent/infra/tools/implementations/search-knowledge-service.d.ts +1 -0
- package/dist/agent/infra/tools/implementations/search-knowledge-service.js +83 -12
- package/dist/agent/infra/tools/implementations/search-knowledge-tool.js +2 -2
- package/dist/agent/infra/tools/tool-manager.js +6 -0
- package/dist/agent/infra/tools/tool-provider.d.ts +12 -0
- package/dist/agent/infra/tools/tool-provider.js +78 -0
- package/dist/agent/infra/tools/tool-registry.d.ts +14 -0
- package/dist/agent/infra/tools/tool-registry.js +32 -0
- package/dist/agent/resources/prompts/system-prompt.yml +48 -74
- package/dist/agent/resources/tools/expand_knowledge.txt +20 -0
- package/dist/oclif/commands/curate/index.js +1 -2
- package/dist/oclif/commands/main.js +1 -0
- package/dist/oclif/commands/providers/connect.d.ts +1 -3
- package/dist/oclif/commands/providers/connect.js +7 -29
- package/dist/oclif/commands/query.js +1 -2
- package/dist/server/constants.d.ts +7 -0
- package/dist/server/constants.js +8 -0
- package/dist/server/core/domain/entities/provider-registry.js +1 -15
- package/dist/server/core/domain/knowledge/memory-scoring.js +1 -1
- package/dist/server/core/domain/knowledge/summary-types.d.ts +126 -0
- package/dist/server/core/domain/knowledge/summary-types.js +7 -0
- package/dist/server/core/domain/transport/schemas.d.ts +0 -4
- package/dist/server/core/interfaces/context-tree/i-context-tree-archive-service.d.ts +30 -0
- package/dist/server/core/interfaces/context-tree/i-context-tree-archive-service.js +1 -0
- package/dist/server/core/interfaces/context-tree/i-context-tree-manifest-service.d.ts +30 -0
- package/dist/server/core/interfaces/context-tree/i-context-tree-manifest-service.js +1 -0
- package/dist/server/core/interfaces/context-tree/i-context-tree-summary-service.d.ts +29 -0
- package/dist/server/core/interfaces/context-tree/i-context-tree-summary-service.js +1 -0
- package/dist/server/infra/cogit/context-tree-to-push-context-mapper.js +10 -3
- package/dist/server/infra/connectors/skill/skill-connector.d.ts +4 -0
- package/dist/server/infra/connectors/skill/skill-connector.js +4 -0
- package/dist/server/infra/context-tree/children-hash.d.ts +20 -0
- package/dist/server/infra/context-tree/children-hash.js +22 -0
- package/dist/server/infra/context-tree/derived-artifact.d.ts +28 -0
- package/dist/server/infra/context-tree/derived-artifact.js +48 -0
- package/dist/server/infra/context-tree/file-context-tree-archive-service.d.ts +37 -0
- package/dist/server/infra/context-tree/file-context-tree-archive-service.js +219 -0
- package/dist/server/infra/context-tree/file-context-tree-manifest-service.d.ts +50 -0
- package/dist/server/infra/context-tree/file-context-tree-manifest-service.js +278 -0
- package/dist/server/infra/context-tree/file-context-tree-merger.js +4 -0
- package/dist/server/infra/context-tree/file-context-tree-snapshot-service.js +12 -4
- package/dist/server/infra/context-tree/file-context-tree-summary-service.d.ts +44 -0
- package/dist/server/infra/context-tree/file-context-tree-summary-service.js +313 -0
- package/dist/server/infra/context-tree/file-context-tree-writer-service.js +5 -0
- package/dist/server/infra/context-tree/prompts/summary-generation.d.ts +22 -0
- package/dist/server/infra/context-tree/prompts/summary-generation.js +45 -0
- package/dist/server/infra/context-tree/snapshot-diff.d.ts +19 -0
- package/dist/server/infra/context-tree/snapshot-diff.js +39 -0
- package/dist/server/infra/context-tree/summary-frontmatter.d.ts +24 -0
- package/dist/server/infra/context-tree/summary-frontmatter.js +111 -0
- package/dist/server/infra/daemon/agent-process.js +2 -14
- package/dist/server/infra/executor/curate-executor.d.ts +1 -0
- package/dist/server/infra/executor/curate-executor.js +82 -34
- package/dist/server/infra/executor/folder-pack-executor.js +1 -1
- package/dist/server/infra/executor/pre-compaction/compaction-escalation.d.ts +6 -0
- package/dist/server/infra/executor/pre-compaction/compaction-escalation.js +6 -0
- package/dist/server/infra/executor/pre-compaction/index.d.ts +3 -0
- package/dist/server/infra/executor/pre-compaction/index.js +1 -0
- package/dist/server/infra/executor/pre-compaction/pre-compaction-service.d.ts +59 -0
- package/dist/server/infra/executor/pre-compaction/pre-compaction-service.js +124 -0
- package/dist/server/infra/executor/pre-compaction/prompts.d.ts +24 -0
- package/dist/server/infra/executor/pre-compaction/prompts.js +47 -0
- package/dist/server/infra/executor/query-executor.d.ts +3 -0
- package/dist/server/infra/executor/query-executor.js +39 -4
- package/dist/server/infra/http/authenticated-http-client.js +4 -0
- package/dist/server/infra/http/provider-model-fetcher-registry.js +1 -5
- package/dist/server/infra/http/provider-model-fetchers.d.ts +0 -14
- package/dist/server/infra/http/provider-model-fetchers.js +0 -132
- package/dist/server/infra/provider/provider-config-resolver.js +0 -55
- package/dist/server/utils/curate-result-parser.d.ts +4 -4
- package/dist/shared/constants/curation.d.ts +6 -0
- package/dist/shared/constants/curation.js +6 -0
- package/dist/shared/utils/escalation-utils.d.ts +59 -0
- package/dist/shared/utils/escalation-utils.js +141 -0
- package/dist/tui/components/command-input.js +1 -1
- package/dist/tui/components/inline-prompts/inline-confirm.js +6 -1
- package/dist/tui/features/commands/definitions/exit.d.ts +2 -0
- package/dist/tui/features/commands/definitions/exit.js +9 -0
- package/dist/tui/features/commands/definitions/index.js +3 -0
- package/dist/tui/features/exit/components/exit-flow.d.ts +10 -0
- package/dist/tui/features/exit/components/exit-flow.js +19 -0
- package/dist/tui/features/provider/components/provider-flow.js +1 -21
- package/oclif.manifest.json +100 -109
- package/package.json +11 -4
- package/dist/agent/infra/blob/migrations.d.ts +0 -63
- package/dist/agent/infra/blob/migrations.js +0 -148
- package/dist/agent/infra/blob/sqlite-blob-storage.d.ts +0 -82
- package/dist/agent/infra/blob/sqlite-blob-storage.js +0 -307
- package/dist/agent/infra/llm/providers/google-vertex.d.ts +0 -15
- package/dist/agent/infra/llm/providers/google-vertex.js +0 -36
- package/dist/agent/infra/storage/blob-history-storage.d.ts +0 -81
- package/dist/agent/infra/storage/blob-history-storage.js +0 -193
- package/dist/agent/infra/storage/dual-format-history-storage.d.ts +0 -83
- package/dist/agent/infra/storage/dual-format-history-storage.js +0 -165
- package/dist/agent/infra/storage/sqlite-key-storage.d.ts +0 -113
- package/dist/agent/infra/storage/sqlite-key-storage.js +0 -438
- package/dist/server/infra/provider/vertex-ai-utils.d.ts +0 -10
- package/dist/server/infra/provider/vertex-ai-utils.js +0 -28
- package/dist/tui/features/provider/components/credential-path-dialog.d.ts +0 -30
- package/dist/tui/features/provider/components/credential-path-dialog.js +0 -85
|
@@ -1,83 +0,0 @@
|
|
|
1
|
-
import type { SessionMetadata } from '../../core/domain/storage/history-types.js';
|
|
2
|
-
import type { IHistoryStorage } from '../../core/interfaces/i-history-storage.js';
|
|
3
|
-
import type { InternalMessage } from '../../core/interfaces/message-types.js';
|
|
4
|
-
import type { BlobHistoryStorage } from './blob-history-storage.js';
|
|
5
|
-
import type { GranularHistoryStorage } from './granular-history-storage.js';
|
|
6
|
-
/**
|
|
7
|
-
* Dual-format history storage that routes between blob and granular storage.
|
|
8
|
-
*
|
|
9
|
-
* This router implements the "no migration" strategy:
|
|
10
|
-
* - NEW sessions → GranularHistoryStorage (message-per-key with streaming)
|
|
11
|
-
* - EXISTING sessions → BlobHistoryStorage (legacy single-blob format)
|
|
12
|
-
*
|
|
13
|
-
* Format detection:
|
|
14
|
-
* - Granular format: has a session record at ["session", sessionId]
|
|
15
|
-
* - Blob format: has a blob at "session-{sessionId}"
|
|
16
|
-
* - New session: neither exists, uses granular format
|
|
17
|
-
*
|
|
18
|
-
* This allows seamless coexistence of both formats without migration.
|
|
19
|
-
*/
|
|
20
|
-
export declare class DualFormatHistoryStorage implements IHistoryStorage {
|
|
21
|
-
private readonly blobStorage;
|
|
22
|
-
private readonly granularStorage;
|
|
23
|
-
constructor(blobStorage: BlobHistoryStorage, granularStorage: GranularHistoryStorage);
|
|
24
|
-
/**
|
|
25
|
-
* Append a single message to the session history.
|
|
26
|
-
* Routes to appropriate storage based on session format.
|
|
27
|
-
* New sessions use granular format.
|
|
28
|
-
*/
|
|
29
|
-
appendMessage(sessionId: string, message: InternalMessage): Promise<void>;
|
|
30
|
-
/**
|
|
31
|
-
* Delete all history for a session.
|
|
32
|
-
* Deletes from both storages to ensure complete cleanup.
|
|
33
|
-
*/
|
|
34
|
-
deleteHistory(sessionId: string): Promise<void>;
|
|
35
|
-
/**
|
|
36
|
-
* Check if history exists for a session in either format.
|
|
37
|
-
*/
|
|
38
|
-
exists(sessionId: string): Promise<boolean>;
|
|
39
|
-
/**
|
|
40
|
-
* Get the underlying granular storage for advanced operations.
|
|
41
|
-
* Returns undefined if session is not in granular format.
|
|
42
|
-
*/
|
|
43
|
-
getGranularStorage(sessionId: string): Promise<GranularHistoryStorage | undefined>;
|
|
44
|
-
/**
|
|
45
|
-
* Get metadata for a session from appropriate storage.
|
|
46
|
-
*/
|
|
47
|
-
getSessionMetadata(sessionId: string): Promise<SessionMetadata | undefined>;
|
|
48
|
-
/**
|
|
49
|
-
* Check if a session uses granular format.
|
|
50
|
-
* Useful for consumers that want to use granular-specific features.
|
|
51
|
-
*/
|
|
52
|
-
isGranularFormat(sessionId: string): Promise<boolean>;
|
|
53
|
-
/**
|
|
54
|
-
* List all session IDs from both storage formats.
|
|
55
|
-
*/
|
|
56
|
-
listSessions(): Promise<string[]>;
|
|
57
|
-
/**
|
|
58
|
-
* Load conversation history for a session.
|
|
59
|
-
* Routes to appropriate storage based on session format.
|
|
60
|
-
*/
|
|
61
|
-
loadHistory(sessionId: string): Promise<InternalMessage[] | undefined>;
|
|
62
|
-
/**
|
|
63
|
-
* Save conversation history for a session.
|
|
64
|
-
* Routes to appropriate storage based on session format.
|
|
65
|
-
*
|
|
66
|
-
* New sessions use granular format.
|
|
67
|
-
* Existing sessions stay in their original format.
|
|
68
|
-
*/
|
|
69
|
-
saveHistory(sessionId: string, messages: InternalMessage[]): Promise<void>;
|
|
70
|
-
/**
|
|
71
|
-
* Detect which storage format a session uses.
|
|
72
|
-
*
|
|
73
|
-
* Priority:
|
|
74
|
-
* 1. Granular format (check first as it's the newer format)
|
|
75
|
-
* 2. Blob format (legacy)
|
|
76
|
-
* 3. None (new session)
|
|
77
|
-
*/
|
|
78
|
-
private detectFormat;
|
|
79
|
-
}
|
|
80
|
-
/**
|
|
81
|
-
* Factory function to create DualFormatHistoryStorage.
|
|
82
|
-
*/
|
|
83
|
-
export declare function createDualFormatHistoryStorage(blobStorage: BlobHistoryStorage, granularStorage: GranularHistoryStorage): DualFormatHistoryStorage;
|
|
@@ -1,165 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Dual-format history storage that routes between blob and granular storage.
|
|
3
|
-
*
|
|
4
|
-
* This router implements the "no migration" strategy:
|
|
5
|
-
* - NEW sessions → GranularHistoryStorage (message-per-key with streaming)
|
|
6
|
-
* - EXISTING sessions → BlobHistoryStorage (legacy single-blob format)
|
|
7
|
-
*
|
|
8
|
-
* Format detection:
|
|
9
|
-
* - Granular format: has a session record at ["session", sessionId]
|
|
10
|
-
* - Blob format: has a blob at "session-{sessionId}"
|
|
11
|
-
* - New session: neither exists, uses granular format
|
|
12
|
-
*
|
|
13
|
-
* This allows seamless coexistence of both formats without migration.
|
|
14
|
-
*/
|
|
15
|
-
export class DualFormatHistoryStorage {
|
|
16
|
-
blobStorage;
|
|
17
|
-
granularStorage;
|
|
18
|
-
constructor(blobStorage, granularStorage) {
|
|
19
|
-
this.blobStorage = blobStorage;
|
|
20
|
-
this.granularStorage = granularStorage;
|
|
21
|
-
}
|
|
22
|
-
/**
|
|
23
|
-
* Append a single message to the session history.
|
|
24
|
-
* Routes to appropriate storage based on session format.
|
|
25
|
-
* New sessions use granular format.
|
|
26
|
-
*/
|
|
27
|
-
async appendMessage(sessionId, message) {
|
|
28
|
-
const format = await this.detectFormat(sessionId);
|
|
29
|
-
if (format === 'granular') {
|
|
30
|
-
return this.granularStorage.appendMessage(sessionId, message);
|
|
31
|
-
}
|
|
32
|
-
if (format === 'blob') {
|
|
33
|
-
return this.blobStorage.appendMessage(sessionId, message);
|
|
34
|
-
}
|
|
35
|
-
// New session - use granular format
|
|
36
|
-
return this.granularStorage.appendMessage(sessionId, message);
|
|
37
|
-
}
|
|
38
|
-
/**
|
|
39
|
-
* Delete all history for a session.
|
|
40
|
-
* Deletes from both storages to ensure complete cleanup.
|
|
41
|
-
*/
|
|
42
|
-
async deleteHistory(sessionId) {
|
|
43
|
-
const format = await this.detectFormat(sessionId);
|
|
44
|
-
if (format === 'granular') {
|
|
45
|
-
await this.granularStorage.deleteHistory(sessionId);
|
|
46
|
-
}
|
|
47
|
-
else if (format === 'blob') {
|
|
48
|
-
await this.blobStorage.deleteHistory(sessionId);
|
|
49
|
-
}
|
|
50
|
-
// For 'none', nothing to delete
|
|
51
|
-
}
|
|
52
|
-
/**
|
|
53
|
-
* Check if history exists for a session in either format.
|
|
54
|
-
*/
|
|
55
|
-
async exists(sessionId) {
|
|
56
|
-
const format = await this.detectFormat(sessionId);
|
|
57
|
-
return format !== 'none';
|
|
58
|
-
}
|
|
59
|
-
/**
|
|
60
|
-
* Get the underlying granular storage for advanced operations.
|
|
61
|
-
* Returns undefined if session is not in granular format.
|
|
62
|
-
*/
|
|
63
|
-
async getGranularStorage(sessionId) {
|
|
64
|
-
const format = await this.detectFormat(sessionId);
|
|
65
|
-
if (format === 'granular' || format === 'none') {
|
|
66
|
-
return this.granularStorage;
|
|
67
|
-
}
|
|
68
|
-
return undefined;
|
|
69
|
-
}
|
|
70
|
-
/**
|
|
71
|
-
* Get metadata for a session from appropriate storage.
|
|
72
|
-
*/
|
|
73
|
-
async getSessionMetadata(sessionId) {
|
|
74
|
-
const format = await this.detectFormat(sessionId);
|
|
75
|
-
if (format === 'granular') {
|
|
76
|
-
return this.granularStorage.getSessionMetadata(sessionId);
|
|
77
|
-
}
|
|
78
|
-
if (format === 'blob') {
|
|
79
|
-
return this.blobStorage.getSessionMetadata(sessionId);
|
|
80
|
-
}
|
|
81
|
-
return undefined;
|
|
82
|
-
}
|
|
83
|
-
/**
|
|
84
|
-
* Check if a session uses granular format.
|
|
85
|
-
* Useful for consumers that want to use granular-specific features.
|
|
86
|
-
*/
|
|
87
|
-
async isGranularFormat(sessionId) {
|
|
88
|
-
const format = await this.detectFormat(sessionId);
|
|
89
|
-
return format === 'granular';
|
|
90
|
-
}
|
|
91
|
-
/**
|
|
92
|
-
* List all session IDs from both storage formats.
|
|
93
|
-
*/
|
|
94
|
-
async listSessions() {
|
|
95
|
-
const [blobSessions, granularSessions] = await Promise.all([
|
|
96
|
-
this.blobStorage.listSessions(),
|
|
97
|
-
this.granularStorage.listSessions(),
|
|
98
|
-
]);
|
|
99
|
-
// Combine and deduplicate (shouldn't have duplicates, but be safe)
|
|
100
|
-
const allSessions = new Set([...blobSessions, ...granularSessions]);
|
|
101
|
-
return [...allSessions];
|
|
102
|
-
}
|
|
103
|
-
/**
|
|
104
|
-
* Load conversation history for a session.
|
|
105
|
-
* Routes to appropriate storage based on session format.
|
|
106
|
-
*/
|
|
107
|
-
async loadHistory(sessionId) {
|
|
108
|
-
const format = await this.detectFormat(sessionId);
|
|
109
|
-
if (format === 'granular') {
|
|
110
|
-
return this.granularStorage.loadHistory(sessionId);
|
|
111
|
-
}
|
|
112
|
-
if (format === 'blob') {
|
|
113
|
-
return this.blobStorage.loadHistory(sessionId);
|
|
114
|
-
}
|
|
115
|
-
// New session - return undefined (no history yet)
|
|
116
|
-
return undefined;
|
|
117
|
-
}
|
|
118
|
-
/**
|
|
119
|
-
* Save conversation history for a session.
|
|
120
|
-
* Routes to appropriate storage based on session format.
|
|
121
|
-
*
|
|
122
|
-
* New sessions use granular format.
|
|
123
|
-
* Existing sessions stay in their original format.
|
|
124
|
-
*/
|
|
125
|
-
async saveHistory(sessionId, messages) {
|
|
126
|
-
const format = await this.detectFormat(sessionId);
|
|
127
|
-
if (format === 'granular') {
|
|
128
|
-
return this.granularStorage.saveHistory(sessionId, messages);
|
|
129
|
-
}
|
|
130
|
-
if (format === 'blob') {
|
|
131
|
-
// Keep existing blob sessions in blob format
|
|
132
|
-
return this.blobStorage.saveHistory(sessionId, messages);
|
|
133
|
-
}
|
|
134
|
-
// New session - use granular format
|
|
135
|
-
return this.granularStorage.saveHistory(sessionId, messages);
|
|
136
|
-
}
|
|
137
|
-
/**
|
|
138
|
-
* Detect which storage format a session uses.
|
|
139
|
-
*
|
|
140
|
-
* Priority:
|
|
141
|
-
* 1. Granular format (check first as it's the newer format)
|
|
142
|
-
* 2. Blob format (legacy)
|
|
143
|
-
* 3. None (new session)
|
|
144
|
-
*/
|
|
145
|
-
async detectFormat(sessionId) {
|
|
146
|
-
// Check granular format first (newer, preferred)
|
|
147
|
-
const isGranular = await this.granularStorage.exists(sessionId);
|
|
148
|
-
if (isGranular) {
|
|
149
|
-
return 'granular';
|
|
150
|
-
}
|
|
151
|
-
// Check blob format (legacy)
|
|
152
|
-
const isBlob = await this.blobStorage.exists(sessionId);
|
|
153
|
-
if (isBlob) {
|
|
154
|
-
return 'blob';
|
|
155
|
-
}
|
|
156
|
-
// New session
|
|
157
|
-
return 'none';
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
/**
|
|
161
|
-
* Factory function to create DualFormatHistoryStorage.
|
|
162
|
-
*/
|
|
163
|
-
export function createDualFormatHistoryStorage(blobStorage, granularStorage) {
|
|
164
|
-
return new DualFormatHistoryStorage(blobStorage, granularStorage);
|
|
165
|
-
}
|
|
@@ -1,113 +0,0 @@
|
|
|
1
|
-
import type { BatchOperation, IKeyStorage, StorageKey } from '../../core/interfaces/i-key-storage.js';
|
|
2
|
-
/**
|
|
3
|
-
* Configuration for SQLite key storage
|
|
4
|
-
*/
|
|
5
|
-
export interface SqliteKeyStorageConfig {
|
|
6
|
-
/**
|
|
7
|
-
* Database file path (relative or absolute).
|
|
8
|
-
* Defaults to 'context.db'
|
|
9
|
-
*/
|
|
10
|
-
dbPath?: string;
|
|
11
|
-
/**
|
|
12
|
-
* Enable in-memory mode for testing.
|
|
13
|
-
* Defaults to false.
|
|
14
|
-
*/
|
|
15
|
-
inMemory?: boolean;
|
|
16
|
-
/**
|
|
17
|
-
* Storage directory for the database file.
|
|
18
|
-
* Defaults to process.cwd()/.brv/blobs
|
|
19
|
-
*/
|
|
20
|
-
storageDir?: string;
|
|
21
|
-
}
|
|
22
|
-
/**
|
|
23
|
-
* SQLite-based key storage implementation.
|
|
24
|
-
*
|
|
25
|
-
* Stores key-value pairs where keys are hierarchical (StorageKey = string[])
|
|
26
|
-
* and values are JSON-serializable objects.
|
|
27
|
-
*
|
|
28
|
-
* Key path structure:
|
|
29
|
-
* - ["session", sessionId] → Session metadata
|
|
30
|
-
* - ["message", sessionId, messageId] → Individual message
|
|
31
|
-
* - ["part", messageId, partId] → Message part (tool output, file, etc.)
|
|
32
|
-
*
|
|
33
|
-
* Schema:
|
|
34
|
-
* - key_store: key_path (primary), value (JSON blob), created_at, updated_at
|
|
35
|
-
*
|
|
36
|
-
* Features:
|
|
37
|
-
* - Hierarchical key organization with prefix-based listing
|
|
38
|
-
* - Reader-writer locks for concurrent access
|
|
39
|
-
* - Atomic batch operations
|
|
40
|
-
* - ACID transactions via SQLite
|
|
41
|
-
*/
|
|
42
|
-
export declare class SqliteKeyStorage implements IKeyStorage {
|
|
43
|
-
private db;
|
|
44
|
-
private readonly dbPath;
|
|
45
|
-
private initialized;
|
|
46
|
-
private readonly inMemory;
|
|
47
|
-
private readonly storageDir;
|
|
48
|
-
constructor(config?: SqliteKeyStorageConfig);
|
|
49
|
-
/**
|
|
50
|
-
* Execute batch operations atomically.
|
|
51
|
-
* All operations succeed or fail together.
|
|
52
|
-
*/
|
|
53
|
-
batch(operations: BatchOperation[]): Promise<void>;
|
|
54
|
-
/**
|
|
55
|
-
* Close the database connection.
|
|
56
|
-
*/
|
|
57
|
-
close(): void;
|
|
58
|
-
/**
|
|
59
|
-
* Delete a value by its composite key.
|
|
60
|
-
*/
|
|
61
|
-
delete(key: StorageKey): Promise<boolean>;
|
|
62
|
-
/**
|
|
63
|
-
* Check if a key exists.
|
|
64
|
-
*/
|
|
65
|
-
exists(key: StorageKey): Promise<boolean>;
|
|
66
|
-
/**
|
|
67
|
-
* Get a value by its composite key.
|
|
68
|
-
*/
|
|
69
|
-
get<T>(key: StorageKey): Promise<T | undefined>;
|
|
70
|
-
/**
|
|
71
|
-
* Initialize the storage backend.
|
|
72
|
-
* Creates the database and runs migrations.
|
|
73
|
-
*/
|
|
74
|
-
initialize(): Promise<void>;
|
|
75
|
-
/**
|
|
76
|
-
* List all keys matching a prefix.
|
|
77
|
-
*/
|
|
78
|
-
list(prefix: StorageKey): Promise<StorageKey[]>;
|
|
79
|
-
/**
|
|
80
|
-
* List all key-value pairs matching a prefix.
|
|
81
|
-
* More efficient than list() followed by individual get() calls.
|
|
82
|
-
*/
|
|
83
|
-
listWithValues<T>(prefix: StorageKey): Promise<Array<{
|
|
84
|
-
key: StorageKey;
|
|
85
|
-
value: T;
|
|
86
|
-
}>>;
|
|
87
|
-
/**
|
|
88
|
-
* Set a value at a composite key.
|
|
89
|
-
*/
|
|
90
|
-
set<T>(key: StorageKey, value: T): Promise<void>;
|
|
91
|
-
/**
|
|
92
|
-
* Atomic update with optimistic locking.
|
|
93
|
-
*/
|
|
94
|
-
update<T>(key: StorageKey, updater: (current: T | undefined) => T): Promise<T>;
|
|
95
|
-
/**
|
|
96
|
-
* Deserialize a key path string back to StorageKey.
|
|
97
|
-
* Converts "message:session123:msg456" to ["message", "session123", "msg456"]
|
|
98
|
-
*/
|
|
99
|
-
private deserializeKey;
|
|
100
|
-
/**
|
|
101
|
-
* Ensure storage has been initialized.
|
|
102
|
-
*/
|
|
103
|
-
private ensureInitialized;
|
|
104
|
-
/**
|
|
105
|
-
* Serialize a StorageKey to a string path.
|
|
106
|
-
* Converts ["message", "session123", "msg456"] to "message:session123:msg456"
|
|
107
|
-
*/
|
|
108
|
-
private serializeKey;
|
|
109
|
-
}
|
|
110
|
-
/**
|
|
111
|
-
* Factory function to create SqliteKeyStorage with common defaults.
|
|
112
|
-
*/
|
|
113
|
-
export declare function createKeyStorage(config?: SqliteKeyStorageConfig): SqliteKeyStorage;
|