@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
|
@@ -0,0 +1,507 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* StepInput:为每个 Step 准备发给模型的输入。
|
|
3
|
+
*
|
|
4
|
+
* 关键点(中文)
|
|
5
|
+
* - 同时拥有「冻结的 system 快照」与「每步宿主事实采集」,因为二者互为前提:首次组装
|
|
6
|
+
* 的结果就是快照,而快照一旦冻结就不再重新采集 Power system。
|
|
7
|
+
* - 只产出输入,不发请求、不判断是否继续;请求与循环归 `SessionExecutor`。
|
|
8
|
+
* - 不拥有 Message、Turn 或 Store 生命周期。
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import type {
|
|
12
|
+
JsonValue,
|
|
13
|
+
ModelClient,
|
|
14
|
+
AgentTool as Tool,
|
|
15
|
+
SessionHookContextBlock,
|
|
16
|
+
SessionTurnContextHookValue,
|
|
17
|
+
ToolCallContext,
|
|
18
|
+
} from "@downcity/type";
|
|
19
|
+
import type { BoundAgentTool, ToolCallSite } from "@/types/tool/BoundAgentTool.js";
|
|
20
|
+
import type {
|
|
21
|
+
AgentSessionSystemBlock,
|
|
22
|
+
AgentSessionSystemSnapshot,
|
|
23
|
+
} from "@/types/agent/SessionTypes.js";
|
|
24
|
+
import type {
|
|
25
|
+
SessionComposeIdentity,
|
|
26
|
+
SessionComposeInput,
|
|
27
|
+
SessionStepInput,
|
|
28
|
+
} from "@/types/session/SessionComposer.js";
|
|
29
|
+
import type { SessionStepExecutionInput } from "@/types/session/SessionExecution.js";
|
|
30
|
+
import type { StepInputOptions } from "@/types/session/StepInput.js";
|
|
31
|
+
import type { SessionTurnContext } from "@/types/turn/SessionTurnContext.js";
|
|
32
|
+
import type { SessionDerivedStore } from "@/types/store/SessionStorage.js";
|
|
33
|
+
import { is_action_result } from "@downcity/type";
|
|
34
|
+
import { SESSION_HOOK_POINTS } from "@downcity/type";
|
|
35
|
+
import { run_pipeline_point } from "@/session/input/SessionHookRunner.js";
|
|
36
|
+
import { resolve_session_power_system_blocks } from "@/session/input/SessionSystem.js";
|
|
37
|
+
|
|
38
|
+
/** 当前 Session 的每步模型输入装配者。 */
|
|
39
|
+
export class StepInput {
|
|
40
|
+
private readonly options: StepInputOptions;
|
|
41
|
+
private effective_instruction_blocks: AgentSessionSystemBlock[];
|
|
42
|
+
/** 当前 Session 首次组装后冻结的完整 system;null 表示尚未冻结。 */
|
|
43
|
+
private frozen_blocks: AgentSessionSystemBlock[] | null = null;
|
|
44
|
+
/** 当前 Session 的一次性初始化任务。 */
|
|
45
|
+
private initialize_promise: Promise<void> | null = null;
|
|
46
|
+
/** 串行化 snapshot / syncshot 对 system 与 instruction.md 的修改。 */
|
|
47
|
+
private mutation_chain: Promise<void> = Promise.resolve();
|
|
48
|
+
|
|
49
|
+
constructor(options: StepInputOptions) {
|
|
50
|
+
this.options = options;
|
|
51
|
+
this.effective_instruction_blocks = options.instruction_system_blocks.map(
|
|
52
|
+
(block) => ({ ...block }),
|
|
53
|
+
);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/** 初始化派生 schema,并恢复显式固化的 system 快照。 */
|
|
57
|
+
async initialize(): Promise<void> {
|
|
58
|
+
if (!this.initialize_promise) {
|
|
59
|
+
this.initialize_promise = (async () => {
|
|
60
|
+
await this.options.store.initialize();
|
|
61
|
+
await this.options.composer.initialize({ derived: this.derived_store() });
|
|
62
|
+
const persisted_instruction = await this.options.store.read_instruction();
|
|
63
|
+
if (persisted_instruction === null) return;
|
|
64
|
+
|
|
65
|
+
const instruction = persisted_instruction.trim();
|
|
66
|
+
this.frozen_blocks = instruction
|
|
67
|
+
? [{
|
|
68
|
+
source: "instruction" as const,
|
|
69
|
+
name: "snapshot",
|
|
70
|
+
content: instruction,
|
|
71
|
+
}]
|
|
72
|
+
: [];
|
|
73
|
+
const stable_system_blocks = this.effective_instruction_blocks
|
|
74
|
+
.filter((block) => block.source !== "instruction")
|
|
75
|
+
.map((block) => ({ ...block }));
|
|
76
|
+
this.effective_instruction_blocks = [
|
|
77
|
+
...(instruction
|
|
78
|
+
? [{
|
|
79
|
+
source: "instruction" as const,
|
|
80
|
+
name: "agent",
|
|
81
|
+
content: instruction,
|
|
82
|
+
}]
|
|
83
|
+
: []),
|
|
84
|
+
...stable_system_blocks,
|
|
85
|
+
];
|
|
86
|
+
})();
|
|
87
|
+
}
|
|
88
|
+
const initialize_promise = this.initialize_promise;
|
|
89
|
+
try {
|
|
90
|
+
await initialize_promise;
|
|
91
|
+
} catch (error) {
|
|
92
|
+
if (this.initialize_promise === initialize_promise) {
|
|
93
|
+
this.initialize_promise = null;
|
|
94
|
+
}
|
|
95
|
+
throw error;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* 为下一个 Provider Step 组装唯一一份输入。
|
|
101
|
+
*
|
|
102
|
+
* 关键点(中文)
|
|
103
|
+
* - 调用方必须先提交 Session 统一输入队列,再调用本方法。
|
|
104
|
+
* - 首次调用会把组装出的完整 system 冻结为当前 Session 的 system 快照。
|
|
105
|
+
*/
|
|
106
|
+
async build(
|
|
107
|
+
turn_context: SessionTurnContext,
|
|
108
|
+
advance_count: number,
|
|
109
|
+
): Promise<SessionStepExecutionInput> {
|
|
110
|
+
const compose_input = await this.gather(turn_context, advance_count);
|
|
111
|
+
const model = compose_input.state.model;
|
|
112
|
+
if (!model) throw new Error("requires a configured model.");
|
|
113
|
+
turn_context.step.commit({
|
|
114
|
+
workspace_env: compose_input.state.env,
|
|
115
|
+
agent_systems: compose_input.state.systems,
|
|
116
|
+
});
|
|
117
|
+
const composed = await this.options.composer.compose(compose_input);
|
|
118
|
+
const frozen = this.apply_frozen_system(composed);
|
|
119
|
+
return {
|
|
120
|
+
model,
|
|
121
|
+
system: frozen.system,
|
|
122
|
+
messages: frozen.messages,
|
|
123
|
+
tools: this.bind_turn_context_to_tools(frozen.tools, turn_context),
|
|
124
|
+
...(compose_input.state.model_context_window !== undefined
|
|
125
|
+
? { context_window: compose_input.state.model_context_window }
|
|
126
|
+
: {}),
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/** 把当前完整 system 显式固化到 instruction.md。 */
|
|
131
|
+
async snapshot(): Promise<void> {
|
|
132
|
+
await this.run_mutation(async () => {
|
|
133
|
+
const system_snapshot = await this.read_system();
|
|
134
|
+
await this.write_snapshot(system_snapshot.blocks);
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/** 使用 Agent 当前 instruction 与 Power 重新生成完整 system。 */
|
|
139
|
+
async syncshot(): Promise<void> {
|
|
140
|
+
await this.run_mutation(async () => {
|
|
141
|
+
await this.initialize();
|
|
142
|
+
const should_persist = await this.options.store.has_instruction();
|
|
143
|
+
const composed = await this.options.composer.compose(
|
|
144
|
+
await this.gather(undefined, 0, true),
|
|
145
|
+
);
|
|
146
|
+
const next_blocks = resolve_composed_system_blocks(composed);
|
|
147
|
+
|
|
148
|
+
if (should_persist) await this.write_snapshot(next_blocks);
|
|
149
|
+
this.effective_instruction_blocks =
|
|
150
|
+
this.options.get_instruction_system_blocks().map((block) => ({ ...block }));
|
|
151
|
+
this.frozen_blocks = next_blocks;
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/** 读取当前 Session 生效的完整 system 快照。 */
|
|
156
|
+
async read_system(): Promise<AgentSessionSystemSnapshot> {
|
|
157
|
+
await this.initialize();
|
|
158
|
+
const composed = await this.options.composer.compose(
|
|
159
|
+
await this.gather(undefined, 0),
|
|
160
|
+
);
|
|
161
|
+
return {
|
|
162
|
+
session_id: this.options.session_id,
|
|
163
|
+
session: {
|
|
164
|
+
agent_id: this.options.agent_id,
|
|
165
|
+
session_id: this.options.session_id,
|
|
166
|
+
project_root: this.options.workspace_path,
|
|
167
|
+
created_at: new Date(this.options.get_created_at()).toISOString(),
|
|
168
|
+
timezone: this.options.get_timezone(),
|
|
169
|
+
},
|
|
170
|
+
blocks: resolve_composed_system_blocks(this.apply_frozen_system(composed)),
|
|
171
|
+
};
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
/** 返回当前 Session 捕获的 instruction blocks 副本。 */
|
|
175
|
+
instruction_blocks(): AgentSessionSystemBlock[] {
|
|
176
|
+
return this.effective_instruction_blocks.map((block) => ({ ...block }));
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
/** 创建 Composer 共用的稳定 Session 身份快照。 */
|
|
180
|
+
identity(): SessionComposeIdentity {
|
|
181
|
+
return {
|
|
182
|
+
agent_id: this.options.agent_id,
|
|
183
|
+
session_id: this.options.session_id,
|
|
184
|
+
project_root: this.options.workspace_path,
|
|
185
|
+
created_at: this.options.get_created_at(),
|
|
186
|
+
timezone: this.options.get_timezone(),
|
|
187
|
+
};
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
/** 采集当前 Step 的宿主事实,交给 Composer 组装。 */
|
|
191
|
+
private async gather(
|
|
192
|
+
turn_context: SessionTurnContext | undefined,
|
|
193
|
+
advance_count: number,
|
|
194
|
+
refresh_system = false,
|
|
195
|
+
): Promise<SessionComposeInput> {
|
|
196
|
+
const instruction_system_blocks = refresh_system
|
|
197
|
+
? this.options.get_instruction_system_blocks().map((block) => ({ ...block }))
|
|
198
|
+
: this.instruction_blocks();
|
|
199
|
+
const workspace_env = Object.freeze({ ...this.options.get_workspace_env() });
|
|
200
|
+
// Power system 参与 Compose,必须先看到当前检查点已确定的 env 与 instruction。
|
|
201
|
+
turn_context?.step.commit({
|
|
202
|
+
workspace_env,
|
|
203
|
+
agent_systems: instruction_system_blocks.map((block) => block.content),
|
|
204
|
+
});
|
|
205
|
+
const call_context = turn_context
|
|
206
|
+
? this.create_tool_call_context(turn_context, {
|
|
207
|
+
tool_call_id: "",
|
|
208
|
+
messages: [],
|
|
209
|
+
})
|
|
210
|
+
: this.create_session_call_context(workspace_env);
|
|
211
|
+
const hooks = this.options.get_hooks();
|
|
212
|
+
const resolved_power_system_blocks = this.frozen_blocks && !refresh_system
|
|
213
|
+
? []
|
|
214
|
+
: await resolve_session_power_system_blocks({
|
|
215
|
+
session_id: this.options.session_id,
|
|
216
|
+
...(turn_context?.session.turn_id
|
|
217
|
+
? { turn_id: turn_context.session.turn_id }
|
|
218
|
+
: {}),
|
|
219
|
+
hooks,
|
|
220
|
+
context: call_context,
|
|
221
|
+
on_error: async (error) => await this.log_power_hook_warning(
|
|
222
|
+
SESSION_HOOK_POINTS.system_context,
|
|
223
|
+
error,
|
|
224
|
+
turn_context?.session.turn_id,
|
|
225
|
+
),
|
|
226
|
+
});
|
|
227
|
+
const power_context_blocks = turn_context
|
|
228
|
+
? await turn_context.step.resolve_power_context_blocks(async () => {
|
|
229
|
+
const value: SessionTurnContextHookValue = {
|
|
230
|
+
session_id: this.options.session_id,
|
|
231
|
+
turn_id: turn_context.session.turn_id,
|
|
232
|
+
user_messages: turn_context.input.user_messages().map((message) => ({
|
|
233
|
+
message_id: message.message_id,
|
|
234
|
+
text: message.parts
|
|
235
|
+
.filter((part) => part.type === "text")
|
|
236
|
+
.map((part) => part.text)
|
|
237
|
+
.join("\n"),
|
|
238
|
+
})),
|
|
239
|
+
blocks: [],
|
|
240
|
+
};
|
|
241
|
+
try {
|
|
242
|
+
const output = await run_pipeline_point({
|
|
243
|
+
hooks,
|
|
244
|
+
point_name: SESSION_HOOK_POINTS.turn_context,
|
|
245
|
+
value: value as unknown as JsonValue,
|
|
246
|
+
context: call_context,
|
|
247
|
+
});
|
|
248
|
+
return normalize_power_context_blocks(
|
|
249
|
+
(output as unknown as SessionTurnContextHookValue)?.blocks,
|
|
250
|
+
);
|
|
251
|
+
} catch (error) {
|
|
252
|
+
await this.log_power_hook_warning(
|
|
253
|
+
SESSION_HOOK_POINTS.turn_context,
|
|
254
|
+
error,
|
|
255
|
+
turn_context.session.turn_id,
|
|
256
|
+
);
|
|
257
|
+
return [];
|
|
258
|
+
}
|
|
259
|
+
})
|
|
260
|
+
: [];
|
|
261
|
+
return {
|
|
262
|
+
session: this.identity(),
|
|
263
|
+
state: {
|
|
264
|
+
model: this.options.get_model(),
|
|
265
|
+
model_context_window: this.options.get_model_context_window(),
|
|
266
|
+
env: workspace_env,
|
|
267
|
+
systems: Object.freeze(
|
|
268
|
+
instruction_system_blocks.map((block) => block.content),
|
|
269
|
+
),
|
|
270
|
+
tools: Object.freeze({ ...this.options.get_tools() }),
|
|
271
|
+
instruction_system_blocks,
|
|
272
|
+
power_system_blocks: resolved_power_system_blocks,
|
|
273
|
+
power_context_blocks,
|
|
274
|
+
},
|
|
275
|
+
history: await this.options.store.list_messages(),
|
|
276
|
+
derived: this.derived_store(),
|
|
277
|
+
turn: {
|
|
278
|
+
...(turn_context ? { turn_id: turn_context.session.turn_id } : {}),
|
|
279
|
+
advance_count,
|
|
280
|
+
},
|
|
281
|
+
};
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
/** 返回当前 Composer 命名空间的派生存储视图。 */
|
|
285
|
+
private derived_store(): SessionDerivedStore {
|
|
286
|
+
return this.options.store.derived_store(this.options.composer.name);
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
/**
|
|
290
|
+
* 冻结或套用当前 Session 的 system 快照。
|
|
291
|
+
*
|
|
292
|
+
* 关键点(中文):首次调用把组装结果记成快照;之后每次都覆盖为快照,保证同一 Session
|
|
293
|
+
* 的 system 不再漂移。
|
|
294
|
+
*/
|
|
295
|
+
private apply_frozen_system(input: SessionStepInput): SessionStepInput {
|
|
296
|
+
if (!this.frozen_blocks) {
|
|
297
|
+
this.frozen_blocks = resolve_composed_system_blocks(input);
|
|
298
|
+
}
|
|
299
|
+
return {
|
|
300
|
+
...input,
|
|
301
|
+
system: this.frozen_blocks.map((block) => ({
|
|
302
|
+
role: "system" as const,
|
|
303
|
+
content: block.content,
|
|
304
|
+
})),
|
|
305
|
+
system_blocks: this.frozen_blocks.map((block) => ({ ...block })),
|
|
306
|
+
};
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
/** Power 上下文 Hook 失败只降级当前扩展内容。 */
|
|
310
|
+
private async log_power_hook_warning(
|
|
311
|
+
point_name: string,
|
|
312
|
+
error: unknown,
|
|
313
|
+
turn_id?: string,
|
|
314
|
+
): Promise<void> {
|
|
315
|
+
try {
|
|
316
|
+
await this.options.logger.log("warn", "[agent] session power hook failed", {
|
|
317
|
+
session_id: this.options.session_id,
|
|
318
|
+
...(turn_id ? { turn_id } : {}),
|
|
319
|
+
point_name,
|
|
320
|
+
error: error instanceof Error ? error.message : String(error),
|
|
321
|
+
});
|
|
322
|
+
} catch {
|
|
323
|
+
// Power 已经降级,日志失败不能反向阻断 Session。
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
/** 串行执行一次 Session system 修改。 */
|
|
328
|
+
private async run_mutation(operation: () => Promise<void>): Promise<void> {
|
|
329
|
+
const next = this.mutation_chain.then(operation, operation);
|
|
330
|
+
this.mutation_chain = next.catch(() => undefined);
|
|
331
|
+
await next;
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
/** 把指定完整 system blocks 原子写入 instruction.md。 */
|
|
335
|
+
private async write_snapshot(
|
|
336
|
+
blocks: readonly AgentSessionSystemBlock[],
|
|
337
|
+
): Promise<void> {
|
|
338
|
+
await this.options.store.write_instruction(
|
|
339
|
+
blocks.map((block) => block.content).join("\n\n"),
|
|
340
|
+
);
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
/**
|
|
344
|
+
* 把工具包装为已绑定调用环境的工具。
|
|
345
|
+
*
|
|
346
|
+
* 关键点(中文)
|
|
347
|
+
* - 包装层是上下文注入的唯一位置:捕获 Session 级信息,并在每次调用时
|
|
348
|
+
* 合并模型 Step 提供的调用身份与消息快照。
|
|
349
|
+
* - 每个 step 使用独立包装,不会在并行 Session 间共享可变指针。
|
|
350
|
+
*/
|
|
351
|
+
private bind_turn_context_to_tools(
|
|
352
|
+
tools: Record<string, Tool>,
|
|
353
|
+
turn_context: SessionTurnContext,
|
|
354
|
+
): Record<string, BoundAgentTool> {
|
|
355
|
+
const wrapped: Record<string, BoundAgentTool> = {};
|
|
356
|
+
for (const [name, tool] of Object.entries(tools)) {
|
|
357
|
+
const original_execute = tool.execute;
|
|
358
|
+
if (typeof original_execute !== "function") {
|
|
359
|
+
wrapped[name] = tool as unknown as BoundAgentTool;
|
|
360
|
+
continue;
|
|
361
|
+
}
|
|
362
|
+
wrapped[name] = {
|
|
363
|
+
...tool,
|
|
364
|
+
execute: async (args: unknown, site: ToolCallSite) => {
|
|
365
|
+
const tool_call_id = String(site.tool_call_id || "").trim();
|
|
366
|
+
if (!tool_call_id) {
|
|
367
|
+
throw new Error(`Tool execution requires toolCallId: ${name}`);
|
|
368
|
+
}
|
|
369
|
+
if (turn_context.output.assistant) {
|
|
370
|
+
await turn_context.output.assistant.prepare_tool_input({
|
|
371
|
+
tool_call_id,
|
|
372
|
+
tool_name: name,
|
|
373
|
+
input: args,
|
|
374
|
+
});
|
|
375
|
+
}
|
|
376
|
+
const context = this.create_tool_call_context(turn_context, {
|
|
377
|
+
tool_call_id,
|
|
378
|
+
abort_signal: site.abort_signal || turn_context.lifecycle.abort_signal,
|
|
379
|
+
messages: site.messages,
|
|
380
|
+
});
|
|
381
|
+
const output = await original_execute(args, context);
|
|
382
|
+
if (!is_action_result(output)) return output;
|
|
383
|
+
if (Array.isArray(output.effects)) {
|
|
384
|
+
turn_context.effects.append(output.effects);
|
|
385
|
+
}
|
|
386
|
+
for (const message of output.messages) {
|
|
387
|
+
if (message.role === "agent") {
|
|
388
|
+
turn_context.output.enqueue_assistant_parts(message.parts);
|
|
389
|
+
continue;
|
|
390
|
+
}
|
|
391
|
+
await turn_context.input.append_internal(message.parts);
|
|
392
|
+
}
|
|
393
|
+
return output.output;
|
|
394
|
+
},
|
|
395
|
+
};
|
|
396
|
+
}
|
|
397
|
+
return wrapped;
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
/** 构造不属任何 Turn 的调用环境;用于 system 查询。 */
|
|
401
|
+
private create_session_call_context(
|
|
402
|
+
workspace_env: Readonly<Record<string, string>>,
|
|
403
|
+
): ToolCallContext {
|
|
404
|
+
const workspace = this.options.get_workspace?.();
|
|
405
|
+
return Object.freeze({
|
|
406
|
+
agent_id: this.options.agent_id,
|
|
407
|
+
agent_name: this.options.agent_name,
|
|
408
|
+
agent_description: this.options.agent_description,
|
|
409
|
+
agent_instructions: Object.freeze(
|
|
410
|
+
this.effective_instruction_blocks.map((block) => block.content),
|
|
411
|
+
),
|
|
412
|
+
session_id: this.options.session_id,
|
|
413
|
+
session_origin: this.options.session_origin,
|
|
414
|
+
...(workspace ? { workspace } : {}),
|
|
415
|
+
messages: Object.freeze([]),
|
|
416
|
+
workspace_env,
|
|
417
|
+
});
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
/** 构造一次工具调用获得的值快照。 */
|
|
421
|
+
private create_tool_call_context(
|
|
422
|
+
turn_context: SessionTurnContext,
|
|
423
|
+
site: ToolCallSite,
|
|
424
|
+
): ToolCallContext {
|
|
425
|
+
const workspace_env = turn_context.step.workspace_env;
|
|
426
|
+
const agent_systems = turn_context.step.agent_systems;
|
|
427
|
+
const workspace = this.options.get_workspace?.();
|
|
428
|
+
return Object.freeze({
|
|
429
|
+
agent_id: this.options.agent_id,
|
|
430
|
+
agent_name: this.options.agent_name,
|
|
431
|
+
agent_description: this.options.agent_description,
|
|
432
|
+
agent_instructions: Object.freeze([...(agent_systems ?? [])]),
|
|
433
|
+
session_id: this.options.session_id,
|
|
434
|
+
session_origin: this.options.session_origin,
|
|
435
|
+
...(workspace ? { workspace } : {}),
|
|
436
|
+
turn_id: turn_context.session.turn_id,
|
|
437
|
+
abort_signal: site.abort_signal,
|
|
438
|
+
tool_call_id: site.tool_call_id,
|
|
439
|
+
messages: site.messages,
|
|
440
|
+
interactions: turn_context.interactions,
|
|
441
|
+
...(workspace_env ? { workspace_env } : {}),
|
|
442
|
+
});
|
|
443
|
+
}
|
|
444
|
+
}
|
|
445
|
+
|
|
446
|
+
/** 把 Turn pipeline 输出限制为低权限动态参考内容块。 */
|
|
447
|
+
function normalize_power_context_blocks(input: unknown): SessionHookContextBlock[] {
|
|
448
|
+
if (!Array.isArray(input)) return [];
|
|
449
|
+
return input.flatMap((item) => {
|
|
450
|
+
if (!item || typeof item !== "object" || Array.isArray(item)) return [];
|
|
451
|
+
const record = item as Record<string, unknown>;
|
|
452
|
+
const source_power = String(record.source_power || "").trim();
|
|
453
|
+
const name = String(record.name || "").trim();
|
|
454
|
+
const content = String(record.content || "").trim();
|
|
455
|
+
if (
|
|
456
|
+
!source_power ||
|
|
457
|
+
!name ||
|
|
458
|
+
!content ||
|
|
459
|
+
record.trust_level !== "reference"
|
|
460
|
+
) return [];
|
|
461
|
+
const citations = Array.isArray(record.citations)
|
|
462
|
+
? record.citations
|
|
463
|
+
.map((citation) => String(citation || "").trim())
|
|
464
|
+
.filter(Boolean)
|
|
465
|
+
: [];
|
|
466
|
+
const version = String(record.version || "").trim();
|
|
467
|
+
return [{
|
|
468
|
+
source_power,
|
|
469
|
+
name,
|
|
470
|
+
content,
|
|
471
|
+
trust_level: "reference" as const,
|
|
472
|
+
...(citations.length > 0 ? { citations } : {}),
|
|
473
|
+
...(version ? { version } : {}),
|
|
474
|
+
}];
|
|
475
|
+
});
|
|
476
|
+
}
|
|
477
|
+
|
|
478
|
+
/** 把自定义 Composer 的 system content 转为可展示文本。 */
|
|
479
|
+
function stringify_system_content(content: unknown): string {
|
|
480
|
+
if (typeof content === "string") return content.trim();
|
|
481
|
+
if (content === null || content === undefined) return "";
|
|
482
|
+
try {
|
|
483
|
+
return JSON.stringify(content);
|
|
484
|
+
} catch {
|
|
485
|
+
return String(content || "").trim();
|
|
486
|
+
}
|
|
487
|
+
}
|
|
488
|
+
|
|
489
|
+
/** 以实际模型输入为准,保留仍与其一致的 system block 来源信息。 */
|
|
490
|
+
function resolve_composed_system_blocks(
|
|
491
|
+
composed: SessionStepInput,
|
|
492
|
+
): AgentSessionSystemBlock[] {
|
|
493
|
+
const declared_blocks = composed.system_blocks || [];
|
|
494
|
+
return composed.system.flatMap((message, index) => {
|
|
495
|
+
const content = stringify_system_content(message.content);
|
|
496
|
+
if (!content) return [];
|
|
497
|
+
const declared = declared_blocks[index];
|
|
498
|
+
if (declared && declared.content.trim() === content) {
|
|
499
|
+
return [{ ...declared, content }];
|
|
500
|
+
}
|
|
501
|
+
return [{
|
|
502
|
+
source: "session" as const,
|
|
503
|
+
name: `custom_system:${index + 1}`,
|
|
504
|
+
content,
|
|
505
|
+
}];
|
|
506
|
+
});
|
|
507
|
+
}
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 上下文 checkpoint 的派生表读写。
|
|
3
|
+
*
|
|
4
|
+
* checkpoint 只记录「累计摘要覆盖到哪个 canonical Part」。它属于 Composer 自己的派生
|
|
5
|
+
* 数据:结构不兼容时直接丢弃重建,因为摘要可以从 canonical history 重新累积。
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { generate_id } from "@/utils/Id.js";
|
|
9
|
+
import type { ContextCheckpointRow } from "@/types/session/ContextCheckpoint.js";
|
|
10
|
+
import type { SessionDerivedStore } from "@/types/store/SessionStorage.js";
|
|
11
|
+
|
|
12
|
+
/** checkpoint schema 版本;版本或列结构变化时旧派生表会被重建。 */
|
|
13
|
+
export const CHECKPOINT_SCHEMA_VERSION = 1;
|
|
14
|
+
|
|
15
|
+
/** 返回指定 Composer 命名空间的 checkpoint 表名。 */
|
|
16
|
+
export function checkpoint_table(composer_name: string): string {
|
|
17
|
+
return `composer_${composer_name}_checkpoints`;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* 建立 checkpoint schema。
|
|
22
|
+
*
|
|
23
|
+
* 关键点(中文):派生表可以重建,因此旧结构的表在初始化时被丢弃;新表从当前
|
|
24
|
+
* canonical history 重新累积摘要,不需要迁移脚本。
|
|
25
|
+
*/
|
|
26
|
+
export async function initialize_checkpoint_schema(
|
|
27
|
+
derived: SessionDerivedStore,
|
|
28
|
+
composer_name: string,
|
|
29
|
+
): Promise<void> {
|
|
30
|
+
const table = checkpoint_table(composer_name);
|
|
31
|
+
const compatible = await has_compatible_schema(derived, table);
|
|
32
|
+
await derived.transaction((transaction) => {
|
|
33
|
+
if (!compatible) transaction.execute(`DROP TABLE IF EXISTS ${table}`);
|
|
34
|
+
transaction.execute(`
|
|
35
|
+
CREATE TABLE IF NOT EXISTS ${table} (
|
|
36
|
+
checkpoint_id TEXT PRIMARY KEY,
|
|
37
|
+
through_message_id TEXT NOT NULL REFERENCES messages(message_id) ON DELETE CASCADE,
|
|
38
|
+
through_message_sequence INTEGER NOT NULL,
|
|
39
|
+
through_part_sequence INTEGER NOT NULL,
|
|
40
|
+
summary TEXT NOT NULL,
|
|
41
|
+
schema_version INTEGER NOT NULL,
|
|
42
|
+
created_at INTEGER NOT NULL,
|
|
43
|
+
UNIQUE(through_message_sequence, through_part_sequence, schema_version)
|
|
44
|
+
)
|
|
45
|
+
`);
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/** 读取当前版本位置最靠后的累计 checkpoint。 */
|
|
50
|
+
export async function read_latest_checkpoint(
|
|
51
|
+
derived: SessionDerivedStore,
|
|
52
|
+
composer_name: string,
|
|
53
|
+
): Promise<ContextCheckpointRow | null> {
|
|
54
|
+
const table = checkpoint_table(composer_name);
|
|
55
|
+
return await derived.transaction((transaction) =>
|
|
56
|
+
transaction.get<ContextCheckpointRow>(`
|
|
57
|
+
SELECT checkpoint_id, through_message_id, through_message_sequence,
|
|
58
|
+
through_part_sequence, summary, schema_version, created_at
|
|
59
|
+
FROM ${table}
|
|
60
|
+
WHERE schema_version = ?
|
|
61
|
+
ORDER BY through_message_sequence DESC, through_part_sequence DESC
|
|
62
|
+
LIMIT 1
|
|
63
|
+
`, [CHECKPOINT_SCHEMA_VERSION])
|
|
64
|
+
);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/** 追加一条累计 checkpoint。 */
|
|
68
|
+
export async function insert_checkpoint(
|
|
69
|
+
derived: SessionDerivedStore,
|
|
70
|
+
composer_name: string,
|
|
71
|
+
input: {
|
|
72
|
+
/** 边界所属 Message 标识。 */
|
|
73
|
+
through_message_id: string;
|
|
74
|
+
/** 边界所属 Message sequence。 */
|
|
75
|
+
through_message_sequence: number;
|
|
76
|
+
/** 边界 Part sequence。 */
|
|
77
|
+
through_part_sequence: number;
|
|
78
|
+
/** 截至边界的累计摘要正文。 */
|
|
79
|
+
summary: string;
|
|
80
|
+
},
|
|
81
|
+
): Promise<void> {
|
|
82
|
+
const table = checkpoint_table(composer_name);
|
|
83
|
+
await derived.transaction((transaction) => {
|
|
84
|
+
transaction.execute(`
|
|
85
|
+
INSERT INTO ${table} (
|
|
86
|
+
checkpoint_id, through_message_id, through_message_sequence,
|
|
87
|
+
through_part_sequence, summary, schema_version, created_at
|
|
88
|
+
) VALUES (?, ?, ?, ?, ?, ?, ?)
|
|
89
|
+
`, [
|
|
90
|
+
`checkpoint:${generate_id()}`,
|
|
91
|
+
input.through_message_id,
|
|
92
|
+
input.through_message_sequence,
|
|
93
|
+
input.through_part_sequence,
|
|
94
|
+
input.summary,
|
|
95
|
+
CHECKPOINT_SCHEMA_VERSION,
|
|
96
|
+
Date.now(),
|
|
97
|
+
]);
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/** 探测现有派生表是否具备当前列结构。 */
|
|
102
|
+
async function has_compatible_schema(
|
|
103
|
+
derived: SessionDerivedStore,
|
|
104
|
+
table: string,
|
|
105
|
+
): Promise<boolean> {
|
|
106
|
+
try {
|
|
107
|
+
await derived.transaction((transaction) =>
|
|
108
|
+
transaction.get(`SELECT schema_version FROM ${table} LIMIT 1`)
|
|
109
|
+
);
|
|
110
|
+
return true;
|
|
111
|
+
} catch {
|
|
112
|
+
// 表缺失或列结构不兼容都由建表语句一次性收敛。
|
|
113
|
+
return false;
|
|
114
|
+
}
|
|
115
|
+
}
|