Files
windmill/frontend/src/lib/components/chat/utils.ts
T
centdix c47669be0b feat(app): add chat component (#7199)
* draft

* fix

* use user message

* correctly stream

* add send trigger

* add control

* fix on success trigger

* add warning about expected input

* nit

* styling

* fix stream

* styling

* dry

* dry

* nit

* better logic

* css

* cleaning

* use managed by component input

* fix

* fix managed inputs

* handle memory

* cleaning

* cleaning

* cleaning

* update sqlx

* use id
2025-11-24 17:39:35 +00:00

31 lines
755 B
TypeScript

export function parseStreamDeltas(streamData: string): {
content: string
type?: string
success?: boolean
} {
const lines = streamData.trim().split('\n')
let content = ''
let type = 'message'
let success = true
for (const line of lines) {
if (!line.trim()) continue
try {
const parsed = JSON.parse(line)
if (parsed.type === 'tool_result') {
type = 'tool_result'
success = parsed.success
const toolName = parsed.function_name
content = success ? `Used ${toolName} tool` : `Failed to use ${toolName} tool`
}
if (parsed.type === 'token_delta' && parsed.content) {
content += parsed.content
}
} catch (e) {
console.error('Failed to parse stream line:', line, e)
}
}
return { content, type, success }
}