@downcity/agent 1.1.430 → 1.1.438
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
|
@@ -12,52 +12,40 @@ import test from "node:test";
|
|
|
12
12
|
|
|
13
13
|
import { create_session_turn_context } from "../bin/session/runtime/SessionTurnContext.js";
|
|
14
14
|
|
|
15
|
-
function create_user_message(message_id, text, created_at) {
|
|
16
|
-
return {
|
|
17
|
-
message_id,
|
|
18
|
-
session_id: "session-context-test",
|
|
19
|
-
turn_id: "turn-context-test",
|
|
20
|
-
sequence: created_at,
|
|
21
|
-
revision: 1,
|
|
22
|
-
visibility: "visible",
|
|
23
|
-
created_at,
|
|
24
|
-
updated_at: created_at,
|
|
25
|
-
type: "user",
|
|
26
|
-
input_type: "steer",
|
|
27
|
-
parts: [{
|
|
28
|
-
part_id: `${message_id}:text`,
|
|
29
|
-
type: "text",
|
|
30
|
-
text,
|
|
31
|
-
state: "done",
|
|
32
|
-
}],
|
|
33
|
-
};
|
|
34
|
-
}
|
|
35
|
-
|
|
36
15
|
test("SessionTurnContext 在检查点消费输入并封装输出缓冲", async () => {
|
|
16
|
+
let commit_count = 0;
|
|
17
|
+
const internal_messages = [];
|
|
37
18
|
const context = create_session_turn_context({
|
|
38
19
|
session_id: "session-context-test",
|
|
39
20
|
session_origin: { type: "chat" },
|
|
40
21
|
turn_id: "turn-context-test",
|
|
41
22
|
project_root: "/workspace",
|
|
42
|
-
|
|
23
|
+
commit_step_input: async () => {
|
|
24
|
+
commit_count += 1;
|
|
25
|
+
},
|
|
26
|
+
append_internal_user_message: async (parts) => {
|
|
27
|
+
internal_messages.push(parts);
|
|
28
|
+
return {
|
|
29
|
+
message_id: "internal-1", session_id: "session-context-test",
|
|
30
|
+
turn_id: "turn-context-test", sequence: 1, revision: 1,
|
|
31
|
+
visibility: "internal", created_at: 1, updated_at: 1,
|
|
32
|
+
role: "user", parts: parts.map((part, index) => ({
|
|
33
|
+
...part, part_id: `part-${index + 1}`, sequence: index + 1,
|
|
34
|
+
})),
|
|
35
|
+
};
|
|
36
|
+
},
|
|
43
37
|
});
|
|
44
|
-
context.input.
|
|
45
|
-
create_user_message("injected-message", "injected", 1),
|
|
46
|
-
);
|
|
38
|
+
await context.input.append_internal([{ type: "text", text: "injected" }]);
|
|
47
39
|
context.output.enqueue_assistant_parts([{
|
|
48
40
|
type: "file",
|
|
49
41
|
media_type: "text/plain",
|
|
50
42
|
url: "/workspace/result.txt",
|
|
51
43
|
}]);
|
|
52
44
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
);
|
|
57
|
-
assert.deepEqual(
|
|
58
|
-
(await context.input.checkpoint()).map((message) => message.message_id),
|
|
59
|
-
["queued-message"],
|
|
60
|
-
);
|
|
45
|
+
await context.input.checkpoint();
|
|
46
|
+
await context.input.checkpoint();
|
|
47
|
+
assert.equal(internal_messages[0][0].text, "injected");
|
|
48
|
+
assert.equal(commit_count, 2);
|
|
61
49
|
assert.equal(context.output.take_assistant_parts().length, 1);
|
|
62
50
|
assert.equal(context.output.take_assistant_parts().length, 0);
|
|
63
51
|
});
|
package/src/agent/Agent.ts
CHANGED
|
@@ -14,7 +14,10 @@ import type {
|
|
|
14
14
|
StorageProvider,
|
|
15
15
|
WorkspaceRuntime,
|
|
16
16
|
} from "@downcity/type";
|
|
17
|
-
import {
|
|
17
|
+
import {
|
|
18
|
+
create_instruction_system_blocks,
|
|
19
|
+
normalize_instruction_input,
|
|
20
|
+
} from "@/agent/AgentInstructions.js";
|
|
18
21
|
import type {
|
|
19
22
|
AgentOptions,
|
|
20
23
|
AgentSessionConstructor,
|
|
@@ -29,10 +32,13 @@ import { LocalSessionStore } from "@/session/storage/LocalSessionStore.js";
|
|
|
29
32
|
import { EMPTY_SESSION_HOOKS } from "@/session/SessionHooks.js";
|
|
30
33
|
import type { AgentStorage } from "@/types/agent/AgentStorage.js";
|
|
31
34
|
import type { SessionSystemMessage } from "@/executor/types/SessionPrompts.js";
|
|
35
|
+
import type { SessionComposer } from "@/types/session/SessionComposer.js";
|
|
32
36
|
import {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
} from "@/
|
|
37
|
+
build_session_system_blocks,
|
|
38
|
+
resolve_session_plugin_system_blocks,
|
|
39
|
+
} from "@/session/SessionSystem.js";
|
|
40
|
+
import { create_session_hook_context } from "@/session/runtime/SessionTurnContext.js";
|
|
41
|
+
import { resolve_system_timezone } from "@/session/storage/Metadata.js";
|
|
36
42
|
|
|
37
43
|
/** SDK Agent 主体。 */
|
|
38
44
|
export class Agent {
|
|
@@ -57,6 +63,9 @@ export class Agent {
|
|
|
57
63
|
/** Agent 使用的 Session 类。 */
|
|
58
64
|
readonly session_class?: AgentSessionConstructor;
|
|
59
65
|
|
|
66
|
+
/** 为每个 Session 创建独立 Composer 的工厂。 */
|
|
67
|
+
readonly session_composer?: () => SessionComposer;
|
|
68
|
+
|
|
60
69
|
/** Agent 级日志器,不绑定任何 Workspace。 */
|
|
61
70
|
private readonly logger = new Logger();
|
|
62
71
|
|
|
@@ -89,6 +98,7 @@ export class Agent {
|
|
|
89
98
|
this.model = options.model;
|
|
90
99
|
this.instruction = normalize_instruction_input(options.instruction);
|
|
91
100
|
this.session_class = options.session_class;
|
|
101
|
+
this.session_composer = options.session_composer;
|
|
92
102
|
this.custom_tools = options.tools && typeof options.tools === "object"
|
|
93
103
|
? { ...options.tools }
|
|
94
104
|
: {};
|
|
@@ -99,6 +109,7 @@ export class Agent {
|
|
|
99
109
|
ensure_agent_ready: async () => await this.ensure_ready(),
|
|
100
110
|
get_agent_model: () => this.model,
|
|
101
111
|
session_class: this.session_class,
|
|
112
|
+
create_session_composer: this.session_composer,
|
|
102
113
|
on_session_routed: () => {
|
|
103
114
|
if (!this.city) this.memory_session_started = true;
|
|
104
115
|
},
|
|
@@ -180,19 +191,42 @@ export class Agent {
|
|
|
180
191
|
input: {
|
|
181
192
|
/** 目标 Session 稳定标识。 */
|
|
182
193
|
session_id: string;
|
|
183
|
-
/** system message 使用场景。 */
|
|
184
|
-
profile?: SystemProfile;
|
|
185
194
|
},
|
|
186
195
|
): Promise<SessionSystemMessage[]> {
|
|
187
196
|
this.assert_workspace(workspace);
|
|
188
|
-
|
|
197
|
+
const session_id = String(input.session_id || "").trim();
|
|
198
|
+
if (!session_id) {
|
|
199
|
+
throw new Error("resolve_system_messages requires a non-empty session_id");
|
|
200
|
+
}
|
|
201
|
+
const instruction_system_blocks = create_instruction_system_blocks(
|
|
202
|
+
[...this.get_instructions()],
|
|
203
|
+
workspace.path,
|
|
204
|
+
);
|
|
205
|
+
const hooks = this.city?.get_session_hooks(this.id, workspace)
|
|
206
|
+
?? EMPTY_SESSION_HOOKS;
|
|
207
|
+
const hook_context = create_session_hook_context({
|
|
208
|
+
session_id,
|
|
209
|
+
session_origin: { type: "chat" },
|
|
210
|
+
project_root: workspace.path,
|
|
211
|
+
workspace_env: Object.freeze({ ...workspace.get_env() }),
|
|
212
|
+
agent_systems: instruction_system_blocks.map((block) => block.content),
|
|
213
|
+
});
|
|
214
|
+
const plugin_system_blocks = await resolve_session_plugin_system_blocks({
|
|
215
|
+
session_id,
|
|
216
|
+
hooks,
|
|
217
|
+
context: hook_context,
|
|
218
|
+
});
|
|
219
|
+
const blocks = await build_session_system_blocks({
|
|
220
|
+
agent_id: this.id,
|
|
189
221
|
project_root: workspace.path,
|
|
190
|
-
session_id
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
222
|
+
session_id,
|
|
223
|
+
created_at: Date.now(),
|
|
224
|
+
timezone: resolve_system_timezone(),
|
|
225
|
+
get_instruction_system_blocks: () => instruction_system_blocks,
|
|
226
|
+
get_managed_plugin_system_blocks: async () => [],
|
|
227
|
+
get_plugin_system_blocks: async () => plugin_system_blocks,
|
|
195
228
|
});
|
|
229
|
+
return blocks.map((block) => ({ role: "system", content: block.content }));
|
|
196
230
|
}
|
|
197
231
|
|
|
198
232
|
/** 释放 Agent 的 Session 后台任务、存储与宿主引用。 */
|
|
@@ -229,10 +263,12 @@ export class Agent {
|
|
|
229
263
|
this.agent_storage = {
|
|
230
264
|
root_path: scope.root_path,
|
|
231
265
|
files: scope.files,
|
|
266
|
+
database_location: scope.database_location,
|
|
232
267
|
sessions: new LocalSessionStore({
|
|
233
268
|
files: scope.files,
|
|
234
269
|
storage_root_path: scope.root_path,
|
|
235
270
|
agent_id: this.id,
|
|
271
|
+
database_location: scope.database_location,
|
|
236
272
|
}),
|
|
237
273
|
};
|
|
238
274
|
return this.agent_storage;
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
10
|
import type { AgentSessionSystemBlock } from "@/types/agent/SessionTypes.js";
|
|
11
|
-
import {
|
|
11
|
+
import { CORE_SYSTEM_PROMPT } from "@executor/composer/system/default/SystemPromptAssets.js";
|
|
12
12
|
|
|
13
13
|
/**
|
|
14
14
|
* 归一化调用方传入的静态 instruction。
|
|
@@ -28,7 +28,7 @@ export function normalize_instruction_input(
|
|
|
28
28
|
|
|
29
29
|
function createCoreInstructionContent(project_root: string): string {
|
|
30
30
|
const current_year = String(new Date().getFullYear());
|
|
31
|
-
return
|
|
31
|
+
return CORE_SYSTEM_PROMPT
|
|
32
32
|
.replaceAll("{{project_path}}", project_root)
|
|
33
33
|
.replaceAll("{{project_root}}", project_root)
|
|
34
34
|
.replaceAll("{{current_year}}", current_year);
|
|
@@ -191,6 +191,7 @@ export class AgentMemoryStorageProvider implements StorageProvider {
|
|
|
191
191
|
const scope = Object.freeze({
|
|
192
192
|
root_path,
|
|
193
193
|
files: new AgentMemoryFileSystem(root_path),
|
|
194
|
+
database_location: { type: "memory" as const },
|
|
194
195
|
});
|
|
195
196
|
this.scopes_by_key.set(scope_key, scope);
|
|
196
197
|
return scope;
|
|
@@ -29,9 +29,12 @@ import type {
|
|
|
29
29
|
import type { AgentManagedSession } from "@/types/session/SessionOptions.js";
|
|
30
30
|
import { Session } from "@/session/Session.js";
|
|
31
31
|
import type { SessionPort } from "@/types/session/SessionPort.js";
|
|
32
|
+
import type { SessionComposer } from "@/types/session/SessionComposer.js";
|
|
32
33
|
import { create_instruction_system_blocks } from "@/agent/AgentInstructions.js";
|
|
34
|
+
import { DefaultSessionComposer } from "@/session/DefaultSessionComposer.js";
|
|
33
35
|
import type { SessionHookRuntime } from "@downcity/type";
|
|
34
36
|
import type { SessionStore } from "@/types/store/SessionStore.js";
|
|
37
|
+
import type { SessionStorage } from "@/types/store/SessionStorage.js";
|
|
35
38
|
import type { WorkspaceRuntime } from "@downcity/type";
|
|
36
39
|
import type { SessionOrigin } from "@downcity/type";
|
|
37
40
|
import { normalize_session_origin, normalize_session_origin_type } from "@downcity/type";
|
|
@@ -78,6 +81,9 @@ type AgentSessionsOptions = {
|
|
|
78
81
|
*/
|
|
79
82
|
session_class?: AgentSessionConstructor;
|
|
80
83
|
|
|
84
|
+
/** 为每个 Session 创建独立 Composer 的工厂。 */
|
|
85
|
+
create_session_composer?: () => SessionComposer;
|
|
86
|
+
|
|
81
87
|
/** 读取 Agent 当前持有的运行时模型实例。 */
|
|
82
88
|
get_agent_model: () => ModelClient | undefined;
|
|
83
89
|
|
|
@@ -95,6 +101,7 @@ export class AgentSessions implements AgentSessionsContract<AgentSession> {
|
|
|
95
101
|
private readonly get_instruction: AgentSessionsOptions["get_instruction"];
|
|
96
102
|
private readonly ensure_agent_ready: AgentSessionsOptions["ensure_agent_ready"];
|
|
97
103
|
private readonly session_class: AgentSessionConstructor;
|
|
104
|
+
private readonly create_session_composer: () => SessionComposer;
|
|
98
105
|
private readonly get_agent_model: AgentSessionsOptions["get_agent_model"];
|
|
99
106
|
private readonly on_session_routed?: AgentSessionsOptions["on_session_routed"];
|
|
100
107
|
private readonly sessions_by_id = new Map<string, AgentManagedSession>();
|
|
@@ -106,6 +113,8 @@ export class AgentSessions implements AgentSessionsContract<AgentSession> {
|
|
|
106
113
|
this.get_instruction = options.get_instruction;
|
|
107
114
|
this.ensure_agent_ready = options.ensure_agent_ready;
|
|
108
115
|
this.session_class = options.session_class || Session;
|
|
116
|
+
this.create_session_composer = options.create_session_composer ||
|
|
117
|
+
(() => new DefaultSessionComposer());
|
|
109
118
|
this.get_agent_model = options.get_agent_model;
|
|
110
119
|
this.on_session_routed = options.on_session_routed;
|
|
111
120
|
}
|
|
@@ -180,9 +189,17 @@ export class AgentSessions implements AgentSessionsContract<AgentSession> {
|
|
|
180
189
|
input?: AgentCreateSessionInput & { workspace?: WorkspaceRuntime },
|
|
181
190
|
): Promise<AgentSession> {
|
|
182
191
|
const origin = normalize_session_origin(input?.origin);
|
|
192
|
+
const session_id = `session-${Date.now()}-${nanoid(8)}`;
|
|
193
|
+
const context = this.resolve_session_context(input?.workspace);
|
|
183
194
|
const session = this.get_or_create_session({
|
|
195
|
+
session_id,
|
|
184
196
|
workspace: input?.workspace,
|
|
185
197
|
origin,
|
|
198
|
+
storage: context.store.create_session(
|
|
199
|
+
session_id,
|
|
200
|
+
origin,
|
|
201
|
+
context.workspace_id,
|
|
202
|
+
),
|
|
186
203
|
});
|
|
187
204
|
this.on_session_routed?.(session.id, this);
|
|
188
205
|
await session.initialize();
|
|
@@ -213,9 +230,8 @@ export class AgentSessions implements AgentSessionsContract<AgentSession> {
|
|
|
213
230
|
`Session "${resolved_session_id}" not found in origin "${resolved_origin_type}"`,
|
|
214
231
|
);
|
|
215
232
|
}
|
|
216
|
-
const
|
|
217
|
-
|
|
218
|
-
.read_metadata();
|
|
233
|
+
const storage = await store.open_session(resolved_session_id, resolved_origin_type);
|
|
234
|
+
const persisted_metadata = await storage.read_metadata();
|
|
219
235
|
const persisted_workspace_id = String(persisted_metadata.workspace_id || "").trim() || undefined;
|
|
220
236
|
const persisted_origin = persisted_metadata.origin;
|
|
221
237
|
const cached = this.sessions_by_id.get(cache_key);
|
|
@@ -236,6 +252,7 @@ export class AgentSessions implements AgentSessionsContract<AgentSession> {
|
|
|
236
252
|
session_id: resolved_session_id,
|
|
237
253
|
workspace: input?.workspace,
|
|
238
254
|
origin: persisted_origin,
|
|
255
|
+
storage,
|
|
239
256
|
});
|
|
240
257
|
this.on_session_routed?.(resolved_session_id, this);
|
|
241
258
|
await session.initialize();
|
|
@@ -349,7 +366,7 @@ export class AgentSessions implements AgentSessionsContract<AgentSession> {
|
|
|
349
366
|
* 把 Session 重新绑定到另一个 Workspace。
|
|
350
367
|
*
|
|
351
368
|
* 关键点(中文)
|
|
352
|
-
* - 只改写
|
|
369
|
+
* - 只改写 session_state 中的 workspace_id 并清掉运行时缓存;
|
|
353
370
|
* - 之后用新 Workspace 恢复时不再触发严格的 workspace 归属校验。
|
|
354
371
|
*/
|
|
355
372
|
async workspace(
|
|
@@ -370,10 +387,9 @@ export class AgentSessions implements AgentSessionsContract<AgentSession> {
|
|
|
370
387
|
if (!(await context.store.has_session(resolved_session_id, resolved_origin_type))) {
|
|
371
388
|
throw new Error(`Session "${resolved_session_id}" not found`);
|
|
372
389
|
}
|
|
373
|
-
const store = context.store.
|
|
390
|
+
const store = await context.store.open_session(
|
|
374
391
|
resolved_session_id,
|
|
375
|
-
|
|
376
|
-
context.workspace_id,
|
|
392
|
+
resolved_origin_type,
|
|
377
393
|
);
|
|
378
394
|
const metadata = await store.read_metadata();
|
|
379
395
|
if (metadata.agent_id !== this.agent_id) {
|
|
@@ -397,10 +413,12 @@ export class AgentSessions implements AgentSessionsContract<AgentSession> {
|
|
|
397
413
|
workspace?: WorkspaceRuntime;
|
|
398
414
|
/** 当前 Session 的创建来源。 */
|
|
399
415
|
origin?: SessionOrigin;
|
|
416
|
+
/** 已由集合层创建或打开的单 Session Storage。 */
|
|
417
|
+
storage?: SessionStorage;
|
|
400
418
|
}): AgentManagedSession {
|
|
401
|
-
const resolved_session_id =
|
|
402
|
-
|
|
403
|
-
|
|
419
|
+
const resolved_session_id = String(
|
|
420
|
+
input?.session_id || input?.storage?.session_id || "",
|
|
421
|
+
).trim() || `session-${Date.now()}-${nanoid(8)}`;
|
|
404
422
|
const origin = normalize_session_origin(input?.origin);
|
|
405
423
|
const cache_key = this.session_cache_key(resolved_session_id, origin.type);
|
|
406
424
|
const cached = this.sessions_by_id.get(cache_key);
|
|
@@ -412,8 +430,8 @@ export class AgentSessions implements AgentSessionsContract<AgentSession> {
|
|
|
412
430
|
workspace_path: context.workspace_path,
|
|
413
431
|
...(context.workspace_id ? { workspace_id: context.workspace_id } : {}),
|
|
414
432
|
origin,
|
|
415
|
-
store: context.store.
|
|
416
|
-
|
|
433
|
+
store: input?.storage || context.store.create_session(resolved_session_id, origin, context.workspace_id),
|
|
434
|
+
create_session_store: (session_id) => context.store.create_session(session_id, origin, context.workspace_id),
|
|
417
435
|
register_forked_session: (session) => this.register_forked_session(session),
|
|
418
436
|
session_id: resolved_session_id,
|
|
419
437
|
get_tools: () => context.get_tools(),
|
|
@@ -424,6 +442,7 @@ export class AgentSessions implements AgentSessionsContract<AgentSession> {
|
|
|
424
442
|
get_agent_model: () => this.get_agent_model(),
|
|
425
443
|
get_hooks: () => context.get_hooks(),
|
|
426
444
|
get_managed_plugin_system_blocks: async () => [],
|
|
445
|
+
create_composer: this.create_session_composer,
|
|
427
446
|
ensure_configured: async (session) => {
|
|
428
447
|
await this.ensure_agent_ready();
|
|
429
448
|
},
|