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

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.
Files changed (63) hide show
  1. package/README.md +15 -128
  2. package/dist/AdkClient.d.ts +30 -26
  3. package/dist/AdkClient.d.ts.map +1 -1
  4. package/dist/AdkClient.js +131 -165
  5. package/dist/AdkClient.js.map +1 -1
  6. package/dist/AdkEventAccumulator.d.ts +43 -39
  7. package/dist/AdkEventAccumulator.d.ts.map +1 -1
  8. package/dist/AdkEventAccumulator.js +446 -531
  9. package/dist/AdkEventAccumulator.js.map +1 -1
  10. package/dist/AdkSessionAdapter.d.ts +40 -37
  11. package/dist/AdkSessionAdapter.d.ts.map +1 -1
  12. package/dist/AdkSessionAdapter.js +134 -155
  13. package/dist/AdkSessionAdapter.js.map +1 -1
  14. package/dist/contentToParts.d.ts +6 -2
  15. package/dist/contentToParts.d.ts.map +1 -1
  16. package/dist/contentToParts.js +37 -34
  17. package/dist/contentToParts.js.map +1 -1
  18. package/dist/convertAdkMessages.d.ts +7 -3
  19. package/dist/convertAdkMessages.d.ts.map +1 -1
  20. package/dist/convertAdkMessages.js +93 -86
  21. package/dist/convertAdkMessages.js.map +1 -1
  22. package/dist/hooks.d.ts +38 -34
  23. package/dist/hooks.d.ts.map +1 -1
  24. package/dist/hooks.js +132 -155
  25. package/dist/hooks.js.map +1 -1
  26. package/dist/index.d.ts +10 -11
  27. package/dist/index.js +10 -10
  28. package/dist/server/adkEventStream.d.ts +27 -25
  29. package/dist/server/adkEventStream.d.ts.map +1 -1
  30. package/dist/server/adkEventStream.js +91 -126
  31. package/dist/server/adkEventStream.js.map +1 -1
  32. package/dist/server/createAdkApiRoute.d.ts +26 -23
  33. package/dist/server/createAdkApiRoute.d.ts.map +1 -1
  34. package/dist/server/createAdkApiRoute.js +34 -37
  35. package/dist/server/createAdkApiRoute.js.map +1 -1
  36. package/dist/server/index.d.ts +4 -4
  37. package/dist/server/index.js +4 -4
  38. package/dist/server/parseAdkRequest.d.ts +21 -18
  39. package/dist/server/parseAdkRequest.d.ts.map +1 -1
  40. package/dist/server/parseAdkRequest.js +80 -88
  41. package/dist/server/parseAdkRequest.js.map +1 -1
  42. package/dist/structuredEvents.d.ts +6 -2
  43. package/dist/structuredEvents.d.ts.map +1 -1
  44. package/dist/structuredEvents.js +70 -75
  45. package/dist/structuredEvents.js.map +1 -1
  46. package/dist/types.d.ts +231 -227
  47. package/dist/types.d.ts.map +1 -1
  48. package/dist/types.js +15 -12
  49. package/dist/types.js.map +1 -1
  50. package/dist/useAdkMessages.d.ts +32 -25
  51. package/dist/useAdkMessages.d.ts.map +1 -1
  52. package/dist/useAdkMessages.js +155 -182
  53. package/dist/useAdkMessages.js.map +1 -1
  54. package/dist/useAdkRuntime.d.ts +43 -34
  55. package/dist/useAdkRuntime.d.ts.map +1 -1
  56. package/dist/useAdkRuntime.js +219 -273
  57. package/dist/useAdkRuntime.js.map +1 -1
  58. package/package.json +8 -8
  59. package/src/useAdkRuntime.ts +6 -2
  60. package/dist/index.d.ts.map +0 -1
  61. package/dist/index.js.map +0 -1
  62. package/dist/server/index.d.ts.map +0 -1
  63. package/dist/server/index.js.map +0 -1
@@ -1,93 +1,85 @@
1
+ //#region src/server/parseAdkRequest.ts
1
2
  /**
2
- * Parses an incoming HTTP request into a structured ADK request.
3
- *
4
- * Supports two request shapes:
5
- *
6
- * 1. User message:
7
- * ```json
8
- * { "message": "Hello", "runConfig": {}, "stateDelta": {} }
9
- * ```
10
- *
11
- * 2. Tool result:
12
- * ```json
13
- * {
14
- * "type": "tool-result",
15
- * "toolCallId": "call_123",
16
- * "toolName": "search",
17
- * "result": { ... },
18
- * "isError": false
19
- * }
20
- * ```
21
- */
22
- export const parseAdkRequest = async (request) => {
23
- let body;
24
- try {
25
- body = (await request.json());
26
- }
27
- catch {
28
- throw new Error("Invalid JSON in request body");
29
- }
30
- if (!body || typeof body !== "object" || Array.isArray(body)) {
31
- throw new Error("Request body must be a JSON object");
32
- }
33
- const config = {};
34
- if (body.runConfig !== undefined)
35
- config.runConfig = body.runConfig;
36
- if (body.checkpointId !== undefined)
37
- config.checkpointId = body.checkpointId;
38
- const stateDelta = body.stateDelta;
39
- if (body.type === "tool-result") {
40
- return {
41
- type: "tool-result",
42
- toolCallId: body.toolCallId ?? "",
43
- toolName: body.toolName ?? "",
44
- result: body.result,
45
- isError: body.isError ?? false,
46
- config,
47
- ...(stateDelta != null && { stateDelta }),
48
- };
49
- }
50
- return {
51
- type: "message",
52
- text: body.message ?? "",
53
- ...(body.parts != null && {
54
- parts: body.parts,
55
- }),
56
- config,
57
- ...(stateDelta != null && { stateDelta }),
58
- };
3
+ * Parses an incoming HTTP request into a structured ADK request.
4
+ *
5
+ * Supports two request shapes:
6
+ *
7
+ * 1. User message:
8
+ * ```json
9
+ * { "message": "Hello", "runConfig": {}, "stateDelta": {} }
10
+ * ```
11
+ *
12
+ * 2. Tool result:
13
+ * ```json
14
+ * {
15
+ * "type": "tool-result",
16
+ * "toolCallId": "call_123",
17
+ * "toolName": "search",
18
+ * "result": { ... },
19
+ * "isError": false
20
+ * }
21
+ * ```
22
+ */
23
+ const parseAdkRequest = async (request) => {
24
+ let body;
25
+ try {
26
+ body = await request.json();
27
+ } catch {
28
+ throw new Error("Invalid JSON in request body");
29
+ }
30
+ if (!body || typeof body !== "object" || Array.isArray(body)) throw new Error("Request body must be a JSON object");
31
+ const config = {};
32
+ if (body.runConfig !== void 0) config.runConfig = body.runConfig;
33
+ if (body.checkpointId !== void 0) config.checkpointId = body.checkpointId;
34
+ const stateDelta = body.stateDelta;
35
+ if (body.type === "tool-result") return {
36
+ type: "tool-result",
37
+ toolCallId: body.toolCallId ?? "",
38
+ toolName: body.toolName ?? "",
39
+ result: body.result,
40
+ isError: body.isError ?? false,
41
+ config,
42
+ ...stateDelta != null && { stateDelta }
43
+ };
44
+ return {
45
+ type: "message",
46
+ text: body.message ?? "",
47
+ ...body.parts != null && { parts: body.parts },
48
+ config,
49
+ ...stateDelta != null && { stateDelta }
50
+ };
59
51
  };
60
52
  /**
61
- * Converts a parsed ADK request into a Google GenAI Content object
62
- * suitable for `Runner.runAsync({ newMessage })`.
63
- *
64
- * @example
65
- * ```ts
66
- * const parsed = await parseAdkRequest(req);
67
- * const newMessage = toAdkContent(parsed);
68
- * const events = runner.runAsync({ userId, sessionId, newMessage, stateDelta: parsed.stateDelta });
69
- * return adkEventStream(events);
70
- * ```
71
- */
72
- export const toAdkContent = (parsed) => {
73
- if (parsed.type === "tool-result") {
74
- return {
75
- role: "user",
76
- parts: [
77
- {
78
- functionResponse: {
79
- name: parsed.toolName,
80
- id: parsed.toolCallId,
81
- response: parsed.result,
82
- },
83
- },
84
- ],
85
- };
86
- }
87
- // If raw parts are provided (multimodal), use them directly
88
- if (parsed.parts?.length) {
89
- return { role: "user", parts: parsed.parts };
90
- }
91
- return { role: "user", parts: [{ text: parsed.text }] };
53
+ * Converts a parsed ADK request into a Google GenAI Content object
54
+ * suitable for `Runner.runAsync({ newMessage })`.
55
+ *
56
+ * @example
57
+ * ```ts
58
+ * const parsed = await parseAdkRequest(req);
59
+ * const newMessage = toAdkContent(parsed);
60
+ * const events = runner.runAsync({ userId, sessionId, newMessage, stateDelta: parsed.stateDelta });
61
+ * return adkEventStream(events);
62
+ * ```
63
+ */
64
+ const toAdkContent = (parsed) => {
65
+ if (parsed.type === "tool-result") return {
66
+ role: "user",
67
+ parts: [{ functionResponse: {
68
+ name: parsed.toolName,
69
+ id: parsed.toolCallId,
70
+ response: parsed.result
71
+ } }]
72
+ };
73
+ if (parsed.parts?.length) return {
74
+ role: "user",
75
+ parts: parsed.parts
76
+ };
77
+ return {
78
+ role: "user",
79
+ parts: [{ text: parsed.text }]
80
+ };
92
81
  };
82
+ //#endregion
83
+ export { parseAdkRequest, toAdkContent };
84
+
93
85
  //# sourceMappingURL=parseAdkRequest.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"parseAdkRequest.js","sourceRoot":"","s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I,CAAC,OAAkB,IAAI,EAAE;QACpC,GAAG,CAAC,IAAI,CAAC,KAAK,IAAI,IAAI,IAAI;YACxB,KAAK,EAAE,IAAI,CAAC,KAAuC;SACpD,CAAC;QACF,MAAM;QACN,GAAG,CAAC,UAAU,IAAI,IAAI,IAAI,EAAE,UAAU,EAAE,CAAC;KAC1C,CAAC;AACJ,CAAC,CAAC;AAEF;;;;;;;;;;;GAWG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG,CAC1B,MAAwB,EACiC,EAAE;IAC3D,IAAI,MAAM,CAAC,IAAI,KAAK,aAAa,EAAE,CAAC;QAClC,OAAO;YACL,IAAI,EAAE,MAAM;YACZ,KAAK,EAAE;gBACL;oBACE,gBAAgB,EAAE;wBAChB,IAAI,EAAE,MAAM,CAAC,QAAQ;wBACrB,EAAE,EAAE,MAAM,CAAC,UAAU;wBACrB,QAAQ,EAAE,MAAM,CAAC,MAAM;qBACxB;iBACF;aACF;SACF,CAAC;IACJ,CAAC;IAED,4DAA4D;IAC5D,IAAI,MAAM,CAAC,KAAK,EAAE,MAAM,EAAE,CAAC;QACzB,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,CAAC,KAAK,EAAE,CAAC;IAC/C,CAAC;IAED,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,EAAE,IAAI,EAAE,MAAM,CAAC,IAAI,EAAE,CAAC,EAAE,CAAC;AAC1D,CAAC,CAAC"}
1
+ {"version":3,"file":"parseAdkRequest.js","names":[],"sources":["../../src/server/parseAdkRequest.ts"],"sourcesContent":["import type { AdkSendMessageConfig } from \"../types\";\n\ntype ParsedAdkRequest =\n | {\n type: \"message\";\n text: string;\n parts?: Array<Record<string, unknown>> | undefined;\n config: AdkSendMessageConfig;\n stateDelta?: Record<string, unknown> | undefined;\n }\n | {\n type: \"tool-result\";\n toolCallId: string;\n toolName: string;\n result: unknown;\n isError: boolean;\n config: AdkSendMessageConfig;\n stateDelta?: Record<string, unknown> | undefined;\n };\n\n/**\n * Parses an incoming HTTP request into a structured ADK request.\n *\n * Supports two request shapes:\n *\n * 1. User message:\n * ```json\n * { \"message\": \"Hello\", \"runConfig\": {}, \"stateDelta\": {} }\n * ```\n *\n * 2. Tool result:\n * ```json\n * {\n * \"type\": \"tool-result\",\n * \"toolCallId\": \"call_123\",\n * \"toolName\": \"search\",\n * \"result\": { ... },\n * \"isError\": false\n * }\n * ```\n */\nexport const parseAdkRequest = async (\n request: Request,\n): Promise<ParsedAdkRequest> => {\n let body: Record<string, unknown>;\n try {\n body = (await request.json()) as Record<string, unknown>;\n } catch {\n throw new Error(\"Invalid JSON in request body\");\n }\n\n if (!body || typeof body !== \"object\" || Array.isArray(body)) {\n throw new Error(\"Request body must be a JSON object\");\n }\n\n const config: AdkSendMessageConfig = {};\n if (body.runConfig !== undefined) config.runConfig = body.runConfig;\n if (body.checkpointId !== undefined)\n config.checkpointId = body.checkpointId as string;\n\n const stateDelta = body.stateDelta as Record<string, unknown> | undefined;\n\n if (body.type === \"tool-result\") {\n return {\n type: \"tool-result\",\n toolCallId: (body.toolCallId as string) ?? \"\",\n toolName: (body.toolName as string) ?? \"\",\n result: body.result,\n isError: (body.isError as boolean) ?? false,\n config,\n ...(stateDelta != null && { stateDelta }),\n };\n }\n\n return {\n type: \"message\",\n text: (body.message as string) ?? \"\",\n ...(body.parts != null && {\n parts: body.parts as Array<Record<string, unknown>>,\n }),\n config,\n ...(stateDelta != null && { stateDelta }),\n };\n};\n\n/**\n * Converts a parsed ADK request into a Google GenAI Content object\n * suitable for `Runner.runAsync({ newMessage })`.\n *\n * @example\n * ```ts\n * const parsed = await parseAdkRequest(req);\n * const newMessage = toAdkContent(parsed);\n * const events = runner.runAsync({ userId, sessionId, newMessage, stateDelta: parsed.stateDelta });\n * return adkEventStream(events);\n * ```\n */\nexport const toAdkContent = (\n parsed: ParsedAdkRequest,\n): { role: string; parts: Array<Record<string, unknown>> } => {\n if (parsed.type === \"tool-result\") {\n return {\n role: \"user\",\n parts: [\n {\n functionResponse: {\n name: parsed.toolName,\n id: parsed.toolCallId,\n response: parsed.result,\n },\n },\n ],\n };\n }\n\n // If raw parts are provided (multimodal), use them directly\n if (parsed.parts?.length) {\n return { role: \"user\", parts: parsed.parts };\n }\n\n return { role: \"user\", parts: [{ text: parsed.text }] };\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAyCA,MAAa,kBAAkB,OAC7B,YAC8B;CAC9B,IAAI;CACJ,IAAI;EACF,OAAQ,MAAM,QAAQ,KAAK;CAC7B,QAAQ;EACN,MAAM,IAAI,MAAM,8BAA8B;CAChD;CAEA,IAAI,CAAC,QAAQ,OAAO,SAAS,YAAY,MAAM,QAAQ,IAAI,GACzD,MAAM,IAAI,MAAM,oCAAoC;CAGtD,MAAM,SAA+B,CAAC;CACtC,IAAI,KAAK,cAAc,KAAA,GAAW,OAAO,YAAY,KAAK;CAC1D,IAAI,KAAK,iBAAiB,KAAA,GACxB,OAAO,eAAe,KAAK;CAE7B,MAAM,aAAa,KAAK;CAExB,IAAI,KAAK,SAAS,eAChB,OAAO;EACL,MAAM;EACN,YAAa,KAAK,cAAyB;EAC3C,UAAW,KAAK,YAAuB;EACvC,QAAQ,KAAK;EACb,SAAU,KAAK,WAAuB;EACtC;EACA,GAAI,cAAc,QAAQ,EAAE,WAAW;CACzC;CAGF,OAAO;EACL,MAAM;EACN,MAAO,KAAK,WAAsB;EAClC,GAAI,KAAK,SAAS,QAAQ,EACxB,OAAO,KAAK,MACd;EACA;EACA,GAAI,cAAc,QAAQ,EAAE,WAAW;CACzC;AACF;;;;;;;;;;;;;AAcA,MAAa,gBACX,WAC4D;CAC5D,IAAI,OAAO,SAAS,eAClB,OAAO;EACL,MAAM;EACN,OAAO,CACL,EACE,kBAAkB;GAChB,MAAM,OAAO;GACb,IAAI,OAAO;GACX,UAAU,OAAO;EACnB,EACF,CACF;CACF;CAIF,IAAI,OAAO,OAAO,QAChB,OAAO;EAAE,MAAM;EAAQ,OAAO,OAAO;CAAM;CAG7C,OAAO;EAAE,MAAM;EAAQ,OAAO,CAAC,EAAE,MAAM,OAAO,KAAK,CAAC;CAAE;AACxD"}
@@ -1,7 +1,11 @@
1
- import type { AdkEvent, AdkStructuredEvent } from "./types.js";
1
+ import { AdkEvent, AdkStructuredEvent } from "./types.js";
2
+
3
+ //#region src/structuredEvents.d.ts
2
4
  /**
3
5
  * Converts a raw `AdkEvent` into an array of structured, typed events.
4
6
  * Useful for building custom event renderers.
5
7
  */
6
- export declare function toAdkStructuredEvents(event: AdkEvent): AdkStructuredEvent[];
8
+ declare function toAdkStructuredEvents(event: AdkEvent): AdkStructuredEvent[];
9
+ //#endregion
10
+ export { toAdkStructuredEvents };
7
11
  //# sourceMappingURL=structuredEvents.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"structuredEvents.d.ts","sourceRoot":"","sources":["../src/structuredEvents.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,kBAAkB,EAAE,mBAAgB;AAG5D;;;GAGG;AACH,wBAAgB,qBAAqB,CAAC,KAAK,EAAE,QAAQ,GAAG,kBAAkB,EAAE,CAyE3E"}
1
+ {"version":3,"file":"structuredEvents.d.ts","names":[],"sources":["../src/structuredEvents.ts"],"mappings":";;;;;AAOA;;iBAAgB,qBAAA,CAAsB,KAAA,EAAO,QAAA,GAAW,kBAAkB"}
@@ -1,79 +1,74 @@
1
1
  import { isFinalResponse } from "./AdkEventAccumulator.js";
2
+ //#region src/structuredEvents.ts
2
3
  /**
3
- * Converts a raw `AdkEvent` into an array of structured, typed events.
4
- * Useful for building custom event renderers.
5
- */
6
- export function toAdkStructuredEvents(event) {
7
- const result = [];
8
- if (event.errorCode || event.errorMessage) {
9
- const err = { type: "error" };
10
- if (event.errorCode != null)
11
- err.errorCode = event.errorCode;
12
- if (event.errorMessage != null)
13
- err.errorMessage = event.errorMessage;
14
- result.push(err);
15
- }
16
- const parts = event.content?.parts;
17
- if (parts) {
18
- for (const part of parts) {
19
- if (part.text != null) {
20
- if (part.thought) {
21
- result.push({ type: "thought", content: part.text });
22
- }
23
- else {
24
- result.push({ type: "content", content: part.text });
25
- }
26
- }
27
- if (part.functionCall) {
28
- const call = {
29
- type: "tool_call",
30
- call: { name: part.functionCall.name, args: part.functionCall.args },
31
- };
32
- if (part.functionCall.id != null)
33
- call.call.id = part.functionCall.id;
34
- result.push(call);
35
- }
36
- if (part.functionResponse) {
37
- const tr = {
38
- type: "tool_result",
39
- result: {
40
- name: part.functionResponse.name,
41
- response: part.functionResponse.response,
42
- },
43
- };
44
- if (part.functionResponse.id != null)
45
- tr.result.id = part.functionResponse.id;
46
- result.push(tr);
47
- }
48
- if (part.executableCode) {
49
- const ce = {
50
- type: "call_code",
51
- code: { code: part.executableCode.code },
52
- };
53
- if (part.executableCode.language != null)
54
- ce.code.language = part.executableCode.language;
55
- result.push(ce);
56
- }
57
- if (part.codeExecutionResult) {
58
- const cr = {
59
- type: "code_result",
60
- result: { output: part.codeExecutionResult.output },
61
- };
62
- if (part.codeExecutionResult.outcome != null)
63
- cr.result.outcome = part.codeExecutionResult.outcome;
64
- result.push(cr);
65
- }
66
- }
67
- }
68
- if (event.actions?.requestedToolConfirmations) {
69
- result.push({
70
- type: "tool_confirmation",
71
- confirmations: event.actions.requestedToolConfirmations,
72
- });
73
- }
74
- if (isFinalResponse(event) && result.length === 0) {
75
- result.push({ type: "finished" });
76
- }
77
- return result;
4
+ * Converts a raw `AdkEvent` into an array of structured, typed events.
5
+ * Useful for building custom event renderers.
6
+ */
7
+ function toAdkStructuredEvents(event) {
8
+ const result = [];
9
+ if (event.errorCode || event.errorMessage) {
10
+ const err = { type: "error" };
11
+ if (event.errorCode != null) err.errorCode = event.errorCode;
12
+ if (event.errorMessage != null) err.errorMessage = event.errorMessage;
13
+ result.push(err);
14
+ }
15
+ const parts = event.content?.parts;
16
+ if (parts) for (const part of parts) {
17
+ if (part.text != null) if (part.thought) result.push({
18
+ type: "thought",
19
+ content: part.text
20
+ });
21
+ else result.push({
22
+ type: "content",
23
+ content: part.text
24
+ });
25
+ if (part.functionCall) {
26
+ const call = {
27
+ type: "tool_call",
28
+ call: {
29
+ name: part.functionCall.name,
30
+ args: part.functionCall.args
31
+ }
32
+ };
33
+ if (part.functionCall.id != null) call.call.id = part.functionCall.id;
34
+ result.push(call);
35
+ }
36
+ if (part.functionResponse) {
37
+ const tr = {
38
+ type: "tool_result",
39
+ result: {
40
+ name: part.functionResponse.name,
41
+ response: part.functionResponse.response
42
+ }
43
+ };
44
+ if (part.functionResponse.id != null) tr.result.id = part.functionResponse.id;
45
+ result.push(tr);
46
+ }
47
+ if (part.executableCode) {
48
+ const ce = {
49
+ type: "call_code",
50
+ code: { code: part.executableCode.code }
51
+ };
52
+ if (part.executableCode.language != null) ce.code.language = part.executableCode.language;
53
+ result.push(ce);
54
+ }
55
+ if (part.codeExecutionResult) {
56
+ const cr = {
57
+ type: "code_result",
58
+ result: { output: part.codeExecutionResult.output }
59
+ };
60
+ if (part.codeExecutionResult.outcome != null) cr.result.outcome = part.codeExecutionResult.outcome;
61
+ result.push(cr);
62
+ }
63
+ }
64
+ if (event.actions?.requestedToolConfirmations) result.push({
65
+ type: "tool_confirmation",
66
+ confirmations: event.actions.requestedToolConfirmations
67
+ });
68
+ if (isFinalResponse(event) && result.length === 0) result.push({ type: "finished" });
69
+ return result;
78
70
  }
71
+ //#endregion
72
+ export { toAdkStructuredEvents };
73
+
79
74
  //# sourceMappingURL=structuredEvents.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"structuredEvents.js","sourceRoot":"","sources":["../src/structuredEvents.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,iCAA8B;AAExD;;;GAGG;AACH,MAAM,UAAU,qBAAqB,CAAC,KAAe;IACnD,MAAM,MAAM,GAAyB,EAAE,CAAC;IAExC,IAAI,KAAK,CAAC,SAAS,IAAI,KAAK,CAAC,YAAY,EAAE,CAAC;QAC1C,MAAM,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KAAK,CAAC,OAAO,EAAE,0BAA0B,EAAE,CAAC;QAC9C,MAAM,CAAC,IAAI,CAAC;YACV,IAAI,EAAE,mBAAmB;YACzB,aAAa,EAAE,KAAK,CAAC,OAAO,CAAC,0BAA0B;SACxD,CAAC,CAAC;IACL,CAAC;IAED,IAAI,eAAe,CAAC,KAAK,CAAC,IAAI,MAAM,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QAClD,MAAM,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,UAAU,EAAE,CAAC,CAAC;IACpC,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC"}
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,MACf,IAAI,KAAK,SACP,OAAO,KAAK;GAAE,MAAM;GAAW,SAAS,KAAK;EAAK,CAAC;OAEnD,OAAO,KAAK;GAAE,MAAM;GAAW,SAAS,KAAK;EAAK,CAAC;EAGvD,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;EAC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