@a1hvdy/cc-openclaw 0.25.0 → 0.25.1

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.
@@ -0,0 +1,52 @@
1
+ /**
2
+ * src/channels/telegram-mirror/inbound-handler.ts — v0.25.1 wire-up.
3
+ *
4
+ * The piece that was missing from v0.25.0: subscribes to OpenClaw's
5
+ * `before_dispatch` event, identifies mirror slash commands, routes
6
+ * through `dispatchCommand` (from commands.ts), and forwards the
7
+ * resulting TelegramAction list out via `telegram-bot-api`'s sendTg.
8
+ *
9
+ * Returns `{ handled: true }` on dispatch so OpenClaw's default model
10
+ * route (or any built-in command handler) doesn't ALSO respond — the
11
+ * legacy event-reducer's `/quota` / `/sessions` handlers used the same
12
+ * claim shape.
13
+ *
14
+ * Out-of-scope for v0.25.1 (deferred to v0.25.2+):
15
+ * • Tool/text/turn stream-event subscription → mirror-card render.
16
+ * • callback_query handling for inline-keyboard taps.
17
+ * • Burst-accumulator + compose-buffer engine injection (the
18
+ * ComposeBuffer + BurstAccumulator capture user text but the
19
+ * concatenated payload from /send still needs to reach the engine
20
+ * as a synthetic user message — that's a separate dispatch path).
21
+ *
22
+ * Single shared CallbackMap + ComposeBuffer per process so callback
23
+ * resolution and compose state survive across handler invocations.
24
+ */
25
+ import { CallbackMap } from './callback-mapping.js';
26
+ import { ComposeBuffer } from './compose-buffer.js';
27
+ export interface InboundHandlerApi {
28
+ on(event: string, handler: (...args: unknown[]) => unknown | Promise<unknown>): void;
29
+ logger?: {
30
+ info: (msg: string) => void;
31
+ warn: (msg: string) => void;
32
+ };
33
+ }
34
+ /**
35
+ * Internal handler state — exported only for tests so they can inspect
36
+ * compose-buffer state + callback-map without going through Telegram.
37
+ */
38
+ export interface HandlerState {
39
+ callbackMap: CallbackMap;
40
+ composeBuffer: ComposeBuffer;
41
+ }
42
+ export declare function createHandlerState(): HandlerState;
43
+ /**
44
+ * Register the inbound dispatcher. Called by mirror's register() at boot.
45
+ *
46
+ * Hooked to `before_dispatch` — OpenClaw's name for the inbound-message
47
+ * event surface. We return `{ handled: true }` to claim the message when
48
+ * it's a known mirror slash command; `undefined` lets the event proceed
49
+ * to OpenClaw's default routing (which is what we want for non-slash
50
+ * user text destined for the model).
51
+ */
52
+ export declare function registerInboundHandler(api: InboundHandlerApi, state?: HandlerState): HandlerState;
@@ -0,0 +1,115 @@
1
+ /**
2
+ * src/channels/telegram-mirror/inbound-handler.ts — v0.25.1 wire-up.
3
+ *
4
+ * The piece that was missing from v0.25.0: subscribes to OpenClaw's
5
+ * `before_dispatch` event, identifies mirror slash commands, routes
6
+ * through `dispatchCommand` (from commands.ts), and forwards the
7
+ * resulting TelegramAction list out via `telegram-bot-api`'s sendTg.
8
+ *
9
+ * Returns `{ handled: true }` on dispatch so OpenClaw's default model
10
+ * route (or any built-in command handler) doesn't ALSO respond — the
11
+ * legacy event-reducer's `/quota` / `/sessions` handlers used the same
12
+ * claim shape.
13
+ *
14
+ * Out-of-scope for v0.25.1 (deferred to v0.25.2+):
15
+ * • Tool/text/turn stream-event subscription → mirror-card render.
16
+ * • callback_query handling for inline-keyboard taps.
17
+ * • Burst-accumulator + compose-buffer engine injection (the
18
+ * ComposeBuffer + BurstAccumulator capture user text but the
19
+ * concatenated payload from /send still needs to reach the engine
20
+ * as a synthetic user message — that's a separate dispatch path).
21
+ *
22
+ * Single shared CallbackMap + ComposeBuffer per process so callback
23
+ * resolution and compose state survive across handler invocations.
24
+ */
25
+ import { dispatchCommand, parseSlash, COMMAND_HANDLERS } from './commands.js';
26
+ import { sendTg, editTg } from '../../lib/telegram-bot-api.js';
27
+ import { CallbackMap } from './callback-mapping.js';
28
+ import { ComposeBuffer } from './compose-buffer.js';
29
+ const PLUGIN_TAG = '[cc-openclaw/telegram-mirror/inbound]';
30
+ export function createHandlerState() {
31
+ return {
32
+ callbackMap: new CallbackMap(),
33
+ composeBuffer: new ComposeBuffer(),
34
+ };
35
+ }
36
+ /**
37
+ * The set of slash commands the mirror claims. Names match what
38
+ * dispatchCommand recognises (commands.ts COMMAND_HANDLERS keys).
39
+ */
40
+ const MIRROR_COMMANDS = new Set(Object.keys(COMMAND_HANDLERS));
41
+ /**
42
+ * Forward a single TelegramAction to the actual Telegram API. Returns
43
+ * the API response (or {ok:false} on failure). Pure I/O — no state
44
+ * mutation.
45
+ *
46
+ * editMessageText and sendDocument variants land in v0.25.2 when the
47
+ * render pipeline and plan-attachment dispatch wire up.
48
+ */
49
+ async function forwardAction(action, threadId, logger) {
50
+ try {
51
+ if (action.type === 'sendMessage') {
52
+ await sendTg(String(action.chat_id), action.text, threadId !== undefined ? String(threadId) : undefined, action.reply_markup);
53
+ return;
54
+ }
55
+ if (action.type === 'editMessageText') {
56
+ await editTg(String(action.chat_id), action.message_id, action.text, action.reply_markup);
57
+ return;
58
+ }
59
+ // sendDocument: v0.25.2 — plan-mode attachment wire-up.
60
+ logger.warn(`${PLUGIN_TAG} action type "${action.type}" not yet forwarded (deferred to v0.25.2)`);
61
+ }
62
+ catch (err) {
63
+ logger.warn(`${PLUGIN_TAG} forwardAction failed: ${err.message}`);
64
+ }
65
+ }
66
+ /**
67
+ * Register the inbound dispatcher. Called by mirror's register() at boot.
68
+ *
69
+ * Hooked to `before_dispatch` — OpenClaw's name for the inbound-message
70
+ * event surface. We return `{ handled: true }` to claim the message when
71
+ * it's a known mirror slash command; `undefined` lets the event proceed
72
+ * to OpenClaw's default routing (which is what we want for non-slash
73
+ * user text destined for the model).
74
+ */
75
+ export function registerInboundHandler(api, state = createHandlerState()) {
76
+ const logger = (api.logger ?? console);
77
+ api.on('before_dispatch', async (...args) => {
78
+ const event = args[0];
79
+ if (!event)
80
+ return undefined;
81
+ if (event.channel !== 'telegram')
82
+ return undefined;
83
+ // callback_query rides on `before_dispatch` too — deferred to v0.25.2.
84
+ if (event.raw?.callback_query)
85
+ return undefined;
86
+ const text = event.raw?.message?.text;
87
+ if (typeof text !== 'string')
88
+ return undefined;
89
+ const parsed = parseSlash(text);
90
+ if (!parsed)
91
+ return undefined;
92
+ if (!MIRROR_COMMANDS.has(parsed.cmd))
93
+ return undefined;
94
+ const chatRaw = event.raw?.message?.chat?.id;
95
+ const chatId = chatRaw !== undefined && chatRaw !== null ? String(chatRaw) : '';
96
+ if (!chatId)
97
+ return undefined;
98
+ const threadId = event.raw?.message?.message_thread_id;
99
+ const result = dispatchCommand(parsed, {
100
+ chatId,
101
+ callbackMap: state.callbackMap,
102
+ composeBuffer: state.composeBuffer,
103
+ });
104
+ if (!result)
105
+ return undefined;
106
+ for (const action of result.actions) {
107
+ await forwardAction(action, threadId, logger);
108
+ }
109
+ logger.info(`${PLUGIN_TAG} dispatched /${parsed.cmd}${parsed.args.length ? ' ' + parsed.args.join(' ') : ''} (chat=${chatId}, actions=${result.actions.length})`);
110
+ return { handled: true };
111
+ });
112
+ logger.info(`${PLUGIN_TAG} subscribed to before_dispatch — ${MIRROR_COMMANDS.size} commands armed.`);
113
+ return state;
114
+ }
115
+ //# sourceMappingURL=inbound-handler.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"inbound-handler.js","sourceRoot":"","sources":["../../../../src/channels/telegram-mirror/inbound-handler.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAEH,OAAO,EAAE,eAAe,EAAE,UAAU,EAAE,gBAAgB,EAAuB,MAAM,eAAe,CAAC;AACnG,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,+BAA+B,CAAC;AAC/D,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AACpD,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAEpD,MAAM,UAAU,GAAG,uCAAuC,CAAC;AAkC3D,MAAM,UAAU,kBAAkB;IAChC,OAAO;QACL,WAAW,EAAE,IAAI,WAAW,EAAE;QAC9B,aAAa,EAAE,IAAI,aAAa,EAAE;KACnC,CAAC;AACJ,CAAC;AAED;;;GAGG;AACH,MAAM,eAAe,GAAG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AC,IAAI,CACT,GAAG,UAAU,gBAAgB,MAAM,CAAC,GAAG,GAAG,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,GAAG,GAAG,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,UAAU,MAAM,aAAa,MAAM,CAAC,OAAO,CAAC,MAAM,GAAG,CACrJ,CAAC;QACF,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;IAC3B,CAAC,CAAC,CAAC;IAEH,MAAM,CAAC,IAAI,CAAC,GAAG,UAAU,oCAAoC,eAAe,CAAC,IAAI,kBAAkB,CAAC,CAAC;IACrG,OAAO,KAAK,CAAC;AACf,CAAC"}
@@ -18,6 +18,7 @@
18
18
  */
19
19
  import { defaultRegisterGuard } from '../../lib/register-guard.js';
20
20
  import { initBotTokenFromConfig } from '../../lib/telegram-bot-api.js';
21
+ import { registerInboundHandler } from './inbound-handler.js';
21
22
  /**
22
23
  * Mirror channel register — idempotent via defaultRegisterGuard.
23
24
  *
@@ -28,14 +29,21 @@ import { initBotTokenFromConfig } from '../../lib/telegram-bot-api.js';
28
29
  export function register(api) {
29
30
  defaultRegisterGuard.guard('cc-openclaw/telegram-mirror', api, () => {
30
31
  const logger = api.logger || console;
31
- logger.info('[cc-openclaw/telegram-mirror] M0 skeleton loaded no handlers wired yet (CC_OPENCLAW_TERMINAL_MIRROR=1).');
32
- // v0.25.0 M16 — initialise Telegram bot token (token sourcing migrated
32
+ logger.info('[cc-openclaw/telegram-mirror] register()wiring inbound dispatcher (v0.25.1).');
33
+ // v0.25.0 M16 — initialise Telegram bot token (sourcing migrated
33
34
  // out of the legacy live-card module into src/lib/telegram-bot-api).
34
35
  // Same precedence as before: api.config first, then ~/.openclaw/openclaw.json.
35
36
  initBotTokenFromConfig({
36
37
  config: api.config,
37
38
  logger: logger,
38
39
  });
40
+ // v0.25.1 — subscribe before_dispatch and route mirror slash commands
41
+ // through dispatchCommand → telegram-bot-api. Without this, v0.25.0's
42
+ // handlers were unreachable from the live Telegram path.
43
+ registerInboundHandler({
44
+ on: api.on.bind(api),
45
+ logger: logger,
46
+ });
39
47
  });
40
48
  }
41
49
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/channels/telegram-mirror/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,OAAO,EAAE,oBAAoB,EAAE,MAAM,6BAA6B,CAAC;AACnE,OAAO,EAAE,sBAAsB,EAAE,MAAM,+BAA+B,CAAC;AAOvE;;;;;;GAMG;AACH,MAAM,UAAU,QAAQ,CAAC,GAAc;IACrC,oBAAoB,CAAC,KAAK,CAAC,6BAA6B,EAAE,GAAG,EAAE,GAAG,EAAE;QAClE,MAAM,MAAM,GAAG,GAAG,CAAC,MAAM,IAAI,OAAO,CAAC;QACrC,MAAM,CAAC,IAAI,CACT,2GAA2G,CAC5G,CAAC;QACF,uEAAuE;QACvE,qEAAqE;QACrE,+EAA+E;QAC/E,sBAAsB,CAAC;YACrB,MAAM,EAAG,GAAuD,CAAC,MAAM;YACvE,MAAM,EAAE,MAAiF;SAC1F,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/channels/telegram-mirror/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,OAAO,EAAE,oBAAoB,EAAE,MAAM,6BAA6B,CAAC;AACnE,OAAO,EAAE,sBAAsB,EAAE,MAAM,+BAA+B,CAAC;AACvE,OAAO,EAAE,sBAAsB,EAAE,MAAM,sBAAsB,CAAC;AAO9D;;;;;;GAMG;AACH,MAAM,UAAU,QAAQ,CAAC,GAAc;IACrC,oBAAoB,CAAC,KAAK,CAAC,6BAA6B,EAAE,GAAG,EAAE,GAAG,EAAE;QAClE,MAAM,MAAM,GAAG,GAAG,CAAC,MAAM,IAAI,OAAO,CAAC;QACrC,MAAM,CAAC,IAAI,CACT,iFAAiF,CAClF,CAAC;QACF,iEAAiE;QACjE,qEAAqE;QACrE,+EAA+E;QAC/E,sBAAsB,CAAC;YACrB,MAAM,EAAG,GAAuD,CAAC,MAAM;YACvE,MAAM,EAAE,MAAiF;SAC1F,CAAC,CAAC;QACH,sEAAsE;QACtE,sEAAsE;QACtE,yDAAyD;QACzD,sBAAsB,CAAC;YACrB,EAAE,EAAE,GAAG,CAAC,EAAE,CAAC,IAAI,CAAC,GAAG,CAAC;YACpB,MAAM,EAAE,MAAiF;SAC1F,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@a1hvdy/cc-openclaw",
3
- "version": "0.25.0",
3
+ "version": "0.25.1",
4
4
  "description": "A1xAI's Anthropic CLI bridge plugin for OpenClaw",
5
5
  "author": "@a1cy",
6
6
  "license": "MIT",