@agent-native/core 0.131.4 → 0.131.6

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 (330) hide show
  1. package/corpus/README.md +3 -3
  2. package/corpus/core/CHANGELOG.md +69 -0
  3. package/corpus/core/docs/content/agent-native-toolkit.mdx +13 -6
  4. package/corpus/core/docs/content/cloneable-saas.mdx +5 -5
  5. package/corpus/core/docs/content/creating-templates.mdx +9 -0
  6. package/corpus/core/docs/content/deployment.mdx +14 -10
  7. package/corpus/core/docs/content/docs-components.mdx +491 -0
  8. package/corpus/core/docs/content/doctor.mdx +8 -1
  9. package/corpus/core/docs/content/drop-in-agent.mdx +1 -1
  10. package/corpus/core/docs/content/extensions.mdx +18 -18
  11. package/corpus/core/docs/content/faq.mdx +4 -4
  12. package/corpus/core/docs/content/key-concepts.mdx +30 -21
  13. package/corpus/core/docs/content/template-brain-developers.mdx +4 -1
  14. package/corpus/core/docs/content/template-mail-developers.mdx +4 -1
  15. package/corpus/core/docs/content/what-is-agent-native.mdx +6 -6
  16. package/corpus/core/package.json +1 -1
  17. package/corpus/core/src/a2a/client.ts +449 -66
  18. package/corpus/core/src/a2a/correlation.ts +31 -0
  19. package/corpus/core/src/a2a/types.ts +4 -0
  20. package/corpus/core/src/action.ts +3 -0
  21. package/corpus/core/src/agent/engine/registry.ts +45 -5
  22. package/corpus/core/src/agent/production-agent.ts +151 -18
  23. package/corpus/core/src/agent/run-loop-with-resume.ts +190 -3
  24. package/corpus/core/src/agent/run-manager.ts +117 -41
  25. package/corpus/core/src/agent/thread-debug-history.ts +86 -0
  26. package/corpus/core/src/agent/types.ts +3 -1
  27. package/corpus/core/src/cli/create.ts +11 -1
  28. package/corpus/core/src/cli/templates-meta.ts +2 -2
  29. package/corpus/core/src/client/agent-chat-adapter.ts +91 -13
  30. package/corpus/core/src/client/resources/McpIntegrationDialog.tsx +11 -9
  31. package/corpus/core/src/client/sse-event-processor.ts +17 -3
  32. package/corpus/core/src/db/client.ts +57 -17
  33. package/corpus/core/src/integrations/adapters/slack.ts +8 -3
  34. package/corpus/core/src/localization/default-messages.ts +44 -0
  35. package/corpus/core/src/observability/traces.ts +78 -5
  36. package/corpus/core/src/scripts/call-agent.ts +290 -9
  37. package/corpus/core/src/scripts/describe-workspace-apps.ts +2 -2
  38. package/corpus/core/src/secrets/crypto.ts +126 -34
  39. package/corpus/core/src/secrets/storage.ts +61 -25
  40. package/corpus/core/src/server/agent-capabilities.ts +1 -1
  41. package/corpus/core/src/server/agent-chat/action-filters-a2a.ts +111 -7
  42. package/corpus/core/src/server/agent-chat/context-tools.ts +2 -0
  43. package/corpus/core/src/server/agent-chat/plugin-options.ts +34 -1
  44. package/corpus/core/src/server/agent-chat/prompt-resources.ts +1 -1
  45. package/corpus/core/src/server/agent-chat-plugin.ts +91 -59
  46. package/corpus/core/src/templates/default/.agents/skills/secrets/SKILL.md +14 -7
  47. package/corpus/core/src/templates/headless/.agents/skills/secrets/SKILL.md +14 -7
  48. package/corpus/core/src/templates/workspace-core/.agents/skills/a2a-protocol/SKILL.md +18 -7
  49. package/corpus/core/src/templates/workspace-core/.agents/skills/composable-mini-apps/SKILL.md +15 -14
  50. package/corpus/core/src/templates/workspace-core/.agents/skills/secrets/SKILL.md +14 -7
  51. package/corpus/core/src/vite/client.ts +1 -0
  52. package/corpus/templates/analytics/.agents/skills/dashboard-ops/SKILL.md +5 -4
  53. package/corpus/templates/analytics/.agents/skills/gong/SKILL.md +6 -4
  54. package/corpus/templates/analytics/AGENTS.md +6 -4
  55. package/corpus/templates/analytics/actions/query-agent-native-analytics.ts +4 -3
  56. package/corpus/templates/analytics/changelog/2026-07-30-scheduled-dashboard-emails-complete-every-panel-without-pool.md +6 -0
  57. package/corpus/templates/analytics/scripts/emit-netlify-dashboard-report-cron.ts +28 -1
  58. package/corpus/templates/analytics/server/jobs/dashboard-report.ts +18 -11
  59. package/corpus/templates/analytics/server/lib/analytics-connector-catalog.ts +4 -4
  60. package/corpus/templates/analytics/server/lib/canonical-first-party-dashboard-repair.ts +9 -5
  61. package/corpus/templates/analytics/server/lib/dashboard-panel-query.ts +6 -2
  62. package/corpus/templates/analytics/server/lib/dashboard-panel-source-resolver.ts +11 -4
  63. package/corpus/templates/analytics/server/lib/dashboard-report-render.ts +49 -31
  64. package/corpus/templates/analytics/server/lib/first-party-analytics.ts +16 -8
  65. package/corpus/templates/analytics/server/lib/first-party-metric-catalog.ts +9 -3
  66. package/corpus/templates/analytics/server/lib/production-serverless-runtime.ts +11 -0
  67. package/corpus/templates/analytics/server/plugins/agent-chat.ts +3 -2
  68. package/corpus/templates/analytics/server/plugins/analytics-alert-jobs.ts +2 -1
  69. package/corpus/templates/analytics/server/plugins/dashboard-report-jobs.ts +2 -1
  70. package/corpus/templates/analytics/server/plugins/uptime-monitor-jobs.ts +1 -12
  71. package/corpus/templates/brain/.agents/skills/brain/RUNBOOK.md +54 -6
  72. package/corpus/templates/brain/.agents/skills/brain/SKILL.md +20 -9
  73. package/corpus/templates/brain/.agents/skills/ingestion-and-connectors/SKILL.md +33 -1
  74. package/corpus/templates/brain/AGENTS.md +3 -1
  75. package/corpus/templates/brain/README.md +4 -1
  76. package/corpus/templates/brain/actions/_schemas.ts +30 -8
  77. package/corpus/templates/brain/actions/ask-brain.ts +124 -14
  78. package/corpus/templates/brain/actions/create-source.ts +18 -2
  79. package/corpus/templates/brain/actions/enqueue-captures-distillation.ts +8 -123
  80. package/corpus/templates/brain/actions/enqueue-distillation.ts +6 -127
  81. package/corpus/templates/brain/actions/import-capture.ts +17 -5
  82. package/corpus/templates/brain/actions/import-transcript.ts +17 -5
  83. package/corpus/templates/brain/actions/update-source.ts +25 -5
  84. package/corpus/templates/brain/app/components/layout/Sidebar.tsx +1 -1
  85. package/corpus/templates/brain/changelog/2026-07-30-blessed-resources-can-feed-cited-company-answers.md +6 -0
  86. package/corpus/templates/brain/changelog/2026-07-30-the-left-sidebar-no-longer-shows-a-blank-organization-placeh.md +6 -0
  87. package/corpus/templates/brain/server/lib/brain.ts +49 -19
  88. package/corpus/templates/brain/server/lib/distillation-queue.ts +147 -0
  89. package/corpus/templates/brain/server/lib/source-policy.ts +264 -0
  90. package/corpus/templates/brain/server/plugins/agent-chat.ts +3 -2
  91. package/corpus/templates/brain/server/routes/api/_agent-native/brain/ingest.post.ts +116 -19
  92. package/corpus/templates/clips/app/components/meetings/google-oauth-identity-notice.tsx +51 -0
  93. package/corpus/templates/clips/app/i18n/en-US.ts +4 -0
  94. package/corpus/templates/clips/app/routes/_app.meetings._index.tsx +3 -1
  95. package/corpus/templates/clips/changelog/2026-07-30-google-calendar-warning.md +6 -0
  96. package/corpus/templates/content/.agents/skills/content-product-development/SKILL.md +47 -0
  97. package/corpus/templates/content/app/components/editor/VisualEditor.tsx +72 -8
  98. package/corpus/templates/content/changelog/2026-07-30-the-slash-command-hint-now-stays-on-only-the-active-empty-li.md +6 -0
  99. package/corpus/templates/design/.generated/bridge/editor-chrome.generated.ts +506 -11
  100. package/corpus/templates/design/app/components/design/bridge/editor-chrome.bridge.ts +148 -17
  101. package/corpus/templates/design/app/components/design/canvas-interactions/design-canvas-interactions.ts +357 -0
  102. package/corpus/templates/design/app/components/design/inspector/ScrubInput.tsx +7 -466
  103. package/corpus/templates/design/app/components/design/inspector/scrub-input-utils.ts +15 -311
  104. package/corpus/templates/design/app/components/visual-editor/CanvasCommentPins.tsx +19 -997
  105. package/corpus/templates/design/app/components/visual-editor/DrawOverlay.tsx +8 -1216
  106. package/corpus/templates/design/app/hooks/useDesignHotkeys.ts +31 -38
  107. package/corpus/templates/design/package.json +0 -1
  108. package/corpus/templates/dispatch/AGENTS.md +8 -0
  109. package/corpus/templates/dispatch/DEVELOPING.md +29 -0
  110. package/corpus/templates/dispatch/actions/view-screen.ts +34 -2
  111. package/corpus/templates/dispatch/app/i18n-data.ts +457 -0
  112. package/corpus/templates/dispatch/changelog/2026-07-30-delegated-dispatch-work-continues-reliably-in-the-background.md +6 -0
  113. package/corpus/templates/dispatch/changelog/2026-07-30-find-failed-runs-across-apps.md +6 -0
  114. package/corpus/templates/dispatch/netlify.toml +3 -0
  115. package/corpus/templates/slides/.agents/skills/analytics-data-for-decks/SKILL.md +8 -12
  116. package/corpus/templates/slides/AGENTS.md +4 -4
  117. package/corpus/templates/slides/actions/duplicate-deck.ts +19 -4
  118. package/corpus/templates/slides/app/components/deck/DeckCard.tsx +2 -10
  119. package/corpus/templates/slides/app/components/deck/MermaidRenderer.tsx +12 -1
  120. package/corpus/templates/slides/app/components/deck/SlideRenderer.tsx +30 -13
  121. package/corpus/templates/slides/app/components/editor/DeckEditorSkeleton.tsx +35 -0
  122. package/corpus/templates/slides/app/components/editor/EditorSidebar.tsx +63 -56
  123. package/corpus/templates/slides/app/components/editor/EditorToolbar.tsx +21 -76
  124. package/corpus/templates/slides/app/components/editor/SlideEditor.tsx +1110 -292
  125. package/corpus/templates/slides/app/components/editor/SlideOverflowWarning.tsx +53 -0
  126. package/corpus/templates/slides/app/components/editor/SlideStyleInspector.tsx +235 -18
  127. package/corpus/templates/slides/app/components/editor/SpeakerNotesPanel.tsx +4 -1
  128. package/corpus/templates/slides/app/components/editor/canvas-interactions/index.ts +11 -0
  129. package/corpus/templates/slides/app/components/editor/canvas-interactions/slides-canvas-adapter.ts +129 -0
  130. package/corpus/templates/slides/app/components/editor/selection-overlay-measurement.ts +70 -0
  131. package/corpus/templates/slides/app/components/editor/slide-object-interactions.ts +519 -65
  132. package/corpus/templates/slides/app/components/visual-editor/CanvasCommentPins.tsx +36 -426
  133. package/corpus/templates/slides/app/components/visual-editor/DrawOverlay.tsx +19 -458
  134. package/corpus/templates/slides/app/context/DeckContext.tsx +179 -72
  135. package/corpus/templates/slides/app/global.css +105 -0
  136. package/corpus/templates/slides/app/i18n/en-US.ts +8 -0
  137. package/corpus/templates/slides/app/lib/deck-editor-loading.ts +26 -0
  138. package/corpus/templates/slides/app/lib/mermaid-blocks.ts +27 -0
  139. package/corpus/templates/slides/app/pages/DeckEditor.tsx +71 -38
  140. package/corpus/templates/slides/app/pages/Index.tsx +98 -41
  141. package/corpus/templates/slides/changelog/2026-07-30-deck-loading-no-longer-flashes-an-unavailable-message.md +6 -0
  142. package/corpus/templates/slides/changelog/2026-07-30-duplicating-a-deck-from-the-deck-list-now-opens-the-copy-imm.md +6 -0
  143. package/corpus/templates/slides/changelog/2026-07-30-layout-overflow-warning-is-readable-and-dismissible.md +6 -0
  144. package/corpus/templates/slides/changelog/2026-07-30-shared-canvas-annotations.md +6 -0
  145. package/corpus/templates/slides/changelog/2026-07-30-slide-objects-can-be-moved-as-a-group-copied-and-pasted-with.md +6 -0
  146. package/corpus/templates/slides/changelog/2026-07-30-slide-text-editing-and-object-controls-now-match-google-slides.md +6 -0
  147. package/corpus/templates/slides/changelog/2026-07-30-style-panel-now-scrolls-with-speaker-notes-open-shows-the-sl.md +6 -0
  148. package/corpus/templates/slides/changelog/2026-07-30-top-toolbar-controls-now-use-consistent-sizing-with-undo-and.md +6 -0
  149. package/corpus/templates/slides/netlify.toml +3 -1
  150. package/corpus/templates/slides/package.json +0 -1
  151. package/corpus/templates/slides/server/lib/chat-attachments.ts +18 -0
  152. package/corpus/templates/slides/server/plugins/agent-chat.ts +5 -0
  153. package/corpus/templates/slides/vite.config.ts +0 -1
  154. package/corpus/toolkit/CHANGELOG.md +13 -0
  155. package/corpus/toolkit/README.md +19 -0
  156. package/corpus/toolkit/agent-native.eject.json +38 -0
  157. package/corpus/toolkit/package.json +29 -1
  158. package/corpus/toolkit/src/canvas-annotations/CanvasCommentPins.tsx +861 -0
  159. package/corpus/toolkit/src/canvas-annotations/DrawOverlay.tsx +1233 -0
  160. package/corpus/toolkit/src/canvas-annotations/index.ts +15 -0
  161. package/corpus/toolkit/src/canvas-annotations/types.ts +14 -0
  162. package/corpus/toolkit/src/canvas-interactions/canvas-interactions.ts +933 -0
  163. package/corpus/toolkit/src/canvas-interactions/index.ts +67 -0
  164. package/corpus/toolkit/src/design-tweaks/scrub-input-utils.ts +311 -0
  165. package/corpus/toolkit/src/design-tweaks/scrub-input.tsx +491 -0
  166. package/corpus/toolkit/src/design-tweaks/visual-style-controls.tsx +26 -171
  167. package/corpus/toolkit/src/index.ts +1 -0
  168. package/dist/a2a/client.d.ts +23 -0
  169. package/dist/a2a/client.d.ts.map +1 -1
  170. package/dist/a2a/client.js +309 -44
  171. package/dist/a2a/client.js.map +1 -1
  172. package/dist/a2a/correlation.d.ts +1 -0
  173. package/dist/a2a/correlation.d.ts.map +1 -1
  174. package/dist/a2a/correlation.js +27 -0
  175. package/dist/a2a/correlation.js.map +1 -1
  176. package/dist/a2a/types.d.ts +4 -0
  177. package/dist/a2a/types.d.ts.map +1 -1
  178. package/dist/a2a/types.js.map +1 -1
  179. package/dist/action.d.ts +3 -0
  180. package/dist/action.d.ts.map +1 -1
  181. package/dist/action.js.map +1 -1
  182. package/dist/agent/engine/registry.d.ts.map +1 -1
  183. package/dist/agent/engine/registry.js +34 -7
  184. package/dist/agent/engine/registry.js.map +1 -1
  185. package/dist/agent/production-agent.d.ts +40 -1
  186. package/dist/agent/production-agent.d.ts.map +1 -1
  187. package/dist/agent/production-agent.js +113 -15
  188. package/dist/agent/production-agent.js.map +1 -1
  189. package/dist/agent/run-loop-with-resume.d.ts +21 -0
  190. package/dist/agent/run-loop-with-resume.d.ts.map +1 -1
  191. package/dist/agent/run-loop-with-resume.js +163 -4
  192. package/dist/agent/run-loop-with-resume.js.map +1 -1
  193. package/dist/agent/run-manager.d.ts +16 -9
  194. package/dist/agent/run-manager.d.ts.map +1 -1
  195. package/dist/agent/run-manager.js +93 -42
  196. package/dist/agent/run-manager.js.map +1 -1
  197. package/dist/agent/thread-debug-history.d.ts +10 -0
  198. package/dist/agent/thread-debug-history.d.ts.map +1 -0
  199. package/dist/agent/thread-debug-history.js +68 -0
  200. package/dist/agent/thread-debug-history.js.map +1 -0
  201. package/dist/agent/types.d.ts +3 -1
  202. package/dist/agent/types.d.ts.map +1 -1
  203. package/dist/agent/types.js.map +1 -1
  204. package/dist/cli/create.d.ts.map +1 -1
  205. package/dist/cli/create.js +6 -1
  206. package/dist/cli/create.js.map +1 -1
  207. package/dist/cli/templates-meta.js +2 -2
  208. package/dist/cli/templates-meta.js.map +1 -1
  209. package/dist/client/agent-chat-adapter.d.ts +1 -1
  210. package/dist/client/agent-chat-adapter.d.ts.map +1 -1
  211. package/dist/client/agent-chat-adapter.js +76 -13
  212. package/dist/client/agent-chat-adapter.js.map +1 -1
  213. package/dist/client/resources/McpIntegrationDialog.d.ts.map +1 -1
  214. package/dist/client/resources/McpIntegrationDialog.js +1 -1
  215. package/dist/client/resources/McpIntegrationDialog.js.map +1 -1
  216. package/dist/client/sse-event-processor.d.ts.map +1 -1
  217. package/dist/client/sse-event-processor.js +12 -3
  218. package/dist/client/sse-event-processor.js.map +1 -1
  219. package/dist/collab/awareness.d.ts +2 -2
  220. package/dist/collab/awareness.d.ts.map +1 -1
  221. package/dist/db/client.d.ts.map +1 -1
  222. package/dist/db/client.js +48 -17
  223. package/dist/db/client.js.map +1 -1
  224. package/dist/file-upload/actions/upload-image.d.ts +1 -1
  225. package/dist/integrations/adapters/slack.js +7 -3
  226. package/dist/integrations/adapters/slack.js.map +1 -1
  227. package/dist/localization/default-messages.d.ts +43 -0
  228. package/dist/localization/default-messages.d.ts.map +1 -1
  229. package/dist/localization/default-messages.js +43 -0
  230. package/dist/localization/default-messages.js.map +1 -1
  231. package/dist/notifications/routes.d.ts +2 -2
  232. package/dist/observability/traces.d.ts +3 -1
  233. package/dist/observability/traces.d.ts.map +1 -1
  234. package/dist/observability/traces.js +73 -4
  235. package/dist/observability/traces.js.map +1 -1
  236. package/dist/progress/routes.d.ts +1 -1
  237. package/dist/provider-api/actions/custom-provider-registration.d.ts +12 -12
  238. package/dist/provider-api/actions/provider-api.d.ts +13 -13
  239. package/dist/provider-api/corpus-jobs.d.ts +2 -2
  240. package/dist/resources/handlers.d.ts +1 -1
  241. package/dist/scripts/call-agent.d.ts.map +1 -1
  242. package/dist/scripts/call-agent.js +233 -10
  243. package/dist/scripts/call-agent.js.map +1 -1
  244. package/dist/scripts/describe-workspace-apps.js +2 -2
  245. package/dist/scripts/describe-workspace-apps.js.map +1 -1
  246. package/dist/secrets/crypto.d.ts +31 -21
  247. package/dist/secrets/crypto.d.ts.map +1 -1
  248. package/dist/secrets/crypto.js +108 -33
  249. package/dist/secrets/crypto.js.map +1 -1
  250. package/dist/secrets/storage.d.ts +3 -5
  251. package/dist/secrets/storage.d.ts.map +1 -1
  252. package/dist/secrets/storage.js +40 -25
  253. package/dist/secrets/storage.js.map +1 -1
  254. package/dist/server/agent-capabilities.js +1 -1
  255. package/dist/server/agent-capabilities.js.map +1 -1
  256. package/dist/server/agent-chat/action-filters-a2a.d.ts +17 -3
  257. package/dist/server/agent-chat/action-filters-a2a.d.ts.map +1 -1
  258. package/dist/server/agent-chat/action-filters-a2a.js +92 -3
  259. package/dist/server/agent-chat/action-filters-a2a.js.map +1 -1
  260. package/dist/server/agent-chat/context-tools.d.ts.map +1 -1
  261. package/dist/server/agent-chat/context-tools.js +2 -0
  262. package/dist/server/agent-chat/context-tools.js.map +1 -1
  263. package/dist/server/agent-chat/plugin-options.d.ts +23 -0
  264. package/dist/server/agent-chat/plugin-options.d.ts.map +1 -1
  265. package/dist/server/agent-chat/plugin-options.js +4 -1
  266. package/dist/server/agent-chat/plugin-options.js.map +1 -1
  267. package/dist/server/agent-chat/prompt-resources.js +1 -1
  268. package/dist/server/agent-chat/prompt-resources.js.map +1 -1
  269. package/dist/server/agent-chat-plugin.d.ts +2 -1
  270. package/dist/server/agent-chat-plugin.d.ts.map +1 -1
  271. package/dist/server/agent-chat-plugin.js +79 -56
  272. package/dist/server/agent-chat-plugin.js.map +1 -1
  273. package/dist/server/agent-engine-api-key-route.d.ts +1 -1
  274. package/dist/templates/default/.agents/skills/secrets/SKILL.md +14 -7
  275. package/dist/templates/headless/.agents/skills/secrets/SKILL.md +14 -7
  276. package/dist/templates/workspace-core/.agents/skills/a2a-protocol/SKILL.md +18 -7
  277. package/dist/templates/workspace-core/.agents/skills/composable-mini-apps/SKILL.md +15 -14
  278. package/dist/templates/workspace-core/.agents/skills/secrets/SKILL.md +14 -7
  279. package/dist/vite/client.d.ts.map +1 -1
  280. package/dist/vite/client.js +1 -0
  281. package/dist/vite/client.js.map +1 -1
  282. package/docs/content/agent-native-toolkit.mdx +13 -6
  283. package/docs/content/cloneable-saas.mdx +5 -5
  284. package/docs/content/creating-templates.mdx +9 -0
  285. package/docs/content/deployment.mdx +14 -10
  286. package/docs/content/docs-components.mdx +491 -0
  287. package/docs/content/doctor.mdx +8 -1
  288. package/docs/content/drop-in-agent.mdx +1 -1
  289. package/docs/content/extensions.mdx +18 -18
  290. package/docs/content/faq.mdx +4 -4
  291. package/docs/content/key-concepts.mdx +30 -21
  292. package/docs/content/template-brain-developers.mdx +4 -1
  293. package/docs/content/template-mail-developers.mdx +4 -1
  294. package/docs/content/what-is-agent-native.mdx +6 -6
  295. package/package.json +2 -2
  296. package/src/a2a/client.ts +449 -66
  297. package/src/a2a/correlation.ts +31 -0
  298. package/src/a2a/types.ts +4 -0
  299. package/src/action.ts +3 -0
  300. package/src/agent/engine/registry.ts +45 -5
  301. package/src/agent/production-agent.ts +151 -18
  302. package/src/agent/run-loop-with-resume.ts +190 -3
  303. package/src/agent/run-manager.ts +117 -41
  304. package/src/agent/thread-debug-history.ts +86 -0
  305. package/src/agent/types.ts +3 -1
  306. package/src/cli/create.ts +11 -1
  307. package/src/cli/templates-meta.ts +2 -2
  308. package/src/client/agent-chat-adapter.ts +91 -13
  309. package/src/client/resources/McpIntegrationDialog.tsx +11 -9
  310. package/src/client/sse-event-processor.ts +17 -3
  311. package/src/db/client.ts +57 -17
  312. package/src/integrations/adapters/slack.ts +8 -3
  313. package/src/localization/default-messages.ts +44 -0
  314. package/src/observability/traces.ts +78 -5
  315. package/src/scripts/call-agent.ts +290 -9
  316. package/src/scripts/describe-workspace-apps.ts +2 -2
  317. package/src/secrets/crypto.ts +126 -34
  318. package/src/secrets/storage.ts +61 -25
  319. package/src/server/agent-capabilities.ts +1 -1
  320. package/src/server/agent-chat/action-filters-a2a.ts +111 -7
  321. package/src/server/agent-chat/context-tools.ts +2 -0
  322. package/src/server/agent-chat/plugin-options.ts +34 -1
  323. package/src/server/agent-chat/prompt-resources.ts +1 -1
  324. package/src/server/agent-chat-plugin.ts +91 -59
  325. package/src/templates/default/.agents/skills/secrets/SKILL.md +14 -7
  326. package/src/templates/headless/.agents/skills/secrets/SKILL.md +14 -7
  327. package/src/templates/workspace-core/.agents/skills/a2a-protocol/SKILL.md +18 -7
  328. package/src/templates/workspace-core/.agents/skills/composable-mini-apps/SKILL.md +15 -14
  329. package/src/templates/workspace-core/.agents/skills/secrets/SKILL.md +14 -7
  330. package/src/vite/client.ts +1 -0
@@ -95,7 +95,7 @@ export function formatCapabilitySummary(peers, truncated, detailHint) {
95
95
  "",
96
96
  lines.join("\n\n"),
97
97
  "",
98
- "Delegate with call-agent: pass action + input for a listed action, or message for open-ended work. Prefer the app that owns the data over rebuilding its capability here.",
98
+ "Delegate with call-agent using a natural-language message by default. The receiving app owns interpretation and its local tools. Use action + input only for an exact bounded read with a fully known schema, never as a workaround for failed delegation. Prefer the app that owns the data over rebuilding its capability here.",
99
99
  ]
100
100
  .filter(Boolean)
101
101
  .join("\n");
@@ -1 +1 @@
1
- {"version":3,"file":"agent-capabilities.js","sourceRoot":"","sources":["../../src/server/agent-capabilities.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAG7C,OAAO,EAAE,mBAAmB,EAAE,MAAM,sBAAsB,CAAC;AAE3D,0EAA0E;AAC1E,MAAM,CAAC,MAAM,QAAQ,GAAG,EAAE,CAAC;AAC3B,MAAM,qBAAqB,GAAG,CAAC,CAAC;AAChC,MAAM,oBAAoB,GAAG,EAAE,CAAC;AAChC,MAAM,qBAAqB,GAAG,GAAG,CAAC;AAClC,MAAM,eAAe,GAAG,KAAK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E,0CAA0C;QAC1C,OAAO,KAAK,KAAK,CAAC,EAAE,GAAG,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,aAAa,KAAK,OAAO,GACpE,gBAAgB,CAAC,KAAK,CAAC,IAAI,EAC7B,EAAE,CAAC;IACL,CAAC,CAAC,CAAC;IAEH,OAAO;QACL,MAAM;QACN,EAAE;QACF,mBAAmB;QACnB,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC;QAChB,IAAI,GAAG,CAAC,CAAC,CAAC,CAAC,KAAK,IAAI,mBAAmB,CAAC,CAAC,CAAC,EAAE;QAC5C,EAAE;QACF,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC;KACxB;SACE,MAAM,CAAC,OAAO,CAAC;SACf,IAAI,CAAC,IAAI,CAAC,CAAC;AAChB,CAAC","sourcesContent":["import { A2AClient } from \"../a2a/client.js\";\nimport type { AgentCard, AgentSkill } from \"../a2a/types.js\";\nimport { type DiscoveredAgent } from \"./agent-discovery.js\";\nimport { getRequestUserEmail } from \"./request-context.js\";\n\n/** Matches the `<available-apps>` prompt block so both surfaces agree. */\nexport const MAX_APPS = 30;\nconst MAX_SKILLS_IN_SUMMARY = 8;\nconst MAX_SKILLS_IN_DETAIL = 60;\nconst MAX_DESCRIPTION_CHARS = 240;\nconst CARD_TIMEOUT_MS = 6_000;\nconst CARD_CONCURRENCY = 8;\n\nexport interface PeerCapabilities {\n agent: DiscoveredAgent;\n /** null distinguishes an unreachable card from a peer that exposes nothing. */\n skills: AgentSkill[] | null;\n cardDescription?: string;\n error?: string;\n /**\n * The full card from this same fetch, for callers that need more than\n * skills/description (e.g. the peer-probe route's name/securitySchemes).\n * Kept optional so existing consumers of this shape are unaffected.\n */\n card?: AgentCard;\n}\n\nfunction truncate(value: string, max: number): string {\n const collapsed = value.replace(/\\s+/g, \" \").trim();\n return collapsed.length > max ? `${collapsed.slice(0, max - 1)}…` : collapsed;\n}\n\nexport async function loadCapabilities(\n agent: DiscoveredAgent,\n): Promise<PeerCapabilities> {\n try {\n // Discover as ourselves. An anonymous card lists only publicly-safe\n // actions, which never overlap the set `actions/invoke` accepts, so an\n // unauthenticated probe reports every sibling as having no callable\n // actions and pushes the caller into open-ended delegation.\n let token: string | undefined;\n try {\n const { signA2AToken } = await import(\"../a2a/client.js\");\n const email = getRequestUserEmail();\n if (email) {\n token = await signA2AToken(email, undefined, undefined, {\n preferGlobalSecret: true,\n audience: new URL(agent.url).origin,\n });\n }\n } catch {\n // No signable identity (no secret, no session) — fall back to the\n // anonymous card rather than failing discovery outright.\n }\n const card = await new A2AClient(agent.url).getAgentCard({\n timeoutMs: CARD_TIMEOUT_MS,\n ...(token ? { token } : {}),\n });\n return {\n agent,\n skills: Array.isArray(card.skills) ? card.skills : [],\n cardDescription:\n typeof card.description === \"string\" ? card.description : undefined,\n card,\n };\n } catch (error) {\n return {\n agent,\n skills: null,\n error: error instanceof Error ? error.message : String(error),\n };\n }\n}\n\nexport async function loadAllCapabilities(\n agents: DiscoveredAgent[],\n): Promise<PeerCapabilities[]> {\n const results: PeerCapabilities[] = [];\n for (let i = 0; i < agents.length; i += CARD_CONCURRENCY) {\n results.push(\n ...(await Promise.all(\n agents.slice(i, i + CARD_CONCURRENCY).map(loadCapabilities),\n )),\n );\n }\n return results;\n}\n\nexport function purposeOf(peer: PeerCapabilities): string {\n // The manifest description comes from the app's own package.json and is\n // authored; the card description is a generic template for auto-mounted\n // apps, so it is only a fallback.\n const manifest = peer.agent.description?.trim();\n if (manifest) return truncate(manifest, MAX_DESCRIPTION_CHARS);\n const card = peer.cardDescription?.trim();\n return card\n ? truncate(card, MAX_DESCRIPTION_CHARS)\n : \"(no description published)\";\n}\n\n/**\n * `detailHint` differs per surface: the agent tool tells the model to call\n * itself again with an app id, the CLI tells the reader to pass `--app`.\n */\nexport function formatCapabilitySummary(\n peers: PeerCapabilities[],\n truncated: number,\n detailHint: (appId: string) => string,\n): string {\n const lines = peers.map((peer) => {\n const header = `### ${peer.agent.name} (${peer.agent.id})\\n${purposeOf(peer)}`;\n if (peer.skills === null) {\n return `${header}\\nCapabilities: could not read agent card (${truncate(peer.error ?? \"unreachable\", 120)}). Delegate with a natural-language message instead of a direct action.`;\n }\n if (peer.skills.length === 0) {\n return `${header}\\nCapabilities: exposes no directly callable actions. Delegate with a natural-language message via call-agent.`;\n }\n const shown = peer.skills.slice(0, MAX_SKILLS_IN_SUMMARY);\n const rest = peer.skills.length - shown.length;\n return `${header}\\nCallable actions: ${shown.map((skill) => skill.id).join(\", \")}${\n rest > 0 ? ` (+${rest} more — ${detailHint(peer.agent.id)})` : \"\"\n }`;\n });\n\n return [\n `${peers.length} other app${peers.length === 1 ? \"\" : \"s\"} reachable from this one over A2A.`,\n truncated > 0\n ? `(${truncated} additional app${truncated === 1 ? \"\" : \"s\"} not shown.)`\n : \"\",\n \"\",\n lines.join(\"\\n\\n\"),\n \"\",\n \"Delegate with call-agent: pass action + input for a listed action, or message for open-ended work. Prefer the app that owns the data over rebuilding its capability here.\",\n ]\n .filter(Boolean)\n .join(\"\\n\");\n}\n\n/**\n * Render a skill's `input` contract as `input: { field*: type, other?: type }`,\n * marking required fields with `*`. Returns undefined when the skill publishes\n * no schema, so callers fall back to the description alone.\n */\nfunction formatSkillInput(skill: AgentSkill): string | undefined {\n const schema = skill.inputSchema as\n | {\n properties?: Record<string, { type?: unknown }>;\n required?: unknown;\n }\n | undefined;\n const properties = schema?.properties;\n if (!properties || typeof properties !== \"object\") return undefined;\n const names = Object.keys(properties);\n if (names.length === 0) return \" — input: {} (no fields)\";\n\n const required = new Set(\n Array.isArray(schema?.required)\n ? schema.required.filter(\n (name): name is string => typeof name === \"string\",\n )\n : [],\n );\n const fields = names.map((name) => {\n const type = properties[name]?.type;\n const rendered = typeof type === \"string\" ? type : \"any\";\n return `${name}${required.has(name) ? \"*\" : \"?\"}: ${rendered}`;\n });\n return ` — input: { ${fields.join(\", \")} } (* = required)`;\n}\n\nexport function formatCapabilityDetail(\n peer: PeerCapabilities,\n callHint: (appId: string) => string,\n): string {\n const header = `## ${peer.agent.name} (${peer.agent.id})\\n${purposeOf(peer)}\\nURL: ${peer.agent.url}`;\n\n if (peer.skills === null) {\n return `${header}\\n\\nIts agent card could not be read (${truncate(peer.error ?? \"unreachable\", 200)}), so its callable actions are unknown. It may still answer a natural-language call-agent message.`;\n }\n if (peer.skills.length === 0) {\n return `${header}\\n\\nIt exposes no directly callable actions. Delegate with a natural-language call-agent message.`;\n }\n\n const shown = peer.skills.slice(0, MAX_SKILLS_IN_DETAIL);\n const rest = peer.skills.length - shown.length;\n const lines = shown.map((skill) => {\n const summary = skill.description\n ? truncate(skill.description, MAX_DESCRIPTION_CHARS)\n : skill.name || \"(no description)\";\n // Naming an action without its parameters is what makes a caller invoke it\n // with `{}` and fail on a required field, which reads as the sibling being\n // broken rather than as a malformed call.\n return `- ${skill.id}${skill.readOnly ? \"\" : \" (mutating)\"}: ${summary}${\n formatSkillInput(skill) ?? \"\"\n }`;\n });\n\n return [\n header,\n \"\",\n \"Callable actions:\",\n lines.join(\"\\n\"),\n rest > 0 ? `(+${rest} more not shown.)` : \"\",\n \"\",\n callHint(peer.agent.id),\n ]\n .filter(Boolean)\n .join(\"\\n\");\n}\n"]}
1
+ {"version":3,"file":"agent-capabilities.js","sourceRoot":"","sources":["../../src/server/agent-capabilities.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAG7C,OAAO,EAAE,mBAAmB,EAAE,MAAM,sBAAsB,CAAC;AAE3D,0EAA0E;AAC1E,MAAM,CAAC,MAAM,QAAQ,GAAG,EAAE,CAAC;AAC3B,MAAM,qBAAqB,GAAG,CAAC,CAAC;AAChC,MAAM,oBAAoB,GAAG,EAAE,CAAC;AAChC,MAAM,qBAAqB,GAAG,GAAG,CAAC;AAClC,MAAM,eAAe,GAAG,KAAK,CAAC;AAC9B,MAAM,gBAAgB,GAAG,CAAC,CAAC;AAgB3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KAAK,CAAC,QAAQ,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,aAAa,KAAK,OAAO,GACpE,gBAAgB,CAAC,KAAK,CAAC,IAAI,EAC7B,EAAE,CAAC;IACL,CAAC,CAAC,CAAC;IAEH,OAAO;QACL,MAAM;QACN,EAAE;QACF,mBAAmB;QACnB,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC;QAChB,IAAI,GAAG,CAAC,CAAC,CAAC,CAAC,KAAK,IAAI,mBAAmB,CAAC,CAAC,CAAC,EAAE;QAC5C,EAAE;QACF,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC;KACxB;SACE,MAAM,CAAC,OAAO,CAAC;SACf,IAAI,CAAC,IAAI,CAAC,CAAC;AAChB,CAAC","sourcesContent":["import { A2AClient } from \"../a2a/client.js\";\nimport type { AgentCard, AgentSkill } from \"../a2a/types.js\";\nimport { type DiscoveredAgent } from \"./agent-discovery.js\";\nimport { getRequestUserEmail } from \"./request-context.js\";\n\n/** Matches the `<available-apps>` prompt block so both surfaces agree. */\nexport const MAX_APPS = 30;\nconst MAX_SKILLS_IN_SUMMARY = 8;\nconst MAX_SKILLS_IN_DETAIL = 60;\nconst MAX_DESCRIPTION_CHARS = 240;\nconst CARD_TIMEOUT_MS = 6_000;\nconst CARD_CONCURRENCY = 8;\n\nexport interface PeerCapabilities {\n agent: DiscoveredAgent;\n /** null distinguishes an unreachable card from a peer that exposes nothing. */\n skills: AgentSkill[] | null;\n cardDescription?: string;\n error?: string;\n /**\n * The full card from this same fetch, for callers that need more than\n * skills/description (e.g. the peer-probe route's name/securitySchemes).\n * Kept optional so existing consumers of this shape are unaffected.\n */\n card?: AgentCard;\n}\n\nfunction truncate(value: string, max: number): string {\n const collapsed = value.replace(/\\s+/g, \" \").trim();\n return collapsed.length > max ? `${collapsed.slice(0, max - 1)}…` : collapsed;\n}\n\nexport async function loadCapabilities(\n agent: DiscoveredAgent,\n): Promise<PeerCapabilities> {\n try {\n // Discover as ourselves. An anonymous card lists only publicly-safe\n // actions, which never overlap the set `actions/invoke` accepts, so an\n // unauthenticated probe reports every sibling as having no callable\n // actions and pushes the caller into open-ended delegation.\n let token: string | undefined;\n try {\n const { signA2AToken } = await import(\"../a2a/client.js\");\n const email = getRequestUserEmail();\n if (email) {\n token = await signA2AToken(email, undefined, undefined, {\n preferGlobalSecret: true,\n audience: new URL(agent.url).origin,\n });\n }\n } catch {\n // No signable identity (no secret, no session) — fall back to the\n // anonymous card rather than failing discovery outright.\n }\n const card = await new A2AClient(agent.url).getAgentCard({\n timeoutMs: CARD_TIMEOUT_MS,\n ...(token ? { token } : {}),\n });\n return {\n agent,\n skills: Array.isArray(card.skills) ? card.skills : [],\n cardDescription:\n typeof card.description === \"string\" ? card.description : undefined,\n card,\n };\n } catch (error) {\n return {\n agent,\n skills: null,\n error: error instanceof Error ? error.message : String(error),\n };\n }\n}\n\nexport async function loadAllCapabilities(\n agents: DiscoveredAgent[],\n): Promise<PeerCapabilities[]> {\n const results: PeerCapabilities[] = [];\n for (let i = 0; i < agents.length; i += CARD_CONCURRENCY) {\n results.push(\n ...(await Promise.all(\n agents.slice(i, i + CARD_CONCURRENCY).map(loadCapabilities),\n )),\n );\n }\n return results;\n}\n\nexport function purposeOf(peer: PeerCapabilities): string {\n // The manifest description comes from the app's own package.json and is\n // authored; the card description is a generic template for auto-mounted\n // apps, so it is only a fallback.\n const manifest = peer.agent.description?.trim();\n if (manifest) return truncate(manifest, MAX_DESCRIPTION_CHARS);\n const card = peer.cardDescription?.trim();\n return card\n ? truncate(card, MAX_DESCRIPTION_CHARS)\n : \"(no description published)\";\n}\n\n/**\n * `detailHint` differs per surface: the agent tool tells the model to call\n * itself again with an app id, the CLI tells the reader to pass `--app`.\n */\nexport function formatCapabilitySummary(\n peers: PeerCapabilities[],\n truncated: number,\n detailHint: (appId: string) => string,\n): string {\n const lines = peers.map((peer) => {\n const header = `### ${peer.agent.name} (${peer.agent.id})\\n${purposeOf(peer)}`;\n if (peer.skills === null) {\n return `${header}\\nCapabilities: could not read agent card (${truncate(peer.error ?? \"unreachable\", 120)}). Delegate with a natural-language message instead of a direct action.`;\n }\n if (peer.skills.length === 0) {\n return `${header}\\nCapabilities: exposes no directly callable actions. Delegate with a natural-language message via call-agent.`;\n }\n const shown = peer.skills.slice(0, MAX_SKILLS_IN_SUMMARY);\n const rest = peer.skills.length - shown.length;\n return `${header}\\nCallable actions: ${shown.map((skill) => skill.id).join(\", \")}${\n rest > 0 ? ` (+${rest} more — ${detailHint(peer.agent.id)})` : \"\"\n }`;\n });\n\n return [\n `${peers.length} other app${peers.length === 1 ? \"\" : \"s\"} reachable from this one over A2A.`,\n truncated > 0\n ? `(${truncated} additional app${truncated === 1 ? \"\" : \"s\"} not shown.)`\n : \"\",\n \"\",\n lines.join(\"\\n\\n\"),\n \"\",\n \"Delegate with call-agent using a natural-language message by default. The receiving app owns interpretation and its local tools. Use action + input only for an exact bounded read with a fully known schema, never as a workaround for failed delegation. Prefer the app that owns the data over rebuilding its capability here.\",\n ]\n .filter(Boolean)\n .join(\"\\n\");\n}\n\n/**\n * Render a skill's `input` contract as `input: { field*: type, other?: type }`,\n * marking required fields with `*`. Returns undefined when the skill publishes\n * no schema, so callers fall back to the description alone.\n */\nfunction formatSkillInput(skill: AgentSkill): string | undefined {\n const schema = skill.inputSchema as\n | {\n properties?: Record<string, { type?: unknown }>;\n required?: unknown;\n }\n | undefined;\n const properties = schema?.properties;\n if (!properties || typeof properties !== \"object\") return undefined;\n const names = Object.keys(properties);\n if (names.length === 0) return \" — input: {} (no fields)\";\n\n const required = new Set(\n Array.isArray(schema?.required)\n ? schema.required.filter(\n (name): name is string => typeof name === \"string\",\n )\n : [],\n );\n const fields = names.map((name) => {\n const type = properties[name]?.type;\n const rendered = typeof type === \"string\" ? type : \"any\";\n return `${name}${required.has(name) ? \"*\" : \"?\"}: ${rendered}`;\n });\n return ` — input: { ${fields.join(\", \")} } (* = required)`;\n}\n\nexport function formatCapabilityDetail(\n peer: PeerCapabilities,\n callHint: (appId: string) => string,\n): string {\n const header = `## ${peer.agent.name} (${peer.agent.id})\\n${purposeOf(peer)}\\nURL: ${peer.agent.url}`;\n\n if (peer.skills === null) {\n return `${header}\\n\\nIts agent card could not be read (${truncate(peer.error ?? \"unreachable\", 200)}), so its callable actions are unknown. It may still answer a natural-language call-agent message.`;\n }\n if (peer.skills.length === 0) {\n return `${header}\\n\\nIt exposes no directly callable actions. Delegate with a natural-language call-agent message.`;\n }\n\n const shown = peer.skills.slice(0, MAX_SKILLS_IN_DETAIL);\n const rest = peer.skills.length - shown.length;\n const lines = shown.map((skill) => {\n const summary = skill.description\n ? truncate(skill.description, MAX_DESCRIPTION_CHARS)\n : skill.name || \"(no description)\";\n // Naming an action without its parameters is what makes a caller invoke it\n // with `{}` and fail on a required field, which reads as the sibling being\n // broken rather than as a malformed call.\n return `- ${skill.id}${skill.readOnly ? \"\" : \" (mutating)\"}: ${summary}${\n formatSkillInput(skill) ?? \"\"\n }`;\n });\n\n return [\n header,\n \"\",\n \"Callable actions:\",\n lines.join(\"\\n\"),\n rest > 0 ? `(+${rest} more not shown.)` : \"\",\n \"\",\n callHint(peer.agent.id),\n ]\n .filter(Boolean)\n .join(\"\\n\");\n}\n"]}
@@ -1,6 +1,6 @@
1
1
  import { type A2AArtifactResponseOptions, type A2AToolResultSummary } from "../../a2a/artifact-response.js";
2
2
  import type { EngineTool } from "../../agent/engine/types.js";
3
- import { type ActionEntry } from "../../agent/production-agent.js";
3
+ import { type ActionEntry, type AgentLoopOutcome } from "../../agent/production-agent.js";
4
4
  import { runAgentLoopDirectWithSoftTimeout } from "../../agent/run-loop-with-resume.js";
5
5
  import type { AgentChatEvent } from "../../agent/types.js";
6
6
  import type { AgentChatPluginOptions } from "./plugin-options.js";
@@ -57,11 +57,25 @@ export declare function buildAuthenticatedAgentA2ASkills(actions: Record<string,
57
57
  export declare function resolveArtifactBaseUrl(event: any | undefined): string | undefined;
58
58
  export declare function assembleA2AFinalResponse(events: readonly AgentChatEvent[], toolResults: readonly A2AToolResultSummary[], options?: A2AArtifactResponseOptions & {
59
59
  event?: any;
60
+ outcome?: AgentLoopOutcome;
60
61
  }): {
61
62
  responseText: string;
62
63
  finalText: string;
63
64
  };
64
65
  type A2AAgentLoopRunner = typeof runAgentLoopDirectWithSoftTimeout;
66
+ /**
67
+ * Delegated turns should do specialist work with the receiver's own tools,
68
+ * but must return a bounded caller-ready result. Interactive defaults allow
69
+ * extremely deep work (400 iterations / 20M cumulative input tokens), which
70
+ * made healthy Slides -> Analytics calls take 4-13 minutes and consume up to
71
+ * millions of input tokens as tool results accumulated. These defaults leave
72
+ * ample room for multi-source analysis while failing before a delegated turn
73
+ * can silently become an unbounded research session.
74
+ */
75
+ export declare const DEFAULT_DELEGATED_MAX_ITERATIONS = 80;
76
+ export declare const DEFAULT_DELEGATED_MAX_RUN_INPUT_TOKENS = 750000;
77
+ export declare const DEFAULT_DELEGATED_MAX_TOOL_RESULT_CHARS = 20000;
78
+ export declare const DELEGATED_AGENT_EXECUTION_CONTRACT = "\n<delegated-agent-contract>\nThis request was delegated by another app. You are the specialist owner of the work.\n- Interpret the caller's natural-language objective using your own instructions, skills, data dictionary, credentials, and tools. Choose providers, schemas, queries, and joins here; never ask the caller to invent SQL or source-specific implementation details for you.\n- Minimize round trips. Filter, join, aggregate, paginate, stage, and reduce large datasets inside your own tools rather than returning raw records or transcripts.\n- Return a concise caller-ready result with the answer, source and coverage details, relevant counts or IDs, caveats/partial gaps, and exact artifact URLs. Do not return tool transcripts or large raw payloads.\n</delegated-agent-contract>";
65
79
  export interface DelegatedAgentLoopTelemetry {
66
80
  runId: string;
67
81
  threadId: string | null;
@@ -86,13 +100,13 @@ interface DelegatedAgentLoopOptions {
86
100
  * template guarantees such as Analytics' requirement to query real data
87
101
  * before presenting metrics or exhaustive provider conclusions.
88
102
  */
89
- export declare function runA2AAgentLoop(runOptions: Parameters<A2AAgentLoopRunner>[0], pluginOptions: Pick<AgentChatPluginOptions, "finalResponseGuard" | "runSoftTimeoutMs">, timeoutOptions: Parameters<A2AAgentLoopRunner>[2], options?: DelegatedAgentLoopOptions): Promise<import("../../agent/production-agent.js").AgentLoopUsage>;
103
+ export declare function runA2AAgentLoop(runOptions: Parameters<A2AAgentLoopRunner>[0], pluginOptions: Pick<AgentChatPluginOptions, "delegatedRunPolicy" | "finalResponseGuard" | "runSoftTimeoutMs">, timeoutOptions: Parameters<A2AAgentLoopRunner>[2], options?: DelegatedAgentLoopOptions): Promise<import("../../agent/production-agent.js").AgentLoopUsage>;
90
104
  /**
91
105
  * Run the MCP-local ask_app turn with the same app-level response guard as
92
106
  * A2A. Keeping this seam shared prevents hosted MCP callers from bypassing
93
107
  * template guarantees when the request cannot use the self-A2A route.
94
108
  */
95
- export declare function runMCPAgentLoop(runOptions: Parameters<A2AAgentLoopRunner>[0], pluginOptions: Pick<AgentChatPluginOptions, "finalResponseGuard" | "runSoftTimeoutMs">, timeoutOptions: Parameters<A2AAgentLoopRunner>[2], options?: DelegatedAgentLoopOptions): Promise<import("../../agent/production-agent.js").AgentLoopUsage>;
109
+ export declare function runMCPAgentLoop(runOptions: Parameters<A2AAgentLoopRunner>[0], pluginOptions: Pick<AgentChatPluginOptions, "delegatedRunPolicy" | "finalResponseGuard" | "runSoftTimeoutMs">, timeoutOptions: Parameters<A2AAgentLoopRunner>[2], options?: DelegatedAgentLoopOptions): Promise<import("../../agent/production-agent.js").AgentLoopUsage>;
96
110
  /**
97
111
  * Keep delegated A2A turns on the same compact initial tool surface as
98
112
  * interactive chat. `tool-search` remains in the initial set, while the
@@ -1 +1 @@
1
- {"version":3,"file":"action-filters-a2a.d.ts","sourceRoot":"","sources":["../../../src/server/agent-chat/action-filters-a2a.ts"],"names":[],"mappings":"AAEA,OAAO,EAEL,KAAK,0BAA0B,EAC/B,KAAK,oBAAoB,EAC1B,MAAM,gCAAgC,CAAC;AAGxC,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,6BAA6B,CAAC;AAC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EAAE,MAAM,CAAC;QAChB,WAAW,CAAC,EAAE,MAAM,CAAC;QACrB,YAAY,CAAC,EAAE,MAAM,CAAC;KACvB,CAAC;CACH;AAED,UAAU,yBAAyB;IACjC,MAAM,CAAC,EAAE,kBAAkB,CAAC;IAC5B,SAAS,CAAC,EAAE,2BAA2B,CAAC;CACzC;AAiFD;;;;;;;GAOG;AACH,wBAAgB,eAAe,CAC7B,UAAU,EAAE,UAAU,CAAC,kBAAkB,CAAC,CAAC,CAAC,CAAC,EAC7C,aAAa,EAAE,IAAI,CACjB,sBAAsB,EACtB,oBAAoB,GAAG,oBAAoB,GAAG,kBAAkB,CACjE,EACD,cAAc,EAAE,UAAU,CAAC,kBAAkB,CAAC,CAAC,CAAC,CAAC,EACjD,OAAO,GAAE,yBAA8B,qEAQxC;AAED;;;;GAIG;AACH,wBAAgB,eAAe,CAC7B,UAAU,EAAE,UAAU,CAAC,kBAAkB,CAAC,CAAC,CAAC,CAAC,EAC7C,aAAa,EAAE,IAAI,CACjB,sBAAsB,EACtB,oBAAoB,GAAG,oBAAoB,GAAG,kBAAkB,CACjE,EACD,cAAc,EAAE,UAAU,CAAC,kBAAkB,CAAC,CAAC,CAAC,CAAC,EACjD,OAAO,GAAE,yBAA8B,qEAQxC;AAED;;;;;GAKG;AACH,wBAAgB,0BAA0B,CACxC,cAAc,EAAE,UAAU,EAAE,EAC5B,gBAAgB,CAAC,EAAE,MAAM,EAAE,GAC1B;IAAE,KAAK,EAAE,UAAU,EAAE,CAAC;IAAC,cAAc,EAAE,UAAU,EAAE,CAAA;CAAE,CAKvD;AAED,wBAAgB,uBAAuB,CACrC,eAAe,EAAE,MAAM,CAAC,MAAM,EAAE,WAAW,CAAC,EAC5C,UAAU,CAAC,EAAE,MAAM,EAAE,GACpB,MAAM,EAAE,CAEV"}
@@ -121,6 +121,10 @@ export function buildAuthenticatedAgentA2ASkills(actions, options) {
121
121
  name,
122
122
  description: entry.tool.description,
123
123
  publicAgent: entry.publicAgent,
124
+ // Every action in this set is read-only by construction. Omitting the
125
+ // flag made discovery label all of them "(mutating)", which pushes a
126
+ // caller away from invoking them and back into open-ended delegation.
127
+ readOnly: true,
124
128
  // Naming an action without its parameters is what makes a caller invoke
125
129
  // it with `{}` and fail on a required field.
126
130
  ...(entry.tool.parameters
@@ -147,7 +151,9 @@ export function resolveArtifactBaseUrl(event) {
147
151
  return undefined;
148
152
  }
149
153
  export function assembleA2AFinalResponse(events, toolResults, options = {}) {
150
- const terminalError = getA2ATerminalErrorEvent(events);
154
+ const terminalError = options.outcome
155
+ ? terminalErrorFromOutcome(options.outcome)
156
+ : getA2ATerminalErrorEvent(events);
151
157
  const responseText = collectFinalResponseTextFromAgentEvents(events, {
152
158
  fallbackToPreToolText: !terminalError,
153
159
  });
@@ -156,11 +162,43 @@ export function assembleA2AFinalResponse(events, toolResults, options = {}) {
156
162
  includeReferencedArtifacts: true,
157
163
  includePersistedArtifactMarker: true,
158
164
  });
159
- if (terminalError && !finalText.trim()) {
160
- throw new Error(formatA2ATerminalError(terminalError));
165
+ if (terminalError) {
166
+ const partialResult = finalText.trim()
167
+ ? `\n\nPartial verified results before the failure:\n${finalText.trim()}`
168
+ : "";
169
+ throw new Error(formatA2ATerminalError(terminalError) + partialResult);
170
+ }
171
+ if (!finalText.trim()) {
172
+ throw new Error("Agent completed without a response or verified artifact.\ncode: empty_agent_response");
161
173
  }
162
174
  return { responseText, finalText };
163
175
  }
176
+ function terminalErrorFromOutcome(outcome) {
177
+ if (outcome.state === "completed")
178
+ return null;
179
+ if (outcome.state === "failed") {
180
+ return {
181
+ type: "error",
182
+ error: outcome.message,
183
+ errorCode: outcome.code,
184
+ recoverable: outcome.retryable,
185
+ };
186
+ }
187
+ if (outcome.state === "input_required") {
188
+ return {
189
+ type: "error",
190
+ error: outcome.message,
191
+ errorCode: outcome.code,
192
+ recoverable: true,
193
+ };
194
+ }
195
+ return {
196
+ type: "error",
197
+ error: outcome.message ?? "Agent run was canceled.",
198
+ errorCode: "canceled",
199
+ recoverable: false,
200
+ };
201
+ }
164
202
  function getA2ATerminalErrorEvent(events) {
165
203
  for (let i = events.length - 1; i >= 0; i--) {
166
204
  const event = events[i];
@@ -170,6 +208,22 @@ function getA2ATerminalErrorEvent(events) {
170
208
  return null;
171
209
  if (event.type === "error")
172
210
  return event;
211
+ if (event.type === "tripwire") {
212
+ return {
213
+ type: "error",
214
+ error: event.reason || "Agent stopped at a delegated-run guardrail.",
215
+ errorCode: event.processor ? `tripwire:${event.processor}` : "tripwire",
216
+ recoverable: true,
217
+ };
218
+ }
219
+ if (event.type === "loop_limit") {
220
+ return {
221
+ type: "error",
222
+ error: "Agent stopped before finishing at the delegated-run step limit.",
223
+ errorCode: "loop_limit",
224
+ recoverable: true,
225
+ };
226
+ }
173
227
  if (event.type === "auto_continue") {
174
228
  return {
175
229
  type: "error",
@@ -189,10 +243,33 @@ function formatA2ATerminalError(event) {
189
243
  ].filter(Boolean);
190
244
  return parts.join("\n");
191
245
  }
246
+ /**
247
+ * Delegated turns should do specialist work with the receiver's own tools,
248
+ * but must return a bounded caller-ready result. Interactive defaults allow
249
+ * extremely deep work (400 iterations / 20M cumulative input tokens), which
250
+ * made healthy Slides -> Analytics calls take 4-13 minutes and consume up to
251
+ * millions of input tokens as tool results accumulated. These defaults leave
252
+ * ample room for multi-source analysis while failing before a delegated turn
253
+ * can silently become an unbounded research session.
254
+ */
255
+ export const DEFAULT_DELEGATED_MAX_ITERATIONS = 80;
256
+ export const DEFAULT_DELEGATED_MAX_RUN_INPUT_TOKENS = 750_000;
257
+ export const DEFAULT_DELEGATED_MAX_TOOL_RESULT_CHARS = 20_000;
258
+ export const DELEGATED_AGENT_EXECUTION_CONTRACT = `
259
+ <delegated-agent-contract>
260
+ This request was delegated by another app. You are the specialist owner of the work.
261
+ - Interpret the caller's natural-language objective using your own instructions, skills, data dictionary, credentials, and tools. Choose providers, schemas, queries, and joins here; never ask the caller to invent SQL or source-specific implementation details for you.
262
+ - Minimize round trips. Filter, join, aggregate, paginate, stage, and reduce large datasets inside your own tools rather than returning raw records or transcripts.
263
+ - Return a concise caller-ready result with the answer, source and coverage details, relevant counts or IDs, caveats/partial gaps, and exact artifact URLs. Do not return tool transcripts or large raw payloads.
264
+ </delegated-agent-contract>`;
192
265
  async function runDelegatedAgentLoop(runOptions, pluginOptions, timeoutOptions, options) {
193
266
  const runner = options.runner ?? runAgentLoopDirectWithSoftTimeout;
267
+ const policy = pluginOptions.delegatedRunPolicy;
268
+ const configuredHardToolResultCap = runOptions.toolLimits?.hardMaxResultChars;
269
+ const delegatedHardToolResultCap = policy?.maxToolResultChars ?? DEFAULT_DELEGATED_MAX_TOOL_RESULT_CHARS;
194
270
  const resolvedRunOptions = {
195
271
  ...runOptions,
272
+ systemPrompt: runOptions.systemPrompt + DELEGATED_AGENT_EXECUTION_CONTRACT,
196
273
  // Delegated runs resolve their own model and do not pass through the
197
274
  // interactive request handler's output-token setup. Use the same
198
275
  // model-aware headroom here so reasoning models (notably GPT-5.x) do
@@ -202,6 +279,18 @@ async function runDelegatedAgentLoop(runOptions, pluginOptions, timeoutOptions,
202
279
  resolveMainChatMaxOutputTokens(runOptions.model),
203
280
  reasoningEffort: runOptions.reasoningEffort ??
204
281
  resolveAgentRequestReasoningEffort({ model: runOptions.model }),
282
+ maxIterations: runOptions.maxIterations ??
283
+ policy?.maxIterations ??
284
+ DEFAULT_DELEGATED_MAX_ITERATIONS,
285
+ maxRunInputTokens: runOptions.maxRunInputTokens ??
286
+ policy?.maxRunInputTokens ??
287
+ DEFAULT_DELEGATED_MAX_RUN_INPUT_TOKENS,
288
+ toolLimits: {
289
+ ...(runOptions.toolLimits ?? {}),
290
+ hardMaxResultChars: typeof configuredHardToolResultCap === "number"
291
+ ? Math.min(configuredHardToolResultCap, delegatedHardToolResultCap)
292
+ : delegatedHardToolResultCap,
293
+ },
205
294
  finalResponseGuard: pluginOptions.finalResponseGuard,
206
295
  };
207
296
  const execute = (loopOptions = resolvedRunOptions) => runner(loopOptions, pluginOptions.runSoftTimeoutMs, timeoutOptions);
@@ -1 +1 @@
1
- {"version":3,"file":"action-filters-a2a.js","sourceRoot":"","sources":["../../../src/server/agent-chat/action-filters-a2a.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,IAAI,CAAC;AAE/B,OAAO,EACL,sBAAsB,GAGvB,MAAM,gCAAgC,CAAC;AACxC,OAAO,EAAE,uCAAuC,EAAE,MAAM,4BAA4B,CAAC;AACrF,OAAO,EAAE,8BAA8B,EAAE,MAAM,qCAAqC,CAAC;AAErF,OAAO,EACL,wBAAwB,EACxB,kCAAkC,GAEnC,MAAM,iCAAiC,CAAC;AACzC,OAAO,EAAE,iCAAiC,EAAE,MAAM,qCAAqC,CAAC;AAExF,OAAO,EACL,yBAAyB,EACzB,4BAA4B,GAC7B,MAAM,2BAA2B,CAAC;AACnC,OAAO,EAAE,yBAAyB,EAAE,MAAM,qBAAqB,CAAC;AAGhE,8EAA8E;AAC9E,4EAA4E;AAC5E,uEAAuE;AACvE,oCAAoC;AACpC,8EAA8E;AAE9E,MAAM,UAAU,qBAAqB,CACnC,OAAoC;IAEpC,OAAO,MAAM,CAAC,WAAW,CACvB,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,KAAK,CAAC,EAAE,EAAE,CAAC,KAAK,CAAC,QAAQ,KAAK,IAAI,CAAC,CACvE,CAAC;AACJ,CAAC;AAED;;;;2DAI2D;AAC3D,MAAM,UAAU,gBAAgB,CAC9B,OAAoC;IAEpC,OAAO,MAAM,CAAC,WAAW,CACvB,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,KAAK,CAAC,EAAE,EAAE,CAAC,KAAK,CAAC,SAAS,KAAK,KAAK,CAAC,CACzE,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,wBAAwB,CACtC,OAAoC;IAEpC,OAAO,MAAM,CAAC,WAAW,CACvB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7B,UAA6C,EAC7C,aAGC,EACD,cAAiD,EACjD,OAAO,GAA8B,EAAE;IAEvC,OAAO,qBAAqB,CAC1B,UAAU,EACV,aAAa,EACb,cAAc,EACd,OAAO,CACR,CAAC;AACJ,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,eAAe,CAC7B,UAA6C,EAC7C,aAGC,EACD,cAAiD,EACjD,OAAO,GAA8B,EAAE;IAEvC,OAAO,qBAAqB,CAC1B,UAAU,EACV,aAAa,EACb,cAAc,EACd,OAAO,CACR,CAAC;AACJ,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,0BAA0B,CACxC,cAA4B,EAC5B,gBAA2B;IAE3B,OAAO;QACL,KAAK,EAAE,wBAAwB,CAAC,cAAc,EAAE,gBAAgB,CAAC;QACjE,cAAc;KACf,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,uBAAuB,CACrC,eAA4C,EAC5C,UAAqB;IAErB,OAAO,UAAU,IAAI,MAAM,CAAC,IAAI,CAAC,eAAe,CAAC,CAAC;AACpD,CAAC","sourcesContent":["import { getHeader } from \"h3\";\n\nimport {\n appendA2AArtifactLinks,\n type A2AArtifactResponseOptions,\n type A2AToolResultSummary,\n} from \"../../a2a/artifact-response.js\";\nimport { collectFinalResponseTextFromAgentEvents } from \"../../a2a/response-text.js\";\nimport { resolveMainChatMaxOutputTokens } from \"../../agent/engine/output-tokens.js\";\nimport type { EngineTool } from \"../../agent/engine/types.js\";\nimport {\n filterInitialEngineTools,\n resolveAgentRequestReasoningEffort,\n type ActionEntry,\n} from \"../../agent/production-agent.js\";\nimport { runAgentLoopDirectWithSoftTimeout } from \"../../agent/run-loop-with-resume.js\";\nimport type { AgentChatEvent } from \"../../agent/types.js\";\nimport {\n isAuthenticatedReadAction,\n isAutoReadExcludedActionName,\n} from \"../../mcp/build-server.js\";\nimport { withConfiguredAppBasePath } from \"../app-base-path.js\";\nimport type { AgentChatPluginOptions } from \"./plugin-options.js\";\n\n// ---------------------------------------------------------------------------\n// Action-visibility filters (read-only / agent-exposed / public-agent-safe)\n// and the A2A (agent-to-agent) final-response assembly + delegated-run\n// helpers that share those filters.\n// ---------------------------------------------------------------------------\n\nexport function filterReadOnlyActions(\n actions: Record<string, ActionEntry>,\n): Record<string, ActionEntry> {\n return Object.fromEntries(\n Object.entries(actions).filter(([, entry]) => entry.readOnly === true),\n );\n}\n\n/** Drop actions that opted out of agent exposure via `agentTool: false`. They\n * remain callable from the frontend / HTTP (mounted separately from this\n * agent tool surface — see `httpActions`) but never appear in any agent tool\n * list (in-app assistant, MCP, A2A, job/trigger runners) or actions prompt.\n * Default-allow: only an explicit `false` is excluded. */\nexport function filterAgentTools(\n actions: Record<string, ActionEntry>,\n): Record<string, ActionEntry> {\n return Object.fromEntries(\n Object.entries(actions).filter(([, entry]) => entry.agentTool !== false),\n );\n}\n\nexport function filterPublicAgentActions(\n actions: Record<string, ActionEntry>,\n): Record<string, ActionEntry> {\n return Object.fromEntries(\n Object.entries(actions).filter(([, entry]) => {\n const config = entry.publicAgent;\n return (\n config?.expose === true &&\n config.readOnly === true &&\n config.requiresAuth !== true &&\n config.isConsequential !== true\n );\n }),\n );\n}\n\n/**\n * Input fields that unambiguously carry a program the receiver executes.\n *\n * Deliberately excludes `query`: across the templates that field is nearly\n * always natural-language search text (Brain's `search-everything`,\n * `search-knowledge`), and blocking it would break exactly the ask-don't-instruct\n * calls this rule exists to encourage.\n */\nconst RAW_QUERY_INPUT_FIELDS = new Set([\"sql\", \"code\", \"script\", \"expression\"]);\n\n/**\n * True when an action takes a free-form query or program as input — raw SQL, a\n * code body, an arbitrary expression.\n *\n * Such an action must not be sibling-invocable over A2A. The app that owns the\n * data owns its schema, data dictionary, skills, and reference queries; a\n * calling app has none of that, so letting it pass SQL means every caller\n * reimplements the owner's schema knowledge badly and silently rots when the\n * owner's shape changes. Callers ask the owning app a question; the owner\n * forms the query. Set `publicAgent.allowRawQueryInput` to opt a specific\n * action out of this rule.\n */\nexport function hasRawQueryInput(entry: ActionEntry): boolean {\n const parameters = entry.tool?.parameters as\n | { properties?: Record<string, { type?: unknown }> }\n | undefined;\n const properties = parameters?.properties;\n if (!properties || typeof properties !== \"object\") return false;\n return Object.entries(properties).some(([field, schema]) => {\n const type = schema?.type;\n const acceptsString =\n type === \"string\" ||\n type === undefined ||\n (Array.isArray(type) && type.includes(\"string\"));\n return RAW_QUERY_INPUT_FIELDS.has(field.toLowerCase()) && acceptsString;\n });\n}\n\n/**\n * Direct A2A action calls share the authenticated external-agent policy with\n * MCP, but remain stricter: only explicitly exposed, authenticated read-only\n * actions can skip the receiver's model loop, and never one that takes a raw\n * query the caller wrote.\n */\nexport function filterDirectA2AActions(\n actions: Record<string, ActionEntry>,\n options: Pick<AgentChatPluginOptions, \"connectorCatalog\" | \"externalAgents\">,\n): Record<string, ActionEntry> {\n const catalog = new Set(options.connectorCatalog ?? []);\n const denied = new Set(options.externalAgents?.denyActions ?? []);\n const autoReads = options.externalAgents?.authenticatedReads === \"auto\";\n\n return Object.fromEntries(\n Object.entries(actions).filter(([name, entry]) => {\n const exposure = entry.publicAgent;\n const selected =\n catalog.has(name) ||\n (autoReads &&\n isAuthenticatedReadAction(entry) &&\n !isAutoReadExcludedActionName(name));\n const rawQueryAllowed =\n !hasRawQueryInput(entry) || exposure?.allowRawQueryInput === true;\n return (\n selected &&\n rawQueryAllowed &&\n !denied.has(name) &&\n entry.agentTool !== false &&\n entry.readOnly === true &&\n exposure?.expose === true &&\n exposure.readOnly === true &&\n exposure.requiresAuth === true &&\n (entry.needsApproval === undefined || entry.needsApproval === false) &&\n exposure.isConsequential !== true\n );\n }),\n );\n}\n\nexport function buildPublicAgentA2ASkills(\n actions: Record<string, ActionEntry>,\n): Array<{\n id: string;\n name: string;\n description: string;\n publicAgent: ActionEntry[\"publicAgent\"];\n inputSchema?: Record<string, unknown>;\n}> {\n return Object.entries(filterPublicAgentActions(actions)).map(\n ([name, entry]) => ({\n id: name,\n name,\n description: entry.tool.description,\n publicAgent: entry.publicAgent,\n ...(entry.tool.parameters\n ? {\n inputSchema: entry.tool.parameters as unknown as Record<\n string,\n unknown\n >,\n }\n : {}),\n }),\n );\n}\n\n/**\n * Skills for a caller with a verified A2A identity: exactly what\n * `filterDirectA2AActions` will execute. Kept separate from\n * `buildPublicAgentA2ASkills` because the public card may only name actions\n * with `requiresAuth !== true` while direct invocation requires\n * `requiresAuth === true` — advertising the public set alone tells siblings\n * an app has nothing callable when it does.\n */\nexport function buildAuthenticatedAgentA2ASkills(\n actions: Record<string, ActionEntry>,\n options: Pick<AgentChatPluginOptions, \"connectorCatalog\" | \"externalAgents\">,\n): Array<{\n id: string;\n name: string;\n description: string;\n publicAgent: ActionEntry[\"publicAgent\"];\n inputSchema?: Record<string, unknown>;\n}> {\n return Object.entries(filterDirectA2AActions(actions, options)).map(\n ([name, entry]) => ({\n id: name,\n name,\n description: entry.tool.description,\n publicAgent: entry.publicAgent,\n // Naming an action without its parameters is what makes a caller invoke\n // it with `{}` and fail on a required field.\n ...(entry.tool.parameters\n ? {\n inputSchema: entry.tool.parameters as unknown as Record<\n string,\n unknown\n >,\n }\n : {}),\n }),\n );\n}\n\nexport function resolveArtifactBaseUrl(\n event: any | undefined,\n): string | undefined {\n const fromEnv =\n process.env.APP_URL ||\n process.env.URL ||\n process.env.DEPLOY_URL ||\n process.env.BETTER_AUTH_URL;\n if (fromEnv) return withConfiguredAppBasePath(String(fromEnv));\n\n try {\n const proto = getHeader(event, \"x-forwarded-proto\") || \"https\";\n const host = getHeader(event, \"host\");\n if (host) return withConfiguredAppBasePath(`${proto}://${host}`);\n } catch {}\n\n return undefined;\n}\n\nexport function assembleA2AFinalResponse(\n events: readonly AgentChatEvent[],\n toolResults: readonly A2AToolResultSummary[],\n options: A2AArtifactResponseOptions & { event?: any } = {},\n): { responseText: string; finalText: string } {\n const terminalError = getA2ATerminalErrorEvent(events);\n const responseText = collectFinalResponseTextFromAgentEvents(events, {\n fallbackToPreToolText: !terminalError,\n });\n const finalText = appendA2AArtifactLinks(responseText, [...toolResults], {\n baseUrl: options.baseUrl ?? resolveArtifactBaseUrl(options.event),\n includeReferencedArtifacts: true,\n includePersistedArtifactMarker: true,\n });\n if (terminalError && !finalText.trim()) {\n throw new Error(formatA2ATerminalError(terminalError));\n }\n return { responseText, finalText };\n}\n\nfunction getA2ATerminalErrorEvent(\n events: readonly AgentChatEvent[],\n): Extract<AgentChatEvent, { type: \"error\" }> | null {\n for (let i = events.length - 1; i >= 0; i--) {\n const event = events[i];\n if (event.type === \"clear\") continue;\n if (event.type === \"done\") return null;\n if (event.type === \"error\") return event;\n if (event.type === \"auto_continue\") {\n return {\n type: \"error\",\n error: `Agent stopped before finishing (${event.reason}).`,\n errorCode: event.reason,\n recoverable: true,\n };\n }\n }\n return null;\n}\n\nfunction formatA2ATerminalError(\n event: Extract<AgentChatEvent, { type: \"error\" }>,\n): string {\n const parts = [\n event.error || \"Agent failed before producing a final response.\",\n event.errorCode ? `code: ${event.errorCode}` : \"\",\n event.details ? `details: ${event.details}` : \"\",\n ].filter(Boolean);\n return parts.join(\"\\n\");\n}\n\ntype A2AAgentLoopRunner = typeof runAgentLoopDirectWithSoftTimeout;\n\nexport interface DelegatedAgentLoopTelemetry {\n runId: string;\n threadId: string | null;\n userId: string | null;\n delegation: {\n protocol: \"a2a\" | \"mcp\";\n callerApp?: string;\n taskId?: string;\n parentRunId?: string;\n parentTurnId?: string;\n };\n}\n\ninterface DelegatedAgentLoopOptions {\n runner?: A2AAgentLoopRunner;\n telemetry?: DelegatedAgentLoopTelemetry;\n}\n\nasync function runDelegatedAgentLoop(\n runOptions: Parameters<A2AAgentLoopRunner>[0],\n pluginOptions: Pick<\n AgentChatPluginOptions,\n \"finalResponseGuard\" | \"runSoftTimeoutMs\"\n >,\n timeoutOptions: Parameters<A2AAgentLoopRunner>[2],\n options: DelegatedAgentLoopOptions,\n) {\n const runner = options.runner ?? runAgentLoopDirectWithSoftTimeout;\n const resolvedRunOptions = {\n ...runOptions,\n // Delegated runs resolve their own model and do not pass through the\n // interactive request handler's output-token setup. Use the same\n // model-aware headroom here so reasoning models (notably GPT-5.x) do\n // not spend the small internal default entirely on reasoning before\n // emitting a tool call or answer. Preserve explicit test/caller values.\n maxOutputTokens:\n runOptions.maxOutputTokens ??\n resolveMainChatMaxOutputTokens(runOptions.model),\n reasoningEffort:\n runOptions.reasoningEffort ??\n resolveAgentRequestReasoningEffort({ model: runOptions.model }),\n finalResponseGuard: pluginOptions.finalResponseGuard,\n };\n const execute = (loopOptions = resolvedRunOptions) =>\n runner(loopOptions, pluginOptions.runSoftTimeoutMs, timeoutOptions);\n\n if (!options.telemetry) return execute();\n\n let instrumented = false;\n try {\n const { getObservabilityConfig, instrumentAgentLoop } =\n await import(\"../../observability/traces.js\");\n const config = await getObservabilityConfig();\n if (config.enabled) {\n instrumented = true;\n return await instrumentAgentLoop({\n runAgentLoop: (loopOptions) =>\n execute(\n loopOptions as Parameters<A2AAgentLoopRunner>[0] &\n typeof resolvedRunOptions,\n ),\n loopOpts: resolvedRunOptions,\n runId: options.telemetry.runId,\n threadId: options.telemetry.threadId,\n userId: options.telemetry.userId,\n config,\n delegation: options.telemetry.delegation,\n });\n }\n } catch (error) {\n // Match interactive chat: setup failures fall through, but a failure from\n // inside an instrumented agent loop is the real run failure and rethrows.\n if (instrumented) throw error;\n }\n return execute();\n}\n\n/**\n * Run an A2A-delegated agent turn with the same final-response guard used by\n * the app's interactive chat surface.\n *\n * Keeping this in one helper prevents delegated calls from silently bypassing\n * template guarantees such as Analytics' requirement to query real data\n * before presenting metrics or exhaustive provider conclusions.\n */\nexport function runA2AAgentLoop(\n runOptions: Parameters<A2AAgentLoopRunner>[0],\n pluginOptions: Pick<\n AgentChatPluginOptions,\n \"finalResponseGuard\" | \"runSoftTimeoutMs\"\n >,\n timeoutOptions: Parameters<A2AAgentLoopRunner>[2],\n options: DelegatedAgentLoopOptions = {},\n) {\n return runDelegatedAgentLoop(\n runOptions,\n pluginOptions,\n timeoutOptions,\n options,\n );\n}\n\n/**\n * Run the MCP-local ask_app turn with the same app-level response guard as\n * A2A. Keeping this seam shared prevents hosted MCP callers from bypassing\n * template guarantees when the request cannot use the self-A2A route.\n */\nexport function runMCPAgentLoop(\n runOptions: Parameters<A2AAgentLoopRunner>[0],\n pluginOptions: Pick<\n AgentChatPluginOptions,\n \"finalResponseGuard\" | \"runSoftTimeoutMs\"\n >,\n timeoutOptions: Parameters<A2AAgentLoopRunner>[2],\n options: DelegatedAgentLoopOptions = {},\n) {\n return runDelegatedAgentLoop(\n runOptions,\n pluginOptions,\n timeoutOptions,\n options,\n );\n}\n\n/**\n * Keep delegated A2A turns on the same compact initial tool surface as\n * interactive chat. `tool-search` remains in the initial set, while the\n * complete registry is supplied separately so the run loop can load a matched\n * schema after a tool-search result.\n */\nexport function createA2AEngineToolSurface(\n availableTools: EngineTool[],\n initialToolNames?: string[],\n): { tools: EngineTool[]; availableTools: EngineTool[] } {\n return {\n tools: filterInitialEngineTools(availableTools, initialToolNames),\n availableTools,\n };\n}\n\nexport function resolveInitialToolNames(\n templateActions: Record<string, ActionEntry>,\n configured?: string[],\n): string[] {\n return configured ?? Object.keys(templateActions);\n}\n"]}
1
+ {"version":3,"file":"action-filters-a2a.js","sourceRoot":"","sources":["../../../src/server/agent-chat/action-filters-a2a.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,IAAI,CAAC;AAE/B,OAAO,EACL,sBAAsB,GAGvB,MAAM,gCAAgC,CAAC;AACxC,OAAO,EAAE,uCAAuC,EAAE,MAAM,4BAA4B,CAAC;AACrF,OAAO,EAAE,8BAA8B,EAAE,MAAM,qCAAqC,CAAC;AAErF,OAAO,EACL,wBAAwB,EACxB,kCAAkC,GAGnC,MAAM,iCAAiC,CAAC;AACzC,OAAO,EAAE,iCAAiC,EAAE,MAAM,qCAAqC,CAAC;AAExF,OAAO,EACL,yBAAyB,EACzB,4BAA4B,GAC7B,MAAM,2BAA2B,CAAC;AACnC,OAAO,EAAE,yBAAyB,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,IAAI,CAAC,eAAe,CAAC,CAAC;AACpD,CAAC","sourcesContent":["import { getHeader } from \"h3\";\n\nimport {\n appendA2AArtifactLinks,\n type A2AArtifactResponseOptions,\n type A2AToolResultSummary,\n} from \"../../a2a/artifact-response.js\";\nimport { collectFinalResponseTextFromAgentEvents } from \"../../a2a/response-text.js\";\nimport { resolveMainChatMaxOutputTokens } from \"../../agent/engine/output-tokens.js\";\nimport type { EngineTool } from \"../../agent/engine/types.js\";\nimport {\n filterInitialEngineTools,\n resolveAgentRequestReasoningEffort,\n type ActionEntry,\n type AgentLoopOutcome,\n} from \"../../agent/production-agent.js\";\nimport { runAgentLoopDirectWithSoftTimeout } from \"../../agent/run-loop-with-resume.js\";\nimport type { AgentChatEvent } from \"../../agent/types.js\";\nimport {\n isAuthenticatedReadAction,\n isAutoReadExcludedActionName,\n} from \"../../mcp/build-server.js\";\nimport { withConfiguredAppBasePath } from \"../app-base-path.js\";\nimport type { AgentChatPluginOptions } from \"./plugin-options.js\";\n\n// ---------------------------------------------------------------------------\n// Action-visibility filters (read-only / agent-exposed / public-agent-safe)\n// and the A2A (agent-to-agent) final-response assembly + delegated-run\n// helpers that share those filters.\n// ---------------------------------------------------------------------------\n\nexport function filterReadOnlyActions(\n actions: Record<string, ActionEntry>,\n): Record<string, ActionEntry> {\n return Object.fromEntries(\n Object.entries(actions).filter(([, entry]) => entry.readOnly === true),\n );\n}\n\n/** Drop actions that opted out of agent exposure via `agentTool: false`. They\n * remain callable from the frontend / HTTP (mounted separately from this\n * agent tool surface — see `httpActions`) but never appear in any agent tool\n * list (in-app assistant, MCP, A2A, job/trigger runners) or actions prompt.\n * Default-allow: only an explicit `false` is excluded. */\nexport function filterAgentTools(\n actions: Record<string, ActionEntry>,\n): Record<string, ActionEntry> {\n return Object.fromEntries(\n Object.entries(actions).filter(([, entry]) => entry.agentTool !== false),\n );\n}\n\nexport function filterPublicAgentActions(\n actions: Record<string, ActionEntry>,\n): Record<string, ActionEntry> {\n return Object.fromEntries(\n Object.entries(actions).filter(([, entry]) => {\n const config = entry.publicAgent;\n return (\n config?.expose === true &&\n config.readOnly === true &&\n config.requiresAuth !== true &&\n config.isConsequential !== true\n );\n }),\n );\n}\n\n/**\n * Input fields that unambiguously carry a program the receiver executes.\n *\n * Deliberately excludes `query`: across the templates that field is nearly\n * always natural-language search text (Brain's `search-everything`,\n * `search-knowledge`), and blocking it would break exactly the ask-don't-instruct\n * calls this rule exists to encourage.\n */\nconst RAW_QUERY_INPUT_FIELDS = new Set([\"sql\", \"code\", \"script\", \"expression\"]);\n\n/**\n * True when an action takes a free-form query or program as input — raw SQL, a\n * code body, an arbitrary expression.\n *\n * Such an action must not be sibling-invocable over A2A. The app that owns the\n * data owns its schema, data dictionary, skills, and reference queries; a\n * calling app has none of that, so letting it pass SQL means every caller\n * reimplements the owner's schema knowledge badly and silently rots when the\n * owner's shape changes. Callers ask the owning app a question; the owner\n * forms the query. Set `publicAgent.allowRawQueryInput` to opt a specific\n * action out of this rule.\n */\nexport function hasRawQueryInput(entry: ActionEntry): boolean {\n const parameters = entry.tool?.parameters as\n | { properties?: Record<string, { type?: unknown }> }\n | undefined;\n const properties = parameters?.properties;\n if (!properties || typeof properties !== \"object\") return false;\n return Object.entries(properties).some(([field, schema]) => {\n const type = schema?.type;\n const acceptsString =\n type === \"string\" ||\n type === undefined ||\n (Array.isArray(type) && type.includes(\"string\"));\n return RAW_QUERY_INPUT_FIELDS.has(field.toLowerCase()) && acceptsString;\n });\n}\n\n/**\n * Direct A2A action calls share the authenticated external-agent policy with\n * MCP, but remain stricter: only explicitly exposed, authenticated read-only\n * actions can skip the receiver's model loop, and never one that takes a raw\n * query the caller wrote.\n */\nexport function filterDirectA2AActions(\n actions: Record<string, ActionEntry>,\n options: Pick<AgentChatPluginOptions, \"connectorCatalog\" | \"externalAgents\">,\n): Record<string, ActionEntry> {\n const catalog = new Set(options.connectorCatalog ?? []);\n const denied = new Set(options.externalAgents?.denyActions ?? []);\n const autoReads = options.externalAgents?.authenticatedReads === \"auto\";\n\n return Object.fromEntries(\n Object.entries(actions).filter(([name, entry]) => {\n const exposure = entry.publicAgent;\n const selected =\n catalog.has(name) ||\n (autoReads &&\n isAuthenticatedReadAction(entry) &&\n !isAutoReadExcludedActionName(name));\n const rawQueryAllowed =\n !hasRawQueryInput(entry) || exposure?.allowRawQueryInput === true;\n return (\n selected &&\n rawQueryAllowed &&\n !denied.has(name) &&\n entry.agentTool !== false &&\n entry.readOnly === true &&\n exposure?.expose === true &&\n exposure.readOnly === true &&\n exposure.requiresAuth === true &&\n (entry.needsApproval === undefined || entry.needsApproval === false) &&\n exposure.isConsequential !== true\n );\n }),\n );\n}\n\nexport function buildPublicAgentA2ASkills(\n actions: Record<string, ActionEntry>,\n): Array<{\n id: string;\n name: string;\n description: string;\n publicAgent: ActionEntry[\"publicAgent\"];\n inputSchema?: Record<string, unknown>;\n}> {\n return Object.entries(filterPublicAgentActions(actions)).map(\n ([name, entry]) => ({\n id: name,\n name,\n description: entry.tool.description,\n publicAgent: entry.publicAgent,\n ...(entry.tool.parameters\n ? {\n inputSchema: entry.tool.parameters as unknown as Record<\n string,\n unknown\n >,\n }\n : {}),\n }),\n );\n}\n\n/**\n * Skills for a caller with a verified A2A identity: exactly what\n * `filterDirectA2AActions` will execute. Kept separate from\n * `buildPublicAgentA2ASkills` because the public card may only name actions\n * with `requiresAuth !== true` while direct invocation requires\n * `requiresAuth === true` — advertising the public set alone tells siblings\n * an app has nothing callable when it does.\n */\nexport function buildAuthenticatedAgentA2ASkills(\n actions: Record<string, ActionEntry>,\n options: Pick<AgentChatPluginOptions, \"connectorCatalog\" | \"externalAgents\">,\n): Array<{\n id: string;\n name: string;\n description: string;\n publicAgent: ActionEntry[\"publicAgent\"];\n inputSchema?: Record<string, unknown>;\n}> {\n return Object.entries(filterDirectA2AActions(actions, options)).map(\n ([name, entry]) => ({\n id: name,\n name,\n description: entry.tool.description,\n publicAgent: entry.publicAgent,\n // Every action in this set is read-only by construction. Omitting the\n // flag made discovery label all of them \"(mutating)\", which pushes a\n // caller away from invoking them and back into open-ended delegation.\n readOnly: true,\n // Naming an action without its parameters is what makes a caller invoke\n // it with `{}` and fail on a required field.\n ...(entry.tool.parameters\n ? {\n inputSchema: entry.tool.parameters as unknown as Record<\n string,\n unknown\n >,\n }\n : {}),\n }),\n );\n}\n\nexport function resolveArtifactBaseUrl(\n event: any | undefined,\n): string | undefined {\n const fromEnv =\n process.env.APP_URL ||\n process.env.URL ||\n process.env.DEPLOY_URL ||\n process.env.BETTER_AUTH_URL;\n if (fromEnv) return withConfiguredAppBasePath(String(fromEnv));\n\n try {\n const proto = getHeader(event, \"x-forwarded-proto\") || \"https\";\n const host = getHeader(event, \"host\");\n if (host) return withConfiguredAppBasePath(`${proto}://${host}`);\n } catch {}\n\n return undefined;\n}\n\nexport function assembleA2AFinalResponse(\n events: readonly AgentChatEvent[],\n toolResults: readonly A2AToolResultSummary[],\n options: A2AArtifactResponseOptions & {\n event?: any;\n outcome?: AgentLoopOutcome;\n } = {},\n): { responseText: string; finalText: string } {\n const terminalError = options.outcome\n ? terminalErrorFromOutcome(options.outcome)\n : getA2ATerminalErrorEvent(events);\n const responseText = collectFinalResponseTextFromAgentEvents(events, {\n fallbackToPreToolText: !terminalError,\n });\n const finalText = appendA2AArtifactLinks(responseText, [...toolResults], {\n baseUrl: options.baseUrl ?? resolveArtifactBaseUrl(options.event),\n includeReferencedArtifacts: true,\n includePersistedArtifactMarker: true,\n });\n if (terminalError) {\n const partialResult = finalText.trim()\n ? `\\n\\nPartial verified results before the failure:\\n${finalText.trim()}`\n : \"\";\n throw new Error(formatA2ATerminalError(terminalError) + partialResult);\n }\n if (!finalText.trim()) {\n throw new Error(\n \"Agent completed without a response or verified artifact.\\ncode: empty_agent_response\",\n );\n }\n return { responseText, finalText };\n}\n\nfunction terminalErrorFromOutcome(\n outcome: AgentLoopOutcome,\n): Extract<AgentChatEvent, { type: \"error\" }> | null {\n if (outcome.state === \"completed\") return null;\n if (outcome.state === \"failed\") {\n return {\n type: \"error\",\n error: outcome.message,\n errorCode: outcome.code,\n recoverable: outcome.retryable,\n };\n }\n if (outcome.state === \"input_required\") {\n return {\n type: \"error\",\n error: outcome.message,\n errorCode: outcome.code,\n recoverable: true,\n };\n }\n return {\n type: \"error\",\n error: outcome.message ?? \"Agent run was canceled.\",\n errorCode: \"canceled\",\n recoverable: false,\n };\n}\n\nfunction getA2ATerminalErrorEvent(\n events: readonly AgentChatEvent[],\n): Extract<AgentChatEvent, { type: \"error\" }> | null {\n for (let i = events.length - 1; i >= 0; i--) {\n const event = events[i];\n if (event.type === \"clear\") continue;\n if (event.type === \"done\") return null;\n if (event.type === \"error\") return event;\n if (event.type === \"tripwire\") {\n return {\n type: \"error\",\n error: event.reason || \"Agent stopped at a delegated-run guardrail.\",\n errorCode: event.processor ? `tripwire:${event.processor}` : \"tripwire\",\n recoverable: true,\n };\n }\n if (event.type === \"loop_limit\") {\n return {\n type: \"error\",\n error:\n \"Agent stopped before finishing at the delegated-run step limit.\",\n errorCode: \"loop_limit\",\n recoverable: true,\n };\n }\n if (event.type === \"auto_continue\") {\n return {\n type: \"error\",\n error: `Agent stopped before finishing (${event.reason}).`,\n errorCode: event.reason,\n recoverable: true,\n };\n }\n }\n return null;\n}\n\nfunction formatA2ATerminalError(\n event: Extract<AgentChatEvent, { type: \"error\" }>,\n): string {\n const parts = [\n event.error || \"Agent failed before producing a final response.\",\n event.errorCode ? `code: ${event.errorCode}` : \"\",\n event.details ? `details: ${event.details}` : \"\",\n ].filter(Boolean);\n return parts.join(\"\\n\");\n}\n\ntype A2AAgentLoopRunner = typeof runAgentLoopDirectWithSoftTimeout;\n\n/**\n * Delegated turns should do specialist work with the receiver's own tools,\n * but must return a bounded caller-ready result. Interactive defaults allow\n * extremely deep work (400 iterations / 20M cumulative input tokens), which\n * made healthy Slides -> Analytics calls take 4-13 minutes and consume up to\n * millions of input tokens as tool results accumulated. These defaults leave\n * ample room for multi-source analysis while failing before a delegated turn\n * can silently become an unbounded research session.\n */\nexport const DEFAULT_DELEGATED_MAX_ITERATIONS = 80;\nexport const DEFAULT_DELEGATED_MAX_RUN_INPUT_TOKENS = 750_000;\nexport const DEFAULT_DELEGATED_MAX_TOOL_RESULT_CHARS = 20_000;\n\nexport const DELEGATED_AGENT_EXECUTION_CONTRACT = `\n<delegated-agent-contract>\nThis request was delegated by another app. You are the specialist owner of the work.\n- Interpret the caller's natural-language objective using your own instructions, skills, data dictionary, credentials, and tools. Choose providers, schemas, queries, and joins here; never ask the caller to invent SQL or source-specific implementation details for you.\n- Minimize round trips. Filter, join, aggregate, paginate, stage, and reduce large datasets inside your own tools rather than returning raw records or transcripts.\n- Return a concise caller-ready result with the answer, source and coverage details, relevant counts or IDs, caveats/partial gaps, and exact artifact URLs. Do not return tool transcripts or large raw payloads.\n</delegated-agent-contract>`;\n\nexport interface DelegatedAgentLoopTelemetry {\n runId: string;\n threadId: string | null;\n userId: string | null;\n delegation: {\n protocol: \"a2a\" | \"mcp\";\n callerApp?: string;\n taskId?: string;\n parentRunId?: string;\n parentTurnId?: string;\n };\n}\n\ninterface DelegatedAgentLoopOptions {\n runner?: A2AAgentLoopRunner;\n telemetry?: DelegatedAgentLoopTelemetry;\n}\n\nasync function runDelegatedAgentLoop(\n runOptions: Parameters<A2AAgentLoopRunner>[0],\n pluginOptions: Pick<\n AgentChatPluginOptions,\n \"delegatedRunPolicy\" | \"finalResponseGuard\" | \"runSoftTimeoutMs\"\n >,\n timeoutOptions: Parameters<A2AAgentLoopRunner>[2],\n options: DelegatedAgentLoopOptions,\n) {\n const runner = options.runner ?? runAgentLoopDirectWithSoftTimeout;\n const policy = pluginOptions.delegatedRunPolicy;\n const configuredHardToolResultCap = runOptions.toolLimits?.hardMaxResultChars;\n const delegatedHardToolResultCap =\n policy?.maxToolResultChars ?? DEFAULT_DELEGATED_MAX_TOOL_RESULT_CHARS;\n const resolvedRunOptions = {\n ...runOptions,\n systemPrompt: runOptions.systemPrompt + DELEGATED_AGENT_EXECUTION_CONTRACT,\n // Delegated runs resolve their own model and do not pass through the\n // interactive request handler's output-token setup. Use the same\n // model-aware headroom here so reasoning models (notably GPT-5.x) do\n // not spend the small internal default entirely on reasoning before\n // emitting a tool call or answer. Preserve explicit test/caller values.\n maxOutputTokens:\n runOptions.maxOutputTokens ??\n resolveMainChatMaxOutputTokens(runOptions.model),\n reasoningEffort:\n runOptions.reasoningEffort ??\n resolveAgentRequestReasoningEffort({ model: runOptions.model }),\n maxIterations:\n runOptions.maxIterations ??\n policy?.maxIterations ??\n DEFAULT_DELEGATED_MAX_ITERATIONS,\n maxRunInputTokens:\n runOptions.maxRunInputTokens ??\n policy?.maxRunInputTokens ??\n DEFAULT_DELEGATED_MAX_RUN_INPUT_TOKENS,\n toolLimits: {\n ...(runOptions.toolLimits ?? {}),\n hardMaxResultChars:\n typeof configuredHardToolResultCap === \"number\"\n ? Math.min(configuredHardToolResultCap, delegatedHardToolResultCap)\n : delegatedHardToolResultCap,\n },\n finalResponseGuard: pluginOptions.finalResponseGuard,\n };\n const execute = (loopOptions = resolvedRunOptions) =>\n runner(loopOptions, pluginOptions.runSoftTimeoutMs, timeoutOptions);\n\n if (!options.telemetry) return execute();\n\n let instrumented = false;\n try {\n const { getObservabilityConfig, instrumentAgentLoop } =\n await import(\"../../observability/traces.js\");\n const config = await getObservabilityConfig();\n if (config.enabled) {\n instrumented = true;\n return await instrumentAgentLoop({\n runAgentLoop: (loopOptions) =>\n execute(\n loopOptions as Parameters<A2AAgentLoopRunner>[0] &\n typeof resolvedRunOptions,\n ),\n loopOpts: resolvedRunOptions,\n runId: options.telemetry.runId,\n threadId: options.telemetry.threadId,\n userId: options.telemetry.userId,\n config,\n delegation: options.telemetry.delegation,\n });\n }\n } catch (error) {\n // Match interactive chat: setup failures fall through, but a failure from\n // inside an instrumented agent loop is the real run failure and rethrows.\n if (instrumented) throw error;\n }\n return execute();\n}\n\n/**\n * Run an A2A-delegated agent turn with the same final-response guard used by\n * the app's interactive chat surface.\n *\n * Keeping this in one helper prevents delegated calls from silently bypassing\n * template guarantees such as Analytics' requirement to query real data\n * before presenting metrics or exhaustive provider conclusions.\n */\nexport function runA2AAgentLoop(\n runOptions: Parameters<A2AAgentLoopRunner>[0],\n pluginOptions: Pick<\n AgentChatPluginOptions,\n \"delegatedRunPolicy\" | \"finalResponseGuard\" | \"runSoftTimeoutMs\"\n >,\n timeoutOptions: Parameters<A2AAgentLoopRunner>[2],\n options: DelegatedAgentLoopOptions = {},\n) {\n return runDelegatedAgentLoop(\n runOptions,\n pluginOptions,\n timeoutOptions,\n options,\n );\n}\n\n/**\n * Run the MCP-local ask_app turn with the same app-level response guard as\n * A2A. Keeping this seam shared prevents hosted MCP callers from bypassing\n * template guarantees when the request cannot use the self-A2A route.\n */\nexport function runMCPAgentLoop(\n runOptions: Parameters<A2AAgentLoopRunner>[0],\n pluginOptions: Pick<\n AgentChatPluginOptions,\n \"delegatedRunPolicy\" | \"finalResponseGuard\" | \"runSoftTimeoutMs\"\n >,\n timeoutOptions: Parameters<A2AAgentLoopRunner>[2],\n options: DelegatedAgentLoopOptions = {},\n) {\n return runDelegatedAgentLoop(\n runOptions,\n pluginOptions,\n timeoutOptions,\n options,\n );\n}\n\n/**\n * Keep delegated A2A turns on the same compact initial tool surface as\n * interactive chat. `tool-search` remains in the initial set, while the\n * complete registry is supplied separately so the run loop can load a matched\n * schema after a tool-search result.\n */\nexport function createA2AEngineToolSurface(\n availableTools: EngineTool[],\n initialToolNames?: string[],\n): { tools: EngineTool[]; availableTools: EngineTool[] } {\n return {\n tools: filterInitialEngineTools(availableTools, initialToolNames),\n availableTools,\n };\n}\n\nexport function resolveInitialToolNames(\n templateActions: Record<string, ActionEntry>,\n configured?: string[],\n): string[] {\n return configured ?? Object.keys(templateActions);\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"context-tools.d.ts","sourceRoot":"","sources":["../../../src/server/agent-chat/context-tools.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,iCAAiC,CAAC;AAgBnE;;;;GAIG;AACH,eAAO,MAAM,0BAA0B,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAuL7D,CAAC;AAEF,wBAAgB,2BAA2B,IAAI,MAAM,CAAC,MAAM,EAAE,WAAW,CAAC,CA+BzE;AAED;;;;;;;;;GASG;AACH,wBAAgB,wBAAwB,IAAI,MAAM,CAAC,MAAM,EAAE,WAAW,CAAC,CAsCtE;AAMD,wBAAgB,wBAAwB,CACtC,GAAG,EAAE,MAAM,EACX,YAAY,EAAE,OAAO,GACpB,MAAM,CAIR;AAED;;;;;;;;;GASG;AACH,wBAAgB,cAAc,IAAI,MAAM,CAAC,MAAM,EAAE,WAAW,CAAC,CAgP5D;AAED,wBAAgB,6BAA6B,IAAI,MAAM,CAAC,MAAM,EAAE,WAAW,CAAC,CAyD3E"}
1
+ {"version":3,"file":"context-tools.d.ts","sourceRoot":"","sources":["../../../src/server/agent-chat/context-tools.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,iCAAiC,CAAC;AAgBnE;;;;GAIG;AACH,eAAO,MAAM,0BAA0B,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAyL7D,CAAC;AAEF,wBAAgB,2BAA2B,IAAI,MAAM,CAAC,MAAM,EAAE,WAAW,CAAC,CA+BzE;AAED;;;;;;;;;GASG;AACH,wBAAgB,wBAAwB,IAAI,MAAM,CAAC,MAAM,EAAE,WAAW,CAAC,CAsCtE;AAMD,wBAAgB,wBAAwB,CACtC,GAAG,EAAE,MAAM,EACX,YAAY,EAAE,OAAO,GACpB,MAAM,CAIR;AAED;;;;;;;;;GASG;AACH,wBAAgB,cAAc,IAAI,MAAM,CAAC,MAAM,EAAE,WAAW,CAAC,CAgP5D;AAED,wBAAgB,6BAA6B,IAAI,MAAM,CAAC,MAAM,EAAE,WAAW,CAAC,CAyD3E"}
@@ -138,6 +138,8 @@ Prefer \`web-request\` for simple API calls and static pages. Use browser automa
138
138
 
139
139
  The \`call-agent\` tool sends a message to a DIFFERENT, separately-deployed app's agent (A2A protocol). It is **not** for calling actions within the current app.
140
140
 
141
+ Use a natural-language \`message\` by default. The receiving app owns interpretation and runs with its own instructions, skills, connected sources, data dictionary, and tools. Do not choose its provider, schema, query, joins, or SQL for it. A direct \`action\` + \`input\` call is only for an exact bounded read whose complete contract is already known; it is never a workaround for unreliable delegation.
142
+
141
143
  **NEVER use \`call-agent\` to:**
142
144
  - Call your own app by name
143
145
  - Perform tasks you can accomplish with your own registered tools