@manet/agent-ui-builder
v0.0.4
Published
Agent UI builder for generating replay HTML files
Downloads
12
Readme
@manet/agent-ui-builder
Simple and clean agent UI builder for generating replay HTML files from agent session data.
Features
- Simple API: Just two methods -
dump()andupload() - Type Safety: Strict TypeScript interfaces
- Built-in Static Files: Includes pre-built agent UI static files
- Smart Path Resolution: Automatic static path detection with fallbacks
- Share Provider Support: Built-in upload functionality for sharing
- Isomorphic Design: Prepared for Python SDK compatibility
Installation
pnpm add @manet/agent-ui-builderUsage
Basic Usage
import { AgentUIBuilder } from '@manet/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);Save to File
import { AgentUIBuilder } from '@manet/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);Upload to Share Provider
import { AgentUIBuilder } from '@manet/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);Combined Workflow
import { AgentUIBuilder } from '@manet/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);API Reference
AgentUIBuilder
Constructor
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 Configuration
Methods
dump(filePath?: string): string
Generates HTML from session data and optionally saves to file.
Parameters:
filePath?: Optional file path to save HTML
Returns: 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 optionsslug?: Custom slug for the share URLquery?: Original user query for metadata
Returns: 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?',
});Types
AgentUIBuilderInputOptions
interface AgentUIBuilderInputOptions {
events: AgentEventStream.Event[];
sessionInfo: SessionInfo;
serverInfo?: AgentServerVersionInfo;
uiConfig?: AgentWebUIImplementation;
}UploadOptions
interface UploadOptions {
slug?: string; // Custom slug for the share URL
query?: string; // Original user query for metadata
}Design Philosophy
This package follows a simple and clean design:
Two Core Methods:
dump()for generating (and optionally saving) HTMLupload()for sharing HTML content
No 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
Python SDK Compatibility
This package is designed with isomorphic principles to enable a Python SDK with identical interfaces:
# Future Python SDK (same API design)
from manet_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'
})License
Apache-2.0
