Skip to content

Refactor AI assistant dialogue and inspection process#59

Merged
cmjang merged 6 commits intoOpenLegged:devfrom
kleinlau17:dev
Apr 7, 2026
Merged

Refactor AI assistant dialogue and inspection process#59
cmjang merged 6 commits intoOpenLegged:devfrom
kleinlau17:dev

Conversation

@kleinlau17
Copy link
Copy Markdown
Contributor

No description provided.

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request refactors the AI assistant by splitting the monolithic AI modal into specialized Inspection and Conversation components, adding support for Markdown rendering via react-markdown and remark-gfm. Key updates include enhancing the robot and selection stores to preserve inspection context and improve camera focusing. Review feedback identifies redundant token usage from passing conversation history in both the system prompt and message array, and notes that Node.js-specific .unref() calls on timers will fail in a browser environment.

Comment on lines +257 to +261
const systemPrompt = getConversationSystemPrompt(lang, {
mode,
context,
history: serializeConversationHistory(history),
})
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The conversation history is being passed redundantly to the AI model. It is currently serialized into the system prompt via getConversationSystemPrompt and also provided as a sequence of messages in the messages array. This redundancy increases token consumption and can occasionally lead to conflicting instructions if the model prioritizes one source over the other. It is recommended to remove the history from the system prompt and rely solely on the messages array for context.

if (pendingRefocusTimeout !== null) {
clearTimeout(pendingRefocusTimeout);
pendingRefocusTimeout = null;
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The .unref() method is specific to Node.js timers and is not available on browser setTimeout return values. This should be removed.

Suggested change
}
if (pendingRefocusTimeout !== null) {
clearTimeout(pendingRefocusTimeout);
pendingRefocusTimeout = null;
}

set({ focusTarget: id });
scheduleFocusReset();
}, 0);
pendingRefocusTimeout.unref?.();
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The .unref() method is specific to Node.js timers and is not available on browser setTimeout return values. This should be removed.

        pendingRefocusTimeout = setTimeout(() => {
          pendingRefocusTimeout = null;
          set({ focusTarget: id });
          scheduleFocusReset();
        }, 0);

@cmjang cmjang merged commit 981c671 into OpenLegged:dev Apr 7, 2026
1 check failed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants