@google/adk 1.3.0 → 1.4.0

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 (165) hide show
  1. package/dist/cjs/agents/active_streaming_tool.js +6 -1
  2. package/dist/cjs/agents/context.js +1 -11
  3. package/dist/cjs/agents/functions.js +35 -16
  4. package/dist/cjs/agents/instructions.js +23 -5
  5. package/dist/cjs/agents/invocation_context.js +2 -5
  6. package/dist/cjs/agents/llm_agent.js +8 -6
  7. package/dist/cjs/agents/processors/code_execution_request_processor.js +0 -3
  8. package/dist/cjs/agents/processors/content_processor_utils.js +16 -3
  9. package/dist/cjs/agents/processors/context_compactor_request_processor.js +4 -2
  10. package/dist/cjs/agents/processors/interactions_request_processor.js +63 -0
  11. package/dist/cjs/apps/app.js +79 -0
  12. package/dist/cjs/apps/resumability_config.js +44 -0
  13. package/dist/cjs/artifacts/file_artifact_service.js +14 -1
  14. package/dist/cjs/artifacts/gcs_artifact_service.js +57 -15
  15. package/dist/cjs/artifacts/in_memory_artifact_service.js +5 -1
  16. package/dist/cjs/artifacts/scoped_artifact_service.js +101 -0
  17. package/dist/cjs/artifacts/session_artifact_service.js +27 -0
  18. package/dist/cjs/auth/oauth2/oauth2_discovery.js +17 -5
  19. package/dist/cjs/auth/oauth2/oauth2_utils.js +12 -1
  20. package/dist/cjs/common.js +47 -0
  21. package/dist/cjs/context/agent_controlled_context_compactor.js +109 -0
  22. package/dist/cjs/context/token_based_context_compactor.js +42 -10
  23. package/dist/cjs/context/trajectory_thought_pruning_compactor.js +71 -0
  24. package/dist/cjs/events/event.js +24 -0
  25. package/dist/cjs/models/google_llm.js +25 -10
  26. package/dist/cjs/models/interactions_utils.js +732 -0
  27. package/dist/cjs/plugins/base_plugin.js +1 -0
  28. package/dist/cjs/runner/in_memory_runner.js +13 -2
  29. package/dist/cjs/runner/runner.js +93 -72
  30. package/dist/cjs/sessions/base_session_service.js +6 -1
  31. package/dist/cjs/sessions/database_session_service.js +24 -7
  32. package/dist/cjs/sessions/vertex_ai_session_service.js +19 -4
  33. package/dist/cjs/skills/loader.js +2 -2
  34. package/dist/cjs/tools/base_toolset.js +1 -1
  35. package/dist/cjs/tools/consolidate_context_tool.js +79 -0
  36. package/dist/cjs/tools/forwarding_artifact_service.js +16 -28
  37. package/dist/cjs/tools/openapi_tool/openapi_spec_parser/tool_auth_handler.js +2 -12
  38. package/dist/cjs/utils/async_hooks_shim.js +52 -0
  39. package/dist/cjs/utils/client_labels.js +41 -3
  40. package/dist/cjs/utils/env_aware_utils.js +10 -1
  41. package/dist/cjs/utils/streaming_utils.js +10 -4
  42. package/dist/cjs/utils/task.js +62 -0
  43. package/dist/cjs/version.js +1 -1
  44. package/dist/esm/agents/active_streaming_tool.js +6 -1
  45. package/dist/esm/agents/context.js +1 -11
  46. package/dist/esm/agents/functions.js +36 -15
  47. package/dist/esm/agents/instructions.js +23 -5
  48. package/dist/esm/agents/invocation_context.js +2 -5
  49. package/dist/esm/agents/llm_agent.js +8 -6
  50. package/dist/esm/agents/processors/code_execution_request_processor.js +0 -3
  51. package/dist/esm/agents/processors/content_processor_utils.js +14 -2
  52. package/dist/esm/agents/processors/context_compactor_request_processor.js +4 -2
  53. package/dist/esm/agents/processors/interactions_request_processor.js +34 -0
  54. package/dist/esm/apps/app.js +49 -0
  55. package/dist/esm/apps/resumability_config.js +16 -0
  56. package/dist/esm/artifacts/file_artifact_service.js +14 -1
  57. package/dist/esm/artifacts/gcs_artifact_service.js +57 -15
  58. package/dist/esm/artifacts/in_memory_artifact_service.js +5 -1
  59. package/dist/esm/artifacts/scoped_artifact_service.js +73 -0
  60. package/dist/esm/artifacts/session_artifact_service.js +7 -0
  61. package/dist/esm/auth/oauth2/oauth2_discovery.js +14 -4
  62. package/dist/esm/auth/oauth2/oauth2_utils.js +12 -1
  63. package/dist/esm/common.js +42 -2
  64. package/dist/esm/context/agent_controlled_context_compactor.js +81 -0
  65. package/dist/esm/context/token_based_context_compactor.js +42 -10
  66. package/dist/esm/context/trajectory_thought_pruning_compactor.js +43 -0
  67. package/dist/esm/events/event.js +22 -0
  68. package/dist/esm/models/google_llm.js +23 -9
  69. package/dist/esm/models/interactions_utils.js +697 -0
  70. package/dist/esm/plugins/base_plugin.js +1 -0
  71. package/dist/esm/runner/in_memory_runner.js +13 -2
  72. package/dist/esm/runner/runner.js +91 -73
  73. package/dist/esm/sessions/base_session_service.js +6 -1
  74. package/dist/esm/sessions/database_session_service.js +24 -7
  75. package/dist/esm/sessions/vertex_ai_session_service.js +17 -3
  76. package/dist/esm/skills/loader.js +2 -2
  77. package/dist/esm/tools/base_toolset.js +1 -1
  78. package/dist/esm/tools/consolidate_context_tool.js +51 -0
  79. package/dist/esm/tools/forwarding_artifact_service.js +16 -28
  80. package/dist/esm/tools/openapi_tool/openapi_spec_parser/tool_auth_handler.js +2 -12
  81. package/dist/esm/utils/async_hooks_shim.js +24 -0
  82. package/dist/esm/utils/client_labels.js +38 -2
  83. package/dist/esm/utils/env_aware_utils.js +10 -1
  84. package/dist/esm/utils/streaming_utils.js +10 -4
  85. package/dist/esm/utils/task.js +34 -0
  86. package/dist/esm/version.js +1 -1
  87. package/dist/types/agents/active_streaming_tool.d.ts +3 -4
  88. package/dist/types/agents/functions.d.ts +12 -9
  89. package/dist/types/agents/invocation_context.d.ts +7 -3
  90. package/dist/types/agents/processors/content_processor_utils.d.ts +8 -0
  91. package/dist/types/agents/processors/interactions_request_processor.d.ts +17 -0
  92. package/dist/types/apps/app.d.ts +52 -0
  93. package/dist/types/apps/resumability_config.d.ts +27 -0
  94. package/dist/types/artifacts/base_artifact_service.d.ts +6 -36
  95. package/dist/types/artifacts/gcs_artifact_service.d.ts +2 -1
  96. package/dist/types/artifacts/scoped_artifact_service.d.ts +25 -0
  97. package/dist/types/artifacts/session_artifact_service.d.ts +25 -0
  98. package/dist/types/auth/oauth2/oauth2_discovery.d.ts +11 -0
  99. package/dist/types/common.d.ts +20 -3
  100. package/dist/types/context/agent_controlled_context_compactor.d.ts +24 -0
  101. package/dist/types/context/base_context_compactor.d.ts +3 -0
  102. package/dist/types/context/token_based_context_compactor.d.ts +6 -1
  103. package/dist/types/context/trajectory_thought_pruning_compactor.d.ts +27 -0
  104. package/dist/types/events/event.d.ts +8 -0
  105. package/dist/types/models/google_llm.d.ts +15 -1
  106. package/dist/types/models/interactions_utils.d.ts +92 -0
  107. package/dist/types/models/llm_request.d.ts +4 -0
  108. package/dist/types/models/llm_response.d.ts +4 -0
  109. package/dist/types/plugins/base_plugin.d.ts +2 -1
  110. package/dist/types/runner/in_memory_runner.d.ts +7 -1
  111. package/dist/types/runner/runner.d.ts +43 -9
  112. package/dist/types/sessions/base_session_service.d.ts +3 -16
  113. package/dist/types/sessions/session.d.ts +11 -0
  114. package/dist/types/sessions/vertex_ai_session_service.d.ts +9 -1
  115. package/dist/types/tools/consolidate_context_tool.d.ts +19 -0
  116. package/dist/types/tools/forwarding_artifact_service.d.ts +3 -2
  117. package/dist/types/utils/async_hooks_shim.d.ts +10 -0
  118. package/dist/types/utils/client_labels.d.ts +10 -0
  119. package/dist/types/utils/env_aware_utils.d.ts +3 -3
  120. package/dist/types/utils/task.d.ts +24 -0
  121. package/dist/types/version.d.ts +1 -1
  122. package/dist/web/agents/active_streaming_tool.js +6 -1
  123. package/dist/web/agents/context.js +1 -11
  124. package/dist/web/agents/functions.js +36 -15
  125. package/dist/web/agents/instructions.js +23 -5
  126. package/dist/web/agents/invocation_context.js +2 -5
  127. package/dist/web/agents/llm_agent.js +8 -6
  128. package/dist/web/agents/processors/code_execution_request_processor.js +0 -3
  129. package/dist/web/agents/processors/content_processor_utils.js +14 -2
  130. package/dist/web/agents/processors/context_compactor_request_processor.js +4 -2
  131. package/dist/web/agents/processors/interactions_request_processor.js +52 -0
  132. package/dist/web/apps/app.js +49 -0
  133. package/dist/web/apps/resumability_config.js +31 -0
  134. package/dist/web/artifacts/file_artifact_service.js +14 -1
  135. package/dist/web/artifacts/gcs_artifact_service.js +55 -15
  136. package/dist/web/artifacts/in_memory_artifact_service.js +5 -1
  137. package/dist/web/artifacts/scoped_artifact_service.js +86 -0
  138. package/dist/web/artifacts/session_artifact_service.js +7 -0
  139. package/dist/web/auth/oauth2/oauth2_discovery.js +14 -4
  140. package/dist/web/auth/oauth2/oauth2_utils.js +12 -1
  141. package/dist/web/common.js +42 -2
  142. package/dist/web/context/agent_controlled_context_compactor.js +81 -0
  143. package/dist/web/context/token_based_context_compactor.js +42 -10
  144. package/dist/web/context/trajectory_thought_pruning_compactor.js +43 -0
  145. package/dist/web/events/event.js +20 -0
  146. package/dist/web/models/google_llm.js +54 -9
  147. package/dist/web/models/interactions_utils.js +728 -0
  148. package/dist/web/plugins/base_plugin.js +1 -0
  149. package/dist/web/runner/in_memory_runner.js +13 -2
  150. package/dist/web/runner/runner.js +111 -75
  151. package/dist/web/sessions/base_session_service.js +6 -1
  152. package/dist/web/sessions/database_session_service.js +24 -7
  153. package/dist/web/sessions/vertex_ai_session_service.js +17 -3
  154. package/dist/web/skills/loader.js +2 -2
  155. package/dist/web/tools/base_toolset.js +1 -1
  156. package/dist/web/tools/consolidate_context_tool.js +51 -0
  157. package/dist/web/tools/forwarding_artifact_service.js +16 -28
  158. package/dist/web/tools/openapi_tool/openapi_spec_parser/tool_auth_handler.js +2 -12
  159. package/dist/web/utils/async_hooks_shim.js +24 -0
  160. package/dist/web/utils/client_labels.js +38 -2
  161. package/dist/web/utils/env_aware_utils.js +10 -1
  162. package/dist/web/utils/streaming_utils.js +10 -4
  163. package/dist/web/utils/task.js +34 -0
  164. package/dist/web/version.js +1 -1
  165. package/package.json +2 -2
@@ -27,6 +27,7 @@ __export(active_streaming_tool_exports, {
27
27
  ActiveStreamingTool: () => ActiveStreamingTool
28
28
  });
29
29
  module.exports = __toCommonJS(active_streaming_tool_exports);
30
+ var import_task = require("../utils/task.js");
30
31
  /**
31
32
  * @license
32
33
  * Copyright 2025 Google LLC
@@ -34,7 +35,11 @@ module.exports = __toCommonJS(active_streaming_tool_exports);
34
35
  */
35
36
  class ActiveStreamingTool {
36
37
  constructor(params = {}) {
37
- this.task = params.task;
38
+ if (params.task instanceof Promise) {
39
+ this.task = new import_task.Task(() => params.task);
40
+ } else {
41
+ this.task = params.task;
42
+ }
38
43
  this.stream = params.stream;
39
44
  }
40
45
  }
@@ -83,9 +83,6 @@ class Context extends import_readonly_context.ReadonlyContext {
83
83
  throw new Error("Artifact service is not initialized.");
84
84
  }
85
85
  return this.invocationContext.artifactService.loadArtifact({
86
- appName: this.invocationContext.appName,
87
- userId: this.invocationContext.userId,
88
- sessionId: this.invocationContext.session.id,
89
86
  filename,
90
87
  version
91
88
  });
@@ -102,9 +99,6 @@ class Context extends import_readonly_context.ReadonlyContext {
102
99
  throw new Error("Artifact service is not initialized.");
103
100
  }
104
101
  const version = await this.invocationContext.artifactService.saveArtifact({
105
- appName: this.invocationContext.appName,
106
- userId: this.invocationContext.userId,
107
- sessionId: this.invocationContext.session.id,
108
102
  filename,
109
103
  artifact
110
104
  });
@@ -137,11 +131,7 @@ class Context extends import_readonly_context.ReadonlyContext {
137
131
  if (!this.invocationContext.artifactService) {
138
132
  throw new Error("Artifact service is not initialized.");
139
133
  }
140
- return this.invocationContext.artifactService.listArtifactKeys({
141
- appName: this.invocationContext.session.appName,
142
- userId: this.invocationContext.session.userId,
143
- sessionId: this.invocationContext.session.id
144
- });
134
+ return this.invocationContext.artifactService.listArtifactKeys();
145
135
  }
146
136
  /**
147
137
  * Searches the memory of the current user.
@@ -24,8 +24,11 @@ var __copyProps = (to, from, except, desc) => {
24
24
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
25
25
  var functions_exports = {};
26
26
  __export(functions_exports, {
27
+ AF_FUNCTION_CALL_ID_PREFIX: () => AF_FUNCTION_CALL_ID_PREFIX,
27
28
  REQUEST_CONFIRMATION_FUNCTION_CALL_NAME: () => REQUEST_CONFIRMATION_FUNCTION_CALL_NAME,
28
29
  REQUEST_EUC_FUNCTION_CALL_NAME: () => REQUEST_EUC_FUNCTION_CALL_NAME,
30
+ findEventByFunctionCallId: () => findEventByFunctionCallId,
31
+ findMatchingFunctionCall: () => findMatchingFunctionCall,
29
32
  functionsExportedForTestingOnly: () => functionsExportedForTestingOnly,
30
33
  generateAuthEvent: () => generateAuthEvent,
31
34
  generateClientFunctionCallId: () => generateClientFunctionCallId,
@@ -34,8 +37,7 @@ __export(functions_exports, {
34
37
  handleFunctionCallList: () => handleFunctionCallList,
35
38
  handleFunctionCallsAsync: () => handleFunctionCallsAsync,
36
39
  mergeParallelFunctionResponseEvents: () => mergeParallelFunctionResponseEvents,
37
- populateClientFunctionCallId: () => populateClientFunctionCallId,
38
- removeClientFunctionCallId: () => removeClientFunctionCallId
40
+ populateClientFunctionCallId: () => populateClientFunctionCallId
39
41
  });
40
42
  module.exports = __toCommonJS(functions_exports);
41
43
  var import_genai = require("@google/genai");
@@ -73,18 +75,6 @@ function populateClientFunctionCallId(modelResponseEvent) {
73
75
  }
74
76
  }
75
77
  }
76
- function removeClientFunctionCallId(content) {
77
- if (content && content.parts) {
78
- for (const part of content.parts) {
79
- if (part.functionCall && part.functionCall.id && part.functionCall.id.startsWith(AF_FUNCTION_CALL_ID_PREFIX)) {
80
- part.functionCall.id = void 0;
81
- }
82
- if (part.functionResponse && part.functionResponse.id && part.functionResponse.id.startsWith(AF_FUNCTION_CALL_ID_PREFIX)) {
83
- part.functionResponse.id = void 0;
84
- }
85
- }
86
- }
87
- }
88
78
  function getLongRunningFunctionCalls(functionCalls, toolsDict) {
89
79
  const longRunningToolIds = /* @__PURE__ */ new Set();
90
80
  for (const functionCall of functionCalls) {
@@ -427,10 +417,40 @@ function mergeParallelFunctionResponseEvents(functionResponseEvents) {
427
417
  timestamp: baseEvent.timestamp
428
418
  });
429
419
  }
420
+ function findEventByFunctionCallId(events, functionCallId, endIndex = events.length) {
421
+ for (let i = endIndex - 1; i >= 0; i--) {
422
+ const event = events[i];
423
+ const functionCalls = (0, import_event.getFunctionCalls)(event);
424
+ for (const functionCall of functionCalls) {
425
+ if (functionCall.id === functionCallId) {
426
+ return event;
427
+ }
428
+ }
429
+ }
430
+ return void 0;
431
+ }
432
+ function findMatchingFunctionCall(events) {
433
+ if (!events.length) {
434
+ return void 0;
435
+ }
436
+ const lastEvent = events[events.length - 1];
437
+ const functionResponses = (0, import_event.getFunctionResponses)(lastEvent);
438
+ if (!functionResponses.length || !functionResponses[0].id) {
439
+ return void 0;
440
+ }
441
+ return findEventByFunctionCallId(
442
+ events,
443
+ functionResponses[0].id,
444
+ events.length - 1
445
+ );
446
+ }
430
447
  // Annotate the CommonJS export names for ESM import in node:
431
448
  0 && (module.exports = {
449
+ AF_FUNCTION_CALL_ID_PREFIX,
432
450
  REQUEST_CONFIRMATION_FUNCTION_CALL_NAME,
433
451
  REQUEST_EUC_FUNCTION_CALL_NAME,
452
+ findEventByFunctionCallId,
453
+ findMatchingFunctionCall,
434
454
  functionsExportedForTestingOnly,
435
455
  generateAuthEvent,
436
456
  generateClientFunctionCallId,
@@ -439,6 +459,5 @@ function mergeParallelFunctionResponseEvents(functionResponseEvents) {
439
459
  handleFunctionCallList,
440
460
  handleFunctionCallsAsync,
441
461
  mergeParallelFunctionResponseEvents,
442
- populateClientFunctionCallId,
443
- removeClientFunctionCallId
462
+ populateClientFunctionCallId
444
463
  });
@@ -42,9 +42,6 @@ async function resolveKey(key, isOptional, rawMatch, readonlyContext) {
42
42
  throw new Error("Artifact service is not initialized.");
43
43
  }
44
44
  const artifact = await invocationContext.artifactService.loadArtifact({
45
- appName: invocationContext.session.appName,
46
- userId: invocationContext.session.userId,
47
- sessionId: invocationContext.session.id,
48
45
  filename: fileName
49
46
  });
50
47
  if (!artifact) {
@@ -53,19 +50,40 @@ async function resolveKey(key, isOptional, rawMatch, readonlyContext) {
53
50
  }
54
51
  throw new Error(`Artifact ${fileName} not found.`);
55
52
  }
56
- return String(artifact);
53
+ return formatValue(artifact, true);
57
54
  }
58
55
  if (!isValidStateName(key)) {
59
56
  return rawMatch;
60
57
  }
61
58
  if (key in invocationContext.session.state) {
62
- return String(invocationContext.session.state[key]);
59
+ return formatValue(invocationContext.session.state[key], false);
63
60
  }
64
61
  if (isOptional) {
65
62
  return "";
66
63
  }
67
64
  throw new Error(`Context variable not found: \`${key}\`.`);
68
65
  }
66
+ function formatValue(value, isArtifact = false) {
67
+ if (typeof value === "string") {
68
+ return value;
69
+ }
70
+ if (typeof value === "object" && value !== null) {
71
+ if (isArtifact && "text" in value && typeof value.text === "string") {
72
+ return value.text;
73
+ }
74
+ try {
75
+ const json = JSON.stringify(value);
76
+ if (json !== void 0) {
77
+ return json;
78
+ }
79
+ } catch (e) {
80
+ throw new Error(
81
+ `Failed to serialize value for instruction template: ${e instanceof Error ? e.message : String(e)}`
82
+ );
83
+ }
84
+ }
85
+ return String(value);
86
+ }
69
87
  async function injectSessionState(template, readonlyContext) {
70
88
  const pattern = /\{+[^{}]*}+/g;
71
89
  const matches = Array.from(template.matchAll(pattern));
@@ -58,11 +58,7 @@ class InvocationContext {
58
58
  * @param params The parameters for creating an invocation context.
59
59
  */
60
60
  constructor(params) {
61
- /**
62
- * A container to keep track of different kinds of costs incurred as a part of
63
- * this invocation.
64
- */
65
- this.invocationCostManager = new InvocationCostManager();
61
+ var _a;
66
62
  this.artifactService = params.artifactService;
67
63
  this.sessionService = params.sessionService;
68
64
  this.memoryService = params.memoryService;
@@ -77,6 +73,7 @@ class InvocationContext {
77
73
  this.activeStreamingTools = params.activeStreamingTools;
78
74
  this.pluginManager = params.pluginManager;
79
75
  this.abortSignal = params.abortSignal;
76
+ this.invocationCostManager = (_a = params.invocationCostManager) != null ? _a : new InvocationCostManager();
80
77
  }
81
78
  /**
82
79
  * The app name of the current session.
@@ -48,6 +48,7 @@ var import_content_request_processor = require("./processors/content_request_pro
48
48
  var import_context_compactor_request_processor = require("./processors/context_compactor_request_processor.js");
49
49
  var import_identity_llm_request_processor = require("./processors/identity_llm_request_processor.js");
50
50
  var import_instructions_llm_request_processor = require("./processors/instructions_llm_request_processor.js");
51
+ var import_interactions_request_processor = require("./processors/interactions_request_processor.js");
51
52
  var import_request_confirmation_llm_request_processor = require("./processors/request_confirmation_llm_request_processor.js");
52
53
  var import_tool_filter_request_processor = require("./processors/tool_filter_request_processor.js");
53
54
  var import_readonly_context = require("./readonly_context.js");
@@ -98,6 +99,7 @@ class LlmAgent extends (_b = import_base_agent.BaseAgent, _a = LLM_AGENT_SIGNATU
98
99
  import_instructions_llm_request_processor.INSTRUCTIONS_LLM_REQUEST_PROCESSOR,
99
100
  import_request_confirmation_llm_request_processor.REQUEST_CONFIRMATION_LLM_REQUEST_PROCESSOR,
100
101
  import_content_request_processor.CONTENT_REQUEST_PROCESSOR,
102
+ import_interactions_request_processor.INTERACTIONS_REQUEST_PROCESSOR,
101
103
  import_code_execution_request_processor.CODE_EXECUTION_REQUEST_PROCESSOR,
102
104
  import_tool_filter_request_processor.TOOL_FILTER_REQUEST_PROCESSOR
103
105
  ];
@@ -480,7 +482,7 @@ class LlmAgent extends (_b = import_base_agent.BaseAgent, _a = LLM_AGENT_SIGNATU
480
482
  span.end();
481
483
  }
482
484
  async *postprocess(invocationContext, llmRequest, llmResponse, modelResponseEvent) {
483
- var _a2, _b2, _c, _d, _e;
485
+ var _a2, _b2, _c, _d, _e, _f;
484
486
  for (const processor of this.responseProcessors) {
485
487
  for await (const event of processor.runAsync(
486
488
  invocationContext,
@@ -492,7 +494,7 @@ class LlmAgent extends (_b = import_base_agent.BaseAgent, _a = LLM_AGENT_SIGNATU
492
494
  yield event;
493
495
  }
494
496
  }
495
- if (!llmResponse.content && !llmResponse.errorCode && !llmResponse.interrupted) {
497
+ if ((!llmResponse.content || ((_b2 = llmResponse.content.parts) == null ? void 0 : _b2.length) === 0) && !llmResponse.errorCode && !llmResponse.interrupted) {
496
498
  return;
497
499
  }
498
500
  const mergedEvent = (0, import_event.createEvent)({
@@ -516,10 +518,10 @@ class LlmAgent extends (_b = import_base_agent.BaseAgent, _a = LLM_AGENT_SIGNATU
516
518
  }
517
519
  }
518
520
  yield mergedEvent;
519
- if (!((_b2 = (0, import_event.getFunctionCalls)(mergedEvent)) == null ? void 0 : _b2.length)) {
521
+ if (!((_c = (0, import_event.getFunctionCalls)(mergedEvent)) == null ? void 0 : _c.length)) {
520
522
  return;
521
523
  }
522
- if ((_c = invocationContext.runConfig) == null ? void 0 : _c.pauseOnToolCalls) {
524
+ if ((_d = invocationContext.runConfig) == null ? void 0 : _d.pauseOnToolCalls) {
523
525
  invocationContext.endInvocation = true;
524
526
  return;
525
527
  }
@@ -530,7 +532,7 @@ class LlmAgent extends (_b = import_base_agent.BaseAgent, _a = LLM_AGENT_SIGNATU
530
532
  beforeToolCallbacks: this.canonicalBeforeToolCallbacks,
531
533
  afterToolCallbacks: this.canonicalAfterToolCallbacks
532
534
  });
533
- if (!functionResponseEvent || ((_d = invocationContext.abortSignal) == null ? void 0 : _d.aborted)) {
535
+ if (!functionResponseEvent || ((_e = invocationContext.abortSignal) == null ? void 0 : _e.aborted)) {
534
536
  return;
535
537
  }
536
538
  const authEvent = (0, import_functions.generateAuthEvent)(
@@ -555,7 +557,7 @@ class LlmAgent extends (_b = import_base_agent.BaseAgent, _a = LLM_AGENT_SIGNATU
555
557
  if (nextAgentName) {
556
558
  const nextAgent = this.getAgentByName(invocationContext, nextAgentName);
557
559
  for await (const event of nextAgent.runAsync(invocationContext)) {
558
- if ((_e = invocationContext.abortSignal) == null ? void 0 : _e.aborted) {
560
+ if ((_f = invocationContext.abortSignal) == null ? void 0 : _f.aborted) {
559
561
  return;
560
562
  }
561
563
  yield event;
@@ -339,9 +339,6 @@ async function postProcessCodeExecutionResult(invocationContext, codeExecutorCon
339
339
  }
340
340
  for (const outputFile of codeExecutionResult.outputFiles) {
341
341
  const version = await invocationContext.artifactService.saveArtifact({
342
- appName: invocationContext.appName || "",
343
- userId: invocationContext.userId || "",
344
- sessionId: invocationContext.session.id,
345
342
  filename: outputFile.name,
346
343
  artifact: {
347
344
  inlineData: { data: outputFile.content, mimeType: outputFile.mimeType }
@@ -26,7 +26,8 @@ var content_processor_utils_exports = {};
26
26
  __export(content_processor_utils_exports, {
27
27
  getContents: () => getContents,
28
28
  getCurrentTurnContents: () => getCurrentTurnContents,
29
- mergeFunctionResponseEvents: () => mergeFunctionResponseEvents
29
+ mergeFunctionResponseEvents: () => mergeFunctionResponseEvents,
30
+ removeClientFunctionCallId: () => removeClientFunctionCallId
30
31
  });
31
32
  module.exports = __toCommonJS(content_processor_utils_exports);
32
33
  var import_genai = require("@google/genai");
@@ -39,6 +40,17 @@ var import_functions = require("../functions.js");
39
40
  * Copyright 2025 Google LLC
40
41
  * SPDX-License-Identifier: Apache-2.0
41
42
  */
43
+ function removeClientFunctionCallId(content) {
44
+ var _a, _b, _c, _d, _e;
45
+ for (const part of (_a = content == null ? void 0 : content.parts) != null ? _a : []) {
46
+ if ((_c = (_b = part.functionCall) == null ? void 0 : _b.id) == null ? void 0 : _c.startsWith(import_functions.AF_FUNCTION_CALL_ID_PREFIX)) {
47
+ part.functionCall.id = void 0;
48
+ }
49
+ if ((_e = (_d = part.functionResponse) == null ? void 0 : _d.id) == null ? void 0 : _e.startsWith(import_functions.AF_FUNCTION_CALL_ID_PREFIX)) {
50
+ part.functionResponse.id = void 0;
51
+ }
52
+ }
53
+ }
42
54
  function getContents(events, agentName, currentBranch) {
43
55
  var _a, _b, _c;
44
56
  const filteredEvents = [];
@@ -68,7 +80,7 @@ function getContents(events, agentName, currentBranch) {
68
80
  const contents = [];
69
81
  for (const event of resultEvents) {
70
82
  const content = (0, import_lodash_es.cloneDeep)(event.content);
71
- (0, import_functions.removeClientFunctionCallId)(content);
83
+ removeClientFunctionCallId(content);
72
84
  contents.push(content);
73
85
  }
74
86
  return contents;
@@ -347,5 +359,6 @@ ${event.compactedContent}`
347
359
  0 && (module.exports = {
348
360
  getContents,
349
361
  getCurrentTurnContents,
350
- mergeFunctionResponseEvents
362
+ mergeFunctionResponseEvents,
363
+ removeClientFunctionCallId
351
364
  });
@@ -50,20 +50,22 @@ class ContextCompactorRequestProcessor {
50
50
  * @param _llmRequest - Unused; present to satisfy the {@link BaseLlmRequestProcessor} interface.
51
51
  */
52
52
  async *runAsync(invocationContext, _llmRequest) {
53
+ var _a;
53
54
  for (const compactor of this.compactors) {
54
55
  const shouldCompact = await Promise.resolve(
55
56
  compactor.shouldCompact(invocationContext)
56
57
  );
57
58
  if (shouldCompact) {
59
+ const trigger = (_a = compactor.trigger) != null ? _a : import_base_plugin.ContextCompactionTrigger.Auto;
58
60
  await invocationContext.pluginManager.runBeforeContextCompaction({
59
61
  invocationContext,
60
- trigger: import_base_plugin.ContextCompactionTrigger.Auto
62
+ trigger
61
63
  });
62
64
  const oldEvents = new Set(invocationContext.session.events);
63
65
  await Promise.resolve(compactor.compact(invocationContext));
64
66
  await invocationContext.pluginManager.runAfterContextCompaction({
65
67
  invocationContext,
66
- trigger: import_base_plugin.ContextCompactionTrigger.Auto
68
+ trigger
67
69
  });
68
70
  const newEvents = invocationContext.session.events.filter(
69
71
  (e) => !oldEvents.has(e)
@@ -0,0 +1,63 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2026 Google LLC
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+
7
+ "use strict";
8
+ var __defProp = Object.defineProperty;
9
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
10
+ var __getOwnPropNames = Object.getOwnPropertyNames;
11
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
12
+ var __export = (target, all) => {
13
+ for (var name in all)
14
+ __defProp(target, name, { get: all[name], enumerable: true });
15
+ };
16
+ var __copyProps = (to, from, except, desc) => {
17
+ if (from && typeof from === "object" || typeof from === "function") {
18
+ for (let key of __getOwnPropNames(from))
19
+ if (!__hasOwnProp.call(to, key) && key !== except)
20
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
21
+ }
22
+ return to;
23
+ };
24
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
25
+ var interactions_request_processor_exports = {};
26
+ __export(interactions_request_processor_exports, {
27
+ INTERACTIONS_REQUEST_PROCESSOR: () => INTERACTIONS_REQUEST_PROCESSOR,
28
+ InteractionsRequestProcessor: () => InteractionsRequestProcessor
29
+ });
30
+ module.exports = __toCommonJS(interactions_request_processor_exports);
31
+ var import_google_llm = require("../../models/google_llm.js");
32
+ var import_llm_agent = require("../llm_agent.js");
33
+ /**
34
+ * @license
35
+ * Copyright 2026 Google LLC
36
+ * SPDX-License-Identifier: Apache-2.0
37
+ */
38
+ class InteractionsRequestProcessor {
39
+ // eslint-disable-next-line require-yield
40
+ async *runAsync(invocationContext, llmRequest) {
41
+ const agent = invocationContext.agent;
42
+ if (!agent || !(0, import_llm_agent.isLlmAgent)(agent)) {
43
+ return;
44
+ }
45
+ const model = agent.canonicalModel;
46
+ if ((0, import_google_llm.isGemini)(model) && model.useInteractionsApi) {
47
+ const events = invocationContext.session.events;
48
+ for (let i = events.length - 1; i >= 0; i--) {
49
+ const event = events[i];
50
+ if (event.branch === invocationContext.branch && event.author === agent.name && event.interactionId) {
51
+ llmRequest.previousInteractionId = event.interactionId;
52
+ break;
53
+ }
54
+ }
55
+ }
56
+ }
57
+ }
58
+ const INTERACTIONS_REQUEST_PROCESSOR = new InteractionsRequestProcessor();
59
+ // Annotate the CommonJS export names for ESM import in node:
60
+ 0 && (module.exports = {
61
+ INTERACTIONS_REQUEST_PROCESSOR,
62
+ InteractionsRequestProcessor
63
+ });
@@ -0,0 +1,79 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2026 Google LLC
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+
7
+ "use strict";
8
+ var __defProp = Object.defineProperty;
9
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
10
+ var __getOwnPropNames = Object.getOwnPropertyNames;
11
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
12
+ var __export = (target, all) => {
13
+ for (var name in all)
14
+ __defProp(target, name, { get: all[name], enumerable: true });
15
+ };
16
+ var __copyProps = (to, from, except, desc) => {
17
+ if (from && typeof from === "object" || typeof from === "function") {
18
+ for (let key of __getOwnPropNames(from))
19
+ if (!__hasOwnProp.call(to, key) && key !== except)
20
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
21
+ }
22
+ return to;
23
+ };
24
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
25
+ var app_exports = {};
26
+ __export(app_exports, {
27
+ App: () => App,
28
+ isApp: () => isApp,
29
+ validateAppName: () => validateAppName
30
+ });
31
+ module.exports = __toCommonJS(app_exports);
32
+ var import_base_agent = require("../agents/base_agent.js");
33
+ /**
34
+ * @license
35
+ * Copyright 2026 Google LLC
36
+ * SPDX-License-Identifier: Apache-2.0
37
+ */
38
+ var _a;
39
+ const VALID_APP_NAME_RE = /^[a-zA-Z][a-zA-Z0-9_-]*$/;
40
+ function validateAppName(name) {
41
+ if (!VALID_APP_NAME_RE.test(name)) {
42
+ throw new Error(
43
+ `Invalid app name '${name}': must start with a letter and can only consist of letters, digits, underscores, and hyphens.`
44
+ );
45
+ }
46
+ if (name === "user") {
47
+ throw new Error("App name cannot be 'user'; reserved for end-user input.");
48
+ }
49
+ }
50
+ const APP_SIGNATURE_SYMBOL = Symbol.for("google.adk.app");
51
+ function isApp(obj) {
52
+ return typeof obj === "object" && obj !== null && APP_SIGNATURE_SYMBOL in obj && obj[APP_SIGNATURE_SYMBOL] === true;
53
+ }
54
+ _a = APP_SIGNATURE_SYMBOL;
55
+ class App {
56
+ constructor(options) {
57
+ this[_a] = true;
58
+ var _a2, _b, _c, _d;
59
+ validateAppName(options.name);
60
+ if (options.rootAgent === void 0 || options.rootAgent === null) {
61
+ throw new Error("rootAgent must be provided.");
62
+ }
63
+ if (!(0, import_base_agent.isBaseAgent)(options.rootAgent)) {
64
+ throw new TypeError(
65
+ `rootAgent must be a BaseAgent instance, got ${(_c = (_b = (_a2 = options.rootAgent) == null ? void 0 : _a2.constructor) == null ? void 0 : _b.name) != null ? _c : typeof options.rootAgent}`
66
+ );
67
+ }
68
+ this.name = options.name;
69
+ this.rootAgent = options.rootAgent;
70
+ this.plugins = (_d = options.plugins) != null ? _d : [];
71
+ this.resumabilityConfig = options.resumabilityConfig;
72
+ }
73
+ }
74
+ // Annotate the CommonJS export names for ESM import in node:
75
+ 0 && (module.exports = {
76
+ App,
77
+ isApp,
78
+ validateAppName
79
+ });
@@ -0,0 +1,44 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2026 Google LLC
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+
7
+ "use strict";
8
+ var __defProp = Object.defineProperty;
9
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
10
+ var __getOwnPropNames = Object.getOwnPropertyNames;
11
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
12
+ var __export = (target, all) => {
13
+ for (var name in all)
14
+ __defProp(target, name, { get: all[name], enumerable: true });
15
+ };
16
+ var __copyProps = (to, from, except, desc) => {
17
+ if (from && typeof from === "object" || typeof from === "function") {
18
+ for (let key of __getOwnPropNames(from))
19
+ if (!__hasOwnProp.call(to, key) && key !== except)
20
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
21
+ }
22
+ return to;
23
+ };
24
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
25
+ var resumability_config_exports = {};
26
+ __export(resumability_config_exports, {
27
+ createResumabilityConfig: () => createResumabilityConfig
28
+ });
29
+ module.exports = __toCommonJS(resumability_config_exports);
30
+ /**
31
+ * @license
32
+ * Copyright 2026 Google LLC
33
+ * SPDX-License-Identifier: Apache-2.0
34
+ */
35
+ function createResumabilityConfig(params = {}) {
36
+ return {
37
+ isResumable: false,
38
+ ...params
39
+ };
40
+ }
41
+ // Annotate the CommonJS export names for ESM import in node:
42
+ 0 && (module.exports = {
43
+ createResumabilityConfig
44
+ });
@@ -67,7 +67,7 @@ class FileArtifactService {
67
67
  artifact,
68
68
  customMetadata
69
69
  }) {
70
- if (!artifact.inlineData && !artifact.text) {
70
+ if (!artifact.inlineData && !artifact.text && !artifact.fileData) {
71
71
  throw new Error("Artifact must have either inlineData or text content.");
72
72
  }
73
73
  const artifactDir = getArtifactDir(
@@ -85,12 +85,19 @@ class FileArtifactService {
85
85
  const storedFilename = path.basename(artifactDir);
86
86
  const contentPath = path.join(versionDir, storedFilename);
87
87
  let mimeType;
88
+ let fileUri;
88
89
  if (artifact.inlineData) {
89
90
  const data = artifact.inlineData.data || "";
90
91
  await fs.writeFile(contentPath, Buffer.from(data, "base64"));
91
92
  mimeType = artifact.inlineData.mimeType || "application/octet-stream";
92
93
  } else if (artifact.text !== void 0) {
93
94
  await fs.writeFile(contentPath, artifact.text, "utf-8");
95
+ } else {
96
+ fileUri = artifact.fileData.fileUri;
97
+ if (!fileUri) {
98
+ throw new Error("Artifact fileData must have a fileUri.");
99
+ }
100
+ mimeType = artifact.fileData.mimeType;
94
101
  }
95
102
  const canonicalUri = await getCanonicalUri(
96
103
  this.rootDir,
@@ -102,6 +109,7 @@ class FileArtifactService {
102
109
  const metadata = {
103
110
  fileName: filename,
104
111
  mimeType,
112
+ fileUri,
105
113
  version: nextVersion,
106
114
  canonicalUri,
107
115
  customMetadata
@@ -153,6 +161,11 @@ class FileArtifactService {
153
161
  );
154
162
  const metadataPath = path.join(versionDir, "metadata.json");
155
163
  const metadata = await readMetadata(metadataPath);
164
+ if (metadata.fileUri) {
165
+ return {
166
+ fileData: { fileUri: metadata.fileUri, mimeType: metadata.mimeType }
167
+ };
168
+ }
156
169
  const storedFilename = path.basename(artifactDir);
157
170
  let contentPath = path.join(versionDir, storedFilename);
158
171
  if (metadata.canonicalUri) {