@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
|
@@ -1,307 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 基于稳定 Part 游标的自适应上下文策略。
|
|
3
|
-
*
|
|
4
|
-
* Message 仍是 canonical 持久化聚合,Part 是上下文取舍与摘要边界。策略只写自己的
|
|
5
|
-
* checkpoint 派生表,不修改 Message;单个 Agent Message 很大时也可以在
|
|
6
|
-
* Message 内部形成摘要边界。
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
import type {
|
|
10
|
-
SessionAgentMessagePart,
|
|
11
|
-
SessionMessage,
|
|
12
|
-
SessionUserMessagePart,
|
|
13
|
-
} from "@downcity/type";
|
|
14
|
-
import { generate_id } from "@/utils/Id.js";
|
|
15
|
-
import { build_text_model_messages, generate_model } from "@executor/model/ModelGenerate.js";
|
|
16
|
-
import { session_messages_to_model_messages } from "@/executor/messages/SessionModelMessages.js";
|
|
17
|
-
import type { SessionContextPolicy } from "@/types/session/SessionContextPolicy.js";
|
|
18
|
-
import type {
|
|
19
|
-
AdaptivePartCheckpointRow,
|
|
20
|
-
StablePartCandidate,
|
|
21
|
-
} from "@/types/session/AdaptivePartContextPolicy.js";
|
|
22
|
-
import {
|
|
23
|
-
build_initial_session_summary_prompt,
|
|
24
|
-
build_updated_session_summary_prompt,
|
|
25
|
-
SESSION_SUMMARY_SYSTEM_PROMPT,
|
|
26
|
-
} from "@/session/composer/policies/SessionSummaryPrompts.js";
|
|
27
|
-
|
|
28
|
-
const POLICY_VERSION = 1;
|
|
29
|
-
const SUMMARY_MAX_OUTPUT_TOKENS = 4_000;
|
|
30
|
-
const CHECKPOINT_TABLE = "composer_adaptive_part_checkpoints";
|
|
31
|
-
|
|
32
|
-
/** 默认 Part 级上下文策略。 */
|
|
33
|
-
export class AdaptivePartContextPolicy implements SessionContextPolicy {
|
|
34
|
-
readonly name = "adaptive_part";
|
|
35
|
-
|
|
36
|
-
/** 创建当前策略独享的 checkpoint 表。 */
|
|
37
|
-
async initialize(input: Parameters<SessionContextPolicy["initialize"]>[0]): Promise<void> {
|
|
38
|
-
await input.storage.transaction((transaction) => {
|
|
39
|
-
transaction.execute(`
|
|
40
|
-
CREATE TABLE IF NOT EXISTS ${CHECKPOINT_TABLE} (
|
|
41
|
-
checkpoint_id TEXT PRIMARY KEY,
|
|
42
|
-
through_message_id TEXT NOT NULL REFERENCES messages(message_id) ON DELETE CASCADE,
|
|
43
|
-
through_message_sequence INTEGER NOT NULL,
|
|
44
|
-
through_part_sequence INTEGER NOT NULL,
|
|
45
|
-
summary TEXT NOT NULL,
|
|
46
|
-
policy_version INTEGER NOT NULL,
|
|
47
|
-
created_at INTEGER NOT NULL,
|
|
48
|
-
UNIQUE(through_message_sequence, through_part_sequence, policy_version)
|
|
49
|
-
)
|
|
50
|
-
`);
|
|
51
|
-
});
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
/** 返回显式摘要 system block 与 Part 边界后的 canonical 历史。 */
|
|
55
|
-
async resolve(input: Parameters<SessionContextPolicy["resolve"]>[0]) {
|
|
56
|
-
const checkpoint = await this.read_latest_checkpoint(input.storage);
|
|
57
|
-
const canonical = await input.storage.list_messages();
|
|
58
|
-
const tail = checkpoint
|
|
59
|
-
? slice_messages_after_checkpoint(canonical, checkpoint)
|
|
60
|
-
: canonical;
|
|
61
|
-
return {
|
|
62
|
-
messages: await session_messages_to_model_messages(tail, input.project_root),
|
|
63
|
-
...(checkpoint?.summary.trim()
|
|
64
|
-
? {
|
|
65
|
-
system_blocks: [{
|
|
66
|
-
source: "session" as const,
|
|
67
|
-
name: "context-summary",
|
|
68
|
-
content: `<session-context-summary>\n${checkpoint.summary}\n</session-context-summary>`,
|
|
69
|
-
}],
|
|
70
|
-
}
|
|
71
|
-
: {}),
|
|
72
|
-
diagnostics: {
|
|
73
|
-
policy_name: this.name,
|
|
74
|
-
...(canonical.at(-1)?.sequence !== undefined
|
|
75
|
-
? { through_sequence: canonical.at(-1)?.sequence }
|
|
76
|
-
: {}),
|
|
77
|
-
...(checkpoint
|
|
78
|
-
? { through_part_sequence: checkpoint.through_part_sequence }
|
|
79
|
-
: {}),
|
|
80
|
-
derived: Boolean(checkpoint),
|
|
81
|
-
...(checkpoint ? { derivation_id: checkpoint.checkpoint_id } : {}),
|
|
82
|
-
},
|
|
83
|
-
};
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
/** 上下文压力出现时,按体积选择较旧稳定 Part 并合并进累计摘要。 */
|
|
87
|
-
async recover(input: Parameters<SessionContextPolicy["recover"]>[0]): Promise<boolean> {
|
|
88
|
-
if (!input.model) return false;
|
|
89
|
-
const previous = await this.read_latest_checkpoint(input.storage);
|
|
90
|
-
const canonical = await input.storage.list_messages();
|
|
91
|
-
const candidates = collect_stable_parts(canonical, previous);
|
|
92
|
-
const compact_parts = select_compact_parts(candidates);
|
|
93
|
-
const boundary = compact_parts.at(-1);
|
|
94
|
-
if (!boundary) return false;
|
|
95
|
-
const conversation_text = compact_parts
|
|
96
|
-
.map(candidate_to_summary_text)
|
|
97
|
-
.filter(Boolean)
|
|
98
|
-
.join("\n");
|
|
99
|
-
if (!conversation_text) return false;
|
|
100
|
-
const prompt = previous?.summary.trim()
|
|
101
|
-
? build_updated_session_summary_prompt({
|
|
102
|
-
previous_summary: previous.summary,
|
|
103
|
-
conversation_text,
|
|
104
|
-
})
|
|
105
|
-
: build_initial_session_summary_prompt({ conversation_text });
|
|
106
|
-
const result = await generate_model(input.model, {
|
|
107
|
-
messages: build_text_model_messages(SESSION_SUMMARY_SYSTEM_PROMPT, prompt),
|
|
108
|
-
max_output_tokens: SUMMARY_MAX_OUTPUT_TOKENS,
|
|
109
|
-
}, {
|
|
110
|
-
request_kind: "history_compaction",
|
|
111
|
-
on_failure: input.on_model_request_failure,
|
|
112
|
-
});
|
|
113
|
-
const summary = String(result.text || "").trim();
|
|
114
|
-
if (!summary) throw new Error("Context summary model returned an empty result");
|
|
115
|
-
const checkpoint_id = `checkpoint:${generate_id()}`;
|
|
116
|
-
try {
|
|
117
|
-
await input.storage.transaction((transaction) => {
|
|
118
|
-
transaction.execute(`
|
|
119
|
-
INSERT INTO ${CHECKPOINT_TABLE} (
|
|
120
|
-
checkpoint_id, through_message_id, through_message_sequence,
|
|
121
|
-
through_part_sequence, summary, policy_version, created_at
|
|
122
|
-
) VALUES (?, ?, ?, ?, ?, ?, ?)
|
|
123
|
-
`, [
|
|
124
|
-
checkpoint_id,
|
|
125
|
-
boundary.message.message_id,
|
|
126
|
-
boundary.message.sequence,
|
|
127
|
-
boundary.part.sequence,
|
|
128
|
-
summary,
|
|
129
|
-
POLICY_VERSION,
|
|
130
|
-
Date.now(),
|
|
131
|
-
]);
|
|
132
|
-
});
|
|
133
|
-
return true;
|
|
134
|
-
} catch (error) {
|
|
135
|
-
const latest = await this.read_latest_checkpoint(input.storage);
|
|
136
|
-
if (latest && compare_position(latest, boundary) >= 0) return true;
|
|
137
|
-
throw error;
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
/** 读取当前版本位置最靠后的累计 checkpoint。 */
|
|
142
|
-
private async read_latest_checkpoint(
|
|
143
|
-
storage: Parameters<SessionContextPolicy["resolve"]>[0]["storage"],
|
|
144
|
-
): Promise<AdaptivePartCheckpointRow | null> {
|
|
145
|
-
return await storage.transaction((transaction) =>
|
|
146
|
-
transaction.get<AdaptivePartCheckpointRow>(`
|
|
147
|
-
SELECT checkpoint_id, through_message_id, through_message_sequence,
|
|
148
|
-
through_part_sequence, summary, policy_version, created_at
|
|
149
|
-
FROM ${CHECKPOINT_TABLE}
|
|
150
|
-
WHERE policy_version = ?
|
|
151
|
-
ORDER BY through_message_sequence DESC, through_part_sequence DESC
|
|
152
|
-
LIMIT 1
|
|
153
|
-
`, [POLICY_VERSION])
|
|
154
|
-
);
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
/** 收集 checkpoint 后适合进入摘要的稳定 Part。 */
|
|
159
|
-
function collect_stable_parts(
|
|
160
|
-
messages: readonly SessionMessage[],
|
|
161
|
-
checkpoint: AdaptivePartCheckpointRow | null,
|
|
162
|
-
): StablePartCandidate[] {
|
|
163
|
-
return messages.flatMap((message) => message.parts.flatMap((part) => {
|
|
164
|
-
if (checkpoint && compare_part_position(message.sequence, part.sequence, checkpoint) <= 0) {
|
|
165
|
-
return [];
|
|
166
|
-
}
|
|
167
|
-
if (!is_stable_summary_part(message, part)) return [];
|
|
168
|
-
return [{ message, part }];
|
|
169
|
-
}));
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
/** 判断 Part 是否稳定且值得占据累计摘要。 */
|
|
173
|
-
function is_stable_summary_part(
|
|
174
|
-
message: SessionMessage,
|
|
175
|
-
part: SessionUserMessagePart | SessionAgentMessagePart,
|
|
176
|
-
): boolean {
|
|
177
|
-
switch (part.type) {
|
|
178
|
-
case "reasoning":
|
|
179
|
-
case "action":
|
|
180
|
-
case "interaction":
|
|
181
|
-
return false;
|
|
182
|
-
case "tool":
|
|
183
|
-
return part.state === "completed" || part.state === "failed";
|
|
184
|
-
case "text":
|
|
185
|
-
if (message.role === "user") return true;
|
|
186
|
-
return "state" in part && part.state === "done" && message.state === "done";
|
|
187
|
-
case "context":
|
|
188
|
-
case "file":
|
|
189
|
-
case "data":
|
|
190
|
-
case "error":
|
|
191
|
-
return true;
|
|
192
|
-
default:
|
|
193
|
-
return assert_never(part);
|
|
194
|
-
}
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
/** 把单个 Part 收窄为摘要模型需要的稳定事实。 */
|
|
198
|
-
function candidate_to_summary_text(candidate: StablePartCandidate): string {
|
|
199
|
-
return JSON.stringify({
|
|
200
|
-
role: candidate.message.role,
|
|
201
|
-
message_id: candidate.message.message_id,
|
|
202
|
-
part: summary_part(candidate.part),
|
|
203
|
-
});
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
/** 删除瞬时字段并保留 Tool 调用/结果原子。 */
|
|
207
|
-
function summary_part(
|
|
208
|
-
part: SessionUserMessagePart | SessionAgentMessagePart,
|
|
209
|
-
): Record<string, unknown> {
|
|
210
|
-
switch (part.type) {
|
|
211
|
-
case "text":
|
|
212
|
-
return { type: "text", text: part.text };
|
|
213
|
-
case "context":
|
|
214
|
-
return { type: "context", tag: part.tag, context: part.context };
|
|
215
|
-
case "file":
|
|
216
|
-
return { type: "file", media_type: part.media_type, url: part.url, filename: part.filename };
|
|
217
|
-
case "data":
|
|
218
|
-
return { type: "data", data_type: part.data_type, data: part.data };
|
|
219
|
-
case "tool":
|
|
220
|
-
return {
|
|
221
|
-
type: "tool",
|
|
222
|
-
tool_name: part.tool_name,
|
|
223
|
-
input: part.input,
|
|
224
|
-
output: part.output,
|
|
225
|
-
error: part.error,
|
|
226
|
-
};
|
|
227
|
-
case "error":
|
|
228
|
-
return { type: "error", code: part.code, message: part.message };
|
|
229
|
-
case "reasoning":
|
|
230
|
-
case "action":
|
|
231
|
-
case "interaction":
|
|
232
|
-
return { type: part.type };
|
|
233
|
-
default:
|
|
234
|
-
return assert_never(part);
|
|
235
|
-
}
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
/**
|
|
239
|
-
* 选择足以释放约一半原始上下文体积的最旧 Part。
|
|
240
|
-
*
|
|
241
|
-
* 关键点(中文):Part 数量不能代表上下文压力。一个巨大 Tool/Text Part
|
|
242
|
-
* 可以独自占满窗口,因此使用送入摘要模型的序列化字符体积作为轻量估算,
|
|
243
|
-
* 并保证只有一个可用 Part 时仍能推进 checkpoint。
|
|
244
|
-
*/
|
|
245
|
-
function select_compact_parts(
|
|
246
|
-
candidates: readonly StablePartCandidate[],
|
|
247
|
-
): StablePartCandidate[] {
|
|
248
|
-
if (candidates.length === 0) return [];
|
|
249
|
-
const sizes = candidates.map((candidate) =>
|
|
250
|
-
Math.max(candidate_to_summary_text(candidate).length, 1)
|
|
251
|
-
);
|
|
252
|
-
const target_size = Math.ceil(
|
|
253
|
-
sizes.reduce((total, size) => total + size, 0) / 2,
|
|
254
|
-
);
|
|
255
|
-
let selected_size = 0;
|
|
256
|
-
let selected_count = 0;
|
|
257
|
-
while (selected_count < candidates.length && selected_size < target_size) {
|
|
258
|
-
selected_size += sizes[selected_count] ?? 0;
|
|
259
|
-
selected_count += 1;
|
|
260
|
-
}
|
|
261
|
-
return candidates.slice(0, Math.max(selected_count, 1));
|
|
262
|
-
}
|
|
263
|
-
|
|
264
|
-
/** 删除 checkpoint 以前的 Part;边界可以位于单个 Message 内部。 */
|
|
265
|
-
function slice_messages_after_checkpoint(
|
|
266
|
-
messages: readonly SessionMessage[],
|
|
267
|
-
checkpoint: AdaptivePartCheckpointRow,
|
|
268
|
-
): SessionMessage[] {
|
|
269
|
-
return messages.flatMap((message): SessionMessage[] => {
|
|
270
|
-
if (message.sequence < checkpoint.through_message_sequence) return [];
|
|
271
|
-
if (message.sequence > checkpoint.through_message_sequence) return [message];
|
|
272
|
-
const parts = message.parts.filter(
|
|
273
|
-
(part) => part.sequence > checkpoint.through_part_sequence,
|
|
274
|
-
);
|
|
275
|
-
if (parts.length === 0) return [];
|
|
276
|
-
return [{ ...message, parts } as SessionMessage];
|
|
277
|
-
});
|
|
278
|
-
}
|
|
279
|
-
|
|
280
|
-
/** 比较 canonical Part 与 checkpoint 的全局线性位置。 */
|
|
281
|
-
function compare_part_position(
|
|
282
|
-
message_sequence: number,
|
|
283
|
-
part_sequence: number,
|
|
284
|
-
checkpoint: AdaptivePartCheckpointRow,
|
|
285
|
-
): number {
|
|
286
|
-
if (message_sequence !== checkpoint.through_message_sequence) {
|
|
287
|
-
return message_sequence - checkpoint.through_message_sequence;
|
|
288
|
-
}
|
|
289
|
-
return part_sequence - checkpoint.through_part_sequence;
|
|
290
|
-
}
|
|
291
|
-
|
|
292
|
-
/** 比较 checkpoint 与候选边界。 */
|
|
293
|
-
function compare_position(
|
|
294
|
-
checkpoint: AdaptivePartCheckpointRow,
|
|
295
|
-
candidate: StablePartCandidate,
|
|
296
|
-
): number {
|
|
297
|
-
return -compare_part_position(
|
|
298
|
-
candidate.message.sequence,
|
|
299
|
-
candidate.part.sequence,
|
|
300
|
-
checkpoint,
|
|
301
|
-
);
|
|
302
|
-
}
|
|
303
|
-
|
|
304
|
-
/** canonical Part 联合类型新增成员时强制摘要策略显式选择语义。 */
|
|
305
|
-
function assert_never(value: never): never {
|
|
306
|
-
throw new Error(`Unsupported summary Session Part: ${String((value as { type?: unknown }).type)}`);
|
|
307
|
-
}
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 全量历史上下文策略。
|
|
3
|
-
*
|
|
4
|
-
* 该策略没有派生状态,适用于短会话、测试或拥有足够上下文窗口的模型。
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
import { session_messages_to_model_messages } from "@/executor/messages/SessionModelMessages.js";
|
|
8
|
-
import type { SessionContextPolicy } from "@/types/session/SessionContextPolicy.js";
|
|
9
|
-
|
|
10
|
-
/** 直接把全部 canonical Message 转换为模型历史。 */
|
|
11
|
-
export class FullHistoryContextPolicy implements SessionContextPolicy {
|
|
12
|
-
readonly name = "full_history";
|
|
13
|
-
|
|
14
|
-
/** 全量历史策略不需要创建派生表。 */
|
|
15
|
-
async initialize(): Promise<void> {}
|
|
16
|
-
|
|
17
|
-
/** 按 canonical 顺序返回完整模型历史。 */
|
|
18
|
-
async resolve(input: Parameters<SessionContextPolicy["resolve"]>[0]) {
|
|
19
|
-
const messages = await input.storage.list_messages();
|
|
20
|
-
return {
|
|
21
|
-
messages: await session_messages_to_model_messages(messages, input.project_root),
|
|
22
|
-
diagnostics: {
|
|
23
|
-
policy_name: this.name,
|
|
24
|
-
...(messages.at(-1)?.sequence !== undefined
|
|
25
|
-
? { through_sequence: messages.at(-1)?.sequence }
|
|
26
|
-
: {}),
|
|
27
|
-
derived: false,
|
|
28
|
-
},
|
|
29
|
-
};
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
/** 没有派生状态,因此无法通过恢复改变上下文。 */
|
|
33
|
-
async recover(): Promise<boolean> {
|
|
34
|
-
return false;
|
|
35
|
-
}
|
|
36
|
-
}
|
|
@@ -1,311 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Session 用户异步交互运行时。
|
|
3
|
-
*
|
|
4
|
-
* 本模块只拥有 pending waiter、超时与恢复执行;Interaction 的权威状态由
|
|
5
|
-
* SessionMessages 持久化。任何终态都必须先提交 canonical Message,再兑现等待 Promise。
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
import type { SessionMessages } from "@/session/SessionMessages.js";
|
|
9
|
-
import type {
|
|
10
|
-
RespondSessionInteractionInput,
|
|
11
|
-
SessionInteractionHandle,
|
|
12
|
-
SessionInteractionLifecycle,
|
|
13
|
-
SessionInteractionPort,
|
|
14
|
-
SessionInteractionRequest,
|
|
15
|
-
SessionInteractionResponse,
|
|
16
|
-
SessionInteractionResult,
|
|
17
|
-
SessionPendingInteraction,
|
|
18
|
-
} from "@downcity/type";
|
|
19
|
-
import type { SessionPendingInteractionRuntime } from "@/types/session/SessionInteractions.js";
|
|
20
|
-
|
|
21
|
-
/** 单个 Session 的异步用户交互入口。 */
|
|
22
|
-
export class SessionInteractions implements SessionInteractionPort, SessionInteractionLifecycle {
|
|
23
|
-
private readonly session_id: string;
|
|
24
|
-
private readonly messages: SessionMessages;
|
|
25
|
-
private readonly pending_by_id = new Map<
|
|
26
|
-
string,
|
|
27
|
-
SessionPendingInteractionRuntime
|
|
28
|
-
>();
|
|
29
|
-
|
|
30
|
-
constructor(options: {
|
|
31
|
-
/** 当前 Interaction 运行时所属 Session 标识。 */
|
|
32
|
-
session_id: string;
|
|
33
|
-
/** 当前 Session 的 canonical Message 入口。 */
|
|
34
|
-
messages: SessionMessages;
|
|
35
|
-
}) {
|
|
36
|
-
this.session_id = String(options.session_id || "").trim();
|
|
37
|
-
this.messages = options.messages;
|
|
38
|
-
if (!this.session_id) {
|
|
39
|
-
throw new Error("SessionInteractions requires a non-empty session_id");
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
/** 创建并持久化一次 Interaction,返回等待终态结果的句柄。 */
|
|
44
|
-
async request(
|
|
45
|
-
request: SessionInteractionRequest,
|
|
46
|
-
): Promise<SessionInteractionHandle> {
|
|
47
|
-
this.validate_request(request);
|
|
48
|
-
if (this.pending_by_id.has(request.interaction_id)) {
|
|
49
|
-
throw new Error(`Session Interaction is already pending: ${request.interaction_id}`);
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
let resolve_result!: (result: SessionInteractionResult) => void;
|
|
53
|
-
const result = new Promise<SessionInteractionResult>((resolve) => {
|
|
54
|
-
resolve_result = resolve;
|
|
55
|
-
});
|
|
56
|
-
const pending: SessionPendingInteractionRuntime = {
|
|
57
|
-
request: structuredClone(request),
|
|
58
|
-
resolve: resolve_result,
|
|
59
|
-
};
|
|
60
|
-
this.pending_by_id.set(request.interaction_id, pending);
|
|
61
|
-
|
|
62
|
-
try {
|
|
63
|
-
await this.messages.request_interaction(request);
|
|
64
|
-
} catch (error) {
|
|
65
|
-
this.pending_by_id.delete(request.interaction_id);
|
|
66
|
-
throw error;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
if (request.expires_at !== undefined) {
|
|
70
|
-
const delay_ms = Math.max(0, request.expires_at - Date.now());
|
|
71
|
-
const timer = setTimeout(() => {
|
|
72
|
-
void this.expire(request.interaction_id);
|
|
73
|
-
}, delay_ms);
|
|
74
|
-
if (typeof timer.unref === "function") timer.unref();
|
|
75
|
-
pending.timer = timer;
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
return {
|
|
79
|
-
interaction_id: request.interaction_id,
|
|
80
|
-
result,
|
|
81
|
-
};
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
/** 返回当前 Session 全部 pending Interaction 请求快照。 */
|
|
85
|
-
list(): SessionPendingInteraction[] {
|
|
86
|
-
return this.messages.list_pending_interactions().map((interaction) => ({
|
|
87
|
-
request: structuredClone(interaction.request),
|
|
88
|
-
}));
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
/** 保存用户响应,并在提交成功后恢复原执行。 */
|
|
92
|
-
async respond(
|
|
93
|
-
input: RespondSessionInteractionInput,
|
|
94
|
-
): Promise<SessionInteractionResult> {
|
|
95
|
-
const pending = this.require_pending(input.interaction_id);
|
|
96
|
-
this.validate_response(pending.request, input.response);
|
|
97
|
-
await this.messages.resolve_interaction(
|
|
98
|
-
input.interaction_id,
|
|
99
|
-
input.response,
|
|
100
|
-
);
|
|
101
|
-
const result: SessionInteractionResult = input.response.outcome === "denied"
|
|
102
|
-
? {
|
|
103
|
-
status: "denied",
|
|
104
|
-
interaction_id: input.interaction_id,
|
|
105
|
-
reason: extract_interaction_reason(input.response.payload),
|
|
106
|
-
}
|
|
107
|
-
: {
|
|
108
|
-
status: "resolved",
|
|
109
|
-
interaction_id: input.interaction_id,
|
|
110
|
-
response: structuredClone(input.response),
|
|
111
|
-
};
|
|
112
|
-
this.finish_pending(input.interaction_id, result);
|
|
113
|
-
return result;
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
/** 取消当前 Session 的全部 pending Interaction。 */
|
|
117
|
-
async cancel_all(
|
|
118
|
-
reason: "turn_stopped" | "session_disposed" | "runtime_interrupted",
|
|
119
|
-
): Promise<void> {
|
|
120
|
-
let first_error: unknown;
|
|
121
|
-
for (const interaction_id of [...this.pending_by_id.keys()]) {
|
|
122
|
-
const result: SessionInteractionResult = {
|
|
123
|
-
status: "cancelled",
|
|
124
|
-
interaction_id,
|
|
125
|
-
reason,
|
|
126
|
-
};
|
|
127
|
-
try {
|
|
128
|
-
await this.messages.close_interaction(interaction_id, {
|
|
129
|
-
status: "cancelled",
|
|
130
|
-
reason,
|
|
131
|
-
});
|
|
132
|
-
this.finish_pending(interaction_id, result);
|
|
133
|
-
} catch (error) {
|
|
134
|
-
first_error ??= error;
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
if (first_error) throw first_error;
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
/** 处理单个 Interaction 自动过期。 */
|
|
141
|
-
private async expire(interaction_id: string): Promise<void> {
|
|
142
|
-
if (!this.pending_by_id.has(interaction_id)) return;
|
|
143
|
-
const result: SessionInteractionResult = {
|
|
144
|
-
status: "expired",
|
|
145
|
-
interaction_id,
|
|
146
|
-
};
|
|
147
|
-
try {
|
|
148
|
-
await this.messages.close_interaction(interaction_id, {
|
|
149
|
-
status: "expired",
|
|
150
|
-
});
|
|
151
|
-
} catch {
|
|
152
|
-
return;
|
|
153
|
-
}
|
|
154
|
-
this.finish_pending(interaction_id, result);
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
/** 校验执行面提交的 Interaction 请求。 */
|
|
158
|
-
private validate_request(request: SessionInteractionRequest): void {
|
|
159
|
-
if (!String(request.interaction_id || "").trim()) {
|
|
160
|
-
throw new Error("Session Interaction requires interaction_id");
|
|
161
|
-
}
|
|
162
|
-
if (!String(request.turn_id || "").trim()) {
|
|
163
|
-
throw new Error("Session Interaction requires turn_id");
|
|
164
|
-
}
|
|
165
|
-
if (
|
|
166
|
-
request.expires_at !== undefined &&
|
|
167
|
-
(!Number.isFinite(request.expires_at) || request.expires_at < request.created_at)
|
|
168
|
-
) {
|
|
169
|
-
throw new Error("Session Interaction expires_at must not precede created_at");
|
|
170
|
-
}
|
|
171
|
-
if (!String(request.type || "").trim()) {
|
|
172
|
-
throw new Error("Session Interaction requires a non-empty type");
|
|
173
|
-
}
|
|
174
|
-
if (!request.source || typeof request.source !== "object") {
|
|
175
|
-
throw new Error("Session Interaction requires a source");
|
|
176
|
-
}
|
|
177
|
-
if (request.type === "question") {
|
|
178
|
-
const payload = request.payload as { questions?: unknown };
|
|
179
|
-
const questions = payload?.questions;
|
|
180
|
-
if (!Array.isArray(questions) || questions.length === 0) {
|
|
181
|
-
throw new Error("Question Interaction requires at least one question");
|
|
182
|
-
}
|
|
183
|
-
const question_ids = new Set<string>();
|
|
184
|
-
for (const question of questions as Array<Record<string, unknown>>) {
|
|
185
|
-
if (!String(question.question_id || "").trim()) {
|
|
186
|
-
throw new Error("Interaction question requires question_id");
|
|
187
|
-
}
|
|
188
|
-
if (question_ids.has(String(question.question_id))) {
|
|
189
|
-
throw new Error("Duplicate Interaction question_id");
|
|
190
|
-
}
|
|
191
|
-
question_ids.add(String(question.question_id));
|
|
192
|
-
if (!String(question.prompt || "").trim()) {
|
|
193
|
-
throw new Error(
|
|
194
|
-
`Interaction question requires prompt: ${question.question_id}`,
|
|
195
|
-
);
|
|
196
|
-
}
|
|
197
|
-
if (
|
|
198
|
-
question.response_type !== "text" &&
|
|
199
|
-
(!Array.isArray(question.options) || question.options.length === 0)
|
|
200
|
-
) {
|
|
201
|
-
throw new Error(
|
|
202
|
-
`Select Interaction question requires options: ${question.question_id}`,
|
|
203
|
-
);
|
|
204
|
-
}
|
|
205
|
-
if (question.options) {
|
|
206
|
-
const option_values = new Set<string>();
|
|
207
|
-
for (const option of question.options as Array<Record<string, unknown>>) {
|
|
208
|
-
if (!String(option.value || "").trim()) {
|
|
209
|
-
throw new Error(
|
|
210
|
-
`Interaction option requires value: ${question.question_id}`,
|
|
211
|
-
);
|
|
212
|
-
}
|
|
213
|
-
const option_value = String(option.value);
|
|
214
|
-
if (option_values.has(option_value)) {
|
|
215
|
-
throw new Error("Duplicate Interaction option value");
|
|
216
|
-
}
|
|
217
|
-
option_values.add(option_value);
|
|
218
|
-
}
|
|
219
|
-
}
|
|
220
|
-
}
|
|
221
|
-
}
|
|
222
|
-
}
|
|
223
|
-
|
|
224
|
-
/** 校验响应 type、问题集合与回答值。 */
|
|
225
|
-
private validate_response(
|
|
226
|
-
request: SessionInteractionRequest,
|
|
227
|
-
response: SessionInteractionResponse,
|
|
228
|
-
): void {
|
|
229
|
-
if (request.type !== response.type) {
|
|
230
|
-
throw new Error("Session Interaction response type mismatch");
|
|
231
|
-
}
|
|
232
|
-
if (response.outcome !== "resolved" && response.outcome !== "denied") {
|
|
233
|
-
throw new Error("Session Interaction response requires a valid outcome");
|
|
234
|
-
}
|
|
235
|
-
if (request.type !== "question") return;
|
|
236
|
-
const request_payload = request.payload as { questions?: unknown };
|
|
237
|
-
const response_payload = response.payload as { answers?: unknown };
|
|
238
|
-
const questions = Array.isArray(request_payload.questions)
|
|
239
|
-
? request_payload.questions as Array<Record<string, unknown>>
|
|
240
|
-
: [];
|
|
241
|
-
const response_answers = Array.isArray(response_payload?.answers)
|
|
242
|
-
? response_payload.answers as Array<Record<string, unknown>>
|
|
243
|
-
: [];
|
|
244
|
-
const answers = new Map<string, string | string[]>();
|
|
245
|
-
for (const answer of response_answers) {
|
|
246
|
-
const question_id = String(answer.question_id || "");
|
|
247
|
-
if (answers.has(question_id)) {
|
|
248
|
-
throw new Error("Duplicate Session Interaction answer");
|
|
249
|
-
}
|
|
250
|
-
answers.set(question_id, answer.value as string | string[]);
|
|
251
|
-
}
|
|
252
|
-
if (answers.size !== questions.length) {
|
|
253
|
-
throw new Error("Session Interaction answer count mismatch");
|
|
254
|
-
}
|
|
255
|
-
for (const question of questions) {
|
|
256
|
-
const question_id = String(question.question_id || "");
|
|
257
|
-
const value = answers.get(question_id);
|
|
258
|
-
if (value === undefined) {
|
|
259
|
-
throw new Error("Session Interaction answer is missing");
|
|
260
|
-
}
|
|
261
|
-
if (question.response_type === "multi_select") {
|
|
262
|
-
if (!Array.isArray(value)) {
|
|
263
|
-
throw new Error("Session Interaction answer must be an array");
|
|
264
|
-
}
|
|
265
|
-
} else if (typeof value !== "string") {
|
|
266
|
-
throw new Error("Session Interaction answer must be a string");
|
|
267
|
-
}
|
|
268
|
-
if (question.response_type !== "text") {
|
|
269
|
-
const allowed = new Set(
|
|
270
|
-
(Array.isArray(question.options) ? question.options : []).map(
|
|
271
|
-
(option) => (option as { value: string }).value,
|
|
272
|
-
),
|
|
273
|
-
);
|
|
274
|
-
const selected = Array.isArray(value) ? value : [value];
|
|
275
|
-
if (selected.some((item) => !allowed.has(item))) {
|
|
276
|
-
throw new Error("Session Interaction answer contains an invalid option");
|
|
277
|
-
}
|
|
278
|
-
}
|
|
279
|
-
}
|
|
280
|
-
}
|
|
281
|
-
|
|
282
|
-
/** 读取当前 pending Interaction 运行态。 */
|
|
283
|
-
private require_pending(
|
|
284
|
-
interaction_id: string,
|
|
285
|
-
): SessionPendingInteractionRuntime {
|
|
286
|
-
const pending = this.pending_by_id.get(interaction_id);
|
|
287
|
-
if (pending) return pending;
|
|
288
|
-
throw new Error(`Pending Session Interaction not found: ${interaction_id}`);
|
|
289
|
-
}
|
|
290
|
-
|
|
291
|
-
/** 清理运行态并兑现执行方等待 Promise。 */
|
|
292
|
-
private finish_pending(
|
|
293
|
-
interaction_id: string,
|
|
294
|
-
result: SessionInteractionResult,
|
|
295
|
-
): void {
|
|
296
|
-
const pending = this.pending_by_id.get(interaction_id);
|
|
297
|
-
if (!pending) return;
|
|
298
|
-
if (pending.timer) clearTimeout(pending.timer);
|
|
299
|
-
this.pending_by_id.delete(interaction_id);
|
|
300
|
-
pending.resolve(result);
|
|
301
|
-
}
|
|
302
|
-
}
|
|
303
|
-
|
|
304
|
-
/** 从通用响应 payload 中读取可选的人类可读拒绝原因。 */
|
|
305
|
-
function extract_interaction_reason(payload: unknown): string | undefined {
|
|
306
|
-
if (!payload || typeof payload !== "object" || Array.isArray(payload)) {
|
|
307
|
-
return undefined;
|
|
308
|
-
}
|
|
309
|
-
const reason = (payload as { reason?: unknown }).reason;
|
|
310
|
-
return typeof reason === "string" ? reason : undefined;
|
|
311
|
-
}
|