UNPKG

mongodb-chatbot-ui

Version:

UI React components for the MongoDB Assistant

157 lines (156 loc) 4.59 kB
import { b as L, R as U, T as X, C as z, a as N, u as P } from "./Chatbot2.js"; import { useChatbotContext as W } from "./useChatbotContext.js"; import { I as G, u as J } from "./InputBarTrigger2.js"; import { M as O, d as Y, m as Z } from "./ui-text.js"; import { HotkeyTrigger as oe } from "./HotkeyTrigger.js"; import { FloatingActionButtonTrigger as ne } from "./FloatingActionButtonTrigger.js"; import { ActionButtonTrigger as re, ButtonTrigger as ie } from "./ButtonTrigger.js"; import { f as me, g as ce } from "./LinkDataProvider.js"; import { ModalView as de } from "./ModalView.js"; import { ChatWindow as ge } from "./ChatWindow.js"; import "react/jsx-runtime"; import "./index2.js"; import "react"; import "./index3.js"; import "./ConversationStateProvider2.js"; import "./utils.js"; import "./useConversationStateContext.js"; import "./ChatbotProvider.js"; import "./HotkeyContext.js"; import "./emotion-css.esm.js"; import "./index4.js"; import "./glyphCommon-cTThlth0.js"; import "./polished.esm.js"; import "./index5.js"; import "react-dom"; import "./index6.js"; import "./index7.js"; import "./Refresh.js"; import "./index8.js"; import "./X.js"; import "./CheckmarkWithCircle.js"; import "./index9.js"; import "./index10.js"; import "./index11.js"; import "./ChatMessageFeed.js"; function s(t) { return t == null ? void 0 : t.replace(/^"|"$/g, ""); } function a() { const t = typeof window < "u" && window.analytics ? window.analytics : null, e = s( (t == null ? void 0 : t.user().id()) ?? localStorage.getItem("ajs_user_id") ?? void 0 ), o = s( (t == null ? void 0 : t.user().anonymousId()) ?? localStorage.getItem("ajs_anonymous_id") ?? void 0 ); return { userId: e, anonymousId: o }; } function H() { const { userId: t, anonymousId: e } = a(), o = new Headers(); return t && o.set("X-Segment-User-Id", t), e && o.set("X-Segment-Anonymous-Id", e), o; } class m { constructor() { this.version = 0; } /** * Get the current version of the cache. This number increments whenever * the cache is modified and can be used to trigger UI updates. */ getVersion() { return this.version; } } function R() { return new c(); } class c extends m { constructor() { super(), this.conversations = /* @__PURE__ */ new Map(); } incrementVersion() { this.version++; } async generateConversationName() { return `Conversation ${this.conversations.size + 1}`; } async getInfo() { return Array.from(this.conversations.values()).map((e) => ({ _id: e._id, name: e.name ?? "Unnamed Conversation" })); } async getConversation(e) { const o = this.conversations.get(e); return o ? { ...o, messages: o.messages.map((n) => ({ ...n })) } : null; } async addConversation(e) { if (this.conversations.has(e._id)) throw new Error( `Conversation with id ${e._id} already exists in this cache` ); const o = { ...e, messages: e.messages.map((n) => ({ ...n })) }; this.conversations.set(e._id, o), this.incrementVersion(); } async setConversation(e) { const o = { ...e, messages: e.messages.map((n) => ({ ...n })) }; this.conversations.set(e._id, o), this.incrementVersion(); } async addMessagesToConversation(e, o) { const n = this.conversations.get(e); if (!n) throw new Error( `Failed to add messages: Conversation with id ${e} not found in this cache` ); const r = o.map((i) => ({ ...i })); n.messages.push(...r), this.incrementVersion(); } async renameConversation(e, o) { const n = this.conversations.get(e); if (!n) throw new Error( `Failed to rename conversation: Conversation with id ${e} not found in this cache` ); n.name = o, this.incrementVersion(); } async deleteConversation(e) { this.conversations.delete(e), this.incrementVersion(); } } export { re as ActionButtonTrigger, ie as ButtonTrigger, ge as ChatWindow, L as ConversationService, ne as FloatingActionButtonTrigger, oe as HotkeyTrigger, c as InMemoryConversationCache, G as InputBarTrigger, de as ModalView, O as MongoDbInputBarPlaceholder, U as RetriableError, X as TimeoutError, z as default, Y as defaultChatbotFatalErrorMessage, me as formatReferences, ce as getMessageLinks, H as getSegmentIdHeaders, a as getSegmentIds, R as makeInMemoryConversationCache, Z as mongoDbVerifyInformationMessage, N as useChatbot, W as useChatbotContext, P as useConversation, J as useTextInputTrigger };