Add "AI Chat" app.

This commit is contained in:
James Babcock committed 2026-09-09 01:15:19 -07:00
1 parent 78c56ffc4e
commit 0765e943fb
13 files changed
+616 -87

No files matched your search

+5 -1
View File
@@ -50,6 +50,7 @@ export class DirectAssistantBackend {
const startMs = Date.now();
let cancelled = false;
let streamHandle: LlmStreamHandle | null = null;
let priorText = "";
const finishError = (message: string) => {
if (cancelled) return;
@@ -78,7 +79,7 @@ export class DirectAssistantBackend {
tools: options.buildTools(),
onTextDelta: (delta, textSoFar) => {
if (cancelled) return;
options.callbacks.onTextDelta(delta, textSoFar);
options.callbacks.onTextDelta(delta, priorText + textSoFar);
},
onDone: (result) => {
streamHandle = null;
@@ -87,6 +88,9 @@ export class DirectAssistantBackend {
finishError("The assistant declined this request");
return;
}
const fullText = priorText + result.text;
options.callbacks.onTextDelta("", fullText);
priorText = fullText ? `${fullText}\n\n` : "";
// Record what the model produced this iteration.
const assistantContent: LlmContentBlock[] = result.content.length
? result.content