@vercel/geistdocs 2.7.10 → 2.9.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.
Files changed (128) hide show
  1. package/dist/assets/icons/icon-fullscreen-close.d.ts +26 -0
  2. package/dist/assets/icons/icon-fullscreen-close.d.ts.map +1 -0
  3. package/dist/assets/icons/icon-fullscreen-close.js +25 -0
  4. package/dist/assets/icons/icon-fullscreen.d.ts +26 -0
  5. package/dist/assets/icons/icon-fullscreen.d.ts.map +1 -0
  6. package/dist/assets/icons/icon-fullscreen.js +25 -0
  7. package/dist/assets/icons/icon-thumb-down.d.ts +26 -0
  8. package/dist/assets/icons/icon-thumb-down.d.ts.map +1 -0
  9. package/dist/assets/icons/icon-thumb-down.js +25 -0
  10. package/dist/assets/icons/index.d.ts +3 -0
  11. package/dist/assets/icons/index.d.ts.map +1 -1
  12. package/dist/assets/icons/index.js +3 -0
  13. package/dist/cli/index.js +1 -1
  14. package/dist/config.d.ts +67 -3
  15. package/dist/config.d.ts.map +1 -1
  16. package/dist/controls.d.ts +23 -1
  17. package/dist/controls.d.ts.map +1 -1
  18. package/dist/controls.js +44 -3
  19. package/dist/footer.js +1 -1
  20. package/dist/internal/chat/activity.d.ts +5 -1
  21. package/dist/internal/chat/activity.d.ts.map +1 -1
  22. package/dist/internal/chat/activity.js +11 -4
  23. package/dist/internal/chat/chat-user.d.ts +12 -0
  24. package/dist/internal/chat/chat-user.d.ts.map +1 -0
  25. package/dist/internal/chat/chat-user.js +27 -0
  26. package/dist/internal/chat/commands.d.ts +91 -0
  27. package/dist/internal/chat/commands.d.ts.map +1 -0
  28. package/dist/internal/chat/commands.js +165 -0
  29. package/dist/internal/chat/context.d.ts +49 -2
  30. package/dist/internal/chat/context.d.ts.map +1 -1
  31. package/dist/internal/chat/context.js +57 -4
  32. package/dist/internal/chat/message-actions.d.ts +15 -0
  33. package/dist/internal/chat/message-actions.d.ts.map +1 -0
  34. package/dist/internal/chat/message-actions.js +113 -0
  35. package/dist/internal/chat/message-feedback.d.ts +68 -0
  36. package/dist/internal/chat/message-feedback.d.ts.map +1 -0
  37. package/dist/internal/chat/message-feedback.js +188 -0
  38. package/dist/internal/chat/message-metadata.d.ts.map +1 -1
  39. package/dist/internal/chat/message-metadata.js +7 -1
  40. package/dist/internal/chat/message-text.d.ts +9 -0
  41. package/dist/internal/chat/message-text.d.ts.map +1 -0
  42. package/dist/internal/chat/message-text.js +15 -0
  43. package/dist/internal/chat/message.d.ts +4 -2
  44. package/dist/internal/chat/message.d.ts.map +1 -1
  45. package/dist/internal/chat/message.js +8 -1
  46. package/dist/internal/chat/options.d.ts +94 -0
  47. package/dist/internal/chat/options.d.ts.map +1 -0
  48. package/dist/internal/chat/options.js +171 -0
  49. package/dist/internal/chat/page-attachment.d.ts +12 -0
  50. package/dist/internal/chat/page-attachment.d.ts.map +1 -0
  51. package/dist/internal/chat/page-attachment.js +18 -0
  52. package/dist/internal/chat/session-provider.d.ts +33 -0
  53. package/dist/internal/chat/session-provider.d.ts.map +1 -0
  54. package/dist/internal/chat/session-provider.js +138 -0
  55. package/dist/internal/chat/session.d.ts +60 -0
  56. package/dist/internal/chat/session.d.ts.map +1 -0
  57. package/dist/internal/chat/session.js +85 -0
  58. package/dist/internal/chat/shell.d.ts.map +1 -1
  59. package/dist/internal/chat/shell.js +86 -157
  60. package/dist/internal/chat/use-chat-commands.d.ts +28 -0
  61. package/dist/internal/chat/use-chat-commands.d.ts.map +1 -0
  62. package/dist/internal/chat/use-chat-commands.js +62 -0
  63. package/dist/internal/chat/user-avatar.d.ts +7 -0
  64. package/dist/internal/chat/user-avatar.d.ts.map +1 -0
  65. package/dist/internal/chat/user-avatar.js +27 -0
  66. package/dist/internal/eve-agent-session-cookie.d.ts +68 -0
  67. package/dist/internal/eve-agent-session-cookie.d.ts.map +1 -0
  68. package/dist/internal/eve-agent-session-cookie.js +164 -0
  69. package/dist/internal/eve-agent-session.d.ts +9 -7
  70. package/dist/internal/eve-agent-session.d.ts.map +1 -1
  71. package/dist/internal/eve-agent-session.js +10 -13
  72. package/dist/internal/eve-agent.d.ts +96 -24
  73. package/dist/internal/eve-agent.d.ts.map +1 -1
  74. package/dist/internal/eve-agent.js +74 -51
  75. package/dist/internal/feedback-action.d.ts +14 -0
  76. package/dist/internal/feedback-action.d.ts.map +1 -1
  77. package/dist/internal/feedback-action.js +37 -5
  78. package/dist/internal/mdx-to-markdown.d.ts.map +1 -1
  79. package/dist/internal/mdx-to-markdown.js +226 -19
  80. package/dist/internal/page-actions-client.d.ts +9 -0
  81. package/dist/internal/page-actions-client.d.ts.map +1 -1
  82. package/dist/internal/page-actions-client.js +8 -4
  83. package/dist/internal/provider-client.d.ts.map +1 -1
  84. package/dist/internal/provider-client.js +10 -4
  85. package/dist/internal/use-mobile.d.ts +7 -0
  86. package/dist/internal/use-mobile.d.ts.map +1 -1
  87. package/dist/internal/use-mobile.js +17 -1
  88. package/dist/internal/webmcp-client.d.ts.map +1 -1
  89. package/dist/internal/webmcp-client.js +13 -3
  90. package/dist/internal/webmcp.d.ts +5 -1
  91. package/dist/internal/webmcp.d.ts.map +1 -1
  92. package/dist/internal/webmcp.js +31 -1
  93. package/dist/pages/changelog.d.ts.map +1 -1
  94. package/dist/pages/changelog.js +4 -0
  95. package/dist/pages/docs.d.ts.map +1 -1
  96. package/dist/pages/docs.js +2 -0
  97. package/dist/routes/chat.d.ts +83 -5
  98. package/dist/routes/chat.d.ts.map +1 -1
  99. package/dist/routes/chat.js +517 -80
  100. package/dist/routes/discovery.d.ts +1 -1
  101. package/dist/routes/discovery.d.ts.map +1 -1
  102. package/dist/routes/discovery.js +7 -11
  103. package/dist/routes/openapi.d.ts.map +1 -1
  104. package/dist/routes/openapi.js +47 -25
  105. package/docs/agents.md +3 -3
  106. package/docs/llms.txt +634 -37
  107. package/docs/manifest.json +3 -3
  108. package/docs/pages/agent-readiness.md +1 -1
  109. package/docs/pages/ask-ai.md +570 -26
  110. package/docs/pages/configuration.md +21 -1
  111. package/docs/pages/env.md +17 -3
  112. package/docs/pages/feedback.md +4 -0
  113. package/docs/pages/webmcp.md +18 -3
  114. package/docs/sitemap.md +1 -1
  115. package/package.json +1 -2
  116. package/template/.env.example +5 -0
  117. package/template/AGENTS.md +2 -0
  118. package/template/content/docs/agent-readiness.mdx +1 -1
  119. package/template/content/docs/ask-ai.cn.mdx +466 -15
  120. package/template/content/docs/ask-ai.mdx +570 -26
  121. package/template/content/docs/configuration.cn.mdx +39 -0
  122. package/template/content/docs/configuration.mdx +21 -1
  123. package/template/content/docs/env.cn.mdx +15 -1
  124. package/template/content/docs/env.mdx +18 -4
  125. package/template/content/docs/feedback.cn.mdx +4 -0
  126. package/template/content/docs/feedback.mdx +4 -0
  127. package/template/content/docs/webmcp.mdx +18 -3
  128. package/template/package.json +1 -2
@@ -1,14 +1,10 @@
1
1
  "use client";
2
2
  import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
3
3
  import { useChat } from "@ai-sdk/react";
4
- import { DefaultChatTransport } from "ai";
5
- import { useLiveQuery } from "dexie-react-hooks";
6
4
  import { catchError } from "next/error";
7
- import { usePathname } from "next/navigation";
8
5
  import { Portal } from "radix-ui";
9
- import { useCallback, useEffect, useId, useMemo, useRef, useState, } from "react";
10
- import { IconChevronDoubleRight, IconCreditCard, IconDeviceDesktop, IconFluid, IconTrash, } from "#geistdocs-assets/icons";
11
- import { LogoIconVercelFillSvg } from "#geistdocs-assets/logos";
6
+ import { useEffect, useRef } from "react";
7
+ import { IconChevronDoubleRight, IconFullscreen, IconFullscreenClose, IconTrash, } from "#geistdocs-assets/icons";
12
8
  import { Button } from "#geistdocs-ui/components/button";
13
9
  import { Drawer, DrawerTitle } from "#geistdocs-ui/components/drawer";
14
10
  import { Kbd } from "#geistdocs-ui/components/kbd";
@@ -16,160 +12,81 @@ import { Spinner } from "#geistdocs-ui/components/spinner";
16
12
  import { useToasts } from "#geistdocs-ui/components/toasts";
17
13
  import { Tooltip } from "#geistdocs-ui/components/tooltip";
18
14
  import { cn } from "#geistdocs-ui/utils";
19
- import { getPublicPath } from "../../config";
20
- import { requestEveAgentPrewarm } from "../eve-agent-session.js";
21
- import { useIsMobile } from "../use-mobile";
15
+ import { useIsMobileAfterHydration } from "../use-mobile";
22
16
  import { isActiveAssistantMessage, shouldShowPendingActivity, } from "./activity";
23
- import { useGeistdocsChat } from "./context";
17
+ import { useGeistdocsChatContext } from "./context";
24
18
  import { Conversation, ConversationContent, ConversationScrollButton, } from "./conversation";
25
19
  import { CopyChat } from "./copy-chat";
26
- import { getChatDatabase } from "./db";
27
20
  import { DotsSpinner } from "./dots-spinner";
28
21
  import { Message, MessageContent, MessageResponse } from "./message";
22
+ import { MessageActions } from "./message-actions";
29
23
  import { MessageMetadata } from "./message-metadata";
24
+ import { ChatMessagePageChip, ChatPageAttachmentCard } from "./page-attachment";
30
25
  import { ChatPromptInput } from "./prompt-input";
26
+ import { GeistdocsChatSessionProvider, useChatSession, } from "./session-provider";
31
27
  import { Suggestion, Suggestions } from "./suggestion";
32
- const isFromPreviousDay = (timestamp) => {
33
- const messageDate = new Date(timestamp);
34
- const today = new Date();
35
- return (messageDate.getFullYear() !== today.getFullYear() ||
36
- messageDate.getMonth() !== today.getMonth() ||
37
- messageDate.getDate() !== today.getDate());
38
- };
39
- const suggestionIcons = [
40
- _jsx(LogoIconVercelFillSvg, { color: "gray-700" }, "vercel"),
41
- _jsx(IconDeviceDesktop, { color: "gray-700" }, "deploy"),
42
- _jsx(IconFluid, { color: "gray-700" }, "fluid"),
43
- _jsx(IconCreditCard, { color: "gray-700" }, "cost"),
44
- ];
45
- const useChatPersistence = (title) => {
46
- const saveTimeoutRef = useRef(undefined);
47
- const db = useMemo(() => getChatDatabase(title), [title]);
48
- const storedMessages = useLiveQuery(() => db.messages.orderBy("sequence").toArray(), [db]);
28
+ import { useChatCommands } from "./use-chat-commands";
29
+ import { useChatUserAvatar } from "./user-avatar";
30
+ const ChatLoading = () => (_jsx("div", { className: "flex size-full w-full flex-col items-center justify-center overflow-hidden whitespace-nowrap rounded-xl xl:max-w-md xl:border xl:bg-background-100", children: _jsx(Spinner, {}) }));
31
+ // Centers the header, transcript, and composer when the panel fills the
32
+ // viewport, so lines stay readable on wide screens.
33
+ const EXPANDED_COLUMN = "mx-auto w-full max-w-5xl";
34
+ const GeistdocsChatInner = ({ active, expandable = false, isOpen, }) => {
35
+ const state = useChatSession();
36
+ const textareaRef = useRef(null);
37
+ const ready = state.status === "ready";
38
+ // Focus the prompt when the chat opens or finishes loading while open. It
39
+ // lives here rather than in the panel so the panel mounting when this
40
+ // shell becomes active (a breakpoint change) doesn't move focus.
49
41
  useEffect(() => {
50
- if (storedMessages && storedMessages.length > 0) {
51
- const firstMessage = storedMessages[0];
52
- if (firstMessage && isFromPreviousDay(firstMessage.timestamp)) {
53
- db.messages.clear();
54
- }
55
- }
56
- }, [db, storedMessages]);
57
- const freshMessages = storedMessages?.filter((message) => !isFromPreviousDay(message.timestamp));
58
- const initialMessages = freshMessages?.map(({ timestamp, sequence, ...message }) => message) ?? [];
59
- const isLoading = storedMessages === undefined;
60
- const saveMessages = useCallback((messages) => {
61
- if (saveTimeoutRef.current) {
62
- clearTimeout(saveTimeoutRef.current);
63
- }
64
- saveTimeoutRef.current = setTimeout(async () => {
65
- try {
66
- const baseTimestamp = Date.now();
67
- const messagesToStore = messages.map((message, index) => ({
68
- ...message,
69
- timestamp: baseTimestamp + index * 1000,
70
- sequence: index,
71
- }));
72
- await db.transaction("rw", db.messages, async () => {
73
- await db.messages.clear();
74
- await db.messages.bulkAdd(messagesToStore);
75
- });
76
- }
77
- catch (error) {
78
- console.error("Failed to save messages:", error);
79
- }
80
- }, 300);
81
- }, [db]);
82
- const clearMessages = useCallback(async () => {
83
- try {
84
- if (saveTimeoutRef.current) {
85
- clearTimeout(saveTimeoutRef.current);
86
- saveTimeoutRef.current = undefined;
87
- }
88
- await db.messages.clear();
89
- }
90
- catch (error) {
91
- console.error("Failed to clear messages:", error);
92
- }
93
- }, [db]);
94
- useEffect(() => () => {
95
- if (saveTimeoutRef.current) {
96
- clearTimeout(saveTimeoutRef.current);
42
+ if (!(isOpen && ready)) {
43
+ return;
97
44
  }
98
- }, []);
99
- return {
100
- initialMessages,
101
- isLoading,
102
- saveMessages,
103
- clearMessages,
104
- };
45
+ const timer = setTimeout(() => {
46
+ textareaRef.current?.focus();
47
+ }, 100);
48
+ return () => clearTimeout(timer);
49
+ }, [isOpen, ready]);
50
+ // The inactive shell is hidden, so it renders nothing: only the visible
51
+ // shell subscribes to the chat and re-renders as a response streams. When
52
+ // the breakpoint changes, the newly active shell renders the shared
53
+ // conversation in full on its first render.
54
+ if (!active) {
55
+ return null;
56
+ }
57
+ if (state.status === "error") {
58
+ // Thrown here, inside the chat error boundary, so an invalid
59
+ // `ai.endpoint` or unreadable history fails the panel, not the page.
60
+ throw state.error;
61
+ }
62
+ if (state.status === "loading") {
63
+ return _jsx(ChatLoading, {});
64
+ }
65
+ return (_jsx(GeistdocsChatPanel, { clearConversation: state.clearConversation, expandable: expandable, session: state.session, textareaRef: textareaRef }));
105
66
  };
106
- const GeistdocsChatInner = ({ isOpen }) => {
107
- const id = useId();
108
- const pathname = usePathname();
109
- const textareaRef = useRef(null);
110
- const prewarmPromiseRef = useRef(null);
111
- const [isInitialized, setIsInitialized] = useState(false);
67
+ const GeistdocsChatPanel = ({ clearConversation, expandable, session, textareaRef, }) => {
112
68
  const toast = useToasts();
113
- const { prompt, setPrompt, setIsOpen, title, basePath, footer, prewarmEveAgent, suggestions, } = useGeistdocsChat();
114
- const { initialMessages, isLoading, saveMessages, clearMessages } = useChatPersistence(title);
115
- const chatApi = getPublicPath("/api/chat", basePath);
116
- const { messages, sendMessage, status, setMessages, stop } = useChat({
117
- id,
118
- transport: new DefaultChatTransport({
119
- api: chatApi,
120
- prepareSendMessagesRequest: async ({ body, messages }) => {
121
- const prewarmedSession = await prewarmPromiseRef.current;
122
- prewarmPromiseRef.current = null;
123
- return {
124
- body: {
125
- ...body,
126
- messages,
127
- currentRoute: pathname,
128
- eveAgentSession: prewarmedSession ?? undefined,
129
- },
130
- };
131
- },
132
- }),
133
- onError: (error) => {
134
- toast.error({ text: error.message });
135
- },
69
+ const { prompt, setPrompt, setIsOpen, chatTitle, commands, commandState, footer, isExpanded: isExpandedState, setIsExpanded, suggestions, } = useGeistdocsChatContext();
70
+ const isExpanded = expandable && isExpandedState;
71
+ const expandLabel = isExpanded ? "Collapse chat" : "Expand chat";
72
+ const userAvatar = useChatUserAvatar();
73
+ const { messages, sendMessage, setMessages, status, stop } = useChat({
74
+ chat: session.chat,
75
+ });
76
+ const submitText = useChatCommands({
77
+ clearConversation,
78
+ commandState,
79
+ commands,
80
+ sendMessage,
81
+ status,
82
+ stop,
136
83
  });
137
- useEffect(() => {
138
- if (!(isLoading || isInitialized) && initialMessages.length > 0) {
139
- setMessages(initialMessages);
140
- setIsInitialized(true);
141
- }
142
- else if (!(isLoading || isInitialized)) {
143
- setIsInitialized(true);
144
- }
145
- }, [initialMessages, isInitialized, isLoading, setMessages]);
146
- useEffect(() => {
147
- if (prewarmEveAgent &&
148
- isInitialized &&
149
- messages.length === 0 &&
150
- prewarmPromiseRef.current === null) {
151
- prewarmPromiseRef.current = requestEveAgentPrewarm({ apiUrl: chatApi });
152
- }
153
- }, [chatApi, isInitialized, messages.length, prewarmEveAgent]);
154
- useEffect(() => {
155
- if (isInitialized && messages.length > 0) {
156
- saveMessages(messages);
157
- }
158
- }, [isInitialized, messages, saveMessages]);
159
- useEffect(() => {
160
- if (isOpen) {
161
- const timer = setTimeout(() => {
162
- textareaRef.current?.focus();
163
- }, 100);
164
- return () => clearTimeout(timer);
165
- }
166
- }, [isOpen]);
167
84
  const handleSuggestionClick = async (text) => {
168
85
  if (status === "streaming" || status === "submitted") {
169
86
  return;
170
87
  }
171
88
  setPrompt("");
172
- await sendMessage({ text });
89
+ await submitText(text);
173
90
  };
174
91
  const handleSubmit = async () => {
175
92
  if (status === "streaming" || status === "submitted" || !prompt) {
@@ -177,12 +94,12 @@ const GeistdocsChatInner = ({ isOpen }) => {
177
94
  }
178
95
  const currentPrompt = prompt;
179
96
  setPrompt("");
180
- await sendMessage({ text: currentPrompt });
97
+ await submitText(currentPrompt);
181
98
  };
182
99
  const handleClearChat = async () => {
183
100
  try {
184
- await clearMessages();
185
- setMessages([]);
101
+ await clearConversation();
102
+ commands.detachPage();
186
103
  toast.success({ text: "Chat cleared" });
187
104
  }
188
105
  catch (error) {
@@ -193,33 +110,45 @@ const GeistdocsChatInner = ({ isOpen }) => {
193
110
  });
194
111
  }
195
112
  };
196
- if (isLoading) {
197
- return (_jsx("div", { className: "flex size-full w-full flex-col items-center justify-center overflow-hidden whitespace-nowrap rounded-xl xl:max-w-md xl:border xl:bg-background-100", children: _jsx(Spinner, {}) }));
198
- }
199
- return (_jsxs("aside", { "aria-label": "Ask AI chat", className: "flex size-full w-full flex-col overflow-hidden whitespace-nowrap bg-background-100", children: [_jsxs("div", { className: "sticky top-0 z-10 flex h-16 items-center justify-between bg-background-100 py-2 pr-2 pl-3.5", children: [_jsx("h2", { className: "font-semibold text-sm", children: "Ask AI" }), _jsxs("div", { className: "flex items-center gap-0.5", children: [_jsx(CopyChat, { messages: messages }), _jsx(Tooltip, { position: "bottom", text: "Delete chat", children: _jsx(Button, { "aria-label": "Delete chat", className: "text-gray-800! disabled:bg-gray-alpha-100!", disabled: messages.length === 0 ||
113
+ return (_jsxs("aside", { "aria-label": `${chatTitle} chat`, className: "flex size-full w-full flex-col overflow-hidden whitespace-nowrap bg-background-100", children: [_jsxs("div", { className: cn("sticky top-0 z-10 flex h-16 shrink-0 items-center justify-between bg-background-100 py-2 pr-2 pl-3.5", isExpanded && EXPANDED_COLUMN), children: [_jsx("h2", { className: "font-semibold text-sm", children: chatTitle }), _jsxs("div", { className: "flex items-center gap-0.5", children: [_jsx(CopyChat, { messages: messages }), expandable ? (_jsx(Tooltip, { position: "bottom", text: expandLabel, children: _jsx(Button, { "aria-label": expandLabel, "aria-pressed": isExpanded, className: "text-gray-800! shadow-none", onClick: () => setIsExpanded(!isExpanded), shape: "square", size: "small", svgOnly: true, typeName: "button", variant: "tertiary", children: isExpanded ? (_jsx(IconFullscreenClose, { size: 14 })) : (_jsx(IconFullscreen, { size: 14 })) }) })) : null, _jsx(Tooltip, { position: "bottom", text: "Delete chat", children: _jsx(Button, { "aria-label": "Delete chat", className: "text-gray-800! disabled:bg-gray-alpha-100!", disabled: messages.length === 0 ||
200
114
  status === "streaming" ||
201
- status === "submitted", onClick: handleClearChat, shape: "square", size: "small", svgOnly: true, typeName: "button", variant: "tertiary", children: _jsx(IconTrash, { size: 14 }) }) }), _jsx(Tooltip, { position: "bottom", text: "Close chat", children: _jsx(Button, { "aria-label": "Close chat", className: "text-gray-800! shadow-none", onClick: () => setIsOpen(false), shape: "square", size: "small", svgOnly: true, typeName: "button", variant: "tertiary", children: _jsx(IconChevronDoubleRight, { size: 14 }) }) })] })] }), _jsxs(Conversation, { children: [_jsxs(ConversationContent, { children: [messages.map((message, index) => (_jsxs(Message, { from: message.role, children: [_jsx(MessageMetadata, { inProgress: isActiveAssistantMessage({
115
+ status === "submitted", onClick: handleClearChat, shape: "square", size: "small", svgOnly: true, typeName: "button", variant: "tertiary", children: _jsx(IconTrash, { size: 14 }) }) }), _jsx(Tooltip, { position: "bottom", text: "Close chat", children: _jsx(Button, { "aria-label": "Close chat", className: "text-gray-800! shadow-none", onClick: () => setIsOpen(false), shape: "square", size: "small", svgOnly: true, typeName: "button", variant: "tertiary", children: _jsx(IconChevronDoubleRight, { size: 14 }) }) })] })] }), _jsxs(Conversation, { children: [_jsxs(ConversationContent, { className: cn(isExpanded && EXPANDED_COLUMN), children: [messages.map((message, index) => (_jsxs(Message, { avatar: message.role === "user" ? userAvatar : undefined, from: message.role, children: [_jsx(MessageMetadata, { inProgress: isActiveAssistantMessage({
202
116
  index,
203
117
  messages,
204
118
  status,
205
- }), parts: message.parts }), message.parts
119
+ }), parts: message.parts }), _jsx(ChatMessagePageChip, { metadata: message.metadata }), message.parts
206
120
  .filter((part) => part.type === "text")
207
- .map((part) => (_jsx(MessageContent, { children: _jsx(MessageResponse, { className: "text-wrap", children: part.text }) }, `${message.id}-${part.type}-${part.text}`)))] }, message.id))), shouldShowPendingActivity({ messages, status }) ? (_jsx("div", { className: "h-12 animate-pulse pt-2 text-gray-900 text-sm", children: _jsx(DotsSpinner, {}) })) : null] }), _jsx(ConversationScrollButton, {})] }), _jsxs("div", { className: "relative grid w-auto shrink-0 gap-3 whitespace-normal p-4 text-left", children: [messages.length ? null : (_jsxs(_Fragment, { children: [_jsx(Suggestions, { className: "w-full cursor-text", children: suggestions.slice(0, 4).map((text, index) => (_jsx(Suggestion, { className: "w-full", icon: suggestionIcons[index], onClick: handleSuggestionClick, suggestion: text, variant: "tertiary" }, text))) }), _jsxs("p", { className: "mb-3 whitespace-normal px-2 text-left text-gray-900 text-label-14", children: ["Tip: You can open and close chat with", _jsx(Kbd, { className: "material-base ml-1.5 text-gray-900", meta: true, small: true }), _jsx(Kbd, { className: "material-base ml-1 font-mono! text-gray-900", small: true, children: "I" })] })] })), _jsx(ChatPromptInput, { onChange: setPrompt, onStop: stop, onSubmit: (event) => {
121
+ .map((part) => (_jsx(MessageContent, { children: _jsx(MessageResponse, { className: "text-wrap", children: part.text }) }, `${message.id}-${part.type}-${part.text}`))), _jsx(MessageActions, { index: index, messages: messages, setMessages: setMessages, status: status })] }, message.id))), shouldShowPendingActivity({ messages, status }) ? (_jsx("div", { className: "h-12 animate-pulse pt-2 text-gray-900 text-sm", children: _jsx(DotsSpinner, {}) })) : null] }), _jsx(ConversationScrollButton, {})] }), _jsxs("div", { className: cn("relative grid w-auto shrink-0 gap-3 whitespace-normal p-4 text-left", isExpanded && EXPANDED_COLUMN), children: [messages.length ? null : (_jsxs(_Fragment, { children: [_jsx(Suggestions, { className: "w-full cursor-text", children: suggestions.map((suggestion) => (_jsx(Suggestion, { className: "w-full", icon: suggestion.icon, onClick: handleSuggestionClick, suggestion: suggestion.text, variant: "tertiary" }, suggestion.key))) }), _jsxs("p", { className: "mb-3 whitespace-normal px-2 text-left text-gray-900 text-label-14", children: ["Tip: You can open and close chat with", _jsx(Kbd, { className: "material-base ml-1.5 text-gray-900", meta: true, small: true }), _jsx(Kbd, { className: "material-base ml-1 font-mono! text-gray-900", small: true, children: "I" })] })] })), commandState.attachedPage ? (_jsx(ChatPageAttachmentCard, { onRemove: commands.detachPage, page: commandState.attachedPage })) : null, _jsx(ChatPromptInput, { onChange: setPrompt, onStop: stop, onSubmit: (event) => {
208
122
  event.preventDefault();
209
123
  handleSubmit().catch((error) => {
210
124
  console.error("Failed to submit chat message:", error);
211
125
  });
212
126
  }, status: status, textareaRef: textareaRef, value: prompt }), footer ? _jsx("div", { className: "text-gray-800 text-sm", children: footer }) : null] })] }));
213
127
  };
214
- const GeistdocsChatErrorFallback = ({ onClose }, { retry }) => (_jsxs("div", { className: "flex size-full flex-col items-start justify-center gap-4 p-6", "data-geistdocs-chat-error": true, role: "alert", children: [_jsx("h2", { className: "font-semibold text-lg", children: "Ask AI couldn't load" }), _jsx("p", { className: "text-gray-900 text-sm", children: "Try loading Ask AI again or close the panel to continue reading." }), _jsxs("div", { className: "flex gap-2", children: [_jsx(Button, { onClick: () => retry(), typeName: "button", children: "Try again" }), _jsx(Button, { onClick: onClose, typeName: "button", variant: "secondary", children: "Close" })] })] }));
128
+ const GeistdocsChatError = ({ chatTitle, onClose, retry, }) => {
129
+ const state = useChatSession();
130
+ const handleRetry = () => {
131
+ // The session error lives above this boundary, so resetting the boundary
132
+ // alone would throw it again: restart the failed load first. Errors
133
+ // without `retry` (an invalid `ai.endpoint`) fail again, by design.
134
+ if (state.status === "error") {
135
+ state.retry?.();
136
+ }
137
+ retry();
138
+ };
139
+ return (_jsxs("div", { className: "flex size-full flex-col items-start justify-center gap-4 p-6", "data-geistdocs-chat-error": true, role: "alert", children: [_jsxs("h2", { className: "font-semibold text-lg", children: [chatTitle, " couldn't load"] }), _jsxs("p", { className: "text-gray-900 text-sm", children: ["Try loading ", chatTitle, " again or close the panel to continue reading."] }), _jsxs("div", { className: "flex gap-2", children: [_jsx(Button, { onClick: handleRetry, typeName: "button", children: "Try again" }), _jsx(Button, { onClick: onClose, typeName: "button", variant: "secondary", children: "Close" })] })] }));
140
+ };
141
+ const GeistdocsChatErrorFallback = ({ chatTitle, onClose }, { retry }) => (_jsx(GeistdocsChatError, { chatTitle: chatTitle, onClose: onClose, retry: retry }));
215
142
  const GeistdocsChatErrorBoundary = catchError(GeistdocsChatErrorFallback);
216
143
  export const GeistdocsChatShell = () => {
217
- const { enabled, isOpen, setIsOpen } = useGeistdocsChat();
218
- const isMobile = useIsMobile();
144
+ const { chatTitle, enabled, isExpanded, isOpen, setIsOpen } = useGeistdocsChatContext();
145
+ // The shell mounts only on the client after hydration, so read the
146
+ // breakpoint now instead of starting as desktop for a frame.
147
+ const isMobile = useIsMobileAfterHydration();
219
148
  if (!enabled) {
220
149
  return null;
221
150
  }
222
- return (_jsxs(_Fragment, { children: [isOpen ? (_jsx("style", { children: `
151
+ return (_jsxs(GeistdocsChatSessionProvider, { children: [isOpen ? (_jsx("style", { children: `
223
152
  html {
224
153
  scrollbar-width: none !important;
225
154
  -ms-overflow-style: none !important;
@@ -232,5 +161,5 @@ export const GeistdocsChatShell = () => {
232
161
  // modal surfaces like the search command menu, dialogs, and
233
162
  // dropdowns (z-50), so opening the command menu paints over an
234
163
  // open chat panel.
235
- "fixed inset-y-0 right-0 z-45 hidden h-full w-[400px] max-w-[75vw] flex-col gap-4 border-l bg-background-100 transition-transform min-[768px]:flex", "translate-x-full data-[state=open]:translate-x-0"), "data-state": isOpen ? "open" : "closed", children: _jsx(GeistdocsChatErrorBoundary, { onClose: () => setIsOpen(false), children: _jsx(GeistdocsChatInner, { isOpen: isOpen }) }) }) }), _jsx("div", { className: "min-[768px]:hidden", children: _jsxs(Drawer, { className: "flex flex-col bg-background-100", height: "80dvh", onDismiss: () => setIsOpen(false), show: isMobile && isOpen, children: [_jsx(DrawerTitle, { className: "sr-only", children: "Ask AI" }), _jsx(GeistdocsChatErrorBoundary, { onClose: () => setIsOpen(false), children: _jsx(GeistdocsChatInner, { isOpen: isOpen }) })] }) })] }));
164
+ "fixed inset-y-0 right-0 z-45 hidden h-full flex-col gap-4 border-l bg-background-100 transition-transform min-[768px]:flex", isExpanded ? "w-screen border-l-0" : "w-[400px] max-w-[75vw]", "translate-x-full data-[state=open]:translate-x-0"), "data-state": isOpen ? "open" : "closed", children: _jsx(GeistdocsChatErrorBoundary, { chatTitle: chatTitle, onClose: () => setIsOpen(false), children: _jsx(GeistdocsChatInner, { active: !isMobile, expandable: true, isOpen: isOpen }) }) }) }), _jsx("div", { className: "min-[768px]:hidden", children: _jsxs(Drawer, { className: "flex flex-col bg-background-100", height: "80dvh", onDismiss: () => setIsOpen(false), show: isMobile && isOpen, children: [_jsx(DrawerTitle, { className: "sr-only", children: chatTitle }), _jsx(GeistdocsChatErrorBoundary, { chatTitle: chatTitle, onClose: () => setIsOpen(false), children: _jsx(GeistdocsChatInner, { active: isMobile, isOpen: isOpen }) })] }) })] }));
236
165
  };
@@ -0,0 +1,28 @@
1
+ import type { ChatRequestOptions } from "ai";
2
+ import { type ChatCommandQueue, type ChatCommandState } from "./commands";
3
+ /**
4
+ * Render the hook only in the active shell (desktop panel or mobile drawer),
5
+ * once stored history has loaded into the shared chat. Both shells use the
6
+ * same chat, so `sendMessage`, `status`, and `stop` act on one conversation.
7
+ */
8
+ interface UseChatCommandsOptions {
9
+ /** Clear the stored and displayed conversation. */
10
+ clearConversation: () => Promise<void>;
11
+ commandState: ChatCommandState;
12
+ commands: ChatCommandQueue;
13
+ sendMessage: (message: {
14
+ metadata?: unknown;
15
+ text: string;
16
+ }, options?: ChatRequestOptions) => Promise<void>;
17
+ status: string;
18
+ stop: () => Promise<void> | void;
19
+ }
20
+ /**
21
+ * Drains the provider's command queue into the chat: a requested clear runs
22
+ * first (stopping a streaming response), then queued questions are sent one
23
+ * at a time whenever the chat is idle. Returns `submitText`, which every
24
+ * submission path uses so an attached page travels with exactly one message.
25
+ */
26
+ export declare const useChatCommands: ({ clearConversation, commandState, commands, sendMessage, status, stop, }: UseChatCommandsOptions) => (text: string) => Promise<void>;
27
+ export {};
28
+ //# sourceMappingURL=use-chat-commands.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-chat-commands.d.ts","sourceRoot":"","sources":["../../../src/internal/chat/use-chat-commands.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,IAAI,CAAC;AAE7C,OAAO,EACL,KAAK,gBAAgB,EACrB,KAAK,gBAAgB,EAEtB,MAAM,YAAY,CAAC;AAEpB;;;;GAIG;AACH,UAAU,sBAAsB;IAC9B,mDAAmD;IACnD,iBAAiB,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;IACvC,YAAY,EAAE,gBAAgB,CAAC;IAC/B,QAAQ,EAAE,gBAAgB,CAAC;IAC3B,WAAW,EAAE,CACX,OAAO,EAAE;QAAE,QAAQ,CAAC,EAAE,OAAO,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,EAC7C,OAAO,CAAC,EAAE,kBAAkB,KACzB,OAAO,CAAC,IAAI,CAAC,CAAC;IACnB,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC;CAClC;AAED;;;;;GAKG;AACH,eAAO,MAAM,eAAe,GAAI,2EAO7B,sBAAsB,YAER,MAAM,kBA4DtB,CAAC"}
@@ -0,0 +1,62 @@
1
+ "use client";
2
+ import { useCallback, useEffect } from "react";
3
+ import { getNextChatCommand, } from "./commands";
4
+ /**
5
+ * Drains the provider's command queue into the chat: a requested clear runs
6
+ * first (stopping a streaming response), then queued questions are sent one
7
+ * at a time whenever the chat is idle. Returns `submitText`, which every
8
+ * submission path uses so an attached page travels with exactly one message.
9
+ */
10
+ export const useChatCommands = ({ clearConversation, commandState, commands, sendMessage, status, stop, }) => {
11
+ const submitText = useCallback(async (text) => {
12
+ const page = commands.takeAttachedPage();
13
+ if (!page) {
14
+ await sendMessage({ text });
15
+ return;
16
+ }
17
+ await sendMessage({ metadata: { page }, text }, { body: { pageContext: { url: page.url } } });
18
+ }, [commands, sendMessage]);
19
+ useEffect(() => {
20
+ // Holds the shared queue until the command settles: `sendMessage`
21
+ // resolves only after the response finishes, so the next question waits
22
+ // its turn even if the other shell becomes active meanwhile. The shells
23
+ // share one chat, so the next question carries the full history either
24
+ // way.
25
+ const run = (task, onSettled) => {
26
+ task()
27
+ .catch((error) => {
28
+ console.error("Failed to run chat command:", error);
29
+ })
30
+ .finally(() => {
31
+ onSettled?.();
32
+ commands.endCommand();
33
+ });
34
+ };
35
+ switch (getNextChatCommand({ state: commandState, status })) {
36
+ case "stop":
37
+ Promise.resolve(stop()).catch(() => undefined);
38
+ break;
39
+ case "clear":
40
+ if (commands.beginCommand()) {
41
+ run(clearConversation, commands.completeClear);
42
+ }
43
+ break;
44
+ case "ask": {
45
+ if (!commands.beginCommand()) {
46
+ break;
47
+ }
48
+ const next = commands.takeNextAsk();
49
+ if (next) {
50
+ run(() => submitText(next.text));
51
+ }
52
+ else {
53
+ commands.endCommand();
54
+ }
55
+ break;
56
+ }
57
+ default:
58
+ break;
59
+ }
60
+ }, [clearConversation, commandState, commands, status, stop, submitText]);
61
+ return submitText;
62
+ };
@@ -0,0 +1,7 @@
1
+ import { type ReactNode } from "react";
2
+ /**
3
+ * The avatar shown beside user messages, or `undefined` when no reader with
4
+ * a valid avatar URL is set with `<AskAIUser />`.
5
+ */
6
+ export declare const useChatUserAvatar: () => ReactNode;
7
+ //# sourceMappingURL=user-avatar.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"user-avatar.d.ts","sourceRoot":"","sources":["../../../src/internal/chat/user-avatar.tsx"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,SAAS,EAAY,MAAM,OAAO,CAAC;AA+BjD;;;GAGG;AACH,eAAO,MAAM,iBAAiB,QAAO,SAKpC,CAAC"}
@@ -0,0 +1,27 @@
1
+ "use client";
2
+ import { jsx as _jsx } from "react/jsx-runtime";
3
+ import { useState } from "react";
4
+ import { resolveChatUserAvatarUrl } from "./chat-user";
5
+ import { useGeistdocsChatContext } from "./context";
6
+ const ChatUserAvatar = ({ name, src }) => {
7
+ const [failedSrc, setFailedSrc] = useState(null);
8
+ // A broken avatar is hidden rather than shown as a broken image.
9
+ if (failedSrc === src) {
10
+ return null;
11
+ }
12
+ return (
13
+ // External avatar hosts vary per site, so next/image remote patterns
14
+ // can't be configured for them.
15
+ // biome-ignore lint/performance/noImgElement: arbitrary avatar hosts
16
+ // biome-ignore lint/a11y/noNoninteractiveElementInteractions: onError is a load event, not an interaction
17
+ _jsx("img", { alt: name?.trim() ?? "", className: "size-6 shrink-0 rounded-full bg-gray-alpha-200 object-cover", decoding: "async", height: 24, loading: "lazy", onError: () => setFailedSrc(src), referrerPolicy: "no-referrer", src: src, width: 24 }));
18
+ };
19
+ /**
20
+ * The avatar shown beside user messages, or `undefined` when no reader with
21
+ * a valid avatar URL is set with `<AskAIUser />`.
22
+ */
23
+ export const useChatUserAvatar = () => {
24
+ const { user } = useGeistdocsChatContext();
25
+ const src = resolveChatUserAvatarUrl(user?.avatarUrl);
26
+ return src ? _jsx(ChatUserAvatar, { name: user?.name, src: src }) : undefined;
27
+ };
@@ -0,0 +1,68 @@
1
+ /**
2
+ * Server-only binding between a browser and its eve session.
3
+ *
4
+ * The chat route talks to the eve agent with the site's own credentials, so
5
+ * it must only ever contact a session this browser created through the
6
+ * route. The session ID lives in an HMAC-signed, httpOnly cookie that page
7
+ * scripts cannot read; the browser only stores a non-reversible tag of the
8
+ * session in message metadata so the route can tell which conversation a
9
+ * session belongs to.
10
+ *
11
+ * Cookie value: `base64url(JSON payload) + "." + base64url(HMAC-SHA256)`.
12
+ * The MAC covers a versioned domain-separation prefix, the agent URL (kept
13
+ * out of the payload so the browser never sees it), and the encoded payload.
14
+ */
15
+ export declare const CHAT_SECRET_ENV = "GEISTDOCS_CHAT_SECRET";
16
+ export declare const MIN_CHAT_SECRET_BYTES = 32;
17
+ export declare const EVE_AGENT_SESSION_COOKIE = "geistdocs_eve_session";
18
+ export declare const EVE_AGENT_SESSION_MAX_AGE_SECONDS: number;
19
+ export interface EveAgentCookieSession {
20
+ /** Created by a prewarm request and not yet used for a turn. */
21
+ prewarmed: boolean;
22
+ sessionId: string;
23
+ }
24
+ export interface EveAgentSessionCookieCodec {
25
+ /**
26
+ * Return the session a cookie value carries, or `null` for anything that
27
+ * is not a valid, unexpired cookie issued for this agent with this secret.
28
+ */
29
+ open: (value: string) => EveAgentCookieSession | null;
30
+ /** Seal a session into a cookie value with a fresh expiry. */
31
+ seal: (session: EveAgentCookieSession) => string;
32
+ /**
33
+ * Short, non-reversible tag for a session ID. Stored in assistant message
34
+ * metadata so the route can match a conversation to the cookie's session
35
+ * without exposing the session ID to page scripts.
36
+ */
37
+ tag: (sessionId: string) => string;
38
+ }
39
+ /**
40
+ * Validate a chat secret. Throws for secrets too short to resist guessing
41
+ * so a misconfigured deployment fails loudly instead of signing cookies
42
+ * with a weak key. A base64 value that decodes to 32 bytes (44 characters)
43
+ * passes, because the raw string is used as the key.
44
+ */
45
+ export declare const assertChatSecret: (secret: string) => void;
46
+ export declare const createEveAgentSessionCookieCodec: ({ agentUrl, now, secret, ttlMs, }: {
47
+ /** Normalized agent URL the sessions belong to. */
48
+ agentUrl: string;
49
+ /** Clock override for tests. */
50
+ now?: () => number;
51
+ secret: string;
52
+ ttlMs?: number;
53
+ }) => EveAgentSessionCookieCodec;
54
+ /** Compare two session tags without leaking where they differ. */
55
+ export declare const isSameSessionTag: (actual: string, expected: string) => boolean;
56
+ /**
57
+ * Every value sent for `name` in a `Cookie` header, in header order.
58
+ * Browsers send one value per matching path, most specific first, so
59
+ * callers should try each value rather than trusting the first.
60
+ */
61
+ export declare const readCookieValues: (header: string | null, name: string) => string[];
62
+ /**
63
+ * `Set-Cookie` header for the eve session. The cookie is scoped to the
64
+ * chat route's own path, so it follows any endpoint or base path without
65
+ * configuration, and is never sent with page or asset requests.
66
+ */
67
+ export declare const serializeEveAgentSessionCookie: (value: string, req: Request) => string;
68
+ //# sourceMappingURL=eve-agent-session-cookie.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"eve-agent-session-cookie.d.ts","sourceRoot":"","sources":["../../src/internal/eve-agent-session-cookie.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;GAaG;AAEH,eAAO,MAAM,eAAe,0BAA0B,CAAC;AACvD,eAAO,MAAM,qBAAqB,KAAK,CAAC;AACxC,eAAO,MAAM,wBAAwB,0BAA0B,CAAC;AAChE,eAAO,MAAM,iCAAiC,QAAmB,CAAC;AAYlE,MAAM,WAAW,qBAAqB;IACpC,gEAAgE;IAChE,SAAS,EAAE,OAAO,CAAC;IACnB,SAAS,EAAE,MAAM,CAAC;CACnB;AAYD,MAAM,WAAW,0BAA0B;IACzC;;;OAGG;IACH,IAAI,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,qBAAqB,GAAG,IAAI,CAAC;IACtD,8DAA8D;IAC9D,IAAI,EAAE,CAAC,OAAO,EAAE,qBAAqB,KAAK,MAAM,CAAC;IACjD;;;;OAIG;IACH,GAAG,EAAE,CAAC,SAAS,EAAE,MAAM,KAAK,MAAM,CAAC;CACpC;AAcD;;;;;GAKG;AACH,eAAO,MAAM,gBAAgB,GAAI,QAAQ,MAAM,SAM9C,CAAC;AAEF,eAAO,MAAM,gCAAgC,GAAI,mCAK9C;IACD,mDAAmD;IACnD,QAAQ,EAAE,MAAM,CAAC;IACjB,gCAAgC;IAChC,GAAG,CAAC,EAAE,MAAM,MAAM,CAAC;IACnB,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB,KAAG,0BA6EH,CAAC;AAEF,kEAAkE;AAClE,eAAO,MAAM,gBAAgB,GAAI,QAAQ,MAAM,EAAE,UAAU,MAAM,YAQhE,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,gBAAgB,GAAI,QAAQ,MAAM,GAAG,IAAI,EAAE,MAAM,MAAM,aAwBnE,CAAC;AAgBF;;;;GAIG;AACH,eAAO,MAAM,8BAA8B,GAAI,OAAO,MAAM,EAAE,KAAK,OAAO,WAczE,CAAC"}