@assistant-ui/react-google-adk 0.0.23 → 0.0.25
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/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 AgentbaseAI Inc.
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -23,13 +23,14 @@ function createAdkApiRoute(options) {
|
|
|
23
23
|
const newMessage = toAdkContent(parsed);
|
|
24
24
|
const userId = typeof options.userId === "function" ? await options.userId(req) : options.userId;
|
|
25
25
|
const sessionId = typeof options.sessionId === "function" ? await options.sessionId(req) : options.sessionId;
|
|
26
|
-
|
|
26
|
+
const events = options.runner.runAsync({
|
|
27
27
|
userId,
|
|
28
28
|
sessionId,
|
|
29
29
|
newMessage,
|
|
30
30
|
...parsed.stateDelta != null && { stateDelta: parsed.stateDelta },
|
|
31
31
|
...parsed.config.runConfig != null && { runConfig: parsed.config.runConfig }
|
|
32
|
-
})
|
|
32
|
+
});
|
|
33
|
+
return adkEventStream(events, options.onError ? { onError: options.onError } : void 0);
|
|
33
34
|
};
|
|
34
35
|
}
|
|
35
36
|
//#endregion
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createAdkApiRoute.js","names":[],"sources":["../../src/server/createAdkApiRoute.ts"],"sourcesContent":["import { parseAdkRequest, toAdkContent } from \"./parseAdkRequest\";\nimport { adkEventStream, type AdkEventStreamOptions } from \"./adkEventStream\";\n\n/**\n * Loose runner type matching the ADK SDK's Runner interface.\n * Avoids requiring `@google/adk` as a dependency.\n */\ntype AdkRunner = {\n runAsync(\n options: Record<string, unknown>,\n ): AsyncGenerator<any, void, undefined>;\n};\n\nexport type CreateAdkApiRouteOptions = {\n /**\n * ADK Runner instance.\n */\n runner: AdkRunner;\n\n /**\n * User ID to use for the ADK session. Can be a static string\n * or a function that extracts it from the request.\n */\n userId: string | ((req: Request) => string | Promise<string>);\n\n /**\n * Session ID to use. Can be a static string or a function\n * that extracts it from the request (e.g. from query params or headers).\n */\n sessionId: string | ((req: Request) => string | Promise<string>);\n\n /**\n * Error handler for stream errors.\n */\n onError?: AdkEventStreamOptions[\"onError\"];\n};\n\n/**\n * Creates a request handler that combines `parseAdkRequest`, `toAdkContent`,\n * and `adkEventStream` into a single function.\n *\n * @example Next.js App Router\n * ```ts\n * import { createAdkApiRoute } from '@assistant-ui/react-google-adk/server';\n * import { runner } from './agent';\n *\n * export const POST = createAdkApiRoute({\n * runner,\n * userId: \"default-user\",\n * sessionId: (req) => new URL(req.url).searchParams.get(\"sessionId\") ?? \"default\",\n * });\n * ```\n */\nexport function createAdkApiRoute(\n options: CreateAdkApiRouteOptions,\n): (req: Request) => Promise<Response> {\n return async (req: Request): Promise<Response> => {\n const parsed = await parseAdkRequest(req);\n const newMessage = toAdkContent(parsed);\n\n const userId =\n typeof options.userId === \"function\"\n ? await options.userId(req)\n : options.userId;\n\n const sessionId =\n typeof options.sessionId === \"function\"\n ? await options.sessionId(req)\n : options.sessionId;\n\n const events = options.runner.runAsync({\n userId,\n sessionId,\n newMessage,\n ...(parsed.stateDelta != null && { stateDelta: parsed.stateDelta }),\n ...(parsed.config.runConfig != null && {\n runConfig: parsed.config.runConfig,\n }),\n });\n\n return adkEventStream(\n events,\n options.onError ? { onError: options.onError } : undefined,\n );\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAqDA,SAAgB,kBACd,SACqC;CACrC,OAAO,OAAO,QAAoC;EAChD,MAAM,SAAS,MAAM,gBAAgB,GAAG;EACxC,MAAM,aAAa,aAAa,MAAM;EAEtC,MAAM,SACJ,OAAO,QAAQ,WAAW,aACtB,MAAM,QAAQ,OAAO,GAAG,IACxB,QAAQ;EAEd,MAAM,YACJ,OAAO,QAAQ,cAAc,aACzB,MAAM,QAAQ,UAAU,GAAG,IAC3B,QAAQ;
|
|
1
|
+
{"version":3,"file":"createAdkApiRoute.js","names":[],"sources":["../../src/server/createAdkApiRoute.ts"],"sourcesContent":["import { parseAdkRequest, toAdkContent } from \"./parseAdkRequest\";\nimport { adkEventStream, type AdkEventStreamOptions } from \"./adkEventStream\";\n\n/**\n * Loose runner type matching the ADK SDK's Runner interface.\n * Avoids requiring `@google/adk` as a dependency.\n */\ntype AdkRunner = {\n runAsync(\n options: Record<string, unknown>,\n ): AsyncGenerator<any, void, undefined>;\n};\n\nexport type CreateAdkApiRouteOptions = {\n /**\n * ADK Runner instance.\n */\n runner: AdkRunner;\n\n /**\n * User ID to use for the ADK session. Can be a static string\n * or a function that extracts it from the request.\n */\n userId: string | ((req: Request) => string | Promise<string>);\n\n /**\n * Session ID to use. Can be a static string or a function\n * that extracts it from the request (e.g. from query params or headers).\n */\n sessionId: string | ((req: Request) => string | Promise<string>);\n\n /**\n * Error handler for stream errors.\n */\n onError?: AdkEventStreamOptions[\"onError\"];\n};\n\n/**\n * Creates a request handler that combines `parseAdkRequest`, `toAdkContent`,\n * and `adkEventStream` into a single function.\n *\n * @example Next.js App Router\n * ```ts\n * import { createAdkApiRoute } from '@assistant-ui/react-google-adk/server';\n * import { runner } from './agent';\n *\n * export const POST = createAdkApiRoute({\n * runner,\n * userId: \"default-user\",\n * sessionId: (req) => new URL(req.url).searchParams.get(\"sessionId\") ?? \"default\",\n * });\n * ```\n */\nexport function createAdkApiRoute(\n options: CreateAdkApiRouteOptions,\n): (req: Request) => Promise<Response> {\n return async (req: Request): Promise<Response> => {\n const parsed = await parseAdkRequest(req);\n const newMessage = toAdkContent(parsed);\n\n const userId =\n typeof options.userId === \"function\"\n ? await options.userId(req)\n : options.userId;\n\n const sessionId =\n typeof options.sessionId === \"function\"\n ? await options.sessionId(req)\n : options.sessionId;\n\n const events = options.runner.runAsync({\n userId,\n sessionId,\n newMessage,\n ...(parsed.stateDelta != null && { stateDelta: parsed.stateDelta }),\n ...(parsed.config.runConfig != null && {\n runConfig: parsed.config.runConfig,\n }),\n });\n\n return adkEventStream(\n events,\n options.onError ? { onError: options.onError } : undefined,\n );\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAqDA,SAAgB,kBACd,SACqC;CACrC,OAAO,OAAO,QAAoC;EAChD,MAAM,SAAS,MAAM,gBAAgB,GAAG;EACxC,MAAM,aAAa,aAAa,MAAM;EAEtC,MAAM,SACJ,OAAO,QAAQ,WAAW,aACtB,MAAM,QAAQ,OAAO,GAAG,IACxB,QAAQ;EAEd,MAAM,YACJ,OAAO,QAAQ,cAAc,aACzB,MAAM,QAAQ,UAAU,GAAG,IAC3B,QAAQ;EAEd,MAAM,SAAS,QAAQ,OAAO,SAAS;GACrC;GACA;GACA;GACA,GAAI,OAAO,cAAc,QAAQ,EAAE,YAAY,OAAO,WAAW;GACjE,GAAI,OAAO,OAAO,aAAa,QAAQ,EACrC,WAAW,OAAO,OAAO,UAC3B;EACF,CAAC;EAED,OAAO,eACL,QACA,QAAQ,UAAU,EAAE,SAAS,QAAQ,QAAQ,IAAI,KAAA,CACnD;CACF;AACF"}
|
package/dist/structuredEvents.js
CHANGED
|
@@ -14,14 +14,16 @@ function toAdkStructuredEvents(event) {
|
|
|
14
14
|
}
|
|
15
15
|
const parts = event.content?.parts;
|
|
16
16
|
if (parts) for (const part of parts) {
|
|
17
|
-
if (part.text != null)
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
17
|
+
if (part.text != null) {
|
|
18
|
+
if (part.thought) result.push({
|
|
19
|
+
type: "thought",
|
|
20
|
+
content: part.text
|
|
21
|
+
});
|
|
22
|
+
else result.push({
|
|
23
|
+
type: "content",
|
|
24
|
+
content: part.text
|
|
25
|
+
});
|
|
26
|
+
}
|
|
25
27
|
if (part.functionCall) {
|
|
26
28
|
const call = {
|
|
27
29
|
type: "tool_call",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"structuredEvents.js","names":[],"sources":["../src/structuredEvents.ts"],"sourcesContent":["import type { AdkEvent, AdkStructuredEvent } from \"./types\";\nimport { isFinalResponse } from \"./AdkEventAccumulator\";\n\n/**\n * Converts a raw `AdkEvent` into an array of structured, typed events.\n * Useful for building custom event renderers.\n */\nexport function toAdkStructuredEvents(event: AdkEvent): AdkStructuredEvent[] {\n const result: AdkStructuredEvent[] = [];\n\n if (event.errorCode || event.errorMessage) {\n const err: AdkStructuredEvent & { type: \"error\" } = { type: \"error\" };\n if (event.errorCode != null) err.errorCode = event.errorCode;\n if (event.errorMessage != null) err.errorMessage = event.errorMessage;\n result.push(err);\n }\n\n const parts = event.content?.parts;\n if (parts) {\n for (const part of parts) {\n if (part.text != null) {\n if (part.thought) {\n result.push({ type: \"thought\", content: part.text });\n } else {\n result.push({ type: \"content\", content: part.text });\n }\n }\n if (part.functionCall) {\n const call: AdkStructuredEvent & { type: \"tool_call\" } = {\n type: \"tool_call\",\n call: { name: part.functionCall.name, args: part.functionCall.args },\n };\n if (part.functionCall.id != null) call.call.id = part.functionCall.id;\n result.push(call);\n }\n if (part.functionResponse) {\n const tr: AdkStructuredEvent & { type: \"tool_result\" } = {\n type: \"tool_result\",\n result: {\n name: part.functionResponse.name,\n response: part.functionResponse.response,\n },\n };\n if (part.functionResponse.id != null)\n tr.result.id = part.functionResponse.id;\n result.push(tr);\n }\n if (part.executableCode) {\n const ce: AdkStructuredEvent & { type: \"call_code\" } = {\n type: \"call_code\",\n code: { code: part.executableCode.code },\n };\n if (part.executableCode.language != null)\n ce.code.language = part.executableCode.language;\n result.push(ce);\n }\n if (part.codeExecutionResult) {\n const cr: AdkStructuredEvent & { type: \"code_result\" } = {\n type: \"code_result\",\n result: { output: part.codeExecutionResult.output },\n };\n if (part.codeExecutionResult.outcome != null)\n cr.result.outcome = part.codeExecutionResult.outcome;\n result.push(cr);\n }\n }\n }\n\n if (event.actions?.requestedToolConfirmations) {\n result.push({\n type: \"tool_confirmation\",\n confirmations: event.actions.requestedToolConfirmations,\n });\n }\n\n if (isFinalResponse(event) && result.length === 0) {\n result.push({ type: \"finished\" });\n }\n\n return result;\n}\n"],"mappings":";;;;;;AAOA,SAAgB,sBAAsB,OAAuC;CAC3E,MAAM,SAA+B,CAAC;CAEtC,IAAI,MAAM,aAAa,MAAM,cAAc;EACzC,MAAM,MAA8C,EAAE,MAAM,QAAQ;EACpE,IAAI,MAAM,aAAa,MAAM,IAAI,YAAY,MAAM;EACnD,IAAI,MAAM,gBAAgB,MAAM,IAAI,eAAe,MAAM;EACzD,OAAO,KAAK,GAAG;CACjB;CAEA,MAAM,QAAQ,MAAM,SAAS;CAC7B,IAAI,OACF,KAAK,MAAM,QAAQ,OAAO;EACxB,IAAI,KAAK,QAAQ,
|
|
1
|
+
{"version":3,"file":"structuredEvents.js","names":[],"sources":["../src/structuredEvents.ts"],"sourcesContent":["import type { AdkEvent, AdkStructuredEvent } from \"./types\";\nimport { isFinalResponse } from \"./AdkEventAccumulator\";\n\n/**\n * Converts a raw `AdkEvent` into an array of structured, typed events.\n * Useful for building custom event renderers.\n */\nexport function toAdkStructuredEvents(event: AdkEvent): AdkStructuredEvent[] {\n const result: AdkStructuredEvent[] = [];\n\n if (event.errorCode || event.errorMessage) {\n const err: AdkStructuredEvent & { type: \"error\" } = { type: \"error\" };\n if (event.errorCode != null) err.errorCode = event.errorCode;\n if (event.errorMessage != null) err.errorMessage = event.errorMessage;\n result.push(err);\n }\n\n const parts = event.content?.parts;\n if (parts) {\n for (const part of parts) {\n if (part.text != null) {\n if (part.thought) {\n result.push({ type: \"thought\", content: part.text });\n } else {\n result.push({ type: \"content\", content: part.text });\n }\n }\n if (part.functionCall) {\n const call: AdkStructuredEvent & { type: \"tool_call\" } = {\n type: \"tool_call\",\n call: { name: part.functionCall.name, args: part.functionCall.args },\n };\n if (part.functionCall.id != null) call.call.id = part.functionCall.id;\n result.push(call);\n }\n if (part.functionResponse) {\n const tr: AdkStructuredEvent & { type: \"tool_result\" } = {\n type: \"tool_result\",\n result: {\n name: part.functionResponse.name,\n response: part.functionResponse.response,\n },\n };\n if (part.functionResponse.id != null)\n tr.result.id = part.functionResponse.id;\n result.push(tr);\n }\n if (part.executableCode) {\n const ce: AdkStructuredEvent & { type: \"call_code\" } = {\n type: \"call_code\",\n code: { code: part.executableCode.code },\n };\n if (part.executableCode.language != null)\n ce.code.language = part.executableCode.language;\n result.push(ce);\n }\n if (part.codeExecutionResult) {\n const cr: AdkStructuredEvent & { type: \"code_result\" } = {\n type: \"code_result\",\n result: { output: part.codeExecutionResult.output },\n };\n if (part.codeExecutionResult.outcome != null)\n cr.result.outcome = part.codeExecutionResult.outcome;\n result.push(cr);\n }\n }\n }\n\n if (event.actions?.requestedToolConfirmations) {\n result.push({\n type: \"tool_confirmation\",\n confirmations: event.actions.requestedToolConfirmations,\n });\n }\n\n if (isFinalResponse(event) && result.length === 0) {\n result.push({ type: \"finished\" });\n }\n\n return result;\n}\n"],"mappings":";;;;;;AAOA,SAAgB,sBAAsB,OAAuC;CAC3E,MAAM,SAA+B,CAAC;CAEtC,IAAI,MAAM,aAAa,MAAM,cAAc;EACzC,MAAM,MAA8C,EAAE,MAAM,QAAQ;EACpE,IAAI,MAAM,aAAa,MAAM,IAAI,YAAY,MAAM;EACnD,IAAI,MAAM,gBAAgB,MAAM,IAAI,eAAe,MAAM;EACzD,OAAO,KAAK,GAAG;CACjB;CAEA,MAAM,QAAQ,MAAM,SAAS;CAC7B,IAAI,OACF,KAAK,MAAM,QAAQ,OAAO;EACxB,IAAI,KAAK,QAAQ,MAAM;GACrB,IAAI,KAAK,SACP,OAAO,KAAK;IAAE,MAAM;IAAW,SAAS,KAAK;GAAK,CAAC;QAEnD,OAAO,KAAK;IAAE,MAAM;IAAW,SAAS,KAAK;GAAK,CAAC;EAEvD;EACA,IAAI,KAAK,cAAc;GACrB,MAAM,OAAmD;IACvD,MAAM;IACN,MAAM;KAAE,MAAM,KAAK,aAAa;KAAM,MAAM,KAAK,aAAa;IAAK;GACrE;GACA,IAAI,KAAK,aAAa,MAAM,MAAM,KAAK,KAAK,KAAK,KAAK,aAAa;GACnE,OAAO,KAAK,IAAI;EAClB;EACA,IAAI,KAAK,kBAAkB;GACzB,MAAM,KAAmD;IACvD,MAAM;IACN,QAAQ;KACN,MAAM,KAAK,iBAAiB;KAC5B,UAAU,KAAK,iBAAiB;IAClC;GACF;GACA,IAAI,KAAK,iBAAiB,MAAM,MAC9B,GAAG,OAAO,KAAK,KAAK,iBAAiB;GACvC,OAAO,KAAK,EAAE;EAChB;EACA,IAAI,KAAK,gBAAgB;GACvB,MAAM,KAAiD;IACrD,MAAM;IACN,MAAM,EAAE,MAAM,KAAK,eAAe,KAAK;GACzC;GACA,IAAI,KAAK,eAAe,YAAY,MAClC,GAAG,KAAK,WAAW,KAAK,eAAe;GACzC,OAAO,KAAK,EAAE;EAChB;EACA,IAAI,KAAK,qBAAqB;GAC5B,MAAM,KAAmD;IACvD,MAAM;IACN,QAAQ,EAAE,QAAQ,KAAK,oBAAoB,OAAO;GACpD;GACA,IAAI,KAAK,oBAAoB,WAAW,MACtC,GAAG,OAAO,UAAU,KAAK,oBAAoB;GAC/C,OAAO,KAAK,EAAE;EAChB;CACF;CAGF,IAAI,MAAM,SAAS,4BACjB,OAAO,KAAK;EACV,MAAM;EACN,eAAe,MAAM,QAAQ;CAC/B,CAAC;CAGH,IAAI,gBAAgB,KAAK,KAAK,OAAO,WAAW,GAC9C,OAAO,KAAK,EAAE,MAAM,WAAW,CAAC;CAGlC,OAAO;AACT"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@assistant-ui/react-google-adk",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.25",
|
|
4
4
|
"description": "Google ADK adapter for assistant-ui",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"google-adk",
|
|
@@ -33,16 +33,11 @@
|
|
|
33
33
|
"README.md"
|
|
34
34
|
],
|
|
35
35
|
"sideEffects": false,
|
|
36
|
-
"scripts": {
|
|
37
|
-
"build": "aui-build",
|
|
38
|
-
"test": "vitest run",
|
|
39
|
-
"test:watch": "vitest"
|
|
40
|
-
},
|
|
41
36
|
"dependencies": {
|
|
42
|
-
"@assistant-ui/core": "^0.3.
|
|
43
|
-
"@assistant-ui/store": "^0.3.
|
|
37
|
+
"@assistant-ui/core": "^0.3.11",
|
|
38
|
+
"@assistant-ui/store": "^0.3.8",
|
|
44
39
|
"assistant-cloud": "*",
|
|
45
|
-
"assistant-stream": "^0.3.
|
|
40
|
+
"assistant-stream": "^0.3.37",
|
|
46
41
|
"uuid": "^14.0.1"
|
|
47
42
|
},
|
|
48
43
|
"peerDependencies": {
|
|
@@ -59,14 +54,13 @@
|
|
|
59
54
|
}
|
|
60
55
|
},
|
|
61
56
|
"devDependencies": {
|
|
62
|
-
"@assistant-ui/x-buildutils": "workspace:*",
|
|
63
57
|
"@testing-library/dom": "^10.4.1",
|
|
64
58
|
"@testing-library/react": "^16.3.2",
|
|
65
|
-
"@types/react": "^19.2.
|
|
66
|
-
"
|
|
67
|
-
"jsdom": "^29.1.1",
|
|
59
|
+
"@types/react": "^19.2.18",
|
|
60
|
+
"jsdom": "^30.0.1",
|
|
68
61
|
"react": "^19.2.8",
|
|
69
|
-
"vitest": "^4.1.10"
|
|
62
|
+
"vitest": "^4.1.10",
|
|
63
|
+
"@assistant-ui/x-buildutils": "0.0.22"
|
|
70
64
|
},
|
|
71
65
|
"publishConfig": {
|
|
72
66
|
"access": "public",
|
|
@@ -80,5 +74,10 @@
|
|
|
80
74
|
},
|
|
81
75
|
"bugs": {
|
|
82
76
|
"url": "https://github.com/assistant-ui/assistant-ui/issues"
|
|
77
|
+
},
|
|
78
|
+
"scripts": {
|
|
79
|
+
"build": "aui-build",
|
|
80
|
+
"test": "vitest run",
|
|
81
|
+
"test:watch": "vitest"
|
|
83
82
|
}
|
|
84
|
-
}
|
|
83
|
+
}
|