@downcity/plugins 1.0.153 → 1.0.156

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 (175) hide show
  1. package/bin/chat/ChatPlugin.d.ts +2 -10
  2. package/bin/chat/ChatPlugin.d.ts.map +1 -1
  3. package/bin/chat/ChatPlugin.js +3 -13
  4. package/bin/chat/ChatPlugin.js.map +1 -1
  5. package/bin/chat/PROMPT.direct.d.ts +1 -1
  6. package/bin/chat/PROMPT.direct.d.ts.map +1 -1
  7. package/bin/chat/PROMPT.direct.js +1 -1
  8. package/bin/chat/PROMPT.direct.js.map +1 -1
  9. package/bin/chat/access/ChatAccessActions.d.ts +11 -0
  10. package/bin/chat/access/ChatAccessActions.d.ts.map +1 -0
  11. package/bin/chat/access/ChatAccessActions.js +137 -0
  12. package/bin/chat/access/ChatAccessActions.js.map +1 -0
  13. package/bin/chat/access/ChatAccessRuntime.d.ts +17 -0
  14. package/bin/chat/access/ChatAccessRuntime.d.ts.map +1 -0
  15. package/bin/chat/access/ChatAccessRuntime.js +31 -0
  16. package/bin/chat/access/ChatAccessRuntime.js.map +1 -0
  17. package/bin/chat/access/ChatAccessSchema.d.ts +16 -0
  18. package/bin/chat/access/ChatAccessSchema.d.ts.map +1 -0
  19. package/bin/chat/access/ChatAccessSchema.js +99 -0
  20. package/bin/chat/access/ChatAccessSchema.js.map +1 -0
  21. package/bin/chat/access/ChatAccessService.d.ts +44 -0
  22. package/bin/chat/access/ChatAccessService.d.ts.map +1 -0
  23. package/bin/chat/access/ChatAccessService.js +281 -0
  24. package/bin/chat/access/ChatAccessService.js.map +1 -0
  25. package/bin/chat/access/ChatAccessStore.d.ts +67 -0
  26. package/bin/chat/access/ChatAccessStore.d.ts.map +1 -0
  27. package/bin/chat/access/ChatAccessStore.js +367 -0
  28. package/bin/chat/access/ChatAccessStore.js.map +1 -0
  29. package/bin/chat/accounts/Crypto.d.ts +1 -1
  30. package/bin/chat/accounts/Crypto.js +1 -1
  31. package/bin/chat/accounts/Store.d.ts +1 -1
  32. package/bin/chat/accounts/Store.js +1 -1
  33. package/bin/chat/channels/BaseChatChannel.d.ts +18 -21
  34. package/bin/chat/channels/BaseChatChannel.d.ts.map +1 -1
  35. package/bin/chat/channels/BaseChatChannel.js +48 -58
  36. package/bin/chat/channels/BaseChatChannel.js.map +1 -1
  37. package/bin/chat/channels/BaseChatChannelQueue.d.ts +1 -1
  38. package/bin/chat/channels/BaseChatChannelQueue.d.ts.map +1 -1
  39. package/bin/chat/channels/BaseChatChannelQueue.js +2 -14
  40. package/bin/chat/channels/BaseChatChannelQueue.js.map +1 -1
  41. package/bin/chat/channels/Configuration.d.ts +2 -2
  42. package/bin/chat/channels/Configuration.d.ts.map +1 -1
  43. package/bin/chat/channels/Configuration.js +3 -3
  44. package/bin/chat/channels/Configuration.js.map +1 -1
  45. package/bin/chat/channels/feishu/Configuration.js +4 -4
  46. package/bin/chat/channels/feishu/Configuration.js.map +1 -1
  47. package/bin/chat/channels/feishu/Feishu.d.ts +2 -0
  48. package/bin/chat/channels/feishu/Feishu.d.ts.map +1 -1
  49. package/bin/chat/channels/feishu/Feishu.js +8 -7
  50. package/bin/chat/channels/feishu/Feishu.js.map +1 -1
  51. package/bin/chat/channels/feishu/FeishuMessageHandler.d.ts +9 -17
  52. package/bin/chat/channels/feishu/FeishuMessageHandler.d.ts.map +1 -1
  53. package/bin/chat/channels/feishu/FeishuMessageHandler.js +6 -17
  54. package/bin/chat/channels/feishu/FeishuMessageHandler.js.map +1 -1
  55. package/bin/chat/channels/qq/Configuration.js +4 -4
  56. package/bin/chat/channels/qq/Configuration.js.map +1 -1
  57. package/bin/chat/channels/qq/QQ.d.ts +2 -0
  58. package/bin/chat/channels/qq/QQ.d.ts.map +1 -1
  59. package/bin/chat/channels/qq/QQ.js +8 -7
  60. package/bin/chat/channels/qq/QQ.js.map +1 -1
  61. package/bin/chat/channels/qq/QQMessageHandler.d.ts +9 -17
  62. package/bin/chat/channels/qq/QQMessageHandler.d.ts.map +1 -1
  63. package/bin/chat/channels/qq/QQMessageHandler.js +7 -25
  64. package/bin/chat/channels/qq/QQMessageHandler.js.map +1 -1
  65. package/bin/chat/channels/telegram/Bot.d.ts +2 -0
  66. package/bin/chat/channels/telegram/Bot.d.ts.map +1 -1
  67. package/bin/chat/channels/telegram/Bot.js +8 -7
  68. package/bin/chat/channels/telegram/Bot.js.map +1 -1
  69. package/bin/chat/channels/telegram/Configuration.js +4 -4
  70. package/bin/chat/channels/telegram/Configuration.js.map +1 -1
  71. package/bin/chat/channels/telegram/TelegramMessageHandler.d.ts +9 -17
  72. package/bin/chat/channels/telegram/TelegramMessageHandler.d.ts.map +1 -1
  73. package/bin/chat/channels/telegram/TelegramMessageHandler.js +5 -16
  74. package/bin/chat/channels/telegram/TelegramMessageHandler.js.map +1 -1
  75. package/bin/chat/runtime/ChatChannelActions.d.ts +3 -2
  76. package/bin/chat/runtime/ChatChannelActions.d.ts.map +1 -1
  77. package/bin/chat/runtime/ChatChannelActions.js +57 -0
  78. package/bin/chat/runtime/ChatChannelActions.js.map +1 -1
  79. package/bin/chat/runtime/ChatChannelConfig.d.ts +2 -2
  80. package/bin/chat/runtime/ChatChannelConfig.js +3 -3
  81. package/bin/chat/runtime/ChatChannelConfig.js.map +1 -1
  82. package/bin/chat/runtime/ChatChannelCore.d.ts +2 -2
  83. package/bin/chat/runtime/ChatChannelCore.js +1 -1
  84. package/bin/chat/runtime/ChatChannelLifecycle.d.ts +1 -1
  85. package/bin/chat/runtime/ChatChannelLifecycle.js +1 -1
  86. package/bin/chat/runtime/PluginPoints.d.ts +0 -24
  87. package/bin/chat/runtime/PluginPoints.d.ts.map +1 -1
  88. package/bin/chat/runtime/PluginPoints.js +0 -24
  89. package/bin/chat/runtime/PluginPoints.js.map +1 -1
  90. package/bin/chat/runtime/QueuedUserMessage.d.ts.map +1 -1
  91. package/bin/chat/runtime/QueuedUserMessage.js +0 -2
  92. package/bin/chat/runtime/QueuedUserMessage.js.map +1 -1
  93. package/bin/chat/types/ChannelConfiguration.d.ts +4 -4
  94. package/bin/chat/types/ChannelConfiguration.d.ts.map +1 -1
  95. package/bin/chat/types/ChatAccess.d.ts +300 -0
  96. package/bin/chat/types/ChatAccess.d.ts.map +1 -0
  97. package/bin/chat/types/ChatAccess.js +22 -0
  98. package/bin/chat/types/ChatAccess.js.map +1 -0
  99. package/bin/chat/types/ChatPromptContext.d.ts +0 -15
  100. package/bin/chat/types/ChatPromptContext.d.ts.map +1 -1
  101. package/bin/index.d.ts +4 -4
  102. package/bin/index.d.ts.map +1 -1
  103. package/bin/index.js +3 -3
  104. package/bin/index.js.map +1 -1
  105. package/bin/skill/Config.d.ts +1 -1
  106. package/bin/skill/Config.js +1 -1
  107. package/bin/skill/runtime/Paths.d.ts +1 -1
  108. package/bin/skill/runtime/Paths.js +1 -1
  109. package/package.json +6 -4
  110. package/scripts/chat-access.test.mjs +90 -0
  111. package/scripts/chat-channel-config.test.mjs +82 -0
  112. package/src/chat/ChatPlugin.ts +4 -24
  113. package/src/chat/PROMPT.direct.ts +1 -1
  114. package/src/chat/PROMPT.direct.ts.txt +1 -1
  115. package/src/chat/access/ChatAccessActions.ts +159 -0
  116. package/src/chat/access/ChatAccessRuntime.ts +41 -0
  117. package/src/chat/access/ChatAccessSchema.ts +104 -0
  118. package/src/chat/access/ChatAccessService.ts +311 -0
  119. package/src/chat/access/ChatAccessStore.ts +462 -0
  120. package/src/chat/accounts/Crypto.ts +1 -1
  121. package/src/chat/accounts/Store.ts +1 -1
  122. package/src/chat/channels/BaseChatChannel.ts +59 -80
  123. package/src/chat/channels/BaseChatChannelQueue.ts +2 -14
  124. package/src/chat/channels/Configuration.ts +3 -3
  125. package/src/chat/channels/feishu/Configuration.ts +4 -4
  126. package/src/chat/channels/feishu/Feishu.ts +11 -9
  127. package/src/chat/channels/feishu/FeishuMessageHandler.ts +16 -40
  128. package/src/chat/channels/qq/Configuration.ts +4 -4
  129. package/src/chat/channels/qq/QQ.ts +11 -9
  130. package/src/chat/channels/qq/QQMessageHandler.ts +17 -49
  131. package/src/chat/channels/telegram/Bot.ts +11 -9
  132. package/src/chat/channels/telegram/Configuration.ts +4 -4
  133. package/src/chat/channels/telegram/TelegramMessageHandler.ts +15 -39
  134. package/src/chat/runtime/ChatChannelActions.ts +72 -1
  135. package/src/chat/runtime/ChatChannelConfig.ts +3 -3
  136. package/src/chat/runtime/ChatChannelCore.ts +1 -1
  137. package/src/chat/runtime/ChatChannelLifecycle.ts +1 -1
  138. package/src/chat/runtime/PluginPoints.ts +0 -24
  139. package/src/chat/runtime/QueuedUserMessage.ts +0 -2
  140. package/src/chat/types/ChannelConfiguration.ts +4 -4
  141. package/src/chat/types/ChatAccess.ts +335 -0
  142. package/src/chat/types/ChatPromptContext.ts +0 -17
  143. package/src/index.ts +27 -31
  144. package/src/skill/Config.ts +1 -1
  145. package/src/skill/runtime/Paths.ts +1 -1
  146. package/bin/auth/runtime/AuthorizationConfig.d.ts +0 -41
  147. package/bin/auth/runtime/AuthorizationConfig.d.ts.map +0 -1
  148. package/bin/auth/runtime/AuthorizationConfig.js +0 -185
  149. package/bin/auth/runtime/AuthorizationConfig.js.map +0 -1
  150. package/bin/auth/runtime/AuthorizationPolicy.d.ts +0 -28
  151. package/bin/auth/runtime/AuthorizationPolicy.d.ts.map +0 -1
  152. package/bin/auth/runtime/AuthorizationPolicy.js +0 -124
  153. package/bin/auth/runtime/AuthorizationPolicy.js.map +0 -1
  154. package/bin/auth/runtime/AuthorizationStore.d.ts +0 -29
  155. package/bin/auth/runtime/AuthorizationStore.d.ts.map +0 -1
  156. package/bin/auth/runtime/AuthorizationStore.js +0 -179
  157. package/bin/auth/runtime/AuthorizationStore.js.map +0 -1
  158. package/bin/auth/types/AuthPlugin.d.ts +0 -403
  159. package/bin/auth/types/AuthPlugin.d.ts.map +0 -1
  160. package/bin/auth/types/AuthPlugin.js +0 -111
  161. package/bin/auth/types/AuthPlugin.js.map +0 -1
  162. package/bin/chat/runtime/ChatAuthorizationRuntime.d.ts +0 -22
  163. package/bin/chat/runtime/ChatAuthorizationRuntime.d.ts.map +0 -1
  164. package/bin/chat/runtime/ChatAuthorizationRuntime.js +0 -230
  165. package/bin/chat/runtime/ChatAuthorizationRuntime.js.map +0 -1
  166. package/bin/chat/runtime/PluginDispatch.d.ts +0 -43
  167. package/bin/chat/runtime/PluginDispatch.d.ts.map +0 -1
  168. package/bin/chat/runtime/PluginDispatch.js +0 -57
  169. package/bin/chat/runtime/PluginDispatch.js.map +0 -1
  170. package/src/auth/runtime/AuthorizationConfig.ts +0 -247
  171. package/src/auth/runtime/AuthorizationPolicy.ts +0 -167
  172. package/src/auth/runtime/AuthorizationStore.ts +0 -220
  173. package/src/auth/types/AuthPlugin.ts +0 -540
  174. package/src/chat/runtime/ChatAuthorizationRuntime.ts +0 -270
  175. package/src/chat/runtime/PluginDispatch.ts +0 -89
@@ -7,7 +7,11 @@
7
7
  * - 对外只暴露 action 级入口,供 ChatPluginActions 装配使用。
8
8
  */
9
9
 
10
- import type { AgentContext } from "@downcity/agent";
10
+ import type {
11
+ AgentContext,
12
+ DowncityChatChannelConfig,
13
+ DowncityConfig,
14
+ } from "@downcity/agent";
11
15
  import type { ChatChannelState } from "@/chat/types/ChatRuntime.js";
12
16
  import { getStoredChannelAccountSync } from "@/chat/accounts/Store.js";
13
17
  import type {
@@ -20,6 +24,7 @@ import type {
20
24
  ChatTestActionPayload,
21
25
  } from "@/chat/types/ChatPluginActionPayload.js";
22
26
  import type { ChatChannelTestResult } from "@/chat/types/ChannelStatus.js";
27
+ import type { ChatChannelName } from "@/chat/types/ChannelStatus.js";
23
28
  import {
24
29
  describeChatChannelConfiguration,
25
30
  getChatChannelStatus,
@@ -49,6 +54,54 @@ function getChatRuntimeBindings(context: AgentContext): ChatRuntimeControlBindin
49
54
  return plugin as ChatRuntimeControlBindings;
50
55
  }
51
56
 
57
+ /**
58
+ * 将 channel patch 合并进完整 plugins 配置并交给宿主持久化。
59
+ *
60
+ * 关键点(中文)
61
+ * - 始终写回完整 plugins 对象,避免覆盖其他 plugin 配置。
62
+ * - 宿主持久化成功后才更新当前 context 快照,保证运行态与存储态一致。
63
+ */
64
+ async function persist_chat_channel_patches(params: {
65
+ context: AgentContext;
66
+ patches: Array<{
67
+ channel: ChatChannelName;
68
+ enabled?: boolean;
69
+ channel_account_id?: string | null;
70
+ }>;
71
+ }): Promise<DowncityConfig["plugins"]> {
72
+ const current_plugins = params.context.config.plugins || {};
73
+ const current_chat = current_plugins.chat || {};
74
+ const next_channels = { ...(current_chat.channels || {}) };
75
+
76
+ for (const patch of params.patches) {
77
+ const current_channel = next_channels[patch.channel] || {};
78
+ const next_channel: DowncityChatChannelConfig = { ...current_channel };
79
+ if (typeof patch.enabled === "boolean") {
80
+ next_channel.enabled = patch.enabled;
81
+ }
82
+ if (Object.prototype.hasOwnProperty.call(patch, "channel_account_id")) {
83
+ const channel_account_id = String(patch.channel_account_id || "").trim();
84
+ if (channel_account_id) {
85
+ next_channel.channelAccountId = channel_account_id;
86
+ } else {
87
+ delete next_channel.channelAccountId;
88
+ }
89
+ }
90
+ next_channels[patch.channel] = next_channel;
91
+ }
92
+
93
+ const next_plugins: DowncityConfig["plugins"] = {
94
+ ...current_plugins,
95
+ chat: {
96
+ ...current_chat,
97
+ channels: next_channels,
98
+ },
99
+ };
100
+ await params.context.pluginConfig.persistProjectPlugins(next_plugins);
101
+ params.context.config.plugins = next_plugins;
102
+ return next_plugins;
103
+ }
104
+
52
105
  /**
53
106
  * 执行 `chat.status` action。
54
107
  */
@@ -176,6 +229,10 @@ export async function executeChatOpenAction(params: {
176
229
  }) {
177
230
  const targets = resolveTargetChannels(params.payload.channel);
178
231
  const plugin = getChatRuntimeBindings(params.context);
232
+ await persist_chat_channel_patches({
233
+ context: params.context,
234
+ patches: targets.map((channel) => ({ channel, enabled: true })),
235
+ });
179
236
  for (const channel of targets) {
180
237
  plugin.applyChannelRuntimePatch({
181
238
  channel,
@@ -211,6 +268,10 @@ export async function executeChatCloseAction(params: {
211
268
  }) {
212
269
  const targets = resolveTargetChannels(params.payload.channel);
213
270
  const plugin = getChatRuntimeBindings(params.context);
271
+ await persist_chat_channel_patches({
272
+ context: params.context,
273
+ patches: targets.map((channel) => ({ channel, enabled: false })),
274
+ });
214
275
  for (const channel of targets) {
215
276
  await stopSingleChatChannel(params.state, channel);
216
277
  plugin.applyChannelRuntimePatch({
@@ -293,6 +354,16 @@ export async function executeChatConfigureAction(params: {
293
354
  }
294
355
 
295
356
  const plugin = getChatRuntimeBindings(params.context);
357
+ await persist_chat_channel_patches({
358
+ context: params.context,
359
+ patches: [{
360
+ channel,
361
+ ...(typeof patch.enabled === "boolean" ? { enabled: patch.enabled } : {}),
362
+ ...(Object.prototype.hasOwnProperty.call(patch, "channelAccountId")
363
+ ? { channel_account_id: String(patch.channelAccountId || "").trim() || null }
364
+ : {}),
365
+ }],
366
+ });
296
367
  plugin.applyChannelRuntimePatch({
297
368
  channel,
298
369
  ...(typeof patch.enabled === "boolean" ? { enabled: patch.enabled } : {}),
@@ -3,7 +3,7 @@
3
3
  *
4
4
  * 关键点(中文)
5
5
  * - 渠道配置摘要、状态快照、patch 归一化都收敛在这里。
6
- * - chat.configure 的运行态写入由 ChatPlugin 实例承载,不再落盘到 downcity.json。
6
+ * - chat.configure 的配置持久化由宿主能力承载,运行态更新由 ChatPlugin 实例承载。
7
7
  * - 该模块不直接负责 action 流程控制,只提供可复用的底层能力。
8
8
  */
9
9
 
@@ -37,7 +37,7 @@ function toJsonObject(input: unknown): JsonObject {
37
37
  *
38
38
  * 关键点(中文)
39
39
  * - 不返回明文密钥,只返回布尔“是否已配置”。
40
- * - 字段命名尽量贴近 `downcity.json`,便于前端直接映射编辑。
40
+ * - 字段命名与 Agent 全局配置保持一致,便于前端直接映射编辑。
41
41
  */
42
42
  export function buildChatChannelConfigSummary(
43
43
  context: AgentContext,
@@ -194,7 +194,7 @@ export function normalizeChatChannelConfigPatch(params: {
194
194
  config: Record<string, JsonValue>;
195
195
  }): Record<string, string | number | boolean | null> {
196
196
  const configDefinition = getChatChannelConfiguration(params.channel);
197
- const writableFields = configDefinition.getWritableShipFields();
197
+ const writableFields = configDefinition.get_writable_agent_config_fields();
198
198
  const patch: Record<string, string | number | boolean | null> = {};
199
199
 
200
200
  for (const field of writableFields) {
@@ -101,7 +101,7 @@ export function resolveChannelAccountId(
101
101
  * 关键点(中文)
102
102
  * - 优先使用 ChatPlugin 实例上的显式解析逻辑。
103
103
  * - 若实例只提供 channelAccountId,再从默认全局账号池读取对应账号。
104
- * - 不再从 downcity.json 隐式推断运行时账号。
104
+ * - 不从项目文件隐式推断运行时账号。
105
105
  */
106
106
  export function resolveChannelAccount(
107
107
  context: AgentContext,
@@ -4,7 +4,7 @@
4
4
  * 关键点(中文)
5
5
  * - 渠道 bot 的创建、启动、停止逻辑统一收敛在这里。
6
6
  * - 渠道 bot 状态归属于 chat plugin runtime 实例持有的 `ChatChannelState`。
7
- * - 本模块不处理 downcity.json 写入,也不负责 action 输入输出包装。
7
+ * - 本模块不处理配置持久化,也不负责 action 输入输出包装。
8
8
  */
9
9
 
10
10
  import type { AgentContext } from "@downcity/agent";
@@ -51,28 +51,4 @@ export const CHAT_PLUGIN_POINTS = {
51
51
  * - plugin 可在这里做统计、观测、调试落点。
52
52
  */
53
53
  afterEnqueue: "chat.afterEnqueue",
54
- /**
55
- * 观测入站主体信息。
56
- *
57
- * 说明(中文)
58
- * - 仅做副作用记录,不返回值。
59
- * - ChatPlugin 内置授权能力会使用该点记录主体快照。
60
- */
61
- observePrincipal: "chat.observePrincipal",
62
- /**
63
- * 判定当前入站消息是否允许执行。
64
- *
65
- * 说明(中文)
66
- * - 由 chat plugin runtime 在 ingress 阶段显式调用。
67
- * - ChatPlugin 内置授权能力会使用该点执行角色与权限判定。
68
- */
69
- authorizeIncoming: "chat.authorizeIncoming",
70
- /**
71
- * 解析当前用户角色。
72
- *
73
- * 说明(中文)
74
- * - 主要用于在 history / queue metadata 中补齐授权上下文。
75
- * - ChatPlugin 内置授权能力会使用该点补齐用户角色。
76
- */
77
- resolveUserRole: "chat.resolveUserRole",
78
54
  } as const;
@@ -43,8 +43,6 @@ export function buildQueuedUserMessageWithInfo(params: {
43
43
  `message_id: ${normalizeInfoValue(params.messageId || "unknown")}`,
44
44
  `user_id: ${normalizeInfoValue(params.userId || "unknown")}`,
45
45
  `username: ${normalizeInfoValue(params.username || "unknown")}`,
46
- `role_id: ${normalizeInfoValue(params.roleId || "unknown")}`,
47
- `permissions: ${normalizeInfoValue((params.permissions || []).join(",") || "none")}`,
48
46
  `received_at: ${normalizeInfoValue(receivedAtIso)}`,
49
47
  `received_at_local: ${normalizeInfoValue(formatDateTimeInTimezone(receivedAtDate, runtimeTimezone))}`,
50
48
  `runtime_timezone: ${normalizeInfoValue(runtimeTimezone)}`,
@@ -27,7 +27,7 @@ export type ChatChannelConfigurationFieldType =
27
27
  * 配置字段来源枚举。
28
28
  */
29
29
  export type ChatChannelConfigurationFieldSource =
30
- | "ship_json"
30
+ | "agent_config"
31
31
  | "bot_account"
32
32
  | "env_fallback";
33
33
 
@@ -70,7 +70,7 @@ export interface ChatChannelConfigurationField {
70
70
  */
71
71
  type: ChatChannelConfigurationFieldType;
72
72
  /**
73
- * 字段值来源(downcity.json / chat account / env fallback)。
73
+ * 字段值来源(Agent config / chat account / env fallback)。
74
74
  */
75
75
  source: ChatChannelConfigurationFieldSource;
76
76
  /**
@@ -145,9 +145,9 @@ export interface ChatChannelConfigurationDescriptor {
145
145
  */
146
146
  fields: {
147
147
  /**
148
- * `downcity.json` 可声明字段。
148
+ * Agent 全局配置可声明字段。
149
149
  */
150
- ship: ChatChannelConfigurationField[];
150
+ agent_config: ChatChannelConfigurationField[];
151
151
  /**
152
152
  * `channel_accounts` 字段。
153
153
  */
@@ -0,0 +1,335 @@
1
+ /**
2
+ * Chat Access 领域类型。
3
+ *
4
+ * 关键点(中文)
5
+ * - Chat Access 只负责外部聊天用户进入当前 Agent 前的准入判定。
6
+ * - 用户唯一身份由 channel、issuer、subject_id 共同确定。
7
+ * - `all` 仅用于管理命令输入,持久化时展开为 direct/group 两条明确记录。
8
+ */
9
+
10
+ import type { ChatDispatchChannel } from "@/chat/types/ChatDispatcher.js";
11
+
12
+ /** Chat Plugin 对外暴露的 Access Action。 */
13
+ export const CHAT_ACCESS_ACTIONS = {
14
+ /** 读取 Principal、Grant 和 Request 快照。 */
15
+ snapshot: "access-snapshot",
16
+ /** 批准待处理 Request。 */
17
+ approve: "access-approve",
18
+ /** 拒绝待处理 Request。 */
19
+ deny: "access-deny",
20
+ /** 直接设置已知 Principal 的 Access。 */
21
+ set: "access-set",
22
+ /** 撤销已知 Principal 的 Access。 */
23
+ revoke: "access-revoke",
24
+ } as const;
25
+
26
+ /** Chat Access 支持的消息范围。 */
27
+ export type ChatAccessScope = "direct" | "group";
28
+
29
+ /** Chat Access 管理入口支持的范围。 */
30
+ export type ChatAccessScopeInput = ChatAccessScope | "all";
31
+
32
+ /** Chat Access Grant 效果。 */
33
+ export type ChatAccessEffect = "allow" | "deny";
34
+
35
+ /** Chat Access Request 状态。 */
36
+ export type ChatAccessRequestStatus =
37
+ | "pending"
38
+ | "approved"
39
+ | "denied"
40
+ | "expired";
41
+
42
+ /** Chat Access 判定原因。 */
43
+ export type ChatAccessDecisionReason =
44
+ | "grant_allowed"
45
+ | "grant_denied"
46
+ | "request_pending"
47
+ | "identity_missing";
48
+
49
+ /**
50
+ * Chat 平台提供的原始身份与消息来源。
51
+ */
52
+ export interface ChatAccessIdentityInput {
53
+ /** 当前消息来源渠道。 */
54
+ channel: ChatDispatchChannel;
55
+ /** 当前 Bot/App 的稳定账号标识,不得包含密钥。 */
56
+ issuer: string;
57
+ /** 平台用户稳定 ID。 */
58
+ subject_id: string;
59
+ /** 用户展示名称。 */
60
+ display_name?: string;
61
+ /** 当前平台会话 ID。 */
62
+ chat_id: string;
63
+ /** 当前平台会话类型。 */
64
+ chat_type?: string;
65
+ /** 当前会话展示名称。 */
66
+ chat_title?: string;
67
+ }
68
+
69
+ /**
70
+ * Chat Access 内部规范化主体。
71
+ */
72
+ export interface ChatAccessPrincipal {
73
+ /** 内部稳定主体 ID。 */
74
+ principal_id: string;
75
+ /** 当前主体来源渠道。 */
76
+ channel: ChatDispatchChannel;
77
+ /** 当前主体所在 Bot/App 账号边界。 */
78
+ issuer: string;
79
+ /** 平台用户稳定 ID。 */
80
+ subject_id: string;
81
+ /** 最近观测到的展示名称。 */
82
+ display_name?: string;
83
+ /** 首次观测时间。 */
84
+ first_seen_at: string;
85
+ /** 最近观测时间。 */
86
+ last_seen_at: string;
87
+ /** 最近发言会话 ID。 */
88
+ last_chat_id?: string;
89
+ /** 最近发言会话类型。 */
90
+ last_chat_type?: string;
91
+ }
92
+
93
+ /**
94
+ * Chat Access Grant。
95
+ */
96
+ export interface ChatAccessGrant {
97
+ /** Grant 稳定 ID。 */
98
+ grant_id: string;
99
+ /** 关联主体 ID。 */
100
+ principal_id: string;
101
+ /** Grant 适用范围。 */
102
+ scope: ChatAccessScope;
103
+ /** Allow 或 Deny。 */
104
+ effect: ChatAccessEffect;
105
+ /** 执行该变更的可信操作者。 */
106
+ created_by: string;
107
+ /** 创建时间。 */
108
+ created_at: string;
109
+ /** 最近更新时间。 */
110
+ updated_at: string;
111
+ }
112
+
113
+ /**
114
+ * Chat Access Request。
115
+ */
116
+ export interface ChatAccessRequest {
117
+ /** Request 稳定 ID。 */
118
+ request_id: string;
119
+ /** 关联主体 ID。 */
120
+ principal_id: string;
121
+ /** 请求准入范围。 */
122
+ scope: ChatAccessScope;
123
+ /** 触发请求的平台会话 ID。 */
124
+ chat_id: string;
125
+ /** 触发请求的平台会话类型。 */
126
+ chat_type: string;
127
+ /** 当前请求状态。 */
128
+ status: ChatAccessRequestStatus;
129
+ /** 解决该请求的可信操作者。 */
130
+ resolved_by?: string;
131
+ /** 创建时间。 */
132
+ created_at: string;
133
+ /** 最近一次重复请求时间。 */
134
+ last_requested_at: string;
135
+ /** 请求解决时间。 */
136
+ resolved_at?: string;
137
+ }
138
+
139
+ /**
140
+ * 带主体详情的请求展示项。
141
+ */
142
+ export interface ChatAccessRequestView extends ChatAccessRequest {
143
+ /** 当前请求对应主体。 */
144
+ principal: ChatAccessPrincipal;
145
+ }
146
+
147
+ /**
148
+ * 带 Grant 的主体展示项。
149
+ */
150
+ export interface ChatAccessPrincipalView {
151
+ /** 当前主体。 */
152
+ principal: ChatAccessPrincipal;
153
+ /** 当前主体所有 Grant。 */
154
+ grants: ChatAccessGrant[];
155
+ }
156
+
157
+ /**
158
+ * Chat Access 入站判定结果。
159
+ */
160
+ export interface ChatAccessDecision {
161
+ /** 是否允许进入 Agent。 */
162
+ allowed: boolean;
163
+ /** 归一化主体 ID;身份缺失时为空字符串。 */
164
+ principal_id: string;
165
+ /** 当前消息对应范围。 */
166
+ scope: ChatAccessScope;
167
+ /** 稳定判定原因。 */
168
+ reason: ChatAccessDecisionReason;
169
+ /** 未批准时创建或复用的 Request ID。 */
170
+ request_id?: string;
171
+ }
172
+
173
+ /**
174
+ * 批准请求输入。
175
+ */
176
+ export interface ApproveChatAccessRequestInput {
177
+ /** Request ID。 */
178
+ request_id: string;
179
+ /** 可选范围覆盖;默认使用请求自身范围。 */
180
+ scope?: ChatAccessScopeInput;
181
+ /** 执行批准的可信操作者。 */
182
+ operator: string;
183
+ }
184
+
185
+ /**
186
+ * 拒绝请求输入。
187
+ */
188
+ export interface DenyChatAccessRequestInput {
189
+ /** Request ID。 */
190
+ request_id: string;
191
+ /** 可选范围覆盖;默认使用请求自身范围。 */
192
+ scope?: ChatAccessScopeInput;
193
+ /** 执行拒绝的可信操作者。 */
194
+ operator: string;
195
+ }
196
+
197
+ /**
198
+ * 撤销 Grant 输入。
199
+ */
200
+ export interface RevokeChatAccessGrantInput {
201
+ /** Principal ID。 */
202
+ principal_id: string;
203
+ /** 要撤销的范围。 */
204
+ scope: ChatAccessScopeInput;
205
+ /** 执行撤销的可信操作者。 */
206
+ operator: string;
207
+ }
208
+
209
+ /** ChatAccessService 构造参数。 */
210
+ export interface ChatAccessServiceOptions {
211
+ /** 当前 Agent 项目根目录。 */
212
+ project_root: string;
213
+ }
214
+
215
+ /** 直接设置 Principal Grant 的输入。 */
216
+ export interface SetChatAccessPrincipalEffectInput {
217
+ /** Principal 稳定 ID。 */
218
+ principal_id: string;
219
+ /** 要设置的 Chat 消息范围。 */
220
+ scope: ChatAccessScopeInput;
221
+ /** 要写入的 Allow/Deny 效果。 */
222
+ effect: ChatAccessEffect;
223
+ /** 执行设置的可信操作者。 */
224
+ operator: string;
225
+ }
226
+
227
+ /** Store 新增或更新 Principal 的输入。 */
228
+ export interface UpsertChatAccessPrincipalInput {
229
+ /** Principal 来源渠道。 */
230
+ channel: ChatDispatchChannel;
231
+ /** 当前 Bot/App 的稳定账号边界。 */
232
+ issuer: string;
233
+ /** 平台用户稳定 ID。 */
234
+ subject_id: string;
235
+ /** 最近观测到的展示名称。 */
236
+ display_name?: string;
237
+ /** 最近发言会话 ID。 */
238
+ chat_id?: string;
239
+ /** 最近发言会话类型。 */
240
+ chat_type?: string;
241
+ /** 迁移时提供的首次观测时间。 */
242
+ first_seen_at?: string;
243
+ /** 迁移时提供的最近观测时间。 */
244
+ last_seen_at?: string;
245
+ }
246
+
247
+ /** Store 新增或更新 Grant 的输入。 */
248
+ export interface UpsertChatAccessGrantInput {
249
+ /** 关联 Principal 稳定 ID。 */
250
+ principal_id: string;
251
+ /** Grant 适用范围。 */
252
+ scope: ChatAccessScope;
253
+ /** Grant 的 Allow/Deny 效果。 */
254
+ effect: ChatAccessEffect;
255
+ /** 执行变更的可信操作者。 */
256
+ operator: string;
257
+ }
258
+
259
+ /** Store 创建或复用 Request 的输入。 */
260
+ export interface CreateChatAccessRequestInput {
261
+ /** 关联 Principal 稳定 ID。 */
262
+ principal_id: string;
263
+ /** 请求准入范围。 */
264
+ scope: ChatAccessScope;
265
+ /** 触发请求的平台会话 ID。 */
266
+ chat_id: string;
267
+ /** 触发请求的平台会话类型。 */
268
+ chat_type?: string;
269
+ }
270
+
271
+ /** Store 创建或复用 Request 的结果。 */
272
+ export interface CreateChatAccessRequestResult {
273
+ /** 创建或复用后的 Request。 */
274
+ request: ChatAccessRequest;
275
+ /** 本次是否创建了新 Request。 */
276
+ created: boolean;
277
+ }
278
+
279
+ /** Store 解决单个 Request 的输入。 */
280
+ export interface ResolveChatAccessRequestStoreInput {
281
+ /** 要解决的 Request ID。 */
282
+ request_id: string;
283
+ /** Request 最终状态。 */
284
+ status: "approved" | "denied";
285
+ /** 执行操作的可信操作者。 */
286
+ operator: string;
287
+ }
288
+
289
+ /** Store 批量解决 Principal pending Request 的输入。 */
290
+ export interface ResolvePendingChatAccessRequestsInput {
291
+ /** 关联 Principal 稳定 ID。 */
292
+ principal_id: string;
293
+ /** 要解决的明确范围集合。 */
294
+ scopes: ChatAccessScope[];
295
+ /** Request 最终状态。 */
296
+ status: "approved" | "denied";
297
+ /** 执行操作的可信操作者。 */
298
+ operator: string;
299
+ }
300
+
301
+ /** Store 写入审计事件的输入。 */
302
+ export interface InsertChatAccessAuditEventInput {
303
+ /** 可选关联 Principal ID。 */
304
+ principal_id?: string;
305
+ /** 可选关联 Request ID。 */
306
+ request_id?: string;
307
+ /** 稳定审计动作名称。 */
308
+ action: string;
309
+ /** 可选 Chat 消息范围。 */
310
+ scope?: ChatAccessScope;
311
+ /** 可选判定或 Grant 效果。 */
312
+ decision?: string;
313
+ /** 可选可信操作者。 */
314
+ operator?: string;
315
+ /** 可选结构化审计详情。 */
316
+ detail?: Record<string, unknown>;
317
+ }
318
+
319
+ /**
320
+ * 请求列表过滤条件。
321
+ */
322
+ export interface ListChatAccessRequestsInput {
323
+ /** 可选状态过滤。 */
324
+ status?: ChatAccessRequestStatus;
325
+ }
326
+
327
+ /**
328
+ * Chat Access 快照。
329
+ */
330
+ export interface ChatAccessSnapshot {
331
+ /** 当前 Principal 列表。 */
332
+ principals: ChatAccessPrincipalView[];
333
+ /** 当前 Request 列表。 */
334
+ requests: ChatAccessRequestView[];
335
+ }
@@ -7,7 +7,6 @@
7
7
  * - 所有字段均保持可序列化,便于 system prompt 与入站消息文本复用。
8
8
  */
9
9
 
10
- import type { ChatAuthorizationPermission } from "@/auth/types/AuthPlugin.js";
11
10
  import type { ChatDispatchChannel } from "@/chat/types/ChatDispatcher.js";
12
11
 
13
12
  /**
@@ -103,22 +102,6 @@ export interface QueuedUserInfoInput {
103
102
  */
104
103
  username?: string;
105
104
 
106
- /**
107
- * 当前用户在授权系统中的角色 ID。
108
- *
109
- * 说明(中文)
110
- * - 例如 `default`、`member`、`admin`。
111
- */
112
- roleId?: string;
113
-
114
- /**
115
- * 当前用户拥有的权限集合。
116
- *
117
- * 说明(中文)
118
- * - 仅描述授权快照,不代表平台原生权限模型。
119
- */
120
- permissions?: ChatAuthorizationPermission[];
121
-
122
105
  /**
123
106
  * 当前消息接收时间。
124
107
  *
package/src/index.ts CHANGED
@@ -32,18 +32,13 @@ export { WorkboardPlugin } from "./workboard/Plugin.js";
32
32
  export { TaskPlugin } from "./task/TaskPlugin.js";
33
33
  export { MemoryPlugin } from "./memory/MemoryPlugin.js";
34
34
  export {
35
- listChatAuthorizationRoles,
36
- readChatAuthorizationConfigSync,
37
- setChatAuthorizationUserRole,
38
- } from "./auth/runtime/AuthorizationConfig.js";
39
- export { resolveAuthorizedUserRole } from "./auth/runtime/AuthorizationPolicy.js";
40
- export {
41
- CHAT_AUTHORIZATION_ACTIONS,
42
- CHAT_AUTHORIZATION_CHANNELS,
43
- CHAT_AUTHORIZATION_POINTS,
44
- createDefaultChatAuthorizationRoles,
45
- isChatAuthorizationChannel,
46
- } from "./auth/types/AuthPlugin.js";
35
+ ChatAccessService,
36
+ is_chat_access_channel,
37
+ resolve_chat_access_scope,
38
+ resolve_chat_access_scopes,
39
+ } from "./chat/access/ChatAccessService.js";
40
+ export { get_chat_access_db_path } from "./chat/access/ChatAccessStore.js";
41
+ export { CHAT_ACCESS_ACTIONS } from "./chat/types/ChatAccess.js";
47
42
 
48
43
  export type {
49
44
  ChatChannelAccountListItem,
@@ -121,22 +116,23 @@ export type {
121
116
  ImagePluginTextContent,
122
117
  } from "./image/types/ImagePlugin.js";
123
118
  export type {
124
- ChatAuthorizationCatalog,
125
- ChatAuthorizationChannel,
126
- ChatAuthorizationConfig,
127
- ChatAuthorizationDecision,
128
- ChatAuthorizationEvaluateInput,
129
- ChatAuthorizationEvaluateResult,
130
- ChatAuthorizationObservePrincipalPayload,
131
- ChatAuthorizationObservedChat,
132
- ChatAuthorizationObservedUser,
133
- ChatAuthorizationPermission,
134
- ChatAuthorizationPermissionMeta,
135
- ChatAuthorizationResolveUserRolePayload,
136
- ChatAuthorizationRole,
137
- ChatAuthorizationSetUserRolePayload,
138
- ChatAuthorizationSnapshot,
139
- ChatAuthorizationStateFile,
140
- ChatAuthorizationWriteConfigPayload,
141
- ChatChannelAuthorizationConfig,
142
- } from "./auth/types/AuthPlugin.js";
119
+ ApproveChatAccessRequestInput,
120
+ ChatAccessDecision,
121
+ ChatAccessDecisionReason,
122
+ ChatAccessEffect,
123
+ ChatAccessGrant,
124
+ ChatAccessIdentityInput,
125
+ ChatAccessPrincipal,
126
+ ChatAccessPrincipalView,
127
+ ChatAccessRequest,
128
+ ChatAccessRequestStatus,
129
+ ChatAccessRequestView,
130
+ ChatAccessScope,
131
+ ChatAccessScopeInput,
132
+ ChatAccessServiceOptions,
133
+ ChatAccessSnapshot,
134
+ DenyChatAccessRequestInput,
135
+ ListChatAccessRequestsInput,
136
+ RevokeChatAccessGrantInput,
137
+ SetChatAccessPrincipalEffectInput,
138
+ } from "./chat/types/ChatAccess.js";
@@ -2,7 +2,7 @@
2
2
  * SkillPlugin 构造参数归一化工具。
3
3
  *
4
4
  * 关键点(中文)
5
- * - SkillPlugin 不再读取 `downcity.json.plugins.skill` 私有配置。
5
+ * - SkillPlugin 只读取 constructor 配置,不读取项目配置文件。
6
6
  * - constructor options 是唯一行为配置入口,便于 SDK 用户直接理解。
7
7
  * - 这里只做默认值与去重,不做文件系统扫描。
8
8
  */
@@ -3,7 +3,7 @@
3
3
  *
4
4
  * 关键点(中文)
5
5
  * - roots 分三类:项目内(project)、用户目录(home),以及构造参数路径(custom)
6
- * - SkillPlugin constructor 是唯一配置入口,不再读取 downcity.json 的 skill 私有配置
6
+ * - SkillPlugin constructor 是唯一配置入口,不读取项目配置文件
7
7
  * - 兼容 `<any>/skills` 这种布局:如果 root basename 不是 `skills` 且其子目录 `skills/` 存在,则优先扫描 `<root>/skills`
8
8
  */
9
9