@0xmaxma/claude-gateway 1.8.13 → 1.8.14
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.
- package/README.md +8 -0
- package/dist/agent/runner.d.ts +17 -0
- package/dist/agent/runner.d.ts.map +1 -1
- package/dist/agent/runner.js +187 -14
- package/dist/agent/runner.js.map +1 -1
- package/dist/api/router.d.ts.map +1 -1
- package/dist/api/router.js +237 -1
- package/dist/api/router.js.map +1 -1
- package/dist/api/wechat-access.d.ts +45 -0
- package/dist/api/wechat-access.d.ts.map +1 -0
- package/dist/api/wechat-access.js +48 -0
- package/dist/api/wechat-access.js.map +1 -0
- package/dist/history/types.d.ts +10 -1
- package/dist/history/types.d.ts.map +1 -1
- package/dist/history/types.js +10 -1
- package/dist/history/types.js.map +1 -1
- package/dist/session/process.d.ts.map +1 -1
- package/dist/session/process.js +1 -0
- package/dist/session/process.js.map +1 -1
- package/dist/types.d.ts +40 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/wechat/ilink-client.d.ts +194 -0
- package/dist/wechat/ilink-client.d.ts.map +1 -0
- package/dist/wechat/ilink-client.js +641 -0
- package/dist/wechat/ilink-client.js.map +1 -0
- package/dist/wechat/manager.d.ts +93 -0
- package/dist/wechat/manager.d.ts.map +1 -0
- package/dist/wechat/manager.js +409 -0
- package/dist/wechat/manager.js.map +1 -0
- package/mcp/server.ts +2 -0
- package/mcp/tools/wechat/client.ts +49 -0
- package/mcp/tools/wechat/module.ts +88 -0
- package/package.json +1 -1
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WeChat outbound tool module — exposes `wechat_reply` to the Claude session.
|
|
3
|
+
*
|
|
4
|
+
* WeChat is a ToolModule (reply-only): inbound arrives via the gateway's own
|
|
5
|
+
* WeChatManager long-poll loop (src/wechat/manager.ts), not here. Unlike
|
|
6
|
+
* Slack (`mcp/tools/slack/module.ts`), this module cannot talk to the
|
|
7
|
+
* third-party API directly — the live iLink session (credentials, per-
|
|
8
|
+
* recipient context tokens) only exists inside the main gateway process, so
|
|
9
|
+
* every send is proxied through that process's own `/wechat/send` route,
|
|
10
|
+
* the same reasoning WhatsApp's Baileys socket needs (see
|
|
11
|
+
* src/api/router.ts's `/whatsapp/send` route once that channel lands, and
|
|
12
|
+
* `mcp/tools/cron/module.ts` for the same "call back into our own gateway
|
|
13
|
+
* API" shape this module follows).
|
|
14
|
+
*/
|
|
15
|
+
import type { ToolModule, McpToolDefinition, McpToolResult, ToolVisibility } from '../../types';
|
|
16
|
+
import { WeChatClient } from './client';
|
|
17
|
+
|
|
18
|
+
export class WeChatModule implements ToolModule {
|
|
19
|
+
id = 'wechat';
|
|
20
|
+
toolVisibility: ToolVisibility = 'current-channel';
|
|
21
|
+
|
|
22
|
+
private client: WeChatClient | null = null;
|
|
23
|
+
|
|
24
|
+
isEnabled(): boolean {
|
|
25
|
+
return (
|
|
26
|
+
process.env.GATEWAY_ORIGIN_CHANNEL === 'wechat' &&
|
|
27
|
+
Boolean(process.env.GATEWAY_API_URL && process.env.GATEWAY_AGENT_ID)
|
|
28
|
+
);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
private getClient(): WeChatClient {
|
|
32
|
+
if (!this.client) {
|
|
33
|
+
const apiUrl = process.env.GATEWAY_API_URL!;
|
|
34
|
+
const agentId = process.env.GATEWAY_AGENT_ID!;
|
|
35
|
+
const apiKey = process.env.GATEWAY_API_KEY;
|
|
36
|
+
this.client = new WeChatClient(apiUrl, agentId, apiKey);
|
|
37
|
+
}
|
|
38
|
+
return this.client;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
getTools(): McpToolDefinition[] {
|
|
42
|
+
return [
|
|
43
|
+
{
|
|
44
|
+
name: 'wechat_reply',
|
|
45
|
+
description:
|
|
46
|
+
'Send a reply to the current WeChat conversation. ' +
|
|
47
|
+
'Pass chat_id (the WeChat sender id shown in the <channel> tag) and text. ' +
|
|
48
|
+
'Text-only for now — WeChat media sending is not yet supported.',
|
|
49
|
+
inputSchema: {
|
|
50
|
+
type: 'object',
|
|
51
|
+
properties: {
|
|
52
|
+
chat_id: {
|
|
53
|
+
type: 'string',
|
|
54
|
+
description: 'WeChat sender id to send to (the chat_id from the channel turn).',
|
|
55
|
+
},
|
|
56
|
+
text: {
|
|
57
|
+
type: 'string',
|
|
58
|
+
description: 'Message text.',
|
|
59
|
+
},
|
|
60
|
+
},
|
|
61
|
+
required: ['chat_id', 'text'],
|
|
62
|
+
additionalProperties: false,
|
|
63
|
+
},
|
|
64
|
+
},
|
|
65
|
+
];
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
async handleTool(name: string, args: Record<string, unknown>): Promise<McpToolResult> {
|
|
69
|
+
if (name !== 'wechat_reply') {
|
|
70
|
+
return { content: [{ type: 'text', text: `unknown tool: ${name}` }], isError: true };
|
|
71
|
+
}
|
|
72
|
+
const chatId = args.chat_id as string | undefined;
|
|
73
|
+
const text = args.text as string | undefined;
|
|
74
|
+
if (!chatId || !text) {
|
|
75
|
+
return {
|
|
76
|
+
content: [{ type: 'text', text: 'wechat_reply failed: chat_id and text are required' }],
|
|
77
|
+
isError: true,
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
try {
|
|
81
|
+
await this.getClient().send(chatId, text);
|
|
82
|
+
return { content: [{ type: 'text', text: 'sent' }] };
|
|
83
|
+
} catch (err) {
|
|
84
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
85
|
+
return { content: [{ type: 'text', text: `wechat_reply failed: ${msg}` }], isError: true };
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
}
|