@xopcai/xopc 0.0.369 → 0.0.371

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 (418) hide show
  1. package/README.md +59 -174
  2. package/README.zh-CN.md +59 -174
  3. package/dist/.pnpm/@noble_hashes@1.8.0/node_modules/@noble/hashes/esm/_md.js +131 -0
  4. package/dist/.pnpm/@noble_hashes@1.8.0/node_modules/@noble/hashes/esm/_u64.js +30 -0
  5. package/dist/.pnpm/@noble_hashes@1.8.0/node_modules/@noble/hashes/esm/sha2.js +252 -0
  6. package/dist/.pnpm/@noble_hashes@1.8.0/node_modules/@noble/hashes/esm/sha256.js +16 -0
  7. package/dist/.pnpm/@noble_hashes@1.8.0/node_modules/@noble/hashes/esm/utils.js +66 -0
  8. package/dist/browser-ext/dist/sidepanel.js +21 -1
  9. package/dist/browser-ext/manifest.json +1 -1
  10. package/dist/extensions/telegram/xopc.extension.json +1 -1
  11. package/dist/gateway/static/root/assets/{agent-avatar-dicebear-Stj17S9u.js → agent-avatar-dicebear-C8MqXy6W.js} +1 -1
  12. package/dist/gateway/static/root/assets/agent-defaults-settings-panel-BLaL4law.js +1 -0
  13. package/dist/gateway/static/root/assets/agent-plugin-dialog-BrysdA6F.js +1 -0
  14. package/dist/gateway/static/root/assets/agents-BJRyMNx2.js +66 -0
  15. package/dist/gateway/static/root/assets/{app-management-settings-panel-pJFe6M6c.js → app-management-settings-panel-Bi02swpZ.js} +1 -1
  16. package/dist/gateway/static/root/assets/{appearance-settings-BrxSpBWa.js → appearance-settings-rr0qirDm.js} +1 -1
  17. package/dist/gateway/static/root/assets/{apps-page-DegSl5Lh.js → apps-page-Sz3wl3lV.js} +1 -1
  18. package/dist/gateway/static/root/assets/{automations-page-BZQ_VHjp.js → automations-page-DqdbP0hD.js} +1 -1
  19. package/dist/gateway/static/root/assets/automations-workspace-CxgKlA5d.js +6 -0
  20. package/dist/gateway/static/root/assets/{block-editor-3XjFv3kK.js → block-editor-CfVR1zGa.js} +3 -3
  21. package/dist/gateway/static/root/assets/browser-automations-page-DeYnh3mY.js +3 -0
  22. package/dist/gateway/static/root/assets/{browser-settings-page-ch2_bQF0.js → browser-settings-page-DDZvlGCD.js} +2 -2
  23. package/dist/gateway/static/root/assets/{capabilities-DO-vfNKI.js → capabilities-CY4SiHcP.js} +1 -1
  24. package/dist/gateway/static/root/assets/{capabilities-B48r0DDa.js → capabilities-gjQtMhKu.js} +1 -1
  25. package/dist/gateway/static/root/assets/capabilities-page-Bl6PZqx3.js +2 -0
  26. package/dist/gateway/static/root/assets/{capabilities-settings-panel-NckMsJ5N.js → capabilities-settings-panel-B-MM4LJA.js} +4 -4
  27. package/dist/gateway/static/root/assets/{capability-header-actions-CY8KCO9j.js → capability-header-actions-CAiY7HK1.js} +1 -1
  28. package/dist/gateway/static/root/assets/{channels-CHOS2CGa.js → channels-D1_fDkhu.js} +1 -1
  29. package/dist/gateway/static/root/assets/{chat-terminal-dock-Bwknnb4c.js → chat-terminal-dock-D6slpF2a.js} +2 -2
  30. package/dist/gateway/static/root/assets/{computer-settings-page-B2xeFCSt.js → computer-settings-page-D1n_uQHN.js} +1 -1
  31. package/dist/gateway/static/root/assets/{connector-service-page-C83DnAqK.js → connector-service-page-FvSCyJzn.js} +1 -1
  32. package/dist/gateway/static/root/assets/connectors-page-DroD-gQn.js +1 -0
  33. package/dist/gateway/static/root/assets/copy-text-row-C1gaJwlZ.js +1 -0
  34. package/dist/gateway/static/root/assets/{date-picker-Bq9GR-DU.js → date-picker-Bl-HqvGU.js} +1 -1
  35. package/dist/gateway/static/root/assets/dependency-picker-DY4nU-HL.js +1 -0
  36. package/dist/gateway/static/root/assets/{desktop-pet-BwsbQw8V.js → desktop-pet-_A89B2xw.js} +1 -1
  37. package/dist/gateway/static/root/assets/{desktop-pet-settings-sL9i44pP.js → desktop-pet-settings-BJWkGynu.js} +1 -1
  38. package/dist/gateway/static/root/assets/device-pairing-wizard-DJ_ITvkI.js +1 -0
  39. package/dist/gateway/static/root/assets/{directory-picker-path-field-BFlDmsS5.js → directory-picker-path-field-Bj2Cpmxs.js} +1 -1
  40. package/dist/gateway/static/root/assets/{extension-debug-page-7Z1Tp7-w.js → extension-debug-page-BfAtjhoK.js} +1 -1
  41. package/dist/gateway/static/root/assets/{extension-page-uGqvb8QX.js → extension-page-BFjc1zDp.js} +1 -1
  42. package/dist/gateway/static/root/assets/{extension-provider-xlSyz4Z6.js → extension-provider-Br6LXyIj.js} +1 -1
  43. package/dist/gateway/static/root/assets/{extension-settings-page-CKHgrjOs.js → extension-settings-page-oAwllsMb.js} +1 -1
  44. package/dist/gateway/static/root/assets/{fallback-models-BwQg0G1D.js → fallback-models-KHd6tw_t.js} +1 -1
  45. package/dist/gateway/static/root/assets/gateway-realtime-F6D4A7N5.js +1 -0
  46. package/dist/gateway/static/root/assets/{gateway-settings-BAQnSEMJ.js → gateway-settings-BIyhyiOq.js} +1 -1
  47. package/dist/gateway/static/root/assets/home-page-CEjaIUTF.js +2 -0
  48. package/dist/gateway/static/root/assets/{imports-page-re1_Nh64.js → imports-page-ClFqRiGQ.js} +1 -1
  49. package/dist/gateway/static/root/assets/index-BGBkIIzM.css +1 -0
  50. package/dist/gateway/static/root/assets/index-GBFmI8im.js +106 -0
  51. package/dist/gateway/static/root/assets/{keyboard-shortcuts-settings-B_xja9LN.js → keyboard-shortcuts-settings-Ca9_GJSQ.js} +1 -1
  52. package/dist/gateway/static/root/assets/{local-app-workbench-page-CErdCrPX.js → local-app-workbench-page-BaK9zX1-.js} +1 -1
  53. package/dist/gateway/static/root/assets/{local-apps-page-BPL2RXdK.js → local-apps-page-1CjSftZ3.js} +1 -1
  54. package/dist/gateway/static/root/assets/local-session-drafts-pox8evDV.js +1 -0
  55. package/dist/gateway/static/root/assets/logs-page-6joZBbcx.js +2 -0
  56. package/dist/gateway/static/root/assets/management-settings-Cnubkklb.js +1 -0
  57. package/dist/gateway/static/root/assets/note-detail-panel-B6DHbMzT.js +5 -0
  58. package/dist/gateway/static/root/assets/notes-page-CGZkIKdi.js +8 -0
  59. package/dist/gateway/static/root/assets/{page-context-capture-button-tf77xIz3.js → page-context-capture-button-y3QmhTu2.js} +1 -1
  60. package/dist/gateway/static/root/assets/personal-page-C_roXCJB.js +1 -0
  61. package/dist/gateway/static/root/assets/{product-open-page-Dc3Y-Y7J.js → product-open-page-CSRYWt0f.js} +1 -1
  62. package/dist/gateway/static/root/assets/{product-preview-content-MG_hmVA3.js → product-preview-content-DuOML6gs.js} +1 -1
  63. package/dist/gateway/static/root/assets/project-detail-page-v7xtnvha.js +1 -0
  64. package/dist/gateway/static/root/assets/{projects-page-MllfNLGA.js → projects-page-BuJCBT6n.js} +1 -1
  65. package/dist/gateway/static/root/assets/{remote-access-hub-Bs-C70el.js → remote-access-hub-DpHnyBnG.js} +1 -1
  66. package/dist/gateway/static/root/assets/{runtime-tools-settings-panel-DpJ5jNzR.js → runtime-tools-settings-panel-DTMTL0hy.js} +1 -1
  67. package/dist/gateway/static/root/assets/{scenes-page-Dpxamkw6.js → scenes-page-B0JqO_fM.js} +2 -2
  68. package/dist/gateway/static/root/assets/{schema-form-DUeyQ1zh.js → schema-form-g4z7GH4W.js} +1 -1
  69. package/dist/gateway/static/root/assets/{send-session-input-Dgn4BRk_.js → send-session-input-BW40VHiL.js} +1 -1
  70. package/dist/gateway/static/root/assets/session-manager-BqlvrjPE.js +16 -0
  71. package/dist/gateway/static/root/assets/sessions-page-CftImbH7.js +1 -0
  72. package/dist/gateway/static/root/assets/settings-advanced-gate-BkvbSieZ.js +1 -0
  73. package/dist/gateway/static/root/assets/{settings-page-DouHuBXt.js → settings-page-YD-U8BVw.js} +1 -1
  74. package/dist/gateway/static/root/assets/setup-status-panel-q_X3kxw2.js +1 -0
  75. package/dist/gateway/static/root/assets/{share-link-dialog-DJTabLAM.js → share-link-dialog-HCHM8qnf.js} +1 -1
  76. package/dist/gateway/static/root/assets/{share-preview-page-jw7h4t_B.js → share-preview-page-Ce6FNWt1.js} +1 -1
  77. package/dist/gateway/static/root/assets/shares-settings-KHRg_-03.js +1 -0
  78. package/dist/gateway/static/root/assets/{skill-api-CfyX_0zN.js → skill-api-BpqDMkNB.js} +1 -1
  79. package/dist/gateway/static/root/assets/skills-page-Bnfn51ks.js +2 -0
  80. package/dist/gateway/static/root/assets/{system-settings-panel-DWf256TE.js → system-settings-panel-CncvC2CI.js} +1 -1
  81. package/dist/gateway/static/root/assets/{task-detail-page-DE6N1ZQe.js → task-detail-page-BVJKdnMC.js} +2 -2
  82. package/dist/gateway/static/root/assets/{tunnel-api-BBm9esrY.js → tunnel-api-g7etuoaT.js} +1 -1
  83. package/dist/gateway/static/root/assets/{usage-page-C93x89uW.js → usage-page-Dao1I-5F.js} +1 -1
  84. package/dist/gateway/static/root/assets/{use-composer-attachments-C7Gaaai1.js → use-composer-attachments-DJya1hIL.js} +1 -1
  85. package/dist/gateway/static/root/assets/use-file-preview-expanded-C5ONO7sF.js +2 -0
  86. package/dist/gateway/static/root/assets/user-model-page-jr986ucl.js +2 -0
  87. package/dist/gateway/static/root/assets/{work-discovery-overlay-Bs2MKiTv.js → work-discovery-overlay-CC3mr7tX.js} +1 -1
  88. package/dist/gateway/static/root/assets/{workflow-run-setup-panel-BR_U_snV.js → workflow-run-setup-panel-CqpXZJxs.js} +2 -2
  89. package/dist/gateway/static/root/assets/workflows-page-DOk6tBbK.js +6 -0
  90. package/dist/gateway/static/root/assets/{workspace-api-Si2o3inw.js → workspace-api-WhbMvdBE.js} +2 -2
  91. package/dist/gateway/static/root/index.html +18 -20
  92. package/dist/package.js +1 -1
  93. package/dist/packages/endpoint-tools-client/src/index.js +189 -0
  94. package/dist/packages/endpoint-tools-protocol/src/bridge.js +105 -0
  95. package/dist/packages/endpoint-tools-protocol/src/index.js +95 -2
  96. package/dist/packages/endpoint-tools-protocol/src/location.js +109 -0
  97. package/dist/packages/endpoint-tools-protocol/src/personal.js +149 -0
  98. package/dist/packages/gateway-contract/src/session-input-command.js +30 -5
  99. package/dist/src/agent/agent-manager.js +23 -27
  100. package/dist/src/agent/background-review/run-background-review.js +1 -1
  101. package/dist/src/agent/embedded/codemode-extension.d.ts +7 -0
  102. package/dist/src/agent/embedded/codemode-extension.js +232 -0
  103. package/dist/src/agent/embedded/codemode-output.d.ts +2 -0
  104. package/dist/src/agent/embedded/codemode-output.js +34 -0
  105. package/dist/src/agent/embedded/external-tool-discovery.d.ts +6 -0
  106. package/dist/src/agent/embedded/external-tool-discovery.js +60 -0
  107. package/dist/src/agent/embedded/model-runtime.js +5 -2
  108. package/dist/src/agent/embedded/run-for-session.js +10 -1
  109. package/dist/src/agent/embedded/run-turn.js +10 -3
  110. package/dist/src/agent/embedded/session-runner.d.ts +9 -1
  111. package/dist/src/agent/embedded/session-runner.js +111 -23
  112. package/dist/src/agent/embedded/session-tool-result-guard.d.ts +2 -0
  113. package/dist/src/agent/embedded/session-tool-result-guard.js +17 -0
  114. package/dist/src/agent/embedded/subscribe-session.js +14 -4
  115. package/dist/src/agent/embedded/tool-metadata.d.ts +15 -0
  116. package/dist/src/agent/embedded/tool-metadata.js +38 -0
  117. package/dist/src/agent/embedded/tool-search-extension.d.ts +5 -0
  118. package/dist/src/agent/embedded/tool-search-extension.js +31 -0
  119. package/dist/src/agent/embedded/types.d.ts +7 -0
  120. package/dist/src/agent/embedded/xopc-tools-bridge.js +6 -0
  121. package/dist/src/agent/external-tools/endpoint-provider.d.ts +1 -1
  122. package/dist/src/agent/external-tools/endpoint-provider.js +174 -53
  123. package/dist/src/agent/external-tools/extension-provider.js +8 -1
  124. package/dist/src/agent/external-tools/gateway-tools.d.ts +1 -1
  125. package/dist/src/agent/external-tools/gateway-tools.js +45 -22
  126. package/dist/src/agent/external-tools/index.js +46 -14
  127. package/dist/src/agent/external-tools/memory-provider.js +8 -1
  128. package/dist/src/agent/external-tools/read-policy.js +2 -1
  129. package/dist/src/agent/external-tools/service.d.ts +2 -0
  130. package/dist/src/agent/external-tools/service.js +25 -3
  131. package/dist/src/agent/external-tools/tool-registry.d.ts +14 -0
  132. package/dist/src/agent/external-tools/tool-registry.js +14 -0
  133. package/dist/src/agent/external-tools/types.d.ts +8 -1
  134. package/dist/src/agent/external-tools/types.js +0 -1
  135. package/dist/src/agent/inbound/attachment-pipeline.js +1 -1
  136. package/dist/src/agent/mcp/config.d.ts +18 -0
  137. package/dist/src/agent/mcp/{bundle-mcp-config.js → config.js} +8 -25
  138. package/dist/src/agent/mcp/native-mcp.d.ts +6 -0
  139. package/dist/src/agent/mcp/native-mcp.js +73 -0
  140. package/dist/src/agent/service.js +3 -6
  141. package/dist/src/agent/skills/index.js +1 -1
  142. package/dist/src/agent/skills/installer.js +1 -1
  143. package/dist/src/agent/skills/managed-store.js +1 -1
  144. package/dist/src/agent/skills/skill-manage-ops.js +1 -1
  145. package/dist/src/agent/skills/skill-manager.js +1 -1
  146. package/dist/src/agent/skills/skill-sources.js +1 -1
  147. package/dist/src/agent/source-context/index.d.ts +0 -1
  148. package/dist/src/agent/source-context/index.js +1 -2
  149. package/dist/src/agent/source-context/injector.js +1 -0
  150. package/dist/src/agent/source-context/types.d.ts +2 -2
  151. package/dist/src/agent/source-context/types.js +1 -1
  152. package/dist/src/agent/tools/cli-clarify.js +1 -1
  153. package/dist/src/agent/tools/codemode-permissions.d.ts +4 -0
  154. package/dist/src/agent/tools/codemode-permissions.js +23 -0
  155. package/dist/src/agent/tools/dataBatch.js +3 -1
  156. package/dist/src/agent/tools/delegation-parent-policy.js +1 -4
  157. package/dist/src/agent/tools/factory.js +4 -3
  158. package/dist/src/agent/tools/xopc-use-tool.js +2 -2
  159. package/dist/src/agent/transcript/provider-capabilities.js +0 -1
  160. package/dist/src/agent/transcript/transcript-policy.js +1 -2
  161. package/dist/src/agent-catalog/capabilities.js +2 -2
  162. package/dist/src/agent-catalog/migrations/legacy-config-cutover.js +1 -1
  163. package/dist/src/agent-catalog/repository.js +1 -1
  164. package/dist/src/agent-config/schema.d.ts +28 -0
  165. package/dist/src/agent-config/schema.js +7 -0
  166. package/dist/src/auth/credentials.js +7 -20
  167. package/dist/src/auth/model-credential-store.js +11 -4
  168. package/dist/src/auth/oauth/index.d.ts +1 -1
  169. package/dist/src/auth/oauth/index.js +3 -3
  170. package/dist/src/auth/oauth/openai.d.ts +2 -0
  171. package/dist/src/auth/oauth/openai.js +90 -0
  172. package/dist/src/auth/oauth/registry.js +3 -3
  173. package/dist/src/auth/oauth/types.d.ts +1 -0
  174. package/dist/src/auth/oauth/xopc-cloud.js +1 -1
  175. package/dist/src/auth/sync-provider-auth.js +5 -0
  176. package/dist/src/automations/capabilities/drafts.js +1 -1
  177. package/dist/src/bootstrap/application-state.js +1 -1
  178. package/dist/src/capabilities/runtime/dispatcher.js +1 -1
  179. package/dist/src/capabilities/runtime/product.js +1 -1
  180. package/dist/src/chat-commands/builtins/model.js +2 -2
  181. package/dist/src/cli/command-manifest.js +1 -1
  182. package/dist/src/cli/commands/agents.js +1 -1
  183. package/dist/src/cli/commands/doctor/checks/database-schema.js +1 -1
  184. package/dist/src/cli/commands/doctor/checks/provider-auth.js +1 -1
  185. package/dist/src/cli/commands/extension-agent-plugin.js +0 -19
  186. package/dist/src/cli/commands/mcp.js +36 -2
  187. package/dist/src/cli/commands/models.js +2 -2
  188. package/dist/src/cli/commands/onboard/model.js +2 -2
  189. package/dist/src/cli/utils/init-workspace-core.js +1 -1
  190. package/dist/src/cli/utils/oauth-login.js +2 -2
  191. package/dist/src/config/agent-profile.js +1 -1
  192. package/dist/src/config/index.js +3 -3
  193. package/dist/src/config/mcp-config-normalize.d.ts +0 -3
  194. package/dist/src/config/mcp-config-normalize.js +2 -22
  195. package/dist/src/config/models-json.d.ts +0 -5
  196. package/dist/src/config/models-json.js +13 -4
  197. package/dist/src/config/paths.d.ts +0 -1
  198. package/dist/src/config/paths.js +1 -4
  199. package/dist/src/config/schema.d.ts +130 -36
  200. package/dist/src/config/schema.js +52 -35
  201. package/dist/src/connectors/auth-provider-registry.d.ts +1 -1
  202. package/dist/src/connectors/auth-provider-registry.js +1 -21
  203. package/dist/src/connectors/china-catalog.js +5 -5
  204. package/dist/src/connectors/connection-recovery-service.d.ts +1 -6
  205. package/dist/src/connectors/connection-recovery-service.js +3 -105
  206. package/dist/src/connectors/health.d.ts +1 -2
  207. package/dist/src/connectors/health.js +2 -101
  208. package/dist/src/connectors/types.d.ts +1 -1
  209. package/dist/src/endpoint-tools/binding-service.d.ts +2 -0
  210. package/dist/src/endpoint-tools/binding-service.js +14 -2
  211. package/dist/src/endpoint-tools/bridge-host.d.ts +15 -0
  212. package/dist/src/endpoint-tools/bridge-host.js +166 -0
  213. package/dist/src/endpoint-tools/bridge.d.ts +27 -0
  214. package/dist/src/endpoint-tools/bridge.js +88 -0
  215. package/dist/src/endpoint-tools/capability-catalog.d.ts +2 -0
  216. package/dist/src/endpoint-tools/capability-catalog.js +8 -0
  217. package/dist/src/endpoint-tools/grant-service.d.ts +69 -0
  218. package/dist/src/endpoint-tools/grant-service.js +113 -0
  219. package/dist/src/endpoint-tools/index.js +1 -1
  220. package/dist/src/endpoint-tools/invocation-service.js +21 -4
  221. package/dist/src/endpoint-tools/location-task.d.ts +22 -0
  222. package/dist/src/endpoint-tools/location-task.js +114 -0
  223. package/dist/src/endpoint-tools/policy.js +21 -1
  224. package/dist/src/endpoint-tools/registry.d.ts +2 -0
  225. package/dist/src/endpoint-tools/registry.js +9 -0
  226. package/dist/src/endpoint-tools/result-projector.d.ts +15 -0
  227. package/dist/src/endpoint-tools/result-projector.js +31 -0
  228. package/dist/src/endpoint-tools/runtime.d.ts +2 -0
  229. package/dist/src/endpoint-tools/runtime.js +15 -2
  230. package/dist/src/endpoint-tools/target-resolver.d.ts +12 -0
  231. package/dist/src/endpoint-tools/target-resolver.js +27 -0
  232. package/dist/src/endpoint-tools/turn-context.d.ts +6 -0
  233. package/dist/src/endpoint-tools/turn-context.js +29 -0
  234. package/dist/src/endpoint-tools/upload-service.d.ts +4 -2
  235. package/dist/src/endpoint-tools/upload-service.js +29 -4
  236. package/dist/src/extensions/agent-plugins/auth.d.ts +0 -2
  237. package/dist/src/extensions/agent-plugins/auth.js +2 -19
  238. package/dist/src/extensions/agent-plugins/credentials.js +3 -19
  239. package/dist/src/extensions/agent-plugins/inventory.d.ts +2 -2
  240. package/dist/src/extensions/agent-plugins/mcp-adapter.js +1 -5
  241. package/dist/src/extensions/agent-plugins/source-http-fetch.d.ts +2 -0
  242. package/dist/src/{agent/mcp/plugin-http-fetch.js → extensions/agent-plugins/source-http-fetch.js} +7 -7
  243. package/dist/src/extensions/agent-plugins/sources.js +2 -2
  244. package/dist/src/extensions/agent-plugins/store.js +1 -3
  245. package/dist/src/extensions/agent-plugins/validation.d.ts +0 -4
  246. package/dist/src/extensions/agent-plugins/validation.js +14 -21
  247. package/dist/src/gateway/agents-admin.d.ts +5 -0
  248. package/dist/src/gateway/agents-admin.js +58 -3
  249. package/dist/src/gateway/chat-stream/mapper.js +9 -0
  250. package/dist/src/gateway/chat-stream/protocol.d.ts +4 -4
  251. package/dist/src/gateway/hono/lib/config-payload.d.ts +9 -4
  252. package/dist/src/gateway/hono/lib/config-payload.js +2 -5
  253. package/dist/src/gateway/hono/oauth-async.js +9 -2
  254. package/dist/src/gateway/hono/routes/agent-plugins.js +4 -9
  255. package/dist/src/gateway/hono/routes/agents.js +5 -4
  256. package/dist/src/gateway/hono/routes/config-patch/misc.js +1 -1
  257. package/dist/src/gateway/hono/routes/connection-waits.js +2 -5
  258. package/dist/src/gateway/hono/routes/connectors.js +5 -60
  259. package/dist/src/gateway/hono/routes/device-authorizations.d.ts +3 -0
  260. package/dist/src/gateway/hono/routes/device-authorizations.js +74 -0
  261. package/dist/src/gateway/hono/routes/endpoint-compatibility.js +8 -0
  262. package/dist/src/gateway/hono/routes/endpoint-tools.d.ts +1 -0
  263. package/dist/src/gateway/hono/routes/endpoint-tools.js +70 -3
  264. package/dist/src/gateway/hono/routes/lazy-bundles.js +17 -1
  265. package/dist/src/gateway/hono/routes/mcp.d.ts +1 -1
  266. package/dist/src/gateway/hono/routes/mcp.js +11 -237
  267. package/dist/src/gateway/hono/routes/notes.js +2 -2
  268. package/dist/src/gateway/hono/routes/projects.js +2 -2
  269. package/dist/src/gateway/hono/routes/session-command-handler.js +11 -1
  270. package/dist/src/gateway/hono/routes/session-input-handler.d.ts +8 -2
  271. package/dist/src/gateway/hono/routes/session-input-handler.js +26 -2
  272. package/dist/src/gateway/hono/routes/tasks.js +1 -1
  273. package/dist/src/gateway/image-generation-setup.js +1 -1
  274. package/dist/src/gateway/service/config-coordinator.js +2 -5
  275. package/dist/src/gateway/service/marketplace-service.js +2 -2
  276. package/dist/src/gateway/service/run-gateway-agent.js +13 -5
  277. package/dist/src/gateway/service/session-input-coordinator.d.ts +1 -1
  278. package/dist/src/gateway/service/session-input-coordinator.js +29 -9
  279. package/dist/src/gateway/service/sessions-api.js +0 -6
  280. package/dist/src/gateway/service.js +7 -16
  281. package/dist/src/gateway/session-reset-service.js +0 -6
  282. package/dist/src/gateway/xopc-cloud-capability-setup.js +1 -1
  283. package/dist/src/home-intelligence/host.js +2 -2
  284. package/dist/src/imports/compatibility.js +12 -10
  285. package/dist/src/local-apps/service.js +1 -1
  286. package/dist/src/mcp/channel-bridge.js +1 -1
  287. package/dist/src/notes/agent-context.js +1 -1
  288. package/dist/src/personal-agent/service.js +1 -1
  289. package/dist/src/providers/env-keys.js +1 -1
  290. package/dist/src/providers/index.js +26 -24
  291. package/dist/src/providers/model-call.d.ts +0 -2
  292. package/dist/src/providers/model-call.js +2 -6
  293. package/dist/src/providers/model-registry.js +4 -2
  294. package/dist/src/providers/model-supplements.d.ts +3 -3
  295. package/dist/src/providers/model-supplements.js +6 -27
  296. package/dist/src/providers/presentation.js +3 -8
  297. package/dist/src/providers/prompt-cache-plan.js +1 -1
  298. package/dist/src/providers/provider-auth-service.d.ts +1 -1
  299. package/dist/src/providers/provider-auth-service.js +7 -2
  300. package/dist/src/providers/provider-policy.d.ts +3 -0
  301. package/dist/src/providers/provider-policy.js +14 -0
  302. package/dist/src/providers/register-runtime-providers.js +6 -1
  303. package/dist/src/realtime/runtime.js +1 -1
  304. package/dist/src/session/store.js +7 -1
  305. package/dist/src/session/transcript-events.d.ts +5 -0
  306. package/dist/src/session/transcript-events.js +1 -0
  307. package/dist/src/session/types.d.ts +2 -0
  308. package/dist/src/storage/sqlite/device-grant-audit-repository.d.ts +11 -0
  309. package/dist/src/storage/sqlite/device-grant-audit-repository.js +10 -0
  310. package/dist/src/storage/sqlite/endpoint-device-settings-repository.d.ts +7 -0
  311. package/dist/src/storage/sqlite/endpoint-device-settings-repository.js +17 -0
  312. package/dist/src/storage/sqlite/migrations/240_device_settings.sql +5 -0
  313. package/dist/src/storage/sqlite/migrations/241_device_grant_audit.sql +13 -0
  314. package/dist/src/storage/sqlite/migrations/runner.d.ts +1 -1
  315. package/dist/src/storage/sqlite/migrations/runner.js +3 -3
  316. package/dist/src/storage/sqlite/schema.js +1 -1
  317. package/dist/src/storage/sqlite/session-input-repository.d.ts +1 -0
  318. package/dist/src/storage/sqlite/session-input-repository.js +5 -1
  319. package/dist/src/tasks/capabilities/read.js +2 -2
  320. package/dist/src/tui/backends/embedded-backend.js +1 -1
  321. package/dist/src/tui/backends/gateway-realtime-backend.js +1 -1
  322. package/dist/src/tui/xopc-tui-keybindings.d.ts +4 -4
  323. package/dist/src/voice/realtime/persona-context.js +1 -1
  324. package/package.json +20 -9
  325. package/dist/gateway/static/root/assets/agent-defaults-settings-panel-CCRfvuov.js +0 -1
  326. package/dist/gateway/static/root/assets/agent-plugin-dialog-CRlzd8El.js +0 -1
  327. package/dist/gateway/static/root/assets/agents-_ug2LCQb.js +0 -66
  328. package/dist/gateway/static/root/assets/automations-workspace-BQywN6nG.js +0 -6
  329. package/dist/gateway/static/root/assets/browser-automations-page-yiEuG1v7.js +0 -3
  330. package/dist/gateway/static/root/assets/capabilities-page-BEnFt_dj.js +0 -2
  331. package/dist/gateway/static/root/assets/connectors-page-D6wTmWA6.js +0 -2
  332. package/dist/gateway/static/root/assets/copy-text-row-BHDs3cBa.js +0 -1
  333. package/dist/gateway/static/root/assets/dependency-picker-BTERkA9X.js +0 -1
  334. package/dist/gateway/static/root/assets/device-pairing-wizard-DI2bqaKO.js +0 -1
  335. package/dist/gateway/static/root/assets/dist-Che_jiQF.js +0 -1
  336. package/dist/gateway/static/root/assets/gateway-realtime-DDWymi-o.js +0 -1
  337. package/dist/gateway/static/root/assets/home-page-BZDjvwet.js +0 -2
  338. package/dist/gateway/static/root/assets/index-BB1z8QxA.js +0 -106
  339. package/dist/gateway/static/root/assets/index-D9R6tU7r.css +0 -1
  340. package/dist/gateway/static/root/assets/link-2-D_ZKYUW7.js +0 -1
  341. package/dist/gateway/static/root/assets/local-session-drafts-DRPsDCj1.js +0 -1
  342. package/dist/gateway/static/root/assets/logs-page-DL-BM0xq.js +0 -2
  343. package/dist/gateway/static/root/assets/management-settings-BOVRHhXk.js +0 -1
  344. package/dist/gateway/static/root/assets/note-detail-panel-DJJK2yL4.js +0 -5
  345. package/dist/gateway/static/root/assets/notes-page-oCxO7ZTv.js +0 -8
  346. package/dist/gateway/static/root/assets/personal-page-DOk9gUK5.js +0 -1
  347. package/dist/gateway/static/root/assets/project-detail-page-3uAzbW4T.js +0 -1
  348. package/dist/gateway/static/root/assets/session-manager-LInoZ_Yi.js +0 -16
  349. package/dist/gateway/static/root/assets/sessions-page-BCVlNHtq.js +0 -1
  350. package/dist/gateway/static/root/assets/settings-advanced-gate-Bz-ue9fZ.js +0 -1
  351. package/dist/gateway/static/root/assets/setup-status-panel-B5BoZ-1y.js +0 -1
  352. package/dist/gateway/static/root/assets/shares-settings-BlnlzGjH.js +0 -1
  353. package/dist/gateway/static/root/assets/skills-page-DjdTeYzm.js +0 -2
  354. package/dist/gateway/static/root/assets/use-file-preview-expanded-Db2VYg1b.js +0 -2
  355. package/dist/gateway/static/root/assets/user-model-page-B74LkVbp.js +0 -2
  356. package/dist/gateway/static/root/assets/workflows-page-Crk4SxtC.js +0 -6
  357. package/dist/src/agent/embedded/system-prompt-override.d.ts +0 -2
  358. package/dist/src/agent/embedded/system-prompt-override.js +0 -21
  359. package/dist/src/agent/external-tools/mcp-provider.d.ts +0 -32
  360. package/dist/src/agent/external-tools/mcp-provider.js +0 -208
  361. package/dist/src/agent/mcp/bundle-mcp-config.d.ts +0 -20
  362. package/dist/src/agent/mcp/bundle-mcp-gateway.d.ts +0 -79
  363. package/dist/src/agent/mcp/bundle-mcp-gateway.js +0 -93
  364. package/dist/src/agent/mcp/bundle-mcp-names.d.ts +0 -1
  365. package/dist/src/agent/mcp/bundle-mcp-names.js +0 -25
  366. package/dist/src/agent/mcp/bundle-mcp-policy.d.ts +0 -1
  367. package/dist/src/agent/mcp/bundle-mcp-policy.js +0 -6
  368. package/dist/src/agent/mcp/bundle-mcp-runtime.d.ts +0 -46
  369. package/dist/src/agent/mcp/bundle-mcp-runtime.js +0 -571
  370. package/dist/src/agent/mcp/bundle-mcp-tools.d.ts +0 -2
  371. package/dist/src/agent/mcp/bundle-mcp-tools.js +0 -2
  372. package/dist/src/agent/mcp/bundle-mcp-types.d.ts +0 -76
  373. package/dist/src/agent/mcp/bundle-mcp-types.js +0 -1
  374. package/dist/src/agent/mcp/embedded-mcp.d.ts +0 -10
  375. package/dist/src/agent/mcp/embedded-mcp.js +0 -14
  376. package/dist/src/agent/mcp/index.d.ts +0 -5
  377. package/dist/src/agent/mcp/index.js +0 -12
  378. package/dist/src/agent/mcp/mcp-config-shared.d.ts +0 -8
  379. package/dist/src/agent/mcp/mcp-config-shared.js +0 -39
  380. package/dist/src/agent/mcp/mcp-http.d.ts +0 -23
  381. package/dist/src/agent/mcp/mcp-http.js +0 -67
  382. package/dist/src/agent/mcp/mcp-resource-id.d.ts +0 -6
  383. package/dist/src/agent/mcp/mcp-resource-id.js +0 -19
  384. package/dist/src/agent/mcp/mcp-stdio-transport.d.ts +0 -26
  385. package/dist/src/agent/mcp/mcp-stdio-transport.js +0 -120
  386. package/dist/src/agent/mcp/mcp-stdio.d.ts +0 -18
  387. package/dist/src/agent/mcp/mcp-stdio.js +0 -35
  388. package/dist/src/agent/mcp/mcp-transport-config.d.ts +0 -28
  389. package/dist/src/agent/mcp/mcp-transport-config.js +0 -91
  390. package/dist/src/agent/mcp/mcp-transport.d.ts +0 -17
  391. package/dist/src/agent/mcp/mcp-transport.js +0 -141
  392. package/dist/src/agent/mcp/oauth/index.d.ts +0 -6
  393. package/dist/src/agent/mcp/oauth/index.js +0 -6
  394. package/dist/src/agent/mcp/oauth/mcp-oauth-errors.d.ts +0 -5
  395. package/dist/src/agent/mcp/oauth/mcp-oauth-errors.js +0 -14
  396. package/dist/src/agent/mcp/oauth/mcp-oauth-manager.d.ts +0 -30
  397. package/dist/src/agent/mcp/oauth/mcp-oauth-manager.js +0 -276
  398. package/dist/src/agent/mcp/oauth/mcp-oauth-provider.d.ts +0 -33
  399. package/dist/src/agent/mcp/oauth/mcp-oauth-provider.js +0 -103
  400. package/dist/src/agent/mcp/oauth/mcp-oauth-session.d.ts +0 -31
  401. package/dist/src/agent/mcp/oauth/mcp-oauth-session.js +0 -181
  402. package/dist/src/agent/mcp/oauth/mcp-oauth-store.d.ts +0 -12
  403. package/dist/src/agent/mcp/oauth/mcp-oauth-store.js +0 -91
  404. package/dist/src/agent/mcp/oauth/mcp-oauth-types.d.ts +0 -22
  405. package/dist/src/agent/mcp/oauth/mcp-oauth-types.js +0 -1
  406. package/dist/src/agent/mcp/plugin-http-fetch.d.ts +0 -2
  407. package/dist/src/agent/source-context/mcp-resource-context.d.ts +0 -8
  408. package/dist/src/agent/source-context/mcp-resource-context.js +0 -30
  409. package/dist/src/auth/oauth/openai-codex.d.ts +0 -9
  410. package/dist/src/auth/oauth/openai-codex.js +0 -414
  411. package/dist/src/connectors/plugin-mcp-recovery.d.ts +0 -28
  412. package/dist/src/connectors/plugin-mcp-recovery.js +0 -90
  413. package/dist/src/extensions/agent-plugins/connection.d.ts +0 -8
  414. package/dist/src/extensions/agent-plugins/connection.js +0 -41
  415. package/dist/src/extensions/agent-plugins/health.d.ts +0 -4
  416. package/dist/src/extensions/agent-plugins/health.js +0 -48
  417. package/dist/src/extensions/agent-plugins/plugin-oauth-scope.d.ts +0 -1
  418. package/dist/src/extensions/agent-plugins/plugin-oauth-scope.js +0 -8
@@ -12,12 +12,18 @@ function canonicalSessionCommand(value) {
12
12
  }
13
13
  function sessionCommandIdentity(command) {
14
14
  if ("origin" in command) {
15
- const { origin: _origin, ...identity } = command;
16
- return canonicalSessionCommand(identity);
15
+ const origin = command.origin.type === "endpoint" ? {
16
+ type: "endpoint",
17
+ endpointId: command.origin.endpointId
18
+ } : command.origin;
19
+ return canonicalSessionCommand({
20
+ ...command,
21
+ origin
22
+ });
17
23
  }
18
24
  return canonicalSessionCommand(command);
19
25
  }
20
- var sessionCreationSchema, attachmentSchema, sessionInputContentSchema, originSchema, sessionInputCommandSchema, sessionMaterializeCommandSchema;
26
+ var sessionCreationSchema, attachmentSchema, endpointContextSchema, sessionInputContentSchema, originSchema, sessionInputCommandSchema, sessionMaterializeCommandSchema;
21
27
  var init_session_input_command = __esmMin((() => {
22
28
  init_app_context();
23
29
  init_browser_page_context();
@@ -46,8 +52,28 @@ var init_session_input_command = __esmMin((() => {
46
52
  workspaceRelativePath: z.string().optional(),
47
53
  durationSeconds: z.number().nonnegative().optional()
48
54
  });
55
+ endpointContextSchema = z.strictObject({
56
+ version: z.literal(1),
57
+ capturedAt: z.number().int().nonnegative().max(Number.MAX_SAFE_INTEGER),
58
+ timezone: z.string().min(1).max(80).refine((value) => {
59
+ try {
60
+ new Intl.DateTimeFormat("en", { timeZone: value });
61
+ return true;
62
+ } catch {
63
+ return false;
64
+ }
65
+ }, "Invalid timezone"),
66
+ locale: z.string().min(1).max(80).refine((value) => {
67
+ try {
68
+ return Intl.getCanonicalLocales(value).length === 1;
69
+ } catch {
70
+ return false;
71
+ }
72
+ }, "Invalid locale")
73
+ });
49
74
  sessionInputContentSchema = z.strictObject({
50
75
  content: z.string(),
76
+ endpointContext: endpointContextSchema.optional(),
51
77
  attachments: z.array(attachmentSchema).optional(),
52
78
  contextRefs: z.array(z.strictObject({
53
79
  kind: z.enum([
@@ -56,7 +82,6 @@ var init_session_input_command = __esmMin((() => {
56
82
  "file",
57
83
  "session",
58
84
  "browser_tab",
59
- "mcp_resource",
60
85
  "user_assertion"
61
86
  ]),
62
87
  sourceId: z.string().trim().min(1),
@@ -108,4 +133,4 @@ var init_session_input_command = __esmMin((() => {
108
133
  }));
109
134
  //#endregion
110
135
  init_session_input_command();
111
- export { canonicalSessionCommand, init_session_input_command, sessionCommandIdentity, sessionCreationSchema, sessionInputCommandSchema, sessionInputContentSchema, sessionMaterializeCommandSchema };
136
+ export { canonicalSessionCommand, endpointContextSchema, init_session_input_command, sessionCommandIdentity, sessionCreationSchema, sessionInputCommandSchema, sessionInputContentSchema, sessionMaterializeCommandSchema };
@@ -8,6 +8,7 @@ import { getSessionMetadata } from "../storage/sqlite/session-read-repository.js
8
8
  import { init_sqlite } from "../storage/sqlite/index.js";
9
9
  import { expandWorkspacePathString, init_workspace_path } from "../config/workspace-path.js";
10
10
  import { init_agent_scope, listAgentEntries, resolveAgentProfileDir } from "./agent-scope.js";
11
+ import { extractTextContent } from "./context/workspace.js";
11
12
  import { init_paths, resolveBundledSkillsDir } from "../config/paths.js";
12
13
  import { CredentialResolver, init_credentials } from "../auth/credentials.js";
13
14
  import { traceTools } from "../observability/runtime.js";
@@ -18,7 +19,6 @@ import { init_sync_provider_auth, resolveProviderApiKeySync } from "../auth/sync
18
19
  import { getApiKeySync, getDefaultModelSync, init_providers, resolveModel } from "../providers/index.js";
19
20
  import { createExtensionAwareStreamFn } from "../providers/extension-stream-bridge.js";
20
21
  import { continuesAfterTool, trackAiUsageStream } from "../usage/recorder.js";
21
- import { extractTextContent } from "./context/workspace.js";
22
22
  import { resolveUserContextSessionAccess } from "../user-context/access-policy.js";
23
23
  import { isPersonalConversation } from "../personal-agent/repository.js";
24
24
  import { PersonalPromptContext } from "../personal-agent/prompt-context.js";
@@ -27,22 +27,18 @@ import { clearBootstrapSnapshot } from "./bootstrap/bootstrap-cache.js";
27
27
  import { resolveBootstrapContextSync } from "./bootstrap/bootstrap-files.js";
28
28
  import { loadProjectAgentsContextFile } from "./bootstrap/project-agents-context.js";
29
29
  import { getEmbeddedExecutionRunId } from "./embedded/execution-context.js";
30
- import { parseExternalToolRef } from "./external-tools/refs.js";
31
30
  import { loadSkillsLock } from "./skills/hub-lock.js";
32
31
  import { isUnderManagedSkillsDir } from "./skills/managed-store.js";
33
- import { mcpToolPolicyId } from "./mcp/bundle-mcp-policy.js";
34
- import { disposeAllSessionMcpRuntimes, retireSessionMcpRuntimeForConversationId } from "./mcp/bundle-mcp-runtime.js";
35
32
  import { createSkillConfigManager, isSkillEnabled, resolveSkillConfig } from "./skills/config.js";
36
33
  import { isValidSkillEnvVarName } from "./skills/required-env-vars.js";
37
34
  import { resolveWorkspaceSkillsDir, resolveWorkspaceSkillsLockPath } from "./skills/workspace-skills-dir.js";
38
- import { replaceAgentSystemPrompt } from "./prompt/agent-system-prompt.js";
35
+ import { abortEmbeddedRun } from "./embedded/runs.js";
39
36
  import { evictAllEmbeddedSessionRunners, evictEmbeddedSessionRunner } from "./embedded/session-runner.js";
40
37
  import { createAgentTurnPolicy } from "./orchestration/agent-turn-policy.js";
41
38
  import { createAgentCapabilitySessionState, resolveAgentCapabilityCatalog } from "./capabilities/registry.js";
42
39
  import "./capabilities/index.js";
43
40
  import { sortToolsForPromptCache } from "./tools/cache-stability.js";
44
41
  import { AgentToolsFactory } from "./tools/factory.js";
45
- import "./mcp/bundle-mcp-tools.js";
46
42
  import { isMemorySubsystemEnabled } from "./memory/memory-config.js";
47
43
  import { evaluateToolGate } from "./context/execution-context.js";
48
44
  import { ExecutionContextCoordinator } from "./context/coordinator.js";
@@ -51,6 +47,7 @@ import { BackgroundReviewCoordinator } from "./background-review/coordinator.js"
51
47
  import { maybeRequestChannelExecApproval } from "../channels/exec-approval-runtime.js";
52
48
  import { SkillFilesystemWatcher } from "./skills/filesystem-watcher.js";
53
49
  import { ProjectTrustStore, hasTrustRequiringProjectResources } from "../project-trust/trust-store.js";
50
+ import { replaceAgentSystemPrompt } from "./prompt/agent-system-prompt.js";
54
51
  import { basename, resolve, sep } from "node:path";
55
52
  import { createHash } from "node:crypto";
56
53
  import { Agent } from "@earendil-works/pi-agent-core";
@@ -232,6 +229,22 @@ var AgentManager = class {
232
229
  */
233
230
  updateRuntimeConfiguration(config) {
234
231
  this.config.config = config;
232
+ for (const instance of this.agents.values()) {
233
+ const before = instance.effectiveProfile.config;
234
+ const after = resolveEffectiveAgentProfileForSession(instance.conversationId).config;
235
+ if (JSON.stringify([
236
+ before.runtime.codemode,
237
+ before.tools,
238
+ before.toolAllowlist
239
+ ]) !== JSON.stringify([
240
+ after.runtime.codemode,
241
+ after.tools,
242
+ after.toolAllowlist
243
+ ])) {
244
+ abortEmbeddedRun(instance.conversationId);
245
+ evictEmbeddedSessionRunner(instance.conversationId, "agent_tool_configuration_changed");
246
+ }
247
+ }
235
248
  const ref = getAgentDefaultModelRef();
236
249
  this.config.model = ref;
237
250
  this.defaultModel = ref || getDefaultModelSync(config);
@@ -849,10 +862,6 @@ var AgentManager = class {
849
862
  if (instance) {
850
863
  this.backgroundReview.forgetSession(conversationId);
851
864
  this.toolsFactory.closeBrowserPageForSession(conversationId);
852
- retireSessionMcpRuntimeForConversationId({
853
- conversationId,
854
- reason: "agent-evict"
855
- });
856
865
  instance.agent.abort();
857
866
  evictEmbeddedSessionRunner(conversationId, "agent_removed");
858
867
  this.agents.delete(conversationId);
@@ -930,7 +939,6 @@ var AgentManager = class {
930
939
  if (this.skillsUpdatedTimer) clearTimeout(this.skillsUpdatedTimer);
931
940
  this.skillFilesystemWatcher.dispose();
932
941
  this.toolsFactory.shutdownBrowser();
933
- disposeAllSessionMcpRuntimes().catch(() => {});
934
942
  evictAllEmbeddedSessionRunners("agent_manager_dispose");
935
943
  this.backgroundReview.clear();
936
944
  this.userUnderstandingMaintenance.clear();
@@ -1177,22 +1185,10 @@ var AgentManager = class {
1177
1185
  } : void 0;
1178
1186
  }
1179
1187
  const toolRef = typeof args?.toolRef === "string" ? args.toolRef : "";
1180
- const parsed = parseExternalToolRef(toolRef, "mcp");
1181
- if (!parsed) {
1182
- const externalPolicy = profile.config.tools[toolRef];
1183
- return externalPolicy ? {
1184
- id: toolRef,
1185
- ...externalPolicy
1186
- } : gatewayPolicy ? {
1187
- id: toolName,
1188
- ...gatewayPolicy
1189
- } : void 0;
1190
- }
1191
- const id = mcpToolPolicyId(parsed.namespace, parsed.toolName);
1192
- const policy = profile.config.tools[id];
1193
- return policy ? {
1194
- id,
1195
- ...policy
1188
+ const externalPolicy = profile.config.tools[toolRef];
1189
+ return externalPolicy ? {
1190
+ id: toolRef,
1191
+ ...externalPolicy
1196
1192
  } : gatewayPolicy ? {
1197
1193
  id: toolName,
1198
1194
  ...gatewayPolicy
@@ -4,12 +4,12 @@ import { finishContextExtractionRun } from "../../storage/sqlite/context-extract
4
4
  import { getSessionMetadata } from "../../storage/sqlite/session-read-repository.js";
5
5
  import { loadCompactionSourceSnapshot } from "../../storage/sqlite/transcript-repository.js";
6
6
  import { init_sqlite } from "../../storage/sqlite/index.js";
7
+ import { extractTextContent } from "../context/workspace.js";
7
8
  import { extractProfileAgentId } from "../../config/agent-profile.js";
8
9
  import { init_sync_provider_auth, resolveProviderApiKeySync } from "../../auth/sync-provider-auth.js";
9
10
  import { getApiKeySync, init_providers, resolveModel } from "../../providers/index.js";
10
11
  import { createExtensionAwareStreamFn } from "../../providers/extension-stream-bridge.js";
11
12
  import { trackAiUsageStream } from "../../usage/recorder.js";
12
- import { extractTextContent } from "../context/workspace.js";
13
13
  import { getAssertionSlot, listUserAssertions } from "../../user-model/repository.js";
14
14
  import { readAgentMessageContent } from "../memory/agent-message-access.js";
15
15
  import { isAssistantTurnAborted, isAssistantTurnFailed } from "../orchestration/llm-turn-retry.js";
@@ -0,0 +1,7 @@
1
+ import type { AgentTool } from '@earendil-works/pi-agent-core';
2
+ import { type AgentSession, type ExtensionFactory } from '@earendil-works/pi-coding-agent';
3
+ import type { EffectiveAgentConfig } from '../../agent-config/schema.js';
4
+ export type CodemodePolicy = NonNullable<EffectiveAgentConfig['runtime']['codemode']>;
5
+ /** Public pi extension, restricted to core reads and the current xopc turn policy. */
6
+ export declare function createXopcCodemodeExtension(policy: CodemodePolicy, tools: readonly AgentTool[], getSession: () => AgentSession | undefined): ExtensionFactory;
7
+ export declare function boundCodemodeSource(source: string, policy: CodemodePolicy): string;
@@ -0,0 +1,232 @@
1
+ import { isCodemodeCoreRead } from "../tools/codemode-permissions.js";
2
+ import { getXopcToolMetadata } from "./tool-metadata.js";
3
+ import { withDataToolPermissions } from "../tools/dataBatch.js";
4
+ import { retainCodemodeOutput } from "./codemode-output.js";
5
+ import { AsyncLocalStorage } from "node:async_hooks";
6
+ import { createCodemodeExtension } from "@earendil-works/pi-coding-agent";
7
+ //#region src/agent/embedded/codemode-extension.ts
8
+ const MAX_STORE_BYTES = 64 * 1024;
9
+ const MAX_SOURCE_BYTES = 64 * 1024;
10
+ /** Public pi extension, restricted to core reads and the current xopc turn policy. */
11
+ function createXopcCodemodeExtension(policy, tools, getSession) {
12
+ const allowed = new Set(tools.filter((tool) => isCodemodeCoreRead(tool) || getXopcToolMetadata(tool)?.external?.readOnly === true).map((tool) => tool.name));
13
+ const isAllowed = (name) => allowed.has(name) || name.startsWith("mcp__") || [
14
+ "list_mcp_resources",
15
+ "list_mcp_resource_templates",
16
+ "read_mcp_resource"
17
+ ].includes(name);
18
+ const inlineReads = tools.filter(isCodemodeCoreRead).map((tool) => tool.name);
19
+ const execution = new AsyncLocalStorage();
20
+ const original = createCodemodeExtension({
21
+ mode: "on",
22
+ models: false
23
+ });
24
+ const contextFor = (id, name, args) => {
25
+ const session = getSession();
26
+ const assistantMessage = session?.agent.state.messages.findLast((message) => message.role === "assistant");
27
+ if (!session || assistantMessage?.role !== "assistant") throw new Error("Codemode needs an active xopc turn");
28
+ return {
29
+ assistantMessage,
30
+ toolCall: {
31
+ type: "toolCall",
32
+ id,
33
+ name,
34
+ arguments: args
35
+ },
36
+ args,
37
+ context: {
38
+ messages: session.agent.state.messages,
39
+ tools: session.agent.state.tools
40
+ }
41
+ };
42
+ };
43
+ return (pi) => {
44
+ pi.on("tool_call", async (event) => {
45
+ if (!event.parentToolCallId) return;
46
+ const active = execution.getStore();
47
+ if (!active || active.parentId !== event.parentToolCallId || !isAllowed(event.toolName)) return {
48
+ block: true,
49
+ reason: "Codemode tool is not authorized"
50
+ };
51
+ active.signal.throwIfAborted();
52
+ return getSession()?.agent.beforeToolCall?.(contextFor(event.toolCallId, event.toolName, event.input), active.signal);
53
+ });
54
+ pi.on("tool_result", async (event) => {
55
+ if (!event.parentToolCallId) return;
56
+ const active = execution.getStore();
57
+ if (!active || active.parentId !== event.parentToolCallId) return {
58
+ content: [{
59
+ type: "text",
60
+ text: "Codemode execution is no longer active"
61
+ }],
62
+ isError: true
63
+ };
64
+ try {
65
+ return await getSession()?.agent.afterToolCall?.({
66
+ ...contextFor(event.toolCallId, event.toolName, event.input),
67
+ result: {
68
+ content: event.content,
69
+ details: event.details,
70
+ structuredContent: event.structuredContent,
71
+ usage: event.usage
72
+ },
73
+ isError: event.isError
74
+ }, active.signal);
75
+ } catch {
76
+ return {
77
+ content: [{
78
+ type: "text",
79
+ text: "Codemode result policy failed"
80
+ }],
81
+ details: {},
82
+ isError: true
83
+ };
84
+ }
85
+ });
86
+ return original({
87
+ ...pi,
88
+ appendEntry(customType, data) {
89
+ if (customType !== "codemode-store") throw new Error("Unsupported Codemode entry");
90
+ const active = execution.getStore();
91
+ if (!active || active.signal.aborted) throw new Error("Codemode execution is no longer active");
92
+ if (Buffer.byteLength(JSON.stringify(data)) > MAX_STORE_BYTES) throw new Error("Codemode store writes exceed 64 KiB");
93
+ const state = Object.create(null);
94
+ const apply = (value) => {
95
+ const writes = value;
96
+ for (const key of writes.delete ?? []) delete state[key];
97
+ Object.assign(state, writes.set ?? {});
98
+ };
99
+ for (const entry of active.ctx.sessionManager.getBranch()) if (entry.type === "custom" && entry.customType === customType) apply(entry.data);
100
+ apply(data);
101
+ if (Object.keys(state).length > 64 || Buffer.byteLength(JSON.stringify(state)) > MAX_STORE_BYTES) throw new Error("Codemode store exceeds 64 keys or 64 KiB");
102
+ pi.appendEntry(customType, data);
103
+ },
104
+ registerTool(definition) {
105
+ const prepare = definition.prepareLoadout;
106
+ pi.registerTool({
107
+ ...definition,
108
+ prepareLoadout(loadout) {
109
+ const changes = prepare?.({
110
+ ...loadout,
111
+ callable: loadout.callable.filter((tool) => isAllowed(tool.name))
112
+ });
113
+ return {
114
+ ...changes,
115
+ descriptions: {
116
+ ...changes?.descriptions,
117
+ codemode: `${changes?.descriptions?.codemode ?? definition.description}\n\nCore reads: ${inlineReads.join(", ") || "(none)"}. Host-approved deferred reads and native MCP tools can be found with searchTools(). Host limits: ${policy.timeoutMs}ms, ${policy.maxConcurrentCalls} concurrent calls, ${policy.maxCalls} calls, ${policy.maxOutputTokens} estimated output tokens. Store: 64 keys / 64 KiB. Models APIs are unavailable.`
118
+ }
119
+ };
120
+ },
121
+ async execute(id, params, signal, onUpdate, ctx) {
122
+ if (!ctx) throw new Error("Codemode needs an active session");
123
+ const input = params;
124
+ if (Buffer.byteLength(input.code) > MAX_SOURCE_BYTES) throw new Error("Codemode source exceeds 64 KiB");
125
+ const source = boundCodemodeSource(input.code, policy);
126
+ const deadline = AbortSignal.timeout(policy.timeoutMs);
127
+ const budgetAbort = new AbortController();
128
+ const combined = AbortSignal.any([
129
+ deadline,
130
+ budgetAbort.signal,
131
+ ...signal ? [signal] : []
132
+ ]);
133
+ let calls = 0;
134
+ let running = 0;
135
+ const waiting = /* @__PURE__ */ new Set();
136
+ const boundedContext = {
137
+ ...ctx,
138
+ tools: ctx.tools.filter((tool) => isAllowed(tool.name)),
139
+ async executeTool(name, args, options) {
140
+ if (!isAllowed(name)) throw new Error(`Codemode tool ${name} is not authorized`);
141
+ if (++calls > policy.maxCalls) {
142
+ const error = /* @__PURE__ */ new Error(`Codemode exceeds ${policy.maxCalls} calls`);
143
+ budgetAbort.abort(error);
144
+ throw error;
145
+ }
146
+ const callSignal = options?.signal ? AbortSignal.any([combined, options.signal]) : combined;
147
+ while (running >= policy.maxConcurrentCalls) {
148
+ callSignal.throwIfAborted();
149
+ await new Promise((resolve) => {
150
+ const wake = () => {
151
+ waiting.delete(wake);
152
+ callSignal.removeEventListener("abort", wake);
153
+ resolve();
154
+ };
155
+ waiting.add(wake);
156
+ callSignal.addEventListener("abort", wake, { once: true });
157
+ });
158
+ }
159
+ callSignal.throwIfAborted();
160
+ running++;
161
+ try {
162
+ return await execution.run({
163
+ parentId: id,
164
+ signal: callSignal,
165
+ ctx
166
+ }, () => ctx.executeTool(name, args, {
167
+ ...options,
168
+ signal: callSignal
169
+ }));
170
+ } finally {
171
+ running--;
172
+ waiting.values().next().value?.();
173
+ }
174
+ }
175
+ };
176
+ return execution.run({
177
+ parentId: id,
178
+ signal: combined,
179
+ ctx
180
+ }, () => withDataToolPermissions(allowed, async () => {
181
+ const result = await definition.execute(id, {
182
+ ...params,
183
+ code: source
184
+ }, combined, onUpdate, boundedContext);
185
+ const details = result.details;
186
+ let outputPath;
187
+ if (details.fullOutputPath) try {
188
+ outputPath = await retainCodemodeOutput(ctx.cwd, details.fullOutputPath);
189
+ } catch {}
190
+ let remaining = policy.maxOutputTokens * 4;
191
+ const link = outputPath ? `Full Codemode output: ${outputPath}\n` : "";
192
+ const retainedLink = link.length <= remaining ? link : "";
193
+ remaining -= retainedLink.length;
194
+ const content = result.content.flatMap((block) => {
195
+ if (block.type === "image") {
196
+ if (block.data.length > remaining) return [];
197
+ remaining -= block.data.length;
198
+ return [block];
199
+ }
200
+ const text = block.text.replace(/\[Full output: [^\n]+\]/g, "").slice(0, remaining);
201
+ remaining -= text.length;
202
+ return text ? [{
203
+ type: "text",
204
+ text
205
+ }] : [];
206
+ });
207
+ details.fullOutputPath = outputPath;
208
+ return {
209
+ ...result,
210
+ content: [...retainedLink ? [{
211
+ type: "text",
212
+ text: retainedLink
213
+ }] : [], ...content]
214
+ };
215
+ }));
216
+ }
217
+ });
218
+ }
219
+ });
220
+ };
221
+ }
222
+ function boundCodemodeSource(source, policy) {
223
+ const match = /^\s*\/\/\s*@options:\s*([^\r\n]*)(?:\r?\n|$)/.exec(source);
224
+ const options = match ? JSON.parse(match[1]) : {};
225
+ const clamp = (value, limit) => typeof value === "number" && Number.isFinite(value) && value > 0 ? Math.min(Math.floor(value), limit) : limit;
226
+ return `// @options: ${JSON.stringify({
227
+ timeout_ms: clamp(options.timeout_ms, policy.timeoutMs),
228
+ max_output_tokens: clamp(options.max_output_tokens, policy.maxOutputTokens)
229
+ })}\n${match ? source.slice(match[0].length) : source}`;
230
+ }
231
+ //#endregion
232
+ export { boundCodemodeSource, createXopcCodemodeExtension };
@@ -0,0 +1,2 @@
1
+ /** Adopt only pi's own spill file, never a path printed by a script or an MCP server. */
2
+ export declare function retainCodemodeOutput(workspace: string, source: unknown): Promise<string | undefined>;
@@ -0,0 +1,34 @@
1
+ import { tmpdir } from "node:os";
2
+ import { basename, dirname, join, relative, sep } from "node:path";
3
+ import { constants } from "node:fs";
4
+ import { randomUUID } from "node:crypto";
5
+ import { mkdir, open, realpath, writeFile } from "node:fs/promises";
6
+ //#region src/agent/embedded/codemode-output.ts
7
+ /** Adopt only pi's own spill file, never a path printed by a script or an MCP server. */
8
+ async function retainCodemodeOutput(workspace, source) {
9
+ if (typeof source !== "string" || dirname(source) !== tmpdir() || !/^pi-codemode-[a-f0-9]{16}\.txt$/.test(basename(source))) return;
10
+ const handle = await open(source, constants.O_RDONLY | constants.O_NOFOLLOW);
11
+ try {
12
+ const info = await handle.stat();
13
+ if (!info.isFile() || info.size > 64 * 1024 * 1024) throw new Error("Codemode output file exceeds 64 MiB");
14
+ const root = await realpath(workspace);
15
+ const directory = join(root, ".xopc", "codemode-output");
16
+ await mkdir(directory, {
17
+ recursive: true,
18
+ mode: 448
19
+ });
20
+ const resolved = await realpath(directory);
21
+ const location = relative(root, resolved);
22
+ if (location === ".." || location.startsWith(`..${sep}`) || location.startsWith(sep)) throw new Error("Codemode output directory escapes workspace");
23
+ const name = `${randomUUID()}.txt`;
24
+ await writeFile(join(resolved, name), await handle.readFile(), {
25
+ flag: "wx",
26
+ mode: 384
27
+ });
28
+ return `.xopc/codemode-output/${name}`;
29
+ } finally {
30
+ await handle.close();
31
+ }
32
+ }
33
+ //#endregion
34
+ export { retainCodemodeOutput };
@@ -0,0 +1,6 @@
1
+ import type { AgentTool } from '@earendil-works/pi-agent-core';
2
+ /** Project the current host directory into pi; pi owns search and declaration loading. */
3
+ export declare function materializeNativeExternalTools(params: {
4
+ conversationId: string;
5
+ tools: readonly AgentTool[];
6
+ }): Promise<AgentTool[]>;
@@ -0,0 +1,60 @@
1
+ import { getEmbeddedExecutionRunId, runWithEmbeddedExecutionSession } from "./execution-context.js";
2
+ import { parseExternalToolRef } from "../external-tools/refs.js";
3
+ import { wrapToolsWithProtection } from "../tools/executor.js";
4
+ import { setXopcToolMetadata } from "./tool-metadata.js";
5
+ import { getExternalToolRegistry } from "../external-tools/tool-registry.js";
6
+ import { createHash } from "node:crypto";
7
+ //#region src/agent/embedded/external-tool-discovery.ts
8
+ /** Project the current host directory into pi; pi owns search and declaration loading. */
9
+ async function materializeNativeExternalTools(params) {
10
+ const registry = getExternalToolRegistry(params.tools);
11
+ if (!registry) return [];
12
+ return runWithEmbeddedExecutionSession(params.conversationId, async () => {
13
+ const descriptors = await registry.service.catalog(registry.nativeSources);
14
+ const names = new Set(params.tools.map((tool) => tool.name));
15
+ const refs = /* @__PURE__ */ new Map();
16
+ return wrapToolsWithProtection(descriptors.map((descriptor) => {
17
+ const parsed = parseExternalToolRef(descriptor.toolRef, descriptor.source);
18
+ if (!parsed) throw new Error("Invalid native tool identity");
19
+ const suffix = createHash("sha256").update(descriptor.toolRef).digest("hex").slice(0, 12);
20
+ const prefix = descriptor.source === "endpoint" ? "device" : descriptor.source;
21
+ const name = `${prefix}__${parsed.toolName.replace(/[^A-Za-z0-9_]/g, "_").slice(0, 40)}_${suffix}`;
22
+ if (names.has(name)) throw new Error(`Native tool identifier collision: ${name}`);
23
+ names.add(name);
24
+ refs.set(name, descriptor.toolRef);
25
+ return setXopcToolMetadata({
26
+ name,
27
+ label: descriptor.title,
28
+ description: `${descriptor.description}\n${descriptor.summary}`,
29
+ parameters: descriptor.inputSchema,
30
+ execute(id, args, signal, update) {
31
+ return runWithEmbeddedExecutionSession(params.conversationId, () => registry.execute(id, {
32
+ toolRef: descriptor.toolRef,
33
+ revision: descriptor.revision,
34
+ arguments: args,
35
+ ...descriptor.batchRead ? { readOnly: true } : {}
36
+ }, signal, update), getEmbeddedExecutionRunId());
37
+ }
38
+ }, {
39
+ exposure: descriptor.exposure === "model-only" ? "model-only" : "deferred",
40
+ namespace: {
41
+ name: `${prefix}__${createHash("sha256").update(parsed.namespace).digest("hex").slice(0, 12)}`,
42
+ description: descriptor.source === "endpoint" ? "Tools of the current authorized device" : descriptor.namespace
43
+ },
44
+ outputSchema: descriptor.outputSchema,
45
+ annotations: descriptor.annotations,
46
+ external: {
47
+ toolRef: descriptor.toolRef,
48
+ revision: descriptor.revision,
49
+ readOnly: descriptor.batchRead === true
50
+ },
51
+ ...registry.subscribeInvalidation ? { subscribeInvalidation: (listener) => registry.subscribeInvalidation(params.conversationId, descriptor.toolRef, listener) } : {}
52
+ });
53
+ }), {
54
+ ...registry.executorConfig,
55
+ resolveTimeoutMs: (name) => registry.executorConfig?.resolveTimeoutMs?.(refs.get(name) ?? name) ?? registry.executorConfig?.resolveTimeoutMs?.("xopc_tool_execute")
56
+ });
57
+ }, getEmbeddedExecutionRunId());
58
+ }
59
+ //#endregion
60
+ export { materializeNativeExternalTools };
@@ -1,8 +1,9 @@
1
1
  import { init_paths, resolveModelsJsonPath } from "../../config/paths.js";
2
+ import { init_register_bundled_oauth_flows, registerBundledOAuthFlows } from "../../providers/register-bundled-oauth-flows.js";
3
+ import { assertCurrentModelProvider, init_provider_policy } from "../../providers/provider-policy.js";
2
4
  import { CredentialResolver, init_credentials } from "../../auth/credentials.js";
3
5
  import { init_sync_provider_auth, resolveProviderApiKeySync } from "../../auth/sync-provider-auth.js";
4
6
  import { XopcModelCredentialStore, init_model_credential_store } from "../../auth/model-credential-store.js";
5
- import { init_register_bundled_oauth_flows, registerBundledOAuthFlows } from "../../providers/register-bundled-oauth-flows.js";
6
7
  import { init_register_runtime_providers, registerRuntimeProviders } from "../../providers/register-runtime-providers.js";
7
8
  import { getApiKeySync, init_providers } from "../../providers/index.js";
8
9
  import { InMemoryModelsStore } from "@earendil-works/pi-ai";
@@ -15,10 +16,12 @@ init_paths();
15
16
  init_providers();
16
17
  init_register_bundled_oauth_flows();
17
18
  init_register_runtime_providers();
19
+ init_provider_policy();
18
20
  function resolveEmbeddedProviderApiKeySync(providerId) {
19
21
  return resolveProviderApiKeySync(providerId) ?? getApiKeySync(providerId);
20
22
  }
21
23
  async function createEmbeddedModelRuntime(providerId) {
24
+ assertCurrentModelProvider(providerId);
22
25
  registerBundledOAuthFlows();
23
26
  const resolver = new CredentialResolver();
24
27
  const credentials = new XopcModelCredentialStore(resolver);
@@ -30,7 +33,7 @@ async function createEmbeddedModelRuntime(providerId) {
30
33
  registerRuntimeProviders(modelRuntime);
31
34
  const runtimeProvider = modelRuntime.getProvider(providerId);
32
35
  const storedCredential = await credentials.read(providerId);
33
- if (!(runtimeProvider?.auth.oauth && storedCredential?.type === "oauth")) {
36
+ if (await resolver.resolveApiKeySource(providerId) !== "oauth" || !(runtimeProvider?.auth.oauth && storedCredential?.type === "oauth")) {
34
37
  const key = await resolver.resolveApiKey(providerId) ?? getApiKeySync(providerId);
35
38
  if (key && key !== "extension-managed") await modelRuntime.setRuntimeApiKey(providerId, key);
36
39
  }
@@ -10,6 +10,7 @@ import { isPersonalConversation } from "../../personal-agent/repository.js";
10
10
  import { runWithEmbeddedExecutionSession } from "./execution-context.js";
11
11
  import { resolveAgentTurnTimeoutMs } from "../orchestration/run-agent-turn-with-timeout.js";
12
12
  import { resolvePromptCachePolicy } from "../../providers/prompt-cache-plan.js";
13
+ import { prepareNativeMcpConfig } from "../mcp/native-mcp.js";
13
14
  import { evaluateContextBudget } from "../memory/context-budget.js";
14
15
  import { assessContext, recoverContext as recoverContext$1 } from "../memory/context-recovery.js";
15
16
  import { resolveCompactionPolicy } from "../memory/compaction-policy.js";
@@ -18,6 +19,7 @@ import { projectTurnOutcome } from "../../session/turn-outcome-projector.js";
18
19
  import { voicePresentationPrompt } from "../prompt/voice-presentation.js";
19
20
  import { applyStartupContextToUserMessage } from "../reply/apply-turn-user-enrichment.js";
20
21
  import { AgentRunSupervisor } from "../orchestration/agent-run-supervisor.js";
22
+ import { materializeNativeExternalTools } from "./external-tool-discovery.js";
21
23
  import crypto from "node:crypto";
22
24
  //#region src/agent/embedded/run-for-session.ts
23
25
  init_src();
@@ -124,7 +126,7 @@ async function runEmbeddedTurnForSessionInner(params) {
124
126
  if (typeof mm.applyResolvedModel === "function") mm.applyResolvedModel(agent, model, modelRef);
125
127
  else await mm.applyModelForSession(agent, conversationId);
126
128
  agentManager.setModelForSession(conversationId, modelRef);
127
- const tools = agent.state.tools;
129
+ const tools = [...agent.state.tools];
128
130
  const turnPolicy = agentManager.createAgentTurnPolicy(conversationId);
129
131
  const systemPrompt = appendDynamicPromptSection([agent.state.systemPrompt ?? "", params.presentation === "voice" ? voicePresentationPrompt : ""].filter(Boolean).join("\n\n"), params.dynamicSystemContext ?? "");
130
132
  const idlePolicy = resolveCompactionPolicy(config);
@@ -164,6 +166,11 @@ async function runEmbeddedTurnForSessionInner(params) {
164
166
  };
165
167
  const thinkingLevel = params.thinkingOverride ?? agent.state.thinkingLevel;
166
168
  const workspaceDir = agentManager.getResolvedWorkspaceForSession(conversationId);
169
+ tools.push(...await materializeNativeExternalTools({
170
+ conversationId,
171
+ tools
172
+ }));
173
+ const mcp = config ? await prepareNativeMcpConfig(config, workspaceDir) : void 0;
167
174
  const promptCachePolicy = resolvePromptCachePolicy(config ? resolveEffectiveAgentProfileForSession(conversationId).config.runtime.promptCache : void 0);
168
175
  let userMessageForTurn = userMessage;
169
176
  if (params.applyStartupContext !== false) {
@@ -263,6 +270,8 @@ async function runEmbeddedTurnForSessionInner(params) {
263
270
  tools,
264
271
  systemPrompt,
265
272
  thinkingLevel,
273
+ codemode: config ? resolveEffectiveAgentProfileForSession(conversationId).config.runtime.codemode : void 0,
274
+ mcp,
266
275
  promptCachePolicy,
267
276
  compactionPolicy: resolveCompactionPolicy(config),
268
277
  workspaceDir,