Spaces:
Running on CPU Upgrade
Running on CPU Upgrade
Commit ·
3c77a6c
1
Parent(s): 7e62dfa
feat: cooperative cancellation, session persistence, background generation
Browse files
frontend/src/lib/convert-llm-messages.ts
CHANGED
|
@@ -44,7 +44,6 @@ export function llmMessagesToUIMessages(messages: LLMMessage[]): UIMessage[] {
|
|
| 44 |
id: nextId(),
|
| 45 |
role: 'user',
|
| 46 |
parts: [{ type: 'text', text: msg.content || '' }],
|
| 47 |
-
createdAt: new Date(),
|
| 48 |
});
|
| 49 |
continue;
|
| 50 |
}
|
|
@@ -58,20 +57,30 @@ export function llmMessagesToUIMessages(messages: LLMMessage[]): UIMessage[] {
|
|
| 58 |
|
| 59 |
if (msg.tool_calls) {
|
| 60 |
for (const tc of msg.tool_calls) {
|
| 61 |
-
let
|
| 62 |
try {
|
| 63 |
-
|
| 64 |
} catch { /* malformed */ }
|
| 65 |
|
| 66 |
const result = toolResults.get(tc.id);
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 75 |
}
|
| 76 |
}
|
| 77 |
|
|
@@ -79,7 +88,6 @@ export function llmMessagesToUIMessages(messages: LLMMessage[]): UIMessage[] {
|
|
| 79 |
id: nextId(),
|
| 80 |
role: 'assistant',
|
| 81 |
parts,
|
| 82 |
-
createdAt: new Date(),
|
| 83 |
});
|
| 84 |
}
|
| 85 |
}
|
|
|
|
| 44 |
id: nextId(),
|
| 45 |
role: 'user',
|
| 46 |
parts: [{ type: 'text', text: msg.content || '' }],
|
|
|
|
| 47 |
});
|
| 48 |
continue;
|
| 49 |
}
|
|
|
|
| 57 |
|
| 58 |
if (msg.tool_calls) {
|
| 59 |
for (const tc of msg.tool_calls) {
|
| 60 |
+
let input: Record<string, unknown> = {};
|
| 61 |
try {
|
| 62 |
+
input = JSON.parse(tc.function.arguments);
|
| 63 |
} catch { /* malformed */ }
|
| 64 |
|
| 65 |
const result = toolResults.get(tc.id);
|
| 66 |
+
if (result) {
|
| 67 |
+
parts.push({
|
| 68 |
+
type: 'dynamic-tool',
|
| 69 |
+
toolCallId: tc.id,
|
| 70 |
+
toolName: tc.function.name,
|
| 71 |
+
state: 'output-available',
|
| 72 |
+
input,
|
| 73 |
+
output: result.output,
|
| 74 |
+
});
|
| 75 |
+
} else {
|
| 76 |
+
parts.push({
|
| 77 |
+
type: 'dynamic-tool',
|
| 78 |
+
toolCallId: tc.id,
|
| 79 |
+
toolName: tc.function.name,
|
| 80 |
+
state: 'input-available',
|
| 81 |
+
input,
|
| 82 |
+
});
|
| 83 |
+
}
|
| 84 |
}
|
| 85 |
}
|
| 86 |
|
|
|
|
| 88 |
id: nextId(),
|
| 89 |
role: 'assistant',
|
| 90 |
parts,
|
|
|
|
| 91 |
});
|
| 92 |
}
|
| 93 |
}
|