@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 @@
|
|
|
1
|
+
{"version":3,"file":"chat-user.d.ts","sourceRoot":"","sources":["../../../src/internal/chat/chat-user.ts"],"names":[],"mappings":"AAAA,iEAAiE;AACjE,MAAM,WAAW,QAAQ;IACvB,SAAS,EAAE,MAAM,CAAC;IAClB,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAID;;;;GAIG;AACH,eAAO,MAAM,wBAAwB,GAAI,OAAO,OAAO,KAAG,MAAM,GAAG,IAuBlE,CAAC"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
const UNSAFE_CHARACTER_PATTERN = /[\s\\]/;
|
|
2
|
+
/**
|
|
3
|
+
* The avatar URL to render, or `null` when the value is not an `http(s)` URL
|
|
4
|
+
* or a root-relative path. Other schemes, such as `javascript:` and `data:`,
|
|
5
|
+
* and protocol-relative URLs are ignored.
|
|
6
|
+
*/
|
|
7
|
+
export const resolveChatUserAvatarUrl = (value) => {
|
|
8
|
+
if (typeof value !== "string") {
|
|
9
|
+
return null;
|
|
10
|
+
}
|
|
11
|
+
const url = value.trim();
|
|
12
|
+
if (!url || UNSAFE_CHARACTER_PATTERN.test(url)) {
|
|
13
|
+
return null;
|
|
14
|
+
}
|
|
15
|
+
if (url.startsWith("/")) {
|
|
16
|
+
return url.startsWith("//") ? null : url;
|
|
17
|
+
}
|
|
18
|
+
try {
|
|
19
|
+
const parsed = new URL(url);
|
|
20
|
+
return parsed.protocol === "https:" || parsed.protocol === "http:"
|
|
21
|
+
? parsed.href
|
|
22
|
+
: null;
|
|
23
|
+
}
|
|
24
|
+
catch {
|
|
25
|
+
return null;
|
|
26
|
+
}
|
|
27
|
+
};
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Commands issued through the public chat controller before the lazily
|
|
3
|
+
* loaded chat shell can act on them: questions to submit, a page to attach
|
|
4
|
+
* to the next message, and a request to start a new conversation. The
|
|
5
|
+
* provider owns one queue; the active shell drains it once its stored
|
|
6
|
+
* history has loaded and no response is streaming.
|
|
7
|
+
*/
|
|
8
|
+
/** Page attached to a chat message. `url` is a site-relative path. */
|
|
9
|
+
export interface ChatPageAttachment {
|
|
10
|
+
title?: string;
|
|
11
|
+
url: string;
|
|
12
|
+
}
|
|
13
|
+
export interface ChatPendingAsk {
|
|
14
|
+
id: number;
|
|
15
|
+
text: string;
|
|
16
|
+
}
|
|
17
|
+
export interface ChatCommandState {
|
|
18
|
+
attachedPage: ChatPageAttachment | null;
|
|
19
|
+
/** Set when the current conversation must be cleared before anything else. */
|
|
20
|
+
clearRequested: boolean;
|
|
21
|
+
pendingAsks: readonly ChatPendingAsk[];
|
|
22
|
+
/**
|
|
23
|
+
* True while a shell is running a queued command. Shared across the
|
|
24
|
+
* desktop panel and mobile drawer so a shell that becomes active mid-command
|
|
25
|
+
* (for example after a resize) waits instead of sending concurrently.
|
|
26
|
+
*/
|
|
27
|
+
running: boolean;
|
|
28
|
+
}
|
|
29
|
+
/** Matches the chat route's `pageContext.url` limit. */
|
|
30
|
+
export declare const MAX_CHAT_PAGE_URL_CHARS = 2048;
|
|
31
|
+
/**
|
|
32
|
+
* Reduce a page reference to the site-relative path the chat route resolves
|
|
33
|
+
* against the site's own pages. Relative URLs resolve against `origin`; for
|
|
34
|
+
* absolute URLs only the path is kept, so a production URL still names the
|
|
35
|
+
* page on a preview deployment. Query strings and fragments are dropped.
|
|
36
|
+
* Returns `null` for anything that is not an HTTP(S) URL or path.
|
|
37
|
+
*/
|
|
38
|
+
export declare const normalizeChatPage: (page: {
|
|
39
|
+
title?: unknown;
|
|
40
|
+
url?: unknown;
|
|
41
|
+
} | undefined, origin: string) => ChatPageAttachment | null;
|
|
42
|
+
/** Label for an attached page: its title, falling back to its path. */
|
|
43
|
+
export declare const getChatPageLabel: (page: ChatPageAttachment) => string;
|
|
44
|
+
/**
|
|
45
|
+
* Read the page attachment persisted in a user message's metadata, if any.
|
|
46
|
+
*/
|
|
47
|
+
export declare const getMessagePageAttachment: (metadata: unknown) => ChatPageAttachment | null;
|
|
48
|
+
export interface ChatCommandQueue {
|
|
49
|
+
/**
|
|
50
|
+
* Queue `text` as a user message. Returns `false` (and queues nothing)
|
|
51
|
+
* when the trimmed text is empty.
|
|
52
|
+
*/
|
|
53
|
+
ask: (text: string) => boolean;
|
|
54
|
+
/**
|
|
55
|
+
* Start a new conversation about `page`: drops questions queued for the
|
|
56
|
+
* current conversation, requests a clear, and attaches the page to the
|
|
57
|
+
* next message.
|
|
58
|
+
*/
|
|
59
|
+
attachPage: (page: ChatPageAttachment) => void;
|
|
60
|
+
/**
|
|
61
|
+
* Claim the queue for one command. Returns `false` when another command is
|
|
62
|
+
* already running, so the caller must not start one.
|
|
63
|
+
*/
|
|
64
|
+
beginCommand: () => boolean;
|
|
65
|
+
/** Mark a requested clear as done. */
|
|
66
|
+
completeClear: () => void;
|
|
67
|
+
/** Remove the attached page without sending it. */
|
|
68
|
+
detachPage: () => void;
|
|
69
|
+
/** Release the claim taken by `beginCommand`. */
|
|
70
|
+
endCommand: () => void;
|
|
71
|
+
getState: () => ChatCommandState;
|
|
72
|
+
subscribe: (listener: () => void) => () => void;
|
|
73
|
+
/** Remove and return the attached page, so only one message carries it. */
|
|
74
|
+
takeAttachedPage: () => ChatPageAttachment | null;
|
|
75
|
+
/** Remove and return the oldest queued question. */
|
|
76
|
+
takeNextAsk: () => ChatPendingAsk | null;
|
|
77
|
+
}
|
|
78
|
+
export declare const createChatCommandQueue: () => ChatCommandQueue;
|
|
79
|
+
/** Whether the chat can submit a message or clear without interrupting one. */
|
|
80
|
+
export declare const isChatIdle: (status: string) => status is "error" | "ready";
|
|
81
|
+
/**
|
|
82
|
+
* What the active chat shell should do next with the queue. A requested
|
|
83
|
+
* clear interrupts a streaming answer (`"stop"`) and runs before any queued
|
|
84
|
+
* question; questions wait for the chat to be idle and for the previous
|
|
85
|
+
* command, in either shell, to settle (`state.running`).
|
|
86
|
+
*/
|
|
87
|
+
export declare const getNextChatCommand: ({ state, status, }: {
|
|
88
|
+
state: ChatCommandState;
|
|
89
|
+
status: string;
|
|
90
|
+
}) => "ask" | "clear" | "stop" | null;
|
|
91
|
+
//# sourceMappingURL=commands.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"commands.d.ts","sourceRoot":"","sources":["../../../src/internal/chat/commands.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,sEAAsE;AACtE,MAAM,WAAW,kBAAkB;IACjC,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,GAAG,EAAE,MAAM,CAAC;CACb;AAED,MAAM,WAAW,cAAc;IAC7B,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;CACd;AAED,MAAM,WAAW,gBAAgB;IAC/B,YAAY,EAAE,kBAAkB,GAAG,IAAI,CAAC;IACxC,8EAA8E;IAC9E,cAAc,EAAE,OAAO,CAAC;IACxB,WAAW,EAAE,SAAS,cAAc,EAAE,CAAC;IACvC;;;;OAIG;IACH,OAAO,EAAE,OAAO,CAAC;CAClB;AAED,wDAAwD;AACxD,eAAO,MAAM,uBAAuB,OAAO,CAAC;AAU5C;;;;;;GAMG;AACH,eAAO,MAAM,iBAAiB,GAC5B,MAAM;IAAE,KAAK,CAAC,EAAE,OAAO,CAAC;IAAC,GAAG,CAAC,EAAE,OAAO,CAAA;CAAE,GAAG,SAAS,EACpD,QAAQ,MAAM,KACb,kBAAkB,GAAG,IAmCvB,CAAC;AAEF,uEAAuE;AACvE,eAAO,MAAM,gBAAgB,GAAI,MAAM,kBAAkB,WACjC,CAAC;AAEzB;;GAEG;AACH,eAAO,MAAM,wBAAwB,GACnC,UAAU,OAAO,KAChB,kBAAkB,GAAG,IAcvB,CAAC;AAEF,MAAM,WAAW,gBAAgB;IAC/B;;;OAGG;IACH,GAAG,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,OAAO,CAAC;IAC/B;;;;OAIG;IACH,UAAU,EAAE,CAAC,IAAI,EAAE,kBAAkB,KAAK,IAAI,CAAC;IAC/C;;;OAGG;IACH,YAAY,EAAE,MAAM,OAAO,CAAC;IAC5B,sCAAsC;IACtC,aAAa,EAAE,MAAM,IAAI,CAAC;IAC1B,mDAAmD;IACnD,UAAU,EAAE,MAAM,IAAI,CAAC;IACvB,iDAAiD;IACjD,UAAU,EAAE,MAAM,IAAI,CAAC;IACvB,QAAQ,EAAE,MAAM,gBAAgB,CAAC;IACjC,SAAS,EAAE,CAAC,QAAQ,EAAE,MAAM,IAAI,KAAK,MAAM,IAAI,CAAC;IAChD,2EAA2E;IAC3E,gBAAgB,EAAE,MAAM,kBAAkB,GAAG,IAAI,CAAC;IAClD,oDAAoD;IACpD,WAAW,EAAE,MAAM,cAAc,GAAG,IAAI,CAAC;CAC1C;AAED,eAAO,MAAM,sBAAsB,QAAO,gBAyFzC,CAAC;AAEF,+EAA+E;AAC/E,eAAO,MAAM,UAAU,GAAI,QAAQ,MAAM,gCACC,CAAC;AAE3C;;;;;GAKG;AACH,eAAO,MAAM,kBAAkB,GAAI,oBAGhC;IACD,KAAK,EAAE,gBAAgB,CAAC;IACxB,MAAM,EAAE,MAAM,CAAC;CAChB,KAAG,KAAK,GAAG,OAAO,GAAG,MAAM,GAAG,IAgB9B,CAAC"}
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Commands issued through the public chat controller before the lazily
|
|
3
|
+
* loaded chat shell can act on them: questions to submit, a page to attach
|
|
4
|
+
* to the next message, and a request to start a new conversation. The
|
|
5
|
+
* provider owns one queue; the active shell drains it once its stored
|
|
6
|
+
* history has loaded and no response is streaming.
|
|
7
|
+
*/
|
|
8
|
+
/** Matches the chat route's `pageContext.url` limit. */
|
|
9
|
+
export const MAX_CHAT_PAGE_URL_CHARS = 2048;
|
|
10
|
+
const MAX_CHAT_PAGE_TITLE_CHARS = 300;
|
|
11
|
+
const initialState = {
|
|
12
|
+
attachedPage: null,
|
|
13
|
+
clearRequested: false,
|
|
14
|
+
pendingAsks: [],
|
|
15
|
+
running: false,
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* Reduce a page reference to the site-relative path the chat route resolves
|
|
19
|
+
* against the site's own pages. Relative URLs resolve against `origin`; for
|
|
20
|
+
* absolute URLs only the path is kept, so a production URL still names the
|
|
21
|
+
* page on a preview deployment. Query strings and fragments are dropped.
|
|
22
|
+
* Returns `null` for anything that is not an HTTP(S) URL or path.
|
|
23
|
+
*/
|
|
24
|
+
export const normalizeChatPage = (page, origin) => {
|
|
25
|
+
if (typeof page?.url !== "string") {
|
|
26
|
+
return null;
|
|
27
|
+
}
|
|
28
|
+
const raw = page.url.trim();
|
|
29
|
+
if (!raw) {
|
|
30
|
+
return null;
|
|
31
|
+
}
|
|
32
|
+
let url;
|
|
33
|
+
try {
|
|
34
|
+
url = new URL(raw, origin);
|
|
35
|
+
}
|
|
36
|
+
catch {
|
|
37
|
+
return null;
|
|
38
|
+
}
|
|
39
|
+
if (url.protocol !== "http:" && url.protocol !== "https:") {
|
|
40
|
+
return null;
|
|
41
|
+
}
|
|
42
|
+
const path = url.pathname;
|
|
43
|
+
if (path.length > MAX_CHAT_PAGE_URL_CHARS) {
|
|
44
|
+
return null;
|
|
45
|
+
}
|
|
46
|
+
const title = typeof page.title === "string"
|
|
47
|
+
? page.title.trim().slice(0, MAX_CHAT_PAGE_TITLE_CHARS)
|
|
48
|
+
: "";
|
|
49
|
+
return title ? { title, url: path } : { url: path };
|
|
50
|
+
};
|
|
51
|
+
/** Label for an attached page: its title, falling back to its path. */
|
|
52
|
+
export const getChatPageLabel = (page) => page.title || page.url;
|
|
53
|
+
/**
|
|
54
|
+
* Read the page attachment persisted in a user message's metadata, if any.
|
|
55
|
+
*/
|
|
56
|
+
export const getMessagePageAttachment = (metadata) => {
|
|
57
|
+
const page = metadata?.page;
|
|
58
|
+
if (typeof page !== "object" ||
|
|
59
|
+
page === null ||
|
|
60
|
+
typeof page.url !== "string") {
|
|
61
|
+
return null;
|
|
62
|
+
}
|
|
63
|
+
const { title, url } = page;
|
|
64
|
+
return typeof title === "string" && title ? { title, url } : { url };
|
|
65
|
+
};
|
|
66
|
+
export const createChatCommandQueue = () => {
|
|
67
|
+
let state = initialState;
|
|
68
|
+
let nextId = 1;
|
|
69
|
+
const listeners = new Set();
|
|
70
|
+
const update = (next) => {
|
|
71
|
+
if (next === state) {
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
state = next;
|
|
75
|
+
for (const listener of listeners) {
|
|
76
|
+
listener();
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
return {
|
|
80
|
+
ask: (text) => {
|
|
81
|
+
const trimmed = typeof text === "string" ? text.trim() : "";
|
|
82
|
+
if (!trimmed) {
|
|
83
|
+
return false;
|
|
84
|
+
}
|
|
85
|
+
update({
|
|
86
|
+
...state,
|
|
87
|
+
pendingAsks: [...state.pendingAsks, { id: nextId++, text: trimmed }],
|
|
88
|
+
});
|
|
89
|
+
return true;
|
|
90
|
+
},
|
|
91
|
+
attachPage: (page) => {
|
|
92
|
+
update({
|
|
93
|
+
...state,
|
|
94
|
+
attachedPage: page,
|
|
95
|
+
clearRequested: true,
|
|
96
|
+
pendingAsks: [],
|
|
97
|
+
});
|
|
98
|
+
},
|
|
99
|
+
beginCommand: () => {
|
|
100
|
+
if (state.running) {
|
|
101
|
+
return false;
|
|
102
|
+
}
|
|
103
|
+
update({ ...state, running: true });
|
|
104
|
+
return true;
|
|
105
|
+
},
|
|
106
|
+
completeClear: () => {
|
|
107
|
+
if (state.clearRequested) {
|
|
108
|
+
update({ ...state, clearRequested: false });
|
|
109
|
+
}
|
|
110
|
+
},
|
|
111
|
+
detachPage: () => {
|
|
112
|
+
if (state.attachedPage) {
|
|
113
|
+
update({ ...state, attachedPage: null });
|
|
114
|
+
}
|
|
115
|
+
},
|
|
116
|
+
endCommand: () => {
|
|
117
|
+
if (state.running) {
|
|
118
|
+
update({ ...state, running: false });
|
|
119
|
+
}
|
|
120
|
+
},
|
|
121
|
+
getState: () => state,
|
|
122
|
+
subscribe: (listener) => {
|
|
123
|
+
listeners.add(listener);
|
|
124
|
+
return () => {
|
|
125
|
+
listeners.delete(listener);
|
|
126
|
+
};
|
|
127
|
+
},
|
|
128
|
+
takeAttachedPage: () => {
|
|
129
|
+
const page = state.attachedPage;
|
|
130
|
+
if (page) {
|
|
131
|
+
update({ ...state, attachedPage: null });
|
|
132
|
+
}
|
|
133
|
+
return page;
|
|
134
|
+
},
|
|
135
|
+
takeNextAsk: () => {
|
|
136
|
+
const [next, ...rest] = state.pendingAsks;
|
|
137
|
+
if (!next) {
|
|
138
|
+
return null;
|
|
139
|
+
}
|
|
140
|
+
update({ ...state, pendingAsks: rest });
|
|
141
|
+
return next;
|
|
142
|
+
},
|
|
143
|
+
};
|
|
144
|
+
};
|
|
145
|
+
/** Whether the chat can submit a message or clear without interrupting one. */
|
|
146
|
+
export const isChatIdle = (status) => status === "ready" || status === "error";
|
|
147
|
+
/**
|
|
148
|
+
* What the active chat shell should do next with the queue. A requested
|
|
149
|
+
* clear interrupts a streaming answer (`"stop"`) and runs before any queued
|
|
150
|
+
* question; questions wait for the chat to be idle and for the previous
|
|
151
|
+
* command, in either shell, to settle (`state.running`).
|
|
152
|
+
*/
|
|
153
|
+
export const getNextChatCommand = ({ state, status, }) => {
|
|
154
|
+
const idle = isChatIdle(status);
|
|
155
|
+
if (state.clearRequested && !idle) {
|
|
156
|
+
return "stop";
|
|
157
|
+
}
|
|
158
|
+
if (state.running || !idle) {
|
|
159
|
+
return null;
|
|
160
|
+
}
|
|
161
|
+
if (state.clearRequested) {
|
|
162
|
+
return "clear";
|
|
163
|
+
}
|
|
164
|
+
return state.pendingAsks.length > 0 ? "ask" : null;
|
|
165
|
+
};
|
|
@@ -1,19 +1,66 @@
|
|
|
1
1
|
import type { GeistdocsConfig } from "../../config";
|
|
2
|
+
import type { ChatUser } from "./chat-user";
|
|
3
|
+
import { type ChatCommandQueue, type ChatCommandState } from "./commands";
|
|
4
|
+
import { type ChatSuggestion } from "./options";
|
|
5
|
+
/** Page to attach to the next Ask AI message. */
|
|
6
|
+
export interface GeistdocsChatPage {
|
|
7
|
+
/** Title shown on the attached-page card. Falls back to `url`. */
|
|
8
|
+
title?: string;
|
|
9
|
+
/** Site-relative path of the page. For an absolute URL only the path is sent. */
|
|
10
|
+
url: string;
|
|
11
|
+
}
|
|
12
|
+
/** Public Ask AI controller returned by `useGeistdocsChat`. */
|
|
13
|
+
export interface GeistdocsChatController {
|
|
14
|
+
/**
|
|
15
|
+
* Open the chat and submit `text` as a user message. Waits for the chat to
|
|
16
|
+
* load and for any streaming response to finish. Empty text is ignored.
|
|
17
|
+
*/
|
|
18
|
+
ask: (text: string) => void;
|
|
19
|
+
close: () => void;
|
|
20
|
+
/** `false` when `ai.enabled` is `false`; every action is then a no-op. */
|
|
21
|
+
enabled: boolean;
|
|
22
|
+
isOpen: boolean;
|
|
23
|
+
open: () => void;
|
|
24
|
+
/**
|
|
25
|
+
* Start a new conversation about `page` (default: the current page). The
|
|
26
|
+
* page is sent with the next message only.
|
|
27
|
+
*/
|
|
28
|
+
openWithPage: (page?: GeistdocsChatPage) => void;
|
|
29
|
+
toggle: () => void;
|
|
30
|
+
}
|
|
2
31
|
interface GeistdocsChatContextValue {
|
|
32
|
+
ask: GeistdocsChatController["ask"];
|
|
3
33
|
basePath?: string;
|
|
34
|
+
/** Unvalidated `ai.endpoint`; resolved inside the chat error boundary. */
|
|
35
|
+
chatEndpoint?: string;
|
|
36
|
+
/** Chat panel heading from `ai.title`. Not the site title. */
|
|
37
|
+
chatTitle: string;
|
|
38
|
+
commandState: ChatCommandState;
|
|
39
|
+
/** Queue drained by the active chat shell. */
|
|
40
|
+
commands: ChatCommandQueue;
|
|
4
41
|
enabled: boolean;
|
|
5
42
|
footer?: React.ReactNode;
|
|
6
43
|
hasBeenOpened: boolean;
|
|
44
|
+
/** Milliseconds a stored conversation is kept after its last message. */
|
|
45
|
+
historyRetentionMs: number;
|
|
46
|
+
/** Desktop panel fills the viewport. Reset when the chat closes. */
|
|
47
|
+
isExpanded: boolean;
|
|
7
48
|
isOpen: boolean;
|
|
49
|
+
openWithPage: GeistdocsChatController["openWithPage"];
|
|
8
50
|
preloadChat: () => void;
|
|
9
51
|
prewarmEveAgent: boolean;
|
|
10
52
|
prompt: string;
|
|
53
|
+
setIsExpanded: React.Dispatch<React.SetStateAction<boolean>>;
|
|
11
54
|
setIsOpen: React.Dispatch<React.SetStateAction<boolean>>;
|
|
12
55
|
setPrompt: React.Dispatch<React.SetStateAction<string>>;
|
|
13
|
-
|
|
56
|
+
setUser: React.Dispatch<React.SetStateAction<ChatUser | null>>;
|
|
57
|
+
suggestions: ChatSuggestion[];
|
|
58
|
+
/** Site title from `config.title`; names the chat history database. */
|
|
14
59
|
title: string;
|
|
60
|
+
/** Signed-in reader set at runtime by `<AskAIUser />`. */
|
|
61
|
+
user: ChatUser | null;
|
|
15
62
|
}
|
|
16
|
-
export declare const
|
|
63
|
+
export declare const useGeistdocsChatContext: () => GeistdocsChatContextValue;
|
|
17
64
|
interface GeistdocsChatProviderProps {
|
|
18
65
|
children: React.ReactNode;
|
|
19
66
|
config: Pick<GeistdocsConfig, "ai" | "basePath" | "title">;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../../../src/internal/chat/context.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../../../src/internal/chat/context.tsx"],"names":[],"mappings":"AAWA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AACpD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EACL,KAAK,gBAAgB,EACrB,KAAK,gBAAgB,EAGtB,MAAM,YAAY,CAAC;AACpB,OAAO,EACL,KAAK,cAAc,EAKpB,MAAM,WAAW,CAAC;AAInB,iDAAiD;AACjD,MAAM,WAAW,iBAAiB;IAChC,kEAAkE;IAClE,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,iFAAiF;IACjF,GAAG,EAAE,MAAM,CAAC;CACb;AAED,+DAA+D;AAC/D,MAAM,WAAW,uBAAuB;IACtC;;;OAGG;IACH,GAAG,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;IAC5B,KAAK,EAAE,MAAM,IAAI,CAAC;IAClB,0EAA0E;IAC1E,OAAO,EAAE,OAAO,CAAC;IACjB,MAAM,EAAE,OAAO,CAAC;IAChB,IAAI,EAAE,MAAM,IAAI,CAAC;IACjB;;;OAGG;IACH,YAAY,EAAE,CAAC,IAAI,CAAC,EAAE,iBAAiB,KAAK,IAAI,CAAC;IACjD,MAAM,EAAE,MAAM,IAAI,CAAC;CACpB;AAED,UAAU,yBAAyB;IACjC,GAAG,EAAE,uBAAuB,CAAC,KAAK,CAAC,CAAC;IACpC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,0EAA0E;IAC1E,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,8DAA8D;IAC9D,SAAS,EAAE,MAAM,CAAC;IAClB,YAAY,EAAE,gBAAgB,CAAC;IAC/B,8CAA8C;IAC9C,QAAQ,EAAE,gBAAgB,CAAC;IAC3B,OAAO,EAAE,OAAO,CAAC;IACjB,MAAM,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;IACzB,aAAa,EAAE,OAAO,CAAC;IACvB,yEAAyE;IACzE,kBAAkB,EAAE,MAAM,CAAC;IAC3B,oEAAoE;IACpE,UAAU,EAAE,OAAO,CAAC;IACpB,MAAM,EAAE,OAAO,CAAC;IAChB,YAAY,EAAE,uBAAuB,CAAC,cAAc,CAAC,CAAC;IACtD,WAAW,EAAE,MAAM,IAAI,CAAC;IACxB,eAAe,EAAE,OAAO,CAAC;IACzB,MAAM,EAAE,MAAM,CAAC;IACf,aAAa,EAAE,KAAK,CAAC,QAAQ,CAAC,KAAK,CAAC,cAAc,CAAC,OAAO,CAAC,CAAC,CAAC;IAC7D,SAAS,EAAE,KAAK,CAAC,QAAQ,CAAC,KAAK,CAAC,cAAc,CAAC,OAAO,CAAC,CAAC,CAAC;IACzD,SAAS,EAAE,KAAK,CAAC,QAAQ,CAAC,KAAK,CAAC,cAAc,CAAC,MAAM,CAAC,CAAC,CAAC;IACxD,OAAO,EAAE,KAAK,CAAC,QAAQ,CAAC,KAAK,CAAC,cAAc,CAAC,QAAQ,GAAG,IAAI,CAAC,CAAC,CAAC;IAC/D,WAAW,EAAE,cAAc,EAAE,CAAC;IAC9B,uEAAuE;IACvE,KAAK,EAAE,MAAM,CAAC;IACd,0DAA0D;IAC1D,IAAI,EAAE,QAAQ,GAAG,IAAI,CAAC;CACvB;AAMD,eAAO,MAAM,uBAAuB,iCAQnC,CAAC;AAEF,UAAU,0BAA0B;IAClC,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC;IAC1B,MAAM,EAAE,IAAI,CAAC,eAAe,EAAE,IAAI,GAAG,UAAU,GAAG,OAAO,CAAC,CAAC;CAC5D;AAED,eAAO,MAAM,qBAAqB,GAAI,uBAGnC,0BAA0B,4CAkI5B,CAAC"}
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
-
import { createContext, useCallback, useContext, useEffect, useMemo, useState, } from "react";
|
|
3
|
+
import { createContext, useCallback, useContext, useEffect, useMemo, useState, useSyncExternalStore, } from "react";
|
|
4
|
+
import { createChatCommandQueue, normalizeChatPage, } from "./commands";
|
|
5
|
+
import { isValidChatHistoryRetentionDays, normalizeChatSuggestions, resolveChatHistoryRetentionMs, resolveChatTitle, } from "./options";
|
|
4
6
|
const CHAT_OPEN_STORAGE_KEY = "geistdocs:chat-open";
|
|
5
7
|
const GeistdocsChatContext = createContext(null);
|
|
6
|
-
export const
|
|
8
|
+
export const useGeistdocsChatContext = () => {
|
|
7
9
|
const context = useContext(GeistdocsChatContext);
|
|
8
10
|
if (!context) {
|
|
9
11
|
throw new Error("Chat controls must be used within GeistdocsProvider.");
|
|
@@ -12,9 +14,32 @@ export const useGeistdocsChat = () => {
|
|
|
12
14
|
};
|
|
13
15
|
export const GeistdocsChatProvider = ({ children, config, }) => {
|
|
14
16
|
const [isOpen, setIsOpen] = useState(false);
|
|
17
|
+
const [isExpanded, setIsExpanded] = useState(false);
|
|
15
18
|
const [hasBeenOpened, setHasBeenOpened] = useState(false);
|
|
16
19
|
const [prompt, setPrompt] = useState("");
|
|
20
|
+
const [user, setUser] = useState(null);
|
|
17
21
|
const preloadChat = useCallback(() => setHasBeenOpened(true), []);
|
|
22
|
+
const [commands] = useState(createChatCommandQueue);
|
|
23
|
+
const commandState = useSyncExternalStore(commands.subscribe, commands.getState, commands.getState);
|
|
24
|
+
const enabled = config.ai?.enabled !== false;
|
|
25
|
+
const ask = useCallback((text) => {
|
|
26
|
+
if (enabled && commands.ask(text)) {
|
|
27
|
+
setIsOpen(true);
|
|
28
|
+
}
|
|
29
|
+
}, [commands, enabled]);
|
|
30
|
+
const openWithPage = useCallback((page) => {
|
|
31
|
+
if (!enabled) {
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
const attachment = normalizeChatPage(page ?? { url: window.location.pathname }, window.location.origin);
|
|
35
|
+
if (attachment) {
|
|
36
|
+
commands.attachPage(attachment);
|
|
37
|
+
}
|
|
38
|
+
else {
|
|
39
|
+
console.warn(`Ask AI could not attach the page ${String(page?.url)}: expected a site-relative path or HTTP(S) URL.`);
|
|
40
|
+
}
|
|
41
|
+
setIsOpen(true);
|
|
42
|
+
}, [commands, enabled]);
|
|
18
43
|
useEffect(() => {
|
|
19
44
|
const stored = window.localStorage.getItem(CHAT_OPEN_STORAGE_KEY);
|
|
20
45
|
if (stored !== null) {
|
|
@@ -29,31 +54,59 @@ export const GeistdocsChatProvider = ({ children, config, }) => {
|
|
|
29
54
|
if (isOpen) {
|
|
30
55
|
setHasBeenOpened(true);
|
|
31
56
|
}
|
|
57
|
+
else {
|
|
58
|
+
setIsExpanded(false);
|
|
59
|
+
}
|
|
32
60
|
}, [isOpen]);
|
|
33
61
|
useEffect(() => {
|
|
34
62
|
window.localStorage.setItem(CHAT_OPEN_STORAGE_KEY, String(isOpen));
|
|
35
63
|
}, [isOpen]);
|
|
64
|
+
const retentionDays = config.ai?.history?.retentionDays;
|
|
65
|
+
useEffect(() => {
|
|
66
|
+
if (!isValidChatHistoryRetentionDays(retentionDays)) {
|
|
67
|
+
console.warn(`ai.history.retentionDays must be 0, a positive number, or Infinity. Received ${String(retentionDays)}; using the default.`);
|
|
68
|
+
}
|
|
69
|
+
}, [retentionDays]);
|
|
36
70
|
const value = useMemo(() => ({
|
|
71
|
+
ask,
|
|
37
72
|
basePath: config.basePath,
|
|
73
|
+
chatEndpoint: config.ai?.endpoint,
|
|
74
|
+
chatTitle: resolveChatTitle(config.ai?.title),
|
|
75
|
+
commands,
|
|
76
|
+
commandState,
|
|
38
77
|
footer: config.ai?.footer,
|
|
39
|
-
enabled
|
|
78
|
+
enabled,
|
|
40
79
|
hasBeenOpened,
|
|
80
|
+
historyRetentionMs: resolveChatHistoryRetentionMs(retentionDays),
|
|
81
|
+
isExpanded,
|
|
41
82
|
isOpen,
|
|
83
|
+
openWithPage,
|
|
42
84
|
preloadChat,
|
|
43
85
|
prewarmEveAgent: config.ai?.eveAgent?.prewarm === true,
|
|
44
86
|
prompt,
|
|
87
|
+
setIsExpanded,
|
|
45
88
|
setIsOpen,
|
|
46
89
|
setPrompt,
|
|
47
|
-
|
|
90
|
+
setUser,
|
|
91
|
+
suggestions: normalizeChatSuggestions(config.ai?.suggestions),
|
|
48
92
|
title: config.title,
|
|
93
|
+
user,
|
|
49
94
|
}), [
|
|
95
|
+
ask,
|
|
96
|
+
commands,
|
|
97
|
+
commandState,
|
|
50
98
|
config.ai,
|
|
51
99
|
config.basePath,
|
|
52
100
|
config.title,
|
|
101
|
+
enabled,
|
|
53
102
|
hasBeenOpened,
|
|
103
|
+
isExpanded,
|
|
54
104
|
isOpen,
|
|
105
|
+
openWithPage,
|
|
55
106
|
preloadChat,
|
|
56
107
|
prompt,
|
|
108
|
+
retentionDays,
|
|
109
|
+
user,
|
|
57
110
|
]);
|
|
58
111
|
return (_jsx(GeistdocsChatContext.Provider, { value: value, children: children }));
|
|
59
112
|
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { ChatStatus, UIMessage } from "ai";
|
|
2
|
+
type SetMessages = (messages: UIMessage[] | ((messages: UIMessage[]) => UIMessage[])) => void;
|
|
3
|
+
/**
|
|
4
|
+
* Copy and, with `ai.messageFeedback`, thumbs up/down buttons for a finished
|
|
5
|
+
* assistant message that has text. Renders nothing for user messages, the
|
|
6
|
+
* message currently streaming, and messages without text.
|
|
7
|
+
*/
|
|
8
|
+
export declare const MessageActions: ({ index, messages, setMessages, status, }: {
|
|
9
|
+
index: number;
|
|
10
|
+
messages: UIMessage[];
|
|
11
|
+
setMessages: SetMessages;
|
|
12
|
+
status: ChatStatus;
|
|
13
|
+
}) => import("react/jsx-runtime").JSX.Element | null;
|
|
14
|
+
export {};
|
|
15
|
+
//# sourceMappingURL=message-actions.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"message-actions.d.ts","sourceRoot":"","sources":["../../../src/internal/chat/message-actions.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,IAAI,CAAC;AAyBhD,KAAK,WAAW,GAAG,CACjB,QAAQ,EAAE,SAAS,EAAE,GAAG,CAAC,CAAC,QAAQ,EAAE,SAAS,EAAE,KAAK,SAAS,EAAE,CAAC,KAC7D,IAAI,CAAC;AA4JV;;;;GAIG;AACH,eAAO,MAAM,cAAc,GAAI,2CAK5B;IACD,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,SAAS,EAAE,CAAC;IACtB,WAAW,EAAE,WAAW,CAAC;IACzB,MAAM,EAAE,UAAU,CAAC;CACpB,mDA8BA,CAAC"}
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { usePathname } from "next/navigation";
|
|
4
|
+
import { useEffect, useRef, useState } from "react";
|
|
5
|
+
import { IconCheck, IconCopy, IconThumbDown, IconThumbUp, } from "#geistdocs-assets/icons";
|
|
6
|
+
import { Button } from "#geistdocs-ui/components/button";
|
|
7
|
+
import { useToasts } from "#geistdocs-ui/components/toasts";
|
|
8
|
+
import { Tooltip } from "#geistdocs-ui/components/tooltip";
|
|
9
|
+
import { cn } from "#geistdocs-ui/utils";
|
|
10
|
+
import { getPublicPath } from "../../config";
|
|
11
|
+
import { useGeistdocsConfig } from "../config-context";
|
|
12
|
+
import { sendChatMessageFeedback } from "../feedback-action";
|
|
13
|
+
import { isActiveAssistantMessage } from "./activity";
|
|
14
|
+
import { buildChatMessageFeedback, readMessageFeedbackVote, withMessageFeedbackVote, } from "./message-feedback";
|
|
15
|
+
import { getMessageMarkdown } from "./message-text";
|
|
16
|
+
const actionButtonClassName = "text-gray-900! hover:text-gray-1000!";
|
|
17
|
+
const CopyMessageButton = ({ markdown }) => {
|
|
18
|
+
const [copied, setCopied] = useState(false);
|
|
19
|
+
const timeoutRef = useRef(null);
|
|
20
|
+
const toast = useToasts();
|
|
21
|
+
useEffect(() => () => {
|
|
22
|
+
if (timeoutRef.current) {
|
|
23
|
+
clearTimeout(timeoutRef.current);
|
|
24
|
+
}
|
|
25
|
+
}, []);
|
|
26
|
+
const copy = async () => {
|
|
27
|
+
try {
|
|
28
|
+
await navigator.clipboard.writeText(markdown);
|
|
29
|
+
}
|
|
30
|
+
catch (error) {
|
|
31
|
+
toast.error({
|
|
32
|
+
text: error instanceof Error
|
|
33
|
+
? `Failed to copy response: ${error.message}`
|
|
34
|
+
: "Failed to copy response",
|
|
35
|
+
});
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
setCopied(true);
|
|
39
|
+
if (timeoutRef.current) {
|
|
40
|
+
clearTimeout(timeoutRef.current);
|
|
41
|
+
}
|
|
42
|
+
timeoutRef.current = setTimeout(() => setCopied(false), 2000);
|
|
43
|
+
};
|
|
44
|
+
const Icon = copied ? IconCheck : IconCopy;
|
|
45
|
+
return (_jsx(Tooltip, { position: "bottom", text: "Copy response as Markdown", children: _jsxs(Button, { "aria-label": copied ? "Response copied" : "Copy response as Markdown", className: actionButtonClassName, onClick: copy, shape: "square", size: "small", svgOnly: true, typeName: "button", variant: "tertiary", children: [_jsx(Icon, { "aria-hidden": true, size: 14 }), copied ? (_jsx("span", { "aria-live": "polite", className: "sr-only", role: "status", children: "Copied" })) : null] }) }));
|
|
46
|
+
};
|
|
47
|
+
const feedbackOptions = [
|
|
48
|
+
{ icon: IconThumbUp, label: "Helpful", vote: "up" },
|
|
49
|
+
{ icon: IconThumbDown, label: "Not helpful", vote: "down" },
|
|
50
|
+
];
|
|
51
|
+
const MessageFeedbackButtons = ({ messageId, messages, setMessages, vote, }) => {
|
|
52
|
+
const [pendingVote, setPendingVote] = useState(null);
|
|
53
|
+
const { basePath, siteId } = useGeistdocsConfig();
|
|
54
|
+
const pathname = usePathname();
|
|
55
|
+
const toast = useToasts();
|
|
56
|
+
const submit = async (nextVote) => {
|
|
57
|
+
if (vote || pendingVote) {
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
const feedback = buildChatMessageFeedback({
|
|
61
|
+
messageId,
|
|
62
|
+
messages,
|
|
63
|
+
pageUrl: getPublicPath(pathname, basePath),
|
|
64
|
+
vote: nextVote,
|
|
65
|
+
});
|
|
66
|
+
if (!feedback) {
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
setPendingVote(nextVote);
|
|
70
|
+
let success = false;
|
|
71
|
+
try {
|
|
72
|
+
({ success } = await sendChatMessageFeedback({ feedback, siteId }));
|
|
73
|
+
}
|
|
74
|
+
catch (error) {
|
|
75
|
+
console.error("Failed to send Ask AI feedback:", error);
|
|
76
|
+
}
|
|
77
|
+
setPendingVote(null);
|
|
78
|
+
if (!success) {
|
|
79
|
+
toast.error({ text: "Couldn't send feedback. Try again." });
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
// Stored in message metadata so the vote persists with chat history.
|
|
83
|
+
setMessages((current) => withMessageFeedbackVote(current, messageId, nextVote));
|
|
84
|
+
toast.success({ text: "Thanks for your feedback" });
|
|
85
|
+
};
|
|
86
|
+
return feedbackOptions.map((option) => {
|
|
87
|
+
const selected = (vote ?? pendingVote) === option.vote;
|
|
88
|
+
const Icon = option.icon;
|
|
89
|
+
return (_jsx(Tooltip, { position: "bottom", text: option.label, children: _jsx(Button, { "aria-label": option.label, "aria-pressed": selected, className: cn(actionButtonClassName, selected && "text-gray-1000! disabled:opacity-100!"), disabled: Boolean(vote || pendingVote), onClick: () => {
|
|
90
|
+
submit(option.vote).catch((error) => {
|
|
91
|
+
console.error("Failed to send Ask AI feedback:", error);
|
|
92
|
+
});
|
|
93
|
+
}, shape: "square", size: "small", svgOnly: true, typeName: "button", variant: "tertiary", children: _jsx(Icon, { "aria-hidden": true, size: 14 }) }) }, option.vote));
|
|
94
|
+
});
|
|
95
|
+
};
|
|
96
|
+
/**
|
|
97
|
+
* Copy and, with `ai.messageFeedback`, thumbs up/down buttons for a finished
|
|
98
|
+
* assistant message that has text. Renders nothing for user messages, the
|
|
99
|
+
* message currently streaming, and messages without text.
|
|
100
|
+
*/
|
|
101
|
+
export const MessageActions = ({ index, messages, setMessages, status, }) => {
|
|
102
|
+
const { ai } = useGeistdocsConfig();
|
|
103
|
+
const message = messages[index];
|
|
104
|
+
if (message?.role !== "assistant" ||
|
|
105
|
+
isActiveAssistantMessage({ index, messages, status })) {
|
|
106
|
+
return null;
|
|
107
|
+
}
|
|
108
|
+
const markdown = getMessageMarkdown(message);
|
|
109
|
+
if (!markdown) {
|
|
110
|
+
return null;
|
|
111
|
+
}
|
|
112
|
+
return (_jsxs("div", { className: "-ml-2 flex items-center gap-0.5", children: [_jsx(CopyMessageButton, { markdown: markdown }), ai?.messageFeedback === true ? (_jsx(MessageFeedbackButtons, { messageId: message.id, messages: messages, setMessages: setMessages, vote: readMessageFeedbackVote(message) })) : null] }));
|
|
113
|
+
};
|