openclaw-openagent 1.0.0 → 1.0.2

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 (187) hide show
  1. package/dist/index.d.ts +25 -0
  2. package/dist/index.js +105 -0
  3. package/dist/src/app/channel-tools.d.ts +28 -0
  4. package/dist/src/app/channel-tools.js +251 -0
  5. package/dist/src/app/discovery-tools.d.ts +35 -0
  6. package/dist/src/app/discovery-tools.js +243 -0
  7. package/dist/src/app/download-file-tool.d.ts +10 -0
  8. package/dist/src/app/download-file-tool.js +104 -0
  9. package/dist/src/app/hooks.d.ts +14 -0
  10. package/dist/src/app/hooks.js +118 -0
  11. package/dist/src/app/index.d.ts +13 -0
  12. package/dist/src/app/index.js +44 -0
  13. package/dist/src/app/messaging-tools.d.ts +11 -0
  14. package/dist/src/app/messaging-tools.js +79 -0
  15. package/dist/src/app/ops-tools.d.ts +21 -0
  16. package/dist/src/app/ops-tools.js +158 -0
  17. package/dist/src/app/remote-agent-tool.d.ts +27 -0
  18. package/dist/src/app/remote-agent-tool.js +461 -0
  19. package/dist/src/app/types.d.ts +61 -0
  20. package/dist/src/app/types.js +11 -0
  21. package/dist/src/app/upload-file-tool.d.ts +16 -0
  22. package/dist/src/app/upload-file-tool.js +353 -0
  23. package/dist/src/app/verbose-preflight.d.ts +2 -0
  24. package/dist/src/app/verbose-preflight.js +145 -0
  25. package/dist/src/auth/config.d.ts +79 -0
  26. package/dist/src/auth/config.js +133 -0
  27. package/dist/src/auth/credential-manager.d.ts +65 -0
  28. package/dist/src/auth/credential-manager.js +122 -0
  29. package/dist/src/auth/index.d.ts +6 -0
  30. package/dist/src/auth/index.js +6 -0
  31. package/dist/src/auth/verify.d.ts +42 -0
  32. package/dist/src/auth/verify.js +60 -0
  33. package/dist/src/channel.d.ts +269 -0
  34. package/dist/src/channel.js +488 -0
  35. package/dist/src/compat.d.ts +37 -0
  36. package/dist/src/compat.js +70 -0
  37. package/dist/src/config/config-schema.d.ts +56 -0
  38. package/dist/src/config/config-schema.js +34 -0
  39. package/dist/src/messaging/aggregator.d.ts +25 -0
  40. package/dist/src/messaging/aggregator.js +90 -0
  41. package/dist/src/messaging/collector.d.ts +27 -0
  42. package/dist/src/messaging/collector.js +76 -0
  43. package/dist/src/messaging/executor.d.ts +14 -0
  44. package/dist/src/messaging/executor.js +59 -0
  45. package/dist/src/messaging/inbound.d.ts +97 -0
  46. package/dist/src/messaging/inbound.js +63 -0
  47. package/dist/src/messaging/index.d.ts +10 -0
  48. package/dist/src/messaging/index.js +9 -0
  49. package/dist/src/messaging/mention-protocol.d.ts +42 -0
  50. package/dist/src/messaging/mention-protocol.js +74 -0
  51. package/dist/src/messaging/process-c2c-request.d.ts +55 -0
  52. package/dist/src/messaging/process-c2c-request.js +445 -0
  53. package/dist/src/messaging/process-message.d.ts +62 -0
  54. package/dist/src/messaging/process-message.js +282 -0
  55. package/dist/src/messaging/scheduler.d.ts +17 -0
  56. package/dist/src/messaging/scheduler.js +47 -0
  57. package/dist/src/messaging/types.d.ts +34 -0
  58. package/dist/src/messaging/types.js +4 -0
  59. package/dist/src/plugin-ui/assets/openagent-override.js +9267 -0
  60. package/dist/src/plugin-ui/index.d.ts +13 -0
  61. package/dist/src/plugin-ui/index.js +16 -0
  62. package/dist/src/plugin-ui/ui-extension-loader/backup.d.ts +23 -0
  63. package/dist/src/plugin-ui/ui-extension-loader/backup.js +82 -0
  64. package/dist/src/plugin-ui/ui-extension-loader/index.d.ts +28 -0
  65. package/dist/src/plugin-ui/ui-extension-loader/index.js +240 -0
  66. package/dist/src/plugin-ui/ui-extension-loader/locator.d.ts +35 -0
  67. package/dist/src/plugin-ui/ui-extension-loader/locator.js +129 -0
  68. package/dist/src/plugin-ui/ui-extension-loader/manifest.d.ts +26 -0
  69. package/dist/src/plugin-ui/ui-extension-loader/manifest.js +45 -0
  70. package/dist/src/plugin-ui/ui-extension-loader/registry-regex.d.ts +9 -0
  71. package/dist/src/plugin-ui/ui-extension-loader/registry-regex.js +701 -0
  72. package/dist/src/plugin-ui/ui-extension-loader/removed-extensions.d.ts +8 -0
  73. package/dist/src/plugin-ui/ui-extension-loader/removed-extensions.js +58 -0
  74. package/dist/src/plugin-ui/ui-extension-loader/types.d.ts +55 -0
  75. package/dist/src/plugin-ui/ui-extension-loader/types.js +23 -0
  76. package/dist/src/proxy/auth-proxy.d.ts +20 -0
  77. package/dist/src/proxy/auth-proxy.js +337 -0
  78. package/dist/src/runtime/account.d.ts +156 -0
  79. package/dist/src/runtime/account.js +491 -0
  80. package/dist/src/runtime/index.d.ts +5 -0
  81. package/dist/src/runtime/index.js +6 -0
  82. package/dist/src/runtime/plugin-runtime.d.ts +40 -0
  83. package/dist/src/runtime/plugin-runtime.js +72 -0
  84. package/dist/src/runtime/registry.d.ts +41 -0
  85. package/dist/src/runtime/registry.js +60 -0
  86. package/dist/src/sdk/CLASS_MAP.md +143 -0
  87. package/dist/src/sdk/index.d.ts +126 -0
  88. package/dist/src/sdk/index.js +23990 -0
  89. package/dist/src/sdk/modules/cloud-search-module.js +1117 -0
  90. package/dist/src/sdk/modules/follow-module.js +1069 -0
  91. package/dist/src/sdk/modules/group-module.js +7397 -0
  92. package/dist/src/sdk/modules/relationship-module.js +2269 -0
  93. package/dist/src/sdk/modules/signaling-module.js +1468 -0
  94. package/dist/src/sdk/modules/tim-upload-plugin.js +730 -0
  95. package/dist/src/sdk/node-env/http-request.js +90 -0
  96. package/dist/src/sdk/node-env/index.js +57 -0
  97. package/dist/src/sdk/node-env/storage.js +114 -0
  98. package/dist/src/sdk/package.json +10 -0
  99. package/dist/src/sdk/sdk/CLASS_MAP.md +143 -0
  100. package/dist/src/sdk/sdk/index.d.ts +126 -0
  101. package/dist/src/sdk/sdk/index.js +23990 -0
  102. package/dist/src/sdk/sdk/modules/cloud-search-module.js +1117 -0
  103. package/dist/src/sdk/sdk/modules/follow-module.js +1069 -0
  104. package/dist/src/sdk/sdk/modules/group-module.js +7397 -0
  105. package/dist/src/sdk/sdk/modules/relationship-module.js +2269 -0
  106. package/dist/src/sdk/sdk/modules/signaling-module.js +1468 -0
  107. package/dist/src/sdk/sdk/modules/tim-upload-plugin.js +730 -0
  108. package/dist/src/sdk/sdk/node-env/http-request.js +90 -0
  109. package/dist/src/sdk/sdk/node-env/index.js +57 -0
  110. package/dist/src/sdk/sdk/node-env/storage.js +114 -0
  111. package/dist/src/sdk/sdk/package.json +10 -0
  112. package/dist/src/sdk/sdk/tsconfig.json +16 -0
  113. package/dist/src/sdk/tsconfig.json +16 -0
  114. package/dist/src/state/pending-invocation-store.d.ts +26 -0
  115. package/dist/src/state/pending-invocation-store.js +39 -0
  116. package/dist/src/state/store.d.ts +165 -0
  117. package/dist/src/state/store.js +535 -0
  118. package/dist/src/tim/c2c.d.ts +83 -0
  119. package/dist/src/tim/c2c.js +318 -0
  120. package/dist/src/tim/channels.d.ts +95 -0
  121. package/dist/src/tim/channels.js +279 -0
  122. package/dist/src/tim/client.d.ts +54 -0
  123. package/dist/src/tim/client.js +268 -0
  124. package/dist/src/tim/index.d.ts +6 -0
  125. package/dist/src/tim/index.js +6 -0
  126. package/dist/src/tim/messages.d.ts +50 -0
  127. package/dist/src/tim/messages.js +104 -0
  128. package/dist/src/tim/sdk-logger-init.d.ts +13 -0
  129. package/dist/src/tim/sdk-logger-init.js +46 -0
  130. package/dist/src/tools.d.ts +9 -0
  131. package/dist/src/tools.js +8 -0
  132. package/dist/src/transport/factory.d.ts +63 -0
  133. package/dist/src/transport/factory.js +54 -0
  134. package/dist/src/transport/oasn/index.d.ts +12 -0
  135. package/dist/src/transport/oasn/index.js +9 -0
  136. package/dist/src/transport/oasn/oasn-agent-card.d.ts +38 -0
  137. package/dist/src/transport/oasn/oasn-agent-card.js +102 -0
  138. package/dist/src/transport/oasn/oasn-discovery.d.ts +33 -0
  139. package/dist/src/transport/oasn/oasn-discovery.js +97 -0
  140. package/dist/src/transport/oasn/oasn-files.d.ts +64 -0
  141. package/dist/src/transport/oasn/oasn-files.js +174 -0
  142. package/dist/src/transport/oasn/oasn-http.d.ts +98 -0
  143. package/dist/src/transport/oasn/oasn-http.js +362 -0
  144. package/dist/src/transport/oasn/oasn-invocation.d.ts +154 -0
  145. package/dist/src/transport/oasn/oasn-invocation.js +432 -0
  146. package/dist/src/transport/oasn/oasn-normalize.d.ts +6 -0
  147. package/dist/src/transport/oasn/oasn-normalize.js +112 -0
  148. package/dist/src/transport/oasn/oasn-register.d.ts +19 -0
  149. package/dist/src/transport/oasn/oasn-register.js +24 -0
  150. package/dist/src/transport/oasn/oasn-transport.d.ts +114 -0
  151. package/dist/src/transport/oasn/oasn-transport.js +230 -0
  152. package/dist/src/transport/oasn/oasn-types.d.ts +331 -0
  153. package/dist/src/transport/oasn/oasn-types.js +44 -0
  154. package/dist/src/transport/tim/index.d.ts +7 -0
  155. package/dist/src/transport/tim/index.js +6 -0
  156. package/dist/src/transport/tim/tim-transport.d.ts +122 -0
  157. package/dist/src/transport/tim/tim-transport.js +402 -0
  158. package/dist/src/transport/types.d.ts +450 -0
  159. package/dist/src/transport/types.js +38 -0
  160. package/dist/src/util/http.d.ts +21 -0
  161. package/dist/src/util/http.js +93 -0
  162. package/dist/src/util/logger.d.ts +20 -0
  163. package/dist/src/util/logger.js +100 -0
  164. package/dist/src/util/url-resolver.d.ts +7 -0
  165. package/dist/src/util/url-resolver.js +20 -0
  166. package/index.ts +11 -0
  167. package/openclaw.plugin.json +9 -0
  168. package/package.json +7 -4
  169. package/src/app/download-file-tool.ts +133 -0
  170. package/src/app/hooks.ts +89 -5
  171. package/src/app/index.ts +6 -0
  172. package/src/app/remote-agent-tool.ts +46 -0
  173. package/src/app/types.ts +1 -0
  174. package/src/app/upload-file-tool.ts +411 -0
  175. package/src/plugin-ui/assets/openagent-override.js +1 -63
  176. package/src/plugin-ui/modules/agent-book/panel/agent-book.js +0 -61
  177. package/src/plugin-ui/modules/agent-book/panel/agent-data.js +0 -1
  178. package/src/plugin-ui/ui-extension-loader/registry-regex.ts +30 -13
  179. package/src/runtime/account.ts +0 -23
  180. package/src/transport/oasn/oasn-files.ts +5 -5
  181. package/src/transport/oasn/oasn-invocation.ts +44 -2
  182. package/src/transport/oasn/oasn-normalize.ts +0 -26
  183. package/src/transport/oasn/oasn-register.ts +8 -81
  184. package/src/transport/oasn/oasn-transport.ts +9 -32
  185. package/src/transport/oasn/oasn-types.ts +53 -6
  186. package/src/transport/types.ts +33 -36
  187. package/src/util/url-resolver.ts +17 -0
@@ -0,0 +1,25 @@
1
+ /**
2
+ * OpenAgent Plugin — Entry point
3
+ *
4
+ * Registers the channel adapter, tools, and hooks with OpenClaw.
5
+ *
6
+ * Aligned with openclaw-weixin v2.1.1 plugin entry pattern.
7
+ * Reference: docs/reference/plugins/openclaw-weixin-latest-v2.1.1/index.ts
8
+ */
9
+ import type { OpenClawPluginApi } from 'openclaw/plugin-sdk/plugin-entry';
10
+ export declare function getOpenagentRuntime(): OpenClawPluginApi['runtime'] | undefined;
11
+ export declare function setOpenagentRuntime(runtime: OpenClawPluginApi['runtime']): void;
12
+ declare const _default: {
13
+ id: string;
14
+ name: string;
15
+ description: string;
16
+ configSchema: unknown;
17
+ contracts: {
18
+ tools: string[];
19
+ };
20
+ register(api: OpenClawPluginApi): void;
21
+ };
22
+ export default _default;
23
+ export { openagentPlugin } from './src/channel.js';
24
+ export { registerTools, registerHooks } from './src/app/index.js';
25
+ export { registry } from './src/runtime/registry.js';
package/dist/index.js ADDED
@@ -0,0 +1,105 @@
1
+ /**
2
+ * OpenAgent Plugin — Entry point
3
+ *
4
+ * Registers the channel adapter, tools, and hooks with OpenClaw.
5
+ *
6
+ * Aligned with openclaw-weixin v2.1.1 plugin entry pattern.
7
+ * Reference: docs/reference/plugins/openclaw-weixin-latest-v2.1.1/index.ts
8
+ */
9
+ import { buildChannelConfigSchema } from 'openclaw/plugin-sdk/channel-config-schema';
10
+ import { openagentPlugin } from './src/channel.js';
11
+ import { assertHostCompatibility } from './src/compat.js';
12
+ import { OpenagentConfigSchema } from './src/config/config-schema.js';
13
+ import { registerTools, registerHooks } from './src/app/index.js';
14
+ import { installOpenagentVerbosePreflight } from './src/app/verbose-preflight.js';
15
+ // guard.ts removed — unhandled rejections fixed at source in ws-frame.ts send()
16
+ import { setOpenagentPluginRuntime } from './src/runtime/plugin-runtime.js';
17
+ import { injectControlUiOverride } from './src/plugin-ui/index.js';
18
+ import { createAuthProxyHandler } from './src/proxy/auth-proxy.js';
19
+ import { logger } from './src/util/logger.js';
20
+ // ── Runtime reference ─────────────────────────────────────────────────────
21
+ // Saved from api.runtime during register(), accessible by other modules.
22
+ let _runtime;
23
+ export function getOpenagentRuntime() {
24
+ return _runtime;
25
+ }
26
+ export function setOpenagentRuntime(runtime) {
27
+ _runtime = runtime;
28
+ }
29
+ // ── Plugin entry ──────────────────────────────────────────────────────────
30
+ export default {
31
+ id: 'openclaw-openagent',
32
+ name: 'OpenAgent',
33
+ // v3.9+ 双轨抽象:transport 字段决定走 OASN HTTP API 或腾讯 IM C2C。
34
+ // description 同时覆盖两条路径,避免误导用户以为只能用 IM。
35
+ description: 'OpenAgent channel plugin — connects to remote agents on the OASN agent network via HTTP API ' +
36
+ '(transport=oasn) or Tencent IM C2C (transport=tim, default).',
37
+ configSchema: buildChannelConfigSchema(OpenagentConfigSchema),
38
+ // 2026.6.9+: Gateway requires plugins to declare tool contracts before registering them.
39
+ contracts: {
40
+ tools: [
41
+ 'openagent_call_remote_agent',
42
+ 'openagent_search_agents',
43
+ 'openagent_get_agent_detail',
44
+ 'openagent_upload_file',
45
+ 'openagent_download_file',
46
+ ],
47
+ },
48
+ register(api) {
49
+ logger.info('[entry] register() called');
50
+ // P1-1: Fail-fast — reject incompatible host versions before any side-effects.
51
+ assertHostCompatibility(api.runtime?.version);
52
+ logger.info(`[entry] Host version: ${api.runtime?.version ?? 'unknown'}`);
53
+ // P0: TIM rejection guard removed — root cause fixed in ws-frame.ts send() with p.catch(() => {}).
54
+ // P1-3: Save runtime reference for use by other modules (logging, config, etc.)
55
+ if (api.runtime) {
56
+ setOpenagentRuntime(api.runtime);
57
+ setOpenagentPluginRuntime(api.runtime);
58
+ installOpenagentVerbosePreflight(api);
59
+ logger.info('[entry] Runtime reference saved');
60
+ }
61
+ // Always register the channel adapter (needed even in setup-only mode).
62
+ api.registerChannel({ plugin: openagentPlugin });
63
+ logger.info('[entry] Channel adapter registered');
64
+ // P1-2: registrationMode exists in 2026.3.22+; skip heavy registrations in
65
+ // setup-only mode (e.g. `openclaw channels list`).
66
+ const mode = api.registrationMode;
67
+ if (mode && mode !== 'full') {
68
+ logger.info(`[entry] Setup-only mode (registrationMode=${mode}), skipping tools/hooks`);
69
+ return;
70
+ }
71
+ // Full mode — register tools and hooks.
72
+ registerTools(api);
73
+ registerHooks(api);
74
+ // Auth proxy — same-origin reverse proxy to bypass CSP connect-src.
75
+ // Browser fetches /plugins/openagent/* → Gateway proxies to auth.ai-talk.live.
76
+ // Covers both API calls (/api/agents) and static assets (/avatars/oc1.png).
77
+ // Replaces the fragile patchCsp() approach (see docs/audit/022-A §4.6–4.10).
78
+ try {
79
+ if (typeof api.registerHttpRoute !== 'function') {
80
+ logger.warn('[entry] api.registerHttpRoute is NOT a function — type: ' + typeof api.registerHttpRoute);
81
+ }
82
+ else {
83
+ api.registerHttpRoute({
84
+ path: '/plugins/openagent',
85
+ auth: 'plugin',
86
+ match: 'prefix',
87
+ handler: createAuthProxyHandler(),
88
+ });
89
+ logger.info('[entry] Auth proxy route registered (prefix: /plugins/openagent)');
90
+ }
91
+ }
92
+ catch (routeErr) {
93
+ logger.warn(`[entry] registerHttpRoute failed: ${routeErr.message}`);
94
+ }
95
+ // Auto-inject Control UI override (copies openagent-override.js + patches)
96
+ injectControlUiOverride().catch(err => {
97
+ logger.warn(`[entry] Control UI injection failed: ${err.message}`);
98
+ });
99
+ logger.info('[entry] Tools + hooks registered (full mode)');
100
+ },
101
+ };
102
+ // Named exports for direct imports
103
+ export { openagentPlugin } from './src/channel.js';
104
+ export { registerTools, registerHooks } from './src/app/index.js';
105
+ export { registry } from './src/runtime/registry.js';
@@ -0,0 +1,28 @@
1
+ /**
2
+ * Channel Tools — 8 channel management tools
3
+ *
4
+ * list_channels, search_channels, join_channel, leave_channel,
5
+ * create_channel, get_members, set_channel_skill, get_channel_skill
6
+ *
7
+ * Contract ref: §0.2 refactoring-plan.md
8
+ */
9
+ import { type ToolDescriptor } from './types.js';
10
+ export declare function createListChannelsTool(): ToolDescriptor;
11
+ export declare function createSearchChannelsTool(): ToolDescriptor;
12
+ /**
13
+ * join_channel — supports optional `purpose?` per §0.2.
14
+ * If purpose is provided, it is stored via setPurpose().
15
+ */
16
+ export declare function createJoinChannelTool(): ToolDescriptor;
17
+ export declare function createLeaveChannelTool(): ToolDescriptor;
18
+ /**
19
+ * create_channel — supports optional `channelId?`, `skill?`, `desc?` per §0.2.
20
+ * If channelId is not given, auto-generates one.
21
+ */
22
+ export declare function createCreateChannelTool(): ToolDescriptor;
23
+ /**
24
+ * get_members — returns avatar? field per §0.2.
25
+ */
26
+ export declare function createGetMembersTool(): ToolDescriptor;
27
+ export declare function createSetChannelSkillTool(): ToolDescriptor;
28
+ export declare function createGetChannelSkillTool(): ToolDescriptor;
@@ -0,0 +1,251 @@
1
+ /**
2
+ * Channel Tools — 8 channel management tools
3
+ *
4
+ * list_channels, search_channels, join_channel, leave_channel,
5
+ * create_channel, get_members, set_channel_skill, get_channel_skill
6
+ *
7
+ * Contract ref: §0.2 refactoring-plan.md
8
+ */
9
+ import { registry } from '../runtime/registry.js';
10
+ import { toolResult } from './types.js';
11
+ function fail(error) {
12
+ return toolResult(JSON.stringify({ success: false, error }));
13
+ }
14
+ function getRuntime() {
15
+ const rt = registry.getDefault();
16
+ if (!rt || !rt.isRunning)
17
+ return null;
18
+ return rt;
19
+ }
20
+ export function createListChannelsTool() {
21
+ return {
22
+ name: 'openagent_list_channels',
23
+ label: 'List OpenAgent Channels',
24
+ description: 'List all available channels on OpenAgent agent network',
25
+ parameters: { type: 'object', properties: {}, required: [] },
26
+ async execute() {
27
+ const rt = getRuntime();
28
+ if (!rt)
29
+ return fail('Not connected');
30
+ try {
31
+ const channels = await rt.listChannels();
32
+ return toolResult(JSON.stringify({ success: true, channels }));
33
+ }
34
+ catch (err) {
35
+ return fail(err.message);
36
+ }
37
+ },
38
+ };
39
+ }
40
+ export function createSearchChannelsTool() {
41
+ return {
42
+ name: 'openagent_search_channels',
43
+ label: 'Search OpenAgent Channels',
44
+ description: 'Search channels by keyword',
45
+ parameters: {
46
+ type: 'object',
47
+ properties: { keyword: { type: 'string', description: 'Search keyword' } },
48
+ required: ['keyword'],
49
+ },
50
+ async execute(_id, params) {
51
+ const rt = getRuntime();
52
+ if (!rt)
53
+ return fail('Not connected');
54
+ try {
55
+ const channels = await rt.searchChannels(String(params.keyword || ''));
56
+ return toolResult(JSON.stringify({ success: true, channels }));
57
+ }
58
+ catch (err) {
59
+ return fail(err.message);
60
+ }
61
+ },
62
+ };
63
+ }
64
+ /**
65
+ * join_channel — supports optional `purpose?` per §0.2.
66
+ * If purpose is provided, it is stored via setPurpose().
67
+ */
68
+ export function createJoinChannelTool() {
69
+ return {
70
+ name: 'openagent_join_channel',
71
+ label: 'Join OpenAgent Channel',
72
+ description: 'Join a channel by ID (e.g. ch-001). Optionally set a purpose for this channel.',
73
+ parameters: {
74
+ type: 'object',
75
+ properties: {
76
+ channelId: { type: 'string', description: 'Channel ID to join' },
77
+ purpose: { type: 'string', description: 'Optional: your purpose/goal for this channel' },
78
+ },
79
+ required: ['channelId'],
80
+ },
81
+ async execute(_id, params) {
82
+ const rt = getRuntime();
83
+ if (!rt)
84
+ return fail('Not connected');
85
+ try {
86
+ const channelId = String(params.channelId);
87
+ const result = await rt.joinChannel(channelId);
88
+ if (result.success && rt.store) {
89
+ rt.store.markJoined(channelId, channelId);
90
+ if (params.purpose) {
91
+ rt.store.setPurpose(channelId, String(params.purpose));
92
+ }
93
+ }
94
+ return toolResult(JSON.stringify({
95
+ success: result.success,
96
+ channelId,
97
+ purpose: params.purpose ? String(params.purpose) : undefined,
98
+ }));
99
+ }
100
+ catch (err) {
101
+ return fail(err.message);
102
+ }
103
+ },
104
+ };
105
+ }
106
+ export function createLeaveChannelTool() {
107
+ return {
108
+ name: 'openagent_leave_channel',
109
+ label: 'Leave OpenAgent Channel',
110
+ description: 'Leave a channel by ID',
111
+ parameters: {
112
+ type: 'object',
113
+ properties: { channelId: { type: 'string', description: 'Channel ID to leave' } },
114
+ required: ['channelId'],
115
+ },
116
+ async execute(_id, params) {
117
+ const rt = getRuntime();
118
+ if (!rt)
119
+ return fail('Not connected');
120
+ try {
121
+ const channelId = String(params.channelId);
122
+ const result = await rt.leaveChannel(channelId);
123
+ if (result.success && rt.store) {
124
+ rt.store.markLeft(channelId);
125
+ }
126
+ return toolResult(JSON.stringify(result));
127
+ }
128
+ catch (err) {
129
+ return fail(err.message);
130
+ }
131
+ },
132
+ };
133
+ }
134
+ /**
135
+ * create_channel — supports optional `channelId?`, `skill?`, `desc?` per §0.2.
136
+ * If channelId is not given, auto-generates one.
137
+ */
138
+ export function createCreateChannelTool() {
139
+ return {
140
+ name: 'openagent_create_channel',
141
+ label: 'Create OpenAgent Channel',
142
+ description: 'Create a new channel. You become the owner and are automatically joined.',
143
+ parameters: {
144
+ type: 'object',
145
+ properties: {
146
+ name: { type: 'string', description: 'Channel display name (e.g. "AI Research Discussion")' },
147
+ desc: { type: 'string', description: 'Short description of the channel topic' },
148
+ skill: { type: 'string', description: 'Optional initial channel skill/rules' },
149
+ },
150
+ required: ['name'],
151
+ },
152
+ async execute(_id, params) {
153
+ const rt = getRuntime();
154
+ if (!rt)
155
+ return fail('Not connected');
156
+ try {
157
+ // Community groups: SDK auto-generates @TGS#_ prefixed groupID
158
+ const result = await rt.createChannel(String(params.name), String(params.desc || ''), params.skill ? String(params.skill) : undefined);
159
+ return toolResult(JSON.stringify(result));
160
+ }
161
+ catch (err) {
162
+ return fail(err.message);
163
+ }
164
+ },
165
+ };
166
+ }
167
+ /**
168
+ * get_members — returns avatar? field per §0.2.
169
+ */
170
+ export function createGetMembersTool() {
171
+ return {
172
+ name: 'openagent_get_members',
173
+ label: 'Get Channel Members',
174
+ description: 'Get the member list of a channel',
175
+ parameters: {
176
+ type: 'object',
177
+ properties: { channelId: { type: 'string', description: 'Channel ID' } },
178
+ required: ['channelId'],
179
+ },
180
+ async execute(_id, params) {
181
+ const rt = getRuntime();
182
+ if (!rt)
183
+ return fail('Not connected');
184
+ try {
185
+ const members = await rt.getMembers(String(params.channelId));
186
+ // Preserve all fields including avatar? per contract
187
+ return toolResult(JSON.stringify({ success: true, members }));
188
+ }
189
+ catch (err) {
190
+ return fail(err.message);
191
+ }
192
+ },
193
+ };
194
+ }
195
+ export function createSetChannelSkillTool() {
196
+ return {
197
+ name: 'openagent_set_channel_skill',
198
+ label: 'Set Channel Skill',
199
+ description: 'Set the skill/behavior rules for a channel',
200
+ parameters: {
201
+ type: 'object',
202
+ properties: {
203
+ channelId: { type: 'string', description: 'Channel ID' },
204
+ skill: { type: 'string', description: 'Channel rules that control agent behavior' },
205
+ },
206
+ required: ['channelId', 'skill'],
207
+ },
208
+ async execute(_id, params) {
209
+ const rt = getRuntime();
210
+ if (!rt)
211
+ return fail('Not connected');
212
+ try {
213
+ await rt.setChannelSkill(String(params.channelId), String(params.skill));
214
+ return toolResult(JSON.stringify({ success: true, message: `Skill set for ${params.channelId}` }));
215
+ }
216
+ catch (err) {
217
+ return fail(err.message);
218
+ }
219
+ },
220
+ };
221
+ }
222
+ export function createGetChannelSkillTool() {
223
+ return {
224
+ name: 'openagent_get_channel_skill',
225
+ label: 'Get Channel Skill',
226
+ description: 'Get the current skill/behavior rules for a channel',
227
+ parameters: {
228
+ type: 'object',
229
+ properties: {
230
+ channelId: { type: 'string', description: 'Channel ID' },
231
+ },
232
+ required: ['channelId'],
233
+ },
234
+ async execute(_id, params) {
235
+ const rt = getRuntime();
236
+ if (!rt)
237
+ return fail('Not connected');
238
+ try {
239
+ const skill = await rt.getChannelSkill(String(params.channelId));
240
+ return toolResult(JSON.stringify({
241
+ success: true,
242
+ channelId: params.channelId,
243
+ skill: skill || '(no skill set)',
244
+ }));
245
+ }
246
+ catch (err) {
247
+ return fail(err.message);
248
+ }
249
+ },
250
+ };
251
+ }
@@ -0,0 +1,35 @@
1
+ /**
2
+ * Discovery Tools — Agent 搜索 / Agent 详情
3
+ *
4
+ * 封装 OASN DiscoveryTransport 能力为 LLM 可用工具。
5
+ * 当前仅 OASN 模式可用;TIM 模式下工具返回明确错误。
6
+ *
7
+ * 设计依据:docs/specs/2026-06-21-oasn-agent-search-tool-wiring.md
8
+ *
9
+ * 工具列表:
10
+ * - openagent_search_agents — 按关键词 / 分类 / 标签搜索 Agent
11
+ * - openagent_get_agent_detail — 查看单个 Agent 详情
12
+ *
13
+ * 注:getCategories() 传输层能力保留给 Agent Book UI 使用,不暴露为 LLM 工具。
14
+ */
15
+ import { type ToolFactory } from './types.js';
16
+ /**
17
+ * 搜索可用 Agent。
18
+ *
19
+ * 三种搜索模式(互斥,按优先级):
20
+ * 1. query — 自然语言搜索(POST /api/agent-cards/search/by-query)
21
+ * 2. category — 分类浏览(POST /api/agent-cards/search/by-category)
22
+ * 3. tags — 标签筛选(POST /api/agent-cards/search/by-tags)
23
+ *
24
+ * LLM 使用场景:
25
+ * - 用户说"我想去旅行" → search_agents({ query: "旅行" })
26
+ * - 用户说"找个机票助手" → search_agents({ query: "机票" })
27
+ * - 用户说"看看有哪些旅行类 Agent" → search_agents({ category: ["travel"] })
28
+ */
29
+ export declare const createSearchAgentsTool: ToolFactory;
30
+ /**
31
+ * 查看单个 Agent 详情。
32
+ *
33
+ * 在搜索结果中选择了一个 Agent 后,可以调用此工具获取完整信息(包括 MOM)。
34
+ */
35
+ export declare const createGetAgentDetailTool: ToolFactory;