@downcity/agent 1.1.437 → 1.1.445

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (702) hide show
  1. package/README.md +25 -18
  2. package/bin/agent/Agent.d.ts +44 -20
  3. package/bin/agent/Agent.d.ts.map +1 -1
  4. package/bin/agent/Agent.js +114 -69
  5. package/bin/agent/Agent.js.map +1 -1
  6. package/bin/agent/AgentInstructions.d.ts +18 -4
  7. package/bin/agent/AgentInstructions.d.ts.map +1 -1
  8. package/bin/agent/AgentInstructions.js +33 -14
  9. package/bin/agent/AgentInstructions.js.map +1 -1
  10. package/bin/agent/AgentMemoryStorage.d.ts +1 -1
  11. package/bin/agent/AgentMemoryStorage.d.ts.map +1 -1
  12. package/bin/agent/AgentMemoryStorage.js.map +1 -1
  13. package/bin/agent/AgentSessions.d.ts +29 -16
  14. package/bin/agent/AgentSessions.d.ts.map +1 -1
  15. package/bin/agent/AgentSessions.js +42 -22
  16. package/bin/agent/AgentSessions.js.map +1 -1
  17. package/bin/group/Group.d.ts +13 -12
  18. package/bin/group/Group.d.ts.map +1 -1
  19. package/bin/group/Group.js +24 -23
  20. package/bin/group/Group.js.map +1 -1
  21. package/bin/group/GroupSession.d.ts.map +1 -1
  22. package/bin/group/GroupSession.js +13 -9
  23. package/bin/group/GroupSession.js.map +1 -1
  24. package/bin/group/GroupSessions.d.ts +27 -2
  25. package/bin/group/GroupSessions.d.ts.map +1 -1
  26. package/bin/group/GroupSessions.js +68 -21
  27. package/bin/group/GroupSessions.js.map +1 -1
  28. package/bin/group/storage/LocalGroupSessionDataStore.d.ts +8 -0
  29. package/bin/group/storage/LocalGroupSessionDataStore.d.ts.map +1 -1
  30. package/bin/group/storage/LocalGroupSessionDataStore.js +1 -1
  31. package/bin/group/storage/LocalGroupSessionDataStore.js.map +1 -1
  32. package/bin/group/storage/LocalGroupSessionStore.d.ts +64 -5
  33. package/bin/group/storage/LocalGroupSessionStore.d.ts.map +1 -1
  34. package/bin/group/storage/LocalGroupSessionStore.js +114 -23
  35. package/bin/group/storage/LocalGroupSessionStore.js.map +1 -1
  36. package/bin/index.d.ts +25 -30
  37. package/bin/index.d.ts.map +1 -1
  38. package/bin/index.js +14 -14
  39. package/bin/index.js.map +1 -1
  40. package/bin/{executor/model → model}/ModelGenerate.d.ts +1 -1
  41. package/bin/model/ModelGenerate.d.ts.map +1 -0
  42. package/bin/model/ModelGenerate.js.map +1 -0
  43. package/bin/{executor/model → model}/ModelRequestRunner.d.ts +1 -1
  44. package/bin/model/ModelRequestRunner.d.ts.map +1 -0
  45. package/bin/model/ModelRequestRunner.js.map +1 -0
  46. package/bin/{executor/model → model}/ModelStepRunner.d.ts +6 -7
  47. package/bin/model/ModelStepRunner.d.ts.map +1 -0
  48. package/bin/{executor/model → model}/ModelStepRunner.js +16 -10
  49. package/bin/model/ModelStepRunner.js.map +1 -0
  50. package/bin/model/ModelStreamConsumer.d.ts.map +1 -0
  51. package/bin/model/ModelStreamConsumer.js.map +1 -0
  52. package/bin/model/ModelStreamFailure.d.ts.map +1 -0
  53. package/bin/model/ModelStreamFailure.js.map +1 -0
  54. package/bin/model/ToolInputValidation.d.ts +28 -0
  55. package/bin/model/ToolInputValidation.d.ts.map +1 -0
  56. package/bin/model/ToolInputValidation.js +37 -0
  57. package/bin/model/ToolInputValidation.js.map +1 -0
  58. package/bin/model/messages/ChatMessageMarkup.d.ts.map +1 -0
  59. package/bin/model/messages/ChatMessageMarkup.js.map +1 -0
  60. package/bin/{executor → model}/messages/ChatMessageMarkupTypes.d.ts +1 -1
  61. package/bin/model/messages/ChatMessageMarkupTypes.d.ts.map +1 -0
  62. package/bin/{executor → model}/messages/ChatMessageMarkupTypes.js +1 -1
  63. package/bin/model/messages/ChatMessageMarkupTypes.js.map +1 -0
  64. package/bin/model/messages/SessionAttachmentMapper.d.ts.map +1 -0
  65. package/bin/model/messages/SessionAttachmentMapper.js.map +1 -0
  66. package/bin/model/messages/SessionMessageLog.d.ts.map +1 -0
  67. package/bin/model/messages/SessionMessageLog.js.map +1 -0
  68. package/bin/model/messages/SessionModelMessages.d.ts.map +1 -0
  69. package/bin/{executor → model}/messages/SessionModelMessages.js +0 -1
  70. package/bin/model/messages/SessionModelMessages.js.map +1 -0
  71. package/bin/model/prompts/SystemPromptAssets.d.ts.map +1 -0
  72. package/bin/{executor/composer/system/default → model/prompts}/SystemPromptAssets.js +1 -1
  73. package/bin/model/prompts/SystemPromptAssets.js.map +1 -0
  74. package/bin/model/prompts/assets/core.prompt.d.ts +7 -0
  75. package/bin/model/prompts/assets/core.prompt.d.ts.map +1 -0
  76. package/bin/model/prompts/assets/core.prompt.js +8 -0
  77. package/bin/model/prompts/assets/core.prompt.js.map +1 -0
  78. package/bin/session/Session.d.ts +29 -17
  79. package/bin/session/Session.d.ts.map +1 -1
  80. package/bin/session/Session.js +161 -134
  81. package/bin/session/Session.js.map +1 -1
  82. package/bin/session/input/SessionHookRunner.d.ts +52 -0
  83. package/bin/session/input/SessionHookRunner.d.ts.map +1 -0
  84. package/bin/session/input/SessionHookRunner.js +51 -0
  85. package/bin/session/input/SessionHookRunner.js.map +1 -0
  86. package/bin/session/input/SessionSystem.d.ts +26 -0
  87. package/bin/session/input/SessionSystem.d.ts.map +1 -0
  88. package/bin/session/{SessionSystem.js → input/SessionSystem.js} +27 -23
  89. package/bin/session/input/SessionSystem.js.map +1 -0
  90. package/bin/session/input/StepInput.d.ts +77 -0
  91. package/bin/session/input/StepInput.d.ts.map +1 -0
  92. package/bin/session/input/StepInput.js +429 -0
  93. package/bin/session/input/StepInput.js.map +1 -0
  94. package/bin/session/input/composer/AdaptiveContextCheckpoint.d.ts +33 -0
  95. package/bin/session/input/composer/AdaptiveContextCheckpoint.d.ts.map +1 -0
  96. package/bin/session/input/composer/AdaptiveContextCheckpoint.js +83 -0
  97. package/bin/session/input/composer/AdaptiveContextCheckpoint.js.map +1 -0
  98. package/bin/session/input/composer/AdaptiveContextParts.d.ts +26 -0
  99. package/bin/session/input/composer/AdaptiveContextParts.d.ts.map +1 -0
  100. package/bin/session/input/composer/AdaptiveContextParts.js +124 -0
  101. package/bin/session/input/composer/AdaptiveContextParts.js.map +1 -0
  102. package/bin/session/input/composer/ComposerAssembly.d.ts +21 -0
  103. package/bin/session/input/composer/ComposerAssembly.d.ts.map +1 -0
  104. package/bin/session/input/composer/ComposerAssembly.js +64 -0
  105. package/bin/session/input/composer/ComposerAssembly.js.map +1 -0
  106. package/bin/session/{composer/policies/SessionSummaryPrompts.d.ts → input/composer/ContextSummaryPrompts.d.ts} +5 -3
  107. package/bin/session/input/composer/ContextSummaryPrompts.d.ts.map +1 -0
  108. package/bin/session/{composer/policies/SessionSummaryPrompts.js → input/composer/ContextSummaryPrompts.js} +5 -3
  109. package/bin/session/input/composer/ContextSummaryPrompts.js.map +1 -0
  110. package/bin/session/input/composer/DefaultSessionComposer.d.ts +24 -0
  111. package/bin/session/input/composer/DefaultSessionComposer.d.ts.map +1 -0
  112. package/bin/session/input/composer/DefaultSessionComposer.js +108 -0
  113. package/bin/session/input/composer/DefaultSessionComposer.js.map +1 -0
  114. package/bin/session/input/composer/FullHistorySessionComposer.d.ts +19 -0
  115. package/bin/session/input/composer/FullHistorySessionComposer.d.ts.map +1 -0
  116. package/bin/session/input/composer/FullHistorySessionComposer.js +36 -0
  117. package/bin/session/input/composer/FullHistorySessionComposer.js.map +1 -0
  118. package/bin/session/{SessionLoop.d.ts → loop/SessionLoop.d.ts} +34 -7
  119. package/bin/session/loop/SessionLoop.d.ts.map +1 -0
  120. package/bin/session/{SessionLoop.js → loop/SessionLoop.js} +79 -16
  121. package/bin/session/loop/SessionLoop.js.map +1 -0
  122. package/bin/session/{SessionQueue.d.ts → loop/SessionQueue.d.ts} +9 -1
  123. package/bin/session/loop/SessionQueue.d.ts.map +1 -0
  124. package/bin/session/{SessionQueue.js → loop/SessionQueue.js} +19 -0
  125. package/bin/session/loop/SessionQueue.js.map +1 -0
  126. package/bin/session/{SessionState.d.ts → loop/SessionState.d.ts} +4 -5
  127. package/bin/session/loop/SessionState.d.ts.map +1 -0
  128. package/bin/session/{SessionState.js → loop/SessionState.js} +6 -25
  129. package/bin/session/loop/SessionState.js.map +1 -0
  130. package/bin/session/{SessionTitle.d.ts → loop/SessionTitle.d.ts} +4 -4
  131. package/bin/session/loop/SessionTitle.d.ts.map +1 -0
  132. package/bin/session/{SessionTitle.js → loop/SessionTitle.js} +3 -3
  133. package/bin/session/loop/SessionTitle.js.map +1 -0
  134. package/bin/session/loop/SessionTitleTask.d.ts.map +1 -0
  135. package/bin/session/loop/SessionTitleTask.js.map +1 -0
  136. package/bin/session/{runtime → loop}/SessionTurnCompletion.d.ts +7 -0
  137. package/bin/session/loop/SessionTurnCompletion.d.ts.map +1 -0
  138. package/bin/session/{runtime → loop}/SessionTurnCompletion.js +25 -6
  139. package/bin/session/loop/SessionTurnCompletion.js.map +1 -0
  140. package/bin/session/loop/SessionTurnContext.d.ts +12 -0
  141. package/bin/session/loop/SessionTurnContext.d.ts.map +1 -0
  142. package/bin/session/{runtime → loop}/SessionTurnContext.js +14 -67
  143. package/bin/session/loop/SessionTurnContext.js.map +1 -0
  144. package/bin/session/loop/SessionTurnFileDiff.d.ts.map +1 -0
  145. package/bin/session/{runtime → loop}/SessionTurnFileDiff.js +1 -1
  146. package/bin/session/loop/SessionTurnFileDiff.js.map +1 -0
  147. package/bin/session/{messages → loop}/SessionTurnFileDiffBuilder.d.ts +3 -3
  148. package/bin/session/loop/SessionTurnFileDiffBuilder.d.ts.map +1 -0
  149. package/bin/session/loop/SessionTurnFileDiffBuilder.js.map +1 -0
  150. package/bin/session/messages/ApprovalInteraction.d.ts +30 -0
  151. package/bin/session/messages/ApprovalInteraction.d.ts.map +1 -0
  152. package/bin/session/messages/ApprovalInteraction.js +61 -0
  153. package/bin/session/messages/ApprovalInteraction.js.map +1 -0
  154. package/bin/session/messages/SessionAgentMessageState.d.ts +47 -18
  155. package/bin/session/messages/SessionAgentMessageState.d.ts.map +1 -1
  156. package/bin/session/messages/SessionAgentMessageState.js +224 -86
  157. package/bin/session/messages/SessionAgentMessageState.js.map +1 -1
  158. package/bin/session/messages/SessionAgentMessageWriter.d.ts +15 -4
  159. package/bin/session/messages/SessionAgentMessageWriter.d.ts.map +1 -1
  160. package/bin/session/messages/SessionAgentMessageWriter.js +57 -37
  161. package/bin/session/messages/SessionAgentMessageWriter.js.map +1 -1
  162. package/bin/session/messages/SessionAgentParts.d.ts +14 -0
  163. package/bin/session/messages/SessionAgentParts.d.ts.map +1 -0
  164. package/bin/session/messages/SessionAgentParts.js +20 -0
  165. package/bin/session/messages/SessionAgentParts.js.map +1 -0
  166. package/bin/session/{execution → messages}/SessionAssistantOutputAdapter.d.ts +2 -2
  167. package/bin/session/messages/SessionAssistantOutputAdapter.d.ts.map +1 -0
  168. package/bin/session/messages/SessionAssistantOutputAdapter.js.map +1 -0
  169. package/bin/session/messages/SessionEventHub.d.ts.map +1 -0
  170. package/bin/session/messages/SessionEventHub.js.map +1 -0
  171. package/bin/session/messages/SessionInteractions.d.ts +57 -0
  172. package/bin/session/messages/SessionInteractions.d.ts.map +1 -0
  173. package/bin/session/messages/SessionInteractions.js +178 -0
  174. package/bin/session/messages/SessionInteractions.js.map +1 -0
  175. package/bin/session/messages/SessionJsonValue.d.ts +1 -3
  176. package/bin/session/messages/SessionJsonValue.d.ts.map +1 -1
  177. package/bin/session/messages/SessionJsonValue.js +0 -19
  178. package/bin/session/messages/SessionJsonValue.js.map +1 -1
  179. package/bin/session/messages/SessionMessageCache.d.ts +55 -0
  180. package/bin/session/messages/SessionMessageCache.d.ts.map +1 -0
  181. package/bin/session/messages/SessionMessageCache.js +133 -0
  182. package/bin/session/messages/SessionMessageCache.js.map +1 -0
  183. package/bin/session/messages/SessionMessageState.d.ts +17 -0
  184. package/bin/session/messages/SessionMessageState.d.ts.map +1 -0
  185. package/bin/session/messages/SessionMessageState.js +34 -0
  186. package/bin/session/messages/SessionMessageState.js.map +1 -0
  187. package/bin/session/messages/SessionMessageTimeline.d.ts.map +1 -0
  188. package/bin/session/{browse → messages}/SessionMessageTimeline.js +0 -1
  189. package/bin/session/messages/SessionMessageTimeline.js.map +1 -0
  190. package/bin/session/{SessionMessages.d.ts → messages/SessionMessages.d.ts} +35 -43
  191. package/bin/session/messages/SessionMessages.d.ts.map +1 -0
  192. package/bin/session/{SessionMessages.js → messages/SessionMessages.js} +178 -196
  193. package/bin/session/messages/SessionMessages.js.map +1 -0
  194. package/bin/session/messages/SessionModelRequestWarning.d.ts.map +1 -0
  195. package/bin/session/messages/SessionModelRequestWarning.js.map +1 -0
  196. package/bin/session/messages/SessionMutationFactory.d.ts +26 -0
  197. package/bin/session/messages/SessionMutationFactory.d.ts.map +1 -0
  198. package/bin/session/messages/SessionMutationFactory.js +38 -0
  199. package/bin/session/messages/SessionMutationFactory.js.map +1 -0
  200. package/bin/session/messages/SessionUserMessage.d.ts +5 -7
  201. package/bin/session/messages/SessionUserMessage.d.ts.map +1 -1
  202. package/bin/session/messages/SessionUserMessage.js +5 -28
  203. package/bin/session/messages/SessionUserMessage.js.map +1 -1
  204. package/bin/{executor/core-engine/CoreEngineSignals.d.ts → session/runner/AssistantParts.d.ts} +4 -9
  205. package/bin/session/runner/AssistantParts.d.ts.map +1 -0
  206. package/bin/{executor/core-engine/CoreEngineSignals.js → session/runner/AssistantParts.js} +4 -17
  207. package/bin/session/runner/AssistantParts.js.map +1 -0
  208. package/bin/session/runner/ContextPressure.d.ts +15 -0
  209. package/bin/session/runner/ContextPressure.d.ts.map +1 -0
  210. package/bin/{executor/core-engine/CoreEngineContextCompaction.js → session/runner/ContextPressure.js} +11 -11
  211. package/bin/session/runner/ContextPressure.js.map +1 -0
  212. package/bin/session/runner/ContextRetry.d.ts +39 -0
  213. package/bin/session/runner/ContextRetry.d.ts.map +1 -0
  214. package/bin/{executor/services/ExecutorRecoveryPolicy.js → session/runner/ContextRetry.js} +19 -19
  215. package/bin/session/runner/ContextRetry.js.map +1 -0
  216. package/bin/{executor/core-engine/CoreEngineError.d.ts → session/runner/ModelFailure.d.ts} +4 -4
  217. package/bin/session/runner/ModelFailure.d.ts.map +1 -0
  218. package/bin/{executor/core-engine/CoreEngineError.js → session/runner/ModelFailure.js} +4 -4
  219. package/bin/session/runner/ModelFailure.js.map +1 -0
  220. package/bin/session/runner/SessionExecutor.d.ts +108 -0
  221. package/bin/session/runner/SessionExecutor.d.ts.map +1 -0
  222. package/bin/session/runner/SessionExecutor.js +430 -0
  223. package/bin/session/runner/SessionExecutor.js.map +1 -0
  224. package/bin/session/runner/ToolLoopDecision.d.ts +60 -0
  225. package/bin/session/runner/ToolLoopDecision.d.ts.map +1 -0
  226. package/bin/{executor/core-engine/CoreEngineLoopDecision.js → session/runner/ToolLoopDecision.js} +5 -5
  227. package/bin/session/runner/ToolLoopDecision.js.map +1 -0
  228. package/bin/session/runner/ToolLoopLimits.d.ts +30 -0
  229. package/bin/session/runner/ToolLoopLimits.d.ts.map +1 -0
  230. package/bin/session/runner/ToolLoopLimits.js +46 -0
  231. package/bin/session/runner/ToolLoopLimits.js.map +1 -0
  232. package/bin/session/{browse → storage}/Browse.d.ts +1 -1
  233. package/bin/session/storage/Browse.d.ts.map +1 -0
  234. package/bin/session/{browse → storage}/Browse.js +1 -1
  235. package/bin/session/storage/Browse.js.map +1 -0
  236. package/bin/session/storage/LocalSessionStore.js +1 -1
  237. package/bin/session/storage/LocalSessionStore.js.map +1 -1
  238. package/bin/session/storage/LocalStorePaths.d.ts +0 -2
  239. package/bin/session/storage/LocalStorePaths.d.ts.map +1 -1
  240. package/bin/session/storage/LocalStorePaths.js +1 -1
  241. package/bin/session/storage/LocalStorePaths.js.map +1 -1
  242. package/bin/session/storage/Metadata.d.ts +1 -23
  243. package/bin/session/storage/Metadata.d.ts.map +1 -1
  244. package/bin/session/storage/Metadata.js +0 -18
  245. package/bin/session/storage/Metadata.js.map +1 -1
  246. package/bin/session/storage/RuntimeSessionPort.d.ts +0 -4
  247. package/bin/session/storage/RuntimeSessionPort.d.ts.map +1 -1
  248. package/bin/session/storage/RuntimeSessionPort.js +0 -1
  249. package/bin/session/storage/RuntimeSessionPort.js.map +1 -1
  250. package/bin/session/{preview → storage}/SessionMessagePreview.d.ts.map +1 -1
  251. package/bin/session/{preview → storage}/SessionMessagePreview.js +0 -1
  252. package/bin/session/{preview → storage}/SessionMessagePreview.js.map +1 -1
  253. package/bin/session/storage/SessionStorageCodec.d.ts.map +1 -1
  254. package/bin/session/storage/SessionStorageCodec.js +36 -18
  255. package/bin/session/storage/SessionStorageCodec.js.map +1 -1
  256. package/bin/session/storage/SessionStorageSchema.d.ts +1 -1
  257. package/bin/session/storage/SessionStorageSchema.js +1 -1
  258. package/bin/session/storage/SqliteSessionStorage.d.ts +6 -4
  259. package/bin/session/storage/SqliteSessionStorage.d.ts.map +1 -1
  260. package/bin/session/storage/SqliteSessionStorage.js +21 -18
  261. package/bin/session/storage/SqliteSessionStorage.js.map +1 -1
  262. package/bin/tools/ask/AskQuestionAnswers.d.ts +20 -0
  263. package/bin/tools/ask/AskQuestionAnswers.d.ts.map +1 -0
  264. package/bin/tools/ask/AskQuestionAnswers.js +99 -0
  265. package/bin/tools/ask/AskQuestionAnswers.js.map +1 -0
  266. package/bin/tools/ask/AskQuestionsTool.d.ts +5 -2
  267. package/bin/tools/ask/AskQuestionsTool.d.ts.map +1 -1
  268. package/bin/tools/ask/AskQuestionsTool.js +23 -31
  269. package/bin/tools/ask/AskQuestionsTool.js.map +1 -1
  270. package/bin/tools/ask/AskQuestionsToolSchemas.d.ts +1 -1
  271. package/bin/types/agent/AgentOptions.d.ts +16 -8
  272. package/bin/types/agent/AgentOptions.d.ts.map +1 -1
  273. package/bin/types/agent/AgentSessionCollection.d.ts +8 -0
  274. package/bin/types/agent/AgentSessionCollection.d.ts.map +1 -1
  275. package/bin/types/agent/SessionActor.d.ts +3 -3
  276. package/bin/types/agent/SessionActor.d.ts.map +1 -1
  277. package/bin/types/group/DispatchStrategy.js +1 -1
  278. package/bin/types/group/DispatchStrategy.js.map +1 -1
  279. package/bin/types/group/GroupSession.d.ts +41 -1
  280. package/bin/types/group/GroupSession.d.ts.map +1 -1
  281. package/bin/types/group/GroupSessionStore.d.ts +30 -3
  282. package/bin/types/group/GroupSessionStore.d.ts.map +1 -1
  283. package/bin/types/model/ModelRequest.d.ts.map +1 -0
  284. package/bin/types/model/ModelRequest.js.map +1 -0
  285. package/bin/types/sdk/AgentSessionAction.d.ts +1 -9
  286. package/bin/types/sdk/AgentSessionAction.d.ts.map +1 -1
  287. package/bin/types/session/{AdaptivePartContextPolicy.d.ts → ContextCheckpoint.d.ts} +10 -9
  288. package/bin/types/session/ContextCheckpoint.d.ts.map +1 -0
  289. package/bin/types/session/ContextCheckpoint.js +8 -0
  290. package/bin/types/session/ContextCheckpoint.js.map +1 -0
  291. package/bin/types/session/SessionAgentMessageState.d.ts +6 -10
  292. package/bin/types/session/SessionAgentMessageState.d.ts.map +1 -1
  293. package/bin/types/session/SessionAgentMessageState.js +3 -2
  294. package/bin/types/session/SessionAgentMessageState.js.map +1 -1
  295. package/bin/types/session/SessionComposer.d.ts +65 -36
  296. package/bin/types/session/SessionComposer.d.ts.map +1 -1
  297. package/bin/types/session/SessionComposer.js +7 -2
  298. package/bin/types/session/SessionComposer.js.map +1 -1
  299. package/bin/types/session/SessionExecution.d.ts +15 -11
  300. package/bin/types/session/SessionExecution.d.ts.map +1 -1
  301. package/bin/types/session/SessionExecution.js +1 -1
  302. package/bin/types/session/SessionInteractions.d.ts +0 -2
  303. package/bin/types/session/SessionInteractions.d.ts.map +1 -1
  304. package/bin/types/session/SessionLocalState.d.ts +0 -4
  305. package/bin/types/session/SessionLocalState.d.ts.map +1 -1
  306. package/bin/types/session/SessionLoop.d.ts +33 -12
  307. package/bin/types/session/SessionLoop.d.ts.map +1 -1
  308. package/bin/types/session/SessionMessages.d.ts +3 -29
  309. package/bin/types/session/SessionMessages.d.ts.map +1 -1
  310. package/bin/types/session/SessionOptions.d.ts +16 -13
  311. package/bin/types/session/SessionOptions.d.ts.map +1 -1
  312. package/bin/types/session/SessionPort.d.ts +0 -3
  313. package/bin/types/session/SessionPort.d.ts.map +1 -1
  314. package/bin/types/session/SessionState.d.ts +0 -1
  315. package/bin/types/session/SessionState.d.ts.map +1 -1
  316. package/bin/types/session/SessionSystem.d.ts +10 -12
  317. package/bin/types/session/SessionSystem.d.ts.map +1 -1
  318. package/bin/types/session/SessionTool.d.ts +2 -2
  319. package/bin/types/session/SessionTool.d.ts.map +1 -1
  320. package/bin/types/session/SessionTurnCompletion.d.ts +12 -2
  321. package/bin/types/session/SessionTurnCompletion.d.ts.map +1 -1
  322. package/bin/types/session/SessionTurnFileDiff.d.ts +4 -4
  323. package/bin/types/session/SessionTurnFileDiff.d.ts.map +1 -1
  324. package/bin/types/session/{SessionComposition.d.ts → StepInput.d.ts} +17 -15
  325. package/bin/types/session/StepInput.d.ts.map +1 -0
  326. package/bin/types/session/StepInput.js +8 -0
  327. package/bin/types/session/StepInput.js.map +1 -0
  328. package/bin/types/store/SessionHistoryMeta.d.ts.map +1 -0
  329. package/bin/types/store/SessionHistoryMeta.js.map +1 -0
  330. package/bin/types/store/SessionStorage.d.ts +17 -12
  331. package/bin/types/store/SessionStorage.d.ts.map +1 -1
  332. package/bin/types/tool/BoundAgentTool.d.ts +36 -0
  333. package/bin/types/tool/BoundAgentTool.d.ts.map +1 -0
  334. package/bin/types/tool/BoundAgentTool.js +13 -0
  335. package/bin/types/tool/BoundAgentTool.js.map +1 -0
  336. package/bin/types/tools/ask/AskQuestionsTool.d.ts +9 -13
  337. package/bin/types/tools/ask/AskQuestionsTool.d.ts.map +1 -1
  338. package/bin/types/tools/ask/AskQuestionsTool.js +3 -2
  339. package/bin/types/tools/ask/AskQuestionsTool.js.map +1 -1
  340. package/bin/types/turn/SessionAssistantOutput.d.ts.map +1 -0
  341. package/bin/types/turn/SessionAssistantOutput.js.map +1 -0
  342. package/bin/types/{executor → turn}/SessionTurnContext.d.ts +10 -28
  343. package/bin/types/turn/SessionTurnContext.d.ts.map +1 -0
  344. package/bin/types/turn/SessionTurnContext.js.map +1 -0
  345. package/bin/{executor/ids/resolveSessionId.d.ts → utils/ResolveSessionId.d.ts} +1 -1
  346. package/bin/utils/ResolveSessionId.d.ts.map +1 -0
  347. package/bin/{executor/ids/resolveSessionId.js → utils/ResolveSessionId.js} +1 -1
  348. package/bin/utils/ResolveSessionId.js.map +1 -0
  349. package/bin/utils/Time.d.ts +5 -8
  350. package/bin/utils/Time.d.ts.map +1 -1
  351. package/bin/utils/Time.js +5 -54
  352. package/bin/utils/Time.js.map +1 -1
  353. package/package.json +2 -2
  354. package/scripts/ask-question-answers.test.mjs +132 -0
  355. package/scripts/group-session-archive.test.mjs +193 -0
  356. package/scripts/{core-engine-model-stream.test.mjs → model-step-runner.test.mjs} +97 -4
  357. package/scripts/rewrite-build-aliases.mjs +3 -4
  358. package/scripts/session-action-part.test.mjs +172 -0
  359. package/scripts/session-agent-message-part-order.test.mjs +13 -7
  360. package/scripts/{core-engine-context-compaction.test.mjs → session-executor-context-pressure.test.mjs} +40 -32
  361. package/scripts/{executor-failure-result.test.mjs → session-executor-failure-result.test.mjs} +17 -14
  362. package/scripts/session-executor-max-steps.test.mjs +143 -0
  363. package/scripts/session-initialization.test.mjs +3 -4
  364. package/scripts/session-interaction-migration.test.mjs +145 -0
  365. package/scripts/session-interaction-mutation.test.mjs +202 -0
  366. package/scripts/session-messages-error-part.test.mjs +1 -1
  367. package/scripts/session-messages-error.test.mjs +1 -1
  368. package/scripts/session-prompt-idempotency.test.mjs +4 -2
  369. package/scripts/session-queue.test.mjs +21 -1
  370. package/scripts/session-storage-sqlite.test.mjs +3 -3
  371. package/scripts/session-system-blocks.test.mjs +61 -39
  372. package/scripts/session-turn-context.test.mjs +37 -40
  373. package/scripts/verify-build-aliases.mjs +1 -1
  374. package/src/agent/Agent.ts +137 -80
  375. package/src/agent/AgentInstructions.ts +48 -15
  376. package/src/agent/AgentMemoryStorage.ts +1 -1
  377. package/src/agent/AgentSessions.ts +60 -38
  378. package/src/group/Group.ts +27 -24
  379. package/src/group/GroupSession.ts +12 -8
  380. package/src/group/GroupSessions.ts +79 -20
  381. package/src/group/storage/LocalGroupSessionDataStore.ts +9 -1
  382. package/src/group/storage/LocalGroupSessionStore.ts +138 -28
  383. package/src/index.ts +35 -52
  384. package/src/{executor/model → model}/ModelGenerate.ts +3 -3
  385. package/src/{executor/model → model}/ModelRequestRunner.ts +2 -2
  386. package/src/{executor/model → model}/ModelStepRunner.ts +22 -19
  387. package/src/{executor/model → model}/ModelStreamConsumer.ts +1 -1
  388. package/src/model/README.md +117 -0
  389. package/src/model/ToolInputValidation.ts +58 -0
  390. package/src/{executor → model}/messages/ChatMessageMarkupTypes.ts +1 -1
  391. package/src/{executor → model}/messages/SessionModelMessages.ts +0 -1
  392. package/src/{executor/composer/system/default → model/prompts}/SystemPromptAssets.ts +1 -1
  393. package/src/model/prompts/assets/core.prompt.ts +9 -0
  394. package/src/{executor/composer/system/default → model/prompts}/assets/core.prompt.ts.txt +26 -25
  395. package/src/session/Session.ts +185 -151
  396. package/src/session/input/SessionHookRunner.ts +100 -0
  397. package/src/session/{SessionSystem.ts → input/SessionSystem.ts} +31 -29
  398. package/src/session/input/StepInput.ts +507 -0
  399. package/src/session/input/composer/AdaptiveContextCheckpoint.ts +115 -0
  400. package/src/session/input/composer/AdaptiveContextParts.ts +166 -0
  401. package/src/session/input/composer/ComposerAssembly.ts +81 -0
  402. package/src/session/{composer/policies/SessionSummaryPrompts.ts → input/composer/ContextSummaryPrompts.ts} +5 -2
  403. package/src/session/input/composer/DefaultSessionComposer.ts +147 -0
  404. package/src/session/input/composer/FullHistorySessionComposer.ts +55 -0
  405. package/src/session/loop/README.md +28 -0
  406. package/src/session/{SessionLoop.ts → loop/SessionLoop.ts} +100 -24
  407. package/src/session/{SessionQueue.ts → loop/SessionQueue.ts} +18 -0
  408. package/src/session/{SessionState.ts → loop/SessionState.ts} +4 -21
  409. package/src/session/{SessionTitle.ts → loop/SessionTitle.ts} +3 -3
  410. package/src/session/{runtime → loop}/SessionTurnCompletion.ts +27 -8
  411. package/src/session/{runtime → loop}/SessionTurnContext.ts +19 -93
  412. package/src/session/{runtime → loop}/SessionTurnFileDiff.ts +1 -1
  413. package/src/session/{messages → loop}/SessionTurnFileDiffBuilder.ts +4 -4
  414. package/src/session/messages/ApprovalInteraction.ts +77 -0
  415. package/src/session/messages/README.md +27 -0
  416. package/src/session/messages/SessionAgentMessageState.ts +324 -113
  417. package/src/session/messages/SessionAgentMessageWriter.ts +82 -45
  418. package/src/session/messages/SessionAgentParts.ts +39 -0
  419. package/src/session/{execution → messages}/SessionAssistantOutputAdapter.ts +2 -2
  420. package/src/session/messages/SessionInteractions.ts +227 -0
  421. package/src/session/messages/SessionJsonValue.ts +1 -18
  422. package/src/session/messages/SessionMessageCache.ts +171 -0
  423. package/src/session/messages/SessionMessageState.ts +42 -0
  424. package/src/session/{browse → messages}/SessionMessageTimeline.ts +0 -1
  425. package/src/session/{SessionMessages.ts → messages/SessionMessages.ts} +225 -284
  426. package/src/session/messages/SessionMutationFactory.ts +58 -0
  427. package/src/session/messages/SessionUserMessage.ts +7 -32
  428. package/src/{executor/core-engine/CoreEngineSignals.ts → session/runner/AssistantParts.ts} +3 -21
  429. package/src/{executor/core-engine/CoreEngineContextCompaction.ts → session/runner/ContextPressure.ts} +10 -10
  430. package/src/{executor/services/ExecutorRecoveryPolicy.ts → session/runner/ContextRetry.ts} +25 -25
  431. package/src/{executor/core-engine/CoreEngineError.ts → session/runner/ModelFailure.ts} +3 -3
  432. package/src/session/runner/SessionExecutor.ts +633 -0
  433. package/src/session/runner/ToolLoopDecision.ts +98 -0
  434. package/src/session/runner/ToolLoopLimits.ts +53 -0
  435. package/src/session/{browse → storage}/Browse.ts +2 -2
  436. package/src/session/storage/LocalSessionStore.ts +1 -1
  437. package/src/session/storage/LocalStorePaths.ts +1 -1
  438. package/src/session/storage/Metadata.ts +1 -44
  439. package/src/session/storage/RuntimeSessionPort.ts +0 -5
  440. package/src/session/{preview → storage}/SessionMessagePreview.ts +0 -1
  441. package/src/session/storage/SessionStorageCodec.ts +54 -28
  442. package/src/session/storage/SessionStorageSchema.ts +1 -1
  443. package/src/session/storage/SqliteSessionStorage.ts +29 -22
  444. package/src/tools/ask/AskQuestionAnswers.ts +125 -0
  445. package/src/tools/ask/AskQuestionsTool.ts +32 -37
  446. package/src/types/agent/AgentOptions.ts +17 -8
  447. package/src/types/agent/AgentSessionCollection.ts +9 -0
  448. package/src/types/agent/SessionActor.ts +3 -4
  449. package/src/types/group/DispatchStrategy.ts +1 -1
  450. package/src/types/group/GroupSession.ts +44 -1
  451. package/src/types/group/GroupSessionStore.ts +30 -3
  452. package/src/types/sdk/AgentSessionAction.ts +1 -14
  453. package/src/types/session/{AdaptivePartContextPolicy.ts → ContextCheckpoint.ts} +9 -8
  454. package/src/types/session/SessionAgentMessageState.ts +6 -16
  455. package/src/types/session/SessionComposer.ts +67 -39
  456. package/src/types/session/SessionExecution.ts +15 -13
  457. package/src/types/session/SessionInteractions.ts +0 -2
  458. package/src/types/session/SessionLocalState.ts +0 -5
  459. package/src/types/session/SessionLoop.ts +37 -12
  460. package/src/types/session/SessionMessages.ts +3 -34
  461. package/src/types/session/SessionOptions.ts +18 -13
  462. package/src/types/session/SessionPort.ts +0 -4
  463. package/src/types/session/SessionState.ts +0 -1
  464. package/src/types/session/SessionSystem.ts +10 -16
  465. package/src/types/session/SessionTool.ts +2 -2
  466. package/src/types/session/SessionTurnCompletion.ts +12 -2
  467. package/src/types/session/SessionTurnFileDiff.ts +4 -4
  468. package/src/types/session/{SessionComposition.ts → StepInput.ts} +22 -14
  469. package/src/types/store/SessionStorage.ts +17 -12
  470. package/src/types/tool/BoundAgentTool.ts +38 -0
  471. package/src/types/tools/ask/AskQuestionsTool.ts +11 -13
  472. package/src/types/{executor → turn}/SessionTurnContext.ts +8 -34
  473. package/src/utils/Time.ts +12 -64
  474. package/tsconfig.json +1 -2
  475. package/tsconfig.tsbuildinfo +1 -1
  476. package/bin/executor/Executor.d.ts +0 -92
  477. package/bin/executor/Executor.d.ts.map +0 -1
  478. package/bin/executor/Executor.js +0 -232
  479. package/bin/executor/Executor.js.map +0 -1
  480. package/bin/executor/composer/system/default/SystemPromptAssets.d.ts.map +0 -1
  481. package/bin/executor/composer/system/default/SystemPromptAssets.js.map +0 -1
  482. package/bin/executor/composer/system/default/assets/core.prompt.d.ts +0 -7
  483. package/bin/executor/composer/system/default/assets/core.prompt.d.ts.map +0 -1
  484. package/bin/executor/composer/system/default/assets/core.prompt.js +0 -8
  485. package/bin/executor/composer/system/default/assets/core.prompt.js.map +0 -1
  486. package/bin/executor/core-engine/CoreEngineContextCompaction.d.ts +0 -15
  487. package/bin/executor/core-engine/CoreEngineContextCompaction.d.ts.map +0 -1
  488. package/bin/executor/core-engine/CoreEngineContextCompaction.js.map +0 -1
  489. package/bin/executor/core-engine/CoreEngineError.d.ts.map +0 -1
  490. package/bin/executor/core-engine/CoreEngineError.js.map +0 -1
  491. package/bin/executor/core-engine/CoreEngineLoopDecision.d.ts +0 -26
  492. package/bin/executor/core-engine/CoreEngineLoopDecision.d.ts.map +0 -1
  493. package/bin/executor/core-engine/CoreEngineLoopDecision.js.map +0 -1
  494. package/bin/executor/core-engine/CoreEngineRunner.d.ts +0 -48
  495. package/bin/executor/core-engine/CoreEngineRunner.d.ts.map +0 -1
  496. package/bin/executor/core-engine/CoreEngineRunner.js +0 -343
  497. package/bin/executor/core-engine/CoreEngineRunner.js.map +0 -1
  498. package/bin/executor/core-engine/CoreEngineSignals.d.ts.map +0 -1
  499. package/bin/executor/core-engine/CoreEngineSignals.js.map +0 -1
  500. package/bin/executor/ids/resolveSessionId.d.ts.map +0 -1
  501. package/bin/executor/ids/resolveSessionId.js.map +0 -1
  502. package/bin/executor/messages/ChatMessageMarkup.d.ts.map +0 -1
  503. package/bin/executor/messages/ChatMessageMarkup.js.map +0 -1
  504. package/bin/executor/messages/ChatMessageMarkupTypes.d.ts.map +0 -1
  505. package/bin/executor/messages/ChatMessageMarkupTypes.js.map +0 -1
  506. package/bin/executor/messages/SessionAttachmentMapper.d.ts.map +0 -1
  507. package/bin/executor/messages/SessionAttachmentMapper.js.map +0 -1
  508. package/bin/executor/messages/SessionMessageLog.d.ts.map +0 -1
  509. package/bin/executor/messages/SessionMessageLog.js.map +0 -1
  510. package/bin/executor/messages/SessionModelMessages.d.ts.map +0 -1
  511. package/bin/executor/messages/SessionModelMessages.js.map +0 -1
  512. package/bin/executor/model/ModelGenerate.d.ts.map +0 -1
  513. package/bin/executor/model/ModelGenerate.js.map +0 -1
  514. package/bin/executor/model/ModelRequestRunner.d.ts.map +0 -1
  515. package/bin/executor/model/ModelRequestRunner.js.map +0 -1
  516. package/bin/executor/model/ModelStepRunner.d.ts.map +0 -1
  517. package/bin/executor/model/ModelStepRunner.js.map +0 -1
  518. package/bin/executor/model/ModelStreamConsumer.d.ts.map +0 -1
  519. package/bin/executor/model/ModelStreamConsumer.js.map +0 -1
  520. package/bin/executor/model/ModelStreamFailure.d.ts.map +0 -1
  521. package/bin/executor/model/ModelStreamFailure.js.map +0 -1
  522. package/bin/executor/services/ExecutorRecoveryPolicy.d.ts +0 -39
  523. package/bin/executor/services/ExecutorRecoveryPolicy.d.ts.map +0 -1
  524. package/bin/executor/services/ExecutorRecoveryPolicy.js.map +0 -1
  525. package/bin/executor/types/SessionHistoryMeta.d.ts.map +0 -1
  526. package/bin/executor/types/SessionHistoryMeta.js.map +0 -1
  527. package/bin/executor/types/SessionLoop.d.ts +0 -59
  528. package/bin/executor/types/SessionLoop.d.ts.map +0 -1
  529. package/bin/executor/types/SessionLoop.js +0 -9
  530. package/bin/executor/types/SessionLoop.js.map +0 -1
  531. package/bin/executor/types/SessionPrompts.d.ts +0 -14
  532. package/bin/executor/types/SessionPrompts.d.ts.map +0 -1
  533. package/bin/executor/types/SessionPrompts.js +0 -8
  534. package/bin/executor/types/SessionPrompts.js.map +0 -1
  535. package/bin/session/DefaultSessionComposer.d.ts +0 -24
  536. package/bin/session/DefaultSessionComposer.d.ts.map +0 -1
  537. package/bin/session/DefaultSessionComposer.js +0 -99
  538. package/bin/session/DefaultSessionComposer.js.map +0 -1
  539. package/bin/session/SessionComposition.d.ts +0 -49
  540. package/bin/session/SessionComposition.d.ts.map +0 -1
  541. package/bin/session/SessionComposition.js +0 -309
  542. package/bin/session/SessionComposition.js.map +0 -1
  543. package/bin/session/SessionHookPoints.d.ts +0 -15
  544. package/bin/session/SessionHookPoints.d.ts.map +0 -1
  545. package/bin/session/SessionHookPoints.js +0 -15
  546. package/bin/session/SessionHookPoints.js.map +0 -1
  547. package/bin/session/SessionHooks.d.ts +0 -38
  548. package/bin/session/SessionHooks.d.ts.map +0 -1
  549. package/bin/session/SessionHooks.js +0 -71
  550. package/bin/session/SessionHooks.js.map +0 -1
  551. package/bin/session/SessionLoop.d.ts.map +0 -1
  552. package/bin/session/SessionLoop.js.map +0 -1
  553. package/bin/session/SessionMessages.d.ts.map +0 -1
  554. package/bin/session/SessionMessages.js.map +0 -1
  555. package/bin/session/SessionQueue.d.ts.map +0 -1
  556. package/bin/session/SessionQueue.js.map +0 -1
  557. package/bin/session/SessionState.d.ts.map +0 -1
  558. package/bin/session/SessionState.js.map +0 -1
  559. package/bin/session/SessionSystem.d.ts +0 -19
  560. package/bin/session/SessionSystem.d.ts.map +0 -1
  561. package/bin/session/SessionSystem.js.map +0 -1
  562. package/bin/session/SessionTitle.d.ts.map +0 -1
  563. package/bin/session/SessionTitle.js.map +0 -1
  564. package/bin/session/browse/Browse.d.ts.map +0 -1
  565. package/bin/session/browse/Browse.js.map +0 -1
  566. package/bin/session/browse/SessionMessageTimeline.d.ts.map +0 -1
  567. package/bin/session/browse/SessionMessageTimeline.js.map +0 -1
  568. package/bin/session/composer/policies/AdaptivePartContextPolicy.d.ts +0 -35
  569. package/bin/session/composer/policies/AdaptivePartContextPolicy.d.ts.map +0 -1
  570. package/bin/session/composer/policies/AdaptivePartContextPolicy.js +0 -256
  571. package/bin/session/composer/policies/AdaptivePartContextPolicy.js.map +0 -1
  572. package/bin/session/composer/policies/FullHistoryContextPolicy.d.ts +0 -24
  573. package/bin/session/composer/policies/FullHistoryContextPolicy.d.ts.map +0 -1
  574. package/bin/session/composer/policies/FullHistoryContextPolicy.js +0 -31
  575. package/bin/session/composer/policies/FullHistoryContextPolicy.js.map +0 -1
  576. package/bin/session/composer/policies/SessionSummaryPrompts.d.ts.map +0 -1
  577. package/bin/session/composer/policies/SessionSummaryPrompts.js.map +0 -1
  578. package/bin/session/control/SessionInteractions.d.ts +0 -39
  579. package/bin/session/control/SessionInteractions.d.ts.map +0 -1
  580. package/bin/session/control/SessionInteractions.js +0 -255
  581. package/bin/session/control/SessionInteractions.js.map +0 -1
  582. package/bin/session/execution/SessionAssistantOutputAdapter.d.ts.map +0 -1
  583. package/bin/session/execution/SessionAssistantOutputAdapter.js.map +0 -1
  584. package/bin/session/execution/tools/SessionShellApprovalAdapter.d.ts +0 -28
  585. package/bin/session/execution/tools/SessionShellApprovalAdapter.d.ts.map +0 -1
  586. package/bin/session/execution/tools/SessionShellApprovalAdapter.js +0 -87
  587. package/bin/session/execution/tools/SessionShellApprovalAdapter.js.map +0 -1
  588. package/bin/session/messages/SessionAgentActionPartWriter.d.ts +0 -22
  589. package/bin/session/messages/SessionAgentActionPartWriter.d.ts.map +0 -1
  590. package/bin/session/messages/SessionAgentActionPartWriter.js +0 -36
  591. package/bin/session/messages/SessionAgentActionPartWriter.js.map +0 -1
  592. package/bin/session/messages/SessionMessageInteractionWriter.d.ts +0 -46
  593. package/bin/session/messages/SessionMessageInteractionWriter.d.ts.map +0 -1
  594. package/bin/session/messages/SessionMessageInteractionWriter.js +0 -183
  595. package/bin/session/messages/SessionMessageInteractionWriter.js.map +0 -1
  596. package/bin/session/messages/SessionTurnFileDiffBuilder.d.ts.map +0 -1
  597. package/bin/session/messages/SessionTurnFileDiffBuilder.js.map +0 -1
  598. package/bin/session/runtime/SessionEventHub.d.ts.map +0 -1
  599. package/bin/session/runtime/SessionEventHub.js.map +0 -1
  600. package/bin/session/runtime/SessionModelRequestWarning.d.ts.map +0 -1
  601. package/bin/session/runtime/SessionModelRequestWarning.js.map +0 -1
  602. package/bin/session/runtime/SessionTitleTask.d.ts.map +0 -1
  603. package/bin/session/runtime/SessionTitleTask.js.map +0 -1
  604. package/bin/session/runtime/SessionTurnCompletion.d.ts.map +0 -1
  605. package/bin/session/runtime/SessionTurnCompletion.js.map +0 -1
  606. package/bin/session/runtime/SessionTurnContext.d.ts +0 -29
  607. package/bin/session/runtime/SessionTurnContext.d.ts.map +0 -1
  608. package/bin/session/runtime/SessionTurnContext.js.map +0 -1
  609. package/bin/session/runtime/SessionTurnFileDiff.d.ts.map +0 -1
  610. package/bin/session/runtime/SessionTurnFileDiff.js.map +0 -1
  611. package/bin/types/action/ActionResult.d.ts +0 -35
  612. package/bin/types/action/ActionResult.d.ts.map +0 -1
  613. package/bin/types/action/ActionResult.js +0 -18
  614. package/bin/types/action/ActionResult.js.map +0 -1
  615. package/bin/types/executor/ModelRequest.d.ts.map +0 -1
  616. package/bin/types/executor/ModelRequest.js.map +0 -1
  617. package/bin/types/executor/SessionAssistantOutput.d.ts.map +0 -1
  618. package/bin/types/executor/SessionAssistantOutput.js.map +0 -1
  619. package/bin/types/executor/SessionToolExecutionContext.d.ts +0 -23
  620. package/bin/types/executor/SessionToolExecutionContext.d.ts.map +0 -1
  621. package/bin/types/executor/SessionToolExecutionContext.js +0 -10
  622. package/bin/types/executor/SessionToolExecutionContext.js.map +0 -1
  623. package/bin/types/executor/SessionTurnContext.d.ts.map +0 -1
  624. package/bin/types/executor/SessionTurnContext.js.map +0 -1
  625. package/bin/types/session/AdaptivePartContextPolicy.d.ts.map +0 -1
  626. package/bin/types/session/AdaptivePartContextPolicy.js +0 -7
  627. package/bin/types/session/AdaptivePartContextPolicy.js.map +0 -1
  628. package/bin/types/session/SessionComposition.d.ts.map +0 -1
  629. package/bin/types/session/SessionComposition.js +0 -8
  630. package/bin/types/session/SessionComposition.js.map +0 -1
  631. package/bin/types/session/SessionContextPolicy.d.ts +0 -70
  632. package/bin/types/session/SessionContextPolicy.d.ts.map +0 -1
  633. package/bin/types/session/SessionContextPolicy.js +0 -8
  634. package/bin/types/session/SessionContextPolicy.js.map +0 -1
  635. package/bin/types/tools/ToolActionExecutionContext.d.ts +0 -30
  636. package/bin/types/tools/ToolActionExecutionContext.d.ts.map +0 -1
  637. package/bin/types/tools/ToolActionExecutionContext.js +0 -8
  638. package/bin/types/tools/ToolActionExecutionContext.js.map +0 -1
  639. package/src/executor/Executor.ts +0 -319
  640. package/src/executor/README.md +0 -92
  641. package/src/executor/composer/system/default/assets/core.prompt.ts +0 -9
  642. package/src/executor/core-engine/CoreEngineLoopDecision.ts +0 -63
  643. package/src/executor/core-engine/CoreEngineRunner.ts +0 -458
  644. package/src/executor/types/SessionLoop.ts +0 -69
  645. package/src/executor/types/SessionPrompts.ts +0 -14
  646. package/src/session/DefaultSessionComposer.ts +0 -123
  647. package/src/session/SessionComposition.ts +0 -370
  648. package/src/session/SessionHookPoints.ts +0 -17
  649. package/src/session/SessionHooks.ts +0 -85
  650. package/src/session/composer/policies/AdaptivePartContextPolicy.ts +0 -307
  651. package/src/session/composer/policies/FullHistoryContextPolicy.ts +0 -36
  652. package/src/session/control/SessionInteractions.ts +0 -311
  653. package/src/session/execution/tools/SessionShellApprovalAdapter.ts +0 -105
  654. package/src/session/messages/SessionAgentActionPartWriter.ts +0 -54
  655. package/src/session/messages/SessionMessageInteractionWriter.ts +0 -279
  656. package/src/types/action/ActionResult.ts +0 -50
  657. package/src/types/executor/SessionToolExecutionContext.ts +0 -26
  658. package/src/types/session/SessionContextPolicy.ts +0 -77
  659. package/src/types/tools/ToolActionExecutionContext.ts +0 -32
  660. /package/bin/{executor/model → model}/ModelGenerate.js +0 -0
  661. /package/bin/{executor/model → model}/ModelRequestRunner.js +0 -0
  662. /package/bin/{executor/model → model}/ModelStreamConsumer.d.ts +0 -0
  663. /package/bin/{executor/model → model}/ModelStreamConsumer.js +0 -0
  664. /package/bin/{executor/model → model}/ModelStreamFailure.d.ts +0 -0
  665. /package/bin/{executor/model → model}/ModelStreamFailure.js +0 -0
  666. /package/bin/{executor → model}/messages/ChatMessageMarkup.d.ts +0 -0
  667. /package/bin/{executor → model}/messages/ChatMessageMarkup.js +0 -0
  668. /package/bin/{executor → model}/messages/SessionAttachmentMapper.d.ts +0 -0
  669. /package/bin/{executor → model}/messages/SessionAttachmentMapper.js +0 -0
  670. /package/bin/{executor → model}/messages/SessionMessageLog.d.ts +0 -0
  671. /package/bin/{executor → model}/messages/SessionMessageLog.js +0 -0
  672. /package/bin/{executor → model}/messages/SessionModelMessages.d.ts +0 -0
  673. /package/bin/{executor/composer/system/default → model/prompts}/SystemPromptAssets.d.ts +0 -0
  674. /package/bin/session/{runtime → loop}/SessionTitleTask.d.ts +0 -0
  675. /package/bin/session/{runtime → loop}/SessionTitleTask.js +0 -0
  676. /package/bin/session/{runtime → loop}/SessionTurnFileDiff.d.ts +0 -0
  677. /package/bin/session/{messages → loop}/SessionTurnFileDiffBuilder.js +0 -0
  678. /package/bin/session/{execution → messages}/SessionAssistantOutputAdapter.js +0 -0
  679. /package/bin/session/{runtime → messages}/SessionEventHub.d.ts +0 -0
  680. /package/bin/session/{runtime → messages}/SessionEventHub.js +0 -0
  681. /package/bin/session/{browse → messages}/SessionMessageTimeline.d.ts +0 -0
  682. /package/bin/session/{runtime → messages}/SessionModelRequestWarning.d.ts +0 -0
  683. /package/bin/session/{runtime → messages}/SessionModelRequestWarning.js +0 -0
  684. /package/bin/session/{preview → storage}/SessionMessagePreview.d.ts +0 -0
  685. /package/bin/types/{executor → model}/ModelRequest.d.ts +0 -0
  686. /package/bin/types/{executor → model}/ModelRequest.js +0 -0
  687. /package/bin/{executor/types → types/store}/SessionHistoryMeta.d.ts +0 -0
  688. /package/bin/{executor/types → types/store}/SessionHistoryMeta.js +0 -0
  689. /package/bin/types/{executor → turn}/SessionAssistantOutput.d.ts +0 -0
  690. /package/bin/types/{executor → turn}/SessionAssistantOutput.js +0 -0
  691. /package/bin/types/{executor → turn}/SessionTurnContext.js +0 -0
  692. /package/src/{executor/model → model}/ModelStreamFailure.ts +0 -0
  693. /package/src/{executor → model}/messages/ChatMessageMarkup.ts +0 -0
  694. /package/src/{executor → model}/messages/SessionAttachmentMapper.ts +0 -0
  695. /package/src/{executor → model}/messages/SessionMessageLog.ts +0 -0
  696. /package/src/session/{runtime → loop}/SessionTitleTask.ts +0 -0
  697. /package/src/session/{runtime → messages}/SessionEventHub.ts +0 -0
  698. /package/src/session/{runtime → messages}/SessionModelRequestWarning.ts +0 -0
  699. /package/src/types/{executor → model}/ModelRequest.ts +0 -0
  700. /package/src/{executor/types → types/store}/SessionHistoryMeta.ts +0 -0
  701. /package/src/types/{executor → turn}/SessionAssistantOutput.ts +0 -0
  702. /package/src/{executor/ids/resolveSessionId.ts → utils/ResolveSessionId.ts} +0 -0
@@ -3,12 +3,12 @@
3
3
  *
4
4
  * 关键点(中文)
5
5
  * - 统一管理 session 缓存、创建、恢复、默认配置注入与列表查询。
6
- * - 该服务只负责 Session 生命周期与查询,不负责 Plugin / RPC 启停。
6
+ * - 该服务只负责 Session 生命周期与查询,不负责 Power / RPC 启停。
7
7
  * - Session 对象创建细节集中在这里,避免 facade 和 lifecycle 重复依赖 Session 构造逻辑。
8
8
  */
9
9
 
10
10
  import { nanoid } from "nanoid";
11
- import type { ModelClient, RuntimeTool as Tool } from "@downcity/type";
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 { SessionHookRuntime } from "@downcity/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
- get_hooks: () => SessionHookRuntime;
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
- /** 为每个 Session 创建独立 Composer 的工厂。 */
85
- create_session_composer?: () => SessionComposer;
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 create_session_composer: () => SessionComposer;
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.create_session_composer = options.create_session_composer ||
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
- * - 该方法不处理任何 Plugin 自有数据。
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(context.workspace_path),
440
- get_instruction_system_blocks: () => this.load_instruction_system_blocks(context.workspace_path),
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
- get_managed_plugin_system_blocks: async () => [],
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(workspace_path: string): AgentSessionSystemBlock[] {
474
- return create_instruction_system_blocks(
475
- this.get_instruction(),
476
- workspace_path,
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
  }
@@ -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
- /** 当前 Group 所属宿主。 */
26
- private storage_owner?: object;
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
- /** 将宿主存储装配到 Group;必须在使用 GroupSessions 前完成。 */
51
- attach(owner: object, storage_provider: StorageProvider): void {
52
- if (this.storage_owner) {
53
- if (this.storage_owner === owner) return;
54
- throw new Error(`Group "${this.id}" already belongs to another host`);
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.memory_session_started || this.session_store) {
59
+ if (this.session_store) {
57
60
  throw new Error(
58
- `Group "${this.id}" already used standalone storage; attach it before using GroupSessions`,
61
+ `Group "${this.id}" already used standalone storage; bind it before using GroupSessions`,
59
62
  );
60
63
  }
61
- this.storage_owner = owner;
62
- this.storage_provider = storage_provider;
64
+ this.host = host;
65
+ this.storage_provider = host.storage;
63
66
  }
64
67
 
65
- /** 解除指定宿主的存储装配并释放当前 Store。 */
66
- async detach(owner: object): Promise<void> {
67
- if (this.storage_owner !== owner) return;
68
+ /** 解除容器绑定并释放当前 Store,主体回到独立运行状态。 */
69
+ async unbind(): Promise<void> {
70
+ if (!this.host) return;
68
71
  await this.dispose_session_store();
69
- this.storage_owner = undefined;
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/runtime/SessionTitleTask.js";
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 !== "interaction") return;
714
- if (mutation.part.status === "pending") {
715
- this.interaction_sessions.set(mutation.part.interaction_id, session);
716
- this.publish_event({ type: "interaction", agent_id, request: mutation.part.request });
717
- } else {
718
- this.interaction_sessions.delete(mutation.part.interaction_id);
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 store = this.group.get_session_store();
57
- const metadata = await store.list_session_metadata();
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");