openclaw-multi-auto 1.7.0 → 1.7.3
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/dist/build-info.json +3 -3
- package/dist/canvas-host/a2ui/.bundle.hash +1 -1
- package/dist/plugin-sdk/accounts-CJWOBzwB.js +35 -0
- package/dist/plugin-sdk/accounts-DP1-L-QS.js +288 -0
- package/dist/plugin-sdk/accounts-DZhWlEg3.js +46 -0
- package/dist/plugin-sdk/active-listener-B_sLJTXM.js +50 -0
- package/dist/plugin-sdk/api-key-rotation-BRE4X2tf.js +181 -0
- package/dist/plugin-sdk/audio-preflight-DGEUDxxR.js +69 -0
- package/dist/plugin-sdk/audio-transcription-runner-DkoPNPYt.js +2176 -0
- package/dist/plugin-sdk/audit-membership-runtime-DSBHHw7o.js +58 -0
- package/dist/plugin-sdk/channel-activity-F3d0yUwy.js +94 -0
- package/dist/plugin-sdk/channel-web-QF7EpjeP.js +2256 -0
- package/dist/plugin-sdk/chrome-BXoCyCkY.js +2415 -0
- package/dist/plugin-sdk/commands-registry-t7cXBTfN.js +1125 -0
- package/dist/plugin-sdk/config-BkEnz2Po.js +17913 -0
- package/dist/plugin-sdk/deliver-B6AG_l67.js +1694 -0
- package/dist/plugin-sdk/deliver-runtime-D585kJZc.js +32 -0
- package/dist/plugin-sdk/deps-send-discord.runtime-a_OKY2js.js +23 -0
- package/dist/plugin-sdk/deps-send-imessage.runtime-Baxy9TD4.js +22 -0
- package/dist/plugin-sdk/deps-send-signal.runtime-BwXoCrFl.js +21 -0
- package/dist/plugin-sdk/deps-send-slack.runtime-CLmKjgso.js +19 -0
- package/dist/plugin-sdk/deps-send-telegram.runtime-BKfdBKnZ.js +24 -0
- package/dist/plugin-sdk/deps-send-whatsapp.runtime-BOTwkbx_.js +57 -0
- package/dist/plugin-sdk/diagnostic-CsP-lEkI.js +319 -0
- package/dist/plugin-sdk/errors-DaiAM-yU.js +54 -0
- package/dist/plugin-sdk/fetch-guard-DETCcJzQ.js +156 -0
- package/dist/plugin-sdk/fs-safe-B8y811FR.js +352 -0
- package/dist/plugin-sdk/image-DjTEkYZE.js +2310 -0
- package/dist/plugin-sdk/image-ops-BSiMpAw4.js +584 -0
- package/dist/plugin-sdk/image-runtime-6xPp8m5a.js +25 -0
- package/dist/plugin-sdk/index.js +50 -50
- package/dist/plugin-sdk/ir-DQ7_HbvK.js +1296 -0
- package/dist/plugin-sdk/local-roots-BUP4YBmR.js +186 -0
- package/dist/plugin-sdk/logger-CZY9KIoY.js +1163 -0
- package/dist/plugin-sdk/login-BxEKLlCo.js +57 -0
- package/dist/plugin-sdk/login-qr-BQIpMPr9.js +320 -0
- package/dist/plugin-sdk/manager-I6KbPihW.js +3917 -0
- package/dist/plugin-sdk/manager-runtime-CFfYYWIQ.js +15 -0
- package/dist/plugin-sdk/outbound-NS6UHnB6.js +212 -0
- package/dist/plugin-sdk/outbound-attachment-Dy6fyf6H.js +19 -0
- package/dist/plugin-sdk/path-alias-guards-DBjLbIX_.js +43 -0
- package/dist/plugin-sdk/paths-vTM3Lh3X.js +166 -0
- package/dist/plugin-sdk/pi-embedded-helpers-1R1gu7eX.js +9627 -0
- package/dist/plugin-sdk/pi-model-discovery-runtime-Do9o-dUd.js +8 -0
- package/dist/plugin-sdk/pi-model-discovery-v-XPUOOf.js +134 -0
- package/dist/plugin-sdk/pi-tools.before-tool-call.runtime-D4sFsIks.js +354 -0
- package/dist/plugin-sdk/plugins-DeBZB9l_.js +864 -0
- package/dist/plugin-sdk/proxy-fetch-ChxOhWF4.js +38 -0
- package/dist/plugin-sdk/pw-ai-DEOmCSSC.js +1938 -0
- package/dist/plugin-sdk/qmd-manager-HyYKoEch.js +1448 -0
- package/dist/plugin-sdk/query-expansion-CeyKUeDW.js +1011 -0
- package/dist/plugin-sdk/redact-DjVX-1N3.js +319 -0
- package/dist/plugin-sdk/reply-DAo_Jt8K.js +97916 -0
- package/dist/plugin-sdk/resolve-outbound-target-B42qgQS9.js +40 -0
- package/dist/plugin-sdk/run-with-concurrency-Bt_ks0Qa.js +1994 -0
- package/dist/plugin-sdk/runtime-whatsapp-login.runtime-B6W989eF.js +10 -0
- package/dist/plugin-sdk/runtime-whatsapp-outbound.runtime-c_GDFy37.js +19 -0
- package/dist/plugin-sdk/send-CQpMudwO.js +2587 -0
- package/dist/plugin-sdk/send-DQHLzVyO.js +414 -0
- package/dist/plugin-sdk/send-DTB24bEF.js +3135 -0
- package/dist/plugin-sdk/send-DfHadjZ_.js +503 -0
- package/dist/plugin-sdk/send-XXlW2iny.js +540 -0
- package/dist/plugin-sdk/session-6TF6MyaC.js +169 -0
- package/dist/plugin-sdk/skill-commands-CkGeFUMl.js +342 -0
- package/dist/plugin-sdk/skills-CBkHBYPq.js +1428 -0
- package/dist/plugin-sdk/slash-commands.runtime-CxliuGaP.js +13 -0
- package/dist/plugin-sdk/slash-dispatch.runtime-DFaeYlJQ.js +52 -0
- package/dist/plugin-sdk/slash-skill-commands.runtime-0M0OLCxq.js +16 -0
- package/dist/plugin-sdk/ssrf-cFtplYtS.js +202 -0
- package/dist/plugin-sdk/store-5nyxY3WU.js +81 -0
- package/dist/plugin-sdk/subagent-registry-runtime-DCtmDwna.js +52 -0
- package/dist/plugin-sdk/tables-C47P4GTN.js +55 -0
- package/dist/plugin-sdk/target-errors-Blia4S69.js +195 -0
- package/dist/plugin-sdk/thinking-Bo2eosVa.js +1206 -0
- package/dist/plugin-sdk/tokens-DgNRBwIg.js +52 -0
- package/dist/plugin-sdk/tool-images-Gk_-0y2N.js +274 -0
- package/dist/plugin-sdk/web-CVxZbXyH.js +56 -0
- package/dist/plugin-sdk/whatsapp-actions-Bw0H9g-n.js +80 -0
- package/package.json +1 -1
- package/scripts/create-instance.sh +12 -19
package/dist/build-info.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
aefd368fa9a68e0748c1358dae286ec36b151a9b875c5901874ddb08700b2022
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { ot as normalizeAccountId } from "./run-with-concurrency-Bt_ks0Qa.js";
|
|
2
|
+
import { v as resolveAccountEntry, y as createAccountListHelpers } from "./accounts-DP1-L-QS.js";
|
|
3
|
+
|
|
4
|
+
//#region src/imessage/accounts.ts
|
|
5
|
+
const { listAccountIds, resolveDefaultAccountId } = createAccountListHelpers("imessage");
|
|
6
|
+
const listIMessageAccountIds = listAccountIds;
|
|
7
|
+
const resolveDefaultIMessageAccountId = resolveDefaultAccountId;
|
|
8
|
+
function resolveAccountConfig(cfg, accountId) {
|
|
9
|
+
return resolveAccountEntry(cfg.channels?.imessage?.accounts, accountId);
|
|
10
|
+
}
|
|
11
|
+
function mergeIMessageAccountConfig(cfg, accountId) {
|
|
12
|
+
const { accounts: _ignored, ...base } = cfg.channels?.imessage ?? {};
|
|
13
|
+
const account = resolveAccountConfig(cfg, accountId) ?? {};
|
|
14
|
+
return {
|
|
15
|
+
...base,
|
|
16
|
+
...account
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
function resolveIMessageAccount(params) {
|
|
20
|
+
const accountId = normalizeAccountId(params.accountId);
|
|
21
|
+
const baseEnabled = params.cfg.channels?.imessage?.enabled !== false;
|
|
22
|
+
const merged = mergeIMessageAccountConfig(params.cfg, accountId);
|
|
23
|
+
const accountEnabled = merged.enabled !== false;
|
|
24
|
+
const configured = Boolean(merged.cliPath?.trim() || merged.dbPath?.trim() || merged.service || merged.region?.trim() || merged.allowFrom && merged.allowFrom.length > 0 || merged.groupAllowFrom && merged.groupAllowFrom.length > 0 || merged.dmPolicy || merged.groupPolicy || typeof merged.includeAttachments === "boolean" || merged.attachmentRoots && merged.attachmentRoots.length > 0 || merged.remoteAttachmentRoots && merged.remoteAttachmentRoots.length > 0 || typeof merged.mediaMaxMb === "number" || typeof merged.textChunkLimit === "number" || merged.groups && Object.keys(merged.groups).length > 0);
|
|
25
|
+
return {
|
|
26
|
+
accountId,
|
|
27
|
+
enabled: baseEnabled && accountEnabled,
|
|
28
|
+
name: merged.name?.trim() || void 0,
|
|
29
|
+
config: merged,
|
|
30
|
+
configured
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
//#endregion
|
|
35
|
+
export { resolveDefaultIMessageAccountId as n, resolveIMessageAccount as r, listIMessageAccountIds as t };
|
|
@@ -0,0 +1,288 @@
|
|
|
1
|
+
import { at as DEFAULT_ACCOUNT_ID, ot as normalizeAccountId, st as normalizeOptionalAccountId } from "./run-with-concurrency-Bt_ks0Qa.js";
|
|
2
|
+
import { o as resolveOAuthDir } from "./paths-MKyEVmEb.js";
|
|
3
|
+
import { Pr as formatCliCommand } from "./config-BkEnz2Po.js";
|
|
4
|
+
import { B as success, E as resolveUserPath, G as getChildLogger, I as info, c as defaultRuntime, x as jidToE164 } from "./logger-CZY9KIoY.js";
|
|
5
|
+
import fs from "node:fs";
|
|
6
|
+
import path from "node:path";
|
|
7
|
+
import fs$1 from "node:fs/promises";
|
|
8
|
+
|
|
9
|
+
//#region src/channels/plugins/account-helpers.ts
|
|
10
|
+
function createAccountListHelpers(channelKey) {
|
|
11
|
+
function resolveConfiguredDefaultAccountId(cfg) {
|
|
12
|
+
const channel = cfg.channels?.[channelKey];
|
|
13
|
+
const preferred = normalizeOptionalAccountId(typeof channel?.defaultAccount === "string" ? channel.defaultAccount : void 0);
|
|
14
|
+
if (!preferred) return;
|
|
15
|
+
if (listAccountIds(cfg).some((id) => normalizeAccountId(id) === preferred)) return preferred;
|
|
16
|
+
}
|
|
17
|
+
function listConfiguredAccountIds(cfg) {
|
|
18
|
+
const accounts = (cfg.channels?.[channelKey])?.accounts;
|
|
19
|
+
if (!accounts || typeof accounts !== "object") return [];
|
|
20
|
+
return Object.keys(accounts).filter(Boolean);
|
|
21
|
+
}
|
|
22
|
+
function listAccountIds(cfg) {
|
|
23
|
+
const ids = listConfiguredAccountIds(cfg);
|
|
24
|
+
if (ids.length === 0) return [DEFAULT_ACCOUNT_ID];
|
|
25
|
+
return ids.toSorted((a, b) => a.localeCompare(b));
|
|
26
|
+
}
|
|
27
|
+
function resolveDefaultAccountId(cfg) {
|
|
28
|
+
const preferred = resolveConfiguredDefaultAccountId(cfg);
|
|
29
|
+
if (preferred) return preferred;
|
|
30
|
+
const ids = listAccountIds(cfg);
|
|
31
|
+
if (ids.includes(DEFAULT_ACCOUNT_ID)) return DEFAULT_ACCOUNT_ID;
|
|
32
|
+
return ids[0] ?? DEFAULT_ACCOUNT_ID;
|
|
33
|
+
}
|
|
34
|
+
return {
|
|
35
|
+
listConfiguredAccountIds,
|
|
36
|
+
listAccountIds,
|
|
37
|
+
resolveDefaultAccountId
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
//#endregion
|
|
42
|
+
//#region src/routing/account-lookup.ts
|
|
43
|
+
function resolveAccountEntry(accounts, accountId) {
|
|
44
|
+
if (!accounts || typeof accounts !== "object") return;
|
|
45
|
+
if (Object.hasOwn(accounts, accountId)) return accounts[accountId];
|
|
46
|
+
const normalized = accountId.toLowerCase();
|
|
47
|
+
const matchKey = Object.keys(accounts).find((key) => key.toLowerCase() === normalized);
|
|
48
|
+
return matchKey ? accounts[matchKey] : void 0;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
//#endregion
|
|
52
|
+
//#region src/web/auth-store.ts
|
|
53
|
+
function resolveDefaultWebAuthDir() {
|
|
54
|
+
return path.join(resolveOAuthDir(), "whatsapp", DEFAULT_ACCOUNT_ID);
|
|
55
|
+
}
|
|
56
|
+
const WA_WEB_AUTH_DIR = resolveDefaultWebAuthDir();
|
|
57
|
+
function resolveWebCredsPath(authDir) {
|
|
58
|
+
return path.join(authDir, "creds.json");
|
|
59
|
+
}
|
|
60
|
+
function resolveWebCredsBackupPath(authDir) {
|
|
61
|
+
return path.join(authDir, "creds.json.bak");
|
|
62
|
+
}
|
|
63
|
+
function hasWebCredsSync(authDir) {
|
|
64
|
+
try {
|
|
65
|
+
const stats = fs.statSync(resolveWebCredsPath(authDir));
|
|
66
|
+
return stats.isFile() && stats.size > 1;
|
|
67
|
+
} catch {
|
|
68
|
+
return false;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
function readCredsJsonRaw(filePath) {
|
|
72
|
+
try {
|
|
73
|
+
if (!fs.existsSync(filePath)) return null;
|
|
74
|
+
const stats = fs.statSync(filePath);
|
|
75
|
+
if (!stats.isFile() || stats.size <= 1) return null;
|
|
76
|
+
return fs.readFileSync(filePath, "utf-8");
|
|
77
|
+
} catch {
|
|
78
|
+
return null;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
function maybeRestoreCredsFromBackup(authDir) {
|
|
82
|
+
const logger = getChildLogger({ module: "web-session" });
|
|
83
|
+
try {
|
|
84
|
+
const credsPath = resolveWebCredsPath(authDir);
|
|
85
|
+
const backupPath = resolveWebCredsBackupPath(authDir);
|
|
86
|
+
const raw = readCredsJsonRaw(credsPath);
|
|
87
|
+
if (raw) {
|
|
88
|
+
JSON.parse(raw);
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
const backupRaw = readCredsJsonRaw(backupPath);
|
|
92
|
+
if (!backupRaw) return;
|
|
93
|
+
JSON.parse(backupRaw);
|
|
94
|
+
fs.copyFileSync(backupPath, credsPath);
|
|
95
|
+
try {
|
|
96
|
+
fs.chmodSync(credsPath, 384);
|
|
97
|
+
} catch {}
|
|
98
|
+
logger.warn({ credsPath }, "restored corrupted WhatsApp creds.json from backup");
|
|
99
|
+
} catch {}
|
|
100
|
+
}
|
|
101
|
+
async function webAuthExists(authDir = resolveDefaultWebAuthDir()) {
|
|
102
|
+
const resolvedAuthDir = resolveUserPath(authDir);
|
|
103
|
+
maybeRestoreCredsFromBackup(resolvedAuthDir);
|
|
104
|
+
const credsPath = resolveWebCredsPath(resolvedAuthDir);
|
|
105
|
+
try {
|
|
106
|
+
await fs$1.access(resolvedAuthDir);
|
|
107
|
+
} catch {
|
|
108
|
+
return false;
|
|
109
|
+
}
|
|
110
|
+
try {
|
|
111
|
+
const stats = await fs$1.stat(credsPath);
|
|
112
|
+
if (!stats.isFile() || stats.size <= 1) return false;
|
|
113
|
+
const raw = await fs$1.readFile(credsPath, "utf-8");
|
|
114
|
+
JSON.parse(raw);
|
|
115
|
+
return true;
|
|
116
|
+
} catch {
|
|
117
|
+
return false;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
async function clearLegacyBaileysAuthState(authDir) {
|
|
121
|
+
const entries = await fs$1.readdir(authDir, { withFileTypes: true });
|
|
122
|
+
const shouldDelete = (name) => {
|
|
123
|
+
if (name === "oauth.json") return false;
|
|
124
|
+
if (name === "creds.json" || name === "creds.json.bak") return true;
|
|
125
|
+
if (!name.endsWith(".json")) return false;
|
|
126
|
+
return /^(app-state-sync|session|sender-key|pre-key)-/.test(name);
|
|
127
|
+
};
|
|
128
|
+
await Promise.all(entries.map(async (entry) => {
|
|
129
|
+
if (!entry.isFile()) return;
|
|
130
|
+
if (!shouldDelete(entry.name)) return;
|
|
131
|
+
await fs$1.rm(path.join(authDir, entry.name), { force: true });
|
|
132
|
+
}));
|
|
133
|
+
}
|
|
134
|
+
async function logoutWeb(params) {
|
|
135
|
+
const runtime = params.runtime ?? defaultRuntime;
|
|
136
|
+
const resolvedAuthDir = resolveUserPath(params.authDir ?? resolveDefaultWebAuthDir());
|
|
137
|
+
if (!await webAuthExists(resolvedAuthDir)) {
|
|
138
|
+
runtime.log(info("No WhatsApp Web session found; nothing to delete."));
|
|
139
|
+
return false;
|
|
140
|
+
}
|
|
141
|
+
if (params.isLegacyAuthDir) await clearLegacyBaileysAuthState(resolvedAuthDir);
|
|
142
|
+
else await fs$1.rm(resolvedAuthDir, {
|
|
143
|
+
recursive: true,
|
|
144
|
+
force: true
|
|
145
|
+
});
|
|
146
|
+
runtime.log(success("Cleared WhatsApp Web credentials."));
|
|
147
|
+
return true;
|
|
148
|
+
}
|
|
149
|
+
function readWebSelfId(authDir = resolveDefaultWebAuthDir()) {
|
|
150
|
+
try {
|
|
151
|
+
const credsPath = resolveWebCredsPath(resolveUserPath(authDir));
|
|
152
|
+
if (!fs.existsSync(credsPath)) return {
|
|
153
|
+
e164: null,
|
|
154
|
+
jid: null
|
|
155
|
+
};
|
|
156
|
+
const raw = fs.readFileSync(credsPath, "utf-8");
|
|
157
|
+
const jid = JSON.parse(raw)?.me?.id ?? null;
|
|
158
|
+
return {
|
|
159
|
+
e164: jid ? jidToE164(jid, { authDir }) : null,
|
|
160
|
+
jid
|
|
161
|
+
};
|
|
162
|
+
} catch {
|
|
163
|
+
return {
|
|
164
|
+
e164: null,
|
|
165
|
+
jid: null
|
|
166
|
+
};
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* Return the age (in milliseconds) of the cached WhatsApp web auth state, or null when missing.
|
|
171
|
+
* Helpful for heartbeats/observability to spot stale credentials.
|
|
172
|
+
*/
|
|
173
|
+
function getWebAuthAgeMs(authDir = resolveDefaultWebAuthDir()) {
|
|
174
|
+
try {
|
|
175
|
+
const stats = fs.statSync(resolveWebCredsPath(resolveUserPath(authDir)));
|
|
176
|
+
return Date.now() - stats.mtimeMs;
|
|
177
|
+
} catch {
|
|
178
|
+
return null;
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
function logWebSelfId(authDir = resolveDefaultWebAuthDir(), runtime = defaultRuntime, includeChannelPrefix = false) {
|
|
182
|
+
const { e164, jid } = readWebSelfId(authDir);
|
|
183
|
+
const details = e164 || jid ? `${e164 ?? "unknown"}${jid ? ` (jid ${jid})` : ""}` : "unknown";
|
|
184
|
+
const prefix = includeChannelPrefix ? "Web Channel: " : "";
|
|
185
|
+
runtime.log(info(`${prefix}${details}`));
|
|
186
|
+
}
|
|
187
|
+
async function pickWebChannel(pref, authDir = resolveDefaultWebAuthDir()) {
|
|
188
|
+
const choice = pref === "auto" ? "web" : pref;
|
|
189
|
+
if (!await webAuthExists(authDir)) throw new Error(`No WhatsApp Web session found. Run \`${formatCliCommand("openclaw channels login --channel whatsapp --verbose")}\` to link.`);
|
|
190
|
+
return choice;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
//#endregion
|
|
194
|
+
//#region src/web/accounts.ts
|
|
195
|
+
const { listConfiguredAccountIds, listAccountIds, resolveDefaultAccountId } = createAccountListHelpers("whatsapp");
|
|
196
|
+
const listWhatsAppAccountIds = listAccountIds;
|
|
197
|
+
const resolveDefaultWhatsAppAccountId = resolveDefaultAccountId;
|
|
198
|
+
function listWhatsAppAuthDirs(cfg) {
|
|
199
|
+
const oauthDir = resolveOAuthDir();
|
|
200
|
+
const whatsappDir = path.join(oauthDir, "whatsapp");
|
|
201
|
+
const authDirs = new Set([oauthDir, path.join(whatsappDir, DEFAULT_ACCOUNT_ID)]);
|
|
202
|
+
const accountIds = listConfiguredAccountIds(cfg);
|
|
203
|
+
for (const accountId of accountIds) authDirs.add(resolveWhatsAppAuthDir({
|
|
204
|
+
cfg,
|
|
205
|
+
accountId
|
|
206
|
+
}).authDir);
|
|
207
|
+
try {
|
|
208
|
+
const entries = fs.readdirSync(whatsappDir, { withFileTypes: true });
|
|
209
|
+
for (const entry of entries) {
|
|
210
|
+
if (!entry.isDirectory()) continue;
|
|
211
|
+
authDirs.add(path.join(whatsappDir, entry.name));
|
|
212
|
+
}
|
|
213
|
+
} catch {}
|
|
214
|
+
return Array.from(authDirs);
|
|
215
|
+
}
|
|
216
|
+
function hasAnyWhatsAppAuth(cfg) {
|
|
217
|
+
return listWhatsAppAuthDirs(cfg).some((authDir) => hasWebCredsSync(authDir));
|
|
218
|
+
}
|
|
219
|
+
function resolveAccountConfig(cfg, accountId) {
|
|
220
|
+
return resolveAccountEntry(cfg.channels?.whatsapp?.accounts, accountId);
|
|
221
|
+
}
|
|
222
|
+
function resolveDefaultAuthDir(accountId) {
|
|
223
|
+
return path.join(resolveOAuthDir(), "whatsapp", normalizeAccountId(accountId));
|
|
224
|
+
}
|
|
225
|
+
function resolveLegacyAuthDir() {
|
|
226
|
+
return resolveOAuthDir();
|
|
227
|
+
}
|
|
228
|
+
function legacyAuthExists(authDir) {
|
|
229
|
+
try {
|
|
230
|
+
return fs.existsSync(path.join(authDir, "creds.json"));
|
|
231
|
+
} catch {
|
|
232
|
+
return false;
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
function resolveWhatsAppAuthDir(params) {
|
|
236
|
+
const accountId = params.accountId.trim() || DEFAULT_ACCOUNT_ID;
|
|
237
|
+
const configured = resolveAccountConfig(params.cfg, accountId)?.authDir?.trim();
|
|
238
|
+
if (configured) return {
|
|
239
|
+
authDir: resolveUserPath(configured),
|
|
240
|
+
isLegacy: false
|
|
241
|
+
};
|
|
242
|
+
const defaultDir = resolveDefaultAuthDir(accountId);
|
|
243
|
+
if (accountId === DEFAULT_ACCOUNT_ID) {
|
|
244
|
+
const legacyDir = resolveLegacyAuthDir();
|
|
245
|
+
if (legacyAuthExists(legacyDir) && !legacyAuthExists(defaultDir)) return {
|
|
246
|
+
authDir: legacyDir,
|
|
247
|
+
isLegacy: true
|
|
248
|
+
};
|
|
249
|
+
}
|
|
250
|
+
return {
|
|
251
|
+
authDir: defaultDir,
|
|
252
|
+
isLegacy: false
|
|
253
|
+
};
|
|
254
|
+
}
|
|
255
|
+
function resolveWhatsAppAccount(params) {
|
|
256
|
+
const rootCfg = params.cfg.channels?.whatsapp;
|
|
257
|
+
const accountId = params.accountId?.trim() || resolveDefaultWhatsAppAccountId(params.cfg);
|
|
258
|
+
const accountCfg = resolveAccountConfig(params.cfg, accountId);
|
|
259
|
+
const enabled = accountCfg?.enabled !== false;
|
|
260
|
+
const { authDir, isLegacy } = resolveWhatsAppAuthDir({
|
|
261
|
+
cfg: params.cfg,
|
|
262
|
+
accountId
|
|
263
|
+
});
|
|
264
|
+
return {
|
|
265
|
+
accountId,
|
|
266
|
+
name: accountCfg?.name?.trim() || void 0,
|
|
267
|
+
enabled,
|
|
268
|
+
sendReadReceipts: accountCfg?.sendReadReceipts ?? rootCfg?.sendReadReceipts ?? true,
|
|
269
|
+
messagePrefix: accountCfg?.messagePrefix ?? rootCfg?.messagePrefix ?? params.cfg.messages?.messagePrefix,
|
|
270
|
+
authDir,
|
|
271
|
+
isLegacyAuthDir: isLegacy,
|
|
272
|
+
selfChatMode: accountCfg?.selfChatMode ?? rootCfg?.selfChatMode,
|
|
273
|
+
dmPolicy: accountCfg?.dmPolicy ?? rootCfg?.dmPolicy,
|
|
274
|
+
allowFrom: accountCfg?.allowFrom ?? rootCfg?.allowFrom,
|
|
275
|
+
groupAllowFrom: accountCfg?.groupAllowFrom ?? rootCfg?.groupAllowFrom,
|
|
276
|
+
groupPolicy: accountCfg?.groupPolicy ?? rootCfg?.groupPolicy,
|
|
277
|
+
textChunkLimit: accountCfg?.textChunkLimit ?? rootCfg?.textChunkLimit,
|
|
278
|
+
chunkMode: accountCfg?.chunkMode ?? rootCfg?.chunkMode,
|
|
279
|
+
mediaMaxMb: accountCfg?.mediaMaxMb ?? rootCfg?.mediaMaxMb,
|
|
280
|
+
blockStreaming: accountCfg?.blockStreaming ?? rootCfg?.blockStreaming,
|
|
281
|
+
ackReaction: accountCfg?.ackReaction ?? rootCfg?.ackReaction,
|
|
282
|
+
groups: accountCfg?.groups ?? rootCfg?.groups,
|
|
283
|
+
debounceMs: accountCfg?.debounceMs ?? rootCfg?.debounceMs
|
|
284
|
+
};
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
//#endregion
|
|
288
|
+
export { webAuthExists as _, resolveWhatsAppAuthDir as a, logWebSelfId as c, pickWebChannel as d, readCredsJsonRaw as f, resolveWebCredsPath as g, resolveWebCredsBackupPath as h, resolveWhatsAppAccount as i, logoutWeb as l, resolveDefaultWebAuthDir as m, listWhatsAppAccountIds as n, WA_WEB_AUTH_DIR as o, readWebSelfId as p, resolveDefaultWhatsAppAccountId as r, getWebAuthAgeMs as s, hasAnyWhatsAppAuth as t, maybeRestoreCredsFromBackup as u, resolveAccountEntry as v, createAccountListHelpers as y };
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { ot as normalizeAccountId } from "./run-with-concurrency-Bt_ks0Qa.js";
|
|
2
|
+
import { v as resolveAccountEntry, y as createAccountListHelpers } from "./accounts-DP1-L-QS.js";
|
|
3
|
+
|
|
4
|
+
//#region src/signal/accounts.ts
|
|
5
|
+
const { listAccountIds, resolveDefaultAccountId } = createAccountListHelpers("signal");
|
|
6
|
+
const listSignalAccountIds = listAccountIds;
|
|
7
|
+
const resolveDefaultSignalAccountId = resolveDefaultAccountId;
|
|
8
|
+
function resolveAccountConfig(cfg, accountId) {
|
|
9
|
+
return resolveAccountEntry(cfg.channels?.signal?.accounts, accountId);
|
|
10
|
+
}
|
|
11
|
+
function mergeSignalAccountConfig(cfg, accountId) {
|
|
12
|
+
const { accounts: _ignored, ...base } = cfg.channels?.signal ?? {};
|
|
13
|
+
const account = resolveAccountConfig(cfg, accountId) ?? {};
|
|
14
|
+
return {
|
|
15
|
+
...base,
|
|
16
|
+
...account
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
function resolveSignalAccount(params) {
|
|
20
|
+
const accountId = normalizeAccountId(params.accountId);
|
|
21
|
+
const baseEnabled = params.cfg.channels?.signal?.enabled !== false;
|
|
22
|
+
const merged = mergeSignalAccountConfig(params.cfg, accountId);
|
|
23
|
+
const accountEnabled = merged.enabled !== false;
|
|
24
|
+
const enabled = baseEnabled && accountEnabled;
|
|
25
|
+
const host = merged.httpHost?.trim() || "127.0.0.1";
|
|
26
|
+
const port = merged.httpPort ?? 8080;
|
|
27
|
+
const baseUrl = merged.httpUrl?.trim() || `http://${host}:${port}`;
|
|
28
|
+
const configured = Boolean(merged.account?.trim() || merged.httpUrl?.trim() || merged.cliPath?.trim() || merged.httpHost?.trim() || typeof merged.httpPort === "number" || typeof merged.autoStart === "boolean");
|
|
29
|
+
return {
|
|
30
|
+
accountId,
|
|
31
|
+
enabled,
|
|
32
|
+
name: merged.name?.trim() || void 0,
|
|
33
|
+
baseUrl,
|
|
34
|
+
configured,
|
|
35
|
+
config: merged
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
function listEnabledSignalAccounts(cfg) {
|
|
39
|
+
return listSignalAccountIds(cfg).map((accountId) => resolveSignalAccount({
|
|
40
|
+
cfg,
|
|
41
|
+
accountId
|
|
42
|
+
})).filter((account) => account.enabled);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
//#endregion
|
|
46
|
+
export { resolveSignalAccount as i, listSignalAccountIds as n, resolveDefaultSignalAccountId as r, listEnabledSignalAccounts as t };
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { at as DEFAULT_ACCOUNT_ID } from "./run-with-concurrency-Bt_ks0Qa.js";
|
|
2
|
+
import { Pr as formatCliCommand } from "./config-BkEnz2Po.js";
|
|
3
|
+
import crypto from "node:crypto";
|
|
4
|
+
|
|
5
|
+
//#region src/logging/redact-identifier.ts
|
|
6
|
+
function sha256HexPrefix(value, len = 12) {
|
|
7
|
+
const safeLen = Number.isFinite(len) ? Math.max(1, Math.floor(len)) : 12;
|
|
8
|
+
return crypto.createHash("sha256").update(value).digest("hex").slice(0, safeLen);
|
|
9
|
+
}
|
|
10
|
+
function redactIdentifier(value, opts) {
|
|
11
|
+
const trimmed = value?.trim();
|
|
12
|
+
if (!trimmed) return "-";
|
|
13
|
+
return `sha256:${sha256HexPrefix(trimmed, opts?.len ?? 12)}`;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
//#endregion
|
|
17
|
+
//#region src/web/active-listener.ts
|
|
18
|
+
const listeners = /* @__PURE__ */ new Map();
|
|
19
|
+
function resolveWebAccountId(accountId) {
|
|
20
|
+
return (accountId ?? "").trim() || DEFAULT_ACCOUNT_ID;
|
|
21
|
+
}
|
|
22
|
+
function requireActiveWebListener(accountId) {
|
|
23
|
+
const id = resolveWebAccountId(accountId);
|
|
24
|
+
const listener = listeners.get(id) ?? null;
|
|
25
|
+
if (!listener) throw new Error(`No active WhatsApp Web listener (account: ${id}). Start the gateway, then link WhatsApp with: ${formatCliCommand(`openclaw channels login --channel whatsapp --account ${id}`)}.`);
|
|
26
|
+
return {
|
|
27
|
+
accountId: id,
|
|
28
|
+
listener
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
function setActiveWebListener(accountIdOrListener, maybeListener) {
|
|
32
|
+
const { accountId, listener } = typeof accountIdOrListener === "string" ? {
|
|
33
|
+
accountId: accountIdOrListener,
|
|
34
|
+
listener: maybeListener ?? null
|
|
35
|
+
} : {
|
|
36
|
+
accountId: DEFAULT_ACCOUNT_ID,
|
|
37
|
+
listener: accountIdOrListener ?? null
|
|
38
|
+
};
|
|
39
|
+
const id = resolveWebAccountId(accountId);
|
|
40
|
+
if (!listener) listeners.delete(id);
|
|
41
|
+
else listeners.set(id, listener);
|
|
42
|
+
if (id === DEFAULT_ACCOUNT_ID) {}
|
|
43
|
+
}
|
|
44
|
+
function getActiveWebListener(accountId) {
|
|
45
|
+
const id = resolveWebAccountId(accountId);
|
|
46
|
+
return listeners.get(id) ?? null;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
//#endregion
|
|
50
|
+
export { redactIdentifier as i, requireActiveWebListener as n, setActiveWebListener as r, getActiveWebListener as t };
|
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
import { jn as normalizeProviderId } from "./config-BkEnz2Po.js";
|
|
2
|
+
import { r as formatErrorMessage } from "./errors-DaiAM-yU.js";
|
|
3
|
+
|
|
4
|
+
//#region src/infra/gemini-auth.ts
|
|
5
|
+
/**
|
|
6
|
+
* Shared Gemini authentication utilities.
|
|
7
|
+
*
|
|
8
|
+
* Supports both traditional API keys and OAuth JSON format.
|
|
9
|
+
*/
|
|
10
|
+
/**
|
|
11
|
+
* Parse Gemini API key and return appropriate auth headers.
|
|
12
|
+
*
|
|
13
|
+
* OAuth format: `{"token": "...", "projectId": "..."}`
|
|
14
|
+
*
|
|
15
|
+
* @param apiKey - Either a traditional API key string or OAuth JSON
|
|
16
|
+
* @returns Headers object with appropriate authentication
|
|
17
|
+
*/
|
|
18
|
+
function parseGeminiAuth(apiKey) {
|
|
19
|
+
if (apiKey.startsWith("{")) try {
|
|
20
|
+
const parsed = JSON.parse(apiKey);
|
|
21
|
+
if (typeof parsed.token === "string" && parsed.token) return { headers: {
|
|
22
|
+
Authorization: `Bearer ${parsed.token}`,
|
|
23
|
+
"Content-Type": "application/json"
|
|
24
|
+
} };
|
|
25
|
+
} catch {}
|
|
26
|
+
return { headers: {
|
|
27
|
+
"x-goog-api-key": apiKey,
|
|
28
|
+
"Content-Type": "application/json"
|
|
29
|
+
} };
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
//#endregion
|
|
33
|
+
//#region src/agents/live-auth-keys.ts
|
|
34
|
+
const KEY_SPLIT_RE = /[\s,;]+/g;
|
|
35
|
+
const GOOGLE_LIVE_SINGLE_KEY = "OPENCLAW_LIVE_GEMINI_KEY";
|
|
36
|
+
const PROVIDER_PREFIX_OVERRIDES = {
|
|
37
|
+
google: "GEMINI",
|
|
38
|
+
"google-vertex": "GEMINI"
|
|
39
|
+
};
|
|
40
|
+
const PROVIDER_API_KEY_CONFIG = {
|
|
41
|
+
anthropic: {
|
|
42
|
+
liveSingle: "OPENCLAW_LIVE_ANTHROPIC_KEY",
|
|
43
|
+
listVar: "OPENCLAW_LIVE_ANTHROPIC_KEYS",
|
|
44
|
+
primaryVar: "ANTHROPIC_API_KEY",
|
|
45
|
+
prefixedVar: "ANTHROPIC_API_KEY_"
|
|
46
|
+
},
|
|
47
|
+
google: {
|
|
48
|
+
liveSingle: GOOGLE_LIVE_SINGLE_KEY,
|
|
49
|
+
listVar: "GEMINI_API_KEYS",
|
|
50
|
+
primaryVar: "GEMINI_API_KEY",
|
|
51
|
+
prefixedVar: "GEMINI_API_KEY_"
|
|
52
|
+
},
|
|
53
|
+
"google-vertex": {
|
|
54
|
+
liveSingle: GOOGLE_LIVE_SINGLE_KEY,
|
|
55
|
+
listVar: "GEMINI_API_KEYS",
|
|
56
|
+
primaryVar: "GEMINI_API_KEY",
|
|
57
|
+
prefixedVar: "GEMINI_API_KEY_"
|
|
58
|
+
},
|
|
59
|
+
openai: {
|
|
60
|
+
liveSingle: "OPENCLAW_LIVE_OPENAI_KEY",
|
|
61
|
+
listVar: "OPENAI_API_KEYS",
|
|
62
|
+
primaryVar: "OPENAI_API_KEY",
|
|
63
|
+
prefixedVar: "OPENAI_API_KEY_"
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
function parseKeyList(raw) {
|
|
67
|
+
if (!raw) return [];
|
|
68
|
+
return raw.split(KEY_SPLIT_RE).map((value) => value.trim()).filter(Boolean);
|
|
69
|
+
}
|
|
70
|
+
function collectEnvPrefixedKeys(prefix) {
|
|
71
|
+
const keys = [];
|
|
72
|
+
for (const [name, value] of Object.entries(process.env)) {
|
|
73
|
+
if (!name.startsWith(prefix)) continue;
|
|
74
|
+
const trimmed = value?.trim();
|
|
75
|
+
if (!trimmed) continue;
|
|
76
|
+
keys.push(trimmed);
|
|
77
|
+
}
|
|
78
|
+
return keys;
|
|
79
|
+
}
|
|
80
|
+
function resolveProviderApiKeyConfig(provider) {
|
|
81
|
+
const normalized = normalizeProviderId(provider);
|
|
82
|
+
const custom = PROVIDER_API_KEY_CONFIG[normalized];
|
|
83
|
+
const base = PROVIDER_PREFIX_OVERRIDES[normalized] ?? normalized.toUpperCase().replace(/-/g, "_");
|
|
84
|
+
const liveSingle = custom?.liveSingle ?? `OPENCLAW_LIVE_${base}_KEY`;
|
|
85
|
+
const listVar = custom?.listVar ?? `${base}_API_KEYS`;
|
|
86
|
+
const primaryVar = custom?.primaryVar ?? `${base}_API_KEY`;
|
|
87
|
+
const prefixedVar = custom?.prefixedVar ?? `${base}_API_KEY_`;
|
|
88
|
+
if (normalized === "google" || normalized === "google-vertex") return {
|
|
89
|
+
liveSingle,
|
|
90
|
+
listVar,
|
|
91
|
+
primaryVar,
|
|
92
|
+
prefixedVar,
|
|
93
|
+
fallbackVars: ["GOOGLE_API_KEY"]
|
|
94
|
+
};
|
|
95
|
+
return {
|
|
96
|
+
liveSingle,
|
|
97
|
+
listVar,
|
|
98
|
+
primaryVar,
|
|
99
|
+
prefixedVar,
|
|
100
|
+
fallbackVars: []
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
function collectProviderApiKeys(provider) {
|
|
104
|
+
const config = resolveProviderApiKeyConfig(provider);
|
|
105
|
+
const forcedSingle = config.liveSingle ? process.env[config.liveSingle]?.trim() : void 0;
|
|
106
|
+
if (forcedSingle) return [forcedSingle];
|
|
107
|
+
const fromList = parseKeyList(config.listVar ? process.env[config.listVar] : void 0);
|
|
108
|
+
const primary = config.primaryVar ? process.env[config.primaryVar]?.trim() : void 0;
|
|
109
|
+
const fromPrefixed = config.prefixedVar ? collectEnvPrefixedKeys(config.prefixedVar) : [];
|
|
110
|
+
const fallback = config.fallbackVars.map((envVar) => process.env[envVar]?.trim()).filter(Boolean);
|
|
111
|
+
const seen = /* @__PURE__ */ new Set();
|
|
112
|
+
const add = (value) => {
|
|
113
|
+
if (!value) return;
|
|
114
|
+
if (seen.has(value)) return;
|
|
115
|
+
seen.add(value);
|
|
116
|
+
};
|
|
117
|
+
for (const value of fromList) add(value);
|
|
118
|
+
add(primary);
|
|
119
|
+
for (const value of fromPrefixed) add(value);
|
|
120
|
+
for (const value of fallback) add(value);
|
|
121
|
+
return Array.from(seen);
|
|
122
|
+
}
|
|
123
|
+
function isApiKeyRateLimitError(message) {
|
|
124
|
+
const lower = message.toLowerCase();
|
|
125
|
+
if (lower.includes("rate_limit")) return true;
|
|
126
|
+
if (lower.includes("rate limit")) return true;
|
|
127
|
+
if (lower.includes("429")) return true;
|
|
128
|
+
if (lower.includes("quota exceeded") || lower.includes("quota_exceeded")) return true;
|
|
129
|
+
if (lower.includes("resource exhausted") || lower.includes("resource_exhausted")) return true;
|
|
130
|
+
if (lower.includes("too many requests")) return true;
|
|
131
|
+
return false;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
//#endregion
|
|
135
|
+
//#region src/agents/api-key-rotation.ts
|
|
136
|
+
function dedupeApiKeys(raw) {
|
|
137
|
+
const seen = /* @__PURE__ */ new Set();
|
|
138
|
+
const keys = [];
|
|
139
|
+
for (const value of raw) {
|
|
140
|
+
const apiKey = value.trim();
|
|
141
|
+
if (!apiKey || seen.has(apiKey)) continue;
|
|
142
|
+
seen.add(apiKey);
|
|
143
|
+
keys.push(apiKey);
|
|
144
|
+
}
|
|
145
|
+
return keys;
|
|
146
|
+
}
|
|
147
|
+
function collectProviderApiKeysForExecution(params) {
|
|
148
|
+
const { primaryApiKey, provider } = params;
|
|
149
|
+
return dedupeApiKeys([primaryApiKey?.trim() ?? "", ...collectProviderApiKeys(provider)]);
|
|
150
|
+
}
|
|
151
|
+
async function executeWithApiKeyRotation(params) {
|
|
152
|
+
const keys = dedupeApiKeys(params.apiKeys);
|
|
153
|
+
if (keys.length === 0) throw new Error(`No API keys configured for provider "${params.provider}".`);
|
|
154
|
+
let lastError;
|
|
155
|
+
for (let attempt = 0; attempt < keys.length; attempt += 1) {
|
|
156
|
+
const apiKey = keys[attempt];
|
|
157
|
+
try {
|
|
158
|
+
return await params.execute(apiKey);
|
|
159
|
+
} catch (error) {
|
|
160
|
+
lastError = error;
|
|
161
|
+
const message = formatErrorMessage(error);
|
|
162
|
+
if (!(params.shouldRetry ? params.shouldRetry({
|
|
163
|
+
apiKey,
|
|
164
|
+
error,
|
|
165
|
+
attempt,
|
|
166
|
+
message
|
|
167
|
+
}) : isApiKeyRateLimitError(message)) || attempt + 1 >= keys.length) break;
|
|
168
|
+
params.onRetry?.({
|
|
169
|
+
apiKey,
|
|
170
|
+
error,
|
|
171
|
+
attempt,
|
|
172
|
+
message
|
|
173
|
+
});
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
if (lastError === void 0) throw new Error(`Failed to run API request for ${params.provider}.`);
|
|
177
|
+
throw lastError;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
//#endregion
|
|
181
|
+
export { executeWithApiKeyRotation as n, parseGeminiAuth as r, collectProviderApiKeysForExecution as t };
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import "./run-with-concurrency-Bt_ks0Qa.js";
|
|
2
|
+
import "./accounts-DP1-L-QS.js";
|
|
3
|
+
import "./paths-MKyEVmEb.js";
|
|
4
|
+
import "./github-copilot-token-D5fdS6xD.js";
|
|
5
|
+
import "./config-BkEnz2Po.js";
|
|
6
|
+
import { L as logVerbose, z as shouldLogVerbose } from "./logger-CZY9KIoY.js";
|
|
7
|
+
import "./thinking-Bo2eosVa.js";
|
|
8
|
+
import "./image-ops-BSiMpAw4.js";
|
|
9
|
+
import "./pi-embedded-helpers-1R1gu7eX.js";
|
|
10
|
+
import "./plugins-DeBZB9l_.js";
|
|
11
|
+
import "./accounts-CJWOBzwB.js";
|
|
12
|
+
import "./accounts-DZhWlEg3.js";
|
|
13
|
+
import "./paths-vTM3Lh3X.js";
|
|
14
|
+
import "./redact-DjVX-1N3.js";
|
|
15
|
+
import "./errors-DaiAM-yU.js";
|
|
16
|
+
import "./path-alias-guards-DBjLbIX_.js";
|
|
17
|
+
import "./fs-safe-B8y811FR.js";
|
|
18
|
+
import "./ssrf-cFtplYtS.js";
|
|
19
|
+
import "./fetch-guard-DETCcJzQ.js";
|
|
20
|
+
import "./local-roots-BUP4YBmR.js";
|
|
21
|
+
import "./tool-images-Gk_-0y2N.js";
|
|
22
|
+
import { f as isAudioAttachment, i as normalizeMediaAttachments, o as resolveMediaAttachmentLocalRoots, t as runAudioTranscription } from "./audio-transcription-runner-DkoPNPYt.js";
|
|
23
|
+
import "./skills-CBkHBYPq.js";
|
|
24
|
+
import "./chrome-BXoCyCkY.js";
|
|
25
|
+
import "./store-5nyxY3WU.js";
|
|
26
|
+
import "./image-DjTEkYZE.js";
|
|
27
|
+
import "./api-key-rotation-BRE4X2tf.js";
|
|
28
|
+
import "./proxy-fetch-ChxOhWF4.js";
|
|
29
|
+
|
|
30
|
+
//#region src/media-understanding/audio-preflight.ts
|
|
31
|
+
/**
|
|
32
|
+
* Transcribes the first audio attachment BEFORE mention checking.
|
|
33
|
+
* This allows voice notes to be processed in group chats with requireMention: true.
|
|
34
|
+
* Returns the transcript or undefined if transcription fails or no audio is found.
|
|
35
|
+
*/
|
|
36
|
+
async function transcribeFirstAudio(params) {
|
|
37
|
+
const { ctx, cfg } = params;
|
|
38
|
+
const audioConfig = cfg.tools?.media?.audio;
|
|
39
|
+
if (!audioConfig || audioConfig.enabled === false) return;
|
|
40
|
+
const attachments = normalizeMediaAttachments(ctx);
|
|
41
|
+
if (!attachments || attachments.length === 0) return;
|
|
42
|
+
const firstAudio = attachments.find((att) => att && isAudioAttachment(att) && !att.alreadyTranscribed);
|
|
43
|
+
if (!firstAudio) return;
|
|
44
|
+
if (shouldLogVerbose()) logVerbose(`audio-preflight: transcribing attachment ${firstAudio.index} for mention check`);
|
|
45
|
+
try {
|
|
46
|
+
const { transcript } = await runAudioTranscription({
|
|
47
|
+
ctx,
|
|
48
|
+
cfg,
|
|
49
|
+
attachments,
|
|
50
|
+
agentDir: params.agentDir,
|
|
51
|
+
providers: params.providers,
|
|
52
|
+
activeModel: params.activeModel,
|
|
53
|
+
localPathRoots: resolveMediaAttachmentLocalRoots({
|
|
54
|
+
cfg,
|
|
55
|
+
ctx
|
|
56
|
+
})
|
|
57
|
+
});
|
|
58
|
+
if (!transcript) return;
|
|
59
|
+
firstAudio.alreadyTranscribed = true;
|
|
60
|
+
if (shouldLogVerbose()) logVerbose(`audio-preflight: transcribed ${transcript.length} chars from attachment ${firstAudio.index}`);
|
|
61
|
+
return transcript;
|
|
62
|
+
} catch (err) {
|
|
63
|
+
if (shouldLogVerbose()) logVerbose(`audio-preflight: transcription failed: ${String(err)}`);
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
//#endregion
|
|
69
|
+
export { transcribeFirstAudio };
|