@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
@@ -1,255 +0,0 @@
1
- /**
2
- * 统一账户路由策略与全局守卫。
3
- *
4
- * 关键点(中文)
5
- * - 这里负责把“哪些接口需要登录、需要什么权限”集中配置。
6
- * - 当系统还没有任何统一账户用户时,受保护接口默认放行,避免首次 bootstrap 被锁死。
7
- */
8
-
9
- import type { MiddlewareHandler } from "hono";
10
- import type { AuthRoutePolicy } from "@/shared/types/auth/AuthRoute.js";
11
- import type { AuthPermissionKey } from "@/shared/types/auth/AuthPermission.js";
12
- import { isAuthError as isAuthDomainError } from "./AuthError.js";
13
- import type { AuthService } from "./AuthService.js";
14
- import { AUTH_PRINCIPAL_CONTEXT_KEY, type AuthMiddlewareVariables } from "./AuthMiddleware.js";
15
-
16
- /**
17
- * Server 侧路由权限矩阵。
18
- */
19
- export const SERVER_AUTH_ROUTE_POLICIES: AuthRoutePolicy[] = [
20
- { path: "/api/auth/*", method: "*", requireAuth: false },
21
- { path: "/health", method: "GET", requireAuth: false },
22
- {
23
- path: "/api/execute",
24
- method: "POST",
25
- requireAuth: true,
26
- anyPermissions: ["agent.execute"],
27
- },
28
- {
29
- path: "/api/services/list",
30
- method: "GET",
31
- requireAuth: true,
32
- anyPermissions: ["service.read"],
33
- },
34
- {
35
- path: "/api/services/control",
36
- method: "POST",
37
- requireAuth: true,
38
- anyPermissions: ["service.write"],
39
- },
40
- {
41
- path: "/api/services/command",
42
- method: "POST",
43
- requireAuth: true,
44
- anyPermissions: ["service.write"],
45
- },
46
- {
47
- path: "/api/plugins/list",
48
- method: "GET",
49
- requireAuth: true,
50
- anyPermissions: ["plugin.read"],
51
- },
52
- {
53
- path: "/api/plugins/availability",
54
- method: "POST",
55
- requireAuth: true,
56
- anyPermissions: ["plugin.read"],
57
- },
58
- {
59
- path: "/api/plugins/action",
60
- method: "POST",
61
- requireAuth: true,
62
- anyPermissions: ["plugin.write"],
63
- },
64
- {
65
- path: "/api/control/authorization",
66
- method: "GET",
67
- requireAuth: true,
68
- anyPermissions: ["auth.read"],
69
- },
70
- {
71
- path: "/api/control/authorization/config",
72
- method: "POST",
73
- requireAuth: true,
74
- anyPermissions: ["auth.write"],
75
- },
76
- {
77
- path: "/api/control/authorization/action",
78
- method: "POST",
79
- requireAuth: true,
80
- anyPermissions: ["auth.write"],
81
- },
82
- {
83
- path: "/api/control/*",
84
- method: "*",
85
- requireAuth: true,
86
- },
87
- ];
88
-
89
- /**
90
- * 控制面网关侧路由权限矩阵。
91
- */
92
- export const CONTROL_PLANE_AUTH_ROUTE_POLICIES: AuthRoutePolicy[] = [
93
- { path: "/api/auth/*", method: "*", requireAuth: false },
94
- { path: "/health", method: "GET", requireAuth: false },
95
- {
96
- path: "/api/ui/agents",
97
- method: "GET",
98
- requireAuth: true,
99
- anyPermissions: ["agent.read"],
100
- },
101
- {
102
- path: "/api/ui/agents/create",
103
- method: "POST",
104
- requireAuth: true,
105
- anyPermissions: ["agent.write"],
106
- },
107
- {
108
- path: "/api/ui/agents/start",
109
- method: "POST",
110
- requireAuth: true,
111
- anyPermissions: ["agent.write"],
112
- },
113
- {
114
- path: "/api/ui/agents/restart",
115
- method: "POST",
116
- requireAuth: true,
117
- anyPermissions: ["agent.write"],
118
- },
119
- {
120
- path: "/api/ui/agents/stop",
121
- method: "POST",
122
- requireAuth: true,
123
- anyPermissions: ["agent.write"],
124
- },
125
- {
126
- path: "/api/ui/model*",
127
- method: "*",
128
- requireAuth: true,
129
- anyPermissions: ["model.read"],
130
- },
131
- {
132
- path: "/api/ui/env*",
133
- method: "*",
134
- requireAuth: true,
135
- anyPermissions: ["env.read"],
136
- },
137
- {
138
- path: "/api/ui/channel*",
139
- method: "*",
140
- requireAuth: true,
141
- anyPermissions: ["channel.read"],
142
- },
143
- {
144
- path: "/api/ui/plugins*",
145
- method: "*",
146
- requireAuth: true,
147
- anyPermissions: ["plugin.read"],
148
- },
149
- {
150
- path: "/api/ui/*",
151
- method: "*",
152
- requireAuth: true,
153
- },
154
- ];
155
-
156
- /**
157
- * 根据路径与方法解析匹配的策略。
158
- */
159
- export function resolveAuthRoutePolicy(
160
- path: string,
161
- method: string,
162
- policies: AuthRoutePolicy[],
163
- ): AuthRoutePolicy | null {
164
- const normalizedPath = String(path || "").trim() || "/";
165
- const normalizedMethod = String(method || "GET").trim().toUpperCase();
166
- for (const policy of policies) {
167
- if (!matchesMethod(policy.method, normalizedMethod)) continue;
168
- if (!matchesPath(policy.path, normalizedPath)) continue;
169
- return policy;
170
- }
171
- return null;
172
- }
173
-
174
- /**
175
- * 创建全局路由鉴权中间件。
176
- */
177
- export function createRouteAuthGuardMiddleware(
178
- authService: AuthService,
179
- policies: AuthRoutePolicy[] = SERVER_AUTH_ROUTE_POLICIES,
180
- ): MiddlewareHandler<{ Variables: AuthMiddlewareVariables }> {
181
- return async (c, next) => {
182
- const policy = resolveAuthRoutePolicy(c.req.path, c.req.method, policies);
183
- if (!policy || policy.requireAuth !== true) {
184
- await next();
185
- return;
186
- }
187
- if (!authService.hasLocalCliAccess()) {
188
- await next();
189
- return;
190
- }
191
- try {
192
- const principal = authService.authenticateBearerHeader(
193
- c.req.header("authorization"),
194
- );
195
- ensurePermissions(principal.permissions, policy.anyPermissions);
196
- c.set(AUTH_PRINCIPAL_CONTEXT_KEY, principal);
197
- await next();
198
- } catch (error) {
199
- if (isRouteGuardError(error)) {
200
- return c.json(
201
- { success: false, error: error.message },
202
- error.status as 200,
203
- );
204
- }
205
- return c.json({ success: false, error: String(error) }, 500);
206
- }
207
- };
208
- }
209
-
210
- function matchesMethod(expectedMethod: string, actualMethod: string): boolean {
211
- const expected = String(expectedMethod || "*").trim().toUpperCase();
212
- return expected === "*" || expected === actualMethod;
213
- }
214
-
215
- function matchesPath(patternInput: string, actualPath: string): boolean {
216
- const pattern = String(patternInput || "").trim();
217
- if (!pattern) return false;
218
- if (pattern.endsWith("*")) {
219
- const prefix = pattern.slice(0, -1);
220
- return actualPath.startsWith(prefix);
221
- }
222
- return actualPath === pattern;
223
- }
224
-
225
- function ensurePermissions(
226
- userPermissions: AuthPermissionKey[],
227
- anyPermissions: AuthRoutePolicy["anyPermissions"],
228
- ): void {
229
- if (!anyPermissions || anyPermissions.length === 0) return;
230
- if (anyPermissions.some((permission) => userPermissions.includes(permission))) return;
231
- throw new ErrorWithStatus("Permission denied", 403);
232
- }
233
-
234
- class ErrorWithStatus extends Error {
235
- readonly status: number;
236
-
237
- constructor(message: string, status: number) {
238
- super(message);
239
- this.name = "AuthPermissionError";
240
- this.status = status;
241
- }
242
- }
243
-
244
- function isAuthErrorLike(error: unknown): error is { message: string; status: number } {
245
- return (
246
- typeof error === "object" &&
247
- error !== null &&
248
- "status" in error &&
249
- typeof (error as { status?: unknown }).status === "number"
250
- );
251
- }
252
-
253
- function isRouteGuardError(error: unknown): error is { message: string; status: number } {
254
- return isAuthDomainError(error) || isAuthErrorLike(error);
255
- }
@@ -1,116 +0,0 @@
1
- /**
2
- * Plugin 生命周期配置模块。
3
- *
4
- * 关键点(中文)
5
- * - Plugin enable/disable 属于 city 级全局配置,不再写入 agent `downcity.json`。
6
- * - 当前实现把 lifecycle 配置存入 PlatformStore 的统一 JSON 设置。
7
- * - 默认策略:除显式关闭外,内建 plugin 视为启用。
8
- */
9
-
10
- import { PlatformStore } from "@/shared/utils/store/index.js";
11
- import type {
12
- CityPluginLifecycleConfig,
13
- CityPluginLifecycleItem,
14
- } from "@/shared/types/PluginLifecycle.js";
15
-
16
- const PLUGIN_LIFECYCLE_SETTING_KEY = "plugins.lifecycle";
17
-
18
- function normalizeLifecycleItem(input: unknown): CityPluginLifecycleItem | null {
19
- if (!input || typeof input !== "object" || Array.isArray(input)) return null;
20
- const record = input as Record<string, unknown>;
21
- if (typeof record.enabled !== "boolean") return null;
22
- const updatedAt = String(record.updatedAt || "").trim() || new Date().toISOString();
23
- return {
24
- enabled: record.enabled,
25
- updatedAt,
26
- };
27
- }
28
-
29
- function normalizeLifecycleConfig(input: unknown): CityPluginLifecycleConfig {
30
- if (!input || typeof input !== "object" || Array.isArray(input)) return {};
31
- const out: CityPluginLifecycleConfig = {};
32
- for (const [pluginName, raw] of Object.entries(input as Record<string, unknown>)) {
33
- const key = String(pluginName || "").trim();
34
- if (!key) continue;
35
- const item = normalizeLifecycleItem(raw);
36
- if (!item) continue;
37
- out[key] = item;
38
- }
39
- return out;
40
- }
41
-
42
- /**
43
- * 读取当前 city 级 plugin lifecycle 配置。
44
- */
45
- export function readCityPluginLifecycleConfig(): CityPluginLifecycleConfig {
46
- const store = new PlatformStore();
47
- try {
48
- return normalizeLifecycleConfig(
49
- store.getSecureSettingJsonSync<CityPluginLifecycleConfig>(
50
- PLUGIN_LIFECYCLE_SETTING_KEY,
51
- ),
52
- );
53
- } finally {
54
- store.close();
55
- }
56
- }
57
-
58
- /**
59
- * 写入完整 city 级 plugin lifecycle 配置。
60
- */
61
- export function writeCityPluginLifecycleConfig(
62
- value: CityPluginLifecycleConfig,
63
- ): CityPluginLifecycleConfig {
64
- const normalized = normalizeLifecycleConfig(value);
65
- const store = new PlatformStore();
66
- try {
67
- store.setSecureSettingJsonSync(PLUGIN_LIFECYCLE_SETTING_KEY, normalized);
68
- return normalized;
69
- } finally {
70
- store.close();
71
- }
72
- }
73
-
74
- /**
75
- * 读取单个 plugin 的 city 级 lifecycle 状态。
76
- */
77
- export function readCityPluginLifecycleItem(
78
- pluginName: string,
79
- ): CityPluginLifecycleItem | null {
80
- const key = String(pluginName || "").trim();
81
- if (!key) return null;
82
- return readCityPluginLifecycleConfig()[key] || null;
83
- }
84
-
85
- /**
86
- * 读取单个 plugin 是否启用。
87
- *
88
- * 关键点(中文)
89
- * - 除显式关闭外,一律默认启用。
90
- */
91
- export function isCityPluginEnabled(pluginName: string): boolean {
92
- const item = readCityPluginLifecycleItem(pluginName);
93
- if (!item) return true;
94
- return item.enabled === true;
95
- }
96
-
97
- /**
98
- * 设置单个 plugin 的 city 级启用态。
99
- */
100
- export function setCityPluginEnabled(
101
- pluginName: string,
102
- enabled: boolean,
103
- ): CityPluginLifecycleConfig {
104
- const key = String(pluginName || "").trim();
105
- if (!key) {
106
- throw new Error("pluginName is required");
107
- }
108
- const current = readCityPluginLifecycleConfig();
109
- return writeCityPluginLifecycleConfig({
110
- ...current,
111
- [key]: {
112
- enabled,
113
- updatedAt: new Date().toISOString(),
114
- },
115
- });
116
- }