mirror of
https://github.com/windmill-labs/windmill.git
synced 2026-09-10 08:07:03 +00:00
* 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
31 lines
755 B
TypeScript
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 }
|
|
}
|