Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(ai-help): send correct context when editing question #10511

Merged
merged 5 commits into from Feb 20, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
19 changes: 12 additions & 7 deletions client/src/plus/ai-help/use-ai.ts
Expand Up @@ -110,27 +110,32 @@ export interface MessageTreeState {

export function stateToMessagePath(
state: MessageTreeState,
path: number[]
path: number[],
lazy: boolean = false
caugner marked this conversation as resolved.
Show resolved Hide resolved
): Message[] {
const [current = 0, ...tail] = path || [];
if (!state.root.length) {
return [];
}
return messagePath(state.root[current], tail);
return messagePath(state.root[current], tail, lazy);
}

function messagePath(node: MessageTreeNode, path: number[]): Message[] {
const [current = 0, ...tail] = path;
function messagePath(
node: MessageTreeNode,
path: number[],
lazy: boolean = false
): Message[] {
const [current = null, ...tail] = path;
if (!node) {
return [];
}
if (!node.children.length) {
if (!node.children.length || (!lazy && current === null)) {
return [node.request, node.response];
}
return [
node.request,
node.response,
...messagePath(node.children[current], tail),
...messagePath(node.children[current || 0], tail, lazy),
];
}

Expand Down Expand Up @@ -672,7 +677,7 @@ export function useAiChat({
);

useEffect(() => {
const messages = stateToMessagePath(state, path);
const messages = stateToMessagePath(state, path, true);
setMessages(messages);
if (messages.length) {
setIsInitializing(false);
Expand Down