@assistant-ui/react-google-adk 0.0.7 → 0.0.8

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.
@@ -1,7 +1,23 @@
1
1
  import { describe, it, expect } from "vitest";
2
- import { getPendingCancellations, getPendingToolCalls } from "./useAdkRuntime";
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
+ });
@@ -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
- const getMessageContent = (msg: AppendMessage) => {
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: "text" as const,
50
- text: `[File: ${part.filename ?? "file"}]`,
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,