@downcity/agent 1.1.437 → 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
package/src/session/Session.ts
CHANGED
|
@@ -7,14 +7,13 @@
|
|
|
7
7
|
* - 内部使用 `SessionMessages` 管理 SQLite 中的 canonical Message 聚合。
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
|
-
import { Executor } from "@executor/Executor.js";
|
|
11
10
|
import {
|
|
12
11
|
type ModelClient,
|
|
13
12
|
read_model_context_window,
|
|
14
13
|
read_model_label,
|
|
15
|
-
type
|
|
14
|
+
type AgentTool as Tool,
|
|
16
15
|
} from "@downcity/type";
|
|
17
|
-
import { SessionMessages } from "@/session/SessionMessages.js";
|
|
16
|
+
import { SessionMessages } from "@/session/messages/SessionMessages.js";
|
|
18
17
|
import type {
|
|
19
18
|
AgentSessionConfigSnapshot,
|
|
20
19
|
AgentSessionForkInput,
|
|
@@ -32,42 +31,40 @@ import type {
|
|
|
32
31
|
RespondSessionInteractionInput,
|
|
33
32
|
SessionApprovalMode,
|
|
34
33
|
SessionInteractionResult,
|
|
35
|
-
|
|
34
|
+
SessionInteractionRequest,
|
|
36
35
|
} from "@downcity/type";
|
|
37
36
|
import type { ListSessionMessagesInput, SessionMessagePage } from "@downcity/type";
|
|
38
37
|
import type { AgentSessionPromptInput } from "@/types/sdk/AgentSessionPrompt.js";
|
|
39
38
|
import type { AgentSessionStopResult } from "@/types/sdk/AgentSessionStop.js";
|
|
40
39
|
import type { AgentSessionTurnHandle } from "@/types/sdk/AgentSessionTurn.js";
|
|
41
|
-
import { SessionEventHub } from "@/session/
|
|
40
|
+
import { SessionEventHub } from "@/session/messages/SessionEventHub.js";
|
|
42
41
|
import {
|
|
43
42
|
create_session_local_state,
|
|
44
43
|
SessionState,
|
|
45
|
-
} from "@/session/SessionState.js";
|
|
46
|
-
import { SessionLoop } from "@/session/SessionLoop.js";
|
|
47
|
-
import { SessionQueue } from "@/session/SessionQueue.js";
|
|
44
|
+
} from "@/session/loop/SessionState.js";
|
|
45
|
+
import { SessionLoop } from "@/session/loop/SessionLoop.js";
|
|
46
|
+
import { SessionQueue } from "@/session/loop/SessionQueue.js";
|
|
48
47
|
import type { SessionLocalState } from "@/types/session/SessionLocalState.js";
|
|
49
48
|
import type { SessionOptions } from "@/types/session/SessionOptions.js";
|
|
50
|
-
import type {
|
|
51
|
-
import { SessionInteractions } from "@/session/
|
|
52
|
-
import {
|
|
53
|
-
import { DefaultSessionComposer } from "@/session/DefaultSessionComposer.js";
|
|
49
|
+
import type { ToolCallContext, ToolHookSet } from "@downcity/type";
|
|
50
|
+
import { SessionInteractions } from "@/session/messages/SessionInteractions.js";
|
|
51
|
+
import { DefaultSessionComposer } from "@/session/input/composer/DefaultSessionComposer.js";
|
|
54
52
|
import type { SessionComposer } from "@/types/session/SessionComposer.js";
|
|
55
53
|
import { generate_id } from "@/utils/Id.js";
|
|
56
54
|
import { nanoid } from "nanoid";
|
|
57
|
-
import { build_session_info } from "@/session/
|
|
58
|
-
import type { SessionActionEventInput } from "@downcity/type";
|
|
55
|
+
import { build_session_info } from "@/session/storage/Browse.js";
|
|
59
56
|
import type { SessionStorage } from "@/types/store/SessionStorage.js";
|
|
60
57
|
import type {
|
|
61
58
|
AppendExternalSessionAgentMessageInput,
|
|
62
59
|
AppendExternalSessionUserMessageInput,
|
|
63
60
|
} from "@/types/session/SessionMessages.js";
|
|
64
|
-
import {
|
|
61
|
+
import { StepInput } from "@/session/input/StepInput.js";
|
|
65
62
|
import {
|
|
66
63
|
relocate_fork_message_files,
|
|
67
64
|
resolve_session_fork_messages,
|
|
68
65
|
} from "@/session/messages/SessionForkMessageFiles.js";
|
|
69
|
-
import { create_session_model_request_warning } from "@/session/
|
|
70
|
-
import type {
|
|
66
|
+
import { create_session_model_request_warning } from "@/session/messages/SessionModelRequestWarning.js";
|
|
67
|
+
import type { SessionContextAdvanceTrigger } from "@/types/session/SessionComposer.js";
|
|
71
68
|
|
|
72
69
|
/**
|
|
73
70
|
* SDK 本地 Session。
|
|
@@ -75,6 +72,10 @@ import type { SessionContextRecoveryReason } from "@/types/session/SessionContex
|
|
|
75
72
|
export class Session implements AgentSession {
|
|
76
73
|
readonly id: string;
|
|
77
74
|
readonly agent_id: string;
|
|
75
|
+
/** 当前 Agent 用户可见名称;进入工具与扩展的调用环境。 */
|
|
76
|
+
readonly agent_name: string;
|
|
77
|
+
/** 当前 Agent 一句话能力描述;进入工具与扩展的调用环境。 */
|
|
78
|
+
readonly agent_description: string;
|
|
78
79
|
/** 当前 Session 创建时绑定的 Workspace ID。 */
|
|
79
80
|
readonly workspace_id?: string;
|
|
80
81
|
/** 当前 Session 的创建来源。 */
|
|
@@ -86,17 +87,16 @@ export class Session implements AgentSession {
|
|
|
86
87
|
private readonly register_forked_session: SessionOptions["register_forked_session"];
|
|
87
88
|
private readonly get_tools: SessionOptions["get_tools"];
|
|
88
89
|
private readonly logger: SessionOptions["logger"];
|
|
89
|
-
private readonly get_managed_plugin_system_blocks: SessionOptions["get_managed_plugin_system_blocks"];
|
|
90
|
-
private readonly ensure_configured_hook?: SessionOptions["ensure_configured"];
|
|
91
90
|
private readonly composer: SessionComposer;
|
|
92
|
-
private readonly create_composer: () => SessionComposer;
|
|
93
91
|
private readonly session_messages: SessionMessages;
|
|
94
|
-
private readonly executor: Executor;
|
|
95
92
|
private readonly events: SessionEventHub;
|
|
96
93
|
private readonly session_interactions: SessionInteractions;
|
|
97
|
-
|
|
94
|
+
/** 当前执行面生效的审批模式;在 Step 检查点从 configured 同步。 */
|
|
95
|
+
private effective_approval_mode: SessionApprovalMode = "ask";
|
|
98
96
|
private readonly local_state: SessionLocalState;
|
|
99
97
|
private readonly get_workspace_env: SessionOptions["get_workspace_env"];
|
|
98
|
+
/** 读取当前 Session 绑定的 Workspace 实例。 */
|
|
99
|
+
private readonly get_workspace: SessionOptions["get_workspace"];
|
|
100
100
|
private readonly get_agent_model: SessionOptions["get_agent_model"];
|
|
101
101
|
private readonly get_hooks: SessionOptions["get_hooks"];
|
|
102
102
|
private readonly get_instruction_system_blocks:
|
|
@@ -104,7 +104,7 @@ export class Session implements AgentSession {
|
|
|
104
104
|
/** 当前 Session 的一次性初始化任务,避免缓存实例被重复恢复运行时状态。 */
|
|
105
105
|
private initialize_promise: Promise<void> | null = null;
|
|
106
106
|
/** 当前 Session 的 system snapshot 与 Step 组装边界。 */
|
|
107
|
-
private readonly
|
|
107
|
+
private readonly step_input: StepInput;
|
|
108
108
|
private readonly state: SessionState;
|
|
109
109
|
/** 当前 Session 独享的 Command FIFO。 */
|
|
110
110
|
private readonly session_queue = new SessionQueue();
|
|
@@ -114,6 +114,8 @@ export class Session implements AgentSession {
|
|
|
114
114
|
constructor(options: SessionOptions) {
|
|
115
115
|
this.id = String(options.session_id || "").trim();
|
|
116
116
|
this.agent_id = String(options.agent_id || "").trim();
|
|
117
|
+
this.agent_name = String(options.agent_name || "").trim() || this.agent_id;
|
|
118
|
+
this.agent_description = String(options.agent_description || "").trim();
|
|
117
119
|
this.workspace_id = String(options.workspace_id || "").trim() || undefined;
|
|
118
120
|
this.origin = options.origin;
|
|
119
121
|
this.workspace_path = String(options.workspace_path || "").trim();
|
|
@@ -123,14 +125,11 @@ export class Session implements AgentSession {
|
|
|
123
125
|
this.get_tools = options.get_tools;
|
|
124
126
|
this.logger = options.logger;
|
|
125
127
|
this.get_workspace_env = options.get_workspace_env;
|
|
128
|
+
this.get_workspace = options.get_workspace;
|
|
126
129
|
this.get_agent_model = options.get_agent_model;
|
|
127
130
|
this.get_hooks = options.get_hooks;
|
|
128
131
|
this.get_instruction_system_blocks = options.get_instruction_system_blocks;
|
|
129
|
-
this.
|
|
130
|
-
this.ensure_configured_hook = options.ensure_configured;
|
|
131
|
-
this.create_composer = options.create_composer ||
|
|
132
|
-
(() => new DefaultSessionComposer());
|
|
133
|
-
this.composer = this.create_composer();
|
|
132
|
+
this.composer = options.composer ?? new DefaultSessionComposer();
|
|
134
133
|
if (!this.id) {
|
|
135
134
|
throw new Error("Session requires a non-empty session_id");
|
|
136
135
|
}
|
|
@@ -153,14 +152,14 @@ export class Session implements AgentSession {
|
|
|
153
152
|
this.session_interactions = new SessionInteractions({
|
|
154
153
|
session_id: this.id,
|
|
155
154
|
messages: this.session_messages,
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
session_id: this.id,
|
|
159
|
-
interactions: this.session_interactions,
|
|
155
|
+
// 审批入口读执行面当前模式;configured 与 effective 的区别保留。
|
|
156
|
+
read_approval_mode: () => this.effective_approval_mode,
|
|
160
157
|
});
|
|
161
158
|
this.local_state = create_session_local_state();
|
|
162
|
-
this.
|
|
159
|
+
this.step_input = new StepInput({
|
|
163
160
|
agent_id: this.agent_id,
|
|
161
|
+
agent_name: this.agent_name,
|
|
162
|
+
agent_description: this.agent_description,
|
|
164
163
|
session_id: this.id,
|
|
165
164
|
session_origin: this.origin,
|
|
166
165
|
workspace_path: this.workspace_path,
|
|
@@ -171,14 +170,13 @@ export class Session implements AgentSession {
|
|
|
171
170
|
get_instruction_system_blocks: this.get_instruction_system_blocks,
|
|
172
171
|
get_hooks: this.get_hooks,
|
|
173
172
|
get_workspace_env: this.get_workspace_env,
|
|
174
|
-
|
|
173
|
+
get_workspace: this.get_workspace,
|
|
175
174
|
get_model: () => this.get_model(),
|
|
176
175
|
get_model_context_window: () => this.get_model_context_window(),
|
|
177
176
|
get_created_at: () => this.local_state.created_at,
|
|
178
177
|
get_timezone: () => this.local_state.timezone,
|
|
179
178
|
logger: this.logger,
|
|
180
179
|
});
|
|
181
|
-
this.executor = this.create_executor();
|
|
182
180
|
this.state = new SessionState({
|
|
183
181
|
agent_id: this.agent_id,
|
|
184
182
|
session_id: this.id,
|
|
@@ -186,11 +184,6 @@ export class Session implements AgentSession {
|
|
|
186
184
|
store: this.store,
|
|
187
185
|
state: this.local_state,
|
|
188
186
|
logger: this.logger,
|
|
189
|
-
ensure_configured_hook: this.ensure_configured_hook
|
|
190
|
-
? async () => {
|
|
191
|
-
await this.ensure_configured_hook?.(this);
|
|
192
|
-
}
|
|
193
|
-
: undefined,
|
|
194
187
|
get_model: () => this.get_model(),
|
|
195
188
|
publish_event: (event) => {
|
|
196
189
|
this.events.publish(event);
|
|
@@ -200,17 +193,19 @@ export class Session implements AgentSession {
|
|
|
200
193
|
session_id: this.id,
|
|
201
194
|
session_origin: this.origin,
|
|
202
195
|
workspace_path: this.workspace_path,
|
|
203
|
-
|
|
196
|
+
step_input: this.step_input,
|
|
197
|
+
advance_context: async (trigger) => await this.advance_context(trigger),
|
|
204
198
|
maintain_context: async () => {
|
|
205
|
-
await this.
|
|
199
|
+
await this.advance_context("usage_pressure");
|
|
206
200
|
},
|
|
207
201
|
state: this.state,
|
|
208
202
|
events: this.events,
|
|
209
203
|
logger: this.logger,
|
|
210
204
|
messages: this.session_messages,
|
|
211
205
|
interactions: this.session_interactions,
|
|
212
|
-
shell_approval_gateway: this.shell_approval_adapter,
|
|
213
206
|
queue: this.session_queue,
|
|
207
|
+
get_hooks: this.get_hooks,
|
|
208
|
+
create_call_context: (input) => this.create_turn_call_context(input),
|
|
214
209
|
});
|
|
215
210
|
}
|
|
216
211
|
|
|
@@ -221,13 +216,11 @@ export class Session implements AgentSession {
|
|
|
221
216
|
if (!this.initialize_promise) {
|
|
222
217
|
this.initialize_promise = (async () => {
|
|
223
218
|
await Promise.all([
|
|
224
|
-
this.
|
|
219
|
+
this.step_input.initialize(),
|
|
225
220
|
this.session_messages.initialize(),
|
|
226
221
|
this.state.initialize(),
|
|
227
222
|
]);
|
|
228
|
-
this.
|
|
229
|
-
this.state.get_approval_mode(),
|
|
230
|
-
);
|
|
223
|
+
this.effective_approval_mode = this.state.get_approval_mode();
|
|
231
224
|
})();
|
|
232
225
|
}
|
|
233
226
|
const initialize_promise = this.initialize_promise;
|
|
@@ -246,23 +239,23 @@ export class Session implements AgentSession {
|
|
|
246
239
|
* 把当前 Session 首次生成后固定的完整 system 显式固化到 instruction.md。
|
|
247
240
|
*
|
|
248
241
|
* 关键点(中文)
|
|
249
|
-
* - 包含 instruction、SDK core、
|
|
242
|
+
* - 包含 instruction、SDK core、Power system 与 Session context。
|
|
250
243
|
* - 多个 system block 按原顺序合并为一个 Markdown 文档。
|
|
251
244
|
*/
|
|
252
245
|
async snapshot(): Promise<void> {
|
|
253
|
-
await this.
|
|
246
|
+
await this.step_input.snapshot();
|
|
254
247
|
}
|
|
255
248
|
|
|
256
249
|
/**
|
|
257
|
-
* 使用 Agent 当前 instruction 与
|
|
250
|
+
* 使用 Agent 当前 instruction 与 Power 重新生成一次完整 system。
|
|
258
251
|
*
|
|
259
252
|
* 关键点(中文)
|
|
260
|
-
* - 只替换内存 snapshot,不改变
|
|
253
|
+
* - 只替换内存 snapshot,不改变 Power execution view。
|
|
261
254
|
* - instruction.md 已存在时同步覆盖;不存在时不自动创建。
|
|
262
255
|
* - 当前已经发出的 provider 请求不受影响,后续 step 使用新 snapshot。
|
|
263
256
|
*/
|
|
264
257
|
async syncshot(): Promise<void> {
|
|
265
|
-
await this.
|
|
258
|
+
await this.step_input.syncshot();
|
|
266
259
|
}
|
|
267
260
|
|
|
268
261
|
/**
|
|
@@ -345,7 +338,7 @@ export class Session implements AgentSession {
|
|
|
345
338
|
execute: async () => {
|
|
346
339
|
if (model_result) this.state.apply_model_config(model_result.config);
|
|
347
340
|
if (security_changed && next_approval_mode) {
|
|
348
|
-
this.
|
|
341
|
+
this.effective_approval_mode = next_approval_mode;
|
|
349
342
|
}
|
|
350
343
|
},
|
|
351
344
|
...(completion ? { completion } : {}),
|
|
@@ -361,7 +354,7 @@ export class Session implements AgentSession {
|
|
|
361
354
|
* 追加一条新的 Session prompt。
|
|
362
355
|
*/
|
|
363
356
|
async prompt(input: AgentSessionPromptInput): Promise<AgentSessionTurnHandle> {
|
|
364
|
-
await this.
|
|
357
|
+
await this.step_input.initialize();
|
|
365
358
|
return await this.session_loop.prompt(input);
|
|
366
359
|
}
|
|
367
360
|
|
|
@@ -382,7 +375,7 @@ export class Session implements AgentSession {
|
|
|
382
375
|
}
|
|
383
376
|
|
|
384
377
|
/** 列出当前 Session 正在等待用户响应的 Interaction。 */
|
|
385
|
-
async interactions(): Promise<
|
|
378
|
+
async interactions(): Promise<SessionInteractionRequest[]> {
|
|
386
379
|
return this.session_interactions.list();
|
|
387
380
|
}
|
|
388
381
|
|
|
@@ -391,11 +384,11 @@ export class Session implements AgentSession {
|
|
|
391
384
|
const active_turn_id = this.session_loop.current_turn_id();
|
|
392
385
|
return {
|
|
393
386
|
session_id: this.id,
|
|
394
|
-
state: active_turn_id || this.
|
|
387
|
+
state: active_turn_id || this.session_loop.is_executing() ? "running" : "idle",
|
|
395
388
|
...(active_turn_id ? { active_turn_id } : {}),
|
|
396
389
|
security: {
|
|
397
390
|
approval_mode: this.state.get_approval_mode(),
|
|
398
|
-
effective_approval_mode: this.
|
|
391
|
+
effective_approval_mode: this.effective_approval_mode,
|
|
399
392
|
},
|
|
400
393
|
};
|
|
401
394
|
}
|
|
@@ -460,18 +453,21 @@ export class Session implements AgentSession {
|
|
|
460
453
|
* 读取当前 session 生效的 system 快照。
|
|
461
454
|
*/
|
|
462
455
|
async system(): Promise<AgentSessionSystemSnapshot> {
|
|
463
|
-
return await this.
|
|
456
|
+
return await this.step_input.read_system();
|
|
464
457
|
}
|
|
465
458
|
|
|
466
459
|
/**
|
|
467
460
|
* 返回当前 session 是否正在执行。
|
|
468
461
|
*/
|
|
469
462
|
is_executing(): boolean {
|
|
470
|
-
return this.session_loop.is_active() || this.
|
|
463
|
+
return this.session_loop.is_active() || this.session_loop.is_executing();
|
|
471
464
|
}
|
|
472
465
|
|
|
473
466
|
/**
|
|
474
467
|
* 从当前 session 创建一个分叉会话。
|
|
468
|
+
*
|
|
469
|
+
* 复制历史与附件是分叉 Session 自身的建立过程,因此 fork 的 Action 只记录在新 Session
|
|
470
|
+
* 时间线末尾,源 Session 不留下任何痕迹;失败时直接抛错,由调用方决定半成品 Session 的去留。
|
|
475
471
|
*/
|
|
476
472
|
async fork(input?: AgentSessionForkInput | string): Promise<this> {
|
|
477
473
|
const message_id = typeof input === "string"
|
|
@@ -487,48 +483,29 @@ export class Session implements AgentSession {
|
|
|
487
483
|
include_message,
|
|
488
484
|
})
|
|
489
485
|
: messages;
|
|
490
|
-
const
|
|
491
|
-
|
|
492
|
-
|
|
486
|
+
const forked = this.create_fork_session(
|
|
487
|
+
`fork-${Date.now()}-${nanoid(8)}`,
|
|
488
|
+
);
|
|
489
|
+
await forked.initialize();
|
|
490
|
+
const session_config = this.state.get_config();
|
|
491
|
+
if (session_config.model) {
|
|
492
|
+
const forked_model = await forked.state.set_model(session_config.model);
|
|
493
|
+
forked.state.apply_model_config(forked_model.config);
|
|
494
|
+
}
|
|
495
|
+
const approval_mode = this.state.get_approval_mode();
|
|
496
|
+
await forked.state.set_approval_mode(approval_mode);
|
|
497
|
+
forked.effective_approval_mode = approval_mode;
|
|
498
|
+
const relocated_messages = await relocate_fork_message_files(fork_messages, this.store.attachments, forked.store.attachments);
|
|
499
|
+
await forked.session_messages.import_messages(relocated_messages);
|
|
500
|
+
await forked.session_messages.persist_action({
|
|
501
|
+
action_id: `history-fork:${forked.id}:${Date.now()}:${nanoid(8)}`,
|
|
493
502
|
action_type: "history-fork",
|
|
494
|
-
title: "
|
|
495
|
-
description: `
|
|
496
|
-
status: "
|
|
503
|
+
title: "Session messages forked",
|
|
504
|
+
description: `Copied ${String(fork_messages.length)} messages from session ${this.id}.`,
|
|
505
|
+
status: "completed",
|
|
497
506
|
});
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
`fork-${Date.now()}-${nanoid(8)}`,
|
|
501
|
-
);
|
|
502
|
-
await forked.initialize();
|
|
503
|
-
const session_config = this.state.get_config();
|
|
504
|
-
if (session_config.model) {
|
|
505
|
-
const forked_model = await forked.state.set_model(session_config.model);
|
|
506
|
-
forked.state.apply_model_config(forked_model.config);
|
|
507
|
-
}
|
|
508
|
-
const approval_mode = this.state.get_approval_mode();
|
|
509
|
-
await forked.state.set_approval_mode(approval_mode);
|
|
510
|
-
forked.shell_approval_adapter.set_effective_mode(approval_mode);
|
|
511
|
-
const relocated_messages = await relocate_fork_message_files(fork_messages, this.store.attachments, forked.store.attachments);
|
|
512
|
-
await forked.session_messages.import_messages(relocated_messages);
|
|
513
|
-
this.register_forked_session(forked);
|
|
514
|
-
await this.emit_action_event({
|
|
515
|
-
action_id,
|
|
516
|
-
action_type: "history-fork",
|
|
517
|
-
title: "Session messages forked",
|
|
518
|
-
description: `Created ${forked.id} with ${String(fork_messages.length)} messages.`,
|
|
519
|
-
status: "completed",
|
|
520
|
-
});
|
|
521
|
-
return forked;
|
|
522
|
-
} catch (error) {
|
|
523
|
-
await this.emit_action_event({
|
|
524
|
-
action_id,
|
|
525
|
-
action_type: "history-fork",
|
|
526
|
-
title: "Session messages fork failed",
|
|
527
|
-
description: error instanceof Error ? error.message : String(error),
|
|
528
|
-
status: "failed",
|
|
529
|
-
});
|
|
530
|
-
throw error;
|
|
531
|
-
}
|
|
507
|
+
this.register_forked_session(forked);
|
|
508
|
+
return forked;
|
|
532
509
|
}
|
|
533
510
|
|
|
534
511
|
/**
|
|
@@ -539,7 +516,6 @@ export class Session implements AgentSession {
|
|
|
539
516
|
this.runtime_port = create_runtime_session_port({
|
|
540
517
|
session_id: this.id,
|
|
541
518
|
get_model: () => this.get_model(),
|
|
542
|
-
get_executor: () => this.executor,
|
|
543
519
|
messages: async () => await this.session_messages.list_history_messages(),
|
|
544
520
|
prompt: async (input) => await this.prompt(input),
|
|
545
521
|
stop: async () => await this.stop(),
|
|
@@ -565,13 +541,40 @@ export class Session implements AgentSession {
|
|
|
565
541
|
* 在执行前确保 session 已完成初始化与宿主装配。
|
|
566
542
|
*/
|
|
567
543
|
async ensure_ready_for_execution(): Promise<void> {
|
|
568
|
-
await this.
|
|
544
|
+
await this.step_input.initialize();
|
|
569
545
|
await this.state.ensure_ready_for_execution();
|
|
570
546
|
}
|
|
571
547
|
|
|
548
|
+
/** 构造当前 Turn 的调用环境快照。 */
|
|
549
|
+
private create_turn_call_context(input: {
|
|
550
|
+
/** 当前 Turn 稳定标识。 */
|
|
551
|
+
readonly turn_id: string;
|
|
552
|
+
/** 当前 Turn 的取消信号。 */
|
|
553
|
+
readonly abort_signal: AbortSignal;
|
|
554
|
+
}): ToolCallContext {
|
|
555
|
+
const workspace = this.get_workspace();
|
|
556
|
+
return Object.freeze({
|
|
557
|
+
agent_id: this.agent_id,
|
|
558
|
+
agent_name: this.agent_name,
|
|
559
|
+
agent_description: this.agent_description,
|
|
560
|
+
agent_instructions: Object.freeze(
|
|
561
|
+
this.get_instruction_system_blocks().map((block) => block.content),
|
|
562
|
+
),
|
|
563
|
+
session_id: this.id,
|
|
564
|
+
session_origin: this.origin,
|
|
565
|
+
...(workspace ? { workspace } : {}),
|
|
566
|
+
turn_id: input.turn_id,
|
|
567
|
+
abort_signal: input.abort_signal,
|
|
568
|
+
interactions: this.session_interactions,
|
|
569
|
+
workspace_env: Object.freeze({ ...this.get_workspace_env() }),
|
|
570
|
+
});
|
|
571
|
+
}
|
|
572
|
+
|
|
572
573
|
private create_fork_session(session_id: string): this {
|
|
573
574
|
return this.create_child_session({
|
|
574
575
|
agent_id: this.agent_id,
|
|
576
|
+
agent_name: this.agent_name,
|
|
577
|
+
agent_description: this.agent_description,
|
|
575
578
|
workspace_path: this.workspace_path,
|
|
576
579
|
...(this.workspace_id ? { workspace_id: this.workspace_id } : {}),
|
|
577
580
|
origin: this.origin,
|
|
@@ -581,14 +584,13 @@ export class Session implements AgentSession {
|
|
|
581
584
|
session_id: session_id,
|
|
582
585
|
get_tools: this.get_tools,
|
|
583
586
|
logger: this.logger,
|
|
584
|
-
instruction_system_blocks: this.
|
|
587
|
+
instruction_system_blocks: this.step_input.instruction_blocks(),
|
|
585
588
|
get_instruction_system_blocks: this.get_instruction_system_blocks,
|
|
586
589
|
get_workspace_env: this.get_workspace_env,
|
|
590
|
+
get_workspace: this.get_workspace,
|
|
587
591
|
get_hooks: this.get_hooks,
|
|
588
|
-
get_managed_plugin_system_blocks: this.get_managed_plugin_system_blocks,
|
|
589
|
-
ensure_configured: this.ensure_configured_hook,
|
|
590
592
|
get_agent_model: this.get_agent_model,
|
|
591
|
-
|
|
593
|
+
composer: this.composer,
|
|
592
594
|
});
|
|
593
595
|
}
|
|
594
596
|
|
|
@@ -606,40 +608,87 @@ export class Session implements AgentSession {
|
|
|
606
608
|
return new session_class(options) as this;
|
|
607
609
|
}
|
|
608
610
|
|
|
609
|
-
/**
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
611
|
+
/**
|
|
612
|
+
* 让 Composer 尝试推进派生上下文状态。
|
|
613
|
+
*
|
|
614
|
+
* 上下文推进是用户可见的 Session 操作,因此结果记录为 Action:写入派生边界时记为
|
|
615
|
+
* completed,抛错时记为 failed。Composer 判定没有可推进区间时返回 false,此时不产生
|
|
616
|
+
* Action,避免空操作污染时间线。
|
|
617
|
+
*/
|
|
618
|
+
private async advance_context(
|
|
619
|
+
trigger: SessionContextAdvanceTrigger,
|
|
620
|
+
): Promise<boolean> {
|
|
621
|
+
const turn_id = this.session_loop.current_turn_id();
|
|
622
|
+
const action_id = `context-compaction:${this.id}:${generate_id()}`;
|
|
623
|
+
try {
|
|
624
|
+
const advanced = await this.composer.advance_context({
|
|
625
|
+
session: this.step_input.identity(),
|
|
626
|
+
model: this.get_model(),
|
|
627
|
+
history: await this.store.list_messages(),
|
|
628
|
+
derived: this.store.derived_store(this.composer.name),
|
|
629
|
+
trigger,
|
|
630
|
+
on_model_request_failure: (notice) => {
|
|
631
|
+
this.events.publish(create_session_model_request_warning({
|
|
632
|
+
session_id: this.id,
|
|
633
|
+
turn_id: this.session_loop.current_turn_id(),
|
|
634
|
+
notice,
|
|
635
|
+
}));
|
|
636
|
+
},
|
|
637
|
+
});
|
|
638
|
+
if (advanced) {
|
|
639
|
+
await this.record_compaction_action({
|
|
640
|
+
action_id,
|
|
641
|
+
turn_id,
|
|
642
|
+
status: "completed",
|
|
643
|
+
title: "Session context compacted",
|
|
644
|
+
description: "Older stable parts were folded into the context summary.",
|
|
645
|
+
});
|
|
646
|
+
}
|
|
647
|
+
return advanced;
|
|
648
|
+
} catch (error) {
|
|
649
|
+
await this.record_compaction_action({
|
|
650
|
+
action_id,
|
|
651
|
+
turn_id,
|
|
652
|
+
status: "failed",
|
|
653
|
+
title: "Session context compaction failed",
|
|
654
|
+
description: error instanceof Error ? error.message : String(error),
|
|
655
|
+
});
|
|
656
|
+
throw error;
|
|
657
|
+
}
|
|
624
658
|
}
|
|
625
659
|
|
|
626
|
-
/**
|
|
627
|
-
private async
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
660
|
+
/** 记录一次上下文压缩结果;Action 观测失败不能改变压缩本身的执行结果。 */
|
|
661
|
+
private async record_compaction_action(input: {
|
|
662
|
+
/** 本次压缩生命周期的稳定标识。 */
|
|
663
|
+
action_id: string;
|
|
664
|
+
/** 压缩所属 Turn;独立的 Session 压缩可以省略。 */
|
|
665
|
+
turn_id?: string;
|
|
666
|
+
/** 压缩结果状态。 */
|
|
667
|
+
status: "completed" | "failed";
|
|
668
|
+
/** Action 展示标题。 */
|
|
669
|
+
title: string;
|
|
670
|
+
/** Action 展示描述。 */
|
|
671
|
+
description?: string;
|
|
672
|
+
}): Promise<void> {
|
|
673
|
+
try {
|
|
674
|
+
await this.session_messages.persist_action({
|
|
675
|
+
action_id: input.action_id,
|
|
676
|
+
action_type: "context-compaction",
|
|
677
|
+
...(input.turn_id ? { turn_id: input.turn_id } : {}),
|
|
678
|
+
title: input.title,
|
|
679
|
+
...(input.description ? { description: input.description } : {}),
|
|
680
|
+
status: input.status,
|
|
681
|
+
});
|
|
682
|
+
} catch (error) {
|
|
683
|
+
try {
|
|
684
|
+
await this.logger.log("warn", "[agent] context compaction action failed", {
|
|
637
685
|
session_id: this.id,
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
})
|
|
641
|
-
}
|
|
642
|
-
|
|
686
|
+
action_id: input.action_id,
|
|
687
|
+
error: error instanceof Error ? error.message : String(error),
|
|
688
|
+
});
|
|
689
|
+
} catch {
|
|
690
|
+
// 压缩结果已经确定,日志失败同样不能反向改变执行结果。
|
|
691
|
+
} }
|
|
643
692
|
}
|
|
644
693
|
|
|
645
694
|
/**
|
|
@@ -688,19 +737,4 @@ export class Session implements AgentSession {
|
|
|
688
737
|
input,
|
|
689
738
|
);
|
|
690
739
|
}
|
|
691
|
-
|
|
692
|
-
/** 持久化并发布一条只包含 Action Part 的 canonical Agent Message。 */
|
|
693
|
-
private async emit_action_event(input: SessionActionEventInput): Promise<void> {
|
|
694
|
-
const action_id = String(input.action_id || "").trim() ||
|
|
695
|
-
`action:${this.id}:${Date.now()}`;
|
|
696
|
-
await this.session_messages.persist_action({
|
|
697
|
-
action_id,
|
|
698
|
-
action_type: input.action_type,
|
|
699
|
-
...(input.turn_id ? { turn_id: input.turn_id } : {}),
|
|
700
|
-
title: input.title,
|
|
701
|
-
...(input.description ? { description: input.description } : {}),
|
|
702
|
-
status: input.status,
|
|
703
|
-
});
|
|
704
|
-
}
|
|
705
|
-
|
|
706
740
|
}
|