Skip to content

Commit 6e31fab

Browse files
Merge pull request #163 from vamplabAI/frontend-hotfix
Missed libraries restored
2 parents b021665 + 387d8e3 commit 6e31fab

File tree

4 files changed

+145
-0
lines changed

4 files changed

+145
-0
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
export const MODEL_TYPES = [
2+
{ name: 'sgr_agent', value: 'sgr_agent', id: 1 },
3+
{ name: 'sgr_auto_tool_calling_agent', value: 'sgr_auto_tool_calling_agent', id: 2 },
4+
]
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// Shared lib exports
2+
export * from './constants/agents'
3+
export * from './utils/id'
4+
export * from './utils/formatMessage'
Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
import type { ChatMessageExtended } from '@/shared/types/store'
2+
3+
/**
4+
* Formats message to markdown format for copying
5+
*/
6+
export function formatMessageToMarkdown(message: ChatMessageExtended): string {
7+
const lines: string[] = []
8+
9+
// Message header
10+
if (message.role === 'user') {
11+
lines.push('## 👤 User\n')
12+
} else if (message.role === 'assistant') {
13+
lines.push('## 🤖 Assistant\n')
14+
} else {
15+
lines.push('## System\n')
16+
}
17+
18+
// Main content
19+
if (message.content && message.content.length > 0) {
20+
message.content.forEach((content) => {
21+
// content can be string or ReasoningStep object
22+
if (typeof content === 'string') {
23+
lines.push(content)
24+
} else if (content && typeof content === 'object') {
25+
// If it's an object (ReasoningStep), convert to string
26+
lines.push(JSON.stringify(content, null, 2))
27+
}
28+
})
29+
}
30+
31+
// Agent Reasoning (if exists)
32+
if (message.agentReasoning) {
33+
lines.push('\n### 🧠 Reasoning\n')
34+
35+
if (message.agentReasoning.reasoning) {
36+
lines.push('**Reasoning:**')
37+
lines.push(String(message.agentReasoning.reasoning))
38+
lines.push('')
39+
}
40+
41+
if (message.agentReasoning.steps && Array.isArray(message.agentReasoning.steps)) {
42+
lines.push('**Steps:**\n')
43+
message.agentReasoning.steps.forEach((step: any, index: number) => {
44+
lines.push(`${index + 1}. **${step.action || step.title || 'Action'}**`)
45+
if (step.reasoning) {
46+
lines.push(` - Reasoning: ${step.reasoning}`)
47+
}
48+
if (step.result || step.content) {
49+
lines.push(` - Result: ${step.result || step.content}`)
50+
}
51+
lines.push('')
52+
})
53+
}
54+
}
55+
56+
// Tool History (if exists)
57+
if (message.toolHistory && message.toolHistory.length > 0) {
58+
lines.push('\n### 🔧 Tool History\n')
59+
message.toolHistory.forEach((tool, index) => {
60+
lines.push(`#### Tool ${index + 1}: ${tool.tool_name || 'Unknown'}`)
61+
if (tool.tool_call_id) {
62+
lines.push(`- Call ID: \`${tool.tool_call_id}\``)
63+
}
64+
lines.push('- Content:')
65+
lines.push('```')
66+
lines.push(tool.content || '')
67+
lines.push('```')
68+
lines.push('')
69+
})
70+
}
71+
72+
// Timestamp
73+
if (message.timestamp) {
74+
const date = new Date(message.timestamp)
75+
lines.push(`\n---`)
76+
lines.push(`*${date.toLocaleString()}*`)
77+
}
78+
79+
return lines.join('\n')
80+
}
81+
82+
/**
83+
* Copies text to clipboard
84+
*/
85+
export async function copyToClipboard(text: string): Promise<boolean> {
86+
try {
87+
// Modern API
88+
if (navigator.clipboard && navigator.clipboard.writeText) {
89+
await navigator.clipboard.writeText(text)
90+
return true
91+
}
92+
93+
// Fallback for old browsers
94+
const textArea = document.createElement('textarea')
95+
textArea.value = text
96+
textArea.style.position = 'fixed'
97+
textArea.style.left = '-999999px'
98+
textArea.style.top = '-999999px'
99+
document.body.appendChild(textArea)
100+
textArea.focus()
101+
textArea.select()
102+
103+
const successful = document.execCommand('copy')
104+
document.body.removeChild(textArea)
105+
106+
return successful
107+
} catch (error) {
108+
console.error('Failed to copy to clipboard:', error)
109+
return false
110+
}
111+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/**
2+
* Generates a unique ID using timestamp and random string
3+
* @param prefix - Optional prefix for the ID
4+
* @returns Unique ID string
5+
*/
6+
export function generateUniqueId(prefix: string = ''): string {
7+
const timestamp = Date.now()
8+
const randomString = Math.random().toString(36).substr(2, 9)
9+
return prefix ? `${prefix}_${timestamp}_${randomString}` : `${timestamp}_${randomString}`
10+
}
11+
12+
/**
13+
* Generates a unique chat session ID
14+
* @returns Unique chat session ID
15+
*/
16+
export function generateChatSessionId(): string {
17+
return generateUniqueId('chat')
18+
}
19+
20+
/**
21+
* Generates a unique message ID
22+
* @returns Unique message ID
23+
*/
24+
export function generateMessageId(): string {
25+
return generateUniqueId('msg')
26+
}

0 commit comments

Comments
 (0)