@downcity/agent 1.1.7 → 1.1.8

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 (274) hide show
  1. package/bin/agent/AgentContext.d.ts.map +1 -1
  2. package/bin/agent/AgentContext.js +1 -0
  3. package/bin/agent/AgentContext.js.map +1 -1
  4. package/bin/agent/AgentContextTypes.d.ts +5 -1
  5. package/bin/agent/AgentContextTypes.d.ts.map +1 -1
  6. package/bin/agent/AgentRuntime.d.ts +6 -1
  7. package/bin/agent/AgentRuntime.d.ts.map +1 -1
  8. package/bin/agent/AgentRuntime.js +22 -3
  9. package/bin/agent/AgentRuntime.js.map +1 -1
  10. package/bin/agent/AgentRuntimeState.d.ts.map +1 -1
  11. package/bin/agent/AgentRuntimeState.js +58 -2
  12. package/bin/agent/AgentRuntimeState.js.map +1 -1
  13. package/bin/agent/AgentRuntimeTypes.d.ts +5 -1
  14. package/bin/agent/AgentRuntimeTypes.d.ts.map +1 -1
  15. package/bin/agent/project/AgentInitializer.d.ts +3 -2
  16. package/bin/agent/project/AgentInitializer.d.ts.map +1 -1
  17. package/bin/agent/project/AgentInitializer.js +34 -44
  18. package/bin/agent/project/AgentInitializer.js.map +1 -1
  19. package/bin/config/Config.d.ts.map +1 -1
  20. package/bin/config/Config.js +2 -21
  21. package/bin/config/Config.js.map +1 -1
  22. package/bin/config/Paths.d.ts +1 -5
  23. package/bin/config/Paths.d.ts.map +1 -1
  24. package/bin/config/Paths.js +2 -8
  25. package/bin/config/Paths.js.map +1 -1
  26. package/bin/host/daemon/ProjectSetup.d.ts +2 -1
  27. package/bin/host/daemon/ProjectSetup.d.ts.map +1 -1
  28. package/bin/host/daemon/ProjectSetup.js +14 -21
  29. package/bin/host/daemon/ProjectSetup.js.map +1 -1
  30. package/bin/host/runtime/AgentHostRuntime.d.ts.map +1 -1
  31. package/bin/host/runtime/AgentHostRuntime.js +1 -2
  32. package/bin/host/runtime/AgentHostRuntime.js.map +1 -1
  33. package/bin/host/runtime/CityPaths.d.ts +0 -3
  34. package/bin/host/runtime/CityPaths.d.ts.map +1 -1
  35. package/bin/host/runtime/CityPaths.js +0 -3
  36. package/bin/host/runtime/CityPaths.js.map +1 -1
  37. package/bin/host/sdk/Agent.d.ts +1 -0
  38. package/bin/host/sdk/Agent.d.ts.map +1 -1
  39. package/bin/host/sdk/Agent.js +24 -2
  40. package/bin/host/sdk/Agent.js.map +1 -1
  41. package/bin/host/sdk/AgentSdkTypes.d.ts +9 -0
  42. package/bin/host/sdk/AgentSdkTypes.d.ts.map +1 -1
  43. package/bin/http/Server.d.ts.map +1 -1
  44. package/bin/http/Server.js +1 -11
  45. package/bin/http/Server.js.map +1 -1
  46. package/bin/http/auth/AuthEnv.d.ts +0 -9
  47. package/bin/http/auth/AuthEnv.d.ts.map +1 -1
  48. package/bin/http/auth/AuthEnv.js +0 -9
  49. package/bin/http/auth/AuthEnv.js.map +1 -1
  50. package/bin/http/auth/CliAuthStateStore.d.ts +0 -4
  51. package/bin/http/auth/CliAuthStateStore.d.ts.map +1 -1
  52. package/bin/http/auth/CliAuthStateStore.js +0 -4
  53. package/bin/http/auth/CliAuthStateStore.js.map +1 -1
  54. package/bin/http/control/ModelRoutes.d.ts.map +1 -1
  55. package/bin/http/control/ModelRoutes.js +3 -8
  56. package/bin/http/control/ModelRoutes.js.map +1 -1
  57. package/bin/index.d.ts +2 -6
  58. package/bin/index.d.ts.map +1 -1
  59. package/bin/index.js +2 -6
  60. package/bin/index.js.map +1 -1
  61. package/bin/model/CreateModel.d.ts +2 -2
  62. package/bin/model/CreateModel.d.ts.map +1 -1
  63. package/bin/model/CreateModel.js +13 -12
  64. package/bin/model/CreateModel.js.map +1 -1
  65. package/bin/plugin/Activation.d.ts +4 -0
  66. package/bin/plugin/Activation.d.ts.map +1 -1
  67. package/bin/plugin/Activation.js +2 -2
  68. package/bin/plugin/Activation.js.map +1 -1
  69. package/bin/plugin/LocalExecution.d.ts.map +1 -1
  70. package/bin/plugin/LocalExecution.js +23 -2
  71. package/bin/plugin/LocalExecution.js.map +1 -1
  72. package/bin/plugin/PluginRegistry.js +2 -2
  73. package/bin/plugin/PluginRegistry.js.map +1 -1
  74. package/bin/plugins/asr/Plugin.d.ts.map +1 -1
  75. package/bin/plugins/asr/Plugin.js +4 -5
  76. package/bin/plugins/asr/Plugin.js.map +1 -1
  77. package/bin/plugins/auth/Plugin.d.ts.map +1 -1
  78. package/bin/plugins/auth/Plugin.js +1 -0
  79. package/bin/plugins/auth/Plugin.js.map +1 -1
  80. package/bin/plugins/auth/runtime/AuthorizationConfig.d.ts +4 -4
  81. package/bin/plugins/auth/runtime/AuthorizationConfig.d.ts.map +1 -1
  82. package/bin/plugins/auth/runtime/AuthorizationConfig.js +28 -26
  83. package/bin/plugins/auth/runtime/AuthorizationConfig.js.map +1 -1
  84. package/bin/plugins/auth/runtime/AuthorizationPolicy.d.ts +2 -0
  85. package/bin/plugins/auth/runtime/AuthorizationPolicy.d.ts.map +1 -1
  86. package/bin/plugins/auth/runtime/AuthorizationPolicy.js +3 -2
  87. package/bin/plugins/auth/runtime/AuthorizationPolicy.js.map +1 -1
  88. package/bin/plugins/auth/runtime/AuthorizationStore.d.ts +1 -1
  89. package/bin/plugins/auth/runtime/AuthorizationStore.d.ts.map +1 -1
  90. package/bin/plugins/auth/runtime/AuthorizationStore.js +3 -4
  91. package/bin/plugins/auth/runtime/AuthorizationStore.js.map +1 -1
  92. package/bin/plugins/skill/Plugin.js +2 -2
  93. package/bin/plugins/skill/Plugin.js.map +1 -1
  94. package/bin/plugins/tts/Plugin.d.ts.map +1 -1
  95. package/bin/plugins/tts/Plugin.js +4 -5
  96. package/bin/plugins/tts/Plugin.js.map +1 -1
  97. package/bin/plugins/web/Plugin.d.ts.map +1 -1
  98. package/bin/plugins/web/Plugin.js +4 -5
  99. package/bin/plugins/web/Plugin.js.map +1 -1
  100. package/bin/plugins/workboard/Plugin.js +2 -2
  101. package/bin/plugins/workboard/Plugin.js.map +1 -1
  102. package/bin/service/builtins/chat/accounts/ChannelAccountService.d.ts +4 -1
  103. package/bin/service/builtins/chat/accounts/ChannelAccountService.d.ts.map +1 -1
  104. package/bin/service/builtins/chat/accounts/ChannelAccountService.js +64 -91
  105. package/bin/service/builtins/chat/accounts/ChannelAccountService.js.map +1 -1
  106. package/bin/service/builtins/chat/runtime/ChatChannelActions.d.ts.map +1 -1
  107. package/bin/service/builtins/chat/runtime/ChatChannelActions.js +11 -18
  108. package/bin/service/builtins/chat/runtime/ChatChannelActions.js.map +1 -1
  109. package/bin/service/builtins/chat/runtime/ChatChannelCore.d.ts +1 -1
  110. package/bin/service/builtins/chat/runtime/ChatChannelCore.d.ts.map +1 -1
  111. package/bin/service/builtins/chat/runtime/ChatChannelCore.js +9 -17
  112. package/bin/service/builtins/chat/runtime/ChatChannelCore.js.map +1 -1
  113. package/bin/service/builtins/memory/Action.d.ts +1 -5
  114. package/bin/service/builtins/memory/Action.d.ts.map +1 -1
  115. package/bin/service/builtins/memory/Action.js +4 -42
  116. package/bin/service/builtins/memory/Action.js.map +1 -1
  117. package/bin/service/builtins/memory/MemoryService.d.ts.map +1 -1
  118. package/bin/service/builtins/memory/MemoryService.js +2 -32
  119. package/bin/service/builtins/memory/MemoryService.js.map +1 -1
  120. package/bin/service/builtins/memory/runtime/Search.d.ts +7 -3
  121. package/bin/service/builtins/memory/runtime/Search.d.ts.map +1 -1
  122. package/bin/service/builtins/memory/runtime/Search.js +220 -16
  123. package/bin/service/builtins/memory/runtime/Search.js.map +1 -1
  124. package/bin/service/builtins/memory/runtime/Store.d.ts +9 -50
  125. package/bin/service/builtins/memory/runtime/Store.d.ts.map +1 -1
  126. package/bin/service/builtins/memory/runtime/Store.js +10 -130
  127. package/bin/service/builtins/memory/runtime/Store.js.map +1 -1
  128. package/bin/service/builtins/memory/runtime/Writer.d.ts.map +1 -1
  129. package/bin/service/builtins/memory/runtime/Writer.js +1 -2
  130. package/bin/service/builtins/memory/runtime/Writer.js.map +1 -1
  131. package/bin/service/builtins/memory/types/Memory.d.ts +3 -57
  132. package/bin/service/builtins/memory/types/Memory.d.ts.map +1 -1
  133. package/bin/service/schedule/Store.d.ts +22 -25
  134. package/bin/service/schedule/Store.d.ts.map +1 -1
  135. package/bin/service/schedule/Store.js +172 -154
  136. package/bin/service/schedule/Store.js.map +1 -1
  137. package/bin/session/composer/system/default/SystemDomain.d.ts.map +1 -1
  138. package/bin/session/composer/system/default/SystemDomain.js +1 -0
  139. package/bin/session/composer/system/default/SystemDomain.js.map +1 -1
  140. package/bin/shared/types/AgentHost.d.ts +120 -4
  141. package/bin/shared/types/AgentHost.d.ts.map +1 -1
  142. package/bin/shared/types/Plugin.d.ts +5 -1
  143. package/bin/shared/types/Plugin.d.ts.map +1 -1
  144. package/package.json +1 -4
  145. package/src/agent/AgentContext.ts +1 -0
  146. package/src/agent/AgentContextTypes.ts +5 -0
  147. package/src/agent/AgentRuntime.ts +32 -3
  148. package/src/agent/AgentRuntimeState.ts +66 -2
  149. package/src/agent/AgentRuntimeTypes.ts +5 -0
  150. package/src/agent/project/AgentInitializer.ts +40 -42
  151. package/src/config/Config.ts +2 -17
  152. package/src/config/Paths.ts +2 -9
  153. package/src/host/daemon/ProjectSetup.ts +19 -21
  154. package/src/host/runtime/AgentHostRuntime.ts +0 -2
  155. package/src/host/runtime/CityPaths.ts +0 -3
  156. package/src/host/sdk/Agent.ts +26 -2
  157. package/src/host/sdk/AgentSdkTypes.ts +10 -0
  158. package/src/http/Server.ts +0 -13
  159. package/src/http/auth/AuthEnv.ts +0 -9
  160. package/src/http/auth/CliAuthStateStore.ts +0 -4
  161. package/src/http/control/ModelRoutes.ts +3 -9
  162. package/src/index.ts +2 -12
  163. package/src/model/CreateModel.ts +15 -13
  164. package/src/plugin/Activation.ts +6 -2
  165. package/src/plugin/LocalExecution.ts +24 -2
  166. package/src/plugin/PluginRegistry.ts +2 -2
  167. package/src/plugins/asr/Plugin.ts +4 -5
  168. package/src/plugins/auth/Plugin.ts +1 -0
  169. package/src/plugins/auth/runtime/AuthorizationConfig.ts +47 -37
  170. package/src/plugins/auth/runtime/AuthorizationPolicy.ts +5 -2
  171. package/src/plugins/auth/runtime/AuthorizationStore.ts +6 -5
  172. package/src/plugins/skill/Plugin.ts +2 -2
  173. package/src/plugins/tts/Plugin.ts +4 -5
  174. package/src/plugins/web/Plugin.ts +4 -5
  175. package/src/plugins/workboard/Plugin.ts +2 -2
  176. package/src/service/builtins/chat/accounts/ChannelAccountService.ts +42 -62
  177. package/src/service/builtins/chat/runtime/ChatChannelActions.ts +12 -18
  178. package/src/service/builtins/chat/runtime/ChatChannelCore.ts +9 -14
  179. package/src/service/builtins/memory/Action.ts +6 -47
  180. package/src/service/builtins/memory/MemoryService.ts +1 -33
  181. package/src/service/builtins/memory/runtime/Search.ts +256 -16
  182. package/src/service/builtins/memory/runtime/Store.ts +13 -185
  183. package/src/service/builtins/memory/runtime/Writer.ts +1 -2
  184. package/src/service/builtins/memory/types/Memory.ts +2 -59
  185. package/src/service/schedule/Store.ts +215 -175
  186. package/src/session/composer/system/default/SystemDomain.ts +1 -0
  187. package/src/shared/types/AgentHost.ts +138 -4
  188. package/src/shared/types/Plugin.ts +5 -0
  189. package/tsconfig.tsbuildinfo +1 -1
  190. package/bin/http/auth/AuthMiddleware.d.ts +0 -36
  191. package/bin/http/auth/AuthMiddleware.d.ts.map +0 -1
  192. package/bin/http/auth/AuthMiddleware.js +0 -37
  193. package/bin/http/auth/AuthMiddleware.js.map +0 -1
  194. package/bin/http/auth/AuthRoutes.d.ts +0 -17
  195. package/bin/http/auth/AuthRoutes.d.ts.map +0 -1
  196. package/bin/http/auth/AuthRoutes.js +0 -78
  197. package/bin/http/auth/AuthRoutes.js.map +0 -1
  198. package/bin/http/auth/AuthService.d.ts +0 -119
  199. package/bin/http/auth/AuthService.d.ts.map +0 -1
  200. package/bin/http/auth/AuthService.js +0 -307
  201. package/bin/http/auth/AuthService.js.map +0 -1
  202. package/bin/http/auth/AuthStore.d.ts +0 -165
  203. package/bin/http/auth/AuthStore.d.ts.map +0 -1
  204. package/bin/http/auth/AuthStore.js +0 -442
  205. package/bin/http/auth/AuthStore.js.map +0 -1
  206. package/bin/http/auth/RoutePolicy.d.ts +0 -30
  207. package/bin/http/auth/RoutePolicy.d.ts.map +0 -1
  208. package/bin/http/auth/RoutePolicy.js +0 -229
  209. package/bin/http/auth/RoutePolicy.js.map +0 -1
  210. package/bin/plugin/Lifecycle.d.ts +0 -33
  211. package/bin/plugin/Lifecycle.d.ts.map +0 -1
  212. package/bin/plugin/Lifecycle.js +0 -102
  213. package/bin/plugin/Lifecycle.js.map +0 -1
  214. package/bin/service/builtins/memory/runtime/Indexer.d.ts +0 -71
  215. package/bin/service/builtins/memory/runtime/Indexer.d.ts.map +0 -1
  216. package/bin/service/builtins/memory/runtime/Indexer.js +0 -345
  217. package/bin/service/builtins/memory/runtime/Indexer.js.map +0 -1
  218. package/bin/service/schedule/Schema.d.ts +0 -171
  219. package/bin/service/schedule/Schema.d.ts.map +0 -1
  220. package/bin/service/schedule/Schema.js +0 -26
  221. package/bin/service/schedule/Schema.js.map +0 -1
  222. package/bin/shared/utils/store/StoreChannelAccountRepository.d.ts +0 -34
  223. package/bin/shared/utils/store/StoreChannelAccountRepository.d.ts.map +0 -1
  224. package/bin/shared/utils/store/StoreChannelAccountRepository.js +0 -198
  225. package/bin/shared/utils/store/StoreChannelAccountRepository.js.map +0 -1
  226. package/bin/shared/utils/store/StoreEnvRepository.d.ts +0 -98
  227. package/bin/shared/utils/store/StoreEnvRepository.d.ts.map +0 -1
  228. package/bin/shared/utils/store/StoreEnvRepository.js +0 -334
  229. package/bin/shared/utils/store/StoreEnvRepository.js.map +0 -1
  230. package/bin/shared/utils/store/StoreModelRepository.d.ts +0 -61
  231. package/bin/shared/utils/store/StoreModelRepository.d.ts.map +0 -1
  232. package/bin/shared/utils/store/StoreModelRepository.js +0 -278
  233. package/bin/shared/utils/store/StoreModelRepository.js.map +0 -1
  234. package/bin/shared/utils/store/StoreSchema.d.ts +0 -13
  235. package/bin/shared/utils/store/StoreSchema.d.ts.map +0 -1
  236. package/bin/shared/utils/store/StoreSchema.js +0 -319
  237. package/bin/shared/utils/store/StoreSchema.js.map +0 -1
  238. package/bin/shared/utils/store/StoreSecureSettings.d.ts +0 -33
  239. package/bin/shared/utils/store/StoreSecureSettings.d.ts.map +0 -1
  240. package/bin/shared/utils/store/StoreSecureSettings.js +0 -91
  241. package/bin/shared/utils/store/StoreSecureSettings.js.map +0 -1
  242. package/bin/shared/utils/store/StoreShared.d.ts +0 -44
  243. package/bin/shared/utils/store/StoreShared.d.ts.map +0 -1
  244. package/bin/shared/utils/store/StoreShared.js +0 -40
  245. package/bin/shared/utils/store/StoreShared.js.map +0 -1
  246. package/bin/shared/utils/store/crypto.d.ts +0 -24
  247. package/bin/shared/utils/store/crypto.d.ts.map +0 -1
  248. package/bin/shared/utils/store/crypto.js +0 -101
  249. package/bin/shared/utils/store/crypto.js.map +0 -1
  250. package/bin/shared/utils/store/index.d.ts +0 -230
  251. package/bin/shared/utils/store/index.d.ts.map +0 -1
  252. package/bin/shared/utils/store/index.js +0 -360
  253. package/bin/shared/utils/store/index.js.map +0 -1
  254. package/bin/shared/utils/store/schema.d.ts +0 -690
  255. package/bin/shared/utils/store/schema.d.ts.map +0 -1
  256. package/bin/shared/utils/store/schema.js +0 -81
  257. package/bin/shared/utils/store/schema.js.map +0 -1
  258. package/src/http/auth/AuthMiddleware.ts +0 -61
  259. package/src/http/auth/AuthRoutes.ts +0 -100
  260. package/src/http/auth/AuthService.ts +0 -367
  261. package/src/http/auth/AuthStore.ts +0 -572
  262. package/src/http/auth/RoutePolicy.ts +0 -255
  263. package/src/plugin/Lifecycle.ts +0 -116
  264. package/src/service/builtins/memory/runtime/Indexer.ts +0 -466
  265. package/src/service/schedule/Schema.ts +0 -34
  266. package/src/shared/utils/store/StoreChannelAccountRepository.ts +0 -269
  267. package/src/shared/utils/store/StoreEnvRepository.ts +0 -452
  268. package/src/shared/utils/store/StoreModelRepository.ts +0 -324
  269. package/src/shared/utils/store/StoreSchema.ts +0 -344
  270. package/src/shared/utils/store/StoreSecureSettings.ts +0 -126
  271. package/src/shared/utils/store/StoreShared.ts +0 -67
  272. package/src/shared/utils/store/crypto.ts +0 -112
  273. package/src/shared/utils/store/index.ts +0 -497
  274. package/src/shared/utils/store/schema.ts +0 -103
@@ -16,6 +16,7 @@ import type { AgentContext } from "@/agent/AgentContextTypes.js";
16
16
  import type { AgentRuntime } from "@/agent/AgentRuntimeTypes.js";
17
17
  import type { DowncityConfig } from "@/shared/types/DowncityConfig.js";
18
18
  import type { JsonValue } from "@/shared/types/Json.js";
19
+ import type { AgentPlatformRuntime } from "@/shared/types/AgentHost.js";
19
20
  import type {
20
21
  Plugin,
21
22
  PluginAvailability,
@@ -43,6 +44,25 @@ import { HookRegistry } from "@/plugin/HookRegistry.js";
43
44
  import { PluginRegistry } from "@/plugin/PluginRegistry.js";
44
45
  import { isPluginEnabled } from "@/plugin/Activation.js";
45
46
 
47
+ const EMPTY_SDK_PLATFORM: AgentPlatformRuntime = {
48
+ getGlobalEnv: () => ({}),
49
+ getAgentEnv: () => ({}),
50
+ listModels: () => [],
51
+ listProviders: async () => [],
52
+ getModel: () => null,
53
+ getChannelAccount: () => null,
54
+ readChatAuthorizationConfig: () => ({
55
+ roles: {},
56
+ channels: {},
57
+ }),
58
+ writeChatAuthorizationConfig: async (_projectRoot, nextConfig) => nextConfig,
59
+ setChatAuthorizationUserRole: async () => ({
60
+ roles: {},
61
+ channels: {},
62
+ }),
63
+ isPluginEnabled: (pluginName) => pluginName === "auth",
64
+ };
65
+
46
66
  function createFallbackSdkConfig(agentId: string): DowncityConfig {
47
67
  return {
48
68
  name: agentId,
@@ -69,6 +89,7 @@ export class Agent {
69
89
  private readonly pluginRegistry: PluginRegistry;
70
90
  private readonly pluginSystemProviders: Plugin[];
71
91
  private readonly config: DowncityConfig;
92
+ private readonly platform: AgentPlatformRuntime;
72
93
  private systems: string[];
73
94
  private servicesStartPromise: Promise<void> | null = null;
74
95
 
@@ -87,6 +108,7 @@ export class Agent {
87
108
 
88
109
  this.logger = new Logger();
89
110
  this.logger.bindProjectRoot(this.path);
111
+ this.platform = options.platform || EMPTY_SDK_PLATFORM;
90
112
  this.systems = loadStaticSystemPrompts(this.path);
91
113
  this.config = this.loadConfig();
92
114
  this.services = this.createServiceMap(options.services || []);
@@ -193,7 +215,7 @@ export class Agent {
193
215
  contextResolver: () => this.serviceContext,
194
216
  pluginEnabledChecker: (pluginName) => {
195
217
  const plugin = pluginRegistryRef?.get(pluginName);
196
- return plugin ? isPluginEnabled({ plugin }) : false;
218
+ return plugin ? isPluginEnabled({ plugin, context: this.serviceContext }) : false;
197
219
  },
198
220
  });
199
221
  const registry = new PluginRegistry({
@@ -235,7 +257,7 @@ export class Agent {
235
257
  for (const plugin of this.pluginSystemProviders) {
236
258
  if (typeof plugin.system !== "function") continue;
237
259
  try {
238
- if (!isPluginEnabled({ plugin })) continue;
260
+ if (!isPluginEnabled({ plugin, context: this.serviceContext })) continue;
239
261
  if (typeof plugin.availability === "function") {
240
262
  const availability = await plugin.availability(this.serviceContext);
241
263
  if (!availability.available) continue;
@@ -276,6 +298,7 @@ export class Agent {
276
298
  systems: this.systems,
277
299
  paths: createAgentPathRuntime(this.path),
278
300
  pluginConfig: createAgentPluginConfigRuntime(this.path),
301
+ platform: this.platform,
279
302
  model: undefined,
280
303
  getSession: (sessionId: string) => {
281
304
  return this.getOrCreateSession(sessionId).getServicePort() as never;
@@ -306,6 +329,7 @@ export class Agent {
306
329
  systems: this.systems,
307
330
  paths: this.runtime.paths,
308
331
  pluginConfig: this.runtime.pluginConfig,
332
+ platform: this.platform,
309
333
  session: {
310
334
  get: (sessionId) => this.getOrCreateSession(sessionId).getServicePort(),
311
335
  listExecutingSessionIds: () => this.runtime.listExecutingSessionIds(),
@@ -12,6 +12,7 @@ import type { BaseService } from "@/service/builtins/BaseService.js";
12
12
  import type { JsonValue } from "@/shared/types/Json.js";
13
13
  import type { Plugin } from "@/shared/types/Plugin.js";
14
14
  import type { SessionMessageV1 } from "@/types/session/SessionMessages.js";
15
+ import type { AgentPlatformRuntime } from "@/shared/types/AgentHost.js";
15
16
 
16
17
  /**
17
18
  * 本地 Agent 构造参数。
@@ -59,6 +60,15 @@ export interface AgentOptions {
59
60
  * - 同名 plugin 会直接报错,避免 action / hook / resolve 行为被静默覆盖。
60
61
  */
61
62
  plugins?: Plugin[];
63
+
64
+ /**
65
+ * 当前 agent 显式注入的平台能力集合。
66
+ *
67
+ * 关键点(中文)
68
+ * - SDK 侧若不提供,则使用最小空实现。
69
+ * - 推荐由宿主产品显式传入,避免 SDK 本地实例隐式依赖 city。
70
+ */
71
+ platform?: AgentPlatformRuntime;
62
72
  }
63
73
 
64
74
  /**
@@ -21,12 +21,6 @@ import {
21
21
  import { pluginsRouter } from "@/http/plugins/plugins.js";
22
22
  import { staticRouter } from "@/http/static/static.js";
23
23
  import { controlRouter } from "@/http/control/ControlRouter.js";
24
- import { registerAuthRoutes } from "@/http/auth/AuthRoutes.js";
25
- import { AuthService } from "@/http/auth/AuthService.js";
26
- import {
27
- createRouteAuthGuardMiddleware,
28
- SERVER_AUTH_ROUTE_POLICIES,
29
- } from "@/http/auth/RoutePolicy.js";
30
24
  import {
31
25
  listBuiltinPluginRuntimeAuthPolicies,
32
26
  registerBuiltinPluginHttpRoutes,
@@ -60,11 +54,6 @@ export interface ServerInstance {
60
54
  */
61
55
  export function createServerApp(): Hono {
62
56
  const app = new Hono();
63
- const authService = new AuthService();
64
- const authPolicies = [
65
- ...SERVER_AUTH_ROUTE_POLICIES,
66
- ...listBuiltinPluginRuntimeAuthPolicies(),
67
- ];
68
57
 
69
58
  app.use("*", logger());
70
59
  app.use(
@@ -75,7 +64,6 @@ export function createServerApp(): Hono {
75
64
  allowHeaders: ["Content-Type", "Authorization"],
76
65
  }),
77
66
  );
78
- app.use("*", createRouteAuthGuardMiddleware(authService, authPolicies));
79
67
 
80
68
  // 关键点(中文):service action 路由在 runtime ready 后再注册,避免命令级 import 副作用。
81
69
  ensureServiceActionRoutesRegistered();
@@ -91,7 +79,6 @@ export function createServerApp(): Hono {
91
79
  app,
92
80
  getContext: getAgentContext,
93
81
  });
94
- registerAuthRoutes({ app, authService });
95
82
 
96
83
  return app;
97
84
  }
@@ -28,11 +28,6 @@ export function normalizeBearerToken(value: unknown): string | null {
28
28
 
29
29
  /**
30
30
  * 解析本次调用应使用的 token。
31
- *
32
- * 优先级(中文)
33
- * 1. 显式传入 token
34
- * 2. 用户显式覆盖环境变量 `DC_AUTH_TOKEN`
35
- * 3. 调用方传入的本地存储 token
36
31
  */
37
32
  export function resolveInvocationToken(params: {
38
33
  explicitToken?: string;
@@ -52,10 +47,6 @@ export function resolveInvocationToken(params: {
52
47
 
53
48
  /**
54
49
  * 从通用子进程环境中剥离 Bearer Token。
55
- *
56
- * 关键点(中文)
57
- * - shell / task script / ACP 等通用执行面不应默认继承任何 HTTP 鉴权信息。
58
- * - 这样可以强制这些链路优先走 RPC,而不是通过环境变量隐式改走本地 HTTP。
59
50
  */
60
51
  export function stripInvocationAuthEnv(targetEnv: NodeJS.ProcessEnv): void {
61
52
  delete targetEnv[CLI_AUTH_TOKEN_ENV_KEY];
@@ -24,10 +24,6 @@ export interface CliAuthStateStoreOptions {
24
24
 
25
25
  /**
26
26
  * 解析当前 CLI 应使用的 Bearer Token。
27
- *
28
- * 优先级(中文)
29
- * 1. 显式传入 token
30
- * 2. 环境变量 `DC_AUTH_TOKEN`
31
27
  */
32
28
  export function resolveCliAuthToken(params: {
33
29
  explicitToken?: string;
@@ -8,7 +8,6 @@
8
8
 
9
9
  import fs from "fs-extra";
10
10
  import { getDowncityJsonPath } from "@/config/Paths.js";
11
- import { PlatformStore } from "@shared/utils/store/index.js";
12
11
  import type { ControlRouteRegistrationParams } from "@/shared/types/ControlRoutes.js";
13
12
  import { buildControlRouteAliases } from "@/http/control/CommonHelpers.js";
14
13
 
@@ -25,9 +24,8 @@ export function registerControlModelRoutes(
25
24
  try {
26
25
  const agentState = params.getAgentRuntime();
27
26
  const agentPrimaryModelId = String(agentState.config.execution?.type === "api" ? agentState.config.execution.modelId || "" : "").trim();
28
- const store = new PlatformStore();
29
- const models = store.listModels();
30
- const providers = await store.listProviders();
27
+ const models = agentState.platform.listModels();
28
+ const providers = await agentState.platform.listProviders();
31
29
  const providerMap = new Map(providers.map((x) => [x.id, x] as const));
32
30
  const activeModel = agentPrimaryModelId
33
31
  ? models.find((x) => x.id === agentPrimaryModelId)
@@ -43,8 +41,6 @@ export function registerControlModelRoutes(
43
41
  providerType: String(providerConfig?.type || "").trim(),
44
42
  };
45
43
  });
46
- store.close();
47
-
48
44
  return c.json({
49
45
  success: true,
50
46
  model: {
@@ -74,9 +70,7 @@ export function registerControlModelRoutes(
74
70
  if (!nextPrimaryModelId) {
75
71
  return c.json({ success: false, error: "Missing primaryModelId" }, 400);
76
72
  }
77
- const store = new PlatformStore();
78
- const targetModel = store.getModel(nextPrimaryModelId);
79
- store.close();
73
+ const targetModel = agentState.platform.getModel(nextPrimaryModelId);
80
74
  if (!targetModel) {
81
75
  return c.json(
82
76
  { success: false, error: `Model not found: ${nextPrimaryModelId}` },
package/src/index.ts CHANGED
@@ -108,9 +108,8 @@ export {
108
108
  startServiceScheduleRuntime,
109
109
  stopServiceScheduleRuntime,
110
110
  } from './service/schedule/Runtime.js';
111
- export { runDueScheduledJobs } from "./service/schedule/Executor.js";
112
111
  export { ServiceScheduleStore } from "./service/schedule/Store.js";
113
- export { scheduledJobsTable } from "./service/schedule/Schema.js";
112
+ export { runDueScheduledJobs } from "./service/schedule/Executor.js";
114
113
  export {
115
114
  normalizeRunAtMsOrThrow,
116
115
  parseScheduledRunAtMsOrThrow,
@@ -121,15 +120,6 @@ export {
121
120
  resolveAssistantMessageForPersistence,
122
121
  } from "./service/builtins/chat/runtime/UserVisibleText.js";
123
122
  export { logger, getLogger, type Logger } from "./shared/utils/logger/Logger.js";
124
- export { PlatformStore, withPlatformStore } from "./shared/utils/store/index.js";
125
- export { ensurePlatformStoreSchema } from "./shared/utils/store/StoreSchema.js";
126
- export {
127
- nowIso,
128
- normalizeNonEmptyText,
129
- optionalTrimmedText,
130
- type PlatformDrizzleDb,
131
- type PlatformStoreContext,
132
- } from "./shared/utils/store/StoreShared.js";
133
123
 
134
124
  // 共享协议类型与控制面常量
135
125
  export * from "./shared/types/AgentHost.js";
@@ -157,6 +147,7 @@ export * from "./shared/types/ServiceSchedule.js";
157
147
  export * from "./shared/types/Services.js";
158
148
  export * from "./shared/types/Start.js";
159
149
  export * from "./shared/types/Store.js";
150
+ export * from "./shared/types/PluginLifecycle.js";
160
151
  export * from "./shared/types/auth/AuthPermission.js";
161
152
  export * from "./shared/types/auth/AuthRoute.js";
162
153
  export * from "./shared/types/auth/AuthToken.js";
@@ -209,7 +200,6 @@ export {
209
200
  listStaticPluginViews,
210
201
  toStaticPluginView,
211
202
  } from "./plugin/Catalog.js";
212
- export { setCityPluginEnabled, isCityPluginEnabled } from "./plugin/Lifecycle.js";
213
203
  export { runLocalPluginAction, listLocalPlugins, getLocalPluginAvailability } from "./plugin/LocalExecution.js";
214
204
  export { registerAllPluginsForCli } from "./plugin/PluginCommand.js";
215
205
  export { listBuiltinPluginRuntimeAuthPolicies } from "./plugin/HttpRoutes.js";
@@ -21,8 +21,8 @@ import { createLlmLoggingFetch } from "@shared/utils/logger/Fetch.js";
21
21
  import { getLogger } from "@shared/utils/logger/Logger.js";
22
22
  import type { DowncityConfig } from "@/shared/types/DowncityConfig.js";
23
23
  import type { LlmProviderType } from "@/shared/types/LlmConfig.js";
24
- import { PlatformStore } from "@shared/utils/store/index.js";
25
24
  import { readProjectExecutionBinding } from "@/agent/project/ProjectExecutionBinding.js";
25
+ import type { AgentPlatformRuntime } from "@/shared/types/AgentHost.js";
26
26
 
27
27
  type ModelLogContext = {
28
28
  sessionId?: string;
@@ -149,7 +149,7 @@ function normalizeProviderType(value: unknown): LlmProviderType | null {
149
149
  export async function createModel(input: {
150
150
  config: DowncityConfig;
151
151
  getSessionRunScope?: () => ModelLogContext | undefined;
152
- store?: PlatformStore;
152
+ platform?: AgentPlatformRuntime;
153
153
  projectRoot?: string;
154
154
  }): Promise<LanguageModel> {
155
155
  const logger = getLogger();
@@ -174,21 +174,23 @@ export async function createModel(input: {
174
174
 
175
175
  const primaryModelId = execution.modelId;
176
176
 
177
- const store = input.store || new PlatformStore();
178
- const resolved = await store.getResolvedModel(primaryModelId);
179
- if (!input.store) {
180
- store.close();
177
+ const platform = input.platform;
178
+ const modelConfig = platform?.getModel(primaryModelId) || null;
179
+ const providerConfigs = await (platform?.listProviders?.() || Promise.resolve([]));
180
+ const providerMap = new Map(providerConfigs.map((item) => [item.id, item] as const));
181
+ const providerConfig = modelConfig
182
+ ? providerMap.get(String(modelConfig.providerId || "").trim()) || null
183
+ : null;
184
+ if (!modelConfig || !providerConfig) {
185
+ await logger.log("warn", `LLM model config not found in platform runtime: ${primaryModelId}`);
186
+ throw Error(`LLM model config not found in platform runtime: ${primaryModelId}`);
181
187
  }
182
- if (!resolved) {
183
- await logger.log("warn", `LLM model config not found in sqlite store: ${primaryModelId}`);
184
- throw Error(`LLM model config not found in sqlite store: ${primaryModelId}`);
185
- }
186
- const selectedModelConfig = resolved.model;
187
- const selectedProviderConfig = resolved.provider;
188
+ const selectedModelConfig = modelConfig;
189
+ const selectedProviderConfig = providerConfig;
188
190
  if (selectedModelConfig.isPaused === true) {
189
191
  await logger.log(
190
192
  "warn",
191
- `LLM model is paused in sqlite store: ${primaryModelId}`,
193
+ `LLM model is paused in platform runtime: ${primaryModelId}`,
192
194
  );
193
195
  throw Error(`LLM model is paused: ${primaryModelId}`);
194
196
  }
@@ -7,16 +7,20 @@
7
7
  */
8
8
 
9
9
  import type { Plugin } from "@/shared/types/Plugin.js";
10
- import { isCityPluginEnabled } from "@/plugin/Lifecycle.js";
10
+ import type { AgentContext } from "@/agent/AgentContextTypes.js";
11
+ import type { AgentRuntimeBase } from "@/agent/AgentRuntimeTypes.js";
11
12
 
12
13
  /**
13
14
  * 读取当前 city 配置下的 plugin 启用态。
14
15
  */
15
16
  export function isPluginEnabled(params: {
16
17
  plugin: Plugin;
18
+ context?: Pick<AgentContext, "platform">;
19
+ runtime?: Pick<AgentRuntimeBase, "platform">;
17
20
  }): boolean {
18
21
  const pluginName = String(params.plugin.name || "").trim();
19
22
  if (!pluginName) return false;
20
23
  if (pluginName === "auth") return true;
21
- return isCityPluginEnabled(pluginName);
24
+ const platform = params.context?.platform || params.runtime?.platform;
25
+ return platform ? platform.isPluginEnabled(pluginName) : true;
22
26
  }
@@ -16,6 +16,7 @@ import {
16
16
  createAgentPathRuntime,
17
17
  createAgentPluginConfigRuntime,
18
18
  } from "@/host/runtime/AgentHostRuntime.js";
19
+ import { getAgentRuntimeBase } from "@/agent/AgentRuntimeState.js";
19
20
  import type { JsonValue } from "@/shared/types/Json.js";
20
21
  import type {
21
22
  PluginActionResult,
@@ -38,6 +39,26 @@ export function createLocalPluginCommandContext(projectRoot: string): PluginComm
38
39
 
39
40
  defaultLogger.bindProjectRoot(rootPath);
40
41
 
42
+ const platform = (() => {
43
+ try {
44
+ return getAgentRuntimeBase().platform;
45
+ } catch {
46
+ return {
47
+ getGlobalEnv: () => ({}),
48
+ getAgentEnv: () => ({}),
49
+ listModels: () => [],
50
+ listProviders: async () => [],
51
+ getModel: () => null,
52
+ getChannelAccount: () => null,
53
+ readChatAuthorizationConfig: () => ({ roles: {}, channels: {} }),
54
+ writeChatAuthorizationConfig: async (_projectRoot: string, nextConfig: unknown) =>
55
+ nextConfig as never,
56
+ setChatAuthorizationUserRole: async () => ({ roles: {}, channels: {} }),
57
+ isPluginEnabled: (pluginName: string) => pluginName === "auth",
58
+ };
59
+ }
60
+ })();
61
+
41
62
  return {
42
63
  cwd: rootPath,
43
64
  rootPath,
@@ -47,6 +68,7 @@ export function createLocalPluginCommandContext(projectRoot: string): PluginComm
47
68
  globalEnv,
48
69
  paths: createAgentPathRuntime(rootPath),
49
70
  pluginConfig: createAgentPluginConfigRuntime(rootPath),
71
+ platform,
50
72
  };
51
73
  }
52
74
 
@@ -78,7 +100,7 @@ export async function getLocalPluginAvailability(
78
100
  return await plugin.availability(context);
79
101
  }
80
102
 
81
- const enabled = isPluginEnabled({ plugin });
103
+ const enabled = isPluginEnabled({ plugin, context });
82
104
  if (!enabled) {
83
105
  return {
84
106
  enabled: false,
@@ -131,7 +153,7 @@ export async function runLocalPluginAction(params: {
131
153
  }
132
154
 
133
155
  const context = createLocalPluginCommandContext(params.projectRoot);
134
- const enabled = isPluginEnabled({ plugin });
156
+ const enabled = isPluginEnabled({ plugin, context });
135
157
  if (!enabled && action.allowWhenDisabled !== true) {
136
158
  return {
137
159
  success: false,
@@ -165,7 +165,7 @@ export class PluginRegistry {
165
165
  }
166
166
 
167
167
  const context = this.contextResolver();
168
- const enabled = isPluginEnabled({ plugin });
168
+ const enabled = isPluginEnabled({ plugin, context });
169
169
 
170
170
  if (!enabled) {
171
171
  return {
@@ -217,7 +217,7 @@ export class PluginRegistry {
217
217
  }
218
218
 
219
219
  const context = this.contextResolver();
220
- const enabled = isPluginEnabled({ plugin });
220
+ const enabled = isPluginEnabled({ plugin, context });
221
221
  if (!enabled && action.allowWhenDisabled !== true) {
222
222
  return {
223
223
  success: false,
@@ -14,7 +14,6 @@ import type { JsonObject, JsonValue } from "@/shared/types/Json.js";
14
14
  import type { AgentPluginConfigRuntime } from "@/shared/types/AgentHost.js";
15
15
  import { CHAT_PLUGIN_POINTS } from "@/service/builtins/chat/runtime/PluginPoints.js";
16
16
  import { isPluginEnabled } from "@/plugin/Activation.js";
17
- import { setCityPluginEnabled } from "@/plugin/Lifecycle.js";
18
17
  import {
19
18
  listVoiceModels,
20
19
  resolveVoicePluginModelId,
@@ -228,7 +227,7 @@ export const asrPlugin: Plugin = {
228
227
  statusAction: "status",
229
228
  },
230
229
  async availability(context) {
231
- if (!isPluginEnabled({ plugin: asrPlugin })) {
230
+ if (!isPluginEnabled({ plugin: asrPlugin, context })) {
232
231
  return {
233
232
  enabled: false,
234
233
  available: false,
@@ -432,7 +431,7 @@ export const asrPlugin: Plugin = {
432
431
  },
433
432
  },
434
433
  execute: async ({ context, payload }) => {
435
- setCityPluginEnabled("asr", true);
434
+ context.platform.setPluginEnabled?.("asr", true);
436
435
  const nextConfig = {
437
436
  ...readVoicePluginConfig(context),
438
437
  injectPrompt:
@@ -481,7 +480,7 @@ export const asrPlugin: Plugin = {
481
480
  },
482
481
  },
483
482
  execute: async ({ context }) => {
484
- setCityPluginEnabled("asr", false);
483
+ context.platform.setPluginEnabled?.("asr", false);
485
484
  return {
486
485
  success: true,
487
486
  data: {
@@ -629,7 +628,7 @@ export const asrPlugin: Plugin = {
629
628
  },
630
629
  system(context) {
631
630
  const config = readVoicePluginConfig(context);
632
- if (!isPluginEnabled({ plugin: asrPlugin }) || config.injectPrompt !== true) {
631
+ if (!isPluginEnabled({ plugin: asrPlugin, context }) || config.injectPrompt !== true) {
633
632
  return "";
634
633
  }
635
634
  return [
@@ -140,6 +140,7 @@ export const authPlugin: Plugin = {
140
140
  channel,
141
141
  userId: String(input.userId || "").trim(),
142
142
  rootPath: context.rootPath,
143
+ platform: context.platform,
143
144
  });
144
145
  return ((role || null) as unknown) as JsonValue;
145
146
  },
@@ -2,7 +2,7 @@
2
2
  * Auth 授权配置读写工具。
3
3
  *
4
4
  * 关键点(中文)
5
- * - 静态授权规则统一写入 console `~/.downcity/downcity.db`。
5
+ * - 静态授权规则通过宿主注入的平台能力读写。
6
6
  * - 授权核心模型为 role / permission / binding。
7
7
  */
8
8
 
@@ -19,9 +19,7 @@ import {
19
19
  CHAT_AUTHORIZATION_PERMISSIONS,
20
20
  createDefaultChatAuthorizationRoles,
21
21
  } from "@/shared/types/AuthPlugin.js";
22
- import { PlatformStore } from "@/shared/utils/store/index.js";
23
22
 
24
- const CHAT_AUTHORIZATION_STORE_KEY = "chat_authorization";
25
23
  const CHANNELS: ChatAuthorizationChannel[] = [...CHAT_AUTHORIZATION_CHANNELS];
26
24
 
27
25
  export const DEFAULT_CHAT_AUTHORIZATION_PERMISSIONS: ChatAuthorizationPermission[] = [
@@ -139,40 +137,41 @@ function cloneAuthorizationConfig(
139
137
  return normalizeAuthorizationConfig(input ? JSON.parse(JSON.stringify(input)) : {});
140
138
  }
141
139
 
142
- function readAuthorizationConfigFromStoreSync(projectRoot: string): ChatAuthorizationConfig {
143
- const normalizedProjectRoot = normalizeText(projectRoot);
140
+ function readAuthorizationConfigFromPlatformSync(params: {
141
+ projectRoot: string;
142
+ readConfig: (projectRoot: string) => ChatAuthorizationConfig;
143
+ }): ChatAuthorizationConfig {
144
+ const normalizedProjectRoot = normalizeText(params.projectRoot);
144
145
  if (!normalizedProjectRoot) return normalizeAuthorizationConfig({});
145
- const store = new PlatformStore();
146
146
  try {
147
- return normalizeAuthorizationConfig(
148
- store.getAgentSecureSettingJsonSync<ChatAuthorizationConfig>(
149
- normalizedProjectRoot,
150
- CHAT_AUTHORIZATION_STORE_KEY,
151
- ) || {},
152
- );
147
+ return normalizeAuthorizationConfig(params.readConfig(normalizedProjectRoot) || {});
153
148
  } catch {
154
149
  return normalizeAuthorizationConfig({});
155
- } finally {
156
- store.close();
157
150
  }
158
151
  }
159
152
 
160
- async function writeAuthorizationConfigToStore(params: {
153
+ function readAuthorizationConfigFromProjectRoot(projectRoot: string): ChatAuthorizationConfig {
154
+ const normalizedProjectRoot = normalizeText(projectRoot);
155
+ if (!normalizedProjectRoot) return normalizeAuthorizationConfig({});
156
+ throw new Error(
157
+ `Platform authorization runtime is not available for project: ${normalizedProjectRoot}`,
158
+ );
159
+ }
160
+
161
+ async function writeAuthorizationConfigToPlatform(params: {
161
162
  projectRoot: string;
162
163
  nextConfig: ChatAuthorizationConfig;
164
+ writeConfig: (
165
+ projectRoot: string,
166
+ nextConfig: ChatAuthorizationConfig,
167
+ ) => Promise<ChatAuthorizationConfig>;
163
168
  }): Promise<void> {
164
169
  const normalizedProjectRoot = normalizeText(params.projectRoot);
165
170
  if (!normalizedProjectRoot) throw new Error("projectRoot is required");
166
- const store = new PlatformStore();
167
- try {
168
- await store.setAgentSecureSettingJson(
169
- normalizedProjectRoot,
170
- CHAT_AUTHORIZATION_STORE_KEY,
171
- normalizeAuthorizationConfig(params.nextConfig),
172
- );
173
- } finally {
174
- store.close();
175
- }
171
+ await params.writeConfig(
172
+ normalizedProjectRoot,
173
+ normalizeAuthorizationConfig(params.nextConfig),
174
+ );
176
175
  }
177
176
 
178
177
  function ensureChannelConfig(
@@ -189,32 +188,37 @@ function ensureChannelConfig(
189
188
  * 同步读取当前 agent 的授权配置。
190
189
  */
191
190
  export function readChatAuthorizationConfigSync(projectRoot: string): ChatAuthorizationConfig {
192
- return readAuthorizationConfigFromStoreSync(projectRoot);
191
+ return readAuthorizationConfigFromProjectRoot(projectRoot);
193
192
  }
194
193
 
195
194
  /**
196
195
  * 读取当前 agent 的授权配置。
197
196
  */
198
197
  export function readChatAuthorizationConfig(
199
- contextOrProjectRoot: Pick<AgentContext, "rootPath"> | string,
198
+ contextOrProjectRoot: Pick<AgentContext, "rootPath" | "platform"> | string,
200
199
  ): ChatAuthorizationConfig {
201
- const projectRoot =
202
- typeof contextOrProjectRoot === "string"
203
- ? contextOrProjectRoot
204
- : contextOrProjectRoot.rootPath;
205
- return readAuthorizationConfigFromStoreSync(projectRoot);
200
+ if (typeof contextOrProjectRoot === "string") {
201
+ return readAuthorizationConfigFromProjectRoot(contextOrProjectRoot);
202
+ }
203
+ return readAuthorizationConfigFromPlatformSync({
204
+ projectRoot: contextOrProjectRoot.rootPath,
205
+ readConfig: (projectRoot) =>
206
+ contextOrProjectRoot.platform.readChatAuthorizationConfig(projectRoot),
207
+ });
206
208
  }
207
209
 
208
210
  /**
209
211
  * 覆盖写入整份授权配置。
210
212
  */
211
213
  export async function writeChatAuthorizationConfig(params: {
212
- context: Pick<AgentContext, "rootPath">;
214
+ context: Pick<AgentContext, "rootPath" | "platform">;
213
215
  nextConfig: ChatAuthorizationConfig;
214
216
  }): Promise<void> {
215
- await writeAuthorizationConfigToStore({
217
+ await writeAuthorizationConfigToPlatform({
216
218
  projectRoot: params.context.rootPath,
217
219
  nextConfig: params.nextConfig,
220
+ writeConfig: (projectRoot, nextConfig) =>
221
+ params.context.platform.writeChatAuthorizationConfig(projectRoot, nextConfig),
218
222
  });
219
223
  }
220
224
 
@@ -232,7 +236,7 @@ export function listChatAuthorizationRoles(params: {
232
236
  * 设置用户角色。
233
237
  */
234
238
  export async function setChatAuthorizationUserRole(params: {
235
- context: Pick<AgentContext, "rootPath">;
239
+ context: Pick<AgentContext, "rootPath" | "platform">;
236
240
  channel: ChatAuthorizationChannel;
237
241
  userId: string;
238
242
  roleId: string;
@@ -241,15 +245,21 @@ export async function setChatAuthorizationUserRole(params: {
241
245
  const roleId = normalizeText(params.roleId);
242
246
  if (!userId || !roleId) throw new Error("userId and roleId are required");
243
247
  const authorization = cloneAuthorizationConfig(
244
- readAuthorizationConfigFromStoreSync(params.context.rootPath),
248
+ readAuthorizationConfigFromPlatformSync({
249
+ projectRoot: params.context.rootPath,
250
+ readConfig: (projectRoot) =>
251
+ params.context.platform.readChatAuthorizationConfig(projectRoot),
252
+ }),
245
253
  );
246
254
  authorization.roles = normalizeRoleMap(authorization.roles);
247
255
  const channelConfig = ensureChannelConfig(authorization, params.channel);
248
256
  if (!authorization.roles?.[roleId]) throw new Error(`Unknown roleId: ${roleId}`);
249
257
  channelConfig.userRoles ??= {};
250
258
  channelConfig.userRoles[userId] = roleId;
251
- await writeAuthorizationConfigToStore({
259
+ await writeAuthorizationConfigToPlatform({
252
260
  projectRoot: params.context.rootPath,
253
261
  nextConfig: authorization,
262
+ writeConfig: (projectRoot, nextConfig) =>
263
+ params.context.platform.writeChatAuthorizationConfig(projectRoot, nextConfig),
254
264
  });
255
265
  }
@@ -7,6 +7,7 @@
7
7
  */
8
8
 
9
9
  import type { DowncityConfig } from "@/shared/types/DowncityConfig.js";
10
+ import type { AgentPlatformRuntime } from "@/shared/types/AgentHost.js";
10
11
  import type {
11
12
  ChatAuthorizationConfig,
12
13
  ChatAuthorizationChannel,
@@ -17,7 +18,6 @@ import type {
17
18
  ChatChannelAuthorizationConfig,
18
19
  } from "@/shared/types/AuthPlugin.js";
19
20
  import { createDefaultChatAuthorizationRoles } from "@/shared/types/AuthPlugin.js";
20
- import { readChatAuthorizationConfigSync } from "@/plugins/auth/runtime/AuthorizationConfig.js";
21
21
 
22
22
  function normalizeText(value: unknown): string | undefined {
23
23
  const text = String(value || "").trim();
@@ -92,12 +92,15 @@ export function resolveAuthorizedUserRole(params: {
92
92
  userId?: string;
93
93
  authorizationConfig?: ChatAuthorizationConfig;
94
94
  rootPath?: string;
95
+ platform?: Pick<AgentPlatformRuntime, "readChatAuthorizationConfig">;
95
96
  }): ChatAuthorizationRole | undefined {
96
97
  const userId = normalizeText(params.userId);
97
98
  if (!userId) return undefined;
98
99
  const authorizationConfig =
99
100
  params.authorizationConfig ||
100
- (params.rootPath ? readChatAuthorizationConfigSync(params.rootPath) : undefined);
101
+ (params.rootPath && params.platform
102
+ ? params.platform.readChatAuthorizationConfig(params.rootPath)
103
+ : undefined);
101
104
  const roles = resolveAuthorizationRoles(authorizationConfig);
102
105
  const channelConfig = resolveChannelAuthorizationConfig(params.channel, authorizationConfig);
103
106
  return resolveUserRole({