@mordn/chat-widget 0.1.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.
@@ -0,0 +1,186 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __export = (target, all) => {
3
+ for (var name in all)
4
+ __defProp(target, name, { get: all[name], enumerable: true });
5
+ };
6
+
7
+ // src/db/index.ts
8
+ import "server-only";
9
+ import { drizzle } from "drizzle-orm/postgres-js";
10
+ import postgres from "postgres";
11
+
12
+ // src/db/schema.ts
13
+ var schema_exports = {};
14
+ __export(schema_exports, {
15
+ conversations: () => conversations,
16
+ messages: () => messages
17
+ });
18
+ import { pgTable, text, timestamp, jsonb, index } from "drizzle-orm/pg-core";
19
+ var conversations = pgTable("conversations", {
20
+ id: text("id").primaryKey(),
21
+ userId: text("user_id").notNull(),
22
+ title: text("title").notNull().default("New Chat"),
23
+ metadata: jsonb("metadata"),
24
+ createdAt: timestamp("created_at").defaultNow().notNull(),
25
+ updatedAt: timestamp("updated_at").defaultNow().notNull()
26
+ }, (table) => [
27
+ index("conversations_user_id_idx").on(table.userId),
28
+ index("conversations_updated_at_idx").on(table.updatedAt)
29
+ ]);
30
+ var messages = pgTable("messages", {
31
+ id: text("id").primaryKey(),
32
+ conversationId: text("conversation_id").notNull().references(() => conversations.id, { onDelete: "cascade" }),
33
+ role: text("role").notNull(),
34
+ // 'user' | 'assistant' | 'system'
35
+ content: text("content").notNull(),
36
+ files: jsonb("files"),
37
+ // Array of file attachments
38
+ model: text("model"),
39
+ // AI model used
40
+ metadata: jsonb("metadata"),
41
+ // Additional data (parts, reasoning, etc.)
42
+ createdAt: timestamp("created_at").defaultNow().notNull()
43
+ }, (table) => [
44
+ index("messages_conversation_id_idx").on(table.conversationId),
45
+ index("messages_created_at_idx").on(table.createdAt)
46
+ ]);
47
+
48
+ // src/db/chat-store.ts
49
+ import { generateId } from "ai";
50
+ import { eq, desc, asc, sql } from "drizzle-orm";
51
+ async function createChat(userId) {
52
+ const id = generateId();
53
+ await db.insert(conversations).values({
54
+ id,
55
+ userId,
56
+ title: "New Chat",
57
+ metadata: {}
58
+ });
59
+ return id;
60
+ }
61
+ async function loadChat(conversationId) {
62
+ try {
63
+ const dbMessages = await db.select().from(messages).where(eq(messages.conversationId, conversationId)).orderBy(asc(messages.createdAt));
64
+ if (!dbMessages.length) return [];
65
+ return dbMessages.map((msg) => {
66
+ const metadata = msg.metadata;
67
+ if (metadata?.parts && Array.isArray(metadata.parts)) {
68
+ return {
69
+ id: msg.id,
70
+ role: msg.role,
71
+ parts: metadata.parts,
72
+ createdAt: msg.createdAt
73
+ };
74
+ }
75
+ return {
76
+ id: msg.id,
77
+ role: msg.role,
78
+ parts: [{ type: "text", text: msg.content }],
79
+ createdAt: msg.createdAt
80
+ };
81
+ });
82
+ } catch (error) {
83
+ console.error("Error loading chat:", error);
84
+ return [];
85
+ }
86
+ }
87
+ async function updateConversationTitle(chatId, title) {
88
+ try {
89
+ await db.update(conversations).set({ title, updatedAt: /* @__PURE__ */ new Date() }).where(eq(conversations.id, chatId));
90
+ } catch (error) {
91
+ console.error("Error updating conversation title:", error);
92
+ }
93
+ }
94
+ async function saveChat({
95
+ chatId,
96
+ messages: chatMessages,
97
+ model,
98
+ userId
99
+ }) {
100
+ if (!userId) {
101
+ console.error("userId is required for saveChat");
102
+ return;
103
+ }
104
+ try {
105
+ const existingConv = await db.select({ id: conversations.id, title: conversations.title }).from(conversations).where(eq(conversations.id, chatId)).limit(1);
106
+ if (!existingConv.length) {
107
+ console.error("Conversation not found:", chatId);
108
+ return;
109
+ }
110
+ const conv = existingConv[0];
111
+ if (conv.title === "New Chat") {
112
+ const firstUserMessage = chatMessages.find((m) => m.role === "user");
113
+ if (firstUserMessage) {
114
+ const textPart = firstUserMessage.parts?.find((p) => p.type === "text");
115
+ if (textPart?.text) {
116
+ const newTitle = textPart.text.slice(0, 100);
117
+ await updateConversationTitle(chatId, newTitle);
118
+ }
119
+ }
120
+ }
121
+ const existingMessages = await db.select({ id: messages.id }).from(messages).where(eq(messages.conversationId, chatId));
122
+ const existingIds = new Set(existingMessages.map((m) => m.id));
123
+ const newMessages = chatMessages.filter((msg) => !existingIds.has(msg.id));
124
+ if (newMessages.length > 0) {
125
+ for (const msg of newMessages) {
126
+ const textPart = msg.parts?.find((p) => p.type === "text");
127
+ const fileParts = msg.parts?.filter((p) => p.type === "file") || [];
128
+ await db.insert(messages).values({
129
+ id: msg.id,
130
+ conversationId: chatId,
131
+ role: msg.role,
132
+ content: textPart?.text || "",
133
+ files: fileParts,
134
+ model: model || "openai/gpt-4o-mini",
135
+ metadata: { parts: msg.parts || [] }
136
+ });
137
+ }
138
+ await db.update(conversations).set({ updatedAt: /* @__PURE__ */ new Date() }).where(eq(conversations.id, chatId));
139
+ }
140
+ } catch (error) {
141
+ console.error("Error saving chat:", error);
142
+ }
143
+ }
144
+ async function getConversations(userId) {
145
+ try {
146
+ const result = await db.select({
147
+ id: conversations.id,
148
+ title: conversations.title,
149
+ createdAt: conversations.createdAt,
150
+ updatedAt: conversations.updatedAt,
151
+ metadata: conversations.metadata,
152
+ messageCount: sql`(
153
+ SELECT COUNT(*) FROM ${messages}
154
+ WHERE ${messages.conversationId} = ${conversations.id}
155
+ )`
156
+ }).from(conversations).where(eq(conversations.userId, userId)).orderBy(desc(conversations.updatedAt));
157
+ return result;
158
+ } catch (error) {
159
+ console.error("Error getting conversations:", error);
160
+ return [];
161
+ }
162
+ }
163
+ async function deleteConversation(chatId) {
164
+ try {
165
+ await db.delete(conversations).where(eq(conversations.id, chatId));
166
+ } catch (error) {
167
+ console.error("Error deleting conversation:", error);
168
+ }
169
+ }
170
+
171
+ // src/db/index.ts
172
+ var connectionString = process.env.DATABASE_URL;
173
+ var client = postgres(connectionString, { prepare: false });
174
+ var db = drizzle(client, { schema: schema_exports });
175
+ export {
176
+ conversations,
177
+ createChat,
178
+ db,
179
+ deleteConversation,
180
+ getConversations,
181
+ loadChat,
182
+ messages,
183
+ saveChat,
184
+ updateConversationTitle
185
+ };
186
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/db/index.ts","../../src/db/schema.ts","../../src/db/chat-store.ts"],"sourcesContent":["import 'server-only';\nimport { drizzle } from 'drizzle-orm/postgres-js';\nimport postgres from 'postgres';\nimport * as schema from './schema';\n\n// Create postgres connection\nconst connectionString = process.env.DATABASE_URL!;\n\n// Disable prefetch as it is not supported for \"Transaction\" pool mode\nconst client = postgres(connectionString, { prepare: false });\n\n// Create drizzle database instance\nexport const db = drizzle(client, { schema });\n\n// Export schema for convenience\nexport * from './schema';\n\n// Export chat store functions\nexport * from './chat-store';\n","import { pgTable, text, timestamp, jsonb, index } from 'drizzle-orm/pg-core';\n\n/**\n * Conversations table\n * Stores chat conversation metadata\n */\nexport const conversations = pgTable('conversations', {\n id: text('id').primaryKey(),\n userId: text('user_id').notNull(),\n title: text('title').notNull().default('New Chat'),\n metadata: jsonb('metadata'),\n createdAt: timestamp('created_at').defaultNow().notNull(),\n updatedAt: timestamp('updated_at').defaultNow().notNull(),\n}, (table) => [\n index('conversations_user_id_idx').on(table.userId),\n index('conversations_updated_at_idx').on(table.updatedAt),\n]);\n\n/**\n * Messages table\n * Stores individual chat messages\n */\nexport const messages = pgTable('messages', {\n id: text('id').primaryKey(),\n conversationId: text('conversation_id').notNull().references(() => conversations.id, { onDelete: 'cascade' }),\n role: text('role').notNull(), // 'user' | 'assistant' | 'system'\n content: text('content').notNull(),\n files: jsonb('files'), // Array of file attachments\n model: text('model'), // AI model used\n metadata: jsonb('metadata'), // Additional data (parts, reasoning, etc.)\n createdAt: timestamp('created_at').defaultNow().notNull(),\n}, (table) => [\n index('messages_conversation_id_idx').on(table.conversationId),\n index('messages_created_at_idx').on(table.createdAt),\n]);\n\n// Type exports for use in application code\nexport type Conversation = typeof conversations.$inferSelect;\nexport type NewConversation = typeof conversations.$inferInsert;\nexport type Message = typeof messages.$inferSelect;\nexport type NewMessage = typeof messages.$inferInsert;\n","import { generateId, UIMessage } from 'ai';\nimport { db, conversations, messages } from './index';\nimport { eq, desc, asc, sql } from 'drizzle-orm';\n\n/**\n * Create a new conversation\n */\nexport async function createChat(userId: string): Promise<string> {\n const id = generateId();\n\n await db.insert(conversations).values({\n id,\n userId,\n title: 'New Chat',\n metadata: {},\n });\n\n return id;\n}\n\n/**\n * Load messages for a conversation\n */\nexport async function loadChat(conversationId: string): Promise<UIMessage[]> {\n try {\n const dbMessages = await db\n .select()\n .from(messages)\n .where(eq(messages.conversationId, conversationId))\n .orderBy(asc(messages.createdAt));\n\n if (!dbMessages.length) return [];\n\n // Convert database messages to UIMessage format\n return dbMessages.map((msg) => {\n // If we have metadata with parts, use those (includes reasoning)\n const metadata = msg.metadata as { parts?: any[] } | null;\n if (metadata?.parts && Array.isArray(metadata.parts)) {\n return {\n id: msg.id,\n role: msg.role as 'user' | 'assistant' | 'system',\n parts: metadata.parts,\n createdAt: msg.createdAt,\n };\n }\n\n // Fallback to simple text message\n return {\n id: msg.id,\n role: msg.role as 'user' | 'assistant' | 'system',\n parts: [{ type: 'text', text: msg.content }],\n createdAt: msg.createdAt,\n };\n });\n } catch (error) {\n console.error('Error loading chat:', error);\n return [];\n }\n}\n\n/**\n * Update conversation title\n */\nexport async function updateConversationTitle(\n chatId: string,\n title: string\n): Promise<void> {\n try {\n await db\n .update(conversations)\n .set({ title, updatedAt: new Date() })\n .where(eq(conversations.id, chatId));\n } catch (error) {\n console.error('Error updating conversation title:', error);\n }\n}\n\n/**\n * Save messages to a conversation\n */\nexport async function saveChat({\n chatId,\n messages: chatMessages,\n model,\n userId,\n}: {\n chatId: string;\n messages: UIMessage[];\n model?: string;\n userId: string;\n}): Promise<void> {\n if (!userId) {\n console.error('userId is required for saveChat');\n return;\n }\n\n try {\n // Verify conversation exists\n const existingConv = await db\n .select({ id: conversations.id, title: conversations.title })\n .from(conversations)\n .where(eq(conversations.id, chatId))\n .limit(1);\n\n if (!existingConv.length) {\n console.error('Conversation not found:', chatId);\n return;\n }\n\n const conv = existingConv[0];\n\n // Update title if this is the first user message and title is still \"New Chat\"\n if (conv.title === 'New Chat') {\n const firstUserMessage = chatMessages.find((m) => m.role === 'user');\n if (firstUserMessage) {\n const textPart = firstUserMessage.parts?.find((p) => p.type === 'text') as { text: string } | undefined;\n if (textPart?.text) {\n const newTitle = textPart.text.slice(0, 100);\n await updateConversationTitle(chatId, newTitle);\n }\n }\n }\n\n // Get existing message IDs from database\n const existingMessages = await db\n .select({ id: messages.id })\n .from(messages)\n .where(eq(messages.conversationId, chatId));\n\n const existingIds = new Set(existingMessages.map((m) => m.id));\n\n // Insert only new messages\n const newMessages = chatMessages.filter((msg) => !existingIds.has(msg.id));\n\n if (newMessages.length > 0) {\n for (const msg of newMessages) {\n const textPart = msg.parts?.find((p) => p.type === 'text') as { text: string } | undefined;\n const fileParts = msg.parts?.filter((p) => p.type === 'file') || [];\n\n await db.insert(messages).values({\n id: msg.id,\n conversationId: chatId,\n role: msg.role,\n content: textPart?.text || '',\n files: fileParts,\n model: model || 'openai/gpt-4o-mini',\n metadata: { parts: msg.parts || [] },\n });\n }\n\n // Update conversation's updatedAt\n await db\n .update(conversations)\n .set({ updatedAt: new Date() })\n .where(eq(conversations.id, chatId));\n }\n } catch (error) {\n console.error('Error saving chat:', error);\n }\n}\n\n/**\n * Get all conversations for a user\n */\nexport async function getConversations(userId: string) {\n try {\n const result = await db\n .select({\n id: conversations.id,\n title: conversations.title,\n createdAt: conversations.createdAt,\n updatedAt: conversations.updatedAt,\n metadata: conversations.metadata,\n messageCount: sql<number>`(\n SELECT COUNT(*) FROM ${messages}\n WHERE ${messages.conversationId} = ${conversations.id}\n )`,\n })\n .from(conversations)\n .where(eq(conversations.userId, userId))\n .orderBy(desc(conversations.updatedAt));\n\n return result;\n } catch (error) {\n console.error('Error getting conversations:', error);\n return [];\n }\n}\n\n/**\n * Delete a conversation and all its messages\n */\nexport async function deleteConversation(chatId: string): Promise<void> {\n try {\n // Messages are deleted automatically due to cascade\n await db.delete(conversations).where(eq(conversations.id, chatId));\n } catch (error) {\n console.error('Error deleting conversation:', error);\n }\n}\n"],"mappings":";;;;;;;AAAA,OAAO;AACP,SAAS,eAAe;AACxB,OAAO,cAAc;;;ACFrB;AAAA;AAAA;AAAA;AAAA;AAAA,SAAS,SAAS,MAAM,WAAW,OAAO,aAAa;AAMhD,IAAM,gBAAgB,QAAQ,iBAAiB;AAAA,EACpD,IAAI,KAAK,IAAI,EAAE,WAAW;AAAA,EAC1B,QAAQ,KAAK,SAAS,EAAE,QAAQ;AAAA,EAChC,OAAO,KAAK,OAAO,EAAE,QAAQ,EAAE,QAAQ,UAAU;AAAA,EACjD,UAAU,MAAM,UAAU;AAAA,EAC1B,WAAW,UAAU,YAAY,EAAE,WAAW,EAAE,QAAQ;AAAA,EACxD,WAAW,UAAU,YAAY,EAAE,WAAW,EAAE,QAAQ;AAC1D,GAAG,CAAC,UAAU;AAAA,EACZ,MAAM,2BAA2B,EAAE,GAAG,MAAM,MAAM;AAAA,EAClD,MAAM,8BAA8B,EAAE,GAAG,MAAM,SAAS;AAC1D,CAAC;AAMM,IAAM,WAAW,QAAQ,YAAY;AAAA,EAC1C,IAAI,KAAK,IAAI,EAAE,WAAW;AAAA,EAC1B,gBAAgB,KAAK,iBAAiB,EAAE,QAAQ,EAAE,WAAW,MAAM,cAAc,IAAI,EAAE,UAAU,UAAU,CAAC;AAAA,EAC5G,MAAM,KAAK,MAAM,EAAE,QAAQ;AAAA;AAAA,EAC3B,SAAS,KAAK,SAAS,EAAE,QAAQ;AAAA,EACjC,OAAO,MAAM,OAAO;AAAA;AAAA,EACpB,OAAO,KAAK,OAAO;AAAA;AAAA,EACnB,UAAU,MAAM,UAAU;AAAA;AAAA,EAC1B,WAAW,UAAU,YAAY,EAAE,WAAW,EAAE,QAAQ;AAC1D,GAAG,CAAC,UAAU;AAAA,EACZ,MAAM,8BAA8B,EAAE,GAAG,MAAM,cAAc;AAAA,EAC7D,MAAM,yBAAyB,EAAE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BAAmB,QAAQ,IAAI;AAGrC,IAAM,SAAS,SAAS,kBAAkB,EAAE,SAAS,MAAM,CAAC;AAGrD,IAAM,KAAK,QAAQ,QAAQ,EAAE,uBAAO,CAAC;","names":[]}
@@ -0,0 +1,187 @@
1
+ import * as react_jsx_runtime from 'react/jsx-runtime';
2
+ import * as class_variance_authority_types from 'class-variance-authority/types';
3
+ import * as React from 'react';
4
+ import { VariantProps } from 'class-variance-authority';
5
+ import * as DialogPrimitive from '@radix-ui/react-dialog';
6
+
7
+ /**
8
+ * ChatWidget Configuration Types
9
+ *
10
+ * These types define all the configurable options for the ChatWidget component.
11
+ * They match the structure used in the settings panel for easy integration with
12
+ * a hosted service dashboard later.
13
+ */
14
+ interface ChatWidgetConfig {
15
+ /**
16
+ * User ID for storing conversations
17
+ * This can be any string identifier from your auth system
18
+ * Required for all widget instances
19
+ */
20
+ userId: string;
21
+ /**
22
+ * AI Model configuration
23
+ */
24
+ model?: string;
25
+ /**
26
+ * System prompt for the AI
27
+ */
28
+ systemPrompt?: string;
29
+ /**
30
+ * Temperature for AI responses (0-1)
31
+ * 0 = more focused, 1 = more creative
32
+ */
33
+ temperature?: number;
34
+ /**
35
+ * Theme configuration
36
+ */
37
+ theme?: ThemeConfig;
38
+ /**
39
+ * Feature toggles
40
+ */
41
+ features?: FeatureConfig;
42
+ /**
43
+ * Display configuration (popup vs inline, positioning, etc.)
44
+ */
45
+ display?: DisplayConfig;
46
+ /**
47
+ * Initial conversation ID (if loading existing conversation)
48
+ */
49
+ conversationId?: string;
50
+ /**
51
+ * Initial messages (if starting with pre-filled messages)
52
+ */
53
+ initialMessages?: any[];
54
+ }
55
+ interface ThemeConfig {
56
+ /**
57
+ * Theme mode
58
+ */
59
+ mode?: 'light' | 'dark';
60
+ /**
61
+ * Primary color (hex)
62
+ */
63
+ primaryColor?: string;
64
+ /**
65
+ * Background color (hex)
66
+ */
67
+ backgroundColor?: string;
68
+ /**
69
+ * Text color (hex)
70
+ */
71
+ textColor?: string;
72
+ }
73
+ interface FeatureConfig {
74
+ /**
75
+ * Enable file uploads
76
+ */
77
+ fileUpload?: boolean;
78
+ /**
79
+ * Enable web search
80
+ */
81
+ webSearch?: boolean;
82
+ }
83
+ interface DisplayConfig {
84
+ /**
85
+ * Width of the widget
86
+ * Default: '450px'
87
+ */
88
+ width?: string;
89
+ /**
90
+ * Initial state (open or closed)
91
+ * Default: false
92
+ */
93
+ defaultOpen?: boolean;
94
+ /**
95
+ * Show toggle button to open the chat
96
+ * Default: true
97
+ */
98
+ showToggleButton?: boolean;
99
+ /**
100
+ * Custom toggle button position
101
+ */
102
+ toggleButtonPosition?: {
103
+ bottom?: string;
104
+ right?: string;
105
+ };
106
+ }
107
+
108
+ interface ChatWidgetProps extends ChatWidgetConfig {
109
+ /**
110
+ * CSS class name for custom styling
111
+ */
112
+ className?: string;
113
+ /**
114
+ * Widget ID (for loading config from hosted service later)
115
+ */
116
+ widgetId?: string;
117
+ }
118
+ declare function ChatWidget({ userId, conversationId, initialMessages, className, model, systemPrompt, temperature, theme, features, display, }: ChatWidgetProps): react_jsx_runtime.JSX.Element;
119
+
120
+ interface ChatTheme {
121
+ lightPrimary: string;
122
+ lightSecondary: string;
123
+ lightText: string;
124
+ darkPrimary: string;
125
+ darkSecondary: string;
126
+ darkText: string;
127
+ fontFamily: string;
128
+ fontSize: number;
129
+ }
130
+ type ThemeMode = 'light' | 'dark';
131
+ interface ConversationStarter {
132
+ text: string;
133
+ enabled: boolean;
134
+ }
135
+ declare const fontOptions: {
136
+ value: string;
137
+ label: string;
138
+ }[];
139
+ declare function useChatTheme(): {
140
+ theme: ChatTheme;
141
+ updateColor: (key: keyof ChatTheme, value: string | number) => void;
142
+ updateLightColors: (colors: {
143
+ primary?: string;
144
+ secondary?: string;
145
+ text?: string;
146
+ }) => void;
147
+ updateDarkColors: (colors: {
148
+ primary?: string;
149
+ secondary?: string;
150
+ text?: string;
151
+ }) => void;
152
+ resetTheme: () => void;
153
+ updateFontSize: (size: number) => void;
154
+ updateFontFamily: (family: string) => void;
155
+ conversationStarters: ConversationStarter[];
156
+ updateConversationStarters: (starters: ConversationStarter[]) => void;
157
+ model: string;
158
+ updateModel: (selectedModel: string) => void;
159
+ systemPrompt: string;
160
+ updateSystemPrompt: (prompt: string) => void;
161
+ temperature: number;
162
+ updateTemperature: (temp: number) => void;
163
+ themeMode: ThemeMode;
164
+ updateThemeMode: (mode: ThemeMode) => void;
165
+ };
166
+
167
+ declare const buttonVariants: (props?: ({
168
+ variant?: "default" | "destructive" | "outline" | "secondary" | "ghost" | "link" | null | undefined;
169
+ size?: "default" | "sm" | "lg" | "icon" | null | undefined;
170
+ } & class_variance_authority_types.ClassProp) | undefined) => string;
171
+ declare function Button({ className, variant, size, asChild, ...props }: React.ComponentProps<"button"> & VariantProps<typeof buttonVariants> & {
172
+ asChild?: boolean;
173
+ }): react_jsx_runtime.JSX.Element;
174
+
175
+ interface InputProps extends React.InputHTMLAttributes<HTMLInputElement> {
176
+ }
177
+ declare const Input: React.ForwardRefExoticComponent<InputProps & React.RefAttributes<HTMLInputElement>>;
178
+
179
+ declare function Dialog({ ...props }: React.ComponentProps<typeof DialogPrimitive.Root>): react_jsx_runtime.JSX.Element;
180
+ declare function DialogContent({ className, children, showCloseButton, ...props }: React.ComponentProps<typeof DialogPrimitive.Content> & {
181
+ showCloseButton?: boolean;
182
+ }): react_jsx_runtime.JSX.Element;
183
+ declare function DialogHeader({ className, ...props }: React.ComponentProps<"div">): react_jsx_runtime.JSX.Element;
184
+ declare function DialogTitle({ className, ...props }: React.ComponentProps<typeof DialogPrimitive.Title>): react_jsx_runtime.JSX.Element;
185
+ declare function DialogDescription({ className, ...props }: React.ComponentProps<typeof DialogPrimitive.Description>): react_jsx_runtime.JSX.Element;
186
+
187
+ export { Button, type ChatTheme, ChatWidget, type ChatWidgetConfig, type ChatWidgetProps, type ConversationStarter, Dialog, DialogContent, DialogDescription, DialogHeader, DialogTitle, type DisplayConfig, type FeatureConfig, Input, type ThemeConfig, type ThemeMode, ChatWidget as default, fontOptions, useChatTheme };
@@ -0,0 +1,187 @@
1
+ import * as react_jsx_runtime from 'react/jsx-runtime';
2
+ import * as class_variance_authority_types from 'class-variance-authority/types';
3
+ import * as React from 'react';
4
+ import { VariantProps } from 'class-variance-authority';
5
+ import * as DialogPrimitive from '@radix-ui/react-dialog';
6
+
7
+ /**
8
+ * ChatWidget Configuration Types
9
+ *
10
+ * These types define all the configurable options for the ChatWidget component.
11
+ * They match the structure used in the settings panel for easy integration with
12
+ * a hosted service dashboard later.
13
+ */
14
+ interface ChatWidgetConfig {
15
+ /**
16
+ * User ID for storing conversations
17
+ * This can be any string identifier from your auth system
18
+ * Required for all widget instances
19
+ */
20
+ userId: string;
21
+ /**
22
+ * AI Model configuration
23
+ */
24
+ model?: string;
25
+ /**
26
+ * System prompt for the AI
27
+ */
28
+ systemPrompt?: string;
29
+ /**
30
+ * Temperature for AI responses (0-1)
31
+ * 0 = more focused, 1 = more creative
32
+ */
33
+ temperature?: number;
34
+ /**
35
+ * Theme configuration
36
+ */
37
+ theme?: ThemeConfig;
38
+ /**
39
+ * Feature toggles
40
+ */
41
+ features?: FeatureConfig;
42
+ /**
43
+ * Display configuration (popup vs inline, positioning, etc.)
44
+ */
45
+ display?: DisplayConfig;
46
+ /**
47
+ * Initial conversation ID (if loading existing conversation)
48
+ */
49
+ conversationId?: string;
50
+ /**
51
+ * Initial messages (if starting with pre-filled messages)
52
+ */
53
+ initialMessages?: any[];
54
+ }
55
+ interface ThemeConfig {
56
+ /**
57
+ * Theme mode
58
+ */
59
+ mode?: 'light' | 'dark';
60
+ /**
61
+ * Primary color (hex)
62
+ */
63
+ primaryColor?: string;
64
+ /**
65
+ * Background color (hex)
66
+ */
67
+ backgroundColor?: string;
68
+ /**
69
+ * Text color (hex)
70
+ */
71
+ textColor?: string;
72
+ }
73
+ interface FeatureConfig {
74
+ /**
75
+ * Enable file uploads
76
+ */
77
+ fileUpload?: boolean;
78
+ /**
79
+ * Enable web search
80
+ */
81
+ webSearch?: boolean;
82
+ }
83
+ interface DisplayConfig {
84
+ /**
85
+ * Width of the widget
86
+ * Default: '450px'
87
+ */
88
+ width?: string;
89
+ /**
90
+ * Initial state (open or closed)
91
+ * Default: false
92
+ */
93
+ defaultOpen?: boolean;
94
+ /**
95
+ * Show toggle button to open the chat
96
+ * Default: true
97
+ */
98
+ showToggleButton?: boolean;
99
+ /**
100
+ * Custom toggle button position
101
+ */
102
+ toggleButtonPosition?: {
103
+ bottom?: string;
104
+ right?: string;
105
+ };
106
+ }
107
+
108
+ interface ChatWidgetProps extends ChatWidgetConfig {
109
+ /**
110
+ * CSS class name for custom styling
111
+ */
112
+ className?: string;
113
+ /**
114
+ * Widget ID (for loading config from hosted service later)
115
+ */
116
+ widgetId?: string;
117
+ }
118
+ declare function ChatWidget({ userId, conversationId, initialMessages, className, model, systemPrompt, temperature, theme, features, display, }: ChatWidgetProps): react_jsx_runtime.JSX.Element;
119
+
120
+ interface ChatTheme {
121
+ lightPrimary: string;
122
+ lightSecondary: string;
123
+ lightText: string;
124
+ darkPrimary: string;
125
+ darkSecondary: string;
126
+ darkText: string;
127
+ fontFamily: string;
128
+ fontSize: number;
129
+ }
130
+ type ThemeMode = 'light' | 'dark';
131
+ interface ConversationStarter {
132
+ text: string;
133
+ enabled: boolean;
134
+ }
135
+ declare const fontOptions: {
136
+ value: string;
137
+ label: string;
138
+ }[];
139
+ declare function useChatTheme(): {
140
+ theme: ChatTheme;
141
+ updateColor: (key: keyof ChatTheme, value: string | number) => void;
142
+ updateLightColors: (colors: {
143
+ primary?: string;
144
+ secondary?: string;
145
+ text?: string;
146
+ }) => void;
147
+ updateDarkColors: (colors: {
148
+ primary?: string;
149
+ secondary?: string;
150
+ text?: string;
151
+ }) => void;
152
+ resetTheme: () => void;
153
+ updateFontSize: (size: number) => void;
154
+ updateFontFamily: (family: string) => void;
155
+ conversationStarters: ConversationStarter[];
156
+ updateConversationStarters: (starters: ConversationStarter[]) => void;
157
+ model: string;
158
+ updateModel: (selectedModel: string) => void;
159
+ systemPrompt: string;
160
+ updateSystemPrompt: (prompt: string) => void;
161
+ temperature: number;
162
+ updateTemperature: (temp: number) => void;
163
+ themeMode: ThemeMode;
164
+ updateThemeMode: (mode: ThemeMode) => void;
165
+ };
166
+
167
+ declare const buttonVariants: (props?: ({
168
+ variant?: "default" | "destructive" | "outline" | "secondary" | "ghost" | "link" | null | undefined;
169
+ size?: "default" | "sm" | "lg" | "icon" | null | undefined;
170
+ } & class_variance_authority_types.ClassProp) | undefined) => string;
171
+ declare function Button({ className, variant, size, asChild, ...props }: React.ComponentProps<"button"> & VariantProps<typeof buttonVariants> & {
172
+ asChild?: boolean;
173
+ }): react_jsx_runtime.JSX.Element;
174
+
175
+ interface InputProps extends React.InputHTMLAttributes<HTMLInputElement> {
176
+ }
177
+ declare const Input: React.ForwardRefExoticComponent<InputProps & React.RefAttributes<HTMLInputElement>>;
178
+
179
+ declare function Dialog({ ...props }: React.ComponentProps<typeof DialogPrimitive.Root>): react_jsx_runtime.JSX.Element;
180
+ declare function DialogContent({ className, children, showCloseButton, ...props }: React.ComponentProps<typeof DialogPrimitive.Content> & {
181
+ showCloseButton?: boolean;
182
+ }): react_jsx_runtime.JSX.Element;
183
+ declare function DialogHeader({ className, ...props }: React.ComponentProps<"div">): react_jsx_runtime.JSX.Element;
184
+ declare function DialogTitle({ className, ...props }: React.ComponentProps<typeof DialogPrimitive.Title>): react_jsx_runtime.JSX.Element;
185
+ declare function DialogDescription({ className, ...props }: React.ComponentProps<typeof DialogPrimitive.Description>): react_jsx_runtime.JSX.Element;
186
+
187
+ export { Button, type ChatTheme, ChatWidget, type ChatWidgetConfig, type ChatWidgetProps, type ConversationStarter, Dialog, DialogContent, DialogDescription, DialogHeader, DialogTitle, type DisplayConfig, type FeatureConfig, Input, type ThemeConfig, type ThemeMode, ChatWidget as default, fontOptions, useChatTheme };