@assistant-ui/react-google-adk 0.0.17 → 0.0.19
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.js +11 -0
- package/dist/AdkClient.js.map +1 -1
- package/dist/AdkEventAccumulator.d.ts.map +1 -1
- package/dist/AdkSessionAdapter.d.ts.map +1 -1
- package/dist/AdkSessionAdapter.js +54 -9
- package/dist/AdkSessionAdapter.js.map +1 -1
- package/dist/useAdkMessages.d.ts.map +1 -1
- package/dist/useAdkMessages.js +1 -1
- package/dist/useAdkMessages.js.map +1 -1
- package/dist/useAdkRuntime.js +4 -4
- package/dist/useAdkRuntime.js.map +1 -1
- package/package.json +6 -6
- package/src/AdkClient.test.ts +133 -65
- package/src/AdkClient.ts +26 -0
- package/src/AdkEventAccumulator.test.ts +0 -36
- package/src/AdkSessionAdapter.test.ts +200 -11
- package/src/AdkSessionAdapter.ts +141 -18
- package/src/useAdkMessages.ts +1 -1
- package/src/useAdkRuntime.ts +4 -4
- package/src/server/createAdkApiRoute.test.ts +0 -370
|
@@ -62,6 +62,30 @@ describe("createAdkSessionAdapter - list", () => {
|
|
|
62
62
|
expect(result.threads).toHaveLength(0);
|
|
63
63
|
});
|
|
64
64
|
|
|
65
|
+
it("rejects a successful response that is not a session array", async () => {
|
|
66
|
+
mockFetch.mockResolvedValueOnce(
|
|
67
|
+
new Response(JSON.stringify({}), { status: 200 }),
|
|
68
|
+
);
|
|
69
|
+
|
|
70
|
+
const { adapter } = createAdkSessionAdapter(baseOptions);
|
|
71
|
+
|
|
72
|
+
await expect(adapter.list()).rejects.toThrow(
|
|
73
|
+
"Invalid ADK session list response: expected an array of sessions.",
|
|
74
|
+
);
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
it("rejects session list entries without a valid id", async () => {
|
|
78
|
+
mockFetch.mockResolvedValueOnce(
|
|
79
|
+
new Response(JSON.stringify([{ id: "s1" }, {}]), { status: 200 }),
|
|
80
|
+
);
|
|
81
|
+
|
|
82
|
+
const { adapter } = createAdkSessionAdapter(baseOptions);
|
|
83
|
+
|
|
84
|
+
await expect(adapter.list()).rejects.toThrow(
|
|
85
|
+
'Invalid ADK session list response: session at index 1 must have a non-empty string "id".',
|
|
86
|
+
);
|
|
87
|
+
});
|
|
88
|
+
|
|
65
89
|
it("throws when response is not ok", async () => {
|
|
66
90
|
mockFetch.mockResolvedValueOnce(
|
|
67
91
|
new Response("Server error", { status: 500 }),
|
|
@@ -139,6 +163,18 @@ describe("createAdkSessionAdapter - initialize", () => {
|
|
|
139
163
|
"Failed to create session: 403",
|
|
140
164
|
);
|
|
141
165
|
});
|
|
166
|
+
|
|
167
|
+
it("rejects a successful response without a session id", async () => {
|
|
168
|
+
mockFetch.mockResolvedValueOnce(
|
|
169
|
+
new Response(JSON.stringify({}), { status: 200 }),
|
|
170
|
+
);
|
|
171
|
+
|
|
172
|
+
const { adapter } = createAdkSessionAdapter(baseOptions);
|
|
173
|
+
|
|
174
|
+
await expect(adapter.initialize("thread-1")).rejects.toThrow(
|
|
175
|
+
'Invalid ADK session create response: expected an object with a non-empty string "id".',
|
|
176
|
+
);
|
|
177
|
+
});
|
|
142
178
|
});
|
|
143
179
|
|
|
144
180
|
// ── adapter.delete() ──
|
|
@@ -188,20 +224,10 @@ describe("createAdkSessionAdapter - delete", () => {
|
|
|
188
224
|
// ── adapter.rename / archive / unarchive ──
|
|
189
225
|
|
|
190
226
|
describe("createAdkSessionAdapter - no-op methods", () => {
|
|
191
|
-
it("rename
|
|
227
|
+
it("rename/archive/unarchive resolve without hitting the network", async () => {
|
|
192
228
|
const { adapter } = createAdkSessionAdapter(baseOptions);
|
|
193
229
|
await expect(adapter.rename("s1", "New Title")).resolves.toBeUndefined();
|
|
194
|
-
expect(mockFetch).not.toHaveBeenCalled();
|
|
195
|
-
});
|
|
196
|
-
|
|
197
|
-
it("archive resolves without error", async () => {
|
|
198
|
-
const { adapter } = createAdkSessionAdapter(baseOptions);
|
|
199
230
|
await expect(adapter.archive("s1")).resolves.toBeUndefined();
|
|
200
|
-
expect(mockFetch).not.toHaveBeenCalled();
|
|
201
|
-
});
|
|
202
|
-
|
|
203
|
-
it("unarchive resolves without error", async () => {
|
|
204
|
-
const { adapter } = createAdkSessionAdapter(baseOptions);
|
|
205
231
|
await expect(adapter.unarchive("s1")).resolves.toBeUndefined();
|
|
206
232
|
expect(mockFetch).not.toHaveBeenCalled();
|
|
207
233
|
});
|
|
@@ -250,6 +276,18 @@ describe("createAdkSessionAdapter - fetch", () => {
|
|
|
250
276
|
"Session not found: 404",
|
|
251
277
|
);
|
|
252
278
|
});
|
|
279
|
+
|
|
280
|
+
it("rejects a successful response without a session id", async () => {
|
|
281
|
+
mockFetch.mockResolvedValueOnce(
|
|
282
|
+
new Response(JSON.stringify({}), { status: 200 }),
|
|
283
|
+
);
|
|
284
|
+
|
|
285
|
+
const { adapter } = createAdkSessionAdapter(baseOptions);
|
|
286
|
+
|
|
287
|
+
await expect(adapter.fetch("s1")).rejects.toThrow(
|
|
288
|
+
'Invalid ADK session fetch response: expected an object with a non-empty string "id".',
|
|
289
|
+
);
|
|
290
|
+
});
|
|
253
291
|
});
|
|
254
292
|
|
|
255
293
|
// ── load() ──
|
|
@@ -305,6 +343,30 @@ describe("createAdkSessionAdapter - load", () => {
|
|
|
305
343
|
expect(result.messages).toEqual([]);
|
|
306
344
|
});
|
|
307
345
|
|
|
346
|
+
it("rejects a successful response without a session id", async () => {
|
|
347
|
+
mockFetch.mockResolvedValueOnce(
|
|
348
|
+
new Response(JSON.stringify({}), { status: 200 }),
|
|
349
|
+
);
|
|
350
|
+
|
|
351
|
+
const { load } = createAdkSessionAdapter(baseOptions);
|
|
352
|
+
|
|
353
|
+
await expect(load("s1")).rejects.toThrow(
|
|
354
|
+
'Invalid ADK session load response: expected an object with a non-empty string "id".',
|
|
355
|
+
);
|
|
356
|
+
});
|
|
357
|
+
|
|
358
|
+
it("rejects a session with a malformed events field", async () => {
|
|
359
|
+
mockFetch.mockResolvedValueOnce(
|
|
360
|
+
new Response(JSON.stringify({ id: "s1", events: {} }), { status: 200 }),
|
|
361
|
+
);
|
|
362
|
+
|
|
363
|
+
const { load } = createAdkSessionAdapter(baseOptions);
|
|
364
|
+
|
|
365
|
+
await expect(load("s1")).rejects.toThrow(
|
|
366
|
+
'Invalid ADK session load response: expected "events" to be an array when present.',
|
|
367
|
+
);
|
|
368
|
+
});
|
|
369
|
+
|
|
308
370
|
it("throws when session fetch fails", async () => {
|
|
309
371
|
mockFetch.mockResolvedValueOnce(
|
|
310
372
|
new Response("Server error", { status: 500 }),
|
|
@@ -343,6 +405,133 @@ describe("createAdkSessionAdapter - load", () => {
|
|
|
343
405
|
});
|
|
344
406
|
});
|
|
345
407
|
|
|
408
|
+
describe("createAdkSessionAdapter - artifacts", () => {
|
|
409
|
+
it("lists names from current and legacy artifact responses", async () => {
|
|
410
|
+
mockFetch.mockResolvedValueOnce(
|
|
411
|
+
new Response(JSON.stringify(["report.pdf", { filename: "chart.png" }]), {
|
|
412
|
+
status: 200,
|
|
413
|
+
}),
|
|
414
|
+
);
|
|
415
|
+
|
|
416
|
+
const { artifacts } = createAdkSessionAdapter(baseOptions);
|
|
417
|
+
|
|
418
|
+
await expect(artifacts.list("s1")).resolves.toEqual([
|
|
419
|
+
"report.pdf",
|
|
420
|
+
"chart.png",
|
|
421
|
+
]);
|
|
422
|
+
expect(mockFetch.mock.calls[0]![0]).toBe(`${expectedBaseUrl}/s1/artifacts`);
|
|
423
|
+
});
|
|
424
|
+
|
|
425
|
+
it("rejects an artifact list that is not an array", async () => {
|
|
426
|
+
mockFetch.mockResolvedValueOnce(
|
|
427
|
+
new Response(JSON.stringify({}), { status: 200 }),
|
|
428
|
+
);
|
|
429
|
+
|
|
430
|
+
const { artifacts } = createAdkSessionAdapter(baseOptions);
|
|
431
|
+
|
|
432
|
+
await expect(artifacts.list("s1")).rejects.toThrow(
|
|
433
|
+
"Invalid ADK artifact list response: expected an array of artifact names.",
|
|
434
|
+
);
|
|
435
|
+
});
|
|
436
|
+
|
|
437
|
+
it("rejects malformed artifact list entries", async () => {
|
|
438
|
+
mockFetch.mockResolvedValueOnce(
|
|
439
|
+
new Response(JSON.stringify(["report.pdf", {}]), { status: 200 }),
|
|
440
|
+
);
|
|
441
|
+
|
|
442
|
+
const { artifacts } = createAdkSessionAdapter(baseOptions);
|
|
443
|
+
|
|
444
|
+
await expect(artifacts.list("s1")).rejects.toThrow(
|
|
445
|
+
'Invalid ADK artifact list response: artifact at index 1 must be a non-empty string or an object with a non-empty string "filename".',
|
|
446
|
+
);
|
|
447
|
+
});
|
|
448
|
+
|
|
449
|
+
it.each([
|
|
450
|
+
["text", { text: "artifact contents" }],
|
|
451
|
+
[
|
|
452
|
+
"inline data",
|
|
453
|
+
{ inlineData: { mimeType: "image/png", data: "aGVsbG8=" } },
|
|
454
|
+
],
|
|
455
|
+
])("loads valid %s artifacts", async (_label, artifact) => {
|
|
456
|
+
mockFetch.mockResolvedValueOnce(
|
|
457
|
+
new Response(JSON.stringify(artifact), { status: 200 }),
|
|
458
|
+
);
|
|
459
|
+
|
|
460
|
+
const { artifacts } = createAdkSessionAdapter(baseOptions);
|
|
461
|
+
|
|
462
|
+
await expect(artifacts.load("s1", "report.pdf")).resolves.toEqual(artifact);
|
|
463
|
+
});
|
|
464
|
+
|
|
465
|
+
it("rejects an artifact without supported content", async () => {
|
|
466
|
+
mockFetch.mockResolvedValueOnce(
|
|
467
|
+
new Response(JSON.stringify({}), { status: 200 }),
|
|
468
|
+
);
|
|
469
|
+
|
|
470
|
+
const { artifacts } = createAdkSessionAdapter(baseOptions);
|
|
471
|
+
|
|
472
|
+
await expect(artifacts.load("s1", "report.pdf")).rejects.toThrow(
|
|
473
|
+
'Invalid ADK artifact load response: expected an object containing "text" or "inlineData".',
|
|
474
|
+
);
|
|
475
|
+
});
|
|
476
|
+
|
|
477
|
+
it.each([
|
|
478
|
+
[
|
|
479
|
+
"text",
|
|
480
|
+
{ text: 42 },
|
|
481
|
+
'Invalid ADK artifact load response: "text" must be a string when present.',
|
|
482
|
+
],
|
|
483
|
+
[
|
|
484
|
+
"inline data",
|
|
485
|
+
{ inlineData: { mimeType: "image/png" } },
|
|
486
|
+
'Invalid ADK artifact load response: "inlineData" must contain string "mimeType" and "data" fields.',
|
|
487
|
+
],
|
|
488
|
+
])("rejects malformed %s artifact content", async (_label, value, error) => {
|
|
489
|
+
mockFetch.mockResolvedValueOnce(
|
|
490
|
+
new Response(JSON.stringify(value), { status: 200 }),
|
|
491
|
+
);
|
|
492
|
+
|
|
493
|
+
const { artifacts } = createAdkSessionAdapter(baseOptions);
|
|
494
|
+
|
|
495
|
+
await expect(artifacts.load("s1", "report.pdf")).rejects.toThrow(error);
|
|
496
|
+
});
|
|
497
|
+
|
|
498
|
+
it("lists artifact versions", async () => {
|
|
499
|
+
mockFetch.mockResolvedValueOnce(
|
|
500
|
+
new Response(JSON.stringify([0, 1, 2]), { status: 200 }),
|
|
501
|
+
);
|
|
502
|
+
|
|
503
|
+
const { artifacts } = createAdkSessionAdapter(baseOptions);
|
|
504
|
+
|
|
505
|
+
await expect(artifacts.listVersions("s1", "report.pdf")).resolves.toEqual([
|
|
506
|
+
0, 1, 2,
|
|
507
|
+
]);
|
|
508
|
+
});
|
|
509
|
+
|
|
510
|
+
it("rejects an artifact version list that is not an array", async () => {
|
|
511
|
+
mockFetch.mockResolvedValueOnce(
|
|
512
|
+
new Response(JSON.stringify({}), { status: 200 }),
|
|
513
|
+
);
|
|
514
|
+
|
|
515
|
+
const { artifacts } = createAdkSessionAdapter(baseOptions);
|
|
516
|
+
|
|
517
|
+
await expect(artifacts.listVersions("s1", "report.pdf")).rejects.toThrow(
|
|
518
|
+
"Invalid ADK artifact versions response: expected an array of version numbers.",
|
|
519
|
+
);
|
|
520
|
+
});
|
|
521
|
+
|
|
522
|
+
it("rejects malformed artifact version entries", async () => {
|
|
523
|
+
mockFetch.mockResolvedValueOnce(
|
|
524
|
+
new Response(JSON.stringify([0, "1"]), { status: 200 }),
|
|
525
|
+
);
|
|
526
|
+
|
|
527
|
+
const { artifacts } = createAdkSessionAdapter(baseOptions);
|
|
528
|
+
|
|
529
|
+
await expect(artifacts.listVersions("s1", "report.pdf")).rejects.toThrow(
|
|
530
|
+
"Invalid ADK artifact versions response: version at index 1 must be a non-negative integer.",
|
|
531
|
+
);
|
|
532
|
+
});
|
|
533
|
+
});
|
|
534
|
+
|
|
346
535
|
// ── URL construction ──
|
|
347
536
|
|
|
348
537
|
describe("createAdkSessionAdapter - URL construction", () => {
|
package/src/AdkSessionAdapter.ts
CHANGED
|
@@ -57,6 +57,130 @@ type AdkSessionAdapterResult = {
|
|
|
57
57
|
};
|
|
58
58
|
};
|
|
59
59
|
|
|
60
|
+
type AdkSessionResponse = {
|
|
61
|
+
id: string;
|
|
62
|
+
events?: unknown;
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
const isRecord = (value: unknown): value is Record<string, unknown> =>
|
|
66
|
+
typeof value === "object" && value !== null && !Array.isArray(value);
|
|
67
|
+
|
|
68
|
+
const isAdkSessionResponse = (value: unknown): value is AdkSessionResponse => {
|
|
69
|
+
if (!isRecord(value)) return false;
|
|
70
|
+
|
|
71
|
+
const id = value.id;
|
|
72
|
+
return typeof id === "string" && id.length > 0;
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
const parseAdkSessionResponse = (
|
|
76
|
+
value: unknown,
|
|
77
|
+
operation: "create" | "fetch" | "load",
|
|
78
|
+
): AdkSessionResponse => {
|
|
79
|
+
if (!isAdkSessionResponse(value)) {
|
|
80
|
+
throw new Error(
|
|
81
|
+
`Invalid ADK session ${operation} response: expected an object with a non-empty string "id".`,
|
|
82
|
+
);
|
|
83
|
+
}
|
|
84
|
+
return value;
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
const parseAdkSessionListResponse = (value: unknown): AdkSessionResponse[] => {
|
|
88
|
+
if (!Array.isArray(value)) {
|
|
89
|
+
throw new Error(
|
|
90
|
+
"Invalid ADK session list response: expected an array of sessions.",
|
|
91
|
+
);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
return value.map((session, index) => {
|
|
95
|
+
if (!isAdkSessionResponse(session)) {
|
|
96
|
+
throw new Error(
|
|
97
|
+
`Invalid ADK session list response: session at index ${index} must have a non-empty string "id".`,
|
|
98
|
+
);
|
|
99
|
+
}
|
|
100
|
+
return session;
|
|
101
|
+
});
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
const parseAdkArtifactListResponse = (value: unknown): string[] => {
|
|
105
|
+
if (!Array.isArray(value)) {
|
|
106
|
+
throw new Error(
|
|
107
|
+
"Invalid ADK artifact list response: expected an array of artifact names.",
|
|
108
|
+
);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
return value.map((artifact, index) => {
|
|
112
|
+
if (typeof artifact === "string" && artifact.length > 0) {
|
|
113
|
+
return artifact;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
if (isRecord(artifact)) {
|
|
117
|
+
const filename = artifact.filename;
|
|
118
|
+
if (typeof filename === "string" && filename.length > 0) {
|
|
119
|
+
return filename;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
throw new Error(
|
|
124
|
+
`Invalid ADK artifact list response: artifact at index ${index} must be a non-empty string or an object with a non-empty string "filename".`,
|
|
125
|
+
);
|
|
126
|
+
});
|
|
127
|
+
};
|
|
128
|
+
|
|
129
|
+
const parseAdkArtifactResponse = (value: unknown): AdkArtifactData => {
|
|
130
|
+
if (!isRecord(value)) {
|
|
131
|
+
throw new Error(
|
|
132
|
+
'Invalid ADK artifact load response: expected an object containing "text" or "inlineData".',
|
|
133
|
+
);
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
const { text, inlineData } = value;
|
|
137
|
+
if (text === undefined && inlineData === undefined) {
|
|
138
|
+
throw new Error(
|
|
139
|
+
'Invalid ADK artifact load response: expected an object containing "text" or "inlineData".',
|
|
140
|
+
);
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
if (text !== undefined && typeof text !== "string") {
|
|
144
|
+
throw new Error(
|
|
145
|
+
'Invalid ADK artifact load response: "text" must be a string when present.',
|
|
146
|
+
);
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
if (
|
|
150
|
+
inlineData !== undefined &&
|
|
151
|
+
(!isRecord(inlineData) ||
|
|
152
|
+
typeof inlineData.mimeType !== "string" ||
|
|
153
|
+
typeof inlineData.data !== "string")
|
|
154
|
+
) {
|
|
155
|
+
throw new Error(
|
|
156
|
+
'Invalid ADK artifact load response: "inlineData" must contain string "mimeType" and "data" fields.',
|
|
157
|
+
);
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
return value as AdkArtifactData;
|
|
161
|
+
};
|
|
162
|
+
|
|
163
|
+
const parseAdkArtifactVersionsResponse = (value: unknown): number[] => {
|
|
164
|
+
if (!Array.isArray(value)) {
|
|
165
|
+
throw new Error(
|
|
166
|
+
"Invalid ADK artifact versions response: expected an array of version numbers.",
|
|
167
|
+
);
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
return value.map((version, index) => {
|
|
171
|
+
if (
|
|
172
|
+
typeof version !== "number" ||
|
|
173
|
+
!Number.isInteger(version) ||
|
|
174
|
+
version < 0
|
|
175
|
+
) {
|
|
176
|
+
throw new Error(
|
|
177
|
+
`Invalid ADK artifact versions response: version at index ${index} must be a non-negative integer.`,
|
|
178
|
+
);
|
|
179
|
+
}
|
|
180
|
+
return version;
|
|
181
|
+
});
|
|
182
|
+
};
|
|
183
|
+
|
|
60
184
|
/**
|
|
61
185
|
* Creates a `RemoteThreadListAdapter` backed by ADK's session REST API,
|
|
62
186
|
* plus a `load` function that reconstructs messages from session events.
|
|
@@ -96,12 +220,7 @@ export function createAdkSessionAdapter(
|
|
|
96
220
|
if (!res.ok) {
|
|
97
221
|
throw new Error(`Failed to list sessions: ${res.status}`);
|
|
98
222
|
}
|
|
99
|
-
const data = (await res.json())
|
|
100
|
-
id: string;
|
|
101
|
-
app_name?: string;
|
|
102
|
-
user_id?: string;
|
|
103
|
-
last_update_time?: number;
|
|
104
|
-
}>;
|
|
223
|
+
const data = parseAdkSessionListResponse(await res.json());
|
|
105
224
|
|
|
106
225
|
const threads: RemoteThreadMetadata[] = data.map((session) => ({
|
|
107
226
|
status: "regular" as const,
|
|
@@ -125,7 +244,7 @@ export function createAdkSessionAdapter(
|
|
|
125
244
|
if (!res.ok) {
|
|
126
245
|
throw new Error(`Failed to create session: ${res.status}`);
|
|
127
246
|
}
|
|
128
|
-
const session = (await res.json())
|
|
247
|
+
const session = parseAdkSessionResponse(await res.json(), "create");
|
|
129
248
|
return { remoteId: session.id, externalId: session.id };
|
|
130
249
|
},
|
|
131
250
|
|
|
@@ -171,7 +290,7 @@ export function createAdkSessionAdapter(
|
|
|
171
290
|
if (!res.ok) {
|
|
172
291
|
throw new Error(`Session not found: ${res.status}`);
|
|
173
292
|
}
|
|
174
|
-
const session = (await res.json())
|
|
293
|
+
const session = parseAdkSessionResponse(await res.json(), "fetch");
|
|
175
294
|
return {
|
|
176
295
|
status: "regular",
|
|
177
296
|
remoteId: session.id,
|
|
@@ -191,18 +310,23 @@ export function createAdkSessionAdapter(
|
|
|
191
310
|
if (!res.ok) {
|
|
192
311
|
throw new Error(`Failed to load session: ${res.status}`);
|
|
193
312
|
}
|
|
194
|
-
const session = (await res.json())
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
313
|
+
const session = parseAdkSessionResponse(await res.json(), "load");
|
|
314
|
+
|
|
315
|
+
if (session.events !== undefined && !Array.isArray(session.events)) {
|
|
316
|
+
throw new Error(
|
|
317
|
+
'Invalid ADK session load response: expected "events" to be an array when present.',
|
|
318
|
+
);
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
const events = session.events as AdkEvent[] | undefined;
|
|
198
322
|
|
|
199
|
-
if (!
|
|
323
|
+
if (!events?.length) {
|
|
200
324
|
return { messages: [] };
|
|
201
325
|
}
|
|
202
326
|
|
|
203
327
|
const accumulator = new AdkEventAccumulator();
|
|
204
328
|
let messages: AdkMessage[] = [];
|
|
205
|
-
for (const event of
|
|
329
|
+
for (const event of events) {
|
|
206
330
|
messages = accumulator.processEvent(event);
|
|
207
331
|
}
|
|
208
332
|
return { messages };
|
|
@@ -216,8 +340,7 @@ export function createAdkSessionAdapter(
|
|
|
216
340
|
const headers = await getHeaders();
|
|
217
341
|
const res = await fetch(artifactBaseUrl(sessionId), { headers });
|
|
218
342
|
if (!res.ok) throw new Error(`Failed to list artifacts: ${res.status}`);
|
|
219
|
-
|
|
220
|
-
return data.map((a) => a.filename);
|
|
343
|
+
return parseAdkArtifactListResponse(await res.json());
|
|
221
344
|
},
|
|
222
345
|
|
|
223
346
|
async load(sessionId, artifactName, version?) {
|
|
@@ -226,7 +349,7 @@ export function createAdkSessionAdapter(
|
|
|
226
349
|
if (version != null) url += `/versions/${version}`;
|
|
227
350
|
const res = await fetch(url, { headers });
|
|
228
351
|
if (!res.ok) throw new Error(`Failed to load artifact: ${res.status}`);
|
|
229
|
-
return (await res.json())
|
|
352
|
+
return parseAdkArtifactResponse(await res.json());
|
|
230
353
|
},
|
|
231
354
|
|
|
232
355
|
async listVersions(sessionId, artifactName) {
|
|
@@ -236,7 +359,7 @@ export function createAdkSessionAdapter(
|
|
|
236
359
|
if (!res.ok) {
|
|
237
360
|
throw new Error(`Failed to list artifact versions: ${res.status}`);
|
|
238
361
|
}
|
|
239
|
-
return (await res.json())
|
|
362
|
+
return parseAdkArtifactVersionsResponse(await res.json());
|
|
240
363
|
},
|
|
241
364
|
|
|
242
365
|
async delete(sessionId, artifactName) {
|
package/src/useAdkMessages.ts
CHANGED
package/src/useAdkRuntime.ts
CHANGED
|
@@ -356,7 +356,7 @@ const useAdkRuntimeImpl = (options: UseAdkRuntimeOptions) => {
|
|
|
356
356
|
setMessages(nextMessages);
|
|
357
357
|
return;
|
|
358
358
|
}
|
|
359
|
-
const externalId = aui.threadListItem
|
|
359
|
+
const externalId = aui.threadListItem.getState().externalId;
|
|
360
360
|
const checkpointId = externalId
|
|
361
361
|
? await getCheckpointId(externalId, truncated)
|
|
362
362
|
: null;
|
|
@@ -397,7 +397,7 @@ const useAdkRuntimeImpl = (options: UseAdkRuntimeOptions) => {
|
|
|
397
397
|
parentId,
|
|
398
398
|
);
|
|
399
399
|
replaceMessages(truncated);
|
|
400
|
-
const externalId = aui.threadListItem
|
|
400
|
+
const externalId = aui.threadListItem.getState().externalId;
|
|
401
401
|
const checkpointId = externalId
|
|
402
402
|
? await getCheckpointId(externalId, truncated)
|
|
403
403
|
: null;
|
|
@@ -447,7 +447,7 @@ const useAdkRuntimeImpl = (options: UseAdkRuntimeOptions) => {
|
|
|
447
447
|
const loadFn = loadRef.current;
|
|
448
448
|
if (!loadFn) return;
|
|
449
449
|
|
|
450
|
-
const externalId = aui.threadListItem
|
|
450
|
+
const externalId = aui.threadListItem.getState().externalId;
|
|
451
451
|
if (externalId == null) return;
|
|
452
452
|
|
|
453
453
|
loadFn(externalId).then(
|
|
@@ -477,7 +477,7 @@ export const useAdkRuntime = ({
|
|
|
477
477
|
cloud,
|
|
478
478
|
create: async () => {
|
|
479
479
|
if (create) return create();
|
|
480
|
-
if (aui.threadListItem.source) return aui.threadListItem
|
|
480
|
+
if (aui.threadListItem.source) return aui.threadListItem.initialize();
|
|
481
481
|
return { externalId: undefined };
|
|
482
482
|
},
|
|
483
483
|
delete: deleteFn,
|