@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
|
@@ -90,10 +90,12 @@ export const AskQuestionsTool = define_runtime_tool<AskQuestionsToolInput, Actio
|
|
|
90
90
|
"ask_question received an incompatible Interaction response",
|
|
91
91
|
);
|
|
92
92
|
}
|
|
93
|
+
const response_payload = result.response.payload as unknown as { answers: SessionInteractionAnswer[]; note?: string };
|
|
93
94
|
return {
|
|
94
95
|
output: {
|
|
95
96
|
status: "resolved",
|
|
96
|
-
answers:
|
|
97
|
+
answers: response_payload.answers,
|
|
98
|
+
...(response_payload.note ? { note: response_payload.note } : {}),
|
|
97
99
|
},
|
|
98
100
|
messages: [],
|
|
99
101
|
};
|
|
@@ -3,15 +3,15 @@
|
|
|
3
3
|
*
|
|
4
4
|
* 关键点(中文)
|
|
5
5
|
* - `output` 是标准 Tool Result,原样交给模型执行器和 canonical Tool Part。
|
|
6
|
-
* - `messages`
|
|
6
|
+
* - `messages` 是执行后产生的运行期 User 输入或 canonical Agent 内容。
|
|
7
7
|
* - `effects` 是当前 Turn 只追加收集、并在收口检查点解释的已发生副作用。
|
|
8
8
|
* - Message Parts 复用 Downcity Session UI 协议,不再建立文件、图片或 Plugin 专用桥接。
|
|
9
9
|
*/
|
|
10
10
|
|
|
11
11
|
import type { RuntimeToolEffect } from "@downcity/type";
|
|
12
12
|
import type {
|
|
13
|
-
|
|
14
|
-
|
|
13
|
+
SessionAgentContent,
|
|
14
|
+
SessionModelUserContent,
|
|
15
15
|
} from "@downcity/type";
|
|
16
16
|
|
|
17
17
|
/** Action 执行后产生的一条 Session 消息。 */
|
|
@@ -19,14 +19,14 @@ export type ActionResultMessage =
|
|
|
19
19
|
| {
|
|
20
20
|
/** User 内容在下一 Step 生效。 */
|
|
21
21
|
role: "user";
|
|
22
|
-
/**
|
|
23
|
-
parts:
|
|
22
|
+
/** 只在当前 Turn 生效、不会伪装成 canonical Message 的模型输入。 */
|
|
23
|
+
parts: SessionModelUserContent[];
|
|
24
24
|
}
|
|
25
25
|
| {
|
|
26
|
-
/**
|
|
27
|
-
role: "
|
|
28
|
-
/**
|
|
29
|
-
parts:
|
|
26
|
+
/** Agent 内容写入当前 canonical 回复。 */
|
|
27
|
+
role: "agent";
|
|
28
|
+
/** 等待追加到 canonical Agent Message 的内容。 */
|
|
29
|
+
parts: SessionAgentContent[];
|
|
30
30
|
};
|
|
31
31
|
|
|
32
32
|
/** Action 或 Tool 内部实现返回的统一结果。 */
|
|
@@ -34,7 +34,7 @@ export interface ActionResult<TOutput = unknown> {
|
|
|
34
34
|
/** 返回给调用方、模型执行器与 canonical Tool Part 的标准执行输出。 */
|
|
35
35
|
output: TOutput;
|
|
36
36
|
|
|
37
|
-
/**
|
|
37
|
+
/** 执行产生的运行期 User 输入或 Agent 输出;没有附加内容时传入空数组。 */
|
|
38
38
|
messages: ActionResultMessage[];
|
|
39
39
|
|
|
40
40
|
/** 已经发生且需要由当前 Turn 收集的副作用;不会发送给模型或直接持久化。 */
|
|
@@ -11,6 +11,7 @@ import type {
|
|
|
11
11
|
AgentManagedSession,
|
|
12
12
|
SessionOptions,
|
|
13
13
|
} from "@/types/session/SessionOptions.js";
|
|
14
|
+
import type { SessionComposer } from "@/types/session/SessionComposer.js";
|
|
14
15
|
|
|
15
16
|
/**
|
|
16
17
|
* Agent 可使用的 Session 类。
|
|
@@ -88,4 +89,14 @@ export interface AgentOptions {
|
|
|
88
89
|
*/
|
|
89
90
|
session_class?: AgentSessionConstructor;
|
|
90
91
|
|
|
92
|
+
/**
|
|
93
|
+
* 为每个 Session 创建独立 Composer 的工厂。
|
|
94
|
+
*
|
|
95
|
+
* 关键点(中文)
|
|
96
|
+
* - 每次创建、恢复或 fork Session 都会调用一次,禁止返回共享实例。
|
|
97
|
+
* - 省略时创建默认 `DefaultSessionComposer`。
|
|
98
|
+
* - Context Policy 应在工厂内部随 Composer 一起创建,避免跨 Session 共享派生状态。
|
|
99
|
+
*/
|
|
100
|
+
session_composer?: () => SessionComposer;
|
|
101
|
+
|
|
91
102
|
}
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
8
|
import type { SessionStore } from "@/types/store/SessionStore.js";
|
|
9
|
-
import type { FileSystem } from "@downcity/type";
|
|
9
|
+
import type { FileSystem, StorageDatabaseLocation } from "@downcity/type";
|
|
10
10
|
|
|
11
11
|
/** Agent 持有的 Session、日志与调度共享存储。 */
|
|
12
12
|
export interface AgentStorage {
|
|
@@ -14,6 +14,8 @@ export interface AgentStorage {
|
|
|
14
14
|
root_path: string;
|
|
15
15
|
/** 受当前 Agent 根路径约束的文件能力。 */
|
|
16
16
|
files: FileSystem;
|
|
17
|
+
/** Agent 私有结构化数据库使用的位置类型。 */
|
|
18
|
+
database_location: StorageDatabaseLocation;
|
|
17
19
|
/** 当前 Agent 的 Session 集合存储。 */
|
|
18
20
|
sessions: SessionStore;
|
|
19
21
|
}
|
|
@@ -39,7 +39,6 @@ import type {
|
|
|
39
39
|
} from "@downcity/type";
|
|
40
40
|
import type { AgentSessionPromptInput } from "@/types/sdk/AgentSessionPrompt.js";
|
|
41
41
|
import type { AgentSessionStopResult } from "@/types/sdk/AgentSessionStop.js";
|
|
42
|
-
import type { AgentSessionCompactHandle } from "@/types/sdk/AgentSessionCompact.js";
|
|
43
42
|
import type { AgentSessionTurnHandle } from "@/types/sdk/AgentSessionTurn.js";
|
|
44
43
|
import type { SessionOrigin } from "@downcity/type";
|
|
45
44
|
|
|
@@ -88,15 +87,6 @@ export interface AgentSessionActor {
|
|
|
88
87
|
/** 停止当前 turn,并取消尚未被吸收的排队 prompt。 */
|
|
89
88
|
stop(): Promise<AgentSessionStopResult>;
|
|
90
89
|
|
|
91
|
-
/**
|
|
92
|
-
* 把一次显式历史压缩加入当前 Session 的有序输入队列。
|
|
93
|
-
*
|
|
94
|
-
* 关键点(中文)
|
|
95
|
-
* - 返回句柄表示 Command 已成功入队。
|
|
96
|
-
* - `handle.finished` 在压缩真正完成或失败后兑现。
|
|
97
|
-
*/
|
|
98
|
-
compact(): Promise<AgentSessionCompactHandle>;
|
|
99
|
-
|
|
100
90
|
/** 订阅当前 session 的未来事件。 */
|
|
101
91
|
subscribe(
|
|
102
92
|
subscriber: SessionMutationSubscriber,
|
|
@@ -97,17 +97,17 @@ export interface AgentSessionSetInput {
|
|
|
97
97
|
/** Session 配置提交后的 Action 可观测性选项。 */
|
|
98
98
|
export interface AgentSessionSetOptions {
|
|
99
99
|
/**
|
|
100
|
-
*
|
|
100
|
+
* 是否把真实配置变化持久化为包含 completed Action Part 的 Agent Message。
|
|
101
101
|
*
|
|
102
102
|
* 关键点(中文)
|
|
103
103
|
* - 默认值为 true。
|
|
104
|
-
* - 设为 false 只关闭 Action
|
|
104
|
+
* - 设为 false 只关闭 Action Part 历史,不影响配置写入与检查点提交。
|
|
105
105
|
* - 适用于 Session 初始化、恢复与其他不应进入时间线的宿主装配流程。
|
|
106
106
|
*/
|
|
107
107
|
persist_action?: boolean;
|
|
108
108
|
|
|
109
109
|
/**
|
|
110
|
-
* 是否在 Action Message 持久化成功后发布对应 Session Mutation。
|
|
110
|
+
* 是否在 Action Part 所属 Agent Message 持久化成功后发布对应 Session Mutation。
|
|
111
111
|
*
|
|
112
112
|
* 关键点(中文)
|
|
113
113
|
* - 默认跟随 `persist_action`。
|
|
@@ -181,7 +181,7 @@ export interface AgentSessionTimelineEvent {
|
|
|
181
181
|
* 说明(中文)
|
|
182
182
|
* - `tool-call` / `tool-result` 用于把 assistant 内部工具过程平铺给 UI。
|
|
183
183
|
*/
|
|
184
|
-
role: "user" | "
|
|
184
|
+
role: "user" | "agent" | "tool-call" | "tool-result" | "action";
|
|
185
185
|
/** 事件时间戳(毫秒)。 */
|
|
186
186
|
ts?: number;
|
|
187
187
|
/** 事件所属消息种类。 */
|
|
@@ -289,7 +289,7 @@ export interface AgentSessionSummary {
|
|
|
289
289
|
* 当前 session 可读标题。
|
|
290
290
|
*
|
|
291
291
|
* 说明(中文)
|
|
292
|
-
* - 标题持久化在
|
|
292
|
+
* - 标题持久化在 Session SQLite 的 `session_state` 中。
|
|
293
293
|
* - SDK 只在模型成功生成标题时写入,不再从首条用户消息生成 fallback。
|
|
294
294
|
* - 标题允许为空,调用方需要展示占位文案时可自行回退到 `session_id`。
|
|
295
295
|
*/
|
|
@@ -5,8 +5,8 @@
|
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
7
|
import type { ModelStreamEvent } from "@downcity/type";
|
|
8
|
-
import type {
|
|
9
|
-
import type {
|
|
8
|
+
import type { SessionAgentContent } from "@downcity/type";
|
|
9
|
+
import type { SessionAgentMessagePart } from "@downcity/type";
|
|
10
10
|
import type {
|
|
11
11
|
SessionToolExecutionResult,
|
|
12
12
|
SessionToolInputReady,
|
|
@@ -23,13 +23,24 @@ export interface SessionAssistantOutput {
|
|
|
23
23
|
/** 写入 Tool 执行终态。 */
|
|
24
24
|
write_tool_result(result: SessionToolExecutionResult): Promise<void>;
|
|
25
25
|
/** 使用模型流聚合出的 canonical Parts 校验当前 Step。 */
|
|
26
|
-
finish_step(parts:
|
|
26
|
+
finish_step(parts: SessionAgentMessagePart[]): Promise<void>;
|
|
27
27
|
/** 放弃当前未完成 Step 的临时作用域。 */
|
|
28
28
|
abort_step(): Promise<void>;
|
|
29
29
|
/** User steer 插入前关闭当前连续 Assistant Message。 */
|
|
30
30
|
close_current_message(): Promise<void>;
|
|
31
31
|
/** 把 Action 产生的封闭内容追加到当前 Assistant Message。 */
|
|
32
|
-
append_result_parts(parts: readonly
|
|
32
|
+
append_result_parts(parts: readonly SessionAgentContent[]): Promise<SessionAgentMessagePart[]>;
|
|
33
|
+
/** 在 Turn 收口产物之前追加用户可见的 canonical Error Part。 */
|
|
34
|
+
append_error(input: {
|
|
35
|
+
/** 错误影响范围。 */
|
|
36
|
+
scope: "session" | "turn";
|
|
37
|
+
/** 稳定错误码。 */
|
|
38
|
+
code: string;
|
|
39
|
+
/** 用户可见错误信息。 */
|
|
40
|
+
message: string;
|
|
41
|
+
/** 当前错误是否允许重试恢复。 */
|
|
42
|
+
recoverable: boolean;
|
|
43
|
+
}): Promise<void>;
|
|
33
44
|
/** 按 Turn 最终结果收口 Assistant 输出。 */
|
|
34
45
|
finish(input: {
|
|
35
46
|
/** Assistant 最终状态。 */
|
|
@@ -9,8 +9,11 @@
|
|
|
9
9
|
|
|
10
10
|
import type { RuntimeToolEffect } from "@downcity/type";
|
|
11
11
|
import type { ShellApprovalGateway } from "@downcity/type";
|
|
12
|
-
import type {
|
|
13
|
-
|
|
12
|
+
import type {
|
|
13
|
+
SessionModelUserContent,
|
|
14
|
+
SessionUserMessage,
|
|
15
|
+
} from "@downcity/type";
|
|
16
|
+
import type { SessionAgentContent } from "@downcity/type";
|
|
14
17
|
import type { SessionAssistantOutput } from "@/types/executor/SessionAssistantOutput.js";
|
|
15
18
|
import type { SessionHookContext } from "@downcity/type";
|
|
16
19
|
import type { SessionHookScopeRuntime } from "@downcity/type";
|
|
@@ -45,15 +48,17 @@ export interface SessionTurnContextInit {
|
|
|
45
48
|
/** 上游取消信号;上下文会把它转发到自身拥有的运行生命周期。 */
|
|
46
49
|
abort_signal?: AbortSignal;
|
|
47
50
|
|
|
48
|
-
/** 在 Step
|
|
49
|
-
|
|
51
|
+
/** 在 Step 检查点提交 Session 输入队列;持久化消息由 Composer 重新读取。 */
|
|
52
|
+
commit_step_input?: () => Promise<void>;
|
|
53
|
+
|
|
54
|
+
/** 将 Executor 产生的内部模型输入持久化为当前 Turn 的 canonical User Message。 */
|
|
55
|
+
append_internal_user_message?: (
|
|
56
|
+
parts: readonly SessionModelUserContent[],
|
|
57
|
+
) => Promise<SessionUserMessage>;
|
|
50
58
|
|
|
51
59
|
/** 判断是否仍有等待下一个 Step 消费的 User prompt。 */
|
|
52
60
|
has_pending_step_input?: () => boolean;
|
|
53
61
|
|
|
54
|
-
/** 消费一次 canonical history 重载请求。 */
|
|
55
|
-
consume_history_reload?: () => boolean;
|
|
56
|
-
|
|
57
62
|
/** Executor 写入 canonical Assistant Message 使用的唯一输出端口。 */
|
|
58
63
|
assistant_output?: SessionAssistantOutput;
|
|
59
64
|
|
|
@@ -142,25 +147,23 @@ export interface SessionTurnContext {
|
|
|
142
147
|
hook_context(call_id?: string): SessionHookContext;
|
|
143
148
|
};
|
|
144
149
|
|
|
145
|
-
/** 当前运行的动态 User
|
|
150
|
+
/** 当前运行的动态 User 输入。 */
|
|
146
151
|
readonly input: {
|
|
147
|
-
/**
|
|
148
|
-
|
|
152
|
+
/** 登记已经持久化、属于本 Turn 的 canonical User Message。 */
|
|
153
|
+
observe_user_message(message: SessionUserMessage): void;
|
|
149
154
|
|
|
150
|
-
/**
|
|
151
|
-
|
|
155
|
+
/** 返回本 Turn 已登记 User Message 的不可变快照。 */
|
|
156
|
+
user_messages(): readonly SessionUserMessage[];
|
|
152
157
|
|
|
153
|
-
/**
|
|
154
|
-
|
|
158
|
+
/** 提交输入队列;下一 Step 由 Composer 重新读取 canonical history。 */
|
|
159
|
+
checkpoint(): Promise<void>;
|
|
155
160
|
|
|
156
|
-
/**
|
|
157
|
-
|
|
161
|
+
/** 判断是否有等待下一个 Step 消费的 Session prompt。 */
|
|
162
|
+
has_pending(): boolean;
|
|
158
163
|
|
|
159
|
-
/**
|
|
160
|
-
|
|
164
|
+
/** 持久化一条只供模型消费的内部 canonical User Message。 */
|
|
165
|
+
append_internal(parts: readonly SessionModelUserContent[]): Promise<SessionUserMessage>;
|
|
161
166
|
|
|
162
|
-
/** 消费一次 canonical history 重载请求。 */
|
|
163
|
-
consume_history_reload(): boolean;
|
|
164
167
|
};
|
|
165
168
|
|
|
166
169
|
/** 当前运行的 Assistant Message 与辅助 Action 输出能力。 */
|
|
@@ -169,10 +172,10 @@ export interface SessionTurnContext {
|
|
|
169
172
|
readonly assistant?: SessionAssistantOutput;
|
|
170
173
|
|
|
171
174
|
/** 把 Action 产生的 Assistant Parts 加入当前 Step 收口队列。 */
|
|
172
|
-
enqueue_assistant_parts(parts: readonly
|
|
175
|
+
enqueue_assistant_parts(parts: readonly SessionAgentContent[]): void;
|
|
173
176
|
|
|
174
177
|
/** 消费当前 Step 中等待写入 canonical Assistant Message 的 Parts。 */
|
|
175
|
-
take_assistant_parts():
|
|
178
|
+
take_assistant_parts(): SessionAgentContent[];
|
|
176
179
|
|
|
177
180
|
/** 发布一条不进入 LLM 输入的 Session Action。 */
|
|
178
181
|
publish_action(event: AgentSessionActionEvent): Promise<void>;
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
* - 首条输入、运行中补充输入、排队到下一轮的输入,调用侧都使用同一结构。
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
import type {
|
|
9
|
+
import type { SessionUserContent } from "@downcity/type";
|
|
10
10
|
|
|
11
11
|
/**
|
|
12
12
|
* Session user message part 类型。
|
|
@@ -15,7 +15,7 @@ import type { SessionPromptPart } from "@downcity/type";
|
|
|
15
15
|
* - 这是 Downcity Session 输入边界,不依赖模型协议或第三方 SDK。
|
|
16
16
|
* - 可直接用于 `session.prompt({ query: [...parts] })` 传入 text、context、file 等 parts。
|
|
17
17
|
*/
|
|
18
|
-
export type
|
|
18
|
+
export type AgentSessionPromptContent = SessionUserContent;
|
|
19
19
|
|
|
20
20
|
/**
|
|
21
21
|
* Session prompt 输入。
|
|
@@ -44,17 +44,27 @@ export type SessionUserMessagePart = SessionPromptPart;
|
|
|
44
44
|
* - 远程 Session 中,Data URL 在服务端落盘;调用方本地路径必须对服务端可访问。
|
|
45
45
|
*/
|
|
46
46
|
export interface AgentSessionPromptInput {
|
|
47
|
+
/**
|
|
48
|
+
* 调用方为同一业务输入提供的稳定幂等标识。
|
|
49
|
+
*
|
|
50
|
+
* 说明(中文)
|
|
51
|
+
* - 相同 Session 内重复提交同一个 `request_id`,只会创建一条 canonical User Message。
|
|
52
|
+
* - 已完成的请求直接返回原 Turn 结果;进程重启后未完成的请求会复用原 Turn 恢复执行。
|
|
53
|
+
* - 不同业务输入不得复用同一个值;不需要跨进程重试的交互式调用可以省略。
|
|
54
|
+
*/
|
|
55
|
+
request_id?: string;
|
|
56
|
+
|
|
47
57
|
/**
|
|
48
58
|
* 当前这次要追加到 Session 的用户文本或 parts 数组。
|
|
49
59
|
*
|
|
50
60
|
* 说明(中文)
|
|
51
61
|
* - 支持两种格式:
|
|
52
62
|
* 1. `string`:纯文本用户输入,Session 会将其包装为用户消息。
|
|
53
|
-
* 2. `
|
|
63
|
+
* 2. `AgentSessionPromptContent[]`:Downcity Session 内容,可直接携带 text、context、file 等内容。
|
|
54
64
|
* - 调用侧永远只传"新的用户输入"。
|
|
55
65
|
* - 它是否并入当前 turn,还是排到下一 turn,由 Session 内部决定。
|
|
56
66
|
*/
|
|
57
|
-
query: string |
|
|
67
|
+
query: string | AgentSessionPromptContent[];
|
|
58
68
|
}
|
|
59
69
|
|
|
60
70
|
/**
|
|
@@ -62,7 +72,7 @@ export interface AgentSessionPromptInput {
|
|
|
62
72
|
*
|
|
63
73
|
* 说明(中文)
|
|
64
74
|
* - `string`:trim 后为空即视为空。
|
|
65
|
-
* - `
|
|
75
|
+
* - `AgentSessionPromptContent[]`:数组为空,或仅包含空文本和空 Context 时视为空。
|
|
66
76
|
*/
|
|
67
77
|
export function is_agent_session_prompt_input_empty(input: AgentSessionPromptInput): boolean {
|
|
68
78
|
const query = input.query;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* AdaptivePartContextPolicy 内部持久化与候选类型。
|
|
3
|
+
*
|
|
4
|
+
* 类型集中在 types 目录,策略模块只保留上下文选择行为。
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import type {
|
|
8
|
+
SessionAgentMessagePart,
|
|
9
|
+
SessionMessage,
|
|
10
|
+
SessionUserMessagePart,
|
|
11
|
+
} from "@downcity/type";
|
|
12
|
+
|
|
13
|
+
/** Part 级累计摘要 checkpoint。 */
|
|
14
|
+
export interface AdaptivePartCheckpointRow {
|
|
15
|
+
/** checkpoint 稳定标识。 */
|
|
16
|
+
checkpoint_id: string;
|
|
17
|
+
/** 边界所属 Message 标识。 */
|
|
18
|
+
through_message_id: string;
|
|
19
|
+
/** 边界所属 Message sequence。 */
|
|
20
|
+
through_message_sequence: number;
|
|
21
|
+
/** 边界 Part sequence。 */
|
|
22
|
+
through_part_sequence: number;
|
|
23
|
+
/** 累计摘要正文。 */
|
|
24
|
+
summary: string;
|
|
25
|
+
/** 生成派生结果的策略版本。 */
|
|
26
|
+
policy_version: number;
|
|
27
|
+
/** 派生记录创建时间。 */
|
|
28
|
+
created_at: number;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/** 可参与摘要的稳定 Part 及其 canonical 位置。 */
|
|
32
|
+
export interface StablePartCandidate {
|
|
33
|
+
/** Part 所属完整 Message。 */
|
|
34
|
+
message: SessionMessage;
|
|
35
|
+
/** 具体 canonical Part。 */
|
|
36
|
+
part: SessionUserMessagePart | SessionAgentMessagePart;
|
|
37
|
+
}
|
|
@@ -5,16 +5,16 @@
|
|
|
5
5
|
* 复制 SessionMessages 的消息索引或 Mutation 发布状态。
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
import type {
|
|
8
|
+
import type { SessionStorage } from "@/types/store/SessionStorage.js";
|
|
9
9
|
import type { SessionMessage } from "@downcity/type";
|
|
10
10
|
import type { SessionMutation } from "@downcity/type";
|
|
11
11
|
|
|
12
12
|
/** Assistant Message 状态转换器的构造参数。 */
|
|
13
|
-
export interface
|
|
13
|
+
export interface SessionAgentMessageStateOptions {
|
|
14
14
|
/** 当前 Assistant Message 所属 Session 的稳定标识。 */
|
|
15
15
|
session_id: string;
|
|
16
|
-
/** 负责持久化 canonical Message
|
|
17
|
-
store:
|
|
16
|
+
/** 负责持久化 canonical Message 稳定检查点的 Store。 */
|
|
17
|
+
store: SessionStorage;
|
|
18
18
|
/** 读取 SessionMessages 当前持有的 canonical Message 集合。 */
|
|
19
19
|
list_messages: () => Iterable<SessionMessage>;
|
|
20
20
|
/** 接受已持久化的完整 Message 快照,并按需发布 Mutation。 */
|
|
@@ -22,8 +22,8 @@ export interface SessionAssistantMessageStateOptions {
|
|
|
22
22
|
message: SessionMessage,
|
|
23
23
|
publish_mutation?: boolean,
|
|
24
24
|
) => void;
|
|
25
|
-
/**
|
|
26
|
-
|
|
25
|
+
/** 接受未持久化的实时 Mutation,并只更新当前运行投影。 */
|
|
26
|
+
project_mutation: (
|
|
27
27
|
mutation: SessionMutation,
|
|
28
28
|
message: SessionMessage,
|
|
29
29
|
) => void;
|
|
@@ -4,8 +4,19 @@
|
|
|
4
4
|
* Command 只存在于 Session 运行进程内,不属于 Remote Transport 协议,也不持久化。
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
|
-
/** Session Command
|
|
8
|
-
export
|
|
7
|
+
/** Session Command 的执行类别。 */
|
|
8
|
+
export type SessionCommandKind =
|
|
9
|
+
/** Prompt Command 需要创建或加入一个 Turn。 */
|
|
10
|
+
| "prompt"
|
|
11
|
+
/** Maintenance Command 可以在 Session 空闲期独立执行。 */
|
|
12
|
+
| "maintenance";
|
|
13
|
+
|
|
14
|
+
/** Session 有序输入队列中的 Command。 */
|
|
15
|
+
export interface SessionCommand {
|
|
16
|
+
/** 当前 Command 的执行类别。 */
|
|
17
|
+
kind: SessionCommandKind;
|
|
18
|
+
/** Prompt 恢复执行时要求复用的稳定 Turn ID。 */
|
|
19
|
+
turn_id?: string;
|
|
9
20
|
/** Command 出队后执行的完整行为。 */
|
|
10
21
|
execute: () => Promise<void>;
|
|
11
22
|
/** Session stop 时取消该 Command 的可选行为;未提供时 Command 继续保留。 */
|
|
@@ -14,16 +25,19 @@ export interface SessionCommandOptions {
|
|
|
14
25
|
completion?: SessionCommandCompletion;
|
|
15
26
|
}
|
|
16
27
|
|
|
28
|
+
/** Session facade 创建 Command 时使用的输入。 */
|
|
29
|
+
export type SessionCommandOptions = SessionCommand;
|
|
30
|
+
|
|
17
31
|
/** Session Command 成功执行后的 canonical 持久化信息。 */
|
|
18
32
|
export interface SessionCommandCompletion {
|
|
19
|
-
/** 完成信息固定持久化为 Action
|
|
33
|
+
/** 完成信息固定持久化为 Agent Message 内的 Action Part。 */
|
|
20
34
|
type: "action";
|
|
21
|
-
/** Action Message
|
|
35
|
+
/** Action Part 及其所属 Agent Message 共用的稳定业务标识。 */
|
|
22
36
|
id: string;
|
|
23
|
-
/** Action
|
|
37
|
+
/** Action Part 展示的用户可读标题。 */
|
|
24
38
|
title: string;
|
|
25
|
-
/** Action
|
|
39
|
+
/** Action Part 展示的可选结果说明。 */
|
|
26
40
|
description?: string;
|
|
27
|
-
/** Action Message 持久化后是否发布对应 Session Mutation。 */
|
|
41
|
+
/** Action Part 所属 Agent Message 持久化后是否发布对应 Session Mutation。 */
|
|
28
42
|
publish_mutation?: boolean;
|
|
29
43
|
}
|
|
@@ -1,17 +1,20 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Session Composer 类型。
|
|
3
3
|
*
|
|
4
|
-
* Composer
|
|
5
|
-
*
|
|
4
|
+
* Composer 是最终模型输入的唯一生成者:它组合运行快照、canonical history 与内部
|
|
5
|
+
* Context Policy;不拥有 Message、Turn 或数据库连接生命周期。
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
import type { ModelClient, ModelMessage } from "@downcity/type";
|
|
9
|
-
import type { RuntimeTool as Tool } from "@downcity/type";
|
|
8
|
+
import type { ModelClient, ModelMessage, RuntimeTool as Tool } from "@downcity/type";
|
|
10
9
|
import type { SessionSystemMessage } from "@/executor/types/SessionPrompts.js";
|
|
11
10
|
import type { AgentSessionSystemBlock } from "@/types/agent/SessionTypes.js";
|
|
12
|
-
import type { SessionContextSnapshot, SessionSegmentSummary } from "@/types/session/SessionSegment.js";
|
|
13
11
|
import type { SessionHookContextBlock } from "@downcity/type";
|
|
14
12
|
import type { ModelRequestFailureReporter } from "@/types/executor/ModelRequest.js";
|
|
13
|
+
import type { SessionStorage } from "@/types/store/SessionStorage.js";
|
|
14
|
+
import type {
|
|
15
|
+
SessionContextRecoveryReason,
|
|
16
|
+
SessionResolvedContextDiagnostics,
|
|
17
|
+
} from "@/types/session/SessionContextPolicy.js";
|
|
15
18
|
|
|
16
19
|
/** Composer 可读取的 Session 身份快照。 */
|
|
17
20
|
export interface SessionComposeIdentity {
|
|
@@ -19,9 +22,9 @@ export interface SessionComposeIdentity {
|
|
|
19
22
|
agent_id: string;
|
|
20
23
|
/** 当前 Session 的稳定标识。 */
|
|
21
24
|
session_id: string;
|
|
22
|
-
/** 当前
|
|
25
|
+
/** 当前 Workspace 的绝对根目录。 */
|
|
23
26
|
project_root: string;
|
|
24
|
-
/** 当前 Session
|
|
27
|
+
/** 当前 Session 的创建时间戳。 */
|
|
25
28
|
created_at: number;
|
|
26
29
|
/** 当前 Session 使用的参考时区。 */
|
|
27
30
|
timezone: string;
|
|
@@ -29,11 +32,11 @@ export interface SessionComposeIdentity {
|
|
|
29
32
|
|
|
30
33
|
/** Composer 可读取的当前 Step 生效状态。 */
|
|
31
34
|
export interface SessionComposeState {
|
|
32
|
-
/** 当前 Step
|
|
35
|
+
/** 当前 Step 使用的模型实例。 */
|
|
33
36
|
model?: ModelClient;
|
|
34
|
-
/**
|
|
37
|
+
/** 当前模型声明的上下文窗口。 */
|
|
35
38
|
model_context_window?: number;
|
|
36
|
-
/** 当前 Step 生效的
|
|
39
|
+
/** 当前 Step 生效的 Workspace 环境变量。 */
|
|
37
40
|
env: Readonly<Record<string, string>>;
|
|
38
41
|
/** 当前 Step 生效的 Agent instruction 文本。 */
|
|
39
42
|
systems: readonly string[];
|
|
@@ -41,79 +44,76 @@ export interface SessionComposeState {
|
|
|
41
44
|
tools: Readonly<Record<string, Tool>>;
|
|
42
45
|
/** 当前 Step 生效的 instruction system blocks。 */
|
|
43
46
|
instruction_system_blocks: readonly AgentSessionSystemBlock[];
|
|
44
|
-
/**
|
|
47
|
+
/** 宿主注入的受托管 Plugin system blocks。 */
|
|
45
48
|
managed_plugin_system_blocks: readonly AgentSessionSystemBlock[];
|
|
46
49
|
/** 当前 Step 捕获的 Plugin system blocks。 */
|
|
47
50
|
plugin_system_blocks: readonly AgentSessionSystemBlock[];
|
|
48
|
-
/** 当前 Turn
|
|
51
|
+
/** 当前 Turn 冻结的 Plugin 动态上下文。 */
|
|
49
52
|
plugin_context_blocks: readonly SessionHookContextBlock[];
|
|
50
53
|
}
|
|
51
54
|
|
|
52
55
|
/** Composer 可读取的当前 Turn 快照。 */
|
|
53
56
|
export interface SessionComposeTurn {
|
|
54
|
-
/** 当前 Turn
|
|
57
|
+
/** 当前 Turn 标识;只读查询时允许为空。 */
|
|
55
58
|
turn_id?: string;
|
|
56
|
-
/**
|
|
59
|
+
/** 当前执行已进行的上下文恢复次数。 */
|
|
57
60
|
retry_count: number;
|
|
58
61
|
}
|
|
59
62
|
|
|
63
|
+
/** Composer 初始化输入。 */
|
|
64
|
+
export interface SessionComposerInitializeInput {
|
|
65
|
+
/** 当前 Session 的统一持久化边界。 */
|
|
66
|
+
storage: SessionStorage;
|
|
67
|
+
}
|
|
68
|
+
|
|
60
69
|
/** 单次模型输入组装参数。 */
|
|
61
70
|
export interface SessionComposeInput {
|
|
62
71
|
/** 当前 Session 身份快照。 */
|
|
63
72
|
session: SessionComposeIdentity;
|
|
64
73
|
/** 当前 Step 已生效的运行状态。 */
|
|
65
74
|
state: SessionComposeState;
|
|
66
|
-
/** 当前 Session
|
|
67
|
-
|
|
75
|
+
/** 当前 Session 的统一持久化边界。 */
|
|
76
|
+
storage: SessionStorage;
|
|
68
77
|
/** 当前 Turn 快照。 */
|
|
69
78
|
turn: SessionComposeTurn;
|
|
70
79
|
}
|
|
71
80
|
|
|
81
|
+
/** 上下文超限后的恢复输入。 */
|
|
82
|
+
export interface SessionContextRecoveryInput {
|
|
83
|
+
/** 当前 Session 身份快照。 */
|
|
84
|
+
session: SessionComposeIdentity;
|
|
85
|
+
/** 当前 Session 使用的模型。 */
|
|
86
|
+
model?: ModelClient;
|
|
87
|
+
/** 当前 Session 的统一持久化边界。 */
|
|
88
|
+
storage: SessionStorage;
|
|
89
|
+
/** 触发当前恢复的稳定领域原因。 */
|
|
90
|
+
reason: SessionContextRecoveryReason;
|
|
91
|
+
/** 模型请求逐次失败的可选观测入口。 */
|
|
92
|
+
on_model_request_failure?: ModelRequestFailureReporter;
|
|
93
|
+
}
|
|
94
|
+
|
|
72
95
|
/** Composer 为一次模型 Step 生成的完整输入。 */
|
|
73
96
|
export interface SessionStepInput {
|
|
74
97
|
/** 当前 Step 的 system messages。 */
|
|
75
98
|
system: SessionSystemMessage[];
|
|
76
|
-
/** 当前 Step 的可解释 system
|
|
99
|
+
/** 当前 Step 的可解释 system blocks。 */
|
|
77
100
|
system_blocks?: AgentSessionSystemBlock[];
|
|
78
101
|
/** 当前 Step 已转换完成的标准模型消息。 */
|
|
79
102
|
messages: ModelMessage[];
|
|
80
103
|
/** 当前 Step 可调用的工具集合。 */
|
|
81
104
|
tools: Record<string, Tool>;
|
|
105
|
+
/** 本次上下文策略诊断。 */
|
|
106
|
+
context_diagnostics?: SessionResolvedContextDiagnostics;
|
|
82
107
|
}
|
|
83
108
|
|
|
84
|
-
/**
|
|
85
|
-
export interface SessionCompactionInput {
|
|
86
|
-
/** 当前 Session 的稳定身份快照。 */
|
|
87
|
-
session: SessionComposeIdentity;
|
|
88
|
-
/** 当前 Session 实际使用的模型;只读或未配置场景允许为空。 */
|
|
89
|
-
model?: ModelClient;
|
|
90
|
-
/** 当前 Session 的累计 Summary 与 Active Message 快照。 */
|
|
91
|
-
history: Readonly<SessionContextSnapshot>;
|
|
92
|
-
/** 可选的模型请求逐次失败通知入口。 */
|
|
93
|
-
on_model_request_failure?: ModelRequestFailureReporter;
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
/** Composer 生成、等待 SessionMessages 提交的压缩计划。 */
|
|
97
|
-
export interface SessionCompactionPlan {
|
|
98
|
-
/** Active 中最后一条需要移入 Segment 的 Message sequence。 */
|
|
99
|
-
through_sequence: number;
|
|
100
|
-
/** 新 Segment 使用的累计 Summary。 */
|
|
101
|
-
summary: SessionSegmentSummary;
|
|
102
|
-
/** 当前计划覆盖到的最后一条 Message 标识。 */
|
|
103
|
-
boundary_message_id: string;
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
/** Session 级可替换执行策略。 */
|
|
109
|
+
/** Session 级可替换 Composer。 */
|
|
107
110
|
export interface SessionComposer {
|
|
108
111
|
/** Composer 的稳定可读名称。 */
|
|
109
112
|
readonly name: string;
|
|
110
|
-
|
|
111
|
-
|
|
113
|
+
/** 初始化 Composer 及其内部 Policy。 */
|
|
114
|
+
initialize(input: SessionComposerInitializeInput): Promise<void>;
|
|
115
|
+
/** 组装一次模型 Step 使用的最终输入。 */
|
|
112
116
|
compose(input: SessionComposeInput): Promise<SessionStepInput>;
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
compact(input: SessionCompactionInput): Promise<SessionCompactionPlan | null>;
|
|
116
|
-
|
|
117
|
-
/** 判断给定错误是否应在持久化压缩后重试。 */
|
|
118
|
-
should_compact(error: unknown): boolean;
|
|
117
|
+
/** 尝试推进上下文派生状态;有效推进时返回 true。 */
|
|
118
|
+
recover_context(input: SessionContextRecoveryInput): Promise<boolean>;
|
|
119
119
|
}
|