@downcity/agent 1.1.208 → 1.1.210

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 (262) hide show
  1. package/bin/agent/local/Agent.d.ts +3 -3
  2. package/bin/agent/local/Agent.d.ts.map +1 -1
  3. package/bin/agent/local/Agent.js +0 -3
  4. package/bin/agent/local/Agent.js.map +1 -1
  5. package/bin/agent/local/AgentInstructions.d.ts +1 -1
  6. package/bin/agent/local/AgentInstructions.d.ts.map +1 -1
  7. package/bin/agent/local/services/AgentAssemblyService.d.ts +3 -8
  8. package/bin/agent/local/services/AgentAssemblyService.d.ts.map +1 -1
  9. package/bin/agent/local/services/AgentAssemblyService.js +0 -1
  10. package/bin/agent/local/services/AgentAssemblyService.js.map +1 -1
  11. package/bin/agent/local/services/AgentSessions.d.ts +5 -7
  12. package/bin/agent/local/services/AgentSessions.d.ts.map +1 -1
  13. package/bin/agent/local/services/AgentSessions.js +2 -3
  14. package/bin/agent/local/services/AgentSessions.js.map +1 -1
  15. package/bin/agent/remote/RemoteAgent.d.ts +3 -1
  16. package/bin/agent/remote/RemoteAgent.d.ts.map +1 -1
  17. package/bin/agent/remote/RemoteAgent.js.map +1 -1
  18. package/bin/agent/remote/RemoteSession.d.ts +10 -1
  19. package/bin/agent/remote/RemoteSession.d.ts.map +1 -1
  20. package/bin/agent/remote/RemoteSession.js +18 -0
  21. package/bin/agent/remote/RemoteSession.js.map +1 -1
  22. package/bin/agent/remote/RemoteTransport.d.ts +5 -1
  23. package/bin/agent/remote/RemoteTransport.d.ts.map +1 -1
  24. package/bin/agent/remote/transports/HttpRemoteAgentTransport.d.ts +4 -1
  25. package/bin/agent/remote/transports/HttpRemoteAgentTransport.d.ts.map +1 -1
  26. package/bin/agent/remote/transports/HttpRemoteAgentTransport.js +7 -0
  27. package/bin/agent/remote/transports/HttpRemoteAgentTransport.js.map +1 -1
  28. package/bin/agent/remote/transports/RpcRemoteAgentTransport.d.ts +4 -1
  29. package/bin/agent/remote/transports/RpcRemoteAgentTransport.d.ts.map +1 -1
  30. package/bin/agent/remote/transports/RpcRemoteAgentTransport.js +1 -0
  31. package/bin/agent/remote/transports/RpcRemoteAgentTransport.js.map +1 -1
  32. package/bin/executor/Executor.d.ts +0 -16
  33. package/bin/executor/Executor.d.ts.map +1 -1
  34. package/bin/executor/Executor.js +0 -16
  35. package/bin/executor/Executor.js.map +1 -1
  36. package/bin/executor/composer/compaction/jsonl/JsonlSessionCompactionExecutor.d.ts +1 -3
  37. package/bin/executor/composer/compaction/jsonl/JsonlSessionCompactionExecutor.d.ts.map +1 -1
  38. package/bin/executor/composer/compaction/jsonl/JsonlSessionCompactionExecutor.js +1 -5
  39. package/bin/executor/composer/compaction/jsonl/JsonlSessionCompactionExecutor.js.map +1 -1
  40. package/bin/executor/composer/history/SessionHistoryWriter.d.ts +0 -10
  41. package/bin/executor/composer/history/SessionHistoryWriter.d.ts.map +1 -1
  42. package/bin/executor/composer/history/SessionHistoryWriter.js +31 -61
  43. package/bin/executor/composer/history/SessionHistoryWriter.js.map +1 -1
  44. package/bin/executor/messages/AssistantFileResource.d.ts.map +1 -1
  45. package/bin/executor/messages/AssistantFileResource.js +58 -15
  46. package/bin/executor/messages/AssistantFileResource.js.map +1 -1
  47. package/bin/executor/services/ExecutorInflightService.d.ts +0 -5
  48. package/bin/executor/services/ExecutorInflightService.d.ts.map +1 -1
  49. package/bin/executor/services/ExecutorInflightService.js +0 -6
  50. package/bin/executor/services/ExecutorInflightService.js.map +1 -1
  51. package/bin/executor/store/history/jsonl/JsonlSessionHistoryStore.d.ts +4 -0
  52. package/bin/executor/store/history/jsonl/JsonlSessionHistoryStore.d.ts.map +1 -1
  53. package/bin/executor/store/history/jsonl/JsonlSessionHistoryStore.js +115 -3
  54. package/bin/executor/store/history/jsonl/JsonlSessionHistoryStore.js.map +1 -1
  55. package/bin/executor/types/SessionHistoryMeta.d.ts +6 -0
  56. package/bin/executor/types/SessionHistoryMeta.d.ts.map +1 -1
  57. package/bin/index.d.ts +38 -6
  58. package/bin/index.d.ts.map +1 -1
  59. package/bin/index.js +14 -1
  60. package/bin/index.js.map +1 -1
  61. package/bin/plugin/core/ActionScheduleExecutor.js +1 -1
  62. package/bin/plugin/core/ActionScheduleExecutor.js.map +1 -1
  63. package/bin/plugin/core/BasePlugin.d.ts +7 -9
  64. package/bin/plugin/core/BasePlugin.d.ts.map +1 -1
  65. package/bin/plugin/core/BasePlugin.js +1 -14
  66. package/bin/plugin/core/BasePlugin.js.map +1 -1
  67. package/bin/plugin/core/HookRegistry.d.ts +1 -1
  68. package/bin/plugin/core/HookRegistry.d.ts.map +1 -1
  69. package/bin/plugin/core/PluginActionFactory.d.ts +1 -5
  70. package/bin/plugin/core/PluginActionFactory.d.ts.map +1 -1
  71. package/bin/plugin/core/PluginActionFactory.js +0 -3
  72. package/bin/plugin/core/PluginActionFactory.js.map +1 -1
  73. package/bin/plugin/core/PluginActionRunner.d.ts +6 -4
  74. package/bin/plugin/core/PluginActionRunner.d.ts.map +1 -1
  75. package/bin/plugin/core/PluginActionRunner.js +2 -2
  76. package/bin/plugin/core/PluginActionRunner.js.map +1 -1
  77. package/bin/plugin/core/PluginCatalog.d.ts +2 -1
  78. package/bin/plugin/core/PluginCatalog.d.ts.map +1 -1
  79. package/bin/plugin/core/PluginCatalog.js.map +1 -1
  80. package/bin/plugin/core/PluginCommand.d.ts +1 -1
  81. package/bin/plugin/core/PluginCommand.d.ts.map +1 -1
  82. package/bin/plugin/core/PluginCommand.js.map +1 -1
  83. package/bin/plugin/core/PluginHttpRoutes.d.ts +1 -1
  84. package/bin/plugin/core/PluginHttpRoutes.d.ts.map +1 -1
  85. package/bin/plugin/core/PluginLocalExecution.d.ts +4 -1
  86. package/bin/plugin/core/PluginLocalExecution.d.ts.map +1 -1
  87. package/bin/plugin/core/PluginLocalExecution.js +0 -1
  88. package/bin/plugin/core/PluginLocalExecution.js.map +1 -1
  89. package/bin/plugin/core/PluginRegistry.d.ts +4 -2
  90. package/bin/plugin/core/PluginRegistry.d.ts.map +1 -1
  91. package/bin/plugin/core/PluginRegistry.js +7 -6
  92. package/bin/plugin/core/PluginRegistry.js.map +1 -1
  93. package/bin/plugin/core/PluginStateController.d.ts +7 -27
  94. package/bin/plugin/core/PluginStateController.d.ts.map +1 -1
  95. package/bin/plugin/core/PluginStateController.js +5 -39
  96. package/bin/plugin/core/PluginStateController.js.map +1 -1
  97. package/bin/plugin/types/PluginApi.d.ts +3 -79
  98. package/bin/plugin/types/PluginApi.d.ts.map +1 -1
  99. package/bin/rpc/Client.d.ts +11 -6
  100. package/bin/rpc/Client.d.ts.map +1 -1
  101. package/bin/rpc/Client.js +2 -0
  102. package/bin/rpc/Client.js.map +1 -1
  103. package/bin/session/Session.d.ts +2 -5
  104. package/bin/session/Session.d.ts.map +1 -1
  105. package/bin/session/Session.js +3 -16
  106. package/bin/session/Session.js.map +1 -1
  107. package/bin/session/SessionSystemBuilder.d.ts +1 -1
  108. package/bin/session/SessionSystemBuilder.d.ts.map +1 -1
  109. package/bin/session/browse/Browse.d.ts +4 -6
  110. package/bin/session/browse/Browse.d.ts.map +1 -1
  111. package/bin/session/browse/Browse.js +71 -71
  112. package/bin/session/browse/Browse.js.map +1 -1
  113. package/bin/session/preview/SessionMessagePreview.d.ts +13 -0
  114. package/bin/session/preview/SessionMessagePreview.d.ts.map +1 -0
  115. package/bin/session/preview/SessionMessagePreview.js +61 -0
  116. package/bin/session/preview/SessionMessagePreview.js.map +1 -0
  117. package/bin/session/services/SessionStateService.d.ts +1 -1
  118. package/bin/session/services/SessionStateService.d.ts.map +1 -1
  119. package/bin/session/services/SessionStateService.js +2 -2
  120. package/bin/session/services/SessionStateService.js.map +1 -1
  121. package/bin/session/services/SessionViewService.d.ts +2 -1
  122. package/bin/session/services/SessionViewService.d.ts.map +1 -1
  123. package/bin/session/services/SessionViewService.js +4 -1
  124. package/bin/session/services/SessionViewService.js.map +1 -1
  125. package/bin/session/storage/Metadata.d.ts.map +1 -1
  126. package/bin/session/storage/Metadata.js +23 -0
  127. package/bin/session/storage/Metadata.js.map +1 -1
  128. package/bin/session/storage/Persistence.d.ts +1 -1
  129. package/bin/session/storage/Persistence.d.ts.map +1 -1
  130. package/bin/session/storage/RuntimeSessionPort.d.ts +0 -12
  131. package/bin/session/storage/RuntimeSessionPort.d.ts.map +1 -1
  132. package/bin/session/storage/RuntimeSessionPort.js +0 -8
  133. package/bin/session/storage/RuntimeSessionPort.js.map +1 -1
  134. package/bin/types/plugin/PluginAction.d.ts +0 -10
  135. package/bin/types/plugin/PluginAction.d.ts.map +1 -1
  136. package/bin/types/plugin/PluginCommand.d.ts +2 -3
  137. package/bin/types/plugin/PluginCommand.d.ts.map +1 -1
  138. package/bin/types/plugin/PluginControl.d.ts +74 -0
  139. package/bin/types/plugin/PluginControl.d.ts.map +1 -0
  140. package/bin/types/plugin/PluginControl.js +9 -0
  141. package/bin/types/plugin/PluginControl.js.map +1 -0
  142. package/bin/types/plugin/PluginDefinition.d.ts +1 -1
  143. package/bin/types/plugin/PluginDefinition.d.ts.map +1 -1
  144. package/bin/types/plugin/PluginRuntime.d.ts +1 -3
  145. package/bin/types/plugin/PluginRuntime.d.ts.map +1 -1
  146. package/bin/types/plugin/PluginState.d.ts +3 -16
  147. package/bin/types/plugin/PluginState.d.ts.map +1 -1
  148. package/bin/types/rpc/RpcProtocol.d.ts +3 -3
  149. package/bin/types/rpc/RpcProtocol.d.ts.map +1 -1
  150. package/bin/types/runtime/agent/AgentContext.d.ts +1 -9
  151. package/bin/types/runtime/agent/AgentContext.d.ts.map +1 -1
  152. package/bin/types/runtime/agent/AgentContext.js.map +1 -1
  153. package/bin/types/session/SessionLocalState.d.ts +1 -1
  154. package/bin/types/session/SessionLocalState.d.ts.map +1 -1
  155. package/package.json +4 -7
  156. package/scripts/agent-ready.test.mjs +38 -0
  157. package/scripts/assistant-file-resource.test.mjs +39 -0
  158. package/scripts/city-model-tool-loop.test.mjs +18 -30
  159. package/scripts/image-plugin-job.test.mjs +13 -13
  160. package/scripts/plugin-tool-bridge.test.mjs +2 -3
  161. package/scripts/remote-session-reconnect.test.mjs +67 -0
  162. package/scripts/session-history-writer-error.test.mjs +57 -0
  163. package/scripts/session-list-title.test.mjs +114 -23
  164. package/src/agent/local/Agent.ts +4 -10
  165. package/src/agent/local/AgentInstructions.ts +1 -1
  166. package/src/agent/local/services/AgentAssemblyService.ts +3 -9
  167. package/src/agent/local/services/AgentSessions.ts +8 -15
  168. package/src/agent/remote/RemoteAgent.ts +5 -4
  169. package/src/agent/remote/RemoteSession.ts +21 -2
  170. package/src/agent/remote/RemoteTransport.ts +6 -2
  171. package/src/agent/remote/transports/HttpRemoteAgentTransport.ts +13 -3
  172. package/src/agent/remote/transports/RpcRemoteAgentTransport.ts +6 -2
  173. package/src/executor/Executor.ts +0 -23
  174. package/src/executor/composer/compaction/jsonl/JsonlSessionCompactionExecutor.ts +2 -8
  175. package/src/executor/composer/history/SessionHistoryWriter.ts +33 -64
  176. package/src/executor/messages/AssistantFileResource.ts +61 -17
  177. package/src/executor/services/ExecutorInflightService.ts +0 -10
  178. package/src/executor/store/history/jsonl/JsonlSessionHistoryStore.ts +130 -4
  179. package/src/executor/types/SessionHistoryMeta.ts +6 -0
  180. package/src/index.ts +100 -29
  181. package/src/plugin/core/ActionScheduleExecutor.ts +1 -1
  182. package/src/plugin/core/BasePlugin.ts +8 -22
  183. package/src/plugin/core/HookRegistry.ts +1 -1
  184. package/src/plugin/core/PluginActionFactory.ts +1 -8
  185. package/src/plugin/core/PluginActionRunner.ts +8 -11
  186. package/src/plugin/core/PluginCatalog.ts +2 -5
  187. package/src/plugin/core/PluginCommand.ts +2 -1
  188. package/src/plugin/core/PluginHttpRoutes.ts +1 -1
  189. package/src/plugin/core/PluginLocalExecution.ts +4 -7
  190. package/src/plugin/core/PluginRegistry.ts +10 -10
  191. package/src/plugin/core/PluginStateController.ts +12 -60
  192. package/src/plugin/types/PluginApi.ts +6 -81
  193. package/src/rpc/Client.ts +22 -16
  194. package/src/session/Session.ts +5 -21
  195. package/src/session/SessionSystemBuilder.ts +1 -1
  196. package/src/session/browse/Browse.ts +103 -84
  197. package/src/session/preview/SessionMessagePreview.ts +75 -0
  198. package/src/session/services/SessionStateService.ts +3 -4
  199. package/src/session/services/SessionViewService.ts +6 -6
  200. package/src/session/storage/Metadata.ts +26 -0
  201. package/src/session/storage/Persistence.ts +1 -1
  202. package/src/session/storage/RuntimeSessionPort.ts +0 -20
  203. package/src/types/plugin/PluginAction.ts +0 -10
  204. package/src/types/plugin/PluginCommand.ts +2 -3
  205. package/src/types/plugin/PluginControl.ts +80 -0
  206. package/src/types/plugin/PluginDefinition.ts +1 -1
  207. package/src/types/plugin/PluginRuntime.ts +1 -3
  208. package/src/types/plugin/PluginState.ts +3 -20
  209. package/src/types/rpc/RpcProtocol.ts +4 -4
  210. package/src/types/runtime/agent/AgentContext.ts +1 -9
  211. package/src/types/session/SessionLocalState.ts +1 -1
  212. package/tsconfig.tsbuildinfo +1 -1
  213. package/bin/config/DowncitySchema.d.ts +0 -20
  214. package/bin/config/DowncitySchema.d.ts.map +0 -1
  215. package/bin/config/DowncitySchema.js +0 -160
  216. package/bin/config/DowncitySchema.js.map +0 -1
  217. package/bin/plugin/core/Activation.d.ts +0 -18
  218. package/bin/plugin/core/Activation.d.ts.map +0 -1
  219. package/bin/plugin/core/Activation.js +0 -21
  220. package/bin/plugin/core/Activation.js.map +0 -1
  221. package/bin/plugin/core/Manager.d.ts +0 -7
  222. package/bin/plugin/core/Manager.d.ts.map +0 -1
  223. package/bin/plugin/core/Manager.js +0 -6
  224. package/bin/plugin/core/Manager.js.map +0 -1
  225. package/bin/plugin/types/Plugin.d.ts +0 -15
  226. package/bin/plugin/types/Plugin.d.ts.map +0 -1
  227. package/bin/plugin/types/Plugin.js +0 -9
  228. package/bin/plugin/types/Plugin.js.map +0 -1
  229. package/bin/plugin/types/PluginLifecycle.d.ts +0 -34
  230. package/bin/plugin/types/PluginLifecycle.d.ts.map +0 -1
  231. package/bin/plugin/types/PluginLifecycle.js +0 -9
  232. package/bin/plugin/types/PluginLifecycle.js.map +0 -1
  233. package/bin/plugin/types/PluginState.d.ts +0 -5
  234. package/bin/plugin/types/PluginState.d.ts.map +0 -1
  235. package/bin/plugin/types/PluginState.js +0 -5
  236. package/bin/plugin/types/PluginState.js.map +0 -1
  237. package/bin/plugin/types/Plugins.d.ts +0 -61
  238. package/bin/plugin/types/Plugins.d.ts.map +0 -1
  239. package/bin/plugin/types/Plugins.js +0 -5
  240. package/bin/plugin/types/Plugins.js.map +0 -1
  241. package/bin/session/index.d.ts +0 -15
  242. package/bin/session/index.d.ts.map +0 -1
  243. package/bin/session/index.js +0 -15
  244. package/bin/session/index.js.map +0 -1
  245. package/bin/types/agent/AgentTypes.d.ts +0 -18
  246. package/bin/types/agent/AgentTypes.d.ts.map +0 -1
  247. package/bin/types/agent/AgentTypes.js +0 -10
  248. package/bin/types/agent/AgentTypes.js.map +0 -1
  249. package/bin/utils/logger/Format.d.ts +0 -11
  250. package/bin/utils/logger/Format.d.ts.map +0 -1
  251. package/bin/utils/logger/Format.js +0 -10
  252. package/bin/utils/logger/Format.js.map +0 -1
  253. package/src/config/DowncitySchema.ts +0 -175
  254. package/src/plugin/core/Activation.ts +0 -26
  255. package/src/plugin/core/Manager.ts +0 -17
  256. package/src/plugin/types/Plugin.ts +0 -63
  257. package/src/plugin/types/PluginLifecycle.ts +0 -35
  258. package/src/plugin/types/PluginState.ts +0 -12
  259. package/src/plugin/types/Plugins.ts +0 -67
  260. package/src/session/index.ts +0 -57
  261. package/src/types/agent/AgentTypes.ts +0 -58
  262. package/src/utils/logger/Format.ts +0 -15
package/src/index.ts CHANGED
@@ -16,22 +16,15 @@ export {
16
16
  inferAgentModelLabel,
17
17
  normalizeAgentModel,
18
18
  } from "./model/CityModelAdapter.js";
19
+ export type { AgentModel } from "./model/CityModelAdapter.js";
19
20
  export type {
20
21
  AgentArchiveSessionInput,
21
22
  AgentArchiveSessionsInput,
22
23
  AgentArchiveSessionResult,
23
24
  AgentArchiveSessionsResult,
24
25
  AgentCleanArchiveResult,
25
- AgentSessions,
26
- AgentModel,
27
- AgentManagedSession,
28
- AgentSessionActor,
29
- AgentSession,
30
- AgentSessionConstructor,
31
26
  AgentCreateSessionInput,
32
27
  AgentListSessionsInput,
33
- AgentOptions,
34
- RemoteAgentOptions,
35
28
  AgentSessionConfigSnapshot,
36
29
  AgentSessionForkInput,
37
30
  AgentSessionRecordsInput,
@@ -46,10 +39,23 @@ export type {
46
39
  AgentSessionSystemSessionInfo,
47
40
  AgentSessionSystemSnapshot,
48
41
  AgentSessionTimelineEvent,
42
+ } from "./types/agent/SessionTypes.js";
43
+ export type {
44
+ AgentOptions,
45
+ AgentSessionConstructor,
46
+ } from "./types/agent/AgentOptions.js";
47
+ export type {
48
+ AgentSession,
49
+ AgentSessionActor,
50
+ AgentSessions,
51
+ RemoteAgentSession,
52
+ } from "./types/agent/SessionActor.js";
53
+ export type { AgentManagedSession } from "./types/session/SessionOptions.js";
54
+ export type { RemoteAgentOptions } from "./types/agent/RemoteAgentOptions.js";
55
+ export type {
49
56
  RemoteAgentPluginActionInput,
50
57
  RemoteAgentPluginActionResult,
51
- RemoteAgentSession,
52
- } from "./types/agent/AgentTypes.js";
58
+ } from "./types/agent/RemoteAgentPluginAction.js";
53
59
  export type {
54
60
  AgentSessionEvent,
55
61
  AgentSessionSubscriber,
@@ -91,7 +97,10 @@ export type {
91
97
  export { Executor } from "./executor/Executor.js";
92
98
  export {
93
99
  drainDeferredPersistedUserMessages,
100
+ drainInjectedUserMessages,
101
+ getSessionRunContext,
94
102
  getSessionRunScope,
103
+ withSessionRunScope,
95
104
  } from "./executor/SessionRunScope.js";
96
105
  export { JsonlSessionHistoryComposer } from "./executor/composer/history/jsonl/JsonlSessionHistoryComposer.js";
97
106
  export { LocalSessionContextComposer } from "./executor/composer/context/LocalSessionContextComposer.js";
@@ -110,6 +119,27 @@ export type {
110
119
  SessionHistoryPrepareInput,
111
120
  } from "./executor/composer/history/SessionHistoryComposer.js";
112
121
  export type { SessionSystemComposer } from "./executor/composer/system/SessionSystemComposer.js";
122
+ export { DefaultSessionSystemComposer } from "./executor/composer/system/default/DefaultSessionSystemComposer.js";
123
+ export { resolveSessionSystemMessages } from "./executor/composer/system/default/SystemDomain.js";
124
+ export type { SessionHistoryStore } from "./executor/store/history/SessionHistoryStore.js";
125
+ export type { SessionExecutor } from "./executor/types/SessionExecutor.js";
126
+ export type {
127
+ SessionAssistantStepCallback,
128
+ SessionRunResult,
129
+ } from "./executor/types/SessionRun.js";
130
+ export type { SessionRunContext } from "./types/executor/SessionRunContext.js";
131
+ export type {
132
+ SessionActionRecordV1,
133
+ SessionMessageRecordV1,
134
+ SessionMetadataV1,
135
+ SessionRecordV1,
136
+ SessionUserMessageV1,
137
+ } from "./executor/types/SessionRecords.js";
138
+ export {
139
+ is_session_action_record,
140
+ is_session_message_record,
141
+ } from "./executor/types/SessionRecords.js";
142
+ export type { SessionSystemMessage } from "./executor/types/SessionPrompts.js";
113
143
  export type {
114
144
  SessionComposerFactoryContext,
115
145
  SessionComposerInput,
@@ -152,6 +182,18 @@ export {
152
182
  pickLastSuccessfulChatSendText,
153
183
  resolveAssistantMessageForPersistence,
154
184
  } from "./executor/messages/UserVisibleText.js";
185
+ export { extractToolCallsFromUiMessage } from "./executor/messages/UIMessageTransformer.js";
186
+ export {
187
+ buildChatMessageText,
188
+ parseChatMessageMarkup,
189
+ renderChatMessageFileTag,
190
+ } from "./executor/messages/ChatMessageMarkup.js";
191
+ export type {
192
+ ChatMessageFileTag,
193
+ ChatMessageFileType,
194
+ ChatMessageSegment,
195
+ ChatMessageSendOptions,
196
+ } from "./executor/messages/ChatMessageMarkupTypes.js";
155
197
 
156
198
  // 项目与配置集成
157
199
  export {
@@ -160,6 +202,14 @@ export {
160
202
  normalizeDefaultAgentId,
161
203
  } from "./config/AgentInitializer.js";
162
204
  export { loadDowncityConfig } from "./config/Config.js";
205
+ export {
206
+ getDowncityChatHistoryPath,
207
+ getDowncitySessionMessagesPath,
208
+ } from "./config/Paths.js";
209
+ export {
210
+ getPlatformStoreDbPath,
211
+ getPlatformStoreKeyPath,
212
+ } from "./config/PlatformPaths.js";
163
213
  export {
164
214
  ensureRuntimeProjectReady,
165
215
  } from "./agent/local/ProjectSetup.js";
@@ -167,6 +217,11 @@ export { assertProjectExecutionTarget } from "./config/ExecutionBinding.js";
167
217
 
168
218
  // 日志
169
219
  export { getLogger, logger, type Logger } from "./utils/logger/Logger.js";
220
+ export { generateId } from "./utils/Id.js";
221
+ export {
222
+ formatDateTimeInTimezone,
223
+ resolveRuntimeTimezone,
224
+ } from "./utils/Time.js";
170
225
 
171
226
  // 宿主端口类型
172
227
  export type {
@@ -231,7 +286,6 @@ export type {
231
286
 
232
287
  // Plugin 作者与控制面类型
233
288
  export type {
234
- Plugin,
235
289
  PluginAction,
236
290
  PluginActionApi,
237
291
  PluginActionCommand,
@@ -241,27 +295,39 @@ export type {
241
295
  PluginActionMetadata,
242
296
  PluginActionResult,
243
297
  PluginActions,
298
+ PluginActionInvokeParams,
299
+ PluginActionInvokePort,
300
+ PluginActionInvokeResult,
301
+ } from "./types/plugin/PluginAction.js";
302
+ export type { Plugin } from "./types/plugin/PluginDefinition.js";
303
+ export type {
304
+ PluginCommandResult,
305
+ PluginLifecycle,
306
+ } from "./types/plugin/PluginCommand.js";
307
+ export type {
308
+ AgentPlugins,
244
309
  PluginAvailability,
245
310
  PluginConfigDefinition,
246
311
  PluginEffectHook,
247
312
  PluginGuardHook,
248
313
  PluginHooks,
249
- PluginHttpDefinition,
250
314
  PluginPipelineHook,
251
- AgentPlugins,
315
+ PluginResolves,
252
316
  PluginResolveHook,
317
+ PluginView,
318
+ } from "./types/plugin/PluginRuntime.js";
319
+ export type {
320
+ PluginHttpDefinition,
253
321
  PluginHttpRegistration,
254
- PluginActionInvokeParams,
255
- PluginActionInvokePort,
256
- PluginActionInvokeResult,
322
+ } from "./types/plugin/PluginHttp.js";
323
+ export type {
257
324
  PluginSetupDefinition,
258
325
  PluginSetupField,
259
326
  PluginSetupFieldOption,
260
327
  PluginUsageDefinition,
261
328
  PluginUsageField,
262
329
  PluginUsageFieldOption,
263
- PluginView,
264
- } from "./plugin/types/Plugin.js";
330
+ } from "./types/plugin/PluginSetup.js";
265
331
  export type {
266
332
  PluginActionResponse,
267
333
  PluginCatalogResponse,
@@ -270,11 +336,7 @@ export type {
270
336
  } from "./plugin/types/PluginApi.js";
271
337
 
272
338
  // 主动型 plugin 与 CLI/control 协议类型
273
- export type {
274
- PluginCommandResult,
275
- PluginLifecycle,
276
- PluginState,
277
- } from "./plugin/types/Plugin.js";
339
+ export type { PluginState, PluginSnapshot } from "./types/plugin/PluginState.js";
278
340
  export type {
279
341
  ActionScheduleJobRecord,
280
342
  ActionScheduleJobStatus,
@@ -287,13 +349,22 @@ export type {
287
349
  PluginControlAction,
288
350
  PluginControlResponse,
289
351
  PluginStateListResponse,
290
- PluginStateView,
291
- } from "./plugin/types/Plugins.js";
352
+ } from "./types/plugin/PluginControl.js";
353
+ export type { PluginControlResult } from "./types/plugin/PluginState.js";
354
+ export {
355
+ controlPluginState,
356
+ listPluginStates,
357
+ } from "./plugin/core/PluginStateController.js";
358
+ export { runPluginCommand } from "./plugin/core/PluginActionRunner.js";
359
+ export { parsePluginCommandRequestBody } from "./plugin/core/PluginCommandRequest.js";
360
+
361
+ // 跨包 RPC 与 session 标识协议
292
362
  export type {
293
- PluginStateControlAction,
294
- PluginStateControlResult,
295
- PluginStateSnapshot,
296
- } from "./plugin/core/Manager.js";
363
+ RpcEventFrame,
364
+ RpcRequest,
365
+ RpcServerFrame,
366
+ } from "./types/rpc/RpcProtocol.js";
367
+ export { resolveSessionId } from "./executor/ids/resolveSessionId.js";
297
368
 
298
369
  // Platform store 类型
299
370
  export type {
@@ -9,7 +9,7 @@
9
9
 
10
10
  import type { AgentContext } from "@/types/runtime/agent/AgentContext.js";
11
11
  import type { ActionScheduleStore } from "@/plugin/core/ActionScheduleStore.js";
12
- import { runPluginCommand } from "@/plugin/core/Manager.js";
12
+ import { runPluginCommand } from "@/plugin/core/PluginActionRunner.js";
13
13
 
14
14
  /**
15
15
  * 执行当前已到点的 pending 任务。
@@ -8,38 +8,26 @@
8
8
  */
9
9
 
10
10
  import type { AgentContext } from "@/types/runtime/agent/AgentContext.js";
11
+ import type { Plugin } from "@/types/plugin/PluginDefinition.js";
12
+ import type { PluginActions } from "@/types/plugin/PluginAction.js";
13
+ import type { PluginCommandContext, PluginLifecycle } from "@/types/plugin/PluginCommand.js";
11
14
  import type {
12
- Plugin,
13
- PluginActions,
14
15
  PluginAvailability,
15
- PluginCommandContext,
16
16
  PluginConfigDefinition,
17
17
  PluginHooks,
18
- PluginHttpDefinition,
19
- PluginLifecycle,
20
18
  PluginResolves,
19
+ } from "@/types/plugin/PluginRuntime.js";
20
+ import type { PluginHttpDefinition } from "@/types/plugin/PluginHttp.js";
21
+ import type {
21
22
  PluginSetupDefinition,
22
23
  PluginUsageDefinition,
23
- } from "@/plugin/types/Plugin.js";
24
- import type { PluginRuntimeRecord } from "@/types/plugin/PluginState.js";
24
+ } from "@/types/plugin/PluginSetup.js";
25
25
  import type { StructuredConfig } from "@/types/runtime/agent/AgentContext.js";
26
26
 
27
27
  /**
28
28
  * BasePlugin 抽象基类。
29
29
  */
30
30
  export abstract class BasePlugin implements Plugin {
31
- /**
32
- * 当前实例持有的 plugin 注册状态记录。
33
- */
34
- public readonly pluginStateRecord: PluginRuntimeRecord = {
35
- plugin: this,
36
- state: "ready",
37
- registered_at: Date.now(),
38
- updated_at: Date.now(),
39
- chain: Promise.resolve(),
40
- lifecycle_started: false,
41
- };
42
-
43
31
  /**
44
32
  * 当前 plugin 名称。
45
33
  */
@@ -90,9 +78,7 @@ export abstract class BasePlugin implements Plugin {
90
78
  */
91
79
  readonly http?: PluginHttpDefinition;
92
80
 
93
- /**
94
- * 生命周期兼容层。
95
- */
81
+ /** Plugin 生命周期钩子。 */
96
82
  lifecycle?: PluginLifecycle;
97
83
 
98
84
  /**
@@ -12,7 +12,7 @@ import type {
12
12
  PluginGuardHook,
13
13
  PluginPipelineHook,
14
14
  PluginResolveHook,
15
- } from "@/plugin/types/Plugin.js";
15
+ } from "@/types/plugin/PluginRuntime.js";
16
16
  import type { AgentContext } from "@/types/runtime/agent/AgentContext.js";
17
17
 
18
18
  type ContextResolver = () => AgentContext;
@@ -56,8 +56,6 @@ export interface CreatePluginActionOptions<
56
56
  input_schema?: z.ZodTypeAny | PluginActionInputSchema<P>;
57
57
  /** Action 调用示例。 */
58
58
  examples?: PluginActionExample<P>[];
59
- /** disabled 状态下是否仍允许执行。 */
60
- allowWhenDisabled?: boolean;
61
59
  /** CLI 定义。 */
62
60
  command?: PluginActionCommand<P>;
63
61
  /** HTTP 定义。 */
@@ -68,8 +66,6 @@ export interface CreatePluginActionOptions<
68
66
  context: AgentContext;
69
67
  /** 已通过 schema 校验后的输入。 */
70
68
  input: P;
71
- /** 兼容旧命名的 payload。 */
72
- payload: P;
73
69
  /** 当前插件名称。 */
74
70
  pluginName: string;
75
71
  /** 当前 Action 名称。 */
@@ -101,7 +97,7 @@ export interface CreatePluginOptions<TActions extends PluginActions> {
101
97
  resolves?: PluginResolves;
102
98
  /** Plugin system 文本构建器。 */
103
99
  system?: (context: AgentContext) => string | Promise<string>;
104
- /** 旧生命周期兼容定义。 */
100
+ /** Plugin 生命周期定义。 */
105
101
  lifecycle?: PluginLifecycle;
106
102
  /** Plugin 可用性检查。 */
107
103
  availability?: (
@@ -148,9 +144,6 @@ export function createAction(
148
144
  ? { input_schema: normalize_input_schema(options.input_schema) }
149
145
  : {}),
150
146
  ...(options.examples ? { examples: options.examples } : {}),
151
- ...(typeof options.allowWhenDisabled === "boolean"
152
- ? { allowWhenDisabled: options.allowWhenDisabled }
153
- : {}),
154
147
  ...(options.command ? { command: options.command } : {}),
155
148
  ...(options.api ? { api: options.api } : {}),
156
149
  execute: options.execute,
@@ -1,19 +1,16 @@
1
1
  /**
2
- * PluginActionRunner:plugin command/action 兼容执行模块。
2
+ * PluginActionRunner:plugin command/action 执行模块。
3
3
  *
4
4
  * 关键点(中文)
5
5
  * - 新模型中注册即生效,不再要求 plugin 处于 running 状态。
6
- * - `command` 仅作为 CLI/RPC action 的兼容入口;优先执行同名 action。
6
+ * - CLI/RPC command 优先解析为同名 action,再处理 plugin 自定义命令。
7
7
  * - 延迟调度仍复用本模块,保证 schedule 到点后走统一 action 规则。
8
8
  */
9
9
 
10
10
  import type { AgentContext } from "@/types/runtime/agent/AgentContext.js";
11
- import type {
12
- PluginAction,
13
- PluginActionResult,
14
- PluginCommandResult,
15
- PluginStateSnapshot,
16
- } from "@/plugin/types/Plugin.js";
11
+ import type { PluginAction, PluginActionResult } from "@/types/plugin/PluginAction.js";
12
+ import type { PluginCommandResult } from "@/types/plugin/PluginCommand.js";
13
+ import type { PluginSnapshot } from "@/types/plugin/PluginState.js";
17
14
  import type { PluginActionScheduleInput } from "@/plugin/types/ActionSchedule.js";
18
15
  import type { JsonValue } from "@/types/common/Json.js";
19
16
  import { ActionScheduleStore } from "@/plugin/core/ActionScheduleStore.js";
@@ -54,9 +51,9 @@ async function schedulePluginAction(params: {
54
51
  command: string;
55
52
  payload?: JsonValue;
56
53
  schedule: JsonValue | PluginActionScheduleInput;
57
- recordSnapshot: PluginStateSnapshot;
54
+ recordSnapshot: PluginSnapshot;
58
55
  context: AgentContext;
59
- }): Promise<PluginCommandResult & { plugin?: PluginStateSnapshot }> {
56
+ }): Promise<PluginCommandResult & { plugin?: PluginSnapshot }> {
60
57
  try {
61
58
  const scheduleInput = params.schedule as Partial<PluginActionScheduleInput>;
62
59
  const runAtMs = normalizeRunAtMsOrThrow(
@@ -102,7 +99,7 @@ export async function runPluginCommand(params: {
102
99
  payload?: JsonValue;
103
100
  schedule?: JsonValue | PluginActionScheduleInput;
104
101
  context: AgentContext;
105
- }): Promise<PluginCommandResult & { plugin?: PluginStateSnapshot }> {
102
+ }): Promise<PluginCommandResult & { plugin?: PluginSnapshot }> {
106
103
  const pluginName = String(params.pluginName || "").trim();
107
104
  const command = String(params.command || "")
108
105
  .trim()
@@ -7,11 +7,8 @@
7
7
  * - Agent 的视角只有“传入的 plugin”,目录视图和可用性检查都从这些实例推导。
8
8
  */
9
9
 
10
- import type {
11
- Plugin,
12
- PluginAvailability,
13
- PluginView,
14
- } from "@/plugin/types/Plugin.js";
10
+ import type { Plugin } from "@/types/plugin/PluginDefinition.js";
11
+ import type { PluginAvailability, PluginView } from "@/types/plugin/PluginRuntime.js";
15
12
  import type { AgentContext } from "@/types/runtime/agent/AgentContext.js";
16
13
 
17
14
  /**
@@ -9,7 +9,8 @@
9
9
  import path from "node:path";
10
10
  import type { Command } from "commander";
11
11
  import type { JsonObject, JsonValue } from "@/types/common/Json.js";
12
- import type { Plugin, PluginAction } from "@/plugin/types/Plugin.js";
12
+ import type { Plugin } from "@/types/plugin/PluginDefinition.js";
13
+ import type { PluginAction } from "@/types/plugin/PluginAction.js";
13
14
  import { runLocalPluginAction } from "@/plugin/core/PluginLocalExecution.js";
14
15
  import { printResult } from "@/utils/cli/CliOutput.js";
15
16
 
@@ -7,7 +7,7 @@
7
7
  */
8
8
 
9
9
  import type { Hono } from "hono";
10
- import type { Plugin } from "@/plugin/types/Plugin.js";
10
+ import type { Plugin } from "@/types/plugin/PluginDefinition.js";
11
11
  import type { AgentContext } from "@/types/runtime/agent/AgentContext.js";
12
12
  import type { AuthRoutePolicy } from "@/types/runtime/auth/AuthRoute.js";
13
13
 
@@ -17,12 +17,10 @@ import {
17
17
  } from "@/agent/local/AgentRuntimeAssembly.js";
18
18
  import { createFallbackSdkConfig } from "@/agent/local/AgentInstructions.js";
19
19
  import type { JsonValue } from "@/types/common/Json.js";
20
- import type {
21
- Plugin,
22
- PluginActionResult,
23
- PluginAvailability,
24
- PluginCommandContext,
25
- } from "@/plugin/types/Plugin.js";
20
+ import type { Plugin } from "@/types/plugin/PluginDefinition.js";
21
+ import type { PluginActionResult } from "@/types/plugin/PluginAction.js";
22
+ import type { PluginCommandContext } from "@/types/plugin/PluginCommand.js";
23
+ import type { PluginAvailability } from "@/types/plugin/PluginRuntime.js";
26
24
  import type { AgentContext } from "@/types/runtime/agent/AgentContext.js";
27
25
  import type { DowncityConfig } from "@/types/config/DowncityConfig.js";
28
26
 
@@ -155,7 +153,6 @@ export async function runLocalPluginAction(params: {
155
153
  : payload;
156
154
  return await action.execute({
157
155
  context: context as unknown as AgentContext,
158
- payload: input_payload,
159
156
  input: input_payload,
160
157
  pluginName: plugin.name,
161
158
  actionName,
@@ -9,16 +9,16 @@
9
9
 
10
10
  import { toPluginView } from "@/plugin/core/PluginCatalog.js";
11
11
  import type { HookRegistry } from "@/plugin/core/HookRegistry.js";
12
+ import type { Plugin } from "@/types/plugin/PluginDefinition.js";
13
+ import type { PluginActionResult } from "@/types/plugin/PluginAction.js";
12
14
  import type {
13
- Plugin,
14
- PluginActionResult,
15
15
  AgentPlugins,
16
16
  PluginAvailability,
17
17
  PluginActionReadView,
18
18
  PluginReadView,
19
19
  PluginView,
20
- } from "@/plugin/types/Plugin.js";
21
- import type { AgentSessionSystemBlock } from "@/types/agent/AgentTypes.js";
20
+ } from "@/types/plugin/PluginRuntime.js";
21
+ import type { AgentSessionSystemBlock } from "@/types/agent/SessionTypes.js";
22
22
  import type { AgentContext } from "@/types/runtime/agent/AgentContext.js";
23
23
  import type { JsonValue } from "@/types/common/Json.js";
24
24
  import type {
@@ -56,11 +56,9 @@ function to_plugin_snapshot(record: PluginRuntimeRecord): PluginSnapshot {
56
56
  title: String(plugin.title || plugin.name || "").trim(),
57
57
  description: String(plugin.description || "").trim(),
58
58
  status: record.state,
59
- state: record.state,
60
59
  registered_at: record.registered_at,
61
60
  updated_at: record.updated_at,
62
- updatedAt: record.updated_at,
63
- ...(last_error ? { last_error, lastError: last_error } : {}),
61
+ ...(last_error ? { last_error } : {}),
64
62
  };
65
63
  }
66
64
 
@@ -190,7 +188,11 @@ export class PluginRegistry implements AgentPlugins {
190
188
  async startAll(): Promise<PluginSnapshot[]> {
191
189
  const snapshots: PluginSnapshot[] = [];
192
190
  for (const record of this.records.values()) {
193
- await this.start_record(record);
191
+ try {
192
+ await this.start_record(record);
193
+ } catch {
194
+ // 关键点(中文):单个 plugin 启动失败只影响自身,不能阻断其他 plugin 与 Agent ready。
195
+ }
194
196
  snapshots.push(to_plugin_snapshot(record));
195
197
  }
196
198
  return snapshots;
@@ -367,7 +369,6 @@ export class PluginRegistry implements AgentPlugins {
367
369
  ? { input_schema: action.input_schema.json_schema }
368
370
  : {}),
369
371
  ...(action.examples ? { examples: action.examples } : {}),
370
- allow_when_disabled: action.allowWhenDisabled === true,
371
372
  has_command: Boolean(action.command),
372
373
  has_api: Boolean(action.api),
373
374
  };
@@ -517,7 +518,6 @@ export class PluginRegistry implements AgentPlugins {
517
518
  }
518
519
  const result = await action.execute({
519
520
  context: this.contextResolver(),
520
- payload: parsed_payload.input,
521
521
  input: parsed_payload.input,
522
522
  pluginName: record.plugin.name,
523
523
  actionName,
@@ -1,47 +1,35 @@
1
1
  /**
2
- * Plugin 注册状态兼容控制模块。
2
+ * Plugin 注册状态控制模块。
3
3
  *
4
4
  * 关键点(中文)
5
5
  * - 新模型中 plugin 只有注册 / 卸载,不再暴露 start / stop / restart。
6
- * - 该模块保留旧内部函数名,方便 RPC、CLI 与内建 plugin 渐进迁移。
6
+ * - 控制动作与类型协议保持一致,只支持状态查询和卸载。
7
7
  */
8
8
 
9
9
  import type { AgentContext } from "@/types/runtime/agent/AgentContext.js";
10
10
  import type {
11
- PluginStateControlAction,
12
- PluginStateControlResult,
13
- PluginStateSnapshot,
14
- } from "@/plugin/types/Plugin.js";
11
+ PluginControlAction,
12
+ PluginControlResult,
13
+ PluginSnapshot,
14
+ } from "@/types/plugin/PluginState.js";
15
15
 
16
16
  /**
17
17
  * 列出当前 Agent 已注册 plugin 快照。
18
18
  */
19
19
  export function listPluginStates(input?: {
20
20
  context?: AgentContext;
21
- }): PluginStateSnapshot[] {
21
+ }): PluginSnapshot[] {
22
22
  return input?.context?.plugins.snapshots() || [];
23
23
  }
24
24
 
25
25
  /**
26
- * 判断指定 plugin 是否已注册且 ready。
27
- */
28
- export function isPluginRunning(
29
- pluginName: string,
30
- input?: {
31
- context?: AgentContext;
32
- },
33
- ): boolean {
34
- return input?.context?.plugins.status(pluginName)?.status === "ready";
35
- }
36
-
37
- /**
38
- * 执行兼容 plugin 控制动作。
26
+ * 执行 plugin 控制动作。
39
27
  */
40
28
  export async function controlPluginState(params: {
41
29
  pluginName: string;
42
- action: PluginStateControlAction;
30
+ action: PluginControlAction;
43
31
  context: AgentContext;
44
- }): Promise<PluginStateControlResult> {
32
+ }): Promise<PluginControlResult> {
45
33
  const pluginName = String(params.pluginName || "").trim();
46
34
  if (!pluginName) {
47
35
  return {
@@ -51,14 +39,14 @@ export async function controlPluginState(params: {
51
39
  }
52
40
 
53
41
  const action = String(params.action || "").trim().toLowerCase();
54
- if (action === "status" || action === "start" || action === "restart") {
42
+ if (action === "status") {
55
43
  const plugin = params.context.plugins.status(pluginName);
56
44
  return plugin
57
45
  ? { success: true, plugin }
58
46
  : { success: false, error: `Unknown plugin: ${pluginName}` };
59
47
  }
60
48
 
61
- if (action === "unregister" || action === "stop") {
49
+ if (action === "unregister") {
62
50
  const plugin = params.context.plugins.status(pluginName) || undefined;
63
51
  const success = await params.context.plugins.unregister(pluginName);
64
52
  return success
@@ -71,39 +59,3 @@ export async function controlPluginState(params: {
71
59
  error: `Unsupported plugin control action: ${params.action}`,
72
60
  };
73
61
  }
74
-
75
- /**
76
- * 启动当前上下文中全部已挂载 plugin。
77
- */
78
- export async function startAllPlugins(context: AgentContext): Promise<{
79
- success: boolean;
80
- results: PluginStateControlResult[];
81
- }> {
82
- const snapshots = await context.plugins.startAll();
83
- return {
84
- success: snapshots.every((item) => item.status === "ready"),
85
- results: snapshots.map((plugin) => ({
86
- success: plugin.status === "ready",
87
- plugin,
88
- ...(plugin.last_error ? { error: plugin.last_error } : {}),
89
- })),
90
- };
91
- }
92
-
93
- /**
94
- * 卸载当前上下文中全部 plugin。
95
- */
96
- export async function stopAllPlugins(context: AgentContext): Promise<{
97
- success: boolean;
98
- results: PluginStateControlResult[];
99
- }> {
100
- const snapshots = context.plugins.snapshots();
101
- await context.plugins.unregisterAll();
102
- return {
103
- success: true,
104
- results: snapshots.map((plugin) => ({
105
- success: true,
106
- plugin,
107
- })),
108
- };
109
- }