-
Notifications
You must be signed in to change notification settings - Fork 0
Issue 24/annotations #39
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
Changes from 6 commits
e3ec54e
2ba0792
286a757
ba512cc
09d4233
d588255
08fca7f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,8 @@ | ||
| // using a barrel file helps tsc-alias resolve the path correctly | ||
| import type { PluginContextActions } from "./plugin-context"; | ||
| import { PluginContextProvider, usePlugin } from "./plugin-context"; | ||
|
|
||
| export { PluginContextProvider, usePlugin }; | ||
| export type { PluginContextActions }; | ||
| export { | ||
| PluginContextProvider, | ||
| usePlugin, | ||
| type PluginContextActions, | ||
| type PluginContextStore, | ||
| } from "./plugin-context"; |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -2,9 +2,13 @@ import { createAnthropic, type AnthropicProvider } from "@ai-sdk/anthropic"; | |||||||||||||||||||
| import { createGoogleGenerativeAI, type google } from "@ai-sdk/google"; | ||||||||||||||||||||
| import { createOpenAI, type OpenAIProvider } from "@ai-sdk/openai"; | ||||||||||||||||||||
| import { Button, Heading, Input } from "@components"; | ||||||||||||||||||||
| import { serializeConfigPresentation3, Traverse } from "@iiif/parser"; | ||||||||||||||||||||
| import type { Canvas } from "@iiif/presentation-3"; | ||||||||||||||||||||
| import { Tool } from "@langchain/core/tools"; | ||||||||||||||||||||
| import type { AssistantMessage, Message } from "@types"; | ||||||||||||||||||||
| import { streamText, tool } from "ai"; | ||||||||||||||||||||
| import { getLabelByUserLanguage } from "@utils"; | ||||||||||||||||||||
| import { CoreMessage, streamText, tool } from "ai"; | ||||||||||||||||||||
| import dedent from "dedent"; | ||||||||||||||||||||
| import React from "react"; | ||||||||||||||||||||
| import { BaseProvider } from "../../plugin/base_provider"; | ||||||||||||||||||||
| import { ModelSelection } from "./components/ModelSelection"; | ||||||||||||||||||||
|
|
@@ -44,8 +48,12 @@ export class UserTokenProvider extends BaseProvider { | |||||||||||||||||||
| * | ||||||||||||||||||||
| * @param message | ||||||||||||||||||||
| * @returns a formatted message | ||||||||||||||||||||
| * | ||||||||||||||||||||
| * @privateRemarks | ||||||||||||||||||||
| * | ||||||||||||||||||||
| * Use an arrow function so `this` references the `UserTokenProvider` class | ||||||||||||||||||||
| */ | ||||||||||||||||||||
| #format_message(message: Message) { | ||||||||||||||||||||
| #format_message = (message: Message, index: number, messages: Message[]): CoreMessage => { | ||||||||||||||||||||
|
||||||||||||||||||||
| #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
AI
Sep 8, 2025
There was a problem hiding this comment.
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
AI
Sep 8, 2025
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 returnundefined, but the fallback?? "N/A"won't trigger sinceundefinedis not nullish in this context when chained with optional chaining.