multimodal/tarko/agent-ui-cli/README.md
CLI for Agent UI Builder - generate and share agent replay HTML files from trace data.
npm install @tarko/agent-ui-cli
The agui CLI supports the following options:
--out <path> - Output file path for the generated HTML--transformer <path> - Path to transformer file (TypeScript or JavaScript)--config <path> - Path to config file--upload <url> - Upload URL for sharing (generates and uploads HTML)--dump-transformed - Dump transformed JSON to file (requires --transformer)# Generate HTML from JSON trace
agui ./trace.json
# Generate HTML from JSONL trace (auto-detected format)
agui ./trace.jsonl
# Specify output path
agui ./trace.json --out ./agent-ui.html
# Use custom config (agui.config.ts will be auto-detected)
agui ./trace.json
# Specify config explicitly
agui ./trace.json --config ./agui.config.ts
# Convert custom format using transformer
agui ./custom-format.json --transformer ./transformer.ts
# With both transformer and config
agui ./custom-format.json --transformer ./transformer.ts --config ./agui.config.ts
# Debug transformer output by saving transformed JSON
agui ./custom-format.json --transformer ./transformer.ts --dump-transformed
# Upload to sharing service
agui ./trace.json --upload http://share.example.com
# Upload with transformer
agui ./custom-format.json --transformer ./transformer.ts --upload http://share.example.com
# Full example with all options
agui ./custom-format.json \
--transformer ./transformer.ts \
--config ./agui.config.ts \
--out ./agent-demo.html \
--dump-transformed
Standard JSON files with an events array containing AgentEventStream.Event[]:
{
"events": [
{
"id": "event-1",
"type": "user_message",
"timestamp": 1640995200000,
"content": "Hello"
},
{
"id": "event-2",
"type": "assistant_message",
"timestamp": 1640995201000,
"content": "Hi there!"
}
]
}
JSON Lines format where each line is a separate event (auto-detected by .jsonl extension):
{"id": "event-1", "type": "user_message", "timestamp": 1640995200000, "content": "Hello"}
{"id": "event-2", "type": "assistant_message", "timestamp": 1640995201000, "content": "Hi there!"}
Any format can be supported using transformers that convert to AgentEventStream.Event[].
All commands will generate HTML files that can be opened in a browser to view the agent execution replay with:
When using --dump-transformed, a JSON file will be created alongside the HTML:
custom-format.json → Output: custom-format-transformed.jsontrace.jsonl → Output: trace-transformed.jsonAgentEventStream.Event[] formatTransformers convert custom trace formats to the standard AgentEventStream.Event[] format. The CLI supports both TypeScript (.ts) and JavaScript (.js) transformer files.
import { AgentEventStream } from '@tarko/interface';
import { defineTransformer } from '@tarko/agent-ui-cli';
interface CustomLogEntry {
type: 'user_input' | 'tool_execution' | 'agent_response';
timestamp: string;
message?: string;
tool_name?: string;
parameters?: Record<string, any>;
result?: Record<string, any>;
}
interface CustomLogFormat {
logs: CustomLogEntry[];
}
export default defineTransformer<CustomLogFormat>((input) => {
const events: AgentEventStream.Event[] = [];
let eventIdCounter = 1;
for (const log of input.logs) {
const timestamp = new Date(log.timestamp).getTime();
if (log.type === 'user_input') {
events.push({
id: `event-${eventIdCounter++}`,
type: 'user_message',
timestamp,
content: log.message || '',
} as AgentEventStream.UserMessageEvent);
}
// Add more event type conversions...
}
return { events };
});
For proper UI rendering, ensure these requirements are met:
toolCall.id must match toolResult.toolCallId"tool_calls" when assistant makes tool callsconst toolCallId = `tool-call-${eventIdCounter++}`;
// Tool call event
events.push({
id: `event-${eventIdCounter++}`,
type: 'tool_call',
timestamp,
toolCallId,
name: toolName,
arguments: parameters,
// ... other fields
});
// Tool result event
events.push({
id: `event-${eventIdCounter++}`,
type: 'tool_result',
timestamp: timestamp + 100,
toolCallId, // Same ID as tool call
name: toolName,
content: result,
// ... other fields
});
// Assistant message with tool calls
events.push({
id: `event-${eventIdCounter++}`,
type: 'assistant_message',
timestamp,
content: message,
finishReason: 'tool_calls', // Important for UI rendering
// ... other fields
});
Use defineTransformer for better TypeScript support and IntelliSense:
import { defineTransformer } from '@tarko/agent-ui-cli';
// Type-safe transformer with custom input type
export default defineTransformer<YourCustomFormat>((input) => {
// Transform logic here
return { events };
});
The CLI automatically detects config files: agui.config.{ts,js,json} or you can specify with --config.
Use defineConfig for better TypeScript support and IntelliSense. All configuration properties support deep partial types, so you only need to specify the fields you want to override:
import { defineConfig } from '@tarko/agent-ui-cli';
export default defineConfig({
sessionInfo: {
metadata: {
name: 'My Custom Agent',
// Only specify the fields you want to override
modelConfig: {
provider: 'openai', // Other fields will use defaults
},
},
},
uiConfig: {
title: 'My Agent UI',
logo: 'https://example.com/logo.png',
guiAgent: {
renderGUIAction: false, // Partial nested configuration
},
},
});
export default {
sessionInfo: {
id: 'sessionId',
createdAt: Date.now(),
updatedAt: Date.now(),
workspace: '~/workspace',
metadata: {
name: 'Session Name',
tags: [],
modelConfig: {
provider: 'volcengine',
modelId: 'model-id',
displayName: 'Model Name',
configuredAt: Date.now(),
},
agentInfo: {
name: 'Agent Name',
configuredAt: Date.now(),
},
},
},
serverInfo: {
version: '1.0.0',
buildTime: Date.now(),
gitHash: '1234567',
},
uiConfig: {
logo: 'https://example.com/logo.png',
title: 'Agent UI',
subtitle: 'Agent execution replay',
welcomTitle: 'Welcome',
guiAgent: {
defaultScreenshotRenderStrategy: 'afterAction',
enableScreenshotRenderStrategySwitch: true,
renderGUIAction: true,
renderBrowserShell: false,
},
},
};
The --dump-transformed flag is invaluable for debugging transformer logic:
# Debug your transformer output
agui custom-format.json --transformer transformer.ts --dump-transformed
# This creates custom-format-transformed.json with the standardized events
# Compare this with your expected output to debug transformation issues
Tool calls show as "executing" forever
toolCall.id matches toolResult.toolCallIdfinishReason: 'tool_calls' when assistant makes tool callsJSONL files not loading
.jsonl extension for auto-detectionTransformer not found
TypeScript transformer compilation errors
jiti to load TypeScript files automatically.ts files manuallyThe CLI automatically validates that transformed data contains:
events arrayAgentEventStream.Event[] structureUse --dump-transformed to inspect the final event structure before HTML generation.
See the examples/ directory for complete working examples:
examples/basic-json/ - Standard JSON format processingexamples/jsonl-format/ - JSONL format with auto-detectionexamples/custom-transformer/ - Custom formats with transformersEach example includes:
run.sh script# Run any example with one command
cd examples/basic-json && ./run.sh
cd examples/jsonl-format && ./run.sh
cd examples/custom-transformer && ./run.sh
For detailed documentation, see examples/README.md.