@downcity/plugins 1.0.57 → 1.0.59

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 (134) hide show
  1. package/bin/BuiltinPlugins.d.ts.map +1 -1
  2. package/bin/BuiltinPlugins.js +0 -2
  3. package/bin/BuiltinPlugins.js.map +1 -1
  4. package/bin/auth/types/AuthPlugin.d.ts +12 -16
  5. package/bin/auth/types/AuthPlugin.d.ts.map +1 -1
  6. package/bin/auth/types/AuthPlugin.js +9 -13
  7. package/bin/auth/types/AuthPlugin.js.map +1 -1
  8. package/bin/chat/ChatPlugin.d.ts +37 -6
  9. package/bin/chat/ChatPlugin.d.ts.map +1 -1
  10. package/bin/chat/ChatPlugin.js +58 -80
  11. package/bin/chat/ChatPlugin.js.map +1 -1
  12. package/bin/chat/Index.d.ts +4 -1
  13. package/bin/chat/Index.d.ts.map +1 -1
  14. package/bin/chat/Index.js +2 -1
  15. package/bin/chat/Index.js.map +1 -1
  16. package/bin/chat/channels/Configuration.d.ts +1 -1
  17. package/bin/chat/channels/Configuration.js +1 -1
  18. package/bin/chat/channels/RuntimeChannel.d.ts +145 -0
  19. package/bin/chat/channels/RuntimeChannel.d.ts.map +1 -0
  20. package/bin/chat/channels/RuntimeChannel.js +148 -0
  21. package/bin/chat/channels/RuntimeChannel.js.map +1 -0
  22. package/bin/chat/runtime/ChatAuthorizationRuntime.d.ts +22 -0
  23. package/bin/chat/runtime/ChatAuthorizationRuntime.d.ts.map +1 -0
  24. package/bin/chat/runtime/ChatAuthorizationRuntime.js +189 -0
  25. package/bin/chat/runtime/ChatAuthorizationRuntime.js.map +1 -0
  26. package/bin/chat/runtime/ChatChannelActions.d.ts.map +1 -1
  27. package/bin/chat/runtime/ChatChannelActions.js +19 -9
  28. package/bin/chat/runtime/ChatChannelActions.js.map +1 -1
  29. package/bin/chat/runtime/ChatChannelConfig.d.ts +2 -18
  30. package/bin/chat/runtime/ChatChannelConfig.d.ts.map +1 -1
  31. package/bin/chat/runtime/ChatChannelConfig.js +2 -73
  32. package/bin/chat/runtime/ChatChannelConfig.js.map +1 -1
  33. package/bin/chat/runtime/ChatChannelCore.d.ts +22 -1
  34. package/bin/chat/runtime/ChatChannelCore.d.ts.map +1 -1
  35. package/bin/chat/runtime/ChatChannelCore.js +5 -5
  36. package/bin/chat/runtime/ChatChannelCore.js.map +1 -1
  37. package/bin/chat/runtime/ChatPluginActionRegistry.js +1 -1
  38. package/bin/chat/runtime/ChatPluginActionRegistry.js.map +1 -1
  39. package/bin/chat/runtime/PluginPoints.d.ts +3 -3
  40. package/bin/chat/runtime/PluginPoints.js +3 -3
  41. package/bin/chat/types/ChannelStatus.d.ts +1 -1
  42. package/bin/chat/types/ChatPluginOptions.d.ts +76 -0
  43. package/bin/chat/types/ChatPluginOptions.d.ts.map +1 -0
  44. package/bin/chat/types/ChatPluginOptions.js +10 -0
  45. package/bin/chat/types/ChatPluginOptions.js.map +1 -0
  46. package/bin/index.d.ts +4 -3
  47. package/bin/index.d.ts.map +1 -1
  48. package/bin/index.js +2 -2
  49. package/bin/index.js.map +1 -1
  50. package/bin/skill/Action.d.ts.map +1 -1
  51. package/bin/skill/Action.js +2 -2
  52. package/bin/skill/Action.js.map +1 -1
  53. package/bin/skill/Command.js +5 -5
  54. package/bin/skill/Command.js.map +1 -1
  55. package/bin/skill/Plugin.js +1 -1
  56. package/bin/skill/Plugin.js.map +1 -1
  57. package/bin/skill/runtime/Discovery.d.ts +4 -4
  58. package/bin/skill/runtime/Discovery.d.ts.map +1 -1
  59. package/bin/skill/runtime/Discovery.js +5 -5
  60. package/bin/skill/runtime/Discovery.js.map +1 -1
  61. package/bin/skill/runtime/Paths.d.ts +1 -5
  62. package/bin/skill/runtime/Paths.d.ts.map +1 -1
  63. package/bin/skill/runtime/Paths.js +1 -9
  64. package/bin/skill/runtime/Paths.js.map +1 -1
  65. package/bin/skill/runtime/Prompt.d.ts +2 -2
  66. package/bin/skill/runtime/Prompt.d.ts.map +1 -1
  67. package/bin/skill/runtime/Prompt.js +3 -3
  68. package/bin/skill/runtime/Prompt.js.map +1 -1
  69. package/bin/skill/runtime/Store.d.ts +2 -2
  70. package/bin/skill/runtime/Store.d.ts.map +1 -1
  71. package/bin/skill/runtime/Store.js.map +1 -1
  72. package/bin/skill/runtime/SystemProvider.js +4 -4
  73. package/bin/skill/runtime/SystemProvider.js.map +1 -1
  74. package/bin/skill/runtime/Types.d.ts +3 -3
  75. package/bin/skill/runtime/Types.d.ts.map +1 -1
  76. package/bin/skill/types/{ClaudeSkill.d.ts → SkillDefinition.d.ts} +4 -4
  77. package/bin/skill/types/SkillDefinition.d.ts.map +1 -0
  78. package/bin/skill/types/{ClaudeSkill.js → SkillDefinition.js} +2 -2
  79. package/bin/skill/types/SkillDefinition.js.map +1 -0
  80. package/bin/skill/types/SkillPlugin.d.ts +2 -2
  81. package/bin/skill/types/SkillPlugin.d.ts.map +1 -1
  82. package/bin/web/Plugin.js +1 -1
  83. package/bin/web/Plugin.js.map +1 -1
  84. package/bin/web/runtime/Install.js +2 -2
  85. package/bin/web/runtime/Install.js.map +1 -1
  86. package/bin/web/types/WebPlugin.d.ts +2 -1
  87. package/bin/web/types/WebPlugin.d.ts.map +1 -1
  88. package/bin/workboard/Plugin.d.ts +23 -3
  89. package/bin/workboard/Plugin.d.ts.map +1 -1
  90. package/bin/workboard/Plugin.js +66 -85
  91. package/bin/workboard/Plugin.js.map +1 -1
  92. package/package.json +1 -1
  93. package/src/BuiltinPlugins.ts +0 -2
  94. package/src/auth/types/AuthPlugin.ts +12 -17
  95. package/src/chat/ChatPlugin.ts +92 -89
  96. package/src/chat/Index.ts +18 -1
  97. package/src/chat/channels/Configuration.ts +1 -1
  98. package/src/chat/channels/RuntimeChannel.ts +264 -0
  99. package/src/chat/runtime/ChatAuthorizationRuntime.ts +229 -0
  100. package/src/chat/runtime/ChatChannelActions.ts +24 -9
  101. package/src/chat/runtime/ChatChannelConfig.ts +2 -100
  102. package/src/chat/runtime/ChatChannelCore.ts +20 -8
  103. package/src/chat/runtime/ChatPluginActionRegistry.ts +1 -1
  104. package/src/chat/runtime/PluginPoints.ts +3 -3
  105. package/src/chat/types/ChannelStatus.ts +1 -1
  106. package/src/chat/types/ChatPluginOptions.ts +79 -0
  107. package/src/index.ts +17 -6
  108. package/src/skill/Action.ts +10 -7
  109. package/src/skill/Command.ts +5 -5
  110. package/src/skill/Plugin.ts +1 -1
  111. package/src/skill/runtime/Discovery.ts +14 -11
  112. package/src/skill/runtime/Paths.ts +1 -13
  113. package/src/skill/runtime/Prompt.ts +5 -5
  114. package/src/skill/runtime/Store.ts +6 -3
  115. package/src/skill/runtime/SystemProvider.ts +4 -4
  116. package/src/skill/runtime/Types.ts +3 -3
  117. package/src/skill/types/{ClaudeSkill.ts → SkillDefinition.ts} +3 -3
  118. package/src/skill/types/SkillPlugin.ts +2 -2
  119. package/src/web/Plugin.ts +1 -1
  120. package/src/web/runtime/Install.ts +3 -3
  121. package/src/web/types/WebPlugin.ts +2 -2
  122. package/src/workboard/Plugin.ts +80 -95
  123. package/bin/auth/Plugin.d.ts +0 -17
  124. package/bin/auth/Plugin.d.ts.map +0 -1
  125. package/bin/auth/Plugin.js +0 -199
  126. package/bin/auth/Plugin.js.map +0 -1
  127. package/bin/chat/ChatPluginTypes.d.ts +0 -122
  128. package/bin/chat/ChatPluginTypes.d.ts.map +0 -1
  129. package/bin/chat/ChatPluginTypes.js +0 -10
  130. package/bin/chat/ChatPluginTypes.js.map +0 -1
  131. package/bin/skill/types/ClaudeSkill.d.ts.map +0 -1
  132. package/bin/skill/types/ClaudeSkill.js.map +0 -1
  133. package/src/auth/Plugin.ts +0 -237
  134. package/src/chat/ChatPluginTypes.ts +0 -126
@@ -1 +1 @@
1
- {"version":3,"file":"Plugin.d.ts","sourceRoot":"","sources":["../../src/workboard/Plugin.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,oDAAoD,CAAC;AAkGhF;;GAEG;AACH,qBAAa,eAAgB,SAAQ,UAAU;IAC7C,QAAQ,CAAC,IAAI,eAAe;;CAM7B"}
1
+ {"version":3,"file":"Plugin.d.ts","sourceRoot":"","sources":["../../src/workboard/Plugin.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,oDAAoD,CAAC;AAChF,OAAO,KAAK,EACV,aAAa,EACb,oBAAoB,EACrB,MAAM,iDAAiD,CAAC;AAqBzD;;GAEG;AACH,qBAAa,eAAgB,SAAQ,UAAU;IAC7C;;OAEG;IACH,QAAQ,CAAC,IAAI,eAAe;IAE5B;;OAEG;IACH,QAAQ,CAAC,KAAK,wBAAwB;IAEtC;;OAEG;IACH,QAAQ,CAAC,WAAW,qJACgI;IAEpJ;;OAEG;IACH,QAAQ,CAAC,OAAO,EAAE,aAAa,CAY7B;IAEF;;OAEG;IACH,QAAQ,CAAC,IAAI,EAAE,oBAAoB,CA0BjC;CACH"}
@@ -2,102 +2,83 @@
2
2
  * Workboard Plugin。
3
3
  *
4
4
  * 关键点(中文)
5
- * - workboard 是一个 runtime 观测面板插件,负责提供结构化工作快照。
6
- * - 当前同时通过 plugin action 与 HTTP 注入提供快照,供 Town RPC 与 Town HTTP gateway 复用。
5
+ * - workboard runtime 观测面板插件,负责提供结构化工作快照。
6
+ * - plugin action 与 HTTP route 共享同一份快照读取逻辑。
7
+ * - 是否启用由是否注册该 plugin 决定,不再读取项目配置做二次开关。
7
8
  */
8
9
  import { BasePlugin } from "@downcity/agent/internal/plugin/core/BasePlugin.js";
9
- import { isPluginEnabled } from "@downcity/agent/internal/plugin/core/Activation.js";
10
10
  import { getWorkboardSnapshotStore } from "../workboard/runtime/Store.js";
11
- function createWorkboardPluginDefinition(plugin) {
11
+ /**
12
+ * 读取 workboard 快照。
13
+ */
14
+ async function readWorkboardSnapshot(context) {
15
+ const snapshot = await getWorkboardSnapshotStore({
16
+ contextResolver: () => context,
17
+ }).readSnapshot();
12
18
  return {
13
- name: "workboard",
14
- title: "Workboard Snapshot",
15
- description: "Collects structured runtime activity snapshots so console surfaces can show what the current agent is doing now and what it recently worked on.",
16
- availability(context) {
17
- if (!isPluginEnabled({ plugin, context })) {
19
+ success: true,
20
+ snapshot,
21
+ };
22
+ }
23
+ /**
24
+ * WorkboardPlugin:运行态观测面板插件。
25
+ */
26
+ export class WorkboardPlugin extends BasePlugin {
27
+ /**
28
+ * 当前 plugin 稳定名称。
29
+ */
30
+ name = "workboard";
31
+ /**
32
+ * 插件标题。
33
+ */
34
+ title = "Workboard Snapshot";
35
+ /**
36
+ * 插件说明。
37
+ */
38
+ description = "Collects structured runtime activity snapshots so console surfaces can show what the current agent is doing now and what it recently worked on.";
39
+ /**
40
+ * Workboard 对外 action。
41
+ */
42
+ actions = {
43
+ snapshot: {
44
+ execute: async ({ context }) => {
45
+ const response = await readWorkboardSnapshot(context);
18
46
  return {
19
- enabled: false,
20
- available: false,
21
- reasons: ["workboard plugin disabled in project config"],
47
+ success: true,
48
+ data: {
49
+ snapshot: response.snapshot,
50
+ },
22
51
  };
23
- }
24
- return {
25
- enabled: true,
26
- available: true,
27
- reasons: [],
28
- };
29
- },
30
- actions: {
31
- snapshot: {
32
- execute: async ({ context }) => {
33
- const availability = await plugin.availability?.(context);
34
- if (availability && availability.available !== true) {
35
- return {
36
- success: false,
37
- error: availability.reasons.join("; ") || "workboard unavailable",
38
- };
39
- }
40
- const snapshot = await getWorkboardSnapshotStore({
41
- contextResolver: () => context,
42
- }).readSnapshot();
43
- return {
44
- success: true,
45
- data: {
46
- snapshot,
47
- },
48
- };
49
- },
50
52
  },
51
53
  },
52
- http: {
53
- server: {
54
- authPolicies: [
55
- {
56
- path: "/api/workboard/*",
57
- method: "GET",
58
- requireAuth: true,
59
- anyPermissions: ["agent.read"],
60
- },
61
- ],
62
- register({ app, getContext }) {
63
- app.get("/api/workboard/snapshot", async (c) => {
64
- try {
65
- const availability = await plugin.availability?.(getContext());
66
- if (availability && availability.available !== true) {
67
- return c.json({
68
- success: false,
69
- error: availability.reasons.join("; ") || "workboard unavailable",
70
- }, 503);
71
- }
72
- const snapshot = await getWorkboardSnapshotStore({
73
- contextResolver: getContext,
74
- }).readSnapshot();
75
- const payload = {
76
- success: true,
77
- snapshot,
78
- };
79
- return c.json(payload);
80
- }
81
- catch (error) {
82
- return c.json({
83
- success: false,
84
- error: error instanceof Error ? error.message : String(error),
85
- }, 500);
86
- }
87
- });
54
+ };
55
+ /**
56
+ * Workboard HTTP route。
57
+ */
58
+ http = {
59
+ server: {
60
+ authPolicies: [
61
+ {
62
+ path: "/api/workboard/*",
63
+ method: "GET",
64
+ requireAuth: true,
65
+ anyPermissions: ["agent.read"],
88
66
  },
67
+ ],
68
+ register({ app, getContext }) {
69
+ app.get("/api/workboard/snapshot", async (c) => {
70
+ try {
71
+ return c.json(await readWorkboardSnapshot(getContext()));
72
+ }
73
+ catch (error) {
74
+ return c.json({
75
+ success: false,
76
+ error: error instanceof Error ? error.message : String(error),
77
+ }, 500);
78
+ }
79
+ });
89
80
  },
90
81
  },
91
82
  };
92
83
  }
93
- /**
94
- * WorkboardPlugin:运行态观测面板插件。
95
- */
96
- export class WorkboardPlugin extends BasePlugin {
97
- name = "workboard";
98
- constructor() {
99
- super();
100
- Object.assign(this, createWorkboardPluginDefinition(this));
101
- }
102
- }
103
84
  //# sourceMappingURL=Plugin.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"Plugin.js","sourceRoot":"","sources":["../../src/workboard/Plugin.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,oDAAoD,CAAC;AAGhF,OAAO,EAAE,eAAe,EAAE,MAAM,oDAAoD,CAAC;AACrF,OAAO,EAAE,yBAAyB,EAAE,MAAM,8BAA8B,CAAC;AAGzE,SAAS,+BAA+B,CAAC,MAAc;IACrD,OAAO;QACL,IAAI,EAAE,WAAW;QACjB,KAAK,EAAE,oBAAoB;QAC3B,WAAW,E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E,CAAC,EAAE,EAAE;oBAC7C,IAAI,CAAC;wBACH,OAAO,CAAC,CAAC,IAAI,CAAC,MAAM,qBAAqB,CAAC,UAAU,EAAE,CAAC,CAAC,CAAC;oBAC3D,CAAC;oBAAC,OAAO,KAAK,EAAE,CAAC;wBACf,OAAO,CAAC,CAAC,IAAI,CACX;4BACE,OAAO,EAAE,KAAK;4BACd,KAAK,EAAE,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC;yBAC9D,EACD,GAAG,CACJ,CAAC;oBACJ,CAAC;gBACH,CAAC,CAAC,CAAC;YACL,CAAC;SACF;KACF,CAAC;CACH"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@downcity/plugins",
3
- "version": "1.0.57",
3
+ "version": "1.0.59",
4
4
  "type": "module",
5
5
  "description": "Downcity 内建 plugin 集合包",
6
6
  "main": "./bin/index.js",
@@ -8,7 +8,6 @@
8
8
  */
9
9
 
10
10
  import type { BasePlugin } from "@downcity/agent/internal/plugin/core/BasePlugin.js";
11
- import { ChatAuthorizationPlugin } from "@/auth/Plugin.js";
12
11
  import { SkillPlugin } from "@/skill/Plugin.js";
13
12
  import { WebPlugin } from "@/web/Plugin.js";
14
13
  import { WorkboardPlugin } from "@/workboard/Plugin.js";
@@ -27,7 +26,6 @@ export type BuiltinPluginClass<T extends BasePlugin = BasePlugin> = new () => T;
27
26
  * 全部内建 plugin classes。
28
27
  */
29
28
  export const BUILTIN_PLUGIN_CLASSES: BuiltinPluginClass[] = [
30
- ChatAuthorizationPlugin,
31
29
  SkillPlugin,
32
30
  WebPlugin,
33
31
  WorkboardPlugin,
@@ -1,20 +1,15 @@
1
1
  /**
2
- * ChatAuthorizationPlugin 类型与契约定义。
2
+ * ChatAuthorization 类型与契约定义。
3
3
  *
4
4
  * 关键点(中文)
5
- * - 统一维护聊天授权 plugin 的领域类型、扩展点/action 名称、payload 契约。
6
- * - 业务层不应散落硬编码字符串,如 `chat.authorizeIncoming`、`set-user-role`。
7
- * - chat / console / plugin 执行链路都从这里共享同一份边界定义。
5
+ * - 统一维护 ChatPlugin 内置授权能力的领域类型、扩展点/action 名称、payload 契约。
6
+ * - 业务层不应散落硬编码字符串,如 `chat.authorizeIncoming`、`authorization-set-user-role`。
7
+ * - chat / console / plugin action 执行链路都从这里共享同一份边界定义。
8
8
  */
9
9
 
10
10
  import type { ChatDispatchChannel } from "@/chat/types/ChatDispatcher.js";
11
11
  import { CHAT_PLUGIN_POINTS } from "@/chat/runtime/PluginPoints.js";
12
12
 
13
- /**
14
- * 聊天授权 plugin 稳定名称。
15
- */
16
- export const CHAT_AUTHORIZATION_PLUGIN_NAME = "chat-authorization";
17
-
18
13
  /**
19
14
  * 聊天授权支持的渠道目录。
20
15
  */
@@ -28,7 +23,7 @@ export type ChatAuthorizationChannel = (typeof CHAT_AUTHORIZATION_CHANNELS)[numb
28
23
  /**
29
24
  * 聊天授权扩展点名称集合。
30
25
  */
31
- export const CHAT_AUTHORIZATION_PLUGIN_POINTS = {
26
+ export const CHAT_AUTHORIZATION_POINTS = {
32
27
  observePrincipal: CHAT_PLUGIN_POINTS.observePrincipal,
33
28
  authorizeIncoming: CHAT_PLUGIN_POINTS.authorizeIncoming,
34
29
  resolveUserRole: CHAT_PLUGIN_POINTS.resolveUserRole,
@@ -38,10 +33,10 @@ export const CHAT_AUTHORIZATION_PLUGIN_POINTS = {
38
33
  * 聊天授权 action 名称集合。
39
34
  */
40
35
  export const CHAT_AUTHORIZATION_ACTIONS = {
41
- snapshot: "snapshot",
42
- readConfig: "read-config",
43
- writeConfig: "write-config",
44
- setUserRole: "set-user-role",
36
+ snapshot: "authorization-snapshot",
37
+ readConfig: "authorization-read-config",
38
+ writeConfig: "authorization-write-config",
39
+ setUserRole: "authorization-set-user-role",
45
40
  } as const;
46
41
 
47
42
  /**
@@ -463,7 +458,7 @@ export interface ChatAuthorizationStateFile {
463
458
  }
464
459
 
465
460
  /**
466
- * plugin effect 输入:记录观测主体。
461
+ * ChatPlugin effect 输入:记录观测主体。
467
462
  */
468
463
  export interface ChatAuthorizationObservePrincipalPayload {
469
464
  /**
@@ -493,7 +488,7 @@ export interface ChatAuthorizationObservePrincipalPayload {
493
488
  }
494
489
 
495
490
  /**
496
- * plugin effect 输出:记录观测主体结果。
491
+ * ChatPlugin effect 输出:记录观测主体结果。
497
492
  */
498
493
  export interface ChatAuthorizationObservePrincipalResult {
499
494
  /**
@@ -503,7 +498,7 @@ export interface ChatAuthorizationObservePrincipalResult {
503
498
  }
504
499
 
505
500
  /**
506
- * plugin resolve 输入:查询用户角色。
501
+ * ChatPlugin resolve 输入:查询用户角色。
507
502
  */
508
503
  export interface ChatAuthorizationResolveUserRolePayload {
509
504
  /**
@@ -9,29 +9,47 @@
9
9
  */
10
10
 
11
11
  import { BasePlugin } from "@downcity/agent/internal/plugin/core/BasePlugin.js";
12
- import type { PluginActions } from "@downcity/agent/internal/plugin/types/Plugin.js";
12
+ import type {
13
+ PluginActions,
14
+ PluginHooks,
15
+ PluginResolves,
16
+ } from "@downcity/agent/internal/plugin/types/Plugin.js";
13
17
  import type { AgentContext } from "@downcity/agent/internal/types/runtime/agent/AgentContext.js";
14
18
  import type { ChatChannelState } from "@/chat/types/ChatRuntime.js";
15
- import type { StoredChannelAccount } from "@downcity/agent/internal/types/platform/Store.js";
16
19
  import type { ChatQueueWorkerConfig } from "@/chat/types/ChatQueueWorker.js";
17
20
  import type {
18
- ChatPluginFeishuOptions,
21
+ ChatChannel,
19
22
  ChatPluginOptions,
20
- ChatPluginQqOptions,
21
- ChatPluginTelegramOptions,
22
- } from "@/chat/ChatPluginTypes.js";
23
+ } from "@/chat/types/ChatPluginOptions.js";
23
24
  import type { ChatChannelName } from "@/chat/types/ChannelStatus.js";
25
+ import {
26
+ FeishuChannel,
27
+ QqChannel,
28
+ TelegramChannel,
29
+ } from "@/chat/channels/RuntimeChannel.js";
24
30
  import {
25
31
  createChatChannelState,
26
32
  startChatChannels,
27
33
  stopChatChannels,
28
34
  } from "./runtime/ChatChannelFacade.js";
29
- import { getStoredChannelAccountSync } from "./accounts/Store.js";
30
35
  import { createChatPluginActions } from "./runtime/ChatPluginActions.js";
36
+ import {
37
+ createChatAuthorizationActions,
38
+ createChatAuthorizationHooks,
39
+ createChatAuthorizationResolves,
40
+ } from "./runtime/ChatAuthorizationRuntime.js";
31
41
  import { ChatQueueWorker } from "./runtime/ChatQueueWorker.js";
32
42
  import { buildChatPluginSystem } from "./runtime/ChatPluginSystem.js";
33
43
  import { ChatQueueStore } from "./runtime/ChatQueueStore.js";
34
44
 
45
+ function createDefaultChannels(): ChatChannel[] {
46
+ return [
47
+ new TelegramChannel({ enabled: false }),
48
+ new FeishuChannel({ enabled: false }),
49
+ new QqChannel({ enabled: false }),
50
+ ];
51
+ }
52
+
35
53
  /**
36
54
  * Chat plugin 类实现。
37
55
  */
@@ -69,6 +87,11 @@ export class ChatPlugin extends BasePlugin {
69
87
  */
70
88
  public readonly options: ChatPluginOptions;
71
89
 
90
+ /**
91
+ * 当前实例持有的 chat channels。
92
+ */
93
+ public readonly channels: ChatChannel[];
94
+
72
95
  /**
73
96
  * 当前 plugin 的 system 文本构建器。
74
97
  */
@@ -81,6 +104,16 @@ export class ChatPlugin extends BasePlugin {
81
104
  */
82
105
  readonly actions: PluginActions;
83
106
 
107
+ /**
108
+ * 当前 plugin 的 hook 定义表。
109
+ */
110
+ readonly hooks: PluginHooks;
111
+
112
+ /**
113
+ * 当前 plugin 的 resolve 定义表。
114
+ */
115
+ readonly resolves: PluginResolves;
116
+
84
117
  /**
85
118
  * 启动当前实例的 queue worker。
86
119
  */
@@ -109,9 +142,17 @@ export class ChatPlugin extends BasePlugin {
109
142
  constructor(options?: ChatPluginOptions) {
110
143
  super();
111
144
  this.options = options || {};
112
- this.actions = createChatPluginActions({
113
- channelState: this.channelState,
114
- });
145
+ this.channels = Array.isArray(this.options.channels)
146
+ ? [...this.options.channels]
147
+ : createDefaultChannels();
148
+ this.actions = {
149
+ ...createChatPluginActions({
150
+ channelState: this.channelState,
151
+ }),
152
+ ...createChatAuthorizationActions(),
153
+ };
154
+ this.hooks = createChatAuthorizationHooks();
155
+ this.resolves = createChatAuthorizationResolves();
115
156
  this.lifecycle = {
116
157
  start: async (context) => {
117
158
  this.startQueueWorker(context);
@@ -130,18 +171,15 @@ export class ChatPlugin extends BasePlugin {
130
171
  getQueueWorkerConfig(
131
172
  context: AgentContext,
132
173
  ): Partial<ChatQueueWorkerConfig> | undefined {
133
- return this.options.queue || context.config.plugins?.chat?.queue;
174
+ void context;
175
+ return this.options.queue;
134
176
  }
135
177
 
136
178
  /**
137
179
  * 判断指定渠道是否启用。
138
180
  */
139
181
  isChannelEnabled(context: AgentContext, channel: ChatChannelName): boolean {
140
- const explicit = this.getExplicitChannelOptions(channel);
141
- if (explicit) {
142
- return explicit.enabled !== false;
143
- }
144
- return context.config.plugins?.chat?.channels?.[channel]?.enabled === true;
182
+ return this.getChannel(channel)?.isEnabled(context) === true;
145
183
  }
146
184
 
147
185
  /**
@@ -151,13 +189,40 @@ export class ChatPlugin extends BasePlugin {
151
189
  context: AgentContext,
152
190
  channel: ChatChannelName,
153
191
  ): string {
154
- const explicit = this.getExplicitChannelOptions(channel);
155
- const explicitAccountId = String(explicit?.channelAccountId || "").trim();
156
- if (explicitAccountId) return explicitAccountId;
157
- const config = context.config.plugins?.chat?.channels?.[channel] as
158
- | { channelAccountId?: unknown }
159
- | undefined;
160
- return String(config?.channelAccountId || "").trim();
192
+ return String(this.getChannel(channel)?.getChannelAccountId(context) || "").trim();
193
+ }
194
+
195
+ /**
196
+ * 更新当前实例的渠道运行态配置。
197
+ *
198
+ * 关键点(中文)
199
+ * - chat.open/close/configure 只修改当前 plugin 实例,不写 downcity.json。
200
+ * - 当前运行态只允许更新 `enabled` 与 `channelAccountId`,密钥仍来自 constructor 或账号池。
201
+ */
202
+ applyChannelRuntimePatch(params: {
203
+ /**
204
+ * 目标渠道。
205
+ */
206
+ channel: ChatChannelName;
207
+ /**
208
+ * 是否启用该渠道。
209
+ */
210
+ enabled?: boolean;
211
+ /**
212
+ * 绑定的账号池记录 ID;传入 null 表示清空绑定。
213
+ */
214
+ channelAccountId?: string | null;
215
+ }): void {
216
+ const channel = this.getChannel(params.channel);
217
+ if (!channel) {
218
+ throw new Error(`Chat channel is not registered: ${params.channel}`);
219
+ }
220
+ channel.applyRuntimePatch({
221
+ ...(typeof params.enabled === "boolean" ? { enabled: params.enabled } : {}),
222
+ ...(Object.prototype.hasOwnProperty.call(params, "channelAccountId")
223
+ ? { channelAccountId: params.channelAccountId ?? null }
224
+ : {}),
225
+ });
161
226
  }
162
227
 
163
228
  /**
@@ -166,73 +231,11 @@ export class ChatPlugin extends BasePlugin {
166
231
  resolveChannelAccount(
167
232
  context: AgentContext,
168
233
  channel: ChatChannelName,
169
- ): StoredChannelAccount | null {
170
- const explicit = this.buildExplicitChannelAccount(channel);
171
- if (explicit) return explicit;
172
- const channelAccountId = this.getChannelAccountId(context, channel);
173
- if (!channelAccountId) return null;
174
- return getStoredChannelAccountSync(channelAccountId);
234
+ ) {
235
+ return this.getChannel(channel)?.getAccount(context) || null;
175
236
  }
176
237
 
177
- private getExplicitChannelOptions(
178
- channel: ChatChannelName,
179
- ): ChatPluginTelegramOptions | ChatPluginFeishuOptions | ChatPluginQqOptions | undefined {
180
- if (channel === "telegram") return this.options.telegram;
181
- if (channel === "feishu") return this.options.feishu;
182
- return this.options.qq;
183
- }
184
-
185
- private buildExplicitChannelAccount(
186
- channel: ChatChannelName,
187
- ): StoredChannelAccount | null {
188
- const now = new Date().toISOString();
189
-
190
- if (channel === "telegram") {
191
- const config = this.options.telegram;
192
- const botToken = String(config?.botToken || "").trim();
193
- if (!botToken) return null;
194
- return {
195
- id: String(config?.channelAccountId || `chat-sdk-${channel}`).trim(),
196
- channel,
197
- name: String(config?.name || "telegram").trim() || "telegram",
198
- botToken,
199
- createdAt: now,
200
- updatedAt: now,
201
- };
202
- }
203
-
204
- if (channel === "feishu") {
205
- const config = this.options.feishu;
206
- const appId = String(config?.appId || "").trim();
207
- const appSecret = String(config?.appSecret || "").trim();
208
- if (!appId || !appSecret) return null;
209
- return {
210
- id: String(config?.channelAccountId || `chat-sdk-${channel}`).trim(),
211
- channel,
212
- name: String(config?.name || "feishu").trim() || "feishu",
213
- appId,
214
- appSecret,
215
- ...(String(config?.domain || "").trim()
216
- ? { domain: String(config?.domain || "").trim() }
217
- : {}),
218
- createdAt: now,
219
- updatedAt: now,
220
- };
221
- }
222
-
223
- const config = this.options.qq;
224
- const appId = String(config?.appId || "").trim();
225
- const appSecret = String(config?.appSecret || "").trim();
226
- if (!appId || !appSecret) return null;
227
- return {
228
- id: String(config?.channelAccountId || `chat-sdk-${channel}`).trim(),
229
- channel,
230
- name: String(config?.name || "qq").trim() || "qq",
231
- appId,
232
- appSecret,
233
- ...(config?.sandbox === true ? { sandbox: true } : {}),
234
- createdAt: now,
235
- updatedAt: now,
236
- };
238
+ private getChannel(channel: ChatChannelName): ChatChannel | null {
239
+ return this.channels.find((item) => item.name === channel) || null;
237
240
  }
238
241
  }
package/src/chat/Index.ts CHANGED
@@ -2,7 +2,24 @@
2
2
  * Chat Plugin 导出入口。
3
3
  *
4
4
  * 关键点(中文)
5
- * - Index 只负责导出类实现。
5
+ * - Index 只负责导出类实现与 channel SDK 对象。
6
6
  * - 真正的类实现位于 `ChatPlugin.ts`。
7
7
  */
8
8
  export { ChatPlugin } from "./ChatPlugin.js";
9
+ export {
10
+ FeishuChannel,
11
+ QqChannel,
12
+ TelegramChannel,
13
+ } from "./channels/RuntimeChannel.js";
14
+ export type {
15
+ BaseChatChannelOptions,
16
+ ChatChannelEnv,
17
+ FeishuChannelOptions,
18
+ QqChannelOptions,
19
+ TelegramChannelOptions,
20
+ } from "./channels/RuntimeChannel.js";
21
+ export type {
22
+ ChatChannel,
23
+ ChatChannelRuntimePatch,
24
+ ChatPluginOptions,
25
+ } from "./types/ChatPluginOptions.js";
@@ -27,7 +27,7 @@ export abstract class ChatChannelConfiguration {
27
27
  abstract describe(): ChatChannelConfigurationDescriptor;
28
28
 
29
29
  /**
30
- * 返回可通过 `chat.configure` 写入的 downcity.json 字段定义。
30
+ * 返回可通过 `chat.configure` 更新的运行态字段定义。
31
31
  */
32
32
  getWritableShipFields(): ChatChannelConfigurationField[] {
33
33
  return this.describe().fields.ship.filter((field) => field.writable);