multimodal/tarko/agent-ui-builder/README.md
Simple and clean agent UI builder for generating replay HTML files from agent session data.
dump() and upload()pnpm add @tarko/agent-ui-builder
import { AgentUIBuilder } from '@tarko/agent-ui-builder';
const builder = new AgentUIBuilder({
events: sessionEvents,
sessionInfo: sessionMetadata,
// staticPath is optional - will use built-in static files if not provided
serverInfo: versionInfo,
uiConfig: uiConfig,
});
// Generate HTML in memory
const html = await builder.dump();
console.log('Generated HTML:', html);
import { AgentUIBuilder } from '@tarko/agent-ui-builder';
const builder = new AgentUIBuilder({
events: sessionEvents,
sessionInfo: sessionMetadata,
});
// Generate HTML and save to file
const html = await builder.dump('/path/to/output/replay.html');
console.log('HTML saved to file and returned:', html);
import { AgentUIBuilder } from '@tarko/agent-ui-builder';
const builder = new AgentUIBuilder({
events: sessionEvents,
sessionInfo: sessionMetadata,
});
// Generate HTML
const html = await builder.dump();
// Upload to share provider
const shareUrl = await builder.upload(html, 'https://share-provider.example.com/upload', {
slug: 'my-session',
query: 'original user query',
});
console.log('Share URL:', shareUrl);
import { AgentUIBuilder } from '@tarko/agent-ui-builder';
const builder = new AgentUIBuilder({
events: sessionEvents,
sessionInfo: sessionMetadata,
});
// Generate and save HTML
const html = await builder.dump('/local/backup/replay.html');
// Upload the same HTML for sharing
const shareUrl = await builder.upload(html, shareProviderUrl, {
slug: 'user-session-backup',
query: 'How to build a web app?',
});
console.log('Local file saved and share URL:', shareUrl);
new AgentUIBuilder(input: AgentUIBuilderInputOptions)
Parameters:
input.events: Array of agent eventsinput.sessionInfo: Session metadatainput.staticPath?: Optional path to static web UI filesinput.serverInfo?: Optional server version infoinput.uiConfig?: Optional Agent UI Configurationdump(filePath?: string): stringGenerates HTML from session data and optionally saves to file.
Parameters:
filePath?: Optional file path to save HTMLReturns: Generated HTML string
Example:
// Generate HTML only
const html = await builder.dump();
// Generate HTML and save to file
const html = await builder.dump('/path/to/file.html');
upload(html: string, shareProviderUrl: string, options?: UploadOptions): Promise<string>Uploads HTML to a share provider and returns the share URL.
Parameters:
html: HTML content to uploadshareProviderUrl: URL of the share provider endpointoptions?: Upload options
slug?: Custom slug for the share URLquery?: Original user query for metadataReturns: Promise resolving to share URL with replay parameter
Example:
const shareUrl = await builder.upload(html, 'https://api.example.com/share', {
slug: 'my-session',
query: 'How to use the API?',
});
AgentUIBuilderInputOptionsinterface AgentUIBuilderInputOptions {
events: AgentEventStream.Event[];
sessionInfo: SessionInfo;
serverInfo?: AgentServerVersionInfo;
uiConfig?: AgentWebUIImplementation;
}
UploadOptionsinterface UploadOptions {
slug?: string; // Custom slug for the share URL
query?: string; // Original user query for metadata
}
This package follows a simple and clean design:
Two Core Methods:
dump() for generating (and optionally saving) HTMLupload() for sharing HTML contentNo Complex Configurations: Simple parameters, clear responsibilities
Flexible Workflow: Generate once, use multiple times (save locally + upload for sharing)
Type Safety: Full TypeScript support with clear interfaces
This package is designed with isomorphic principles to enable a Python SDK with identical interfaces:
# Future Python SDK (same API design)
from tarko_agent_ui_builder import AgentUIBuilder
builder = AgentUIBuilder({
'events': session_events,
'session_info': session_metadata,
'static_path': '/path/to/web-ui/static',
})
# Generate HTML
html = builder.dump()
# Save to file
html = builder.dump('/path/to/file.html')
# Upload for sharing
share_url = builder.upload(html, provider_url, {
'slug': 'my-session',
'query': 'user query'
})
Apache-2.0