-
Notifications
You must be signed in to change notification settings - Fork 12
feat(agent): OpenUI bindings — library/fragment builders, toUIOutput, getUiStream() (DEV-773) #92
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
Open
LukasParke
wants to merge
23
commits into
main
Choose a base branch
from
lukeparke/dev-773-typescript-agent-openui-module-libraryfragment-builders
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
383c282
feat(agent): OpenUI library model, fragment builder, and plugin helpe…
LukasParke a3347b5
feat(agent): toUIOutput on tool(), tool.ui_fragment events, and getUi…
LukasParke 978cab9
feat(playground): OpenUI test/bench/eval webapp (DEV-773)
LukasParke 69bfb14
fix(openui): quote non-identifier object keys, guard non-finite numbers
LukasParke 3720fde
refactor: clear the structural gate — god file and 4 complex functions
LukasParke e5759d3
docs(agent): list getUiStream in the README stream table
LukasParke 4eb82c7
Merge remote-tracking branch 'origin/main' into lukeparke/dev-773-typ…
LukasParke b388f35
fix(playground): escape diagnostic messages; label rendered controls
LukasParke 37f816d
fix(openui): address cortex review — security, a11y, perf
LukasParke 6898806
Merge branch 'lukeparke/dev-773-typescript-agent-openui-module-librar…
LukasParke 20ab446
Merge branch 'main' into lukeparke/dev-773-typescript-agent-openui-mo…
synapse-github-agent[bot] 20c0e5c
Merge remote-tracking branch 'origin/main' into wt/pr92
LukasParke 3d4a582
fix(openui): address review findings
LukasParke 3cefbdc
refactor(openui): simplify native diagnostics counting
LukasParke 829a94c
fix(agent): bound OpenUI fragment rendering
LukasParke 6701156
fix(openui): finish review feedback
LukasParke ff70982
fix(openui): release timed-out UI renders
LukasParke e956e1e
fix(openui): drain renders added before close
LukasParke 0f7eb50
fix(agent): drain UI fragments before stream completion
LukasParke bccd1ad
fix(agent): isolate UI stream lifecycle
LukasParke cbfd884
fix(agent): release exited UI consumers
LukasParke 1f68c5e
fix(agent): merge OpenUI event streams
LukasParke 11eac75
fix(agent): render deferred tool UI results
LukasParke File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| --- | ||
| '@openrouter/agent': minor | ||
| --- | ||
|
|
||
| OpenUI bindings: a component-library model (`defineComponent`, `createLibrary`, `componentProps`), a typed fragment builder (`fragment`, `uiRef`, `uiState`, `uiBuiltin`), the `openui` plugin helper, `serializeExpr`/`OPENUI_LANG_DIALECT` for emitting OpenUI Lang, a `toUiOutput` tool option that renders a tool's result as UI, and `ModelResult.getUiStream()` for consuming fragments as they arrive. | ||
|
|
||
| A tool declares how its output renders, and the caller streams the fragments: | ||
|
|
||
| ```ts | ||
| import { | ||
| callModel, | ||
| createLibrary, | ||
| defineComponent, | ||
| fragment, | ||
| openui, | ||
| tool, | ||
| } from '@openrouter/agent'; | ||
| import { z } from 'zod/v4'; | ||
|
|
||
| const library = createLibrary([ | ||
| defineComponent({ | ||
| name: 'Card', | ||
| description: 'Container with a title', | ||
| props: z.object({ | ||
| title: z.string(), | ||
| children: z.array(z.unknown()).optional(), | ||
| }), | ||
| }), | ||
| defineComponent({ | ||
| name: 'Text', | ||
| props: z.object({ | ||
| value: z.string(), | ||
| }), | ||
| }), | ||
| ]); | ||
|
|
||
| const ui = fragment(library); | ||
|
|
||
| const weather = tool({ | ||
| name: 'weather', | ||
| inputSchema: z.object({ | ||
| city: z.string(), | ||
| }), | ||
| outputSchema: z.object({ | ||
| summary: z.string(), | ||
| }), | ||
| execute: ({ city }) => ({ | ||
| summary: `Clear in ${city}`, | ||
| }), | ||
| // Renders the tool's result instead of leaving the model to describe it. | ||
| toUiOutput: ({ input, output }) => | ||
| ui.Card(input.city, [ | ||
| ui.Text(output.summary), | ||
| ]), | ||
| }); | ||
|
|
||
| const result = callModel(client, { | ||
| model: 'anthropic/claude-sonnet-4.5', | ||
| input: 'What is the weather in Lisbon?', | ||
| tools: [ | ||
| weather, | ||
| ], | ||
| plugins: [ | ||
| openui(library), | ||
| ], | ||
| }); | ||
|
|
||
| for await (const event of result.getUiStream()) { | ||
| if (event.type === 'fragment') { | ||
| // source: 'root = Card("Lisbon", [Text("Clear in Lisbon")])' | ||
| console.log(event.source); | ||
| } | ||
| } | ||
| ``` |
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
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
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
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
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.