weacpx 0.6.1 → 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.
- package/README.md +10 -564
- package/package.json +10 -72
- package/plugin-api.d.ts +2 -0
- package/plugin-api.js +5 -0
- package/LICENSE +0 -21
- package/config.example.json +0 -44
- package/dist/bridge/bridge-main.js +0 -2120
- package/dist/channels/channel-scope.d.ts +0 -17
- package/dist/channels/cli/provider.d.ts +0 -73
- package/dist/channels/cli/registry.d.ts +0 -7
- package/dist/channels/cli/weixin-provider.d.ts +0 -2
- package/dist/channels/create-channel.d.ts +0 -16
- package/dist/channels/media-store.d.ts +0 -29
- package/dist/channels/media-types.d.ts +0 -28
- package/dist/channels/outbound-media-safety.d.ts +0 -7
- package/dist/channels/plugin.d.ts +0 -9
- package/dist/channels/types.d.ts +0 -115
- package/dist/channels/weixin-channel.d.ts +0 -25
- package/dist/cli.js +0 -46971
- package/dist/commands/command-hints.d.ts +0 -11
- package/dist/commands/command-list.d.ts +0 -3
- package/dist/commands/config-clone.d.ts +0 -2
- package/dist/commands/handlers/agent-handler.d.ts +0 -6
- package/dist/commands/handlers/config-handler.d.ts +0 -5
- package/dist/commands/handlers/later-handler.d.ts +0 -21
- package/dist/commands/handlers/orchestration-handler.d.ts +0 -16
- package/dist/commands/handlers/permission-handler.d.ts +0 -9
- package/dist/commands/handlers/session-handler.d.ts +0 -37
- package/dist/commands/handlers/workspace-handler.d.ts +0 -8
- package/dist/commands/help/help-registry.d.ts +0 -4
- package/dist/commands/help/help-types.d.ts +0 -12
- package/dist/commands/parse-command.d.ts +0 -175
- package/dist/commands/router-types.d.ts +0 -144
- package/dist/commands/workspace-name.d.ts +0 -4
- package/dist/commands/workspace-path.d.ts +0 -4
- package/dist/config/agent-templates.d.ts +0 -4
- package/dist/config/config-store.d.ts +0 -13
- package/dist/config/load-config.d.ts +0 -10
- package/dist/config/resolve-agent-command.d.ts +0 -2
- package/dist/config/types.d.ts +0 -85
- package/dist/formatting/render-text.d.ts +0 -23
- package/dist/logging/app-logger.d.ts +0 -23
- package/dist/logging/rotating-file-writer.d.ts +0 -2
- package/dist/orchestration/async-mutex.d.ts +0 -4
- package/dist/orchestration/build-coordinator-prompt.d.ts +0 -66
- package/dist/orchestration/orchestration-service.d.ts +0 -471
- package/dist/orchestration/orchestration-types.d.ts +0 -181
- package/dist/orchestration/progress-line-parser.d.ts +0 -19
- package/dist/orchestration/render-delegate-group-result.d.ts +0 -6
- package/dist/orchestration/render-delegate-question-package.d.ts +0 -21
- package/dist/orchestration/render-delegate-result.d.ts +0 -2
- package/dist/orchestration/task-watch-timeouts.d.ts +0 -5
- package/dist/perf/perf-log-writer.d.ts +0 -25
- package/dist/perf/perf-tracer.d.ts +0 -54
- package/dist/plugin-api.d.ts +0 -9
- package/dist/plugin-api.js +0 -180
- package/dist/plugins/compatibility.d.ts +0 -16
- package/dist/plugins/known-plugins.d.ts +0 -9
- package/dist/plugins/types.d.ts +0 -18
- package/dist/scheduled/parse-later-time.d.ts +0 -11
- package/dist/scheduled/scheduled-render.d.ts +0 -7
- package/dist/scheduled/scheduled-service.d.ts +0 -41
- package/dist/scheduled/scheduled-types.d.ts +0 -29
- package/dist/sessions/session-service.d.ts +0 -83
- package/dist/state/state-store.d.ts +0 -8
- package/dist/state/types.d.ts +0 -44
- package/dist/transport/tool-event-mode.d.ts +0 -14
- package/dist/transport/types.d.ts +0 -129
- package/dist/util/path.d.ts +0 -4
- package/dist/util/private-file.d.ts +0 -26
- package/dist/util/sanitize.d.ts +0 -10
- package/dist/util/text.d.ts +0 -3
- package/dist/version.d.ts +0 -3
- package/dist/weixin/agent/interface.d.ts +0 -78
- package/dist/weixin/api/api.d.ts +0 -76
- package/dist/weixin/api/config-cache.d.ts +0 -18
- package/dist/weixin/api/session-guard.d.ts +0 -17
- package/dist/weixin/api/types.d.ts +0 -203
- package/dist/weixin/auth/accounts.d.ts +0 -69
- package/dist/weixin/auth/login-qr.d.ts +0 -37
- package/dist/weixin/bot.d.ts +0 -56
- package/dist/weixin/cdn/aes-ecb.d.ts +0 -6
- package/dist/weixin/cdn/cdn-upload.d.ts +0 -17
- package/dist/weixin/cdn/cdn-url.d.ts +0 -11
- package/dist/weixin/cdn/pic-decrypt.d.ts +0 -9
- package/dist/weixin/cdn/upload.d.ts +0 -42
- package/dist/weixin/index.d.ts +0 -6
- package/dist/weixin/media/media-download.d.ts +0 -18
- package/dist/weixin/media/mime.d.ts +0 -6
- package/dist/weixin/media/silk-transcode.d.ts +0 -8
- package/dist/weixin/messaging/conversation-executor.d.ts +0 -7
- package/dist/weixin/messaging/debug-mode.d.ts +0 -9
- package/dist/weixin/messaging/deliver-coordinator-message.d.ts +0 -22
- package/dist/weixin/messaging/deliver-orchestration-task-notice.d.ts +0 -18
- package/dist/weixin/messaging/deliver-orchestration-task-progress.d.ts +0 -16
- package/dist/weixin/messaging/error-notice.d.ts +0 -13
- package/dist/weixin/messaging/execute-chat-turn.d.ts +0 -12
- package/dist/weixin/messaging/final-heads-up.d.ts +0 -5
- package/dist/weixin/messaging/handle-weixin-message-turn.d.ts +0 -32
- package/dist/weixin/messaging/inbound.d.ts +0 -80
- package/dist/weixin/messaging/markdown-filter.d.ts +0 -45
- package/dist/weixin/messaging/orchestration-notice-accounts.d.ts +0 -2
- package/dist/weixin/messaging/quota-errors.d.ts +0 -8
- package/dist/weixin/messaging/quota-manager.d.ts +0 -44
- package/dist/weixin/messaging/scheduled-turn.d.ts +0 -22
- package/dist/weixin/messaging/send-errors.d.ts +0 -39
- package/dist/weixin/messaging/send-media.d.ts +0 -23
- package/dist/weixin/messaging/send-orchestration-notice.d.ts +0 -10
- package/dist/weixin/messaging/send.d.ts +0 -73
- package/dist/weixin/messaging/slash-commands.d.ts +0 -40
- package/dist/weixin/monitor/consumer-lock.d.ts +0 -24
- package/dist/weixin/monitor/monitor.d.ts +0 -30
- package/dist/weixin/storage/ensure-dir.d.ts +0 -1
- package/dist/weixin/storage/state-dir.d.ts +0 -2
- package/dist/weixin/storage/sync-buf.d.ts +0 -20
- package/dist/weixin/util/logger.d.ts +0 -14
- package/dist/weixin/util/random.d.ts +0 -10
- package/dist/weixin/util/redact.d.ts +0 -21
|
@@ -1,83 +0,0 @@
|
|
|
1
|
-
import type { AppConfig } from "../config/types";
|
|
2
|
-
import { AsyncMutex } from "../orchestration/async-mutex";
|
|
3
|
-
import type { StateStore } from "../state/state-store";
|
|
4
|
-
import type { AppState } from "../state/types";
|
|
5
|
-
import type { AgentSession, ResolvedSession } from "../transport/types";
|
|
6
|
-
interface SessionListItem {
|
|
7
|
-
alias: string;
|
|
8
|
-
internalAlias: string;
|
|
9
|
-
agent: string;
|
|
10
|
-
workspace: string;
|
|
11
|
-
isCurrent: boolean;
|
|
12
|
-
}
|
|
13
|
-
interface NativeSessionAttachmentInput {
|
|
14
|
-
alias: string;
|
|
15
|
-
agent: string;
|
|
16
|
-
workspace: string;
|
|
17
|
-
transportSession: string;
|
|
18
|
-
transportAgentCommand?: string;
|
|
19
|
-
agentSessionId: string;
|
|
20
|
-
title?: string | null;
|
|
21
|
-
updatedAt?: string;
|
|
22
|
-
}
|
|
23
|
-
interface NativeSessionListInput {
|
|
24
|
-
agent: string;
|
|
25
|
-
workspace?: string;
|
|
26
|
-
cwd: string;
|
|
27
|
-
sessions: AgentSession[];
|
|
28
|
-
nextCursor?: string | null;
|
|
29
|
-
}
|
|
30
|
-
interface NativeSessionListResult {
|
|
31
|
-
agent: string;
|
|
32
|
-
workspace?: string;
|
|
33
|
-
cwd: string;
|
|
34
|
-
sessions: AgentSession[];
|
|
35
|
-
nextCursor?: string | null;
|
|
36
|
-
}
|
|
37
|
-
interface SessionServiceOptions {
|
|
38
|
-
stateMutex?: AsyncMutex;
|
|
39
|
-
now?: () => number;
|
|
40
|
-
}
|
|
41
|
-
export declare class SessionService {
|
|
42
|
-
private readonly config;
|
|
43
|
-
private readonly stateStore;
|
|
44
|
-
private readonly state;
|
|
45
|
-
private readonly stateMutex;
|
|
46
|
-
private readonly now;
|
|
47
|
-
constructor(config: AppConfig, stateStore: Pick<StateStore, "save">, state: AppState, options?: SessionServiceOptions);
|
|
48
|
-
createSession(alias: string, agent: string, workspace: string): Promise<ResolvedSession>;
|
|
49
|
-
/**
|
|
50
|
-
* All currently-known logical sessions resolved to transport sessions, deduped by
|
|
51
|
-
* transport session. Sessions whose agent or workspace is no longer registered are
|
|
52
|
-
* skipped (toResolvedSession would throw). Used by shutdown cleanup to reap warm
|
|
53
|
-
* acpx queue owners; never throws.
|
|
54
|
-
*/
|
|
55
|
-
listAllResolvedSessions(): ResolvedSession[];
|
|
56
|
-
resolveSession(alias: string, agent: string, workspace: string, transportSession: string): ResolvedSession;
|
|
57
|
-
attachSession(alias: string, agent: string, workspace: string, transportSession: string, transportAgentCommand?: string): Promise<ResolvedSession>;
|
|
58
|
-
attachNativeSession(input: NativeSessionAttachmentInput): Promise<ResolvedSession>;
|
|
59
|
-
getSession(alias: string): Promise<ResolvedSession | null>;
|
|
60
|
-
getPreferredSessionForTransport(transportSession: string): Promise<ResolvedSession | null>;
|
|
61
|
-
findAttachedNativeSession(chatKey: string, agent: string, agentSessionId: string): Promise<ResolvedSession | null>;
|
|
62
|
-
useSession(chatKey: string, alias: string): Promise<void>;
|
|
63
|
-
resolveAliasForChat(chatKey: string, displayAlias: string): Promise<string>;
|
|
64
|
-
buildDefaultTransportSessionForChat(chatKey: string, displayAlias: string): string;
|
|
65
|
-
listInternalAliases(): string[];
|
|
66
|
-
setCurrentSessionMode(chatKey: string, modeId: string | undefined): Promise<void>;
|
|
67
|
-
setCurrentSessionReplyMode(chatKey: string, replyMode: "stream" | "final" | "verbose" | undefined): Promise<void>;
|
|
68
|
-
getCurrentSession(chatKey: string): Promise<ResolvedSession | null>;
|
|
69
|
-
listSessions(chatKey: string): Promise<SessionListItem[]>;
|
|
70
|
-
countAliasesSharingTransport(transportSession: string, excludeAlias?: string): number;
|
|
71
|
-
removeSession(alias: string): Promise<{
|
|
72
|
-
wasActive: boolean;
|
|
73
|
-
}>;
|
|
74
|
-
cacheNativeSessionList(chatKey: string, input: NativeSessionListInput): Promise<void>;
|
|
75
|
-
getNativeSessionList(chatKey: string, ttlMs?: number): Promise<NativeSessionListResult | null>;
|
|
76
|
-
private toResolvedSession;
|
|
77
|
-
setSessionTransportAgentCommand(alias: string, transportAgentCommand: string | undefined): Promise<void>;
|
|
78
|
-
private mutate;
|
|
79
|
-
private persist;
|
|
80
|
-
private createLogicalSession;
|
|
81
|
-
private validateSession;
|
|
82
|
-
}
|
|
83
|
-
export {};
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { type AppState } from "./types";
|
|
2
|
-
export declare function parseState(raw: unknown, path: string): AppState;
|
|
3
|
-
export declare class StateStore {
|
|
4
|
-
private readonly path;
|
|
5
|
-
constructor(path: string);
|
|
6
|
-
load(): Promise<AppState>;
|
|
7
|
-
save(state: AppState): Promise<void>;
|
|
8
|
-
}
|
package/dist/state/types.d.ts
DELETED
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import { type OrchestrationState } from "../orchestration/orchestration-types";
|
|
2
|
-
import type { ScheduledTaskRecord } from "../scheduled/scheduled-types";
|
|
3
|
-
export type LogicalSessionSource = "weacpx" | "agent-side";
|
|
4
|
-
export interface NativeSessionCacheEntry {
|
|
5
|
-
session_id: string;
|
|
6
|
-
cwd?: string;
|
|
7
|
-
title?: string | null;
|
|
8
|
-
updated_at?: string;
|
|
9
|
-
}
|
|
10
|
-
export interface NativeSessionListCacheRecord {
|
|
11
|
-
created_at: string;
|
|
12
|
-
agent: string;
|
|
13
|
-
workspace?: string;
|
|
14
|
-
cwd: string;
|
|
15
|
-
sessions: NativeSessionCacheEntry[];
|
|
16
|
-
next_cursor?: string | null;
|
|
17
|
-
}
|
|
18
|
-
export interface LogicalSession {
|
|
19
|
-
alias: string;
|
|
20
|
-
agent: string;
|
|
21
|
-
workspace: string;
|
|
22
|
-
transport_session: string;
|
|
23
|
-
source?: LogicalSessionSource;
|
|
24
|
-
agent_session_id?: string;
|
|
25
|
-
agent_session_title?: string;
|
|
26
|
-
agent_session_updated_at?: string;
|
|
27
|
-
attached_at?: string;
|
|
28
|
-
transport_agent_command?: string;
|
|
29
|
-
mode_id?: string;
|
|
30
|
-
reply_mode?: "stream" | "final" | "verbose";
|
|
31
|
-
created_at: string;
|
|
32
|
-
last_used_at: string;
|
|
33
|
-
}
|
|
34
|
-
export interface ChatContextState {
|
|
35
|
-
current_session: string;
|
|
36
|
-
}
|
|
37
|
-
export interface AppState {
|
|
38
|
-
sessions: Record<string, LogicalSession>;
|
|
39
|
-
chat_contexts: Record<string, ChatContextState>;
|
|
40
|
-
native_session_lists: Record<string, NativeSessionListCacheRecord>;
|
|
41
|
-
orchestration: OrchestrationState;
|
|
42
|
-
scheduled_tasks: Record<string, ScheduledTaskRecord>;
|
|
43
|
-
}
|
|
44
|
-
export declare function createEmptyState(): AppState;
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import type { ToolUseEvent } from "../channels/types.js";
|
|
2
|
-
export type ToolEventMode = "text" | "structured" | "both";
|
|
3
|
-
/**
|
|
4
|
-
* Resolves the effective tool-event rendering mode.
|
|
5
|
-
*
|
|
6
|
-
* Resolution order (hard contract — preserves Phase 0 invariant):
|
|
7
|
-
* 1. Explicit `toolEventMode` always wins.
|
|
8
|
-
* 2. `onToolEvent` present → "structured" (structured consumer, suppress text tool calls).
|
|
9
|
-
* 3. Default → "text" (legacy text tool calls; no structured consumer).
|
|
10
|
-
*/
|
|
11
|
-
export declare function resolveToolEventMode(input?: {
|
|
12
|
-
toolEventMode?: ToolEventMode;
|
|
13
|
-
onToolEvent?: (event: ToolUseEvent) => void | Promise<void>;
|
|
14
|
-
}): ToolEventMode;
|
|
@@ -1,129 +0,0 @@
|
|
|
1
|
-
import type { NonInteractivePermissions, PermissionMode } from "../config/types";
|
|
2
|
-
import type { QuotaManager } from "../weixin/messaging/quota-manager.js";
|
|
3
|
-
import type { ToolUseEvent } from "../channels/types.js";
|
|
4
|
-
import type { ToolEventMode } from "./tool-event-mode.js";
|
|
5
|
-
export type { ToolEventMode } from "./tool-event-mode.js";
|
|
6
|
-
export interface ReplyQuotaContext {
|
|
7
|
-
chatKey: string;
|
|
8
|
-
quota: QuotaManager;
|
|
9
|
-
}
|
|
10
|
-
export interface PromptMedia {
|
|
11
|
-
type: "image" | "audio" | "video" | "file";
|
|
12
|
-
filePath: string;
|
|
13
|
-
mimeType: string;
|
|
14
|
-
fileName?: string;
|
|
15
|
-
}
|
|
16
|
-
export interface PermissionPolicy {
|
|
17
|
-
permissionMode: PermissionMode;
|
|
18
|
-
nonInteractivePermissions: NonInteractivePermissions;
|
|
19
|
-
permissionPolicy?: string;
|
|
20
|
-
}
|
|
21
|
-
export interface ResolvedSession {
|
|
22
|
-
alias: string;
|
|
23
|
-
agent: string;
|
|
24
|
-
agentCommand?: string;
|
|
25
|
-
workspace: string;
|
|
26
|
-
transportSession: string;
|
|
27
|
-
source?: "weacpx" | "agent-side";
|
|
28
|
-
agentSessionId?: string;
|
|
29
|
-
agentSessionTitle?: string;
|
|
30
|
-
agentSessionUpdatedAt?: string;
|
|
31
|
-
attachedAt?: string;
|
|
32
|
-
mcpCoordinatorSession?: string;
|
|
33
|
-
mcpSourceHandle?: string;
|
|
34
|
-
modeId?: string;
|
|
35
|
-
replyMode?: "stream" | "final" | "verbose";
|
|
36
|
-
cwd: string;
|
|
37
|
-
/**
|
|
38
|
-
* True for a non-persisted, single-use session (e.g. a `/later` temp-mode
|
|
39
|
-
* scheduled run). Transport errors for such a session must not suggest
|
|
40
|
-
* `/session new`/`attach`, and missing-session recovery (which mutates
|
|
41
|
-
* persisted state by alias) does not apply.
|
|
42
|
-
*/
|
|
43
|
-
transient?: boolean;
|
|
44
|
-
}
|
|
45
|
-
export interface AgentSession {
|
|
46
|
-
sessionId: string;
|
|
47
|
-
cwd?: string;
|
|
48
|
-
title?: string | null;
|
|
49
|
-
updatedAt?: string;
|
|
50
|
-
_meta?: Record<string, unknown>;
|
|
51
|
-
}
|
|
52
|
-
export interface AgentSessionListQuery {
|
|
53
|
-
agent: string;
|
|
54
|
-
agentCommand?: string;
|
|
55
|
-
cwd: string;
|
|
56
|
-
cursor?: string;
|
|
57
|
-
filterCwd?: string;
|
|
58
|
-
}
|
|
59
|
-
export interface AgentSessionListResult {
|
|
60
|
-
source: "agent";
|
|
61
|
-
sessions: AgentSession[];
|
|
62
|
-
cursor?: string;
|
|
63
|
-
nextCursor?: string | null;
|
|
64
|
-
cwd?: string;
|
|
65
|
-
}
|
|
66
|
-
export type EnsureSessionProgressStage = "spawn" | "initializing" | "ready";
|
|
67
|
-
export type EnsureSessionProgress = EnsureSessionProgressStage | {
|
|
68
|
-
kind: "note";
|
|
69
|
-
text: string;
|
|
70
|
-
};
|
|
71
|
-
export type PromptMediaInput = PromptMedia | PromptMedia[];
|
|
72
|
-
export interface PromptOptions {
|
|
73
|
-
onSegment?: (text: string) => void | Promise<void>;
|
|
74
|
-
/**
|
|
75
|
-
* Structured side-channel for tool calls. See `toolEventMode` for routing.
|
|
76
|
-
*
|
|
77
|
-
* Async semantics: callbacks are invoked in event order and serialized —
|
|
78
|
-
* each invocation is awaited before the next is dispatched. The transport
|
|
79
|
-
* waits for all callbacks to settle before resolving the prompt. If any
|
|
80
|
-
* invocation throws or returns a rejected promise, the prompt rejects
|
|
81
|
-
* with the first observed error (matching `onSegment` behavior).
|
|
82
|
-
*/
|
|
83
|
-
onToolEvent?: (event: ToolUseEvent) => void | Promise<void>;
|
|
84
|
-
/**
|
|
85
|
-
* Optional structured side-channel for the agent's thinking/reasoning.
|
|
86
|
-
*
|
|
87
|
-
* Each acpx `agent_thought_chunk` is forwarded raw (no buffering, no
|
|
88
|
-
* paragraph splitting). Channels that register this callback opt in to
|
|
89
|
-
* receiving thoughts and are responsible for their own accumulation /
|
|
90
|
-
* rendering. When omitted, thought chunks are dropped at the transport
|
|
91
|
-
* boundary — the built-in WeChat channel does not register it.
|
|
92
|
-
*
|
|
93
|
-
* Async semantics match `onSegment`: invocations are serialized and the
|
|
94
|
-
* transport awaits all of them before resolving the prompt; the first
|
|
95
|
-
* error observed rejects the prompt.
|
|
96
|
-
*/
|
|
97
|
-
onThought?: (chunk: string) => void | Promise<void>;
|
|
98
|
-
/**
|
|
99
|
-
* How tool_call / tool_call_update events are surfaced for this prompt.
|
|
100
|
-
*
|
|
101
|
-
* - "text" (default when no handler): legacy emoji-prefixed segments in the reply stream.
|
|
102
|
-
* - "structured" (default when a handler is provided): events go to `onToolEvent` only.
|
|
103
|
-
* - "both": events go to `onToolEvent` AND legacy text segments — useful for migration.
|
|
104
|
-
*
|
|
105
|
-
* Resolved at the transport boundary via `resolveToolEventMode`.
|
|
106
|
-
*/
|
|
107
|
-
toolEventMode?: ToolEventMode;
|
|
108
|
-
media?: PromptMediaInput;
|
|
109
|
-
}
|
|
110
|
-
export interface SessionTransport {
|
|
111
|
-
ensureSession(session: ResolvedSession, onProgress?: (progress: EnsureSessionProgress) => void): Promise<void>;
|
|
112
|
-
tailSessionHistory(session: ResolvedSession, lines: number): Promise<{
|
|
113
|
-
text: string;
|
|
114
|
-
}>;
|
|
115
|
-
prompt(session: ResolvedSession, text: string, reply?: (text: string) => Promise<void>, replyContext?: ReplyQuotaContext, options?: PromptOptions): Promise<{
|
|
116
|
-
text: string;
|
|
117
|
-
}>;
|
|
118
|
-
setMode(session: ResolvedSession, modeId: string): Promise<void>;
|
|
119
|
-
cancel(session: ResolvedSession): Promise<{
|
|
120
|
-
cancelled: boolean;
|
|
121
|
-
message: string;
|
|
122
|
-
}>;
|
|
123
|
-
hasSession(session: ResolvedSession): Promise<boolean>;
|
|
124
|
-
listAgentSessions?(query: AgentSessionListQuery): Promise<AgentSessionListResult | undefined>;
|
|
125
|
-
resumeAgentSession?(session: ResolvedSession, agentSessionId: string): Promise<void>;
|
|
126
|
-
removeSession?(session: ResolvedSession): Promise<void>;
|
|
127
|
-
updatePermissionPolicy?(policy: PermissionPolicy): Promise<void>;
|
|
128
|
-
dispose?(): Promise<void>;
|
|
129
|
-
}
|
package/dist/util/path.d.ts
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
export declare function writePrivateFileAtomic(path: string, content: string): Promise<void>;
|
|
2
|
-
/**
|
|
3
|
-
* Synchronous private-file write for hot-path callers that cannot await
|
|
4
|
-
* (e.g. per-message weixin credential/sync-buf/context-token persistence).
|
|
5
|
-
* Atomic via write-file-atomic's temp+rename, created at 0600 so the secret is
|
|
6
|
-
* never momentarily world-readable. No cross-process lock: weixin's per-account
|
|
7
|
-
* consumer lock already serializes the single writing daemon.
|
|
8
|
-
*/
|
|
9
|
-
interface WritePrivateFileSyncDeps {
|
|
10
|
-
platform?: NodeJS.Platform;
|
|
11
|
-
atomicWrite?: (path: string, content: string) => void;
|
|
12
|
-
directWrite?: (path: string, content: string) => void;
|
|
13
|
-
}
|
|
14
|
-
export declare function writePrivateFileSync(path: string, content: string, deps?: WritePrivateFileSyncDeps): void;
|
|
15
|
-
interface RetryTransientWriteOptions {
|
|
16
|
-
platform?: NodeJS.Platform;
|
|
17
|
-
maxAttempts?: number;
|
|
18
|
-
baseDelayMs?: number;
|
|
19
|
-
maxDelayMs?: number;
|
|
20
|
-
delay?: (ms: number) => Promise<void>;
|
|
21
|
-
}
|
|
22
|
-
export declare function retryTransientWriteErrors(run: () => Promise<void>, options?: RetryTransientWriteOptions): Promise<void>;
|
|
23
|
-
export declare const __privateFileForTests: {
|
|
24
|
-
retryTransientWriteErrors: typeof retryTransientWriteErrors;
|
|
25
|
-
};
|
|
26
|
-
export {};
|
package/dist/util/sanitize.d.ts
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
export interface SanitizeOptions {
|
|
2
|
-
allow?: RegExp;
|
|
3
|
-
deny?: RegExp;
|
|
4
|
-
replacement?: string;
|
|
5
|
-
collapse?: boolean;
|
|
6
|
-
trim?: boolean;
|
|
7
|
-
lowercase?: boolean;
|
|
8
|
-
fallback?: string;
|
|
9
|
-
}
|
|
10
|
-
export declare function sanitizeString(input: string, options?: SanitizeOptions): string;
|
package/dist/util/text.d.ts
DELETED
package/dist/version.d.ts
DELETED
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
import type { ChannelMediaAttachment, OutboundChannelMedia } from "../../channels/media-types.js";
|
|
2
|
-
import type { ScheduledSessionDescriptor, ToolUseEvent } from "../../channels/types.js";
|
|
3
|
-
import type { PerfSpan } from "../../perf/perf-tracer.js";
|
|
4
|
-
/**
|
|
5
|
-
* Agent interface — any AI backend that can handle a chat message.
|
|
6
|
-
*
|
|
7
|
-
* Implement this interface to connect WeChat to your own AI service.
|
|
8
|
-
* The WeChat bridge calls `chat()` for each inbound message and sends
|
|
9
|
-
* the returned response back to the user.
|
|
10
|
-
*/
|
|
11
|
-
export interface Agent {
|
|
12
|
-
/** Process a single message and return a reply. */
|
|
13
|
-
chat(request: ChatRequest): Promise<ChatResponse>;
|
|
14
|
-
/** Return true when the text begins with a command prefix handled by this agent. */
|
|
15
|
-
isKnownCommand?(text: string): boolean;
|
|
16
|
-
/** Clear/reset the session for a given conversation. */
|
|
17
|
-
clearSession?(conversationId: string): void | Promise<void>;
|
|
18
|
-
}
|
|
19
|
-
export interface ChatRequest {
|
|
20
|
-
/** Inbound Weixin account id that received this message. */
|
|
21
|
-
accountId: string;
|
|
22
|
-
/** Conversation / user identifier. Use this to maintain per-user context. */
|
|
23
|
-
conversationId: string;
|
|
24
|
-
/** Text content of the message. */
|
|
25
|
-
text: string;
|
|
26
|
-
/** Attached media file(s) (image, audio, video, or generic file). */
|
|
27
|
-
media?: ChannelMediaAttachment | ChannelMediaAttachment[];
|
|
28
|
-
/**
|
|
29
|
-
* Optional callback for streaming text out during long-running agent
|
|
30
|
-
* processing. When the channel delivers any non-empty reply segment,
|
|
31
|
-
* callers may treat it as the text output channel for that turn and
|
|
32
|
-
* suppress `ChatResponse.text`.
|
|
33
|
-
*/
|
|
34
|
-
reply?: (text: string) => Promise<void>;
|
|
35
|
-
/** Latest inbound Weixin context token for follow-up replies in the same chat. */
|
|
36
|
-
replyContextToken?: string;
|
|
37
|
-
/** Channel-provided facts for command authorization and routing policy. */
|
|
38
|
-
metadata?: ChatRequestMetadata;
|
|
39
|
-
/**
|
|
40
|
-
* Signals that the channel has received an abort/stop request for this turn.
|
|
41
|
-
* Agents that can interrupt long-running work (e.g. cancel an in-flight acpx
|
|
42
|
-
* prompt) should observe this and bail out early. Optional; agents that don't
|
|
43
|
-
* support cancellation may ignore it — the channel will still suppress any
|
|
44
|
-
* output produced after abort.
|
|
45
|
-
*/
|
|
46
|
-
abortSignal?: AbortSignal;
|
|
47
|
-
/** Structured tool-use side-channel; see PromptOptions.onToolEvent. */
|
|
48
|
-
onToolEvent?: (event: ToolUseEvent) => void | Promise<void>;
|
|
49
|
-
/** Structured thinking side-channel; see PromptOptions.onThought. */
|
|
50
|
-
onThought?: (chunk: string) => void | Promise<void>;
|
|
51
|
-
/**
|
|
52
|
-
* Optional per-turn performance tracing span. When `logging.perf.enabled` is
|
|
53
|
-
* true, the channel handler attaches a `PerfSpan` so downstream layers can
|
|
54
|
-
* inline `request.perfSpan?.mark(event, ctx)` without further plumbing.
|
|
55
|
-
*/
|
|
56
|
-
perfSpan?: PerfSpan;
|
|
57
|
-
}
|
|
58
|
-
export interface ChatRequestMetadata {
|
|
59
|
-
channel?: string;
|
|
60
|
-
chatType?: "direct" | "group";
|
|
61
|
-
senderId?: string;
|
|
62
|
-
senderName?: string;
|
|
63
|
-
groupId?: string;
|
|
64
|
-
isOwner?: boolean;
|
|
65
|
-
/** Internal weacpx session alias to use for non-interactive scheduled prompts. */
|
|
66
|
-
scheduledSessionAlias?: string;
|
|
67
|
-
/** Transient session descriptor for temp-mode scheduled prompts (no persisted alias). */
|
|
68
|
-
scheduledSessionDescriptor?: ScheduledSessionDescriptor;
|
|
69
|
-
}
|
|
70
|
-
export interface ChatResponse {
|
|
71
|
-
/**
|
|
72
|
-
* Final reply text when no streamed `reply()` output was delivered for
|
|
73
|
-
* the same turn. May contain markdown and will be normalized before send.
|
|
74
|
-
*/
|
|
75
|
-
text?: string;
|
|
76
|
-
/** Reply media file(s). */
|
|
77
|
-
media?: OutboundChannelMedia | OutboundChannelMedia[];
|
|
78
|
-
}
|
package/dist/weixin/api/api.d.ts
DELETED
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
import type { BaseInfo, GetUploadUrlReq, GetUploadUrlResp, GetUpdatesReq, GetUpdatesResp, SendMessageReq, SendTypingReq, GetConfigResp } from "./types.js";
|
|
2
|
-
export type WeixinApiOptions = {
|
|
3
|
-
baseUrl: string;
|
|
4
|
-
token?: string;
|
|
5
|
-
timeoutMs?: number;
|
|
6
|
-
/** Long-poll timeout for getUpdates (server may hold the request up to this). */
|
|
7
|
-
longPollTimeoutMs?: number;
|
|
8
|
-
};
|
|
9
|
-
/**
|
|
10
|
-
* Sanitize a user-supplied `botAgent` config value into a wire-safe string.
|
|
11
|
-
*
|
|
12
|
-
* Grammar (UA-style):
|
|
13
|
-
* bot_agent = product *( SP product )
|
|
14
|
-
* product = name "/" version [ SP "(" comment ")" ]
|
|
15
|
-
* name = 1*32( ALPHA / DIGIT / "_" / "." / "-" )
|
|
16
|
-
* version = 1*32( ALPHA / DIGIT / "_" / "." / "+" / "-" )
|
|
17
|
-
* comment = 1*64( printable ASCII minus "(" ")" )
|
|
18
|
-
*
|
|
19
|
-
* Tokens that fail to parse are dropped silently (no partial tokens kept).
|
|
20
|
-
* Returns `DEFAULT_BOT_AGENT` when the input is empty / all tokens dropped /
|
|
21
|
-
* the result exceeds the length cap after truncation.
|
|
22
|
-
*/
|
|
23
|
-
export declare function sanitizeBotAgent(raw: string | undefined): string;
|
|
24
|
-
/** Build the `base_info` payload included in every API request. */
|
|
25
|
-
export declare function buildBaseInfo(): BaseInfo;
|
|
26
|
-
/**
|
|
27
|
-
* GET fetch wrapper: send a GET request to a Weixin API endpoint with timeout + abort.
|
|
28
|
-
* Query parameters should already be encoded in `endpoint`.
|
|
29
|
-
* Returns the raw response text on success; throws on HTTP error or timeout.
|
|
30
|
-
*/
|
|
31
|
-
export declare function apiGetFetch(params: {
|
|
32
|
-
baseUrl: string;
|
|
33
|
-
endpoint: string;
|
|
34
|
-
timeoutMs: number;
|
|
35
|
-
label: string;
|
|
36
|
-
}): Promise<string>;
|
|
37
|
-
/**
|
|
38
|
-
* Simple POST fetch wrapper for login/auth endpoints.
|
|
39
|
-
* Returns the raw response text on success; throws on HTTP error or timeout.
|
|
40
|
-
*/
|
|
41
|
-
export declare function apiPostFetch(params: {
|
|
42
|
-
baseUrl: string;
|
|
43
|
-
endpoint: string;
|
|
44
|
-
body: string;
|
|
45
|
-
token?: string;
|
|
46
|
-
timeoutMs?: number;
|
|
47
|
-
label: string;
|
|
48
|
-
abortSignal?: AbortSignal;
|
|
49
|
-
}): Promise<string>;
|
|
50
|
-
/**
|
|
51
|
-
* Long-poll getUpdates. Server should hold the request until new messages or timeout.
|
|
52
|
-
*
|
|
53
|
-
* On client-side timeout (no server response within timeoutMs), returns an empty response
|
|
54
|
-
* with ret=0 so the caller can simply retry. This is normal for long-poll.
|
|
55
|
-
*/
|
|
56
|
-
export declare function getUpdates(params: GetUpdatesReq & {
|
|
57
|
-
baseUrl: string;
|
|
58
|
-
token?: string;
|
|
59
|
-
timeoutMs?: number;
|
|
60
|
-
abortSignal?: AbortSignal;
|
|
61
|
-
}): Promise<GetUpdatesResp>;
|
|
62
|
-
/** Get a pre-signed CDN upload URL for a file. */
|
|
63
|
-
export declare function getUploadUrl(params: GetUploadUrlReq & WeixinApiOptions): Promise<GetUploadUrlResp>;
|
|
64
|
-
/** Send a single message downstream. */
|
|
65
|
-
export declare function sendMessage(params: WeixinApiOptions & {
|
|
66
|
-
body: SendMessageReq;
|
|
67
|
-
}): Promise<void>;
|
|
68
|
-
/** Fetch bot config (includes typing_ticket) for a given user. */
|
|
69
|
-
export declare function getConfig(params: WeixinApiOptions & {
|
|
70
|
-
ilinkUserId: string;
|
|
71
|
-
contextToken?: string;
|
|
72
|
-
}): Promise<GetConfigResp>;
|
|
73
|
-
/** Send a typing indicator to a user. */
|
|
74
|
-
export declare function sendTyping(params: WeixinApiOptions & {
|
|
75
|
-
body: SendTypingReq;
|
|
76
|
-
}): Promise<void>;
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
/** Subset of getConfig fields that we actually need; add new fields here as needed. */
|
|
2
|
-
export interface CachedConfig {
|
|
3
|
-
typingTicket: string;
|
|
4
|
-
}
|
|
5
|
-
/**
|
|
6
|
-
* Per-user getConfig cache with periodic random refresh (within 24h) and
|
|
7
|
-
* exponential-backoff retry (up to 1h) on failure.
|
|
8
|
-
*/
|
|
9
|
-
export declare class WeixinConfigManager {
|
|
10
|
-
private apiOpts;
|
|
11
|
-
private log;
|
|
12
|
-
private cache;
|
|
13
|
-
constructor(apiOpts: {
|
|
14
|
-
baseUrl: string;
|
|
15
|
-
token?: string;
|
|
16
|
-
}, log: (msg: string) => void);
|
|
17
|
-
getForUser(userId: string, contextToken?: string): Promise<CachedConfig>;
|
|
18
|
-
}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
/** Error code returned by the server when the bot session has expired. */
|
|
2
|
-
export declare const SESSION_EXPIRED_ERRCODE = -14;
|
|
3
|
-
/** Pause all inbound/outbound API calls for `accountId` for one hour. */
|
|
4
|
-
export declare function pauseSession(accountId: string): void;
|
|
5
|
-
/** Returns `true` when the bot is still within its one-hour cooldown window. */
|
|
6
|
-
export declare function isSessionPaused(accountId: string): boolean;
|
|
7
|
-
/** Milliseconds remaining until the pause expires (0 when not paused). */
|
|
8
|
-
export declare function getRemainingPauseMs(accountId: string): number;
|
|
9
|
-
/** Clear the session pause for a specific account. Used when fresh credentials are detected. */
|
|
10
|
-
export declare function resetSessionPause(accountId: string): void;
|
|
11
|
-
/** Throw if the session is currently paused. Call before any API request. */
|
|
12
|
-
export declare function assertSessionActive(accountId: string): void;
|
|
13
|
-
/**
|
|
14
|
-
* Reset internal state — only for tests.
|
|
15
|
-
* @internal
|
|
16
|
-
*/
|
|
17
|
-
export declare function _resetForTest(): void;
|