prompt-api-polyfill 1.10.0 → 1.12.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 CHANGED
@@ -7,7 +7,7 @@ supporting dynamic backends:
7
7
  - **Firebase AI Logic** (cloud)
8
8
  - **Google Gemini API** (cloud)
9
9
  - **OpenAI API** (cloud)
10
- - **Transformers.js** (local after initial model download)
10
+ - **Transformers.js** (local after initial model download, **default backend**)
11
11
 
12
12
  When loaded in the browser, it defines a global:
13
13
 
@@ -20,6 +20,9 @@ natively available.
20
20
 
21
21
  ## Supported Backends
22
22
 
23
+ You can choose between multiple cloud and local backends. If no backend is
24
+ configured, the polyfill will use Transformers.js with the default model.
25
+
23
26
  ### Firebase AI Logic (cloud)
24
27
 
25
28
  - **Uses**: `firebase/ai` SDK.
@@ -49,6 +52,7 @@ natively available.
49
52
 
50
53
  - **Uses**: `@huggingface/transformers` SDK.
51
54
  - **Select by setting**: `window.TRANSFORMERS_CONFIG`.
55
+ - **Note**: This is the **default backend** if no other configuration is provided.
52
56
  - **Model**: Uses default if not specified (see
53
57
  [`backends/defaults.js`](backends/defaults.js)).
54
58
 
@@ -1,6 +1,6 @@
1
1
  import { initializeApp as Fe } from "firebase/app";
2
2
  import { VertexAIBackend as ze, GoogleAIBackend as Ue, getAI as je, getGenerativeModel as Ve, InferenceMode as We } from "firebase/ai";
3
- import { P as Ke, D as Ge } from "../chunks/defaults-_qJIFiOb.js";
3
+ import { P as Ke, D as Ge } from "../chunks/defaults-j68Er1oH.js";
4
4
  const qe = () => {
5
5
  };
6
6
  const be = function(t) {
@@ -89,9 +89,9 @@ const be = function(t) {
89
89
  this.init_();
90
90
  const r = e ? this.byteToCharMapWebSafe_ : this.byteToCharMap_, n = [];
91
91
  for (let s = 0; s < t.length; s += 3) {
92
- const o = t[s], i = s + 1 < t.length, c = i ? t[s + 1] : 0, a = s + 2 < t.length, l = a ? t[s + 2] : 0, y = o >> 2, f = (o & 3) << 4 | c >> 4;
92
+ const o = t[s], i = s + 1 < t.length, c = i ? t[s + 1] : 0, a = s + 2 < t.length, l = a ? t[s + 2] : 0, p = o >> 2, f = (o & 3) << 4 | c >> 4;
93
93
  let k = (c & 15) << 2 | l >> 6, S = l & 63;
94
- a || (S = 64, i || (k = 64)), n.push(r[y], r[f], r[k], r[S]);
94
+ a || (S = 64, i || (k = 64)), n.push(r[p], r[f], r[k], r[S]);
95
95
  }
96
96
  return n.join("");
97
97
  },
@@ -321,7 +321,7 @@ function dt(t, e = at, r = ct) {
321
321
  function ut(t) {
322
322
  return t && t._delegate ? t._delegate : t;
323
323
  }
324
- class w {
324
+ class y {
325
325
  /**
326
326
  *
327
327
  * @param name The public service name, e.g. app, auth, firestore, database
@@ -344,7 +344,7 @@ class w {
344
344
  return this.onInstanceCreated = e, this;
345
345
  }
346
346
  }
347
- const E = "[DEFAULT]";
347
+ const _ = "[DEFAULT]";
348
348
  class ft {
349
349
  constructor(e, r) {
350
350
  this.name = e, this.container = r, this.component = null, this.instances = /* @__PURE__ */ new Map(), this.instancesDeferred = /* @__PURE__ */ new Map(), this.instancesOptions = /* @__PURE__ */ new Map(), this.onInitCallbacks = /* @__PURE__ */ new Map();
@@ -397,7 +397,7 @@ class ft {
397
397
  if (this.component = e, !!this.shouldAutoInitialize()) {
398
398
  if (gt(e))
399
399
  try {
400
- this.getOrInitializeService({ instanceIdentifier: E });
400
+ this.getOrInitializeService({ instanceIdentifier: _ });
401
401
  } catch {
402
402
  }
403
403
  for (const [r, n] of this.instancesDeferred.entries()) {
@@ -412,7 +412,7 @@ class ft {
412
412
  }
413
413
  }
414
414
  }
415
- clearInstance(e = E) {
415
+ clearInstance(e = _) {
416
416
  this.instancesDeferred.delete(e), this.instancesOptions.delete(e), this.instances.delete(e);
417
417
  }
418
418
  // app.delete() will call this method on every provider to delete the services
@@ -427,10 +427,10 @@ class ft {
427
427
  isComponentSet() {
428
428
  return this.component != null;
429
429
  }
430
- isInitialized(e = E) {
430
+ isInitialized(e = _) {
431
431
  return this.instances.has(e);
432
432
  }
433
- getOptions(e = E) {
433
+ getOptions(e = _) {
434
434
  return this.instancesOptions.get(e) || {};
435
435
  }
436
436
  initialize(e = {}) {
@@ -490,15 +490,15 @@ class ft {
490
490
  }
491
491
  return n || null;
492
492
  }
493
- normalizeInstanceIdentifier(e = E) {
494
- return this.component ? this.component.multipleInstances ? e : E : e;
493
+ normalizeInstanceIdentifier(e = _) {
494
+ return this.component ? this.component.multipleInstances ? e : _ : e;
495
495
  }
496
496
  shouldAutoInitialize() {
497
497
  return !!this.component && this.component.instantiationMode !== "EXPLICIT";
498
498
  }
499
499
  }
500
500
  function pt(t) {
501
- return t === E ? void 0 : t;
501
+ return t === _ ? void 0 : t;
502
502
  }
503
503
  function gt(t) {
504
504
  return t.instantiationMode === "EAGER";
@@ -647,7 +647,7 @@ function Tt(t) {
647
647
  const s = () => {
648
648
  t.removeEventListener("success", o), t.removeEventListener("error", i);
649
649
  }, o = () => {
650
- r(m(t.result)), s();
650
+ r(b(t.result)), s();
651
651
  }, i = () => {
652
652
  n(t.error), s();
653
653
  };
@@ -683,7 +683,7 @@ let U = {
683
683
  if (e === "store")
684
684
  return r.objectStoreNames[1] ? void 0 : r.objectStore(r.objectStoreNames[0]);
685
685
  }
686
- return m(t[e]);
686
+ return b(t[e]);
687
687
  },
688
688
  set(t, e, r) {
689
689
  return t[e] = r, !0;
@@ -698,17 +698,17 @@ function Dt(t) {
698
698
  function kt(t) {
699
699
  return t === IDBDatabase.prototype.transaction && !("objectStoreNames" in IDBTransaction.prototype) ? function(e, ...r) {
700
700
  const n = t.call(N(this), e, ...r);
701
- return Ie.set(n, e.sort ? e.sort() : [e]), m(n);
701
+ return Ie.set(n, e.sort ? e.sort() : [e]), b(n);
702
702
  } : It().includes(t) ? function(...e) {
703
- return t.apply(N(this), e), m(Ae.get(this));
703
+ return t.apply(N(this), e), b(Ae.get(this));
704
704
  } : function(...e) {
705
- return m(t.apply(N(this), e));
705
+ return b(t.apply(N(this), e));
706
706
  };
707
707
  }
708
708
  function St(t) {
709
709
  return typeof t == "function" ? kt(t) : (t instanceof IDBTransaction && Ct(t), yt(t, At()) ? new Proxy(t, U) : t);
710
710
  }
711
- function m(t) {
711
+ function b(t) {
712
712
  if (t instanceof IDBRequest)
713
713
  return Tt(t);
714
714
  if (O.has(t))
@@ -718,9 +718,9 @@ function m(t) {
718
718
  }
719
719
  const N = (t) => J.get(t);
720
720
  function vt(t, e, { blocked: r, upgrade: n, blocking: s, terminated: o } = {}) {
721
- const i = indexedDB.open(t, e), c = m(i);
721
+ const i = indexedDB.open(t, e), c = b(i);
722
722
  return n && i.addEventListener("upgradeneeded", (a) => {
723
- n(m(i.result), a.oldVersion, a.newVersion, m(i.transaction), a);
723
+ n(b(i.result), a.oldVersion, a.newVersion, b(i.transaction), a);
724
724
  }), r && i.addEventListener("blocked", (a) => r(
725
725
  // Casting due to https://github.com/microsoft/TypeScript-DOM-lib-generator/pull/1405
726
726
  a.oldVersion,
@@ -777,8 +777,8 @@ class Pt {
777
777
  function Mt(t) {
778
778
  return t.getComponent()?.type === "VERSION";
779
779
  }
780
- const j = "@firebase/app", ae = "0.14.8";
781
- const p = new ye("@firebase/app"), Ot = "@firebase/app-compat", Nt = "@firebase/analytics-compat", $t = "@firebase/analytics", xt = "@firebase/app-check-compat", Lt = "@firebase/app-check", Ht = "@firebase/auth", Ft = "@firebase/auth-compat", zt = "@firebase/database", Ut = "@firebase/data-connect", jt = "@firebase/database-compat", Vt = "@firebase/functions", Wt = "@firebase/functions-compat", Kt = "@firebase/installations", Gt = "@firebase/installations-compat", qt = "@firebase/messaging", Xt = "@firebase/messaging-compat", Yt = "@firebase/performance", Jt = "@firebase/performance-compat", Zt = "@firebase/remote-config", Qt = "@firebase/remote-config-compat", er = "@firebase/storage", tr = "@firebase/storage-compat", rr = "@firebase/firestore", nr = "@firebase/ai", sr = "@firebase/firestore-compat", or = "firebase";
780
+ const j = "@firebase/app", ae = "0.14.9";
781
+ const g = new ye("@firebase/app"), Ot = "@firebase/app-compat", Nt = "@firebase/analytics-compat", $t = "@firebase/analytics", xt = "@firebase/app-check-compat", Lt = "@firebase/app-check", Ht = "@firebase/auth", Ft = "@firebase/auth-compat", zt = "@firebase/database", Ut = "@firebase/data-connect", jt = "@firebase/database-compat", Vt = "@firebase/functions", Wt = "@firebase/functions-compat", Kt = "@firebase/installations", Gt = "@firebase/installations-compat", qt = "@firebase/messaging", Xt = "@firebase/messaging-compat", Yt = "@firebase/performance", Jt = "@firebase/performance-compat", Zt = "@firebase/remote-config", Qt = "@firebase/remote-config-compat", er = "@firebase/storage", tr = "@firebase/storage-compat", rr = "@firebase/firestore", nr = "@firebase/ai", sr = "@firebase/firestore-compat", or = "firebase";
782
782
  const V = "[DEFAULT]", ir = {
783
783
  [j]: "fire-core",
784
784
  [Ot]: "fire-core-compat",
@@ -815,13 +815,13 @@ function ce(t, e) {
815
815
  try {
816
816
  t.container.addComponent(e);
817
817
  } catch (r) {
818
- p.debug(`Component ${e.name} failed to register with FirebaseApp ${t.name}`, r);
818
+ g.debug(`Component ${e.name} failed to register with FirebaseApp ${t.name}`, r);
819
819
  }
820
820
  }
821
821
  function I(t) {
822
822
  const e = t.name;
823
823
  if (W.has(e))
824
- return p.debug(`There were multiple attempts to register component ${e}.`), !1;
824
+ return g.debug(`There were multiple attempts to register component ${e}.`), !1;
825
825
  W.set(e, t);
826
826
  for (const r of P.values())
827
827
  ce(r, t);
@@ -848,10 +848,10 @@ const cr = {
848
848
  "idb-delete": "Error thrown when deleting from IndexedDB. Original error: {$originalErrorMessage}.",
849
849
  "finalization-registry-not-supported": "FirebaseServerApp deleteOnDeref field defined but the JS runtime does not support FinalizationRegistry.",
850
850
  "invalid-server-app-environment": "FirebaseServerApp is not for use in browser environments."
851
- }, b = new Y("app", "Firebase", cr);
851
+ }, E = new Y("app", "Firebase", cr);
852
852
  class lr {
853
853
  constructor(e, r, n) {
854
- this._isDeleted = !1, this._options = { ...e }, this._config = { ...r }, this._name = r.name, this._automaticDataCollectionEnabled = r.automaticDataCollectionEnabled, this._container = n, this.container.addComponent(new w(
854
+ this._isDeleted = !1, this._options = { ...e }, this._config = { ...r }, this._name = r.name, this._automaticDataCollectionEnabled = r.automaticDataCollectionEnabled, this._container = n, this.container.addComponent(new y(
855
855
  "app",
856
856
  () => this,
857
857
  "PUBLIC"
@@ -888,7 +888,7 @@ class lr {
888
888
  */
889
889
  checkDestroyed() {
890
890
  if (this.isDeleted)
891
- throw b.create("app-deleted", { appName: this._name });
891
+ throw E.create("app-deleted", { appName: this._name });
892
892
  }
893
893
  }
894
894
  function hr(t, e = {}) {
@@ -900,11 +900,11 @@ function hr(t, e = {}) {
900
900
  ...e
901
901
  }, s = n.name;
902
902
  if (typeof s != "string" || !s)
903
- throw b.create("bad-app-name", {
903
+ throw E.create("bad-app-name", {
904
904
  appName: String(s)
905
905
  });
906
906
  if (r || (r = we()), !r)
907
- throw b.create(
907
+ throw E.create(
908
908
  "no-options"
909
909
  /* AppError.NO_OPTIONS */
910
910
  );
@@ -912,7 +912,7 @@ function hr(t, e = {}) {
912
912
  if (o) {
913
913
  if (F(r, o.options) && F(n, o.config))
914
914
  return o;
915
- throw b.create("duplicate-app", { appName: s });
915
+ throw E.create("duplicate-app", { appName: s });
916
916
  }
917
917
  const i = new mt(s);
918
918
  for (const a of W.values())
@@ -925,7 +925,7 @@ function dr(t = V) {
925
925
  if (!e && t === V && we())
926
926
  return hr();
927
927
  if (!e)
928
- throw b.create("no-app", { appName: t });
928
+ throw E.create("no-app", { appName: t });
929
929
  return e;
930
930
  }
931
931
  function B(t, e, r) {
@@ -936,10 +936,10 @@ function B(t, e, r) {
936
936
  const i = [
937
937
  `Unable to register library "${n}" with version "${e}":`
938
938
  ];
939
- s && i.push(`library name "${n}" contains illegal characters (whitespace or "/")`), s && o && i.push("and"), o && i.push(`version name "${e}" contains illegal characters (whitespace or "/")`), p.warn(i.join(" "));
939
+ s && i.push(`library name "${n}" contains illegal characters (whitespace or "/")`), s && o && i.push("and"), o && i.push(`version name "${e}" contains illegal characters (whitespace or "/")`), g.warn(i.join(" "));
940
940
  return;
941
941
  }
942
- I(new w(
942
+ I(new y(
943
943
  `${n}-version`,
944
944
  () => ({ library: n, version: e }),
945
945
  "VERSION"
@@ -961,7 +961,7 @@ function Ce() {
961
961
  }
962
962
  }
963
963
  }).catch((t) => {
964
- throw b.create("idb-open", {
964
+ throw E.create("idb-open", {
965
965
  originalErrorMessage: t.message
966
966
  });
967
967
  })), x;
@@ -972,12 +972,12 @@ async function pr(t) {
972
972
  return await r.done, n;
973
973
  } catch (e) {
974
974
  if (e instanceof D)
975
- p.warn(e.message);
975
+ g.warn(e.message);
976
976
  else {
977
- const r = b.create("idb-get", {
977
+ const r = E.create("idb-get", {
978
978
  originalErrorMessage: e?.message
979
979
  });
980
- p.warn(r.message);
980
+ g.warn(r.message);
981
981
  }
982
982
  }
983
983
  }
@@ -987,12 +987,12 @@ async function le(t, e) {
987
987
  await n.objectStore(T).put(e, De(t)), await n.done;
988
988
  } catch (r) {
989
989
  if (r instanceof D)
990
- p.warn(r.message);
990
+ g.warn(r.message);
991
991
  else {
992
- const n = b.create("idb-set", {
992
+ const n = E.create("idb-set", {
993
993
  originalErrorMessage: r?.message
994
994
  });
995
- p.warn(n.message);
995
+ g.warn(n.message);
996
996
  }
997
997
  }
998
998
  }
@@ -1024,7 +1024,7 @@ class br {
1024
1024
  }
1025
1025
  return this._storage.overwrite(this._heartbeatsCache);
1026
1026
  } catch (e) {
1027
- p.warn(e);
1027
+ g.warn(e);
1028
1028
  }
1029
1029
  }
1030
1030
  /**
@@ -1041,7 +1041,7 @@ class br {
1041
1041
  const e = he(), { heartbeatsToSend: r, unsentEntries: n } = Er(this._heartbeatsCache.heartbeats), s = Ee(JSON.stringify({ version: 2, heartbeats: r }));
1042
1042
  return this._heartbeatsCache.lastSentHeartbeatDate = e, n.length > 0 ? (this._heartbeatsCache.heartbeats = n, await this._storage.overwrite(this._heartbeatsCache)) : (this._heartbeatsCache.heartbeats = [], this._storage.overwrite(this._heartbeatsCache)), s;
1043
1043
  } catch (e) {
1044
- return p.warn(e), "";
1044
+ return g.warn(e), "";
1045
1045
  }
1046
1046
  }
1047
1047
  }
@@ -1130,12 +1130,12 @@ function wr(t) {
1130
1130
  return e;
1131
1131
  }
1132
1132
  function yr(t) {
1133
- I(new w(
1133
+ I(new y(
1134
1134
  "platform-logger",
1135
1135
  (e) => new Pt(e),
1136
1136
  "PRIVATE"
1137
1137
  /* ComponentType.PRIVATE */
1138
- )), I(new w(
1138
+ )), I(new y(
1139
1139
  "heartbeat",
1140
1140
  (e) => new br(e),
1141
1141
  "PRIVATE"
@@ -1281,11 +1281,11 @@ async function Q({ url: t, body: e }, r) {
1281
1281
  throw u.create("fetch-parse-error", {
1282
1282
  originalErrorMessage: `ttl field (timeToLive) is not in standard Protobuf Duration format: ${c.ttl}`
1283
1283
  });
1284
- const l = Number(a[1]) * 1e3, y = Date.now();
1284
+ const l = Number(a[1]) * 1e3, p = Date.now();
1285
1285
  return {
1286
1286
  token: c.token,
1287
- expireTimeMillis: y + l,
1288
- issuedAtTimeMillis: y
1287
+ expireTimeMillis: p + l,
1288
+ issuedAtTimeMillis: p
1289
1289
  };
1290
1290
  }
1291
1291
  function Rr(t, e) {
@@ -1375,21 +1375,21 @@ async function Oe(t) {
1375
1375
  function Ne(t) {
1376
1376
  return `${t.options.appId}-${t.name}`;
1377
1377
  }
1378
- const g = new ye("@firebase/app-check");
1378
+ const m = new ye("@firebase/app-check");
1379
1379
  async function xr(t) {
1380
1380
  if (X()) {
1381
1381
  let e;
1382
1382
  try {
1383
1383
  e = await Mr(t);
1384
1384
  } catch (r) {
1385
- g.warn(`Failed to read token from IndexedDB. Error: ${r}`);
1385
+ m.warn(`Failed to read token from IndexedDB. Error: ${r}`);
1386
1386
  }
1387
1387
  return e;
1388
1388
  }
1389
1389
  }
1390
1390
  function L(t, e) {
1391
1391
  return X() ? Or(t, e).catch((r) => {
1392
- g.warn(`Failed to write token to IndexedDB. Error: ${r}`);
1392
+ m.warn(`Failed to write token to IndexedDB. Error: ${r}`);
1393
1393
  }) : Promise.resolve();
1394
1394
  }
1395
1395
  async function Lr() {
@@ -1402,7 +1402,7 @@ async function Lr() {
1402
1402
  return t;
1403
1403
  {
1404
1404
  const e = crypto.randomUUID();
1405
- return Nr(e).catch((r) => g.warn(`Failed to persist debug token to IndexedDB. Error: ${r}`)), e;
1405
+ return Nr(e).catch((r) => m.warn(`Failed to persist debug token to IndexedDB. Error: ${r}`)), e;
1406
1406
  }
1407
1407
  }
1408
1408
  function ee() {
@@ -1437,34 +1437,35 @@ async function G(t, e = !1, r = !1) {
1437
1437
  Z(n);
1438
1438
  const s = d(n);
1439
1439
  let o = s.token, i;
1440
- if (o && !_(o) && (s.token = void 0, o = void 0), !o) {
1440
+ if (o && !w(o) && (s.token = void 0, o = void 0), !o) {
1441
1441
  const l = await s.cachedTokenPromise;
1442
- l && (_(l) ? o = l : await L(n, void 0));
1442
+ l && (w(l) ? o = l : await L(n, void 0));
1443
1443
  }
1444
- if (!e && o && _(o))
1444
+ if (!e && o && w(o))
1445
1445
  return {
1446
1446
  token: o.token
1447
1447
  };
1448
1448
  let c = !1;
1449
1449
  if (ee())
1450
1450
  try {
1451
- s.exchangeTokenPromise || (s.exchangeTokenPromise = Q(Re(n, await te()), t.heartbeatServiceProvider).finally(() => {
1451
+ const l = await te();
1452
+ s.exchangeTokenPromise || (s.exchangeTokenPromise = Q(Re(n, l), t.heartbeatServiceProvider).finally(() => {
1452
1453
  s.exchangeTokenPromise = void 0;
1453
1454
  }), c = !0);
1454
- const l = await s.exchangeTokenPromise;
1455
- return await L(n, l), s.token = l, { token: l.token };
1455
+ const p = await s.exchangeTokenPromise;
1456
+ return await L(n, p), s.token = p, { token: p.token };
1456
1457
  } catch (l) {
1457
- return l.code === "appCheck/throttled" || l.code === "appCheck/initial-throttle" ? g.warn(l.message) : r && g.error(l), H(l);
1458
+ return l.code === "appCheck/throttled" || l.code === "appCheck/initial-throttle" ? m.warn(l.message) : r && m.error(l), H(l);
1458
1459
  }
1459
1460
  try {
1460
1461
  s.exchangeTokenPromise || (s.exchangeTokenPromise = s.provider.getToken().finally(() => {
1461
1462
  s.exchangeTokenPromise = void 0;
1462
1463
  }), c = !0), o = await d(n).exchangeTokenPromise;
1463
1464
  } catch (l) {
1464
- l.code === "appCheck/throttled" || l.code === "appCheck/initial-throttle" ? g.warn(l.message) : r && g.error(l), i = l;
1465
+ l.code === "appCheck/throttled" || l.code === "appCheck/initial-throttle" ? m.warn(l.message) : r && m.error(l), i = l;
1465
1466
  }
1466
1467
  let a;
1467
- return o ? i ? _(o) ? a = {
1468
+ return o ? i ? w(o) ? a = {
1468
1469
  token: o.token,
1469
1470
  internalError: i
1470
1471
  } : a = H(i) : (a = {
@@ -1489,7 +1490,7 @@ function $e(t, e, r, n) {
1489
1490
  error: n,
1490
1491
  type: e
1491
1492
  };
1492
- if (o.tokenObservers = [...o.tokenObservers, i], o.token && _(o.token)) {
1493
+ if (o.tokenObservers = [...o.tokenObservers, i], o.token && w(o.token)) {
1493
1494
  const c = o.token;
1494
1495
  Promise.resolve().then(() => {
1495
1496
  r({ token: c.token }), pe(t);
@@ -1542,7 +1543,7 @@ function Le(t, e) {
1542
1543
  } catch {
1543
1544
  }
1544
1545
  }
1545
- function _(t) {
1546
+ function w(t) {
1546
1547
  return t.expireTimeMillis - Date.now() > 0;
1547
1548
  }
1548
1549
  function H(t) {
@@ -1573,7 +1574,7 @@ function Kr(t) {
1573
1574
  removeTokenListener: (e) => xe(t.app, e)
1574
1575
  };
1575
1576
  }
1576
- const Gr = "@firebase/app-check", qr = "0.11.0", Xr = "https://www.google.com/recaptcha/enterprise.js";
1577
+ const Gr = "@firebase/app-check", qr = "0.11.1", Xr = "https://www.google.com/recaptcha/enterprise.js";
1577
1578
  function Yr(t, e) {
1578
1579
  const r = new A(), n = d(t);
1579
1580
  n.reCAPTCHAState = { initialized: r };
@@ -1728,11 +1729,11 @@ function nn(t = dr(), e) {
1728
1729
  }
1729
1730
  function sn(t, e, r = !1) {
1730
1731
  const n = Ir(t, { ...ke });
1731
- n.activated = !0, n.provider = e, n.cachedTokenPromise = xr(t).then((s) => (s && _(s) && (n.token = s, Le(t, { token: s.token })), s)), n.isTokenAutoRefreshEnabled = r && t.automaticDataCollectionEnabled, !t.automaticDataCollectionEnabled && r && g.warn("`isTokenAutoRefreshEnabled` is true but `automaticDataCollectionEnabled` was set to false during `initializeApp()`. This blocks automatic token refresh."), n.provider.initialize(t);
1732
+ n.activated = !0, n.provider = e, n.cachedTokenPromise = xr(t).then((s) => (s && w(s) && (n.token = s, Le(t, { token: s.token })), s)), n.isTokenAutoRefreshEnabled = r && t.automaticDataCollectionEnabled, !t.automaticDataCollectionEnabled && r && m.warn("`isTokenAutoRefreshEnabled` is true but `automaticDataCollectionEnabled` was set to false during `initializeApp()`. This blocks automatic token refresh."), n.provider.initialize(t);
1732
1733
  }
1733
1734
  const on = "app-check", me = "app-check-internal";
1734
1735
  function an() {
1735
- I(new w(
1736
+ I(new y(
1736
1737
  on,
1737
1738
  (t) => {
1738
1739
  const e = t.getProvider("app").getImmediate(), r = t.getProvider("heartbeat");
@@ -1745,7 +1746,7 @@ function an() {
1745
1746
  /* InstantiationMode.EXPLICIT */
1746
1747
  ).setInstanceCreatedCallback((t, e, r) => {
1747
1748
  t.getProvider(me).initialize();
1748
- })), I(new w(
1749
+ })), I(new y(
1749
1750
  me,
1750
1751
  (t) => {
1751
1752
  const e = t.getProvider("app-check").getImmediate();
@@ -1761,7 +1762,6 @@ function an() {
1761
1762
  an();
1762
1763
  class dn extends Ke {
1763
1764
  #e;
1764
- #t;
1765
1765
  constructor(e) {
1766
1766
  const {
1767
1767
  geminiApiProvider: r,
@@ -1783,19 +1783,40 @@ class dn extends Ke {
1783
1783
  useLimitedUseAppCheckTokens: i || !0
1784
1784
  });
1785
1785
  }
1786
+ /**
1787
+ * Creates a model session and stores it.
1788
+ * @param {Object} _options - LanguageModel options.
1789
+ * @param {Object} sessionParams - Parameters for the cloud or local model.
1790
+ * @returns {any} The created session object.
1791
+ */
1786
1792
  createSession(e, r) {
1787
- return this.#t = r, this.#e = Ve(this.ai, {
1793
+ return this.#e = Ve(this.ai, {
1788
1794
  mode: We.ONLY_IN_CLOUD,
1789
1795
  inCloudParams: r
1790
1796
  }), this.#e;
1791
1797
  }
1798
+ /**
1799
+ * Generates content (non-streaming).
1800
+ * @param {Array} contents - The history + new message content.
1801
+ * @returns {Promise<{text: string, usage: number}>}
1802
+ */
1792
1803
  async generateContent(e) {
1793
1804
  const r = await this.#e.generateContent({ contents: e }), n = r.response.usageMetadata?.promptTokenCount || 0;
1794
1805
  return { text: r.response.text(), usage: n };
1795
1806
  }
1807
+ /**
1808
+ * Generates content stream.
1809
+ * @param {Array} contents - The history + new content.
1810
+ * @returns {Promise<AsyncIterable>} Stream of chunks.
1811
+ */
1796
1812
  async generateContentStream(e) {
1797
1813
  return (await this.#e.generateContentStream({ contents: e })).stream;
1798
1814
  }
1815
+ /**
1816
+ * Counts tokens.
1817
+ * @param {Array} contents - The content to count.
1818
+ * @returns {Promise<number>} Total tokens.
1819
+ */
1799
1820
  async countTokens(e) {
1800
1821
  const { totalTokens: r } = await this.#e.countTokens({
1801
1822
  contents: e
@@ -1,5 +1,5 @@
1
1
  import { GoogleGenAI as s } from "@google/genai";
2
- import { P as a, D as i } from "../chunks/defaults-_qJIFiOb.js";
2
+ import { P as a, D as i } from "../chunks/defaults-j68Er1oH.js";
3
3
  class u extends a {
4
4
  #n;
5
5
  #e;
@@ -7,9 +7,20 @@ class u extends a {
7
7
  constructor(t) {
8
8
  super(t.modelName || i.gemini.modelName), this.#n = new s({ apiKey: t.apiKey });
9
9
  }
10
+ /**
11
+ * Creates a model session.
12
+ * @param {Object} options - LanguageModel options.
13
+ * @param {Object} sessionParams - Session parameters.
14
+ * @returns {Object} The session object.
15
+ */
10
16
  createSession(t, e) {
11
17
  return this.#t = e, this.#e = t.modelName || this.modelName, { model: this.#e, params: e };
12
18
  }
19
+ /**
20
+ * Generates content (non-streaming).
21
+ * @param {Array} contents - The history + new message content.
22
+ * @returns {Promise<{text: string, usage: number}>}
23
+ */
13
24
  async generateContent(t) {
14
25
  const e = {
15
26
  systemInstruction: this.#t.systemInstruction,
@@ -22,6 +33,11 @@ class u extends a {
22
33
  }), o = n.usageMetadata?.promptTokenCount || 0;
23
34
  return { text: n.text, usage: o };
24
35
  }
36
+ /**
37
+ * Generates content stream.
38
+ * @param {Array} contents - The history + new content.
39
+ * @returns {Promise<AsyncIterable>} Stream of chunks.
40
+ */
25
41
  async generateContentStream(t) {
26
42
  const e = {
27
43
  systemInstruction: this.#t.systemInstruction,
@@ -42,6 +58,11 @@ class u extends a {
42
58
  };
43
59
  })();
44
60
  }
61
+ /**
62
+ * Counts tokens.
63
+ * @param {Array} contents - The content to count.
64
+ * @returns {Promise<number>} Total tokens.
65
+ */
45
66
  async countTokens(t) {
46
67
  const { totalTokens: e } = await this.#n.models.countTokens({
47
68
  model: this.#e,
@@ -1,5 +1,5 @@
1
1
  import u from "openai";
2
- import { P as m, D as l } from "../chunks/defaults-_qJIFiOb.js";
2
+ import { P as m, D as l } from "../chunks/defaults-j68Er1oH.js";
3
3
  class y extends m {
4
4
  #e;
5
5
  constructor(t) {
@@ -21,6 +21,12 @@ class y extends m {
21
21
  }
22
22
  return "available";
23
23
  }
24
+ /**
25
+ * Creates a model session and stores it.
26
+ * @param {Object} options - LanguageModel options.
27
+ * @param {Object} sessionParams - Parameters for the cloud or local model.
28
+ * @returns {any} The created session object.
29
+ */
24
30
  createSession(t, s) {
25
31
  this.#e = {
26
32
  model: t.modelName || this.modelName,
@@ -93,6 +99,11 @@ class y extends m {
93
99
  #s(t) {
94
100
  return this.#e.model !== this.modelName ? this.#e.model : t ? `${this.modelName}-audio-preview` : this.modelName;
95
101
  }
102
+ /**
103
+ * Generates content (non-streaming).
104
+ * @param {Array} contents - The history + new message content.
105
+ * @returns {Promise<{text: string, usage: number}>}
106
+ */
96
107
  async generateContent(t) {
97
108
  const { messages: s } = this.#r(
98
109
  t,
@@ -117,12 +128,17 @@ class y extends m {
117
128
  c && typeof c == "object" && "value" in c && (i = JSON.stringify(c.value));
118
129
  } catch {
119
130
  }
120
- const n = a.usage?.prompt_tokens || 0;
121
- return { text: i, usage: n };
131
+ const p = a.usage?.prompt_tokens || 0;
132
+ return { text: i, usage: p };
122
133
  } catch (a) {
123
134
  throw console.error("OpenAI Generate Content Error:", a), a;
124
135
  }
125
136
  }
137
+ /**
138
+ * Generates content stream.
139
+ * @param {Array} contents - The history + new content.
140
+ * @returns {Promise<AsyncIterable>} Stream of chunks.
141
+ */
126
142
  async generateContentStream(t) {
127
143
  const { messages: s } = this.#r(
128
144
  t,
@@ -142,11 +158,10 @@ class y extends m {
142
158
  try {
143
159
  const a = await this.openai.chat.completions.create(o);
144
160
  return (async function* () {
145
- let p = !0;
146
- for await (const i of a) {
147
- let n = i.choices[0]?.delta?.content;
148
- n && (yield {
149
- text: () => n,
161
+ for await (const n of a) {
162
+ let i = n.choices[0]?.delta?.content;
163
+ i && (yield {
164
+ text: () => i,
150
165
  usageMetadata: { totalTokenCount: 0 }
151
166
  });
152
167
  }
@@ -155,6 +170,11 @@ class y extends m {
155
170
  throw console.error("OpenAI Generate Content Stream Error:", a), a;
156
171
  }
157
172
  }
173
+ /**
174
+ * Counts tokens.
175
+ * @param {Array} contents - The content to count.
176
+ * @returns {Promise<number>} Total tokens.
177
+ */
158
178
  async countTokens(t) {
159
179
  let s = "";
160
180
  if (Array.isArray(t)) {
@@ -173,19 +193,19 @@ class y extends m {
173
193
  });
174
194
  for (const e of t) {
175
195
  const o = e.role === "model" ? "assistant" : "user", a = [];
176
- for (const p of e.parts)
177
- if (p.text)
178
- a.push({ type: "text", text: p.text });
179
- else if (p.inlineData) {
180
- const { data: i, mimeType: n } = p.inlineData;
181
- n.startsWith("image/") ? a.push({
196
+ for (const n of e.parts)
197
+ if (n.text)
198
+ a.push({ type: "text", text: n.text });
199
+ else if (n.inlineData) {
200
+ const { data: i, mimeType: p } = n.inlineData;
201
+ p.startsWith("image/") ? a.push({
182
202
  type: "image_url",
183
- image_url: { url: `data:${n};base64,${i}` }
184
- }) : n.startsWith("audio/") && a.push({
203
+ image_url: { url: `data:${p};base64,${i}` }
204
+ }) : p.startsWith("audio/") && a.push({
185
205
  type: "input_audio",
186
206
  input_audio: {
187
207
  data: i,
188
- format: n.split("/")[1] === "mpeg" ? "mp3" : "wav"
208
+ format: p.split("/")[1] === "mpeg" ? "mp3" : "wav"
189
209
  }
190
210
  });
191
211
  }