@downcity/agent 1.1.438 → 1.1.446
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
|
@@ -6,52 +6,64 @@
|
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
8
|
import { generate_id } from "@/utils/Id.js";
|
|
9
|
-
import {
|
|
9
|
+
import { create_session_part_mutation } from "@/session/messages/SessionMutationFactory.js";
|
|
10
|
+
import { resolve_session_message_state } from "@/session/messages/SessionMessageState.js";
|
|
11
|
+
import {
|
|
12
|
+
is_same_agent_part,
|
|
13
|
+
next_agent_part_sequence,
|
|
14
|
+
resolve_changed_agent_parts,
|
|
15
|
+
} from "@/session/messages/SessionAgentParts.js";
|
|
10
16
|
import type {
|
|
11
17
|
SessionAgentErrorPart,
|
|
12
|
-
|
|
18
|
+
SessionAgentInteraction,
|
|
13
19
|
SessionAgentMessage,
|
|
14
20
|
SessionAgentMessagePart,
|
|
15
21
|
SessionAgentToolPart,
|
|
16
22
|
SessionMessage,
|
|
17
|
-
SessionMutation,
|
|
18
23
|
} from "@downcity/type";
|
|
19
24
|
import type {
|
|
20
25
|
SessionInteractionCloseInput,
|
|
21
26
|
SessionInteractionRequest,
|
|
22
27
|
SessionInteractionResponse,
|
|
23
28
|
} from "@downcity/type";
|
|
24
|
-
import type {
|
|
29
|
+
import type { SessionOpenMessageToolLocation } from "@/types/session/SessionTool.js";
|
|
25
30
|
import type { SessionAgentMessageStateOptions } from "@/types/session/SessionAgentMessageState.js";
|
|
26
31
|
|
|
32
|
+
/** 一次 Interaction 的定位结果:所属 Message、Tool 与自身。 */
|
|
33
|
+
interface SessionInteractionLocation {
|
|
34
|
+
/** 所属 Agent Message 标识。 */
|
|
35
|
+
message_id: string;
|
|
36
|
+
/** 承载该 Interaction 的 canonical Tool Part。 */
|
|
37
|
+
tool: SessionAgentToolPart;
|
|
38
|
+
/** Interaction 自身。 */
|
|
39
|
+
interaction: SessionAgentInteraction;
|
|
40
|
+
}
|
|
41
|
+
|
|
27
42
|
/** 管理 Agent Message 运行投影、语义检查点与 Interaction 原子状态。 */
|
|
28
43
|
export class SessionAgentMessageState {
|
|
29
44
|
private readonly session_id: string;
|
|
30
45
|
private readonly options: SessionAgentMessageStateOptions;
|
|
31
46
|
/** 同一 Agent Message 的检查点严格串行,不同 Message 可以独立提交。 */
|
|
32
47
|
private readonly write_chains = new Map<string, Promise<void>>();
|
|
33
|
-
private readonly interaction_writer: SessionMessageInteractionWriter;
|
|
34
48
|
|
|
35
49
|
constructor(options: SessionAgentMessageStateOptions) {
|
|
36
50
|
this.session_id = options.session_id;
|
|
37
51
|
this.options = options;
|
|
38
|
-
this.interaction_writer = new SessionMessageInteractionWriter({
|
|
39
|
-
list_messages: options.list_messages,
|
|
40
|
-
find_streaming_tool: (tool_call_id) => this.find_streaming_tool(tool_call_id),
|
|
41
|
-
enqueue_assistant_write: (message_id, operation) =>
|
|
42
|
-
this.enqueue_write(message_id, operation),
|
|
43
|
-
commit_assistant_snapshot: (current, parts) =>
|
|
44
|
-
this.persist_snapshot(current.message_id, parts),
|
|
45
|
-
});
|
|
46
52
|
}
|
|
47
53
|
|
|
48
|
-
/**
|
|
54
|
+
/**
|
|
55
|
+
* 只在内存中创建或替换一个 Part,并立即发布实时完整 Part。
|
|
56
|
+
*
|
|
57
|
+
* 内容未变化时不发布:Tool 的 ready 状态会被模型事件与输入校验先后置为同一值,
|
|
58
|
+
* 无条件下发会产生同 revision、同内容的重复 Mutation。
|
|
59
|
+
*/
|
|
49
60
|
project_part(message_id: string, part: SessionAgentMessagePart): void {
|
|
50
|
-
const current = this.
|
|
61
|
+
const current = this.require_writable_agent(message_id);
|
|
51
62
|
const existing = current.parts.find((item) => item.part_id === part.part_id);
|
|
52
63
|
if (existing && existing.sequence !== part.sequence) {
|
|
53
64
|
throw new Error(`Agent Part sequence changed: ${part.part_id}`);
|
|
54
65
|
}
|
|
66
|
+
if (existing && is_same_agent_part(existing, part)) return;
|
|
55
67
|
const projected: SessionAgentMessage = {
|
|
56
68
|
...current,
|
|
57
69
|
updated_at: Date.now(),
|
|
@@ -60,18 +72,18 @@ export class SessionAgentMessageState {
|
|
|
60
72
|
: [...current.parts, structuredClone(part)]
|
|
61
73
|
).sort((left, right) => left.sequence - right.sequence),
|
|
62
74
|
};
|
|
63
|
-
this.options.
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
+
this.options.cache.project(
|
|
76
|
+
create_session_part_mutation({
|
|
77
|
+
mutation_id: generate_id(),
|
|
78
|
+
session_id: this.session_id,
|
|
79
|
+
message_id,
|
|
80
|
+
...(current.turn_id ? { turn_id: current.turn_id } : {}),
|
|
81
|
+
revision: current.revision,
|
|
82
|
+
created_at: projected.updated_at,
|
|
83
|
+
part: structuredClone(part),
|
|
84
|
+
}),
|
|
85
|
+
projected,
|
|
86
|
+
);
|
|
75
87
|
}
|
|
76
88
|
|
|
77
89
|
/** 只在内存中追加文本、推理或 Tool 输入增量,并立即发布 delta。 */
|
|
@@ -83,7 +95,7 @@ export class SessionAgentMessageState {
|
|
|
83
95
|
tool_call_id?: string,
|
|
84
96
|
): void {
|
|
85
97
|
if (!delta) return;
|
|
86
|
-
const current = this.
|
|
98
|
+
const current = this.require_writable_agent(message_id);
|
|
87
99
|
let matched = false;
|
|
88
100
|
const projected: SessionAgentMessage = {
|
|
89
101
|
...current,
|
|
@@ -109,25 +121,30 @@ export class SessionAgentMessageState {
|
|
|
109
121
|
}),
|
|
110
122
|
};
|
|
111
123
|
if (!matched) throw new Error(`Delta target Part does not exist: ${part_id}`);
|
|
112
|
-
|
|
124
|
+
const base = {
|
|
113
125
|
mutation_id: generate_id(),
|
|
114
|
-
variant: "delta",
|
|
115
|
-
type,
|
|
126
|
+
variant: "delta" as const,
|
|
116
127
|
message_id,
|
|
128
|
+
...(current.turn_id ? { turn_id: current.turn_id } : {}),
|
|
117
129
|
revision: current.revision,
|
|
118
130
|
session_id: this.session_id,
|
|
119
|
-
...(current.turn_id ? { turn_id: current.turn_id } : {}),
|
|
120
131
|
created_at: projected.updated_at,
|
|
121
132
|
part_id,
|
|
122
|
-
...(tool_call_id ? { tool_call_id } : {}),
|
|
123
133
|
delta,
|
|
124
|
-
}
|
|
134
|
+
};
|
|
135
|
+
const tool_input_id = type === "tool_input" ? String(tool_call_id || "").trim() : "";
|
|
136
|
+
this.options.cache.project(
|
|
137
|
+
type === "tool_input"
|
|
138
|
+
? { ...base, type, tool_call_id: tool_input_id }
|
|
139
|
+
: { ...base, type },
|
|
140
|
+
projected,
|
|
141
|
+
);
|
|
125
142
|
}
|
|
126
143
|
|
|
127
144
|
/** 将当前内存投影作为一个稳定语义检查点原子提交。 */
|
|
128
145
|
async checkpoint(message_id: string): Promise<void> {
|
|
129
146
|
await this.enqueue_write(message_id, async () => {
|
|
130
|
-
const current = this.
|
|
147
|
+
const current = this.require_writable_agent(message_id);
|
|
131
148
|
await this.persist_snapshot(message_id, current.parts);
|
|
132
149
|
});
|
|
133
150
|
}
|
|
@@ -138,7 +155,7 @@ export class SessionAgentMessageState {
|
|
|
138
155
|
parts: SessionAgentMessagePart[],
|
|
139
156
|
): Promise<void> {
|
|
140
157
|
await this.enqueue_write(message_id, async () => {
|
|
141
|
-
const current = this.
|
|
158
|
+
const current = this.require_writable_agent(message_id);
|
|
142
159
|
if (
|
|
143
160
|
parts.length !== current.parts.length ||
|
|
144
161
|
parts.some((part, index) =>
|
|
@@ -152,14 +169,20 @@ export class SessionAgentMessageState {
|
|
|
152
169
|
});
|
|
153
170
|
}
|
|
154
171
|
|
|
155
|
-
/**
|
|
172
|
+
/**
|
|
173
|
+
* 原子追加或替换一组非流式 Agent Parts。
|
|
174
|
+
*
|
|
175
|
+
* 同 part_id 已存在时原地替换并保留原 sequence;不存在时追加到 Message 末尾。
|
|
176
|
+
* options.publish_mutation 为 false 时只更新 canonical 快照而不发布 Mutation。
|
|
177
|
+
*/
|
|
156
178
|
async commit_parts(
|
|
157
179
|
message_id: string,
|
|
158
180
|
parts: readonly SessionAgentMessagePart[],
|
|
181
|
+
options?: { publish_mutation?: boolean },
|
|
159
182
|
): Promise<void> {
|
|
160
183
|
if (parts.length === 0) return;
|
|
161
184
|
await this.enqueue_write(message_id, async () => {
|
|
162
|
-
const current = this.
|
|
185
|
+
const current = this.require_writable_agent(message_id);
|
|
163
186
|
const replacements = new Map(parts.map((part) => [part.part_id, structuredClone(part)]));
|
|
164
187
|
const existing_ids = new Set(current.parts.map((part) => part.part_id));
|
|
165
188
|
const merged = current.parts.map((part) => replacements.get(part.part_id) ?? part);
|
|
@@ -169,6 +192,7 @@ export class SessionAgentMessageState {
|
|
|
169
192
|
await this.persist_snapshot(
|
|
170
193
|
message_id,
|
|
171
194
|
merged.sort((left, right) => left.sequence - right.sequence),
|
|
195
|
+
{ publish_mutation: options?.publish_mutation !== false },
|
|
172
196
|
);
|
|
173
197
|
});
|
|
174
198
|
}
|
|
@@ -180,7 +204,7 @@ export class SessionAgentMessageState {
|
|
|
180
204
|
if (!persisted || persisted.role !== "agent") {
|
|
181
205
|
throw new Error(`Persisted Agent Message not found: ${message_id}`);
|
|
182
206
|
}
|
|
183
|
-
this.options.
|
|
207
|
+
this.options.cache.accept(persisted);
|
|
184
208
|
});
|
|
185
209
|
}
|
|
186
210
|
|
|
@@ -190,17 +214,11 @@ export class SessionAgentMessageState {
|
|
|
190
214
|
outcome: "completed" | "stopped" | "failed",
|
|
191
215
|
error?: string,
|
|
192
216
|
): Promise<void> {
|
|
217
|
+
// 先释放持有,收口提交才能把 Message 收敛为终态。
|
|
218
|
+
this.options.cache.release_held(message_id);
|
|
193
219
|
await this.enqueue_write(message_id, async () => {
|
|
194
|
-
const current = this.
|
|
220
|
+
const current = this.require_writable_agent(message_id);
|
|
195
221
|
const completed_at = Date.now();
|
|
196
|
-
const interrupted_tool_ids = new Set(
|
|
197
|
-
current.parts.flatMap((part) =>
|
|
198
|
-
part.type === "interaction" && part.status === "pending" &&
|
|
199
|
-
part.request.source.tool_call_id
|
|
200
|
-
? [part.request.source.tool_call_id]
|
|
201
|
-
: [],
|
|
202
|
-
),
|
|
203
|
-
);
|
|
204
222
|
const parts: SessionAgentMessagePart[] = current.parts.map((part) => {
|
|
205
223
|
if (part.type === "text" || part.type === "reasoning") {
|
|
206
224
|
return { ...part, state: "done" as const };
|
|
@@ -214,25 +232,36 @@ export class SessionAgentMessageState {
|
|
|
214
232
|
: { description: error || "Action did not complete before Agent Message closed" }),
|
|
215
233
|
};
|
|
216
234
|
}
|
|
217
|
-
if (part.type
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
235
|
+
if (part.type !== "tool") return part;
|
|
236
|
+
// Interaction 属于 Tool,收口时随所属 Tool 一起终止。
|
|
237
|
+
const existing_interactions = part.interactions ?? [];
|
|
238
|
+
const had_pending_interaction = existing_interactions.some(
|
|
239
|
+
(interaction) => interaction.status === "pending",
|
|
240
|
+
);
|
|
241
|
+
const interactions = had_pending_interaction
|
|
242
|
+
? existing_interactions.map((interaction) =>
|
|
243
|
+
interaction.status === "pending"
|
|
244
|
+
? {
|
|
245
|
+
...interaction,
|
|
246
|
+
status: "cancelled" as const,
|
|
247
|
+
cancel_reason: "runtime_interrupted" as const,
|
|
248
|
+
resolved_at: completed_at,
|
|
249
|
+
}
|
|
250
|
+
: interaction,
|
|
251
|
+
)
|
|
252
|
+
: part.interactions;
|
|
253
|
+
if (part.state === "completed" || part.state === "failed") {
|
|
254
|
+
return had_pending_interaction ? { ...part, interactions } : part;
|
|
224
255
|
}
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
}
|
|
235
|
-
return part;
|
|
256
|
+
return {
|
|
257
|
+
...part,
|
|
258
|
+
state: "failed" as const,
|
|
259
|
+
interactions,
|
|
260
|
+
error: outcome === "stopped" && part.state === "waiting-user" &&
|
|
261
|
+
had_pending_interaction
|
|
262
|
+
? "Interaction cancelled"
|
|
263
|
+
: error || "Tool did not complete before Agent Message closed",
|
|
264
|
+
};
|
|
236
265
|
});
|
|
237
266
|
if (outcome === "stopped" && !parts.some((part) =>
|
|
238
267
|
part.type === "error" && part.code === "turn_stopped"
|
|
@@ -241,14 +270,14 @@ export class SessionAgentMessageState {
|
|
|
241
270
|
} else if (outcome === "failed" && error && !parts.some((part) => part.type === "error")) {
|
|
242
271
|
parts.push(create_terminal_error_part(parts, "turn_execution_failed", error));
|
|
243
272
|
}
|
|
244
|
-
await this.persist_snapshot(message_id, parts,
|
|
273
|
+
await this.persist_snapshot(message_id, parts, { held_by_writer: false });
|
|
245
274
|
});
|
|
246
275
|
}
|
|
247
276
|
|
|
248
|
-
/**
|
|
249
|
-
|
|
250
|
-
for (const message of this.options.
|
|
251
|
-
if (message.role !== "agent"
|
|
277
|
+
/** 读取当前可写 Agent Message 中的指定 Tool Part。 */
|
|
278
|
+
find_tool_in_open_message(tool_call_id: string): SessionOpenMessageToolLocation | undefined {
|
|
279
|
+
for (const message of this.options.cache.all()) {
|
|
280
|
+
if (message.role !== "agent") continue;
|
|
252
281
|
const part = message.parts.find(
|
|
253
282
|
(item): item is SessionAgentToolPart =>
|
|
254
283
|
item.type === "tool" && item.tool_call_id === tool_call_id,
|
|
@@ -258,59 +287,166 @@ export class SessionAgentMessageState {
|
|
|
258
287
|
return undefined;
|
|
259
288
|
}
|
|
260
289
|
|
|
261
|
-
/** 返回当前 Session
|
|
262
|
-
list_pending_interactions():
|
|
263
|
-
return this.
|
|
290
|
+
/** 返回当前 Session 中全部等待用户响应的 Interaction。 */
|
|
291
|
+
list_pending_interactions(): SessionAgentInteraction[] {
|
|
292
|
+
return [...this.options.cache.all()].flatMap((message) =>
|
|
293
|
+
message.role === "agent"
|
|
294
|
+
? message.parts.flatMap((part) =>
|
|
295
|
+
part.type === "tool"
|
|
296
|
+
? (part.interactions ?? []).flatMap((interaction) =>
|
|
297
|
+
interaction.status === "pending"
|
|
298
|
+
? [structuredClone(interaction)]
|
|
299
|
+
: [],
|
|
300
|
+
)
|
|
301
|
+
: [],
|
|
302
|
+
)
|
|
303
|
+
: [],
|
|
304
|
+
);
|
|
264
305
|
}
|
|
265
306
|
|
|
266
|
-
/**
|
|
307
|
+
/**
|
|
308
|
+
* 原子创建 Interaction,并把所属 Tool 转为 waiting-user。
|
|
309
|
+
*
|
|
310
|
+
* Interaction 是 Tool Part 的从属数据:Tool 在等待响应时阻塞,因此两者的转换
|
|
311
|
+
* 必须在同一次快照提交内完成,否则会出现“Interaction pending 但 Tool 未等待”的中间态。
|
|
312
|
+
*/
|
|
267
313
|
async request_interaction(
|
|
268
314
|
request: SessionInteractionRequest,
|
|
269
|
-
): Promise<
|
|
270
|
-
|
|
315
|
+
): Promise<SessionAgentInteraction> {
|
|
316
|
+
const tool_call_id = request.source.tool_call_id;
|
|
317
|
+
await this.run_interaction_write(tool_call_id, async (current, owner) => {
|
|
318
|
+
if (
|
|
319
|
+
(owner.interactions ?? []).some(
|
|
320
|
+
(item) => item.interaction_id === request.interaction_id,
|
|
321
|
+
)
|
|
322
|
+
) {
|
|
323
|
+
throw new Error(
|
|
324
|
+
`Session Interaction already exists: ${request.interaction_id}`,
|
|
325
|
+
);
|
|
326
|
+
}
|
|
327
|
+
if (owner.state !== "ready" && owner.state !== "waiting-user") {
|
|
328
|
+
throw new Error(
|
|
329
|
+
`Tool Interaction requires ready input: ${tool_call_id} (${owner.state})`,
|
|
330
|
+
);
|
|
331
|
+
}
|
|
332
|
+
const interaction: SessionAgentInteraction = {
|
|
333
|
+
interaction_id: request.interaction_id,
|
|
334
|
+
interaction_type: request.type,
|
|
335
|
+
status: "pending",
|
|
336
|
+
request: structuredClone(request),
|
|
337
|
+
};
|
|
338
|
+
await this.persist_snapshot(
|
|
339
|
+
current.message_id,
|
|
340
|
+
replace_tool_part(current.parts, {
|
|
341
|
+
...owner,
|
|
342
|
+
state: "waiting-user",
|
|
343
|
+
interactions: [...(owner.interactions ?? []), interaction],
|
|
344
|
+
}),
|
|
345
|
+
);
|
|
346
|
+
});
|
|
347
|
+
return this.require_pending_interaction(request.interaction_id).interaction;
|
|
271
348
|
}
|
|
272
349
|
|
|
273
|
-
/**
|
|
350
|
+
/** 原子保存用户响应,并按 Interaction 结果恢复或终止所属 Tool。 */
|
|
274
351
|
async resolve_interaction(
|
|
275
352
|
interaction_id: string,
|
|
276
353
|
response: SessionInteractionResponse,
|
|
277
|
-
): Promise<
|
|
278
|
-
|
|
354
|
+
): Promise<SessionAgentInteraction> {
|
|
355
|
+
const location = this.require_pending_interaction(interaction_id);
|
|
356
|
+
if (location.interaction.interaction_type !== response.type) {
|
|
357
|
+
throw new Error(`Session Interaction response type mismatch: ${interaction_id}`);
|
|
358
|
+
}
|
|
359
|
+
await this.enqueue_write(location.message_id, async () => {
|
|
360
|
+
const current = this.require_writable_agent(location.message_id);
|
|
361
|
+
const owner = require_tool_part_in(current, location.tool.part_id);
|
|
362
|
+
if (owner.state !== "waiting-user") {
|
|
363
|
+
throw new Error(
|
|
364
|
+
`Tool is not waiting for Interaction: ${owner.tool_call_id} (${owner.state})`,
|
|
365
|
+
);
|
|
366
|
+
}
|
|
367
|
+
const denied = response.outcome === "denied";
|
|
368
|
+
await this.persist_snapshot(
|
|
369
|
+
current.message_id,
|
|
370
|
+
replace_tool_part(current.parts, {
|
|
371
|
+
...owner,
|
|
372
|
+
state: denied ? "failed" : "running",
|
|
373
|
+
...(denied ? { error: "Interaction denied" } : {}),
|
|
374
|
+
interactions: update_tool_interaction(owner, interaction_id, (item) => ({
|
|
375
|
+
...item,
|
|
376
|
+
status: denied ? "denied" : "resolved",
|
|
377
|
+
response: structuredClone(response),
|
|
378
|
+
resolved_at: Date.now(),
|
|
379
|
+
})),
|
|
380
|
+
}),
|
|
381
|
+
);
|
|
382
|
+
});
|
|
383
|
+
return this.require_interaction(interaction_id).interaction;
|
|
279
384
|
}
|
|
280
385
|
|
|
281
|
-
/**
|
|
386
|
+
/** 原子结束未响应 Interaction,并把所属 Tool 标记为失败。 */
|
|
282
387
|
async close_interaction(
|
|
283
388
|
interaction_id: string,
|
|
284
389
|
input: SessionInteractionCloseInput,
|
|
285
|
-
): Promise<
|
|
286
|
-
|
|
390
|
+
): Promise<SessionAgentInteraction> {
|
|
391
|
+
const location = this.require_pending_interaction(interaction_id);
|
|
392
|
+
await this.enqueue_write(location.message_id, async () => {
|
|
393
|
+
const current = this.require_writable_agent(location.message_id);
|
|
394
|
+
const owner = require_tool_part_in(current, location.tool.part_id);
|
|
395
|
+
await this.persist_snapshot(
|
|
396
|
+
current.message_id,
|
|
397
|
+
replace_tool_part(current.parts, {
|
|
398
|
+
...owner,
|
|
399
|
+
...(owner.state === "waiting-user"
|
|
400
|
+
? { state: "failed" as const, error: "Interaction cancelled" }
|
|
401
|
+
: {}),
|
|
402
|
+
interactions: update_tool_interaction(owner, interaction_id, (item) => ({
|
|
403
|
+
...item,
|
|
404
|
+
status: "cancelled",
|
|
405
|
+
resolved_at: Date.now(),
|
|
406
|
+
cancel_reason: input.reason,
|
|
407
|
+
})),
|
|
408
|
+
}),
|
|
409
|
+
);
|
|
410
|
+
});
|
|
411
|
+
return this.require_interaction(interaction_id).interaction;
|
|
287
412
|
}
|
|
288
413
|
|
|
289
414
|
/** 原子保存完整 Message 快照;变更比较以数据库事实而非运行投影为准。 */
|
|
290
415
|
private async persist_snapshot(
|
|
291
416
|
message_id: string,
|
|
292
417
|
parts: SessionAgentMessagePart[],
|
|
293
|
-
|
|
418
|
+
options?: {
|
|
419
|
+
/** 本次提交后是否仍由 writer 持有;收口时传 false。省略时读取当前持有关系。 */
|
|
420
|
+
held_by_writer?: boolean;
|
|
421
|
+
/** 是否向订阅方发布 Message Mutation。 */
|
|
422
|
+
publish_mutation?: boolean;
|
|
423
|
+
},
|
|
294
424
|
): Promise<void> {
|
|
295
425
|
const persisted = await this.options.store.read_message(message_id);
|
|
296
|
-
if (!persisted || persisted.role !== "agent"
|
|
297
|
-
throw new Error(`
|
|
426
|
+
if (!persisted || persisted.role !== "agent") {
|
|
427
|
+
throw new Error(`Agent Message not found: ${message_id}`);
|
|
298
428
|
}
|
|
299
429
|
const committed_at = Date.now();
|
|
430
|
+
const next_parts = structuredClone(parts).sort(
|
|
431
|
+
(left, right) => left.sequence - right.sequence,
|
|
432
|
+
);
|
|
300
433
|
const message: SessionAgentMessage = {
|
|
301
434
|
...persisted,
|
|
302
|
-
state
|
|
435
|
+
state: resolve_session_message_state(
|
|
436
|
+
next_parts,
|
|
437
|
+
options?.held_by_writer ?? this.options.cache.is_held(message_id),
|
|
438
|
+
),
|
|
303
439
|
revision: persisted.revision + 1,
|
|
304
440
|
updated_at: committed_at,
|
|
305
|
-
parts:
|
|
441
|
+
parts: next_parts,
|
|
306
442
|
};
|
|
307
|
-
const changed_parts =
|
|
443
|
+
const changed_parts = resolve_changed_agent_parts(persisted.parts, message.parts);
|
|
308
444
|
await this.options.store.update_message({
|
|
309
445
|
message,
|
|
310
446
|
expected_revision: persisted.revision,
|
|
311
447
|
changed_parts,
|
|
312
448
|
});
|
|
313
|
-
this.options.
|
|
449
|
+
this.options.cache.accept(message, options?.publish_mutation !== false);
|
|
314
450
|
}
|
|
315
451
|
|
|
316
452
|
/** 串行执行同一 Message 的语义检查点。 */
|
|
@@ -329,21 +465,111 @@ export class SessionAgentMessageState {
|
|
|
329
465
|
}
|
|
330
466
|
}
|
|
331
467
|
|
|
332
|
-
/**
|
|
333
|
-
|
|
334
|
-
|
|
468
|
+
/**
|
|
469
|
+
* 在所属 Tool 的串行写链内执行一次 Interaction 变更。
|
|
470
|
+
*
|
|
471
|
+
* Interaction 与 Tool 必须整体提交:先定位 Tool,再在同一串行段内读取最新快照并替换它,
|
|
472
|
+
* 避免两个并发响应基于过期快照各自提交。
|
|
473
|
+
*/
|
|
474
|
+
private async run_interaction_write(
|
|
475
|
+
tool_call_id: string,
|
|
476
|
+
operation: (
|
|
477
|
+
current: SessionAgentMessage,
|
|
478
|
+
owner: SessionAgentToolPart,
|
|
479
|
+
) => Promise<void>,
|
|
480
|
+
): Promise<void> {
|
|
481
|
+
const located = this.find_tool_in_open_message(tool_call_id);
|
|
482
|
+
if (!located) throw new Error(`Open Tool Part not found: ${tool_call_id}`);
|
|
483
|
+
await this.enqueue_write(located.message_id, async () => {
|
|
484
|
+
const current = this.require_writable_agent(located.message_id);
|
|
485
|
+
const owner = require_tool_part_in(current, located.part.part_id);
|
|
486
|
+
await operation(current, owner);
|
|
487
|
+
});
|
|
488
|
+
}
|
|
489
|
+
|
|
490
|
+
/** 查找指定 Interaction 及其所属 Tool 与 Message。 */
|
|
491
|
+
private find_interaction(
|
|
492
|
+
interaction_id: string,
|
|
493
|
+
): SessionInteractionLocation | undefined {
|
|
494
|
+
for (const message of this.options.cache.all()) {
|
|
495
|
+
if (message.role !== "agent") continue;
|
|
496
|
+
for (const part of message.parts) {
|
|
497
|
+
if (part.type !== "tool") continue;
|
|
498
|
+
const interaction = (part.interactions ?? []).find(
|
|
499
|
+
(item) => item.interaction_id === interaction_id,
|
|
500
|
+
);
|
|
501
|
+
if (interaction) {
|
|
502
|
+
return { message_id: message.message_id, tool: part, interaction };
|
|
503
|
+
}
|
|
504
|
+
}
|
|
505
|
+
}
|
|
506
|
+
return undefined;
|
|
507
|
+
}
|
|
508
|
+
|
|
509
|
+
/** 读取指定 Interaction,否则抛出稳定领域错误。 */
|
|
510
|
+
private require_interaction(interaction_id: string): SessionInteractionLocation {
|
|
511
|
+
const interaction = this.find_interaction(interaction_id);
|
|
512
|
+
if (interaction) return interaction;
|
|
513
|
+
throw new Error(`Session Interaction not found: ${interaction_id}`);
|
|
514
|
+
}
|
|
515
|
+
|
|
516
|
+
/** 读取指定 pending Interaction,否则拒绝重复响应终态 Interaction。 */
|
|
517
|
+
private require_pending_interaction(
|
|
518
|
+
interaction_id: string,
|
|
519
|
+
): SessionInteractionLocation {
|
|
520
|
+
const interaction = this.require_interaction(interaction_id);
|
|
521
|
+
if (interaction.interaction.status !== "pending") {
|
|
522
|
+
throw new Error(
|
|
523
|
+
`Session Interaction is already ${interaction.interaction.status}: ${interaction_id}`,
|
|
524
|
+
);
|
|
525
|
+
}
|
|
526
|
+
return interaction;
|
|
527
|
+
}
|
|
528
|
+
|
|
529
|
+
/** 读取当前运行投影中的可写 Agent Message;只有 writer 持有的消息可写。 */
|
|
530
|
+
private require_writable_agent(message_id: string): SessionAgentMessage {
|
|
531
|
+
const message = [...this.options.cache.all()].find(
|
|
335
532
|
(item) => item.message_id === message_id,
|
|
336
533
|
);
|
|
337
534
|
if (!message || message.role !== "agent") {
|
|
338
|
-
throw new Error(`Agent Message not found: ${message_id}`);
|
|
339
|
-
}
|
|
340
|
-
if (message.state !== "streaming") {
|
|
341
|
-
throw new Error(`Agent Message is already done: ${message_id}`);
|
|
535
|
+
throw new Error(`Writable Agent Message not found: ${message_id}`);
|
|
342
536
|
}
|
|
343
537
|
return message;
|
|
344
538
|
}
|
|
345
539
|
}
|
|
346
540
|
|
|
541
|
+
/** 以新的 Tool Part 替换同 part_id 的旧值,其余 Part 保持原引用。 */
|
|
542
|
+
function replace_tool_part(
|
|
543
|
+
parts: readonly SessionAgentMessagePart[],
|
|
544
|
+
tool: SessionAgentToolPart,
|
|
545
|
+
): SessionAgentMessagePart[] {
|
|
546
|
+
return parts.map((part) => (part.part_id === tool.part_id ? tool : part));
|
|
547
|
+
}
|
|
548
|
+
|
|
549
|
+
/** 读取指定 Message 中的 Tool Part,否则抛出稳定领域错误。 */
|
|
550
|
+
function require_tool_part_in(
|
|
551
|
+
message: SessionAgentMessage,
|
|
552
|
+
part_id: string,
|
|
553
|
+
): SessionAgentToolPart {
|
|
554
|
+
const tool = message.parts.find(
|
|
555
|
+
(part): part is SessionAgentToolPart =>
|
|
556
|
+
part.type === "tool" && part.part_id === part_id,
|
|
557
|
+
);
|
|
558
|
+
if (!tool) throw new Error(`Open Tool Part not found: ${part_id}`);
|
|
559
|
+
return tool;
|
|
560
|
+
}
|
|
561
|
+
|
|
562
|
+
/** 就地替换 Tool 内指定 Interaction,丢弃不存在的历史来源。 */
|
|
563
|
+
function update_tool_interaction(
|
|
564
|
+
tool: SessionAgentToolPart,
|
|
565
|
+
interaction_id: string,
|
|
566
|
+
update: (interaction: SessionAgentInteraction) => SessionAgentInteraction,
|
|
567
|
+
): SessionAgentInteraction[] {
|
|
568
|
+
return (tool.interactions ?? []).map((item) =>
|
|
569
|
+
item.interaction_id === interaction_id ? update(item) : item,
|
|
570
|
+
);
|
|
571
|
+
}
|
|
572
|
+
|
|
347
573
|
/** 为 Message 终止原因创建最后一个 Error Part。 */
|
|
348
574
|
function create_terminal_error_part(
|
|
349
575
|
parts: readonly SessionAgentMessagePart[],
|
|
@@ -352,10 +578,7 @@ function create_terminal_error_part(
|
|
|
352
578
|
): SessionAgentErrorPart {
|
|
353
579
|
return {
|
|
354
580
|
part_id: `error:${generate_id()}`,
|
|
355
|
-
sequence: parts
|
|
356
|
-
(sequence, part) => Math.max(sequence, part.sequence + 1),
|
|
357
|
-
1,
|
|
358
|
-
),
|
|
581
|
+
sequence: next_agent_part_sequence(parts),
|
|
359
582
|
type: "error",
|
|
360
583
|
scope: "turn",
|
|
361
584
|
code,
|
|
@@ -364,15 +587,3 @@ function create_terminal_error_part(
|
|
|
364
587
|
};
|
|
365
588
|
}
|
|
366
589
|
|
|
367
|
-
/** 返回相较上次稳定检查点新增或变化的 Parts。 */
|
|
368
|
-
function resolve_changed_parts(
|
|
369
|
-
current_parts: readonly SessionAgentMessagePart[],
|
|
370
|
-
next_parts: readonly SessionAgentMessagePart[],
|
|
371
|
-
): SessionAgentMessagePart[] {
|
|
372
|
-
const current_by_id = new Map(
|
|
373
|
-
current_parts.map((part) => [part.part_id, JSON.stringify(part)]),
|
|
374
|
-
);
|
|
375
|
-
return next_parts.filter(
|
|
376
|
-
(part) => current_by_id.get(part.part_id) !== JSON.stringify(part),
|
|
377
|
-
);
|
|
378
|
-
}
|