levix-bot 4.9.1 → 5.0.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 +57 -3
- package/SETUP.md +63 -7
- package/app.cjs +159 -46
- package/deploy/install.sh +10 -5
- package/package.json +9 -6
- package/public/dashboard/assets/40af6d88b63079a0-BZ8ojJNu.woff2 +0 -0
- package/public/dashboard/assets/481acf6760031cee-BypgxfGb.woff2 +0 -0
- package/public/dashboard/assets/6d3351fc535f8ef3-D2-eand5.woff2 +0 -0
- package/public/dashboard/assets/8ab0af53a3bda9d3-CyCXRvzh.woff2 +0 -0
- package/public/dashboard/assets/8f262393e9249e61-TQp-UTiE.woff2 +0 -0
- package/public/dashboard/assets/94d65887a83f1282-DmpS2jIq.woff2 +0 -0
- package/public/dashboard/assets/99e400330f36ae77-D3oMJlXt.woff2 +0 -0
- package/public/dashboard/assets/9d1f41b13e519d90-BVNSOH3d.woff2 +0 -0
- package/public/dashboard/assets/a005256cb957ecc7-CoYeBiSI.woff2 +0 -0
- package/public/dashboard/assets/b19c2080652a3c2b-DIC32ArD.woff2 +0 -0
- package/public/dashboard/assets/c4064400db3750ce-BehTv68k.woff2 +0 -0
- package/public/dashboard/assets/c69d345fa1068c2d-CmI34b-g.woff2 +0 -0
- package/public/dashboard/assets/cc27b30471250057-6fWv1k7M.woff2 +0 -0
- package/public/dashboard/assets/d8c30647abfeffe6-eXO_dkmS.woff2 +0 -0
- package/public/dashboard/assets/eb83d8d40af4411f-Buze_B52.woff2 +0 -0
- package/public/dashboard/assets/effc6711249e7349-qRpaaN48.woff2 +0 -0
- package/public/dashboard/assets/gateway-BDYet0pI.css +1 -0
- package/public/dashboard/assets/gateway-BYt6-s1O.js +1 -0
- package/public/dashboard/assets/index-B9wFpD_z.css +2 -0
- package/public/dashboard/assets/index-DWcQmu0_.js +124 -0
- package/public/dashboard/assets/index-Da-j89O-.js +458 -0
- package/public/dashboard/font-licenses/jetbrainsmono-OFL.txt +93 -0
- package/public/dashboard/font-licenses/plusjakartasans-OFL.txt +93 -0
- package/public/dashboard/font-licenses/tajawal-OFL.txt +93 -0
- package/public/dashboard/gateway.html +17 -0
- package/public/dashboard/index.html +3 -5
- package/public/ui-boot.js +33 -14
- package/scheduler.cjs +76 -23
- package/src/auth/auth-storage.cjs +54 -7
- package/src/auth/use-database-auth-state.js +70 -39
- package/src/automation/engine.js +412 -0
- package/src/automation/limits.cjs +6 -0
- package/src/automation/manage.js +290 -0
- package/src/automation/reactions.js +471 -0
- package/src/automation/rules.cjs +114 -0
- package/src/automation/status.cjs +76 -0
- package/src/backup/account.cjs +29 -0
- package/src/backup/activation.cjs +247 -0
- package/src/backup/content.cjs +36 -0
- package/src/backup/create.cjs +280 -0
- package/src/backup/extensions.cjs +101 -0
- package/src/backup/format.cjs +565 -0
- package/src/backup/jobs.cjs +111 -0
- package/src/backup/journal.cjs +41 -0
- package/src/backup/plan.cjs +223 -0
- package/src/backup/recovery.cjs +110 -0
- package/src/backup/restore.cjs +460 -0
- package/src/backup/uploads.cjs +146 -0
- package/src/bootstrap/core.js +50 -12
- package/src/bootstrap/panel.js +53 -2
- package/src/bootstrap/session-startup-policy.js +8 -1
- package/src/cli.js +163 -22
- package/src/commands/autodelete.cjs +41 -57
- package/src/commands/autoschedule.cjs +7 -33
- package/src/commands/blacklist.cjs +17 -35
- package/src/commands/block.cjs +4 -18
- package/src/commands/calc.cjs +22 -74
- package/src/commands/debt.cjs +28 -59
- package/src/commands/deleteschedule.cjs +7 -23
- package/src/commands/digit.cjs +5 -39
- package/src/commands/gemini.cjs +135 -218
- package/src/commands/group/add.cjs +28 -76
- package/src/commands/group/all.cjs +4 -15
- package/src/commands/group/antilink.cjs +28 -41
- package/src/commands/group/antispam.cjs +25 -35
- package/src/commands/group/approveall.cjs +7 -21
- package/src/commands/group/clearwarns.cjs +4 -18
- package/src/commands/group/deletenote.cjs +4 -18
- package/src/commands/group/demote.cjs +6 -23
- package/src/commands/group/flagged.cjs +10 -19
- package/src/commands/group/kick.cjs +26 -36
- package/src/commands/group/media.cjs +21 -36
- package/src/commands/group/members.cjs +16 -28
- package/src/commands/group/note.cjs +3 -14
- package/src/commands/group/policy.cjs +16 -37
- package/src/commands/group/promote.cjs +5 -22
- package/src/commands/group/removeall.cjs +6 -38
- package/src/commands/group/rules.cjs +4 -19
- package/src/commands/group/save.cjs +4 -18
- package/src/commands/group/setname.cjs +5 -19
- package/src/commands/group/setpp.cjs +8 -26
- package/src/commands/group/setrules.cjs +4 -15
- package/src/commands/group/setwarn.cjs +6 -23
- package/src/commands/group/tagadmins.cjs +5 -16
- package/src/commands/group/warn.cjs +5 -16
- package/src/commands/group/warns.cjs +12 -33
- package/src/commands/group/welcome.cjs +17 -34
- package/src/commands/group.cjs +91 -68
- package/src/commands/help.cjs +48 -89
- package/src/commands/lang.cjs +38 -97
- package/src/commands/listschedules.cjs +19 -30
- package/src/commands/loop.cjs +9 -55
- package/src/commands/md.cjs +2 -13
- package/src/commands/memory.cjs +53 -87
- package/src/commands/mod.cjs +40 -79
- package/src/commands/notes.cjs +4 -15
- package/src/commands/pack.cjs +26 -49
- package/src/commands/packs.cjs +8 -18
- package/src/commands/perm.cjs +48 -51
- package/src/commands/ping.cjs +2 -10
- package/src/commands/poll.cjs +5 -38
- package/src/commands/prayer.cjs +55 -36
- package/src/commands/qr.cjs +4 -18
- package/src/commands/rand.cjs +9 -58
- package/src/commands/restart.cjs +15 -33
- package/src/commands/schedule.cjs +5 -25
- package/src/commands/score.cjs +6 -27
- package/src/commands/send.cjs +4 -18
- package/src/commands/setprefix.cjs +11 -23
- package/src/commands/shortlink.cjs +13 -39
- package/src/commands/status.cjs +188 -76
- package/src/commands/sticker.cjs +5 -16
- package/src/commands/stickers.cjs +16 -20
- package/src/commands/stopbot.cjs +9 -25
- package/src/commands/stt.cjs +75 -107
- package/src/commands/todo.cjs +11 -31
- package/src/commands/toimage.cjs +11 -27
- package/src/commands/translate.cjs +53 -36
- package/src/commands/tts.cjs +46 -40
- package/src/commands/unblock.cjs +3 -17
- package/src/commands/update.cjs +23 -0
- package/src/commands/weather.cjs +40 -47
- package/src/config/ai-identity.cjs +14 -1
- package/src/config/baileys.config.js +16 -3
- package/src/config/data-dir.cjs +37 -0
- package/src/config/defaults.cjs +1 -0
- package/src/config/exit-codes.cjs +11 -0
- package/src/config/lock.cjs +55 -81
- package/src/config/official-links.cjs +61 -0
- package/src/config/paths.cjs +4 -33
- package/src/config/release.cjs +87 -0
- package/src/config/settings.cjs +199 -10
- package/src/core/connection.js +77 -9
- package/src/core/events.js +119 -33
- package/src/core/session.js +536 -84
- package/src/core/socket.js +81 -10
- package/src/db/copy.cjs +136 -0
- package/src/db/db.cjs +241 -36
- package/src/db/startup-guard.js +5 -0
- package/src/db/store.cjs +561 -54
- package/src/diagnostics/baileysLog.cjs +87 -0
- package/src/diagnostics/debugLog.cjs +16 -4
- package/src/diagnostics/device.cjs +4 -2
- package/src/diagnostics/nodeRuntime.cjs +131 -0
- package/src/diagnostics/signalSessionInspect.cjs +38 -0
- package/src/domain/command.js +24 -22
- package/src/extensions/autoReply.cjs +521 -0
- package/src/extensions/context.cjs +73 -0
- package/src/extensions/contract.cjs +69 -0
- package/src/extensions/entitlement/client.cjs +381 -0
- package/src/extensions/entitlement/index.cjs +629 -0
- package/src/extensions/entitlement/installation.cjs +117 -0
- package/src/extensions/entitlement/keys.cjs +72 -0
- package/src/extensions/entitlement/state.cjs +201 -0
- package/src/extensions/entitlement/target.cjs +7 -0
- package/src/extensions/entitlement/token.cjs +225 -0
- package/src/extensions/host.cjs +519 -0
- package/src/extensions/templateKeys.cjs +81 -0
- package/src/handlers/command.handler.js +191 -64
- package/src/handlers/group.handler.js +78 -18
- package/src/handlers/message.handler.js +56 -25
- package/src/i18n/catalog.generated.cjs +3537 -0
- package/src/index.js +51 -12
- package/src/legal/bundled/ar.json +102 -0
- package/src/legal/bundled/en.json +102 -0
- package/src/legal/bundled/es-419.json +102 -0
- package/src/legal/bundled/pt-BR.json +102 -0
- package/src/legal/cli.cjs +200 -0
- package/src/legal/consent.cjs +187 -0
- package/src/legal/document.cjs +156 -0
- package/src/legal/keys.cjs +100 -0
- package/src/legal/release.cjs +226 -0
- package/src/legal/remote.cjs +419 -0
- package/src/legal/terms.cjs +142 -0
- package/src/messaging/escape.cjs +31 -0
- package/src/messaging/health.cjs +65 -0
- package/src/messaging/identity.cjs +42 -0
- package/src/messaging/message.cjs +136 -0
- package/src/messaging/parser.cjs +88 -0
- package/src/messaging/router.cjs +217 -0
- package/src/middleware/permissions.middleware.js +34 -2
- package/src/panel/account-profile.cjs +489 -0
- package/src/panel/fallback-page.cjs +177 -0
- package/src/panel/password-reset.cjs +13 -14
- package/src/panel/recovery-email.cjs +3 -1
- package/src/routes/backup.api.esm.js +175 -0
- package/src/routes/dashboard.api.esm.js +183 -7
- package/src/routes/plus.api.esm.js +172 -0
- package/src/routes/reactions.api.esm.js +60 -0
- package/src/services/aiAgent.cjs +56 -43
- package/src/services/aiDocs.cjs +187 -0
- package/src/services/aiImage.cjs +183 -0
- package/src/services/aiMedia.cjs +146 -0
- package/src/services/aiProviders.cjs +76 -80
- package/src/services/aiRouter.cjs +2 -2
- package/src/services/aiToolAuth.cjs +76 -4
- package/src/services/aiTools.cjs +431 -105
- package/src/services/autoDelete.cjs +9 -1
- package/src/services/levix-docs.generated.json +2623 -0
- package/src/services/memoryPolicy.cjs +56 -0
- package/src/services/updateCheck.cjs +362 -0
- package/src/stickers/errors.cjs +53 -97
- package/src/stickers/library.cjs +13 -6
- package/src/stickers/owner.cjs +1 -1
- package/src/utils/commandContext.cjs +13 -0
- package/src/utils/commandDocs.cjs +42 -20
- package/src/utils/geminiHttpOptions.cjs +56 -0
- package/src/utils/geminiMedia.cjs +28 -3
- package/src/utils/groupMetadataCache.cjs +386 -21
- package/src/utils/httpsFetch.cjs +113 -0
- package/src/utils/i18n.cjs +117 -7
- package/src/utils/linkPreview.cjs +90 -0
- package/src/utils/logger.cjs +6 -0
- package/src/utils/markdownParser.cjs +3 -3
- package/src/utils/memory.cjs +375 -28
- package/src/utils/messageContent.cjs +7 -1
- package/src/utils/moderationAction.cjs +116 -73
- package/src/utils/moderationSummary.cjs +32 -56
- package/src/utils/permissionLevel.cjs +7 -28
- package/src/utils/permissions.cjs +23 -14
- package/src/utils/permissions.esm.js +99 -166
- package/src/utils/recentMessageCache.esm.js +241 -37
- package/src/utils/recurrence.cjs +78 -66
- package/src/utils/sendBotMessage.cjs +14 -29
- package/src/utils/sendBotMessage.esm.js +28 -13
- package/src/utils/statusMessage.cjs +94 -33
- package/src/utils/stickerBot.cjs +18 -16
- package/src/utils/storage.cjs +2 -0
- package/src/utils/storage.esm.js +2 -0
- package/src/utils/thumbnail.cjs +5 -21
- package/public/dashboard/assets/index-B1sOW2VX.js +0 -561
- package/public/dashboard/assets/index-CK8osB4o.css +0 -2
- package/public/dashboard.css +0 -3127
- package/public/dashboard.js +0 -1981
- package/public/gateway-i18n.js +0 -321
- package/public/gateway.js +0 -70
- package/views/dashboard.ejs +0 -775
- package/views/login.ejs +0 -408
- package/views/qr.ejs +0 -155
- package/views/setup.ejs +0 -118
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
// Dedicated Gemini image generation shared by !generate.
|
|
2
|
+
// Chat stays on ai_provider. This path always uses the image key, base URL,
|
|
3
|
+
// and gemini_image_model. Failures are fixed codes: no credentials, no
|
|
4
|
+
// provider body, and no image URL.
|
|
5
|
+
|
|
6
|
+
const { GoogleGenAI } = require("@google/genai");
|
|
7
|
+
|
|
8
|
+
const settings = require("../config/settings.cjs");
|
|
9
|
+
const { assertProviderBaseUrl, assertProviderRequestUrl } = require("../utils/providerUrl.cjs");
|
|
10
|
+
|
|
11
|
+
const MAX_PROMPT = 3000;
|
|
12
|
+
const MAX_IMAGE_BYTES = 8 * 1024 * 1024;
|
|
13
|
+
const REQUEST_TIMEOUT_MS = 60000;
|
|
14
|
+
|
|
15
|
+
const PNG = Buffer.from([0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a]);
|
|
16
|
+
const JPEG = Buffer.from([0xff, 0xd8, 0xff]);
|
|
17
|
+
|
|
18
|
+
let cache = { key: null, baseUrl: null, client: null };
|
|
19
|
+
|
|
20
|
+
function fail(code) {
|
|
21
|
+
const err = new Error(code);
|
|
22
|
+
err.code = code;
|
|
23
|
+
return err;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function aborted() {
|
|
27
|
+
const err = new Error("aborted");
|
|
28
|
+
err.name = "AbortError";
|
|
29
|
+
err.code = "ABORT";
|
|
30
|
+
return err;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function isAbort(err, signal) {
|
|
34
|
+
return Boolean(signal?.aborted || err?.name === "AbortError" || err?.code === "ABORT");
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function isQuota(err) {
|
|
38
|
+
const status = Number(err?.status || err?.statusCode);
|
|
39
|
+
if (status === 429 || err?.code === "IMAGE_QUOTA") return true;
|
|
40
|
+
return /quota|RESOURCE_EXHAUSTED/i.test(String(err?.message || ""));
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function declaredMime(mime) {
|
|
44
|
+
const bare = String(mime || "")
|
|
45
|
+
.split(";")[0]
|
|
46
|
+
.trim()
|
|
47
|
+
.toLowerCase();
|
|
48
|
+
if (bare === "image/png") return "image/png";
|
|
49
|
+
if (bare === "image/jpeg" || bare === "image/jpg") return "image/jpeg";
|
|
50
|
+
if (bare === "image/webp") return "image/webp";
|
|
51
|
+
return null;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function headerMime(buf) {
|
|
55
|
+
if (
|
|
56
|
+
buf.length >= 45 &&
|
|
57
|
+
buf.subarray(0, PNG.length).equals(PNG) &&
|
|
58
|
+
buf.readUInt32BE(8) === 13 &&
|
|
59
|
+
buf.toString("ascii", 12, 16) === "IHDR" &&
|
|
60
|
+
buf.toString("ascii", buf.length - 8, buf.length - 4) === "IEND" &&
|
|
61
|
+
buf.readUInt32BE(16) > 0 &&
|
|
62
|
+
buf.readUInt32BE(20) > 0 &&
|
|
63
|
+
buf.readUInt32BE(16) * buf.readUInt32BE(20) <= 64_000_000
|
|
64
|
+
)
|
|
65
|
+
return "image/png";
|
|
66
|
+
if (
|
|
67
|
+
buf.length >= 16 &&
|
|
68
|
+
buf.subarray(0, JPEG.length).equals(JPEG) &&
|
|
69
|
+
buf.subarray(-2).equals(Buffer.from([255, 217]))
|
|
70
|
+
)
|
|
71
|
+
return "image/jpeg";
|
|
72
|
+
if (
|
|
73
|
+
buf.length >= 12 &&
|
|
74
|
+
buf.toString("latin1", 0, 4) === "RIFF" &&
|
|
75
|
+
buf.toString("latin1", 8, 12) === "WEBP" &&
|
|
76
|
+
buf.readUInt32LE(4) + 8 === buf.length &&
|
|
77
|
+
["VP8 ", "VP8L", "VP8X"].includes(buf.toString("latin1", 12, 16))
|
|
78
|
+
) {
|
|
79
|
+
return "image/webp";
|
|
80
|
+
}
|
|
81
|
+
return null;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
function decodeImage(data, mime) {
|
|
85
|
+
if (
|
|
86
|
+
typeof data !== "string" ||
|
|
87
|
+
!data ||
|
|
88
|
+
data.length > Math.ceil(MAX_IMAGE_BYTES / 3) * 4 ||
|
|
89
|
+
data.length % 4 !== 0
|
|
90
|
+
)
|
|
91
|
+
return null;
|
|
92
|
+
if (!/^[A-Za-z0-9+/]+={0,2}$/.test(data)) return null;
|
|
93
|
+
const image = Buffer.from(data, "base64");
|
|
94
|
+
if (!image.length || image.length > MAX_IMAGE_BYTES) return null;
|
|
95
|
+
if (image.toString("base64") !== data) return null;
|
|
96
|
+
const declared = declaredMime(mime);
|
|
97
|
+
const header = headerMime(image);
|
|
98
|
+
if (!declared || !header || declared !== header) return null;
|
|
99
|
+
return { image, mimetype: header };
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
function imageFromResponse(response) {
|
|
103
|
+
const parts = response?.candidates?.[0]?.content?.parts;
|
|
104
|
+
if (!Array.isArray(parts)) return null;
|
|
105
|
+
for (const part of parts) {
|
|
106
|
+
const inline = part?.inlineData;
|
|
107
|
+
if (!inline || typeof inline.data !== "string") continue;
|
|
108
|
+
const decoded = decodeImage(inline.data, inline.mimeType);
|
|
109
|
+
if (decoded) return decoded;
|
|
110
|
+
}
|
|
111
|
+
return null;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
function clientFor(baseUrl, key) {
|
|
115
|
+
if (cache.key !== key || cache.baseUrl !== baseUrl) {
|
|
116
|
+
cache = {
|
|
117
|
+
key,
|
|
118
|
+
baseUrl,
|
|
119
|
+
client: new GoogleGenAI({ apiKey: key, httpOptions: { baseUrl } }),
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
return cache.client;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* Generate one raster image on the configured Gemini image model.
|
|
127
|
+
* @param {string} prompt
|
|
128
|
+
* @param {{signal?: AbortSignal}} [options]
|
|
129
|
+
* @returns {Promise<{image: Buffer, mimetype: string, provider: "gemini", model: string}>}
|
|
130
|
+
*/
|
|
131
|
+
async function generateImage(prompt, { signal } = {}) {
|
|
132
|
+
if (typeof prompt !== "string" || !prompt.trim() || prompt.trim().length > MAX_PROMPT) {
|
|
133
|
+
throw fail("IMAGE_FAILED");
|
|
134
|
+
}
|
|
135
|
+
if (signal?.aborted) throw aborted();
|
|
136
|
+
|
|
137
|
+
const key = settings.get("gemini_api_key");
|
|
138
|
+
if (!key) throw fail("IMAGE_KEY_REQUIRED");
|
|
139
|
+
|
|
140
|
+
let baseUrl;
|
|
141
|
+
try {
|
|
142
|
+
baseUrl = assertProviderBaseUrl(settings.get("gemini_base_url"), { allowLoopback: true });
|
|
143
|
+
await assertProviderRequestUrl(baseUrl, { allowLoopback: true });
|
|
144
|
+
} catch {
|
|
145
|
+
throw fail("IMAGE_FAILED");
|
|
146
|
+
}
|
|
147
|
+
if (signal?.aborted) throw aborted();
|
|
148
|
+
|
|
149
|
+
const model = settings.get("gemini_image_model");
|
|
150
|
+
let response;
|
|
151
|
+
try {
|
|
152
|
+
response = await clientFor(baseUrl, key).models.generateContent({
|
|
153
|
+
model,
|
|
154
|
+
contents: `Generate an image using this prompt: ${prompt.trim()}`,
|
|
155
|
+
config: {
|
|
156
|
+
responseModalities: ["IMAGE"],
|
|
157
|
+
abortSignal: signal,
|
|
158
|
+
// baseUrl is repeated so this request stays on the configured endpoint.
|
|
159
|
+
httpOptions: { timeout: REQUEST_TIMEOUT_MS, baseUrl },
|
|
160
|
+
},
|
|
161
|
+
});
|
|
162
|
+
} catch (err) {
|
|
163
|
+
if (isAbort(err, signal)) throw aborted();
|
|
164
|
+
if (isQuota(err)) throw fail("IMAGE_QUOTA");
|
|
165
|
+
throw fail("IMAGE_FAILED");
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
// A late abort must not become a successful image.
|
|
169
|
+
if (signal?.aborted) throw aborted();
|
|
170
|
+
|
|
171
|
+
const decoded = imageFromResponse(response);
|
|
172
|
+
if (!decoded) throw fail("IMAGE_OUTPUT_INVALID");
|
|
173
|
+
if (signal?.aborted) throw aborted();
|
|
174
|
+
|
|
175
|
+
return {
|
|
176
|
+
image: decoded.image,
|
|
177
|
+
mimetype: decoded.mimetype,
|
|
178
|
+
provider: "gemini",
|
|
179
|
+
model,
|
|
180
|
+
};
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
module.exports = { generateImage };
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
// Shared cost/concurrency boundary for model-initiated media operations.
|
|
2
|
+
const settings = require("../config/settings.cjs");
|
|
3
|
+
const { isTrustedCaller } = require("./aiToolAuth.cjs");
|
|
4
|
+
const MAX_MEDIA_BYTES = 8 * 1024 * 1024;
|
|
5
|
+
const windows = new Map();
|
|
6
|
+
const WINDOW_MS = 60_000;
|
|
7
|
+
|
|
8
|
+
async function withMediaLimit(caller, action) {
|
|
9
|
+
if (!isTrustedCaller(caller) || !caller.senderId) throw new Error("MEDIA_CALLER_REQUIRED");
|
|
10
|
+
const now = Date.now();
|
|
11
|
+
for (const [key, state] of windows) {
|
|
12
|
+
if (!state.busy && now - state.start >= WINDOW_MS) windows.delete(key);
|
|
13
|
+
}
|
|
14
|
+
const key = caller.senderId;
|
|
15
|
+
let state = windows.get(key);
|
|
16
|
+
if (state?.busy) throw new Error("MEDIA_BUSY");
|
|
17
|
+
if (!state) {
|
|
18
|
+
if (windows.size >= 1000) throw new Error("MEDIA_BUSY");
|
|
19
|
+
state = { start: now, attempts: 0, busy: false };
|
|
20
|
+
windows.set(key, state);
|
|
21
|
+
}
|
|
22
|
+
if (state.attempts >= 3) throw new Error("MEDIA_RATE_LIMIT");
|
|
23
|
+
state.attempts += 1;
|
|
24
|
+
state.busy = true;
|
|
25
|
+
const controller = new AbortController();
|
|
26
|
+
const timeout = Math.max(
|
|
27
|
+
1,
|
|
28
|
+
Math.min(120_000, Number(settings.get("ai_tool_timeout_ms")) || 30_000),
|
|
29
|
+
);
|
|
30
|
+
let timer;
|
|
31
|
+
const expired = new Promise((_, reject) => {
|
|
32
|
+
timer = setTimeout(() => {
|
|
33
|
+
const error = new Error("MEDIA_TIMEOUT");
|
|
34
|
+
controller.abort(error);
|
|
35
|
+
reject(error);
|
|
36
|
+
}, timeout);
|
|
37
|
+
});
|
|
38
|
+
// Keep a non-cancellable operation busy until it actually finishes, even
|
|
39
|
+
// after its caller has timed out. It must check this signal before sending.
|
|
40
|
+
const work = Promise.resolve()
|
|
41
|
+
.then(() => action(controller.signal))
|
|
42
|
+
.finally(() => {
|
|
43
|
+
state.busy = false;
|
|
44
|
+
});
|
|
45
|
+
try {
|
|
46
|
+
return await Promise.race([work, expired]);
|
|
47
|
+
} finally {
|
|
48
|
+
clearTimeout(timer);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function assertAudio(buffer, mimetype, ptt = false) {
|
|
53
|
+
if (!Buffer.isBuffer(buffer) || buffer.length < 4 || buffer.length > MAX_MEDIA_BYTES) {
|
|
54
|
+
throw new Error("MEDIA_AUDIO_INVALID");
|
|
55
|
+
}
|
|
56
|
+
const mime = String(mimetype || "")
|
|
57
|
+
.split(";")[0]
|
|
58
|
+
.trim()
|
|
59
|
+
.toLowerCase();
|
|
60
|
+
const ogg = buffer.subarray(0, 4).toString() === "OggS";
|
|
61
|
+
const mpeg =
|
|
62
|
+
buffer.subarray(0, 3).toString() === "ID3" || (buffer[0] === 255 && (buffer[1] & 224) === 224);
|
|
63
|
+
const valid =
|
|
64
|
+
mime === "audio/ogg"
|
|
65
|
+
? ogg
|
|
66
|
+
: ["audio/mpeg", "audio/mp3", "audio/aac"].includes(mime)
|
|
67
|
+
? mpeg
|
|
68
|
+
: ["audio/wav", "audio/x-wav"].includes(mime)
|
|
69
|
+
? buffer.subarray(0, 4).toString() === "RIFF" &&
|
|
70
|
+
buffer.subarray(8, 12).toString() === "WAVE"
|
|
71
|
+
: ["audio/mp4", "audio/m4a"].includes(mime)
|
|
72
|
+
? buffer.subarray(4, 8).toString() === "ftyp"
|
|
73
|
+
: mime === "audio/flac"
|
|
74
|
+
? buffer.subarray(0, 4).toString() === "fLaC"
|
|
75
|
+
: mime === "audio/webm"
|
|
76
|
+
? buffer.subarray(0, 4).equals(Buffer.from([26, 69, 223, 163]))
|
|
77
|
+
: mime === "audio/amr"
|
|
78
|
+
? buffer.subarray(0, 5).toString() === "#!AMR"
|
|
79
|
+
: false;
|
|
80
|
+
if (!valid || (ptt && !ogg)) throw new Error("MEDIA_AUDIO_INVALID");
|
|
81
|
+
return buffer;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
function assertWhatsAppAudio(audio) {
|
|
85
|
+
if (!audio || Number(audio.fileLength || 0) > MAX_MEDIA_BYTES)
|
|
86
|
+
throw new Error("MEDIA_NOT_AVAILABLE");
|
|
87
|
+
if (audio.url) {
|
|
88
|
+
let url;
|
|
89
|
+
try {
|
|
90
|
+
url = new URL(audio.url);
|
|
91
|
+
} catch {
|
|
92
|
+
throw new Error("MEDIA_URL_INVALID");
|
|
93
|
+
}
|
|
94
|
+
if (
|
|
95
|
+
url.protocol !== "https:" ||
|
|
96
|
+
url.username ||
|
|
97
|
+
url.password ||
|
|
98
|
+
url.port ||
|
|
99
|
+
!/^(?:[a-z0-9-]+\.)*whatsapp\.net$/i.test(url.hostname)
|
|
100
|
+
)
|
|
101
|
+
throw new Error("MEDIA_URL_INVALID");
|
|
102
|
+
}
|
|
103
|
+
if (
|
|
104
|
+
audio.directPath &&
|
|
105
|
+
(typeof audio.directPath !== "string" ||
|
|
106
|
+
!audio.directPath.startsWith("/") ||
|
|
107
|
+
audio.directPath.startsWith("//") ||
|
|
108
|
+
audio.directPath.includes("\\"))
|
|
109
|
+
) {
|
|
110
|
+
throw new Error("MEDIA_URL_INVALID");
|
|
111
|
+
}
|
|
112
|
+
if (!audio.url && !audio.directPath) throw new Error("MEDIA_NOT_AVAILABLE");
|
|
113
|
+
if (
|
|
114
|
+
!/^audio\/(?:ogg|mpeg|mp3|aac|wav|x-wav|mp4|m4a|flac|webm|amr)(?:\s*;.*)?$/i.test(
|
|
115
|
+
audio.mimetype || "",
|
|
116
|
+
)
|
|
117
|
+
) {
|
|
118
|
+
throw new Error("MEDIA_AUDIO_INVALID");
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
function mediaFailure(error) {
|
|
123
|
+
const message = String(error?.message || "");
|
|
124
|
+
const known =
|
|
125
|
+
/^(?:MEDIA_(?:TIMEOUT|RATE_LIMIT|BUSY|AUDIO_INVALID|URL_INVALID|NOT_AVAILABLE|TOO_LARGE|DISABLED|ARGUMENT_INVALID|DELIVERY_REFUSED|CALLER_REQUIRED)|IMAGE_(?:KEY_REQUIRED|OUTPUT_INVALID|QUOTA|FAILED)|STT_(?:KEY_REQUIRED|QUOTA|OUTPUT_INVALID|FAILED))$/;
|
|
126
|
+
const code = known.test(error?.code)
|
|
127
|
+
? error.code
|
|
128
|
+
: known.test(message)
|
|
129
|
+
? message
|
|
130
|
+
: /quota|429|RESOURCE_EXHAUSTED/i.test(message)
|
|
131
|
+
? "MEDIA_RATE_LIMIT"
|
|
132
|
+
: "MEDIA_FAILED";
|
|
133
|
+
return {
|
|
134
|
+
error:
|
|
135
|
+
"The media request could not be completed. Check the error code, permissions and configured provider.",
|
|
136
|
+
code,
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
module.exports = {
|
|
141
|
+
withMediaLimit,
|
|
142
|
+
assertAudio,
|
|
143
|
+
assertWhatsAppAudio,
|
|
144
|
+
mediaFailure,
|
|
145
|
+
MAX_MEDIA_BYTES,
|
|
146
|
+
};
|
|
@@ -30,7 +30,8 @@
|
|
|
30
30
|
|
|
31
31
|
const logger = require("../utils/logger.cjs");
|
|
32
32
|
const settings = require("../config/settings.cjs");
|
|
33
|
-
const { toolDeclarations, describeCall,
|
|
33
|
+
const { toolDeclarations, describeCall, runToolWithDeadline } = require("./aiTools.cjs");
|
|
34
|
+
const { docSourcesFromTool } = require("./aiDocs.cjs");
|
|
34
35
|
const { assertProviderBaseUrl, safeProviderFetch } = require("../utils/providerUrl.cjs");
|
|
35
36
|
const { baseMimeType, downloadMedia } = require("../utils/geminiMedia.cjs");
|
|
36
37
|
|
|
@@ -103,7 +104,7 @@ const {
|
|
|
103
104
|
getProvider,
|
|
104
105
|
detectModelCapabilities,
|
|
105
106
|
} = require("./aiRouter.cjs");
|
|
106
|
-
const {
|
|
107
|
+
const { t } = require("../utils/i18n.cjs");
|
|
107
108
|
|
|
108
109
|
function visionAllowed(providerId) {
|
|
109
110
|
const id = providerId || settings.get("ai_provider");
|
|
@@ -217,7 +218,7 @@ registerProvider("anthropic", new AnthropicProvider());
|
|
|
217
218
|
|
|
218
219
|
function adapterFor(provider) {
|
|
219
220
|
const adapter = ADAPTERS[provider];
|
|
220
|
-
if (!adapter) throw new Error(
|
|
221
|
+
if (!adapter) throw new Error(t("bot.ai.aiProviders.unknownProvider", { provider }));
|
|
221
222
|
return adapter;
|
|
222
223
|
}
|
|
223
224
|
|
|
@@ -238,7 +239,7 @@ const PROVIDER_KEY_SETTINGS = Object.freeze({
|
|
|
238
239
|
|
|
239
240
|
function activeProviderKeySetting(provider = settings.get("ai_provider")) {
|
|
240
241
|
const keySetting = PROVIDER_KEY_SETTINGS[provider];
|
|
241
|
-
if (!keySetting) throw new Error(
|
|
242
|
+
if (!keySetting) throw new Error(t("bot.ai.aiProviders.unknownProvider", { provider }));
|
|
242
243
|
return keySetting;
|
|
243
244
|
}
|
|
244
245
|
|
|
@@ -343,6 +344,21 @@ function safeJsonArgs(raw) {
|
|
|
343
344
|
}
|
|
344
345
|
}
|
|
345
346
|
|
|
347
|
+
function rememberToolCall(callIds, call, id) {
|
|
348
|
+
const pending = callIds.get(call.name) || [];
|
|
349
|
+
pending.push(id);
|
|
350
|
+
callIds.set(call.name, pending);
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
function toolResponseId(callIds, response, fallback) {
|
|
354
|
+
const pending = callIds.get(response.name);
|
|
355
|
+
// Gemini results have no id and follow call order. Other providers may
|
|
356
|
+
// return explicit ids out of order; consume that exact id from the queue.
|
|
357
|
+
const index = response.id ? (pending?.indexOf(response.id) ?? -1) : 0;
|
|
358
|
+
const matched = index >= 0 ? pending?.splice(index, 1)[0] : undefined;
|
|
359
|
+
return response.id || matched || fallback;
|
|
360
|
+
}
|
|
361
|
+
|
|
346
362
|
/**
|
|
347
363
|
* Canonical -> chat-completions.
|
|
348
364
|
*
|
|
@@ -367,7 +383,7 @@ function historyToOpenAI(history) {
|
|
|
367
383
|
if (calls.length) {
|
|
368
384
|
const toolCalls = calls.map((call, i) => {
|
|
369
385
|
const id = call.id || `call_${turnIndex}_${i}`;
|
|
370
|
-
|
|
386
|
+
rememberToolCall(callIds, call, id);
|
|
371
387
|
return {
|
|
372
388
|
id,
|
|
373
389
|
type: "function",
|
|
@@ -409,7 +425,7 @@ function historyToOpenAI(history) {
|
|
|
409
425
|
for (const response of responses) {
|
|
410
426
|
messages.push({
|
|
411
427
|
role: "tool",
|
|
412
|
-
tool_call_id:
|
|
428
|
+
tool_call_id: toolResponseId(callIds, response, `call_${turnIndex}`),
|
|
413
429
|
content: JSON.stringify(response.response ?? {}),
|
|
414
430
|
});
|
|
415
431
|
}
|
|
@@ -450,7 +466,7 @@ function historyToAnthropic(history) {
|
|
|
450
466
|
blocks.push({ type: "text", text: part.text });
|
|
451
467
|
} else if (part?.functionCall) {
|
|
452
468
|
const id = part.functionCall.id || `call_${turnIndex}_${blocks.length}`;
|
|
453
|
-
|
|
469
|
+
rememberToolCall(callIds, part.functionCall, id);
|
|
454
470
|
blocks.push({
|
|
455
471
|
type: "tool_use",
|
|
456
472
|
id,
|
|
@@ -460,10 +476,7 @@ function historyToAnthropic(history) {
|
|
|
460
476
|
} else if (part?.functionResponse) {
|
|
461
477
|
blocks.push({
|
|
462
478
|
type: "tool_result",
|
|
463
|
-
tool_use_id:
|
|
464
|
-
part.functionResponse.id ||
|
|
465
|
-
callIds.get(part.functionResponse.name) ||
|
|
466
|
-
`call_${turnIndex}`,
|
|
479
|
+
tool_use_id: toolResponseId(callIds, part.functionResponse, `call_${turnIndex}`),
|
|
467
480
|
content: JSON.stringify(part.functionResponse.response ?? {}),
|
|
468
481
|
});
|
|
469
482
|
} else if (part?.fileData || part?.inlineData) {
|
|
@@ -558,44 +571,48 @@ function parseAnthropicResponse(payload) {
|
|
|
558
571
|
// the wire
|
|
559
572
|
// ===========================================================================
|
|
560
573
|
|
|
561
|
-
async function callApi({ url, headers, body, label }) {
|
|
574
|
+
async function callApi({ url, headers, body, label, signal: turnSignal }) {
|
|
562
575
|
const controller = new AbortController();
|
|
563
|
-
const
|
|
564
|
-
|
|
565
|
-
|
|
576
|
+
const timeoutError = new Error(`${label} API request timed out after ${API_TIMEOUT_MS / 1000}s`);
|
|
577
|
+
const timer = setTimeout(() => controller.abort(timeoutError), API_TIMEOUT_MS);
|
|
578
|
+
const signal = turnSignal ? AbortSignal.any([turnSignal, controller.signal]) : controller.signal;
|
|
566
579
|
try {
|
|
567
|
-
response = await safeProviderFetch(
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
? `${label} API request timed out after ${API_TIMEOUT_MS / 1000}s`
|
|
577
|
-
: `${label} API request failed: ${err?.message || err}`,
|
|
580
|
+
const response = await safeProviderFetch(
|
|
581
|
+
url,
|
|
582
|
+
{
|
|
583
|
+
method: "POST",
|
|
584
|
+
headers: { "Content-Type": "application/json", ...headers },
|
|
585
|
+
body: JSON.stringify(body),
|
|
586
|
+
signal,
|
|
587
|
+
},
|
|
588
|
+
{ allowLoopback: true },
|
|
578
589
|
);
|
|
590
|
+
let payload = {};
|
|
591
|
+
try {
|
|
592
|
+
payload = await response.json();
|
|
593
|
+
} catch {
|
|
594
|
+
// Non-JSON proxy pages still use the status; cancellation must escape.
|
|
595
|
+
signal.throwIfAborted();
|
|
596
|
+
}
|
|
597
|
+
signal.throwIfAborted();
|
|
598
|
+
if (!response.ok) {
|
|
599
|
+
const message =
|
|
600
|
+
payload?.error?.message || payload?.error || response.statusText || "unknown error";
|
|
601
|
+
const error = new Error(
|
|
602
|
+
settings.redactSecrets(`${label} API request failed (${response.status}): ${message}`),
|
|
603
|
+
);
|
|
604
|
+
error.status = response.status;
|
|
605
|
+
throw error;
|
|
606
|
+
}
|
|
607
|
+
return payload;
|
|
608
|
+
} catch (err) {
|
|
609
|
+
if (controller.signal.aborted) throw timeoutError;
|
|
610
|
+
if (turnSignal?.aborted) throw turnSignal.reason;
|
|
611
|
+
if (err?.status) throw err;
|
|
612
|
+
throw new Error(settings.redactSecrets(`${label} API request failed: ${err?.message || err}`));
|
|
579
613
|
} finally {
|
|
580
614
|
clearTimeout(timer);
|
|
581
615
|
}
|
|
582
|
-
|
|
583
|
-
let payload = {};
|
|
584
|
-
try {
|
|
585
|
-
payload = await response.json();
|
|
586
|
-
} catch {
|
|
587
|
-
// A non-JSON body (a proxy error page, say) still gets the status below.
|
|
588
|
-
}
|
|
589
|
-
|
|
590
|
-
if (!response.ok) {
|
|
591
|
-
const message =
|
|
592
|
-
payload?.error?.message || payload?.error || response.statusText || "unknown error";
|
|
593
|
-
const error = new Error(`${label} API request failed (${response.status}): ${message}`);
|
|
594
|
-
error.status = response.status;
|
|
595
|
-
throw error;
|
|
596
|
-
}
|
|
597
|
-
|
|
598
|
-
return payload;
|
|
599
616
|
}
|
|
600
617
|
|
|
601
618
|
function requestFor(
|
|
@@ -632,27 +649,6 @@ function requestFor(
|
|
|
632
649
|
};
|
|
633
650
|
}
|
|
634
651
|
|
|
635
|
-
function withTimeout(promise, ms, label) {
|
|
636
|
-
let timer;
|
|
637
|
-
return Promise.race([
|
|
638
|
-
promise,
|
|
639
|
-
new Promise((_, reject) => {
|
|
640
|
-
timer = setTimeout(
|
|
641
|
-
() =>
|
|
642
|
-
reject(
|
|
643
|
-
new Error(
|
|
644
|
-
tr(
|
|
645
|
-
`${label} took longer than ${Math.round(ms / 1000)} seconds`,
|
|
646
|
-
`${label} استغرقت العملية أكثر من ${Math.round(ms / 1000)} ثانية`,
|
|
647
|
-
),
|
|
648
|
-
),
|
|
649
|
-
),
|
|
650
|
-
ms,
|
|
651
|
-
);
|
|
652
|
-
}),
|
|
653
|
-
]).finally(() => clearTimeout(timer));
|
|
654
|
-
}
|
|
655
|
-
|
|
656
652
|
// ===========================================================================
|
|
657
653
|
// the loop — same shape as aiAgent.runAgent, different wire format
|
|
658
654
|
// ===========================================================================
|
|
@@ -680,6 +676,7 @@ async function runProviderAgent(
|
|
|
680
676
|
context = {},
|
|
681
677
|
useTools = true,
|
|
682
678
|
maxSteps = null,
|
|
679
|
+
signal,
|
|
683
680
|
} = {},
|
|
684
681
|
) {
|
|
685
682
|
const adapter = adapterFor(provider);
|
|
@@ -710,6 +707,7 @@ async function runProviderAgent(
|
|
|
710
707
|
|
|
711
708
|
const tools = useTools ? adapter.tools() : [];
|
|
712
709
|
const toolCalls = [];
|
|
710
|
+
const sources = [];
|
|
713
711
|
let steps = 0;
|
|
714
712
|
|
|
715
713
|
const send = () => {
|
|
@@ -721,7 +719,7 @@ async function runProviderAgent(
|
|
|
721
719
|
messages,
|
|
722
720
|
tools,
|
|
723
721
|
});
|
|
724
|
-
return callApi({ ...request, label: adapter.label });
|
|
722
|
+
return callApi({ ...request, label: adapter.label, signal });
|
|
725
723
|
};
|
|
726
724
|
|
|
727
725
|
let response = await send();
|
|
@@ -748,20 +746,16 @@ async function runProviderAgent(
|
|
|
748
746
|
messages.push(parsed.assistantMessage);
|
|
749
747
|
|
|
750
748
|
if (!parsed.calls.length) {
|
|
751
|
-
return finish({ text: parsed.text, canonical, toolCalls, steps });
|
|
749
|
+
return finish({ text: parsed.text, canonical, toolCalls, steps, sources });
|
|
752
750
|
}
|
|
753
751
|
if (steps >= stepBudget) {
|
|
754
752
|
// Same contract as the Gemini loop: the budget answer, not a lie.
|
|
755
753
|
return finish({
|
|
756
|
-
text:
|
|
757
|
-
parsed.text ||
|
|
758
|
-
tr(
|
|
759
|
-
"I ran the tools I have but couldn't reach a final answer. Try asking more clearly.",
|
|
760
|
-
"استخدمت الأدوات المتاحة، لكنني لم أتمكن من الوصول إلى إجابة نهائية. حاول صياغة السؤال بوضوح أكبر.",
|
|
761
|
-
),
|
|
754
|
+
text: parsed.text || t("bot.ai.aiProviders.toolBudget"),
|
|
762
755
|
canonical,
|
|
763
756
|
toolCalls,
|
|
764
757
|
steps,
|
|
758
|
+
sources,
|
|
765
759
|
});
|
|
766
760
|
}
|
|
767
761
|
|
|
@@ -775,18 +769,20 @@ async function runProviderAgent(
|
|
|
775
769
|
const results = [];
|
|
776
770
|
for (const call of parsed.calls) {
|
|
777
771
|
toolCalls.push({ name: call.name, args: call.args });
|
|
778
|
-
logger.info({ tool: call.name
|
|
772
|
+
logger.info({ tool: call.name }, "[aiAgent] tool call");
|
|
779
773
|
|
|
780
774
|
let toolResult;
|
|
781
775
|
try {
|
|
782
|
-
toolResult = await
|
|
783
|
-
runTool(call.name, call.args, context),
|
|
784
|
-
settings.get("ai_tool_timeout_ms"),
|
|
776
|
+
toolResult = await runToolWithDeadline(
|
|
785
777
|
call.name,
|
|
778
|
+
call.args,
|
|
779
|
+
context,
|
|
780
|
+
settings.get("ai_tool_timeout_ms"),
|
|
786
781
|
);
|
|
787
782
|
} catch (err) {
|
|
788
783
|
toolResult = { error: err?.message || String(err) };
|
|
789
784
|
}
|
|
785
|
+
sources.push(...docSourcesFromTool(call.name, toolResult));
|
|
790
786
|
results.push(toolResult);
|
|
791
787
|
}
|
|
792
788
|
|
|
@@ -805,19 +801,19 @@ async function runProviderAgent(
|
|
|
805
801
|
})),
|
|
806
802
|
});
|
|
807
803
|
|
|
808
|
-
if (status) await status.update(
|
|
804
|
+
if (status) await status.update(t("bot.ai.aiProviders.writingAnswer"));
|
|
809
805
|
response = await send();
|
|
810
806
|
}
|
|
811
807
|
}
|
|
812
808
|
|
|
813
|
-
function finish({ text, canonical, toolCalls, steps }) {
|
|
809
|
+
function finish({ text, canonical, toolCalls, steps, sources }) {
|
|
814
810
|
return {
|
|
815
811
|
text,
|
|
816
812
|
history: canonical,
|
|
817
813
|
toolCalls,
|
|
818
814
|
steps,
|
|
819
|
-
//
|
|
820
|
-
sources
|
|
815
|
+
// Public bundled doc citations are available independently of web grounding.
|
|
816
|
+
sources,
|
|
821
817
|
searchOffered: false,
|
|
822
818
|
};
|
|
823
819
|
}
|
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
|
|
8
8
|
const settings = require("../config/settings.cjs");
|
|
9
9
|
const { resolveCapabilities } = require("./modelRegistry.cjs");
|
|
10
|
-
const {
|
|
10
|
+
const { t } = require("../utils/i18n.cjs");
|
|
11
11
|
|
|
12
12
|
class BaseAIProvider {
|
|
13
13
|
constructor({
|
|
@@ -83,7 +83,7 @@ function getProvider(id = settings.get("ai_provider")) {
|
|
|
83
83
|
const key = String(id || "gemini").toLowerCase();
|
|
84
84
|
const provider = REGISTRY.get(key);
|
|
85
85
|
if (!provider) {
|
|
86
|
-
throw new Error(
|
|
86
|
+
throw new Error(t("bot.ai.aiRouter.unknownProvider", { provider: id }));
|
|
87
87
|
}
|
|
88
88
|
return provider;
|
|
89
89
|
}
|