@downcity/agent 1.1.438 → 1.1.445
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 +25 -18
- package/bin/agent/Agent.d.ts +44 -20
- package/bin/agent/Agent.d.ts.map +1 -1
- package/bin/agent/Agent.js +114 -69
- package/bin/agent/Agent.js.map +1 -1
- package/bin/agent/AgentInstructions.d.ts +18 -4
- package/bin/agent/AgentInstructions.d.ts.map +1 -1
- package/bin/agent/AgentInstructions.js +33 -14
- package/bin/agent/AgentInstructions.js.map +1 -1
- package/bin/agent/AgentMemoryStorage.d.ts +1 -1
- package/bin/agent/AgentMemoryStorage.d.ts.map +1 -1
- package/bin/agent/AgentMemoryStorage.js.map +1 -1
- package/bin/agent/AgentSessions.d.ts +29 -16
- package/bin/agent/AgentSessions.d.ts.map +1 -1
- package/bin/agent/AgentSessions.js +42 -22
- package/bin/agent/AgentSessions.js.map +1 -1
- package/bin/group/Group.d.ts +13 -12
- package/bin/group/Group.d.ts.map +1 -1
- package/bin/group/Group.js +24 -23
- package/bin/group/Group.js.map +1 -1
- package/bin/group/GroupSession.d.ts.map +1 -1
- package/bin/group/GroupSession.js +13 -9
- package/bin/group/GroupSession.js.map +1 -1
- package/bin/group/GroupSessions.d.ts +27 -2
- package/bin/group/GroupSessions.d.ts.map +1 -1
- package/bin/group/GroupSessions.js +68 -21
- package/bin/group/GroupSessions.js.map +1 -1
- package/bin/group/storage/LocalGroupSessionDataStore.d.ts +8 -0
- package/bin/group/storage/LocalGroupSessionDataStore.d.ts.map +1 -1
- package/bin/group/storage/LocalGroupSessionDataStore.js +1 -1
- package/bin/group/storage/LocalGroupSessionDataStore.js.map +1 -1
- package/bin/group/storage/LocalGroupSessionStore.d.ts +64 -5
- package/bin/group/storage/LocalGroupSessionStore.d.ts.map +1 -1
- package/bin/group/storage/LocalGroupSessionStore.js +114 -23
- package/bin/group/storage/LocalGroupSessionStore.js.map +1 -1
- package/bin/index.d.ts +25 -30
- package/bin/index.d.ts.map +1 -1
- package/bin/index.js +14 -14
- package/bin/index.js.map +1 -1
- package/bin/{executor/model → model}/ModelGenerate.d.ts +1 -1
- package/bin/model/ModelGenerate.d.ts.map +1 -0
- package/bin/model/ModelGenerate.js.map +1 -0
- package/bin/{executor/model → model}/ModelRequestRunner.d.ts +1 -1
- package/bin/model/ModelRequestRunner.d.ts.map +1 -0
- package/bin/model/ModelRequestRunner.js.map +1 -0
- package/bin/{executor/model → model}/ModelStepRunner.d.ts +6 -7
- package/bin/model/ModelStepRunner.d.ts.map +1 -0
- package/bin/{executor/model → model}/ModelStepRunner.js +16 -10
- package/bin/model/ModelStepRunner.js.map +1 -0
- package/bin/model/ModelStreamConsumer.d.ts.map +1 -0
- package/bin/model/ModelStreamConsumer.js.map +1 -0
- package/bin/model/ModelStreamFailure.d.ts.map +1 -0
- package/bin/model/ModelStreamFailure.js.map +1 -0
- package/bin/model/ToolInputValidation.d.ts +28 -0
- package/bin/model/ToolInputValidation.d.ts.map +1 -0
- package/bin/model/ToolInputValidation.js +37 -0
- package/bin/model/ToolInputValidation.js.map +1 -0
- package/bin/model/messages/ChatMessageMarkup.d.ts.map +1 -0
- package/bin/model/messages/ChatMessageMarkup.js.map +1 -0
- package/bin/{executor → model}/messages/ChatMessageMarkupTypes.d.ts +1 -1
- package/bin/model/messages/ChatMessageMarkupTypes.d.ts.map +1 -0
- package/bin/{executor → model}/messages/ChatMessageMarkupTypes.js +1 -1
- package/bin/model/messages/ChatMessageMarkupTypes.js.map +1 -0
- package/bin/model/messages/SessionAttachmentMapper.d.ts.map +1 -0
- package/bin/model/messages/SessionAttachmentMapper.js.map +1 -0
- package/bin/model/messages/SessionMessageLog.d.ts.map +1 -0
- package/bin/model/messages/SessionMessageLog.js.map +1 -0
- package/bin/model/messages/SessionModelMessages.d.ts.map +1 -0
- package/bin/{executor → model}/messages/SessionModelMessages.js +0 -1
- package/bin/model/messages/SessionModelMessages.js.map +1 -0
- package/bin/model/prompts/SystemPromptAssets.d.ts.map +1 -0
- package/bin/{executor/composer/system/default → model/prompts}/SystemPromptAssets.js +1 -1
- package/bin/model/prompts/SystemPromptAssets.js.map +1 -0
- package/bin/model/prompts/assets/core.prompt.d.ts +7 -0
- package/bin/model/prompts/assets/core.prompt.d.ts.map +1 -0
- package/bin/model/prompts/assets/core.prompt.js +8 -0
- package/bin/model/prompts/assets/core.prompt.js.map +1 -0
- package/bin/session/Session.d.ts +29 -17
- package/bin/session/Session.d.ts.map +1 -1
- package/bin/session/Session.js +161 -134
- package/bin/session/Session.js.map +1 -1
- package/bin/session/input/SessionHookRunner.d.ts +52 -0
- package/bin/session/input/SessionHookRunner.d.ts.map +1 -0
- package/bin/session/input/SessionHookRunner.js +51 -0
- package/bin/session/input/SessionHookRunner.js.map +1 -0
- package/bin/session/input/SessionSystem.d.ts +26 -0
- package/bin/session/input/SessionSystem.d.ts.map +1 -0
- package/bin/session/{SessionSystem.js → input/SessionSystem.js} +27 -23
- package/bin/session/input/SessionSystem.js.map +1 -0
- package/bin/session/input/StepInput.d.ts +77 -0
- package/bin/session/input/StepInput.d.ts.map +1 -0
- package/bin/session/input/StepInput.js +429 -0
- package/bin/session/input/StepInput.js.map +1 -0
- package/bin/session/input/composer/AdaptiveContextCheckpoint.d.ts +33 -0
- package/bin/session/input/composer/AdaptiveContextCheckpoint.d.ts.map +1 -0
- package/bin/session/input/composer/AdaptiveContextCheckpoint.js +83 -0
- package/bin/session/input/composer/AdaptiveContextCheckpoint.js.map +1 -0
- package/bin/session/input/composer/AdaptiveContextParts.d.ts +26 -0
- package/bin/session/input/composer/AdaptiveContextParts.d.ts.map +1 -0
- package/bin/session/input/composer/AdaptiveContextParts.js +124 -0
- package/bin/session/input/composer/AdaptiveContextParts.js.map +1 -0
- package/bin/session/input/composer/ComposerAssembly.d.ts +21 -0
- package/bin/session/input/composer/ComposerAssembly.d.ts.map +1 -0
- package/bin/session/input/composer/ComposerAssembly.js +64 -0
- package/bin/session/input/composer/ComposerAssembly.js.map +1 -0
- package/bin/session/{composer/policies/SessionSummaryPrompts.d.ts → input/composer/ContextSummaryPrompts.d.ts} +5 -3
- package/bin/session/input/composer/ContextSummaryPrompts.d.ts.map +1 -0
- package/bin/session/{composer/policies/SessionSummaryPrompts.js → input/composer/ContextSummaryPrompts.js} +5 -3
- package/bin/session/input/composer/ContextSummaryPrompts.js.map +1 -0
- package/bin/session/input/composer/DefaultSessionComposer.d.ts +24 -0
- package/bin/session/input/composer/DefaultSessionComposer.d.ts.map +1 -0
- package/bin/session/input/composer/DefaultSessionComposer.js +108 -0
- package/bin/session/input/composer/DefaultSessionComposer.js.map +1 -0
- package/bin/session/input/composer/FullHistorySessionComposer.d.ts +19 -0
- package/bin/session/input/composer/FullHistorySessionComposer.d.ts.map +1 -0
- package/bin/session/input/composer/FullHistorySessionComposer.js +36 -0
- package/bin/session/input/composer/FullHistorySessionComposer.js.map +1 -0
- package/bin/session/{SessionLoop.d.ts → loop/SessionLoop.d.ts} +34 -7
- package/bin/session/loop/SessionLoop.d.ts.map +1 -0
- package/bin/session/{SessionLoop.js → loop/SessionLoop.js} +79 -16
- package/bin/session/loop/SessionLoop.js.map +1 -0
- package/bin/session/{SessionQueue.d.ts → loop/SessionQueue.d.ts} +9 -1
- package/bin/session/loop/SessionQueue.d.ts.map +1 -0
- package/bin/session/{SessionQueue.js → loop/SessionQueue.js} +19 -0
- package/bin/session/loop/SessionQueue.js.map +1 -0
- package/bin/session/{SessionState.d.ts → loop/SessionState.d.ts} +4 -5
- package/bin/session/loop/SessionState.d.ts.map +1 -0
- package/bin/session/{SessionState.js → loop/SessionState.js} +6 -25
- package/bin/session/loop/SessionState.js.map +1 -0
- package/bin/session/{SessionTitle.d.ts → loop/SessionTitle.d.ts} +4 -4
- package/bin/session/loop/SessionTitle.d.ts.map +1 -0
- package/bin/session/{SessionTitle.js → loop/SessionTitle.js} +3 -3
- package/bin/session/loop/SessionTitle.js.map +1 -0
- package/bin/session/loop/SessionTitleTask.d.ts.map +1 -0
- package/bin/session/loop/SessionTitleTask.js.map +1 -0
- package/bin/session/{runtime → loop}/SessionTurnCompletion.d.ts +7 -0
- package/bin/session/loop/SessionTurnCompletion.d.ts.map +1 -0
- package/bin/session/{runtime → loop}/SessionTurnCompletion.js +25 -6
- package/bin/session/loop/SessionTurnCompletion.js.map +1 -0
- package/bin/session/loop/SessionTurnContext.d.ts +12 -0
- package/bin/session/loop/SessionTurnContext.d.ts.map +1 -0
- package/bin/session/{runtime → loop}/SessionTurnContext.js +14 -67
- package/bin/session/loop/SessionTurnContext.js.map +1 -0
- package/bin/session/loop/SessionTurnFileDiff.d.ts.map +1 -0
- package/bin/session/{runtime → loop}/SessionTurnFileDiff.js +1 -1
- package/bin/session/loop/SessionTurnFileDiff.js.map +1 -0
- package/bin/session/{messages → loop}/SessionTurnFileDiffBuilder.d.ts +3 -3
- package/bin/session/loop/SessionTurnFileDiffBuilder.d.ts.map +1 -0
- package/bin/session/loop/SessionTurnFileDiffBuilder.js.map +1 -0
- package/bin/session/messages/ApprovalInteraction.d.ts +30 -0
- package/bin/session/messages/ApprovalInteraction.d.ts.map +1 -0
- package/bin/session/messages/ApprovalInteraction.js +61 -0
- package/bin/session/messages/ApprovalInteraction.js.map +1 -0
- package/bin/session/messages/SessionAgentMessageState.d.ts +47 -18
- package/bin/session/messages/SessionAgentMessageState.d.ts.map +1 -1
- package/bin/session/messages/SessionAgentMessageState.js +224 -86
- package/bin/session/messages/SessionAgentMessageState.js.map +1 -1
- package/bin/session/messages/SessionAgentMessageWriter.d.ts +15 -4
- package/bin/session/messages/SessionAgentMessageWriter.d.ts.map +1 -1
- package/bin/session/messages/SessionAgentMessageWriter.js +57 -37
- package/bin/session/messages/SessionAgentMessageWriter.js.map +1 -1
- package/bin/session/messages/SessionAgentParts.d.ts +14 -0
- package/bin/session/messages/SessionAgentParts.d.ts.map +1 -0
- package/bin/session/messages/SessionAgentParts.js +20 -0
- package/bin/session/messages/SessionAgentParts.js.map +1 -0
- package/bin/session/{execution → messages}/SessionAssistantOutputAdapter.d.ts +2 -2
- package/bin/session/messages/SessionAssistantOutputAdapter.d.ts.map +1 -0
- package/bin/session/messages/SessionAssistantOutputAdapter.js.map +1 -0
- package/bin/session/messages/SessionEventHub.d.ts.map +1 -0
- package/bin/session/messages/SessionEventHub.js.map +1 -0
- package/bin/session/messages/SessionInteractions.d.ts +57 -0
- package/bin/session/messages/SessionInteractions.d.ts.map +1 -0
- package/bin/session/messages/SessionInteractions.js +178 -0
- package/bin/session/messages/SessionInteractions.js.map +1 -0
- package/bin/session/messages/SessionJsonValue.d.ts +1 -3
- package/bin/session/messages/SessionJsonValue.d.ts.map +1 -1
- package/bin/session/messages/SessionJsonValue.js +0 -19
- package/bin/session/messages/SessionJsonValue.js.map +1 -1
- package/bin/session/messages/SessionMessageCache.d.ts +55 -0
- package/bin/session/messages/SessionMessageCache.d.ts.map +1 -0
- package/bin/session/messages/SessionMessageCache.js +133 -0
- package/bin/session/messages/SessionMessageCache.js.map +1 -0
- package/bin/session/messages/SessionMessageState.d.ts +17 -0
- package/bin/session/messages/SessionMessageState.d.ts.map +1 -0
- package/bin/session/messages/SessionMessageState.js +34 -0
- package/bin/session/messages/SessionMessageState.js.map +1 -0
- package/bin/session/messages/SessionMessageTimeline.d.ts.map +1 -0
- package/bin/session/{browse → messages}/SessionMessageTimeline.js +0 -1
- package/bin/session/messages/SessionMessageTimeline.js.map +1 -0
- package/bin/session/{SessionMessages.d.ts → messages/SessionMessages.d.ts} +35 -43
- package/bin/session/messages/SessionMessages.d.ts.map +1 -0
- package/bin/session/{SessionMessages.js → messages/SessionMessages.js} +178 -196
- package/bin/session/messages/SessionMessages.js.map +1 -0
- package/bin/session/messages/SessionModelRequestWarning.d.ts.map +1 -0
- package/bin/session/messages/SessionModelRequestWarning.js.map +1 -0
- package/bin/session/messages/SessionMutationFactory.d.ts +26 -0
- package/bin/session/messages/SessionMutationFactory.d.ts.map +1 -0
- package/bin/session/messages/SessionMutationFactory.js +38 -0
- package/bin/session/messages/SessionMutationFactory.js.map +1 -0
- package/bin/session/messages/SessionUserMessage.d.ts +5 -7
- package/bin/session/messages/SessionUserMessage.d.ts.map +1 -1
- package/bin/session/messages/SessionUserMessage.js +5 -28
- package/bin/session/messages/SessionUserMessage.js.map +1 -1
- package/bin/{executor/core-engine/CoreEngineSignals.d.ts → session/runner/AssistantParts.d.ts} +4 -9
- package/bin/session/runner/AssistantParts.d.ts.map +1 -0
- package/bin/{executor/core-engine/CoreEngineSignals.js → session/runner/AssistantParts.js} +4 -17
- package/bin/session/runner/AssistantParts.js.map +1 -0
- package/bin/session/runner/ContextPressure.d.ts +15 -0
- package/bin/session/runner/ContextPressure.d.ts.map +1 -0
- package/bin/{executor/core-engine/CoreEngineContextCompaction.js → session/runner/ContextPressure.js} +11 -11
- package/bin/session/runner/ContextPressure.js.map +1 -0
- package/bin/session/runner/ContextRetry.d.ts +39 -0
- package/bin/session/runner/ContextRetry.d.ts.map +1 -0
- package/bin/{executor/services/ExecutorRecoveryPolicy.js → session/runner/ContextRetry.js} +19 -19
- package/bin/session/runner/ContextRetry.js.map +1 -0
- package/bin/{executor/core-engine/CoreEngineError.d.ts → session/runner/ModelFailure.d.ts} +4 -4
- package/bin/session/runner/ModelFailure.d.ts.map +1 -0
- package/bin/{executor/core-engine/CoreEngineError.js → session/runner/ModelFailure.js} +4 -4
- package/bin/session/runner/ModelFailure.js.map +1 -0
- package/bin/session/runner/SessionExecutor.d.ts +108 -0
- package/bin/session/runner/SessionExecutor.d.ts.map +1 -0
- package/bin/session/runner/SessionExecutor.js +430 -0
- package/bin/session/runner/SessionExecutor.js.map +1 -0
- package/bin/session/runner/ToolLoopDecision.d.ts +60 -0
- package/bin/session/runner/ToolLoopDecision.d.ts.map +1 -0
- package/bin/{executor/core-engine/CoreEngineLoopDecision.js → session/runner/ToolLoopDecision.js} +5 -5
- package/bin/session/runner/ToolLoopDecision.js.map +1 -0
- package/bin/session/runner/ToolLoopLimits.d.ts +30 -0
- package/bin/session/runner/ToolLoopLimits.d.ts.map +1 -0
- package/bin/session/runner/ToolLoopLimits.js +46 -0
- package/bin/session/runner/ToolLoopLimits.js.map +1 -0
- package/bin/session/{browse → storage}/Browse.d.ts +1 -1
- package/bin/session/storage/Browse.d.ts.map +1 -0
- package/bin/session/{browse → storage}/Browse.js +1 -1
- package/bin/session/storage/Browse.js.map +1 -0
- package/bin/session/storage/LocalSessionStore.js +1 -1
- package/bin/session/storage/LocalSessionStore.js.map +1 -1
- package/bin/session/storage/LocalStorePaths.d.ts +0 -2
- package/bin/session/storage/LocalStorePaths.d.ts.map +1 -1
- package/bin/session/storage/LocalStorePaths.js +1 -1
- package/bin/session/storage/LocalStorePaths.js.map +1 -1
- package/bin/session/storage/Metadata.d.ts +1 -23
- package/bin/session/storage/Metadata.d.ts.map +1 -1
- package/bin/session/storage/Metadata.js +0 -18
- package/bin/session/storage/Metadata.js.map +1 -1
- package/bin/session/storage/RuntimeSessionPort.d.ts +0 -4
- package/bin/session/storage/RuntimeSessionPort.d.ts.map +1 -1
- package/bin/session/storage/RuntimeSessionPort.js +0 -1
- package/bin/session/storage/RuntimeSessionPort.js.map +1 -1
- package/bin/session/{preview → storage}/SessionMessagePreview.d.ts.map +1 -1
- package/bin/session/{preview → storage}/SessionMessagePreview.js +0 -1
- package/bin/session/{preview → storage}/SessionMessagePreview.js.map +1 -1
- package/bin/session/storage/SessionStorageCodec.d.ts.map +1 -1
- package/bin/session/storage/SessionStorageCodec.js +36 -18
- package/bin/session/storage/SessionStorageCodec.js.map +1 -1
- package/bin/session/storage/SessionStorageSchema.d.ts +1 -1
- package/bin/session/storage/SessionStorageSchema.js +1 -1
- package/bin/session/storage/SqliteSessionStorage.d.ts +6 -4
- package/bin/session/storage/SqliteSessionStorage.d.ts.map +1 -1
- package/bin/session/storage/SqliteSessionStorage.js +21 -18
- package/bin/session/storage/SqliteSessionStorage.js.map +1 -1
- package/bin/tools/ask/AskQuestionAnswers.d.ts +20 -0
- package/bin/tools/ask/AskQuestionAnswers.d.ts.map +1 -0
- package/bin/tools/ask/AskQuestionAnswers.js +99 -0
- package/bin/tools/ask/AskQuestionAnswers.js.map +1 -0
- package/bin/tools/ask/AskQuestionsTool.d.ts +5 -2
- package/bin/tools/ask/AskQuestionsTool.d.ts.map +1 -1
- package/bin/tools/ask/AskQuestionsTool.js +23 -31
- package/bin/tools/ask/AskQuestionsTool.js.map +1 -1
- package/bin/tools/ask/AskQuestionsToolSchemas.d.ts +1 -1
- package/bin/types/agent/AgentOptions.d.ts +16 -8
- package/bin/types/agent/AgentOptions.d.ts.map +1 -1
- package/bin/types/agent/AgentSessionCollection.d.ts +8 -0
- package/bin/types/agent/AgentSessionCollection.d.ts.map +1 -1
- package/bin/types/agent/SessionActor.d.ts +3 -3
- package/bin/types/agent/SessionActor.d.ts.map +1 -1
- package/bin/types/group/DispatchStrategy.js +1 -1
- package/bin/types/group/DispatchStrategy.js.map +1 -1
- package/bin/types/group/GroupSession.d.ts +41 -1
- package/bin/types/group/GroupSession.d.ts.map +1 -1
- package/bin/types/group/GroupSessionStore.d.ts +30 -3
- package/bin/types/group/GroupSessionStore.d.ts.map +1 -1
- package/bin/types/model/ModelRequest.d.ts.map +1 -0
- package/bin/types/model/ModelRequest.js.map +1 -0
- package/bin/types/sdk/AgentSessionAction.d.ts +1 -9
- package/bin/types/sdk/AgentSessionAction.d.ts.map +1 -1
- package/bin/types/session/{AdaptivePartContextPolicy.d.ts → ContextCheckpoint.d.ts} +10 -9
- package/bin/types/session/ContextCheckpoint.d.ts.map +1 -0
- package/bin/types/session/ContextCheckpoint.js +8 -0
- package/bin/types/session/ContextCheckpoint.js.map +1 -0
- package/bin/types/session/SessionAgentMessageState.d.ts +6 -10
- package/bin/types/session/SessionAgentMessageState.d.ts.map +1 -1
- package/bin/types/session/SessionAgentMessageState.js +3 -2
- package/bin/types/session/SessionAgentMessageState.js.map +1 -1
- package/bin/types/session/SessionComposer.d.ts +65 -36
- package/bin/types/session/SessionComposer.d.ts.map +1 -1
- package/bin/types/session/SessionComposer.js +7 -2
- package/bin/types/session/SessionComposer.js.map +1 -1
- package/bin/types/session/SessionExecution.d.ts +15 -11
- package/bin/types/session/SessionExecution.d.ts.map +1 -1
- package/bin/types/session/SessionExecution.js +1 -1
- package/bin/types/session/SessionInteractions.d.ts +0 -2
- package/bin/types/session/SessionInteractions.d.ts.map +1 -1
- package/bin/types/session/SessionLocalState.d.ts +0 -4
- package/bin/types/session/SessionLocalState.d.ts.map +1 -1
- package/bin/types/session/SessionLoop.d.ts +33 -12
- package/bin/types/session/SessionLoop.d.ts.map +1 -1
- package/bin/types/session/SessionMessages.d.ts +3 -29
- package/bin/types/session/SessionMessages.d.ts.map +1 -1
- package/bin/types/session/SessionOptions.d.ts +16 -13
- package/bin/types/session/SessionOptions.d.ts.map +1 -1
- package/bin/types/session/SessionPort.d.ts +0 -3
- package/bin/types/session/SessionPort.d.ts.map +1 -1
- package/bin/types/session/SessionState.d.ts +0 -1
- package/bin/types/session/SessionState.d.ts.map +1 -1
- package/bin/types/session/SessionSystem.d.ts +10 -12
- 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 +12 -2
- package/bin/types/session/SessionTurnCompletion.d.ts.map +1 -1
- package/bin/types/session/SessionTurnFileDiff.d.ts +4 -4
- package/bin/types/session/SessionTurnFileDiff.d.ts.map +1 -1
- package/bin/types/session/{SessionComposition.d.ts → StepInput.d.ts} +17 -15
- package/bin/types/session/StepInput.d.ts.map +1 -0
- package/bin/types/session/StepInput.js +8 -0
- package/bin/types/session/StepInput.js.map +1 -0
- package/bin/types/store/SessionHistoryMeta.d.ts.map +1 -0
- package/bin/types/store/SessionHistoryMeta.js.map +1 -0
- package/bin/types/store/SessionStorage.d.ts +17 -12
- package/bin/types/store/SessionStorage.d.ts.map +1 -1
- package/bin/types/tool/BoundAgentTool.d.ts +36 -0
- package/bin/types/tool/BoundAgentTool.d.ts.map +1 -0
- package/bin/types/tool/BoundAgentTool.js +13 -0
- package/bin/types/tool/BoundAgentTool.js.map +1 -0
- package/bin/types/tools/ask/AskQuestionsTool.d.ts +9 -13
- package/bin/types/tools/ask/AskQuestionsTool.d.ts.map +1 -1
- package/bin/types/tools/ask/AskQuestionsTool.js +3 -2
- package/bin/types/tools/ask/AskQuestionsTool.js.map +1 -1
- package/bin/types/turn/SessionAssistantOutput.d.ts.map +1 -0
- package/bin/types/turn/SessionAssistantOutput.js.map +1 -0
- package/bin/types/{executor → turn}/SessionTurnContext.d.ts +10 -28
- package/bin/types/turn/SessionTurnContext.d.ts.map +1 -0
- package/bin/types/turn/SessionTurnContext.js.map +1 -0
- package/bin/{executor/ids/resolveSessionId.d.ts → utils/ResolveSessionId.d.ts} +1 -1
- package/bin/utils/ResolveSessionId.d.ts.map +1 -0
- package/bin/{executor/ids/resolveSessionId.js → utils/ResolveSessionId.js} +1 -1
- package/bin/utils/ResolveSessionId.js.map +1 -0
- package/bin/utils/Time.d.ts +5 -8
- package/bin/utils/Time.d.ts.map +1 -1
- package/bin/utils/Time.js +5 -54
- package/bin/utils/Time.js.map +1 -1
- package/package.json +2 -2
- package/scripts/ask-question-answers.test.mjs +132 -0
- package/scripts/group-session-archive.test.mjs +193 -0
- package/scripts/{core-engine-model-stream.test.mjs → model-step-runner.test.mjs} +97 -4
- package/scripts/rewrite-build-aliases.mjs +3 -4
- package/scripts/session-action-part.test.mjs +172 -0
- package/scripts/session-agent-message-part-order.test.mjs +13 -7
- package/scripts/{core-engine-context-compaction.test.mjs → session-executor-context-pressure.test.mjs} +40 -32
- package/scripts/{executor-failure-result.test.mjs → session-executor-failure-result.test.mjs} +17 -14
- package/scripts/session-executor-max-steps.test.mjs +143 -0
- package/scripts/session-initialization.test.mjs +3 -4
- package/scripts/session-interaction-migration.test.mjs +145 -0
- package/scripts/session-interaction-mutation.test.mjs +202 -0
- package/scripts/session-messages-error-part.test.mjs +1 -1
- package/scripts/session-messages-error.test.mjs +1 -1
- package/scripts/session-prompt-idempotency.test.mjs +4 -2
- package/scripts/session-queue.test.mjs +21 -1
- package/scripts/session-storage-sqlite.test.mjs +3 -3
- package/scripts/session-system-blocks.test.mjs +61 -39
- package/scripts/session-turn-context.test.mjs +37 -40
- package/scripts/verify-build-aliases.mjs +1 -1
- package/src/agent/Agent.ts +137 -80
- package/src/agent/AgentInstructions.ts +48 -15
- package/src/agent/AgentMemoryStorage.ts +1 -1
- package/src/agent/AgentSessions.ts +60 -38
- package/src/group/Group.ts +27 -24
- package/src/group/GroupSession.ts +12 -8
- package/src/group/GroupSessions.ts +79 -20
- package/src/group/storage/LocalGroupSessionDataStore.ts +9 -1
- package/src/group/storage/LocalGroupSessionStore.ts +138 -28
- package/src/index.ts +35 -52
- package/src/{executor/model → model}/ModelGenerate.ts +3 -3
- package/src/{executor/model → model}/ModelRequestRunner.ts +2 -2
- package/src/{executor/model → model}/ModelStepRunner.ts +22 -19
- package/src/{executor/model → model}/ModelStreamConsumer.ts +1 -1
- package/src/model/README.md +117 -0
- package/src/model/ToolInputValidation.ts +58 -0
- package/src/{executor → model}/messages/ChatMessageMarkupTypes.ts +1 -1
- package/src/{executor → model}/messages/SessionModelMessages.ts +0 -1
- package/src/{executor/composer/system/default → model/prompts}/SystemPromptAssets.ts +1 -1
- package/src/model/prompts/assets/core.prompt.ts +9 -0
- package/src/{executor/composer/system/default → model/prompts}/assets/core.prompt.ts.txt +26 -25
- package/src/session/Session.ts +185 -151
- package/src/session/input/SessionHookRunner.ts +100 -0
- package/src/session/{SessionSystem.ts → input/SessionSystem.ts} +31 -29
- package/src/session/input/StepInput.ts +507 -0
- package/src/session/input/composer/AdaptiveContextCheckpoint.ts +115 -0
- package/src/session/input/composer/AdaptiveContextParts.ts +166 -0
- package/src/session/input/composer/ComposerAssembly.ts +81 -0
- package/src/session/{composer/policies/SessionSummaryPrompts.ts → input/composer/ContextSummaryPrompts.ts} +5 -2
- package/src/session/input/composer/DefaultSessionComposer.ts +147 -0
- package/src/session/input/composer/FullHistorySessionComposer.ts +55 -0
- package/src/session/loop/README.md +28 -0
- package/src/session/{SessionLoop.ts → loop/SessionLoop.ts} +100 -24
- package/src/session/{SessionQueue.ts → loop/SessionQueue.ts} +18 -0
- package/src/session/{SessionState.ts → loop/SessionState.ts} +4 -21
- package/src/session/{SessionTitle.ts → loop/SessionTitle.ts} +3 -3
- package/src/session/{runtime → loop}/SessionTurnCompletion.ts +27 -8
- package/src/session/{runtime → loop}/SessionTurnContext.ts +19 -93
- package/src/session/{runtime → loop}/SessionTurnFileDiff.ts +1 -1
- package/src/session/{messages → loop}/SessionTurnFileDiffBuilder.ts +4 -4
- package/src/session/messages/ApprovalInteraction.ts +77 -0
- package/src/session/messages/README.md +27 -0
- package/src/session/messages/SessionAgentMessageState.ts +324 -113
- package/src/session/messages/SessionAgentMessageWriter.ts +82 -45
- package/src/session/messages/SessionAgentParts.ts +39 -0
- package/src/session/{execution → messages}/SessionAssistantOutputAdapter.ts +2 -2
- package/src/session/messages/SessionInteractions.ts +227 -0
- package/src/session/messages/SessionJsonValue.ts +1 -18
- package/src/session/messages/SessionMessageCache.ts +171 -0
- package/src/session/messages/SessionMessageState.ts +42 -0
- package/src/session/{browse → messages}/SessionMessageTimeline.ts +0 -1
- package/src/session/{SessionMessages.ts → messages/SessionMessages.ts} +225 -284
- package/src/session/messages/SessionMutationFactory.ts +58 -0
- package/src/session/messages/SessionUserMessage.ts +7 -32
- package/src/{executor/core-engine/CoreEngineSignals.ts → session/runner/AssistantParts.ts} +3 -21
- package/src/{executor/core-engine/CoreEngineContextCompaction.ts → session/runner/ContextPressure.ts} +10 -10
- package/src/{executor/services/ExecutorRecoveryPolicy.ts → session/runner/ContextRetry.ts} +25 -25
- package/src/{executor/core-engine/CoreEngineError.ts → session/runner/ModelFailure.ts} +3 -3
- package/src/session/runner/SessionExecutor.ts +633 -0
- package/src/session/runner/ToolLoopDecision.ts +98 -0
- package/src/session/runner/ToolLoopLimits.ts +53 -0
- package/src/session/{browse → storage}/Browse.ts +2 -2
- package/src/session/storage/LocalSessionStore.ts +1 -1
- package/src/session/storage/LocalStorePaths.ts +1 -1
- package/src/session/storage/Metadata.ts +1 -44
- package/src/session/storage/RuntimeSessionPort.ts +0 -5
- package/src/session/{preview → storage}/SessionMessagePreview.ts +0 -1
- package/src/session/storage/SessionStorageCodec.ts +54 -28
- package/src/session/storage/SessionStorageSchema.ts +1 -1
- package/src/session/storage/SqliteSessionStorage.ts +29 -22
- package/src/tools/ask/AskQuestionAnswers.ts +125 -0
- package/src/tools/ask/AskQuestionsTool.ts +32 -37
- package/src/types/agent/AgentOptions.ts +17 -8
- package/src/types/agent/AgentSessionCollection.ts +9 -0
- package/src/types/agent/SessionActor.ts +3 -4
- package/src/types/group/DispatchStrategy.ts +1 -1
- package/src/types/group/GroupSession.ts +44 -1
- package/src/types/group/GroupSessionStore.ts +30 -3
- package/src/types/sdk/AgentSessionAction.ts +1 -14
- package/src/types/session/{AdaptivePartContextPolicy.ts → ContextCheckpoint.ts} +9 -8
- package/src/types/session/SessionAgentMessageState.ts +6 -16
- package/src/types/session/SessionComposer.ts +67 -39
- package/src/types/session/SessionExecution.ts +15 -13
- package/src/types/session/SessionInteractions.ts +0 -2
- package/src/types/session/SessionLocalState.ts +0 -5
- package/src/types/session/SessionLoop.ts +37 -12
- package/src/types/session/SessionMessages.ts +3 -34
- package/src/types/session/SessionOptions.ts +18 -13
- package/src/types/session/SessionPort.ts +0 -4
- package/src/types/session/SessionState.ts +0 -1
- package/src/types/session/SessionSystem.ts +10 -16
- package/src/types/session/SessionTool.ts +2 -2
- package/src/types/session/SessionTurnCompletion.ts +12 -2
- package/src/types/session/SessionTurnFileDiff.ts +4 -4
- package/src/types/session/{SessionComposition.ts → StepInput.ts} +22 -14
- package/src/types/store/SessionStorage.ts +17 -12
- package/src/types/tool/BoundAgentTool.ts +38 -0
- package/src/types/tools/ask/AskQuestionsTool.ts +11 -13
- package/src/types/{executor → turn}/SessionTurnContext.ts +8 -34
- package/src/utils/Time.ts +12 -64
- package/tsconfig.json +1 -2
- package/tsconfig.tsbuildinfo +1 -1
- package/bin/executor/Executor.d.ts +0 -92
- package/bin/executor/Executor.d.ts.map +0 -1
- package/bin/executor/Executor.js +0 -232
- package/bin/executor/Executor.js.map +0 -1
- package/bin/executor/composer/system/default/SystemPromptAssets.d.ts.map +0 -1
- package/bin/executor/composer/system/default/SystemPromptAssets.js.map +0 -1
- package/bin/executor/composer/system/default/assets/core.prompt.d.ts +0 -7
- package/bin/executor/composer/system/default/assets/core.prompt.d.ts.map +0 -1
- package/bin/executor/composer/system/default/assets/core.prompt.js +0 -8
- package/bin/executor/composer/system/default/assets/core.prompt.js.map +0 -1
- package/bin/executor/core-engine/CoreEngineContextCompaction.d.ts +0 -15
- package/bin/executor/core-engine/CoreEngineContextCompaction.d.ts.map +0 -1
- package/bin/executor/core-engine/CoreEngineContextCompaction.js.map +0 -1
- package/bin/executor/core-engine/CoreEngineError.d.ts.map +0 -1
- package/bin/executor/core-engine/CoreEngineError.js.map +0 -1
- package/bin/executor/core-engine/CoreEngineLoopDecision.d.ts +0 -26
- package/bin/executor/core-engine/CoreEngineLoopDecision.d.ts.map +0 -1
- package/bin/executor/core-engine/CoreEngineLoopDecision.js.map +0 -1
- package/bin/executor/core-engine/CoreEngineRunner.d.ts +0 -48
- package/bin/executor/core-engine/CoreEngineRunner.d.ts.map +0 -1
- package/bin/executor/core-engine/CoreEngineRunner.js +0 -343
- package/bin/executor/core-engine/CoreEngineRunner.js.map +0 -1
- package/bin/executor/core-engine/CoreEngineSignals.d.ts.map +0 -1
- package/bin/executor/core-engine/CoreEngineSignals.js.map +0 -1
- package/bin/executor/ids/resolveSessionId.d.ts.map +0 -1
- package/bin/executor/ids/resolveSessionId.js.map +0 -1
- package/bin/executor/messages/ChatMessageMarkup.d.ts.map +0 -1
- package/bin/executor/messages/ChatMessageMarkup.js.map +0 -1
- package/bin/executor/messages/ChatMessageMarkupTypes.d.ts.map +0 -1
- package/bin/executor/messages/ChatMessageMarkupTypes.js.map +0 -1
- package/bin/executor/messages/SessionAttachmentMapper.d.ts.map +0 -1
- package/bin/executor/messages/SessionAttachmentMapper.js.map +0 -1
- package/bin/executor/messages/SessionMessageLog.d.ts.map +0 -1
- package/bin/executor/messages/SessionMessageLog.js.map +0 -1
- package/bin/executor/messages/SessionModelMessages.d.ts.map +0 -1
- package/bin/executor/messages/SessionModelMessages.js.map +0 -1
- package/bin/executor/model/ModelGenerate.d.ts.map +0 -1
- package/bin/executor/model/ModelGenerate.js.map +0 -1
- package/bin/executor/model/ModelRequestRunner.d.ts.map +0 -1
- package/bin/executor/model/ModelRequestRunner.js.map +0 -1
- package/bin/executor/model/ModelStepRunner.d.ts.map +0 -1
- package/bin/executor/model/ModelStepRunner.js.map +0 -1
- package/bin/executor/model/ModelStreamConsumer.d.ts.map +0 -1
- package/bin/executor/model/ModelStreamConsumer.js.map +0 -1
- package/bin/executor/model/ModelStreamFailure.d.ts.map +0 -1
- package/bin/executor/model/ModelStreamFailure.js.map +0 -1
- package/bin/executor/services/ExecutorRecoveryPolicy.d.ts +0 -39
- package/bin/executor/services/ExecutorRecoveryPolicy.d.ts.map +0 -1
- package/bin/executor/services/ExecutorRecoveryPolicy.js.map +0 -1
- package/bin/executor/types/SessionHistoryMeta.d.ts.map +0 -1
- package/bin/executor/types/SessionHistoryMeta.js.map +0 -1
- package/bin/executor/types/SessionLoop.d.ts +0 -59
- package/bin/executor/types/SessionLoop.d.ts.map +0 -1
- package/bin/executor/types/SessionLoop.js +0 -9
- package/bin/executor/types/SessionLoop.js.map +0 -1
- package/bin/executor/types/SessionPrompts.d.ts +0 -14
- package/bin/executor/types/SessionPrompts.d.ts.map +0 -1
- package/bin/executor/types/SessionPrompts.js +0 -8
- package/bin/executor/types/SessionPrompts.js.map +0 -1
- package/bin/session/DefaultSessionComposer.d.ts +0 -24
- package/bin/session/DefaultSessionComposer.d.ts.map +0 -1
- package/bin/session/DefaultSessionComposer.js +0 -99
- package/bin/session/DefaultSessionComposer.js.map +0 -1
- package/bin/session/SessionComposition.d.ts +0 -49
- package/bin/session/SessionComposition.d.ts.map +0 -1
- package/bin/session/SessionComposition.js +0 -309
- package/bin/session/SessionComposition.js.map +0 -1
- package/bin/session/SessionHookPoints.d.ts +0 -15
- package/bin/session/SessionHookPoints.d.ts.map +0 -1
- package/bin/session/SessionHookPoints.js +0 -15
- package/bin/session/SessionHookPoints.js.map +0 -1
- package/bin/session/SessionHooks.d.ts +0 -38
- package/bin/session/SessionHooks.d.ts.map +0 -1
- package/bin/session/SessionHooks.js +0 -71
- package/bin/session/SessionHooks.js.map +0 -1
- package/bin/session/SessionLoop.d.ts.map +0 -1
- package/bin/session/SessionLoop.js.map +0 -1
- package/bin/session/SessionMessages.d.ts.map +0 -1
- package/bin/session/SessionMessages.js.map +0 -1
- package/bin/session/SessionQueue.d.ts.map +0 -1
- package/bin/session/SessionQueue.js.map +0 -1
- package/bin/session/SessionState.d.ts.map +0 -1
- package/bin/session/SessionState.js.map +0 -1
- package/bin/session/SessionSystem.d.ts +0 -19
- package/bin/session/SessionSystem.d.ts.map +0 -1
- package/bin/session/SessionSystem.js.map +0 -1
- package/bin/session/SessionTitle.d.ts.map +0 -1
- package/bin/session/SessionTitle.js.map +0 -1
- package/bin/session/browse/Browse.d.ts.map +0 -1
- package/bin/session/browse/Browse.js.map +0 -1
- package/bin/session/browse/SessionMessageTimeline.d.ts.map +0 -1
- package/bin/session/browse/SessionMessageTimeline.js.map +0 -1
- package/bin/session/composer/policies/AdaptivePartContextPolicy.d.ts +0 -35
- package/bin/session/composer/policies/AdaptivePartContextPolicy.d.ts.map +0 -1
- package/bin/session/composer/policies/AdaptivePartContextPolicy.js +0 -256
- package/bin/session/composer/policies/AdaptivePartContextPolicy.js.map +0 -1
- package/bin/session/composer/policies/FullHistoryContextPolicy.d.ts +0 -24
- package/bin/session/composer/policies/FullHistoryContextPolicy.d.ts.map +0 -1
- package/bin/session/composer/policies/FullHistoryContextPolicy.js +0 -31
- package/bin/session/composer/policies/FullHistoryContextPolicy.js.map +0 -1
- package/bin/session/composer/policies/SessionSummaryPrompts.d.ts.map +0 -1
- package/bin/session/composer/policies/SessionSummaryPrompts.js.map +0 -1
- package/bin/session/control/SessionInteractions.d.ts +0 -39
- package/bin/session/control/SessionInteractions.d.ts.map +0 -1
- package/bin/session/control/SessionInteractions.js +0 -255
- package/bin/session/control/SessionInteractions.js.map +0 -1
- package/bin/session/execution/SessionAssistantOutputAdapter.d.ts.map +0 -1
- package/bin/session/execution/SessionAssistantOutputAdapter.js.map +0 -1
- package/bin/session/execution/tools/SessionShellApprovalAdapter.d.ts +0 -28
- package/bin/session/execution/tools/SessionShellApprovalAdapter.d.ts.map +0 -1
- package/bin/session/execution/tools/SessionShellApprovalAdapter.js +0 -87
- package/bin/session/execution/tools/SessionShellApprovalAdapter.js.map +0 -1
- package/bin/session/messages/SessionAgentActionPartWriter.d.ts +0 -22
- package/bin/session/messages/SessionAgentActionPartWriter.d.ts.map +0 -1
- package/bin/session/messages/SessionAgentActionPartWriter.js +0 -36
- package/bin/session/messages/SessionAgentActionPartWriter.js.map +0 -1
- package/bin/session/messages/SessionMessageInteractionWriter.d.ts +0 -46
- package/bin/session/messages/SessionMessageInteractionWriter.d.ts.map +0 -1
- package/bin/session/messages/SessionMessageInteractionWriter.js +0 -183
- package/bin/session/messages/SessionMessageInteractionWriter.js.map +0 -1
- package/bin/session/messages/SessionTurnFileDiffBuilder.d.ts.map +0 -1
- package/bin/session/messages/SessionTurnFileDiffBuilder.js.map +0 -1
- package/bin/session/runtime/SessionEventHub.d.ts.map +0 -1
- package/bin/session/runtime/SessionEventHub.js.map +0 -1
- package/bin/session/runtime/SessionModelRequestWarning.d.ts.map +0 -1
- package/bin/session/runtime/SessionModelRequestWarning.js.map +0 -1
- package/bin/session/runtime/SessionTitleTask.d.ts.map +0 -1
- package/bin/session/runtime/SessionTitleTask.js.map +0 -1
- package/bin/session/runtime/SessionTurnCompletion.d.ts.map +0 -1
- package/bin/session/runtime/SessionTurnCompletion.js.map +0 -1
- package/bin/session/runtime/SessionTurnContext.d.ts +0 -29
- package/bin/session/runtime/SessionTurnContext.d.ts.map +0 -1
- package/bin/session/runtime/SessionTurnContext.js.map +0 -1
- package/bin/session/runtime/SessionTurnFileDiff.d.ts.map +0 -1
- package/bin/session/runtime/SessionTurnFileDiff.js.map +0 -1
- package/bin/types/action/ActionResult.d.ts +0 -35
- package/bin/types/action/ActionResult.d.ts.map +0 -1
- package/bin/types/action/ActionResult.js +0 -18
- package/bin/types/action/ActionResult.js.map +0 -1
- package/bin/types/executor/ModelRequest.d.ts.map +0 -1
- package/bin/types/executor/ModelRequest.js.map +0 -1
- package/bin/types/executor/SessionAssistantOutput.d.ts.map +0 -1
- package/bin/types/executor/SessionAssistantOutput.js.map +0 -1
- package/bin/types/executor/SessionToolExecutionContext.d.ts +0 -23
- package/bin/types/executor/SessionToolExecutionContext.d.ts.map +0 -1
- package/bin/types/executor/SessionToolExecutionContext.js +0 -10
- package/bin/types/executor/SessionToolExecutionContext.js.map +0 -1
- package/bin/types/executor/SessionTurnContext.d.ts.map +0 -1
- package/bin/types/executor/SessionTurnContext.js.map +0 -1
- package/bin/types/session/AdaptivePartContextPolicy.d.ts.map +0 -1
- package/bin/types/session/AdaptivePartContextPolicy.js +0 -7
- package/bin/types/session/AdaptivePartContextPolicy.js.map +0 -1
- package/bin/types/session/SessionComposition.d.ts.map +0 -1
- package/bin/types/session/SessionComposition.js +0 -8
- package/bin/types/session/SessionComposition.js.map +0 -1
- package/bin/types/session/SessionContextPolicy.d.ts +0 -70
- package/bin/types/session/SessionContextPolicy.d.ts.map +0 -1
- package/bin/types/session/SessionContextPolicy.js +0 -8
- package/bin/types/session/SessionContextPolicy.js.map +0 -1
- package/bin/types/tools/ToolActionExecutionContext.d.ts +0 -30
- package/bin/types/tools/ToolActionExecutionContext.d.ts.map +0 -1
- package/bin/types/tools/ToolActionExecutionContext.js +0 -8
- package/bin/types/tools/ToolActionExecutionContext.js.map +0 -1
- package/src/executor/Executor.ts +0 -319
- package/src/executor/README.md +0 -92
- package/src/executor/composer/system/default/assets/core.prompt.ts +0 -9
- package/src/executor/core-engine/CoreEngineLoopDecision.ts +0 -63
- package/src/executor/core-engine/CoreEngineRunner.ts +0 -458
- package/src/executor/types/SessionLoop.ts +0 -69
- package/src/executor/types/SessionPrompts.ts +0 -14
- package/src/session/DefaultSessionComposer.ts +0 -123
- package/src/session/SessionComposition.ts +0 -370
- package/src/session/SessionHookPoints.ts +0 -17
- package/src/session/SessionHooks.ts +0 -85
- package/src/session/composer/policies/AdaptivePartContextPolicy.ts +0 -307
- package/src/session/composer/policies/FullHistoryContextPolicy.ts +0 -36
- package/src/session/control/SessionInteractions.ts +0 -311
- package/src/session/execution/tools/SessionShellApprovalAdapter.ts +0 -105
- package/src/session/messages/SessionAgentActionPartWriter.ts +0 -54
- package/src/session/messages/SessionMessageInteractionWriter.ts +0 -279
- package/src/types/action/ActionResult.ts +0 -50
- package/src/types/executor/SessionToolExecutionContext.ts +0 -26
- package/src/types/session/SessionContextPolicy.ts +0 -77
- package/src/types/tools/ToolActionExecutionContext.ts +0 -32
- /package/bin/{executor/model → model}/ModelGenerate.js +0 -0
- /package/bin/{executor/model → model}/ModelRequestRunner.js +0 -0
- /package/bin/{executor/model → model}/ModelStreamConsumer.d.ts +0 -0
- /package/bin/{executor/model → model}/ModelStreamConsumer.js +0 -0
- /package/bin/{executor/model → model}/ModelStreamFailure.d.ts +0 -0
- /package/bin/{executor/model → model}/ModelStreamFailure.js +0 -0
- /package/bin/{executor → model}/messages/ChatMessageMarkup.d.ts +0 -0
- /package/bin/{executor → model}/messages/ChatMessageMarkup.js +0 -0
- /package/bin/{executor → model}/messages/SessionAttachmentMapper.d.ts +0 -0
- /package/bin/{executor → model}/messages/SessionAttachmentMapper.js +0 -0
- /package/bin/{executor → model}/messages/SessionMessageLog.d.ts +0 -0
- /package/bin/{executor → model}/messages/SessionMessageLog.js +0 -0
- /package/bin/{executor → model}/messages/SessionModelMessages.d.ts +0 -0
- /package/bin/{executor/composer/system/default → model/prompts}/SystemPromptAssets.d.ts +0 -0
- /package/bin/session/{runtime → loop}/SessionTitleTask.d.ts +0 -0
- /package/bin/session/{runtime → loop}/SessionTitleTask.js +0 -0
- /package/bin/session/{runtime → loop}/SessionTurnFileDiff.d.ts +0 -0
- /package/bin/session/{messages → loop}/SessionTurnFileDiffBuilder.js +0 -0
- /package/bin/session/{execution → messages}/SessionAssistantOutputAdapter.js +0 -0
- /package/bin/session/{runtime → messages}/SessionEventHub.d.ts +0 -0
- /package/bin/session/{runtime → messages}/SessionEventHub.js +0 -0
- /package/bin/session/{browse → messages}/SessionMessageTimeline.d.ts +0 -0
- /package/bin/session/{runtime → messages}/SessionModelRequestWarning.d.ts +0 -0
- /package/bin/session/{runtime → messages}/SessionModelRequestWarning.js +0 -0
- /package/bin/session/{preview → storage}/SessionMessagePreview.d.ts +0 -0
- /package/bin/types/{executor → model}/ModelRequest.d.ts +0 -0
- /package/bin/types/{executor → model}/ModelRequest.js +0 -0
- /package/bin/{executor/types → types/store}/SessionHistoryMeta.d.ts +0 -0
- /package/bin/{executor/types → types/store}/SessionHistoryMeta.js +0 -0
- /package/bin/types/{executor → turn}/SessionAssistantOutput.d.ts +0 -0
- /package/bin/types/{executor → turn}/SessionAssistantOutput.js +0 -0
- /package/bin/types/{executor → turn}/SessionTurnContext.js +0 -0
- /package/src/{executor/model → model}/ModelStreamFailure.ts +0 -0
- /package/src/{executor → model}/messages/ChatMessageMarkup.ts +0 -0
- /package/src/{executor → model}/messages/SessionAttachmentMapper.ts +0 -0
- /package/src/{executor → model}/messages/SessionMessageLog.ts +0 -0
- /package/src/session/{runtime → loop}/SessionTitleTask.ts +0 -0
- /package/src/session/{runtime → messages}/SessionEventHub.ts +0 -0
- /package/src/session/{runtime → messages}/SessionModelRequestWarning.ts +0 -0
- /package/src/types/{executor → model}/ModelRequest.ts +0 -0
- /package/src/{executor/types → types/store}/SessionHistoryMeta.ts +0 -0
- /package/src/types/{executor → turn}/SessionAssistantOutput.ts +0 -0
- /package/src/{executor/ids/resolveSessionId.ts → utils/ResolveSessionId.ts} +0 -0
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ToolLoopDecision:工具循环的“是否继续下一轮”纯决策。
|
|
3
|
+
*
|
|
4
|
+
* 关键点(中文)
|
|
5
|
+
* - 把继续/停止的分支优先级从执行器主流程中拆出。
|
|
6
|
+
* - 保持纯函数,不依赖模型、持久化或 logger,便于直接测试。
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* 单轮 loop 决策输入。
|
|
11
|
+
*/
|
|
12
|
+
export interface ToolLoopDecisionInput {
|
|
13
|
+
/** 当前 step 是否检测到了不完整响应。 */
|
|
14
|
+
hasIncompleteResponse: boolean;
|
|
15
|
+
/** 当前已经执行过多少次不完整响应恢复。 */
|
|
16
|
+
incompleteRecoveryCount: number;
|
|
17
|
+
/** 允许执行的不完整响应恢复上限。 */
|
|
18
|
+
maxIncompleteRecoveries: number;
|
|
19
|
+
/** 当前 step 实际产出的工具调用数量。 */
|
|
20
|
+
toolCallCount: number;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* 单轮 loop 决策结果。
|
|
25
|
+
*/
|
|
26
|
+
export interface ToolLoopDecision {
|
|
27
|
+
/** 本轮命中的主决策类型。 */
|
|
28
|
+
kind:
|
|
29
|
+
| "recover_incomplete"
|
|
30
|
+
| "continue_for_tool_calls"
|
|
31
|
+
| "stop";
|
|
32
|
+
/** 是否因为工具调用而继续下一轮。 */
|
|
33
|
+
continueForToolCalls: boolean;
|
|
34
|
+
/** 是否因为不完整响应恢复而继续下一轮。 */
|
|
35
|
+
continueForIncompleteRecovery: boolean;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* stop 分支上的尾部消息续跑判定输入。
|
|
40
|
+
*
|
|
41
|
+
* 关键点(中文)
|
|
42
|
+
* - 用于处理“最后一个 step 结束后,恰好又有新的 user 消息写入”的窗口。
|
|
43
|
+
* - 这里只关心是否真的合并到了新增 user message,不关心消息内容细节。
|
|
44
|
+
*/
|
|
45
|
+
export interface TailMergeContinuationInput {
|
|
46
|
+
/** stop 前最后一次 tail merge 实际合并到的 user message 数量。 */
|
|
47
|
+
mergedUserMessageCount: number;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* 评估当前 step 完成后,tool-loop 是否应继续下一轮。
|
|
52
|
+
*
|
|
53
|
+
* 优先级(中文)
|
|
54
|
+
* 1. 不完整响应恢复
|
|
55
|
+
* 2. 已发生的工具调用
|
|
56
|
+
* 3. 停止
|
|
57
|
+
*/
|
|
58
|
+
export function decide_tool_loop(
|
|
59
|
+
input: ToolLoopDecisionInput,
|
|
60
|
+
): ToolLoopDecision {
|
|
61
|
+
if (
|
|
62
|
+
input.hasIncompleteResponse &&
|
|
63
|
+
input.incompleteRecoveryCount < input.maxIncompleteRecoveries
|
|
64
|
+
) {
|
|
65
|
+
return {
|
|
66
|
+
kind: "recover_incomplete",
|
|
67
|
+
continueForToolCalls: false,
|
|
68
|
+
continueForIncompleteRecovery: true,
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
if (input.toolCallCount > 0) {
|
|
73
|
+
return {
|
|
74
|
+
kind: "continue_for_tool_calls",
|
|
75
|
+
continueForToolCalls: true,
|
|
76
|
+
continueForIncompleteRecovery: false,
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
return {
|
|
81
|
+
kind: "stop",
|
|
82
|
+
continueForToolCalls: false,
|
|
83
|
+
continueForIncompleteRecovery: false,
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* 评估 stop 前的尾部合并是否应该继续下一轮。
|
|
89
|
+
*
|
|
90
|
+
* 关键点(中文)
|
|
91
|
+
* - 只要最后一次 tail merge 真正并入了新的 user 消息,就必须续跑。
|
|
92
|
+
* - 这样可以覆盖“最后一个 step 结束后,新消息才到达”的收尾窗口。
|
|
93
|
+
*/
|
|
94
|
+
export function should_continue_after_tail_merge(
|
|
95
|
+
input: TailMergeContinuationInput,
|
|
96
|
+
): boolean {
|
|
97
|
+
return input.mergedUserMessageCount > 0;
|
|
98
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ToolLoopLimits:工具循环的边界与边界提示。
|
|
3
|
+
*
|
|
4
|
+
* 关键点(中文):这里只描述「循环能跑多久」以及撞到边界时对模型说什么,
|
|
5
|
+
* 不参与循环决策本身。
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* 单次 Tool Loop 允许的最大 Step 数。
|
|
10
|
+
*
|
|
11
|
+
* 关键点(中文)
|
|
12
|
+
* - Step 计的是模型往返次数,不是工具调用次数;一次 shell 调用就会消耗一个 Step。
|
|
13
|
+
* - 该上限只用于防止跑飞,正常运行不应触达;旧值 64 很容易被稍长的排查任务撞顶。
|
|
14
|
+
* - 撞顶不再静默成功:先强制执行一次收尾 Step,收尾仍无正文时才按明确错误结束。
|
|
15
|
+
*/
|
|
16
|
+
export const MAX_TOOL_LOOP_STEPS = 1000;
|
|
17
|
+
|
|
18
|
+
/** Tool Loop 撞顶且收尾失败时写入 canonical Error Part 的稳定错误码。 */
|
|
19
|
+
export const TOOL_LOOP_MAX_STEPS_ERROR_CODE = "tool_loop_max_steps";
|
|
20
|
+
|
|
21
|
+
/** 不完整响应自动恢复的最大次数。 */
|
|
22
|
+
export const MAX_INCOMPLETE_RESPONSE_RECOVERIES = 1;
|
|
23
|
+
|
|
24
|
+
/** 构造不完整响应恢复提示。 */
|
|
25
|
+
export function build_incomplete_response_recovery_nudge(
|
|
26
|
+
recovery_index: number,
|
|
27
|
+
): string {
|
|
28
|
+
const round = Math.max(1, recovery_index);
|
|
29
|
+
return [
|
|
30
|
+
`系统恢复提醒(第 ${round} 次):上一轮响应在流式阶段异常中断。`,
|
|
31
|
+
"不要复述已完成内容。",
|
|
32
|
+
"请从中断处继续;如果需要工具,请重新发起完整工具调用。",
|
|
33
|
+
"只有在答案完整结束、任务真正完成、或明确受阻时才停止。",
|
|
34
|
+
].join("\n");
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* 构造工具循环撞顶后的收尾提示。
|
|
39
|
+
*
|
|
40
|
+
* 关键点(中文):这里只描述收尾要求,不解释工具循环机制,避免模型继续尝试调用工具。
|
|
41
|
+
*/
|
|
42
|
+
export function build_max_steps_finalization_nudge(step_limit: number): string {
|
|
43
|
+
return [
|
|
44
|
+
`系统收尾提醒:本轮已经连续执行 ${step_limit} 个模型 Step,达到工具循环上限。`,
|
|
45
|
+
"现在不允许再调用任何工具。",
|
|
46
|
+
"请基于已经完成的工具结果直接给出结论;若任务尚未完成,请明确说明已完成部分、当前受阻原因和下一步建议。",
|
|
47
|
+
].join("\n");
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/** 构造工具循环撞顶收尾失败时的用户可见错误文本。 */
|
|
51
|
+
export function build_max_steps_error_text(step_limit: number): string {
|
|
52
|
+
return `Agent reached the tool loop limit of ${step_limit} steps without producing a final answer.`;
|
|
53
|
+
}
|
|
@@ -12,8 +12,8 @@ import type {
|
|
|
12
12
|
AgentSessionSummary,
|
|
13
13
|
AgentSessionSummaryPage,
|
|
14
14
|
} from "@/types/agent/SessionTypes.js";
|
|
15
|
-
import type { SessionHistoryMeta } from "@/
|
|
16
|
-
import { resolve_session_message_preview } from "@/session/
|
|
15
|
+
import type { SessionHistoryMeta } from "@/types/store/SessionHistoryMeta.js";
|
|
16
|
+
import { resolve_session_message_preview } from "@/session/storage/SessionMessagePreview.js";
|
|
17
17
|
import {
|
|
18
18
|
get_agent_archived_session_database_path,
|
|
19
19
|
get_agent_archived_sessions_path,
|
|
@@ -33,7 +33,7 @@ import {
|
|
|
33
33
|
list_archived_agent_session_summary_page,
|
|
34
34
|
list_agent_session_summary_page,
|
|
35
35
|
read_session_metadata_from_database,
|
|
36
|
-
} from "@/session/
|
|
36
|
+
} from "@/session/storage/Browse.js";
|
|
37
37
|
import type { FileSystem } from "@downcity/type";
|
|
38
38
|
import type { LocalSessionStoreOptions } from "@/types/store/LocalStore.js";
|
|
39
39
|
import type { SessionOrigin } from "@downcity/type";
|
|
@@ -37,7 +37,7 @@ function encode_origin_type(origin_type: string): string {
|
|
|
37
37
|
}
|
|
38
38
|
|
|
39
39
|
/** 返回全部活动 Session 来源分区的根目录。 */
|
|
40
|
-
|
|
40
|
+
function get_agent_session_origins_path(storage_root_path: string): string {
|
|
41
41
|
return path.join(path.resolve(storage_root_path), "sessions");
|
|
42
42
|
}
|
|
43
43
|
|
|
@@ -6,9 +6,8 @@
|
|
|
6
6
|
* - 不负责数据库连接、消息聚合或附件读写。
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
import type { SessionHistoryMeta } from "@/
|
|
9
|
+
import type { SessionHistoryMeta } from "@/types/store/SessionHistoryMeta.js";
|
|
10
10
|
import type { SessionOrigin } from "@downcity/type";
|
|
11
|
-
import type { FileSystem } from "@downcity/type";
|
|
12
11
|
import { restore_session_origin } from "@downcity/type";
|
|
13
12
|
|
|
14
13
|
function normalizeModelLabel(input: unknown): string | undefined {
|
|
@@ -57,48 +56,6 @@ function normalize_preview_text(input: unknown): string | undefined {
|
|
|
57
56
|
return preview_text || undefined;
|
|
58
57
|
}
|
|
59
58
|
|
|
60
|
-
/**
|
|
61
|
-
* 从指定路径读取旧版 Session metadata。
|
|
62
|
-
*
|
|
63
|
-
* 关键点(中文)
|
|
64
|
-
* - 供归档 session 等需要脱离默认 `sessions/` 目录的场景复用。
|
|
65
|
-
* - 路径本身不做校验,调用方需保证可访问。
|
|
66
|
-
*/
|
|
67
|
-
export async function read_session_metadata_from_path(input: {
|
|
68
|
-
/** 旧版 metadata 文件路径。 */
|
|
69
|
-
filePath: string;
|
|
70
|
-
/** 当前 session_id。 */
|
|
71
|
-
session_id: string;
|
|
72
|
-
/** 当前 agent_id。 */
|
|
73
|
-
agent_id: string;
|
|
74
|
-
/** 当前查询上下文的 workspace_id;存在时必须与 metadata 严格匹配。 */
|
|
75
|
-
workspace_id?: string;
|
|
76
|
-
/** 当前读取目录对应的来源类型。 */
|
|
77
|
-
origin_type: string;
|
|
78
|
-
/** 当前 Agent 私有 Storage 的文件能力。 */
|
|
79
|
-
files: FileSystem;
|
|
80
|
-
}): Promise<SessionHistoryMeta> {
|
|
81
|
-
const raw = JSON.parse(
|
|
82
|
-
(await input.files.read_file(input.filePath)).toString("utf8"),
|
|
83
|
-
) as Partial<SessionHistoryMeta>;
|
|
84
|
-
if (
|
|
85
|
-
raw.session_id !== input.session_id ||
|
|
86
|
-
raw.agent_id !== input.agent_id
|
|
87
|
-
) {
|
|
88
|
-
throw new Error(`Invalid Session ownership metadata: ${input.session_id}`);
|
|
89
|
-
}
|
|
90
|
-
if (input.workspace_id && raw.workspace_id !== input.workspace_id) {
|
|
91
|
-
throw new Error(`Invalid Session Workspace metadata: ${input.session_id}`);
|
|
92
|
-
}
|
|
93
|
-
return normalize_session_metadata(
|
|
94
|
-
raw,
|
|
95
|
-
input.session_id,
|
|
96
|
-
input.agent_id,
|
|
97
|
-
restore_session_origin(raw.origin, input.origin_type),
|
|
98
|
-
raw.workspace_id,
|
|
99
|
-
);
|
|
100
|
-
}
|
|
101
|
-
|
|
102
59
|
/** 将未知 Metadata 内容规范化为当前 Session 的稳定结构。 */
|
|
103
60
|
export function normalize_session_metadata(
|
|
104
61
|
raw: Partial<SessionHistoryMeta>,
|
|
@@ -25,10 +25,6 @@ export interface CreateRuntimeSessionPortParams {
|
|
|
25
25
|
session_id: string;
|
|
26
26
|
/** 获取当前 Session 优先解析后的运行时模型实例。 */
|
|
27
27
|
get_model: SessionPort["get_model"];
|
|
28
|
-
/**
|
|
29
|
-
* 读取当前 session 底层执行端口。
|
|
30
|
-
*/
|
|
31
|
-
get_executor: SessionPort["get_executor"];
|
|
32
28
|
/** 读取全部 canonical Session Message。 */
|
|
33
29
|
messages: SessionPort["messages"];
|
|
34
30
|
/**
|
|
@@ -72,7 +68,6 @@ export function create_runtime_session_port(
|
|
|
72
68
|
return {
|
|
73
69
|
session_id: params.session_id,
|
|
74
70
|
get_model: () => params.get_model(),
|
|
75
|
-
get_executor: () => params.get_executor(),
|
|
76
71
|
messages: async () => await params.messages(),
|
|
77
72
|
prompt: async (input) => {
|
|
78
73
|
await params.ensure_ready_for_execution();
|
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
import type {
|
|
8
8
|
JsonObject,
|
|
9
9
|
JsonValue,
|
|
10
|
+
SessionAgentInteraction,
|
|
10
11
|
SessionAgentMessagePart,
|
|
11
12
|
SessionInteractionRequest,
|
|
12
13
|
SessionInteractionResponse,
|
|
@@ -158,6 +159,15 @@ function decode_session_part(
|
|
|
158
159
|
role: SessionMessageRow["role"],
|
|
159
160
|
): SessionUserMessagePart | SessionAgentMessagePart {
|
|
160
161
|
const content = parse_part_content(row);
|
|
162
|
+
// 旧数据可能仍存有已废弃的独立 Interaction Part;类型层已不含该值,按原始字符串拦截。
|
|
163
|
+
// 归属取自旧行的 request.source.tool_call_id,所以修复路径是确定的一次性迁移,而不是丢弃数据。
|
|
164
|
+
if ((row.type as string) === "interaction") {
|
|
165
|
+
throw invalid_part(
|
|
166
|
+
row,
|
|
167
|
+
"legacy standalone Interaction Part requires migration into its Tool Part; "
|
|
168
|
+
+ "run `node scripts/migrate-session-interaction-into-tool.mjs` once from the repository root",
|
|
169
|
+
);
|
|
170
|
+
}
|
|
161
171
|
const identity = {
|
|
162
172
|
part_id: row.part_id,
|
|
163
173
|
sequence: row.sequence,
|
|
@@ -217,34 +227,9 @@ function decode_session_part(
|
|
|
217
227
|
...optional_json(content, "output"),
|
|
218
228
|
...optional_string(content, "error", row),
|
|
219
229
|
...optional_string(content, "title", row),
|
|
220
|
-
|
|
221
|
-
case "interaction":
|
|
222
|
-
return {
|
|
223
|
-
...identity,
|
|
224
|
-
type: "interaction",
|
|
225
|
-
interaction_id: read_string(content, "interaction_id", row),
|
|
226
|
-
interaction_type: read_string(content, "interaction_type", row),
|
|
227
|
-
status: read_enum(
|
|
228
|
-
content,
|
|
229
|
-
"status",
|
|
230
|
-
["pending", "resolved", "denied", "expired", "cancelled", "failed"],
|
|
231
|
-
row,
|
|
232
|
-
),
|
|
233
|
-
request: decode_interaction_request(content.request, row),
|
|
234
|
-
...(content.response === undefined
|
|
230
|
+
...(content.interactions === undefined
|
|
235
231
|
? {}
|
|
236
|
-
: {
|
|
237
|
-
...optional_number(content, "resolved_at", row),
|
|
238
|
-
...(content.cancel_reason === undefined
|
|
239
|
-
? {}
|
|
240
|
-
: {
|
|
241
|
-
cancel_reason: read_enum(
|
|
242
|
-
content,
|
|
243
|
-
"cancel_reason",
|
|
244
|
-
["turn_stopped", "session_disposed", "runtime_interrupted"],
|
|
245
|
-
row,
|
|
246
|
-
),
|
|
247
|
-
}),
|
|
232
|
+
: { interactions: decode_tool_interactions(content.interactions, row) }),
|
|
248
233
|
};
|
|
249
234
|
case "file":
|
|
250
235
|
return {
|
|
@@ -415,6 +400,46 @@ function read_json_object(
|
|
|
415
400
|
return value as JsonObject;
|
|
416
401
|
}
|
|
417
402
|
|
|
403
|
+
/** 校验并读取 Tool Part 内持久化的 Interaction 列表。 */
|
|
404
|
+
function decode_tool_interactions(
|
|
405
|
+
value: unknown,
|
|
406
|
+
row: SessionMessagePartRow,
|
|
407
|
+
): SessionAgentInteraction[] {
|
|
408
|
+
if (!Array.isArray(value)) {
|
|
409
|
+
throw invalid_part(row, "interactions must be a JSON array");
|
|
410
|
+
}
|
|
411
|
+
return value.map((item) => {
|
|
412
|
+
if (!item || typeof item !== "object" || Array.isArray(item)) {
|
|
413
|
+
throw invalid_part(row, "interaction must be a JSON object");
|
|
414
|
+
}
|
|
415
|
+
const interaction = item as Record<string, unknown>;
|
|
416
|
+
read_string(interaction, "interaction_id", row);
|
|
417
|
+
read_string(interaction, "interaction_type", row);
|
|
418
|
+
read_enum(
|
|
419
|
+
interaction,
|
|
420
|
+
"status",
|
|
421
|
+
["pending", "resolved", "denied", "cancelled", "failed"],
|
|
422
|
+
row,
|
|
423
|
+
);
|
|
424
|
+
decode_interaction_request(interaction.request, row);
|
|
425
|
+
if (interaction.response !== undefined) {
|
|
426
|
+
decode_interaction_response(interaction.response, row);
|
|
427
|
+
}
|
|
428
|
+
if (interaction.resolved_at !== undefined) {
|
|
429
|
+
optional_number(interaction, "resolved_at", row);
|
|
430
|
+
}
|
|
431
|
+
if (interaction.cancel_reason !== undefined) {
|
|
432
|
+
read_enum(
|
|
433
|
+
interaction,
|
|
434
|
+
"cancel_reason",
|
|
435
|
+
["turn_stopped", "session_disposed", "runtime_interrupted"],
|
|
436
|
+
row,
|
|
437
|
+
);
|
|
438
|
+
}
|
|
439
|
+
return item as SessionAgentInteraction;
|
|
440
|
+
});
|
|
441
|
+
}
|
|
442
|
+
|
|
418
443
|
/** 校验并读取持久化 Interaction 请求。 */
|
|
419
444
|
function decode_interaction_request(
|
|
420
445
|
value: unknown,
|
|
@@ -429,9 +454,10 @@ function decode_interaction_request(
|
|
|
429
454
|
read_string(request, "type", row);
|
|
430
455
|
read_json(request, "payload", row);
|
|
431
456
|
const source = read_json_object(request, "source", row);
|
|
432
|
-
if (!["tool", "
|
|
457
|
+
if (!["tool", "shell"].includes(String(source.type))) {
|
|
433
458
|
throw invalid_part(row, "request.source.type has an unsupported value");
|
|
434
459
|
}
|
|
460
|
+
read_string(source, "tool_call_id", row);
|
|
435
461
|
const created_at = request.created_at;
|
|
436
462
|
if (typeof created_at !== "number" || !Number.isFinite(created_at)) {
|
|
437
463
|
throw invalid_part(row, "request.created_at must be a finite number");
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
import path from "node:path";
|
|
9
9
|
import { DatabaseSync, type SQLInputValue } from "node:sqlite";
|
|
10
10
|
import type {
|
|
11
|
-
|
|
11
|
+
SessionAgentActionPart,
|
|
12
12
|
SessionAgentMessage,
|
|
13
13
|
SessionAgentMessagePart,
|
|
14
14
|
SessionMessage,
|
|
@@ -17,9 +17,9 @@ import type {
|
|
|
17
17
|
} from "@downcity/type";
|
|
18
18
|
import { restore_session_origin } from "@downcity/type";
|
|
19
19
|
import type { FileSystem, StorageDatabaseLocation } from "@downcity/type";
|
|
20
|
-
import type { SessionHistoryMeta } from "@/
|
|
20
|
+
import type { SessionHistoryMeta } from "@/types/store/SessionHistoryMeta.js";
|
|
21
21
|
import { normalize_session_metadata, resolve_system_timezone } from "@/session/storage/Metadata.js";
|
|
22
|
-
import { resolve_session_message_preview } from "@/session/
|
|
22
|
+
import { resolve_session_message_preview } from "@/session/storage/SessionMessagePreview.js";
|
|
23
23
|
import {
|
|
24
24
|
decode_session_message,
|
|
25
25
|
encode_session_message_row,
|
|
@@ -32,8 +32,8 @@ import {
|
|
|
32
32
|
SESSION_STORAGE_SCHEMA_VERSION,
|
|
33
33
|
} from "@/session/storage/SessionStorageSchema.js";
|
|
34
34
|
import type {
|
|
35
|
-
|
|
36
|
-
|
|
35
|
+
SessionDerivedStore,
|
|
36
|
+
SessionDerivedStoreTransaction,
|
|
37
37
|
SessionMessageCreateState,
|
|
38
38
|
SessionMessageStorageStats,
|
|
39
39
|
SessionMessageUpdate,
|
|
@@ -330,6 +330,15 @@ export class SqliteSessionStorage implements SessionStorage {
|
|
|
330
330
|
};
|
|
331
331
|
}
|
|
332
332
|
|
|
333
|
+
/** 读取已持久化 Message 总数;不读最新 Message,也不计算文件大小。 */
|
|
334
|
+
async message_count(): Promise<number> {
|
|
335
|
+
await this.initialize();
|
|
336
|
+
const row = this.require_database().prepare(
|
|
337
|
+
"SELECT message_count FROM session_state WHERE singleton_id = 1",
|
|
338
|
+
).get() as { message_count: number } | undefined;
|
|
339
|
+
return row?.message_count ?? 0;
|
|
340
|
+
}
|
|
341
|
+
|
|
333
342
|
/** 清空 Message;外键负责同步删除 Part 与正确关联的派生数据。 */
|
|
334
343
|
async clear_messages(): Promise<void> {
|
|
335
344
|
await this.initialize();
|
|
@@ -344,25 +353,24 @@ export class SqliteSessionStorage implements SessionStorage {
|
|
|
344
353
|
});
|
|
345
354
|
}
|
|
346
355
|
|
|
347
|
-
/** 创建只允许当前 namespace 派生表的 Composer
|
|
348
|
-
|
|
349
|
-
const normalized_namespace =
|
|
356
|
+
/** 创建只允许当前 namespace 派生表的 Composer 派生存储。 */
|
|
357
|
+
derived_store(namespace: string): SessionDerivedStore {
|
|
358
|
+
const normalized_namespace = normalize_derived_namespace(namespace);
|
|
350
359
|
const table_prefix = `composer_${normalized_namespace}_`;
|
|
351
360
|
return {
|
|
352
|
-
|
|
353
|
-
transaction: async <T>(operation: (transaction: SessionComposerStorageTransaction) => T) => {
|
|
361
|
+
transaction: async <T>(operation: (transaction: SessionDerivedStoreTransaction) => T) => {
|
|
354
362
|
await this.initialize();
|
|
355
363
|
return this.run_transaction(() => operation({
|
|
356
364
|
execute: (sql, parameters) => {
|
|
357
|
-
|
|
365
|
+
assert_derived_sql(sql, table_prefix);
|
|
358
366
|
this.run_statement(sql, parameters);
|
|
359
367
|
},
|
|
360
368
|
get: <TRow>(sql: string, parameters?: readonly SessionStorageValue[]) => {
|
|
361
|
-
|
|
369
|
+
assert_derived_sql(sql, table_prefix);
|
|
362
370
|
return (this.get_statement(sql, parameters) as TRow | undefined) ?? null;
|
|
363
371
|
},
|
|
364
372
|
all: <TRow>(sql: string, parameters?: readonly SessionStorageValue[]) => {
|
|
365
|
-
|
|
373
|
+
assert_derived_sql(sql, table_prefix);
|
|
366
374
|
return this.all_statement(sql, parameters) as TRow[];
|
|
367
375
|
},
|
|
368
376
|
}));
|
|
@@ -652,7 +660,6 @@ export class SqliteSessionStorage implements SessionStorage {
|
|
|
652
660
|
if (part.type === "tool") {
|
|
653
661
|
return part.state !== "completed" && part.state !== "failed";
|
|
654
662
|
}
|
|
655
|
-
if (part.type === "interaction") return part.status === "pending";
|
|
656
663
|
if (part.type === "action") return part.state === "running";
|
|
657
664
|
return false;
|
|
658
665
|
});
|
|
@@ -733,25 +740,25 @@ interface SessionStateRow {
|
|
|
733
740
|
}
|
|
734
741
|
|
|
735
742
|
/** 校验 Composer 派生表 namespace。 */
|
|
736
|
-
function
|
|
743
|
+
function normalize_derived_namespace(value: string): string {
|
|
737
744
|
const namespace = String(value || "").trim();
|
|
738
745
|
if (!/^[a-z][a-z0-9_]*$/u.test(namespace)) {
|
|
739
|
-
throw new Error("Composer
|
|
746
|
+
throw new Error("Composer derived namespace must use lowercase snake_case");
|
|
740
747
|
}
|
|
741
748
|
return namespace;
|
|
742
749
|
}
|
|
743
750
|
|
|
744
|
-
/** 限制派生 SQL
|
|
745
|
-
function
|
|
751
|
+
/** 限制派生 SQL 的写目标,避免 Composer 修改 canonical 表。 */
|
|
752
|
+
function assert_derived_sql(sql: string, table_prefix: string): void {
|
|
746
753
|
const source = String(sql || "").trim();
|
|
747
|
-
if (!source) throw new Error("Composer
|
|
754
|
+
if (!source) throw new Error("Composer derived SQL cannot be empty");
|
|
748
755
|
if (
|
|
749
756
|
/\b(?:ATTACH|DETACH|VACUUM|PRAGMA|REINDEX|ANALYZE|ALTER)\b/iu.test(source) ||
|
|
750
757
|
/\bCREATE\s+(?:UNIQUE\s+)?INDEX\b/iu.test(source) ||
|
|
751
758
|
/\bCREATE\s+TRIGGER\b/iu.test(source) ||
|
|
752
759
|
/\bDROP\s+(?:INDEX|TRIGGER)\b/iu.test(source)
|
|
753
760
|
) {
|
|
754
|
-
throw new Error("Composer
|
|
761
|
+
throw new Error("Composer derived SQL cannot execute database control statements");
|
|
755
762
|
}
|
|
756
763
|
const mutation_targets = [
|
|
757
764
|
...source.matchAll(/\bCREATE\s+TABLE(?:\s+IF\s+NOT\s+EXISTS)?\s+([a-zA-Z_][a-zA-Z0-9_]*)/giu),
|
|
@@ -763,10 +770,10 @@ function assert_policy_sql(sql: string, table_prefix: string): void {
|
|
|
763
770
|
].map((match) => match[1] || "");
|
|
764
771
|
const mutates_database = /\b(?:CREATE|INSERT|REPLACE|UPDATE|DELETE|DROP|ALTER)\b/iu.test(source);
|
|
765
772
|
if (mutates_database && mutation_targets.length === 0) {
|
|
766
|
-
throw new Error("Composer
|
|
773
|
+
throw new Error("Composer derived SQL mutation is not supported");
|
|
767
774
|
}
|
|
768
775
|
if (mutation_targets.some((table_name) => !table_name.startsWith(table_prefix))) {
|
|
769
|
-
throw new Error(`Composer
|
|
776
|
+
throw new Error(`Composer derived SQL can only mutate ${table_prefix}* tables`);
|
|
770
777
|
}
|
|
771
778
|
}
|
|
772
779
|
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ask_question 对自己 Interaction payload 的解释。
|
|
3
|
+
*
|
|
4
|
+
* Interaction 只有通用信封,`payload` 由生产者解释,所以「回答是否完整、选项是否合法」
|
|
5
|
+
* 归本模块,而不是 Session 核心。
|
|
6
|
+
*
|
|
7
|
+
* 回答形状在这里按问题自身的 `type` 收敛:多选是字符串数组,其余是字符串。客户端
|
|
8
|
+
* 提交了另一种形状也能被收编(单选来了数组就取首项),而不是让整次交互失败;内容
|
|
9
|
+
* 仍然严格校验,缺答、重复、越界选项都会抛出可读错误。
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
import type {
|
|
13
|
+
SessionInteractionAnswer,
|
|
14
|
+
SessionInteractionQuestion,
|
|
15
|
+
} from "@downcity/type";
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* 把用户提交的回答解释为规范答案集合。
|
|
19
|
+
*
|
|
20
|
+
* 返回顺序与 `questions` 一致,值形状与 `type` 一致,可直接作为 Tool Result 交给模型。
|
|
21
|
+
*/
|
|
22
|
+
export function resolve_ask_question_answers(
|
|
23
|
+
questions: readonly SessionInteractionQuestion[],
|
|
24
|
+
payload: unknown,
|
|
25
|
+
): SessionInteractionAnswer[] {
|
|
26
|
+
const submitted = new Map<string, unknown>();
|
|
27
|
+
for (const raw of read_raw_answers(payload)) {
|
|
28
|
+
const question_id = String(raw.question_id || "").trim();
|
|
29
|
+
if (!question_id) {
|
|
30
|
+
throw new Error("ask_question answer requires question_id");
|
|
31
|
+
}
|
|
32
|
+
if (submitted.has(question_id)) {
|
|
33
|
+
throw new Error(`Duplicate ask_question answer: ${question_id}`);
|
|
34
|
+
}
|
|
35
|
+
submitted.set(question_id, raw.value);
|
|
36
|
+
}
|
|
37
|
+
if (submitted.size !== questions.length) {
|
|
38
|
+
throw new Error(
|
|
39
|
+
`ask_question expected ${questions.length} answers but received ${submitted.size}`,
|
|
40
|
+
);
|
|
41
|
+
}
|
|
42
|
+
return questions.map((question) => {
|
|
43
|
+
if (!submitted.has(question.question_id)) {
|
|
44
|
+
throw new Error(`ask_question answer is missing: ${question.question_id}`);
|
|
45
|
+
}
|
|
46
|
+
const value = normalize_answer_value(question, submitted.get(question.question_id));
|
|
47
|
+
assert_answer_options(question, value);
|
|
48
|
+
return { question_id: question.question_id, value };
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/** 从回答 payload 中读取可选的补充说明。 */
|
|
53
|
+
export function read_ask_question_note(payload: unknown): string | undefined {
|
|
54
|
+
if (!is_record(payload)) return undefined;
|
|
55
|
+
const note = payload.note;
|
|
56
|
+
return typeof note === "string" && note.trim() ? note : undefined;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/** 读取 payload 中已提交的原始回答条目;结构不可用时视为未提交。 */
|
|
60
|
+
function read_raw_answers(
|
|
61
|
+
payload: unknown,
|
|
62
|
+
): Array<{ question_id?: unknown; value?: unknown }> {
|
|
63
|
+
if (!is_record(payload) || !Array.isArray(payload.answers)) return [];
|
|
64
|
+
return payload.answers.filter(is_record);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* 把回答值收敛到问题要求的形状。
|
|
69
|
+
*
|
|
70
|
+
* 多选始终是数组,其余始终是字符串。值本身不是字符串(或字符串数组)时抛出,
|
|
71
|
+
* 避免把 `[object Object]` 这类内容当成用户答案交给模型。
|
|
72
|
+
*/
|
|
73
|
+
function normalize_answer_value(
|
|
74
|
+
question: SessionInteractionQuestion,
|
|
75
|
+
value: unknown,
|
|
76
|
+
): string | string[] {
|
|
77
|
+
if (question.type === "multi_select") {
|
|
78
|
+
if (Array.isArray(value)) {
|
|
79
|
+
return value.map((item) => require_answer_string(question, item));
|
|
80
|
+
}
|
|
81
|
+
// 未选择任何候选项:保持空数组,由选项校验决定是否可接受。
|
|
82
|
+
if (value === undefined || value === null) return [];
|
|
83
|
+
return [require_answer_string(question, value)];
|
|
84
|
+
}
|
|
85
|
+
if (Array.isArray(value)) {
|
|
86
|
+
// 单选题误传数组时取首项收编,而不是让整次交互失败。
|
|
87
|
+
return value.length > 0 ? require_answer_string(question, value[0]) : "";
|
|
88
|
+
}
|
|
89
|
+
if (value === undefined || value === null) return "";
|
|
90
|
+
return require_answer_string(question, value);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/** 选择题的回答必须落在候选项内。 */
|
|
94
|
+
function assert_answer_options(
|
|
95
|
+
question: SessionInteractionQuestion,
|
|
96
|
+
value: string | string[],
|
|
97
|
+
): void {
|
|
98
|
+
if (question.type === "text") return;
|
|
99
|
+
const allowed = new Set((question.options ?? []).map((option) => option.value));
|
|
100
|
+
const selected = Array.isArray(value) ? value : [value];
|
|
101
|
+
const invalid = selected.find((item) => !allowed.has(item));
|
|
102
|
+
if (invalid !== undefined) {
|
|
103
|
+
throw new Error(
|
|
104
|
+
`ask_question answer is not a valid option: ${question.question_id} -> ${invalid}`,
|
|
105
|
+
);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/** 读取单个回答值,非字符串一律拒绝。 */
|
|
110
|
+
function require_answer_string(
|
|
111
|
+
question: SessionInteractionQuestion,
|
|
112
|
+
value: unknown,
|
|
113
|
+
): string {
|
|
114
|
+
if (typeof value !== "string") {
|
|
115
|
+
throw new Error(
|
|
116
|
+
`ask_question answer must be a string or string array: ${question.question_id}`,
|
|
117
|
+
);
|
|
118
|
+
}
|
|
119
|
+
return value;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/** 判断一个未知值是否为普通对象。 */
|
|
123
|
+
function is_record(value: unknown): value is Record<string, unknown> {
|
|
124
|
+
return Boolean(value) && typeof value === "object" && !Array.isArray(value);
|
|
125
|
+
}
|