@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.
- package/dist/assets/icons/icon-fullscreen-close.d.ts +26 -0
- package/dist/assets/icons/icon-fullscreen-close.d.ts.map +1 -0
- package/dist/assets/icons/icon-fullscreen-close.js +25 -0
- package/dist/assets/icons/icon-fullscreen.d.ts +26 -0
- package/dist/assets/icons/icon-fullscreen.d.ts.map +1 -0
- package/dist/assets/icons/icon-fullscreen.js +25 -0
- 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 +3 -0
- package/dist/assets/icons/index.d.ts.map +1 -1
- package/dist/assets/icons/index.js +3 -0
- package/dist/cli/index.js +1 -1
- 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 +49 -2
- package/dist/internal/chat/context.d.ts.map +1 -1
- package/dist/internal/chat/context.js +57 -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 +8 -1
- 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 +86 -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/mdx-to-markdown.d.ts.map +1 -1
- package/dist/internal/mdx-to-markdown.js +226 -19
- 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 +10 -4
- 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/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 +3 -3
- package/docs/llms.txt +634 -37
- package/docs/manifest.json +3 -3
- package/docs/pages/agent-readiness.md +1 -1
- package/docs/pages/ask-ai.md +570 -26
- 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 +1 -1
- package/package.json +1 -2
- package/template/.env.example +5 -0
- package/template/AGENTS.md +2 -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 +570 -26
- 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
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { IconCross, IconFileText } from "#geistdocs-assets/icons";
|
|
4
|
+
import { cn } from "#geistdocs-ui/utils";
|
|
5
|
+
import { getChatPageLabel, getMessagePageAttachment, } from "./commands";
|
|
6
|
+
/** Removable card above the prompt input naming the page the next message carries. */
|
|
7
|
+
export const ChatPageAttachmentCard = ({ onRemove, page, }) => {
|
|
8
|
+
const label = getChatPageLabel(page);
|
|
9
|
+
return (_jsxs("div", { className: "flex min-w-0 items-center gap-2 rounded-md border border-gray-alpha-400 bg-background-200 py-1.5 pr-1 pl-2.5 text-gray-1000 text-label-13", "data-geistdocs-chat-page-attachment": true, children: [_jsx(IconFileText, { className: "shrink-0 text-gray-900", size: 14 }), _jsxs("span", { className: "min-w-0 flex-1 truncate", title: page.url, children: [_jsx("span", { className: "sr-only", children: "Asking about " }), label] }), _jsx("button", { "aria-label": `Remove ${label}`, className: "flex size-6 shrink-0 cursor-pointer items-center justify-center rounded text-gray-900 hover:bg-gray-alpha-100 hover:text-gray-1000 focus-visible:shadow-focus-ring focus-visible:outline-none", onClick: onRemove, type: "button", children: _jsx(IconCross, { size: 12 }) })] }));
|
|
10
|
+
};
|
|
11
|
+
/** Chip on a sent user message naming the page it was asked about. */
|
|
12
|
+
export const ChatMessagePageChip = ({ className, metadata, }) => {
|
|
13
|
+
const page = getMessagePageAttachment(metadata);
|
|
14
|
+
if (!page) {
|
|
15
|
+
return null;
|
|
16
|
+
}
|
|
17
|
+
return (_jsxs("span", { className: cn("inline-flex max-w-[80%] items-center gap-1 rounded-full border border-gray-alpha-400 px-2 py-0.5 text-gray-900 text-label-12", className), "data-geistdocs-chat-message-page": true, title: page.url, children: [_jsx(IconFileText, { className: "shrink-0", size: 12 }), _jsxs("span", { className: "truncate", children: [_jsx("span", { className: "sr-only", children: "Asked about " }), getChatPageLabel(page)] })] }));
|
|
18
|
+
};
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { type ReactNode } from "react";
|
|
2
|
+
import { type GeistdocsChatSession } from "./session";
|
|
3
|
+
type ChatSessionState = {
|
|
4
|
+
status: "loading";
|
|
5
|
+
} | {
|
|
6
|
+
error: Error;
|
|
7
|
+
/**
|
|
8
|
+
* Try again after a transient failure, such as an unreadable history
|
|
9
|
+
* store. Absent for configuration errors, which retrying can't fix.
|
|
10
|
+
*/
|
|
11
|
+
retry?: () => void;
|
|
12
|
+
status: "error";
|
|
13
|
+
} | {
|
|
14
|
+
/** Clear the stored and displayed conversation. */
|
|
15
|
+
clearConversation: () => Promise<void>;
|
|
16
|
+
session: GeistdocsChatSession;
|
|
17
|
+
status: "ready";
|
|
18
|
+
};
|
|
19
|
+
/**
|
|
20
|
+
* The shared chat session. `"error"` must be thrown by the consumer so it
|
|
21
|
+
* fails inside that shell's chat error boundary instead of the page.
|
|
22
|
+
*/
|
|
23
|
+
export declare const useChatSession: () => ChatSessionState;
|
|
24
|
+
/**
|
|
25
|
+
* Provides the single chat shared by the desktop panel and the mobile
|
|
26
|
+
* drawer. An invalid `ai.endpoint` is caught here and handed to the shells
|
|
27
|
+
* as an `"error"` state, so it fails inside their error boundaries.
|
|
28
|
+
*/
|
|
29
|
+
export declare const GeistdocsChatSessionProvider: ({ children, }: {
|
|
30
|
+
children: ReactNode;
|
|
31
|
+
}) => import("react/jsx-runtime").JSX.Element;
|
|
32
|
+
export {};
|
|
33
|
+
//# sourceMappingURL=session-provider.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"session-provider.d.ts","sourceRoot":"","sources":["../../../src/internal/chat/session-provider.tsx"],"names":[],"mappings":"AAIA,OAAO,EAEL,KAAK,SAAS,EAQf,MAAM,OAAO,CAAC;AAMf,OAAO,EAEL,KAAK,oBAAoB,EAE1B,MAAM,WAAW,CAAC;AAInB,KAAK,gBAAgB,GACjB;IAAE,MAAM,EAAE,SAAS,CAAA;CAAE,GACrB;IACE,KAAK,EAAE,KAAK,CAAC;IACb;;;OAGG;IACH,KAAK,CAAC,EAAE,MAAM,IAAI,CAAC;IACnB,MAAM,EAAE,OAAO,CAAC;CACjB,GACD;IACE,mDAAmD;IACnD,iBAAiB,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;IACvC,OAAO,EAAE,oBAAoB,CAAC;IAC9B,MAAM,EAAE,OAAO,CAAC;CACjB,CAAC;AAIN;;;GAGG;AACH,eAAO,MAAM,cAAc,wBAU1B,CAAC;AA8HF;;;;GAIG;AACH,eAAO,MAAM,4BAA4B,GAAI,eAE1C;IACD,QAAQ,EAAE,SAAS,CAAC;CACrB,4CAmCA,CAAC"}
|
|
@@ -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":"AA6ZA,eAAO,MAAM,kBAAkB,sDAgE9B,CAAC"}
|