Skip to content

Commit 3e04e96

Browse files
committed
Fix type errors in use-client-transport demo
Fix parent type from string | null to optional string to match the transport's newTurn signature. Fix disableApprovalForApprovedTools return type to typeof tools so streamText accepts it as ToolSet.
1 parent 457f2d5 commit 3e04e96

File tree

3 files changed

+31
-16
lines changed

3 files changed

+31
-16
lines changed

demo/vercel/react/use-client-transport/src/app/api/chat/route.ts

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ interface ChatRequestBody {
3939
events?: EventsNode<UIMessageChunk>[];
4040
id: string;
4141
forkOf?: string;
42-
parent?: string | null;
42+
parent?: string;
4343
toolApprovals?: ToolApproval[];
4444
}
4545

@@ -116,7 +116,6 @@ function patchToolApprovals(
116116
break;
117117
}
118118
}
119-
120119
}
121120

122121
/**
@@ -140,7 +139,7 @@ function removeTrailingUserMessage(
140139
* that was just approved. Prevents an infinite approval loop when the LLM
141140
* calls the same tool again in multi-step mode.
142141
*/
143-
function disableApprovalForApprovedTools(approvals: ToolApproval[] | undefined): Record<string, unknown> {
142+
function disableApprovalForApprovedTools(approvals: ToolApproval[] | undefined): typeof tools {
144143
const approvedNames = new Set((approvals ?? []).filter((a) => a.approved).map((a) => a.toolName));
145144
if (approvedNames.size === 0) return tools;
146145
return Object.fromEntries(
@@ -206,10 +205,7 @@ export async function POST(req: Request) {
206205
patchToolApprovals(pendingPublish, allMessages, toolApprovals);
207206
}
208207

209-
const modelMessages = removeTrailingUserMessage(
210-
await convertToModelMessages(allMessages),
211-
toolApprovals,
212-
);
208+
const modelMessages = removeTrailingUserMessage(await convertToModelMessages(allMessages), toolApprovals);
213209

214210
const effectiveTools = disableApprovalForApprovedTools(toolApprovals);
215211

@@ -231,11 +227,13 @@ export async function POST(req: Request) {
231227
for (const [toolCallId, targetMsgId] of pendingPublish) {
232228
const output = capturedOutputs.get(toolCallId);
233229
if (output !== undefined) {
234-
await turn.addEvents([{
235-
kind: 'event',
236-
msgId: targetMsgId,
237-
events: [{ type: 'tool-output-available', toolCallId, output, dynamic: true } as UIMessageChunk],
238-
}]);
230+
await turn.addEvents([
231+
{
232+
kind: 'event',
233+
msgId: targetMsgId,
234+
events: [{ type: 'tool-output-available', toolCallId, output, dynamic: true } as UIMessageChunk],
235+
},
236+
]);
239237
}
240238
}
241239

demo/vercel/react/use-client-transport/src/app/components/message-bubble.tsx

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -217,12 +217,24 @@ export function MessageBubble({
217217
part={toolPart}
218218
onApprove={
219219
toolPart.state === 'approval-requested' && onToolApprove && headers?.['x-ably-msg-id']
220-
? () => onToolApprove(headers['x-ably-msg-id'], toolPart.toolCallId, toolPart.toolName, toolPart.input)
220+
? () =>
221+
onToolApprove(
222+
headers['x-ably-msg-id'],
223+
toolPart.toolCallId,
224+
toolPart.toolName,
225+
toolPart.input,
226+
)
221227
: undefined
222228
}
223229
onDeny={
224230
toolPart.state === 'approval-requested' && onToolDeny && headers?.['x-ably-msg-id']
225-
? () => onToolDeny(headers['x-ably-msg-id'], toolPart.toolCallId, toolPart.toolName, toolPart.input)
231+
? () =>
232+
onToolDeny(
233+
headers['x-ably-msg-id'],
234+
toolPart.toolCallId,
235+
toolPart.toolName,
236+
toolPart.input,
237+
)
226238
: undefined
227239
}
228240
/>

demo/vercel/react/use-client-transport/src/app/components/tool-invocation.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,12 +75,17 @@ function ForecastCard({ data }: { data: ForecastData }) {
7575
const highC = Math.round(((day.high - 32) * 5) / 9);
7676
const lowC = Math.round(((day.low - 32) * 5) / 9);
7777
return (
78-
<div key={day.day} className="flex items-center justify-between text-xs">
78+
<div
79+
key={day.day}
80+
className="flex items-center justify-between text-xs"
81+
>
7982
<span className="text-zinc-300 w-8">{day.day}</span>
8083
<span className="text-base">{icon}</span>
8184
<span className="text-zinc-400 w-24 text-right">
8285
{day.high}&deg;/{day.low}&deg;F
83-
<span className="text-zinc-600 ml-1">({highC}&deg;/{lowC}&deg;C)</span>
86+
<span className="text-zinc-600 ml-1">
87+
({highC}&deg;/{lowC}&deg;C)
88+
</span>
8489
</span>
8590
</div>
8691
);

0 commit comments

Comments
 (0)