[Init] Initial commit - NetMesh terminal manager
Some checks failed
build-packages / resolve bundled mosh-client (push) Has been cancelled
build-packages / resolve bundled et-client (push) Has been cancelled
build-packages / build-macos (push) Has been cancelled
build-packages / build-windows (push) Has been cancelled
build-packages / build-linux-x64 (push) Has been cancelled
build-packages / build-linux-arm64 (push) Has been cancelled
build-packages / release (push) Has been cancelled
build-packages / update Nix release metadata (push) Has been cancelled
build-packages / bump homebrew tap (push) Has been cancelled
test / lint-and-test (push) Has been cancelled
AI automation / Route event (push) Has been cancelled
AI automation / Hand reopened issue to maintainers (push) Has been cancelled
AI automation / Clean source issue state (push) Has been cancelled
AI automation / Reconcile handoffs (push) Has been cancelled
AI automation / Classify issue (push) Has been cancelled
AI automation / Claude Code smoke (push) Has been cancelled
AI automation / Review issue follow-up (push) Has been cancelled
AI automation / Publish issue follow-up (push) Has been cancelled
AI automation / Implement with Claude Code (push) Has been cancelled
AI automation / Publish implement PR (push) Has been cancelled
AI automation / Continue queued issue comments (push) Has been cancelled
AI automation / Codex review loop (push) Has been cancelled
AI automation / Publish Codex fix (push) Has been cancelled
AI automation / Clear Codex dispatch marker (push) Has been cancelled
AI automation / Own PR re-request Codex (push) Has been cancelled
AI automation / External PR re-request Codex (push) Has been cancelled
AI automation / Poll Codex reaction / retry (push) Has been cancelled
build-et-binaries / build-linux-x64 (push) Has been cancelled
build-et-binaries / build-linux-arm64 (push) Has been cancelled
build-et-binaries / build-macos-universal (push) Has been cancelled
build-et-binaries / build-windows-x64 (push) Has been cancelled
build-et-binaries / release (push) Has been cancelled
Some checks failed
build-packages / resolve bundled mosh-client (push) Has been cancelled
build-packages / resolve bundled et-client (push) Has been cancelled
build-packages / build-macos (push) Has been cancelled
build-packages / build-windows (push) Has been cancelled
build-packages / build-linux-x64 (push) Has been cancelled
build-packages / build-linux-arm64 (push) Has been cancelled
build-packages / release (push) Has been cancelled
build-packages / update Nix release metadata (push) Has been cancelled
build-packages / bump homebrew tap (push) Has been cancelled
test / lint-and-test (push) Has been cancelled
AI automation / Route event (push) Has been cancelled
AI automation / Hand reopened issue to maintainers (push) Has been cancelled
AI automation / Clean source issue state (push) Has been cancelled
AI automation / Reconcile handoffs (push) Has been cancelled
AI automation / Classify issue (push) Has been cancelled
AI automation / Claude Code smoke (push) Has been cancelled
AI automation / Review issue follow-up (push) Has been cancelled
AI automation / Publish issue follow-up (push) Has been cancelled
AI automation / Implement with Claude Code (push) Has been cancelled
AI automation / Publish implement PR (push) Has been cancelled
AI automation / Continue queued issue comments (push) Has been cancelled
AI automation / Codex review loop (push) Has been cancelled
AI automation / Publish Codex fix (push) Has been cancelled
AI automation / Clear Codex dispatch marker (push) Has been cancelled
AI automation / Own PR re-request Codex (push) Has been cancelled
AI automation / External PR re-request Codex (push) Has been cancelled
AI automation / Poll Codex reaction / retry (push) Has been cancelled
build-et-binaries / build-linux-x64 (push) Has been cancelled
build-et-binaries / build-linux-arm64 (push) Has been cancelled
build-et-binaries / build-macos-universal (push) Has been cancelled
build-et-binaries / build-windows-x64 (push) Has been cancelled
build-et-binaries / release (push) Has been cancelled
This commit is contained in:
125
infrastructure/ai/conversationExport.ts
Normal file
125
infrastructure/ai/conversationExport.ts
Normal file
@@ -0,0 +1,125 @@
|
||||
import type { AISession } from './types';
|
||||
|
||||
/**
|
||||
* Export a session as Markdown
|
||||
*/
|
||||
export function exportAsMarkdown(session: AISession): string {
|
||||
const lines: string[] = [];
|
||||
|
||||
lines.push(`# ${session.title || 'Untitled Chat'}`);
|
||||
lines.push('');
|
||||
lines.push(`- **Agent:** ${session.agentId}`);
|
||||
lines.push(`- **Scope:** ${session.scope.type}${session.scope.targetId ? ` (${session.scope.targetId})` : ''}`);
|
||||
lines.push(`- **Created:** ${new Date(session.createdAt).toLocaleString()}`);
|
||||
lines.push(`- **Updated:** ${new Date(session.updatedAt).toLocaleString()}`);
|
||||
lines.push('');
|
||||
lines.push('---');
|
||||
lines.push('');
|
||||
|
||||
for (const msg of session.messages) {
|
||||
if (msg.role === 'system') continue;
|
||||
|
||||
const time = new Date(msg.timestamp).toLocaleTimeString();
|
||||
|
||||
if (msg.role === 'user') {
|
||||
lines.push(`## User [${time}]`);
|
||||
lines.push('');
|
||||
lines.push(msg.content);
|
||||
lines.push('');
|
||||
} else if (msg.role === 'assistant') {
|
||||
lines.push(`## Assistant [${time}]${msg.model ? ` (${msg.model})` : ''}`);
|
||||
lines.push('');
|
||||
lines.push(msg.content);
|
||||
|
||||
if (msg.toolCalls?.length) {
|
||||
lines.push('');
|
||||
for (const tc of msg.toolCalls) {
|
||||
lines.push(`### Tool Call: \`${tc.name}\``);
|
||||
lines.push('');
|
||||
lines.push('```json');
|
||||
lines.push(JSON.stringify(tc.arguments, null, 2));
|
||||
lines.push('```');
|
||||
lines.push('');
|
||||
}
|
||||
}
|
||||
lines.push('');
|
||||
} else if (msg.role === 'tool') {
|
||||
if (msg.toolResults?.length) {
|
||||
for (const tr of msg.toolResults) {
|
||||
lines.push(`### Tool Result${tr.isError ? ' (Error)' : ''}`);
|
||||
lines.push('');
|
||||
lines.push('```');
|
||||
lines.push(tr.content);
|
||||
lines.push('```');
|
||||
lines.push('');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return lines.join('\n');
|
||||
}
|
||||
|
||||
/**
|
||||
* Export a session as JSON
|
||||
*/
|
||||
export function exportAsJSON(session: AISession): string {
|
||||
return JSON.stringify(session, null, 2);
|
||||
}
|
||||
|
||||
/**
|
||||
* Export a session as plain text
|
||||
*/
|
||||
export function exportAsPlainText(session: AISession): string {
|
||||
const lines: string[] = [];
|
||||
|
||||
lines.push(`Chat: ${session.title || 'Untitled'}`);
|
||||
lines.push(`Date: ${new Date(session.createdAt).toLocaleString()}`);
|
||||
lines.push('='.repeat(60));
|
||||
lines.push('');
|
||||
|
||||
for (const msg of session.messages) {
|
||||
if (msg.role === 'system') continue;
|
||||
|
||||
const time = new Date(msg.timestamp).toLocaleTimeString();
|
||||
|
||||
if (msg.role === 'user') {
|
||||
lines.push(`[${time}] You:`);
|
||||
lines.push(msg.content);
|
||||
lines.push('');
|
||||
} else if (msg.role === 'assistant') {
|
||||
lines.push(`[${time}] Assistant:`);
|
||||
lines.push(msg.content);
|
||||
|
||||
if (msg.toolCalls?.length) {
|
||||
for (const tc of msg.toolCalls) {
|
||||
lines.push(` > Tool: ${tc.name}(${JSON.stringify(tc.arguments)})`);
|
||||
}
|
||||
}
|
||||
lines.push('');
|
||||
} else if (msg.role === 'tool') {
|
||||
if (msg.toolResults?.length) {
|
||||
for (const tr of msg.toolResults) {
|
||||
lines.push(` > Result${tr.isError ? ' [ERROR]' : ''}:`);
|
||||
lines.push(` ${tr.content}`);
|
||||
}
|
||||
lines.push('');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return lines.join('\n');
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate a suggested filename for export
|
||||
*/
|
||||
export function getExportFilename(session: AISession, format: 'md' | 'json' | 'txt'): string {
|
||||
const title = (session.title || 'chat')
|
||||
.toLowerCase()
|
||||
.replace(/[^a-z0-9]+/g, '-')
|
||||
.replace(/^-|-$/g, '')
|
||||
.slice(0, 40);
|
||||
const date = new Date(session.createdAt).toISOString().slice(0, 10);
|
||||
return `netcatty-${title}-${date}.${format}`;
|
||||
}
|
||||
Reference in New Issue
Block a user