@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
|
@@ -2,11 +2,12 @@
|
|
|
2
2
|
* 单个 canonical Assistant Message 的流式写入器。
|
|
3
3
|
*
|
|
4
4
|
* Writer 直接消费 Downcity `ModelStreamEvent`,并把模型内容、Tool 状态和 Action 内容
|
|
5
|
-
* 串行写入
|
|
5
|
+
* 串行写入 Agent Message 状态与运行缓存。它不理解 UI Message 或 Provider 私有事件。
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
8
|
import type { ModelStreamEvent } from "@downcity/type";
|
|
9
|
-
import type {
|
|
9
|
+
import type { SessionAgentMessageState } from "@/session/messages/SessionAgentMessageState.js";
|
|
10
|
+
import type { SessionMessageCache } from "@/session/messages/SessionMessageCache.js";
|
|
10
11
|
import { to_session_json_value } from "@/session/messages/SessionJsonValue.js";
|
|
11
12
|
import { SessionToolPartGate } from "@/session/messages/SessionToolPartGate.js";
|
|
12
13
|
import type { SessionAgentContent } from "@downcity/type";
|
|
@@ -22,13 +23,25 @@ import type {
|
|
|
22
23
|
} from "@/types/session/SessionTool.js";
|
|
23
24
|
import { generate_id } from "@/utils/Id.js";
|
|
24
25
|
import { create_session_agent_content_part } from "@/session/messages/SessionAgentContent.js";
|
|
26
|
+
import { next_agent_part_sequence } from "@/session/messages/SessionAgentParts.js";
|
|
27
|
+
|
|
28
|
+
/** Writer 构造参数。 */
|
|
29
|
+
export interface SessionAgentMessageWriterOptions {
|
|
30
|
+
/** 当前 canonical Assistant Message 标识。 */
|
|
31
|
+
message_id: string;
|
|
32
|
+
/** Agent Message 写入状态转换器。 */
|
|
33
|
+
state: SessionAgentMessageState;
|
|
34
|
+
/** Message 运行缓存。 */
|
|
35
|
+
cache: SessionMessageCache;
|
|
36
|
+
}
|
|
25
37
|
|
|
26
38
|
/** 单个 Assistant Message 的流式 Writer。 */
|
|
27
39
|
export class SessionAgentMessageWriter {
|
|
28
40
|
/** 当前 canonical Assistant Message 标识。 */
|
|
29
41
|
readonly message_id: string;
|
|
30
42
|
|
|
31
|
-
private readonly
|
|
43
|
+
private readonly state: SessionAgentMessageState;
|
|
44
|
+
private readonly cache: SessionMessageCache;
|
|
32
45
|
private readonly content_part_ids = new Map<string, string>();
|
|
33
46
|
private readonly tool_call_ids = new Map<string, string>();
|
|
34
47
|
private readonly current_step_part_ids = new Set<string>();
|
|
@@ -39,9 +52,10 @@ export class SessionAgentMessageWriter {
|
|
|
39
52
|
private step_active = false;
|
|
40
53
|
private closed = false;
|
|
41
54
|
|
|
42
|
-
constructor(
|
|
43
|
-
this.
|
|
44
|
-
this.
|
|
55
|
+
constructor(options: SessionAgentMessageWriterOptions) {
|
|
56
|
+
this.state = options.state;
|
|
57
|
+
this.cache = options.cache;
|
|
58
|
+
this.message_id = options.message_id;
|
|
45
59
|
}
|
|
46
60
|
|
|
47
61
|
/** 建立一个独立模型 Step 的 canonical Part 作用域。 */
|
|
@@ -85,7 +99,7 @@ export class SessionAgentMessageWriter {
|
|
|
85
99
|
state: "ready",
|
|
86
100
|
input: to_session_json_value(input.input),
|
|
87
101
|
});
|
|
88
|
-
await this.
|
|
102
|
+
await this.state.checkpoint(this.message_id);
|
|
89
103
|
});
|
|
90
104
|
}
|
|
91
105
|
|
|
@@ -105,7 +119,7 @@ export class SessionAgentMessageWriter {
|
|
|
105
119
|
state: "failed",
|
|
106
120
|
error: read_tool_error(result.output),
|
|
107
121
|
});
|
|
108
|
-
await this.
|
|
122
|
+
await this.state.checkpoint(this.message_id);
|
|
109
123
|
});
|
|
110
124
|
}
|
|
111
125
|
|
|
@@ -121,7 +135,7 @@ export class SessionAgentMessageWriter {
|
|
|
121
135
|
}
|
|
122
136
|
const current = this.current_message();
|
|
123
137
|
const current_parts = current.parts.filter((part) =>
|
|
124
|
-
this.current_step_part_ids.has(part.part_id)
|
|
138
|
+
this.current_step_part_ids.has(part.part_id)
|
|
125
139
|
);
|
|
126
140
|
if (current_parts.length !== parts.length) {
|
|
127
141
|
throw this.step_snapshot_error(
|
|
@@ -137,7 +151,7 @@ export class SessionAgentMessageWriter {
|
|
|
137
151
|
this.merge_step_part(current_part, final_part, index),
|
|
138
152
|
);
|
|
139
153
|
}
|
|
140
|
-
await this.
|
|
154
|
+
await this.state.commit_step(
|
|
141
155
|
this.message_id,
|
|
142
156
|
current.parts.map((part) => merged_parts.get(part.part_id) ?? part),
|
|
143
157
|
);
|
|
@@ -150,7 +164,7 @@ export class SessionAgentMessageWriter {
|
|
|
150
164
|
await this.enqueue_write(async () => {
|
|
151
165
|
this.tool_part_gate.reject_pending("Assistant canonical step was aborted");
|
|
152
166
|
if (this.step_active) {
|
|
153
|
-
await this.
|
|
167
|
+
await this.state.rollback_projection(this.message_id);
|
|
154
168
|
this.reset_step_state();
|
|
155
169
|
}
|
|
156
170
|
});
|
|
@@ -171,7 +185,7 @@ export class SessionAgentMessageWriter {
|
|
|
171
185
|
appended_parts.push(canonical);
|
|
172
186
|
sequence += 1;
|
|
173
187
|
}
|
|
174
|
-
await this.
|
|
188
|
+
await this.state.commit_parts(this.message_id, appended_parts);
|
|
175
189
|
return appended_parts;
|
|
176
190
|
});
|
|
177
191
|
}
|
|
@@ -198,13 +212,13 @@ export class SessionAgentMessageWriter {
|
|
|
198
212
|
message: input.message,
|
|
199
213
|
recoverable: input.recoverable,
|
|
200
214
|
} satisfies SessionAgentErrorPart;
|
|
201
|
-
await this.
|
|
215
|
+
await this.state.commit_parts(this.message_id, [part]);
|
|
202
216
|
});
|
|
203
217
|
}
|
|
204
218
|
|
|
205
219
|
/** 写入一个完整 canonical Assistant Part。 */
|
|
206
220
|
async upsert_part(part: SessionAgentMessagePart): Promise<void> {
|
|
207
|
-
this.
|
|
221
|
+
this.state.project_part(this.message_id, part);
|
|
208
222
|
if (this.step_active) this.current_step_part_ids.add(part.part_id);
|
|
209
223
|
}
|
|
210
224
|
|
|
@@ -254,7 +268,7 @@ export class SessionAgentMessageWriter {
|
|
|
254
268
|
if (!event.delta) return;
|
|
255
269
|
const type = event.type === "text_delta" ? "text" : "reasoning";
|
|
256
270
|
const part_id = this.require_content_part_id(event.content_id);
|
|
257
|
-
this.
|
|
271
|
+
this.state.project_delta(
|
|
258
272
|
this.message_id,
|
|
259
273
|
part_id,
|
|
260
274
|
type,
|
|
@@ -291,11 +305,12 @@ export class SessionAgentMessageWriter {
|
|
|
291
305
|
if (!event.input_delta) return;
|
|
292
306
|
const tool_call_id = this.require_tool_call_id(event.content_id);
|
|
293
307
|
const tool = this.require_tool(tool_call_id);
|
|
294
|
-
this.
|
|
308
|
+
this.state.project_delta(
|
|
295
309
|
this.message_id,
|
|
296
310
|
tool.part_id,
|
|
297
|
-
|
|
311
|
+
"tool_input",
|
|
298
312
|
event.input_delta,
|
|
313
|
+
tool_call_id,
|
|
299
314
|
);
|
|
300
315
|
return;
|
|
301
316
|
}
|
|
@@ -313,7 +328,7 @@ export class SessionAgentMessageWriter {
|
|
|
313
328
|
|
|
314
329
|
/** 读取当前 Assistant Message 快照。 */
|
|
315
330
|
private current_message(): SessionAgentMessage {
|
|
316
|
-
const message = this.
|
|
331
|
+
const message = this.cache.get(this.message_id);
|
|
317
332
|
if (!message || message.role !== "agent") {
|
|
318
333
|
throw new Error(`Assistant Message not found: ${this.message_id}`);
|
|
319
334
|
}
|
|
@@ -389,27 +404,15 @@ export class SessionAgentMessageWriter {
|
|
|
389
404
|
`part ${index + 1} type ${current_part.type} != ${final_part.type}`,
|
|
390
405
|
);
|
|
391
406
|
}
|
|
392
|
-
if (
|
|
393
|
-
|
|
394
|
-
(final_part.type === "text" || final_part.type === "reasoning") &&
|
|
395
|
-
current_part.text !== final_part.text
|
|
396
|
-
) {
|
|
407
|
+
if (is_text_like(current_part) && is_text_like(final_part)
|
|
408
|
+
&& current_part.text !== final_part.text) {
|
|
397
409
|
throw this.step_snapshot_error(`part ${index + 1} text differs`);
|
|
398
410
|
}
|
|
399
|
-
if (
|
|
400
|
-
current_part.
|
|
401
|
-
final_part.type === "tool" &&
|
|
402
|
-
current_part.tool_call_id !== final_part.tool_call_id
|
|
403
|
-
) {
|
|
411
|
+
if (is_agent_part_type(current_part, "tool") && is_agent_part_type(final_part, "tool")
|
|
412
|
+
&& current_part.tool_call_id !== final_part.tool_call_id) {
|
|
404
413
|
throw this.step_snapshot_error(`part ${index + 1} tool_call_id differs`);
|
|
405
414
|
}
|
|
406
|
-
return
|
|
407
|
-
...current_part,
|
|
408
|
-
...final_part,
|
|
409
|
-
part_id: current_part.part_id,
|
|
410
|
-
sequence: current_part.sequence,
|
|
411
|
-
step_id: current_part.step_id,
|
|
412
|
-
} as SessionAgentMessagePart;
|
|
415
|
+
return merge_same_part(current_part, final_part);
|
|
413
416
|
}
|
|
414
417
|
|
|
415
418
|
/** 构造不包含正文与 Tool 输出的结构化 Step 快照错误。 */
|
|
@@ -436,10 +439,7 @@ export class SessionAgentMessageWriter {
|
|
|
436
439
|
|
|
437
440
|
/** 计算下一个不可变 Part 顺序号。 */
|
|
438
441
|
private next_part_sequence(): number {
|
|
439
|
-
return this.current_message().parts
|
|
440
|
-
(sequence, part) => Math.max(sequence, part.sequence + 1),
|
|
441
|
-
1,
|
|
442
|
-
);
|
|
442
|
+
return next_agent_part_sequence(this.current_message().parts);
|
|
443
443
|
}
|
|
444
444
|
|
|
445
445
|
/** 串行执行对当前 Assistant Message 的全部写操作。 */
|
|
@@ -459,18 +459,55 @@ export class SessionAgentMessageWriter {
|
|
|
459
459
|
`Assistant Message writer closed with status ${status}`,
|
|
460
460
|
);
|
|
461
461
|
this.reset_step_state();
|
|
462
|
-
await this.
|
|
462
|
+
await this.state.complete(this.message_id, status, error);
|
|
463
463
|
this.closed = true;
|
|
464
464
|
}
|
|
465
465
|
}
|
|
466
466
|
|
|
467
|
+
/** 文本与推理 Part 都携带可直接比较的正文。 */
|
|
468
|
+
type TextLikeAgentPart = Extract<SessionAgentMessagePart, { type: "text" | "reasoning" }>;
|
|
469
|
+
|
|
470
|
+
/** 判断 Part 是否属于指定类型。 */
|
|
471
|
+
function is_agent_part_type<T extends SessionAgentMessagePart["type"]>(
|
|
472
|
+
part: SessionAgentMessagePart,
|
|
473
|
+
type: T,
|
|
474
|
+
): part is Extract<SessionAgentMessagePart, { type: T }> {
|
|
475
|
+
return part.type === type;
|
|
476
|
+
}
|
|
477
|
+
|
|
478
|
+
/** 判断 Part 是否携带可直接比较的正文。 */
|
|
479
|
+
function is_text_like(part: SessionAgentMessagePart): part is TextLikeAgentPart {
|
|
480
|
+
return part.type === "text" || part.type === "reasoning";
|
|
481
|
+
}
|
|
482
|
+
|
|
483
|
+
/** 合并同一类型的两个 Part,只保留当前快照的规范身份字段。 */
|
|
484
|
+
function merge_same_part<T extends SessionAgentMessagePart["type"]>(
|
|
485
|
+
current: Extract<SessionAgentMessagePart, { type: T }>,
|
|
486
|
+
final: Extract<SessionAgentMessagePart, { type: T }>,
|
|
487
|
+
): Extract<SessionAgentMessagePart, { type: T }> {
|
|
488
|
+
return {
|
|
489
|
+
...current,
|
|
490
|
+
...final,
|
|
491
|
+
part_id: current.part_id,
|
|
492
|
+
sequence: current.sequence,
|
|
493
|
+
step_id: current.step_id,
|
|
494
|
+
};
|
|
495
|
+
}
|
|
496
|
+
|
|
467
497
|
/** 从 Tool 失败输出中提取稳定错误文本。 */
|
|
468
498
|
function read_tool_error(output: unknown): string {
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
for (const candidate of [result.error, result.message, result.output]) {
|
|
472
|
-
if (typeof candidate === "string" && candidate.trim()) return candidate;
|
|
473
|
-
}
|
|
499
|
+
for (const candidate of read_tool_error_candidates(output)) {
|
|
500
|
+
if (typeof candidate === "string" && candidate.trim()) return candidate;
|
|
474
501
|
}
|
|
475
502
|
return "Tool execution failed";
|
|
476
503
|
}
|
|
504
|
+
|
|
505
|
+
/** 读取 Tool 失败输出中可能携带错误文本的字段。 */
|
|
506
|
+
function read_tool_error_candidates(output: unknown): unknown[] {
|
|
507
|
+
if (typeof output !== "object" || output === null) return [];
|
|
508
|
+
return [
|
|
509
|
+
"error" in output ? output.error : undefined,
|
|
510
|
+
"message" in output ? output.message : undefined,
|
|
511
|
+
"output" in output ? output.output : undefined,
|
|
512
|
+
];
|
|
513
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* canonical Agent Message Part 的共享纯函数。
|
|
3
|
+
*
|
|
4
|
+
* Part 变更比较与顺序号计算在 Canonical Message、运行投影和流式 Writer 中含义完全一致,
|
|
5
|
+
* 只在本模块实现一次,避免同一表达式在多处漂移。
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import type { SessionAgentMessagePart } from "@downcity/type";
|
|
9
|
+
|
|
10
|
+
/** 判断两个 Part 快照是否表示同一个 canonical 版本。 */
|
|
11
|
+
export function is_same_agent_part(
|
|
12
|
+
left: SessionAgentMessagePart | undefined,
|
|
13
|
+
right: SessionAgentMessagePart,
|
|
14
|
+
): boolean {
|
|
15
|
+
return left !== undefined && JSON.stringify(left) === JSON.stringify(right);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/** 返回相较上一稳定快照新增或载荷发生变化的 Parts。 */
|
|
19
|
+
export function resolve_changed_agent_parts(
|
|
20
|
+
current: readonly SessionAgentMessagePart[],
|
|
21
|
+
next: readonly SessionAgentMessagePart[],
|
|
22
|
+
): SessionAgentMessagePart[] {
|
|
23
|
+
const current_by_id = new Map(
|
|
24
|
+
current.map((part) => [part.part_id, part]),
|
|
25
|
+
);
|
|
26
|
+
return next.filter(
|
|
27
|
+
(part) => !is_same_agent_part(current_by_id.get(part.part_id), part),
|
|
28
|
+
);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/** 计算追加到 Agent Message 末尾的下一个 Part 顺序号。 */
|
|
32
|
+
export function next_agent_part_sequence(
|
|
33
|
+
parts: readonly SessionAgentMessagePart[],
|
|
34
|
+
): number {
|
|
35
|
+
return parts.reduce(
|
|
36
|
+
(sequence, part) => Math.max(sequence, part.sequence + 1),
|
|
37
|
+
1,
|
|
38
|
+
);
|
|
39
|
+
}
|
|
@@ -9,10 +9,10 @@ import type { ModelStreamEvent } from "@downcity/type";
|
|
|
9
9
|
import {
|
|
10
10
|
SessionAgentMessageWriter,
|
|
11
11
|
SessionMessages,
|
|
12
|
-
} from "@/session/SessionMessages.js";
|
|
12
|
+
} from "@/session/messages/SessionMessages.js";
|
|
13
13
|
import type { SessionAgentContent } from "@downcity/type";
|
|
14
14
|
import type { SessionAgentMessagePart } from "@downcity/type";
|
|
15
|
-
import type { SessionAssistantOutput } from "@/types/
|
|
15
|
+
import type { SessionAssistantOutput } from "@/types/turn/SessionAssistantOutput.js";
|
|
16
16
|
import type {
|
|
17
17
|
SessionToolExecutionResult,
|
|
18
18
|
SessionToolInputReady,
|
|
@@ -0,0 +1,227 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Session 用户异步交互运行时。
|
|
3
|
+
*
|
|
4
|
+
* 关键点(中文)
|
|
5
|
+
* - 本模块只拥有 pending waiter 与恢复执行;Interaction 的权威状态由 SessionMessages 持久化。
|
|
6
|
+
* 任何终态都必须先提交 canonical Message,再兑现等待 Promise。
|
|
7
|
+
* - 原语只认识信封与 type 字符串:payload 的解释属于它的生产者。
|
|
8
|
+
* - 审批的专用入口(模式判断与决定解释)由 {@link ApprovalInteraction} 承担。
|
|
9
|
+
*
|
|
10
|
+
* Interaction 没有超时:它只能由用户响应,或随所属 Turn/Session 结束而被取消。
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
import type { SessionMessages } from "@/session/messages/SessionMessages.js";
|
|
14
|
+
import { ApprovalInteraction } from "@/session/messages/ApprovalInteraction.js";
|
|
15
|
+
import type {
|
|
16
|
+
RespondSessionInteractionInput,
|
|
17
|
+
SessionApprovalMode,
|
|
18
|
+
SessionInteractionHandle,
|
|
19
|
+
SessionInteractionLifecycle,
|
|
20
|
+
SessionInteractionPort,
|
|
21
|
+
SessionInteractionRequest,
|
|
22
|
+
SessionInteractionRequestInput,
|
|
23
|
+
SessionInteractionResponse,
|
|
24
|
+
SessionInteractionResult,
|
|
25
|
+
} from "@downcity/type";
|
|
26
|
+
import type { SessionPendingInteractionRuntime } from "@/types/session/SessionInteractions.js";
|
|
27
|
+
import { generate_id } from "@/utils/Id.js";
|
|
28
|
+
|
|
29
|
+
/** 单个 Session 的异步用户交互入口。 */
|
|
30
|
+
export class SessionInteractions implements SessionInteractionPort, SessionInteractionLifecycle {
|
|
31
|
+
/** 审批专用入口;长生命周期,每次调用只传身份与 payload。 */
|
|
32
|
+
readonly approval: ApprovalInteraction;
|
|
33
|
+
private readonly session_id: string;
|
|
34
|
+
private readonly messages: SessionMessages;
|
|
35
|
+
private readonly pending_by_id = new Map<
|
|
36
|
+
string,
|
|
37
|
+
SessionPendingInteractionRuntime
|
|
38
|
+
>();
|
|
39
|
+
|
|
40
|
+
constructor(options: {
|
|
41
|
+
/** 当前 Interaction 运行时所属 Session 标识。 */
|
|
42
|
+
session_id: string;
|
|
43
|
+
/** 当前 Session 的 canonical Message 入口。 */
|
|
44
|
+
messages: SessionMessages;
|
|
45
|
+
/** 读取当前 Session 审批模式;always-allow 在审批入口内生效。 */
|
|
46
|
+
read_approval_mode?: () => SessionApprovalMode;
|
|
47
|
+
}) {
|
|
48
|
+
this.session_id = String(options.session_id || "").trim();
|
|
49
|
+
this.messages = options.messages;
|
|
50
|
+
if (!this.session_id) {
|
|
51
|
+
throw new Error("SessionInteractions requires a non-empty session_id");
|
|
52
|
+
}
|
|
53
|
+
this.approval = new ApprovalInteraction({
|
|
54
|
+
interactions: this,
|
|
55
|
+
read_mode: options.read_approval_mode ?? (() => "ask"),
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* 创建并持久化一次 Interaction,返回等待终态结果的句柄。
|
|
61
|
+
*
|
|
62
|
+
* 关键点(中文)
|
|
63
|
+
* - 调用方只提供语义字段;`interaction_id`、`created_at` 与 `source` 在这里补齐。
|
|
64
|
+
*/
|
|
65
|
+
async request(
|
|
66
|
+
input: SessionInteractionRequestInput,
|
|
67
|
+
): Promise<SessionInteractionHandle> {
|
|
68
|
+
const request: SessionInteractionRequest = {
|
|
69
|
+
interaction_id: `interaction:${generate_id()}`,
|
|
70
|
+
turn_id: input.turn_id,
|
|
71
|
+
type: input.type,
|
|
72
|
+
source: {
|
|
73
|
+
type: input.source_type ?? "tool",
|
|
74
|
+
tool_call_id: input.tool_call_id,
|
|
75
|
+
...(input.tool_name ? { tool_name: input.tool_name } : {}),
|
|
76
|
+
},
|
|
77
|
+
...(input.title ? { title: input.title } : {}),
|
|
78
|
+
...(input.description ? { description: input.description } : {}),
|
|
79
|
+
payload: input.payload,
|
|
80
|
+
...(input.response_schema ? { response_schema: input.response_schema } : {}),
|
|
81
|
+
created_at: Date.now(),
|
|
82
|
+
};
|
|
83
|
+
this.validate_request(request);
|
|
84
|
+
if (this.pending_by_id.has(request.interaction_id)) {
|
|
85
|
+
throw new Error(`Session Interaction is already pending: ${request.interaction_id}`);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
let resolve_result!: (result: SessionInteractionResult) => void;
|
|
89
|
+
const result = new Promise<SessionInteractionResult>((resolve) => {
|
|
90
|
+
resolve_result = resolve;
|
|
91
|
+
});
|
|
92
|
+
const pending: SessionPendingInteractionRuntime = {
|
|
93
|
+
request: structuredClone(request),
|
|
94
|
+
resolve: resolve_result,
|
|
95
|
+
};
|
|
96
|
+
this.pending_by_id.set(request.interaction_id, pending);
|
|
97
|
+
|
|
98
|
+
try {
|
|
99
|
+
await this.messages.request_interaction(request);
|
|
100
|
+
} catch (error) {
|
|
101
|
+
this.pending_by_id.delete(request.interaction_id);
|
|
102
|
+
throw error;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
return {
|
|
106
|
+
interaction_id: request.interaction_id,
|
|
107
|
+
result,
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/** 返回当前 Session 全部 pending Interaction 请求快照。 */
|
|
112
|
+
list(): SessionInteractionRequest[] {
|
|
113
|
+
return this.messages.list_pending_interactions().map((interaction) => interaction.request);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/** 保存用户响应,并在提交成功后恢复原执行。 */
|
|
117
|
+
async respond(
|
|
118
|
+
input: RespondSessionInteractionInput,
|
|
119
|
+
): Promise<SessionInteractionResult> {
|
|
120
|
+
const pending = this.require_pending(input.interaction_id);
|
|
121
|
+
this.validate_response(pending.request, input.response);
|
|
122
|
+
await this.messages.resolve_interaction(
|
|
123
|
+
input.interaction_id,
|
|
124
|
+
input.response,
|
|
125
|
+
);
|
|
126
|
+
const result: SessionInteractionResult = input.response.outcome === "denied"
|
|
127
|
+
? {
|
|
128
|
+
status: "denied",
|
|
129
|
+
interaction_id: input.interaction_id,
|
|
130
|
+
reason: extract_interaction_reason(input.response.payload),
|
|
131
|
+
}
|
|
132
|
+
: {
|
|
133
|
+
status: "resolved",
|
|
134
|
+
interaction_id: input.interaction_id,
|
|
135
|
+
response: structuredClone(input.response),
|
|
136
|
+
};
|
|
137
|
+
this.finish_pending(input.interaction_id, result);
|
|
138
|
+
return result;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/** 取消当前 Session 的全部 pending Interaction。 */
|
|
142
|
+
async cancel_all(
|
|
143
|
+
reason: "turn_stopped" | "session_disposed" | "runtime_interrupted",
|
|
144
|
+
): Promise<void> {
|
|
145
|
+
let first_error: unknown;
|
|
146
|
+
for (const interaction_id of [...this.pending_by_id.keys()]) {
|
|
147
|
+
const result: SessionInteractionResult = {
|
|
148
|
+
status: "cancelled",
|
|
149
|
+
interaction_id,
|
|
150
|
+
reason,
|
|
151
|
+
};
|
|
152
|
+
try {
|
|
153
|
+
await this.messages.close_interaction(interaction_id, { reason });
|
|
154
|
+
this.finish_pending(interaction_id, result);
|
|
155
|
+
} catch (error) {
|
|
156
|
+
first_error ??= error;
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
if (first_error) throw first_error;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
/**
|
|
163
|
+
* 校验执行面提交的 Interaction 信封。
|
|
164
|
+
*
|
|
165
|
+
* 核心不认识业务类型:`payload` 的类型就是 `JsonValue`,怎么解释由它的生产者负责。
|
|
166
|
+
* 因此这里只检查信封自身,不拆业务字段。
|
|
167
|
+
*/
|
|
168
|
+
private validate_request(request: SessionInteractionRequest): void {
|
|
169
|
+
if (!String(request.interaction_id || "").trim()) {
|
|
170
|
+
throw new Error("Session Interaction requires interaction_id");
|
|
171
|
+
}
|
|
172
|
+
if (!String(request.turn_id || "").trim()) {
|
|
173
|
+
throw new Error("Session Interaction requires turn_id");
|
|
174
|
+
}
|
|
175
|
+
if (!String(request.type || "").trim()) {
|
|
176
|
+
throw new Error("Session Interaction requires a non-empty type");
|
|
177
|
+
}
|
|
178
|
+
if (!request.source || typeof request.source !== "object") {
|
|
179
|
+
throw new Error("Session Interaction requires a source");
|
|
180
|
+
}
|
|
181
|
+
if (!String(request.source.tool_call_id || "").trim()) {
|
|
182
|
+
throw new Error("Session Interaction requires the Tool Call it belongs to");
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
/** 校验响应信封:type 必须与请求一致,outcome 必须合法。 */
|
|
187
|
+
private validate_response(
|
|
188
|
+
request: SessionInteractionRequest,
|
|
189
|
+
response: SessionInteractionResponse,
|
|
190
|
+
): void {
|
|
191
|
+
if (request.type !== response.type) {
|
|
192
|
+
throw new Error("Session Interaction response type mismatch");
|
|
193
|
+
}
|
|
194
|
+
if (response.outcome !== "resolved" && response.outcome !== "denied") {
|
|
195
|
+
throw new Error("Session Interaction response requires a valid outcome");
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
/** 读取当前 pending Interaction 运行态。 */
|
|
200
|
+
private require_pending(
|
|
201
|
+
interaction_id: string,
|
|
202
|
+
): SessionPendingInteractionRuntime {
|
|
203
|
+
const pending = this.pending_by_id.get(interaction_id);
|
|
204
|
+
if (pending) return pending;
|
|
205
|
+
throw new Error(`Pending Session Interaction not found: ${interaction_id}`);
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
/** 清理运行态并兑现执行方等待 Promise。 */
|
|
209
|
+
private finish_pending(
|
|
210
|
+
interaction_id: string,
|
|
211
|
+
result: SessionInteractionResult,
|
|
212
|
+
): void {
|
|
213
|
+
const pending = this.pending_by_id.get(interaction_id);
|
|
214
|
+
if (!pending) return;
|
|
215
|
+
this.pending_by_id.delete(interaction_id);
|
|
216
|
+
pending.resolve(result);
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
/** 从通用响应 payload 中读取可选的人类可读拒绝原因。 */
|
|
221
|
+
function extract_interaction_reason(payload: unknown): string | undefined {
|
|
222
|
+
if (!payload || typeof payload !== "object" || Array.isArray(payload)) {
|
|
223
|
+
return undefined;
|
|
224
|
+
}
|
|
225
|
+
const reason = (payload as { reason?: unknown }).reason;
|
|
226
|
+
return typeof reason === "string" ? reason : undefined;
|
|
227
|
+
}
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* 避免 Tool、User Data 等外部输入污染 canonical Message。
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
import type {
|
|
8
|
+
import type { JsonValue } from "@downcity/type";
|
|
9
9
|
|
|
10
10
|
/** 把任意运行时输入转换为可持久化的 JSON 值。 */
|
|
11
11
|
export function to_session_json_value(input: unknown): JsonValue {
|
|
@@ -24,20 +24,3 @@ export function to_session_json_value(input: unknown): JsonValue {
|
|
|
24
24
|
}
|
|
25
25
|
}
|
|
26
26
|
|
|
27
|
-
/** 把任意运行时输入转换为可持久化 JSON 对象,非对象输入返回 undefined。 */
|
|
28
|
-
export function to_session_json_object(input: unknown): JsonObject | undefined {
|
|
29
|
-
if (!is_plain_object(input)) return undefined;
|
|
30
|
-
try {
|
|
31
|
-
const value = JSON.parse(JSON.stringify(input)) as unknown;
|
|
32
|
-
return is_plain_object(value) ? value as JsonObject : undefined;
|
|
33
|
-
} catch {
|
|
34
|
-
return undefined;
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
/** 判断未知值是否为普通对象。 */
|
|
39
|
-
function is_plain_object(input: unknown): input is Record<string, unknown> {
|
|
40
|
-
if (!input || typeof input !== "object" || Array.isArray(input)) return false;
|
|
41
|
-
const prototype = Object.getPrototypeOf(input);
|
|
42
|
-
return prototype === Object.prototype || prototype === null;
|
|
43
|
-
}
|