weixin-agent-sdk 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.
@@ -0,0 +1,60 @@
1
+ //#region src/agent/interface.d.ts
2
+ /**
3
+ * Agent interface — any AI backend that can handle a chat message.
4
+ *
5
+ * Implement this interface to connect WeChat to your own AI service.
6
+ * The WeChat bridge calls `chat()` for each inbound message and sends
7
+ * the returned response back to the user.
8
+ */
9
+ interface Agent {
10
+ /** Process a single message and return a reply. */
11
+ chat(request: ChatRequest): Promise<ChatResponse>;
12
+ }
13
+ interface ChatRequest {
14
+ /** Conversation / user identifier. Use this to maintain per-user context. */
15
+ conversationId: string;
16
+ /** Text content of the message. */
17
+ text: string;
18
+ /** Attached media file (image, audio, video, or generic file). */
19
+ media?: {
20
+ type: "image" | "audio" | "video" | "file"; /** Local file path (already downloaded and decrypted). */
21
+ filePath: string; /** MIME type, e.g. "image/jpeg", "audio/wav". */
22
+ mimeType: string; /** Original filename (available for file attachments). */
23
+ fileName?: string;
24
+ };
25
+ }
26
+ interface ChatResponse {
27
+ /** Reply text (may contain markdown — will be converted to plain text before sending). */
28
+ text?: string;
29
+ /** Reply media file. */
30
+ media?: {
31
+ type: "image" | "video" | "file"; /** Local file path or HTTPS URL. */
32
+ url: string; /** Filename hint (for file attachments). */
33
+ fileName?: string;
34
+ };
35
+ }
36
+ //#endregion
37
+ //#region src/bot.d.ts
38
+ type LoginOptions = {
39
+ /** Override the API base URL. */baseUrl?: string; /** Log callback (defaults to console.log). */
40
+ log?: (msg: string) => void;
41
+ };
42
+ type StartOptions = {
43
+ /** Account ID to use. Auto-selects the first registered account if omitted. */accountId?: string; /** AbortSignal to stop the bot. */
44
+ abortSignal?: AbortSignal; /** Log callback (defaults to console.log). */
45
+ log?: (msg: string) => void;
46
+ };
47
+ /**
48
+ * Interactive QR-code login. Prints the QR code to the terminal and waits
49
+ * for the user to scan it with WeChat.
50
+ *
51
+ * Returns the normalized account ID on success.
52
+ */
53
+ declare function login(opts?: LoginOptions): Promise<string>;
54
+ /**
55
+ * Start the bot — long-polls for new messages and dispatches them to the agent.
56
+ * Blocks until the abort signal fires or an unrecoverable error occurs.
57
+ */
58
+ declare function start(agent: Agent, opts?: StartOptions): Promise<void>;
59
+ //#endregion
60
+ export { type Agent, type ChatRequest, type ChatResponse, type LoginOptions, type StartOptions, login, start };