@agent-native/core 0.221.0-same-host-mcp-20261027-20261027081850 → 0.221.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 (327) hide show
  1. package/dist/a2a/server.js +4 -4
  2. package/dist/a2a/task-lifecycle.d.ts +12 -12
  3. package/dist/a2a/task-lifecycle.js +10 -12
  4. package/dist/a2a/task-store.js +81 -228
  5. package/dist/action-caller.d.ts +3 -0
  6. package/dist/action-caller.js +8 -0
  7. package/dist/action.d.ts +1 -0
  8. package/dist/agent/engine/ai-sdk-engine.js +3 -3
  9. package/dist/agent/engine/anthropic-engine.js +3 -3
  10. package/dist/agent/engine/credential-owner.d.ts +3 -0
  11. package/dist/agent/engine/credential-owner.js +9 -0
  12. package/dist/agent/engine/registry.js +28 -2
  13. package/dist/agent/harness/acp-adapter.d.ts +1 -0
  14. package/dist/agent/harness/acp-adapter.js +36 -5
  15. package/dist/agent/harness/background.d.ts +5 -1
  16. package/dist/agent/harness/background.js +4 -3
  17. package/dist/agent/harness/lifecycle.d.ts +2 -0
  18. package/dist/agent/harness/lifecycle.js +452 -84
  19. package/dist/agent/harness/run-policy.d.ts +5 -0
  20. package/dist/agent/harness/run-policy.js +70 -0
  21. package/dist/agent/harness/runner.js +89 -73
  22. package/dist/agent/harness/store.d.ts +10 -1
  23. package/dist/agent/harness/store.js +91 -12
  24. package/dist/agent/harness/turn-driver.d.ts +12 -0
  25. package/dist/agent/harness/turn-driver.js +42 -0
  26. package/dist/agent/harness/types.d.ts +11 -0
  27. package/dist/agent/production-agent.d.ts +9 -0
  28. package/dist/agent/production-agent.js +153 -41
  29. package/dist/agent/run-manager.d.ts +4 -0
  30. package/dist/agent/run-manager.js +23 -7
  31. package/dist/agent/run-store.d.ts +3 -1
  32. package/dist/agent/run-store.fencing.native-harness.fixture.test.support.js +34 -0
  33. package/dist/agent/run-store.fencing.worker.test.support.d.ts +1 -0
  34. package/dist/agent/{run-store.fencing.worker.js → run-store.fencing.worker.test.support.js} +337 -4
  35. package/dist/agent/run-store.js +89 -17
  36. package/dist/app-config/clips.d.ts +10 -0
  37. package/dist/app-config/clips.js +24 -0
  38. package/dist/app-config/index.d.ts +1 -1
  39. package/dist/app-config/index.js +1 -1
  40. package/dist/app-config/schema.d.ts +1 -0
  41. package/dist/appearance/actions/set-theme-family.js +16 -2
  42. package/dist/appearance/theme-family.d.ts +11 -1
  43. package/dist/appearance/theme-family.js +21 -2
  44. package/dist/automations/outside-origin.d.ts +13 -0
  45. package/dist/automations/outside-origin.js +23 -0
  46. package/dist/automations/service.d.ts +4 -2
  47. package/dist/automations/service.js +11 -8
  48. package/dist/cli/code-agent-executor.js +5 -16
  49. package/dist/cli/create.d.ts +11 -2
  50. package/dist/cli/create.js +121 -32
  51. package/dist/cli/skills-content/turn-into-app-skill.d.ts +4 -3
  52. package/dist/cli/skills-content/turn-into-app-skill.js +143 -36
  53. package/dist/cli/skills.d.ts +3 -0
  54. package/dist/cli/skills.js +4 -1
  55. package/dist/cli/template-sync.js +4 -4
  56. package/dist/cli/upgrade.d.ts +1 -0
  57. package/dist/cli/upgrade.js +207 -2
  58. package/dist/client/chat/agentkit-agent-native.js +23 -3
  59. package/dist/client/mcp-approval.d.ts +53 -0
  60. package/dist/client/mcp-approval.js +81 -0
  61. package/dist/client/onboarding/use-onboarding.js +6 -4
  62. package/dist/client/resources/mcp-integration-catalog.js +19 -0
  63. package/dist/client/theme-family.d.ts +2 -1
  64. package/dist/client/theme-family.js +271 -32
  65. package/dist/client/theme.js +3 -2
  66. package/dist/code-agents/background-controller.js +1 -13
  67. package/dist/code-agents/prompt-attachments.d.ts +11 -0
  68. package/dist/code-agents/prompt-attachments.js +103 -6
  69. package/dist/collab/awareness-store.d.ts +8 -0
  70. package/dist/collab/awareness-store.js +9 -1
  71. package/dist/collab/index.d.ts +1 -1
  72. package/dist/collab/index.js +1 -1
  73. package/dist/collab/routes.d.ts +1 -1
  74. package/dist/collab/struct-routes.d.ts +1 -1
  75. package/dist/config.d.ts +13 -3
  76. package/dist/config.js +64 -1
  77. package/dist/db/client.d.ts +8 -6
  78. package/dist/db/client.js +56 -17
  79. package/dist/db/create-get-db.js +6 -1
  80. package/dist/db/index.d.ts +2 -1
  81. package/dist/db/index.js +1 -0
  82. package/dist/db/schema-snapshot.generated.js +9 -2
  83. package/dist/db/sql.d.ts +28 -0
  84. package/dist/db/sql.js +186 -0
  85. package/dist/decisions/actions/decide.d.ts +4 -0
  86. package/dist/decisions/actions/decide.js +7 -0
  87. package/dist/decisions/decide.d.ts +1 -0
  88. package/dist/decisions/decide.js +21 -9
  89. package/dist/decisions/index.d.ts +4 -1
  90. package/dist/decisions/index.js +3 -0
  91. package/dist/decisions/response.d.ts +1 -0
  92. package/dist/decisions/response.js +36 -11
  93. package/dist/decisions/types.d.ts +5 -0
  94. package/dist/decisions/validation.js +6 -3
  95. package/dist/deploy/build.js +11 -5
  96. package/dist/file-upload/actions/upload-image.d.ts +2 -2
  97. package/dist/file-upload/attachment-text.d.ts +71 -0
  98. package/dist/file-upload/attachment-text.js +209 -0
  99. package/dist/file-upload/downscale-inline-image.d.ts +4 -0
  100. package/dist/file-upload/downscale-inline-image.js +27 -0
  101. package/dist/file-upload/inline-attachment-limits.d.ts +4 -0
  102. package/dist/file-upload/inline-attachment-limits.js +20 -1
  103. package/dist/file-upload/owned-attachment.d.ts +13 -1
  104. package/dist/file-upload/owned-attachment.js +52 -15
  105. package/dist/file-upload/pre-upload-attachments.js +74 -12
  106. package/dist/file-upload/registry.d.ts +1 -0
  107. package/dist/file-upload/registry.js +15 -7
  108. package/dist/file-upload/status.d.ts +19 -0
  109. package/dist/file-upload/status.js +49 -0
  110. package/dist/file-upload/thread-image-history.js +10 -2
  111. package/dist/index.browser.d.ts +1 -0
  112. package/dist/index.browser.js +1 -0
  113. package/dist/index.d.ts +1 -0
  114. package/dist/index.js +1 -0
  115. package/dist/ingestion/media.js +11 -5
  116. package/dist/jobs/actions/run-automation-now.js +2 -2
  117. package/dist/jobs/background-automation-runner.js +4 -4
  118. package/dist/jobs/frontmatter.d.ts +1 -1
  119. package/dist/jobs/frontmatter.js +5 -2
  120. package/dist/jobs/run-now.d.ts +2 -0
  121. package/dist/jobs/run-now.js +1 -1
  122. package/dist/jobs/scheduler.d.ts +2 -0
  123. package/dist/jobs/scheduler.js +1 -1
  124. package/dist/localization/automation-outcome-messages.js +22 -22
  125. package/dist/localization/core-messages/supplemental/ar-SA.js +1 -0
  126. package/dist/localization/core-messages/supplemental/de-DE.js +1 -0
  127. package/dist/localization/core-messages/supplemental/en-US.js +1 -0
  128. package/dist/localization/core-messages/supplemental/es-ES.js +1 -0
  129. package/dist/localization/core-messages/supplemental/fr-FR.js +1 -0
  130. package/dist/localization/core-messages/supplemental/hi-IN.js +1 -0
  131. package/dist/localization/core-messages/supplemental/ja-JP.js +1 -0
  132. package/dist/localization/core-messages/supplemental/ko-KR.js +1 -0
  133. package/dist/localization/core-messages/supplemental/pt-BR.js +1 -0
  134. package/dist/localization/core-messages/supplemental/zh-CN.js +1 -0
  135. package/dist/localization/core-messages/supplemental/zh-TW.js +1 -0
  136. package/dist/localization/mcp-approval-messages.d.ts +7 -1
  137. package/dist/localization/mcp-approval-messages.js +66 -0
  138. package/dist/localization/mcp-settings-messages.d.ts +1 -0
  139. package/dist/mcp/action-eligibility.d.ts +1 -0
  140. package/dist/mcp/action-eligibility.js +10 -5
  141. package/dist/mcp/analytics.d.ts +2 -0
  142. package/dist/mcp/analytics.js +10 -2
  143. package/dist/mcp/approval-route.d.ts +7 -0
  144. package/dist/mcp/approval-route.js +41 -16
  145. package/dist/mcp/approval-summary.d.ts +12 -2
  146. package/dist/mcp/approval-summary.js +128 -23
  147. package/dist/mcp/approval-time.d.ts +13 -3
  148. package/dist/mcp/approval-time.js +49 -5
  149. package/dist/mcp/build-server.d.ts +12 -1
  150. package/dist/mcp/build-server.js +157 -155
  151. package/dist/mcp/builtin-tools.d.ts +1 -0
  152. package/dist/mcp/builtin-tools.js +30 -14
  153. package/dist/mcp/direct-action-call.js +72 -27
  154. package/dist/mcp/embed-app.js +11 -6
  155. package/dist/mcp/embed-redaction.d.ts +10 -13
  156. package/dist/mcp/embed-redaction.js +227 -40
  157. package/dist/mcp/execute-action-call.d.ts +3 -2
  158. package/dist/mcp/execute-action-call.js +1 -4
  159. package/dist/mcp/framework-tools.d.ts +2 -2
  160. package/dist/mcp/oauth-route.js +102 -6
  161. package/dist/mcp/screen-memory-stdio.d.ts +3 -3
  162. package/dist/mcp/server.js +6 -0
  163. package/dist/mcp-client/oauth-routes.js +12 -2
  164. package/dist/notifications/routes.d.ts +3 -3
  165. package/dist/observability/failure-context.js +1 -0
  166. package/dist/observability/traces.js +11 -1
  167. package/dist/onboarding/first-run-builder-credits-experiment.d.ts +12 -0
  168. package/dist/onboarding/first-run-builder-credits-experiment.js +91 -0
  169. package/dist/org/index.d.ts +1 -1
  170. package/dist/provider-api/actions/custom-provider-registration.d.ts +11 -11
  171. package/dist/provider-api/actions/provider-api.d.ts +12 -12
  172. package/dist/server/action-approval.d.ts +2 -2
  173. package/dist/server/action-approval.js +17 -10
  174. package/dist/server/action-discovery.js +2 -122
  175. package/dist/server/action-routes.d.ts +0 -1
  176. package/dist/server/action-routes.js +138 -58
  177. package/dist/server/agent-chat/action-filters-a2a.d.ts +1 -0
  178. package/dist/server/agent-chat/action-filters-a2a.js +11 -1
  179. package/dist/server/agent-chat/framework-prompts.d.ts +1 -0
  180. package/dist/server/agent-chat/framework-prompts.js +22 -1
  181. package/dist/server/agent-chat/mcp-options.d.ts +7 -0
  182. package/dist/server/agent-chat/mcp-options.js +1 -0
  183. package/dist/server/agent-chat/plugin-options.d.ts +23 -0
  184. package/dist/server/agent-chat/prompt-resources.d.ts +4 -2
  185. package/dist/server/agent-chat/prompt-resources.js +78 -32
  186. package/dist/server/agent-chat-plugin.js +214 -125
  187. package/dist/server/agent-engine-api-key-route.d.ts +2 -2
  188. package/dist/server/agent-engine-ollama-models-route.d.ts +1 -1
  189. package/dist/server/agent-run-context.js +4 -0
  190. package/dist/server/attachment-actions.d.ts +14 -7
  191. package/dist/server/attachment-actions.js +310 -65
  192. package/dist/server/attribution.d.ts +2 -0
  193. package/dist/server/auth.d.ts +2 -1
  194. package/dist/server/auth.js +84 -17
  195. package/dist/server/better-auth-instance.js +46 -12
  196. package/dist/server/builder-api-auth.d.ts +1 -0
  197. package/dist/server/builder-api-auth.js +8 -0
  198. package/dist/server/builder-browser.d.ts +5 -1
  199. package/dist/server/builder-browser.js +80 -4
  200. package/dist/server/cli-wrapper-flags.d.ts +27 -0
  201. package/dist/server/cli-wrapper-flags.js +500 -0
  202. package/dist/server/consent-route.d.ts +3 -0
  203. package/dist/server/consent-route.js +29 -10
  204. package/dist/server/core-routes-plugin.js +72 -60
  205. package/dist/server/credential-provider.js +26 -11
  206. package/dist/server/edge.d.ts +3 -2
  207. package/dist/server/edge.js +3 -2
  208. package/dist/server/embed-request-origin.d.ts +4 -0
  209. package/dist/server/embed-request-origin.js +28 -0
  210. package/dist/server/embed-route.js +4 -2
  211. package/dist/server/embed-session.d.ts +16 -4
  212. package/dist/server/embed-session.js +253 -145
  213. package/dist/server/embedded.d.ts +2 -1
  214. package/dist/server/embedded.js +9 -5
  215. package/dist/server/filesystem-action-entry.d.ts +15 -1
  216. package/dist/server/filesystem-action-entry.js +153 -23
  217. package/dist/server/first-touch-route.d.ts +1 -1
  218. package/dist/server/google-oauth.d.ts +7 -0
  219. package/dist/server/google-oauth.js +33 -6
  220. package/dist/server/index.d.ts +11 -6
  221. package/dist/server/index.js +8 -3
  222. package/dist/server/magic-link-attribution.d.ts +2 -0
  223. package/dist/server/magic-link-attribution.js +8 -2
  224. package/dist/server/mcp-signup-attribution.d.ts +23 -0
  225. package/dist/server/mcp-signup-attribution.js +135 -0
  226. package/dist/server/prompts/framework-core.js +2 -1
  227. package/dist/server/prompts/shared-rules.d.ts +2 -0
  228. package/dist/server/prompts/shared-rules.js +2 -0
  229. package/dist/server/realtime-voice.d.ts +65 -2
  230. package/dist/server/realtime-voice.js +235 -36
  231. package/dist/server/release-migrations.js +37 -10
  232. package/dist/server/request-context.d.ts +17 -0
  233. package/dist/server/request-context.js +4 -0
  234. package/dist/server/request-origin.d.ts +4 -6
  235. package/dist/server/request-origin.js +26 -28
  236. package/dist/server/session-resolution-unavailable.d.ts +22 -0
  237. package/dist/server/session-resolution-unavailable.js +65 -0
  238. package/dist/server/short-lived-token.d.ts +10 -2
  239. package/dist/server/short-lived-token.js +12 -4
  240. package/dist/server/ui-action-capability.js +18 -4
  241. package/dist/shared/first-run-builder-credits-experiment.d.ts +13 -0
  242. package/dist/shared/first-run-builder-credits-experiment.js +22 -0
  243. package/dist/shared/index.d.ts +1 -0
  244. package/dist/shared/index.js +1 -0
  245. package/dist/shared/mcp-approval-review.d.ts +19 -0
  246. package/dist/shared/mcp-approval-review.js +29 -0
  247. package/dist/shared/reasoning-effort.d.ts +4 -0
  248. package/dist/shared/reasoning-effort.js +20 -0
  249. package/dist/sharing/access.d.ts +11 -2
  250. package/dist/sharing/access.js +12 -7
  251. package/dist/state-machine/index.d.ts +5 -8
  252. package/dist/state-machine/index.js +6 -2
  253. package/dist/templates/builder-code-starter/app/components/layout/Layout.tsx.patch +48 -18
  254. package/dist/templates/builder-code-starter/server/plugins/agent-chat.ts.patch +7 -6
  255. package/dist/templates/builder-code-starter/template-layer.json +1 -0
  256. package/dist/templates/chat/.agents/skills/storing-data/SKILL.md +18 -0
  257. package/dist/templates/chat/app/components/chat/ChatRouteContent.tsx +18 -4
  258. package/dist/templates/chat/app/components/home/HomePage.tsx +28 -69
  259. package/dist/templates/chat/app/components/layout/Layout.tsx +46 -14
  260. package/dist/templates/chat/app/i18n/ar-SA.ts +0 -4
  261. package/dist/templates/chat/app/i18n/de-DE.ts +0 -5
  262. package/dist/templates/chat/app/i18n/en-US.ts +0 -4
  263. package/dist/templates/chat/app/i18n/es-ES.ts +0 -5
  264. package/dist/templates/chat/app/i18n/fr-FR.ts +0 -5
  265. package/dist/templates/chat/app/i18n/hi-IN.ts +0 -5
  266. package/dist/templates/chat/app/i18n/ja-JP.ts +0 -5
  267. package/dist/templates/chat/app/i18n/ko-KR.ts +0 -5
  268. package/dist/templates/chat/app/i18n/pt-BR.ts +0 -5
  269. package/dist/templates/chat/app/i18n/zh-CN.ts +0 -4
  270. package/dist/templates/chat/app/i18n/zh-TW.ts +0 -4
  271. package/dist/templates/chat/app/lib/chat-paths.ts +36 -13
  272. package/dist/templates/chat/package.json +1 -0
  273. package/dist/templates/chat/server/plugins/agent-chat.ts +2 -1
  274. package/dist/templates/default/.agents/skills/storing-data/SKILL.md +18 -0
  275. package/dist/templates/factory/.agents/skills/review-latest-feedback/SKILL.md +123 -33
  276. package/dist/templates/headless/.agents/skills/storing-data/SKILL.md +18 -0
  277. package/dist/templates/workspace-core/.agents/skills/storing-data/SKILL.md +18 -0
  278. package/dist/templates/workspace-core/.agents/skills/turn-into-app/SKILL.md +34 -29
  279. package/dist/templates/workspace-core/.agents/skills/turn-into-app/references/fresh-project.md +12 -5
  280. package/dist/templates/workspace-core/.agents/skills/turn-into-app/references/review-loop.md +3 -2
  281. package/dist/templates/workspace-core/.agents/skills/turn-into-app/references/where-it-runs.md +93 -0
  282. package/dist/tracking/registry.js +25 -0
  283. package/dist/triggers/actions/manage-automation.js +6 -2
  284. package/dist/triggers/actions.js +14 -2
  285. package/dist/triggers/index.d.ts +1 -0
  286. package/dist/triggers/index.js +1 -0
  287. package/dist/vite/client.js +5 -4
  288. package/docs/content/authentication.mdx +2 -0
  289. package/docs/content/components.mdx +1 -1
  290. package/docs/content/decisions.mdx +1 -1
  291. package/docs/content/recurring-jobs.mdx +15 -0
  292. package/docs/content/template-chat-developers.mdx +1 -1
  293. package/docs/content/template-chat-features.mdx +4 -4
  294. package/docs/content/turn-into-app.mdx +18 -10
  295. package/package.json +6 -4
  296. package/src/templates/builder-code-starter/app/components/layout/Layout.tsx.patch +48 -18
  297. package/src/templates/builder-code-starter/server/plugins/agent-chat.ts.patch +7 -6
  298. package/src/templates/builder-code-starter/template-layer.json +1 -0
  299. package/src/templates/chat/.agents/skills/storing-data/SKILL.md +18 -0
  300. package/src/templates/chat/app/components/chat/ChatRouteContent.tsx +18 -4
  301. package/src/templates/chat/app/components/home/HomePage.tsx +28 -69
  302. package/src/templates/chat/app/components/layout/Layout.tsx +46 -14
  303. package/src/templates/chat/app/i18n/ar-SA.ts +0 -4
  304. package/src/templates/chat/app/i18n/de-DE.ts +0 -5
  305. package/src/templates/chat/app/i18n/en-US.ts +0 -4
  306. package/src/templates/chat/app/i18n/es-ES.ts +0 -5
  307. package/src/templates/chat/app/i18n/fr-FR.ts +0 -5
  308. package/src/templates/chat/app/i18n/hi-IN.ts +0 -5
  309. package/src/templates/chat/app/i18n/ja-JP.ts +0 -5
  310. package/src/templates/chat/app/i18n/ko-KR.ts +0 -5
  311. package/src/templates/chat/app/i18n/pt-BR.ts +0 -5
  312. package/src/templates/chat/app/i18n/zh-CN.ts +0 -4
  313. package/src/templates/chat/app/i18n/zh-TW.ts +0 -4
  314. package/src/templates/chat/app/lib/chat-paths.ts +36 -13
  315. package/src/templates/chat/package.json +1 -0
  316. package/src/templates/chat/server/plugins/agent-chat.ts +2 -1
  317. package/src/templates/default/.agents/skills/storing-data/SKILL.md +18 -0
  318. package/src/templates/factory/.agents/skills/review-latest-feedback/SKILL.md +123 -33
  319. package/src/templates/headless/.agents/skills/storing-data/SKILL.md +18 -0
  320. package/src/templates/workspace-core/.agents/skills/storing-data/SKILL.md +18 -0
  321. package/src/templates/workspace-core/.agents/skills/turn-into-app/SKILL.md +34 -29
  322. package/src/templates/workspace-core/.agents/skills/turn-into-app/references/fresh-project.md +12 -5
  323. package/src/templates/workspace-core/.agents/skills/turn-into-app/references/review-loop.md +3 -2
  324. package/src/templates/workspace-core/.agents/skills/turn-into-app/references/where-it-runs.md +93 -0
  325. package/dist/automations/mcp-origin.d.ts +0 -2
  326. package/dist/automations/mcp-origin.js +0 -10
  327. /package/dist/agent/{run-store.fencing.worker.d.ts → run-store.fencing.native-harness.fixture.test.support.d.ts} +0 -0
@@ -1,14 +1,16 @@
1
- import { createError, getRequestHeader, getRequestIP, getRequestURL, } from "h3";
1
+ import { createError, getRequestHeader, getRequestHeaders, getRequestIP, getRequestURL, } from "h3";
2
2
  function isLoopbackAddress(address) {
3
3
  return Boolean(address === "::1" ||
4
4
  address?.startsWith("127.") ||
5
5
  address?.startsWith("::ffff:127."));
6
6
  }
7
7
  export function getForwardedRequestOrigin(event) {
8
- const requestUrl = getRequestURL(event);
8
+ const headers = getRequestHeaders(event);
9
+ return forwardedRequestOrigin(getRequestURL(event), headers["x-forwarded-host"], headers["x-forwarded-proto"], getRequestIP(event));
10
+ }
11
+ function forwardedRequestOrigin(requestUrl, rawHost, rawProto, remoteAddress) {
9
12
  // Nitro does not pass Srvx's peer-checked proxy trust through to H3 events.
10
- if (isLoopbackAddress(getRequestIP(event))) {
11
- const rawHost = getRequestHeader(event, "x-forwarded-host");
13
+ if (isLoopbackAddress(remoteAddress)) {
12
14
  const headerHost = rawHost?.split(",")[0]?.trim();
13
15
  if (rawHost !== undefined && !headerHost) {
14
16
  throw createError({
@@ -16,7 +18,6 @@ export function getForwardedRequestOrigin(event) {
16
18
  statusMessage: "Invalid forwarded request origin",
17
19
  });
18
20
  }
19
- const rawProto = getRequestHeader(event, "x-forwarded-proto");
20
21
  const defaultProto = process.env.NODE_ENV === "production"
21
22
  ? "https"
22
23
  : requestUrl.protocol.slice(0, -1);
@@ -69,51 +70,48 @@ export function getForwardedRequestHostname(event) {
69
70
  .toLowerCase()
70
71
  .replace(/\.$/, "");
71
72
  }
72
- export function getForwardedRequestHostnameFromHeaders(headers, remoteAddress) {
73
- const forwardedHost = isLoopbackAddress(remoteAddress)
74
- ? headers instanceof Headers
75
- ? headers.get("x-forwarded-host")
76
- : headers["x-forwarded-host"]
77
- : undefined;
78
- const rawHost = forwardedHost ??
79
- (headers instanceof Headers ? headers.get("host") : headers.host);
80
- const firstHost = Array.isArray(rawHost)
81
- ? rawHost[0]?.split(",")[0]?.trim()
82
- : rawHost?.split(",")[0]?.trim();
83
- if (!firstHost)
84
- throw new Error("Missing forwarded request hostname");
85
- const origin = new URL(`https://${firstHost}`);
73
+ export function getForwardedRequestOriginFromHeaders(headers, remoteAddress, protocol = "http:") {
74
+ const header = (name) => {
75
+ const value = headers instanceof Headers ? headers.get(name) : headers[name];
76
+ return Array.isArray(value) ? value.join(",") : (value ?? undefined);
77
+ };
78
+ const host = header("host");
79
+ if (!host)
80
+ throw new Error("Missing request host");
81
+ const origin = new URL(`${protocol}//${host}`);
86
82
  if (origin.username ||
87
83
  origin.password ||
88
84
  origin.pathname !== "/" ||
89
85
  origin.search ||
90
86
  origin.hash) {
91
- throw new Error("Invalid forwarded request hostname");
87
+ throw new Error("Invalid request host");
92
88
  }
93
- return origin.hostname.toLowerCase().replace(/\.$/, "");
89
+ return forwardedRequestOrigin(origin, header("x-forwarded-host"), header("x-forwarded-proto"), remoteAddress);
94
90
  }
95
91
  function isLoopbackHost(host) {
96
92
  return host.startsWith("localhost:") || host.startsWith("127.0.0.1:");
97
93
  }
98
- /**
99
- * Stricter than `isSameOriginRequest`, for a POST that writes cookies: a
100
- * request with neither header, a navigation, or a desktop shell's origin
101
- * can't prove it came from this site's pages.
102
- */
103
- export function isSameOriginPost(event) {
94
+ /** Positive origin evidence must be paired with browser-cookie identity for UI proof. */
95
+ export function hasSameOriginBrowserEvidence(event) {
104
96
  const fetchSite = getRequestHeader(event, "sec-fetch-site");
105
97
  if (fetchSite)
106
98
  return fetchSite === "same-origin";
107
99
  const origin = getRequestHeader(event, "origin");
108
100
  return !!origin && origin === getForwardedRequestOrigin(event);
109
101
  }
102
+ /** A cookie-writing POST requires positive origin evidence. */
103
+ export function isSameOriginPost(event) {
104
+ return hasSameOriginBrowserEvidence(event);
105
+ }
110
106
  export function isSameOriginRequest(event) {
111
107
  const fetchSite = getRequestHeader(event, "sec-fetch-site");
112
108
  if (fetchSite)
113
109
  return fetchSite === "same-origin" || fetchSite === "none";
114
110
  const host = getRequestHeader(event, "host");
115
111
  const origin = getRequestHeader(event, "origin");
116
- if (origin && host) {
112
+ if (origin) {
113
+ if (!host)
114
+ return false;
117
115
  try {
118
116
  const parsed = new URL(origin);
119
117
  const forwardedProto = getRequestHeader(event, "x-forwarded-proto");
@@ -0,0 +1,22 @@
1
+ import { type H3Event } from "h3";
2
+ export declare const SESSION_UNAVAILABLE_ERROR_CODE = "session_unavailable";
3
+ export declare const SESSION_UNAVAILABLE_MESSAGE = "Your session could not be verified. Retry shortly.";
4
+ /**
5
+ * Records that this request presented a session credential the server could
6
+ * not check (the lookup threw). Such a request has no session, but it is not
7
+ * signed out: answer a retryable 503, never a 401 that reads as "sign in
8
+ * again". The first failure is kept; later ones are usually its echo.
9
+ */
10
+ export declare function markSessionResolutionUnavailable(event: H3Event, source: string, error: unknown): void;
11
+ export declare function isSessionResolutionUnavailable(event: H3Event): boolean;
12
+ /**
13
+ * Sends the lookup's real cause to the error tracker and the server log with
14
+ * the request id the client also holds, once per request. Called where a null
15
+ * session is handed to a consumer, so a lookup that a fallback path recovered
16
+ * from is not reported.
17
+ */
18
+ export declare function reportSessionResolutionUnavailable(event: H3Event): void;
19
+ export declare function sessionResolutionUnavailableError(): import("h3").HTTPError<unknown> & {
20
+ errorCode: string;
21
+ expected: boolean;
22
+ };
@@ -0,0 +1,65 @@
1
+ import { createError } from "h3";
2
+ import { redact, redactErrorStack } from "../tracking/redaction.js";
3
+ import { captureError } from "./capture-error.js";
4
+ import { getHttpRequestTelemetryId } from "./http-response-telemetry.js";
5
+ // Also read by templates that answer their own 503, so the key stays stable.
6
+ const CONTEXT_KEY = "__anSessionResolutionError";
7
+ export const SESSION_UNAVAILABLE_ERROR_CODE = "session_unavailable";
8
+ export const SESSION_UNAVAILABLE_MESSAGE = "Your session could not be verified. Retry shortly.";
9
+ function contextOf(event) {
10
+ const holder = event;
11
+ return (holder.context ??= {});
12
+ }
13
+ /**
14
+ * Records that this request presented a session credential the server could
15
+ * not check (the lookup threw). Such a request has no session, but it is not
16
+ * signed out: answer a retryable 503, never a 401 that reads as "sign in
17
+ * again". The first failure is kept; later ones are usually its echo.
18
+ */
19
+ export function markSessionResolutionUnavailable(event, source, error) {
20
+ const context = contextOf(event);
21
+ if (context[CONTEXT_KEY])
22
+ return;
23
+ context[CONTEXT_KEY] = {
24
+ source,
25
+ error,
26
+ reported: false,
27
+ };
28
+ }
29
+ export function isSessionResolutionUnavailable(event) {
30
+ return Boolean(event.context?.[CONTEXT_KEY]);
31
+ }
32
+ /**
33
+ * Sends the lookup's real cause to the error tracker and the server log with
34
+ * the request id the client also holds, once per request. Called where a null
35
+ * session is handed to a consumer, so a lookup that a fallback path recovered
36
+ * from is not reported.
37
+ */
38
+ export function reportSessionResolutionUnavailable(event) {
39
+ const failure = event.context?.[CONTEXT_KEY];
40
+ if (!failure || failure === true || failure.reported)
41
+ return;
42
+ failure.reported = true;
43
+ const requestId = getHttpRequestTelemetryId(event);
44
+ const captureId = captureError(failure.error, {
45
+ route: "auth.session-resolution",
46
+ tags: { auth: "session-resolution", source: failure.source },
47
+ ...(requestId ? { extra: { request_id: requestId } } : {}),
48
+ });
49
+ console.error("[auth] session unavailable, request refused with 503:", {
50
+ source: failure.source,
51
+ ...(requestId ? { requestId } : {}),
52
+ ...(captureId ? { captureId } : {}),
53
+ error: redactErrorStack(failure.error) ?? redact(String(failure.error)),
54
+ });
55
+ }
56
+ export function sessionResolutionUnavailableError() {
57
+ // `expected` + `errorCode` make the action route return this as a typed
58
+ // answer instead of folding every 5xx into "Internal server error".
59
+ return Object.assign(createError({
60
+ statusCode: 503,
61
+ statusMessage: "Service Unavailable",
62
+ message: SESSION_UNAVAILABLE_MESSAGE,
63
+ headers: { "Retry-After": "5" },
64
+ }), { errorCode: SESSION_UNAVAILABLE_ERROR_CODE, expected: true });
65
+ }
@@ -9,6 +9,14 @@ export interface ShortLivedTokenClaims {
9
9
  agentLabel?: string;
10
10
  ttlSeconds?: number;
11
11
  }
12
+ export interface ShortLivedTokenKeyOptions {
13
+ /**
14
+ * Sign or verify with this key alone, never the app's server secret, so a
15
+ * token minted under another key (one derived from `A2A_SECRET`, say)
16
+ * cannot pass. An empty key throws rather than fall back.
17
+ */
18
+ signingKey?: string;
19
+ }
12
20
  export type VerifyResult = {
13
21
  ok: true;
14
22
  viewerEmail?: string;
@@ -17,7 +25,7 @@ export type VerifyResult = {
17
25
  ok: false;
18
26
  reason: string;
19
27
  };
20
- export declare function signShortLivedToken(claims: ShortLivedTokenClaims): string;
28
+ export declare function signShortLivedToken(claims: ShortLivedTokenClaims, options?: ShortLivedTokenKeyOptions): string;
21
29
  /**
22
30
  * Verify a token previously produced by {@link signShortLivedToken}.
23
31
  *
@@ -30,7 +38,7 @@ export declare function signShortLivedToken(claims: ShortLivedTokenClaims): stri
30
38
  * Otherwise returns `{ ok: false, reason: <error string> }`. Callers should
31
39
  * not surface the reason to viewers (it's useful for server-side logs only).
32
40
  */
33
- export declare function verifyShortLivedToken(token: string, expectedResourceId: string): VerifyResult;
41
+ export declare function verifyShortLivedToken(token: string, expectedResourceId: string, options?: ShortLivedTokenKeyOptions): VerifyResult;
34
42
  export declare function signCompactShortLivedToken(claims: ShortLivedTokenClaims): string;
35
43
  /**
36
44
  * Verify a token produced by {@link signCompactShortLivedToken}. A token for a
@@ -18,6 +18,14 @@ function getSigningKey() {
18
18
  }
19
19
  return _devSigningKey;
20
20
  }
21
+ function keyFor(options) {
22
+ if (options?.signingKey === undefined)
23
+ return getSigningKey();
24
+ if (!options.signingKey) {
25
+ throw new Error("An explicit short-lived token signing key is empty.");
26
+ }
27
+ return options.signingKey;
28
+ }
21
29
  function base64UrlEncode(buf) {
22
30
  const b = typeof buf === "string" ? Buffer.from(buf, "utf8") : buf;
23
31
  return b
@@ -30,7 +38,7 @@ function base64UrlDecode(s) {
30
38
  const padded = s + "=".repeat((4 - (s.length % 4)) % 4);
31
39
  return Buffer.from(padded.replace(/-/g, "+").replace(/_/g, "/"), "base64");
32
40
  }
33
- export function signShortLivedToken(claims) {
41
+ export function signShortLivedToken(claims, options) {
34
42
  const ttl = claims.ttlSeconds ?? DEFAULT_TTL_SECONDS;
35
43
  const payload = {
36
44
  resourceId: claims.resourceId,
@@ -41,7 +49,7 @@ export function signShortLivedToken(claims) {
41
49
  if (claims.agentLabel)
42
50
  payload.agentLabel = claims.agentLabel;
43
51
  const payloadStr = base64UrlEncode(JSON.stringify(payload));
44
- const sig = base64UrlEncode(crypto.createHmac("sha256", getSigningKey()).update(payloadStr).digest());
52
+ const sig = base64UrlEncode(crypto.createHmac("sha256", keyFor(options)).update(payloadStr).digest());
45
53
  return `${payloadStr}.${sig}`;
46
54
  }
47
55
  /**
@@ -56,14 +64,14 @@ export function signShortLivedToken(claims) {
56
64
  * Otherwise returns `{ ok: false, reason: <error string> }`. Callers should
57
65
  * not surface the reason to viewers (it's useful for server-side logs only).
58
66
  */
59
- export function verifyShortLivedToken(token, expectedResourceId) {
67
+ export function verifyShortLivedToken(token, expectedResourceId, options) {
60
68
  if (typeof token !== "string" || !token.includes(".")) {
61
69
  return { ok: false, reason: "malformed" };
62
70
  }
63
71
  const [payloadStr, sig] = token.split(".", 2);
64
72
  if (!payloadStr || !sig)
65
73
  return { ok: false, reason: "malformed" };
66
- const expected = base64UrlEncode(crypto.createHmac("sha256", getSigningKey()).update(payloadStr).digest());
74
+ const expected = base64UrlEncode(crypto.createHmac("sha256", keyFor(options)).update(payloadStr).digest());
67
75
  const sigBuf = Buffer.from(sig, "utf8");
68
76
  const expBuf = Buffer.from(expected, "utf8");
69
77
  if (sigBuf.length !== expBuf.length) {
@@ -1,9 +1,11 @@
1
- import { defineEventHandler, getCookie, getMethod, setCookie, setResponseHeader, setResponseStatus, } from "h3";
1
+ import { defineEventHandler, getCookie, getHeader, getMethod, setCookie, setResponseHeader, setResponseStatus, } from "h3";
2
2
  import { getConfiguredAppBasePath, normalizeAppBasePath, } from "./app-base-path.js";
3
- import { getSession } from "./auth.js";
3
+ import { getBrowserCookieSession, getBrowserSessionConfigurationError, } from "./auth.js";
4
+ import { hasEmbedSessionRequestMarker } from "./embed-session.js";
4
5
  import { getH3App } from "./framework-request-handler.js";
5
6
  import { publicFrameworkPath } from "./framework-route-prefix.js";
6
7
  import { isHttpsRequest } from "./https-request.js";
8
+ import { hasSameOriginBrowserEvidence } from "./request-origin.js";
7
9
  import { signShortLivedToken, verifyShortLivedToken, } from "./short-lived-token.js";
8
10
  export const UI_ACTION_CAPABILITY_COOKIE = "agent-native-ui-capability";
9
11
  export const UI_ACTION_CAPABILITY_PATH = "/ui-capability";
@@ -31,11 +33,23 @@ export function hasUiActionCapability(event, ownerEmail) {
31
33
  }
32
34
  }
33
35
  async function issueUiActionCapability(event, appBasePath) {
34
- const session = await getSession(event);
36
+ if (hasEmbedSessionRequestMarker(event)) {
37
+ setResponseStatus(event, 403);
38
+ return { error: "Browser cookie session required" };
39
+ }
40
+ const session = getHeader(event, "authorization")
41
+ ? null
42
+ : await getBrowserCookieSession(event);
35
43
  const ownerEmail = normalizedEmail(session?.email);
36
44
  if (!ownerEmail) {
37
45
  setResponseStatus(event, 401);
38
- return { error: "Authentication required" };
46
+ return {
47
+ error: getBrowserSessionConfigurationError() ?? "Authentication required",
48
+ };
49
+ }
50
+ if (!hasSameOriginBrowserEvidence(event)) {
51
+ setResponseStatus(event, 403);
52
+ return { error: "Same-origin request required" };
39
53
  }
40
54
  const token = signShortLivedToken({
41
55
  resourceId: UI_ACTION_CAPABILITY_RESOURCE,
@@ -0,0 +1,13 @@
1
+ export declare const FIRST_RUN_BUILDER_CREDITS_V2_EXPERIMENT_ID = "first_run_builder_credits_v2";
2
+ export declare const FIRST_RUN_BUILDER_CREDITS_V2_FLAG_KEY = "clips-first-run-credits-v2";
3
+ export declare const FIRST_RUN_BUILDER_CREDITS_V2_VARIANTS: readonly ["control", "credits"];
4
+ export type FirstRunBuilderCreditsV2Variant = (typeof FIRST_RUN_BUILDER_CREDITS_V2_VARIANTS)[number];
5
+ export interface FirstRunBuilderCreditsV2Assignment {
6
+ experiment_id: typeof FIRST_RUN_BUILDER_CREDITS_V2_EXPERIMENT_ID;
7
+ experiment_variant: FirstRunBuilderCreditsV2Variant;
8
+ }
9
+ export interface FirstRunBuilderCreditsV2RequestAssignment extends FirstRunBuilderCreditsV2Assignment {
10
+ authUserId: string;
11
+ }
12
+ /** A stable, account-scoped arm that is the same in the browser and on server events. */
13
+ export declare function assignFirstRunBuilderCreditsV2(authUserId: string | null | undefined): FirstRunBuilderCreditsV2Assignment | null;
@@ -0,0 +1,22 @@
1
+ export const FIRST_RUN_BUILDER_CREDITS_V2_EXPERIMENT_ID = "first_run_builder_credits_v2";
2
+ export const FIRST_RUN_BUILDER_CREDITS_V2_FLAG_KEY = "clips-first-run-credits-v2";
3
+ export const FIRST_RUN_BUILDER_CREDITS_V2_VARIANTS = [
4
+ "control",
5
+ "credits",
6
+ ];
7
+ /** A stable, account-scoped arm that is the same in the browser and on server events. */
8
+ export function assignFirstRunBuilderCreditsV2(authUserId) {
9
+ const userId = authUserId?.trim();
10
+ if (!userId)
11
+ return null;
12
+ const input = `${FIRST_RUN_BUILDER_CREDITS_V2_EXPERIMENT_ID}:${userId}`;
13
+ let hash = 0x811c9dc5;
14
+ for (let index = 0; index < input.length; index += 1) {
15
+ hash ^= input.charCodeAt(index);
16
+ hash = Math.imul(hash, 0x01000193);
17
+ }
18
+ return {
19
+ experiment_id: FIRST_RUN_BUILDER_CREDITS_V2_EXPERIMENT_ID,
20
+ experiment_variant: (hash >>> 0) % 2 === 0 ? "control" : "credits",
21
+ };
22
+ }
@@ -14,6 +14,7 @@ export { MAX_USER_REGEX_INPUT_LENGTH, MAX_USER_REGEX_LENGTH, analyzeRegexSource,
14
14
  export { isHumanReadableDocumentTitle, normalizeDocumentTitle, } from "./document-title.js";
15
15
  export { parseBase64DataUrl, parseDataUrl, type ParsedBase64DataUrl, type ParsedDataUrl, } from "./data-url.js";
16
16
  export { stripInlineAttachmentPayloads } from "./attachments.js";
17
+ export { assignFirstRunBuilderCreditsV2, FIRST_RUN_BUILDER_CREDITS_V2_EXPERIMENT_ID, FIRST_RUN_BUILDER_CREDITS_V2_FLAG_KEY, FIRST_RUN_BUILDER_CREDITS_V2_VARIANTS, type FirstRunBuilderCreditsV2Assignment, type FirstRunBuilderCreditsV2RequestAssignment, type FirstRunBuilderCreditsV2Variant, } from "./first-run-builder-credits-experiment.js";
17
18
  export { stripInlineBytes, type InlineBytesPolicy } from "./inline-bytes.js";
18
19
  export { DEFAULT_REASONING_EFFORT, REASONING_EFFORTS, getReasoningEffortOptionsForModel, isReasoningEffort, isUnsetReasoningEffort, reasoningEffortLabel, resolveReasoningEffortSelection, type ReasoningEffort, } from "./reasoning-effort.js";
19
20
  export { injectDocumentMarkup } from "./html-document.js";
@@ -14,6 +14,7 @@ export { MAX_USER_REGEX_INPUT_LENGTH, MAX_USER_REGEX_LENGTH, analyzeRegexSource,
14
14
  export { isHumanReadableDocumentTitle, normalizeDocumentTitle, } from "./document-title.js";
15
15
  export { parseBase64DataUrl, parseDataUrl, } from "./data-url.js";
16
16
  export { stripInlineAttachmentPayloads } from "./attachments.js";
17
+ export { assignFirstRunBuilderCreditsV2, FIRST_RUN_BUILDER_CREDITS_V2_EXPERIMENT_ID, FIRST_RUN_BUILDER_CREDITS_V2_FLAG_KEY, FIRST_RUN_BUILDER_CREDITS_V2_VARIANTS, } from "./first-run-builder-credits-experiment.js";
17
18
  export { stripInlineBytes } from "./inline-bytes.js";
18
19
  export { DEFAULT_REASONING_EFFORT, REASONING_EFFORTS, getReasoningEffortOptionsForModel, isReasoningEffort, isUnsetReasoningEffort, reasoningEffortLabel, resolveReasoningEffortSelection, } from "./reasoning-effort.js";
19
20
  export { injectDocumentMarkup } from "./html-document.js";
@@ -0,0 +1,19 @@
1
+ /**
2
+ * Where an app shows its own MCP approval review page: on its home page, with
3
+ * the grant id in this key of the URL fragment. The toolkit's `AppProviders`
4
+ * renders the page there. The id is a lookup handle, not a credential: the
5
+ * page reads and decides through the framework route, which checks the
6
+ * browser session.
7
+ */
8
+ export declare const MCP_APPROVAL_HASH_PARAM = "mcpApproval";
9
+ /** A grant id is a UUID, so it never needs percent-encoding. */
10
+ export declare function isMcpApprovalId(value: unknown): value is string;
11
+ /** The grant id a page's URL fragment names, if it names a well-formed one. */
12
+ export declare function readMcpApprovalId(hash: string): string | undefined;
13
+ /**
14
+ * The app page that reviews one grant. The id rides in the fragment, not the
15
+ * query: an app's home route often redirects (to `/inbox`, `/plans`), and a
16
+ * browser carries the fragment through an HTTP redirect, where a server
17
+ * redirect can drop the query.
18
+ */
19
+ export declare function mcpApprovalAppPagePath(id: string, homePath: string, basePath?: string): string;
@@ -0,0 +1,29 @@
1
+ /**
2
+ * Where an app shows its own MCP approval review page: on its home page, with
3
+ * the grant id in this key of the URL fragment. The toolkit's `AppProviders`
4
+ * renders the page there. The id is a lookup handle, not a credential: the
5
+ * page reads and decides through the framework route, which checks the
6
+ * browser session.
7
+ */
8
+ export const MCP_APPROVAL_HASH_PARAM = "mcpApproval";
9
+ // The auth guard admits the review route only for `:id(uuidv4)`, a lowercase
10
+ // UUID v4; accept nothing wider, or a link would reach the sign-in wall.
11
+ const GRANT_ID = /^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/;
12
+ /** A grant id is a UUID, so it never needs percent-encoding. */
13
+ export function isMcpApprovalId(value) {
14
+ return typeof value === "string" && GRANT_ID.test(value);
15
+ }
16
+ /** The grant id a page's URL fragment names, if it names a well-formed one. */
17
+ export function readMcpApprovalId(hash) {
18
+ const id = new URLSearchParams(hash.replace(/^#/, "")).get(MCP_APPROVAL_HASH_PARAM);
19
+ return isMcpApprovalId(id) ? id : undefined;
20
+ }
21
+ /**
22
+ * The app page that reviews one grant. The id rides in the fragment, not the
23
+ * query: an app's home route often redirects (to `/inbox`, `/plans`), and a
24
+ * browser carries the fragment through an HTTP redirect, where a server
25
+ * redirect can drop the query.
26
+ */
27
+ export function mcpApprovalAppPagePath(id, homePath, basePath = "") {
28
+ return `${basePath}${homePath}#${MCP_APPROVAL_HASH_PARAM}=${id}`;
29
+ }
@@ -16,6 +16,10 @@ export declare function resolveReasoningEffortSelection(model: string | undefine
16
16
  export declare function stepDownReasoningEffort(effort: ReasoningEffort | undefined): ReasoningEffort | undefined;
17
17
  export declare function isGPTReasoningModel(model: string): boolean;
18
18
  export declare function supportsClaudeAdaptiveThinking(model: string | undefined): boolean;
19
+ export declare function claudeAdaptiveThinking(model: string): {
20
+ type: "adaptive";
21
+ display?: "summarized";
22
+ };
19
23
  export declare function anthropicManualThinkingBudget(effort: ReasoningEffort): 1024 | 4096 | 8000 | 16000 | 32000;
20
24
  export declare function allowsSamplingParams(args: {
21
25
  model: string | undefined;
@@ -141,6 +141,26 @@ export function supportsClaudeAdaptiveThinking(model) {
141
141
  return true;
142
142
  return claudeOpusAtLeast(id, 4, 6);
143
143
  }
144
+ /**
145
+ * Opus 4.7 and later default adaptive thinking to `display: "omitted"`, which
146
+ * streams thinking blocks with no text, so the chat has no reasoning to show.
147
+ * Older models reject the field and already summarize.
148
+ */
149
+ function claudeDefaultsThinkingToOmitted(model) {
150
+ const id = model.toLowerCase().replace(/^anthropic\//, "");
151
+ if (id.includes("fable-5") || id.includes("mythos-5"))
152
+ return true;
153
+ if (id.includes("haiku-5-5") || id.includes("haiku-5.5"))
154
+ return true;
155
+ if (id.includes("sonnet-5"))
156
+ return true;
157
+ return claudeOpusAtLeast(id, 4, 7);
158
+ }
159
+ export function claudeAdaptiveThinking(model) {
160
+ return claudeDefaultsThinkingToOmitted(model)
161
+ ? { type: "adaptive", display: "summarized" }
162
+ : { type: "adaptive" };
163
+ }
144
164
  export function anthropicManualThinkingBudget(effort) {
145
165
  switch (effort) {
146
166
  case "low":
@@ -61,10 +61,19 @@ export declare function resolveAccess(resourceType: string, resourceId: string,
61
61
  * to a Builder project), the host is the authority on who may open them. The
62
62
  * resolver returns a role, `null` to deny, or `undefined` to fall through to
63
63
  * AN's own owner/org/share rules. AN keeps no copy of the host's members,
64
- * orgs or roles: it asks, per resource, per request.
64
+ * orgs or roles: it asks, per resource, per request. It is asked only about
65
+ * signed-in requests unless registered with `includeSignedOut`.
65
66
  */
66
67
  export type HostAccessResolver = (resource: any, ctx: AccessContext) => Promise<ResolvedAccess["role"] | null | undefined>;
67
- export declare function registerHostAccessResolver(resourceType: string, resolver: HostAccessResolver | null): void;
68
+ export interface HostAccessResolverOptions {
69
+ /**
70
+ * Also ask about signed-out requests, with `ctx.userEmail` unset. Only a
71
+ * resolver written to vouch for someone with no identity may set this: any
72
+ * role it returns then goes to an anonymous request.
73
+ */
74
+ includeSignedOut?: boolean;
75
+ }
76
+ export declare function registerHostAccessResolver(resourceType: string, resolver: HostAccessResolver | null, options?: HostAccessResolverOptions): void;
68
77
  /**
69
78
  * What a link to a shareable resource can honestly say to the person who
70
79
  * opened it.
@@ -448,11 +448,16 @@ async function loadAndResolveAccess(resourceType, resourceId, rawCtx, options) {
448
448
  };
449
449
  }
450
450
  const hostAccessResolvers = new Map();
451
- export function registerHostAccessResolver(resourceType, resolver) {
452
- if (resolver)
453
- hostAccessResolvers.set(resourceType, resolver);
454
- else
451
+ export function registerHostAccessResolver(resourceType, resolver, options) {
452
+ if (resolver) {
453
+ hostAccessResolvers.set(resourceType, {
454
+ resolve: resolver,
455
+ includeSignedOut: options?.includeSignedOut === true,
456
+ });
457
+ }
458
+ else {
455
459
  hostAccessResolvers.delete(resourceType);
460
+ }
456
461
  }
457
462
  async function ownerOrAdminRole(reg, resource, ctx, normalizedUserEmail) {
458
463
  if (normalizedUserEmail &&
@@ -481,9 +486,9 @@ async function accessToResource(reg, resourceId, resource, ctx) {
481
486
  };
482
487
  // A host can deny outright. When it grants access, the resource's owner
483
488
  // and admins keep their own roles; the host's role covers everyone else.
484
- const hostResolver = hostAccessResolvers.get(reg.type);
485
- const hosted = hostResolver && normalizedUserEmail
486
- ? await hostResolver(resource, ctx)
489
+ const host = hostAccessResolvers.get(reg.type);
490
+ const hosted = host && (normalizedUserEmail || host.includeSignedOut)
491
+ ? await host.resolve(resource, ctx)
487
492
  : undefined;
488
493
  if (hosted === null)
489
494
  return null;
@@ -1,10 +1,4 @@
1
- /**
2
- * Typed lifecycle state machines for states persisted in SQL.
3
- *
4
- * A machine is plain data. `defineMachine` validates it once at module load,
5
- * then the same definition answers runtime checks, `WHERE status IN (...)`
6
- * clauses, and shortest-path fixtures for tests.
7
- */
1
+ import { type SqlFragment } from "../db/sql.js";
8
2
  export declare class StateMachineError extends Error {
9
3
  readonly code: "unknown_state" | "invalid_transition" | "invalid_definition";
10
4
  readonly machineId: string;
@@ -25,6 +19,9 @@ export interface Machine<S extends string, E extends string> {
25
19
  isTerminal(state: S): boolean;
26
20
  shortestPaths(): ReadonlyMap<S, readonly E[]>;
27
21
  }
22
+ export interface SqlMachine<S extends string, E extends string> extends Machine<S, E> {
23
+ sqlIn(event: E): SqlFragment;
24
+ }
28
25
  export declare function defineMachine<const S extends string, const E extends string>(def: {
29
26
  id: string;
30
27
  states: readonly S[];
@@ -36,5 +33,5 @@ export declare function defineMachine<const S extends string, const E extends st
36
33
  readonly to: NoInfer<S>;
37
34
  };
38
35
  };
39
- }): Machine<S, E>;
36
+ }): SqlMachine<S, E>;
40
37
  export { renderMachineTrace } from "./trace.js";
@@ -1,9 +1,10 @@
1
+ import { sql } from "../db/sql.js";
1
2
  /**
2
3
  * Typed lifecycle state machines for states persisted in SQL.
3
4
  *
4
5
  * A machine is plain data. `defineMachine` validates it once at module load,
5
- * then the same definition answers runtime checks, `WHERE status IN (...)`
6
- * clauses, and shortest-path fixtures for tests.
6
+ * then the same definition answers runtime checks, SQL state predicates, and
7
+ * shortest-path fixtures for tests.
7
8
  */
8
9
  const STATE_NAME = /^[a-z][a-z0-9_-]*$/;
9
10
  export class StateMachineError extends Error {
@@ -155,6 +156,9 @@ export function defineMachine(def) {
155
156
  .fromStates.map((state) => `'${state}'`)
156
157
  .join(", ");
157
158
  },
159
+ sqlIn(event) {
160
+ return sql.in(ruleFor(event).fromStates);
161
+ },
158
162
  isTerminal(state) {
159
163
  return terminal.has(parseState(state));
160
164
  },