@agent-native/core 0.107.1 → 0.108.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 (257) hide show
  1. package/corpus/README.md +2 -2
  2. package/corpus/core/CHANGELOG.md +12 -0
  3. package/corpus/core/docs/content/actions.mdx +48 -0
  4. package/corpus/core/docs/content/locales/ar-SA/actions.mdx +38 -0
  5. package/corpus/core/docs/content/locales/de-DE/actions.mdx +38 -0
  6. package/corpus/core/docs/content/locales/es-ES/actions.mdx +38 -0
  7. package/corpus/core/docs/content/locales/fr-FR/actions.mdx +38 -0
  8. package/corpus/core/docs/content/locales/hi-IN/actions.mdx +38 -0
  9. package/corpus/core/docs/content/locales/ja-JP/actions.mdx +38 -0
  10. package/corpus/core/docs/content/locales/ko-KR/actions.mdx +38 -0
  11. package/corpus/core/docs/content/locales/pt-BR/actions.mdx +38 -0
  12. package/corpus/core/docs/content/locales/zh-CN/actions.mdx +38 -0
  13. package/corpus/core/docs/content/locales/zh-TW/actions.mdx +38 -0
  14. package/corpus/core/package.json +5 -1
  15. package/corpus/core/src/a2a/artifact-response.ts +32 -10
  16. package/corpus/core/src/a2a-claims.ts +52 -0
  17. package/corpus/core/src/action.ts +6 -2
  18. package/corpus/core/src/audit/record.ts +6 -0
  19. package/corpus/core/src/client/feature-flags/FeatureFlagsPanel.tsx +519 -0
  20. package/corpus/core/src/client/feature-flags/helpers.ts +77 -0
  21. package/corpus/core/src/client/feature-flags/index.ts +13 -0
  22. package/corpus/core/src/client/feature-flags/types.ts +29 -0
  23. package/corpus/core/src/client/feature-flags/use-feature-flag.ts +26 -0
  24. package/corpus/core/src/client/index.ts +11 -0
  25. package/corpus/core/src/extensions/routes.ts +1 -1
  26. package/corpus/core/src/feature-flags/a2a-action-route.ts +56 -0
  27. package/corpus/core/src/feature-flags/actions/get-feature-flags.ts +24 -0
  28. package/corpus/core/src/feature-flags/actions/list-feature-flags.ts +69 -0
  29. package/corpus/core/src/feature-flags/actions/set-feature-flag.ts +89 -0
  30. package/corpus/core/src/feature-flags/index.ts +21 -0
  31. package/corpus/core/src/feature-flags/permissions.ts +53 -0
  32. package/corpus/core/src/feature-flags/plugin.ts +44 -0
  33. package/corpus/core/src/feature-flags/registry.ts +96 -0
  34. package/corpus/core/src/feature-flags/store.ts +176 -0
  35. package/corpus/core/src/index.ts +15 -0
  36. package/corpus/core/src/integrations/a2a-continuation-processor.ts +107 -3
  37. package/corpus/core/src/integrations/pending-tasks-store.ts +98 -1
  38. package/corpus/core/src/integrations/plugin.ts +129 -4
  39. package/corpus/core/src/integrations/webhook-handler.ts +339 -36
  40. package/corpus/core/src/localization/default-messages.ts +47 -0
  41. package/corpus/core/src/server/action-discovery.ts +12 -0
  42. package/corpus/core/src/server/action-routes.ts +47 -5
  43. package/corpus/core/src/server/agent-chat-plugin.ts +93 -8
  44. package/corpus/core/src/server/index.ts +1 -0
  45. package/corpus/core/src/settings/org-settings.ts +13 -0
  46. package/corpus/core/src/settings/store.ts +57 -0
  47. package/corpus/core/src/templates/default/.agents/skills/feature-flags/SKILL.md +169 -0
  48. package/corpus/core/src/templates/default/AGENTS.md +1 -0
  49. package/corpus/core/src/templates/headless/.agents/skills/feature-flags/SKILL.md +169 -0
  50. package/corpus/core/src/templates/workspace-core/.agents/skills/feature-flags/SKILL.md +169 -0
  51. package/corpus/core/src/templates/workspace-core/AGENTS.md +1 -1
  52. package/corpus/core/src/templates/workspace-root/AGENTS.md +1 -1
  53. package/corpus/core/src/vite/action-types-plugin.ts +12 -0
  54. package/corpus/templates/analytics/.agents/skills/feature-flags/SKILL.md +169 -0
  55. package/corpus/templates/analytics/AGENTS.md +15 -3
  56. package/corpus/templates/analytics/actions/list-workspace-feature-flags.ts +15 -0
  57. package/corpus/templates/analytics/actions/navigate.ts +2 -2
  58. package/corpus/templates/analytics/actions/set-workspace-feature-flag.ts +45 -0
  59. package/corpus/templates/analytics/actions/view-screen.ts +13 -0
  60. package/corpus/templates/analytics/app/components/agents/FeatureFlagsFleetPanel.tsx +243 -0
  61. package/corpus/templates/analytics/app/components/layout/CommandPalette.tsx +11 -3
  62. package/corpus/templates/analytics/app/hooks/use-navigation-state.ts +3 -1
  63. package/corpus/templates/analytics/app/i18n/zh-TW.ts +17 -0
  64. package/corpus/templates/analytics/app/i18n-data.ts +251 -0
  65. package/corpus/templates/analytics/app/pages/Agents.tsx +22 -2
  66. package/corpus/templates/analytics/changelog/2026-07-17-manage-feature-flag-rollouts-across-your-organization-s-apps.md +6 -0
  67. package/corpus/templates/analytics/server/lib/db-admin-connections.ts +13 -5
  68. package/corpus/templates/analytics/server/lib/workspace-feature-flags.ts +347 -0
  69. package/corpus/templates/assets/.agents/skills/feature-flags/SKILL.md +169 -0
  70. package/corpus/templates/brain/.agents/skills/feature-flags/SKILL.md +169 -0
  71. package/corpus/templates/calendar/.agents/skills/feature-flags/SKILL.md +169 -0
  72. package/corpus/templates/chat/.agents/skills/feature-flags/SKILL.md +169 -0
  73. package/corpus/templates/clips/.agents/skills/feature-flags/SKILL.md +169 -0
  74. package/corpus/templates/clips/server/plugins/feature-flags.ts +11 -0
  75. package/corpus/templates/clips/shared/feature-flags.ts +30 -37
  76. package/corpus/templates/content/.agents/skills/feature-flags/SKILL.md +169 -0
  77. package/corpus/templates/design/.agents/skills/feature-flags/SKILL.md +169 -0
  78. package/corpus/templates/design/AGENTS.md +5 -3
  79. package/corpus/templates/design/actions/add-fusion-screens.ts +4 -6
  80. package/corpus/templates/design/actions/apply-fusion-edits.ts +4 -6
  81. package/corpus/templates/design/actions/create-fusion-app.ts +5 -4
  82. package/corpus/templates/design/actions/deploy-fusion-app.ts +4 -3
  83. package/corpus/templates/design/actions/get-fusion-deploy-status.ts +4 -6
  84. package/corpus/templates/design/actions/list-fusion-edits.ts +4 -3
  85. package/corpus/templates/design/actions/push-fusion-app.ts +4 -6
  86. package/corpus/templates/design/actions/queue-fusion-edit.ts +4 -3
  87. package/corpus/templates/design/actions/send-fusion-message.ts +4 -6
  88. package/corpus/templates/design/actions/sync-fusion-app.ts +4 -3
  89. package/corpus/templates/design/app/components/editor/PromptDialog.tsx +1 -1
  90. package/corpus/templates/design/app/pages/Index.tsx +8 -6
  91. package/corpus/templates/design/server/plugins/feature-flags.ts +5 -0
  92. package/corpus/templates/design/shared/full-app.ts +10 -7
  93. package/corpus/templates/dispatch/.agents/skills/feature-flags/SKILL.md +169 -0
  94. package/corpus/templates/forms/.agents/skills/feature-flags/SKILL.md +169 -0
  95. package/corpus/templates/macros/.agents/skills/feature-flags/SKILL.md +169 -0
  96. package/corpus/templates/mail/.agents/skills/feature-flags/SKILL.md +169 -0
  97. package/corpus/templates/plan/.agents/skills/feature-flags/SKILL.md +169 -0
  98. package/corpus/templates/slides/.agents/skills/feature-flags/SKILL.md +169 -0
  99. package/corpus/templates/tasks/.agents/skills/feature-flags/SKILL.md +169 -0
  100. package/dist/a2a/artifact-response.d.ts +5 -1
  101. package/dist/a2a/artifact-response.d.ts.map +1 -1
  102. package/dist/a2a/artifact-response.js +18 -12
  103. package/dist/a2a/artifact-response.js.map +1 -1
  104. package/dist/a2a-claims.d.ts +10 -0
  105. package/dist/a2a-claims.d.ts.map +1 -0
  106. package/dist/a2a-claims.js +41 -0
  107. package/dist/a2a-claims.js.map +1 -0
  108. package/dist/action.d.ts +6 -2
  109. package/dist/action.d.ts.map +1 -1
  110. package/dist/action.js.map +1 -1
  111. package/dist/audit/record.d.ts +3 -0
  112. package/dist/audit/record.d.ts.map +1 -1
  113. package/dist/audit/record.js +3 -0
  114. package/dist/audit/record.js.map +1 -1
  115. package/dist/client/feature-flags/FeatureFlagsPanel.d.ts +10 -0
  116. package/dist/client/feature-flags/FeatureFlagsPanel.d.ts.map +1 -0
  117. package/dist/client/feature-flags/FeatureFlagsPanel.js +143 -0
  118. package/dist/client/feature-flags/FeatureFlagsPanel.js.map +1 -0
  119. package/dist/client/feature-flags/helpers.d.ts +16 -0
  120. package/dist/client/feature-flags/helpers.d.ts.map +1 -0
  121. package/dist/client/feature-flags/helpers.js +50 -0
  122. package/dist/client/feature-flags/helpers.js.map +1 -0
  123. package/dist/client/feature-flags/index.d.ts +5 -0
  124. package/dist/client/feature-flags/index.d.ts.map +1 -0
  125. package/dist/client/feature-flags/index.js +4 -0
  126. package/dist/client/feature-flags/index.js.map +1 -0
  127. package/dist/client/feature-flags/types.d.ts +27 -0
  128. package/dist/client/feature-flags/types.d.ts.map +1 -0
  129. package/dist/client/feature-flags/types.js +2 -0
  130. package/dist/client/feature-flags/types.js.map +1 -0
  131. package/dist/client/feature-flags/use-feature-flag.d.ts +8 -0
  132. package/dist/client/feature-flags/use-feature-flag.d.ts.map +1 -0
  133. package/dist/client/feature-flags/use-feature-flag.js +15 -0
  134. package/dist/client/feature-flags/use-feature-flag.js.map +1 -0
  135. package/dist/client/index.d.ts +1 -0
  136. package/dist/client/index.d.ts.map +1 -1
  137. package/dist/client/index.js +1 -0
  138. package/dist/client/index.js.map +1 -1
  139. package/dist/collab/routes.d.ts +1 -1
  140. package/dist/collab/struct-routes.d.ts +1 -1
  141. package/dist/extensions/routes.d.ts.map +1 -1
  142. package/dist/extensions/routes.js +1 -1
  143. package/dist/extensions/routes.js.map +1 -1
  144. package/dist/feature-flags/a2a-action-route.d.ts +14 -0
  145. package/dist/feature-flags/a2a-action-route.d.ts.map +1 -0
  146. package/dist/feature-flags/a2a-action-route.js +50 -0
  147. package/dist/feature-flags/a2a-action-route.js.map +1 -0
  148. package/dist/feature-flags/actions/get-feature-flags.d.ts +3 -0
  149. package/dist/feature-flags/actions/get-feature-flags.d.ts.map +1 -0
  150. package/dist/feature-flags/actions/get-feature-flags.js +18 -0
  151. package/dist/feature-flags/actions/get-feature-flags.js.map +1 -0
  152. package/dist/feature-flags/actions/list-feature-flags.d.ts +28 -0
  153. package/dist/feature-flags/actions/list-feature-flags.d.ts.map +1 -0
  154. package/dist/feature-flags/actions/list-feature-flags.js +60 -0
  155. package/dist/feature-flags/actions/list-feature-flags.js.map +1 -0
  156. package/dist/feature-flags/actions/set-feature-flag.d.ts +26 -0
  157. package/dist/feature-flags/actions/set-feature-flag.d.ts.map +1 -0
  158. package/dist/feature-flags/actions/set-feature-flag.js +78 -0
  159. package/dist/feature-flags/actions/set-feature-flag.js.map +1 -0
  160. package/dist/feature-flags/index.d.ts +5 -0
  161. package/dist/feature-flags/index.d.ts.map +1 -0
  162. package/dist/feature-flags/index.js +5 -0
  163. package/dist/feature-flags/index.js.map +1 -0
  164. package/dist/feature-flags/permissions.d.ts +13 -0
  165. package/dist/feature-flags/permissions.d.ts.map +1 -0
  166. package/dist/feature-flags/permissions.js +37 -0
  167. package/dist/feature-flags/permissions.js.map +1 -0
  168. package/dist/feature-flags/plugin.d.ts +17 -0
  169. package/dist/feature-flags/plugin.d.ts.map +1 -0
  170. package/dist/feature-flags/plugin.js +29 -0
  171. package/dist/feature-flags/plugin.js.map +1 -0
  172. package/dist/feature-flags/registry.d.ts +23 -0
  173. package/dist/feature-flags/registry.d.ts.map +1 -0
  174. package/dist/feature-flags/registry.js +59 -0
  175. package/dist/feature-flags/registry.js.map +1 -0
  176. package/dist/feature-flags/store.d.ts +31 -0
  177. package/dist/feature-flags/store.d.ts.map +1 -0
  178. package/dist/feature-flags/store.js +124 -0
  179. package/dist/feature-flags/store.js.map +1 -0
  180. package/dist/index.d.ts +1 -0
  181. package/dist/index.d.ts.map +1 -1
  182. package/dist/index.js +1 -0
  183. package/dist/index.js.map +1 -1
  184. package/dist/integrations/a2a-continuation-processor.js +62 -5
  185. package/dist/integrations/a2a-continuation-processor.js.map +1 -1
  186. package/dist/integrations/pending-tasks-store.d.ts +3 -0
  187. package/dist/integrations/pending-tasks-store.d.ts.map +1 -1
  188. package/dist/integrations/pending-tasks-store.js +75 -1
  189. package/dist/integrations/pending-tasks-store.js.map +1 -1
  190. package/dist/integrations/plugin.d.ts.map +1 -1
  191. package/dist/integrations/plugin.js +81 -5
  192. package/dist/integrations/plugin.js.map +1 -1
  193. package/dist/integrations/webhook-handler.d.ts +23 -2
  194. package/dist/integrations/webhook-handler.d.ts.map +1 -1
  195. package/dist/integrations/webhook-handler.js +257 -35
  196. package/dist/integrations/webhook-handler.js.map +1 -1
  197. package/dist/localization/default-messages.d.ts +42 -0
  198. package/dist/localization/default-messages.d.ts.map +1 -1
  199. package/dist/localization/default-messages.js +42 -0
  200. package/dist/localization/default-messages.js.map +1 -1
  201. package/dist/notifications/routes.d.ts +2 -2
  202. package/dist/observability/routes.d.ts +1 -1
  203. package/dist/progress/routes.d.ts +1 -1
  204. package/dist/server/action-discovery.d.ts.map +1 -1
  205. package/dist/server/action-discovery.js +12 -0
  206. package/dist/server/action-discovery.js.map +1 -1
  207. package/dist/server/action-routes.d.ts +3 -0
  208. package/dist/server/action-routes.d.ts.map +1 -1
  209. package/dist/server/action-routes.js +45 -5
  210. package/dist/server/action-routes.js.map +1 -1
  211. package/dist/server/agent-chat-plugin.d.ts +6 -0
  212. package/dist/server/agent-chat-plugin.d.ts.map +1 -1
  213. package/dist/server/agent-chat-plugin.js +71 -6
  214. package/dist/server/agent-chat-plugin.js.map +1 -1
  215. package/dist/server/agent-engine-api-key-route.d.ts +1 -1
  216. package/dist/server/index.d.ts +1 -0
  217. package/dist/server/index.d.ts.map +1 -1
  218. package/dist/server/index.js +1 -0
  219. package/dist/server/index.js.map +1 -1
  220. package/dist/settings/org-settings.d.ts +2 -0
  221. package/dist/settings/org-settings.d.ts.map +1 -1
  222. package/dist/settings/org-settings.js +5 -1
  223. package/dist/settings/org-settings.js.map +1 -1
  224. package/dist/settings/store.d.ts +8 -0
  225. package/dist/settings/store.d.ts.map +1 -1
  226. package/dist/settings/store.js +48 -0
  227. package/dist/settings/store.js.map +1 -1
  228. package/dist/templates/chat/.agents/skills/feature-flags/SKILL.md +169 -0
  229. package/dist/templates/default/.agents/skills/feature-flags/SKILL.md +169 -0
  230. package/dist/templates/default/AGENTS.md +1 -0
  231. package/dist/templates/headless/.agents/skills/feature-flags/SKILL.md +169 -0
  232. package/dist/templates/workspace-core/.agents/skills/feature-flags/SKILL.md +169 -0
  233. package/dist/templates/workspace-core/AGENTS.md +1 -1
  234. package/dist/templates/workspace-root/AGENTS.md +1 -1
  235. package/dist/vite/action-types-plugin.d.ts.map +1 -1
  236. package/dist/vite/action-types-plugin.js +12 -0
  237. package/dist/vite/action-types-plugin.js.map +1 -1
  238. package/docs/content/actions.mdx +48 -0
  239. package/docs/content/locales/ar-SA/actions.mdx +38 -0
  240. package/docs/content/locales/de-DE/actions.mdx +38 -0
  241. package/docs/content/locales/es-ES/actions.mdx +38 -0
  242. package/docs/content/locales/fr-FR/actions.mdx +38 -0
  243. package/docs/content/locales/hi-IN/actions.mdx +38 -0
  244. package/docs/content/locales/ja-JP/actions.mdx +38 -0
  245. package/docs/content/locales/ko-KR/actions.mdx +38 -0
  246. package/docs/content/locales/pt-BR/actions.mdx +38 -0
  247. package/docs/content/locales/zh-CN/actions.mdx +38 -0
  248. package/docs/content/locales/zh-TW/actions.mdx +38 -0
  249. package/package.json +5 -1
  250. package/src/templates/chat/.agents/skills/feature-flags/SKILL.md +169 -0
  251. package/src/templates/default/.agents/skills/feature-flags/SKILL.md +169 -0
  252. package/src/templates/default/AGENTS.md +1 -0
  253. package/src/templates/headless/.agents/skills/feature-flags/SKILL.md +169 -0
  254. package/src/templates/workspace-core/.agents/skills/feature-flags/SKILL.md +169 -0
  255. package/src/templates/workspace-core/AGENTS.md +1 -1
  256. package/src/templates/workspace-root/AGENTS.md +1 -1
  257. package/corpus/templates/clips/actions/get-feature-flags.ts +0 -30
@@ -1,8 +1,28 @@
1
1
  import type { H3Event } from "h3";
2
+ import { type A2AArtifactIdentity } from "../a2a/artifact-response.js";
2
3
  import type { AgentEngine } from "../agent/engine/types.js";
3
4
  import { type ActionEntry } from "../agent/production-agent.js";
4
5
  import { type PendingTask } from "./pending-tasks-store.js";
5
- import type { PlatformAdapter, IncomingMessage } from "./types.js";
6
+ import type { PlatformAdapter, IncomingMessage, OutgoingMessage, PlatformDeliveryReceipt } from "./types.js";
7
+ export type IntegrationResponseDeliveryTaskPayload = {
8
+ kind: "response-delivery";
9
+ incoming: IncomingMessage;
10
+ message: OutgoingMessage;
11
+ placeholderRef?: string;
12
+ internalThreadId?: string;
13
+ userMessageId?: string;
14
+ assistantMessageId?: string;
15
+ deliveryReceipt?: PlatformDeliveryReceipt;
16
+ deliveredAt?: string;
17
+ artifacts?: A2AArtifactIdentity[];
18
+ };
19
+ export type ProcessIntegrationTaskResult = {
20
+ status: "completed";
21
+ } | {
22
+ status: "delivery-pending";
23
+ payload: IntegrationResponseDeliveryTaskPayload;
24
+ errorMessage: string;
25
+ };
6
26
  export interface WebhookHandlerOptions {
7
27
  adapter: PlatformAdapter;
8
28
  /** Resolved system prompt string */
@@ -85,5 +105,6 @@ export declare function resolveBaseUrl(event: H3Event): string;
85
105
  * processor endpoint in `plugin.ts`. This is a fresh function execution, so
86
106
  * it gets its own timeout budget independent of the inbound webhook handler.
87
107
  */
88
- export declare function processIntegrationTask(task: PendingTask, options: WebhookHandlerOptions): Promise<void>;
108
+ export declare function processIntegrationTask(task: PendingTask, options: WebhookHandlerOptions): Promise<ProcessIntegrationTaskResult>;
109
+ export declare function recordIntegrationResponseDelivery(payload: IntegrationResponseDeliveryTaskPayload, receipt: PlatformDeliveryReceipt): Promise<void>;
89
110
  //# sourceMappingURL=webhook-handler.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"webhook-handler.d.ts","sourceRoot":"","sources":["../../src/integrations/webhook-handler.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,IAAI,CAAC;AAqBlC,OAAO,KAAK,EAAE,WAAW,EAAiB,MAAM,0BAA0B,CAAC;AAC3E,OAAO,EAOL,KAAK,WAAW,EACjB,MAAM,8BAA8B,CAAC;AA+BtC,OAAO,EAGL,KAAK,WAAW,EACjB,MAAM,0BAA0B,CAAC;AAGlC,OAAO,KAAK,EACV,eAAe,EACf,eAAe,EAEhB,MAAM,YAAY,CAAC;AA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QAAQ,CAAC,EAC7C,UAAU,EAAE,MAAM,EAClB,cAAc,EAAE,MAAM,GACrB,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAyB7B;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAsB,aAAa,CACjC,KAAK,EAAE,OAAO,EACd,OAAO,EAAE,qBAAqB,GAC7B,OAAO,CAAC;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,OAAO,CAAA;CAAE,CAAC,CA0E5C;AA6ID;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CAgCrD;AAED;;;;GAIG;AACH,wBAAsB,sBAAsB,CAC1C,IAAI,EAAE,WAAW,EACjB,OAAO,EAAE,qBAAqB,GAC7B,OAAO,CAAC,4BAA4B,CAAC,CAgBvC;AAkvCD,wBAAsB,iCAAiC,CACrD,OAAO,EAAE,sCAAsC,EAC/C,OAAO,EAAE,uBAAuB,GAC/B,OAAO,CAAC,IAAI,CAAC,CAsEf"}
@@ -12,7 +12,7 @@ import { attachToolSearch } from "../agent/tool-search.js";
12
12
  import { createThread, getThread } from "../chat-threads/store.js";
13
13
  import { updateThreadData } from "../chat-threads/store.js";
14
14
  import { isLocalDatabase } from "../db/client.js";
15
- import { resolveOrgIdForEmail } from "../org/context.js";
15
+ import { getOrgA2ASecret, resolveOrgIdForEmail } from "../org/context.js";
16
16
  import { withConfiguredAppBasePath } from "../server/app-base-path.js";
17
17
  import { FRAMEWORK_ROUTE_PREFIX } from "../server/core-routes-plugin.js";
18
18
  import { canUseDeployCredentialFallbackForRequest, readDeployCredentialEnv, } from "../server/credential-provider.js";
@@ -22,7 +22,7 @@ import { A2A_CONTINUATION_QUEUED_MARKER } from "./a2a-continuation-marker.js";
22
22
  import { clearIntegrationAwaitingInput, setIntegrationAwaitingInput, } from "./awaiting-input-store.js";
23
23
  import { loadIntegrationMemoryPrompt } from "./integration-memory.js";
24
24
  import { signInternalToken } from "./internal-token.js";
25
- import { insertPendingTask, isDuplicateEventError, } from "./pending-tasks-store.js";
25
+ import { insertPendingTask, isDuplicateEventError, stageTaskDeliveryPayload, } from "./pending-tasks-store.js";
26
26
  import { integrationScopeSubjectKey } from "./scope-store.js";
27
27
  import { getThreadMapping, saveThreadMapping } from "./thread-mapping-store.js";
28
28
  import { listIntegrationUsageBudgets, releaseIntegrationUsageBudget, reserveIntegrationUsageBudget, settleIntegrationUsageBudget, } from "./usage-budget-store.js";
@@ -59,6 +59,13 @@ function buildEventDedupKey(incoming) {
59
59
  : String(incoming.timestamp);
60
60
  return `${incoming.platform}:${incoming.externalThreadId}:${eventReference}`;
61
61
  }
62
+ function buildDeliveryHistoryMessageIds(incoming) {
63
+ const eventKey = buildEventDedupKey(incoming);
64
+ return {
65
+ userMessageId: `integration-${eventKey}-user`,
66
+ assistantMessageId: `integration-${eventKey}-assistant`,
67
+ };
68
+ }
62
69
  function explicitEngineName(engineOption) {
63
70
  if (!engineOption)
64
71
  return undefined;
@@ -361,7 +368,7 @@ export function resolveBaseUrl(event) {
361
368
  export async function processIntegrationTask(task, options) {
362
369
  const parsed = JSON.parse(task.payload);
363
370
  await recordInboundIntegrationAudit(task, parsed.incoming);
364
- await processIncomingMessage(parsed.incoming, options, {
371
+ return processIncomingMessage(parsed.incoming, options, {
365
372
  taskId: task.id,
366
373
  attempts: task.attempts,
367
374
  placeholderRef: parsed.placeholderRef,
@@ -458,10 +465,41 @@ async function processIncomingMessage(incoming, options, opts = {}) {
458
465
  });
459
466
  if (!budgetReservations.allowed) {
460
467
  const outgoing = adapter.formatAgentResponse("This channel or requester has reached its configured AI usage budget. An admin can review the budget in Messaging settings.");
461
- await adapter.sendResponse(outgoing, incoming, {
462
- placeholderRef: opts.placeholderRef,
463
- });
464
- return;
468
+ let deliveryPayload = {
469
+ kind: "response-delivery",
470
+ incoming,
471
+ message: outgoing,
472
+ ...(opts.placeholderRef ? { placeholderRef: opts.placeholderRef } : {}),
473
+ };
474
+ try {
475
+ if (opts.taskId) {
476
+ await stageTaskDeliveryPayload(opts.taskId, JSON.stringify(deliveryPayload));
477
+ }
478
+ const receipt = await adapter.sendResponse(outgoing, incoming, {
479
+ placeholderRef: opts.placeholderRef,
480
+ });
481
+ if (receipt?.status !== "delivered") {
482
+ throw new Error(`${incoming.platform} response completed without delivery proof`);
483
+ }
484
+ deliveryPayload = {
485
+ ...deliveryPayload,
486
+ deliveryReceipt: receipt,
487
+ deliveredAt: new Date().toISOString(),
488
+ };
489
+ if (opts.taskId) {
490
+ await stageTaskDeliveryPayload(opts.taskId, JSON.stringify(deliveryPayload));
491
+ }
492
+ return { status: "completed" };
493
+ }
494
+ catch (error) {
495
+ return {
496
+ status: "delivery-pending",
497
+ payload: deliveryPayload,
498
+ errorMessage: error instanceof Error
499
+ ? error.message.slice(0, 1000)
500
+ : `${incoming.platform} response delivery failed`,
501
+ };
502
+ }
465
503
  }
466
504
  let threadId;
467
505
  let thread;
@@ -530,11 +568,13 @@ async function processIncomingMessage(incoming, options, opts = {}) {
530
568
  // A2A delegation. Without this, getRequestOrgId() returns undefined and
531
569
  // call-agent can't look up the org's a2a_secret or org_domain.
532
570
  let orgId;
571
+ let artifactSecrets;
533
572
  let runnableActions;
534
573
  let tools;
535
574
  let availableTools;
536
575
  try {
537
576
  orgId = opts.orgId ?? (await resolveOrgIdForEmail(ownerEmail));
577
+ artifactSecrets = await resolveIntegrationArtifactSecrets(orgId);
538
578
  // Attach tool-search on a shallow copy so framework additions merged in
539
579
  // by `createIntegrationsPlugin` (integration memory, `call-agent`) can be
540
580
  // deferred behind it without mutating the plugin's long-lived registry.
@@ -555,7 +595,7 @@ async function processIncomingMessage(incoming, options, opts = {}) {
555
595
  let budgetsSettled = false;
556
596
  // Wait for the run to complete inside this fresh function execution.
557
597
  // We use a Promise so the processor endpoint can await the full lifecycle.
558
- await new Promise((resolve) => {
598
+ return new Promise((resolve) => {
559
599
  startRun(runId, threadId, async (send, signal) => {
560
600
  await runWithRequestContext({
561
601
  userEmail: ownerEmail,
@@ -638,6 +678,10 @@ async function processIncomingMessage(incoming, options, opts = {}) {
638
678
  }, async (completedRun) => {
639
679
  let keepSlackInputWindow = false;
640
680
  let queuedA2AContinuation = false;
681
+ let outgoingForDelivery;
682
+ let stagedDeliveryPayload;
683
+ let threadCheckpoint;
684
+ let outcome = { status: "completed" };
641
685
  try {
642
686
  queuedA2AContinuation = hasQueuedA2AContinuation(completedRun);
643
687
  const slackInputRequest = incoming.platform === "slack"
@@ -720,6 +764,23 @@ async function processIncomingMessage(incoming, options, opts = {}) {
720
764
  const outgoing = adapter.formatAgentResponse(responseText, {
721
765
  threadDeepLinkUrl,
722
766
  });
767
+ outgoingForDelivery = outgoing;
768
+ stagedDeliveryPayload = {
769
+ kind: "response-delivery",
770
+ incoming,
771
+ message: outgoing,
772
+ ...(opts.placeholderRef
773
+ ? { placeholderRef: opts.placeholderRef }
774
+ : {}),
775
+ internalThreadId: threadId,
776
+ ...buildDeliveryHistoryMessageIds(incoming),
777
+ artifacts: extractA2AArtifactIdentities(toolResults, {
778
+ persistedArtifactSecrets: artifactSecrets,
779
+ }),
780
+ };
781
+ if (opts.taskId) {
782
+ await stageTaskDeliveryPayload(opts.taskId, JSON.stringify(stagedDeliveryPayload));
783
+ }
723
784
  let deliveryReceipt;
724
785
  if (queuedA2AContinuation && progress?.ref) {
725
786
  // Post substantive parent results as a normal thread reply while
@@ -744,22 +805,28 @@ async function processIncomingMessage(incoming, options, opts = {}) {
744
805
  placeholderRef: opts.placeholderRef,
745
806
  });
746
807
  }
747
- const delivered = deliveryReceipt?.status === "delivered";
748
- if (!delivered) {
808
+ if (deliveryReceipt?.status !== "delivered") {
749
809
  throw new Error(`${incoming.platform} response completed without delivery proof`);
750
810
  }
751
- if (delivered) {
752
- deliveredResponse = {
753
- platform: incoming.platform,
754
- status: "delivered",
755
- text: outgoing.text,
756
- deliveredAt: new Date().toISOString(),
757
- ...(deliveryReceipt?.messageRefs?.length
758
- ? { messageRefs: deliveryReceipt.messageRefs }
759
- : {}),
760
- };
811
+ const deliveredAt = new Date().toISOString();
812
+ stagedDeliveryPayload = {
813
+ ...stagedDeliveryPayload,
814
+ deliveryReceipt,
815
+ deliveredAt,
816
+ };
817
+ if (opts.taskId) {
818
+ await stageTaskDeliveryPayload(opts.taskId, JSON.stringify(stagedDeliveryPayload));
761
819
  }
762
- if (slackInputRequest && delivered && incoming.senderId) {
820
+ deliveredResponse = {
821
+ platform: incoming.platform,
822
+ status: "delivered",
823
+ text: outgoing.text,
824
+ deliveredAt,
825
+ ...(deliveryReceipt.messageRefs?.length
826
+ ? { messageRefs: deliveryReceipt.messageRefs }
827
+ : {}),
828
+ };
829
+ if (slackInputRequest && incoming.senderId) {
763
830
  await setIntegrationAwaitingInput({
764
831
  platform: "slack",
765
832
  externalThreadId: incoming.externalThreadId,
@@ -798,7 +865,22 @@ async function processIncomingMessage(incoming, options, opts = {}) {
798
865
  }
799
866
  }
800
867
  // Persist thread data
801
- await persistThreadData(threadId, incoming.text, completedRun, thread, deliveredResponse, toolResults);
868
+ threadCheckpoint = await persistThreadData(threadId, incoming.text, completedRun, thread, deliveredResponse, toolResults, stagedDeliveryPayload, artifactSecrets);
869
+ if (outgoingForDelivery && stagedDeliveryPayload) {
870
+ if (!threadCheckpoint) {
871
+ throw new Error("Integration response history checkpoint failed");
872
+ }
873
+ stagedDeliveryPayload = {
874
+ ...stagedDeliveryPayload,
875
+ userMessageId: threadCheckpoint.userMessageId,
876
+ ...(threadCheckpoint.assistantMessageId
877
+ ? { assistantMessageId: threadCheckpoint.assistantMessageId }
878
+ : {}),
879
+ };
880
+ if (opts.taskId) {
881
+ await stageTaskDeliveryPayload(opts.taskId, JSON.stringify(stagedDeliveryPayload));
882
+ }
883
+ }
802
884
  await recordIntegrationUsage({
803
885
  usage,
804
886
  ownerEmail,
@@ -814,9 +896,52 @@ async function processIncomingMessage(incoming, options, opts = {}) {
814
896
  }
815
897
  catch (err) {
816
898
  console.error(`[integrations] Error sending response to ${incoming.platform}:`, err);
899
+ if (outgoingForDelivery) {
900
+ const errorMessage = err instanceof Error
901
+ ? err.message.slice(0, 1000)
902
+ : `${incoming.platform} response delivery failed`;
903
+ if (!stagedDeliveryPayload?.deliveryReceipt) {
904
+ threadCheckpoint = await persistThreadData(threadId, incoming.text, completedRun, thread, undefined, collectToolResultSummaries(completedRun), stagedDeliveryPayload, artifactSecrets);
905
+ }
906
+ if (usage) {
907
+ await recordIntegrationUsage({
908
+ usage,
909
+ ownerEmail,
910
+ appId: options.appId,
911
+ runId,
912
+ threadId,
913
+ taskId: opts.taskId,
914
+ orgId: orgId ?? undefined,
915
+ incoming,
916
+ }).catch(() => { });
917
+ try {
918
+ await settleApplicableIntegrationBudgets(budgetReservations.reservations, usage);
919
+ budgetsSettled = true;
920
+ }
921
+ catch { }
922
+ }
923
+ outcome = {
924
+ status: "delivery-pending",
925
+ payload: {
926
+ ...(stagedDeliveryPayload ?? {
927
+ kind: "response-delivery",
928
+ incoming,
929
+ message: outgoingForDelivery,
930
+ internalThreadId: threadId,
931
+ }),
932
+ ...(threadCheckpoint?.userMessageId
933
+ ? { userMessageId: threadCheckpoint.userMessageId }
934
+ : {}),
935
+ ...(threadCheckpoint?.assistantMessageId
936
+ ? { assistantMessageId: threadCheckpoint.assistantMessageId }
937
+ : {}),
938
+ },
939
+ errorMessage,
940
+ };
941
+ return;
942
+ }
817
943
  // A queued continuation owns the final platform response. Later
818
- // bookkeeping failures (for example, persisting this parent run)
819
- // must not close its resumable native stream with a false failure.
944
+ // bookkeeping failures must not close its stream with a false failure.
820
945
  if (queuedA2AContinuation)
821
946
  return;
822
947
  // Last-ditch: try to post a brief apology so the thread isn't silent.
@@ -838,7 +963,7 @@ async function processIncomingMessage(incoming, options, opts = {}) {
838
963
  if (!budgetsSettled) {
839
964
  await releaseApplicableIntegrationBudgets(budgetReservations.reservations);
840
965
  }
841
- resolve();
966
+ resolve(outcome);
842
967
  }
843
968
  },
844
969
  // Integration workers are ordinary self-dispatched serverless requests,
@@ -1130,7 +1255,7 @@ function hasSubstantiveA2APartialAnswer(text) {
1130
1255
  * Persist the user message and agent response to the thread data,
1131
1256
  * so the conversation history is available in the web UI too.
1132
1257
  */
1133
- async function persistThreadData(threadId, userText, completedRun, thread, deliveredResponse, toolResults = []) {
1258
+ async function persistThreadData(threadId, userText, completedRun, thread, deliveredResponse, toolResults = [], messageIds, artifactSecrets = []) {
1134
1259
  try {
1135
1260
  let repo;
1136
1261
  try {
@@ -1143,32 +1268,129 @@ async function persistThreadData(threadId, userText, completedRun, thread, deliv
1143
1268
  repo.messages = [];
1144
1269
  // Add user message
1145
1270
  const userMsg = {
1146
- id: `msg-${Date.now()}-user`,
1271
+ id: messageIds?.userMessageId ?? `msg-${Date.now()}-user`,
1147
1272
  role: "user",
1148
1273
  content: [{ type: "text", text: userText }],
1149
1274
  createdAt: new Date().toISOString(),
1150
1275
  };
1151
1276
  // Build assistant message from run events
1152
- const assistantMsg = buildAssistantMessage(completedRun.events ?? [], completedRun.runId);
1277
+ const builtAssistantMsg = buildAssistantMessage(completedRun.events ?? [], completedRun.runId);
1278
+ if (builtAssistantMsg && messageIds?.assistantMessageId) {
1279
+ builtAssistantMsg.id = messageIds.assistantMessageId;
1280
+ }
1281
+ const existingAssistantMsg = builtAssistantMsg
1282
+ ? repo.messages.find((message) => message?.id === builtAssistantMsg.id)
1283
+ : undefined;
1284
+ const assistantMsg = existingAssistantMsg ?? builtAssistantMsg;
1153
1285
  if (assistantMsg) {
1154
1286
  assistantMsg.metadata.integrationDeliveryAttempted = true;
1287
+ const artifactIdentities = extractA2AArtifactIdentities(toolResults, {
1288
+ persistedArtifactSecrets: artifactSecrets,
1289
+ });
1290
+ if (artifactIdentities.length > 0) {
1291
+ assistantMsg.metadata.integrationArtifacts = artifactIdentities;
1292
+ }
1155
1293
  if (deliveredResponse) {
1156
1294
  assistantMsg.metadata.integrationDelivery = deliveredResponse;
1157
- const artifactIdentities = extractA2AArtifactIdentities(toolResults);
1158
- if (artifactIdentities.length > 0) {
1159
- assistantMsg.metadata.integrationArtifacts = artifactIdentities;
1160
- }
1161
1295
  }
1162
1296
  }
1163
- repo.messages.push(userMsg);
1164
- if (assistantMsg) {
1165
- repo.messages.push(assistantMsg);
1297
+ if (!repo.messages.some((message) => message?.id === userMsg.id)) {
1298
+ repo.messages.push(userMsg);
1299
+ }
1300
+ if (builtAssistantMsg && !existingAssistantMsg) {
1301
+ repo.messages.push(builtAssistantMsg);
1166
1302
  }
1167
1303
  const meta = extractThreadMeta(repo);
1168
1304
  await updateThreadData(threadId, JSON.stringify(repo), meta.title || thread?.title || "Integration Chat", meta.preview || thread?.preview || "", repo.messages.length);
1305
+ return {
1306
+ userMessageId: userMsg.id,
1307
+ ...(assistantMsg?.id ? { assistantMessageId: assistantMsg.id } : {}),
1308
+ };
1169
1309
  }
1170
1310
  catch {
1171
1311
  // Best-effort persistence
1312
+ return undefined;
1313
+ }
1314
+ }
1315
+ async function resolveIntegrationArtifactSecrets(orgId) {
1316
+ const secrets = [];
1317
+ const add = (secret) => {
1318
+ const value = secret?.trim();
1319
+ if (value && !secrets.includes(value))
1320
+ secrets.push(value);
1321
+ };
1322
+ add(process.env.A2A_SECRET);
1323
+ if (orgId) {
1324
+ try {
1325
+ add(await getOrgA2ASecret(orgId));
1326
+ }
1327
+ catch { }
1172
1328
  }
1329
+ return secrets;
1330
+ }
1331
+ export async function recordIntegrationResponseDelivery(payload, receipt) {
1332
+ if (!payload.internalThreadId)
1333
+ return;
1334
+ const thread = await getThread(payload.internalThreadId);
1335
+ if (!thread)
1336
+ throw new Error("Integration delivery thread was not found");
1337
+ let repo;
1338
+ try {
1339
+ repo = JSON.parse(thread.threadData || "{}");
1340
+ }
1341
+ catch {
1342
+ throw new Error("Integration delivery thread data is invalid");
1343
+ }
1344
+ if (!Array.isArray(repo.messages)) {
1345
+ repo.messages = [];
1346
+ }
1347
+ const stableMessageIds = buildDeliveryHistoryMessageIds(payload.incoming);
1348
+ const userMessageId = payload.userMessageId ?? stableMessageIds.userMessageId;
1349
+ const assistantMessageId = payload.assistantMessageId ?? stableMessageIds.assistantMessageId;
1350
+ const userMsg = userMessageId
1351
+ ? repo.messages.find((message) => message?.id === userMessageId)
1352
+ : undefined;
1353
+ let assistantMsg = assistantMessageId
1354
+ ? repo.messages.find((message) => message?.id === assistantMessageId)
1355
+ : undefined;
1356
+ const createdAt = payload.deliveredAt ?? new Date().toISOString();
1357
+ if (!userMsg) {
1358
+ repo.messages.push({
1359
+ id: userMessageId,
1360
+ role: "user",
1361
+ content: [{ type: "text", text: payload.incoming.text }],
1362
+ createdAt,
1363
+ });
1364
+ }
1365
+ if (!assistantMsg) {
1366
+ assistantMsg = {
1367
+ id: assistantMessageId,
1368
+ role: "assistant",
1369
+ content: [{ type: "text", text: payload.message.text }],
1370
+ createdAt,
1371
+ metadata: {
1372
+ integrationDeliveryAttempted: true,
1373
+ ...(payload.artifacts?.length
1374
+ ? { integrationArtifacts: payload.artifacts }
1375
+ : {}),
1376
+ },
1377
+ };
1378
+ repo.messages.push(assistantMsg);
1379
+ }
1380
+ if (!assistantMsg.metadata || typeof assistantMsg.metadata !== "object") {
1381
+ assistantMsg.metadata = {};
1382
+ }
1383
+ assistantMsg.metadata.integrationDeliveryAttempted = true;
1384
+ assistantMsg.metadata.integrationDelivery = {
1385
+ platform: payload.incoming.platform,
1386
+ status: "delivered",
1387
+ text: payload.message.text,
1388
+ deliveredAt: payload.deliveredAt ?? new Date().toISOString(),
1389
+ ...(receipt.messageRefs?.length
1390
+ ? { messageRefs: receipt.messageRefs }
1391
+ : {}),
1392
+ };
1393
+ const meta = extractThreadMeta(repo);
1394
+ await updateThreadData(payload.internalThreadId, JSON.stringify(repo), meta.title || thread.title || "Integration Chat", meta.preview || thread.preview || "", repo.messages.length);
1173
1395
  }
1174
1396
  //# sourceMappingURL=webhook-handler.js.map