Skip to content

Instantly share code, notes, and snippets.

@nezort11
Created February 13, 2024 14:14
Show Gist options
  • Save nezort11/33f8e4bb0b0913e0f99cc4104375ba6c to your computer and use it in GitHub Desktop.
Save nezort11/33f8e4bb0b0913e0f99cc4104375ba6c to your computer and use it in GitHub Desktop.
import { S as P, i as V, s as R, C as K, a as U, c as M, b as k, G, H as x, I as j, g as Y, d as z, h as H, K as X, o as Q, P as Z, $ as p, Z as q, _ as J } from "./index.ff0009f4.js";
import { l as T, L as W, b as o, Q as N, S as d } from "./common-text.425980d7.js";
import { w as B, j as $ } from "./singletons.725ad3fb.js";
import { H as ee } from "./control.f5b05b5f.js";
function te(e) {
let t, r;
const a = e[4].default,
i = K(a, e, e[3], null);
return {
c() {
i && i.c(), (t = U());
},
l(s) {
i && i.l(s), (t = M(s));
},
m(s, _) {
i && i.m(s, _), k(s, t, _), (r = !0);
},
p(s, [_]) {
i && i.p && (!r || _ & 8) && G(i, a, s, s[3], r ? j(a, s[3], _, null) : x(s[3]), null);
},
i(s) {
r || (Y(i, s), (r = !0));
},
o(s) {
z(i, s), (r = !1);
},
d(s) {
i && i.d(s), s && H(t);
},
};
}
const re = { componentName: "YandexMetrika" },
ne = (e, t) => p(T).error({ ...re, functionName: "defaultReachGoal", goal: e, params: t, err: new Error("Metrika is not initialized") }),
A = B(ne);
function oe(...e) {
return p(A)(...e);
}
function Ve(...e) {
return () => oe(...e);
}
function se(e, t, r) {
let a;
X(e, A, (l) => r(5, (a = l)));
let { $$slots: i = {}, $$scope: s } = t;
const _ = { clickmap: !0, trackLinks: !0, accurateTrackBounce: !0 };
let { logger: y } = t,
{ counterId: h } = t,
{ ymOptions: g = _ } = t;
return (
Q(() => {
const l = y.child({ componentName: "YandexMetrika", counterId: h, ymOptions: g });
try {
window.ym ||
(function (u, E, L, D, I, n, c) {
var f;
(u[I] =
u[I] ||
function () {
(u[I].a = u[I].a || []).push(arguments);
}),
(u[I].l = Date.now()),
(n = E.createElement(L)),
(c = E.getElementsByTagName(L)[0]),
(n.async = !0),
(n.src = D),
(f = c.parentNode) == null || f.insertBefore(n, c);
})(window, document, "script", "https://mc.yandex.ru/metrika/tag.js", "ym"),
window.ym(h, "init", g);
} catch (u) {
l.error({ method: "init", err: new Error("Fail to init yandex metrica API", { cause: u }) });
}
Z(
A,
(a = (...u) => {
const E = l.child({ functionName: "reachGoal", goal: u[0], params: u[1] });
window.ym || E.error({ err: new Error("Missing yandex metrika API") });
try {
window.ym(h, "reachGoal", ...u);
} catch (L) {
E.error({ err: new Error("Fail to reach goals in yandex metrica API", { cause: L }) });
}
}),
a
);
}),
(e.$$set = (l) => {
"logger" in l && r(1, (y = l.logger)), "counterId" in l && r(0, (h = l.counterId)), "ymOptions" in l && r(2, (g = l.ymOptions)), "$$scope" in l && r(3, (s = l.$$scope));
}),
[h, y, g, s, i]
);
}
class Re extends P {
constructor(t) {
super(), V(this, t, se, te, R, { logger: 1, counterId: 0, ymOptions: 2 });
}
}
function ae(e) {
return e && e.__esModule && Object.prototype.hasOwnProperty.call(e, "default") ? e.default : e;
}
Object.values(W);
function ce(e, t) {
return new ee(e, t);
}
new TextEncoder();
var w = ((e) => ((e[(e.Unknown = 0)] = "Unknown"), (e[(e.InProgress = 1)] = "InProgress"), (e[(e.Success = 2)] = "Success"), (e[(e.Error = 3)] = "Error"), (e[(e.NotFoundInCache = 4)] = "NotFoundInCache"), e))(w || {}),
b = ((e) => ((e[(e.Success = 0)] = "Success"), (e[(e.InProgress = 1)] = "InProgress"), (e[(e.Error = 2)] = "Error"), e))(b || {}),
v = ((e) => ((e[(e.ServiceUnavailable = 500)] = "ServiceUnavailable"), e))(v || {});
const ie = {
[0]: o.FALLBACK,
[1]: o.NOT_FOUND,
[2]: o.EXTRACTION,
[3]: o.TOO_MANY_TOKENS,
[4]: o.NOT_FOUND,
[5]: o.FALLBACK,
[6]: o.IMPOSSIBLE,
[7]: o.FALLBACK,
[8]: o.IMPOSSIBLE,
[9]: o.FALLBACK,
[10]: o.OLD_CLIENT,
[11]: o.IMPOSSIBLE,
[12]: o.IMPOSSIBLE,
[500]: o.FALLBACK,
},
le = {
[0]: o.VIDEO_FALLBACK,
[1]: o.OLD_CLIENT,
[2]: o.VIDEO_FALLBACK,
[3]: o.VIDEO_IMPOSSIBLE,
[4]: o.VIDEO_FALLBACK,
[5]: o.VIDEO_FALLBACK,
[6]: o.VIDEO_FALLBACK,
[7]: o.VIDEO_FALLBACK,
[8]: o.VIDEO_IMPOSSIBLE,
[9]: o.VIDEO_FALLBACK,
[10]: o.VIDEO_FALLBACK,
[11]: o.VIDEO_FALLBACK,
[12]: o.VIDEO_FALLBACK,
[13]: o.VIDEO_FALLBACK,
[14]: o.VIDEO_NO_ACCESS,
[15]: o.VIDEO_NO_ACCESS,
[16]: o.VIDEO_NO_ACCESS,
[17]: o.VIDEO_NO_ACCESS,
[18]: o.VIDEO_NO_ACCESS,
[19]: o.VIDEO_NO_ACCESS,
[20]: o.VIDEO_NO_SUBTITLES,
[21]: o.VIDEO_TOO_BIG,
[22]: o.VIDEO_TOO_SMALL,
[500]: o.VIDEO_FALLBACK,
},
ue = (e) => new Promise((t) => setTimeout(t, e)),
Ke = (e) => {
if (e == null) return "";
let t = e;
return [3600, 60, 1]
.map((r) => {
const a = (t / r) | 0;
return (t %= r), me(a);
})
.join(":");
},
me = (e) => (e > 9 ? e : `0${e}`);
var _e = de,
fe = /^(?:\w+:)?\/\/(\S+)$/,
he = /^localhost[\:?\d]*(?:[^\:?\d]\S*)?$/,
Ee = /^[^\s\.]+\.\S{2,}$/;
function de(e) {
if (typeof e != "string") return !1;
var t = e.match(fe);
if (!t) return !1;
var r = t[1];
return r ? !!(he.test(r) || Ee.test(r)) : !1;
}
const ge = ae(_e),
Ue = (e) => e.map((t) => t.theses).flat(),
Le = (e) => {
const t = Number(e.searchParams.get(N.TIME));
return isNaN(t) || t <= 0 ? 0 : Math.floor(t);
},
Me = (e) =>
e
? e.map((t, r) => {
const a = e[r + 1];
return { ...t, end_time: a ? a.start_time : 1 / 0 };
})
: null,
Ie = (e) => {
const t = Le(new URL(window.location.href));
try {
if (t) {
const r = new URL(e);
return r.searchParams.set(N.TIME, String(t)), r.href;
}
return e;
} catch {
return e;
}
},
ye = (e, t) => {
if (!e) throw new Error("Empty input prompt");
const r = Oe(e);
return Ae(r) ? { session_id: t, video_url: r } : { article_url: r, session_id: t, text: r ? "" : e };
},
Oe = (e, t = !1) => {
const r = Se(e, t);
if (!ge(r)) return "";
try {
return new URL(r).href;
} catch {
return "";
}
},
Se = (e, t = !1) => {
if (!e) return "";
const r = e.trim();
if (pe(r)) return r;
const a = r.includes("http") ? r : "https://" + r;
return t ? Ie(a) : a;
},
pe = (e) => !/(\w+\.)+[^\s]+/.test(e.trim()) || /\s/g.test(e.trim());
function Ae(e) {
if (!we(e)) return null;
const t = /^.*(?:(?:youtu\.be\/|v\/|vi\/|u\/\w\/|embed\/|shorts\/|live\/)|(?:(?:watch)?\?v(?:i)?=|&v(?:i)?=))([^#&?]*).*/i,
r = e.match(t);
return r && (r[1].length == 11 || r[1].length == 12) ? r[1].trim() : null;
}
const we = (e) => /^(https?:\/\/)?(www\.|m\.)?youtu(\.be|be\.\w{2,3})+\//i.test(e),
Ce = (e) => (e.video_url ? d.VIDEO : e.text ? d.TEXT : d.ARTICLE);
var Te = ((e) => ((e.INIT = "init"), (e.LOADING = "loading"), (e.ASYNC_LOADING = "async-loading"), (e.SUCCESS = "success"), (e.ERROR = "error"), e))(Te || {});
function De() {
const { set: e, update: t, subscribe: r } = B({ status: "init", keypoints: null, theses: null, title: "", prompt: "" }),
a = async ({ prompt: n = "" }) => {
const c = ye(n),
f = Ce(c),
O = new AbortController(),
S = O.signal;
L(n, f, O);
const m = await i(c, S);
if (C(m) || h(m)) {
E(m);
return;
}
if (y(m)) {
g(m), u();
return;
}
},
i = async (n, c) => {
let O, S, m;
do {
if ((await ue(S ?? 500), (m = await Fe(n, O)), C(m) || c.aborted)) break;
(O = m.session_id), (S = m.poll_interval_ms), l(m);
} while (_(m));
return m;
},
s = { [d.ARTICLE]: w, [d.VIDEO]: b, [d.TEXT]: w },
_ = (n) => n.status_code === s[n.type].InProgress,
y = (n) => n.status_code === s[n.type].Success,
h = (n) => n.status_code === s[n.type].Error,
g = (n) => {
if (n.sharing_url)
try {
const c = new URL(n.sharing_url);
window.history.replaceState(history.state, "", c.pathname);
} catch (c) {
p(T).error({ message: "Error while trying to create URL object from sharing url" }, c);
}
},
l = (n) => {
t((c) => ({ ...c, keypoints: n.keypoints ?? null, sharingUrl: n.sharing_url, theses: n.thesis ?? null, title: n.video_title ?? n.title, type: n.type }));
},
u = () => {
t((n) => ({ ...n, status: "success" }));
},
E = (n) => {
const c = Ne(n);
t((f) => ({ ...f, status: "error", error: { message: c }, type: n.type }));
},
L = (n, c, f) => {
e({ abortController: f, keypoints: null, status: "loading", theses: null, prompt: n, type: c });
};
return {
set: e,
update: t,
subscribe: r,
getSummary: a,
resetSummary: () => {
e({ keypoints: null, status: "init", theses: null, title: "", prompt: "" });
},
setStoreSummary: (n) => {
e({
ageSeconds: n.summary_age_seconds ?? n.article_age_seconds,
keypoints: n.keypoints ?? null,
sharingUrl: n.sharing_url,
status: "success",
theses: n.thesis ?? null,
title: n.video_title ?? n.title,
type: n.type,
prompt: n.normalized_url,
});
},
};
}
async function Fe(e, t) {
return await (await fetch("/api/generation", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ ...e, session_id: t }) }).catch(F)).json().catch(F);
}
const Ne = (e) => {
const t = C(e) ? v.ServiceUnavailable : e.error_code;
return t ? (e.type === d.VIDEO ? le[t] : ie[t]) : o.SERVER_FALLBACK;
},
F = (e) => {
throw (p(T).error({ message: "Error while fetching the summary from /api/generation" }, e), ce(500, { message: o.SERVER_FALLBACK }));
},
C = (e) => "message" in e,
ke = () => q("summary-store"),
Ge = () => {
J("summary-store", De());
},
xe = $("goto");
export { Te as S, Re as Y, Ve as a, xe as b, we as c, w as d, ce as e, Oe as f, ke as g, ae as h, pe as i, Le as j, Ke as k, Me as l, Ie as m, Ae as n, Ue as o, oe as r, Ge as s };
//# sourceMappingURL=https://browserweb.s3.mdst.yandex.net/stardust/browser-summary-web/source-maps/1.15.0/navigation.8576e62a.js.map
@nezort11
Copy link
Author

nezort11 commented Feb 13, 2024

Yandex's 300.ya.ru navigation component chunk of code responsible for sending request to yandexgpt generation backend

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment