@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
|
@@ -3,12 +3,12 @@
|
|
|
3
3
|
*
|
|
4
4
|
* 关键点(中文)
|
|
5
5
|
* - 统一管理 session 缓存、创建、恢复、默认配置注入与列表查询。
|
|
6
|
-
* - 该服务只负责 Session 生命周期与查询,不负责
|
|
6
|
+
* - 该服务只负责 Session 生命周期与查询,不负责 Power / RPC 启停。
|
|
7
7
|
* - Session 对象创建细节集中在这里,避免 facade 和 lifecycle 重复依赖 Session 构造逻辑。
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
10
|
import { nanoid } from "nanoid";
|
|
11
|
-
import type { ModelClient,
|
|
11
|
+
import type { ModelClient, AgentTool as Tool } from "@downcity/type";
|
|
12
12
|
import type { Logger } from "@/utils/logger/Logger.js";
|
|
13
13
|
import type {
|
|
14
14
|
AgentCreateSessionInput,
|
|
@@ -31,8 +31,8 @@ import { Session } from "@/session/Session.js";
|
|
|
31
31
|
import type { SessionPort } from "@/types/session/SessionPort.js";
|
|
32
32
|
import type { SessionComposer } from "@/types/session/SessionComposer.js";
|
|
33
33
|
import { create_instruction_system_blocks } from "@/agent/AgentInstructions.js";
|
|
34
|
-
import { DefaultSessionComposer } from "@/session/DefaultSessionComposer.js";
|
|
35
|
-
import type {
|
|
34
|
+
import { DefaultSessionComposer } from "@/session/input/composer/DefaultSessionComposer.js";
|
|
35
|
+
import type { ToolHookSet } from "@downcity/type";
|
|
36
36
|
import type { SessionStore } from "@/types/store/SessionStore.js";
|
|
37
37
|
import type { SessionStorage } from "@/types/store/SessionStorage.js";
|
|
38
38
|
import type { WorkspaceRuntime } from "@downcity/type";
|
|
@@ -45,6 +45,16 @@ type AgentSessionsOptions = {
|
|
|
45
45
|
*/
|
|
46
46
|
agent_id: string;
|
|
47
47
|
|
|
48
|
+
/**
|
|
49
|
+
* 当前 agent 用户可见名称;为空时回退到 agent_id。
|
|
50
|
+
*/
|
|
51
|
+
agent_name: string;
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* 当前 agent 一句话能力描述;进入工具与扩展的调用环境。
|
|
55
|
+
*/
|
|
56
|
+
agent_description: string;
|
|
57
|
+
|
|
48
58
|
/**
|
|
49
59
|
* 按 Session 解析执行上下文。
|
|
50
60
|
*
|
|
@@ -57,7 +67,8 @@ type AgentSessionsOptions = {
|
|
|
57
67
|
logger: Logger;
|
|
58
68
|
get_tools: () => Record<string, Tool>;
|
|
59
69
|
get_workspace_env: () => Record<string, string>;
|
|
60
|
-
|
|
70
|
+
get_workspace: () => WorkspaceRuntime | undefined;
|
|
71
|
+
get_hooks: () => ToolHookSet;
|
|
61
72
|
store: SessionStore;
|
|
62
73
|
};
|
|
63
74
|
|
|
@@ -71,24 +82,16 @@ type AgentSessionsOptions = {
|
|
|
71
82
|
*/
|
|
72
83
|
get_instruction: () => string[];
|
|
73
84
|
|
|
74
|
-
/**
|
|
75
|
-
* 等待当前 Agent 持有的长期运行时启动完成。
|
|
76
|
-
*/
|
|
77
|
-
ensure_agent_ready: () => Promise<void>;
|
|
78
|
-
|
|
79
85
|
/**
|
|
80
86
|
* 当前 agent 使用的本地 Session 类。
|
|
81
87
|
*/
|
|
82
88
|
session_class?: AgentSessionConstructor;
|
|
83
89
|
|
|
84
|
-
/**
|
|
85
|
-
|
|
90
|
+
/** 当前 Agent 使用的 Session Composer;其所有 Session 共享该实例。 */
|
|
91
|
+
session_composer?: SessionComposer;
|
|
86
92
|
|
|
87
93
|
/** 读取 Agent 当前持有的运行时模型实例。 */
|
|
88
94
|
get_agent_model: () => ModelClient | undefined;
|
|
89
|
-
|
|
90
|
-
/** Session 创建或恢复后的内部路由登记回调。 */
|
|
91
|
-
on_session_routed?: (session_id: string, sessions: AgentSessions) => void;
|
|
92
95
|
};
|
|
93
96
|
|
|
94
97
|
/**
|
|
@@ -96,27 +99,26 @@ type AgentSessionsOptions = {
|
|
|
96
99
|
*/
|
|
97
100
|
export class AgentSessions implements AgentSessionsContract<AgentSession> {
|
|
98
101
|
private readonly agent_id: string;
|
|
102
|
+
private readonly agent_name: string;
|
|
103
|
+
private readonly agent_description: string;
|
|
99
104
|
private readonly resolve_session_context: AgentSessionsOptions["resolve_session_context"];
|
|
100
105
|
private readonly logger: Logger;
|
|
101
106
|
private readonly get_instruction: AgentSessionsOptions["get_instruction"];
|
|
102
|
-
private readonly ensure_agent_ready: AgentSessionsOptions["ensure_agent_ready"];
|
|
103
107
|
private readonly session_class: AgentSessionConstructor;
|
|
104
|
-
private readonly
|
|
108
|
+
private readonly session_composer: SessionComposer;
|
|
105
109
|
private readonly get_agent_model: AgentSessionsOptions["get_agent_model"];
|
|
106
|
-
private readonly on_session_routed?: AgentSessionsOptions["on_session_routed"];
|
|
107
110
|
private readonly sessions_by_id = new Map<string, AgentManagedSession>();
|
|
108
111
|
|
|
109
112
|
constructor(options: AgentSessionsOptions) {
|
|
110
113
|
this.agent_id = options.agent_id;
|
|
114
|
+
this.agent_name = options.agent_name;
|
|
115
|
+
this.agent_description = options.agent_description;
|
|
111
116
|
this.resolve_session_context = options.resolve_session_context;
|
|
112
117
|
this.logger = options.logger;
|
|
113
118
|
this.get_instruction = options.get_instruction;
|
|
114
|
-
this.ensure_agent_ready = options.ensure_agent_ready;
|
|
115
119
|
this.session_class = options.session_class || Session;
|
|
116
|
-
this.
|
|
117
|
-
(() => new DefaultSessionComposer());
|
|
120
|
+
this.session_composer = options.session_composer ?? new DefaultSessionComposer();
|
|
118
121
|
this.get_agent_model = options.get_agent_model;
|
|
119
|
-
this.on_session_routed = options.on_session_routed;
|
|
120
122
|
}
|
|
121
123
|
|
|
122
124
|
/**
|
|
@@ -201,7 +203,6 @@ export class AgentSessions implements AgentSessionsContract<AgentSession> {
|
|
|
201
203
|
context.workspace_id,
|
|
202
204
|
),
|
|
203
205
|
});
|
|
204
|
-
this.on_session_routed?.(session.id, this);
|
|
205
206
|
await session.initialize();
|
|
206
207
|
return session;
|
|
207
208
|
}
|
|
@@ -254,7 +255,6 @@ export class AgentSessions implements AgentSessionsContract<AgentSession> {
|
|
|
254
255
|
origin: persisted_origin,
|
|
255
256
|
storage,
|
|
256
257
|
});
|
|
257
|
-
this.on_session_routed?.(resolved_session_id, this);
|
|
258
258
|
await session.initialize();
|
|
259
259
|
return session;
|
|
260
260
|
}
|
|
@@ -264,7 +264,7 @@ export class AgentSessions implements AgentSessionsContract<AgentSession> {
|
|
|
264
264
|
*
|
|
265
265
|
* 关键点(中文)
|
|
266
266
|
* - 正在执行的 Session 会先停止,避免删除后继续写入。
|
|
267
|
-
* - 该方法不处理任何
|
|
267
|
+
* - 该方法不处理任何 Power 自有数据。
|
|
268
268
|
*/
|
|
269
269
|
async remove(session_id: string, origin_type = "chat"): Promise<boolean> {
|
|
270
270
|
const resolved_session_id = String(session_id || "").trim();
|
|
@@ -427,6 +427,8 @@ export class AgentSessions implements AgentSessionsContract<AgentSession> {
|
|
|
427
427
|
const context = this.resolve_session_context(input?.workspace);
|
|
428
428
|
const created = new this.session_class({
|
|
429
429
|
agent_id: this.agent_id,
|
|
430
|
+
agent_name: this.agent_name,
|
|
431
|
+
agent_description: this.agent_description,
|
|
430
432
|
workspace_path: context.workspace_path,
|
|
431
433
|
...(context.workspace_id ? { workspace_id: context.workspace_id } : {}),
|
|
432
434
|
origin,
|
|
@@ -436,21 +438,41 @@ export class AgentSessions implements AgentSessionsContract<AgentSession> {
|
|
|
436
438
|
session_id: resolved_session_id,
|
|
437
439
|
get_tools: () => context.get_tools(),
|
|
438
440
|
logger: context.logger,
|
|
439
|
-
instruction_system_blocks: this.load_instruction_system_blocks(
|
|
440
|
-
get_instruction_system_blocks: () => this.load_instruction_system_blocks(
|
|
441
|
+
instruction_system_blocks: this.load_instruction_system_blocks(),
|
|
442
|
+
get_instruction_system_blocks: () => this.load_instruction_system_blocks(),
|
|
441
443
|
get_workspace_env: () => context.get_workspace_env(),
|
|
444
|
+
get_workspace: () => context.get_workspace(),
|
|
442
445
|
get_agent_model: () => this.get_agent_model(),
|
|
443
446
|
get_hooks: () => context.get_hooks(),
|
|
444
|
-
|
|
445
|
-
create_composer: this.create_session_composer,
|
|
446
|
-
ensure_configured: async (session) => {
|
|
447
|
-
await this.ensure_agent_ready();
|
|
448
|
-
},
|
|
447
|
+
composer: this.session_composer,
|
|
449
448
|
});
|
|
450
449
|
this.sessions_by_id.set(cache_key, created);
|
|
451
450
|
return created;
|
|
452
451
|
}
|
|
453
452
|
|
|
453
|
+
/**
|
|
454
|
+
* 释放一个空闲 Session 的运行时实例。
|
|
455
|
+
*
|
|
456
|
+
* 关键点(中文)
|
|
457
|
+
* - 只释放内存实例;消息与元数据都在 Store 中,下次 `get()` 会重新恢复。
|
|
458
|
+
* - 正在执行的 Session 不释放:执行上下文与取消信号都在实例上,丢掉会让 Turn 失去归属。
|
|
459
|
+
* - 返回是否真的释放。调用方必须先自行解除对该实例的订阅,否则重新 `get()` 会拿到新实例
|
|
460
|
+
* 而旧订阅仍然挂在被丢弃的实例上。
|
|
461
|
+
*/
|
|
462
|
+
release(session_id: string, origin_type = "chat"): boolean {
|
|
463
|
+
const resolved_session_id = String(session_id || "").trim();
|
|
464
|
+
if (!resolved_session_id) return false;
|
|
465
|
+
const cache_key = this.session_cache_key(
|
|
466
|
+
resolved_session_id,
|
|
467
|
+
normalize_session_origin_type(origin_type),
|
|
468
|
+
);
|
|
469
|
+
const cached = this.sessions_by_id.get(cache_key);
|
|
470
|
+
if (!cached || cached.is_executing()) return false;
|
|
471
|
+
cached.dispose_title_generation?.();
|
|
472
|
+
this.sessions_by_id.delete(cache_key);
|
|
473
|
+
return true;
|
|
474
|
+
}
|
|
475
|
+
|
|
454
476
|
/** 接管 fork 产生的 Session,确保后续读取与执行使用同一运行时实例。 */
|
|
455
477
|
private register_forked_session(session: AgentManagedSession): void {
|
|
456
478
|
if (session.agent_id !== this.agent_id) {
|
|
@@ -462,7 +484,6 @@ export class AgentSessions implements AgentSessionsContract<AgentSession> {
|
|
|
462
484
|
throw new Error(`Session "${session.id}" already has another runtime instance`);
|
|
463
485
|
}
|
|
464
486
|
this.sessions_by_id.set(cache_key, session);
|
|
465
|
-
this.on_session_routed?.(session.id, this);
|
|
466
487
|
}
|
|
467
488
|
|
|
468
489
|
/** 返回来源分区内唯一的 Session 运行时缓存键。 */
|
|
@@ -470,11 +491,12 @@ export class AgentSessions implements AgentSessionsContract<AgentSession> {
|
|
|
470
491
|
return `${origin_type}\u0000${session_id}`;
|
|
471
492
|
}
|
|
472
493
|
|
|
473
|
-
private load_instruction_system_blocks(
|
|
474
|
-
return create_instruction_system_blocks(
|
|
475
|
-
this.
|
|
476
|
-
|
|
477
|
-
|
|
494
|
+
private load_instruction_system_blocks(): AgentSessionSystemBlock[] {
|
|
495
|
+
return create_instruction_system_blocks({
|
|
496
|
+
agent_id: this.agent_id,
|
|
497
|
+
agent_name: this.agent_name,
|
|
498
|
+
instruction: this.get_instruction(),
|
|
499
|
+
});
|
|
478
500
|
}
|
|
479
501
|
|
|
480
502
|
}
|
package/src/group/Group.ts
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
import { AiDispatchStrategy } from "@/types/group/DispatchStrategy.js";
|
|
4
4
|
import type { DispatchStrategy } from "@/types/group/DispatchStrategy.js";
|
|
5
|
-
import type { ModelClient, StorageProvider } from "@downcity/type";
|
|
5
|
+
import type { ModelClient, StorageProvider, CityRuntime } from "@downcity/type";
|
|
6
6
|
import type { GroupContract, GroupOptions } from "@/types/group/Group.js";
|
|
7
7
|
import type { Agent } from "@/agent/Agent.js";
|
|
8
8
|
import { GroupSessions } from "@/group/GroupSessions.js";
|
|
@@ -20,14 +20,12 @@ export class Group implements GroupContract {
|
|
|
20
20
|
readonly dispatch_strategy: DispatchStrategy;
|
|
21
21
|
readonly sessions: GroupSessions;
|
|
22
22
|
|
|
23
|
-
/**
|
|
23
|
+
/** 未加入容器时使用的隔离进程内存储。 */
|
|
24
24
|
private storage_provider: StorageProvider = new AgentMemoryStorageProvider();
|
|
25
|
-
/**
|
|
26
|
-
private
|
|
25
|
+
/** 当前绑定的容器运行环境;独立运行时为空。 */
|
|
26
|
+
private host?: CityRuntime;
|
|
27
27
|
/** 延迟创建的 GroupSession 持久化 Store。 */
|
|
28
28
|
private session_store?: GroupSessionStore;
|
|
29
|
-
/** 是否已经在无宿主存储中创建或恢复过 Session。 */
|
|
30
|
-
private memory_session_started = false;
|
|
31
29
|
|
|
32
30
|
constructor(options: GroupOptions) {
|
|
33
31
|
this.id = String(options.id || "").trim();
|
|
@@ -47,26 +45,31 @@ export class Group implements GroupContract {
|
|
|
47
45
|
this.sessions = new GroupSessions(this);
|
|
48
46
|
}
|
|
49
47
|
|
|
50
|
-
/**
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
48
|
+
/**
|
|
49
|
+
* 绑定容器运行环境;必须在创建或恢复 GroupSession 前完成。
|
|
50
|
+
*
|
|
51
|
+
* 关键点(中文)
|
|
52
|
+
* - 与 Agent 使用同一套绑定语义:只收下容器推送的存储能力,不持有容器引用。
|
|
53
|
+
*/
|
|
54
|
+
bind(host: CityRuntime): void {
|
|
55
|
+
if (this.host) {
|
|
56
|
+
if (this.host === host) return;
|
|
57
|
+
throw new Error(`Group "${this.id}" is already bound to another container`);
|
|
55
58
|
}
|
|
56
|
-
if (this.
|
|
59
|
+
if (this.session_store) {
|
|
57
60
|
throw new Error(
|
|
58
|
-
`Group "${this.id}" already used standalone storage;
|
|
61
|
+
`Group "${this.id}" already used standalone storage; bind it before using GroupSessions`,
|
|
59
62
|
);
|
|
60
63
|
}
|
|
61
|
-
this.
|
|
62
|
-
this.storage_provider =
|
|
64
|
+
this.host = host;
|
|
65
|
+
this.storage_provider = host.storage;
|
|
63
66
|
}
|
|
64
67
|
|
|
65
|
-
/**
|
|
66
|
-
async
|
|
67
|
-
if (this.
|
|
68
|
+
/** 解除容器绑定并释放当前 Store,主体回到独立运行状态。 */
|
|
69
|
+
async unbind(): Promise<void> {
|
|
70
|
+
if (!this.host) return;
|
|
68
71
|
await this.dispose_session_store();
|
|
69
|
-
this.
|
|
72
|
+
this.host = undefined;
|
|
70
73
|
this.storage_provider = new AgentMemoryStorageProvider();
|
|
71
74
|
}
|
|
72
75
|
|
|
@@ -82,11 +85,6 @@ export class Group implements GroupContract {
|
|
|
82
85
|
return this.session_store;
|
|
83
86
|
}
|
|
84
87
|
|
|
85
|
-
/** 标记 Group 已经创建或恢复过 Session。 */
|
|
86
|
-
mark_session_started(): void {
|
|
87
|
-
if (!this.storage_owner) this.memory_session_started = true;
|
|
88
|
-
}
|
|
89
|
-
|
|
90
88
|
/** 释放当前 GroupSession Store。 */
|
|
91
89
|
async dispose_session_store(): Promise<void> {
|
|
92
90
|
await this.session_store?.dispose();
|
|
@@ -95,6 +93,11 @@ export class Group implements GroupContract {
|
|
|
95
93
|
|
|
96
94
|
/** 释放 Group 所拥有的全部群聊上下文。 */
|
|
97
95
|
async dispose(): Promise<void> {
|
|
96
|
+
if (this.host) {
|
|
97
|
+
throw new Error(
|
|
98
|
+
`Group "${this.id}" is bound to a container; release it with city.groups.remove(id)`,
|
|
99
|
+
);
|
|
100
|
+
}
|
|
98
101
|
await this.sessions.dispose();
|
|
99
102
|
}
|
|
100
103
|
}
|
|
@@ -28,8 +28,8 @@ import {
|
|
|
28
28
|
} from "@/group/GroupDispatchRuntime.js";
|
|
29
29
|
import type { GroupDispatchResult } from "@/types/group/GroupDispatch.js";
|
|
30
30
|
import { normalize_session_title } from "@/session/storage/Metadata.js";
|
|
31
|
-
import { generate_session_title } from "@/session/SessionTitle.js";
|
|
32
|
-
import { SessionTitleTask } from "@/session/
|
|
31
|
+
import { generate_session_title } from "@/session/loop/SessionTitle.js";
|
|
32
|
+
import { SessionTitleTask } from "@/session/loop/SessionTitleTask.js";
|
|
33
33
|
|
|
34
34
|
const max_auto_dispatch_count = 32;
|
|
35
35
|
|
|
@@ -710,12 +710,16 @@ export class GroupSession implements GroupSessionContract {
|
|
|
710
710
|
private subscribe_member_session(agent_id: string, session: AgentSession): void {
|
|
711
711
|
this.member_session_unsubscribes.get(agent_id)?.();
|
|
712
712
|
this.member_session_unsubscribes.set(agent_id, session.subscribe((mutation) => {
|
|
713
|
-
if (mutation.variant !== "part" || mutation.type !== "
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
this.
|
|
717
|
-
|
|
718
|
-
|
|
713
|
+
if (mutation.variant !== "part" || mutation.type !== "tool") return;
|
|
714
|
+
// Interaction 属于 Tool Part;同一次 Tool 更新可能同时出现新增与终结的 Interaction。
|
|
715
|
+
for (const interaction of mutation.part.interactions ?? []) {
|
|
716
|
+
const registered = this.interaction_sessions.has(interaction.interaction_id);
|
|
717
|
+
if (interaction.status === "pending" && !registered) {
|
|
718
|
+
this.interaction_sessions.set(interaction.interaction_id, session);
|
|
719
|
+
this.publish_event({ type: "interaction", agent_id, request: interaction.request });
|
|
720
|
+
} else if (interaction.status !== "pending" && registered) {
|
|
721
|
+
this.interaction_sessions.delete(interaction.interaction_id);
|
|
722
|
+
}
|
|
719
723
|
}
|
|
720
724
|
}));
|
|
721
725
|
}
|
|
@@ -4,8 +4,12 @@ import { nanoid } from "nanoid";
|
|
|
4
4
|
import { GroupSession } from "@/group/GroupSession.js";
|
|
5
5
|
import type { Group } from "@/group/Group.js";
|
|
6
6
|
import type { WorkspaceRuntime } from "@downcity/type";
|
|
7
|
+
import type { GroupSessionHistoryMeta } from "@/types/group/GroupSessionStore.js";
|
|
7
8
|
import type {
|
|
8
9
|
GroupSession as GroupSessionContract,
|
|
10
|
+
GroupSessionArchiveListInput,
|
|
11
|
+
GroupSessionArchiveResult,
|
|
12
|
+
GroupSessionCleanArchiveResult,
|
|
9
13
|
GroupSessionCreateInput,
|
|
10
14
|
GroupSessionGetInput,
|
|
11
15
|
GroupSessionListInput,
|
|
@@ -27,7 +31,6 @@ export class GroupSessions implements GroupSessionsContract {
|
|
|
27
31
|
const session = this.create_runtime_session(`group-session-${Date.now()}-${nanoid(8)}`, input?.workspace);
|
|
28
32
|
const store = this.group.get_session_store();
|
|
29
33
|
await session.initialize(store.session(session.id));
|
|
30
|
-
this.group.mark_session_started();
|
|
31
34
|
this.sessions_by_id.set(session.id, session);
|
|
32
35
|
return session;
|
|
33
36
|
}
|
|
@@ -46,30 +49,14 @@ export class GroupSessions implements GroupSessionsContract {
|
|
|
46
49
|
if (!(await store.has_session(resolved_session_id))) return null;
|
|
47
50
|
const session = this.create_runtime_session(resolved_session_id, input?.workspace);
|
|
48
51
|
await session.initialize(store.session(resolved_session_id));
|
|
49
|
-
this.group.mark_session_started();
|
|
50
52
|
this.sessions_by_id.set(session.id, session);
|
|
51
53
|
return session;
|
|
52
54
|
}
|
|
53
55
|
|
|
54
|
-
/** 恢复当前 Group
|
|
56
|
+
/** 恢复当前 Group 的全部群聊上下文(不含已归档)。 */
|
|
55
57
|
async list(input?: GroupSessionListInput): Promise<readonly GroupSessionSummary[]> {
|
|
56
|
-
const
|
|
57
|
-
|
|
58
|
-
if (metadata.length > 0) this.group.mark_session_started();
|
|
59
|
-
const workspace_id = String(input?.workspace_id || "").trim() || undefined;
|
|
60
|
-
const filtered_metadata = workspace_id
|
|
61
|
-
? metadata.filter((item) => item.workspace_id === workspace_id)
|
|
62
|
-
: metadata;
|
|
63
|
-
return filtered_metadata.map((item) => ({
|
|
64
|
-
id: item.session_id,
|
|
65
|
-
group_id: item.group_id,
|
|
66
|
-
created_at: item.created_at,
|
|
67
|
-
updated_at: item.updated_at,
|
|
68
|
-
message_count: item.message_count,
|
|
69
|
-
...(item.workspace_id ? { workspace_id: item.workspace_id } : {}),
|
|
70
|
-
...(item.title ? { title: item.title } : {}),
|
|
71
|
-
...(item.preview_text ? { preview_text: item.preview_text } : {}),
|
|
72
|
-
}));
|
|
58
|
+
const metadata = await this.group.get_session_store().list_session_metadata();
|
|
59
|
+
return to_summaries(metadata, input?.workspace_id);
|
|
73
60
|
}
|
|
74
61
|
|
|
75
62
|
/** 释放并删除指定群聊上下文及其持久化数据。 */
|
|
@@ -83,6 +70,53 @@ export class GroupSessions implements GroupSessionsContract {
|
|
|
83
70
|
return session;
|
|
84
71
|
}
|
|
85
72
|
|
|
73
|
+
/**
|
|
74
|
+
* 归档指定群聊上下文:从活动区迁入归档区。
|
|
75
|
+
*
|
|
76
|
+
* 与 `remove` 的区别是**可逆性**:归档只是收起来,数据仍在归档区;
|
|
77
|
+
* 而 `remove` 是永久删除。
|
|
78
|
+
*
|
|
79
|
+
* 归档前必须 `dispose` 运行时实例:否则内存里的实例会继续往旧路径(活动区)写,
|
|
80
|
+
* 而那份目录已经不存在了。`dispose` 失败不阻止归档——实例已经跑不起来了,
|
|
81
|
+
* 而用户想归档的意图不该因此落空。
|
|
82
|
+
*/
|
|
83
|
+
async archive(session_id: string): Promise<GroupSessionArchiveResult> {
|
|
84
|
+
const resolved_session_id = String(session_id || "").trim();
|
|
85
|
+
if (!resolved_session_id) throw new Error("GroupSessions.archive requires a non-empty session_id");
|
|
86
|
+
const cached = this.sessions_by_id.get(resolved_session_id);
|
|
87
|
+
if (cached) {
|
|
88
|
+
await cached.dispose();
|
|
89
|
+
this.sessions_by_id.delete(resolved_session_id);
|
|
90
|
+
}
|
|
91
|
+
return await this.group.get_session_store().archive_session(resolved_session_id);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/** 列出已归档的群聊上下文摘要。 */
|
|
95
|
+
async archived(input?: GroupSessionArchiveListInput): Promise<readonly GroupSessionSummary[]> {
|
|
96
|
+
const metadata = await this.group.get_session_store().list_archived_session_metadata();
|
|
97
|
+
return to_summaries(metadata, input?.workspace_id);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/** 永久清空当前 Group 的全部归档。 */
|
|
101
|
+
async clean_archive(): Promise<GroupSessionCleanArchiveResult> {
|
|
102
|
+
return await this.group.get_session_store().clean_archive();
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* 永久删除当前 Group 的全部群聊数据(活动区 + 归档区)。
|
|
107
|
+
*
|
|
108
|
+
* 它服务于「Group 被删除」:Group 是群聊的**所有者**,所有者消失时它拥有的数据
|
|
109
|
+
* 不该继续存在。与 `dispose` 的区别:那个只释放运行时实例,数据仍在磁盘上。
|
|
110
|
+
*
|
|
111
|
+
* 先释放运行时实例再删目录:实例还活着时删掉它的数据目录,
|
|
112
|
+
* 之后任何写入都会落到一个已经不存在的位置。
|
|
113
|
+
*/
|
|
114
|
+
async purge(): Promise<void> {
|
|
115
|
+
await Promise.allSettled([...this.sessions_by_id.values()].map((session) => session.dispose()));
|
|
116
|
+
this.sessions_by_id.clear();
|
|
117
|
+
await this.group.get_session_store().purge();
|
|
118
|
+
}
|
|
119
|
+
|
|
86
120
|
/** 释放 Group 所有群聊上下文。 */
|
|
87
121
|
async dispose(): Promise<void> {
|
|
88
122
|
await Promise.allSettled([...this.sessions_by_id.values()].map((session) => session.dispose()));
|
|
@@ -103,3 +137,28 @@ export class GroupSessions implements GroupSessionsContract {
|
|
|
103
137
|
});
|
|
104
138
|
}
|
|
105
139
|
}
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* 把 metadata 投影成列表摘要,并按 Workspace 过滤。
|
|
143
|
+
*
|
|
144
|
+
* 活动列表与归档列表共用这一段:两处各写一遍必然分叉,
|
|
145
|
+
* 而分叉的表现是「归档后摘要少了字段」这类很难一眼看出的差异。
|
|
146
|
+
*/
|
|
147
|
+
function to_summaries(
|
|
148
|
+
metadata: readonly GroupSessionHistoryMeta[],
|
|
149
|
+
workspace_id_input?: string,
|
|
150
|
+
): readonly GroupSessionSummary[] {
|
|
151
|
+
const workspace_id = String(workspace_id_input || "").trim() || undefined;
|
|
152
|
+
return metadata
|
|
153
|
+
.filter((item) => !workspace_id || item.workspace_id === workspace_id)
|
|
154
|
+
.map((item) => ({
|
|
155
|
+
id: item.session_id,
|
|
156
|
+
group_id: item.group_id,
|
|
157
|
+
created_at: item.created_at,
|
|
158
|
+
updated_at: item.updated_at,
|
|
159
|
+
message_count: item.message_count,
|
|
160
|
+
...(item.workspace_id ? { workspace_id: item.workspace_id } : {}),
|
|
161
|
+
...(item.title ? { title: item.title } : {}),
|
|
162
|
+
...(item.preview_text ? { preview_text: item.preview_text } : {}),
|
|
163
|
+
}));
|
|
164
|
+
}
|
|
@@ -35,6 +35,14 @@ export class LocalGroupSessionDataStore implements GroupSessionDataStore {
|
|
|
35
35
|
session_id: string;
|
|
36
36
|
/** 所属 Group 标识。 */
|
|
37
37
|
group_id: string;
|
|
38
|
+
/**
|
|
39
|
+
* 当前 Session 所在的存储区。
|
|
40
|
+
*
|
|
41
|
+
* 默认 `active`(`sessions/`);归档后的 Session 住在 `archived-sessions/`。
|
|
42
|
+
* 区由调用方给而不是在这里判断:DataStore 只负责“某个目录里的一个 Session”,
|
|
43
|
+
* 该在哪个区是集合层的事。
|
|
44
|
+
*/
|
|
45
|
+
area?: "active" | "archived";
|
|
38
46
|
}) {
|
|
39
47
|
this.files = options.files;
|
|
40
48
|
this.group_id = options.group_id;
|
|
@@ -42,7 +50,7 @@ export class LocalGroupSessionDataStore implements GroupSessionDataStore {
|
|
|
42
50
|
if (!this.session_id) throw new Error("GroupSession store requires a non-empty session_id");
|
|
43
51
|
this.session_root_path = path.join(
|
|
44
52
|
path.resolve(options.storage_root_path),
|
|
45
|
-
"sessions",
|
|
53
|
+
options.area === "archived" ? "archived-sessions" : "sessions",
|
|
46
54
|
encodeURIComponent(this.session_id),
|
|
47
55
|
);
|
|
48
56
|
this.metadata_file_path = path.join(this.session_root_path, "meta.json");
|