Skip to content

Commit 503e121

Browse files
committed
chore(apollo-vertex): ai chat update to latest tanstack ai
1 parent e2070b5 commit 503e121

6 files changed

Lines changed: 105 additions & 70 deletions

File tree

apps/apollo-vertex/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,9 @@
5555
"@radix-ui/react-toggle-group": "^1.1.11",
5656
"@radix-ui/react-tooltip": "^1.2.8",
5757
"@tailwindcss/postcss": "^4.1.17",
58-
"@tanstack/ai": "^0.8.1",
59-
"@tanstack/ai-client": "0.7.2",
60-
"@tanstack/ai-react": "0.7.2",
58+
"@tanstack/ai": "0.14.0",
59+
"@tanstack/ai-client": "0.8.0",
60+
"@tanstack/ai-react": "0.8.0",
6161
"@tanstack/react-query": "^5.90.21",
6262
"@tanstack/react-router": "^1.132.31",
6363
"@tanstack/react-table": "^8.21.3",

apps/apollo-vertex/registry.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -261,9 +261,9 @@
261261
"description": "A composable AI chat UI component for TanStack AI with AgentHub adapter, markdown rendering, suggestion buttons, and error display",
262262
"dependencies": [
263263
"@mantine/hooks@^9.0.0",
264-
"@tanstack/ai@^0.8.1",
265-
"@tanstack/ai-client@0.7.2",
266-
"@tanstack/ai-react@0.7.2",
264+
"@tanstack/ai@0.14.0",
265+
"@tanstack/ai-client@0.8.0",
266+
"@tanstack/ai-react@0.8.0",
267267
"@tanstack/react-query@^5.90.0",
268268
"@types/luxon",
269269
"@uipath/apollo-dashboarding@0.0.61",

apps/apollo-vertex/registry/ai-chat/adapters/agenthub/adapter.ts

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1-
import type { AnyClientTool, ModelMessage, StreamChunk } from "@tanstack/ai";
1+
import {
2+
type AnyClientTool,
3+
EventType,
4+
type ModelMessage,
5+
type StreamChunk,
6+
} from "@tanstack/ai";
27
import type {
38
ConnectConnectionAdapter,
49
ToolCallPart,
@@ -47,18 +52,24 @@ function shouldSkipFollowUp(
4752
async function* emptyStream(): AsyncIterable<StreamChunk> {
4853
await Promise.resolve();
4954
const runId = crypto.randomUUID();
55+
const threadId = crypto.randomUUID();
5056
const messageId = crypto.randomUUID();
51-
yield { type: "RUN_STARTED", runId, timestamp: Date.now() };
57+
yield { type: EventType.RUN_STARTED, runId, threadId, timestamp: Date.now() };
5258
yield {
53-
type: "TEXT_MESSAGE_START",
59+
type: EventType.TEXT_MESSAGE_START,
5460
messageId,
5561
role: "assistant",
5662
timestamp: Date.now(),
5763
};
58-
yield { type: "TEXT_MESSAGE_END", messageId, timestamp: Date.now() };
5964
yield {
60-
type: "RUN_FINISHED",
65+
type: EventType.TEXT_MESSAGE_END,
66+
messageId,
67+
timestamp: Date.now(),
68+
};
69+
yield {
70+
type: EventType.RUN_FINISHED,
6171
runId,
72+
threadId,
6273
timestamp: Date.now(),
6374
finishReason: "stop",
6475
};

apps/apollo-vertex/registry/ai-chat/adapters/agenthub/stream.ts

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { StreamChunk } from "@tanstack/ai";
1+
import { EventType, type StreamChunk } from "@tanstack/ai";
22
import type { UIMessage } from "@tanstack/ai-client";
33
import { EventSourceParserStream } from "eventsource-parser/stream";
44
import { z } from "zod/v4";
@@ -119,7 +119,7 @@ function* handleToolCallDelta(
119119
if (fn?.arguments && existing) {
120120
existing.arguments += fn.arguments;
121121
yield {
122-
type: "TOOL_CALL_ARGS" as const,
122+
type: EventType.TOOL_CALL_ARGS,
123123
toolCallId: existing.id,
124124
delta: fn.arguments,
125125
timestamp: Date.now(),
@@ -128,19 +128,20 @@ function* handleToolCallDelta(
128128
return;
129129
}
130130

131-
const id = tc.id ?? "";
131+
const id = tc.id ?? crypto.randomUUID();
132132
const name = fn?.name ?? "";
133133
toolCalls.set(idx, { id, name, arguments: fn?.arguments ?? "" });
134134
yield {
135-
type: "TOOL_CALL_START" as const,
135+
type: EventType.TOOL_CALL_START,
136136
toolCallId: id,
137+
toolCallName: name,
137138
toolName: name,
138139
parentMessageId,
139140
timestamp: Date.now(),
140141
};
141142
if (fn?.arguments) {
142143
yield {
143-
type: "TOOL_CALL_ARGS" as const,
144+
type: EventType.TOOL_CALL_ARGS,
144145
toolCallId: id,
145146
delta: fn.arguments,
146147
timestamp: Date.now(),
@@ -153,10 +154,11 @@ async function* toStreamChunks(
153154
): AsyncIterable<StreamChunk> {
154155
const messageId = crypto.randomUUID();
155156
const runId = crypto.randomUUID();
157+
const threadId = crypto.randomUUID();
156158

157-
yield { type: "RUN_STARTED", runId, timestamp: Date.now() };
159+
yield { type: EventType.RUN_STARTED, runId, threadId, timestamp: Date.now() };
158160
yield {
159-
type: "TEXT_MESSAGE_START",
161+
type: EventType.TEXT_MESSAGE_START,
160162
messageId,
161163
role: "assistant",
162164
timestamp: Date.now(),
@@ -197,7 +199,7 @@ async function* toStreamChunks(
197199

198200
if (delta?.content) {
199201
yield {
200-
type: "TEXT_MESSAGE_CONTENT" as const,
202+
type: EventType.TEXT_MESSAGE_CONTENT,
201203
messageId,
202204
delta: delta.content,
203205
timestamp: Date.now(),
@@ -214,8 +216,9 @@ async function* toStreamChunks(
214216
// Close open tool calls and trigger client-side execution
215217
for (const [, tc] of toolCalls) {
216218
yield {
217-
type: "TOOL_CALL_END" as const,
219+
type: EventType.TOOL_CALL_END,
218220
toolCallId: tc.id,
221+
toolCallName: tc.name,
219222
toolName: tc.name,
220223
timestamp: Date.now(),
221224
};
@@ -226,7 +229,7 @@ async function* toStreamChunks(
226229
/* empty */
227230
}
228231
yield {
229-
type: "CUSTOM" as const,
232+
type: EventType.CUSTOM,
230233
name: "tool-input-available",
231234
value: {
232235
toolCallId: tc.id,
@@ -236,10 +239,15 @@ async function* toStreamChunks(
236239
timestamp: Date.now(),
237240
};
238241
}
239-
yield { type: "TEXT_MESSAGE_END", messageId, timestamp: Date.now() };
240242
yield {
241-
type: "RUN_FINISHED",
243+
type: EventType.TEXT_MESSAGE_END,
244+
messageId,
245+
timestamp: Date.now(),
246+
};
247+
yield {
248+
type: EventType.RUN_FINISHED,
242249
runId,
250+
threadId,
243251
timestamp: Date.now(),
244252
finishReason: finishReason === "tool_calls" ? "tool_calls" : "stop",
245253
};

apps/apollo-vertex/registry/ai-chat/adapters/conversational-agent/stream.ts

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { StreamChunk } from "@tanstack/ai";
1+
import { EventType, type StreamChunk } from "@tanstack/ai";
22
import type { SessionStream } from "@uipath/uipath-typescript/conversational-agent";
33
import { MessageRole } from "@uipath/uipath-typescript/conversational-agent";
44

@@ -62,9 +62,15 @@ export function bridgeExchange(
6262
): AsyncIterable<StreamChunk> {
6363
const queue = createStreamQueue();
6464
const runId = crypto.randomUUID();
65+
const threadId = crypto.randomUUID();
6566
const cleanups: Array<() => void> = [];
6667

67-
queue.push({ type: "RUN_STARTED", runId, timestamp: Date.now() });
68+
queue.push({
69+
type: EventType.RUN_STARTED,
70+
runId,
71+
threadId,
72+
timestamp: Date.now(),
73+
});
6874

6975
const exchange = session.startExchange();
7076

@@ -79,7 +85,7 @@ export function bridgeExchange(
7985
const messageId = crypto.randomUUID();
8086

8187
queue.push({
82-
type: "TEXT_MESSAGE_START",
88+
type: EventType.TEXT_MESSAGE_START,
8389
messageId,
8490
role: "assistant",
8591
timestamp: Date.now(),
@@ -90,7 +96,7 @@ export function bridgeExchange(
9096

9197
part.onChunk((chunk) => {
9298
queue.push({
93-
type: "TEXT_MESSAGE_CONTENT",
99+
type: EventType.TEXT_MESSAGE_CONTENT,
94100
messageId,
95101
delta: chunk.data ?? "",
96102
timestamp: Date.now(),
@@ -100,7 +106,7 @@ export function bridgeExchange(
100106

101107
msg.onMessageEnd(() => {
102108
queue.push({
103-
type: "TEXT_MESSAGE_END",
109+
type: EventType.TEXT_MESSAGE_END,
104110
messageId,
105111
timestamp: Date.now(),
106112
});
@@ -109,8 +115,9 @@ export function bridgeExchange(
109115

110116
exchange.onExchangeEnd(() => {
111117
queue.push({
112-
type: "RUN_FINISHED",
118+
type: EventType.RUN_FINISHED,
113119
runId,
120+
threadId,
114121
finishReason: "stop",
115122
timestamp: Date.now(),
116123
});
@@ -120,9 +127,9 @@ export function bridgeExchange(
120127

121128
exchange.onErrorStart((err) => {
122129
queue.push({
123-
type: "RUN_ERROR",
130+
type: EventType.RUN_ERROR,
124131
runId,
125-
error: { message: err.message ?? "Exchange error" },
132+
message: err.message ?? "Exchange error",
126133
timestamp: Date.now(),
127134
});
128135
finishRun();
@@ -132,9 +139,9 @@ export function bridgeExchange(
132139
cleanups.push(
133140
session.onErrorStart((err) => {
134141
queue.push({
135-
type: "RUN_ERROR",
142+
type: EventType.RUN_ERROR,
136143
runId,
137-
error: { message: err.message ?? "Session error" },
144+
message: err.message ?? "Session error",
138145
timestamp: Date.now(),
139146
});
140147
finishRun();
@@ -158,8 +165,9 @@ export function bridgeExchange(
158165
const onAbort = () => {
159166
exchange.sendExchangeEnd();
160167
queue.push({
161-
type: "RUN_FINISHED",
168+
type: EventType.RUN_FINISHED,
162169
runId,
170+
threadId,
163171
finishReason: "stop",
164172
timestamp: Date.now(),
165173
});

0 commit comments

Comments
 (0)