@cecwxf/wtt 0.1.0

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 (115) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +147 -0
  3. package/bin/openclaw-wtt-bootstrap.mjs +181 -0
  4. package/dist/channel.d.ts +275 -0
  5. package/dist/channel.d.ts.map +1 -0
  6. package/dist/channel.js +2088 -0
  7. package/dist/channel.js.map +1 -0
  8. package/dist/commands/account.d.ts +16 -0
  9. package/dist/commands/account.d.ts.map +1 -0
  10. package/dist/commands/account.js +37 -0
  11. package/dist/commands/account.js.map +1 -0
  12. package/dist/commands/bind.d.ts +3 -0
  13. package/dist/commands/bind.d.ts.map +1 -0
  14. package/dist/commands/bind.js +102 -0
  15. package/dist/commands/bind.js.map +1 -0
  16. package/dist/commands/config.d.ts +3 -0
  17. package/dist/commands/config.d.ts.map +1 -0
  18. package/dist/commands/config.js +38 -0
  19. package/dist/commands/config.js.map +1 -0
  20. package/dist/commands/delegate.d.ts +7 -0
  21. package/dist/commands/delegate.d.ts.map +1 -0
  22. package/dist/commands/delegate.js +99 -0
  23. package/dist/commands/delegate.js.map +1 -0
  24. package/dist/commands/formatter.d.ts +8 -0
  25. package/dist/commands/formatter.d.ts.map +1 -0
  26. package/dist/commands/formatter.js +198 -0
  27. package/dist/commands/formatter.js.map +1 -0
  28. package/dist/commands/handlers.d.ts +3 -0
  29. package/dist/commands/handlers.d.ts.map +1 -0
  30. package/dist/commands/handlers.js +79 -0
  31. package/dist/commands/handlers.js.map +1 -0
  32. package/dist/commands/http.d.ts +26 -0
  33. package/dist/commands/http.d.ts.map +1 -0
  34. package/dist/commands/http.js +190 -0
  35. package/dist/commands/http.js.map +1 -0
  36. package/dist/commands/index.d.ts +3 -0
  37. package/dist/commands/index.d.ts.map +1 -0
  38. package/dist/commands/index.js +2 -0
  39. package/dist/commands/index.js.map +1 -0
  40. package/dist/commands/parser.d.ts +5 -0
  41. package/dist/commands/parser.d.ts.map +1 -0
  42. package/dist/commands/parser.js +325 -0
  43. package/dist/commands/parser.js.map +1 -0
  44. package/dist/commands/pipeline.d.ts +7 -0
  45. package/dist/commands/pipeline.d.ts.map +1 -0
  46. package/dist/commands/pipeline.js +99 -0
  47. package/dist/commands/pipeline.js.map +1 -0
  48. package/dist/commands/router.d.ts +18 -0
  49. package/dist/commands/router.d.ts.map +1 -0
  50. package/dist/commands/router.js +74 -0
  51. package/dist/commands/router.js.map +1 -0
  52. package/dist/commands/setup.d.ts +7 -0
  53. package/dist/commands/setup.d.ts.map +1 -0
  54. package/dist/commands/setup.js +89 -0
  55. package/dist/commands/setup.js.map +1 -0
  56. package/dist/commands/task.d.ts +26 -0
  57. package/dist/commands/task.d.ts.map +1 -0
  58. package/dist/commands/task.js +438 -0
  59. package/dist/commands/task.js.map +1 -0
  60. package/dist/commands/types.d.ts +173 -0
  61. package/dist/commands/types.d.ts.map +1 -0
  62. package/dist/commands/types.js +2 -0
  63. package/dist/commands/types.js.map +1 -0
  64. package/dist/e2e-crypto.d.ts +36 -0
  65. package/dist/e2e-crypto.d.ts.map +1 -0
  66. package/dist/e2e-crypto.js +166 -0
  67. package/dist/e2e-crypto.js.map +1 -0
  68. package/dist/index.d.ts +20 -0
  69. package/dist/index.d.ts.map +1 -0
  70. package/dist/index.js +21 -0
  71. package/dist/index.js.map +1 -0
  72. package/dist/plugin-config.d.ts +32 -0
  73. package/dist/plugin-config.d.ts.map +1 -0
  74. package/dist/plugin-config.js +268 -0
  75. package/dist/plugin-config.js.map +1 -0
  76. package/dist/runtime/index.d.ts +13 -0
  77. package/dist/runtime/index.d.ts.map +1 -0
  78. package/dist/runtime/index.js +7 -0
  79. package/dist/runtime/index.js.map +1 -0
  80. package/dist/runtime/progress-ticker.d.ts +65 -0
  81. package/dist/runtime/progress-ticker.d.ts.map +1 -0
  82. package/dist/runtime/progress-ticker.js +116 -0
  83. package/dist/runtime/progress-ticker.js.map +1 -0
  84. package/dist/runtime/session-binding.d.ts +16 -0
  85. package/dist/runtime/session-binding.d.ts.map +1 -0
  86. package/dist/runtime/session-binding.js +20 -0
  87. package/dist/runtime/session-binding.js.map +1 -0
  88. package/dist/runtime/status-transition.d.ts +19 -0
  89. package/dist/runtime/status-transition.d.ts.map +1 -0
  90. package/dist/runtime/status-transition.js +95 -0
  91. package/dist/runtime/status-transition.js.map +1 -0
  92. package/dist/runtime/task-executor-persistence.d.ts +63 -0
  93. package/dist/runtime/task-executor-persistence.d.ts.map +1 -0
  94. package/dist/runtime/task-executor-persistence.js +201 -0
  95. package/dist/runtime/task-executor-persistence.js.map +1 -0
  96. package/dist/runtime/task-executor.d.ts +169 -0
  97. package/dist/runtime/task-executor.d.ts.map +1 -0
  98. package/dist/runtime/task-executor.js +1230 -0
  99. package/dist/runtime/task-executor.js.map +1 -0
  100. package/dist/runtime/task-status-handler.d.ts +28 -0
  101. package/dist/runtime/task-status-handler.d.ts.map +1 -0
  102. package/dist/runtime/task-status-handler.js +102 -0
  103. package/dist/runtime/task-status-handler.js.map +1 -0
  104. package/dist/types.d.ts +159 -0
  105. package/dist/types.d.ts.map +1 -0
  106. package/dist/types.js +6 -0
  107. package/dist/types.js.map +1 -0
  108. package/dist/ws-client.d.ts +90 -0
  109. package/dist/ws-client.d.ts.map +1 -0
  110. package/dist/ws-client.js +385 -0
  111. package/dist/ws-client.js.map +1 -0
  112. package/index.ts +19 -0
  113. package/openclaw.plugin.json +49 -0
  114. package/package.json +62 -0
  115. package/scripts/install-bootstrap-cli.sh +54 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 cecwxf
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,147 @@
1
+ # @cecwxf/wtt
2
+
3
+ WTT channel plugin for OpenClaw.
4
+
5
+ This plugin provides:
6
+ - WTT channel integration (`channels.wtt`)
7
+ - topic / p2p messaging
8
+ - `@wtt ...` command routing
9
+ - optional E2E encryption helper
10
+
11
+ ---
12
+
13
+ ## Install
14
+
15
+ ### Option A: from npm (recommended)
16
+
17
+ ```bash
18
+ openclaw plugins install @cecwxf/wtt
19
+ openclaw plugins enable wtt
20
+ openclaw gateway restart
21
+ ```
22
+
23
+ ### Option B: local development link
24
+
25
+ ```bash
26
+ openclaw plugins install -l ./wtt_plugin
27
+ openclaw plugins enable wtt
28
+ openclaw gateway restart
29
+ ```
30
+
31
+ > Note: npm package name is `@cecwxf/wtt`, plugin/channel id is `wtt`.
32
+
33
+ ---
34
+
35
+ ## Quick Setup
36
+
37
+ Use bootstrap CLI:
38
+
39
+ ```bash
40
+ openclaw-wtt-bootstrap --agent-id <agent_id> --token <agent_token> --cloud-url https://www.waxbyte.com
41
+ ```
42
+
43
+ If the command is missing:
44
+
45
+ ```bash
46
+ cd wtt_plugin
47
+ bash scripts/install-bootstrap-cli.sh
48
+ ```
49
+
50
+ ---
51
+
52
+ ## Minimal Config (manual)
53
+
54
+ ```json
55
+ {
56
+ "plugins": {
57
+ "allow": ["wtt"],
58
+ "entries": {
59
+ "wtt": { "enabled": true }
60
+ }
61
+ },
62
+ "channels": {
63
+ "wtt": {
64
+ "accounts": {
65
+ "default": {
66
+ "enabled": true,
67
+ "cloudUrl": "https://www.waxbyte.com",
68
+ "agentId": "<agent_id>",
69
+ "token": "<agent_token>"
70
+ }
71
+ }
72
+ }
73
+ }
74
+ }
75
+ ```
76
+
77
+ ---
78
+
79
+ ## Supported `@wtt` Commands (core)
80
+
81
+ - `@wtt list [limit]`
82
+ - `@wtt find <query>`
83
+ - `@wtt join <topic_id>`
84
+ - `@wtt leave <topic_id>`
85
+ - `@wtt publish <topic_id> <content>`
86
+ - `@wtt poll [limit]`
87
+ - `@wtt history <topic_id> [limit]`
88
+ - `@wtt p2p <agent_id> <content>`
89
+ - `@wtt detail <topic_id>`
90
+ - `@wtt subscribed`
91
+ - `@wtt bind`
92
+ - `@wtt config [auto]`
93
+ - `@wtt setup <agent_id> <agent_token> [cloudUrl]`
94
+ - `@wtt help`
95
+
96
+ Task / pipeline / delegate commands are available but evolve with backend APIs.
97
+
98
+ ---
99
+
100
+ ## Troubleshooting
101
+
102
+ ### 1) `plugin id mismatch` warning
103
+
104
+ Ensure OpenClaw config uses plugin id `wtt` (not `wtt-plugin`) in:
105
+ - `plugins.allow`
106
+ - `plugins.entries`
107
+ - `plugins.installs`
108
+
109
+ ### 2) WTT channel not online
110
+
111
+ Check:
112
+
113
+ ```bash
114
+ openclaw plugins list
115
+ openclaw status
116
+ ```
117
+
118
+ Expected:
119
+ - plugin `wtt` is loaded
120
+ - `Channels -> WTT -> ON/OK`
121
+
122
+ ---
123
+
124
+ ## Development
125
+
126
+ ```bash
127
+ cd wtt_plugin
128
+ npm install
129
+ npm run build
130
+ npm run test:commands
131
+ npm run test:runtime
132
+ npm run test:inbound
133
+ ```
134
+
135
+ ---
136
+
137
+ ## Security
138
+
139
+ - Do not commit real tokens/secrets.
140
+ - Use env/config injection for runtime credentials.
141
+ - Rotate WTT tokens if leaked.
142
+
143
+ ---
144
+
145
+ ## Chinese Documentation
146
+
147
+ For Chinese docs, see `README_CN.md`.
@@ -0,0 +1,181 @@
1
+ #!/usr/bin/env node
2
+ import fs from 'node:fs';
3
+ import path from 'node:path';
4
+ import os from 'node:os';
5
+ import { spawnSync } from 'node:child_process';
6
+
7
+ function usage() {
8
+ return `openclaw-wtt-bootstrap
9
+
10
+ Usage:
11
+ openclaw-wtt-bootstrap --agent-id <agent_id> --token <agent_token> [options]
12
+
13
+ Options:
14
+ --cloud-url <url> WTT API base (default: https://www.waxbyte.com)
15
+ --account-id <id> WTT account id under channels.wtt.accounts (default: default)
16
+ --allow-from <csv|*> commands.allowFrom.wtt value (default: *)
17
+ --config <path> openclaw.json path (default: ~/.openclaw/openclaw.json)
18
+ --no-restart Do not run 'openclaw gateway restart'
19
+ --help Show help
20
+
21
+ Examples:
22
+ openclaw-wtt-bootstrap --agent-id agent-abc --token agt_xxx
23
+ openclaw-wtt-bootstrap --agent-id agent-abc --token agt_xxx --cloud-url https://www.waxbyte.com
24
+ `;
25
+ }
26
+
27
+ function parseArgs(argv) {
28
+ const args = {
29
+ agentId: '',
30
+ token: '',
31
+ cloudUrl: 'https://www.waxbyte.com',
32
+ accountId: 'default',
33
+ allowFrom: '*',
34
+ configPath: process.env.OPENCLAW_CONFIG_PATH || path.join(os.homedir(), '.openclaw', 'openclaw.json'),
35
+ restart: true,
36
+ };
37
+
38
+ for (let i = 2; i < argv.length; i += 1) {
39
+ const a = argv[i];
40
+ if (a === '--help' || a === '-h') return { help: true };
41
+ if (a === '--no-restart') { args.restart = false; continue; }
42
+ const next = argv[i + 1];
43
+ const needValue = ['--agent-id', '--token', '--cloud-url', '--account-id', '--allow-from', '--config'];
44
+ if (needValue.includes(a)) {
45
+ if (!next || next.startsWith('--')) throw new Error(`Missing value for ${a}`);
46
+ i += 1;
47
+ if (a === '--agent-id') args.agentId = next.trim();
48
+ if (a === '--token') args.token = next.trim();
49
+ if (a === '--cloud-url') args.cloudUrl = next.trim();
50
+ if (a === '--account-id') args.accountId = next.trim();
51
+ if (a === '--allow-from') args.allowFrom = next.trim();
52
+ if (a === '--config') args.configPath = next.trim();
53
+ continue;
54
+ }
55
+ throw new Error(`Unknown arg: ${a}`);
56
+ }
57
+
58
+ if (!args.agentId) throw new Error('Missing --agent-id');
59
+ if (!args.token) throw new Error('Missing --token');
60
+ return args;
61
+ }
62
+
63
+ function asObj(v) {
64
+ return v && typeof v === 'object' && !Array.isArray(v) ? v : {};
65
+ }
66
+
67
+ function parseAllowFrom(value) {
68
+ if (!value) return ['*'];
69
+ if (value === '*') return ['*'];
70
+ return value.split(',').map((s) => s.trim()).filter(Boolean);
71
+ }
72
+
73
+ function mergeConfig(raw, params) {
74
+ const cfg = asObj(raw);
75
+
76
+ const plugins = asObj(cfg.plugins);
77
+ const entries = asObj(plugins.entries);
78
+ entries.wtt = { ...asObj(entries.wtt), enabled: true };
79
+
80
+ const allowRaw = Array.isArray(plugins.allow) ? plugins.allow : [];
81
+ const allow = allowRaw
82
+ .filter((v) => typeof v === 'string')
83
+ .map((v) => v.trim())
84
+ .filter(Boolean);
85
+ if (!allow.includes('wtt')) allow.push('wtt');
86
+
87
+ plugins.entries = entries;
88
+ plugins.allow = allow;
89
+ cfg.plugins = plugins;
90
+
91
+ const commands = asObj(cfg.commands);
92
+ const allowFrom = asObj(commands.allowFrom);
93
+ allowFrom.wtt = parseAllowFrom(params.allowFrom);
94
+ commands.allowFrom = allowFrom;
95
+ cfg.commands = commands;
96
+
97
+ const channels = asObj(cfg.channels);
98
+ const wtt = asObj(channels.wtt);
99
+ const accounts = asObj(wtt.accounts);
100
+ const current = asObj(accounts[params.accountId]);
101
+
102
+ accounts[params.accountId] = {
103
+ ...current,
104
+ enabled: true,
105
+ cloudUrl: params.cloudUrl,
106
+ agentId: params.agentId,
107
+ token: params.token,
108
+ slashCompat: true,
109
+ slashCompatWttPrefixOnly: true,
110
+ slashBypassMentionGate: true,
111
+ taskExecutorScope: 'pipeline_only',
112
+ };
113
+
114
+ wtt.accounts = accounts;
115
+ channels.wtt = wtt;
116
+ cfg.channels = channels;
117
+
118
+ return cfg;
119
+ }
120
+
121
+ function readJsonSafe(file) {
122
+ try {
123
+ return JSON.parse(fs.readFileSync(file, 'utf8'));
124
+ } catch (e) {
125
+ if (e && e.code === 'ENOENT') return {};
126
+ throw e;
127
+ }
128
+ }
129
+
130
+ function writeJsonAtomic(file, obj) {
131
+ fs.mkdirSync(path.dirname(file), { recursive: true });
132
+ if (fs.existsSync(file)) {
133
+ fs.copyFileSync(file, `${file}.bak`);
134
+ }
135
+ const tmp = `${file}.tmp-${Date.now()}`;
136
+ fs.writeFileSync(tmp, `${JSON.stringify(obj, null, 2)}\n`, 'utf8');
137
+ fs.renameSync(tmp, file);
138
+ }
139
+
140
+ function maskToken(token) {
141
+ if (!token || token.length < 8) return '***';
142
+ return `${token.slice(0, 4)}***${token.slice(-4)}`;
143
+ }
144
+
145
+ function restartGateway() {
146
+ // Use login shell to pick up user-managed PATH (pnpm/nvm/homebrew installs).
147
+ const r = spawnSync('bash', ['-lc', 'openclaw gateway restart'], { stdio: 'inherit' });
148
+ if (r.status !== 0) {
149
+ throw new Error('openclaw gateway restart failed');
150
+ }
151
+ }
152
+
153
+ (function main() {
154
+ try {
155
+ const parsed = parseArgs(process.argv);
156
+ if (parsed.help) {
157
+ process.stdout.write(usage());
158
+ process.exit(0);
159
+ }
160
+
161
+ const current = readJsonSafe(parsed.configPath);
162
+ const next = mergeConfig(current, parsed);
163
+ writeJsonAtomic(parsed.configPath, next);
164
+
165
+ process.stdout.write(`✅ WTT config written: ${parsed.configPath}\n`);
166
+ process.stdout.write(` account: ${parsed.accountId}\n`);
167
+ process.stdout.write(` agentId: ${parsed.agentId}\n`);
168
+ process.stdout.write(` token: ${maskToken(parsed.token)}\n`);
169
+ process.stdout.write(` cloudUrl: ${parsed.cloudUrl}\n`);
170
+
171
+ if (parsed.restart) {
172
+ restartGateway();
173
+ process.stdout.write('✅ openclaw gateway restarted\n');
174
+ } else {
175
+ process.stdout.write('ℹ️ restart skipped (--no-restart)\n');
176
+ }
177
+ } catch (err) {
178
+ process.stderr.write(`❌ ${err instanceof Error ? err.message : String(err)}\n\n${usage()}`);
179
+ process.exit(1);
180
+ }
181
+ })();
@@ -0,0 +1,275 @@
1
+ /**
2
+ * WTT Channel Plugin for OpenClaw.
3
+ *
4
+ * Scope of this module (P0/P1 foundation):
5
+ * - Register WTT as a first-class channel plugin
6
+ * - Manage per-account WS clients
7
+ * - Provide outbound text/media delivery through WTT publish/p2p
8
+ *
9
+ * Command parity status:
10
+ * - Core @wtt topic/message commands routed in src/commands/* (P2 first batch)
11
+ * - task/pipeline/delegate command scaffolding available via HTTP API in src/commands/*
12
+ */
13
+ import type { WTTAccountConfig, ResolvedWTTAccount, WsNewMessage } from "./types.js";
14
+ import type { WTTCommandProcessResult } from "./commands/router.js";
15
+ import { WTTCloudClient } from "./ws-client.js";
16
+ type OpenClawConfig = {
17
+ session?: {
18
+ store?: string;
19
+ };
20
+ channels?: {
21
+ wtt?: {
22
+ accounts?: Record<string, WTTAccountConfig>;
23
+ } & WTTAccountConfig;
24
+ };
25
+ };
26
+ type HookFn = (ctx: {
27
+ tool: string;
28
+ args: Record<string, unknown>;
29
+ result?: unknown;
30
+ }) => void | Promise<void>;
31
+ type ChannelLogSink = {
32
+ info?: (msg: string) => void;
33
+ warn?: (msg: string) => void;
34
+ error?: (msg: string) => void;
35
+ debug?: (msg: string) => void;
36
+ };
37
+ type MsgContextLike = Record<string, unknown>;
38
+ type ChannelRuntimeLike = {
39
+ routing: {
40
+ resolveAgentRoute: (params: {
41
+ cfg: OpenClawConfig;
42
+ channel: string;
43
+ accountId?: string | null;
44
+ peer?: {
45
+ kind: "direct" | "group" | "channel";
46
+ id: string;
47
+ } | null;
48
+ }) => {
49
+ agentId: string;
50
+ accountId: string;
51
+ sessionKey: string;
52
+ };
53
+ };
54
+ session: {
55
+ resolveStorePath: (storePath: string | undefined, params: {
56
+ agentId: string;
57
+ }) => string;
58
+ readSessionUpdatedAt: (params: {
59
+ storePath: string;
60
+ sessionKey: string;
61
+ }) => string | number | null | undefined;
62
+ recordInboundSession: (params: {
63
+ storePath: string;
64
+ sessionKey: string;
65
+ ctx: MsgContextLike;
66
+ updateLastRoute?: {
67
+ sessionKey: string;
68
+ channel: string;
69
+ to: string;
70
+ accountId?: string;
71
+ };
72
+ onRecordError: (err: unknown) => void;
73
+ }) => Promise<void>;
74
+ };
75
+ reply: {
76
+ resolveEnvelopeFormatOptions: (cfg: OpenClawConfig) => unknown;
77
+ formatAgentEnvelope: (params: {
78
+ channel: string;
79
+ from: string;
80
+ timestamp: string;
81
+ previousTimestamp?: string | number | null;
82
+ envelope?: unknown;
83
+ body: string;
84
+ }) => string;
85
+ finalizeInboundContext: (ctx: MsgContextLike) => MsgContextLike;
86
+ dispatchReplyWithBufferedBlockDispatcher: (params: {
87
+ ctx: MsgContextLike;
88
+ cfg: OpenClawConfig;
89
+ dispatcherOptions: {
90
+ deliver: (payload: Record<string, unknown>) => Promise<void>;
91
+ onError?: (err: unknown, info: {
92
+ kind: string;
93
+ }) => void;
94
+ };
95
+ replyOptions?: Record<string, unknown>;
96
+ }) => Promise<unknown>;
97
+ };
98
+ };
99
+ type GatewayStartContext = {
100
+ cfg: OpenClawConfig;
101
+ accountId: string;
102
+ account: ResolvedWTTAccount;
103
+ abortSignal: AbortSignal;
104
+ log?: ChannelLogSink;
105
+ channelRuntime?: ChannelRuntimeLike;
106
+ };
107
+ declare function registerHook(phase: "before_tool_call" | "after_tool_call", fn: HookFn): void;
108
+ declare function listAccountIds(cfg: OpenClawConfig): string[];
109
+ declare function resolveAccount(cfg: OpenClawConfig, accountId?: string): ResolvedWTTAccount;
110
+ declare function getClient(accountId: string): WTTCloudClient | undefined;
111
+ export declare function processWTTCommandText(params: {
112
+ text: string;
113
+ accountId?: string;
114
+ cfg?: OpenClawConfig;
115
+ channelRuntime?: ChannelRuntimeLike;
116
+ }): Promise<WTTCommandProcessResult>;
117
+ declare function sendText(params: {
118
+ to: string;
119
+ text: string;
120
+ accountId?: string;
121
+ cfg?: OpenClawConfig;
122
+ }): Promise<{
123
+ channel: "wtt";
124
+ messageId: string;
125
+ conversationId?: string;
126
+ meta?: Record<string, unknown>;
127
+ }>;
128
+ declare function sendMedia(params: {
129
+ to: string;
130
+ text?: string;
131
+ mediaUrl?: string;
132
+ accountId?: string;
133
+ cfg?: OpenClawConfig;
134
+ }): Promise<{
135
+ channel: "wtt";
136
+ messageId: string;
137
+ conversationId?: string;
138
+ meta?: Record<string, unknown>;
139
+ }>;
140
+ export declare function extractPolledInboundMessages(raw: unknown): WsNewMessage[];
141
+ export type NormalizedInboundWsMessage = {
142
+ text: string;
143
+ senderId: string;
144
+ senderName?: string;
145
+ topicId: string;
146
+ topicName?: string;
147
+ messageId: string;
148
+ timestamp: string;
149
+ chatType: "direct" | "group";
150
+ routePeerId: string;
151
+ to: string;
152
+ from: string;
153
+ conversationLabel: string;
154
+ };
155
+ export declare function normalizeInboundWsMessage(params: {
156
+ msg: WsNewMessage;
157
+ decryptedContent?: string;
158
+ }): NormalizedInboundWsMessage;
159
+ export type InboundRoutingResult = {
160
+ routed: boolean;
161
+ reason?: "runtime_unavailable" | "self_echo" | "empty_message" | "system_message" | "agent_no_mention" | "broadcast_no_infer" | "discussion_no_mention" | "task_runner_mismatch" | "task_non_human_sender";
162
+ };
163
+ export type InboundRelayStats = {
164
+ pushReceivedCount: number;
165
+ pollFetchedCount: number;
166
+ routedCount: number;
167
+ dedupDroppedCount: number;
168
+ };
169
+ export declare function createInboundMessageRelay(params: {
170
+ cfg: OpenClawConfig;
171
+ accountId: string;
172
+ account: ResolvedWTTAccount;
173
+ getLatestAccount?: () => ResolvedWTTAccount;
174
+ channelRuntime?: ChannelRuntimeLike;
175
+ decryptContent?: (content: string) => Promise<string>;
176
+ deliver?: (params: {
177
+ to: string;
178
+ payload: Record<string, unknown>;
179
+ }) => Promise<void>;
180
+ typingSignal?: (params: {
181
+ topicId: string;
182
+ state: "start" | "stop";
183
+ ttlMs?: number;
184
+ }) => Promise<void>;
185
+ log?: (level: "debug" | "info" | "warn" | "error", msg: string, data?: unknown) => void;
186
+ dedupWindowMs?: number;
187
+ dedupMaxEntries?: number;
188
+ }): {
189
+ stats: InboundRelayStats;
190
+ handlePush: (msg: WsNewMessage) => Promise<InboundRoutingResult>;
191
+ handlePollResult: (rawPollResult: unknown) => Promise<{
192
+ fetched: number;
193
+ routed: number;
194
+ dedupDropped: number;
195
+ }>;
196
+ };
197
+ export declare function routeInboundWsMessage(params: {
198
+ cfg: OpenClawConfig;
199
+ accountId: string;
200
+ account: ResolvedWTTAccount;
201
+ msg: WsNewMessage;
202
+ channelRuntime?: ChannelRuntimeLike;
203
+ decryptContent?: (content: string) => Promise<string>;
204
+ deliver?: (params: {
205
+ to: string;
206
+ payload: Record<string, unknown>;
207
+ }) => Promise<void>;
208
+ typingSignal?: (params: {
209
+ topicId: string;
210
+ state: "start" | "stop";
211
+ ttlMs?: number;
212
+ }) => Promise<void>;
213
+ log?: (level: "debug" | "info" | "warn" | "error", msg: string, data?: unknown) => void;
214
+ }): Promise<InboundRoutingResult>;
215
+ declare function startGatewayAccount(ctx: GatewayStartContext): Promise<void>;
216
+ export declare const wttPlugin: {
217
+ id: string;
218
+ meta: {
219
+ id: string;
220
+ label: string;
221
+ selectionLabel: string;
222
+ docsPath: string;
223
+ docsLabel: string;
224
+ blurb: string;
225
+ aliases: string[];
226
+ order: number;
227
+ };
228
+ capabilities: {
229
+ chatTypes: string[];
230
+ threads: boolean;
231
+ media: boolean;
232
+ };
233
+ reload: {
234
+ configPrefixes: string[];
235
+ };
236
+ config: {
237
+ listAccountIds: typeof listAccountIds;
238
+ resolveAccount: typeof resolveAccount;
239
+ defaultAccountId: () => string;
240
+ isConfigured: (account: ResolvedWTTAccount) => boolean;
241
+ describeAccount: (account: ResolvedWTTAccount) => {
242
+ accountId: string;
243
+ name: string | undefined;
244
+ enabled: boolean;
245
+ configured: boolean;
246
+ cloudUrl: string;
247
+ };
248
+ };
249
+ gateway: {
250
+ startAccount: typeof startGatewayAccount;
251
+ stopAccount: (ctx: {
252
+ accountId: string;
253
+ }) => Promise<void>;
254
+ };
255
+ outbound: {
256
+ deliveryMode: string;
257
+ textChunkLimit: number;
258
+ resolveTarget: ({ to }: {
259
+ to: string;
260
+ }) => string;
261
+ sendText: typeof sendText;
262
+ sendMedia: typeof sendMedia;
263
+ };
264
+ agentPrompt: {
265
+ messageToolHints: () => string[];
266
+ };
267
+ hooks: {
268
+ register: typeof registerHook;
269
+ runBefore: (ctx: Parameters<HookFn>[0]) => Promise<void>;
270
+ runAfter: (ctx: Parameters<HookFn>[0]) => Promise<void>;
271
+ };
272
+ getClient: typeof getClient;
273
+ };
274
+ export {};
275
+ //# sourceMappingURL=channel.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"channel.d.ts","sourceRoot":"","sources":["../src/channel.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,KAAK,EACV,gBAAgB,EAChB,kBAAkB,EAClB,YAAY,EAGb,MAAM,YAAY,CAAC;AACpB,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,sBAAsB,CAAC;AAYpE,OAAO,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAsBhD,KAAK,cAAc,GAAG;IACpB,OAAO,CAAC,EAAE;QACR,KAAK,CAAC,EAAE,MAAM,CAAC;KAChB,CAAC;IACF,QAAQ,CAAC,EAAE;QACT,GAAG,CAAC,EAAE;YACJ,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,gBAAgB,CAAC,CAAC;SAC7C,GAAG,gBAAgB,CAAC;KACtB,CAAC;CACH,CAAC;AAEF,KAAK,MAAM,GAAG,CAAC,GAAG,EAAE;IAClB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC,MAAM,E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