weacpx 0.6.0 → 0.7.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 (63) hide show
  1. package/dist/bridge/bridge-main.js +66 -24
  2. package/dist/channels/types.d.ts +14 -0
  3. package/dist/cli.js +1268 -407
  4. package/dist/commands/command-hints.d.ts +11 -0
  5. package/dist/commands/command-list.d.ts +3 -0
  6. package/dist/commands/config-clone.d.ts +2 -0
  7. package/dist/commands/handlers/agent-handler.d.ts +6 -0
  8. package/dist/commands/handlers/config-handler.d.ts +5 -0
  9. package/dist/commands/handlers/later-handler.d.ts +21 -0
  10. package/dist/commands/handlers/orchestration-handler.d.ts +16 -0
  11. package/dist/commands/handlers/permission-handler.d.ts +9 -0
  12. package/dist/commands/handlers/session-handler.d.ts +39 -0
  13. package/dist/commands/handlers/session-list-marker.d.ts +1 -0
  14. package/dist/commands/handlers/workspace-handler.d.ts +8 -0
  15. package/dist/commands/help/help-registry.d.ts +4 -0
  16. package/dist/commands/help/help-types.d.ts +12 -0
  17. package/dist/commands/parse-command.d.ts +178 -0
  18. package/dist/commands/router-types.d.ts +144 -0
  19. package/dist/commands/workspace-name.d.ts +4 -0
  20. package/dist/commands/workspace-path.d.ts +4 -0
  21. package/dist/config/agent-templates.d.ts +4 -0
  22. package/dist/config/config-store.d.ts +13 -0
  23. package/dist/config/load-config.d.ts +10 -0
  24. package/dist/config/resolve-agent-command.d.ts +2 -0
  25. package/dist/formatting/render-text.d.ts +23 -0
  26. package/dist/orchestration/async-mutex.d.ts +4 -0
  27. package/dist/orchestration/build-coordinator-prompt.d.ts +66 -0
  28. package/dist/orchestration/orchestration-service.d.ts +471 -0
  29. package/dist/orchestration/progress-line-parser.d.ts +19 -0
  30. package/dist/orchestration/render-delegate-group-result.d.ts +6 -0
  31. package/dist/orchestration/render-delegate-question-package.d.ts +21 -0
  32. package/dist/orchestration/render-delegate-result.d.ts +2 -0
  33. package/dist/orchestration/task-watch-timeouts.d.ts +5 -0
  34. package/dist/plugin-api.d.ts +10 -0
  35. package/dist/plugin-api.js +157 -0
  36. package/dist/{weixin/messaging → runtime}/conversation-executor.d.ts +1 -1
  37. package/dist/runtime/core-home.d.ts +26 -0
  38. package/dist/runtime/turn-lane.d.ts +2 -0
  39. package/dist/scheduled/parse-later-time.d.ts +11 -0
  40. package/dist/scheduled/scheduled-render.d.ts +7 -0
  41. package/dist/scheduled/scheduled-service.d.ts +41 -0
  42. package/dist/scheduled/scheduled-types.d.ts +29 -0
  43. package/dist/sessions/active-turn-registry.d.ts +6 -0
  44. package/dist/sessions/session-service.d.ts +118 -0
  45. package/dist/state/state-store.d.ts +8 -0
  46. package/dist/state/types.d.ts +51 -0
  47. package/dist/transport/tool-event-mode.d.ts +14 -0
  48. package/dist/transport/types.d.ts +129 -0
  49. package/dist/util/path.d.ts +4 -0
  50. package/dist/util/sanitize.d.ts +10 -0
  51. package/dist/util/text.d.ts +3 -0
  52. package/dist/version.d.ts +2 -0
  53. package/dist/weixin/agent/interface.d.ts +1 -0
  54. package/dist/weixin/api/config-cache.d.ts +18 -1
  55. package/dist/weixin/auth/accounts.d.ts +0 -1
  56. package/dist/weixin/bot.d.ts +11 -0
  57. package/dist/weixin/messaging/completion-notice.d.ts +2 -0
  58. package/dist/weixin/messaging/foreground-gate.d.ts +3 -0
  59. package/dist/weixin/messaging/handle-weixin-message-turn.d.ts +4 -0
  60. package/dist/weixin/messaging/inbound.d.ts +7 -0
  61. package/dist/weixin/messaging/quota-manager.d.ts +15 -1
  62. package/dist/weixin/monitor/monitor.d.ts +8 -0
  63. package/package.json +1 -1
@@ -1,7 +1,15 @@
1
+ import { getConfig } from "./api.js";
1
2
  /** Subset of getConfig fields that we actually need; add new fields here as needed. */
2
3
  export interface CachedConfig {
3
4
  typingTicket: string;
4
5
  }
6
+ type GetConfigFn = typeof getConfig;
7
+ export interface WeixinConfigManagerOptions {
8
+ maxEntries?: number;
9
+ entryTtlMs?: number;
10
+ now?: () => number;
11
+ getConfig?: GetConfigFn;
12
+ }
5
13
  /**
6
14
  * Per-user getConfig cache with periodic random refresh (within 24h) and
7
15
  * exponential-backoff retry (up to 1h) on failure.
@@ -10,9 +18,18 @@ export declare class WeixinConfigManager {
10
18
  private apiOpts;
11
19
  private log;
12
20
  private cache;
21
+ private readonly maxEntries;
22
+ private readonly entryTtlMs;
23
+ private readonly now;
24
+ private readonly fetchConfig;
13
25
  constructor(apiOpts: {
14
26
  baseUrl: string;
15
27
  token?: string;
16
- }, log: (msg: string) => void);
28
+ }, log: (msg: string) => void, options?: WeixinConfigManagerOptions);
17
29
  getForUser(userId: string, contextToken?: string): Promise<CachedConfig>;
30
+ cacheSizeForTests(): number;
31
+ hasCachedUserForTests(userId: string): boolean;
32
+ private prune;
33
+ private enforceMaxEntries;
18
34
  }
35
+ export {};
@@ -1,6 +1,5 @@
1
1
  export declare const DEFAULT_BASE_URL = "https://ilinkai.weixin.qq.com";
2
2
  export declare const CDN_BASE_URL = "https://novac2c.cdn.weixin.qq.com/c2c";
3
- /** Normalize an account ID to a filesystem-safe string. */
4
3
  export declare function normalizeAccountId(raw: string): string;
5
4
  /**
6
5
  * Pattern-based reverse of normalizeWeixinAccountId for known weixin ID suffixes.
@@ -2,6 +2,7 @@ import type { Agent } from "./agent/interface.js";
2
2
  import type { PendingFinalChunk } from "./messaging/quota-manager.js";
3
3
  import type { RuntimeMediaStore } from "../channels/media-store.js";
4
4
  import type { PerfTracer } from "../perf/perf-tracer.js";
5
+ import type { ActiveTurnRegistry } from "../sessions/active-turn-registry.js";
5
6
  export type LoginOptions = {
6
7
  /** Override the API base URL. */
7
8
  baseUrl?: string;
@@ -31,6 +32,16 @@ export type StartOptions = {
31
32
  dropPendingFinal?: (chatKey: string) => void;
32
33
  mediaStore?: RuntimeMediaStore;
33
34
  perfTracer?: PerfTracer;
35
+ /** Read the chat's current session synchronously for dispatch-time binding. */
36
+ peekCurrentSessionAlias?: (chatKey: string) => string | undefined;
37
+ /** Persist a background turn's final result for later replay. */
38
+ setBackgroundResult?: (chatKey: string, alias: string, result: {
39
+ text: string;
40
+ status: "done" | "error";
41
+ finished_at: string;
42
+ }) => Promise<void>;
43
+ /** Shared in-flight turn registry for dispatch-time foreground tracking. */
44
+ activeTurns?: ActiveTurnRegistry;
34
45
  };
35
46
  /**
36
47
  * Interactive QR-code login. Prints the QR code to the terminal and waits
@@ -0,0 +1,2 @@
1
+ export declare function buildBackgroundCompletionNotice(internalAlias: string, status: "done" | "error"): string;
2
+ export declare function shouldSendBackgroundNotice(reserve: (() => boolean) | undefined): boolean;
@@ -0,0 +1,3 @@
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;
@@ -27,6 +27,10 @@ export type HandleWeixinMessageTurnDeps = {
27
27
  downloadMediaFromItemFn?: typeof downloadMediaFromItem;
28
28
  allowedMediaRoots?: string[];
29
29
  perfTracer?: PerfTracer;
30
+ isForeground?: () => boolean;
31
+ boundSessionAlias?: string;
32
+ onBackgroundFinal?: (alias: string, text: string, status: "done" | "error") => Promise<void>;
30
33
  };
31
34
  export declare function getWeixinMessageTurnLane(full: WeixinMessage): "normal" | "control";
35
+ export declare function buildWeixinChatKey(accountId: string, userId: string): string;
32
36
  export declare function handleWeixinMessageTurn(full: WeixinMessage, deps: HandleWeixinMessageTurnDeps): Promise<void>;
@@ -1,5 +1,11 @@
1
1
  import type { ChannelMediaKind } from "../../channels/media-types.js";
2
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;
3
9
  /**
4
10
  * Restore the per-account context-token cache from disk into memory.
5
11
  * Called at bot startup (after login). Missing/unreadable files are tolerated
@@ -78,3 +84,4 @@ export interface WeixinInboundMediaDescriptor {
78
84
  fileName?: string;
79
85
  }
80
86
  export declare function extractWeixinMediaDescriptors(itemList?: MessageItem[]): WeixinInboundMediaDescriptor[];
87
+ export {};
@@ -24,11 +24,21 @@ export interface QuotaObserver {
24
24
  onFinalReserved?(chatKey: string, snapshot: QuotaSnapshot): void;
25
25
  onFinalRejected?(chatKey: string, snapshot: QuotaSnapshot): void;
26
26
  }
27
+ export interface QuotaManagerOptions {
28
+ maxStates?: number;
29
+ stateTtlMs?: number;
30
+ maxPendingFinalChunksPerChat?: number;
31
+ now?: () => number;
32
+ }
27
33
  export declare class QuotaManager {
28
34
  private readonly states;
29
35
  private readonly observer;
30
36
  private readonly normalizeKey;
31
- constructor(observer?: QuotaObserver, normalizeKey?: (key: string) => string);
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);
32
42
  onInbound(chatKey: string): void;
33
43
  reserveMidSegment(chatKey: string): boolean;
34
44
  reserveFinal(chatKey: string): boolean;
@@ -41,4 +51,8 @@ export declare class QuotaManager {
41
51
  clearPendingFinal(chatKey: string): void;
42
52
  snapshot(chatKey: string): QuotaSnapshot;
43
53
  private getOrCreate;
54
+ private prune;
55
+ private enforceMaxStates;
56
+ private trimPendingFinalChunks;
57
+ private deleteIfEmpty;
44
58
  }
@@ -1,5 +1,6 @@
1
1
  import type { Agent } from "../agent/interface.js";
2
2
  import type { PendingFinalChunk } from "../messaging/quota-manager.js";
3
+ import type { ActiveTurnRegistry } from "../../sessions/active-turn-registry.js";
3
4
  import type { RuntimeMediaStore } from "../../channels/media-store.js";
4
5
  import type { PerfTracer } from "../../perf/perf-tracer.js";
5
6
  export type MonitorWeixinOpts = {
@@ -22,6 +23,13 @@ export type MonitorWeixinOpts = {
22
23
  mediaStore?: RuntimeMediaStore;
23
24
  allowedMediaRoots?: string[];
24
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;
25
33
  };
26
34
  /**
27
35
  * Long-poll loop: getUpdates → process message → call agent → send reply.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "weacpx",
3
- "version": "0.6.0",
3
+ "version": "0.7.0",
4
4
  "description": "使用微信 ClawBot 随时随地通过 `acpx` 控制 Claude Code、Codex 等 Agents。",
5
5
  "keywords": [
6
6
  "acpx",