LLM Agent for <perspective-viewer> - #3209
Merged
Merged
Conversation
Signed-off-by: Andrew Stein <steinlink@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR adds a first-party LLM agent to
<perspective-viewer>: a chat sidebar tab and a JavaScript API that let a model drive the viewer through its own public API: reading the schema, writing theViewerConfig, choosing a plugin, authoring ExprTK expressions and managing panels.The feature is opt-in at runtime. The Chat tab stays hidden and no network request is ever made until the host calls
agentConfig().Added
Element API
agentConfig(config),agentPrompt(text)(resolves with the final answer once tool calls have been applied), andagentReset(). Tool activity firesperspective-agent-toolCustomEvents.Chat sidebar tab Streams tokens (with automatic fallback), streams reasoning-model
reasoning_contentinto a collapsible display-only block that follows its own tail, renders assistant markdown, and shows tool calls.OpenAI compatible A "provider" is a plain spreadable
Object;src/ts/providers.tsships presets foranthropic,gemini,openai,openrouter,lmstudioandollama, and anything OpenAI-compatible works without one.engineaccepts an in-page engine (WebLLM'sMLCEngine), so the agent can run entirely on-device or be proxied to a private model.Documentation bundle — the build emits
dist/docs/perspective-docs.json(~300 KB) containing a BM25-searchable corpus built fromdocs/mdplus authored plugin-config reference files, and generated JSON schemas forViewerConfigUpdate/ViewerConfigInitial. Passing it asdocspowers thesearch_docstool and upgrades the config tools' parameter schemas from permissive objects to the real generated ones. Hosts can append their own{title, text}entries to teach the agent additional context about the data itself, or override/audit the documentation bundle entirely.Docs and New Examples
docs/md/how_to/javascript/agent.md— new guide covering connection, in-page engines, the docs bundle, teaching the agent about your data.viewer.md,events.md,save_restore.md,expressions.md,advanced.md,schema.md,FAQ.mdand a newwindows.md- these are both user-facing improvements and the agent's retrieval corpus, so gaps in them are gaps in the agent.examples/blocks/src/agent/— a runnable demo with a provider modal (OpenAI-compatible, Anthropic, Gemini, WebLLM), dataset-specific corpus entries, and notes on the WebLLM caveats (Hermes-only tool calling).