weacpx 0.7.0 → 0.8.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 (124) hide show
  1. package/README.md +10 -564
  2. package/package.json +10 -72
  3. package/plugin-api.d.ts +2 -0
  4. package/plugin-api.js +5 -0
  5. package/LICENSE +0 -21
  6. package/config.example.json +0 -44
  7. package/dist/bridge/bridge-main.js +0 -2126
  8. package/dist/channels/channel-scope.d.ts +0 -17
  9. package/dist/channels/cli/provider.d.ts +0 -73
  10. package/dist/channels/cli/registry.d.ts +0 -7
  11. package/dist/channels/cli/weixin-provider.d.ts +0 -2
  12. package/dist/channels/create-channel.d.ts +0 -16
  13. package/dist/channels/media-store.d.ts +0 -29
  14. package/dist/channels/media-types.d.ts +0 -28
  15. package/dist/channels/outbound-media-safety.d.ts +0 -7
  16. package/dist/channels/plugin.d.ts +0 -9
  17. package/dist/channels/types.d.ts +0 -124
  18. package/dist/channels/weixin-channel.d.ts +0 -25
  19. package/dist/cli.js +0 -47662
  20. package/dist/commands/command-hints.d.ts +0 -11
  21. package/dist/commands/command-list.d.ts +0 -3
  22. package/dist/commands/config-clone.d.ts +0 -2
  23. package/dist/commands/handlers/agent-handler.d.ts +0 -6
  24. package/dist/commands/handlers/config-handler.d.ts +0 -5
  25. package/dist/commands/handlers/later-handler.d.ts +0 -21
  26. package/dist/commands/handlers/orchestration-handler.d.ts +0 -16
  27. package/dist/commands/handlers/permission-handler.d.ts +0 -9
  28. package/dist/commands/handlers/session-handler.d.ts +0 -39
  29. package/dist/commands/handlers/session-list-marker.d.ts +0 -1
  30. package/dist/commands/handlers/workspace-handler.d.ts +0 -8
  31. package/dist/commands/help/help-registry.d.ts +0 -4
  32. package/dist/commands/help/help-types.d.ts +0 -12
  33. package/dist/commands/parse-command.d.ts +0 -178
  34. package/dist/commands/router-types.d.ts +0 -144
  35. package/dist/commands/workspace-name.d.ts +0 -4
  36. package/dist/commands/workspace-path.d.ts +0 -4
  37. package/dist/config/agent-templates.d.ts +0 -4
  38. package/dist/config/config-store.d.ts +0 -13
  39. package/dist/config/load-config.d.ts +0 -10
  40. package/dist/config/resolve-agent-command.d.ts +0 -2
  41. package/dist/config/types.d.ts +0 -85
  42. package/dist/formatting/render-text.d.ts +0 -23
  43. package/dist/logging/app-logger.d.ts +0 -23
  44. package/dist/logging/rotating-file-writer.d.ts +0 -2
  45. package/dist/orchestration/async-mutex.d.ts +0 -4
  46. package/dist/orchestration/build-coordinator-prompt.d.ts +0 -66
  47. package/dist/orchestration/orchestration-service.d.ts +0 -471
  48. package/dist/orchestration/orchestration-types.d.ts +0 -181
  49. package/dist/orchestration/progress-line-parser.d.ts +0 -19
  50. package/dist/orchestration/render-delegate-group-result.d.ts +0 -6
  51. package/dist/orchestration/render-delegate-question-package.d.ts +0 -21
  52. package/dist/orchestration/render-delegate-result.d.ts +0 -2
  53. package/dist/orchestration/task-watch-timeouts.d.ts +0 -5
  54. package/dist/perf/perf-log-writer.d.ts +0 -25
  55. package/dist/perf/perf-tracer.d.ts +0 -54
  56. package/dist/plugin-api.d.ts +0 -18
  57. package/dist/plugin-api.js +0 -337
  58. package/dist/plugins/compatibility.d.ts +0 -16
  59. package/dist/plugins/known-plugins.d.ts +0 -9
  60. package/dist/plugins/types.d.ts +0 -18
  61. package/dist/runtime/conversation-executor.d.ts +0 -7
  62. package/dist/runtime/core-home.d.ts +0 -26
  63. package/dist/runtime/turn-lane.d.ts +0 -2
  64. package/dist/scheduled/parse-later-time.d.ts +0 -11
  65. package/dist/scheduled/scheduled-render.d.ts +0 -7
  66. package/dist/scheduled/scheduled-service.d.ts +0 -41
  67. package/dist/scheduled/scheduled-types.d.ts +0 -29
  68. package/dist/sessions/active-turn-registry.d.ts +0 -6
  69. package/dist/sessions/session-service.d.ts +0 -118
  70. package/dist/state/state-store.d.ts +0 -8
  71. package/dist/state/types.d.ts +0 -51
  72. package/dist/transport/tool-event-mode.d.ts +0 -14
  73. package/dist/transport/types.d.ts +0 -129
  74. package/dist/util/path.d.ts +0 -4
  75. package/dist/util/private-file.d.ts +0 -26
  76. package/dist/util/sanitize.d.ts +0 -10
  77. package/dist/util/text.d.ts +0 -3
  78. package/dist/version.d.ts +0 -3
  79. package/dist/weixin/agent/interface.d.ts +0 -79
  80. package/dist/weixin/api/api.d.ts +0 -76
  81. package/dist/weixin/api/config-cache.d.ts +0 -35
  82. package/dist/weixin/api/session-guard.d.ts +0 -17
  83. package/dist/weixin/api/types.d.ts +0 -203
  84. package/dist/weixin/auth/accounts.d.ts +0 -69
  85. package/dist/weixin/auth/login-qr.d.ts +0 -37
  86. package/dist/weixin/bot.d.ts +0 -67
  87. package/dist/weixin/cdn/aes-ecb.d.ts +0 -6
  88. package/dist/weixin/cdn/cdn-upload.d.ts +0 -17
  89. package/dist/weixin/cdn/cdn-url.d.ts +0 -11
  90. package/dist/weixin/cdn/pic-decrypt.d.ts +0 -9
  91. package/dist/weixin/cdn/upload.d.ts +0 -42
  92. package/dist/weixin/index.d.ts +0 -6
  93. package/dist/weixin/media/media-download.d.ts +0 -18
  94. package/dist/weixin/media/mime.d.ts +0 -6
  95. package/dist/weixin/media/silk-transcode.d.ts +0 -8
  96. package/dist/weixin/messaging/completion-notice.d.ts +0 -2
  97. package/dist/weixin/messaging/debug-mode.d.ts +0 -9
  98. package/dist/weixin/messaging/deliver-coordinator-message.d.ts +0 -22
  99. package/dist/weixin/messaging/deliver-orchestration-task-notice.d.ts +0 -18
  100. package/dist/weixin/messaging/deliver-orchestration-task-progress.d.ts +0 -16
  101. package/dist/weixin/messaging/error-notice.d.ts +0 -13
  102. package/dist/weixin/messaging/execute-chat-turn.d.ts +0 -12
  103. package/dist/weixin/messaging/final-heads-up.d.ts +0 -5
  104. package/dist/weixin/messaging/foreground-gate.d.ts +0 -3
  105. package/dist/weixin/messaging/handle-weixin-message-turn.d.ts +0 -36
  106. package/dist/weixin/messaging/inbound.d.ts +0 -87
  107. package/dist/weixin/messaging/markdown-filter.d.ts +0 -45
  108. package/dist/weixin/messaging/orchestration-notice-accounts.d.ts +0 -2
  109. package/dist/weixin/messaging/quota-errors.d.ts +0 -8
  110. package/dist/weixin/messaging/quota-manager.d.ts +0 -58
  111. package/dist/weixin/messaging/scheduled-turn.d.ts +0 -22
  112. package/dist/weixin/messaging/send-errors.d.ts +0 -39
  113. package/dist/weixin/messaging/send-media.d.ts +0 -23
  114. package/dist/weixin/messaging/send-orchestration-notice.d.ts +0 -10
  115. package/dist/weixin/messaging/send.d.ts +0 -73
  116. package/dist/weixin/messaging/slash-commands.d.ts +0 -40
  117. package/dist/weixin/monitor/consumer-lock.d.ts +0 -24
  118. package/dist/weixin/monitor/monitor.d.ts +0 -38
  119. package/dist/weixin/storage/ensure-dir.d.ts +0 -1
  120. package/dist/weixin/storage/state-dir.d.ts +0 -2
  121. package/dist/weixin/storage/sync-buf.d.ts +0 -20
  122. package/dist/weixin/util/logger.d.ts +0 -14
  123. package/dist/weixin/util/random.d.ts +0 -10
  124. package/dist/weixin/util/redact.d.ts +0 -21
@@ -1,22 +0,0 @@
1
- import type { AppLogger } from "../../logging/app-logger";
2
- import { sendMessageWeixin } from "./send.js";
3
- export interface DeliverCoordinatorMessageInput {
4
- coordinatorSession: string;
5
- chatKey: string;
6
- accountId?: string;
7
- replyContextToken?: string;
8
- text: string;
9
- }
10
- export interface DeliverCoordinatorMessageDeps {
11
- listAccountIds: () => string[];
12
- resolveAccount: (accountId: string) => {
13
- accountId: string;
14
- baseUrl: string;
15
- token?: string;
16
- };
17
- getContextToken: (accountId: string, userId: string) => string | undefined;
18
- sendMessage?: typeof sendMessageWeixin;
19
- reserveMidSegment?: (chatKey: string) => boolean;
20
- logger: AppLogger;
21
- }
22
- export declare function deliverCoordinatorMessage(input: DeliverCoordinatorMessageInput, deps: DeliverCoordinatorMessageDeps): Promise<void>;
@@ -1,18 +0,0 @@
1
- import type { AppLogger } from "../../logging/app-logger";
2
- import type { OrchestrationTaskRecord } from "../../orchestration/orchestration-types";
3
- import { sendOrchestrationTaskNotice } from "./send-orchestration-notice.js";
4
- export interface DeliverOrchestrationTaskNoticeDeps {
5
- listAccountIds: () => string[];
6
- resolveAccount: (accountId: string) => {
7
- accountId: string;
8
- baseUrl: string;
9
- token?: string;
10
- };
11
- getContextToken: (accountId: string, userId: string) => string | undefined;
12
- markDelivered: (taskId: string, accountId: string) => Promise<void>;
13
- markFailed: (taskId: string, errorMessage: string) => Promise<void>;
14
- sendNotice?: typeof sendOrchestrationTaskNotice;
15
- reserveFinal?: (chatKey: string) => boolean;
16
- logger: AppLogger;
17
- }
18
- export declare function deliverOrchestrationTaskNotice(task: OrchestrationTaskRecord, deps: DeliverOrchestrationTaskNoticeDeps): Promise<void>;
@@ -1,16 +0,0 @@
1
- import type { AppLogger } from "../../logging/app-logger";
2
- import type { OrchestrationTaskRecord } from "../../orchestration/orchestration-types";
3
- import { sendMessageWeixin } from "./send.js";
4
- export interface DeliverOrchestrationTaskProgressDeps {
5
- listAccountIds: () => string[];
6
- resolveAccount: (accountId: string) => {
7
- accountId: string;
8
- baseUrl: string;
9
- token?: string;
10
- };
11
- getContextToken: (accountId: string, userId: string) => string | undefined;
12
- sendMessage?: typeof sendMessageWeixin;
13
- reserveMidSegment?: (chatKey: string) => boolean;
14
- logger: AppLogger;
15
- }
16
- export declare function deliverOrchestrationTaskProgress(task: OrchestrationTaskRecord, text: string, deps: DeliverOrchestrationTaskProgressDeps): Promise<void>;
@@ -1,13 +0,0 @@
1
- /**
2
- * Send a plain-text error notice back to the user.
3
- * Fire-and-forget: errors are logged but never thrown, so callers stay unaffected.
4
- * No-op when contextToken is absent (we have no conversation reference to reply into).
5
- */
6
- export declare function sendWeixinErrorNotice(params: {
7
- to: string;
8
- contextToken: string | undefined;
9
- message: string;
10
- baseUrl: string;
11
- token?: string;
12
- errLog: (m: string) => void;
13
- }): Promise<void>;
@@ -1,12 +0,0 @@
1
- import type { Agent, ChatRequest, ChatResponse } from "../agent/interface.js";
2
- export interface ExecuteChatTurnParams {
3
- agent: Agent;
4
- request: Omit<ChatRequest, "reply">;
5
- onReplySegment?: (text: string) => Promise<boolean | void>;
6
- }
7
- export interface ExecutedChatTurn {
8
- text?: string;
9
- media?: ChatResponse["media"];
10
- usedReply: boolean;
11
- }
12
- export declare function executeChatTurn(params: ExecuteChatTurnParams): Promise<ExecutedChatTurn>;
@@ -1,5 +0,0 @@
1
- export interface FinalHeadsUpInput {
2
- total: number;
3
- sentSoFar: number;
4
- }
5
- export declare function buildFinalHeadsUp(input: FinalHeadsUpInput): string;
@@ -1,3 +0,0 @@
1
- export declare function shouldDeliverSegment(isForeground: (() => boolean) | undefined): boolean;
2
- export type FinalDisposition = "send" | "store" | "drop";
3
- export declare function resolveFinalDisposition(isForeground: boolean, canStore: boolean): FinalDisposition;
@@ -1,36 +0,0 @@
1
- import type { Agent } from "../agent/interface.js";
2
- import type { WeixinMessage } from "../api/types.js";
3
- import { RuntimeMediaStore } from "../../channels/media-store.js";
4
- import { downloadMediaFromItem } from "../media/media-download.js";
5
- import type { PendingFinalChunk } from "./quota-manager.js";
6
- import { type PerfTracer } from "../../perf/perf-tracer.js";
7
- export declare function chunkFinalText(text: string, maxBytes: number): string[];
8
- export declare function resolveMediaTempDir(customRoot?: string): string;
9
- export type HandleWeixinMessageTurnDeps = {
10
- accountId: string;
11
- agent: Agent;
12
- baseUrl: string;
13
- cdnBaseUrl: string;
14
- token?: string;
15
- typingTicket?: string;
16
- log: (msg: string) => void;
17
- errLog: (msg: string) => void;
18
- mediaTempDir?: string;
19
- onInbound?: (chatKey: string) => void;
20
- reserveFinal?: (chatKey: string) => boolean;
21
- finalRemaining?: (chatKey: string) => number;
22
- enqueuePendingFinal?: (chatKey: string, chunks: PendingFinalChunk[]) => void;
23
- hasPendingFinal?: (chatKey: string) => boolean;
24
- drainPendingFinal?: (chatKey: string, available: number) => PendingFinalChunk[];
25
- prependPendingFinal?: (chatKey: string, chunks: PendingFinalChunk[]) => void;
26
- mediaStore?: RuntimeMediaStore;
27
- downloadMediaFromItemFn?: typeof downloadMediaFromItem;
28
- allowedMediaRoots?: string[];
29
- perfTracer?: PerfTracer;
30
- isForeground?: () => boolean;
31
- boundSessionAlias?: string;
32
- onBackgroundFinal?: (alias: string, text: string, status: "done" | "error") => Promise<void>;
33
- };
34
- export declare function getWeixinMessageTurnLane(full: WeixinMessage): "normal" | "control";
35
- export declare function buildWeixinChatKey(accountId: string, userId: string): string;
36
- export declare function handleWeixinMessageTurn(full: WeixinMessage, deps: HandleWeixinMessageTurnDeps): Promise<void>;
@@ -1,87 +0,0 @@
1
- import type { ChannelMediaKind } from "../../channels/media-types.js";
2
- import type { WeixinMessage, MessageItem } from "../api/types.js";
3
- interface ContextTokenRetentionOptions {
4
- maxTokensPerAccount?: number;
5
- tokenTtlMs?: number;
6
- now?: () => number;
7
- }
8
- export declare function configureContextTokenRetentionForTests(options?: ContextTokenRetentionOptions): void;
9
- /**
10
- * Restore the per-account context-token cache from disk into memory.
11
- * Called at bot startup (after login). Missing/unreadable files are tolerated
12
- * silently; corrupt JSON is logged at warn level and ignored.
13
- */
14
- export declare function restoreContextTokens(accountId: string): void;
15
- /**
16
- * Drop all tokens for an account from both the in-memory cache and disk.
17
- * Called on logout so the next login does not see stale associations.
18
- */
19
- export declare function clearContextTokensForAccount(accountId: string): void;
20
- /** Store a context token for a given account+user pair (memory + disk). */
21
- export declare function setContextToken(accountId: string, userId: string, token: string): void;
22
- /** Retrieve the cached context token for a given account+user pair. */
23
- export declare function getContextToken(accountId: string, userId: string): string | undefined;
24
- /**
25
- * Of the given candidate accountIds, return those that have an active
26
- * context-token cached for the given user. `userId` may be a raw user id
27
- * or a `weixin:<accountId>:<userId>` chat-key — both forms resolve.
28
- */
29
- export declare function findAccountIdsByContextToken(accountIds: string[], userId: string): string[];
30
- /** Strip the `weixin:accountId:` prefix from a chat key, returning the bare user id. */
31
- export declare function normalizeWeixinUserIdFromChatKey(chatKey: string): string;
32
- /** Inbound context passed to the OpenClaw core pipeline (matches MsgContext shape). */
33
- export type WeixinMsgContext = {
34
- Body: string;
35
- From: string;
36
- To: string;
37
- AccountId: string;
38
- OriginatingChannel: "openclaw-weixin";
39
- OriginatingTo: string;
40
- MessageSid: string;
41
- Timestamp?: number;
42
- Provider: "openclaw-weixin";
43
- ChatType: "direct";
44
- /** Set by monitor after resolveAgentRoute so dispatchReplyFromConfig uses the correct session. */
45
- SessionKey?: string;
46
- context_token?: string;
47
- MediaUrl?: string;
48
- MediaPath?: string;
49
- MediaType?: string;
50
- /** Raw message body for framework command authorization. */
51
- CommandBody?: string;
52
- /** Whether the sender is authorized to execute slash commands. */
53
- CommandAuthorized?: boolean;
54
- };
55
- /** Returns true if the message item is a media type (image, video, file, or voice). */
56
- export declare function isMediaItem(item: MessageItem): boolean;
57
- export declare function bodyFromItemList(itemList?: MessageItem[]): string;
58
- export type WeixinInboundMediaOpts = {
59
- /** Local path to decrypted image file. */
60
- decryptedPicPath?: string;
61
- /** Local path to transcoded/raw voice file (.wav or .silk). */
62
- decryptedVoicePath?: string;
63
- /** MIME type for the voice file (e.g. "audio/wav" or "audio/silk"). */
64
- voiceMediaType?: string;
65
- /** Local path to decrypted file attachment. */
66
- decryptedFilePath?: string;
67
- /** MIME type for the file attachment (guessed from file_name). */
68
- fileMediaType?: string;
69
- /** Local path to decrypted video file. */
70
- decryptedVideoPath?: string;
71
- };
72
- /**
73
- * Convert a WeixinMessage from getUpdates to the inbound MsgContext for the core pipeline.
74
- * Media: only pass MediaPath (local file, after CDN download + decrypt).
75
- * We never pass MediaUrl — the upstream CDN URL is encrypted/auth-only.
76
- * Priority when multiple media types present: image > video > file > voice.
77
- */
78
- export declare function weixinMessageToMsgContext(msg: WeixinMessage, accountId: string, opts?: WeixinInboundMediaOpts): WeixinMsgContext;
79
- /** Extract the context_token from an inbound WeixinMsgContext. */
80
- export declare function getContextTokenFromMsgContext(ctx: WeixinMsgContext): string | undefined;
81
- export interface WeixinInboundMediaDescriptor {
82
- item: MessageItem;
83
- kind: ChannelMediaKind;
84
- fileName?: string;
85
- }
86
- export declare function extractWeixinMediaDescriptors(itemList?: MessageItem[]): WeixinInboundMediaDescriptor[];
87
- export {};
@@ -1,45 +0,0 @@
1
- /**
2
- * Streaming markdown filter — character-level state machine that strips
3
- * unsupported markdown syntax on-the-fly.
4
- *
5
- * Outputs as much filtered text as possible on each `feed()` call, only
6
- * holding back the minimum characters needed for pattern disambiguation
7
- * (e.g. a trailing `*` that might become `***`).
8
- *
9
- * Constructs passed through (not filtered):
10
- * - Code fences (```)
11
- * - Inline code (`)
12
- * - Tables (|...|)
13
- * - Horizontal rules (---, ***, ___)
14
- * - Bold (**)
15
- * - Italic/bold-italic wrapping non-CJK content
16
- *
17
- * Constructs filtered (markers stripped, content kept):
18
- * - Italic/bold-italic wrapping CJK content
19
- * - Headings H5/H6 (#####, ######)
20
- * - Images (![alt](url)) — removed entirely
21
- *
22
- * States:
23
- * - **sol** (start-of-line): checks for line-start patterns (```, >, #####, indent)
24
- * - **body**: scans for inline patterns (![, ~~, ***) and outputs safe chars
25
- * - **fence**: inside a fenced code block, passes through until closing ```
26
- * - **inline**: accumulating content inside an inline marker pair
27
- */
28
- export declare class StreamingMarkdownFilter {
29
- private buf;
30
- private fence;
31
- private sol;
32
- private inl;
33
- feed(delta: string): string;
34
- flush(): string;
35
- private pump;
36
- /** Inside a code fence: pass content and markers through verbatim. */
37
- private pumpFence;
38
- /** At start of line: detect and consume line-start patterns, then transition to body. */
39
- private pumpSOL;
40
- /** Scan line body for inline pattern triggers; output safe chars eagerly. */
41
- private pumpBody;
42
- /** Accumulate inline content until closing marker is found. */
43
- private pumpInline;
44
- private static containsCJK;
45
- }
@@ -1,2 +0,0 @@
1
- import type { OrchestrationTaskRecord } from "../../orchestration/orchestration-types";
2
- export declare function resolveOrchestrationNoticeAccountIds(task: Pick<OrchestrationTaskRecord, "accountId" | "deliveryAccountId">, availableAccountIds: string[]): string[];
@@ -1,8 +0,0 @@
1
- export declare class QuotaDeferredError extends Error {
2
- readonly chatKey: string;
3
- constructor(input: {
4
- chatKey: string;
5
- reason: string;
6
- });
7
- }
8
- export declare function isQuotaDeferredError(error: unknown): error is QuotaDeferredError;
@@ -1,58 +0,0 @@
1
- export declare const MID_BUDGET = 6;
2
- export declare const FINAL_BUDGET = 4;
3
- export interface PendingFinalChunk {
4
- /** Pre-formatted body, already carrying the (k/N) pagination prefix. */
5
- text: string;
6
- /** 1-based chunk index. */
7
- seq: number;
8
- /** Total chunk count for this final answer. */
9
- total: number;
10
- contextToken?: string;
11
- accountId?: string;
12
- }
13
- export interface QuotaSnapshot {
14
- remaining: number;
15
- midUsed: number;
16
- finalUsed: number;
17
- midRemaining: number;
18
- finalRemaining: number;
19
- }
20
- export interface QuotaObserver {
21
- onInbound?(chatKey: string): void;
22
- onMidReserved?(chatKey: string, snapshot: QuotaSnapshot): void;
23
- onMidRejected?(chatKey: string, snapshot: QuotaSnapshot): void;
24
- onFinalReserved?(chatKey: string, snapshot: QuotaSnapshot): void;
25
- onFinalRejected?(chatKey: string, snapshot: QuotaSnapshot): void;
26
- }
27
- export interface QuotaManagerOptions {
28
- maxStates?: number;
29
- stateTtlMs?: number;
30
- maxPendingFinalChunksPerChat?: number;
31
- now?: () => number;
32
- }
33
- export declare class QuotaManager {
34
- private readonly states;
35
- private readonly observer;
36
- private readonly normalizeKey;
37
- private readonly maxStates;
38
- private readonly stateTtlMs;
39
- private readonly maxPendingFinalChunksPerChat;
40
- private readonly now;
41
- constructor(observer?: QuotaObserver, normalizeKey?: (key: string) => string, options?: QuotaManagerOptions);
42
- onInbound(chatKey: string): void;
43
- reserveMidSegment(chatKey: string): boolean;
44
- reserveFinal(chatKey: string): boolean;
45
- finalRemaining(chatKey: string): number;
46
- enqueuePendingFinal(chatKey: string, chunks: PendingFinalChunk[]): void;
47
- prependPendingFinal(chatKey: string, chunks: PendingFinalChunk[]): void;
48
- drainPendingFinalUpToBudget(chatKey: string, available: number): PendingFinalChunk[];
49
- hasPendingFinal(chatKey: string): boolean;
50
- countPendingFinal(chatKey: string): number;
51
- clearPendingFinal(chatKey: string): void;
52
- snapshot(chatKey: string): QuotaSnapshot;
53
- private getOrCreate;
54
- private prune;
55
- private enforceMaxStates;
56
- private trimPendingFinalChunks;
57
- private deleteIfEmpty;
58
- }
@@ -1,22 +0,0 @@
1
- import type { AppLogger } from "../../logging/app-logger";
2
- import type { ScheduledChannelMessageInput } from "../../channels/types";
3
- import type { Agent } from "../agent/interface";
4
- import type { PendingFinalChunk } from "./quota-manager";
5
- import { sendMessageWeixin } from "./send";
6
- export interface ScheduledTurnDeps {
7
- agent: Agent;
8
- listAccountIds: () => string[];
9
- resolveAccount: (accountId: string) => {
10
- accountId: string;
11
- baseUrl: string;
12
- token?: string;
13
- };
14
- getContextToken: (accountId: string, userId: string) => string | undefined;
15
- reserveMidSegment: (chatKey: string) => boolean;
16
- reserveFinal: (chatKey: string) => boolean;
17
- finalRemaining?: (chatKey: string) => number;
18
- enqueuePendingFinal?: (chatKey: string, chunks: PendingFinalChunk[]) => void;
19
- sendMessage?: typeof sendMessageWeixin;
20
- logger: AppLogger;
21
- }
22
- export declare function executeScheduledTurn(input: ScheduledChannelMessageInput, deps: ScheduledTurnDeps): Promise<void>;
@@ -1,39 +0,0 @@
1
- /**
2
- * Structured error type for failed Weixin API calls.
3
- *
4
- * Two ways the API signals failure:
5
- * 1. Non-2xx HTTP status (network / gateway).
6
- * 2. 2xx HTTP with a JSON body whose `errcode` is non-zero (logical failure,
7
- * e.g. quota exhausted, invalid context_token, expired session). The
8
- * original implementation only handled case 1, so logical failures
9
- * appeared as silent successes — that is why "10 reply quota exhausted"
10
- * never showed up in the logs.
11
- */
12
- export declare class WeixinSendError extends Error {
13
- readonly endpoint: string;
14
- readonly httpStatus: number;
15
- readonly errcode?: number;
16
- readonly errmsg?: string;
17
- readonly textPreview: string;
18
- constructor(input: {
19
- endpoint: string;
20
- httpStatus: number;
21
- errcode?: number;
22
- errmsg?: string;
23
- textPreview: string;
24
- });
25
- }
26
- /** Type guard for callers that need to read structured fields. */
27
- export declare function isWeixinSendError(error: unknown): error is WeixinSendError;
28
- /**
29
- * Extract structured fields from any error for logging context.
30
- * Returns sparse object so spreading into log context only adds what we know.
31
- */
32
- export declare function describeWeixinSendError(error: unknown): {
33
- message: string;
34
- errcode?: number;
35
- errmsg?: string;
36
- httpStatus?: number;
37
- endpoint?: string;
38
- textPreview?: string;
39
- };
@@ -1,23 +0,0 @@
1
- import type { WeixinApiOptions } from "../api/api.js";
2
- import type { OutboundChannelMedia } from "../../channels/media-types.js";
3
- /**
4
- * Upload a local file and send it as a weixin message, routing by MIME type:
5
- * video/* → uploadVideoToWeixin + sendVideoMessageWeixin
6
- * image/* → uploadFileToWeixin + sendImageMessageWeixin
7
- * else → uploadFileAttachmentToWeixin + sendFileMessageWeixin
8
- *
9
- * Used by both the auto-reply deliver path (monitor.ts) and the outbound
10
- * sendMedia path (channel.ts) so they stay in sync.
11
- */
12
- export declare function sendWeixinMediaFile(params: {
13
- media?: OutboundChannelMedia;
14
- filePath: string;
15
- to: string;
16
- text: string;
17
- opts: WeixinApiOptions & {
18
- contextToken?: string;
19
- };
20
- cdnBaseUrl: string;
21
- }): Promise<{
22
- messageId: string;
23
- }>;
@@ -1,10 +0,0 @@
1
- import type { OrchestrationTaskRecord } from "../../orchestration/orchestration-types";
2
- import { sendMessageWeixin } from "./send.js";
3
- interface NoticeDeps {
4
- baseUrl: string;
5
- token?: string;
6
- contextToken: string;
7
- sendMessage?: typeof sendMessageWeixin;
8
- }
9
- export declare function sendOrchestrationTaskNotice(task: OrchestrationTaskRecord, deps: NoticeDeps): Promise<void>;
10
- export {};
@@ -1,73 +0,0 @@
1
- import type { WeixinApiOptions } from "../api/api.js";
2
- import type { UploadedFileInfo } from "../cdn/upload.js";
3
- export declare function generateClientId(): string;
4
- /**
5
- * Convert markdown-formatted model reply to plain text for Weixin delivery.
6
- * Backed by StreamingMarkdownFilter — preserves code blocks, tables, inline
7
- * backticks, non-CJK bold/italic; strips CJK italic/bold-italic markers,
8
- * images, and H5/H6 heading markers.
9
- */
10
- export declare function markdownToPlainText(text: string): string;
11
- /**
12
- * Send a plain text message downstream.
13
- * contextToken is required for all reply sends; missing it breaks conversation association.
14
- */
15
- export declare function sendMessageWeixin(params: {
16
- to: string;
17
- text: string;
18
- opts: WeixinApiOptions & {
19
- contextToken?: string;
20
- };
21
- }): Promise<{
22
- messageId: string;
23
- }>;
24
- /**
25
- * Send an image message downstream using a previously uploaded file.
26
- * Optionally include a text caption as a separate TEXT item before the image.
27
- *
28
- * ImageItem fields:
29
- * - media.encrypt_query_param: CDN download param
30
- * - media.aes_key: AES key, base64-encoded
31
- * - mid_size: original ciphertext file size
32
- */
33
- export declare function sendImageMessageWeixin(params: {
34
- to: string;
35
- text: string;
36
- uploaded: UploadedFileInfo;
37
- opts: WeixinApiOptions & {
38
- contextToken?: string;
39
- };
40
- }): Promise<{
41
- messageId: string;
42
- }>;
43
- /**
44
- * Send a video message downstream using a previously uploaded file.
45
- * VideoItem: media (CDN ref), video_size (ciphertext bytes).
46
- * Includes an optional text caption sent as a separate TEXT item first.
47
- */
48
- export declare function sendVideoMessageWeixin(params: {
49
- to: string;
50
- text: string;
51
- uploaded: UploadedFileInfo;
52
- opts: WeixinApiOptions & {
53
- contextToken?: string;
54
- };
55
- }): Promise<{
56
- messageId: string;
57
- }>;
58
- /**
59
- * Send a file attachment downstream using a previously uploaded file.
60
- * FileItem: media (CDN ref), file_name, len (plaintext bytes as string).
61
- * Includes an optional text caption sent as a separate TEXT item first.
62
- */
63
- export declare function sendFileMessageWeixin(params: {
64
- to: string;
65
- text: string;
66
- fileName: string;
67
- uploaded: UploadedFileInfo;
68
- opts: WeixinApiOptions & {
69
- contextToken?: string;
70
- };
71
- }): Promise<{
72
- messageId: string;
73
- }>;
@@ -1,40 +0,0 @@
1
- import type { PendingFinalChunk } from "./quota-manager.js";
2
- export interface SlashCommandResult {
3
- /** 是否是斜杠指令(true 表示已处理,不需要继续走 AI) */
4
- handled: boolean;
5
- }
6
- export interface SlashCommandContext {
7
- to: string;
8
- contextToken?: string;
9
- baseUrl: string;
10
- token?: string;
11
- accountId: string;
12
- log: (msg: string) => void;
13
- errLog: (msg: string) => void;
14
- /** Called when /clear is invoked to reset the agent session. */
15
- onClear?: () => void | Promise<void>;
16
- hasPendingFinal?: (chatKey: string) => boolean;
17
- drainPendingFinal?: (chatKey: string, available: number) => PendingFinalChunk[];
18
- prependPendingFinal?: (chatKey: string, chunks: PendingFinalChunk[]) => void;
19
- reserveFinal?: (chatKey: string) => boolean;
20
- finalRemaining?: (chatKey: string) => number;
21
- sendText?: (params: {
22
- to: string;
23
- text: string;
24
- contextToken?: string;
25
- }) => Promise<void>;
26
- }
27
- /**
28
- * v1.4: drain the next wave of pending paginated-final chunks parked by an
29
- * earlier inbound's overflow. Sends up to `finalRemaining(chatKey)` chunks; if
30
- * any chunks remain after the wave, appends a heads-up tail to this wave's
31
- * last chunk so the user knows another `/jx` will pull more. No-op when there
32
- * is nothing pending or the wiring is incomplete.
33
- */
34
- export declare function drainPendingFinalForJx(ctx: SlashCommandContext): Promise<void>;
35
- /**
36
- * 尝试处理斜杠指令
37
- *
38
- * @returns handled=true 表示该消息已作为指令处理,不需要继续走 AI 管道
39
- */
40
- export declare function handleSlashCommand(content: string, ctx: SlashCommandContext, receivedAt: number, eventTimestamp?: number): Promise<SlashCommandResult>;
@@ -1,24 +0,0 @@
1
- export interface WeixinConsumerLockMetadata {
2
- pid: number;
3
- mode: "foreground" | "daemon";
4
- startedAt: string;
5
- configPath: string;
6
- statePath: string;
7
- hostname?: string;
8
- }
9
- export interface WeixinConsumerLock {
10
- acquire: (meta: WeixinConsumerLockMetadata) => Promise<void>;
11
- release: () => Promise<void>;
12
- }
13
- export declare class ActiveWeixinConsumerLockError extends Error {
14
- readonly existing: WeixinConsumerLockMetadata;
15
- readonly lockFilePath: string;
16
- constructor(lockFilePath: string, existing: WeixinConsumerLockMetadata);
17
- }
18
- interface CreateWeixinConsumerLockOptions {
19
- lockFilePath?: string;
20
- isProcessRunning?: (pid: number) => boolean;
21
- onDiagnostic?: (event: "lock_exists" | "lock_invalid_removed" | "lock_stale_removed" | "lock_active_conflict" | "lock_acquired" | "lock_released", context: Record<string, string | number | boolean | undefined>) => void | Promise<void>;
22
- }
23
- export declare function createWeixinConsumerLock(options?: CreateWeixinConsumerLockOptions): WeixinConsumerLock;
24
- export {};
@@ -1,38 +0,0 @@
1
- import type { Agent } from "../agent/interface.js";
2
- import type { PendingFinalChunk } from "../messaging/quota-manager.js";
3
- import type { ActiveTurnRegistry } from "../../sessions/active-turn-registry.js";
4
- import type { RuntimeMediaStore } from "../../channels/media-store.js";
5
- import type { PerfTracer } from "../../perf/perf-tracer.js";
6
- export type MonitorWeixinOpts = {
7
- baseUrl: string;
8
- cdnBaseUrl: string;
9
- token?: string;
10
- accountId: string;
11
- agent: Agent;
12
- abortSignal?: AbortSignal;
13
- longPollTimeoutMs?: number;
14
- log?: (msg: string) => void;
15
- onInbound?: (chatKey: string) => void;
16
- reserveFinal?: (chatKey: string) => boolean;
17
- finalRemaining?: (chatKey: string) => number;
18
- hasPendingFinal?: (chatKey: string) => boolean;
19
- drainPendingFinal?: (chatKey: string, available: number) => PendingFinalChunk[];
20
- prependPendingFinal?: (chatKey: string, chunks: PendingFinalChunk[]) => void;
21
- enqueuePendingFinal?: (chatKey: string, chunks: PendingFinalChunk[]) => void;
22
- dropPendingFinal?: (chatKey: string) => void;
23
- mediaStore?: RuntimeMediaStore;
24
- allowedMediaRoots?: string[];
25
- perfTracer?: PerfTracer;
26
- peekCurrentSessionAlias?: (chatKey: string) => string | undefined;
27
- setBackgroundResult?: (chatKey: string, alias: string, result: {
28
- text: string;
29
- status: "done" | "error";
30
- finished_at: string;
31
- }) => Promise<void>;
32
- activeTurns?: ActiveTurnRegistry;
33
- };
34
- /**
35
- * Long-poll loop: getUpdates → process message → call agent → send reply.
36
- * Runs until aborted.
37
- */
38
- export declare function monitorWeixinProvider(opts: MonitorWeixinOpts): Promise<void>;
@@ -1 +0,0 @@
1
- export declare function ensureDirSync(dir: string): void;
@@ -1,2 +0,0 @@
1
- /** Resolve the OpenClaw state directory (mirrors core logic in src/infra). */
2
- export declare function resolveStateDir(): string;
@@ -1,20 +0,0 @@
1
- /**
2
- * Path to the persistent get_updates_buf file for an account.
3
- * Stored alongside account data: ~/.openclaw/openclaw-weixin/accounts/{accountId}.sync.json
4
- */
5
- export declare function getSyncBufFilePath(accountId: string): string;
6
- export type SyncBufData = {
7
- get_updates_buf: string;
8
- };
9
- /**
10
- * Load persisted get_updates_buf.
11
- * Falls back in order:
12
- * 1. Primary path (normalized accountId, new installs)
13
- * 2. Compat path (raw accountId derived from pattern, old installs)
14
- * 3. Legacy single-account path (very old installs without multi-account support)
15
- */
16
- export declare function loadGetUpdatesBuf(filePath: string): string | undefined;
17
- /**
18
- * Persist get_updates_buf. Creates parent dir if needed.
19
- */
20
- export declare function saveGetUpdatesBuf(filePath: string, getUpdatesBuf: string): void;