@clawdbot/zalouser 2026.1.16 → 2026.1.21
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/CHANGELOG.md +23 -0
- package/clawdbot.plugin.json +11 -0
- package/index.ts +7 -3
- package/package.json +21 -2
- package/src/accounts.ts +17 -21
- package/src/channel.ts +196 -103
- package/src/config-schema.ts +24 -0
- package/src/monitor.ts +229 -46
- package/src/onboarding.ts +259 -83
- package/src/probe.ts +28 -0
- package/src/runtime.ts +14 -0
- package/src/status-issues.test.ts +58 -0
- package/src/status-issues.ts +81 -0
- package/src/types.ts +4 -11
- package/src/zca.ts +26 -1
- package/src/core-bridge.ts +0 -171
package/src/zca.ts
CHANGED
|
@@ -114,11 +114,36 @@ export function runZcaInteractive(
|
|
|
114
114
|
});
|
|
115
115
|
}
|
|
116
116
|
|
|
117
|
+
function stripAnsi(str: string): string {
|
|
118
|
+
return str.replace(/\x1B\[[0-9;]*[a-zA-Z]/g, "");
|
|
119
|
+
}
|
|
120
|
+
|
|
117
121
|
export function parseJsonOutput<T>(stdout: string): T | null {
|
|
118
122
|
try {
|
|
119
123
|
return JSON.parse(stdout) as T;
|
|
120
124
|
} catch {
|
|
121
|
-
|
|
125
|
+
const cleaned = stripAnsi(stdout);
|
|
126
|
+
|
|
127
|
+
try {
|
|
128
|
+
return JSON.parse(cleaned) as T;
|
|
129
|
+
} catch {
|
|
130
|
+
// zca may prefix output with INFO/log lines, try to find JSON
|
|
131
|
+
const lines = cleaned.split("\n");
|
|
132
|
+
|
|
133
|
+
for (let i = 0; i < lines.length; i++) {
|
|
134
|
+
const line = lines[i].trim();
|
|
135
|
+
if (line.startsWith("{") || line.startsWith("[")) {
|
|
136
|
+
// Try parsing from this line to the end
|
|
137
|
+
const jsonCandidate = lines.slice(i).join("\n").trim();
|
|
138
|
+
try {
|
|
139
|
+
return JSON.parse(jsonCandidate) as T;
|
|
140
|
+
} catch {
|
|
141
|
+
continue;
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
return null;
|
|
146
|
+
}
|
|
122
147
|
}
|
|
123
148
|
}
|
|
124
149
|
|
package/src/core-bridge.ts
DELETED
|
@@ -1,171 +0,0 @@
|
|
|
1
|
-
import fs from "node:fs";
|
|
2
|
-
import path from "node:path";
|
|
3
|
-
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
4
|
-
|
|
5
|
-
export type CoreChannelDeps = {
|
|
6
|
-
chunkMarkdownText: (text: string, limit: number) => string[];
|
|
7
|
-
formatAgentEnvelope: (params: {
|
|
8
|
-
channel: string;
|
|
9
|
-
from: string;
|
|
10
|
-
timestamp?: number;
|
|
11
|
-
body: string;
|
|
12
|
-
}) => string;
|
|
13
|
-
dispatchReplyWithBufferedBlockDispatcher: (params: {
|
|
14
|
-
ctx: unknown;
|
|
15
|
-
cfg: unknown;
|
|
16
|
-
dispatcherOptions: {
|
|
17
|
-
deliver: (payload: unknown) => Promise<void>;
|
|
18
|
-
onError?: (err: unknown, info: { kind: string }) => void;
|
|
19
|
-
};
|
|
20
|
-
}) => Promise<void>;
|
|
21
|
-
resolveAgentRoute: (params: {
|
|
22
|
-
cfg: unknown;
|
|
23
|
-
channel: string;
|
|
24
|
-
accountId: string;
|
|
25
|
-
peer: { kind: "dm" | "group" | "channel"; id: string };
|
|
26
|
-
}) => { sessionKey: string; accountId: string };
|
|
27
|
-
buildPairingReply: (params: { channel: string; idLine: string; code: string }) => string;
|
|
28
|
-
readChannelAllowFromStore: (channel: string) => Promise<string[]>;
|
|
29
|
-
upsertChannelPairingRequest: (params: {
|
|
30
|
-
channel: string;
|
|
31
|
-
id: string;
|
|
32
|
-
meta?: { name?: string };
|
|
33
|
-
}) => Promise<{ code: string; created: boolean }>;
|
|
34
|
-
fetchRemoteMedia: (params: { url: string }) => Promise<{ buffer: Buffer; contentType?: string }>;
|
|
35
|
-
saveMediaBuffer: (
|
|
36
|
-
buffer: Buffer,
|
|
37
|
-
contentType: string | undefined,
|
|
38
|
-
type: "inbound" | "outbound",
|
|
39
|
-
maxBytes: number,
|
|
40
|
-
) => Promise<{ path: string; contentType: string }>;
|
|
41
|
-
shouldLogVerbose: () => boolean;
|
|
42
|
-
};
|
|
43
|
-
|
|
44
|
-
let coreRootCache: string | null = null;
|
|
45
|
-
let coreDepsPromise: Promise<CoreChannelDeps> | null = null;
|
|
46
|
-
|
|
47
|
-
function findPackageRoot(startDir: string, name: string): string | null {
|
|
48
|
-
let dir = startDir;
|
|
49
|
-
for (;;) {
|
|
50
|
-
const pkgPath = path.join(dir, "package.json");
|
|
51
|
-
try {
|
|
52
|
-
if (fs.existsSync(pkgPath)) {
|
|
53
|
-
const raw = fs.readFileSync(pkgPath, "utf8");
|
|
54
|
-
const pkg = JSON.parse(raw) as { name?: string };
|
|
55
|
-
if (pkg.name === name) return dir;
|
|
56
|
-
}
|
|
57
|
-
} catch {
|
|
58
|
-
// ignore parse errors
|
|
59
|
-
}
|
|
60
|
-
const parent = path.dirname(dir);
|
|
61
|
-
if (parent === dir) return null;
|
|
62
|
-
dir = parent;
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
function resolveClawdbotRoot(): string {
|
|
67
|
-
if (coreRootCache) return coreRootCache;
|
|
68
|
-
const override = process.env.CLAWDBOT_ROOT?.trim();
|
|
69
|
-
if (override) {
|
|
70
|
-
coreRootCache = override;
|
|
71
|
-
return override;
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
const candidates = new Set<string>();
|
|
75
|
-
if (process.argv[1]) {
|
|
76
|
-
candidates.add(path.dirname(process.argv[1]));
|
|
77
|
-
}
|
|
78
|
-
candidates.add(process.cwd());
|
|
79
|
-
try {
|
|
80
|
-
const urlPath = fileURLToPath(import.meta.url);
|
|
81
|
-
candidates.add(path.dirname(urlPath));
|
|
82
|
-
} catch {
|
|
83
|
-
// ignore
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
for (const start of candidates) {
|
|
87
|
-
const found = findPackageRoot(start, "clawdbot");
|
|
88
|
-
if (found) {
|
|
89
|
-
coreRootCache = found;
|
|
90
|
-
return found;
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
throw new Error(
|
|
95
|
-
"Unable to resolve Clawdbot root. Set CLAWDBOT_ROOT to the package root.",
|
|
96
|
-
);
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
async function importCoreModule<T>(relativePath: string): Promise<T> {
|
|
100
|
-
const root = resolveClawdbotRoot();
|
|
101
|
-
const distPath = path.join(root, "dist", relativePath);
|
|
102
|
-
if (!fs.existsSync(distPath)) {
|
|
103
|
-
throw new Error(
|
|
104
|
-
`Missing core module at ${distPath}. Run \`pnpm build\` or install the official package.`,
|
|
105
|
-
);
|
|
106
|
-
}
|
|
107
|
-
return (await import(pathToFileURL(distPath).href)) as T;
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
export async function loadCoreChannelDeps(): Promise<CoreChannelDeps> {
|
|
111
|
-
if (coreDepsPromise) return coreDepsPromise;
|
|
112
|
-
|
|
113
|
-
coreDepsPromise = (async () => {
|
|
114
|
-
const [
|
|
115
|
-
chunk,
|
|
116
|
-
envelope,
|
|
117
|
-
dispatcher,
|
|
118
|
-
routing,
|
|
119
|
-
pairingMessages,
|
|
120
|
-
pairingStore,
|
|
121
|
-
mediaFetch,
|
|
122
|
-
mediaStore,
|
|
123
|
-
globals,
|
|
124
|
-
] = await Promise.all([
|
|
125
|
-
importCoreModule<{ chunkMarkdownText: CoreChannelDeps["chunkMarkdownText"] }>(
|
|
126
|
-
"auto-reply/chunk.js",
|
|
127
|
-
),
|
|
128
|
-
importCoreModule<{ formatAgentEnvelope: CoreChannelDeps["formatAgentEnvelope"] }>(
|
|
129
|
-
"auto-reply/envelope.js",
|
|
130
|
-
),
|
|
131
|
-
importCoreModule<{
|
|
132
|
-
dispatchReplyWithBufferedBlockDispatcher: CoreChannelDeps["dispatchReplyWithBufferedBlockDispatcher"];
|
|
133
|
-
}>("auto-reply/reply/provider-dispatcher.js"),
|
|
134
|
-
importCoreModule<{ resolveAgentRoute: CoreChannelDeps["resolveAgentRoute"] }>(
|
|
135
|
-
"routing/resolve-route.js",
|
|
136
|
-
),
|
|
137
|
-
importCoreModule<{ buildPairingReply: CoreChannelDeps["buildPairingReply"] }>(
|
|
138
|
-
"pairing/pairing-messages.js",
|
|
139
|
-
),
|
|
140
|
-
importCoreModule<{
|
|
141
|
-
readChannelAllowFromStore: CoreChannelDeps["readChannelAllowFromStore"];
|
|
142
|
-
upsertChannelPairingRequest: CoreChannelDeps["upsertChannelPairingRequest"];
|
|
143
|
-
}>("pairing/pairing-store.js"),
|
|
144
|
-
importCoreModule<{ fetchRemoteMedia: CoreChannelDeps["fetchRemoteMedia"] }>(
|
|
145
|
-
"media/fetch.js",
|
|
146
|
-
),
|
|
147
|
-
importCoreModule<{ saveMediaBuffer: CoreChannelDeps["saveMediaBuffer"] }>(
|
|
148
|
-
"media/store.js",
|
|
149
|
-
),
|
|
150
|
-
importCoreModule<{ shouldLogVerbose: CoreChannelDeps["shouldLogVerbose"] }>(
|
|
151
|
-
"globals.js",
|
|
152
|
-
),
|
|
153
|
-
]);
|
|
154
|
-
|
|
155
|
-
return {
|
|
156
|
-
chunkMarkdownText: chunk.chunkMarkdownText,
|
|
157
|
-
formatAgentEnvelope: envelope.formatAgentEnvelope,
|
|
158
|
-
dispatchReplyWithBufferedBlockDispatcher:
|
|
159
|
-
dispatcher.dispatchReplyWithBufferedBlockDispatcher,
|
|
160
|
-
resolveAgentRoute: routing.resolveAgentRoute,
|
|
161
|
-
buildPairingReply: pairingMessages.buildPairingReply,
|
|
162
|
-
readChannelAllowFromStore: pairingStore.readChannelAllowFromStore,
|
|
163
|
-
upsertChannelPairingRequest: pairingStore.upsertChannelPairingRequest,
|
|
164
|
-
fetchRemoteMedia: mediaFetch.fetchRemoteMedia,
|
|
165
|
-
saveMediaBuffer: mediaStore.saveMediaBuffer,
|
|
166
|
-
shouldLogVerbose: globals.shouldLogVerbose,
|
|
167
|
-
};
|
|
168
|
-
})();
|
|
169
|
-
|
|
170
|
-
return coreDepsPromise;
|
|
171
|
-
}
|