@assistant-ui/react-google-adk 0.0.7 → 0.0.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/AdkClient.d.ts.map +1 -1
- package/dist/AdkClient.js +1 -26
- package/dist/AdkClient.js.map +1 -1
- package/dist/AdkEventAccumulator.d.ts.map +1 -1
- package/dist/AdkEventAccumulator.js +10 -20
- package/dist/AdkEventAccumulator.js.map +1 -1
- package/dist/contentToParts.d.ts +3 -0
- package/dist/contentToParts.d.ts.map +1 -0
- package/dist/contentToParts.js +36 -0
- package/dist/contentToParts.js.map +1 -0
- package/dist/convertAdkMessages.d.ts.map +1 -1
- package/dist/convertAdkMessages.js +16 -0
- package/dist/convertAdkMessages.js.map +1 -1
- package/dist/types.d.ts +9 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/dist/useAdkMessages.d.ts.map +1 -1
- package/dist/useAdkMessages.js +3 -27
- package/dist/useAdkMessages.js.map +1 -1
- package/dist/useAdkRuntime.d.ts +2 -1
- package/dist/useAdkRuntime.d.ts.map +1 -1
- package/dist/useAdkRuntime.js +8 -5
- package/dist/useAdkRuntime.js.map +1 -1
- package/package.json +5 -5
- package/src/AdkClient.test.ts +99 -0
- package/src/AdkClient.ts +4 -31
- package/src/AdkEventAccumulator.test.ts +125 -2
- package/src/AdkEventAccumulator.ts +30 -20
- package/src/contentToParts.ts +38 -0
- package/src/convertAdkMessages.test.ts +53 -0
- package/src/convertAdkMessages.ts +17 -0
- package/src/types.ts +11 -0
- package/src/useAdkMessages.test.ts +75 -0
- package/src/useAdkMessages.ts +3 -31
- package/src/useAdkRuntime.test.ts +74 -1
- package/src/useAdkRuntime.ts +10 -5
package/src/useAdkMessages.ts
CHANGED
|
@@ -3,11 +3,10 @@ import { useState, useCallback, useRef, useMemo } from "react";
|
|
|
3
3
|
import { v4 as uuidv4 } from "uuid";
|
|
4
4
|
import { useAui } from "@assistant-ui/store";
|
|
5
5
|
import { AdkEventAccumulator } from "./AdkEventAccumulator";
|
|
6
|
+
import { contentToParts } from "./contentToParts";
|
|
6
7
|
import type {
|
|
7
8
|
AdkEvent,
|
|
8
|
-
AdkEventPart,
|
|
9
9
|
AdkMessage,
|
|
10
|
-
AdkMessageContentPart,
|
|
11
10
|
AdkMessageMetadata,
|
|
12
11
|
AdkSendMessageConfig,
|
|
13
12
|
AdkStreamCallback,
|
|
@@ -200,7 +199,8 @@ export const useAdkMessages = ({
|
|
|
200
199
|
};
|
|
201
200
|
};
|
|
202
201
|
|
|
203
|
-
|
|
202
|
+
/** @internal — exported for unit tests. */
|
|
203
|
+
export const messageToEvent = (msg: AdkMessage): AdkEvent => {
|
|
204
204
|
if (msg.type === "human") {
|
|
205
205
|
return {
|
|
206
206
|
id: msg.id ?? uuidv4(),
|
|
@@ -246,31 +246,3 @@ const messageToEvent = (msg: AdkMessage): AdkEvent => {
|
|
|
246
246
|
};
|
|
247
247
|
return result;
|
|
248
248
|
};
|
|
249
|
-
|
|
250
|
-
const contentToParts = (
|
|
251
|
-
content: string | AdkMessageContentPart[],
|
|
252
|
-
): AdkEventPart[] => {
|
|
253
|
-
if (typeof content === "string") return [{ text: content }];
|
|
254
|
-
return content.map((part) => {
|
|
255
|
-
switch (part.type) {
|
|
256
|
-
case "text":
|
|
257
|
-
return { text: part.text };
|
|
258
|
-
case "reasoning":
|
|
259
|
-
return { text: part.text, thought: true };
|
|
260
|
-
case "image":
|
|
261
|
-
return { inlineData: { mimeType: part.mimeType, data: part.data } };
|
|
262
|
-
case "image_url":
|
|
263
|
-
return { fileData: { fileUri: part.url } };
|
|
264
|
-
case "code":
|
|
265
|
-
return {
|
|
266
|
-
executableCode: { code: part.code, language: part.language },
|
|
267
|
-
};
|
|
268
|
-
case "code_result":
|
|
269
|
-
return {
|
|
270
|
-
codeExecutionResult: { output: part.output, outcome: part.outcome },
|
|
271
|
-
};
|
|
272
|
-
default:
|
|
273
|
-
return { text: "" };
|
|
274
|
-
}
|
|
275
|
-
});
|
|
276
|
-
};
|
|
@@ -1,7 +1,23 @@
|
|
|
1
1
|
import { describe, it, expect } from "vitest";
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
getMessageContent,
|
|
4
|
+
getPendingCancellations,
|
|
5
|
+
getPendingToolCalls,
|
|
6
|
+
} from "./useAdkRuntime";
|
|
7
|
+
import type { AppendMessage } from "@assistant-ui/core";
|
|
3
8
|
import type { AdkMessage } from "./types";
|
|
4
9
|
|
|
10
|
+
const makeAppendMessage = (content: AppendMessage["content"]): AppendMessage =>
|
|
11
|
+
({
|
|
12
|
+
role: "user",
|
|
13
|
+
content,
|
|
14
|
+
attachments: [],
|
|
15
|
+
parentId: null,
|
|
16
|
+
sourceId: null,
|
|
17
|
+
runConfig: undefined,
|
|
18
|
+
metadata: { custom: {} },
|
|
19
|
+
}) as unknown as AppendMessage;
|
|
20
|
+
|
|
5
21
|
const aiWithToolCalls = (
|
|
6
22
|
id: string,
|
|
7
23
|
toolCalls: Array<{ id: string; name: string }>,
|
|
@@ -136,3 +152,60 @@ describe("getPendingCancellations", () => {
|
|
|
136
152
|
});
|
|
137
153
|
});
|
|
138
154
|
});
|
|
155
|
+
|
|
156
|
+
describe("getMessageContent", () => {
|
|
157
|
+
it("preserves file part data and mimeType end-to-end", () => {
|
|
158
|
+
const result = getMessageContent(
|
|
159
|
+
makeAppendMessage([
|
|
160
|
+
{ type: "text", text: "see attached" },
|
|
161
|
+
{
|
|
162
|
+
type: "file",
|
|
163
|
+
mimeType: "application/pdf",
|
|
164
|
+
data: "JVBERi0xLjQK",
|
|
165
|
+
filename: "report.pdf",
|
|
166
|
+
},
|
|
167
|
+
]),
|
|
168
|
+
);
|
|
169
|
+
expect(result).toEqual([
|
|
170
|
+
{ type: "text", text: "see attached" },
|
|
171
|
+
{
|
|
172
|
+
type: "file",
|
|
173
|
+
mimeType: "application/pdf",
|
|
174
|
+
data: "JVBERi0xLjQK",
|
|
175
|
+
filename: "report.pdf",
|
|
176
|
+
},
|
|
177
|
+
]);
|
|
178
|
+
});
|
|
179
|
+
|
|
180
|
+
it("keeps file-only content as an array (does not collapse to a text marker)", () => {
|
|
181
|
+
const result = getMessageContent(
|
|
182
|
+
makeAppendMessage([
|
|
183
|
+
{
|
|
184
|
+
type: "file",
|
|
185
|
+
mimeType: "image/png",
|
|
186
|
+
data: "AAAA",
|
|
187
|
+
filename: "x.png",
|
|
188
|
+
},
|
|
189
|
+
]),
|
|
190
|
+
);
|
|
191
|
+
expect(result).toEqual([
|
|
192
|
+
{
|
|
193
|
+
type: "file",
|
|
194
|
+
mimeType: "image/png",
|
|
195
|
+
data: "AAAA",
|
|
196
|
+
filename: "x.png",
|
|
197
|
+
},
|
|
198
|
+
]);
|
|
199
|
+
});
|
|
200
|
+
|
|
201
|
+
it("omits filename when not provided", () => {
|
|
202
|
+
const result = getMessageContent(
|
|
203
|
+
makeAppendMessage([
|
|
204
|
+
{ type: "file", mimeType: "application/pdf", data: "AAAA" },
|
|
205
|
+
]),
|
|
206
|
+
);
|
|
207
|
+
expect(result).toEqual([
|
|
208
|
+
{ type: "file", mimeType: "application/pdf", data: "AAAA" },
|
|
209
|
+
]);
|
|
210
|
+
});
|
|
211
|
+
});
|
package/src/useAdkRuntime.ts
CHANGED
|
@@ -3,6 +3,7 @@ import { useEffect, useRef, useState } from "react";
|
|
|
3
3
|
import {
|
|
4
4
|
getExternalStoreMessages,
|
|
5
5
|
type AttachmentAdapter,
|
|
6
|
+
type DictationAdapter,
|
|
6
7
|
type FeedbackAdapter,
|
|
7
8
|
type SpeechSynthesisAdapter,
|
|
8
9
|
type AppendMessage,
|
|
@@ -32,7 +33,8 @@ import { convertAdkMessage } from "./convertAdkMessages";
|
|
|
32
33
|
import { symbolAdkRuntimeExtras, type AdkRuntimeExtras } from "./hooks";
|
|
33
34
|
import { v4 as uuidv4 } from "uuid";
|
|
34
35
|
|
|
35
|
-
|
|
36
|
+
/** @internal — exported for unit tests. */
|
|
37
|
+
export const getMessageContent = (msg: AppendMessage) => {
|
|
36
38
|
const allContent = [
|
|
37
39
|
...msg.content,
|
|
38
40
|
...(msg.attachments?.flatMap((a) => a.content) ?? []),
|
|
@@ -46,8 +48,10 @@ const getMessageContent = (msg: AppendMessage) => {
|
|
|
46
48
|
return { type: "image_url" as const, url: part.image };
|
|
47
49
|
case "file":
|
|
48
50
|
return {
|
|
49
|
-
type: "
|
|
50
|
-
|
|
51
|
+
type: "file" as const,
|
|
52
|
+
mimeType: part.mimeType,
|
|
53
|
+
data: part.data,
|
|
54
|
+
...(part.filename != null && { filename: part.filename }),
|
|
51
55
|
};
|
|
52
56
|
|
|
53
57
|
case "tool-call":
|
|
@@ -144,6 +148,7 @@ export type UseAdkRuntimeOptions = {
|
|
|
144
148
|
| {
|
|
145
149
|
attachments?: AttachmentAdapter;
|
|
146
150
|
speech?: SpeechSynthesisAdapter;
|
|
151
|
+
dictation?: DictationAdapter;
|
|
147
152
|
feedback?: FeedbackAdapter;
|
|
148
153
|
}
|
|
149
154
|
| undefined;
|
|
@@ -164,7 +169,7 @@ export type UseAdkRuntimeOptions = {
|
|
|
164
169
|
|
|
165
170
|
const useAdkRuntimeImpl = ({
|
|
166
171
|
autoCancelPendingToolCalls,
|
|
167
|
-
adapters: { attachments, feedback, speech } = {},
|
|
172
|
+
adapters: { attachments, dictation, feedback, speech } = {},
|
|
168
173
|
unstable_allowCancellation,
|
|
169
174
|
stream,
|
|
170
175
|
load,
|
|
@@ -261,7 +266,7 @@ const useAdkRuntimeImpl = ({
|
|
|
261
266
|
const runtime = useExternalStoreRuntime({
|
|
262
267
|
isRunning: effectiveIsRunning,
|
|
263
268
|
messages: threadMessages,
|
|
264
|
-
adapters: { attachments, feedback, speech },
|
|
269
|
+
adapters: { attachments, dictation, feedback, speech },
|
|
265
270
|
extras: {
|
|
266
271
|
[symbolAdkRuntimeExtras]: true,
|
|
267
272
|
agentInfo,
|