@downcity/agent 1.1.438 → 1.1.446
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +25 -18
- package/bin/agent/Agent.d.ts +44 -20
- package/bin/agent/Agent.d.ts.map +1 -1
- package/bin/agent/Agent.js +114 -69
- package/bin/agent/Agent.js.map +1 -1
- package/bin/agent/AgentInstructions.d.ts +18 -4
- package/bin/agent/AgentInstructions.d.ts.map +1 -1
- package/bin/agent/AgentInstructions.js +33 -14
- package/bin/agent/AgentInstructions.js.map +1 -1
- package/bin/agent/AgentMemoryStorage.d.ts +1 -1
- package/bin/agent/AgentMemoryStorage.d.ts.map +1 -1
- package/bin/agent/AgentMemoryStorage.js.map +1 -1
- package/bin/agent/AgentSessions.d.ts +29 -16
- package/bin/agent/AgentSessions.d.ts.map +1 -1
- package/bin/agent/AgentSessions.js +42 -22
- package/bin/agent/AgentSessions.js.map +1 -1
- package/bin/group/Group.d.ts +13 -12
- package/bin/group/Group.d.ts.map +1 -1
- package/bin/group/Group.js +24 -23
- package/bin/group/Group.js.map +1 -1
- package/bin/group/GroupSession.d.ts.map +1 -1
- package/bin/group/GroupSession.js +13 -9
- package/bin/group/GroupSession.js.map +1 -1
- package/bin/group/GroupSessions.d.ts +27 -2
- package/bin/group/GroupSessions.d.ts.map +1 -1
- package/bin/group/GroupSessions.js +68 -21
- package/bin/group/GroupSessions.js.map +1 -1
- package/bin/group/storage/LocalGroupSessionDataStore.d.ts +8 -0
- package/bin/group/storage/LocalGroupSessionDataStore.d.ts.map +1 -1
- package/bin/group/storage/LocalGroupSessionDataStore.js +1 -1
- package/bin/group/storage/LocalGroupSessionDataStore.js.map +1 -1
- package/bin/group/storage/LocalGroupSessionStore.d.ts +64 -5
- package/bin/group/storage/LocalGroupSessionStore.d.ts.map +1 -1
- package/bin/group/storage/LocalGroupSessionStore.js +114 -23
- package/bin/group/storage/LocalGroupSessionStore.js.map +1 -1
- package/bin/index.d.ts +25 -30
- package/bin/index.d.ts.map +1 -1
- package/bin/index.js +14 -14
- package/bin/index.js.map +1 -1
- package/bin/{executor/model → model}/ModelGenerate.d.ts +1 -1
- package/bin/model/ModelGenerate.d.ts.map +1 -0
- package/bin/model/ModelGenerate.js.map +1 -0
- package/bin/{executor/model → model}/ModelRequestRunner.d.ts +1 -1
- package/bin/model/ModelRequestRunner.d.ts.map +1 -0
- package/bin/model/ModelRequestRunner.js.map +1 -0
- package/bin/{executor/model → model}/ModelStepRunner.d.ts +6 -7
- package/bin/model/ModelStepRunner.d.ts.map +1 -0
- package/bin/{executor/model → model}/ModelStepRunner.js +16 -10
- package/bin/model/ModelStepRunner.js.map +1 -0
- package/bin/model/ModelStreamConsumer.d.ts.map +1 -0
- package/bin/model/ModelStreamConsumer.js.map +1 -0
- package/bin/model/ModelStreamFailure.d.ts.map +1 -0
- package/bin/model/ModelStreamFailure.js.map +1 -0
- package/bin/model/ToolInputValidation.d.ts +28 -0
- package/bin/model/ToolInputValidation.d.ts.map +1 -0
- package/bin/model/ToolInputValidation.js +37 -0
- package/bin/model/ToolInputValidation.js.map +1 -0
- package/bin/model/messages/ChatMessageMarkup.d.ts.map +1 -0
- package/bin/model/messages/ChatMessageMarkup.js.map +1 -0
- package/bin/{executor → model}/messages/ChatMessageMarkupTypes.d.ts +1 -1
- package/bin/model/messages/ChatMessageMarkupTypes.d.ts.map +1 -0
- package/bin/{executor → model}/messages/ChatMessageMarkupTypes.js +1 -1
- package/bin/model/messages/ChatMessageMarkupTypes.js.map +1 -0
- package/bin/model/messages/SessionAttachmentMapper.d.ts.map +1 -0
- package/bin/model/messages/SessionAttachmentMapper.js.map +1 -0
- package/bin/model/messages/SessionMessageLog.d.ts.map +1 -0
- package/bin/model/messages/SessionMessageLog.js.map +1 -0
- package/bin/model/messages/SessionModelMessages.d.ts.map +1 -0
- package/bin/{executor → model}/messages/SessionModelMessages.js +0 -1
- package/bin/model/messages/SessionModelMessages.js.map +1 -0
- package/bin/model/prompts/SystemPromptAssets.d.ts.map +1 -0
- package/bin/{executor/composer/system/default → model/prompts}/SystemPromptAssets.js +1 -1
- package/bin/model/prompts/SystemPromptAssets.js.map +1 -0
- package/bin/model/prompts/assets/core.prompt.d.ts +7 -0
- package/bin/model/prompts/assets/core.prompt.d.ts.map +1 -0
- package/bin/model/prompts/assets/core.prompt.js +8 -0
- package/bin/model/prompts/assets/core.prompt.js.map +1 -0
- package/bin/session/Session.d.ts +29 -17
- package/bin/session/Session.d.ts.map +1 -1
- package/bin/session/Session.js +161 -134
- package/bin/session/Session.js.map +1 -1
- package/bin/session/input/SessionHookRunner.d.ts +52 -0
- package/bin/session/input/SessionHookRunner.d.ts.map +1 -0
- package/bin/session/input/SessionHookRunner.js +51 -0
- package/bin/session/input/SessionHookRunner.js.map +1 -0
- package/bin/session/input/SessionSystem.d.ts +26 -0
- package/bin/session/input/SessionSystem.d.ts.map +1 -0
- package/bin/session/{SessionSystem.js → input/SessionSystem.js} +27 -23
- package/bin/session/input/SessionSystem.js.map +1 -0
- package/bin/session/input/StepInput.d.ts +77 -0
- package/bin/session/input/StepInput.d.ts.map +1 -0
- package/bin/session/input/StepInput.js +429 -0
- package/bin/session/input/StepInput.js.map +1 -0
- package/bin/session/input/composer/AdaptiveContextCheckpoint.d.ts +33 -0
- package/bin/session/input/composer/AdaptiveContextCheckpoint.d.ts.map +1 -0
- package/bin/session/input/composer/AdaptiveContextCheckpoint.js +83 -0
- package/bin/session/input/composer/AdaptiveContextCheckpoint.js.map +1 -0
- package/bin/session/input/composer/AdaptiveContextParts.d.ts +26 -0
- package/bin/session/input/composer/AdaptiveContextParts.d.ts.map +1 -0
- package/bin/session/input/composer/AdaptiveContextParts.js +124 -0
- package/bin/session/input/composer/AdaptiveContextParts.js.map +1 -0
- package/bin/session/input/composer/ComposerAssembly.d.ts +21 -0
- package/bin/session/input/composer/ComposerAssembly.d.ts.map +1 -0
- package/bin/session/input/composer/ComposerAssembly.js +64 -0
- package/bin/session/input/composer/ComposerAssembly.js.map +1 -0
- package/bin/session/{composer/policies/SessionSummaryPrompts.d.ts → input/composer/ContextSummaryPrompts.d.ts} +5 -3
- package/bin/session/input/composer/ContextSummaryPrompts.d.ts.map +1 -0
- package/bin/session/{composer/policies/SessionSummaryPrompts.js → input/composer/ContextSummaryPrompts.js} +5 -3
- package/bin/session/input/composer/ContextSummaryPrompts.js.map +1 -0
- package/bin/session/input/composer/DefaultSessionComposer.d.ts +24 -0
- package/bin/session/input/composer/DefaultSessionComposer.d.ts.map +1 -0
- package/bin/session/input/composer/DefaultSessionComposer.js +108 -0
- package/bin/session/input/composer/DefaultSessionComposer.js.map +1 -0
- package/bin/session/input/composer/FullHistorySessionComposer.d.ts +19 -0
- package/bin/session/input/composer/FullHistorySessionComposer.d.ts.map +1 -0
- package/bin/session/input/composer/FullHistorySessionComposer.js +36 -0
- package/bin/session/input/composer/FullHistorySessionComposer.js.map +1 -0
- package/bin/session/{SessionLoop.d.ts → loop/SessionLoop.d.ts} +34 -7
- package/bin/session/loop/SessionLoop.d.ts.map +1 -0
- package/bin/session/{SessionLoop.js → loop/SessionLoop.js} +79 -16
- package/bin/session/loop/SessionLoop.js.map +1 -0
- package/bin/session/{SessionQueue.d.ts → loop/SessionQueue.d.ts} +9 -1
- package/bin/session/loop/SessionQueue.d.ts.map +1 -0
- package/bin/session/{SessionQueue.js → loop/SessionQueue.js} +19 -0
- package/bin/session/loop/SessionQueue.js.map +1 -0
- package/bin/session/{SessionState.d.ts → loop/SessionState.d.ts} +4 -5
- package/bin/session/loop/SessionState.d.ts.map +1 -0
- package/bin/session/{SessionState.js → loop/SessionState.js} +6 -25
- package/bin/session/loop/SessionState.js.map +1 -0
- package/bin/session/{SessionTitle.d.ts → loop/SessionTitle.d.ts} +4 -4
- package/bin/session/loop/SessionTitle.d.ts.map +1 -0
- package/bin/session/{SessionTitle.js → loop/SessionTitle.js} +3 -3
- package/bin/session/loop/SessionTitle.js.map +1 -0
- package/bin/session/loop/SessionTitleTask.d.ts.map +1 -0
- package/bin/session/loop/SessionTitleTask.js.map +1 -0
- package/bin/session/{runtime → loop}/SessionTurnCompletion.d.ts +7 -0
- package/bin/session/loop/SessionTurnCompletion.d.ts.map +1 -0
- package/bin/session/{runtime → loop}/SessionTurnCompletion.js +25 -6
- package/bin/session/loop/SessionTurnCompletion.js.map +1 -0
- package/bin/session/loop/SessionTurnContext.d.ts +12 -0
- package/bin/session/loop/SessionTurnContext.d.ts.map +1 -0
- package/bin/session/{runtime → loop}/SessionTurnContext.js +14 -67
- package/bin/session/loop/SessionTurnContext.js.map +1 -0
- package/bin/session/loop/SessionTurnFileDiff.d.ts.map +1 -0
- package/bin/session/{runtime → loop}/SessionTurnFileDiff.js +1 -1
- package/bin/session/loop/SessionTurnFileDiff.js.map +1 -0
- package/bin/session/{messages → loop}/SessionTurnFileDiffBuilder.d.ts +3 -3
- package/bin/session/loop/SessionTurnFileDiffBuilder.d.ts.map +1 -0
- package/bin/session/loop/SessionTurnFileDiffBuilder.js.map +1 -0
- package/bin/session/messages/ApprovalInteraction.d.ts +30 -0
- package/bin/session/messages/ApprovalInteraction.d.ts.map +1 -0
- package/bin/session/messages/ApprovalInteraction.js +61 -0
- package/bin/session/messages/ApprovalInteraction.js.map +1 -0
- package/bin/session/messages/SessionAgentMessageState.d.ts +47 -18
- package/bin/session/messages/SessionAgentMessageState.d.ts.map +1 -1
- package/bin/session/messages/SessionAgentMessageState.js +224 -86
- package/bin/session/messages/SessionAgentMessageState.js.map +1 -1
- package/bin/session/messages/SessionAgentMessageWriter.d.ts +15 -4
- package/bin/session/messages/SessionAgentMessageWriter.d.ts.map +1 -1
- package/bin/session/messages/SessionAgentMessageWriter.js +57 -37
- package/bin/session/messages/SessionAgentMessageWriter.js.map +1 -1
- package/bin/session/messages/SessionAgentParts.d.ts +14 -0
- package/bin/session/messages/SessionAgentParts.d.ts.map +1 -0
- package/bin/session/messages/SessionAgentParts.js +20 -0
- package/bin/session/messages/SessionAgentParts.js.map +1 -0
- package/bin/session/{execution → messages}/SessionAssistantOutputAdapter.d.ts +2 -2
- package/bin/session/messages/SessionAssistantOutputAdapter.d.ts.map +1 -0
- package/bin/session/messages/SessionAssistantOutputAdapter.js.map +1 -0
- package/bin/session/messages/SessionEventHub.d.ts.map +1 -0
- package/bin/session/messages/SessionEventHub.js.map +1 -0
- package/bin/session/messages/SessionInteractions.d.ts +57 -0
- package/bin/session/messages/SessionInteractions.d.ts.map +1 -0
- package/bin/session/messages/SessionInteractions.js +178 -0
- package/bin/session/messages/SessionInteractions.js.map +1 -0
- package/bin/session/messages/SessionJsonValue.d.ts +1 -3
- package/bin/session/messages/SessionJsonValue.d.ts.map +1 -1
- package/bin/session/messages/SessionJsonValue.js +0 -19
- package/bin/session/messages/SessionJsonValue.js.map +1 -1
- package/bin/session/messages/SessionMessageCache.d.ts +55 -0
- package/bin/session/messages/SessionMessageCache.d.ts.map +1 -0
- package/bin/session/messages/SessionMessageCache.js +133 -0
- package/bin/session/messages/SessionMessageCache.js.map +1 -0
- package/bin/session/messages/SessionMessageState.d.ts +17 -0
- package/bin/session/messages/SessionMessageState.d.ts.map +1 -0
- package/bin/session/messages/SessionMessageState.js +34 -0
- package/bin/session/messages/SessionMessageState.js.map +1 -0
- package/bin/session/messages/SessionMessageTimeline.d.ts.map +1 -0
- package/bin/session/{browse → messages}/SessionMessageTimeline.js +0 -1
- package/bin/session/messages/SessionMessageTimeline.js.map +1 -0
- package/bin/session/{SessionMessages.d.ts → messages/SessionMessages.d.ts} +35 -43
- package/bin/session/messages/SessionMessages.d.ts.map +1 -0
- package/bin/session/{SessionMessages.js → messages/SessionMessages.js} +178 -196
- package/bin/session/messages/SessionMessages.js.map +1 -0
- package/bin/session/messages/SessionModelRequestWarning.d.ts.map +1 -0
- package/bin/session/messages/SessionModelRequestWarning.js.map +1 -0
- package/bin/session/messages/SessionMutationFactory.d.ts +26 -0
- package/bin/session/messages/SessionMutationFactory.d.ts.map +1 -0
- package/bin/session/messages/SessionMutationFactory.js +38 -0
- package/bin/session/messages/SessionMutationFactory.js.map +1 -0
- package/bin/session/messages/SessionUserMessage.d.ts +5 -7
- package/bin/session/messages/SessionUserMessage.d.ts.map +1 -1
- package/bin/session/messages/SessionUserMessage.js +5 -28
- package/bin/session/messages/SessionUserMessage.js.map +1 -1
- package/bin/{executor/core-engine/CoreEngineSignals.d.ts → session/runner/AssistantParts.d.ts} +4 -9
- package/bin/session/runner/AssistantParts.d.ts.map +1 -0
- package/bin/{executor/core-engine/CoreEngineSignals.js → session/runner/AssistantParts.js} +4 -17
- package/bin/session/runner/AssistantParts.js.map +1 -0
- package/bin/session/runner/ContextPressure.d.ts +15 -0
- package/bin/session/runner/ContextPressure.d.ts.map +1 -0
- package/bin/{executor/core-engine/CoreEngineContextCompaction.js → session/runner/ContextPressure.js} +11 -11
- package/bin/session/runner/ContextPressure.js.map +1 -0
- package/bin/session/runner/ContextRetry.d.ts +39 -0
- package/bin/session/runner/ContextRetry.d.ts.map +1 -0
- package/bin/{executor/services/ExecutorRecoveryPolicy.js → session/runner/ContextRetry.js} +19 -19
- package/bin/session/runner/ContextRetry.js.map +1 -0
- package/bin/{executor/core-engine/CoreEngineError.d.ts → session/runner/ModelFailure.d.ts} +4 -4
- package/bin/session/runner/ModelFailure.d.ts.map +1 -0
- package/bin/{executor/core-engine/CoreEngineError.js → session/runner/ModelFailure.js} +4 -4
- package/bin/session/runner/ModelFailure.js.map +1 -0
- package/bin/session/runner/SessionExecutor.d.ts +108 -0
- package/bin/session/runner/SessionExecutor.d.ts.map +1 -0
- package/bin/session/runner/SessionExecutor.js +430 -0
- package/bin/session/runner/SessionExecutor.js.map +1 -0
- package/bin/session/runner/ToolLoopDecision.d.ts +60 -0
- package/bin/session/runner/ToolLoopDecision.d.ts.map +1 -0
- package/bin/{executor/core-engine/CoreEngineLoopDecision.js → session/runner/ToolLoopDecision.js} +5 -5
- package/bin/session/runner/ToolLoopDecision.js.map +1 -0
- package/bin/session/runner/ToolLoopLimits.d.ts +30 -0
- package/bin/session/runner/ToolLoopLimits.d.ts.map +1 -0
- package/bin/session/runner/ToolLoopLimits.js +46 -0
- package/bin/session/runner/ToolLoopLimits.js.map +1 -0
- package/bin/session/{browse → storage}/Browse.d.ts +1 -1
- package/bin/session/storage/Browse.d.ts.map +1 -0
- package/bin/session/{browse → storage}/Browse.js +1 -1
- package/bin/session/storage/Browse.js.map +1 -0
- package/bin/session/storage/LocalSessionStore.js +1 -1
- package/bin/session/storage/LocalSessionStore.js.map +1 -1
- package/bin/session/storage/LocalStorePaths.d.ts +0 -2
- package/bin/session/storage/LocalStorePaths.d.ts.map +1 -1
- package/bin/session/storage/LocalStorePaths.js +1 -1
- package/bin/session/storage/LocalStorePaths.js.map +1 -1
- package/bin/session/storage/Metadata.d.ts +1 -23
- package/bin/session/storage/Metadata.d.ts.map +1 -1
- package/bin/session/storage/Metadata.js +0 -18
- package/bin/session/storage/Metadata.js.map +1 -1
- package/bin/session/storage/RuntimeSessionPort.d.ts +0 -4
- package/bin/session/storage/RuntimeSessionPort.d.ts.map +1 -1
- package/bin/session/storage/RuntimeSessionPort.js +0 -1
- package/bin/session/storage/RuntimeSessionPort.js.map +1 -1
- package/bin/session/{preview → storage}/SessionMessagePreview.d.ts.map +1 -1
- package/bin/session/{preview → storage}/SessionMessagePreview.js +0 -1
- package/bin/session/{preview → storage}/SessionMessagePreview.js.map +1 -1
- package/bin/session/storage/SessionStorageCodec.d.ts.map +1 -1
- package/bin/session/storage/SessionStorageCodec.js +36 -18
- package/bin/session/storage/SessionStorageCodec.js.map +1 -1
- package/bin/session/storage/SessionStorageSchema.d.ts +1 -1
- package/bin/session/storage/SessionStorageSchema.js +1 -1
- package/bin/session/storage/SqliteSessionStorage.d.ts +6 -4
- package/bin/session/storage/SqliteSessionStorage.d.ts.map +1 -1
- package/bin/session/storage/SqliteSessionStorage.js +21 -18
- package/bin/session/storage/SqliteSessionStorage.js.map +1 -1
- package/bin/tools/ask/AskQuestionAnswers.d.ts +20 -0
- package/bin/tools/ask/AskQuestionAnswers.d.ts.map +1 -0
- package/bin/tools/ask/AskQuestionAnswers.js +99 -0
- package/bin/tools/ask/AskQuestionAnswers.js.map +1 -0
- package/bin/tools/ask/AskQuestionsTool.d.ts +5 -2
- package/bin/tools/ask/AskQuestionsTool.d.ts.map +1 -1
- package/bin/tools/ask/AskQuestionsTool.js +23 -31
- package/bin/tools/ask/AskQuestionsTool.js.map +1 -1
- package/bin/tools/ask/AskQuestionsToolSchemas.d.ts +1 -1
- package/bin/types/agent/AgentOptions.d.ts +16 -8
- package/bin/types/agent/AgentOptions.d.ts.map +1 -1
- package/bin/types/agent/AgentSessionCollection.d.ts +8 -0
- package/bin/types/agent/AgentSessionCollection.d.ts.map +1 -1
- package/bin/types/agent/SessionActor.d.ts +3 -3
- package/bin/types/agent/SessionActor.d.ts.map +1 -1
- package/bin/types/group/DispatchStrategy.js +1 -1
- package/bin/types/group/DispatchStrategy.js.map +1 -1
- package/bin/types/group/GroupSession.d.ts +41 -1
- package/bin/types/group/GroupSession.d.ts.map +1 -1
- package/bin/types/group/GroupSessionStore.d.ts +30 -3
- package/bin/types/group/GroupSessionStore.d.ts.map +1 -1
- package/bin/types/model/ModelRequest.d.ts.map +1 -0
- package/bin/types/model/ModelRequest.js.map +1 -0
- package/bin/types/sdk/AgentSessionAction.d.ts +1 -9
- package/bin/types/sdk/AgentSessionAction.d.ts.map +1 -1
- package/bin/types/session/{AdaptivePartContextPolicy.d.ts → ContextCheckpoint.d.ts} +10 -9
- package/bin/types/session/ContextCheckpoint.d.ts.map +1 -0
- package/bin/types/session/ContextCheckpoint.js +8 -0
- package/bin/types/session/ContextCheckpoint.js.map +1 -0
- package/bin/types/session/SessionAgentMessageState.d.ts +6 -10
- package/bin/types/session/SessionAgentMessageState.d.ts.map +1 -1
- package/bin/types/session/SessionAgentMessageState.js +3 -2
- package/bin/types/session/SessionAgentMessageState.js.map +1 -1
- package/bin/types/session/SessionComposer.d.ts +65 -36
- package/bin/types/session/SessionComposer.d.ts.map +1 -1
- package/bin/types/session/SessionComposer.js +7 -2
- package/bin/types/session/SessionComposer.js.map +1 -1
- package/bin/types/session/SessionExecution.d.ts +15 -11
- package/bin/types/session/SessionExecution.d.ts.map +1 -1
- package/bin/types/session/SessionExecution.js +1 -1
- package/bin/types/session/SessionInteractions.d.ts +0 -2
- package/bin/types/session/SessionInteractions.d.ts.map +1 -1
- package/bin/types/session/SessionLocalState.d.ts +0 -4
- package/bin/types/session/SessionLocalState.d.ts.map +1 -1
- package/bin/types/session/SessionLoop.d.ts +33 -12
- package/bin/types/session/SessionLoop.d.ts.map +1 -1
- package/bin/types/session/SessionMessages.d.ts +3 -29
- package/bin/types/session/SessionMessages.d.ts.map +1 -1
- package/bin/types/session/SessionOptions.d.ts +16 -13
- package/bin/types/session/SessionOptions.d.ts.map +1 -1
- package/bin/types/session/SessionPort.d.ts +0 -3
- package/bin/types/session/SessionPort.d.ts.map +1 -1
- package/bin/types/session/SessionState.d.ts +0 -1
- package/bin/types/session/SessionState.d.ts.map +1 -1
- package/bin/types/session/SessionSystem.d.ts +10 -12
- package/bin/types/session/SessionSystem.d.ts.map +1 -1
- package/bin/types/session/SessionTool.d.ts +2 -2
- package/bin/types/session/SessionTool.d.ts.map +1 -1
- package/bin/types/session/SessionTurnCompletion.d.ts +12 -2
- package/bin/types/session/SessionTurnCompletion.d.ts.map +1 -1
- package/bin/types/session/SessionTurnFileDiff.d.ts +4 -4
- package/bin/types/session/SessionTurnFileDiff.d.ts.map +1 -1
- package/bin/types/session/{SessionComposition.d.ts → StepInput.d.ts} +17 -15
- package/bin/types/session/StepInput.d.ts.map +1 -0
- package/bin/types/session/StepInput.js +8 -0
- package/bin/types/session/StepInput.js.map +1 -0
- package/bin/types/store/SessionHistoryMeta.d.ts.map +1 -0
- package/bin/types/store/SessionHistoryMeta.js.map +1 -0
- package/bin/types/store/SessionStorage.d.ts +17 -12
- package/bin/types/store/SessionStorage.d.ts.map +1 -1
- package/bin/types/tool/BoundAgentTool.d.ts +36 -0
- package/bin/types/tool/BoundAgentTool.d.ts.map +1 -0
- package/bin/types/tool/BoundAgentTool.js +13 -0
- package/bin/types/tool/BoundAgentTool.js.map +1 -0
- package/bin/types/tools/ask/AskQuestionsTool.d.ts +9 -13
- package/bin/types/tools/ask/AskQuestionsTool.d.ts.map +1 -1
- package/bin/types/tools/ask/AskQuestionsTool.js +3 -2
- package/bin/types/tools/ask/AskQuestionsTool.js.map +1 -1
- package/bin/types/turn/SessionAssistantOutput.d.ts.map +1 -0
- package/bin/types/turn/SessionAssistantOutput.js.map +1 -0
- package/bin/types/{executor → turn}/SessionTurnContext.d.ts +10 -28
- package/bin/types/turn/SessionTurnContext.d.ts.map +1 -0
- package/bin/types/turn/SessionTurnContext.js.map +1 -0
- package/bin/{executor/ids/resolveSessionId.d.ts → utils/ResolveSessionId.d.ts} +1 -1
- package/bin/utils/ResolveSessionId.d.ts.map +1 -0
- package/bin/{executor/ids/resolveSessionId.js → utils/ResolveSessionId.js} +1 -1
- package/bin/utils/ResolveSessionId.js.map +1 -0
- package/bin/utils/Time.d.ts +5 -8
- package/bin/utils/Time.d.ts.map +1 -1
- package/bin/utils/Time.js +5 -54
- package/bin/utils/Time.js.map +1 -1
- package/package.json +2 -2
- package/scripts/ask-question-answers.test.mjs +132 -0
- package/scripts/group-session-archive.test.mjs +193 -0
- package/scripts/{core-engine-model-stream.test.mjs → model-step-runner.test.mjs} +97 -4
- package/scripts/rewrite-build-aliases.mjs +3 -4
- package/scripts/session-action-part.test.mjs +172 -0
- package/scripts/session-agent-message-part-order.test.mjs +13 -7
- package/scripts/{core-engine-context-compaction.test.mjs → session-executor-context-pressure.test.mjs} +40 -32
- package/scripts/{executor-failure-result.test.mjs → session-executor-failure-result.test.mjs} +17 -14
- package/scripts/session-executor-max-steps.test.mjs +143 -0
- package/scripts/session-initialization.test.mjs +3 -4
- package/scripts/session-interaction-migration.test.mjs +145 -0
- package/scripts/session-interaction-mutation.test.mjs +202 -0
- package/scripts/session-messages-error-part.test.mjs +1 -1
- package/scripts/session-messages-error.test.mjs +1 -1
- package/scripts/session-prompt-idempotency.test.mjs +4 -2
- package/scripts/session-queue.test.mjs +21 -1
- package/scripts/session-storage-sqlite.test.mjs +3 -3
- package/scripts/session-system-blocks.test.mjs +61 -39
- package/scripts/session-turn-context.test.mjs +37 -40
- package/scripts/verify-build-aliases.mjs +1 -1
- package/src/agent/Agent.ts +137 -80
- package/src/agent/AgentInstructions.ts +48 -15
- package/src/agent/AgentMemoryStorage.ts +1 -1
- package/src/agent/AgentSessions.ts +60 -38
- package/src/group/Group.ts +27 -24
- package/src/group/GroupSession.ts +12 -8
- package/src/group/GroupSessions.ts +79 -20
- package/src/group/storage/LocalGroupSessionDataStore.ts +9 -1
- package/src/group/storage/LocalGroupSessionStore.ts +138 -28
- package/src/index.ts +35 -52
- package/src/{executor/model → model}/ModelGenerate.ts +3 -3
- package/src/{executor/model → model}/ModelRequestRunner.ts +2 -2
- package/src/{executor/model → model}/ModelStepRunner.ts +22 -19
- package/src/{executor/model → model}/ModelStreamConsumer.ts +1 -1
- package/src/model/README.md +117 -0
- package/src/model/ToolInputValidation.ts +58 -0
- package/src/{executor → model}/messages/ChatMessageMarkupTypes.ts +1 -1
- package/src/{executor → model}/messages/SessionModelMessages.ts +0 -1
- package/src/{executor/composer/system/default → model/prompts}/SystemPromptAssets.ts +1 -1
- package/src/model/prompts/assets/core.prompt.ts +9 -0
- package/src/{executor/composer/system/default → model/prompts}/assets/core.prompt.ts.txt +26 -25
- package/src/session/Session.ts +185 -151
- package/src/session/input/SessionHookRunner.ts +100 -0
- package/src/session/{SessionSystem.ts → input/SessionSystem.ts} +31 -29
- package/src/session/input/StepInput.ts +507 -0
- package/src/session/input/composer/AdaptiveContextCheckpoint.ts +115 -0
- package/src/session/input/composer/AdaptiveContextParts.ts +166 -0
- package/src/session/input/composer/ComposerAssembly.ts +81 -0
- package/src/session/{composer/policies/SessionSummaryPrompts.ts → input/composer/ContextSummaryPrompts.ts} +5 -2
- package/src/session/input/composer/DefaultSessionComposer.ts +147 -0
- package/src/session/input/composer/FullHistorySessionComposer.ts +55 -0
- package/src/session/loop/README.md +28 -0
- package/src/session/{SessionLoop.ts → loop/SessionLoop.ts} +100 -24
- package/src/session/{SessionQueue.ts → loop/SessionQueue.ts} +18 -0
- package/src/session/{SessionState.ts → loop/SessionState.ts} +4 -21
- package/src/session/{SessionTitle.ts → loop/SessionTitle.ts} +3 -3
- package/src/session/{runtime → loop}/SessionTurnCompletion.ts +27 -8
- package/src/session/{runtime → loop}/SessionTurnContext.ts +19 -93
- package/src/session/{runtime → loop}/SessionTurnFileDiff.ts +1 -1
- package/src/session/{messages → loop}/SessionTurnFileDiffBuilder.ts +4 -4
- package/src/session/messages/ApprovalInteraction.ts +77 -0
- package/src/session/messages/README.md +27 -0
- package/src/session/messages/SessionAgentMessageState.ts +324 -113
- package/src/session/messages/SessionAgentMessageWriter.ts +82 -45
- package/src/session/messages/SessionAgentParts.ts +39 -0
- package/src/session/{execution → messages}/SessionAssistantOutputAdapter.ts +2 -2
- package/src/session/messages/SessionInteractions.ts +227 -0
- package/src/session/messages/SessionJsonValue.ts +1 -18
- package/src/session/messages/SessionMessageCache.ts +171 -0
- package/src/session/messages/SessionMessageState.ts +42 -0
- package/src/session/{browse → messages}/SessionMessageTimeline.ts +0 -1
- package/src/session/{SessionMessages.ts → messages/SessionMessages.ts} +225 -284
- package/src/session/messages/SessionMutationFactory.ts +58 -0
- package/src/session/messages/SessionUserMessage.ts +7 -32
- package/src/{executor/core-engine/CoreEngineSignals.ts → session/runner/AssistantParts.ts} +3 -21
- package/src/{executor/core-engine/CoreEngineContextCompaction.ts → session/runner/ContextPressure.ts} +10 -10
- package/src/{executor/services/ExecutorRecoveryPolicy.ts → session/runner/ContextRetry.ts} +25 -25
- package/src/{executor/core-engine/CoreEngineError.ts → session/runner/ModelFailure.ts} +3 -3
- package/src/session/runner/SessionExecutor.ts +633 -0
- package/src/session/runner/ToolLoopDecision.ts +98 -0
- package/src/session/runner/ToolLoopLimits.ts +53 -0
- package/src/session/{browse → storage}/Browse.ts +2 -2
- package/src/session/storage/LocalSessionStore.ts +1 -1
- package/src/session/storage/LocalStorePaths.ts +1 -1
- package/src/session/storage/Metadata.ts +1 -44
- package/src/session/storage/RuntimeSessionPort.ts +0 -5
- package/src/session/{preview → storage}/SessionMessagePreview.ts +0 -1
- package/src/session/storage/SessionStorageCodec.ts +54 -28
- package/src/session/storage/SessionStorageSchema.ts +1 -1
- package/src/session/storage/SqliteSessionStorage.ts +29 -22
- package/src/tools/ask/AskQuestionAnswers.ts +125 -0
- package/src/tools/ask/AskQuestionsTool.ts +32 -37
- package/src/types/agent/AgentOptions.ts +17 -8
- package/src/types/agent/AgentSessionCollection.ts +9 -0
- package/src/types/agent/SessionActor.ts +3 -4
- package/src/types/group/DispatchStrategy.ts +1 -1
- package/src/types/group/GroupSession.ts +44 -1
- package/src/types/group/GroupSessionStore.ts +30 -3
- package/src/types/sdk/AgentSessionAction.ts +1 -14
- package/src/types/session/{AdaptivePartContextPolicy.ts → ContextCheckpoint.ts} +9 -8
- package/src/types/session/SessionAgentMessageState.ts +6 -16
- package/src/types/session/SessionComposer.ts +67 -39
- package/src/types/session/SessionExecution.ts +15 -13
- package/src/types/session/SessionInteractions.ts +0 -2
- package/src/types/session/SessionLocalState.ts +0 -5
- package/src/types/session/SessionLoop.ts +37 -12
- package/src/types/session/SessionMessages.ts +3 -34
- package/src/types/session/SessionOptions.ts +18 -13
- package/src/types/session/SessionPort.ts +0 -4
- package/src/types/session/SessionState.ts +0 -1
- package/src/types/session/SessionSystem.ts +10 -16
- package/src/types/session/SessionTool.ts +2 -2
- package/src/types/session/SessionTurnCompletion.ts +12 -2
- package/src/types/session/SessionTurnFileDiff.ts +4 -4
- package/src/types/session/{SessionComposition.ts → StepInput.ts} +22 -14
- package/src/types/store/SessionStorage.ts +17 -12
- package/src/types/tool/BoundAgentTool.ts +38 -0
- package/src/types/tools/ask/AskQuestionsTool.ts +11 -13
- package/src/types/{executor → turn}/SessionTurnContext.ts +8 -34
- package/src/utils/Time.ts +12 -64
- package/tsconfig.json +1 -2
- package/tsconfig.tsbuildinfo +1 -1
- package/bin/executor/Executor.d.ts +0 -92
- package/bin/executor/Executor.d.ts.map +0 -1
- package/bin/executor/Executor.js +0 -232
- package/bin/executor/Executor.js.map +0 -1
- package/bin/executor/composer/system/default/SystemPromptAssets.d.ts.map +0 -1
- package/bin/executor/composer/system/default/SystemPromptAssets.js.map +0 -1
- package/bin/executor/composer/system/default/assets/core.prompt.d.ts +0 -7
- package/bin/executor/composer/system/default/assets/core.prompt.d.ts.map +0 -1
- package/bin/executor/composer/system/default/assets/core.prompt.js +0 -8
- package/bin/executor/composer/system/default/assets/core.prompt.js.map +0 -1
- package/bin/executor/core-engine/CoreEngineContextCompaction.d.ts +0 -15
- package/bin/executor/core-engine/CoreEngineContextCompaction.d.ts.map +0 -1
- package/bin/executor/core-engine/CoreEngineContextCompaction.js.map +0 -1
- package/bin/executor/core-engine/CoreEngineError.d.ts.map +0 -1
- package/bin/executor/core-engine/CoreEngineError.js.map +0 -1
- package/bin/executor/core-engine/CoreEngineLoopDecision.d.ts +0 -26
- package/bin/executor/core-engine/CoreEngineLoopDecision.d.ts.map +0 -1
- package/bin/executor/core-engine/CoreEngineLoopDecision.js.map +0 -1
- package/bin/executor/core-engine/CoreEngineRunner.d.ts +0 -48
- package/bin/executor/core-engine/CoreEngineRunner.d.ts.map +0 -1
- package/bin/executor/core-engine/CoreEngineRunner.js +0 -343
- package/bin/executor/core-engine/CoreEngineRunner.js.map +0 -1
- package/bin/executor/core-engine/CoreEngineSignals.d.ts.map +0 -1
- package/bin/executor/core-engine/CoreEngineSignals.js.map +0 -1
- package/bin/executor/ids/resolveSessionId.d.ts.map +0 -1
- package/bin/executor/ids/resolveSessionId.js.map +0 -1
- package/bin/executor/messages/ChatMessageMarkup.d.ts.map +0 -1
- package/bin/executor/messages/ChatMessageMarkup.js.map +0 -1
- package/bin/executor/messages/ChatMessageMarkupTypes.d.ts.map +0 -1
- package/bin/executor/messages/ChatMessageMarkupTypes.js.map +0 -1
- package/bin/executor/messages/SessionAttachmentMapper.d.ts.map +0 -1
- package/bin/executor/messages/SessionAttachmentMapper.js.map +0 -1
- package/bin/executor/messages/SessionMessageLog.d.ts.map +0 -1
- package/bin/executor/messages/SessionMessageLog.js.map +0 -1
- package/bin/executor/messages/SessionModelMessages.d.ts.map +0 -1
- package/bin/executor/messages/SessionModelMessages.js.map +0 -1
- package/bin/executor/model/ModelGenerate.d.ts.map +0 -1
- package/bin/executor/model/ModelGenerate.js.map +0 -1
- package/bin/executor/model/ModelRequestRunner.d.ts.map +0 -1
- package/bin/executor/model/ModelRequestRunner.js.map +0 -1
- package/bin/executor/model/ModelStepRunner.d.ts.map +0 -1
- package/bin/executor/model/ModelStepRunner.js.map +0 -1
- package/bin/executor/model/ModelStreamConsumer.d.ts.map +0 -1
- package/bin/executor/model/ModelStreamConsumer.js.map +0 -1
- package/bin/executor/model/ModelStreamFailure.d.ts.map +0 -1
- package/bin/executor/model/ModelStreamFailure.js.map +0 -1
- package/bin/executor/services/ExecutorRecoveryPolicy.d.ts +0 -39
- package/bin/executor/services/ExecutorRecoveryPolicy.d.ts.map +0 -1
- package/bin/executor/services/ExecutorRecoveryPolicy.js.map +0 -1
- package/bin/executor/types/SessionHistoryMeta.d.ts.map +0 -1
- package/bin/executor/types/SessionHistoryMeta.js.map +0 -1
- package/bin/executor/types/SessionLoop.d.ts +0 -59
- package/bin/executor/types/SessionLoop.d.ts.map +0 -1
- package/bin/executor/types/SessionLoop.js +0 -9
- package/bin/executor/types/SessionLoop.js.map +0 -1
- package/bin/executor/types/SessionPrompts.d.ts +0 -14
- package/bin/executor/types/SessionPrompts.d.ts.map +0 -1
- package/bin/executor/types/SessionPrompts.js +0 -8
- package/bin/executor/types/SessionPrompts.js.map +0 -1
- package/bin/session/DefaultSessionComposer.d.ts +0 -24
- package/bin/session/DefaultSessionComposer.d.ts.map +0 -1
- package/bin/session/DefaultSessionComposer.js +0 -99
- package/bin/session/DefaultSessionComposer.js.map +0 -1
- package/bin/session/SessionComposition.d.ts +0 -49
- package/bin/session/SessionComposition.d.ts.map +0 -1
- package/bin/session/SessionComposition.js +0 -309
- package/bin/session/SessionComposition.js.map +0 -1
- package/bin/session/SessionHookPoints.d.ts +0 -15
- package/bin/session/SessionHookPoints.d.ts.map +0 -1
- package/bin/session/SessionHookPoints.js +0 -15
- package/bin/session/SessionHookPoints.js.map +0 -1
- package/bin/session/SessionHooks.d.ts +0 -38
- package/bin/session/SessionHooks.d.ts.map +0 -1
- package/bin/session/SessionHooks.js +0 -71
- package/bin/session/SessionHooks.js.map +0 -1
- package/bin/session/SessionLoop.d.ts.map +0 -1
- package/bin/session/SessionLoop.js.map +0 -1
- package/bin/session/SessionMessages.d.ts.map +0 -1
- package/bin/session/SessionMessages.js.map +0 -1
- package/bin/session/SessionQueue.d.ts.map +0 -1
- package/bin/session/SessionQueue.js.map +0 -1
- package/bin/session/SessionState.d.ts.map +0 -1
- package/bin/session/SessionState.js.map +0 -1
- package/bin/session/SessionSystem.d.ts +0 -19
- package/bin/session/SessionSystem.d.ts.map +0 -1
- package/bin/session/SessionSystem.js.map +0 -1
- package/bin/session/SessionTitle.d.ts.map +0 -1
- package/bin/session/SessionTitle.js.map +0 -1
- package/bin/session/browse/Browse.d.ts.map +0 -1
- package/bin/session/browse/Browse.js.map +0 -1
- package/bin/session/browse/SessionMessageTimeline.d.ts.map +0 -1
- package/bin/session/browse/SessionMessageTimeline.js.map +0 -1
- package/bin/session/composer/policies/AdaptivePartContextPolicy.d.ts +0 -35
- package/bin/session/composer/policies/AdaptivePartContextPolicy.d.ts.map +0 -1
- package/bin/session/composer/policies/AdaptivePartContextPolicy.js +0 -256
- package/bin/session/composer/policies/AdaptivePartContextPolicy.js.map +0 -1
- package/bin/session/composer/policies/FullHistoryContextPolicy.d.ts +0 -24
- package/bin/session/composer/policies/FullHistoryContextPolicy.d.ts.map +0 -1
- package/bin/session/composer/policies/FullHistoryContextPolicy.js +0 -31
- package/bin/session/composer/policies/FullHistoryContextPolicy.js.map +0 -1
- package/bin/session/composer/policies/SessionSummaryPrompts.d.ts.map +0 -1
- package/bin/session/composer/policies/SessionSummaryPrompts.js.map +0 -1
- package/bin/session/control/SessionInteractions.d.ts +0 -39
- package/bin/session/control/SessionInteractions.d.ts.map +0 -1
- package/bin/session/control/SessionInteractions.js +0 -255
- package/bin/session/control/SessionInteractions.js.map +0 -1
- package/bin/session/execution/SessionAssistantOutputAdapter.d.ts.map +0 -1
- package/bin/session/execution/SessionAssistantOutputAdapter.js.map +0 -1
- package/bin/session/execution/tools/SessionShellApprovalAdapter.d.ts +0 -28
- package/bin/session/execution/tools/SessionShellApprovalAdapter.d.ts.map +0 -1
- package/bin/session/execution/tools/SessionShellApprovalAdapter.js +0 -87
- package/bin/session/execution/tools/SessionShellApprovalAdapter.js.map +0 -1
- package/bin/session/messages/SessionAgentActionPartWriter.d.ts +0 -22
- package/bin/session/messages/SessionAgentActionPartWriter.d.ts.map +0 -1
- package/bin/session/messages/SessionAgentActionPartWriter.js +0 -36
- package/bin/session/messages/SessionAgentActionPartWriter.js.map +0 -1
- package/bin/session/messages/SessionMessageInteractionWriter.d.ts +0 -46
- package/bin/session/messages/SessionMessageInteractionWriter.d.ts.map +0 -1
- package/bin/session/messages/SessionMessageInteractionWriter.js +0 -183
- package/bin/session/messages/SessionMessageInteractionWriter.js.map +0 -1
- package/bin/session/messages/SessionTurnFileDiffBuilder.d.ts.map +0 -1
- package/bin/session/messages/SessionTurnFileDiffBuilder.js.map +0 -1
- package/bin/session/runtime/SessionEventHub.d.ts.map +0 -1
- package/bin/session/runtime/SessionEventHub.js.map +0 -1
- package/bin/session/runtime/SessionModelRequestWarning.d.ts.map +0 -1
- package/bin/session/runtime/SessionModelRequestWarning.js.map +0 -1
- package/bin/session/runtime/SessionTitleTask.d.ts.map +0 -1
- package/bin/session/runtime/SessionTitleTask.js.map +0 -1
- package/bin/session/runtime/SessionTurnCompletion.d.ts.map +0 -1
- package/bin/session/runtime/SessionTurnCompletion.js.map +0 -1
- package/bin/session/runtime/SessionTurnContext.d.ts +0 -29
- package/bin/session/runtime/SessionTurnContext.d.ts.map +0 -1
- package/bin/session/runtime/SessionTurnContext.js.map +0 -1
- package/bin/session/runtime/SessionTurnFileDiff.d.ts.map +0 -1
- package/bin/session/runtime/SessionTurnFileDiff.js.map +0 -1
- package/bin/types/action/ActionResult.d.ts +0 -35
- package/bin/types/action/ActionResult.d.ts.map +0 -1
- package/bin/types/action/ActionResult.js +0 -18
- package/bin/types/action/ActionResult.js.map +0 -1
- package/bin/types/executor/ModelRequest.d.ts.map +0 -1
- package/bin/types/executor/ModelRequest.js.map +0 -1
- package/bin/types/executor/SessionAssistantOutput.d.ts.map +0 -1
- package/bin/types/executor/SessionAssistantOutput.js.map +0 -1
- package/bin/types/executor/SessionToolExecutionContext.d.ts +0 -23
- package/bin/types/executor/SessionToolExecutionContext.d.ts.map +0 -1
- package/bin/types/executor/SessionToolExecutionContext.js +0 -10
- package/bin/types/executor/SessionToolExecutionContext.js.map +0 -1
- package/bin/types/executor/SessionTurnContext.d.ts.map +0 -1
- package/bin/types/executor/SessionTurnContext.js.map +0 -1
- package/bin/types/session/AdaptivePartContextPolicy.d.ts.map +0 -1
- package/bin/types/session/AdaptivePartContextPolicy.js +0 -7
- package/bin/types/session/AdaptivePartContextPolicy.js.map +0 -1
- package/bin/types/session/SessionComposition.d.ts.map +0 -1
- package/bin/types/session/SessionComposition.js +0 -8
- package/bin/types/session/SessionComposition.js.map +0 -1
- package/bin/types/session/SessionContextPolicy.d.ts +0 -70
- package/bin/types/session/SessionContextPolicy.d.ts.map +0 -1
- package/bin/types/session/SessionContextPolicy.js +0 -8
- package/bin/types/session/SessionContextPolicy.js.map +0 -1
- package/bin/types/tools/ToolActionExecutionContext.d.ts +0 -30
- package/bin/types/tools/ToolActionExecutionContext.d.ts.map +0 -1
- package/bin/types/tools/ToolActionExecutionContext.js +0 -8
- package/bin/types/tools/ToolActionExecutionContext.js.map +0 -1
- package/src/executor/Executor.ts +0 -319
- package/src/executor/README.md +0 -92
- package/src/executor/composer/system/default/assets/core.prompt.ts +0 -9
- package/src/executor/core-engine/CoreEngineLoopDecision.ts +0 -63
- package/src/executor/core-engine/CoreEngineRunner.ts +0 -458
- package/src/executor/types/SessionLoop.ts +0 -69
- package/src/executor/types/SessionPrompts.ts +0 -14
- package/src/session/DefaultSessionComposer.ts +0 -123
- package/src/session/SessionComposition.ts +0 -370
- package/src/session/SessionHookPoints.ts +0 -17
- package/src/session/SessionHooks.ts +0 -85
- package/src/session/composer/policies/AdaptivePartContextPolicy.ts +0 -307
- package/src/session/composer/policies/FullHistoryContextPolicy.ts +0 -36
- package/src/session/control/SessionInteractions.ts +0 -311
- package/src/session/execution/tools/SessionShellApprovalAdapter.ts +0 -105
- package/src/session/messages/SessionAgentActionPartWriter.ts +0 -54
- package/src/session/messages/SessionMessageInteractionWriter.ts +0 -279
- package/src/types/action/ActionResult.ts +0 -50
- package/src/types/executor/SessionToolExecutionContext.ts +0 -26
- package/src/types/session/SessionContextPolicy.ts +0 -77
- package/src/types/tools/ToolActionExecutionContext.ts +0 -32
- /package/bin/{executor/model → model}/ModelGenerate.js +0 -0
- /package/bin/{executor/model → model}/ModelRequestRunner.js +0 -0
- /package/bin/{executor/model → model}/ModelStreamConsumer.d.ts +0 -0
- /package/bin/{executor/model → model}/ModelStreamConsumer.js +0 -0
- /package/bin/{executor/model → model}/ModelStreamFailure.d.ts +0 -0
- /package/bin/{executor/model → model}/ModelStreamFailure.js +0 -0
- /package/bin/{executor → model}/messages/ChatMessageMarkup.d.ts +0 -0
- /package/bin/{executor → model}/messages/ChatMessageMarkup.js +0 -0
- /package/bin/{executor → model}/messages/SessionAttachmentMapper.d.ts +0 -0
- /package/bin/{executor → model}/messages/SessionAttachmentMapper.js +0 -0
- /package/bin/{executor → model}/messages/SessionMessageLog.d.ts +0 -0
- /package/bin/{executor → model}/messages/SessionMessageLog.js +0 -0
- /package/bin/{executor → model}/messages/SessionModelMessages.d.ts +0 -0
- /package/bin/{executor/composer/system/default → model/prompts}/SystemPromptAssets.d.ts +0 -0
- /package/bin/session/{runtime → loop}/SessionTitleTask.d.ts +0 -0
- /package/bin/session/{runtime → loop}/SessionTitleTask.js +0 -0
- /package/bin/session/{runtime → loop}/SessionTurnFileDiff.d.ts +0 -0
- /package/bin/session/{messages → loop}/SessionTurnFileDiffBuilder.js +0 -0
- /package/bin/session/{execution → messages}/SessionAssistantOutputAdapter.js +0 -0
- /package/bin/session/{runtime → messages}/SessionEventHub.d.ts +0 -0
- /package/bin/session/{runtime → messages}/SessionEventHub.js +0 -0
- /package/bin/session/{browse → messages}/SessionMessageTimeline.d.ts +0 -0
- /package/bin/session/{runtime → messages}/SessionModelRequestWarning.d.ts +0 -0
- /package/bin/session/{runtime → messages}/SessionModelRequestWarning.js +0 -0
- /package/bin/session/{preview → storage}/SessionMessagePreview.d.ts +0 -0
- /package/bin/types/{executor → model}/ModelRequest.d.ts +0 -0
- /package/bin/types/{executor → model}/ModelRequest.js +0 -0
- /package/bin/{executor/types → types/store}/SessionHistoryMeta.d.ts +0 -0
- /package/bin/{executor/types → types/store}/SessionHistoryMeta.js +0 -0
- /package/bin/types/{executor → turn}/SessionAssistantOutput.d.ts +0 -0
- /package/bin/types/{executor → turn}/SessionAssistantOutput.js +0 -0
- /package/bin/types/{executor → turn}/SessionTurnContext.js +0 -0
- /package/src/{executor/model → model}/ModelStreamFailure.ts +0 -0
- /package/src/{executor → model}/messages/ChatMessageMarkup.ts +0 -0
- /package/src/{executor → model}/messages/SessionAttachmentMapper.ts +0 -0
- /package/src/{executor → model}/messages/SessionMessageLog.ts +0 -0
- /package/src/session/{runtime → loop}/SessionTitleTask.ts +0 -0
- /package/src/session/{runtime → messages}/SessionEventHub.ts +0 -0
- /package/src/session/{runtime → messages}/SessionModelRequestWarning.ts +0 -0
- /package/src/types/{executor → model}/ModelRequest.ts +0 -0
- /package/src/{executor/types → types/store}/SessionHistoryMeta.ts +0 -0
- /package/src/types/{executor → turn}/SessionAssistantOutput.ts +0 -0
- /package/src/{executor/ids/resolveSessionId.ts → utils/ResolveSessionId.ts} +0 -0
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Session tool-loop 决策相关类型。
|
|
3
|
-
*
|
|
4
|
-
* 关键点(中文)
|
|
5
|
-
* - 这里只描述“是否继续下一轮”的纯决策输入/输出。
|
|
6
|
-
* - 不携带 runtime 实例,方便在测试中直接做纯函数验证。
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* 单轮 loop 决策输入。
|
|
11
|
-
*/
|
|
12
|
-
export interface SessionLoopDecisionInput {
|
|
13
|
-
/**
|
|
14
|
-
* 当前 step 是否检测到了不完整响应。
|
|
15
|
-
*/
|
|
16
|
-
hasIncompleteResponse: boolean;
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* 当前已经执行过多少次不完整响应恢复。
|
|
20
|
-
*/
|
|
21
|
-
incompleteRecoveryCount: number;
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* 允许执行的不完整响应恢复上限。
|
|
25
|
-
*/
|
|
26
|
-
maxIncompleteRecoveries: number;
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* 当前 step 实际产出的工具调用数量。
|
|
30
|
-
*/
|
|
31
|
-
toolCallCount: number;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
/**
|
|
35
|
-
* 单轮 loop 决策结果。
|
|
36
|
-
*/
|
|
37
|
-
export interface SessionLoopDecision {
|
|
38
|
-
/**
|
|
39
|
-
* 本轮命中的主决策类型。
|
|
40
|
-
*/
|
|
41
|
-
kind:
|
|
42
|
-
| "recover_incomplete"
|
|
43
|
-
| "continue_for_tool_calls"
|
|
44
|
-
| "stop";
|
|
45
|
-
|
|
46
|
-
/**
|
|
47
|
-
* 是否因为工具调用而继续下一轮。
|
|
48
|
-
*/
|
|
49
|
-
continueForToolCalls: boolean;
|
|
50
|
-
|
|
51
|
-
/**
|
|
52
|
-
* 是否因为不完整响应恢复而继续下一轮。
|
|
53
|
-
*/
|
|
54
|
-
continueForIncompleteRecovery: boolean;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
/**
|
|
58
|
-
* stop 分支上的尾部消息续跑判定输入。
|
|
59
|
-
*
|
|
60
|
-
* 关键点(中文)
|
|
61
|
-
* - 用于处理“最后一个 step 结束后,恰好又有新的 user 消息写入”的窗口。
|
|
62
|
-
* - 这里只关心是否真的合并到了新增 user message,不关心消息内容细节。
|
|
63
|
-
*/
|
|
64
|
-
export interface SessionTailMergeContinuationInput {
|
|
65
|
-
/**
|
|
66
|
-
* stop 前最后一次 tail merge 实际合并到的 user message 数量。
|
|
67
|
-
*/
|
|
68
|
-
mergedUserMessageCount: number;
|
|
69
|
-
}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* SessionSystemMessage:Session 运行阶段使用的 system message。
|
|
3
|
-
*
|
|
4
|
-
* 关键点(中文)
|
|
5
|
-
* - 该类型属于 Downcity Session,不依赖第三方 Provider。
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
/** Session system 消息。 */
|
|
9
|
-
export interface SessionSystemMessage {
|
|
10
|
-
/** 消息角色固定为 system。 */
|
|
11
|
-
role: "system";
|
|
12
|
-
/** 当前 system block 的文本内容。 */
|
|
13
|
-
content: string;
|
|
14
|
-
}
|
|
@@ -1,123 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 默认 Session Composer。
|
|
3
|
-
*
|
|
4
|
-
* 负责把 Session 运行快照与 Context Policy 结果组装为最终模型输入。
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
import { build_session_system_blocks } from "@/session/SessionSystem.js";
|
|
8
|
-
import type {
|
|
9
|
-
SessionComposer,
|
|
10
|
-
SessionComposeInput,
|
|
11
|
-
SessionStepInput,
|
|
12
|
-
} from "@/types/session/SessionComposer.js";
|
|
13
|
-
import type { SessionContextPolicy } from "@/types/session/SessionContextPolicy.js";
|
|
14
|
-
import { AdaptivePartContextPolicy } from "@/session/composer/policies/AdaptivePartContextPolicy.js";
|
|
15
|
-
import type { SessionHookContextBlock } from "@downcity/type";
|
|
16
|
-
import type { ModelMessage } from "@downcity/type";
|
|
17
|
-
|
|
18
|
-
/** 把低权限 Plugin 内容渲染为与用户原文分离的模型参考区。 */
|
|
19
|
-
function render_plugin_context_blocks(
|
|
20
|
-
blocks: readonly SessionHookContextBlock[],
|
|
21
|
-
): string {
|
|
22
|
-
return blocks.map((block) => [
|
|
23
|
-
`<extension-context extension="${escape_xml_attribute(block.source_plugin)}" name="${escape_xml_attribute(block.name)}" trust="reference">`,
|
|
24
|
-
block.content,
|
|
25
|
-
"</extension-context>",
|
|
26
|
-
].join("\n")).join("\n\n");
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
/** 转义模型上下文标签属性,避免 Plugin 名称破坏边界。 */
|
|
30
|
-
function escape_xml_attribute(value: string): string {
|
|
31
|
-
return value
|
|
32
|
-
.replaceAll("&", "&")
|
|
33
|
-
.replaceAll('"', """)
|
|
34
|
-
.replaceAll("<", "<")
|
|
35
|
-
.replaceAll(">", ">");
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
/** 只修改模型消息副本,把动态参考信息前置到当前最后一条 User Message。 */
|
|
39
|
-
function inject_plugin_context(
|
|
40
|
-
messages: ModelMessage[],
|
|
41
|
-
blocks: readonly SessionHookContextBlock[],
|
|
42
|
-
): ModelMessage[] {
|
|
43
|
-
if (blocks.length === 0) return messages;
|
|
44
|
-
for (let index = messages.length - 1; index >= 0; index -= 1) {
|
|
45
|
-
const message = messages[index];
|
|
46
|
-
if (!message || message.role !== "user") continue;
|
|
47
|
-
messages[index] = {
|
|
48
|
-
...message,
|
|
49
|
-
content: [{ type: "text", text: render_plugin_context_blocks(blocks) }, ...message.content],
|
|
50
|
-
};
|
|
51
|
-
break;
|
|
52
|
-
}
|
|
53
|
-
return messages;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
/** 默认 Session 执行策略。 */
|
|
57
|
-
export class DefaultSessionComposer implements SessionComposer {
|
|
58
|
-
readonly name = "default_session";
|
|
59
|
-
|
|
60
|
-
/** 当前 Composer 使用的上下文策略。 */
|
|
61
|
-
private readonly context_policy: SessionContextPolicy;
|
|
62
|
-
|
|
63
|
-
constructor(options?: {
|
|
64
|
-
/** 生成模型历史的上下文策略。 */
|
|
65
|
-
context_policy?: SessionContextPolicy;
|
|
66
|
-
}) {
|
|
67
|
-
this.context_policy = options?.context_policy || new AdaptivePartContextPolicy();
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
/** 初始化内部 Context Policy 的派生 schema。 */
|
|
71
|
-
async initialize(input: Parameters<SessionComposer["initialize"]>[0]): Promise<void> {
|
|
72
|
-
await this.context_policy.initialize({
|
|
73
|
-
storage: input.storage.composer_storage(this.context_policy.name),
|
|
74
|
-
});
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
/** 组装当前 Step 的 system、history 与 tools。 */
|
|
78
|
-
async compose(input: SessionComposeInput): Promise<SessionStepInput> {
|
|
79
|
-
const system_blocks = await build_session_system_blocks({
|
|
80
|
-
agent_id: input.session.agent_id,
|
|
81
|
-
project_root: input.session.project_root,
|
|
82
|
-
session_id: input.session.session_id,
|
|
83
|
-
created_at: input.session.created_at,
|
|
84
|
-
timezone: input.session.timezone,
|
|
85
|
-
get_instruction_system_blocks: () => [
|
|
86
|
-
...(input.state.instruction_system_blocks ?? []),
|
|
87
|
-
],
|
|
88
|
-
get_managed_plugin_system_blocks: async () => [
|
|
89
|
-
...(input.state.managed_plugin_system_blocks ?? []),
|
|
90
|
-
],
|
|
91
|
-
get_plugin_system_blocks: async () => [
|
|
92
|
-
...(input.state.plugin_system_blocks ?? []),
|
|
93
|
-
],
|
|
94
|
-
});
|
|
95
|
-
|
|
96
|
-
const context = await this.context_policy.resolve({
|
|
97
|
-
storage: input.storage.composer_storage(this.context_policy.name),
|
|
98
|
-
project_root: input.session.project_root,
|
|
99
|
-
});
|
|
100
|
-
system_blocks.push(...(context.system_blocks ?? []));
|
|
101
|
-
return {
|
|
102
|
-
system: system_blocks.map((block) => ({
|
|
103
|
-
role: "system" as const,
|
|
104
|
-
content: block.content,
|
|
105
|
-
})),
|
|
106
|
-
system_blocks,
|
|
107
|
-
messages: inject_plugin_context(context.messages, input.state.plugin_context_blocks ?? []),
|
|
108
|
-
tools: { ...input.state.tools },
|
|
109
|
-
context_diagnostics: context.diagnostics,
|
|
110
|
-
};
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
/** 把上下文恢复委托给当前 Policy。 */
|
|
114
|
-
async recover_context(input: Parameters<SessionComposer["recover_context"]>[0]): Promise<boolean> {
|
|
115
|
-
return await this.context_policy.recover({
|
|
116
|
-
storage: input.storage.composer_storage(this.context_policy.name),
|
|
117
|
-
project_root: input.session.project_root,
|
|
118
|
-
reason: input.reason,
|
|
119
|
-
model: input.model,
|
|
120
|
-
on_model_request_failure: input.on_model_request_failure,
|
|
121
|
-
});
|
|
122
|
-
}
|
|
123
|
-
}
|
|
@@ -1,370 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Session system 快照与模型输入组装边界。
|
|
3
|
-
*
|
|
4
|
-
* 关键点(中文)
|
|
5
|
-
* - 拥有 Session 创建后固定的 system snapshot;env、Tool 与 Hook 在 Step 检查点读取。
|
|
6
|
-
* - Composer 只读取本对象生成的不可变输入,不接触 Session 持久化编排。
|
|
7
|
-
* - Plugin Hook 失败只降级对应扩展内容,不改变 canonical Message。
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
import type { JsonValue } from "@downcity/type";
|
|
11
|
-
import type {
|
|
12
|
-
AgentSessionSystemBlock,
|
|
13
|
-
AgentSessionSystemSnapshot,
|
|
14
|
-
} from "@/types/agent/SessionTypes.js";
|
|
15
|
-
import type {
|
|
16
|
-
SessionComposeIdentity,
|
|
17
|
-
SessionComposeInput,
|
|
18
|
-
SessionStepInput,
|
|
19
|
-
} from "@/types/session/SessionComposer.js";
|
|
20
|
-
import type {
|
|
21
|
-
SessionHookContextBlock,
|
|
22
|
-
SessionTurnContextHookValue,
|
|
23
|
-
} from "@downcity/type";
|
|
24
|
-
import type { SessionTurnContext } from "@/types/executor/SessionTurnContext.js";
|
|
25
|
-
import type { SessionCompositionOptions } from "@/types/session/SessionComposition.js";
|
|
26
|
-
import { create_session_hook_context } from "@/session/runtime/SessionTurnContext.js";
|
|
27
|
-
import { SESSION_HOOK_POINTS } from "@/session/SessionHookPoints.js";
|
|
28
|
-
import { resolve_session_plugin_system_blocks } from "@/session/SessionSystem.js";
|
|
29
|
-
|
|
30
|
-
/** 管理当前 Session 的 system snapshot 与 Step 组装输入。 */
|
|
31
|
-
export class SessionComposition {
|
|
32
|
-
private readonly options: SessionCompositionOptions;
|
|
33
|
-
private effective_instruction_blocks: AgentSessionSystemBlock[];
|
|
34
|
-
/** 当前 Session 首次生成后固定的完整 system snapshot。 */
|
|
35
|
-
private snapshot_blocks: AgentSessionSystemBlock[] | null = null;
|
|
36
|
-
/** 当前 Session instruction 的一次性恢复任务。 */
|
|
37
|
-
private initialize_promise: Promise<void> | null = null;
|
|
38
|
-
/** 串行化 snapshot / syncshot 对 system 与 instruction.md 的修改。 */
|
|
39
|
-
private mutation_chain: Promise<void> = Promise.resolve();
|
|
40
|
-
|
|
41
|
-
constructor(options: SessionCompositionOptions) {
|
|
42
|
-
this.options = options;
|
|
43
|
-
this.effective_instruction_blocks = options.instruction_system_blocks.map(
|
|
44
|
-
(block) => ({ ...block }),
|
|
45
|
-
);
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
/** 恢复显式固化的完整 system snapshot。 */
|
|
49
|
-
async initialize(): Promise<void> {
|
|
50
|
-
if (!this.initialize_promise) {
|
|
51
|
-
this.initialize_promise = (async () => {
|
|
52
|
-
await this.options.store.initialize();
|
|
53
|
-
await this.options.composer.initialize({ storage: this.options.store });
|
|
54
|
-
const persisted_instruction = await this.options.store.read_instruction();
|
|
55
|
-
if (persisted_instruction === null) return;
|
|
56
|
-
|
|
57
|
-
const instruction = persisted_instruction.trim();
|
|
58
|
-
this.snapshot_blocks = instruction
|
|
59
|
-
? [{
|
|
60
|
-
source: "instruction" as const,
|
|
61
|
-
name: "snapshot",
|
|
62
|
-
content: instruction,
|
|
63
|
-
}]
|
|
64
|
-
: [];
|
|
65
|
-
const stable_system_blocks = this.effective_instruction_blocks
|
|
66
|
-
.filter((block) => block.source !== "instruction")
|
|
67
|
-
.map((block) => ({ ...block }));
|
|
68
|
-
this.effective_instruction_blocks = [
|
|
69
|
-
...(instruction
|
|
70
|
-
? [{
|
|
71
|
-
source: "instruction" as const,
|
|
72
|
-
name: "agent",
|
|
73
|
-
content: instruction,
|
|
74
|
-
}]
|
|
75
|
-
: []),
|
|
76
|
-
...stable_system_blocks,
|
|
77
|
-
];
|
|
78
|
-
})();
|
|
79
|
-
}
|
|
80
|
-
const initialize_promise = this.initialize_promise;
|
|
81
|
-
try {
|
|
82
|
-
await initialize_promise;
|
|
83
|
-
} catch (error) {
|
|
84
|
-
if (this.initialize_promise === initialize_promise) {
|
|
85
|
-
this.initialize_promise = null;
|
|
86
|
-
}
|
|
87
|
-
throw error;
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
/** 把当前完整 system 显式固化到 instruction.md。 */
|
|
92
|
-
async snapshot(): Promise<void> {
|
|
93
|
-
await this.run_mutation(async () => {
|
|
94
|
-
const system_snapshot = await this.read();
|
|
95
|
-
await this.write_snapshot(system_snapshot.blocks);
|
|
96
|
-
});
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
/** 使用 Agent 当前 instruction 与 Plugin 重新生成完整 system。 */
|
|
100
|
-
async syncshot(): Promise<void> {
|
|
101
|
-
await this.run_mutation(async () => {
|
|
102
|
-
await this.initialize();
|
|
103
|
-
const should_persist = await this.options.store.has_instruction();
|
|
104
|
-
const composed = await this.options.composer.compose(
|
|
105
|
-
await this.create_compose_input(undefined, 0, true),
|
|
106
|
-
);
|
|
107
|
-
const next_blocks = resolve_composed_system_blocks(composed);
|
|
108
|
-
|
|
109
|
-
if (should_persist) await this.write_snapshot(next_blocks);
|
|
110
|
-
this.effective_instruction_blocks =
|
|
111
|
-
this.options.get_instruction_system_blocks().map((block) => ({ ...block }));
|
|
112
|
-
this.snapshot_blocks = next_blocks;
|
|
113
|
-
});
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
/** 读取当前 Session 生效的完整 system 快照。 */
|
|
117
|
-
async read(): Promise<AgentSessionSystemSnapshot> {
|
|
118
|
-
await this.initialize();
|
|
119
|
-
const composed = await this.compose_for_view();
|
|
120
|
-
return {
|
|
121
|
-
session_id: this.options.session_id,
|
|
122
|
-
session: {
|
|
123
|
-
agent_id: this.options.agent_id,
|
|
124
|
-
session_id: this.options.session_id,
|
|
125
|
-
project_root: this.options.workspace_path,
|
|
126
|
-
created_at: new Date(this.options.get_created_at()).toISOString(),
|
|
127
|
-
timezone: this.options.get_timezone(),
|
|
128
|
-
},
|
|
129
|
-
blocks: resolve_composed_system_blocks(composed),
|
|
130
|
-
};
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
/** 返回当前 Session 捕获的 instruction blocks 副本。 */
|
|
134
|
-
instruction_blocks(): AgentSessionSystemBlock[] {
|
|
135
|
-
return this.effective_instruction_blocks.map((block) => ({ ...block }));
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
/** 创建 Composer 共用的稳定 Session 身份快照。 */
|
|
139
|
-
compose_identity(): SessionComposeIdentity {
|
|
140
|
-
return {
|
|
141
|
-
agent_id: this.options.agent_id,
|
|
142
|
-
session_id: this.options.session_id,
|
|
143
|
-
project_root: this.options.workspace_path,
|
|
144
|
-
created_at: this.options.get_created_at(),
|
|
145
|
-
timezone: this.options.get_timezone(),
|
|
146
|
-
};
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
/** 为 Composer 创建当前 Step 的只读 Session 快照。 */
|
|
150
|
-
async create_compose_input(
|
|
151
|
-
turn_context: SessionTurnContext | undefined,
|
|
152
|
-
retry_count: number,
|
|
153
|
-
refresh_system = false,
|
|
154
|
-
): Promise<SessionComposeInput> {
|
|
155
|
-
const instruction_system_blocks = refresh_system
|
|
156
|
-
? this.options.get_instruction_system_blocks().map((block) => ({ ...block }))
|
|
157
|
-
: this.instruction_blocks();
|
|
158
|
-
const workspace_env = Object.freeze({ ...this.options.get_workspace_env() });
|
|
159
|
-
// Plugin system 参与 Compose,必须先看到当前检查点已确定的 env 与 instruction。
|
|
160
|
-
turn_context?.step.commit({
|
|
161
|
-
workspace_env,
|
|
162
|
-
agent_systems: instruction_system_blocks.map((block) => block.content),
|
|
163
|
-
});
|
|
164
|
-
const hook_context =
|
|
165
|
-
turn_context?.step.hook_context() ||
|
|
166
|
-
create_session_hook_context({
|
|
167
|
-
session_id: this.options.session_id,
|
|
168
|
-
session_origin: this.options.session_origin,
|
|
169
|
-
project_root: this.options.workspace_path,
|
|
170
|
-
workspace_env,
|
|
171
|
-
agent_systems: this.effective_instruction_blocks.map(
|
|
172
|
-
(block) => block.content,
|
|
173
|
-
),
|
|
174
|
-
});
|
|
175
|
-
const plugin_runtime = refresh_system
|
|
176
|
-
? this.options.get_hooks()
|
|
177
|
-
: turn_context?.step.hooks || this.options.get_hooks();
|
|
178
|
-
const resolved_plugin_system_blocks = this.snapshot_blocks && !refresh_system
|
|
179
|
-
? []
|
|
180
|
-
: await resolve_session_plugin_system_blocks({
|
|
181
|
-
session_id: this.options.session_id,
|
|
182
|
-
...(turn_context?.session.turn_id
|
|
183
|
-
? { turn_id: turn_context.session.turn_id }
|
|
184
|
-
: {}),
|
|
185
|
-
hooks: plugin_runtime,
|
|
186
|
-
context: hook_context,
|
|
187
|
-
on_error: async (error) => await this.log_plugin_hook_warning(
|
|
188
|
-
SESSION_HOOK_POINTS.system_context,
|
|
189
|
-
error,
|
|
190
|
-
turn_context?.session.turn_id,
|
|
191
|
-
),
|
|
192
|
-
});
|
|
193
|
-
const plugin_context_blocks = turn_context
|
|
194
|
-
? await turn_context.step.resolve_plugin_context_blocks(async () => {
|
|
195
|
-
const hooks = turn_context.step.hooks;
|
|
196
|
-
if (!hooks) return [];
|
|
197
|
-
const value: SessionTurnContextHookValue = {
|
|
198
|
-
session_id: this.options.session_id,
|
|
199
|
-
turn_id: turn_context.session.turn_id,
|
|
200
|
-
user_messages: turn_context.input.user_messages().map((message) => ({
|
|
201
|
-
message_id: message.message_id,
|
|
202
|
-
text: message.parts
|
|
203
|
-
.filter((part) => part.type === "text")
|
|
204
|
-
.map((part) => part.text)
|
|
205
|
-
.join("\n"),
|
|
206
|
-
})),
|
|
207
|
-
blocks: [],
|
|
208
|
-
};
|
|
209
|
-
try {
|
|
210
|
-
const output = await hooks.pipeline(
|
|
211
|
-
SESSION_HOOK_POINTS.turn_context,
|
|
212
|
-
value as unknown as JsonValue,
|
|
213
|
-
) as unknown as SessionTurnContextHookValue;
|
|
214
|
-
return normalize_plugin_context_blocks(output?.blocks);
|
|
215
|
-
} catch (error) {
|
|
216
|
-
await this.log_plugin_hook_warning(
|
|
217
|
-
SESSION_HOOK_POINTS.turn_context,
|
|
218
|
-
error,
|
|
219
|
-
turn_context.session.turn_id,
|
|
220
|
-
);
|
|
221
|
-
return [];
|
|
222
|
-
}
|
|
223
|
-
})
|
|
224
|
-
: [];
|
|
225
|
-
return {
|
|
226
|
-
session: this.compose_identity(),
|
|
227
|
-
state: {
|
|
228
|
-
model: this.options.get_model(),
|
|
229
|
-
model_context_window: this.options.get_model_context_window(),
|
|
230
|
-
env: workspace_env,
|
|
231
|
-
systems: Object.freeze(
|
|
232
|
-
instruction_system_blocks.map((block) => block.content),
|
|
233
|
-
),
|
|
234
|
-
tools: Object.freeze({ ...this.options.get_tools() }),
|
|
235
|
-
instruction_system_blocks,
|
|
236
|
-
managed_plugin_system_blocks:
|
|
237
|
-
this.snapshot_blocks && !refresh_system
|
|
238
|
-
? []
|
|
239
|
-
: await this.options.get_managed_plugin_system_blocks(),
|
|
240
|
-
plugin_system_blocks: resolved_plugin_system_blocks,
|
|
241
|
-
plugin_context_blocks,
|
|
242
|
-
},
|
|
243
|
-
storage: this.options.store,
|
|
244
|
-
turn: {
|
|
245
|
-
...(turn_context ? { turn_id: turn_context.session.turn_id } : {}),
|
|
246
|
-
retry_count,
|
|
247
|
-
},
|
|
248
|
-
};
|
|
249
|
-
}
|
|
250
|
-
|
|
251
|
-
/** 固定或应用当前 Session 的 system snapshot。 */
|
|
252
|
-
apply_snapshot(input: SessionStepInput): SessionStepInput {
|
|
253
|
-
if (!this.snapshot_blocks) {
|
|
254
|
-
this.snapshot_blocks = resolve_composed_system_blocks(input);
|
|
255
|
-
}
|
|
256
|
-
return {
|
|
257
|
-
...input,
|
|
258
|
-
system: this.snapshot_blocks.map((block) => ({
|
|
259
|
-
role: "system" as const,
|
|
260
|
-
content: block.content,
|
|
261
|
-
})),
|
|
262
|
-
system_blocks: this.snapshot_blocks.map((block) => ({ ...block })),
|
|
263
|
-
};
|
|
264
|
-
}
|
|
265
|
-
|
|
266
|
-
/** Plugin 上下文 Hook 失败只降级当前扩展内容。 */
|
|
267
|
-
private async log_plugin_hook_warning(
|
|
268
|
-
point_name: string,
|
|
269
|
-
error: unknown,
|
|
270
|
-
turn_id?: string,
|
|
271
|
-
): Promise<void> {
|
|
272
|
-
try {
|
|
273
|
-
await this.options.logger.log("warn", "[agent] session plugin hook failed", {
|
|
274
|
-
session_id: this.options.session_id,
|
|
275
|
-
...(turn_id ? { turn_id } : {}),
|
|
276
|
-
point_name,
|
|
277
|
-
error: error instanceof Error ? error.message : String(error),
|
|
278
|
-
});
|
|
279
|
-
} catch {
|
|
280
|
-
// Plugin 已经降级,日志失败不能反向阻断 Session。
|
|
281
|
-
}
|
|
282
|
-
}
|
|
283
|
-
|
|
284
|
-
/** 使用统一 Composer 生成只读 system/history 查询结果。 */
|
|
285
|
-
private async compose_for_view(): Promise<SessionStepInput> {
|
|
286
|
-
const composed = await this.options.composer.compose(
|
|
287
|
-
await this.create_compose_input(undefined, 0),
|
|
288
|
-
);
|
|
289
|
-
return this.apply_snapshot(composed);
|
|
290
|
-
}
|
|
291
|
-
|
|
292
|
-
/** 串行执行一次 Session system 修改。 */
|
|
293
|
-
private async run_mutation(operation: () => Promise<void>): Promise<void> {
|
|
294
|
-
const next = this.mutation_chain.then(operation, operation);
|
|
295
|
-
this.mutation_chain = next.catch(() => undefined);
|
|
296
|
-
await next;
|
|
297
|
-
}
|
|
298
|
-
|
|
299
|
-
/** 把指定完整 system blocks 原子写入 instruction.md。 */
|
|
300
|
-
private async write_snapshot(
|
|
301
|
-
blocks: readonly AgentSessionSystemBlock[],
|
|
302
|
-
): Promise<void> {
|
|
303
|
-
await this.options.store.write_instruction(
|
|
304
|
-
blocks.map((block) => block.content).join("\n\n"),
|
|
305
|
-
);
|
|
306
|
-
}
|
|
307
|
-
}
|
|
308
|
-
|
|
309
|
-
/** 把 Turn pipeline 输出限制为低权限动态参考内容块。 */
|
|
310
|
-
function normalize_plugin_context_blocks(input: unknown): SessionHookContextBlock[] {
|
|
311
|
-
if (!Array.isArray(input)) return [];
|
|
312
|
-
return input.flatMap((item) => {
|
|
313
|
-
if (!item || typeof item !== "object" || Array.isArray(item)) return [];
|
|
314
|
-
const record = item as Record<string, unknown>;
|
|
315
|
-
const source_plugin = String(record.source_plugin || "").trim();
|
|
316
|
-
const name = String(record.name || "").trim();
|
|
317
|
-
const content = String(record.content || "").trim();
|
|
318
|
-
if (
|
|
319
|
-
!source_plugin ||
|
|
320
|
-
!name ||
|
|
321
|
-
!content ||
|
|
322
|
-
record.trust_level !== "reference"
|
|
323
|
-
) return [];
|
|
324
|
-
const citations = Array.isArray(record.citations)
|
|
325
|
-
? record.citations
|
|
326
|
-
.map((citation) => String(citation || "").trim())
|
|
327
|
-
.filter(Boolean)
|
|
328
|
-
: [];
|
|
329
|
-
const version = String(record.version || "").trim();
|
|
330
|
-
return [{
|
|
331
|
-
source_plugin,
|
|
332
|
-
name,
|
|
333
|
-
content,
|
|
334
|
-
trust_level: "reference" as const,
|
|
335
|
-
...(citations.length > 0 ? { citations } : {}),
|
|
336
|
-
...(version ? { version } : {}),
|
|
337
|
-
}];
|
|
338
|
-
});
|
|
339
|
-
}
|
|
340
|
-
|
|
341
|
-
/** 把自定义 Composer 的 system content 转为可展示文本。 */
|
|
342
|
-
function stringify_system_content(content: unknown): string {
|
|
343
|
-
if (typeof content === "string") return content.trim();
|
|
344
|
-
if (content === null || content === undefined) return "";
|
|
345
|
-
try {
|
|
346
|
-
return JSON.stringify(content);
|
|
347
|
-
} catch {
|
|
348
|
-
return String(content || "").trim();
|
|
349
|
-
}
|
|
350
|
-
}
|
|
351
|
-
|
|
352
|
-
/** 以实际模型输入为准,保留仍与其一致的 system block 来源信息。 */
|
|
353
|
-
function resolve_composed_system_blocks(
|
|
354
|
-
composed: SessionStepInput,
|
|
355
|
-
): AgentSessionSystemBlock[] {
|
|
356
|
-
const declared_blocks = composed.system_blocks || [];
|
|
357
|
-
return composed.system.flatMap((message, index) => {
|
|
358
|
-
const content = stringify_system_content(message.content);
|
|
359
|
-
if (!content) return [];
|
|
360
|
-
const declared = declared_blocks[index];
|
|
361
|
-
if (declared && declared.content.trim() === content) {
|
|
362
|
-
return [{ ...declared, content }];
|
|
363
|
-
}
|
|
364
|
-
return [{
|
|
365
|
-
source: "session" as const,
|
|
366
|
-
name: `custom_system:${index + 1}`,
|
|
367
|
-
content,
|
|
368
|
-
}];
|
|
369
|
-
});
|
|
370
|
-
}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Session 公开的稳定 Hook 检查点。
|
|
3
|
-
*
|
|
4
|
-
* 检查点由 Session 定义和触发,City Plugin 只选择是否注册处理器。
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
/** Session 运行时的 Hook point 目录。 */
|
|
8
|
-
export const SESSION_HOOK_POINTS = Object.freeze({
|
|
9
|
-
/** 建立 Session system snapshot 时允许 Hook 追加命名 blocks。 */
|
|
10
|
-
system_context: "session.system_context",
|
|
11
|
-
|
|
12
|
-
/** 当前 Turn 首次组装模型输入时允许 Hook 追加低权限参考 blocks。 */
|
|
13
|
-
turn_context: "session.turn_context",
|
|
14
|
-
|
|
15
|
-
/** canonical Turn 完成提交后通知 Hook 执行副作用。 */
|
|
16
|
-
turn_committed: "session.turn_committed",
|
|
17
|
-
} as const);
|
|
@@ -1,85 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Session Hook 运行类。
|
|
3
|
-
*
|
|
4
|
-
* SessionHooks 是 Agent 对 Hook 的唯一认识。默认实例不产生任何行为;City 等上层
|
|
5
|
-
* 组合根可以注入处理函数,并在 open() 时为单个 Step 捕获稳定作用域。
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
import type {
|
|
9
|
-
JsonValue,
|
|
10
|
-
SessionHookContext,
|
|
11
|
-
SessionHookHandlers,
|
|
12
|
-
SessionHookRuntime,
|
|
13
|
-
SessionHookScopeRuntime,
|
|
14
|
-
SessionSystemBlock,
|
|
15
|
-
} from "@downcity/type";
|
|
16
|
-
|
|
17
|
-
/** 单个 Session Step 捕获的稳定 Hook 作用域。 */
|
|
18
|
-
export class SessionHookScope implements SessionHookScopeRuntime {
|
|
19
|
-
/** 当前作用域是否已经关闭。 */
|
|
20
|
-
private closed = false;
|
|
21
|
-
|
|
22
|
-
constructor(private readonly handlers: SessionHookHandlers = {}) {}
|
|
23
|
-
|
|
24
|
-
/** 读取当前作用域提供的 system blocks。 */
|
|
25
|
-
async system_blocks(context?: SessionHookContext): Promise<SessionSystemBlock[]> {
|
|
26
|
-
return await this.handlers.system_blocks?.(context) ?? [];
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
/** 运行一个可转换值的 Hook。 */
|
|
30
|
-
async pipeline<TValue = JsonValue>(point_name: string, value: TValue): Promise<TValue> {
|
|
31
|
-
return this.handlers.pipeline
|
|
32
|
-
? await this.handlers.pipeline(point_name, value)
|
|
33
|
-
: value;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
/** 运行一个只产生副作用的 Hook。 */
|
|
37
|
-
async effect<TValue = JsonValue>(point_name: string, value: TValue): Promise<void> {
|
|
38
|
-
await this.handlers.effect?.(point_name, value);
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
/** 幂等关闭当前作用域。 */
|
|
42
|
-
async close(): Promise<void> {
|
|
43
|
-
if (this.closed) return;
|
|
44
|
-
this.closed = true;
|
|
45
|
-
await this.handlers.close?.();
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
/** Session 级 Hook 集合。 */
|
|
50
|
-
export class SessionHooks implements SessionHookRuntime {
|
|
51
|
-
constructor(private readonly handlers: SessionHookHandlers = {}) {}
|
|
52
|
-
|
|
53
|
-
/** 读取当前配置提供的 system blocks。 */
|
|
54
|
-
async system_blocks(context?: SessionHookContext): Promise<SessionSystemBlock[]> {
|
|
55
|
-
return await this.handlers.system_blocks?.(context) ?? [];
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
/** 运行一个可转换值的 Hook。 */
|
|
59
|
-
async pipeline<TValue = JsonValue>(point_name: string, value: TValue): Promise<TValue> {
|
|
60
|
-
return this.handlers.pipeline
|
|
61
|
-
? await this.handlers.pipeline(point_name, value)
|
|
62
|
-
: value;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
/** 运行一个只产生副作用的 Hook。 */
|
|
66
|
-
async effect<TValue = JsonValue>(point_name: string, value: TValue): Promise<void> {
|
|
67
|
-
await this.handlers.effect?.(point_name, value);
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
/** 为下一个 Session Step 打开稳定 Hook 作用域。 */
|
|
71
|
-
async open(): Promise<SessionHookScope> {
|
|
72
|
-
const scoped_handlers = await this.handlers.open?.();
|
|
73
|
-
if (scoped_handlers) return new SessionHookScope(scoped_handlers);
|
|
74
|
-
return new SessionHookScope({
|
|
75
|
-
system_blocks: async (context) => await this.system_blocks(context),
|
|
76
|
-
pipeline: async <TValue>(point_name: string, value: TValue) =>
|
|
77
|
-
await this.pipeline(point_name, value),
|
|
78
|
-
effect: async <TValue>(point_name: string, value: TValue) =>
|
|
79
|
-
await this.effect(point_name, value),
|
|
80
|
-
});
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
/** 不提供任何 Hook 的默认实例。 */
|
|
85
|
-
export const EMPTY_SESSION_HOOKS = new SessionHooks();
|