@llmnative/react 2.3.0 → 3.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.
Files changed (61) hide show
  1. package/README.md +3 -2
  2. package/dist/index.js +20 -21
  3. package/dist/index.js.map +1 -1
  4. package/dist/index.mjs +6768 -6811
  5. package/dist/index.mjs.map +1 -1
  6. package/dist/modelIdentity-CIXNPtTA.mjs +624 -0
  7. package/dist/modelIdentity-CIXNPtTA.mjs.map +1 -0
  8. package/dist/modelIdentity-DX62i7g2.js +3 -0
  9. package/dist/modelIdentity-DX62i7g2.js.map +1 -0
  10. package/dist/server-B430eH0y.mjs +352 -0
  11. package/dist/server-B430eH0y.mjs.map +1 -0
  12. package/dist/server-CDheNgME.js +2 -0
  13. package/dist/server-CDheNgME.js.map +1 -0
  14. package/dist/server.js +1 -1
  15. package/dist/server.mjs +3 -3
  16. package/dist/types/src/App.d.ts +6 -4
  17. package/dist/types/src/I18n.d.ts +2 -0
  18. package/dist/types/src/components/widgets/grid-core/GridCore.d.ts +1 -1
  19. package/dist/types/src/components/widgets/grid-core/types.d.ts +2 -0
  20. package/dist/types/src/components/widgets/grid-core/useGridDBRecords.d.ts +6 -2
  21. package/dist/types/src/index.d.ts +21 -8
  22. package/dist/types/src/libs/index.d.ts +0 -1
  23. package/dist/types/src/providers/ProviderRegistryContext.d.ts +7 -5
  24. package/dist/types/src/providers/ai/server.d.ts +20 -0
  25. package/dist/types/src/providers/api/ApiProvider.d.ts +1 -1
  26. package/dist/types/src/providers/data/DataProvider.d.ts +29 -0
  27. package/dist/types/src/providers/data/firebase.d.ts +2 -2
  28. package/dist/types/src/providers/data/firestore.d.ts +2 -2
  29. package/dist/types/src/providers/data/query.d.ts +14 -0
  30. package/dist/types/src/providers/data/useDataSubscription.d.ts +20 -0
  31. package/dist/types/src/providers/email/EmailError.d.ts +27 -0
  32. package/dist/types/src/providers/email/EmailProviderContext.d.ts +13 -7
  33. package/dist/types/src/providers/email/EmailRead.d.ts +48 -0
  34. package/dist/types/src/providers/email/EmailSend.d.ts +54 -0
  35. package/dist/types/src/providers/email/brevo/BrevoEmailSender.d.ts +21 -0
  36. package/dist/types/src/providers/email/definitions.d.ts +4 -2
  37. package/dist/types/src/providers/email/gmail/GmailEmailReader.d.ts +37 -0
  38. package/dist/types/src/providers/email/gmail/GmailEmailSender.d.ts +21 -0
  39. package/dist/types/src/providers/email/gmail/browser.d.ts +10 -0
  40. package/dist/types/src/providers/email/gmail/gmailApi.d.ts +53 -0
  41. package/dist/types/src/providers/email/gmail/gmailOAuth.d.ts +25 -0
  42. package/dist/types/src/providers/email/imap/ImapEmailReader.d.ts +70 -0
  43. package/dist/types/src/providers/email/resend/ResendEmailSender.d.ts +20 -0
  44. package/dist/types/src/providers/manifest.d.ts +7 -5
  45. package/dist/vite.js +1 -1
  46. package/dist/vite.mjs +1 -1
  47. package/llms-full.txt +1690 -1625
  48. package/llms.txt +83 -82
  49. package/package.json +18 -1
  50. package/dist/modelIdentity-CGWliGDU.mjs +0 -183
  51. package/dist/modelIdentity-CGWliGDU.mjs.map +0 -1
  52. package/dist/modelIdentity-CgRMrC5H.js +0 -2
  53. package/dist/modelIdentity-CgRMrC5H.js.map +0 -1
  54. package/dist/server-CCbjPJEz.js +0 -2
  55. package/dist/server-CCbjPJEz.js.map +0 -1
  56. package/dist/server-CiWwr3Zg.mjs +0 -107
  57. package/dist/server-CiWwr3Zg.mjs.map +0 -1
  58. package/dist/types/src/libs/email.d.ts +0 -16
  59. package/dist/types/src/providers/email/EmailProvider.d.ts +0 -10
  60. package/dist/types/src/providers/email/google/GmailEmailProvider.d.ts +0 -7
  61. package/dist/types/src/providers/email/google/email.d.ts +0 -13
@@ -0,0 +1,624 @@
1
+ //#region src/providers/ProviderConfiguration.ts
2
+ var e = (e, t, n = "") => t.filter((t) => {
3
+ let n = e?.[t];
4
+ return n == null || n === "";
5
+ }).map((e) => `${n}${e}`), t = (e, t) => ({
6
+ configured: t.length === 0,
7
+ missingKeys: t,
8
+ reason: t.length ? `${e} is not configured. Missing: ${t.join(", ")}.` : void 0
9
+ }), n = (e, t = "Provider") => {
10
+ if (!e) return {
11
+ configured: !1,
12
+ reason: `${t} is not registered.`
13
+ };
14
+ if (e.getConfigurationState) return e.getConfigurationState();
15
+ if (e.isConfigured) {
16
+ let n = e.isConfigured();
17
+ return {
18
+ configured: n,
19
+ reason: n ? void 0 : `${t} is not configured.`
20
+ };
21
+ }
22
+ return { configured: !0 };
23
+ }, r = "llmnative-server-credential", i = /^[A-Za-z0-9_-]+$/, a = /llmnative-server-credential:([A-Za-z0-9_-]+):([a-z-]+)/g, o = (e, t) => {
24
+ if (!i.test(e)) throw Error(`Server credential scope "${e}" may only contain letters, digits, "-" and "_".`);
25
+ return `${r}:${e}:${t}`;
26
+ }, s = (e) => [...e.matchAll(a)].map(([e, t, n]) => ({
27
+ placeholder: e,
28
+ scope: t,
29
+ provider: n
30
+ })), c = (e) => e.includes(`${r}:`), l = {
31
+ openai: "api.openai.com",
32
+ openrouter: "openrouter.ai",
33
+ opencode: "opencode.ai",
34
+ "opencode-go": "opencode.ai",
35
+ deepseek: "api.deepseek.com",
36
+ gemini: "generativelanguage.googleapis.com",
37
+ anthropic: "api.anthropic.com",
38
+ mistral: "api.mistral.ai",
39
+ glm: "open.bigmodel.cn",
40
+ groq: "api.groq.com",
41
+ cloudflare: "api.cloudflare.com"
42
+ }, u = (e) => e.replace(/\/+$/, ""), ee = (e, t) => {
43
+ if (e.id === "openai-compatible") {
44
+ if (!e.baseUrl) return !1;
45
+ let n = new URL(e.baseUrl), r = u(n.pathname);
46
+ return t.origin === n.origin && (t.pathname === r || t.pathname.startsWith(`${r}/`));
47
+ }
48
+ return t.protocol !== "https:" || t.host !== l[e.id] ? !1 : e.id !== "cloudflare" || !!e.accountId && t.pathname.startsWith(`/client/v4/accounts/${encodeURIComponent(e.accountId.trim())}/`);
49
+ }, d = "https://models.dev/api.json", f = "ai.pricing.modelsdev", te = 864e5, p = {
50
+ openai: ["openai"],
51
+ openrouter: ["openrouter"],
52
+ opencode: ["opencode"],
53
+ "opencode-go": ["opencode-go"],
54
+ deepseek: ["deepseek"],
55
+ gemini: ["google"],
56
+ anthropic: ["anthropic"],
57
+ mistral: ["mistral"],
58
+ glm: ["zhipuai", "zai"],
59
+ cloudflare: ["cloudflare-workers-ai"],
60
+ groq: ["groq"]
61
+ }, m = null, ne = () => {
62
+ if (typeof localStorage > "u") return null;
63
+ try {
64
+ let e = localStorage.getItem(f);
65
+ if (!e) return null;
66
+ let t = JSON.parse(e);
67
+ return !t.fetchedAt || !t.index || Date.now() - t.fetchedAt > te ? null : t.index;
68
+ } catch {
69
+ return null;
70
+ }
71
+ }, re = (e) => {
72
+ if (typeof localStorage < "u") try {
73
+ localStorage.setItem(f, JSON.stringify({
74
+ fetchedAt: Date.now(),
75
+ index: e
76
+ }));
77
+ } catch {}
78
+ }, ie = (e) => {
79
+ let t = new Set(Object.values(p).flat()), n = {};
80
+ for (let r of t) {
81
+ let t = e[r]?.models ?? {}, i = {};
82
+ for (let [e, n] of Object.entries(t)) {
83
+ let t = n?.cost?.input, r = n?.cost?.output;
84
+ typeof t == "number" && typeof r == "number" && (i[e] = [t, r]);
85
+ }
86
+ n[r] = i;
87
+ }
88
+ return n;
89
+ }, h = () => {
90
+ let e = ne();
91
+ return e ? Promise.resolve(e) : (m ||= fetch(d).then((e) => e.ok ? e.json() : Promise.reject(/* @__PURE__ */ Error(`HTTP ${e.status}`))).then((e) => {
92
+ let t = ie(e);
93
+ return re(t), t;
94
+ }).catch((e) => (console.warn("models.dev pricing unavailable", e), {})).finally(() => {
95
+ m = null;
96
+ }), m);
97
+ }, ae = (e) => {
98
+ let t = e.toLowerCase(), n = t.replace(/-(\d{8}|\d{4}-\d{2}-\d{2})$/, "");
99
+ return [.../* @__PURE__ */ new Set([
100
+ e,
101
+ t,
102
+ n
103
+ ])];
104
+ }, oe = (e, t, n) => {
105
+ for (let r of p[t] ?? []) {
106
+ let t = e[r];
107
+ if (t) for (let e of ae(n)) {
108
+ let n = t[e];
109
+ if (n) return {
110
+ input: n[0],
111
+ output: n[1],
112
+ currency: "USD",
113
+ source: "models.dev"
114
+ };
115
+ }
116
+ }
117
+ }, g = async (e, t) => {
118
+ if (!p[e] || t.every((e) => e.pricing)) return t;
119
+ let n = await h();
120
+ return t.map((t) => {
121
+ if (t.pricing) return t;
122
+ let r = oe(n, e, t.model);
123
+ return r ? {
124
+ ...t,
125
+ pricing: r
126
+ } : t;
127
+ });
128
+ }, _ = class extends Error {
129
+ code;
130
+ provider;
131
+ status;
132
+ constructor(e, t, n, r = {}) {
133
+ super(n, r.cause === void 0 ? void 0 : { cause: r.cause }), this.name = "EmailProviderError", this.code = e, this.provider = t, this.status = r.status;
134
+ }
135
+ }, v = (e) => e === 401 || e === 403 ? "unauthorized" : e === 429 ? "rate-limited" : e === 400 || e === 404 || e === 409 || e === 422 ? "rejected" : e >= 500 ? "unavailable" : "unknown";
136
+ async function y(e, t, n, r) {
137
+ let i;
138
+ try {
139
+ i = await t(n, r);
140
+ } catch (t) {
141
+ throw new _("unavailable", e, `${e} did not answer`, { cause: t });
142
+ }
143
+ if (!i.ok) throw new _(v(i.status), e, `${e} answered ${i.status} on ${new URL(n).pathname}`, { status: i.status });
144
+ let a = await i.text();
145
+ return a ? JSON.parse(a) : {};
146
+ }
147
+ //#endregion
148
+ //#region src/providers/email/EmailSend.ts
149
+ var b = (e) => typeof e == "string" ? { email: e.trim() } : {
150
+ email: e.email.trim(),
151
+ ...e.name ? { name: e.name } : {}
152
+ }, x = (e) => (e === void 0 ? [] : Array.isArray(e) ? e : [e]).map(b).filter((e) => e.email !== ""), S = ({ email: e, name: t }) => t ? `${/[",<>@;:]/.test(t) ? JSON.stringify(t) : t} <${e}>` : e;
153
+ function C(e, t, n, { fromRequired: r = !0 } = {}) {
154
+ let i = t.from ?? n, a = i ? b(i) : void 0;
155
+ if (r && !a?.email) throw new _("not-configured", e, `${e} has no sender`);
156
+ let o = x(t.to), s = x(t.cc), c = x(t.bcc);
157
+ if (o.length + s.length + c.length === 0) throw new _("invalid-message", e, "The message has no recipient");
158
+ if (!t.html && !t.text) throw new _("invalid-message", e, "The message has no body");
159
+ return {
160
+ from: a?.email ? a : void 0,
161
+ to: o,
162
+ cc: s,
163
+ bcc: c,
164
+ replyTo: t.replyTo ? b(t.replyTo) : void 0,
165
+ subject: t.subject,
166
+ html: t.html || void 0,
167
+ text: t.text || void 0,
168
+ threadId: t.threadId
169
+ };
170
+ }
171
+ //#endregion
172
+ //#region src/providers/email/gmail/gmailApi.ts
173
+ var w = "https://gmail.googleapis.com/gmail/v1/users/me", T = "https://oauth2.googleapis.com/token", E = {
174
+ read: "https://www.googleapis.com/auth/gmail.readonly",
175
+ send: "https://www.googleapis.com/auth/gmail.send"
176
+ }, D = "Gmail";
177
+ function O(n, r) {
178
+ return r && "accessToken" in r ? t(n, typeof r.accessToken == "function" ? [] : ["accessToken"]) : t(n, e(r, [
179
+ "clientId",
180
+ "clientSecret",
181
+ "refreshToken"
182
+ ]));
183
+ }
184
+ async function k(e, t) {
185
+ if ("accessToken" in e) return e.accessToken();
186
+ let n = await y(D, t, T, {
187
+ method: "POST",
188
+ headers: { "content-type": "application/x-www-form-urlencoded" },
189
+ body: new URLSearchParams({
190
+ client_id: e.clientId,
191
+ client_secret: e.clientSecret,
192
+ refresh_token: e.refreshToken,
193
+ grant_type: "refresh_token"
194
+ })
195
+ });
196
+ if (!n.access_token) throw new _("unauthorized", D, "Google returned no access token");
197
+ return n.access_token;
198
+ }
199
+ var se = (e) => {
200
+ let t = "";
201
+ for (let n = 0; n < e.length; n += 32768) t += String.fromCharCode(...e.subarray(n, n + 32768));
202
+ return btoa(t);
203
+ }, A = (e) => se(new TextEncoder().encode(e)), j = (e) => A(e).replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, ""), M = (e) => {
204
+ let t = atob(e.replace(/-/g, "+").replace(/_/g, "/"));
205
+ return new TextDecoder().decode(Uint8Array.from(t, (e) => e.charCodeAt(0)));
206
+ }, N = "\r\n", P = (e) => /^[\x20-\x7e]*$/.test(e) ? e : `=?UTF-8?B?${A(e)}?=`, F = (e) => e.name ? `${P(e.name)} <${e.email}>` : S(e), I = (e) => [`Content-Type: ${e}; charset=UTF-8`, "Content-Transfer-Encoding: base64"], L = (e) => (A(e).match(/.{1,76}/g) ?? []).join(N);
207
+ function R(e) {
208
+ let t = [
209
+ e.from ? `From: ${F(e.from)}` : null,
210
+ e.to.length ? `To: ${e.to.map(F).join(", ")}` : null,
211
+ e.cc.length ? `Cc: ${e.cc.map(F).join(", ")}` : null,
212
+ e.bcc.length ? `Bcc: ${e.bcc.map(F).join(", ")}` : null,
213
+ e.replyTo ? `Reply-To: ${F(e.replyTo)}` : null,
214
+ `Subject: ${P(e.subject)}`,
215
+ "MIME-Version: 1.0"
216
+ ].filter((e) => e !== null), n;
217
+ if (e.html && e.text) {
218
+ let r = `llmnative-${Math.random().toString(36).slice(2)}`;
219
+ t.push(`Content-Type: multipart/alternative; boundary="${r}"`);
220
+ let i = (e, t) => [
221
+ `--${r}`,
222
+ ...I(e),
223
+ "",
224
+ L(t)
225
+ ].join(N);
226
+ n = [
227
+ i("text/plain", e.text),
228
+ i("text/html", e.html),
229
+ `--${r}--`
230
+ ].join(N);
231
+ } else t.push(...I(e.html ? "text/html" : "text/plain")), n = L(e.html ?? e.text ?? "");
232
+ return j([
233
+ ...t,
234
+ "",
235
+ n
236
+ ].join(N));
237
+ }
238
+ function z(e, t) {
239
+ if (e) {
240
+ if (e.mimeType === t && e.body?.data) return M(e.body.data);
241
+ for (let n of e.parts ?? []) {
242
+ let e = z(n, t);
243
+ if (e !== void 0) return e;
244
+ }
245
+ }
246
+ }
247
+ function B(e) {
248
+ return z(e, "text/plain") ?? z(e, "text/html")?.replace(/<[^>]*>/g, " ").replace(/\s+/g, " ").trim() ?? "";
249
+ }
250
+ function V(e, t) {
251
+ let n = (t) => String(e.payload?.headers?.find((e) => e.name.toLowerCase() === t)?.value ?? ""), r = e.internalDate ? new Date(Number(e.internalDate)) : new Date(n("date"));
252
+ return {
253
+ id: String(e.id),
254
+ threadId: String(e.threadId ?? e.id),
255
+ from: n("from"),
256
+ to: n("to"),
257
+ subject: n("subject"),
258
+ date: (Number.isNaN(r.getTime()) ? /* @__PURE__ */ new Date() : r).toISOString(),
259
+ text: (B(e.payload) || String(e.snippet ?? "")).trim(),
260
+ direction: (e.labelIds ?? []).includes("SENT") ? "outbound" : "inbound",
261
+ cursor: t
262
+ };
263
+ }
264
+ //#endregion
265
+ //#region src/providers/email/gmail/GmailEmailSender.ts
266
+ var H = class {
267
+ config;
268
+ constructor(e) {
269
+ this.config = e;
270
+ }
271
+ getConfigurationState() {
272
+ return O("GmailEmailSender", this.config.auth);
273
+ }
274
+ isConfigured() {
275
+ return this.getConfigurationState().configured;
276
+ }
277
+ async send(e) {
278
+ let t = this.getConfigurationState();
279
+ if (!t.configured) throw new _("not-configured", D, t.reason ?? "Gmail is not configured");
280
+ let n = C(D, e, this.config.from, { fromRequired: !1 }), r = this.config.fetch ?? globalThis.fetch, i = await k(this.config.auth, r), a = await y(D, r, `${w}/messages/send`, {
281
+ method: "POST",
282
+ headers: {
283
+ authorization: `Bearer ${i}`,
284
+ "content-type": "application/json"
285
+ },
286
+ body: JSON.stringify({
287
+ raw: R(n),
288
+ ...n.threadId ? { threadId: n.threadId } : {}
289
+ })
290
+ });
291
+ return {
292
+ id: String(a.id ?? ""),
293
+ ...a.threadId ? { threadId: String(a.threadId) } : {}
294
+ };
295
+ }
296
+ }, U = [
297
+ "Google Cloud console → APIs & Services → enable the Gmail API.",
298
+ "OAuth consent screen: add the Gmail scopes the app asks for.",
299
+ "Credentials → Create OAuth client ID → Web application, with the redirect URI of the app's server.",
300
+ "In the app, connect the mailbox: Google asks the owner for consent."
301
+ ], W = [
302
+ {
303
+ id: "resend",
304
+ label: "Resend",
305
+ description: "Developer-first transactional email API.",
306
+ credentialFields: [{
307
+ key: "apiKey",
308
+ label: "API Key",
309
+ type: "password",
310
+ placeholder: "re_..."
311
+ }, {
312
+ key: "from",
313
+ label: "Sender",
314
+ type: "text",
315
+ placeholder: "App <noreply@yourdomain.com>"
316
+ }],
317
+ credentialsUrl: "https://resend.com/api-keys",
318
+ credentialsHint: "Resend dashboard → API Keys → Create API Key. The sender's domain must be verified under Domains."
319
+ },
320
+ {
321
+ id: "brevo",
322
+ label: "Brevo",
323
+ description: "Transactional and marketing email, EU-based.",
324
+ credentialFields: [{
325
+ key: "apiKey",
326
+ label: "API Key",
327
+ type: "password",
328
+ placeholder: "xkeysib-..."
329
+ }, {
330
+ key: "from",
331
+ label: "Sender",
332
+ type: "text",
333
+ placeholder: "App <noreply@yourdomain.com>"
334
+ }],
335
+ credentialsUrl: "https://app.brevo.com/settings/keys/api",
336
+ credentialsHint: "Brevo → SMTP & API → API Keys → Generate a new API key. The sender must be verified under Senders, Domains & Dedicated IPs."
337
+ },
338
+ {
339
+ id: "gmail",
340
+ label: "Gmail",
341
+ description: "Send from a Gmail or Google Workspace mailbox, with the owner's consent.",
342
+ credentialFields: [],
343
+ credentialsUrl: "https://console.cloud.google.com/apis/credentials",
344
+ credentialsSteps: U
345
+ },
346
+ {
347
+ id: "sendgrid",
348
+ label: "SendGrid",
349
+ description: "Scalable email delivery by Twilio.",
350
+ credentialFields: [{
351
+ key: "apiKey",
352
+ label: "API Key",
353
+ type: "password",
354
+ placeholder: "SG..."
355
+ }],
356
+ credentialsUrl: "https://app.sendgrid.com/settings/api_keys",
357
+ credentialsHint: "SendGrid dashboard → Settings → API Keys → Create API Key."
358
+ },
359
+ {
360
+ id: "mailgun",
361
+ label: "Mailgun",
362
+ description: "Email API with analytics and webhooks.",
363
+ credentialFields: [{
364
+ key: "apiKey",
365
+ label: "API Key",
366
+ type: "password"
367
+ }, {
368
+ key: "domain",
369
+ label: "Mailgun domain",
370
+ type: "text",
371
+ placeholder: "mg.yourdomain.com"
372
+ }],
373
+ credentialsUrl: "https://app.mailgun.com/settings/api_security/api_keys",
374
+ credentialsHint: "Mailgun dashboard → Security → API Keys. The domain is the sending domain you verified under Sending → Domains."
375
+ },
376
+ {
377
+ id: "postmark",
378
+ label: "Postmark",
379
+ description: "High-deliverability transactional email.",
380
+ credentialFields: [{
381
+ key: "serverToken",
382
+ label: "Server API Token",
383
+ type: "password"
384
+ }],
385
+ credentialsUrl: "https://account.postmarkapp.com/servers",
386
+ credentialsHint: "Postmark → your Server → API Tokens tab (each server has its own token)."
387
+ },
388
+ {
389
+ id: "ses",
390
+ label: "AWS SES",
391
+ description: "Amazon Simple Email Service.",
392
+ credentialFields: [
393
+ {
394
+ key: "accessKeyId",
395
+ label: "Access Key ID",
396
+ type: "text"
397
+ },
398
+ {
399
+ key: "secretAccessKey",
400
+ label: "Secret Access Key",
401
+ type: "password"
402
+ },
403
+ {
404
+ key: "region",
405
+ label: "Region",
406
+ type: "text",
407
+ placeholder: "us-east-1"
408
+ }
409
+ ],
410
+ credentialsUrl: "https://console.aws.amazon.com/iam/home#/security_credentials",
411
+ credentialsHint: "AWS IAM → Security credentials → Access keys, for a user with SES send permissions."
412
+ },
413
+ {
414
+ id: "smtp",
415
+ label: "SMTP",
416
+ description: "Any SMTP-compatible mail server.",
417
+ credentialFields: [
418
+ {
419
+ key: "host",
420
+ label: "Host",
421
+ type: "text",
422
+ placeholder: "smtp.example.com"
423
+ },
424
+ {
425
+ key: "port",
426
+ label: "Port",
427
+ type: "text",
428
+ placeholder: "587"
429
+ },
430
+ {
431
+ key: "username",
432
+ label: "Username",
433
+ type: "text"
434
+ },
435
+ {
436
+ key: "password",
437
+ label: "Password",
438
+ type: "password"
439
+ }
440
+ ],
441
+ credentialsHint: "Ask your mail host or hosting provider for the SMTP host, port, and credentials."
442
+ }
443
+ ], G = [{
444
+ id: "gmail",
445
+ label: "Gmail",
446
+ description: "New mails arrive at once, through a Pub/Sub topic of Google Cloud.",
447
+ credentialFields: [],
448
+ credentialsUrl: "https://console.cloud.google.com/cloudpubsub/topic/list",
449
+ credentialsSteps: [...U, "Pub/Sub: create a topic and give roles/pubsub.publisher on it to gmail-api-push@system.gserviceaccount.com."]
450
+ }, {
451
+ id: "imap",
452
+ label: "IMAP",
453
+ description: "Any other mailbox, read every few minutes.",
454
+ credentialFields: [
455
+ {
456
+ key: "host",
457
+ label: "IMAP server",
458
+ type: "text",
459
+ placeholder: "imap.example.com"
460
+ },
461
+ {
462
+ key: "port",
463
+ label: "Port",
464
+ type: "text",
465
+ placeholder: "993"
466
+ },
467
+ {
468
+ key: "user",
469
+ label: "User",
470
+ type: "text",
471
+ placeholder: "name@example.com"
472
+ },
473
+ {
474
+ key: "password",
475
+ label: "Password",
476
+ type: "password"
477
+ }
478
+ ],
479
+ credentialsHint: "The IMAP settings of your mail provider. Use an app password where the provider has them."
480
+ }], ce = "https://api.resend.com/emails", le = class {
481
+ config;
482
+ constructor(e) {
483
+ this.config = e;
484
+ }
485
+ getConfigurationState() {
486
+ return t("ResendEmailSender", e(this.config, ["apiKey"]));
487
+ }
488
+ isConfigured() {
489
+ return this.getConfigurationState().configured;
490
+ }
491
+ async send(e) {
492
+ if (!this.isConfigured()) throw new _("not-configured", "Resend", "Resend has no API key");
493
+ let t = C("Resend", e, this.config.from), n = (e) => e.length ? e.map(S) : void 0, r = await y("Resend", this.config.fetch ?? globalThis.fetch, ce, {
494
+ method: "POST",
495
+ headers: {
496
+ authorization: `Bearer ${this.config.apiKey}`,
497
+ "content-type": "application/json"
498
+ },
499
+ body: JSON.stringify({
500
+ from: S(t.from),
501
+ to: n(t.to),
502
+ cc: n(t.cc),
503
+ bcc: n(t.bcc),
504
+ reply_to: t.replyTo ? S(t.replyTo) : void 0,
505
+ subject: t.subject,
506
+ html: t.html,
507
+ text: t.text
508
+ })
509
+ });
510
+ return { id: String(r.id ?? "") };
511
+ }
512
+ }, ue = "https://api.brevo.com/v3/smtp/email", K = ({ email: e, name: t }) => t ? {
513
+ email: e,
514
+ name: t
515
+ } : { email: e }, de = class {
516
+ config;
517
+ constructor(e) {
518
+ this.config = e;
519
+ }
520
+ getConfigurationState() {
521
+ return t("BrevoEmailSender", e(this.config, ["apiKey"]));
522
+ }
523
+ isConfigured() {
524
+ return this.getConfigurationState().configured;
525
+ }
526
+ async send(e) {
527
+ if (!this.isConfigured()) throw new _("not-configured", "Brevo", "Brevo has no API key");
528
+ let t = C("Brevo", e, this.config.from), n = (e) => e.length ? e.map(K) : void 0, r = await y("Brevo", this.config.fetch ?? globalThis.fetch, ue, {
529
+ method: "POST",
530
+ headers: {
531
+ "api-key": this.config.apiKey,
532
+ "content-type": "application/json",
533
+ accept: "application/json"
534
+ },
535
+ body: JSON.stringify({
536
+ sender: K(t.from),
537
+ to: n(t.to),
538
+ cc: n(t.cc),
539
+ bcc: n(t.bcc),
540
+ replyTo: t.replyTo ? K(t.replyTo) : void 0,
541
+ subject: t.subject,
542
+ htmlContent: t.html,
543
+ textContent: t.text
544
+ })
545
+ });
546
+ return { id: String(r.messageId ?? "") };
547
+ }
548
+ }, fe = /* @__PURE__ */ new Set(["free", "latest"]), q = /^(\d{4}|\d{8}|\d{4}-\d{2}-\d{2})$/, J = /\s*\(([^()]*)\)\s*$/, pe = /^(thinking|reasoning|non-reasoning|fast)$/i, Y = (e) => {
549
+ let t = e.trim(), n = [];
550
+ for (let e = J.exec(t); e; e = J.exec(t)) pe.test(e[1].trim()) && n.unshift(e[1].trim()), t = t.slice(0, e.index);
551
+ let r = t.toLowerCase().replace(/[()[\]]/g, " ").split(/\s+/).filter(Boolean);
552
+ for (; r.length > 1 && (fe.has(r[r.length - 1]) || q.test(r[r.length - 1]));) r.pop();
553
+ return [...r, ...n.map((e) => e.toLowerCase())].join(" ");
554
+ }, X = ({ id: e, name: t }) => {
555
+ let n = t.toLowerCase().split(/\s+/);
556
+ return (e.startsWith("~") ? 8 : 0) + (n.includes("free") ? 4 : 0) + (n.includes("latest") ? 2 : 0) + +!!q.test(n[n.length - 1] ?? "") + +!!J.test(t);
557
+ }, me = (e, t) => X(e) - X(t) || e.id.length - t.id.length || e.id.localeCompare(t.id);
558
+ function Z(e) {
559
+ let t = {}, n = {};
560
+ for (let [r, { name: i, models: a = {} }] of Object.entries(e)) {
561
+ n[r] = i || r;
562
+ for (let [e, n] of Object.entries(a)) {
563
+ let i = n?.name?.trim() || e, a = Y(i), o = t[a] ??= {
564
+ key: a,
565
+ name: i,
566
+ providers: {}
567
+ };
568
+ !o.family && n?.family && (o.family = n.family);
569
+ let s = n?.cost?.input, c = n?.cost?.output, l = typeof s == "number" && typeof c == "number" ? {
570
+ input: s,
571
+ output: c
572
+ } : void 0;
573
+ (o.providers[r] ??= []).push({
574
+ id: e,
575
+ name: i,
576
+ ...l ? { cost: l } : {}
577
+ }), X({
578
+ id: e,
579
+ name: i
580
+ }) < X({
581
+ id: "",
582
+ name: o.name
583
+ }) && (o.name = i);
584
+ }
585
+ }
586
+ for (let e of Object.values(t)) for (let t of Object.values(e.providers)) t.sort(me);
587
+ return {
588
+ models: t,
589
+ providers: n
590
+ };
591
+ }
592
+ function he(e, t, n) {
593
+ let r = e.models[Y(t)];
594
+ if (r) for (let e of n) {
595
+ let t = r.providers[e]?.[0];
596
+ if (t) return {
597
+ provider: e,
598
+ model: t.id,
599
+ ref: `${e}/${t.id}`
600
+ };
601
+ }
602
+ }
603
+ function ge(e, t, n) {
604
+ let r = e.models[Y(t)];
605
+ return r ? (n ?? Object.keys(r.providers).sort()).flatMap((e) => {
606
+ let t = r.providers[e]?.[0];
607
+ return t ? [{
608
+ provider: e,
609
+ model: t.id,
610
+ ref: `${e}/${t.id}`,
611
+ ...t.cost ? { cost: t.cost } : {}
612
+ }] : [];
613
+ }) : [];
614
+ }
615
+ var Q = null, $ = null;
616
+ function _e(e = globalThis.fetch) {
617
+ return $ ? Promise.resolve($) : (Q ??= e(d).then((e) => e.ok ? e.json() : Promise.reject(/* @__PURE__ */ Error(`models.dev: HTTP ${e.status}`))).then((e) => $ = Z(e)).finally(() => {
618
+ Q = null;
619
+ }), Q);
620
+ }
621
+ //#endregion
622
+ export { n as A, r as C, o as D, ee as E, t as O, l as S, s as T, O as _, he as a, y as b, G as c, w as d, E as f, k as g, M as h, ge as i, e as k, W as l, D as m, Y as n, de as o, T as p, _e as r, le as s, Z as t, H as u, V as v, c as w, g as x, _ as y };
623
+
624
+ //# sourceMappingURL=modelIdentity-CIXNPtTA.mjs.map