@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
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* 也不持有 active Turn。
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
import { SessionCommand } from "@/session/SessionCommand.js";
|
|
8
|
+
import type { SessionCommand } from "@/types/session/SessionCommand.js";
|
|
9
9
|
|
|
10
10
|
/** 单个 Session 的进程内 FIFO。 */
|
|
11
11
|
export class SessionQueue {
|
|
@@ -41,7 +41,8 @@ export class SessionQueue {
|
|
|
41
41
|
let cancelled_count = 0;
|
|
42
42
|
const retained_commands: SessionCommand[] = [];
|
|
43
43
|
for (const command of this.commands) {
|
|
44
|
-
if (command.cancel
|
|
44
|
+
if (command.cancel) {
|
|
45
|
+
command.cancel();
|
|
45
46
|
cancelled_count += 1;
|
|
46
47
|
} else {
|
|
47
48
|
retained_commands.push(command);
|
|
@@ -23,14 +23,25 @@ import type {
|
|
|
23
23
|
import type { SessionLocalState } from "@/types/session/SessionLocalState.js";
|
|
24
24
|
import { generate_id } from "@/utils/Id.js";
|
|
25
25
|
import type { Logger } from "@/utils/logger/Logger.js";
|
|
26
|
-
import { SessionMessages } from "@/session/SessionMessages.js";
|
|
27
26
|
import { SessionTitleTask } from "@/session/runtime/SessionTitleTask.js";
|
|
28
|
-
import type { SessionMessage } from "@downcity/type";
|
|
29
27
|
import type { SessionStateOptions } from "@/types/session/SessionState.js";
|
|
30
|
-
import type {
|
|
28
|
+
import type { SessionStorage } from "@/types/store/SessionStorage.js";
|
|
31
29
|
import type { SessionApprovalMode } from "@downcity/type";
|
|
32
30
|
import { create_session_model_request_warning } from "@/session/runtime/SessionModelRequestWarning.js";
|
|
33
31
|
|
|
32
|
+
/** 创建单个 Session 唯一的可变内存状态。 */
|
|
33
|
+
export function create_session_local_state(): SessionLocalState {
|
|
34
|
+
return {
|
|
35
|
+
session_config: {},
|
|
36
|
+
effective_session_config: {},
|
|
37
|
+
configured_approval_mode: "ask",
|
|
38
|
+
created_at: Date.now(),
|
|
39
|
+
timezone: resolve_system_timezone(),
|
|
40
|
+
initialize_promise: null,
|
|
41
|
+
ensure_configured_promise: null,
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
|
|
34
45
|
/** Session 模型配置写入结果。 */
|
|
35
46
|
export interface SessionModelSetResult {
|
|
36
47
|
/** 已包含最新运行时模型实例的 configured 快照。 */
|
|
@@ -46,8 +57,7 @@ export class SessionState {
|
|
|
46
57
|
private readonly agent_id: string;
|
|
47
58
|
private readonly session_id: string;
|
|
48
59
|
private readonly origin: SessionStateOptions["origin"];
|
|
49
|
-
private readonly store:
|
|
50
|
-
private readonly messages: SessionMessages;
|
|
60
|
+
private readonly store: SessionStorage;
|
|
51
61
|
private readonly state: SessionLocalState;
|
|
52
62
|
private readonly logger: Logger;
|
|
53
63
|
private readonly ensure_configured_hook?: SessionStateOptions["ensure_configured_hook"];
|
|
@@ -61,7 +71,6 @@ export class SessionState {
|
|
|
61
71
|
this.session_id = options.session_id;
|
|
62
72
|
this.origin = options.origin;
|
|
63
73
|
this.store = options.store;
|
|
64
|
-
this.messages = options.messages;
|
|
65
74
|
this.state = options.state;
|
|
66
75
|
this.logger = options.logger;
|
|
67
76
|
this.ensure_configured_hook = options.ensure_configured_hook;
|
|
@@ -105,36 +114,42 @@ export class SessionState {
|
|
|
105
114
|
* 初始化当前 session metadata 与内存快照。
|
|
106
115
|
*/
|
|
107
116
|
async initialize(): Promise<void> {
|
|
108
|
-
if (this.state.initialize_promise) {
|
|
109
|
-
|
|
110
|
-
|
|
117
|
+
if (!this.state.initialize_promise) {
|
|
118
|
+
this.state.initialize_promise = (async () => {
|
|
119
|
+
const metadata = await this.store.read_metadata();
|
|
120
|
+
const created_at =
|
|
121
|
+
typeof metadata.created_at === "number" ? metadata.created_at : Date.now();
|
|
122
|
+
const timezone =
|
|
123
|
+
typeof metadata.timezone === "string" && metadata.timezone.trim()
|
|
124
|
+
? metadata.timezone.trim()
|
|
125
|
+
: resolve_system_timezone();
|
|
126
|
+
await this.store.write_metadata({
|
|
127
|
+
...metadata,
|
|
128
|
+
agent_id: this.agent_id,
|
|
129
|
+
created_at: created_at,
|
|
130
|
+
timezone,
|
|
131
|
+
origin: this.origin,
|
|
132
|
+
});
|
|
133
|
+
this.state.created_at = created_at;
|
|
134
|
+
this.state.timezone = timezone;
|
|
135
|
+
this.state.session_config = {
|
|
136
|
+
...(metadata.model_label ? { model_label: metadata.model_label } : {}),
|
|
137
|
+
};
|
|
138
|
+
this.state.effective_session_config = {
|
|
139
|
+
...this.state.session_config,
|
|
140
|
+
};
|
|
141
|
+
this.state.configured_approval_mode = metadata.approval_mode || "ask";
|
|
142
|
+
})();
|
|
143
|
+
}
|
|
144
|
+
const initialize_promise = this.state.initialize_promise;
|
|
145
|
+
try {
|
|
146
|
+
await initialize_promise;
|
|
147
|
+
} catch (error) {
|
|
148
|
+
if (this.state.initialize_promise === initialize_promise) {
|
|
149
|
+
this.state.initialize_promise = null;
|
|
150
|
+
}
|
|
151
|
+
throw error;
|
|
111
152
|
}
|
|
112
|
-
this.state.initialize_promise = (async () => {
|
|
113
|
-
const metadata = await this.store.read_metadata();
|
|
114
|
-
const created_at =
|
|
115
|
-
typeof metadata.created_at === "number" ? metadata.created_at : Date.now();
|
|
116
|
-
const timezone =
|
|
117
|
-
typeof metadata.timezone === "string" && metadata.timezone.trim()
|
|
118
|
-
? metadata.timezone.trim()
|
|
119
|
-
: resolve_system_timezone();
|
|
120
|
-
await this.store.write_metadata({
|
|
121
|
-
...metadata,
|
|
122
|
-
agent_id: this.agent_id,
|
|
123
|
-
created_at: created_at,
|
|
124
|
-
timezone,
|
|
125
|
-
origin: this.origin,
|
|
126
|
-
});
|
|
127
|
-
this.state.created_at = created_at;
|
|
128
|
-
this.state.timezone = timezone;
|
|
129
|
-
this.state.session_config = {
|
|
130
|
-
...(metadata.model_label ? { model_label: metadata.model_label } : {}),
|
|
131
|
-
};
|
|
132
|
-
this.state.effective_session_config = {
|
|
133
|
-
...this.state.session_config,
|
|
134
|
-
};
|
|
135
|
-
this.state.configured_approval_mode = metadata.approval_mode || "ask";
|
|
136
|
-
})();
|
|
137
|
-
await this.state.initialize_promise;
|
|
138
153
|
}
|
|
139
154
|
|
|
140
155
|
/**
|
|
@@ -247,60 +262,19 @@ export class SessionState {
|
|
|
247
262
|
};
|
|
248
263
|
}
|
|
249
264
|
|
|
250
|
-
/**
|
|
251
|
-
* 仅刷新当前 session metadata。
|
|
252
|
-
*/
|
|
253
|
-
async touch_metadata(): Promise<void> {
|
|
254
|
-
const stats = await this.messages.storage_stats();
|
|
255
|
-
const preview_text = resolve_message_preview(
|
|
256
|
-
stats.latest_message || undefined,
|
|
257
|
-
).slice(0, 180);
|
|
258
|
-
await this.run_metadata_mutation(async () => {
|
|
259
|
-
const metadata = await this.store.read_metadata();
|
|
260
|
-
await this.store.write_metadata({
|
|
261
|
-
...metadata,
|
|
262
|
-
agent_id: this.agent_id,
|
|
263
|
-
updated_at: Date.now(),
|
|
264
|
-
...(this.state.session_config.model_label
|
|
265
|
-
? { model_label: this.state.session_config.model_label }
|
|
266
|
-
: {}),
|
|
267
|
-
message_count: stats.message_count,
|
|
268
|
-
historyBytes: stats.history_bytes,
|
|
269
|
-
...(preview_text ? { preview_text: preview_text } : {}),
|
|
270
|
-
});
|
|
271
|
-
});
|
|
272
|
-
}
|
|
273
|
-
|
|
274
|
-
/** 在后台刷新 Session metadata,不阻塞当前 Turn。 */
|
|
275
|
-
touch_metadata_in_background(): void {
|
|
276
|
-
void this.touch_metadata().catch(async (error) => {
|
|
277
|
-
try {
|
|
278
|
-
await this.logger.log("warn", "[agent] session_metadata.background_update_failed", {
|
|
279
|
-
session_id: this.session_id,
|
|
280
|
-
error: error instanceof Error ? error.message : String(error),
|
|
281
|
-
});
|
|
282
|
-
} catch {
|
|
283
|
-
// metadata 诊断日志失败不能影响当前 Turn。
|
|
284
|
-
}
|
|
285
|
-
});
|
|
286
|
-
}
|
|
287
|
-
|
|
288
265
|
/** 异步调度首条用户消息的 Session 标题生成。 */
|
|
289
266
|
schedule_title_generation(): void {
|
|
290
267
|
this.title_task.schedule(async (signal) => {
|
|
291
268
|
const before_metadata = await this.store.read_metadata();
|
|
292
269
|
if (String(before_metadata.title || "").trim()) return;
|
|
293
|
-
const
|
|
294
|
-
const first_user_message = messages.find(
|
|
295
|
-
(message) => message.type === "user",
|
|
296
|
-
);
|
|
270
|
+
const first_user_message = await this.store.read_first_user_message();
|
|
297
271
|
if (!first_user_message) return;
|
|
298
272
|
const first_user_message_id = first_user_message.message_id;
|
|
299
273
|
const before_title = String(before_metadata.title || "").trim();
|
|
300
274
|
const next_metadata = await ensure_session_title({
|
|
301
275
|
session_id: this.session_id,
|
|
302
276
|
store: this.store,
|
|
303
|
-
messages,
|
|
277
|
+
messages: [first_user_message],
|
|
304
278
|
model: this.get_model(),
|
|
305
279
|
model_label: this.state.session_config.model_label,
|
|
306
280
|
logger: this.logger,
|
|
@@ -316,10 +290,10 @@ export class SessionState {
|
|
|
316
290
|
const latest_metadata = await this.store.read_metadata();
|
|
317
291
|
if (signal.aborted) return latest_metadata;
|
|
318
292
|
if (String(latest_metadata.title || "").trim()) return latest_metadata;
|
|
319
|
-
const
|
|
320
|
-
|
|
321
|
-
(message) => message.message_id === first_user_message_id,
|
|
293
|
+
const source_message = await this.store.read_message(
|
|
294
|
+
first_user_message_id,
|
|
322
295
|
);
|
|
296
|
+
const source_exists = source_message?.role === "user";
|
|
323
297
|
if (!source_exists || signal.aborted) return latest_metadata;
|
|
324
298
|
const next_metadata = { ...latest_metadata, title };
|
|
325
299
|
await this.store.write_metadata(next_metadata);
|
|
@@ -355,23 +329,3 @@ export class SessionState {
|
|
|
355
329
|
}
|
|
356
330
|
|
|
357
331
|
}
|
|
358
|
-
|
|
359
|
-
function resolve_message_preview(message: SessionMessage | undefined): string {
|
|
360
|
-
if (!message) return "";
|
|
361
|
-
if (message.type === "user") {
|
|
362
|
-
return message.parts
|
|
363
|
-
.flatMap((part) => part.type === "text" ? [part.text] : [])
|
|
364
|
-
.join("")
|
|
365
|
-
.trim();
|
|
366
|
-
}
|
|
367
|
-
if (message.type === "assistant") {
|
|
368
|
-
return message.parts
|
|
369
|
-
.flatMap((part) => part.type === "text" ? [part.text] : [])
|
|
370
|
-
.join("")
|
|
371
|
-
.trim();
|
|
372
|
-
}
|
|
373
|
-
if (message.type === "action") {
|
|
374
|
-
return [message.title, message.description].filter(Boolean).join("\n");
|
|
375
|
-
}
|
|
376
|
-
return message.message.trim();
|
|
377
|
-
}
|
|
@@ -11,7 +11,12 @@ import type {
|
|
|
11
11
|
AgentSessionSystemBlock,
|
|
12
12
|
AgentSessionSystemSessionInfo,
|
|
13
13
|
} from "@/types/agent/SessionTypes.js";
|
|
14
|
-
import type {
|
|
14
|
+
import type {
|
|
15
|
+
BuildSessionSystemBlocksInput,
|
|
16
|
+
ResolveSessionPluginSystemBlocksInput,
|
|
17
|
+
} from "@/types/session/SessionSystem.js";
|
|
18
|
+
import type { JsonValue, SessionSystemContextHookValue } from "@downcity/type";
|
|
19
|
+
import { SESSION_HOOK_POINTS } from "@/session/SessionHookPoints.js";
|
|
15
20
|
|
|
16
21
|
function normalize_system_blocks(
|
|
17
22
|
blocks: AgentSessionSystemBlock[],
|
|
@@ -39,6 +44,51 @@ function normalize_system_blocks(
|
|
|
39
44
|
.filter((block): block is AgentSessionSystemBlock => Boolean(block));
|
|
40
45
|
}
|
|
41
46
|
|
|
47
|
+
/** 把 system pipeline 输出限制为稳定的 Plugin 命名内容块。 */
|
|
48
|
+
export function normalize_plugin_system_blocks(
|
|
49
|
+
input: unknown,
|
|
50
|
+
): AgentSessionSystemBlock[] {
|
|
51
|
+
if (!Array.isArray(input)) return [];
|
|
52
|
+
return input.flatMap((item) => {
|
|
53
|
+
if (!item || typeof item !== "object" || Array.isArray(item)) return [];
|
|
54
|
+
const record = item as Record<string, unknown>;
|
|
55
|
+
const name = String(record.name || "").trim();
|
|
56
|
+
const content = String(record.content || "").trim();
|
|
57
|
+
if (!name || !content) return [];
|
|
58
|
+
return [{ source: "plugin" as const, name, content }];
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/** 使用统一 Hook 检查点解析当前 Session 的 Plugin system blocks。 */
|
|
63
|
+
export async function resolve_session_plugin_system_blocks(
|
|
64
|
+
input: ResolveSessionPluginSystemBlocksInput,
|
|
65
|
+
): Promise<AgentSessionSystemBlock[]> {
|
|
66
|
+
let blocks: AgentSessionSystemBlock[];
|
|
67
|
+
try {
|
|
68
|
+
blocks = normalize_plugin_system_blocks(
|
|
69
|
+
await input.hooks.system_blocks(input.context),
|
|
70
|
+
);
|
|
71
|
+
} catch (error) {
|
|
72
|
+
await input.on_error?.(error);
|
|
73
|
+
return [];
|
|
74
|
+
}
|
|
75
|
+
const value: SessionSystemContextHookValue = {
|
|
76
|
+
session_id: input.session_id,
|
|
77
|
+
...(input.turn_id ? { turn_id: input.turn_id } : {}),
|
|
78
|
+
blocks,
|
|
79
|
+
};
|
|
80
|
+
try {
|
|
81
|
+
const output = await input.hooks.pipeline(
|
|
82
|
+
SESSION_HOOK_POINTS.system_context,
|
|
83
|
+
value as unknown as JsonValue,
|
|
84
|
+
) as unknown as SessionSystemContextHookValue;
|
|
85
|
+
return normalize_plugin_system_blocks(output?.blocks);
|
|
86
|
+
} catch (error) {
|
|
87
|
+
await input.on_error?.(error);
|
|
88
|
+
return blocks;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
42
92
|
function create_session_info(
|
|
43
93
|
input: Pick<
|
|
44
94
|
BuildSessionSystemBlocksInput,
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* SDK Session 标题生成与持久化辅助。
|
|
3
3
|
*
|
|
4
4
|
* 关键点(中文)
|
|
5
|
-
* - session title 是 `
|
|
5
|
+
* - session title 是 `session_state` 的字段,列表与详情都以它为准。
|
|
6
6
|
* - title 默认允许为空;只有模型成功生成标题时才会写入。
|
|
7
7
|
* - 当 title 仍为空时,后续执行链路可以再次尝试生成。
|
|
8
8
|
*/
|
|
@@ -15,7 +15,7 @@ import {
|
|
|
15
15
|
import type { SessionHistoryMeta } from "@/executor/types/SessionHistoryMeta.js";
|
|
16
16
|
import type { Logger } from "@/utils/logger/Logger.js";
|
|
17
17
|
import { normalize_session_title } from "@/session/storage/Metadata.js";
|
|
18
|
-
import type {
|
|
18
|
+
import type { SessionStorage } from "@/types/store/SessionStorage.js";
|
|
19
19
|
import type { SessionMessage } from "@downcity/type";
|
|
20
20
|
import { extract_session_message_text } from "@/session/messages/SessionMessageText.js";
|
|
21
21
|
import type { ModelRequestFailureReporter } from "@/types/executor/ModelRequest.js";
|
|
@@ -27,7 +27,7 @@ const GENERATED_SESSION_TITLE_MAX_CHARS = 24;
|
|
|
27
27
|
*/
|
|
28
28
|
export interface EnsureSessionTitleParams {
|
|
29
29
|
/** 当前 Session 的领域持久化入口。 */
|
|
30
|
-
store:
|
|
30
|
+
store: SessionStorage;
|
|
31
31
|
|
|
32
32
|
/**
|
|
33
33
|
* 当前 session_id。
|
|
@@ -78,7 +78,7 @@ function truncate_title(input: string, max_chars: number): string {
|
|
|
78
78
|
|
|
79
79
|
function resolve_first_user_text(messages: SessionMessage[]): string {
|
|
80
80
|
for (const message of messages) {
|
|
81
|
-
if (message.
|
|
81
|
+
if (message.role !== "user") continue;
|
|
82
82
|
const text = extract_session_message_text(message);
|
|
83
83
|
if (text) return text;
|
|
84
84
|
}
|