index
int64
0
0
repo_id
stringclasses
351 values
file_path
stringlengths
26
186
content
stringlengths
1
990k
0
hf_public_repos/chat-ui/src/routes/settings/(nav)/assistants/[assistantId]
hf_public_repos/chat-ui/src/routes/settings/(nav)/assistants/[assistantId]/edit/+page.server.ts
import { base } from "$app/paths"; import { requiresUser } from "$lib/server/auth"; import { collections } from "$lib/server/database"; import { fail, type Actions, redirect } from "@sveltejs/kit"; import { ObjectId } from "mongodb"; import { z } from "zod"; import { sha256 } from "$lib/utils/sha256"; import sharp fr...
0
hf_public_repos/chat-ui/src/routes/settings/(nav)/assistants/[assistantId]
hf_public_repos/chat-ui/src/routes/settings/(nav)/assistants/[assistantId]/edit/+page@settings.svelte
<script lang="ts"> import type { PageData, ActionData } from "./$types"; import { page } from "$app/stores"; import AssistantSettings from "$lib/components/AssistantSettings.svelte"; export let data: PageData; export let form: ActionData; let assistant = data.assistants.find((el) => el._id.toString() === $page....
0
hf_public_repos/chat-ui/src/routes/settings/(nav)/assistants/[assistantId]
hf_public_repos/chat-ui/src/routes/settings/(nav)/assistants/[assistantId]/avatar.jpg/+server.ts
import { collections } from "$lib/server/database"; import { error, type RequestHandler } from "@sveltejs/kit"; import { ObjectId } from "mongodb"; export const GET: RequestHandler = async ({ params }) => { const assistant = await collections.assistants.findOne({ _id: new ObjectId(params.assistantId), }); if (!a...
0
hf_public_repos/chat-ui/src/routes/settings/(nav)/assistants
hf_public_repos/chat-ui/src/routes/settings/(nav)/assistants/new/+page.server.ts
import { base } from "$app/paths"; import { authCondition, requiresUser } from "$lib/server/auth"; import { collections } from "$lib/server/database"; import { fail, type Actions, redirect } from "@sveltejs/kit"; import { ObjectId } from "mongodb"; import { z } from "zod"; import { sha256 } from "$lib/utils/sha256"; i...
0
hf_public_repos/chat-ui/src/routes/settings/(nav)/assistants
hf_public_repos/chat-ui/src/routes/settings/(nav)/assistants/new/+page@settings.svelte
<script lang="ts"> import type { ActionData, PageData } from "./$types"; import AssistantSettings from "$lib/components/AssistantSettings.svelte"; export let data: PageData; export let form: ActionData; </script> <AssistantSettings bind:form models={data.models} />
0
hf_public_repos/chat-ui/src/routes/settings/(nav)
hf_public_repos/chat-ui/src/routes/settings/(nav)/[...model]/+page.ts
import { base } from "$app/paths"; import { redirect } from "@sveltejs/kit"; export async function load({ parent, params }) { const data = await parent(); const model = data.models.find((m: { id: string }) => m.id === params.model); if (!model || model.unlisted) { redirect(302, `${base}/settings`); } return ...
0
hf_public_repos/chat-ui/src/routes/settings/(nav)
hf_public_repos/chat-ui/src/routes/settings/(nav)/[...model]/+page.svelte
<script lang="ts"> import { page } from "$app/stores"; import { base } from "$app/paths"; import { env as envPublic } from "$env/dynamic/public"; import type { BackendModel } from "$lib/server/models"; import { useSettingsStore } from "$lib/stores/settings"; import CopyToClipBoardBtn from "$lib/components/CopyToC...
0
hf_public_repos/chat-ui/src/routes
hf_public_repos/chat-ui/src/routes/conversations/+page.server.ts
import { base } from "$app/paths"; import { authCondition } from "$lib/server/auth"; import { collections } from "$lib/server/database"; import { redirect } from "@sveltejs/kit"; export const actions = { async delete({ locals }) { // double check we have a user to delete conversations for if (locals.user?._id || ...
0
hf_public_repos/chat-ui/src/routes/admin/stats
hf_public_repos/chat-ui/src/routes/admin/stats/compute/+server.ts
import { json } from "@sveltejs/kit"; import { logger } from "$lib/server/logger"; import { computeAllStats } from "$lib/jobs/refresh-conversation-stats"; // Triger like this: // curl -X POST "http://localhost:5173/chat/admin/stats/compute" -H "Authorization: Bearer <ADMIN_API_SECRET>" export async function POST() { ...
0
hf_public_repos/chat-ui/src/routes/admin
hf_public_repos/chat-ui/src/routes/admin/export/+server.ts
import { env } from "$env/dynamic/private"; import { collections } from "$lib/server/database"; import type { Message } from "$lib/types/Message"; import { error } from "@sveltejs/kit"; import { pathToFileURL } from "node:url"; import { unlink } from "node:fs/promises"; import { uploadFile } from "@huggingface/hub"; im...
0
hf_public_repos/chat-ui/src/routes
hf_public_repos/chat-ui/src/routes/tools/ToolInputComponent.svelte
<script lang="ts"> export let type: string; export let value: string | boolean | number; export let disabled: boolean = false; let innerValue: string | boolean | number = (() => { if (type === "bool") { return Boolean(value) || false; } else if (type === "int" || type === "float") { return Number(value) ...
0
hf_public_repos/chat-ui/src/routes
hf_public_repos/chat-ui/src/routes/tools/+layout.ts
import { base } from "$app/paths"; import { redirect } from "@sveltejs/kit"; export async function load({ parent }) { const { enableCommunityTools } = await parent(); if (enableCommunityTools) { return {}; } redirect(302, `${base}/`); }
0
hf_public_repos/chat-ui/src/routes
hf_public_repos/chat-ui/src/routes/tools/+layout.svelte
<script lang="ts"> import { env as envPublic } from "$env/dynamic/public"; import { isHuggingChat } from "$lib/utils/isHuggingChat"; import { base } from "$app/paths"; import { page } from "$app/stores"; </script> <svelte:head> {#if isHuggingChat} <title>HuggingChat - Tools</title> <meta property="og:title" c...
0
hf_public_repos/chat-ui/src/routes
hf_public_repos/chat-ui/src/routes/tools/+page.svelte
<script lang="ts"> import type { PageData } from "./$types"; import { isHuggingChat } from "$lib/utils/isHuggingChat"; import { goto } from "$app/navigation"; import { base } from "$app/paths"; import { page } from "$app/stores"; import CarbonAdd from "~icons/carbon/add"; import CarbonHelpFilled from "~icons/...
0
hf_public_repos/chat-ui/src/routes
hf_public_repos/chat-ui/src/routes/tools/ToolEdit.svelte
<script lang="ts"> import { ToolOutputComponents, type CommunityToolEditable, type ToolInput, } from "$lib/types/Tool"; import { createEventDispatcher, onMount } from "svelte"; import { browser } from "$app/environment"; import ToolLogo from "$lib/components/ToolLogo.svelte"; import { colors, icons } from "...
0
hf_public_repos/chat-ui/src/routes
hf_public_repos/chat-ui/src/routes/tools/+page.server.ts
import { env } from "$env/dynamic/private"; import { authCondition } from "$lib/server/auth.js"; import { Database, collections } from "$lib/server/database.js"; import { toolFromConfigs } from "$lib/server/tools/index.js"; import { SortKey } from "$lib/types/Assistant.js"; import { ReviewStatus } from "$lib/types/Revi...
0
hf_public_repos/chat-ui/src/routes/tools
hf_public_repos/chat-ui/src/routes/tools/[toolId]/+page.svelte
<script lang="ts"> import { afterNavigate, goto } from "$app/navigation"; import { base } from "$app/paths"; import { page } from "$app/stores"; import Modal from "$lib/components/Modal.svelte"; import ToolLogo from "$lib/components/ToolLogo.svelte"; import { env as envPublic } from "$env/dynamic/public"; import...
0
hf_public_repos/chat-ui/src/routes/tools
hf_public_repos/chat-ui/src/routes/tools/[toolId]/+page.server.ts
import { base } from "$app/paths"; import { env } from "$env/dynamic/private"; import { env as envPublic } from "$env/dynamic/public"; import { collections } from "$lib/server/database"; import { sendSlack } from "$lib/server/sendSlack"; import { ReviewStatus } from "$lib/types/Review"; import type { Tool } from "$lib/...
0
hf_public_repos/chat-ui/src/routes/tools
hf_public_repos/chat-ui/src/routes/tools/[toolId]/+layout.server.ts
import { base } from "$app/paths"; import { collections } from "$lib/server/database.js"; import { toolFromConfigs } from "$lib/server/tools/index.js"; import { ReviewStatus } from "$lib/types/Review.js"; import { redirect } from "@sveltejs/kit"; import { ObjectId } from "mongodb"; export const load = async ({ params,...
0
hf_public_repos/chat-ui/src/routes/tools/[toolId]
hf_public_repos/chat-ui/src/routes/tools/[toolId]/edit/+page.svelte
<script lang="ts"> import Modal from "$lib/components/Modal.svelte"; import ToolEdit from "../../ToolEdit.svelte"; export let data; export let form; </script> <Modal on:close={() => window.history.back()} width="h-[95dvh] w-[90dvw] overflow-hidden rounded-2xl bg-white shadow-2xl outline-none sm:h-[85dvh] xl:w-[...
0
hf_public_repos/chat-ui/src/routes/tools/[toolId]
hf_public_repos/chat-ui/src/routes/tools/[toolId]/edit/+page.server.ts
import { base } from "$app/paths"; import { requiresUser } from "$lib/server/auth.js"; import { collections } from "$lib/server/database.js"; import { editableToolSchema } from "$lib/server/tools/index.js"; import { generateSearchTokens } from "$lib/utils/searchTokens.js"; import { error, fail, redirect } from "@svelte...
0
hf_public_repos/chat-ui/src/routes/tools
hf_public_repos/chat-ui/src/routes/tools/new/+page.svelte
<script lang="ts"> import Modal from "$lib/components/Modal.svelte"; import ToolEdit from "../ToolEdit.svelte"; export let form; </script> <Modal on:close={() => window.history.back()} width="h-[95dvh] w-[90dvw] overflow-hidden rounded-2xl bg-white shadow-2xl outline-none sm:h-[85dvh] xl:w-[1200px] 2xl:h-[75dvh]...
0
hf_public_repos/chat-ui/src/routes/tools
hf_public_repos/chat-ui/src/routes/tools/new/+page.server.ts
import { env } from "$env/dynamic/private"; import { authCondition, requiresUser } from "$lib/server/auth.js"; import { collections } from "$lib/server/database.js"; import { editableToolSchema } from "$lib/server/tools/index.js"; import { usageLimits } from "$lib/server/usageLimits.js"; import { ReviewStatus } from "$...
0
hf_public_repos/chat-ui/src/routes
hf_public_repos/chat-ui/src/routes/models/+page.svelte
<script lang="ts"> import type { PageData } from "./$types"; import { env as envPublic } from "$env/dynamic/public"; import { isHuggingChat } from "$lib/utils/isHuggingChat"; import { base } from "$app/paths"; import { page } from "$app/stores"; import CarbonHelpFilled from "~icons/carbon/help-filled"; import...
0
hf_public_repos/chat-ui/src/routes/models
hf_public_repos/chat-ui/src/routes/models/[...model]/+page.svelte
<script lang="ts"> import { page } from "$app/stores"; import { base } from "$app/paths"; import { goto } from "$app/navigation"; import { onMount } from "svelte"; import { env as envPublic } from "$env/dynamic/public"; import ChatWindow from "$lib/components/chat/ChatWindow.svelte"; import { findCurrentModel } ...
0
hf_public_repos/chat-ui/src/routes/models
hf_public_repos/chat-ui/src/routes/models/[...model]/+page.server.ts
import { base } from "$app/paths"; import { authCondition } from "$lib/server/auth.js"; import { collections } from "$lib/server/database"; import { models } from "$lib/server/models"; import { redirect } from "@sveltejs/kit"; export async function load({ params, locals, parent }) { const model = models.find(({ id })...
0
hf_public_repos/chat-ui/src/routes/models/[...model]
hf_public_repos/chat-ui/src/routes/models/[...model]/thumbnail.png/+server.ts
import ModelThumbnail from "./ModelThumbnail.svelte"; import { redirect, type RequestHandler } from "@sveltejs/kit"; import type { SvelteComponent } from "svelte"; import { Resvg } from "@resvg/resvg-js"; import satori from "satori"; import { html } from "satori-html"; import InterRegular from "$lib/server/fonts/Inte...
0
hf_public_repos/chat-ui/src/routes/models/[...model]
hf_public_repos/chat-ui/src/routes/models/[...model]/thumbnail.png/ModelThumbnail.svelte
<script lang="ts"> import { env as envPublic } from "$env/dynamic/public"; import { isHuggingChat } from "$lib/utils/isHuggingChat"; export let name: string; export let logoUrl: string | undefined; import logo from "../../../../../static/huggingchat/logo.svg?raw"; </script> <div class=" flex h-[648px] w-full fl...
0
hf_public_repos/chat-ui/src/routes
hf_public_repos/chat-ui/src/routes/login/+page.server.ts
import { redirect } from "@sveltejs/kit"; import { getOIDCAuthorizationUrl } from "$lib/server/auth"; import { base } from "$app/paths"; import { env } from "$env/dynamic/private"; export const actions = { async default({ url, locals, request }) { const referer = request.headers.get("referer"); let redirectURI = ...
0
hf_public_repos/chat-ui/src/routes/login
hf_public_repos/chat-ui/src/routes/login/callback/updateUser.ts
import { refreshSessionCookie } from "$lib/server/auth"; import { collections } from "$lib/server/database"; import { ObjectId } from "mongodb"; import { DEFAULT_SETTINGS } from "$lib/types/Settings"; import { z } from "zod"; import type { UserinfoResponse } from "openid-client"; import { error, type Cookies } from "@s...
0
hf_public_repos/chat-ui/src/routes/login
hf_public_repos/chat-ui/src/routes/login/callback/updateUser.spec.ts
import { assert, it, describe, afterEach, vi, expect } from "vitest"; import type { Cookies } from "@sveltejs/kit"; import { collections } from "$lib/server/database"; import { updateUser } from "./updateUser"; import { ObjectId } from "mongodb"; import { DEFAULT_SETTINGS } from "$lib/types/Settings"; import { defaultM...
0
hf_public_repos/chat-ui/src/routes/login
hf_public_repos/chat-ui/src/routes/login/callback/+page.server.ts
import { redirect, error } from "@sveltejs/kit"; import { getOIDCUserData, validateAndParseCsrfToken } from "$lib/server/auth"; import { z } from "zod"; import { base } from "$app/paths"; import { updateUser } from "./updateUser"; import { env } from "$env/dynamic/private"; import JSON5 from "json5"; const allowedUser...
0
hf_public_repos/chat-ui/src/routes
hf_public_repos/chat-ui/src/routes/conversation/+server.ts
import type { RequestHandler } from "./$types"; import { collections } from "$lib/server/database"; import { ObjectId } from "mongodb"; import { error, redirect } from "@sveltejs/kit"; import { base } from "$app/paths"; import { z } from "zod"; import type { Message } from "$lib/types/Message"; import { models, validat...
0
hf_public_repos/chat-ui/src/routes/conversation
hf_public_repos/chat-ui/src/routes/conversation/[id]/+server.ts
import { env } from "$env/dynamic/private"; import { startOfHour } from "date-fns"; import { authCondition, requiresUser } from "$lib/server/auth"; import { collections } from "$lib/server/database"; import { models, validModelIdSchema } from "$lib/server/models"; import { ERROR_MESSAGES } from "$lib/stores/errors"; im...
0
hf_public_repos/chat-ui/src/routes/conversation
hf_public_repos/chat-ui/src/routes/conversation/[id]/+page.svelte
<script lang="ts"> import ChatWindow from "$lib/components/chat/ChatWindow.svelte"; import { pendingMessage } from "$lib/stores/pendingMessage"; import { isAborted } from "$lib/stores/isAborted"; import { onMount } from "svelte"; import { page } from "$app/stores"; import { goto, invalidateAll } from "$app/naviga...
0
hf_public_repos/chat-ui/src/routes/conversation
hf_public_repos/chat-ui/src/routes/conversation/[id]/+page.server.ts
import { collections } from "$lib/server/database"; import { ObjectId } from "mongodb"; import { error } from "@sveltejs/kit"; import { authCondition } from "$lib/server/auth"; import { UrlDependency } from "$lib/types/UrlDependency"; import { convertLegacyConversation } from "$lib/utils/tree/convertLegacyConversation....
0
hf_public_repos/chat-ui/src/routes/conversation/[id]
hf_public_repos/chat-ui/src/routes/conversation/[id]/share/+server.ts
import { authCondition } from "$lib/server/auth"; import { collections } from "$lib/server/database"; import type { SharedConversation } from "$lib/types/SharedConversation"; import { getShareUrl } from "$lib/utils/getShareUrl"; import { hashConv } from "$lib/utils/hashConv"; import { error } from "@sveltejs/kit"; impo...
0
hf_public_repos/chat-ui/src/routes/conversation/[id]
hf_public_repos/chat-ui/src/routes/conversation/[id]/stop-generating/+server.ts
import { authCondition } from "$lib/server/auth"; import { collections } from "$lib/server/database"; import { error } from "@sveltejs/kit"; import { ObjectId } from "mongodb"; /** * Ideally, we'd be able to detect the client-side abort, see https://github.com/huggingface/chat-ui/pull/88#issuecomment-1523173850 */ e...
0
hf_public_repos/chat-ui/src/routes/conversation/[id]/message/[messageId]
hf_public_repos/chat-ui/src/routes/conversation/[id]/message/[messageId]/vote/+server.ts
import { authCondition } from "$lib/server/auth"; import { collections } from "$lib/server/database"; import { MetricsServer } from "$lib/server/metrics.js"; import { error } from "@sveltejs/kit"; import { ObjectId } from "mongodb"; import { z } from "zod"; export async function POST({ params, request, locals }) { co...
0
hf_public_repos/chat-ui/src/routes/conversation/[id]/message/[messageId]
hf_public_repos/chat-ui/src/routes/conversation/[id]/message/[messageId]/prompt/+server.ts
import { buildPrompt } from "$lib/buildPrompt"; import { authCondition } from "$lib/server/auth"; import { collections } from "$lib/server/database"; import { models } from "$lib/server/models"; import { buildSubtree } from "$lib/utils/tree/buildSubtree"; import { isMessageId } from "$lib/utils/tree/isMessageId"; impor...
0
hf_public_repos/chat-ui/src/routes/conversation/[id]/output
hf_public_repos/chat-ui/src/routes/conversation/[id]/output/[sha256]/+server.ts
import { authCondition } from "$lib/server/auth"; import { collections } from "$lib/server/database"; import { error } from "@sveltejs/kit"; import { ObjectId } from "mongodb"; import { z } from "zod"; import type { RequestHandler } from "./$types"; import { downloadFile } from "$lib/server/files/downloadFile"; import ...
0
hf_public_repos/chat-ui/src/routes
hf_public_repos/chat-ui/src/routes/privacy/+page.svelte
<script lang="ts"> import { marked } from "marked"; import privacy from "../../../PRIVACY.md?raw"; </script> <div class="overflow-auto p-6"> <div class="prose mx-auto px-4 pb-24 pt-6 dark:prose-invert md:pt-12"> <!-- eslint-disable-next-line svelte/no-at-html-tags --> {@html marked(privacy, { gfm: true })} </d...
0
hf_public_repos/chat-ui/src/routes
hf_public_repos/chat-ui/src/routes/logout/+page.server.ts
import { dev } from "$app/environment"; import { base } from "$app/paths"; import { env } from "$env/dynamic/private"; import { collections } from "$lib/server/database"; import { redirect } from "@sveltejs/kit"; export const actions = { async default({ cookies, locals }) { await collections.sessions.deleteOne({ se...
0
hf_public_repos/chat-ui/src/routes
hf_public_repos/chat-ui/src/routes/healthcheck/+server.ts
export async function GET() { return new Response("OK", { status: 200 }); }
0
hf_public_repos/chat-ui/src
hf_public_repos/chat-ui/src/lib/buildPrompt.ts
import type { EndpointParameters } from "./server/endpoints/endpoints"; import type { BackendModel } from "./server/models"; import type { Tool, ToolResult } from "./types/Tool"; type buildPromptOptions = Pick<EndpointParameters, "messages" | "preprompt" | "continueMessage"> & { model: BackendModel; tools?: Tool[]; ...
0
hf_public_repos/chat-ui/src
hf_public_repos/chat-ui/src/lib/switchTheme.ts
export function switchTheme() { const { classList } = document.querySelector("html") as HTMLElement; const metaTheme = document.querySelector('meta[name="theme-color"]') as HTMLMetaElement; if (classList.contains("dark")) { classList.remove("dark"); metaTheme.setAttribute("content", "rgb(249, 250, 251)"); loc...
0
hf_public_repos/chat-ui/src
hf_public_repos/chat-ui/src/lib/shareConversation.ts
import { base } from "$app/paths"; import { ERROR_MESSAGES, error } from "$lib/stores/errors"; import { share } from "./utils/share"; import { page } from "$app/stores"; import { get } from "svelte/store"; import { getShareUrl } from "./utils/getShareUrl"; export async function shareConversation(id: string, title: stri...
0
hf_public_repos/chat-ui/src/lib
hf_public_repos/chat-ui/src/lib/types/Conversation.ts
import type { ObjectId } from "mongodb"; import type { Message } from "./Message"; import type { Timestamps } from "./Timestamps"; import type { User } from "./User"; import type { Assistant } from "./Assistant"; export interface Conversation extends Timestamps { _id: ObjectId; sessionId?: string; userId?: User["_...
0
hf_public_repos/chat-ui/src/lib
hf_public_repos/chat-ui/src/lib/types/WebSearch.ts
import type { ObjectId } from "mongodb"; import type { Conversation } from "./Conversation"; import type { Timestamps } from "./Timestamps"; import type { HeaderElement } from "$lib/server/websearch/markdown/types"; export interface WebSearch extends Timestamps { _id?: ObjectId; convId?: Conversation["_id"]; promp...
0
hf_public_repos/chat-ui/src/lib
hf_public_repos/chat-ui/src/lib/types/Report.ts
import type { ObjectId } from "mongodb"; import type { User } from "./User"; import type { Assistant } from "./Assistant"; import type { Timestamps } from "./Timestamps"; export interface Report extends Timestamps { _id: ObjectId; createdBy: User["_id"] | string; object: "assistant" | "tool"; contentId: Assistant[...
0
hf_public_repos/chat-ui/src/lib
hf_public_repos/chat-ui/src/lib/types/Tool.ts
import type { ObjectId } from "mongodb"; import type { User } from "./User"; import type { Timestamps } from "./Timestamps"; import type { BackendToolContext } from "$lib/server/tools"; import type { MessageUpdate } from "./MessageUpdate"; import { z } from "zod"; import type { ReviewStatus } from "./Review"; export c...
0
hf_public_repos/chat-ui/src/lib
hf_public_repos/chat-ui/src/lib/types/SharedConversation.ts
import type { Conversation } from "./Conversation"; export type SharedConversation = Pick< Conversation, | "model" | "embeddingModel" | "title" | "rootMessageId" | "messages" | "preprompt" | "assistantId" | "createdAt" | "updatedAt" > & { _id: string; hash: string; };
0
hf_public_repos/chat-ui/src/lib
hf_public_repos/chat-ui/src/lib/types/Message.ts
import type { MessageUpdate } from "./MessageUpdate"; import type { Timestamps } from "./Timestamps"; import type { WebSearch } from "./WebSearch"; import type { v4 } from "uuid"; export type Message = Partial<Timestamps> & { from: "user" | "assistant" | "system"; id: ReturnType<typeof v4>; content: string; update...
0
hf_public_repos/chat-ui/src/lib
hf_public_repos/chat-ui/src/lib/types/Timestamps.ts
export interface Timestamps { createdAt: Date; updatedAt: Date; }
0
hf_public_repos/chat-ui/src/lib
hf_public_repos/chat-ui/src/lib/types/Model.ts
import type { BackendModel } from "$lib/server/models"; export type Model = Pick< BackendModel, | "id" | "name" | "displayName" | "websiteUrl" | "datasetName" | "promptExamples" | "parameters" | "description" | "logoUrl" | "modelUrl" | "tokenizer" | "datasetUrl" | "preprompt" | "multimodal" | "multimod...
0
hf_public_repos/chat-ui/src/lib
hf_public_repos/chat-ui/src/lib/types/Semaphore.ts
import type { Timestamps } from "./Timestamps"; export interface Semaphore extends Timestamps { key: string; }
0
hf_public_repos/chat-ui/src/lib
hf_public_repos/chat-ui/src/lib/types/ConvSidebar.ts
export interface ConvSidebar { id: string; title: string; updatedAt: Date; model?: string; assistantId?: string; avatarUrl?: string; }
0
hf_public_repos/chat-ui/src/lib
hf_public_repos/chat-ui/src/lib/types/Review.ts
export enum ReviewStatus { PRIVATE = "PRIVATE", PENDING = "PENDING", APPROVED = "APPROVED", DENIED = "DENIED", }
0
hf_public_repos/chat-ui/src/lib
hf_public_repos/chat-ui/src/lib/types/MigrationResult.ts
import type { ObjectId } from "mongodb"; export interface MigrationResult { _id: ObjectId; name: string; status: "success" | "failure" | "ongoing"; }
0
hf_public_repos/chat-ui/src/lib
hf_public_repos/chat-ui/src/lib/types/MessageUpdate.ts
import type { WebSearchSource } from "$lib/types/WebSearch"; import type { ToolCall, ToolResult } from "$lib/types/Tool"; export type MessageUpdate = | MessageStatusUpdate | MessageTitleUpdate | MessageToolUpdate | MessageWebSearchUpdate | MessageStreamUpdate | MessageFileUpdate | MessageFinalAnswerUpdate | Me...
0
hf_public_repos/chat-ui/src/lib
hf_public_repos/chat-ui/src/lib/types/ConversationStats.ts
import type { Timestamps } from "./Timestamps"; export interface ConversationStats extends Timestamps { date: { at: Date; span: "day" | "week" | "month"; field: "updatedAt" | "createdAt"; }; type: "conversation" | "message"; /** _id => number of conversations/messages in the month */ distinct: "sessionId" ...
0
hf_public_repos/chat-ui/src/lib
hf_public_repos/chat-ui/src/lib/types/TokenCache.ts
import type { Timestamps } from "./Timestamps"; export interface TokenCache extends Timestamps { tokenHash: string; // sha256 of the bearer token userId: string; // the matching hf user id }
0
hf_public_repos/chat-ui/src/lib
hf_public_repos/chat-ui/src/lib/types/AbortedGeneration.ts
// Ideally shouldn't be needed, see https://github.com/huggingface/chat-ui/pull/88#issuecomment-1523173850 import type { Conversation } from "./Conversation"; import type { Timestamps } from "./Timestamps"; export interface AbortedGeneration extends Timestamps { conversationId: Conversation["_id"]; }
0
hf_public_repos/chat-ui/src/lib
hf_public_repos/chat-ui/src/lib/types/MessageEvent.ts
import type { Session } from "./Session"; import type { Timestamps } from "./Timestamps"; import type { User } from "./User"; export interface MessageEvent extends Pick<Timestamps, "createdAt"> { userId: User["_id"] | Session["sessionId"]; ip?: string; }
0
hf_public_repos/chat-ui/src/lib
hf_public_repos/chat-ui/src/lib/types/UrlDependency.ts
/* eslint-disable no-shadow */ export enum UrlDependency { ConversationList = "conversation:list", Conversation = "conversation", }
0
hf_public_repos/chat-ui/src/lib
hf_public_repos/chat-ui/src/lib/types/Assistant.ts
import type { ObjectId } from "mongodb"; import type { User } from "./User"; import type { Timestamps } from "./Timestamps"; import type { ReviewStatus } from "./Review"; export interface Assistant extends Timestamps { _id: ObjectId; createdById: User["_id"] | string; // user id or session createdByName?: User["use...
0
hf_public_repos/chat-ui/src/lib
hf_public_repos/chat-ui/src/lib/types/Settings.ts
import { defaultModel } from "$lib/server/models"; import type { Assistant } from "./Assistant"; import type { Timestamps } from "./Timestamps"; import type { User } from "./User"; export interface Settings extends Timestamps { userId?: User["_id"]; sessionId?: string; /** * Note: Only conversations with this se...
0
hf_public_repos/chat-ui/src/lib
hf_public_repos/chat-ui/src/lib/types/User.ts
import type { ObjectId } from "mongodb"; import type { Timestamps } from "./Timestamps"; export interface User extends Timestamps { _id: ObjectId; username?: string; name: string; email?: string; avatarUrl: string | undefined; hfUserId: string; isAdmin?: boolean; isEarlyAccess?: boolean; }
0
hf_public_repos/chat-ui/src/lib
hf_public_repos/chat-ui/src/lib/types/AssistantStats.ts
import type { Timestamps } from "./Timestamps"; import type { Assistant } from "./Assistant"; export interface AssistantStats extends Timestamps { assistantId: Assistant["_id"]; date: { at: Date; span: "hour"; }; count: number; }
0
hf_public_repos/chat-ui/src/lib
hf_public_repos/chat-ui/src/lib/types/Template.ts
import type { Message } from "./Message"; import type { Tool, ToolResult } from "./Tool"; export type ChatTemplateInput = { messages: Pick<Message, "from" | "content" | "files">[]; preprompt?: string; tools?: Tool[]; toolResults?: ToolResult[]; continueMessage?: boolean; };
0
hf_public_repos/chat-ui/src/lib
hf_public_repos/chat-ui/src/lib/types/Session.ts
import type { ObjectId } from "bson"; import type { Timestamps } from "./Timestamps"; import type { User } from "./User"; export interface Session extends Timestamps { _id: ObjectId; sessionId: string; userId: User["_id"]; userAgent?: string; ip?: string; expiresAt: Date; }
0
hf_public_repos/chat-ui/src/lib
hf_public_repos/chat-ui/src/lib/stores/titleUpdate.ts
import { writable } from "svelte/store"; export interface TitleUpdate { convId: string; title: string; } export default writable<TitleUpdate | null>(null);
0
hf_public_repos/chat-ui/src/lib
hf_public_repos/chat-ui/src/lib/stores/webSearchParameters.ts
import { writable } from "svelte/store"; export interface WebSearchParameters { useSearch: boolean; nItems: number; } export const webSearchParameters = writable<WebSearchParameters>({ useSearch: false, nItems: 5, });
0
hf_public_repos/chat-ui/src/lib
hf_public_repos/chat-ui/src/lib/stores/errors.ts
import { writable } from "svelte/store"; export const ERROR_MESSAGES = { default: "Oops, something went wrong.", authOnly: "You have to be logged in.", rateLimited: "You are sending too many messages. Try again later.", }; export const error = writable<string | null>(null);
0
hf_public_repos/chat-ui/src/lib
hf_public_repos/chat-ui/src/lib/stores/isAborted.ts
import { writable } from "svelte/store"; export const isAborted = writable<boolean>(false);
0
hf_public_repos/chat-ui/src/lib
hf_public_repos/chat-ui/src/lib/stores/settings.ts
import { browser } from "$app/environment"; import { invalidate } from "$app/navigation"; import { base } from "$app/paths"; import { UrlDependency } from "$lib/types/UrlDependency"; import type { ObjectId } from "mongodb"; import { getContext, setContext } from "svelte"; import { type Writable, writable, get } from "s...
0
hf_public_repos/chat-ui/src/lib
hf_public_repos/chat-ui/src/lib/stores/pendingMessage.ts
import { writable } from "svelte/store"; export const pendingMessage = writable< | { content: string; files: File[]; } | undefined >();
0
hf_public_repos/chat-ui/src/lib
hf_public_repos/chat-ui/src/lib/stores/convTree.ts
import type { Message } from "$lib/types/Message"; import { getContext, setContext } from "svelte"; import { writable, type Writable } from "svelte/store"; // used to store the id of the message that is the currently displayed leaf of the conversation tree // (that is the last message in the current branch of the conv...
0
hf_public_repos/chat-ui/src/lib
hf_public_repos/chat-ui/src/lib/migrations/migrations.spec.ts
import { afterEach, assert, describe, expect, it } from "vitest"; import { migrations } from "./routines"; import { acquireLock, isDBLocked, refreshLock, releaseLock } from "./lock"; import { collections } from "$lib/server/database"; const LOCK_KEY = "migrations.test"; describe("migrations", () => { it("should not ...
0
hf_public_repos/chat-ui/src/lib
hf_public_repos/chat-ui/src/lib/migrations/lock.ts
import { collections } from "$lib/server/database"; import { ObjectId } from "mongodb"; /** * Returns the lock id if the lock was acquired, false otherwise */ export async function acquireLock(key: string): Promise<ObjectId | false> { try { const id = new ObjectId(); const insert = await collections.semaphores...
0
hf_public_repos/chat-ui/src/lib
hf_public_repos/chat-ui/src/lib/migrations/migrations.ts
import { Database } from "$lib/server/database"; import { migrations } from "./routines"; import { acquireLock, releaseLock, isDBLocked, refreshLock } from "./lock"; import { isHuggingChat } from "$lib/utils/isHuggingChat"; import { logger } from "$lib/server/logger"; const LOCK_KEY = "migrations"; export async funct...
0
hf_public_repos/chat-ui/src/lib/migrations
hf_public_repos/chat-ui/src/lib/migrations/routines/09-delete-empty-conversations.ts
import type { Migration } from "."; import { collections } from "$lib/server/database"; import { Collection, FindCursor, ObjectId } from "mongodb"; import { logger } from "$lib/server/logger"; import type { Conversation } from "$lib/types/Conversation"; const BATCH_SIZE = 1000; const DELETE_THRESHOLD_MS = 60 * 60 * 10...
0
hf_public_repos/chat-ui/src/lib/migrations
hf_public_repos/chat-ui/src/lib/migrations/routines/09-delete-empty-conversations.spec.ts
import type { Session } from "$lib/types/Session"; import type { User } from "$lib/types/User"; import type { Conversation } from "$lib/types/Conversation"; import { ObjectId } from "mongodb"; import { deleteConversations } from "./09-delete-empty-conversations"; import { afterAll, afterEach, beforeAll, describe, expec...
0
hf_public_repos/chat-ui/src/lib/migrations
hf_public_repos/chat-ui/src/lib/migrations/routines/03-add-tools-in-settings.ts
import type { Migration } from "."; import { collections } from "$lib/server/database"; import { ObjectId } from "mongodb"; import { logger } from "$lib/server/logger"; const addToolsToSettings: Migration = { _id: new ObjectId("5c9c4c4c4c4c4c4c4c4c4c4c"), name: "Add empty 'tools' record in settings", up: async () =...
0
hf_public_repos/chat-ui/src/lib/migrations
hf_public_repos/chat-ui/src/lib/migrations/routines/08-update-featured-to-review.ts
import type { Migration } from "."; import { collections } from "$lib/server/database"; import { ObjectId } from "mongodb"; import { ReviewStatus } from "$lib/types/Review"; const updateFeaturedToReview: Migration = { _id: new ObjectId("000000000000000000000008"), name: "Update featured to review", up: async () => ...
0
hf_public_repos/chat-ui/src/lib/migrations
hf_public_repos/chat-ui/src/lib/migrations/routines/06-trim-message-updates.ts
import type { Migration } from "."; import { collections } from "$lib/server/database"; import { ObjectId, type WithId } from "mongodb"; import type { Conversation } from "$lib/types/Conversation"; import { MessageUpdateType, MessageWebSearchUpdateType, type MessageUpdate, } from "$lib/types/MessageUpdate"; import t...
0
hf_public_repos/chat-ui/src/lib/migrations
hf_public_repos/chat-ui/src/lib/migrations/routines/04-update-message-updates.ts
import type { Migration } from "."; import { collections } from "$lib/server/database"; import { ObjectId, type WithId } from "mongodb"; import type { Conversation } from "$lib/types/Conversation"; import type { WebSearchSource } from "$lib/types/WebSearch"; import { MessageUpdateStatus, MessageUpdateType, MessageWe...
0
hf_public_repos/chat-ui/src/lib/migrations
hf_public_repos/chat-ui/src/lib/migrations/routines/05-update-message-files.ts
import { ObjectId, type WithId } from "mongodb"; import { collections } from "$lib/server/database"; import type { Migration } from "."; import type { Conversation } from "$lib/types/Conversation"; import type { MessageFile } from "$lib/types/Message"; const updateMessageFiles: Migration = { _id: new ObjectId("5f9f5...
0
hf_public_repos/chat-ui/src/lib/migrations
hf_public_repos/chat-ui/src/lib/migrations/routines/index.ts
import type { ObjectId } from "mongodb"; import updateSearchAssistant from "./01-update-search-assistants"; import updateAssistantsModels from "./02-update-assistants-models"; import type { Database } from "$lib/server/database"; import addToolsToSettings from "./03-add-tools-in-settings"; import updateMessageUpdates ...
0
hf_public_repos/chat-ui/src/lib/migrations
hf_public_repos/chat-ui/src/lib/migrations/routines/07-reset-tools-in-settings.ts
import type { Migration } from "."; import { collections } from "$lib/server/database"; import { ObjectId } from "mongodb"; const resetTools: Migration = { _id: new ObjectId("000000000000000000000007"), name: "Reset tools to empty", up: async () => { const { settings } = collections; await settings.updateMany(...
0
hf_public_repos/chat-ui/src/lib/migrations
hf_public_repos/chat-ui/src/lib/migrations/routines/02-update-assistants-models.ts
import type { Migration } from "."; import { collections } from "$lib/server/database"; import { ObjectId } from "mongodb"; const updateAssistantsModels: Migration = { _id: new ObjectId("5f9f3f3f3f3f3f3f3f3f3f3f"), name: "Update deprecated models in assistants with the default model", up: async () => { const mode...
0
hf_public_repos/chat-ui/src/lib/migrations
hf_public_repos/chat-ui/src/lib/migrations/routines/01-update-search-assistants.ts
import type { Migration } from "."; import { collections } from "$lib/server/database"; import { ObjectId, type AnyBulkWriteOperation } from "mongodb"; import type { Assistant } from "$lib/types/Assistant"; import { generateSearchTokens } from "$lib/utils/searchTokens"; const migration: Migration = { _id: new ObjectI...
0
hf_public_repos/chat-ui/src/lib
hf_public_repos/chat-ui/src/lib/constants/publicSepToken.ts
export const PUBLIC_SEP_TOKEN = "</s>";
0
hf_public_repos/chat-ui/src/lib
hf_public_repos/chat-ui/src/lib/utils/tools.ts
import type { Tool } from "$lib/types/Tool"; /** * Checks if a tool's name equals a value. Replaces all hyphens with underscores before comparison * since some models return underscores even when hyphens are used in the request. **/ export function toolHasName(name: string, tool: Pick<Tool, "name">): boolean { ret...
0
hf_public_repos/chat-ui/src/lib
hf_public_repos/chat-ui/src/lib/utils/deepestChild.ts
export function deepestChild(el: HTMLElement): HTMLElement { if (el.lastElementChild && el.lastElementChild.nodeType !== Node.TEXT_NODE) { return deepestChild(el.lastElementChild as HTMLElement); } return el; }
0
hf_public_repos/chat-ui/src/lib
hf_public_repos/chat-ui/src/lib/utils/file2base64.ts
const file2base64 = (file: File): Promise<string> => { return new Promise<string>((resolve, reject) => { const reader = new FileReader(); reader.readAsDataURL(file); reader.onload = () => { const dataUrl = reader.result as string; const base64 = dataUrl.split(",")[1]; resolve(base64); }; reader.oner...
0
hf_public_repos/chat-ui/src/lib
hf_public_repos/chat-ui/src/lib/utils/sha256.ts
export async function sha256(input: string): Promise<string> { const utf8 = new TextEncoder().encode(input); const hashBuffer = await crypto.subtle.digest("SHA-256", utf8); const hashArray = Array.from(new Uint8Array(hashBuffer)); const hashHex = hashArray.map((bytes) => bytes.toString(16).padStart(2, "0")).join(""...
0
hf_public_repos/chat-ui/src/lib
hf_public_repos/chat-ui/src/lib/utils/share.ts
import { browser } from "$app/environment"; import { isDesktop } from "./isDesktop"; export async function share(url: string, title: string, appendLeafId: boolean = false) { if (!browser) return; // Retrieve the leafId from localStorage const leafId = localStorage.getItem("leafId"); if (appendLeafId && leafId) {...
0
hf_public_repos/chat-ui/src/lib
hf_public_repos/chat-ui/src/lib/utils/getShareUrl.ts
import { base } from "$app/paths"; import { env as envPublic } from "$env/dynamic/public"; export function getShareUrl(url: URL, shareId: string): string { return `${ envPublic.PUBLIC_SHARE_PREFIX || `${envPublic.PUBLIC_ORIGIN || url.origin}${base}` }/r/${shareId}`; }
0
hf_public_repos/chat-ui/src/lib
hf_public_repos/chat-ui/src/lib/utils/randomUuid.ts
type UUID = ReturnType<typeof crypto.randomUUID>; export function randomUUID(): UUID { // Only on old safari / ios if (!("randomUUID" in crypto)) { return "10000000-1000-4000-8000-100000000000".replace(/[018]/g, (c) => ( Number(c) ^ (crypto.getRandomValues(new Uint8Array(1))[0] & (15 >> (Number(c) / 4))...