@vercel/geistdocs 2.7.9 → 2.8.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.
- package/dist/assets/icons/icon-thumb-down.d.ts +26 -0
- package/dist/assets/icons/icon-thumb-down.d.ts.map +1 -0
- package/dist/assets/icons/icon-thumb-down.js +25 -0
- package/dist/assets/icons/index.d.ts +1 -0
- package/dist/assets/icons/index.d.ts.map +1 -1
- package/dist/assets/icons/index.js +1 -0
- package/dist/cli/index.js +1 -1
- package/dist/components/dialog.d.ts +2 -0
- package/dist/components/dialog.d.ts.map +1 -0
- package/dist/components/dialog.js +3 -0
- package/dist/config.d.ts +67 -3
- package/dist/config.d.ts.map +1 -1
- package/dist/controls.d.ts +23 -1
- package/dist/controls.d.ts.map +1 -1
- package/dist/controls.js +44 -3
- package/dist/footer.js +1 -1
- package/dist/internal/chat/activity.d.ts +5 -1
- package/dist/internal/chat/activity.d.ts.map +1 -1
- package/dist/internal/chat/activity.js +11 -4
- package/dist/internal/chat/chat-user.d.ts +12 -0
- package/dist/internal/chat/chat-user.d.ts.map +1 -0
- package/dist/internal/chat/chat-user.js +27 -0
- package/dist/internal/chat/commands.d.ts +91 -0
- package/dist/internal/chat/commands.d.ts.map +1 -0
- package/dist/internal/chat/commands.js +165 -0
- package/dist/internal/chat/context.d.ts +46 -2
- package/dist/internal/chat/context.d.ts.map +1 -1
- package/dist/internal/chat/context.js +50 -4
- package/dist/internal/chat/message-actions.d.ts +15 -0
- package/dist/internal/chat/message-actions.d.ts.map +1 -0
- package/dist/internal/chat/message-actions.js +113 -0
- package/dist/internal/chat/message-feedback.d.ts +68 -0
- package/dist/internal/chat/message-feedback.d.ts.map +1 -0
- package/dist/internal/chat/message-feedback.js +188 -0
- package/dist/internal/chat/message-metadata.d.ts.map +1 -1
- package/dist/internal/chat/message-metadata.js +7 -1
- package/dist/internal/chat/message-text.d.ts +9 -0
- package/dist/internal/chat/message-text.d.ts.map +1 -0
- package/dist/internal/chat/message-text.js +15 -0
- package/dist/internal/chat/message.d.ts +4 -2
- package/dist/internal/chat/message.d.ts.map +1 -1
- package/dist/internal/chat/message.js +10 -6
- package/dist/internal/chat/options.d.ts +94 -0
- package/dist/internal/chat/options.d.ts.map +1 -0
- package/dist/internal/chat/options.js +171 -0
- package/dist/internal/chat/page-attachment.d.ts +12 -0
- package/dist/internal/chat/page-attachment.d.ts.map +1 -0
- package/dist/internal/chat/page-attachment.js +18 -0
- package/dist/internal/chat/session-provider.d.ts +33 -0
- package/dist/internal/chat/session-provider.d.ts.map +1 -0
- package/dist/internal/chat/session-provider.js +138 -0
- package/dist/internal/chat/session.d.ts +60 -0
- package/dist/internal/chat/session.d.ts.map +1 -0
- package/dist/internal/chat/session.js +85 -0
- package/dist/internal/chat/shell.d.ts.map +1 -1
- package/dist/internal/chat/shell.js +81 -157
- package/dist/internal/chat/use-chat-commands.d.ts +28 -0
- package/dist/internal/chat/use-chat-commands.d.ts.map +1 -0
- package/dist/internal/chat/use-chat-commands.js +62 -0
- package/dist/internal/chat/user-avatar.d.ts +7 -0
- package/dist/internal/chat/user-avatar.d.ts.map +1 -0
- package/dist/internal/chat/user-avatar.js +27 -0
- package/dist/internal/eve-agent-session-cookie.d.ts +68 -0
- package/dist/internal/eve-agent-session-cookie.d.ts.map +1 -0
- package/dist/internal/eve-agent-session-cookie.js +164 -0
- package/dist/internal/eve-agent-session.d.ts +9 -7
- package/dist/internal/eve-agent-session.d.ts.map +1 -1
- package/dist/internal/eve-agent-session.js +10 -13
- package/dist/internal/eve-agent.d.ts +96 -24
- package/dist/internal/eve-agent.d.ts.map +1 -1
- package/dist/internal/eve-agent.js +74 -51
- package/dist/internal/feedback-action.d.ts +14 -0
- package/dist/internal/feedback-action.d.ts.map +1 -1
- package/dist/internal/feedback-action.js +37 -5
- package/dist/internal/page-actions-client.d.ts +9 -0
- package/dist/internal/page-actions-client.d.ts.map +1 -1
- package/dist/internal/page-actions-client.js +8 -4
- package/dist/internal/provider-client.d.ts.map +1 -1
- package/dist/internal/provider-client.js +2 -2
- package/dist/internal/use-mobile.d.ts +7 -0
- package/dist/internal/use-mobile.d.ts.map +1 -1
- package/dist/internal/use-mobile.js +17 -1
- package/dist/internal/webmcp-client.d.ts.map +1 -1
- package/dist/internal/webmcp-client.js +13 -3
- package/dist/internal/webmcp.d.ts +5 -1
- package/dist/internal/webmcp.d.ts.map +1 -1
- package/dist/internal/webmcp.js +31 -1
- package/dist/pages/changelog.d.ts.map +1 -1
- package/dist/pages/changelog.js +4 -0
- package/dist/pages/docs.d.ts.map +1 -1
- package/dist/pages/docs.js +2 -0
- package/dist/providers/public/components/dialog.d.ts +27 -0
- package/dist/providers/public/components/dialog.d.ts.map +1 -0
- package/dist/providers/public/components/dialog.js +17 -0
- package/dist/routes/chat.d.ts +83 -5
- package/dist/routes/chat.d.ts.map +1 -1
- package/dist/routes/chat.js +517 -80
- package/dist/routes/discovery.d.ts +1 -1
- package/dist/routes/discovery.d.ts.map +1 -1
- package/dist/routes/discovery.js +7 -11
- package/dist/routes/openapi.d.ts.map +1 -1
- package/dist/routes/openapi.js +47 -25
- package/docs/agents.md +4 -3
- package/docs/llms.txt +711 -35
- package/docs/manifest.json +12 -3
- package/docs/pages/agent-readiness.md +1 -1
- package/docs/pages/ask-ai.md +567 -24
- package/docs/pages/components/dialog.md +74 -0
- package/docs/pages/components/index.md +1 -0
- package/docs/pages/configuration.md +21 -1
- package/docs/pages/env.md +17 -3
- package/docs/pages/feedback.md +4 -0
- package/docs/pages/webmcp.md +18 -3
- package/docs/sitemap.md +2 -1
- package/package.json +5 -2
- package/public-foundation.css +12 -0
- package/template/.env.example +5 -0
- package/template/AGENTS.md +2 -0
- package/template/components/geistdocs/dialog-demo.tsx +44 -0
- package/template/content/docs/agent-readiness.mdx +1 -1
- package/template/content/docs/ask-ai.cn.mdx +466 -15
- package/template/content/docs/ask-ai.mdx +567 -24
- package/template/content/docs/components/dialog.mdx +70 -0
- package/template/content/docs/components/index.mdx +1 -0
- package/template/content/docs/components/meta.json +1 -0
- package/template/content/docs/configuration.cn.mdx +39 -0
- package/template/content/docs/configuration.mdx +21 -1
- package/template/content/docs/env.cn.mdx +15 -1
- package/template/content/docs/env.mdx +18 -4
- package/template/content/docs/feedback.cn.mdx +4 -0
- package/template/content/docs/feedback.mdx +4 -0
- package/template/content/docs/webmcp.mdx +18 -3
- package/template/package.json +1 -2
- package/dist/providers/public/components/modal.d.ts +0 -22
- package/dist/providers/public/components/modal.d.ts.map +0 -1
- package/dist/providers/public/components/modal.js +0 -19
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
+
import { useChat } from "@ai-sdk/react";
|
|
4
|
+
import { usePathname } from "next/navigation";
|
|
5
|
+
import { createContext, useCallback, useContext, useEffect, useMemo, useRef, useState, useSyncExternalStore, } from "react";
|
|
6
|
+
import { useToasts } from "#geistdocs-ui/components/toasts";
|
|
7
|
+
import { getPublicPath } from "../../config";
|
|
8
|
+
import { useGeistdocsChatContext } from "./context";
|
|
9
|
+
import { getChatDatabase } from "./db";
|
|
10
|
+
import { resolveChatEndpoint, stampChatMessages } from "./options";
|
|
11
|
+
import { createChatSession, toError, } from "./session";
|
|
12
|
+
const SAVE_DELAY_MS = 300;
|
|
13
|
+
const ChatSessionContext = createContext(null);
|
|
14
|
+
/**
|
|
15
|
+
* The shared chat session. `"error"` must be thrown by the consumer so it
|
|
16
|
+
* fails inside that shell's chat error boundary instead of the page.
|
|
17
|
+
*/
|
|
18
|
+
export const useChatSession = () => {
|
|
19
|
+
const state = useContext(ChatSessionContext);
|
|
20
|
+
if (!state) {
|
|
21
|
+
throw new Error("useChatSession must be used within GeistdocsChatSessionProvider.");
|
|
22
|
+
}
|
|
23
|
+
return state;
|
|
24
|
+
};
|
|
25
|
+
/**
|
|
26
|
+
* Owns the one chat both shells render: restores the stored conversation,
|
|
27
|
+
* saves it as it changes, clears it, and prewarms eve sessions. Runs once per
|
|
28
|
+
* page however many shells are mounted.
|
|
29
|
+
*/
|
|
30
|
+
const ChatSessionRoot = ({ api, children, }) => {
|
|
31
|
+
const { historyRetentionMs, prewarmEveAgent, title } = useGeistdocsChatContext();
|
|
32
|
+
const pathname = usePathname();
|
|
33
|
+
const toast = useToasts();
|
|
34
|
+
const pathnameRef = useRef(pathname);
|
|
35
|
+
const toastRef = useRef(toast);
|
|
36
|
+
const saveTimeoutRef = useRef(undefined);
|
|
37
|
+
const db = useMemo(() => getChatDatabase(title), [title]);
|
|
38
|
+
const [session] = useState(() => createChatSession({
|
|
39
|
+
api,
|
|
40
|
+
getCurrentRoute: () => pathnameRef.current,
|
|
41
|
+
history: {
|
|
42
|
+
clear: () => db.messages.clear(),
|
|
43
|
+
read: () => db.messages.orderBy("sequence").toArray(),
|
|
44
|
+
},
|
|
45
|
+
historyRetentionMs,
|
|
46
|
+
onError: (error) => {
|
|
47
|
+
toastRef.current.error({ text: error.message });
|
|
48
|
+
},
|
|
49
|
+
prewarmEveAgent,
|
|
50
|
+
}));
|
|
51
|
+
const { messages } = useChat({ chat: session.chat });
|
|
52
|
+
const history = useSyncExternalStore(session.history.subscribe, session.history.getState, session.history.getState);
|
|
53
|
+
const initialized = history.status === "ready";
|
|
54
|
+
const persist = historyRetentionMs > 0;
|
|
55
|
+
useEffect(() => {
|
|
56
|
+
pathnameRef.current = pathname;
|
|
57
|
+
toastRef.current = toast;
|
|
58
|
+
});
|
|
59
|
+
useEffect(() => {
|
|
60
|
+
session.history.restore();
|
|
61
|
+
}, [session]);
|
|
62
|
+
useEffect(() => {
|
|
63
|
+
if (!(initialized && persist) || messages.length === 0) {
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
clearTimeout(saveTimeoutRef.current);
|
|
67
|
+
saveTimeoutRef.current = setTimeout(async () => {
|
|
68
|
+
try {
|
|
69
|
+
await db.transaction("rw", db.messages, async () => {
|
|
70
|
+
// Keep each stored message's original timestamp so the retention
|
|
71
|
+
// window measures the last new message, not the last save.
|
|
72
|
+
const messagesToStore = stampChatMessages(messages, await db.messages.toArray(), Date.now());
|
|
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
|
+
}, SAVE_DELAY_MS);
|
|
81
|
+
}, [db, initialized, messages, persist]);
|
|
82
|
+
useEffect(() => () => clearTimeout(saveTimeoutRef.current), []);
|
|
83
|
+
useEffect(() => {
|
|
84
|
+
if (initialized && messages.length === 0) {
|
|
85
|
+
session.prewarm();
|
|
86
|
+
}
|
|
87
|
+
}, [initialized, messages.length, session]);
|
|
88
|
+
const clearConversation = useCallback(async () => {
|
|
89
|
+
clearTimeout(saveTimeoutRef.current);
|
|
90
|
+
saveTimeoutRef.current = undefined;
|
|
91
|
+
try {
|
|
92
|
+
await db.messages.clear();
|
|
93
|
+
}
|
|
94
|
+
catch (error) {
|
|
95
|
+
console.error("Failed to clear messages:", error);
|
|
96
|
+
}
|
|
97
|
+
session.chat.messages = [];
|
|
98
|
+
}, [db, session]);
|
|
99
|
+
const value = useMemo(() => {
|
|
100
|
+
if (history.status === "ready") {
|
|
101
|
+
return { clearConversation, session, status: "ready" };
|
|
102
|
+
}
|
|
103
|
+
if (history.status === "error") {
|
|
104
|
+
return {
|
|
105
|
+
error: history.error,
|
|
106
|
+
retry: session.history.restore,
|
|
107
|
+
status: "error",
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
return history;
|
|
111
|
+
}, [clearConversation, history, session]);
|
|
112
|
+
return (_jsx(ChatSessionContext.Provider, { value: value, children: children }));
|
|
113
|
+
};
|
|
114
|
+
/**
|
|
115
|
+
* Provides the single chat shared by the desktop panel and the mobile
|
|
116
|
+
* drawer. An invalid `ai.endpoint` is caught here and handed to the shells
|
|
117
|
+
* as an `"error"` state, so it fails inside their error boundaries.
|
|
118
|
+
*/
|
|
119
|
+
export const GeistdocsChatSessionProvider = ({ children, }) => {
|
|
120
|
+
const { basePath, chatEndpoint, historyRetentionMs, prewarmEveAgent, title } = useGeistdocsChatContext();
|
|
121
|
+
const resolved = useMemo(() => {
|
|
122
|
+
try {
|
|
123
|
+
return {
|
|
124
|
+
api: getPublicPath(resolveChatEndpoint(chatEndpoint), basePath),
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
catch (error) {
|
|
128
|
+
return { failed: { error: toError(error), status: "error" } };
|
|
129
|
+
}
|
|
130
|
+
}, [basePath, chatEndpoint]);
|
|
131
|
+
if ("failed" in resolved) {
|
|
132
|
+
return (_jsx(ChatSessionContext.Provider, { value: resolved.failed, children: children }));
|
|
133
|
+
}
|
|
134
|
+
return (
|
|
135
|
+
// The session captures these options when it is created, so a change
|
|
136
|
+
// starts a new one.
|
|
137
|
+
_jsx(ChatSessionRoot, { api: resolved.api, children: children }, [resolved.api, title, historyRetentionMs, prewarmEveAgent].join("\n")));
|
|
138
|
+
};
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { Chat } from "@ai-sdk/react";
|
|
2
|
+
import { type UIMessage } from "ai";
|
|
3
|
+
export type ChatHistoryState = {
|
|
4
|
+
status: "loading";
|
|
5
|
+
} | {
|
|
6
|
+
status: "ready";
|
|
7
|
+
} | {
|
|
8
|
+
error: Error;
|
|
9
|
+
status: "error";
|
|
10
|
+
};
|
|
11
|
+
/** A stored message row: the message plus its storage fields. */
|
|
12
|
+
export type StoredChatRow = UIMessage & {
|
|
13
|
+
sequence?: unknown;
|
|
14
|
+
timestamp?: unknown;
|
|
15
|
+
};
|
|
16
|
+
/** Browser storage holding the conversation (IndexedDB in the chat shell). */
|
|
17
|
+
export interface ChatHistoryStore {
|
|
18
|
+
clear: () => Promise<void>;
|
|
19
|
+
/** Stored rows in `sequence` order. */
|
|
20
|
+
read: () => Promise<StoredChatRow[]>;
|
|
21
|
+
}
|
|
22
|
+
export declare const toError: (error: unknown) => Error;
|
|
23
|
+
/**
|
|
24
|
+
* The one Ask AI conversation a page owns. The desktop panel and the mobile
|
|
25
|
+
* drawer both render this chat, so whichever is active sends with the full
|
|
26
|
+
* history, sees the same status, and persists the same messages.
|
|
27
|
+
*/
|
|
28
|
+
export interface GeistdocsChatSession {
|
|
29
|
+
chat: Chat<UIMessage>;
|
|
30
|
+
history: {
|
|
31
|
+
getState: () => ChatHistoryState;
|
|
32
|
+
/**
|
|
33
|
+
* Load the stored conversation into the chat, clearing it instead when it
|
|
34
|
+
* has expired. After a failed load, calling it again retries. Does
|
|
35
|
+
* nothing while a load is running or once one has succeeded, so it never
|
|
36
|
+
* replaces a conversation in progress.
|
|
37
|
+
*/
|
|
38
|
+
restore: () => void;
|
|
39
|
+
subscribe: (listener: () => void) => () => void;
|
|
40
|
+
};
|
|
41
|
+
/**
|
|
42
|
+
* Prewarm an eve session for the next conversation. Does nothing when
|
|
43
|
+
* prewarming is off, a prewarm is already pending, or the conversation has
|
|
44
|
+
* messages.
|
|
45
|
+
*/
|
|
46
|
+
prewarm: () => void;
|
|
47
|
+
}
|
|
48
|
+
export interface CreateChatSessionOptions {
|
|
49
|
+
/** Resolved, app-local chat route URL. */
|
|
50
|
+
api: string;
|
|
51
|
+
/** Route the reader is on when a message is sent. */
|
|
52
|
+
getCurrentRoute: () => string | null;
|
|
53
|
+
history: ChatHistoryStore;
|
|
54
|
+
/** Milliseconds a stored conversation is kept after its last message. */
|
|
55
|
+
historyRetentionMs: number;
|
|
56
|
+
onError: (error: Error) => void;
|
|
57
|
+
prewarmEveAgent: boolean;
|
|
58
|
+
}
|
|
59
|
+
export declare const createChatSession: ({ api, getCurrentRoute, history, historyRetentionMs, onError, prewarmEveAgent, }: CreateChatSessionOptions) => GeistdocsChatSession;
|
|
60
|
+
//# sourceMappingURL=session.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"session.d.ts","sourceRoot":"","sources":["../../../src/internal/chat/session.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,eAAe,CAAC;AACrC,OAAO,EAAwB,KAAK,SAAS,EAAE,MAAM,IAAI,CAAC;AAI1D,MAAM,MAAM,gBAAgB,GACxB;IAAE,MAAM,EAAE,SAAS,CAAA;CAAE,GACrB;IAAE,MAAM,EAAE,OAAO,CAAA;CAAE,GACnB;IAAE,KAAK,EAAE,KAAK,CAAC;IAAC,MAAM,EAAE,OAAO,CAAA;CAAE,CAAC;AAEtC,iEAAiE;AACjE,MAAM,MAAM,aAAa,GAAG,SAAS,GAAG;IACtC,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,SAAS,CAAC,EAAE,OAAO,CAAC;CACrB,CAAC;AAEF,8EAA8E;AAC9E,MAAM,WAAW,gBAAgB;IAC/B,KAAK,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;IAC3B,uCAAuC;IACvC,IAAI,EAAE,MAAM,OAAO,CAAC,aAAa,EAAE,CAAC,CAAC;CACtC;AAED,eAAO,MAAM,OAAO,GAAI,OAAO,OAAO,UACqB,CAAC;AAE5D;;;;GAIG;AACH,MAAM,WAAW,oBAAoB;IACnC,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,CAAC;IACtB,OAAO,EAAE;QACP,QAAQ,EAAE,MAAM,gBAAgB,CAAC;QACjC;;;;;WAKG;QACH,OAAO,EAAE,MAAM,IAAI,CAAC;QACpB,SAAS,EAAE,CAAC,QAAQ,EAAE,MAAM,IAAI,KAAK,MAAM,IAAI,CAAC;KACjD,CAAC;IACF;;;;OAIG;IACH,OAAO,EAAE,MAAM,IAAI,CAAC;CACrB;AAED,MAAM,WAAW,wBAAwB;IACvC,0CAA0C;IAC1C,GAAG,EAAE,MAAM,CAAC;IACZ,qDAAqD;IACrD,eAAe,EAAE,MAAM,MAAM,GAAG,IAAI,CAAC;IACrC,OAAO,EAAE,gBAAgB,CAAC;IAC1B,yEAAyE;IACzE,kBAAkB,EAAE,MAAM,CAAC;IAC3B,OAAO,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,CAAC;IAChC,eAAe,EAAE,OAAO,CAAC;CAC1B;AAED,eAAO,MAAM,iBAAiB,GAAI,kFAO/B,wBAAwB,KAAG,oBA6F7B,CAAC"}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { Chat } from "@ai-sdk/react";
|
|
2
|
+
import { DefaultChatTransport } from "ai";
|
|
3
|
+
import { requestEveAgentPrewarm } from "../eve-agent-session.js";
|
|
4
|
+
import { restoreStoredChat } from "./options.js";
|
|
5
|
+
export const toError = (error) => error instanceof Error ? error : new Error(String(error));
|
|
6
|
+
export const createChatSession = ({ api, getCurrentRoute, history, historyRetentionMs, onError, prewarmEveAgent, }) => {
|
|
7
|
+
let pendingPrewarm = null;
|
|
8
|
+
let historyState = { status: "loading" };
|
|
9
|
+
let restoring = false;
|
|
10
|
+
const historyListeners = new Set();
|
|
11
|
+
const setHistoryState = (next) => {
|
|
12
|
+
historyState = next;
|
|
13
|
+
for (const listener of historyListeners) {
|
|
14
|
+
listener();
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
const readHistory = async () => {
|
|
18
|
+
const { expired, messages } = restoreStoredChat({
|
|
19
|
+
now: Date.now(),
|
|
20
|
+
retentionMs: historyRetentionMs,
|
|
21
|
+
rows: await history.read(),
|
|
22
|
+
});
|
|
23
|
+
if (expired) {
|
|
24
|
+
await history.clear().catch((error) => {
|
|
25
|
+
console.error("Failed to clear expired messages:", error);
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
return messages;
|
|
29
|
+
};
|
|
30
|
+
const chat = new Chat({
|
|
31
|
+
transport: new DefaultChatTransport({
|
|
32
|
+
api,
|
|
33
|
+
prepareSendMessagesRequest: async ({ body, messages }) => {
|
|
34
|
+
// The prewarm response sets the session cookie; wait for it so the
|
|
35
|
+
// first message reuses the prewarmed session.
|
|
36
|
+
await pendingPrewarm;
|
|
37
|
+
pendingPrewarm = null;
|
|
38
|
+
return {
|
|
39
|
+
body: {
|
|
40
|
+
...body,
|
|
41
|
+
messages,
|
|
42
|
+
currentRoute: getCurrentRoute(),
|
|
43
|
+
},
|
|
44
|
+
};
|
|
45
|
+
},
|
|
46
|
+
}),
|
|
47
|
+
onError,
|
|
48
|
+
});
|
|
49
|
+
return {
|
|
50
|
+
chat,
|
|
51
|
+
history: {
|
|
52
|
+
getState: () => historyState,
|
|
53
|
+
restore: () => {
|
|
54
|
+
if (restoring || historyState.status === "ready") {
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
restoring = true;
|
|
58
|
+
if (historyState.status === "error") {
|
|
59
|
+
setHistoryState({ status: "loading" });
|
|
60
|
+
}
|
|
61
|
+
readHistory().then((messages) => {
|
|
62
|
+
restoring = false;
|
|
63
|
+
chat.messages = messages;
|
|
64
|
+
setHistoryState({ status: "ready" });
|
|
65
|
+
}, (error) => {
|
|
66
|
+
restoring = false;
|
|
67
|
+
setHistoryState({ error: toError(error), status: "error" });
|
|
68
|
+
});
|
|
69
|
+
},
|
|
70
|
+
subscribe: (listener) => {
|
|
71
|
+
historyListeners.add(listener);
|
|
72
|
+
return () => {
|
|
73
|
+
historyListeners.delete(listener);
|
|
74
|
+
};
|
|
75
|
+
},
|
|
76
|
+
},
|
|
77
|
+
prewarm: () => {
|
|
78
|
+
if (prewarmEveAgent &&
|
|
79
|
+
pendingPrewarm === null &&
|
|
80
|
+
chat.messages.length === 0) {
|
|
81
|
+
pendingPrewarm = requestEveAgentPrewarm({ apiUrl: api });
|
|
82
|
+
}
|
|
83
|
+
},
|
|
84
|
+
};
|
|
85
|
+
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"shell.d.ts","sourceRoot":"","sources":["../../../src/internal/chat/shell.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"shell.d.ts","sourceRoot":"","sources":["../../../src/internal/chat/shell.tsx"],"names":[],"mappings":"AA2WA,eAAO,MAAM,kBAAkB,sDA8D9B,CAAC"}
|
|
@@ -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 {
|
|
10
|
-
import { IconChevronDoubleRight,
|
|
11
|
-
import { LogoIconVercelFillSvg } from "#geistdocs-assets/logos";
|
|
6
|
+
import { useEffect, useRef } from "react";
|
|
7
|
+
import { IconChevronDoubleRight, 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,76 @@ 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 {
|
|
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 {
|
|
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
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
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
|
+
const GeistdocsChatInner = ({ active, isOpen, }) => {
|
|
32
|
+
const state = useChatSession();
|
|
33
|
+
const textareaRef = useRef(null);
|
|
34
|
+
const ready = state.status === "ready";
|
|
35
|
+
// Focus the prompt when the chat opens or finishes loading while open. It
|
|
36
|
+
// lives here rather than in the panel so the panel mounting when this
|
|
37
|
+
// shell becomes active (a breakpoint change) doesn't move focus.
|
|
49
38
|
useEffect(() => {
|
|
50
|
-
if (
|
|
51
|
-
|
|
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);
|
|
39
|
+
if (!(isOpen && ready)) {
|
|
40
|
+
return;
|
|
97
41
|
}
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
42
|
+
const timer = setTimeout(() => {
|
|
43
|
+
textareaRef.current?.focus();
|
|
44
|
+
}, 100);
|
|
45
|
+
return () => clearTimeout(timer);
|
|
46
|
+
}, [isOpen, ready]);
|
|
47
|
+
// The inactive shell is hidden, so it renders nothing: only the visible
|
|
48
|
+
// shell subscribes to the chat and re-renders as a response streams. When
|
|
49
|
+
// the breakpoint changes, the newly active shell renders the shared
|
|
50
|
+
// conversation in full on its first render.
|
|
51
|
+
if (!active) {
|
|
52
|
+
return null;
|
|
53
|
+
}
|
|
54
|
+
if (state.status === "error") {
|
|
55
|
+
// Thrown here, inside the chat error boundary, so an invalid
|
|
56
|
+
// `ai.endpoint` or unreadable history fails the panel, not the page.
|
|
57
|
+
throw state.error;
|
|
58
|
+
}
|
|
59
|
+
if (state.status === "loading") {
|
|
60
|
+
return _jsx(ChatLoading, {});
|
|
61
|
+
}
|
|
62
|
+
return (_jsx(GeistdocsChatPanel, { clearConversation: state.clearConversation, session: state.session, textareaRef: textareaRef }));
|
|
105
63
|
};
|
|
106
|
-
const
|
|
107
|
-
const id = useId();
|
|
108
|
-
const pathname = usePathname();
|
|
109
|
-
const textareaRef = useRef(null);
|
|
110
|
-
const prewarmPromiseRef = useRef(null);
|
|
111
|
-
const [isInitialized, setIsInitialized] = useState(false);
|
|
64
|
+
const GeistdocsChatPanel = ({ clearConversation, session, textareaRef, }) => {
|
|
112
65
|
const toast = useToasts();
|
|
113
|
-
const { prompt, setPrompt, setIsOpen,
|
|
114
|
-
const
|
|
115
|
-
const
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
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
|
-
},
|
|
66
|
+
const { prompt, setPrompt, setIsOpen, chatTitle, commands, commandState, footer, suggestions, } = useGeistdocsChatContext();
|
|
67
|
+
const userAvatar = useChatUserAvatar();
|
|
68
|
+
const { messages, sendMessage, setMessages, status, stop } = useChat({
|
|
69
|
+
chat: session.chat,
|
|
70
|
+
});
|
|
71
|
+
const submitText = useChatCommands({
|
|
72
|
+
clearConversation,
|
|
73
|
+
commandState,
|
|
74
|
+
commands,
|
|
75
|
+
sendMessage,
|
|
76
|
+
status,
|
|
77
|
+
stop,
|
|
136
78
|
});
|
|
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
79
|
const handleSuggestionClick = async (text) => {
|
|
168
80
|
if (status === "streaming" || status === "submitted") {
|
|
169
81
|
return;
|
|
170
82
|
}
|
|
171
83
|
setPrompt("");
|
|
172
|
-
await
|
|
84
|
+
await submitText(text);
|
|
173
85
|
};
|
|
174
86
|
const handleSubmit = async () => {
|
|
175
87
|
if (status === "streaming" || status === "submitted" || !prompt) {
|
|
@@ -177,12 +89,12 @@ const GeistdocsChatInner = ({ isOpen }) => {
|
|
|
177
89
|
}
|
|
178
90
|
const currentPrompt = prompt;
|
|
179
91
|
setPrompt("");
|
|
180
|
-
await
|
|
92
|
+
await submitText(currentPrompt);
|
|
181
93
|
};
|
|
182
94
|
const handleClearChat = async () => {
|
|
183
95
|
try {
|
|
184
|
-
await
|
|
185
|
-
|
|
96
|
+
await clearConversation();
|
|
97
|
+
commands.detachPage();
|
|
186
98
|
toast.success({ text: "Chat cleared" });
|
|
187
99
|
}
|
|
188
100
|
catch (error) {
|
|
@@ -193,33 +105,45 @@ const GeistdocsChatInner = ({ isOpen }) => {
|
|
|
193
105
|
});
|
|
194
106
|
}
|
|
195
107
|
};
|
|
196
|
-
|
|
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 ||
|
|
108
|
+
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: "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: chatTitle }), _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 ||
|
|
200
109
|
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({
|
|
110
|
+
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, { avatar: message.role === "user" ? userAvatar : undefined, from: message.role, children: [_jsx(MessageMetadata, { inProgress: isActiveAssistantMessage({
|
|
202
111
|
index,
|
|
203
112
|
messages,
|
|
204
113
|
status,
|
|
205
|
-
}), parts: message.parts }), message.parts
|
|
114
|
+
}), parts: message.parts }), _jsx(ChatMessagePageChip, { metadata: message.metadata }), message.parts
|
|
206
115
|
.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.
|
|
116
|
+
.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: "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.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
117
|
event.preventDefault();
|
|
209
118
|
handleSubmit().catch((error) => {
|
|
210
119
|
console.error("Failed to submit chat message:", error);
|
|
211
120
|
});
|
|
212
121
|
}, status: status, textareaRef: textareaRef, value: prompt }), footer ? _jsx("div", { className: "text-gray-800 text-sm", children: footer }) : null] })] }));
|
|
213
122
|
};
|
|
214
|
-
const
|
|
123
|
+
const GeistdocsChatError = ({ chatTitle, onClose, retry, }) => {
|
|
124
|
+
const state = useChatSession();
|
|
125
|
+
const handleRetry = () => {
|
|
126
|
+
// The session error lives above this boundary, so resetting the boundary
|
|
127
|
+
// alone would throw it again: restart the failed load first. Errors
|
|
128
|
+
// without `retry` (an invalid `ai.endpoint`) fail again, by design.
|
|
129
|
+
if (state.status === "error") {
|
|
130
|
+
state.retry?.();
|
|
131
|
+
}
|
|
132
|
+
retry();
|
|
133
|
+
};
|
|
134
|
+
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" })] })] }));
|
|
135
|
+
};
|
|
136
|
+
const GeistdocsChatErrorFallback = ({ chatTitle, onClose }, { retry }) => (_jsx(GeistdocsChatError, { chatTitle: chatTitle, onClose: onClose, retry: retry }));
|
|
215
137
|
const GeistdocsChatErrorBoundary = catchError(GeistdocsChatErrorFallback);
|
|
216
138
|
export const GeistdocsChatShell = () => {
|
|
217
|
-
const { enabled, isOpen, setIsOpen } =
|
|
218
|
-
|
|
139
|
+
const { chatTitle, enabled, isOpen, setIsOpen } = useGeistdocsChatContext();
|
|
140
|
+
// The shell mounts only on the client after hydration, so read the
|
|
141
|
+
// breakpoint now instead of starting as desktop for a frame.
|
|
142
|
+
const isMobile = useIsMobileAfterHydration();
|
|
219
143
|
if (!enabled) {
|
|
220
144
|
return null;
|
|
221
145
|
}
|
|
222
|
-
return (_jsxs(
|
|
146
|
+
return (_jsxs(GeistdocsChatSessionProvider, { children: [isOpen ? (_jsx("style", { children: `
|
|
223
147
|
html {
|
|
224
148
|
scrollbar-width: none !important;
|
|
225
149
|
-ms-overflow-style: none !important;
|
|
@@ -232,5 +156,5 @@ export const GeistdocsChatShell = () => {
|
|
|
232
156
|
// modal surfaces like the search command menu, dialogs, and
|
|
233
157
|
// dropdowns (z-50), so opening the command menu paints over an
|
|
234
158
|
// 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:
|
|
159
|
+
"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, { chatTitle: chatTitle, onClose: () => setIsOpen(false), children: _jsx(GeistdocsChatInner, { active: !isMobile, 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
160
|
};
|
|
@@ -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"}
|