Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion app/src/client/pages/ChatPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,25 @@ const SUGGESTIONS = [
"Does anything in my schedule conflict?",
];

/**
* A stream interruption + recovery can split one utterance across several
* consecutive text parts (often mid-sentence). Rendering each part as its
* own markdown block tears sentences and lists apart, so stitch runs of
* text parts back together before rendering.
*/
function coalesceParts(parts: UIMessage["parts"]): UIMessage["parts"] {
const out: UIMessage["parts"] = [];
for (const part of parts) {
const last = out[out.length - 1];
if (part.type === "text" && last?.type === "text") {
out[out.length - 1] = { ...last, text: last.text + part.text };
} else {
out.push(part);
}
}
return out;
}

function messageText(m: UIMessage): string {
return m.parts
.map((p) => (p.type === "text" ? p.text : ""))
Expand Down Expand Up @@ -328,7 +347,7 @@ function Turn({

return (
<div className="turn assistant">
{message.parts.map((part, i) => {
{coalesceParts(message.parts).map((part, i) => {
if (part.type === "text") {
return part.text.trim() ? <Markdown key={i} text={part.text} /> : null;
}
Expand Down
6 changes: 6 additions & 0 deletions app/src/server/pi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ export class Pi extends Think<Env, PiState> {
workspaceBash = false;
waitForMcpConnections = { timeout: 15_000 };
maxSteps = 12;
/**
* Abort-and-recover a model stream that parks without erroring — the
* cause of "spinning forever" turns. Set well above the slowest
* time-to-first-token plus the slowest MCP tool call.
*/
chatStreamStallTimeoutMs = 120_000;

getDefaultTimezone() {
return "America/New_York";
Expand Down
Loading