@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,497 +0,0 @@
1
- /**
2
- * PlatformStore 门面。
3
- *
4
- * 关键点(中文)
5
- * - 对外仍然只暴露一个 `PlatformStore` 类,保持调用入口稳定。
6
- * - 内部已经按职责拆成 schema、model/provider、secure settings、env、channel accounts 多个模块。
7
- * - 这样既能保持外部 API 简洁,也能把通用存储层控制在可维护的模块粒度内。
8
- */
9
-
10
- import fs from "fs-extra";
11
- import Database from "better-sqlite3";
12
- import { drizzle } from "drizzle-orm/better-sqlite3";
13
- import { getPlatformStoreDbPath } from "@/host/runtime/CityPaths.js";
14
- import { ensurePlatformStoreSchema } from "./StoreSchema.js";
15
- import type { PlatformStoreContext } from "./StoreShared.js";
16
- import type {
17
- StoredAgentEnvEntry,
18
- StoredChannelAccount,
19
- StoredEnvEntry,
20
- StoredEnvScope,
21
- StoredGlobalEnvEntry,
22
- StoredModel,
23
- StoredModelProvider,
24
- StoredProviderMeta,
25
- UpsertAgentEnvEntryInput,
26
- UpsertChannelAccountInput,
27
- UpsertEnvEntryInput,
28
- UpsertGlobalEnvEntryInput,
29
- UpsertModelInput,
30
- UpsertModelProviderInput,
31
- } from "@/shared/types/Store.js";
32
- import {
33
- getPlatformRootDirPath,
34
- } from "@/host/runtime/CityPaths.js";
35
- import {
36
- clearStoredModelsAndProviders,
37
- getResolvedStoredModel,
38
- getStoredModel,
39
- getStoredProvider,
40
- listStoredModels,
41
- listStoredProviderMetas,
42
- listStoredProviders,
43
- removeStoredModel,
44
- removeStoredProvider,
45
- setStoredModelPaused,
46
- upsertStoredModel,
47
- upsertStoredProvider,
48
- } from "./StoreModelRepository.js";
49
- import {
50
- buildAgentSecureSettingKey,
51
- getSecureSettingJson,
52
- getSecureSettingJsonSync,
53
- removeSecureSetting,
54
- setSecureSettingJson,
55
- setSecureSettingJsonSync,
56
- } from "./StoreSecureSettings.js";
57
- import {
58
- clearAgentEnvEntries,
59
- clearGlobalEnvEntries,
60
- getAgentEnvMap,
61
- getAgentEnvMapSync,
62
- getGlobalEnvMap,
63
- getGlobalEnvMapSync,
64
- listAgentEnvEntries,
65
- listAgentEnvEntriesSync,
66
- listAllAgentEnvEntries,
67
- listEnvEntries,
68
- listEnvEntriesSync,
69
- listGlobalEnvEntries,
70
- listGlobalEnvEntriesSync,
71
- removeAgentEnvEntry,
72
- removeEnvEntry,
73
- removeGlobalEnvEntry,
74
- upsertAgentEnvEntry,
75
- upsertEnvEntry,
76
- upsertGlobalEnvEntry,
77
- } from "./StoreEnvRepository.js";
78
- import {
79
- getChannelAccount,
80
- getChannelAccountSync,
81
- listChannelAccounts,
82
- listChannelAccountsSync,
83
- removeChannelAccount,
84
- upsertChannelAccount,
85
- } from "./StoreChannelAccountRepository.js";
86
-
87
- /**
88
- * 平台控制面全局存储门面。
89
- */
90
- export class PlatformStore {
91
- private readonly sqlite: Database.Database;
92
- private readonly db: ReturnType<typeof drizzle>;
93
-
94
- constructor(dbPath: string = getPlatformStoreDbPath()) {
95
- fs.ensureDirSync(getPlatformRootDirPath());
96
- this.sqlite = new Database(dbPath);
97
- this.sqlite.pragma("foreign_keys = ON");
98
- this.sqlite.pragma("journal_mode = WAL");
99
- this.db = drizzle(this.sqlite);
100
- ensurePlatformStoreSchema(this.context);
101
- }
102
-
103
- /**
104
- * 暴露给内部 helper 的只读上下文视图。
105
- */
106
- private get context(): PlatformStoreContext {
107
- return {
108
- sqlite: this.sqlite,
109
- db: this.db,
110
- };
111
- }
112
-
113
- /**
114
- * 关闭连接。
115
- */
116
- close(): void {
117
- this.sqlite.close();
118
- }
119
-
120
- /**
121
- * 列出 providers。
122
- */
123
- async listProviders(): Promise<StoredModelProvider[]> {
124
- return await listStoredProviders(this.context);
125
- }
126
-
127
- /**
128
- * 获取单个 provider。
129
- */
130
- async getProvider(providerId: string): Promise<StoredModelProvider | null> {
131
- return await getStoredProvider(this.context, providerId);
132
- }
133
-
134
- /**
135
- * 新增或更新 provider。
136
- */
137
- async upsertProvider(input: UpsertModelProviderInput): Promise<void> {
138
- await upsertStoredProvider(this.context, input);
139
- }
140
-
141
- /**
142
- * 删除 provider。
143
- */
144
- removeProvider(providerId: string): void {
145
- removeStoredProvider(this.context, providerId);
146
- }
147
-
148
- /**
149
- * 列出 models。
150
- */
151
- listModels(): StoredModel[] {
152
- return listStoredModels(this.context);
153
- }
154
-
155
- /**
156
- * 同步列出 provider 元信息(不含 API Key)。
157
- */
158
- listProvidersSync(): StoredProviderMeta[] {
159
- return listStoredProviderMetas(this.context);
160
- }
161
-
162
- /**
163
- * 获取单个 model。
164
- */
165
- getModel(modelId: string): StoredModel | null {
166
- return getStoredModel(this.context, modelId);
167
- }
168
-
169
- /**
170
- * 新增或更新 model。
171
- */
172
- upsertModel(input: UpsertModelInput): void {
173
- upsertStoredModel(this.context, input);
174
- }
175
-
176
- /**
177
- * 切换模型暂停状态。
178
- */
179
- setModelPaused(modelId: string, paused: boolean): void {
180
- setStoredModelPaused(this.context, modelId, paused);
181
- }
182
-
183
- /**
184
- * 删除 model。
185
- */
186
- removeModel(modelId: string): void {
187
- removeStoredModel(this.context, modelId);
188
- }
189
-
190
- /**
191
- * 获取 model + provider 聚合信息。
192
- */
193
- async getResolvedModel(modelId: string): Promise<{
194
- model: StoredModel;
195
- provider: StoredModelProvider;
196
- } | null> {
197
- return await getResolvedStoredModel(this.context, modelId);
198
- }
199
-
200
- /**
201
- * 清空所有存储数据。
202
- */
203
- clearAll(): void {
204
- clearStoredModelsAndProviders(this.context);
205
- this.sqlite.exec("DELETE FROM platform_secure_settings;");
206
- this.sqlite.exec("DELETE FROM env_entries;");
207
- this.sqlite.exec("DELETE FROM global_env;");
208
- this.sqlite.exec("DELETE FROM agent_env;");
209
- this.sqlite.exec("DELETE FROM channel_accounts;");
210
- }
211
-
212
- /**
213
- * 同步读取 console 加密配置项(JSON)。
214
- */
215
- getSecureSettingJsonSync<T>(key: string): T | null {
216
- return getSecureSettingJsonSync<T>(this.context, key);
217
- }
218
-
219
- /**
220
- * 同步写入 console 加密配置项(JSON)。
221
- */
222
- setSecureSettingJsonSync(key: string, value: unknown): void {
223
- setSecureSettingJsonSync(this.context, key, value);
224
- }
225
-
226
- /**
227
- * 删除 console 加密配置项。
228
- */
229
- removeSecureSetting(key: string): void {
230
- removeSecureSetting(this.context, key);
231
- }
232
-
233
- /**
234
- * 异步读取 console 加密配置项(JSON)。
235
- */
236
- async getSecureSettingJson<T>(key: string): Promise<T | null> {
237
- return await getSecureSettingJson<T>(this.context, key);
238
- }
239
-
240
- /**
241
- * 异步写入 console 加密配置项(JSON)。
242
- */
243
- async setSecureSettingJson(key: string, value: unknown): Promise<void> {
244
- await setSecureSettingJson(this.context, key, value);
245
- }
246
-
247
- /**
248
- * 同步读取 agent 加密配置项(JSON)。
249
- */
250
- getAgentSecureSettingJsonSync<T>(agentIdInput: string, keyInput: string): T | null {
251
- return this.getSecureSettingJsonSync<T>(
252
- buildAgentSecureSettingKey(agentIdInput, keyInput),
253
- );
254
- }
255
-
256
- /**
257
- * 同步写入 agent 加密配置项(JSON)。
258
- */
259
- setAgentSecureSettingJsonSync(agentIdInput: string, keyInput: string, value: unknown): void {
260
- this.setSecureSettingJsonSync(
261
- buildAgentSecureSettingKey(agentIdInput, keyInput),
262
- value,
263
- );
264
- }
265
-
266
- /**
267
- * 删除 agent 加密配置项。
268
- */
269
- removeAgentSecureSetting(agentIdInput: string, keyInput: string): void {
270
- this.removeSecureSetting(buildAgentSecureSettingKey(agentIdInput, keyInput));
271
- }
272
-
273
- /**
274
- * 异步读取 agent 加密配置项(JSON)。
275
- */
276
- async getAgentSecureSettingJson<T>(
277
- agentIdInput: string,
278
- keyInput: string,
279
- ): Promise<T | null> {
280
- return await this.getSecureSettingJson<T>(
281
- buildAgentSecureSettingKey(agentIdInput, keyInput),
282
- );
283
- }
284
-
285
- /**
286
- * 异步写入 agent 加密配置项(JSON)。
287
- */
288
- async setAgentSecureSettingJson(
289
- agentIdInput: string,
290
- keyInput: string,
291
- value: unknown,
292
- ): Promise<void> {
293
- await this.setSecureSettingJson(
294
- buildAgentSecureSettingKey(agentIdInput, keyInput),
295
- value,
296
- );
297
- }
298
-
299
- /**
300
- * 查询 env 条目(同步)。
301
- */
302
- listEnvEntriesSync(scopeInput?: StoredEnvScope, agentIdInput?: string): StoredEnvEntry[] {
303
- return listEnvEntriesSync(this.context, scopeInput, agentIdInput);
304
- }
305
-
306
- /**
307
- * 查询 env 条目(异步)。
308
- */
309
- async listEnvEntries(scopeInput?: StoredEnvScope, agentIdInput?: string): Promise<StoredEnvEntry[]> {
310
- return await listEnvEntries(this.context, scopeInput, agentIdInput);
311
- }
312
-
313
- /**
314
- * 新增或更新 env 条目。
315
- */
316
- async upsertEnvEntry(input: UpsertEnvEntryInput): Promise<void> {
317
- await upsertEnvEntry(this.context, input);
318
- }
319
-
320
- /**
321
- * 删除单个 env 条目。
322
- */
323
- removeEnvEntry(input: { scope: StoredEnvScope; agentId?: string; key: string }): void {
324
- removeEnvEntry(this.context, input);
325
- }
326
-
327
- /**
328
- * 列出全局环境变量(同步解密)。
329
- */
330
- listGlobalEnvEntriesSync(): StoredGlobalEnvEntry[] {
331
- return listGlobalEnvEntriesSync(this.context);
332
- }
333
-
334
- /**
335
- * 读取全局环境变量映射(同步解密)。
336
- */
337
- getGlobalEnvMapSync(): Record<string, string> {
338
- return getGlobalEnvMapSync(this.context);
339
- }
340
-
341
- /**
342
- * 列出全局环境变量(解密后)。
343
- */
344
- async listGlobalEnvEntries(): Promise<StoredGlobalEnvEntry[]> {
345
- return await listGlobalEnvEntries(this.context);
346
- }
347
-
348
- /**
349
- * 读取全局环境变量映射(解密后)。
350
- */
351
- async getGlobalEnvMap(): Promise<Record<string, string>> {
352
- return await getGlobalEnvMap(this.context);
353
- }
354
-
355
- /**
356
- * 新增或更新全局环境变量。
357
- */
358
- async upsertGlobalEnvEntry(input: UpsertGlobalEnvEntryInput): Promise<void> {
359
- await upsertGlobalEnvEntry(this.context, input);
360
- }
361
-
362
- /**
363
- * 删除单个全局环境变量。
364
- */
365
- removeGlobalEnvEntry(keyInput: string): void {
366
- removeGlobalEnvEntry(this.context, keyInput);
367
- }
368
-
369
- /**
370
- * 清空全局环境变量。
371
- */
372
- clearGlobalEnvEntries(): void {
373
- clearGlobalEnvEntries(this.context);
374
- }
375
-
376
- /**
377
- * 列出指定 agent 的私有环境变量(同步解密)。
378
- */
379
- listAgentEnvEntriesSync(agentIdInput: string): StoredAgentEnvEntry[] {
380
- return listAgentEnvEntriesSync(this.context, agentIdInput);
381
- }
382
-
383
- /**
384
- * 读取指定 agent 的私有环境变量映射(同步解密)。
385
- */
386
- getAgentEnvMapSync(agentIdInput: string): Record<string, string> {
387
- return getAgentEnvMapSync(this.context, agentIdInput);
388
- }
389
-
390
- /**
391
- * 列出指定 agent 的私有环境变量(解密后)。
392
- */
393
- async listAgentEnvEntries(agentIdInput: string): Promise<StoredAgentEnvEntry[]> {
394
- return await listAgentEnvEntries(this.context, agentIdInput);
395
- }
396
-
397
- /**
398
- * 列出全部 agent 私有环境变量(解密后)。
399
- */
400
- async listAllAgentEnvEntries(): Promise<StoredAgentEnvEntry[]> {
401
- return await listAllAgentEnvEntries(this.context);
402
- }
403
-
404
- /**
405
- * 读取指定 agent 的私有环境变量映射(解密后)。
406
- */
407
- async getAgentEnvMap(agentIdInput: string): Promise<Record<string, string>> {
408
- return await getAgentEnvMap(this.context, agentIdInput);
409
- }
410
-
411
- /**
412
- * 新增或更新 agent 私有环境变量。
413
- */
414
- async upsertAgentEnvEntry(input: UpsertAgentEnvEntryInput): Promise<void> {
415
- await upsertAgentEnvEntry(this.context, input);
416
- }
417
-
418
- /**
419
- * 删除指定 agent 的单个环境变量。
420
- */
421
- removeAgentEnvEntry(agentIdInput: string, keyInput: string): void {
422
- removeAgentEnvEntry(this.context, agentIdInput, keyInput);
423
- }
424
-
425
- /**
426
- * 清空指定 agent 的私有环境变量。
427
- */
428
- clearAgentEnvEntries(agentIdInput: string): void {
429
- clearAgentEnvEntries(this.context, agentIdInput);
430
- }
431
-
432
- /**
433
- * 列出 channel accounts(同步解密)。
434
- */
435
- listChannelAccountsSync(channelInput?: string): StoredChannelAccount[] {
436
- return listChannelAccountsSync(this.context, channelInput);
437
- }
438
-
439
- /**
440
- * 按 ID 获取 channel account(同步解密)。
441
- */
442
- getChannelAccountSync(accountIdInput: string): StoredChannelAccount | null {
443
- return getChannelAccountSync(this.context, accountIdInput);
444
- }
445
-
446
- /**
447
- * 列出 channel accounts(解密后)。
448
- */
449
- async listChannelAccounts(channelInput?: string): Promise<StoredChannelAccount[]> {
450
- return await listChannelAccounts(this.context, channelInput);
451
- }
452
-
453
- /**
454
- * 按 ID 获取 channel account(解密后)。
455
- */
456
- async getChannelAccount(accountIdInput: string): Promise<StoredChannelAccount | null> {
457
- return await getChannelAccount(this.context, accountIdInput);
458
- }
459
-
460
- /**
461
- * 新增或更新 channel account。
462
- */
463
- async upsertChannelAccount(input: UpsertChannelAccountInput): Promise<void> {
464
- await upsertChannelAccount(this.context, input);
465
- }
466
-
467
- /**
468
- * 删除 channel account。
469
- */
470
- removeChannelAccount(accountIdInput: string): void {
471
- removeChannelAccount(this.context, accountIdInput);
472
- }
473
- }
474
-
475
- /**
476
- * 在 PlatformStore 上下文中执行操作。
477
- *
478
- * 关键点(中文)
479
- * - 用于一次性数据库操作,无需手动管理 PlatformStore 实例生命周期。
480
- * - 自动处理数据库连接和关闭。
481
- */
482
- export function withPlatformStore<T>(callback: (context: PlatformStoreContext) => T): T {
483
- const dbPath = getPlatformStoreDbPath();
484
- fs.ensureDirSync(dbPath.replace(/\/[^/]+$/, ""));
485
- const sqlite = new Database(dbPath);
486
- sqlite.pragma("journal_mode = WAL");
487
- const context: PlatformStoreContext = {
488
- sqlite,
489
- db: drizzle(sqlite),
490
- };
491
- ensurePlatformStoreSchema(context);
492
- try {
493
- return callback(context);
494
- } finally {
495
- sqlite.close();
496
- }
497
- }
@@ -1,103 +0,0 @@
1
- /**
2
- * 模型存储表结构(drizzle schema)。
3
- *
4
- * 关键点(中文)
5
- * - providers 与 models 分表,使用 providerId 做关联。
6
- * - API Key 以密文字段存储(`apiKeyEncrypted`)。
7
- */
8
- import {
9
- index,
10
- integer,
11
- primaryKey,
12
- real,
13
- sqliteTable,
14
- text,
15
- } from "drizzle-orm/sqlite-core";
16
-
17
- export const modelProvidersTable = sqliteTable("model_providers", {
18
- id: text("id").primaryKey(),
19
- type: text("type").notNull(),
20
- baseUrl: text("base_url"),
21
- apiKeyEncrypted: text("api_key_encrypted"),
22
- createdAt: text("created_at").notNull(),
23
- updatedAt: text("updated_at").notNull(),
24
- });
25
-
26
- export const modelsTable = sqliteTable(
27
- "models",
28
- {
29
- id: text("id").primaryKey(),
30
- providerId: text("provider_id").notNull(),
31
- name: text("name").notNull(),
32
- temperature: real("temperature"),
33
- maxTokens: integer("max_tokens"),
34
- topP: real("top_p"),
35
- frequencyPenalty: real("frequency_penalty"),
36
- presencePenalty: real("presence_penalty"),
37
- anthropicVersion: text("anthropic_version"),
38
- isPaused: integer("is_paused").notNull().default(0),
39
- createdAt: text("created_at").notNull(),
40
- updatedAt: text("updated_at").notNull(),
41
- },
42
- (table) => ({
43
- providerIdIdx: index("models_provider_id_idx").on(table.providerId),
44
- }),
45
- );
46
-
47
- /**
48
- * 平台 Env 统一存储表。
49
- *
50
- * 关键点(中文)
51
- * - 全局 env 与 agent env 共用一张表,通过 `scope` + `agentId` 区分。
52
- * - `agentId` 在 `scope=global` 时固定为空字符串,避免 SQLite 复合主键中的 NULL 语义问题。
53
- * - value 采用密文存储,解密仅在运行时内存中进行。
54
- */
55
- export const envEntriesTable = sqliteTable(
56
- "env_entries",
57
- {
58
- scope: text("scope").notNull(),
59
- agentId: text("agent_id").notNull().default(""),
60
- key: text("key").notNull(),
61
- description: text("description"),
62
- valueEncrypted: text("value_encrypted").notNull(),
63
- createdAt: text("created_at").notNull(),
64
- updatedAt: text("updated_at").notNull(),
65
- },
66
- (table) => ({
67
- pk: primaryKey({
68
- columns: [table.scope, table.agentId, table.key],
69
- name: "env_entries_scope_agent_key_pk",
70
- }),
71
- scopeIdx: index("env_entries_scope_idx").on(table.scope),
72
- agentIdIdx: index("env_entries_agent_id_idx").on(table.agentId),
73
- }),
74
- );
75
-
76
- /**
77
- * Channel Account 表。
78
- *
79
- * 关键点(中文)
80
- * - 各渠道敏感字段独立密文列存储。
81
- * - `downcity.json` 仅保存 channelAccountId 绑定,不直接保存密钥。
82
- */
83
- export const channelAccountsTable = sqliteTable(
84
- "channel_accounts",
85
- {
86
- id: text("id").primaryKey(),
87
- channel: text("channel").notNull(),
88
- name: text("name").notNull(),
89
- identity: text("identity"),
90
- owner: text("owner"),
91
- creator: text("creator"),
92
- botTokenEncrypted: text("bot_token_encrypted"),
93
- appIdEncrypted: text("app_id_encrypted"),
94
- appSecretEncrypted: text("app_secret_encrypted"),
95
- domain: text("domain"),
96
- sandbox: integer("sandbox"),
97
- createdAt: text("created_at").notNull(),
98
- updatedAt: text("updated_at").notNull(),
99
- },
100
- (table) => ({
101
- channelIdx: index("channel_accounts_channel_idx").on(table.channel),
102
- }),
103
- );