Skip to content

Issue 24/annotations#39

Merged
charlesLoder merged 7 commits intomainfrom
issue-24/annotations
Sep 8, 2025
Merged

Issue 24/annotations#39
charlesLoder merged 7 commits intomainfrom
issue-24/annotations

Conversation

@charlesLoder
Copy link
Owner

Closes #24 by adding annotations into the user message as context

@charlesLoder charlesLoder requested a review from Copilot September 8, 2025 19:03
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR adds context annotations to user messages by extracting annotation data from IIIF Canvas objects and including it as contextual information in chat interactions.

Key changes:

  • Enhanced message formatting to include Canvas annotation context when the Canvas changes
  • Refactored BaseProvider to support system prompt generation and plugin state management
  • Updated message structure to include Canvas context information

Reviewed Changes

Copilot reviewed 6 out of 8 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
src/providers/userTokenProvider/index.tsx Added annotation extraction logic and context injection into user messages
src/plugin/context/index.ts Updated exports to include PluginContextStore type
src/plugin/base_provider.tsx Added plugin state management and system prompt generation methods
src/plugin/Panel/index.tsx Refactored to use BaseProvider's system prompt generation
src/plugin/Panel/ChatInput/index.tsx Added Canvas context to message structure
package.json Added dedent dependency for template string formatting

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

* Use an arrow function so `this` references the `UserTokenProvider` class
*/
#format_message(message: Message) {
#format_message = (message: Message, index: number, messages: Message[]): CoreMessage => {
Copy link

Copilot AI Sep 8, 2025

Choose a reason for hiding this comment

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

The method signature has changed from a private method to an arrow function property with additional parameters. This is a breaking change that affects the method's binding and parameters. Consider maintaining backward compatibility or documenting this breaking change.

Suggested change
#format_message = (message: Message, index: number, messages: Message[]): CoreMessage => {
// Backward compatibility: provide previous method signature as a private method
#format_message(message: Message): CoreMessage {
// Call the new arrow function with default values for index and messages
return this.#format_message_arrow(message, 0, []);
}
// New implementation with additional parameters
#format_message_arrow = (message: Message, index: number, messages: Message[]): CoreMessage => {

Copilot uses AI. Check for mistakes.
Comment on lines +66 to +67
const prevMessages = messages.slice(0, index);
const lastUserMessage = prevMessages.findLast((m) => m.role === "user");
Copy link

Copilot AI Sep 8, 2025

Choose a reason for hiding this comment

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

The prevMessages.slice(0, index) operation creates a new array for every message being processed, and findLast searches through all previous messages. This results in O(n²) complexity when processing multiple messages. Consider caching the last user message or restructuring to avoid repeated array operations.

Copilot uses AI. Check for mistakes.
Comment on lines +75 to +81
const canvas = this.plugin_state.vault.serialize<Canvas>(
{
type: "Canvas",
id: message.context.canvas.id,
},
serializeConfigPresentation3,
);
Copy link

Copilot AI Sep 8, 2025

Choose a reason for hiding this comment

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

Canvas serialization is performed for every user message when the Canvas changes. This could be expensive for large Canvas objects. Consider caching the serialized Canvas or extracting annotations separately to avoid full serialization overhead.

Copilot uses AI. Check for mistakes.
Comment on lines 70 to 71
Copy link

Copilot AI Sep 8, 2025

Choose a reason for hiding this comment

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

Potential array access error if getLabelByUserLanguage() returns an empty array. The [0] access will return undefined, but the fallback ?? "N/A" won't trigger since undefined is not nullish in this context when chained with optional chaining.

Suggested change
## Title: ${getLabelByUserLanguage(manifest.label ?? undefined)[0] ?? "N/A"}
## Summary: ${manifest.summary ? getLabelByUserLanguage(manifest.summary)[0] : "N/A"}
## Title: ${getLabelByUserLanguage(manifest.label ?? undefined)?.[0] ?? "N/A"}
## Summary: ${manifest.summary ? getLabelByUserLanguage(manifest.summary)?.[0] ?? "N/A" : "N/A"}

Copilot uses AI. Check for mistakes.
@charlesLoder charlesLoder merged commit 7cb1843 into main Sep 8, 2025
3 checks passed
@charlesLoder charlesLoder deleted the issue-24/annotations branch September 8, 2025 19:50
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.

Add support for annotations

1 participant

Comments