Merge remote-tracking branch 'upstream/dev' into feat/api-key

This commit is contained in:
Anish Sarkar 2026-06-23 13:09:53 +05:30
commit 3695e1d5c5
64 changed files with 1043 additions and 1852 deletions

View file

@ -18,16 +18,12 @@ import { FENCED_OR_INLINE_CODE } from "@/lib/markdown/code-regions";
* sometimes emit.
*/
export const CITATION_REGEX =
/[[【]\u200B?citation:\s*(https?:\/\/[^\]】\u200B]+|urlcite\d+|d\d+#L\d+-\d+|(?:doc-)?-?\d+(?:\s*,\s*(?:doc-)?-?\d+)*)\s*\u200B?[\]】]/g;
/** Matches the knowledge-base line-citation form `d<documentId>#L<start>-<end>`. */
const LINE_CITATION_REGEX = /^d(\d+)#L(\d+)-(\d+)$/;
/[[【]\u200B?citation:\s*(https?:\/\/[^\]】\u200B]+|urlcite\d+|(?:doc-)?-?\d+(?:\s*,\s*(?:doc-)?-?\d+)*)\s*\u200B?[\]】]/g;
/** A single parsed citation reference. */
export type CitationToken =
| { kind: "url"; url: string }
| { kind: "chunk"; chunkId: number; isDocsChunk: boolean }
| { kind: "line"; documentId: number; startLine: number; endLine: number };
| { kind: "chunk"; chunkId: number; isDocsChunk: boolean };
/** Output of `parseTextWithCitations` — interleaved text + citation tokens. */
export type ParsedSegment = string | CitationToken;
@ -99,15 +95,7 @@ export function parseTextWithCitations(text: string, urlMap: CitationUrlMap): Pa
const captured = match[1];
const lineMatch = LINE_CITATION_REGEX.exec(captured);
if (lineMatch) {
segments.push({
kind: "line",
documentId: Number.parseInt(lineMatch[1], 10),
startLine: Number.parseInt(lineMatch[2], 10),
endLine: Number.parseInt(lineMatch[3], 10),
});
} else if (captured.startsWith("http://") || captured.startsWith("https://")) {
if (captured.startsWith("http://") || captured.startsWith("https://")) {
segments.push({ kind: "url", url: captured.trim() });
} else if (captured.startsWith("urlcite")) {
const url = urlMap.get(captured);

View file

@ -0,0 +1,52 @@
export const RUNTIME_AUTH_TYPE_COOKIE_NAME = "surfsense_auth_type";
export type RuntimeAuthUiMode = "GOOGLE" | "LOCAL";
export function resolveRuntimeAuthUiMode(
value: string | null | undefined,
fallback: string | null | undefined = "GOOGLE"
): RuntimeAuthUiMode {
const candidate = value?.trim().toUpperCase();
if (candidate === "GOOGLE") return "GOOGLE";
if (candidate === "LOCAL") return "LOCAL";
const fallbackCandidate = fallback?.trim().toUpperCase();
return fallbackCandidate === "GOOGLE" ? "GOOGLE" : "LOCAL";
}
export function getRuntimeAuthInitScript(fallbackAuthType: string): string {
const fallback = resolveRuntimeAuthUiMode(fallbackAuthType);
const cookieName = JSON.stringify(RUNTIME_AUTH_TYPE_COOKIE_NAME);
const fallbackValue = JSON.stringify(fallback);
return `
(function() {
try {
var cookieName = ${cookieName};
var fallback = ${fallbackValue};
var prefix = cookieName + "=";
var rawValue = fallback;
var cookies = document.cookie ? document.cookie.split(";") : [];
for (var i = 0; i < cookies.length; i++) {
var cookie = cookies[i].trim();
if (cookie.indexOf(prefix) === 0) {
rawValue = decodeURIComponent(cookie.slice(prefix.length));
break;
}
}
var normalized = String(rawValue || fallback).toUpperCase() === "GOOGLE" ? "GOOGLE" : "LOCAL";
window.__SURFSENSE_AUTH_TYPE__ = normalized;
document.documentElement.setAttribute("data-surfsense-auth-type", normalized);
} catch (_) {
window.__SURFSENSE_AUTH_TYPE__ = ${fallbackValue};
document.documentElement.setAttribute("data-surfsense-auth-type", ${fallbackValue});
}
})();
`;
}
declare global {
interface Window {
__SURFSENSE_AUTH_TYPE__?: RuntimeAuthUiMode;
}
}