@downcity/agent 1.1.430 → 1.1.437
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 +13 -11
- package/bin/agent/Agent.d.ts +3 -3
- package/bin/agent/Agent.d.ts.map +1 -1
- package/bin/agent/Agent.js +38 -8
- package/bin/agent/Agent.js.map +1 -1
- package/bin/agent/AgentInstructions.js +2 -2
- package/bin/agent/AgentInstructions.js.map +1 -1
- package/bin/agent/AgentMemoryStorage.d.ts.map +1 -1
- package/bin/agent/AgentMemoryStorage.js +1 -0
- package/bin/agent/AgentMemoryStorage.js.map +1 -1
- package/bin/agent/AgentSessions.d.ts +5 -1
- package/bin/agent/AgentSessions.d.ts.map +1 -1
- package/bin/agent/AgentSessions.js +17 -9
- package/bin/agent/AgentSessions.js.map +1 -1
- package/bin/executor/Executor.d.ts +9 -27
- package/bin/executor/Executor.d.ts.map +1 -1
- package/bin/executor/Executor.js +32 -127
- package/bin/executor/Executor.js.map +1 -1
- package/bin/executor/composer/system/default/SystemPromptAssets.d.ts +0 -4
- package/bin/executor/composer/system/default/SystemPromptAssets.d.ts.map +1 -1
- package/bin/executor/composer/system/default/SystemPromptAssets.js +0 -5
- package/bin/executor/composer/system/default/SystemPromptAssets.js.map +1 -1
- package/bin/executor/core-engine/CoreEngineContextCompaction.d.ts +3 -9
- package/bin/executor/core-engine/CoreEngineContextCompaction.d.ts.map +1 -1
- package/bin/executor/core-engine/CoreEngineContextCompaction.js +4 -130
- package/bin/executor/core-engine/CoreEngineContextCompaction.js.map +1 -1
- package/bin/executor/core-engine/CoreEngineRunner.d.ts +3 -30
- package/bin/executor/core-engine/CoreEngineRunner.d.ts.map +1 -1
- package/bin/executor/core-engine/CoreEngineRunner.js +38 -194
- package/bin/executor/core-engine/CoreEngineRunner.js.map +1 -1
- package/bin/executor/core-engine/CoreEngineSignals.d.ts +6 -6
- package/bin/executor/core-engine/CoreEngineSignals.d.ts.map +1 -1
- package/bin/executor/core-engine/CoreEngineSignals.js +1 -1
- package/bin/executor/core-engine/CoreEngineSignals.js.map +1 -1
- package/bin/executor/messages/SessionAttachmentMapper.d.ts +2 -2
- package/bin/executor/messages/SessionAttachmentMapper.d.ts.map +1 -1
- package/bin/executor/messages/SessionAttachmentMapper.js.map +1 -1
- package/bin/executor/messages/SessionMessageLog.d.ts +3 -3
- package/bin/executor/messages/SessionMessageLog.d.ts.map +1 -1
- package/bin/executor/messages/SessionMessageLog.js.map +1 -1
- package/bin/executor/messages/SessionModelMessages.d.ts +0 -3
- package/bin/executor/messages/SessionModelMessages.d.ts.map +1 -1
- package/bin/executor/messages/SessionModelMessages.js +80 -97
- package/bin/executor/messages/SessionModelMessages.js.map +1 -1
- package/bin/executor/model/ModelStepRunner.d.ts +2 -6
- package/bin/executor/model/ModelStepRunner.d.ts.map +1 -1
- package/bin/executor/model/ModelStepRunner.js +0 -28
- package/bin/executor/model/ModelStepRunner.js.map +1 -1
- package/bin/executor/services/ExecutorRecoveryPolicy.d.ts +7 -64
- package/bin/executor/services/ExecutorRecoveryPolicy.d.ts.map +1 -1
- package/bin/executor/services/ExecutorRecoveryPolicy.js +29 -45
- package/bin/executor/services/ExecutorRecoveryPolicy.js.map +1 -1
- package/bin/executor/types/SessionHistoryMeta.d.ts +1 -3
- package/bin/executor/types/SessionHistoryMeta.d.ts.map +1 -1
- package/bin/executor/types/SessionHistoryMeta.js +1 -1
- package/bin/index.d.ts +9 -13
- package/bin/index.d.ts.map +1 -1
- package/bin/index.js +2 -4
- package/bin/index.js.map +1 -1
- package/bin/session/DefaultSessionComposer.d.ts +13 -7
- package/bin/session/DefaultSessionComposer.d.ts.map +1 -1
- package/bin/session/DefaultSessionComposer.js +26 -21
- package/bin/session/DefaultSessionComposer.js.map +1 -1
- package/bin/session/Session.d.ts +12 -19
- package/bin/session/Session.d.ts.map +1 -1
- package/bin/session/Session.js +70 -202
- package/bin/session/Session.js.map +1 -1
- package/bin/session/SessionComposition.d.ts +0 -2
- package/bin/session/SessionComposition.d.ts.map +1 -1
- package/bin/session/SessionComposition.js +30 -54
- package/bin/session/SessionComposition.js.map +1 -1
- package/bin/session/SessionLoop.d.ts +17 -16
- package/bin/session/SessionLoop.d.ts.map +1 -1
- package/bin/session/SessionLoop.js +217 -320
- package/bin/session/SessionLoop.js.map +1 -1
- package/bin/session/SessionMessages.d.ts +52 -44
- package/bin/session/SessionMessages.d.ts.map +1 -1
- package/bin/session/SessionMessages.js +285 -187
- package/bin/session/SessionMessages.js.map +1 -1
- package/bin/session/SessionQueue.d.ts +1 -1
- package/bin/session/SessionQueue.d.ts.map +1 -1
- package/bin/session/SessionQueue.js +2 -1
- package/bin/session/SessionQueue.js.map +1 -1
- package/bin/session/SessionState.d.ts +3 -7
- package/bin/session/SessionState.d.ts.map +1 -1
- package/bin/session/SessionState.js +50 -89
- package/bin/session/SessionState.js.map +1 -1
- package/bin/session/SessionSystem.d.ts +5 -1
- package/bin/session/SessionSystem.d.ts.map +1 -1
- package/bin/session/SessionSystem.js +40 -0
- package/bin/session/SessionSystem.js.map +1 -1
- package/bin/session/SessionTitle.d.ts +3 -3
- package/bin/session/SessionTitle.d.ts.map +1 -1
- package/bin/session/SessionTitle.js +2 -2
- package/bin/session/browse/Browse.d.ts +32 -46
- package/bin/session/browse/Browse.d.ts.map +1 -1
- package/bin/session/browse/Browse.js +104 -360
- package/bin/session/browse/Browse.js.map +1 -1
- package/bin/session/browse/SessionMessageTimeline.d.ts.map +1 -1
- package/bin/session/browse/SessionMessageTimeline.js +61 -37
- package/bin/session/browse/SessionMessageTimeline.js.map +1 -1
- package/bin/session/composer/policies/AdaptivePartContextPolicy.d.ts +35 -0
- package/bin/session/composer/policies/AdaptivePartContextPolicy.d.ts.map +1 -0
- package/bin/session/composer/policies/AdaptivePartContextPolicy.js +256 -0
- package/bin/session/composer/policies/AdaptivePartContextPolicy.js.map +1 -0
- package/bin/session/composer/policies/FullHistoryContextPolicy.d.ts +24 -0
- package/bin/session/composer/policies/FullHistoryContextPolicy.d.ts.map +1 -0
- package/bin/session/composer/policies/FullHistoryContextPolicy.js +31 -0
- package/bin/session/composer/policies/FullHistoryContextPolicy.js.map +1 -0
- package/bin/session/composer/policies/SessionSummaryPrompts.d.ts +16 -0
- package/bin/session/composer/policies/SessionSummaryPrompts.d.ts.map +1 -0
- package/bin/session/composer/policies/SessionSummaryPrompts.js +32 -0
- package/bin/session/composer/policies/SessionSummaryPrompts.js.map +1 -0
- package/bin/session/execution/SessionAssistantOutputAdapter.d.ts +15 -4
- package/bin/session/execution/SessionAssistantOutputAdapter.d.ts.map +1 -1
- package/bin/session/execution/SessionAssistantOutputAdapter.js +7 -3
- package/bin/session/execution/SessionAssistantOutputAdapter.js.map +1 -1
- package/bin/session/messages/{SessionActionMessageWriter.d.ts → SessionAgentActionPartWriter.d.ts} +7 -7
- package/bin/session/messages/SessionAgentActionPartWriter.d.ts.map +1 -0
- package/bin/session/messages/{SessionActionMessageWriter.js → SessionAgentActionPartWriter.js} +7 -7
- package/bin/session/messages/SessionAgentActionPartWriter.js.map +1 -0
- package/bin/session/messages/SessionAgentContent.d.ts +10 -0
- package/bin/session/messages/SessionAgentContent.d.ts.map +1 -0
- package/bin/session/messages/SessionAgentContent.js +44 -0
- package/bin/session/messages/SessionAgentContent.js.map +1 -0
- package/bin/session/messages/SessionAgentMessageState.d.ts +50 -0
- package/bin/session/messages/SessionAgentMessageState.d.ts.map +1 -0
- package/bin/session/messages/SessionAgentMessageState.js +283 -0
- package/bin/session/messages/SessionAgentMessageState.js.map +1 -0
- package/bin/session/messages/{SessionAssistantMessageWriter.d.ts → SessionAgentMessageWriter.d.ts} +22 -8
- package/bin/session/messages/SessionAgentMessageWriter.d.ts.map +1 -0
- package/bin/session/messages/{SessionAssistantMessageWriter.js → SessionAgentMessageWriter.js} +54 -42
- package/bin/session/messages/SessionAgentMessageWriter.js.map +1 -0
- package/bin/session/messages/SessionForkMessageFiles.d.ts +11 -0
- package/bin/session/messages/SessionForkMessageFiles.d.ts.map +1 -1
- package/bin/session/messages/SessionForkMessageFiles.js +8 -2
- package/bin/session/messages/SessionForkMessageFiles.js.map +1 -1
- package/bin/session/messages/SessionMessageInteractionWriter.d.ts +6 -6
- package/bin/session/messages/SessionMessageInteractionWriter.d.ts.map +1 -1
- package/bin/session/messages/SessionMessageInteractionWriter.js +4 -4
- package/bin/session/messages/SessionMessageInteractionWriter.js.map +1 -1
- package/bin/session/messages/SessionMessageText.d.ts +3 -3
- package/bin/session/messages/SessionMessageText.d.ts.map +1 -1
- package/bin/session/messages/SessionMessageText.js +0 -2
- package/bin/session/messages/SessionMessageText.js.map +1 -1
- package/bin/session/messages/SessionTurnFileDiffData.d.ts +3 -3
- package/bin/session/messages/SessionTurnFileDiffData.d.ts.map +1 -1
- package/bin/session/messages/SessionTurnFileDiffData.js.map +1 -1
- package/bin/session/messages/SessionUserMessage.d.ts +3 -3
- package/bin/session/messages/SessionUserMessage.d.ts.map +1 -1
- package/bin/session/messages/SessionUserMessage.js +6 -3
- package/bin/session/messages/SessionUserMessage.js.map +1 -1
- package/bin/session/preview/SessionMessagePreview.d.ts.map +1 -1
- package/bin/session/preview/SessionMessagePreview.js +25 -9
- package/bin/session/preview/SessionMessagePreview.js.map +1 -1
- package/bin/session/runtime/SessionTurnCompletion.d.ts +15 -0
- package/bin/session/runtime/SessionTurnCompletion.d.ts.map +1 -0
- package/bin/session/runtime/SessionTurnCompletion.js +126 -0
- package/bin/session/runtime/SessionTurnCompletion.js.map +1 -0
- package/bin/session/runtime/SessionTurnContext.d.ts.map +1 -1
- package/bin/session/runtime/SessionTurnContext.js +14 -19
- package/bin/session/runtime/SessionTurnContext.js.map +1 -1
- package/bin/session/runtime/SessionTurnFileDiff.d.ts +12 -0
- package/bin/session/runtime/SessionTurnFileDiff.d.ts.map +1 -0
- package/bin/session/runtime/SessionTurnFileDiff.js +71 -0
- package/bin/session/runtime/SessionTurnFileDiff.js.map +1 -0
- package/bin/session/storage/LocalSessionDataStore.d.ts +6 -41
- package/bin/session/storage/LocalSessionDataStore.d.ts.map +1 -1
- package/bin/session/storage/LocalSessionDataStore.js +19 -101
- package/bin/session/storage/LocalSessionDataStore.js.map +1 -1
- package/bin/session/storage/LocalSessionStore.d.ts +13 -5
- package/bin/session/storage/LocalSessionStore.d.ts.map +1 -1
- package/bin/session/storage/LocalSessionStore.js +153 -30
- package/bin/session/storage/LocalSessionStore.js.map +1 -1
- package/bin/session/storage/LocalStorePaths.d.ts +4 -16
- package/bin/session/storage/LocalStorePaths.d.ts.map +1 -1
- package/bin/session/storage/LocalStorePaths.js +7 -31
- package/bin/session/storage/LocalStorePaths.js.map +1 -1
- package/bin/session/storage/Metadata.d.ts +4 -4
- package/bin/session/storage/Metadata.d.ts.map +1 -1
- package/bin/session/storage/Metadata.js +3 -11
- package/bin/session/storage/Metadata.js.map +1 -1
- package/bin/session/storage/RuntimeSessionPort.d.ts +4 -4
- package/bin/session/storage/RuntimeSessionPort.d.ts.map +1 -1
- package/bin/session/storage/RuntimeSessionPort.js +3 -3
- package/bin/session/storage/RuntimeSessionPort.js.map +1 -1
- package/bin/session/storage/SessionStorageCodec.d.ts +59 -0
- package/bin/session/storage/SessionStorageCodec.d.ts.map +1 -0
- package/bin/session/storage/SessionStorageCodec.js +331 -0
- package/bin/session/storage/SessionStorageCodec.js.map +1 -0
- package/bin/session/storage/SessionStorageSchema.d.ts +11 -0
- package/bin/session/storage/SessionStorageSchema.d.ts.map +1 -0
- package/bin/session/storage/SessionStorageSchema.js +131 -0
- package/bin/session/storage/SessionStorageSchema.js.map +1 -0
- package/bin/session/storage/SqliteSessionStorage.d.ts +120 -0
- package/bin/session/storage/SqliteSessionStorage.d.ts.map +1 -0
- package/bin/session/storage/SqliteSessionStorage.js +581 -0
- package/bin/session/storage/SqliteSessionStorage.js.map +1 -0
- package/bin/tools/ask/AskQuestionsTool.d.ts.map +1 -1
- package/bin/tools/ask/AskQuestionsTool.js +3 -1
- package/bin/tools/ask/AskQuestionsTool.js.map +1 -1
- package/bin/types/action/ActionResult.d.ts +9 -9
- package/bin/types/action/ActionResult.d.ts.map +1 -1
- package/bin/types/action/ActionResult.js +1 -1
- package/bin/types/agent/AgentOptions.d.ts +10 -0
- package/bin/types/agent/AgentOptions.d.ts.map +1 -1
- package/bin/types/agent/AgentStorage.d.ts +3 -1
- package/bin/types/agent/AgentStorage.d.ts.map +1 -1
- package/bin/types/agent/SessionActor.d.ts +0 -9
- package/bin/types/agent/SessionActor.d.ts.map +1 -1
- package/bin/types/agent/SessionTypes.d.ts +5 -5
- package/bin/types/agent/SessionTypes.d.ts.map +1 -1
- package/bin/types/executor/SessionAssistantOutput.d.ts +15 -4
- package/bin/types/executor/SessionAssistantOutput.d.ts.map +1 -1
- package/bin/types/executor/SessionTurnContext.d.ts +17 -19
- package/bin/types/executor/SessionTurnContext.d.ts.map +1 -1
- package/bin/types/sdk/AgentSessionAction.d.ts +1 -1
- package/bin/types/sdk/AgentSessionAction.js +1 -1
- package/bin/types/sdk/AgentSessionPrompt.d.ts +14 -5
- package/bin/types/sdk/AgentSessionPrompt.d.ts.map +1 -1
- package/bin/types/sdk/AgentSessionPrompt.js +1 -1
- package/bin/types/sdk/AgentSessionPrompt.js.map +1 -1
- package/bin/types/session/AdaptivePartContextPolicy.d.ts +31 -0
- package/bin/types/session/AdaptivePartContextPolicy.d.ts.map +1 -0
- package/bin/types/session/AdaptivePartContextPolicy.js +7 -0
- package/bin/types/session/AdaptivePartContextPolicy.js.map +1 -0
- package/bin/types/session/{SessionAssistantMessageState.d.ts → SessionAgentMessageState.d.ts} +7 -7
- package/bin/types/session/SessionAgentMessageState.d.ts.map +1 -0
- package/bin/types/session/{SessionAssistantMessageState.js → SessionAgentMessageState.js} +1 -1
- package/bin/types/session/SessionAgentMessageState.js.map +1 -0
- package/bin/types/session/SessionCommand.d.ts +19 -7
- package/bin/types/session/SessionCommand.d.ts.map +1 -1
- package/bin/types/session/SessionComposer.d.ts +43 -43
- package/bin/types/session/SessionComposer.d.ts.map +1 -1
- package/bin/types/session/SessionComposer.js +2 -2
- package/bin/types/session/SessionComposition.d.ts +2 -5
- package/bin/types/session/SessionComposition.d.ts.map +1 -1
- package/bin/types/session/SessionContextPolicy.d.ts +70 -0
- package/bin/types/session/SessionContextPolicy.d.ts.map +1 -0
- package/bin/types/session/SessionContextPolicy.js +8 -0
- package/bin/types/session/SessionContextPolicy.js.map +1 -0
- package/bin/types/session/SessionExecution.d.ts +5 -32
- package/bin/types/session/SessionExecution.d.ts.map +1 -1
- package/bin/types/session/SessionLoop.d.ts +3 -5
- package/bin/types/session/SessionLoop.d.ts.map +1 -1
- package/bin/types/session/SessionMessages.d.ts +18 -28
- package/bin/types/session/SessionMessages.d.ts.map +1 -1
- package/bin/types/session/SessionOptions.d.ts +5 -5
- package/bin/types/session/SessionOptions.d.ts.map +1 -1
- package/bin/types/session/SessionPort.d.ts +8 -9
- package/bin/types/session/SessionPort.d.ts.map +1 -1
- package/bin/types/session/SessionState.d.ts +2 -5
- package/bin/types/session/SessionState.d.ts.map +1 -1
- package/bin/types/session/SessionSystem.d.ts +14 -0
- package/bin/types/session/SessionSystem.d.ts.map +1 -1
- package/bin/types/session/SessionTool.d.ts +2 -2
- package/bin/types/session/SessionTool.d.ts.map +1 -1
- package/bin/types/session/SessionTurnCompletion.d.ts +23 -0
- package/bin/types/session/SessionTurnCompletion.d.ts.map +1 -0
- package/bin/types/session/SessionTurnCompletion.js +8 -0
- package/bin/types/session/SessionTurnCompletion.js.map +1 -0
- package/bin/types/session/SessionTurnFileDiff.d.ts +42 -0
- package/bin/types/session/SessionTurnFileDiff.d.ts.map +1 -0
- package/bin/types/session/SessionTurnFileDiff.js +8 -0
- package/bin/types/session/SessionTurnFileDiff.js.map +1 -0
- package/bin/types/store/LocalStore.d.ts +6 -13
- package/bin/types/store/LocalStore.d.ts.map +1 -1
- package/bin/types/store/LocalStore.js +1 -1
- package/bin/types/store/SessionStorage.d.ts +103 -0
- package/bin/types/store/SessionStorage.d.ts.map +1 -0
- package/bin/types/store/SessionStorage.js +8 -0
- package/bin/types/store/SessionStorage.js.map +1 -0
- package/bin/types/store/SessionStore.d.ts +5 -3
- package/bin/types/store/SessionStore.d.ts.map +1 -1
- package/package.json +2 -2
- package/scripts/core-engine-context-compaction.test.mjs +96 -219
- package/scripts/core-engine-model-stream.test.mjs +2 -4
- package/scripts/executor-failure-result.test.mjs +14 -17
- package/scripts/session-agent-message-part-order.test.mjs +63 -0
- package/scripts/session-initialization.test.mjs +141 -0
- package/scripts/session-message-timeline.test.mjs +5 -6
- package/scripts/session-messages-error-part.test.mjs +175 -0
- package/scripts/session-messages-error.test.mjs +47 -6
- package/scripts/session-prompt-idempotency.test.mjs +91 -0
- package/scripts/session-queue.test.mjs +13 -12
- package/scripts/session-storage-sqlite.test.mjs +209 -0
- package/scripts/session-turn-context.test.mjs +21 -33
- package/src/agent/Agent.ts +48 -12
- package/src/agent/AgentInstructions.ts +2 -2
- package/src/agent/AgentMemoryStorage.ts +1 -0
- package/src/agent/AgentSessions.ts +31 -12
- package/src/executor/Executor.ts +47 -184
- package/src/executor/README.md +12 -13
- package/src/executor/composer/system/default/SystemPromptAssets.ts +0 -6
- package/src/executor/core-engine/CoreEngineContextCompaction.ts +3 -135
- package/src/executor/core-engine/CoreEngineRunner.ts +51 -273
- package/src/executor/core-engine/CoreEngineSignals.ts +9 -9
- package/src/executor/messages/SessionAttachmentMapper.ts +4 -4
- package/src/executor/messages/SessionMessageLog.ts +3 -3
- package/src/executor/messages/SessionModelMessages.ts +85 -103
- package/src/executor/model/ModelStepRunner.ts +9 -41
- package/src/executor/services/ExecutorRecoveryPolicy.ts +34 -127
- package/src/executor/types/SessionHistoryMeta.ts +1 -3
- package/src/index.ts +39 -47
- package/src/session/DefaultSessionComposer.ts +33 -30
- package/src/session/Session.ts +96 -227
- package/src/session/SessionComposition.ts +28 -65
- package/src/session/SessionLoop.ts +267 -370
- package/src/session/SessionMessages.ts +363 -242
- package/src/session/SessionQueue.ts +3 -2
- package/src/session/SessionState.ts +55 -101
- package/src/session/SessionSystem.ts +51 -1
- package/src/session/SessionTitle.ts +4 -4
- package/src/session/browse/Browse.ts +182 -468
- package/src/session/browse/SessionMessageTimeline.ts +63 -38
- package/src/session/composer/policies/AdaptivePartContextPolicy.ts +307 -0
- package/src/session/composer/policies/FullHistoryContextPolicy.ts +36 -0
- package/src/session/composer/policies/SessionSummaryPrompts.ts +42 -0
- package/src/session/execution/SessionAssistantOutputAdapter.ts +25 -11
- package/src/session/messages/{SessionActionMessageWriter.ts → SessionAgentActionPartWriter.ts} +8 -8
- package/src/session/messages/SessionAgentContent.ts +56 -0
- package/src/session/messages/SessionAgentMessageState.ts +378 -0
- package/src/session/messages/{SessionAssistantMessageWriter.ts → SessionAgentMessageWriter.ts} +89 -60
- package/src/session/messages/SessionForkMessageFiles.ts +25 -1
- package/src/session/messages/SessionMessageInteractionWriter.ts +19 -19
- package/src/session/messages/SessionMessageText.ts +3 -4
- package/src/session/messages/SessionTurnFileDiffData.ts +3 -3
- package/src/session/messages/SessionUserMessage.ts +10 -7
- package/src/session/preview/SessionMessagePreview.ts +26 -9
- package/src/session/runtime/SessionTurnCompletion.ts +159 -0
- package/src/session/runtime/SessionTurnContext.ts +20 -21
- package/src/session/runtime/SessionTurnFileDiff.ts +105 -0
- package/src/session/storage/LocalSessionDataStore.ts +27 -176
- package/src/session/storage/LocalSessionStore.ts +170 -38
- package/src/session/storage/LocalStorePaths.ts +14 -86
- package/src/session/storage/Metadata.ts +4 -13
- package/src/session/storage/RuntimeSessionPort.ts +7 -7
- package/src/session/storage/SessionStorageCodec.ts +465 -0
- package/src/session/storage/SessionStorageSchema.ts +132 -0
- package/src/session/storage/SqliteSessionStorage.ts +776 -0
- package/src/tools/ask/AskQuestionsTool.ts +3 -1
- package/src/types/action/ActionResult.ts +10 -10
- package/src/types/agent/AgentOptions.ts +11 -0
- package/src/types/agent/AgentStorage.ts +3 -1
- package/src/types/agent/SessionActor.ts +0 -10
- package/src/types/agent/SessionTypes.ts +5 -5
- package/src/types/executor/SessionAssistantOutput.ts +15 -4
- package/src/types/executor/SessionTurnContext.ts +25 -22
- package/src/types/sdk/AgentSessionAction.ts +1 -1
- package/src/types/sdk/AgentSessionPrompt.ts +15 -5
- package/src/types/session/AdaptivePartContextPolicy.ts +37 -0
- package/src/types/session/{SessionAssistantMessageState.ts → SessionAgentMessageState.ts} +6 -6
- package/src/types/session/SessionCommand.ts +21 -7
- package/src/types/session/SessionComposer.ts +48 -48
- package/src/types/session/SessionComposition.ts +2 -5
- package/src/types/session/SessionContextPolicy.ts +77 -0
- package/src/types/session/SessionExecution.ts +11 -36
- package/src/types/session/SessionLoop.ts +3 -8
- package/src/types/session/SessionMessages.ts +19 -29
- package/src/types/session/SessionOptions.ts +5 -5
- package/src/types/session/SessionPort.ts +10 -10
- package/src/types/session/SessionState.ts +2 -5
- package/src/types/session/SessionSystem.ts +19 -0
- package/src/types/session/SessionTool.ts +2 -2
- package/src/types/session/SessionTurnCompletion.ts +24 -0
- package/src/types/session/SessionTurnFileDiff.ts +44 -0
- package/src/types/store/LocalStore.ts +6 -14
- package/src/types/store/SessionStorage.ts +121 -0
- package/src/types/store/SessionStore.ts +6 -3
- package/tsconfig.tsbuildinfo +1 -1
- package/bin/executor/composer/compaction/jsonl/JsonlSessionCompactionPrompts.d.ts +0 -45
- package/bin/executor/composer/compaction/jsonl/JsonlSessionCompactionPrompts.d.ts.map +0 -1
- package/bin/executor/composer/compaction/jsonl/JsonlSessionCompactionPrompts.js +0 -144
- package/bin/executor/composer/compaction/jsonl/JsonlSessionCompactionPrompts.js.map +0 -1
- package/bin/executor/composer/system/SessionSystemComposer.d.ts +0 -23
- package/bin/executor/composer/system/SessionSystemComposer.d.ts.map +0 -1
- package/bin/executor/composer/system/SessionSystemComposer.js +0 -9
- package/bin/executor/composer/system/SessionSystemComposer.js.map +0 -1
- package/bin/executor/composer/system/default/DefaultSessionSystemComposer.d.ts +0 -43
- package/bin/executor/composer/system/default/DefaultSessionSystemComposer.d.ts.map +0 -1
- package/bin/executor/composer/system/default/DefaultSessionSystemComposer.js +0 -42
- package/bin/executor/composer/system/default/DefaultSessionSystemComposer.js.map +0 -1
- package/bin/executor/composer/system/default/PromptRenderer.d.ts +0 -35
- package/bin/executor/composer/system/default/PromptRenderer.d.ts.map +0 -1
- package/bin/executor/composer/system/default/PromptRenderer.js +0 -23
- package/bin/executor/composer/system/default/PromptRenderer.js.map +0 -1
- package/bin/executor/composer/system/default/SystemDomain.d.ts +0 -151
- package/bin/executor/composer/system/default/SystemDomain.d.ts.map +0 -1
- package/bin/executor/composer/system/default/SystemDomain.js +0 -162
- package/bin/executor/composer/system/default/SystemDomain.js.map +0 -1
- package/bin/executor/composer/system/default/assets/task.prompt.d.ts +0 -7
- package/bin/executor/composer/system/default/assets/task.prompt.d.ts.map +0 -1
- package/bin/executor/composer/system/default/assets/task.prompt.js +0 -8
- package/bin/executor/composer/system/default/assets/task.prompt.js.map +0 -1
- package/bin/executor/composer/system/default/variables/GeoContext.d.ts +0 -14
- package/bin/executor/composer/system/default/variables/GeoContext.d.ts.map +0 -1
- package/bin/executor/composer/system/default/variables/GeoContext.js +0 -150
- package/bin/executor/composer/system/default/variables/GeoContext.js.map +0 -1
- package/bin/executor/composer/system/default/variables/PromptTypes.d.ts +0 -36
- package/bin/executor/composer/system/default/variables/PromptTypes.d.ts.map +0 -1
- package/bin/executor/composer/system/default/variables/PromptTypes.js +0 -9
- package/bin/executor/composer/system/default/variables/PromptTypes.js.map +0 -1
- package/bin/executor/composer/system/default/variables/VariableReplacer.d.ts +0 -61
- package/bin/executor/composer/system/default/variables/VariableReplacer.d.ts.map +0 -1
- package/bin/executor/composer/system/default/variables/VariableReplacer.js +0 -93
- package/bin/executor/composer/system/default/variables/VariableReplacer.js.map +0 -1
- package/bin/executor/core-engine/CoreEngineMessageState.d.ts +0 -63
- package/bin/executor/core-engine/CoreEngineMessageState.d.ts.map +0 -1
- package/bin/executor/core-engine/CoreEngineMessageState.js +0 -81
- package/bin/executor/core-engine/CoreEngineMessageState.js.map +0 -1
- package/bin/session/SessionCommand.d.ts +0 -24
- package/bin/session/SessionCommand.d.ts.map +0 -1
- package/bin/session/SessionCommand.js +0 -35
- package/bin/session/SessionCommand.js.map +0 -1
- package/bin/session/messages/SessionActionMessageWriter.d.ts.map +0 -1
- package/bin/session/messages/SessionActionMessageWriter.js.map +0 -1
- package/bin/session/messages/SessionAssistantMessageState.d.ts +0 -49
- package/bin/session/messages/SessionAssistantMessageState.d.ts.map +0 -1
- package/bin/session/messages/SessionAssistantMessageState.js +0 -296
- package/bin/session/messages/SessionAssistantMessageState.js.map +0 -1
- package/bin/session/messages/SessionAssistantMessageWriter.d.ts.map +0 -1
- package/bin/session/messages/SessionAssistantMessageWriter.js.map +0 -1
- package/bin/session/messages/SessionMessageCompaction.d.ts +0 -29
- package/bin/session/messages/SessionMessageCompaction.d.ts.map +0 -1
- package/bin/session/messages/SessionMessageCompaction.js +0 -128
- package/bin/session/messages/SessionMessageCompaction.js.map +0 -1
- package/bin/session/runtime/SessionCompactOperation.d.ts +0 -29
- package/bin/session/runtime/SessionCompactOperation.d.ts.map +0 -1
- package/bin/session/runtime/SessionCompactOperation.js +0 -66
- package/bin/session/runtime/SessionCompactOperation.js.map +0 -1
- package/bin/session/runtime/SessionHistoryCompaction.d.ts +0 -22
- package/bin/session/runtime/SessionHistoryCompaction.d.ts.map +0 -1
- package/bin/session/runtime/SessionHistoryCompaction.js +0 -31
- package/bin/session/runtime/SessionHistoryCompaction.js.map +0 -1
- package/bin/session/storage/JsonlSessionMessageStore.d.ts +0 -77
- package/bin/session/storage/JsonlSessionMessageStore.d.ts.map +0 -1
- package/bin/session/storage/JsonlSessionMessageStore.js +0 -419
- package/bin/session/storage/JsonlSessionMessageStore.js.map +0 -1
- package/bin/session/storage/SessionMessageStoreFactory.d.ts +0 -12
- package/bin/session/storage/SessionMessageStoreFactory.d.ts.map +0 -1
- package/bin/session/storage/SessionMessageStoreFactory.js +0 -13
- package/bin/session/storage/SessionMessageStoreFactory.js.map +0 -1
- package/bin/types/common/Template.d.ts +0 -9
- package/bin/types/common/Template.d.ts.map +0 -1
- package/bin/types/common/Template.js +0 -9
- package/bin/types/common/Template.js.map +0 -1
- package/bin/types/sdk/AgentSessionCompact.d.ts +0 -30
- package/bin/types/sdk/AgentSessionCompact.d.ts.map +0 -1
- package/bin/types/sdk/AgentSessionCompact.js +0 -8
- package/bin/types/sdk/AgentSessionCompact.js.map +0 -1
- package/bin/types/session/SessionAssistantMessageState.d.ts.map +0 -1
- package/bin/types/session/SessionAssistantMessageState.js.map +0 -1
- package/bin/types/session/SessionSegment.d.ts +0 -57
- package/bin/types/session/SessionSegment.d.ts.map +0 -1
- package/bin/types/session/SessionSegment.js +0 -8
- package/bin/types/session/SessionSegment.js.map +0 -1
- package/bin/types/store/SessionDataStore.d.ts +0 -88
- package/bin/types/store/SessionDataStore.d.ts.map +0 -1
- package/bin/types/store/SessionDataStore.js +0 -9
- package/bin/types/store/SessionDataStore.js.map +0 -1
- package/bin/utils/Template.d.ts +0 -17
- package/bin/utils/Template.d.ts.map +0 -1
- package/bin/utils/Template.js +0 -24
- package/bin/utils/Template.js.map +0 -1
- package/scripts/session-compaction-prompts.test.mjs +0 -49
- package/src/executor/composer/compaction/jsonl/JsonlSessionCompactionPrompts.ts +0 -162
- package/src/executor/composer/system/SessionSystemComposer.ts +0 -25
- package/src/executor/composer/system/default/DefaultSessionSystemComposer.ts +0 -76
- package/src/executor/composer/system/default/PromptRenderer.ts +0 -52
- package/src/executor/composer/system/default/SystemDomain.ts +0 -301
- package/src/executor/composer/system/default/assets/task.prompt.ts +0 -9
- package/src/executor/composer/system/default/assets/task.prompt.ts.txt +0 -33
- package/src/executor/composer/system/default/variables/GeoContext.ts +0 -180
- package/src/executor/composer/system/default/variables/PromptTypes.ts +0 -37
- package/src/executor/composer/system/default/variables/VariableReplacer.ts +0 -154
- package/src/executor/core-engine/CoreEngineMessageState.ts +0 -117
- package/src/session/SessionCommand.ts +0 -42
- package/src/session/messages/SessionAssistantMessageState.ts +0 -392
- package/src/session/messages/SessionMessageCompaction.ts +0 -160
- package/src/session/runtime/SessionCompactOperation.ts +0 -93
- package/src/session/runtime/SessionHistoryCompaction.ts +0 -45
- package/src/session/storage/JsonlSessionMessageStore.ts +0 -513
- package/src/session/storage/SessionMessageStoreFactory.ts +0 -18
- package/src/types/common/Template.ts +0 -9
- package/src/types/sdk/AgentSessionCompact.ts +0 -32
- package/src/types/session/SessionSegment.ts +0 -62
- package/src/types/store/SessionDataStore.ts +0 -113
- package/src/utils/Template.ts +0 -28
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
*
|
|
4
4
|
* 职责说明(中文)
|
|
5
5
|
* - 统一管理 Session 创建判断、删除、列表、归档与清理。
|
|
6
|
-
* - 缓存稳定的 LocalSessionDataStore,避免同一 Session 重复创建
|
|
6
|
+
* - 缓存稳定的 LocalSessionDataStore,避免同一 Session 重复创建 SQLite Storage。
|
|
7
7
|
* - 使用来源类型建立确定性一级分区,避免跨来源扫描。
|
|
8
8
|
*/
|
|
9
9
|
|
|
@@ -14,23 +14,25 @@ import type {
|
|
|
14
14
|
AgentArchiveSessionsResult,
|
|
15
15
|
AgentCleanArchiveResult,
|
|
16
16
|
AgentListSessionsInput,
|
|
17
|
+
AgentSessionSummary,
|
|
17
18
|
AgentSessionSummaryPage,
|
|
18
19
|
} from "@/types/agent/SessionTypes.js";
|
|
19
20
|
import type { SessionStore } from "@/types/store/SessionStore.js";
|
|
20
|
-
import type {
|
|
21
|
+
import type { SessionStorage } from "@/types/store/SessionStorage.js";
|
|
21
22
|
import { LocalSessionDataStore } from "@/session/storage/LocalSessionDataStore.js";
|
|
22
23
|
import {
|
|
23
|
-
|
|
24
|
+
get_agent_archived_session_database_path,
|
|
24
25
|
get_agent_archived_session_origins_path,
|
|
25
26
|
get_agent_archived_session_path,
|
|
26
27
|
get_agent_archived_sessions_path,
|
|
27
|
-
|
|
28
|
-
get_agent_session_meta_path,
|
|
28
|
+
get_agent_session_database_path,
|
|
29
29
|
get_agent_session_path,
|
|
30
30
|
} from "@/session/storage/LocalStorePaths.js";
|
|
31
31
|
import {
|
|
32
|
+
build_session_info,
|
|
32
33
|
list_archived_agent_session_summary_page,
|
|
33
34
|
list_agent_session_summary_page,
|
|
35
|
+
read_session_metadata_from_database,
|
|
34
36
|
} from "@/session/browse/Browse.js";
|
|
35
37
|
import type { FileSystem } from "@downcity/type";
|
|
36
38
|
import type { LocalSessionStoreOptions } from "@/types/store/LocalStore.js";
|
|
@@ -60,25 +62,32 @@ export class LocalSessionStore implements SessionStore {
|
|
|
60
62
|
/** 当前 Agent 内部数据根路径。 */
|
|
61
63
|
private readonly storage_root_path: string;
|
|
62
64
|
|
|
65
|
+
/** Session 数据库使用本地文件还是进程内存。 */
|
|
66
|
+
private readonly database_location: LocalSessionStoreOptions["database_location"];
|
|
67
|
+
|
|
63
68
|
/** 已创建的 Session Store 缓存。 */
|
|
64
69
|
private readonly sessions = new Map<string, LocalSessionDataStore>();
|
|
65
70
|
|
|
71
|
+
/** 内存模式中已归档但仍由 Store 持有的 Session。 */
|
|
72
|
+
private readonly archived_sessions = new Map<string, LocalSessionDataStore>();
|
|
73
|
+
|
|
66
74
|
constructor(options: LocalSessionStoreOptions) {
|
|
67
75
|
this.files = options.files;
|
|
68
76
|
this.agent_id = options.agent_id;
|
|
69
77
|
this.workspace_id = options.workspace_id;
|
|
70
78
|
this.storage_root_path = options.storage_root_path;
|
|
79
|
+
this.database_location = options.database_location;
|
|
71
80
|
}
|
|
72
81
|
|
|
73
|
-
/**
|
|
74
|
-
|
|
82
|
+
/** 为新 Session 创建稳定持久化视图。 */
|
|
83
|
+
create_session(
|
|
75
84
|
session_id: string,
|
|
76
85
|
origin: SessionOrigin,
|
|
77
86
|
workspace_id = this.workspace_id,
|
|
78
|
-
):
|
|
87
|
+
): SessionStorage {
|
|
79
88
|
const resolved_session_id = String(session_id || "").trim();
|
|
80
89
|
if (!resolved_session_id) {
|
|
81
|
-
throw new Error("SessionStore.
|
|
90
|
+
throw new Error("SessionStore.create_session requires a non-empty session_id");
|
|
82
91
|
}
|
|
83
92
|
const resolved_origin = normalize_session_origin(origin);
|
|
84
93
|
const cache_key = this.session_cache_key(resolved_session_id, resolved_origin.type);
|
|
@@ -94,6 +103,7 @@ export class LocalSessionStore implements SessionStore {
|
|
|
94
103
|
files: this.files,
|
|
95
104
|
storage_root_path: this.storage_root_path,
|
|
96
105
|
agent_id: this.agent_id,
|
|
106
|
+
database_location: this.database_location,
|
|
97
107
|
workspace_id: workspace_id,
|
|
98
108
|
session_id: resolved_session_id,
|
|
99
109
|
origin: resolved_origin,
|
|
@@ -102,11 +112,55 @@ export class LocalSessionStore implements SessionStore {
|
|
|
102
112
|
return created;
|
|
103
113
|
}
|
|
104
114
|
|
|
115
|
+
/** 打开已有 Session,并以数据库中的完整 origin 作为唯一事实。 */
|
|
116
|
+
async open_session(session_id: string, origin_type = "chat"): Promise<SessionStorage> {
|
|
117
|
+
const resolved_session_id = String(session_id || "").trim();
|
|
118
|
+
if (!resolved_session_id) {
|
|
119
|
+
throw new Error("SessionStore.open_session requires a non-empty session_id");
|
|
120
|
+
}
|
|
121
|
+
const resolved_origin_type = normalize_session_origin_type(origin_type);
|
|
122
|
+
const cache_key = this.session_cache_key(resolved_session_id, resolved_origin_type);
|
|
123
|
+
const cached = this.sessions.get(cache_key);
|
|
124
|
+
if (cached) return cached;
|
|
125
|
+
if (this.database_location.type === "memory") {
|
|
126
|
+
throw new Error(`Session "${resolved_session_id}" not found`);
|
|
127
|
+
}
|
|
128
|
+
const database_path = get_agent_session_database_path(
|
|
129
|
+
this.storage_root_path,
|
|
130
|
+
resolved_origin_type,
|
|
131
|
+
resolved_session_id,
|
|
132
|
+
);
|
|
133
|
+
if (!(await this.files.path_exists(database_path))) {
|
|
134
|
+
throw new Error(`Session "${resolved_session_id}" not found`);
|
|
135
|
+
}
|
|
136
|
+
const metadata = read_session_metadata_from_database(database_path, resolved_origin_type);
|
|
137
|
+
if (!metadata || metadata.agent_id !== this.agent_id) {
|
|
138
|
+
throw new Error(`Session "${resolved_session_id}" belongs to another Agent`);
|
|
139
|
+
}
|
|
140
|
+
const opened = new LocalSessionDataStore({
|
|
141
|
+
files: this.files,
|
|
142
|
+
storage_root_path: this.storage_root_path,
|
|
143
|
+
agent_id: this.agent_id,
|
|
144
|
+
database_location: this.database_location,
|
|
145
|
+
...(metadata.workspace_id ? { workspace_id: metadata.workspace_id } : {}),
|
|
146
|
+
session_id: resolved_session_id,
|
|
147
|
+
origin: metadata.origin,
|
|
148
|
+
});
|
|
149
|
+
this.sessions.set(cache_key, opened);
|
|
150
|
+
return opened;
|
|
151
|
+
}
|
|
152
|
+
|
|
105
153
|
/** 判断活动 Session 是否存在。 */
|
|
106
154
|
async has_session(session_id: string, origin_type = "chat"): Promise<boolean> {
|
|
107
155
|
const resolved_origin_type = normalize_session_origin_type(origin_type);
|
|
108
|
-
const
|
|
109
|
-
if (
|
|
156
|
+
const cache_key = this.session_cache_key(session_id, resolved_origin_type);
|
|
157
|
+
if (this.database_location.type === "memory") return this.sessions.has(cache_key);
|
|
158
|
+
const database_path = get_agent_session_database_path(
|
|
159
|
+
this.storage_root_path,
|
|
160
|
+
resolved_origin_type,
|
|
161
|
+
session_id,
|
|
162
|
+
);
|
|
163
|
+
if (!(await this.files.path_exists(database_path))) return false;
|
|
110
164
|
await this.assert_session_owner(session_id, resolved_origin_type, false);
|
|
111
165
|
return true;
|
|
112
166
|
}
|
|
@@ -115,30 +169,31 @@ export class LocalSessionStore implements SessionStore {
|
|
|
115
169
|
async remove_session(session_id: string, origin_type = "chat"): Promise<boolean> {
|
|
116
170
|
const resolved_origin_type = normalize_session_origin_type(origin_type);
|
|
117
171
|
const session_path = this.session_path(session_id, resolved_origin_type);
|
|
118
|
-
const
|
|
172
|
+
const cache_key = this.session_cache_key(session_id, resolved_origin_type);
|
|
173
|
+
const cached = this.sessions.get(cache_key);
|
|
174
|
+
const existed = this.database_location.type === "memory"
|
|
175
|
+
? Boolean(cached)
|
|
176
|
+
: await this.files.path_exists(get_agent_session_database_path(
|
|
177
|
+
this.storage_root_path,
|
|
178
|
+
resolved_origin_type,
|
|
179
|
+
session_id,
|
|
180
|
+
));
|
|
119
181
|
if (existed) {
|
|
120
182
|
await this.assert_session_owner(session_id, resolved_origin_type, false);
|
|
183
|
+
await cached?.dispose();
|
|
121
184
|
await this.files.remove_path(session_path);
|
|
122
185
|
}
|
|
123
|
-
this.sessions.delete(
|
|
186
|
+
this.sessions.delete(cache_key);
|
|
124
187
|
return existed;
|
|
125
188
|
}
|
|
126
189
|
|
|
127
190
|
/** 清空活动 Session Message 数据。 */
|
|
128
191
|
async clear_session_messages(session_id: string, origin_type = "chat"): Promise<boolean> {
|
|
129
192
|
const resolved_origin_type = normalize_session_origin_type(origin_type);
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
);
|
|
135
|
-
const existed = await this.files.path_exists(messages_path);
|
|
136
|
-
if (existed) {
|
|
137
|
-
await this.assert_session_owner(session_id, resolved_origin_type, false);
|
|
138
|
-
await this.files.remove_path(messages_path);
|
|
139
|
-
}
|
|
140
|
-
this.sessions.delete(this.session_cache_key(session_id, resolved_origin_type));
|
|
141
|
-
return existed;
|
|
193
|
+
if (!(await this.has_session(session_id, resolved_origin_type))) return false;
|
|
194
|
+
const storage = await this.open_session(session_id, resolved_origin_type);
|
|
195
|
+
await storage.clear_messages();
|
|
196
|
+
return true;
|
|
142
197
|
}
|
|
143
198
|
|
|
144
199
|
/** 返回活动 Session 摘要页。 */
|
|
@@ -146,12 +201,15 @@ export class LocalSessionStore implements SessionStore {
|
|
|
146
201
|
input: AgentListSessionsInput | undefined,
|
|
147
202
|
executing_session_ids: ReadonlySet<string>,
|
|
148
203
|
): Promise<AgentSessionSummaryPage> {
|
|
204
|
+
if (this.database_location.type === "memory") {
|
|
205
|
+
return await this.list_cached_sessions(input, executing_session_ids);
|
|
206
|
+
}
|
|
149
207
|
return await list_agent_session_summary_page({
|
|
150
208
|
project_root: this.storage_root_path,
|
|
151
209
|
agent_id: this.agent_id,
|
|
152
210
|
...(this.workspace_id || input?.workspace_id ? { workspace_id: this.workspace_id || input?.workspace_id } : {}),
|
|
153
211
|
input,
|
|
154
|
-
|
|
212
|
+
executing_session_ids,
|
|
155
213
|
files: this.files,
|
|
156
214
|
});
|
|
157
215
|
}
|
|
@@ -159,11 +217,23 @@ export class LocalSessionStore implements SessionStore {
|
|
|
159
217
|
/** 将活动 Session 迁入归档区。 */
|
|
160
218
|
async archive_session(session_id: string, origin_type = "chat"): Promise<AgentArchiveSessionResult> {
|
|
161
219
|
const resolved_origin_type = normalize_session_origin_type(origin_type);
|
|
220
|
+
const cache_key = this.session_cache_key(session_id, resolved_origin_type);
|
|
221
|
+
if (this.database_location.type === "memory") {
|
|
222
|
+
const storage = this.sessions.get(cache_key);
|
|
223
|
+
if (!storage) throw new Error(`Session "${session_id}" not found`);
|
|
224
|
+
if (this.archived_sessions.has(cache_key)) {
|
|
225
|
+
throw new Error(`Archived session "${session_id}" already exists`);
|
|
226
|
+
}
|
|
227
|
+
this.sessions.delete(cache_key);
|
|
228
|
+
this.archived_sessions.set(cache_key, storage);
|
|
229
|
+
return { session_id, archived_at: Date.now() };
|
|
230
|
+
}
|
|
162
231
|
const source_path = this.session_path(session_id, resolved_origin_type);
|
|
163
232
|
if (!(await this.files.path_exists(source_path))) {
|
|
164
233
|
throw new Error(`Session "${session_id}" not found`);
|
|
165
234
|
}
|
|
166
235
|
await this.assert_session_owner(session_id, resolved_origin_type, false);
|
|
236
|
+
await this.sessions.get(cache_key)?.dispose();
|
|
167
237
|
const target_path = get_agent_archived_session_path(
|
|
168
238
|
this.storage_root_path,
|
|
169
239
|
resolved_origin_type,
|
|
@@ -177,7 +247,7 @@ export class LocalSessionStore implements SessionStore {
|
|
|
177
247
|
resolved_origin_type,
|
|
178
248
|
));
|
|
179
249
|
await this.files.move_path(source_path, target_path);
|
|
180
|
-
this.sessions.delete(
|
|
250
|
+
this.sessions.delete(cache_key);
|
|
181
251
|
return {
|
|
182
252
|
session_id: session_id,
|
|
183
253
|
archived_at: Date.now(),
|
|
@@ -188,6 +258,9 @@ export class LocalSessionStore implements SessionStore {
|
|
|
188
258
|
async list_archived_sessions(
|
|
189
259
|
input?: AgentArchiveSessionsInput,
|
|
190
260
|
): Promise<AgentArchiveSessionsResult> {
|
|
261
|
+
if (this.database_location.type === "memory") {
|
|
262
|
+
return await this.list_cached_sessions(input, new Set(), this.archived_sessions);
|
|
263
|
+
}
|
|
191
264
|
return await list_archived_agent_session_summary_page({
|
|
192
265
|
project_root: this.storage_root_path,
|
|
193
266
|
agent_id: this.agent_id,
|
|
@@ -199,6 +272,12 @@ export class LocalSessionStore implements SessionStore {
|
|
|
199
272
|
|
|
200
273
|
/** 永久删除全部归档 Session。 */
|
|
201
274
|
async clean_archive(): Promise<AgentCleanArchiveResult> {
|
|
275
|
+
if (this.database_location.type === "memory") {
|
|
276
|
+
const archived = [...this.archived_sessions.values()];
|
|
277
|
+
this.archived_sessions.clear();
|
|
278
|
+
await Promise.all(archived.map(async (storage) => await storage.dispose()));
|
|
279
|
+
return { removed_session_ids: archived.map((storage) => storage.session_id) };
|
|
280
|
+
}
|
|
202
281
|
const archive_root_path = get_agent_archived_session_origins_path(this.storage_root_path);
|
|
203
282
|
if (!(await this.files.path_exists(archive_root_path))) {
|
|
204
283
|
return { removed_session_ids: [] };
|
|
@@ -227,8 +306,13 @@ export class LocalSessionStore implements SessionStore {
|
|
|
227
306
|
return { removed_session_ids: removed_session_ids };
|
|
228
307
|
}
|
|
229
308
|
|
|
230
|
-
/**
|
|
231
|
-
async dispose(): Promise<void> {
|
|
309
|
+
/** 关闭全部 Session SQLite 连接并清空缓存。 */
|
|
310
|
+
async dispose(): Promise<void> {
|
|
311
|
+
const storages = [...this.sessions.values(), ...this.archived_sessions.values()];
|
|
312
|
+
this.sessions.clear();
|
|
313
|
+
this.archived_sessions.clear();
|
|
314
|
+
await Promise.all(storages.map(async (storage) => await storage.dispose()));
|
|
315
|
+
}
|
|
232
316
|
|
|
233
317
|
/** 返回活动 Session 物理目录,仅供本地实现内部使用。 */
|
|
234
318
|
private session_path(session_id: string, origin_type: string): string {
|
|
@@ -257,22 +341,70 @@ export class LocalSessionStore implements SessionStore {
|
|
|
257
341
|
origin_type: string,
|
|
258
342
|
archived: boolean,
|
|
259
343
|
): Promise<boolean> {
|
|
344
|
+
const cache_key = this.session_cache_key(session_id, origin_type);
|
|
345
|
+
if (this.database_location.type === "memory") {
|
|
346
|
+
const cached = (archived ? this.archived_sessions : this.sessions).get(cache_key);
|
|
347
|
+
if (cached) {
|
|
348
|
+
try {
|
|
349
|
+
const metadata = await cached.read_metadata();
|
|
350
|
+
return metadata.agent_id === this.agent_id && metadata.origin.type === origin_type;
|
|
351
|
+
} catch {
|
|
352
|
+
return false;
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
return false;
|
|
356
|
+
}
|
|
260
357
|
const file_path = archived
|
|
261
|
-
?
|
|
358
|
+
? get_agent_archived_session_database_path(
|
|
262
359
|
this.storage_root_path,
|
|
263
360
|
origin_type,
|
|
264
361
|
session_id,
|
|
265
362
|
)
|
|
266
|
-
:
|
|
363
|
+
: get_agent_session_database_path(this.storage_root_path, origin_type, session_id);
|
|
267
364
|
if (!(await this.files.path_exists(file_path))) return false;
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
365
|
+
const metadata = read_session_metadata_from_database(file_path, origin_type);
|
|
366
|
+
return metadata?.agent_id === this.agent_id && metadata.origin.type === origin_type;
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
/** 从内存数据库缓存投影 Session 列表。 */
|
|
370
|
+
private async list_cached_sessions(
|
|
371
|
+
input: AgentListSessionsInput | AgentArchiveSessionsInput | undefined,
|
|
372
|
+
executing_session_ids: ReadonlySet<string>,
|
|
373
|
+
storages = this.sessions,
|
|
374
|
+
): Promise<AgentSessionSummaryPage> {
|
|
375
|
+
const origin_type = normalize_session_origin_type(input?.origin_type ?? "chat");
|
|
376
|
+
const query = String(input?.query || "").trim().toLowerCase();
|
|
377
|
+
const summaries: AgentSessionSummary[] = [];
|
|
378
|
+
for (const storage of storages.values()) {
|
|
379
|
+
if (storage.origin.type !== origin_type) continue;
|
|
380
|
+
const metadata = await storage.read_metadata();
|
|
381
|
+
if ((this.workspace_id || input?.workspace_id) &&
|
|
382
|
+
metadata.workspace_id !== (this.workspace_id || input?.workspace_id)) continue;
|
|
383
|
+
const summary = build_session_info({
|
|
384
|
+
project_root: this.storage_root_path,
|
|
385
|
+
agent_id: this.agent_id,
|
|
386
|
+
session_id: storage.session_id,
|
|
387
|
+
metadata,
|
|
388
|
+
executing: executing_session_ids.has(storage.session_id),
|
|
389
|
+
});
|
|
390
|
+
if (query && ![
|
|
391
|
+
summary.session_id,
|
|
392
|
+
summary.title || "",
|
|
393
|
+
summary.preview_text || "",
|
|
394
|
+
].join("\n").toLowerCase().includes(query)) continue;
|
|
395
|
+
summaries.push(summary);
|
|
275
396
|
}
|
|
397
|
+
summaries.sort((left, right) => (right.updated_at || 0) - (left.updated_at || 0));
|
|
398
|
+
const cursor = Math.max(0, Number(input?.cursor) || 0);
|
|
399
|
+
const limit = Math.min(Math.max(input?.limit ?? 50, 1), 500);
|
|
400
|
+
const items = summaries.slice(cursor, cursor + limit);
|
|
401
|
+
const next_cursor = cursor + items.length;
|
|
402
|
+
return {
|
|
403
|
+
items,
|
|
404
|
+
total: summaries.length,
|
|
405
|
+
...(next_cursor < summaries.length ? { next_cursor: String(next_cursor) } : {}),
|
|
406
|
+
has_more: next_cursor < summaries.length,
|
|
407
|
+
};
|
|
276
408
|
}
|
|
277
409
|
|
|
278
410
|
/** 返回来源分区内唯一的 Session Store 缓存键。 */
|
|
@@ -74,122 +74,50 @@ export function get_agent_session_path(
|
|
|
74
74
|
);
|
|
75
75
|
}
|
|
76
76
|
|
|
77
|
-
/**
|
|
78
|
-
export function
|
|
79
|
-
storage_root_path: string,
|
|
80
|
-
origin_type: string,
|
|
81
|
-
session_id: string,
|
|
82
|
-
): string {
|
|
83
|
-
return path.join(
|
|
84
|
-
get_agent_archived_sessions_path(storage_root_path, origin_type),
|
|
85
|
-
encode_path_segment(String(session_id || "").trim()),
|
|
86
|
-
);
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
/** 返回单个 Session 的 instruction.md 路径。 */
|
|
90
|
-
export function get_agent_session_instruction_path(
|
|
91
|
-
storage_root_path: string,
|
|
92
|
-
origin_type: string,
|
|
93
|
-
session_id: string,
|
|
94
|
-
): string {
|
|
95
|
-
return path.join(
|
|
96
|
-
get_agent_session_path(storage_root_path, origin_type, session_id),
|
|
97
|
-
"instruction.md",
|
|
98
|
-
);
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
/** 返回单个 Session 的附件目录。 */
|
|
102
|
-
export function get_agent_session_attachments_path(
|
|
77
|
+
/** 返回单个活动 Session 的 SQLite 数据库路径。 */
|
|
78
|
+
export function get_agent_session_database_path(
|
|
103
79
|
storage_root_path: string,
|
|
104
80
|
origin_type: string,
|
|
105
81
|
session_id: string,
|
|
106
82
|
): string {
|
|
107
83
|
return path.join(
|
|
108
84
|
get_agent_session_path(storage_root_path, origin_type, session_id),
|
|
109
|
-
"
|
|
85
|
+
"session.db",
|
|
110
86
|
);
|
|
111
87
|
}
|
|
112
88
|
|
|
113
|
-
/**
|
|
114
|
-
export function
|
|
115
|
-
storage_root_path: string,
|
|
116
|
-
origin_type: string,
|
|
117
|
-
session_id: string,
|
|
118
|
-
): string {
|
|
119
|
-
return path.join(
|
|
120
|
-
get_agent_session_path(storage_root_path, origin_type, session_id),
|
|
121
|
-
"messages",
|
|
122
|
-
);
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
/** 返回单个 Session 的 Active JSONL 路径。 */
|
|
126
|
-
export function get_agent_session_active_messages_path(
|
|
127
|
-
storage_root_path: string,
|
|
128
|
-
origin_type: string,
|
|
129
|
-
session_id: string,
|
|
130
|
-
): string {
|
|
131
|
-
return path.join(
|
|
132
|
-
get_agent_session_messages_path(storage_root_path, origin_type, session_id),
|
|
133
|
-
"active.jsonl",
|
|
134
|
-
);
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
/** 返回单个 Session 的运行中 Assistant 快照路径。 */
|
|
138
|
-
export function get_agent_session_assistant_message_path(
|
|
139
|
-
storage_root_path: string,
|
|
140
|
-
origin_type: string,
|
|
141
|
-
session_id: string,
|
|
142
|
-
): string {
|
|
143
|
-
return path.join(
|
|
144
|
-
get_agent_session_messages_path(storage_root_path, origin_type, session_id),
|
|
145
|
-
"assistant_message.json",
|
|
146
|
-
);
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
/** 返回单个 Session 的 meta.json 路径。 */
|
|
150
|
-
export function get_agent_session_meta_path(
|
|
89
|
+
/** 返回单个归档 Session 目录。 */
|
|
90
|
+
export function get_agent_archived_session_path(
|
|
151
91
|
storage_root_path: string,
|
|
152
92
|
origin_type: string,
|
|
153
93
|
session_id: string,
|
|
154
94
|
): string {
|
|
155
95
|
return path.join(
|
|
156
|
-
|
|
157
|
-
"
|
|
96
|
+
get_agent_archived_sessions_path(storage_root_path, origin_type),
|
|
97
|
+
encode_path_segment(String(session_id || "").trim()),
|
|
158
98
|
);
|
|
159
99
|
}
|
|
160
100
|
|
|
161
|
-
/** 返回单个归档 Session
|
|
162
|
-
export function
|
|
101
|
+
/** 返回单个归档 Session 的 SQLite 数据库路径。 */
|
|
102
|
+
export function get_agent_archived_session_database_path(
|
|
163
103
|
storage_root_path: string,
|
|
164
104
|
origin_type: string,
|
|
165
105
|
session_id: string,
|
|
166
106
|
): string {
|
|
167
107
|
return path.join(
|
|
168
108
|
get_agent_archived_session_path(storage_root_path, origin_type, session_id),
|
|
169
|
-
"
|
|
170
|
-
);
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
/** 返回单个归档 Session 的 Active JSONL 路径。 */
|
|
174
|
-
export function get_agent_archived_session_active_messages_path(
|
|
175
|
-
storage_root_path: string,
|
|
176
|
-
origin_type: string,
|
|
177
|
-
session_id: string,
|
|
178
|
-
): string {
|
|
179
|
-
return path.join(
|
|
180
|
-
get_agent_archived_session_messages_path(storage_root_path, origin_type, session_id),
|
|
181
|
-
"active.jsonl",
|
|
109
|
+
"session.db",
|
|
182
110
|
);
|
|
183
111
|
}
|
|
184
112
|
|
|
185
|
-
/**
|
|
186
|
-
export function
|
|
113
|
+
/** 返回单个 Session 的附件目录。 */
|
|
114
|
+
export function get_agent_session_attachments_path(
|
|
187
115
|
storage_root_path: string,
|
|
188
116
|
origin_type: string,
|
|
189
117
|
session_id: string,
|
|
190
118
|
): string {
|
|
191
119
|
return path.join(
|
|
192
|
-
|
|
193
|
-
"
|
|
120
|
+
get_agent_session_path(storage_root_path, origin_type, session_id),
|
|
121
|
+
"attachments",
|
|
194
122
|
);
|
|
195
123
|
}
|
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
* SDK Session 元数据辅助。
|
|
3
3
|
*
|
|
4
4
|
* 关键点(中文)
|
|
5
|
-
* - 统一负责
|
|
6
|
-
* -
|
|
5
|
+
* - 统一负责 Session SQLite 中轻量配置摘要与索引字段的规范化。
|
|
6
|
+
* - 不负责数据库连接、消息聚合或附件读写。
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
9
|
import type { SessionHistoryMeta } from "@/executor/types/SessionHistoryMeta.js";
|
|
@@ -57,21 +57,15 @@ function normalize_preview_text(input: unknown): string | undefined {
|
|
|
57
57
|
return preview_text || undefined;
|
|
58
58
|
}
|
|
59
59
|
|
|
60
|
-
function normalize_history_bytes(input: unknown): number | undefined {
|
|
61
|
-
return typeof input === "number" && Number.isInteger(input) && input >= 0
|
|
62
|
-
? input
|
|
63
|
-
: undefined;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
60
|
/**
|
|
67
|
-
*
|
|
61
|
+
* 从指定路径读取旧版 Session metadata。
|
|
68
62
|
*
|
|
69
63
|
* 关键点(中文)
|
|
70
64
|
* - 供归档 session 等需要脱离默认 `sessions/` 目录的场景复用。
|
|
71
65
|
* - 路径本身不做校验,调用方需保证可访问。
|
|
72
66
|
*/
|
|
73
67
|
export async function read_session_metadata_from_path(input: {
|
|
74
|
-
/**
|
|
68
|
+
/** 旧版 metadata 文件路径。 */
|
|
75
69
|
filePath: string;
|
|
76
70
|
/** 当前 session_id。 */
|
|
77
71
|
session_id: string;
|
|
@@ -143,8 +137,5 @@ export function normalize_session_metadata(
|
|
|
143
137
|
...(normalize_preview_text(raw.preview_text)
|
|
144
138
|
? { preview_text: normalize_preview_text(raw.preview_text) }
|
|
145
139
|
: {}),
|
|
146
|
-
...(normalize_history_bytes(raw.historyBytes) !== undefined
|
|
147
|
-
? { historyBytes: normalize_history_bytes(raw.historyBytes) }
|
|
148
|
-
: {}),
|
|
149
140
|
};
|
|
150
141
|
}
|
|
@@ -29,6 +29,8 @@ export interface CreateRuntimeSessionPortParams {
|
|
|
29
29
|
* 读取当前 session 底层执行端口。
|
|
30
30
|
*/
|
|
31
31
|
get_executor: SessionPort["get_executor"];
|
|
32
|
+
/** 读取全部 canonical Session Message。 */
|
|
33
|
+
messages: SessionPort["messages"];
|
|
32
34
|
/**
|
|
33
35
|
* 追加一条新的 session prompt。
|
|
34
36
|
*/
|
|
@@ -48,15 +50,13 @@ export interface CreateRuntimeSessionPortParams {
|
|
|
48
50
|
*/
|
|
49
51
|
append_user_message: SessionPort["append_user_message"];
|
|
50
52
|
/**
|
|
51
|
-
* 追加
|
|
53
|
+
* 追加 Agent 消息到底层历史。
|
|
52
54
|
*/
|
|
53
|
-
|
|
55
|
+
append_agent_message: SessionPort["append_agent_message"];
|
|
54
56
|
/**
|
|
55
57
|
* 返回当前 session 是否正在执行。
|
|
56
58
|
*/
|
|
57
59
|
is_executing: () => boolean;
|
|
58
|
-
/** 读取当前 Session 的只读上下文快照。 */
|
|
59
|
-
context: SessionPort["context"];
|
|
60
60
|
/**
|
|
61
61
|
* 在执行前确保当前 session 已完成初始化与宿主级配置。
|
|
62
62
|
*/
|
|
@@ -73,7 +73,7 @@ export function create_runtime_session_port(
|
|
|
73
73
|
session_id: params.session_id,
|
|
74
74
|
get_model: () => params.get_model(),
|
|
75
75
|
get_executor: () => params.get_executor(),
|
|
76
|
-
|
|
76
|
+
messages: async () => await params.messages(),
|
|
77
77
|
prompt: async (input) => {
|
|
78
78
|
await params.ensure_ready_for_execution();
|
|
79
79
|
return await params.prompt(input);
|
|
@@ -88,8 +88,8 @@ export function create_runtime_session_port(
|
|
|
88
88
|
append_user_message: async (messageParams) => {
|
|
89
89
|
await params.append_user_message(messageParams);
|
|
90
90
|
},
|
|
91
|
-
|
|
92
|
-
await params.
|
|
91
|
+
append_agent_message: async (message_params) => {
|
|
92
|
+
await params.append_agent_message(message_params);
|
|
93
93
|
},
|
|
94
94
|
is_executing: () => params.is_executing(),
|
|
95
95
|
};
|