weacpx 0.3.1 → 0.4.0-beta.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 (67) hide show
  1. package/README.md +109 -26
  2. package/config.example.json +8 -1
  3. package/dist/bridge/bridge-main.js +188 -7
  4. package/dist/channels/channel-scope.d.ts +9 -0
  5. package/dist/channels/cli/provider.d.ts +73 -0
  6. package/dist/channels/cli/registry.d.ts +7 -0
  7. package/dist/channels/cli/weixin-provider.d.ts +2 -0
  8. package/dist/channels/create-channel.d.ts +16 -0
  9. package/dist/channels/media-store.d.ts +29 -0
  10. package/dist/channels/media-types.d.ts +28 -0
  11. package/dist/channels/outbound-media-safety.d.ts +7 -0
  12. package/dist/channels/plugin.d.ts +9 -0
  13. package/dist/channels/types.d.ts +61 -0
  14. package/dist/channels/weixin-channel.d.ts +22 -0
  15. package/dist/cli.js +14701 -8461
  16. package/dist/config/types.d.ts +64 -0
  17. package/dist/logging/app-logger.d.ts +23 -0
  18. package/dist/orchestration/orchestration-types.d.ts +156 -0
  19. package/dist/plugin-api.d.ts +8 -0
  20. package/dist/plugin-api.js +180 -0
  21. package/dist/plugins/compatibility.d.ts +16 -0
  22. package/dist/plugins/known-plugins.d.ts +9 -0
  23. package/dist/plugins/types.d.ts +18 -0
  24. package/dist/version.d.ts +1 -0
  25. package/dist/weixin/agent/interface.d.ts +54 -0
  26. package/dist/weixin/api/api.d.ts +48 -0
  27. package/dist/weixin/api/config-cache.d.ts +18 -0
  28. package/dist/weixin/api/session-guard.d.ts +15 -0
  29. package/dist/weixin/api/types.d.ts +201 -0
  30. package/dist/weixin/auth/accounts.d.ts +63 -0
  31. package/dist/weixin/auth/login-qr.d.ts +31 -0
  32. package/dist/weixin/bot.d.ts +54 -0
  33. package/dist/weixin/cdn/aes-ecb.d.ts +6 -0
  34. package/dist/weixin/cdn/cdn-upload.d.ts +17 -0
  35. package/dist/weixin/cdn/cdn-url.d.ts +11 -0
  36. package/dist/weixin/cdn/pic-decrypt.d.ts +9 -0
  37. package/dist/weixin/cdn/upload.d.ts +42 -0
  38. package/dist/weixin/index.d.ts +6 -0
  39. package/dist/weixin/media/media-download.d.ts +18 -0
  40. package/dist/weixin/media/mime.d.ts +6 -0
  41. package/dist/weixin/media/silk-transcode.d.ts +8 -0
  42. package/dist/weixin/messaging/conversation-executor.d.ts +7 -0
  43. package/dist/weixin/messaging/debug-mode.d.ts +9 -0
  44. package/dist/weixin/messaging/deliver-coordinator-message.d.ts +22 -0
  45. package/dist/weixin/messaging/deliver-orchestration-task-notice.d.ts +18 -0
  46. package/dist/weixin/messaging/deliver-orchestration-task-progress.d.ts +16 -0
  47. package/dist/weixin/messaging/error-notice.d.ts +13 -0
  48. package/dist/weixin/messaging/execute-chat-turn.d.ts +12 -0
  49. package/dist/weixin/messaging/final-heads-up.d.ts +5 -0
  50. package/dist/weixin/messaging/handle-weixin-message-turn.d.ts +30 -0
  51. package/dist/weixin/messaging/inbound.d.ts +63 -0
  52. package/dist/weixin/messaging/orchestration-notice-accounts.d.ts +2 -0
  53. package/dist/weixin/messaging/quota-errors.d.ts +8 -0
  54. package/dist/weixin/messaging/quota-manager.d.ts +44 -0
  55. package/dist/weixin/messaging/send-errors.d.ts +39 -0
  56. package/dist/weixin/messaging/send-media.d.ts +23 -0
  57. package/dist/weixin/messaging/send-orchestration-notice.d.ts +10 -0
  58. package/dist/weixin/messaging/send.d.ts +71 -0
  59. package/dist/weixin/messaging/slash-commands.d.ts +40 -0
  60. package/dist/weixin/monitor/consumer-lock.d.ts +24 -0
  61. package/dist/weixin/monitor/monitor.d.ts +28 -0
  62. package/dist/weixin/storage/state-dir.d.ts +2 -0
  63. package/dist/weixin/storage/sync-buf.d.ts +20 -0
  64. package/dist/weixin/util/logger.d.ts +14 -0
  65. package/dist/weixin/util/random.d.ts +10 -0
  66. package/dist/weixin/util/redact.d.ts +21 -0
  67. package/package.json +41 -17
@@ -0,0 +1,28 @@
1
+ export type ChannelId = string;
2
+ export type ChannelMediaKind = "image" | "file" | "audio" | "video";
3
+ export interface ChannelMediaAttachment {
4
+ kind: ChannelMediaKind;
5
+ /** @deprecated Legacy field — prefer `kind`. Kept for backward compat during migration. */
6
+ type?: string;
7
+ filePath: string;
8
+ mimeType: string;
9
+ fileName?: string;
10
+ sizeBytes: number;
11
+ source: {
12
+ channelId: ChannelId;
13
+ accountId: string;
14
+ chatKey: string;
15
+ messageId: string;
16
+ resourceId?: string;
17
+ };
18
+ }
19
+ export interface OutboundChannelMedia {
20
+ kind: ChannelMediaKind;
21
+ filePath: string;
22
+ mimeType?: string;
23
+ fileName?: string;
24
+ caption?: string;
25
+ }
26
+ export type MaybeArray<T> = T | T[] | undefined;
27
+ export declare function normalizeMediaArray<T>(media: MaybeArray<T>): T[];
28
+ export declare function firstMediaOrUndefined<T>(media: T[]): T | undefined;
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Resolve an outbound media file path to a safe absolute realpath.
3
+ * Rejects remote URLs, non-existent paths, symlinks that escape allowed roots,
4
+ * and paths outside all allowed root directories.
5
+ * Returns the resolved realpath on success, or null on rejection.
6
+ */
7
+ export declare function resolveSafeOutboundMediaPath(mediaPath: string, allowedRoots: string[]): Promise<string | null>;
@@ -0,0 +1,9 @@
1
+ import type { ChannelFactory } from "./create-channel.js";
2
+ import type { ChannelCliProvider } from "./cli/provider.js";
3
+ export interface ChannelPluginDefinition {
4
+ /** Stable channel type used in channels[].type and chatKey prefix. */
5
+ type: string;
6
+ factory: ChannelFactory;
7
+ cliProvider?: ChannelCliProvider;
8
+ }
9
+ export declare function registerChannelPlugin(plugin: ChannelPluginDefinition): void;
@@ -0,0 +1,61 @@
1
+ import type { Agent as ChatAgent } from "../weixin/agent/interface.js";
2
+ import type { OrchestrationTaskRecord } from "../orchestration/orchestration-types.js";
3
+ import type { AppLogger } from "../logging/app-logger.js";
4
+ import type { PendingFinalChunk } from "../weixin/messaging/quota-manager.js";
5
+ export type { ChatAgent };
6
+ export interface OutboundQuota {
7
+ onInbound(chatKey: string): void;
8
+ reserveMidSegment(chatKey: string): boolean;
9
+ reserveFinal(chatKey: string): boolean;
10
+ finalRemaining(chatKey: string): number;
11
+ hasPendingFinal(chatKey: string): boolean;
12
+ drainPendingFinalUpToBudget(chatKey: string, available: number): PendingFinalChunk[];
13
+ prependPendingFinal(chatKey: string, chunks: PendingFinalChunk[]): void;
14
+ enqueuePendingFinal(chatKey: string, chunks: PendingFinalChunk[]): void;
15
+ clearPendingFinal(chatKey: string): void;
16
+ }
17
+ export interface CoordinatorMessageInput {
18
+ coordinatorSession: string;
19
+ chatKey: string;
20
+ accountId?: string;
21
+ replyContextToken?: string;
22
+ text: string;
23
+ }
24
+ export interface ChannelStartInput {
25
+ agent: ChatAgent;
26
+ abortSignal: AbortSignal;
27
+ quota: OutboundQuota;
28
+ logger: AppLogger;
29
+ }
30
+ export interface OrchestrationDeliveryCallbacks {
31
+ markTaskNoticeDelivered: (taskId: string, accountId: string) => Promise<void>;
32
+ markTaskNoticeFailed: (taskId: string, errorMessage: string) => Promise<void>;
33
+ }
34
+ export interface ConsumerLockMetadata {
35
+ pid: number;
36
+ mode: "foreground" | "daemon";
37
+ startedAt: string;
38
+ configPath: string;
39
+ statePath: string;
40
+ hostname?: string;
41
+ }
42
+ export interface ConsumerLock {
43
+ acquire(meta: ConsumerLockMetadata): Promise<void>;
44
+ release(): Promise<void>;
45
+ }
46
+ export interface ConsumerLockOptions {
47
+ lockFilePath?: string;
48
+ onDiagnostic?: (event: string, context: Record<string, string | number | boolean | undefined>) => void | Promise<void>;
49
+ }
50
+ export interface MessageChannelRuntime {
51
+ id: string;
52
+ isLoggedIn(): boolean;
53
+ login(): Promise<string>;
54
+ logout(): void;
55
+ start(input: ChannelStartInput): Promise<void>;
56
+ createConsumerLock?(options?: ConsumerLockOptions): ConsumerLock;
57
+ configureOrchestration?(callbacks: OrchestrationDeliveryCallbacks): void;
58
+ notifyTaskCompletion(task: OrchestrationTaskRecord): Promise<void>;
59
+ notifyTaskProgress(task: OrchestrationTaskRecord, text: string): Promise<void>;
60
+ sendCoordinatorMessage(input: CoordinatorMessageInput): Promise<void>;
61
+ }
@@ -0,0 +1,22 @@
1
+ import type { MessageChannelRuntime, ChannelStartInput, CoordinatorMessageInput, OrchestrationDeliveryCallbacks, ConsumerLock, ConsumerLockOptions } from "./types.js";
2
+ import type { RuntimeMediaStore } from "./media-store.js";
3
+ import type { OrchestrationTaskRecord } from "../orchestration/orchestration-types.js";
4
+ export declare class WeixinChannel implements MessageChannelRuntime {
5
+ readonly id = "weixin";
6
+ private quota;
7
+ private logger;
8
+ private markDelivered;
9
+ private markFailed;
10
+ private mediaStore;
11
+ private allowedMediaRoots;
12
+ constructor(mediaStore?: RuntimeMediaStore, allowedMediaRoots?: string[]);
13
+ isLoggedIn(): boolean;
14
+ login(): Promise<string>;
15
+ logout(): void;
16
+ createConsumerLock(options?: ConsumerLockOptions): ConsumerLock;
17
+ configureOrchestration(callbacks: OrchestrationDeliveryCallbacks): void;
18
+ start(input: ChannelStartInput): Promise<void>;
19
+ notifyTaskCompletion(task: OrchestrationTaskRecord): Promise<void>;
20
+ notifyTaskProgress(task: OrchestrationTaskRecord, text: string): Promise<void>;
21
+ sendCoordinatorMessage(input: CoordinatorMessageInput): Promise<void>;
22
+ }